@loaders.gl/core 4.2.0-alpha.4 → 4.2.0-alpha.5

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 (108) hide show
  1. package/dist/core-addons/write-file-browser.js +62 -1
  2. package/dist/dist.dev.js +366 -332
  3. package/dist/dist.min.js +15 -0
  4. package/dist/index.cjs +55 -68
  5. package/dist/index.cjs.map +7 -0
  6. package/dist/index.d.ts +20 -20
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +18 -1
  9. package/dist/iterators/batch-iterators/timed-batch-iterator.js +18 -13
  10. package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts +1 -1
  11. package/dist/iterators/make-iterator/make-array-buffer-iterator.d.ts.map +1 -1
  12. package/dist/iterators/make-iterator/make-array-buffer-iterator.js +21 -15
  13. package/dist/iterators/make-iterator/make-blob-iterator.d.ts +1 -1
  14. package/dist/iterators/make-iterator/make-blob-iterator.d.ts.map +1 -1
  15. package/dist/iterators/make-iterator/make-blob-iterator.js +18 -10
  16. package/dist/iterators/make-iterator/make-iterator.d.ts +1 -1
  17. package/dist/iterators/make-iterator/make-iterator.d.ts.map +1 -1
  18. package/dist/iterators/make-iterator/make-iterator.js +29 -18
  19. package/dist/iterators/make-iterator/make-stream-iterator.js +86 -23
  20. package/dist/iterators/make-iterator/make-string-iterator.d.ts +1 -1
  21. package/dist/iterators/make-iterator/make-string-iterator.d.ts.map +1 -1
  22. package/dist/iterators/make-iterator/make-string-iterator.js +20 -10
  23. package/dist/iterators/make-stream/make-stream.js +47 -29
  24. package/dist/javascript-utils/is-type.js +25 -19
  25. package/dist/lib/api/encode-table.js +40 -35
  26. package/dist/lib/api/encode.js +112 -73
  27. package/dist/lib/api/load-in-batches.js +35 -21
  28. package/dist/lib/api/load.js +35 -20
  29. package/dist/lib/api/loader-options.d.ts +2 -2
  30. package/dist/lib/api/loader-options.d.ts.map +1 -1
  31. package/dist/lib/api/loader-options.js +3 -1
  32. package/dist/lib/api/parse-in-batches.js +105 -69
  33. package/dist/lib/api/parse-sync.js +42 -33
  34. package/dist/lib/api/parse.js +73 -61
  35. package/dist/lib/api/register-loaders.js +23 -14
  36. package/dist/lib/api/select-loader.js +216 -163
  37. package/dist/lib/common.js +3 -1
  38. package/dist/lib/fetch/fetch-error-message.js +17 -12
  39. package/dist/lib/fetch/fetch-file.js +26 -15
  40. package/dist/lib/fetch/read-array-buffer.js +30 -15
  41. package/dist/lib/filesystems/browser-filesystem.js +126 -69
  42. package/dist/lib/filesystems/read-array-buffer.js +14 -6
  43. package/dist/lib/init.js +12 -6
  44. package/dist/lib/loader-utils/check-errors.js +37 -16
  45. package/dist/lib/loader-utils/get-data.js +110 -88
  46. package/dist/lib/loader-utils/get-fetch-function.js +24 -13
  47. package/dist/lib/loader-utils/loader-context.js +50 -31
  48. package/dist/lib/loader-utils/loggers.js +34 -44
  49. package/dist/lib/loader-utils/normalize-loader.js +45 -32
  50. package/dist/lib/loader-utils/option-defaults.js +38 -34
  51. package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
  52. package/dist/lib/loader-utils/option-utils.js +133 -80
  53. package/dist/lib/progress/fetch-progress.js +54 -47
  54. package/dist/lib/utils/log.js +4 -4
  55. package/dist/lib/utils/mime-type-utils.js +34 -11
  56. package/dist/lib/utils/resource-utils.js +77 -45
  57. package/dist/lib/utils/response-utils.js +97 -74
  58. package/dist/lib/utils/url-utils.js +6 -4
  59. package/dist/null-loader.js +43 -29
  60. package/dist/workers/null-worker-node.js +3 -1
  61. package/dist/workers/null-worker.js +3 -1
  62. package/package.json +7 -7
  63. package/src/lib/loader-utils/option-utils.ts +3 -1
  64. package/dist/core-addons/README.md +0 -1
  65. package/dist/core-addons/write-file-browser.js.map +0 -1
  66. package/dist/index.js.map +0 -1
  67. package/dist/iterators/batch-iterators/timed-batch-iterator.js.map +0 -1
  68. package/dist/iterators/make-iterator/make-array-buffer-iterator.js.map +0 -1
  69. package/dist/iterators/make-iterator/make-blob-iterator.js.map +0 -1
  70. package/dist/iterators/make-iterator/make-iterator.js.map +0 -1
  71. package/dist/iterators/make-iterator/make-stream-iterator.js.map +0 -1
  72. package/dist/iterators/make-iterator/make-string-iterator.js.map +0 -1
  73. package/dist/iterators/make-stream/make-stream.js.map +0 -1
  74. package/dist/javascript-utils/is-type.js.map +0 -1
  75. package/dist/lib/api/encode-table.js.map +0 -1
  76. package/dist/lib/api/encode.js.map +0 -1
  77. package/dist/lib/api/load-in-batches.js.map +0 -1
  78. package/dist/lib/api/load.js.map +0 -1
  79. package/dist/lib/api/loader-options.js.map +0 -1
  80. package/dist/lib/api/parse-in-batches.js.map +0 -1
  81. package/dist/lib/api/parse-sync.js.map +0 -1
  82. package/dist/lib/api/parse.js.map +0 -1
  83. package/dist/lib/api/register-loaders.js.map +0 -1
  84. package/dist/lib/api/select-loader.js.map +0 -1
  85. package/dist/lib/common.js.map +0 -1
  86. package/dist/lib/fetch/fetch-error-message.js.map +0 -1
  87. package/dist/lib/fetch/fetch-file.js.map +0 -1
  88. package/dist/lib/fetch/read-array-buffer.js.map +0 -1
  89. package/dist/lib/filesystems/browser-filesystem.js.map +0 -1
  90. package/dist/lib/filesystems/read-array-buffer.js.map +0 -1
  91. package/dist/lib/init.js.map +0 -1
  92. package/dist/lib/loader-utils/check-errors.js.map +0 -1
  93. package/dist/lib/loader-utils/get-data.js.map +0 -1
  94. package/dist/lib/loader-utils/get-fetch-function.js.map +0 -1
  95. package/dist/lib/loader-utils/loader-context.js.map +0 -1
  96. package/dist/lib/loader-utils/loggers.js.map +0 -1
  97. package/dist/lib/loader-utils/normalize-loader.js.map +0 -1
  98. package/dist/lib/loader-utils/option-defaults.js.map +0 -1
  99. package/dist/lib/loader-utils/option-utils.js.map +0 -1
  100. package/dist/lib/progress/fetch-progress.js.map +0 -1
  101. package/dist/lib/utils/log.js.map +0 -1
  102. package/dist/lib/utils/mime-type-utils.js.map +0 -1
  103. package/dist/lib/utils/resource-utils.js.map +0 -1
  104. package/dist/lib/utils/response-utils.js.map +0 -1
  105. package/dist/lib/utils/url-utils.js.map +0 -1
  106. package/dist/null-loader.js.map +0 -1
  107. package/dist/workers/null-worker-node.js.map +0 -1
  108. package/dist/workers/null-worker.js.map +0 -1
@@ -1,52 +1,59 @@
1
- export async function fetchProgress(response, onProgress) {
2
- let onDone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : () => {};
3
- let onError = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : () => {};
4
- response = await response;
5
- if (!response.ok) {
6
- return response;
7
- }
8
- const body = response.body;
9
- if (!body) {
10
- return response;
11
- }
12
- const contentLength = response.headers.get('content-length') || 0;
13
- const totalBytes = contentLength ? parseInt(contentLength) : 0;
14
- if (!(totalBytes > 0)) {
15
- return response;
16
- }
17
- if (typeof ReadableStream === 'undefined' || !body.getReader) {
18
- return response;
19
- }
20
- const progressStream = new ReadableStream({
21
- async start(controller) {
22
- const reader = body.getReader();
23
- await read(controller, reader, 0, totalBytes, onProgress, onDone, onError);
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // Forked from github AnthumChris/fetch-progress-indicators under MIT license
5
+ /**
6
+ * Intercepts the Response stream and creates a new Response
7
+ */
8
+ export 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;
24
14
  }
25
- });
26
- return new Response(progressStream);
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);
27
37
  }
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
28
41
  async function read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError) {
29
- try {
30
- const {
31
- done,
32
- value
33
- } = await reader.read();
34
- if (done) {
35
- onDone();
36
- controller.close();
37
- return;
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);
38
58
  }
39
- loadedBytes += value.byteLength;
40
- const percent = Math.round(loadedBytes / totalBytes * 100);
41
- onProgress(percent, {
42
- loadedBytes,
43
- totalBytes
44
- });
45
- controller.enqueue(value);
46
- await read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError);
47
- } catch (error) {
48
- controller.error(error);
49
- onError(error);
50
- }
51
59
  }
52
- //# sourceMappingURL=fetch-progress.js.map
@@ -1,5 +1,5 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { Log } from '@probe.gl/log';
2
- export const log = new Log({
3
- id: 'loaders.gl'
4
- });
5
- //# sourceMappingURL=log.js.map
5
+ export const log = new Log({ id: 'loaders.gl' });
@@ -1,17 +1,40 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // TODO - build/integrate proper MIME type parsing
5
+ // https://mimesniff.spec.whatwg.org/
1
6
  const DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
2
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
+ */
3
16
  export function parseMIMEType(mimeString) {
4
- const matches = MIME_TYPE_PATTERN.exec(mimeString);
5
- if (matches) {
6
- return matches[1];
7
- }
8
- return 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;
9
23
  }
24
+ /**
25
+ * Extract MIME type from data URL
26
+ *
27
+ * @param mimeString
28
+ * @returns A clean MIME type, or an empty string
29
+ *
30
+ * @todo - handle more advanced MIMETYpes, multiple types
31
+ * @todo - extract charset etc
32
+ */
10
33
  export function parseMIMETypeFromURL(url) {
11
- const matches = DATA_URL_PATTERN.exec(url);
12
- if (matches) {
13
- return matches[1];
14
- }
15
- return '';
34
+ // If resource is a data URL, extract any embedded mime type
35
+ const matches = DATA_URL_PATTERN.exec(url);
36
+ if (matches) {
37
+ return matches[1];
38
+ }
39
+ return '';
16
40
  }
17
- //# sourceMappingURL=mime-type-utils.js.map
@@ -1,54 +1,86 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { isResponse, isBlob } from "../../javascript-utils/is-type.js";
2
5
  import { parseMIMEType, parseMIMETypeFromURL } from "./mime-type-utils.js";
3
6
  import { stripQueryString } from "./url-utils.js";
7
+ /**
8
+ * Returns the URL associated with this resource.
9
+ * The returned value may include a query string and need further processing.
10
+ * If it cannot determine url, the corresponding value will be an empty string
11
+ *
12
+ * @todo string parameters are assumed to be URLs
13
+ */
4
14
  export function getResourceUrl(resource) {
5
- if (isResponse(resource)) {
6
- const response = resource;
7
- return response.url;
8
- }
9
- if (isBlob(resource)) {
10
- const blob = resource;
11
- return blob.name || '';
12
- }
13
- if (typeof resource === 'string') {
14
- return resource;
15
- }
16
- return '';
15
+ // If resource is a `Response`, it contains the information directly as a field
16
+ if (isResponse(resource)) {
17
+ const response = resource;
18
+ return response.url;
19
+ }
20
+ // If the resource is a Blob or a File (subclass of Blob)
21
+ if (isBlob(resource)) {
22
+ const blob = resource;
23
+ // File objects have a "name" property. Blob objects don't have any
24
+ // url (name) information
25
+ return blob.name || '';
26
+ }
27
+ if (typeof resource === 'string') {
28
+ return resource;
29
+ }
30
+ // Unknown
31
+ return '';
17
32
  }
33
+ /**
34
+ * Returns the URL associated with this resource.
35
+ * The returned value may include a query string and need further processing.
36
+ * If it cannot determine url, the corresponding value will be an empty string
37
+ *
38
+ * @todo string parameters are assumed to be URLs
39
+ */
18
40
  export function getResourceMIMEType(resource) {
19
- if (isResponse(resource)) {
20
- const response = resource;
21
- const contentTypeHeader = response.headers.get('content-type') || '';
22
- const noQueryUrl = stripQueryString(response.url);
23
- return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
24
- }
25
- if (isBlob(resource)) {
26
- const blob = resource;
27
- return blob.type || '';
28
- }
29
- if (typeof resource === 'string') {
30
- return parseMIMETypeFromURL(resource);
31
- }
32
- return '';
41
+ // If resource is a response, it contains the information directly
42
+ if (isResponse(resource)) {
43
+ const response = resource;
44
+ const contentTypeHeader = response.headers.get('content-type') || '';
45
+ const noQueryUrl = stripQueryString(response.url);
46
+ return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
47
+ }
48
+ // If the resource is a Blob or a File (subclass of Blob)
49
+ if (isBlob(resource)) {
50
+ const blob = resource;
51
+ return blob.type || '';
52
+ }
53
+ if (typeof resource === 'string') {
54
+ return parseMIMETypeFromURL(resource);
55
+ }
56
+ // Unknown
57
+ return '';
33
58
  }
59
+ /**
60
+ * Returns (approximate) content length for a resource if it can be determined.
61
+ * Returns -1 if content length cannot be determined.
62
+ * @param resource
63
+
64
+ * @note string parameters are NOT assumed to be URLs
65
+ */
34
66
  export function getResourceContentLength(resource) {
35
- if (isResponse(resource)) {
36
- const response = resource;
37
- return response.headers['content-length'] || -1;
38
- }
39
- if (isBlob(resource)) {
40
- const blob = resource;
41
- return blob.size;
42
- }
43
- if (typeof resource === 'string') {
44
- return resource.length;
45
- }
46
- if (resource instanceof ArrayBuffer) {
47
- return resource.byteLength;
48
- }
49
- if (ArrayBuffer.isView(resource)) {
50
- return resource.byteLength;
51
- }
52
- return -1;
67
+ if (isResponse(resource)) {
68
+ const response = resource;
69
+ return response.headers['content-length'] || -1;
70
+ }
71
+ if (isBlob(resource)) {
72
+ const blob = resource;
73
+ return blob.size;
74
+ }
75
+ if (typeof resource === 'string') {
76
+ // TODO - handle data URL?
77
+ return resource.length;
78
+ }
79
+ if (resource instanceof ArrayBuffer) {
80
+ return resource.byteLength;
81
+ }
82
+ if (ArrayBuffer.isView(resource)) {
83
+ return resource.byteLength;
84
+ }
85
+ return -1;
53
86
  }
54
- //# sourceMappingURL=resource-utils.js.map
@@ -1,89 +1,112 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { isResponse } from "../../javascript-utils/is-type.js";
2
5
  import { getResourceContentLength, getResourceUrl, getResourceMIMEType } from "./resource-utils.js";
6
+ /**
7
+ * Returns a Response object
8
+ * Adds content-length header when possible
9
+ *
10
+ * @param resource
11
+ */
3
12
  export async function makeResponse(resource) {
4
- if (isResponse(resource)) {
5
- return resource;
6
- }
7
- const headers = {};
8
- const contentLength = getResourceContentLength(resource);
9
- if (contentLength >= 0) {
10
- headers['content-length'] = String(contentLength);
11
- }
12
- const url = getResourceUrl(resource);
13
- const type = getResourceMIMEType(resource);
14
- if (type) {
15
- headers['content-type'] = type;
16
- }
17
- const initialDataUrl = await getInitialDataUrl(resource);
18
- if (initialDataUrl) {
19
- headers['x-first-bytes'] = initialDataUrl;
20
- }
21
- if (typeof resource === 'string') {
22
- resource = new TextEncoder().encode(resource);
23
- }
24
- const response = new Response(resource, {
25
- headers
26
- });
27
- Object.defineProperty(response, 'url', {
28
- value: url
29
- });
30
- return response;
13
+ if (isResponse(resource)) {
14
+ return resource;
15
+ }
16
+ // Add content-length header if possible
17
+ const headers = {};
18
+ const contentLength = 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 = getResourceUrl(resource);
25
+ const type = 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;
31
45
  }
46
+ /**
47
+ * Checks response status (async) and throws a helpful error message if status is not OK.
48
+ * @param response
49
+ */
32
50
  export async function checkResponse(response) {
33
- if (!response.ok) {
34
- const message = await getResponseError(response);
35
- throw new Error(message);
36
- }
51
+ if (!response.ok) {
52
+ const message = await getResponseError(response);
53
+ throw new Error(message);
54
+ }
37
55
  }
56
+ /**
57
+ * Checks response status (sync) and throws a helpful error message if status is not OK.
58
+ * @param response
59
+ */
38
60
  export function checkResponseSync(response) {
39
- if (!response.ok) {
40
- let message = `${response.status} ${response.statusText}`;
41
- message = message.length > 60 ? `${message.slice(0, 60)}...` : message;
42
- throw new Error(message);
43
- }
61
+ if (!response.ok) {
62
+ let message = `${response.status} ${response.statusText}`;
63
+ message = message.length > 60 ? `${message.slice(0, 60)}...` : message;
64
+ throw new Error(message);
65
+ }
44
66
  }
67
+ // HELPERS
45
68
  async function getResponseError(response) {
46
- let message = `Failed to fetch resource ${response.url} (${response.status}): `;
47
- try {
48
- const contentType = response.headers.get('Content-Type');
49
- let text = response.statusText;
50
- if (contentType !== null && contentType !== void 0 && contentType.includes('application/json')) {
51
- text += ` ${await response.text()}`;
69
+ let message = `Failed to fetch resource ${response.url} (${response.status}): `;
70
+ try {
71
+ const contentType = response.headers.get('Content-Type');
72
+ let text = response.statusText;
73
+ if (contentType?.includes('application/json')) {
74
+ text += ` ${await response.text()}`;
75
+ }
76
+ message += text;
77
+ message = message.length > 60 ? `${message.slice(0, 60)}...` : message;
78
+ }
79
+ catch (error) {
80
+ // eslint forbids return in a finally statement, so we just catch here
52
81
  }
53
- message += text;
54
- message = message.length > 60 ? `${message.slice(0, 60)}...` : message;
55
- } catch (error) {}
56
- return message;
82
+ return message;
57
83
  }
58
84
  async function getInitialDataUrl(resource) {
59
- const INITIAL_DATA_LENGTH = 5;
60
- if (typeof resource === 'string') {
61
- return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`;
62
- }
63
- if (resource instanceof Blob) {
64
- const blobSlice = resource.slice(0, 5);
65
- return await new Promise(resolve => {
66
- const reader = new FileReader();
67
- reader.onload = event => {
68
- var _event$target;
69
- return resolve(event === null || event === void 0 ? void 0 : (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.result);
70
- };
71
- reader.readAsDataURL(blobSlice);
72
- });
73
- }
74
- if (resource instanceof ArrayBuffer) {
75
- const slice = resource.slice(0, INITIAL_DATA_LENGTH);
76
- const base64 = arrayBufferToBase64(slice);
77
- return `data:base64,${base64}`;
78
- }
79
- return null;
85
+ const INITIAL_DATA_LENGTH = 5;
86
+ if (typeof resource === 'string') {
87
+ return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`;
88
+ }
89
+ if (resource instanceof Blob) {
90
+ const blobSlice = resource.slice(0, 5);
91
+ return await new Promise((resolve) => {
92
+ const reader = new FileReader();
93
+ reader.onload = (event) => resolve(event?.target?.result);
94
+ reader.readAsDataURL(blobSlice);
95
+ });
96
+ }
97
+ if (resource instanceof ArrayBuffer) {
98
+ const slice = resource.slice(0, INITIAL_DATA_LENGTH);
99
+ const base64 = arrayBufferToBase64(slice);
100
+ return `data:base64,${base64}`;
101
+ }
102
+ return null;
80
103
  }
104
+ // https://stackoverflow.com/questions/9267899/arraybuffer-to-base64-encoded-string
81
105
  function arrayBufferToBase64(buffer) {
82
- let binary = '';
83
- const bytes = new Uint8Array(buffer);
84
- for (let i = 0; i < bytes.byteLength; i++) {
85
- binary += String.fromCharCode(bytes[i]);
86
- }
87
- return btoa(binary);
106
+ let binary = '';
107
+ const bytes = new Uint8Array(buffer);
108
+ for (let i = 0; i < bytes.byteLength; i++) {
109
+ binary += String.fromCharCode(bytes[i]);
110
+ }
111
+ return btoa(binary);
88
112
  }
89
- //# sourceMappingURL=response-utils.js.map
@@ -1,9 +1,11 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  const QUERY_STRING_PATTERN = /\?.*/;
2
5
  export function extractQueryString(url) {
3
- const matches = url.match(QUERY_STRING_PATTERN);
4
- return matches && matches[0];
6
+ const matches = url.match(QUERY_STRING_PATTERN);
7
+ return matches && matches[0];
5
8
  }
6
9
  export function stripQueryString(url) {
7
- return url.replace(QUERY_STRING_PATTERN, '');
10
+ return url.replace(QUERY_STRING_PATTERN, '');
8
11
  }
9
- //# sourceMappingURL=url-utils.js.map
@@ -1,37 +1,51 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // __VERSION__ is injected by babel-plugin-version-inline
5
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
1
6
  const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest';
7
+ /**
8
+ * Loads any data and returns null (or optionally passes through data unparsed)
9
+ */
2
10
  export const NullWorkerLoader = {
3
- name: 'Null loader',
4
- id: 'null',
5
- module: 'core',
6
- version: VERSION,
7
- worker: true,
8
- mimeTypes: ['application/x.empty'],
9
- extensions: ['null'],
10
- tests: [() => false],
11
- options: {
12
- null: {}
13
- }
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
+ }
14
22
  };
23
+ /**
24
+ * Loads any data and returns null (or optionally passes through data unparsed)
25
+ */
15
26
  export const NullLoader = {
16
- name: 'Null loader',
17
- id: 'null',
18
- module: 'core',
19
- version: VERSION,
20
- mimeTypes: ['application/x.empty'],
21
- extensions: ['null'],
22
- parse: async (arrayBuffer, options, context) => parseSync(arrayBuffer, options || {}, context),
23
- parseSync,
24
- parseInBatches: async function* generator(asyncIterator, options, context) {
25
- for await (const batch of asyncIterator) {
26
- yield parseSync(batch, options, context);
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: {}
27
43
  }
28
- },
29
- tests: [() => false],
30
- options: {
31
- null: {}
32
- }
33
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
+ */
34
49
  function parseSync(arrayBuffer, options, context) {
35
- return null;
50
+ return null;
36
51
  }
37
- //# sourceMappingURL=null-loader.js.map
@@ -1,4 +1,6 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { createLoaderWorker } from '@loaders.gl/loader-utils';
2
5
  import { NullLoader } from "../null-loader.js";
3
6
  createLoaderWorker(NullLoader);
4
- //# sourceMappingURL=null-worker-node.js.map
@@ -1,4 +1,6 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { createLoaderWorker } from '@loaders.gl/loader-utils';
2
5
  import { NullLoader } from "../null-loader.js";
3
6
  createLoaderWorker(NullLoader);
4
- //# sourceMappingURL=null-worker.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/core",
3
- "version": "4.2.0-alpha.4",
3
+ "version": "4.2.0-alpha.5",
4
4
  "description": "The core API for working with loaders.gl loaders and writers",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -48,16 +48,16 @@
48
48
  "README.md"
49
49
  ],
50
50
  "scripts": {
51
- "pre-build": "npm run build-bundle && npm run build-bundle -- --env=dev && npm run build-worker && npm run build-worker-node",
52
- "build-bundle": "ocular-bundle ./src/index.ts",
51
+ "pre-build": "npm run build-bundle && npm run build-bundle-dev && npm run build-worker && npm run build-worker-node",
52
+ "build-bundle": "ocular-bundle ./bundle.ts --output=dist/dist.min.js",
53
+ "build-bundle-dev": "ocular-bundle ./bundle.ts --env=dev --output=dist/dist.dev.js",
53
54
  "build-worker": "esbuild src/workers/null-worker.ts --outfile=dist/null-worker.js --bundle --target=esnext --define:__VERSION__=\\\"$npm_package_version\\\"",
54
55
  "build-worker-node": "esbuild src/workers/null-worker.ts --outfile=dist/null-worker-node.js --bundle --platform=node --target=node16 --define:__VERSION__=\\\"$npm_package_version\\\""
55
56
  },
56
57
  "dependencies": {
57
- "@babel/runtime": "^7.3.1",
58
- "@loaders.gl/loader-utils": "4.2.0-alpha.4",
59
- "@loaders.gl/worker-utils": "4.2.0-alpha.4",
58
+ "@loaders.gl/loader-utils": "4.2.0-alpha.5",
59
+ "@loaders.gl/worker-utils": "4.2.0-alpha.5",
60
60
  "@probe.gl/log": "^4.0.2"
61
61
  },
62
- "gitHead": "6c52dee5c3f005648a394cc4aee7fc37005c8e83"
62
+ "gitHead": "32d95a81971f104e4dfeb88ab57065f05321a76a"
63
63
  }
@@ -26,7 +26,9 @@ export function getGlobalLoaderState(): GlobalLoaderState {
26
26
  const {loaders} = globalThis;
27
27
 
28
28
  // Add _state object to keep separate from modules added to globalThis.loaders
29
- loaders._state = loaders._state || {};
29
+ if (!loaders._state) {
30
+ loaders._state = {};
31
+ }
30
32
  return loaders._state;
31
33
  }
32
34
 
@@ -1 +0,0 @@
1
- These experimental classes should be moved to another module.