@loaders.gl/polyfills 4.2.0-alpha.4 → 4.2.0-alpha.6
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/dist/buffer/btoa.node.js +5 -3
- package/dist/buffer/to-array-buffer.node.js +6 -6
- package/dist/crypto/node-hash.js +46 -45
- package/dist/fetch/decode-data-uri.js +56 -41
- package/dist/fetch/fetch-polyfill.d.ts +1 -1
- package/dist/fetch/fetch-polyfill.d.ts.map +1 -1
- package/dist/fetch/fetch-polyfill.js +118 -103
- package/dist/fetch/headers-polyfill.js +91 -89
- package/dist/fetch/response-polyfill.d.ts +1 -1
- package/dist/fetch/response-polyfill.d.ts.map +1 -1
- package/dist/fetch/response-polyfill.js +73 -57
- package/dist/fetch/utils/decode-data-uri.node.js +56 -41
- package/dist/file/blob-stream-controller.js +55 -38
- package/dist/file/blob-stream.d.ts +1 -1
- package/dist/file/blob-stream.d.ts.map +1 -1
- package/dist/file/blob-stream.js +30 -15
- package/dist/file/blob.d.ts +1 -1
- package/dist/file/blob.d.ts.map +1 -1
- package/dist/file/blob.js +152 -109
- package/dist/file/file-reader.js +38 -50
- package/dist/file/file.js +35 -15
- package/dist/file/install-blob-polyfills.js +6 -5
- package/dist/file/install-file-polyfills.d.ts +3 -2
- package/dist/file/install-file-polyfills.d.ts.map +1 -1
- package/dist/file/install-file-polyfills.js +11 -8
- package/dist/file/readable-stream.js +5 -2
- package/dist/filesystems/fetch-node.d.ts.map +1 -1
- package/dist/filesystems/fetch-node.js +80 -68
- package/dist/filesystems/node-file.d.ts.map +1 -1
- package/dist/filesystems/node-file.js +129 -87
- package/dist/filesystems/node-filesystem.d.ts +1 -1
- package/dist/filesystems/node-filesystem.d.ts.map +1 -1
- package/dist/filesystems/node-filesystem.js +39 -35
- package/dist/filesystems/stream-utils.node.js +88 -55
- package/dist/images/encode-image-node.js +25 -12
- package/dist/images/encode-image.node.js +25 -12
- package/dist/images/parse-image-node.js +30 -23
- package/dist/images/parse-image.node.js +30 -23
- package/dist/index.browser.js +8 -3
- package/dist/index.cjs +13 -65091
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -15
- package/dist/libs/encoding-indexes-asian.js +6 -7
- package/dist/load-library/require-utils.node.js +70 -44
- package/dist/streams/make-node-stream.d.ts.map +1 -1
- package/dist/streams/make-node-stream.js +52 -46
- package/dist/text-encoder/encoding-indexes.js +31 -28
- package/dist/text-encoder/text-encoder.js +2604 -1033
- package/dist/utils/assert.js +3 -4
- package/dist/utils/is-browser.js +7 -2
- package/package.json +13 -11
- package/src/fetch/response-polyfill.ts +2 -0
- package/src/filesystems/fetch-node.ts +2 -0
- package/src/filesystems/node-file.ts +4 -0
- package/src/filesystems/node-filesystem.ts +1 -0
- package/src/index.ts +1 -0
- package/src/load-library/require-utils.node.ts +1 -1
- package/src/streams/make-node-stream.ts +3 -2
- package/dist/buffer/btoa.node.js.map +0 -1
- package/dist/buffer/to-array-buffer.node.js.map +0 -1
- package/dist/crypto/node-hash.js.map +0 -1
- package/dist/dist.dev.js +0 -45
- package/dist/fetch/decode-data-uri.js.map +0 -1
- package/dist/fetch/fetch-polyfill.js.map +0 -1
- package/dist/fetch/headers-polyfill.js.map +0 -1
- package/dist/fetch/response-polyfill.js.map +0 -1
- package/dist/fetch/utils/decode-data-uri.node.js.map +0 -1
- package/dist/file/blob-stream-controller.js.map +0 -1
- package/dist/file/blob-stream.js.map +0 -1
- package/dist/file/blob.js.map +0 -1
- package/dist/file/file-reader.js.map +0 -1
- package/dist/file/file.js.map +0 -1
- package/dist/file/install-blob-polyfills.js.map +0 -1
- package/dist/file/install-file-polyfills.js.map +0 -1
- package/dist/file/readable-stream.js.map +0 -1
- package/dist/filesystems/fetch-node.js.map +0 -1
- package/dist/filesystems/node-file.js.map +0 -1
- package/dist/filesystems/node-filesystem.js.map +0 -1
- package/dist/filesystems/stream-utils.node.js.map +0 -1
- package/dist/images/encode-image-node.js.map +0 -1
- package/dist/images/encode-image.node.js.map +0 -1
- package/dist/images/parse-image-node.js.map +0 -1
- package/dist/images/parse-image.node.js.map +0 -1
- package/dist/index.browser.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/load-library/require-utils.node.js.map +0 -1
- package/dist/streams/make-node-stream.js.map +0 -1
- package/dist/text-encoder/encoding-indexes.js.map +0 -1
- package/dist/text-encoder/text-encoder.js.map +0 -1
- package/dist/utils/assert.js.map +0 -1
- package/dist/utils/is-browser.js.map +0 -1
|
@@ -1,29 +1,36 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import getPixels from 'get-pixels';
|
|
5
|
+
/** Declares which image format mime types this loader polyfill supports */
|
|
2
6
|
export const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
|
|
3
7
|
export async function parseImageNode(arrayBuffer, mimeType) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
if (!mimeType) {
|
|
9
|
+
throw new Error('MIMEType is required to parse image under Node.js');
|
|
10
|
+
}
|
|
11
|
+
const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
|
|
12
|
+
const ndarray = await getPixelsAsync(buffer, mimeType);
|
|
13
|
+
return ndarray;
|
|
10
14
|
}
|
|
15
|
+
// TODO - check if getPixels callback is asynchronous if provided with buffer input
|
|
16
|
+
// if not, parseImage can be a sync function
|
|
11
17
|
function getPixelsAsync(buffer, mimeType) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
return new Promise((resolve) => getPixels(buffer, mimeType, (err, ndarray) => {
|
|
19
|
+
if (err) {
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
const shape = [...ndarray.shape];
|
|
23
|
+
const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;
|
|
24
|
+
const data = ndarray.data instanceof Buffer ? new Uint8Array(ndarray.data) : ndarray.data;
|
|
25
|
+
// extract width/height etc
|
|
26
|
+
resolve({
|
|
27
|
+
shape,
|
|
28
|
+
data,
|
|
29
|
+
width: ndarray.shape[0],
|
|
30
|
+
height: ndarray.shape[1],
|
|
31
|
+
components: ndarray.shape[2],
|
|
32
|
+
// TODO - error
|
|
33
|
+
layers: layers ? [layers] : []
|
|
34
|
+
});
|
|
35
|
+
}));
|
|
28
36
|
}
|
|
29
|
-
//# sourceMappingURL=parse-image.node.js.map
|
package/dist/index.browser.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
export function installFilePolyfills() { }
|
|
4
|
+
// Dummy export to avoid import errors in browser tests
|
|
2
5
|
export const NodeFileSystem = null;
|
|
3
6
|
export function fetchNode(path, options) {
|
|
4
|
-
|
|
7
|
+
throw new Error('fetchNode not available in browser');
|
|
5
8
|
}
|
|
9
|
+
// Ensure process and process.env are defined, as Node code tends to crash on these
|
|
10
|
+
// @ts-ignore
|
|
6
11
|
globalThis.process = globalThis.process || {};
|
|
12
|
+
// @ts-ignore
|
|
7
13
|
globalThis.process.env = globalThis.process.env || {};
|
|
8
|
-
//# sourceMappingURL=index.browser.js.map
|