@loaders.gl/core 5.0.0-beta.1 → 5.0.0-beta.4
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/README.md +3 -1
- package/dist/cluster-source.cjs +7228 -0
- package/dist/cluster-source.cjs.map +6 -0
- package/dist/cluster-source.d.ts +2 -0
- package/dist/cluster-source.d.ts.map +1 -0
- package/dist/cluster-source.js +2 -0
- package/dist/cluster-source.js.map +1 -0
- package/dist/dist.dev.js +2141 -438
- package/dist/dist.min.js +3 -3
- package/dist/federated-table-scan-source.cjs +2677 -0
- package/dist/federated-table-scan-source.cjs.map +6 -0
- package/dist/federated-table-scan-source.d.ts +2 -0
- package/dist/federated-table-scan-source.d.ts.map +1 -0
- package/dist/federated-table-scan-source.js +2 -0
- package/dist/federated-table-scan-source.js.map +1 -0
- package/dist/index.cjs +268 -960
- package/dist/index.cjs.map +3 -3
- package/dist/lib/init.js +1 -1
- package/dist/loader-utils/index.cjs +418 -1234
- package/dist/loader-utils/index.cjs.map +3 -3
- package/dist/loader-utils/json-loader.js +1 -1
- package/dist/loader-utils/lib/log-utils/log.js +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/encode-with-worker.d.ts.map +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/encode-with-worker.js +2 -5
- package/dist/loader-utils/lib/worker-loader-utils/encode-with-worker.js.map +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -1
- package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.js +14 -6
- package/dist/loader-utils/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
- package/dist/loader-utils/loader-types.d.ts +2 -2
- package/dist/loader-utils/loader-types.d.ts.map +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-worker-node.js +538 -82
- package/dist/null-worker.js +514 -81
- package/dist/polyfills/images/encode-image-node.d.ts +18 -15
- package/dist/polyfills/images/encode-image-node.d.ts.map +1 -1
- package/dist/polyfills/images/encode-image-node.js +19 -33
- package/dist/polyfills/images/encode-image-node.js.map +1 -1
- package/dist/polyfills/images/image-codecs-node.d.ts +2 -6
- package/dist/polyfills/images/image-codecs-node.d.ts.map +1 -1
- package/dist/polyfills/images/image-codecs-node.js +2 -24
- package/dist/polyfills/images/image-codecs-node.js.map +1 -1
- package/dist/polyfills/images/load-sharp.d.ts +3 -0
- package/dist/polyfills/images/load-sharp.d.ts.map +1 -0
- package/dist/polyfills/images/load-sharp.js +11 -0
- package/dist/polyfills/images/load-sharp.js.map +1 -0
- package/dist/polyfills/images/node-image-bitmap.d.ts +1 -1
- package/dist/polyfills/images/node-image-bitmap.js +1 -1
- package/dist/polyfills/images/node-image-formats.d.ts +1 -1
- package/dist/polyfills/images/node-image-formats.d.ts.map +1 -1
- package/dist/polyfills/images/node-image-formats.js +10 -4
- package/dist/polyfills/images/node-image-formats.js.map +1 -1
- package/dist/polyfills/images/parse-image-node.d.ts +10 -2
- package/dist/polyfills/images/parse-image-node.d.ts.map +1 -1
- package/dist/polyfills/images/parse-image-node.js +20 -32
- package/dist/polyfills/images/parse-image-node.js.map +1 -1
- package/dist/polyfills/index.cjs +73 -149
- package/dist/vector-table-scan-source.cjs +1703 -0
- package/dist/vector-table-scan-source.cjs.map +6 -0
- package/dist/vector-table-scan-source.d.ts +2 -0
- package/dist/vector-table-scan-source.d.ts.map +1 -0
- package/dist/vector-table-scan-source.js +2 -0
- package/dist/vector-table-scan-source.js.map +1 -0
- package/dist/worker-utils/index.cjs +371 -1182
- package/dist/worker-utils/index.cjs.map +3 -3
- package/dist/worker-utils/index.d.ts +5 -8
- package/dist/worker-utils/index.d.ts.map +1 -1
- package/dist/worker-utils/index.js +4 -10
- package/dist/worker-utils/index.js.map +1 -1
- package/dist/worker-utils/lib/env-utils/version.js +1 -1
- package/dist/worker-utils/lib/worker-api/create-worker.d.ts +5 -7
- package/dist/worker-utils/lib/worker-api/create-worker.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-api/create-worker.js +76 -146
- package/dist/worker-utils/lib/worker-api/create-worker.js.map +1 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts +16 -47
- package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.js +214 -312
- package/dist/worker-utils/lib/worker-api/process-on-worker.js.map +1 -1
- package/dist/worker-utils/lib/worker-api/task-runtime.d.ts +36 -0
- package/dist/worker-utils/lib/worker-api/task-runtime.d.ts.map +1 -0
- package/dist/worker-utils/lib/worker-api/task-runtime.js +23 -0
- package/dist/worker-utils/lib/worker-api/task-runtime.js.map +1 -0
- package/dist/worker-utils/lib/worker-utils/get-transfer-list.d.ts +1 -0
- package/dist/worker-utils/lib/worker-utils/get-transfer-list.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-utils/get-transfer-list.js +3 -1
- package/dist/worker-utils/lib/worker-utils/get-transfer-list.js.map +1 -1
- package/dist/worker-utils/null-worker-node.js +603 -147
- package/dist/worker-utils/null-worker-node.js.map +4 -4
- package/dist/worker-utils/null-worker.js +576 -143
- package/dist/worker-utils/null-worker.js.map +4 -4
- package/dist/worker-utils/types.d.ts +55 -72
- package/dist/worker-utils/types.d.ts.map +1 -1
- package/package.json +27 -29
- package/src/cluster-source.ts +1 -0
- package/src/federated-table-scan-source.ts +1 -0
- package/src/loader-utils/lib/worker-loader-utils/encode-with-worker.ts +5 -6
- package/src/loader-utils/lib/worker-loader-utils/parse-with-worker.ts +14 -6
- package/src/loader-utils/loader-types.ts +2 -2
- package/src/polyfills/README.md +2 -2
- package/src/polyfills/images/encode-image-node.ts +44 -37
- package/src/polyfills/images/image-codecs-node.ts +2 -37
- package/src/polyfills/images/load-sharp.ts +13 -0
- package/src/polyfills/images/node-image-bitmap.ts +1 -1
- package/src/polyfills/images/node-image-formats.ts +10 -4
- package/src/polyfills/images/parse-image-node.ts +31 -40
- package/src/vector-table-scan-source.ts +1 -0
- package/src/worker-utils/index.ts +17 -17
- package/src/worker-utils/lib/worker-api/create-worker.ts +89 -188
- package/src/worker-utils/lib/worker-api/process-on-worker.ts +249 -403
- package/src/worker-utils/lib/worker-api/task-runtime.ts +66 -0
- package/src/worker-utils/lib/worker-utils/get-transfer-list.ts +2 -0
- package/src/worker-utils/types.ts +74 -109
- package/dist/worker-utils/lib/async-queue/async-queue.d.ts +0 -32
- package/dist/worker-utils/lib/async-queue/async-queue.d.ts.map +0 -1
- package/dist/worker-utils/lib/async-queue/async-queue.js +0 -91
- package/dist/worker-utils/lib/async-queue/async-queue.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-body.d.ts +0 -20
- package/dist/worker-utils/lib/worker-farm/worker-body.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-body.js +0 -131
- package/dist/worker-utils/lib/worker-farm/worker-body.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-farm.d.ts +0 -58
- package/dist/worker-utils/lib/worker-farm/worker-farm.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-farm.js +0 -116
- package/dist/worker-utils/lib/worker-farm/worker-farm.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-job.d.ts +0 -34
- package/dist/worker-utils/lib/worker-farm/worker-job.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-job.js +0 -74
- package/dist/worker-utils/lib/worker-farm/worker-job.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-pool.d.ts +0 -94
- package/dist/worker-utils/lib/worker-farm/worker-pool.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-pool.js +0 -246
- package/dist/worker-utils/lib/worker-farm/worker-pool.js.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-thread.d.ts +0 -67
- package/dist/worker-utils/lib/worker-farm/worker-thread.d.ts.map +0 -1
- package/dist/worker-utils/lib/worker-farm/worker-thread.js +0 -175
- package/dist/worker-utils/lib/worker-farm/worker-thread.js.map +0 -1
- package/src/polyfills/images/encode-image.node.ts.disabled +0 -41
- package/src/polyfills/images/parse-image.node.ts.disabled +0 -55
- package/src/worker-utils/lib/async-queue/async-queue.ts +0 -100
- package/src/worker-utils/lib/worker-farm/worker-body.ts +0 -145
- package/src/worker-utils/lib/worker-farm/worker-farm.ts +0 -144
- package/src/worker-utils/lib/worker-farm/worker-job.ts +0 -85
- package/src/worker-utils/lib/worker-farm/worker-pool.ts +0 -316
- package/src/worker-utils/lib/worker-farm/worker-thread.ts +0 -206
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @param options.type='png' - png, jpg or image/png, image/jpg are valid
|
|
8
|
-
* @param options.dataURI - Whether to include a data URI header
|
|
9
|
-
* @return {*} bytes
|
|
10
|
-
*/
|
|
11
|
-
export declare function encodeImageToStreamNode(image: {
|
|
12
|
-
data: any;
|
|
1
|
+
import { PassThrough } from 'node:stream';
|
|
2
|
+
/** Raw RGBA image accepted by the Node encoder. */
|
|
3
|
+
type NodeImageData = {
|
|
4
|
+
/** Interleaved RGBA pixels. */
|
|
5
|
+
data: Uint8Array;
|
|
6
|
+
/** Width in pixels. */
|
|
13
7
|
width: number;
|
|
8
|
+
/** Height in pixels. */
|
|
14
9
|
height: number;
|
|
15
|
-
}
|
|
10
|
+
};
|
|
11
|
+
/** Options for the Node image encoder. */
|
|
12
|
+
type NodeImageEncoderOptions = {
|
|
13
|
+
/** Output format name or MIME type; defaults to JPEG. */
|
|
16
14
|
type?: string;
|
|
15
|
+
/** Legacy option retained for callers. */
|
|
17
16
|
dataURI?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
17
|
+
};
|
|
18
|
+
/** Encodes raw RGBA pixels with the optional Sharp backend. */
|
|
19
|
+
export declare function encodeImageNode(image: NodeImageData, options?: NodeImageEncoderOptions): Promise<ArrayBuffer>;
|
|
20
|
+
/** Streams an encoded image and forwards codec loading and encoding failures. */
|
|
21
|
+
export declare function encodeImageToStreamNode(image: NodeImageData, options?: NodeImageEncoderOptions): PassThrough;
|
|
22
|
+
export {};
|
|
20
23
|
//# sourceMappingURL=encode-image-node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode-image-node.d.ts","sourceRoot":"","sources":["../../../src/polyfills/images/encode-image-node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encode-image-node.d.ts","sourceRoot":"","sources":["../../../src/polyfills/images/encode-image-node.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAC;AAIxC,mDAAmD;AACnD,KAAK,aAAa,GAAG;IACnB,+BAA+B;IAC/B,IAAI,EAAE,UAAU,CAAC;IACjB,uBAAuB;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,0CAA0C;AAC1C,KAAK,uBAAuB,GAAG;IAC7B,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,+DAA+D;AAC/D,wBAAsB,eAAe,CACnC,KAAK,EAAE,aAAa,EACpB,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,WAAW,CAAC,CAUtB;AAED,iFAAiF;AACjF,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,aAAa,EACpB,OAAO,GAAE,uBAA4B,GACpC,WAAW,CAOb"}
|
|
@@ -1,37 +1,23 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
1
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*/
|
|
18
|
-
export function encodeImageToStreamNode(image, options) {
|
|
19
|
-
// Support MIME type strings
|
|
20
|
-
const type = options.type ? options.type.replace('image/', '') : 'jpeg';
|
|
21
|
-
const pixels = ndarray(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);
|
|
22
|
-
// Note: savePixels returns a stream
|
|
23
|
-
return savePixels(pixels, type, options);
|
|
2
|
+
import { PassThrough } from 'node:stream';
|
|
3
|
+
import { loadSharp } from "./load-sharp.js";
|
|
4
|
+
import { toArrayBuffer } from "../utils/buffer-utils.js";
|
|
5
|
+
/** Encodes raw RGBA pixels with the optional Sharp backend. */
|
|
6
|
+
export async function encodeImageNode(image, options = {}) {
|
|
7
|
+
const sharp = await loadSharp();
|
|
8
|
+
const requestedFormat = (options.type || 'jpeg').toLowerCase().replace(/^image\//, '');
|
|
9
|
+
const format = requestedFormat === 'jpg' ? 'jpeg' : requestedFormat;
|
|
10
|
+
const encodedImage = await sharp(Buffer.from(image.data), {
|
|
11
|
+
raw: { width: image.width, height: image.height, channels: 4 }
|
|
12
|
+
})
|
|
13
|
+
.toFormat(format)
|
|
14
|
+
.toBuffer();
|
|
15
|
+
return toArrayBuffer(encodedImage);
|
|
24
16
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// TODO - convert to arraybuffer?
|
|
31
|
-
imageStream.on('end', () => {
|
|
32
|
-
const buffer = Buffer.concat(buffers);
|
|
33
|
-
resolve(bufferToArrayBuffer(buffer));
|
|
34
|
-
});
|
|
35
|
-
});
|
|
17
|
+
/** Streams an encoded image and forwards codec loading and encoding failures. */
|
|
18
|
+
export function encodeImageToStreamNode(image, options = {}) {
|
|
19
|
+
const stream = new PassThrough();
|
|
20
|
+
void encodeImageNode(image, options).then(arrayBuffer => stream.end(Buffer.from(arrayBuffer)), error => stream.destroy(error));
|
|
21
|
+
return stream;
|
|
36
22
|
}
|
|
37
23
|
//# sourceMappingURL=encode-image-node.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode-image-node.js","sourceRoot":"","sources":["../../../src/polyfills/images/encode-image-node.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"encode-image-node.js","sourceRoot":"","sources":["../../../src/polyfills/images/encode-image-node.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,EAAC,SAAS,EAAC,wBAAqB;AACvC,OAAO,EAAC,aAAa,EAAC,iCAA8B;AAoBpD,+DAA+D;AAC/D,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,KAAoB,EACpB,UAAmC,EAAE;IAErC,MAAM,KAAK,GAAG,MAAM,SAAS,EAAE,CAAC;IAChC,MAAM,eAAe,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACvF,MAAM,MAAM,GAAG,eAAe,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC;IACpE,MAAM,YAAY,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;QACxD,GAAG,EAAE,EAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAC;KAC7D,CAAC;SACC,QAAQ,CAAC,MAA0C,CAAC;SACpD,QAAQ,EAAE,CAAC;IACd,OAAO,aAAa,CAAC,YAAY,CAAC,CAAC;AACrC,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,uBAAuB,CACrC,KAAoB,EACpB,UAAmC,EAAE;IAErC,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;IACjC,KAAK,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CACvC,WAAW,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,EACnD,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAC/B,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { parseImageNode } from "./parse-image-node.js";
|
|
2
|
+
export { encodeImageNode } from "./encode-image-node.js";
|
|
3
3
|
export { NODE_FORMAT_SUPPORT } from "./node-image-formats.js";
|
|
4
|
-
/** Loads the optional image decoder only when pixel decoding is requested. */
|
|
5
|
-
export declare function parseImageNode(...parameters: Parameters<typeof parseImageImplementation>): Promise<Awaited<ReturnType<typeof parseImageImplementation>>>;
|
|
6
|
-
/** Loads the optional image encoder only when image encoding is requested. */
|
|
7
|
-
export declare function encodeImageNode(...parameters: Parameters<typeof encodeImageImplementation>): Promise<Awaited<ReturnType<typeof encodeImageImplementation>>>;
|
|
8
4
|
//# sourceMappingURL=image-codecs-node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-codecs-node.d.ts","sourceRoot":"","sources":["../../../src/polyfills/images/image-codecs-node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"image-codecs-node.d.ts","sourceRoot":"","sources":["../../../src/polyfills/images/image-codecs-node.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAC,8BAA2B;AAClD,OAAO,EAAC,eAAe,EAAC,+BAA4B;AACpD,OAAO,EAAC,mBAAmB,EAAC,gCAA6B"}
|
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
1
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
2
|
+
export { parseImageNode } from "./parse-image-node.js";
|
|
3
|
+
export { encodeImageNode } from "./encode-image-node.js";
|
|
4
4
|
export { NODE_FORMAT_SUPPORT } from "./node-image-formats.js";
|
|
5
|
-
/** Loads the optional image decoder only when pixel decoding is requested. */
|
|
6
|
-
export async function parseImageNode(...parameters) {
|
|
7
|
-
let decoder;
|
|
8
|
-
try {
|
|
9
|
-
decoder = await import("./parse-image-node.js");
|
|
10
|
-
}
|
|
11
|
-
catch (error) {
|
|
12
|
-
throw new Error('Node image decoding requires get-pixels. Install get-pixels to decode images.', { cause: error });
|
|
13
|
-
}
|
|
14
|
-
return decoder.parseImageNode(...parameters);
|
|
15
|
-
}
|
|
16
|
-
/** Loads the optional image encoder only when image encoding is requested. */
|
|
17
|
-
export async function encodeImageNode(...parameters) {
|
|
18
|
-
let encoder;
|
|
19
|
-
try {
|
|
20
|
-
encoder = await import("./encode-image-node.js");
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
throw new Error('Node image encoding requires save-pixels and ndarray. Install save-pixels and ndarray to encode images.', { cause: error });
|
|
24
|
-
}
|
|
25
|
-
return encoder.encodeImageNode(...parameters);
|
|
26
|
-
}
|
|
27
5
|
//# sourceMappingURL=image-codecs-node.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-codecs-node.js","sourceRoot":"","sources":["../../../src/polyfills/images/image-codecs-node.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"image-codecs-node.js","sourceRoot":"","sources":["../../../src/polyfills/images/image-codecs-node.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,OAAO,EAAC,cAAc,EAAC,8BAA2B;AAClD,OAAO,EAAC,eAAe,EAAC,+BAA4B;AACpD,OAAO,EAAC,mBAAmB,EAAC,gCAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-sharp.d.ts","sourceRoot":"","sources":["../../../src/polyfills/images/load-sharp.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,wBAAsB,SAAS,IAAI,OAAO,CAAC,cAAc,OAAO,EAAE,OAAO,CAAC,CASzE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/** Loads the optional Node image codec only when image processing is requested. */
|
|
3
|
+
export async function loadSharp() {
|
|
4
|
+
try {
|
|
5
|
+
return (await import('sharp')).default;
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
throw new Error("Node image decoding and encoding require the optional 'sharp' package. Install it with 'npm install sharp'.", { cause: error });
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=load-sharp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-sharp.js","sourceRoot":"","sources":["../../../src/polyfills/images/load-sharp.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,mFAAmF;AACnF,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;IACzC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,6GAA6G,EAC7G,EAAC,KAAK,EAAE,KAAK,EAAC,CACf,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -5,7 +5,7 @@ type NodeImageData = {
|
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
7
|
* Minimal Node.js `ImageBitmap` polyfill backed by decoded pixel data.
|
|
8
|
-
* This is intentionally limited to the functionality needed by `
|
|
8
|
+
* This is intentionally limited to the functionality needed by `ImageLoader`
|
|
9
9
|
* and `getImageBitmapData()`.
|
|
10
10
|
*/
|
|
11
11
|
export declare class NodeImageBitmap {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
/**
|
|
5
5
|
* Minimal Node.js `ImageBitmap` polyfill backed by decoded pixel data.
|
|
6
|
-
* This is intentionally limited to the functionality needed by `
|
|
6
|
+
* This is intentionally limited to the functionality needed by `ImageLoader`
|
|
7
7
|
* and `getImageBitmapData()`.
|
|
8
8
|
*/
|
|
9
9
|
export class NodeImageBitmap {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-image-formats.d.ts","sourceRoot":"","sources":["../../../src/polyfills/images/node-image-formats.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node-image-formats.d.ts","sourceRoot":"","sources":["../../../src/polyfills/images/node-image-formats.ts"],"names":[],"mappings":"AAEA,qEAAqE;AACrE,eAAO,MAAM,mBAAmB,UAQ/B,CAAC"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
1
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
/** Image MIME types supported by the optional Sharp Node backend. */
|
|
3
|
+
export const NODE_FORMAT_SUPPORT = [
|
|
4
|
+
'image/png',
|
|
5
|
+
'image/jpeg',
|
|
6
|
+
'image/gif',
|
|
7
|
+
'image/webp',
|
|
8
|
+
'image/avif',
|
|
9
|
+
'image/tiff',
|
|
10
|
+
'image/svg+xml'
|
|
11
|
+
];
|
|
6
12
|
//# sourceMappingURL=node-image-formats.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-image-formats.js","sourceRoot":"","sources":["../../../src/polyfills/images/node-image-formats.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"node-image-formats.js","sourceRoot":"","sources":["../../../src/polyfills/images/node-image-formats.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,qEAAqE;AACrE,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,WAAW;IACX,YAAY;IACZ,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,eAAe;CAChB,CAAC"}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
export { NODE_FORMAT_SUPPORT } from "./node-image-formats.js";
|
|
2
|
-
|
|
2
|
+
/** Decoded Node image pixels and dimensions. */
|
|
3
|
+
type NodeImageData = {
|
|
4
|
+
/** Pixel layout, including a frame dimension for animations. */
|
|
3
5
|
shape: number[];
|
|
6
|
+
/** Interleaved RGBA pixels. */
|
|
4
7
|
data: Uint8Array;
|
|
8
|
+
/** Frame width in pixels. */
|
|
5
9
|
width: number;
|
|
10
|
+
/** Frame height in pixels. */
|
|
6
11
|
height: number;
|
|
12
|
+
/** Number of components per pixel. */
|
|
7
13
|
components: number;
|
|
14
|
+
/** Number of animation frames. */
|
|
8
15
|
layers: number[];
|
|
9
16
|
};
|
|
10
|
-
|
|
17
|
+
/** Decodes encoded image bytes into RGBA pixels, detecting the format from the bytes. */
|
|
18
|
+
export declare function parseImageNode(arrayBuffer: ArrayBuffer, _mimeType?: string): Promise<NodeImageData>;
|
|
11
19
|
//# sourceMappingURL=parse-image-node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-image-node.d.ts","sourceRoot":"","sources":["../../../src/polyfills/images/parse-image-node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-image-node.d.ts","sourceRoot":"","sources":["../../../src/polyfills/images/parse-image-node.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,mBAAmB,EAAC,gCAA6B;AAEzD,gDAAgD;AAChD,KAAK,aAAa,GAAG;IACnB,gEAAgE;IAChE,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,+BAA+B;IAC/B,IAAI,EAAE,UAAU,CAAC;IACjB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF,yFAAyF;AACzF,wBAAsB,cAAc,CAClC,WAAW,EAAE,WAAW,EACxB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC,CAkBxB"}
|
|
@@ -1,36 +1,24 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
1
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
import getPixels from 'get-pixels';
|
|
2
|
+
import { loadSharp } from "./load-sharp.js";
|
|
5
3
|
export { NODE_FORMAT_SUPPORT } from "./node-image-formats.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
resolve({
|
|
26
|
-
shape,
|
|
27
|
-
data,
|
|
28
|
-
width: ndarray.shape[0],
|
|
29
|
-
height: ndarray.shape[1],
|
|
30
|
-
components: ndarray.shape[2],
|
|
31
|
-
// TODO - error
|
|
32
|
-
layers: layers ? [layers] : []
|
|
33
|
-
});
|
|
34
|
-
}));
|
|
4
|
+
/** Decodes encoded image bytes into RGBA pixels, detecting the format from the bytes. */
|
|
5
|
+
export async function parseImageNode(arrayBuffer, _mimeType) {
|
|
6
|
+
const sharp = await loadSharp();
|
|
7
|
+
const { data, info: imageInformation } = await sharp(Buffer.from(arrayBuffer), { animated: true })
|
|
8
|
+
.toColourspace('srgb')
|
|
9
|
+
.ensureAlpha()
|
|
10
|
+
.raw()
|
|
11
|
+
.toBuffer({ resolveWithObject: true });
|
|
12
|
+
const width = imageInformation.width;
|
|
13
|
+
const height = imageInformation.pageHeight || imageInformation.height;
|
|
14
|
+
const frameCount = imageInformation.pages || 1;
|
|
15
|
+
return {
|
|
16
|
+
shape: frameCount > 1 ? [frameCount, width, height, 4] : [width, height, 4],
|
|
17
|
+
data: new Uint8Array(data),
|
|
18
|
+
width,
|
|
19
|
+
height,
|
|
20
|
+
components: 4,
|
|
21
|
+
layers: [frameCount]
|
|
22
|
+
};
|
|
35
23
|
}
|
|
36
24
|
//# sourceMappingURL=parse-image-node.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-image-node.js","sourceRoot":"","sources":["../../../src/polyfills/images/parse-image-node.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"parse-image-node.js","sourceRoot":"","sources":["../../../src/polyfills/images/parse-image-node.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,OAAO,EAAC,SAAS,EAAC,wBAAqB;AAEvC,OAAO,EAAC,mBAAmB,EAAC,gCAA6B;AAkBzD,yFAAyF;AACzF,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,WAAwB,EACxB,SAAkB;IAElB,MAAM,KAAK,GAAG,MAAM,SAAS,EAAE,CAAC;IAChC,MAAM,EAAC,IAAI,EAAE,IAAI,EAAE,gBAAgB,EAAC,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;SAC3F,aAAa,CAAC,MAAM,CAAC;SACrB,WAAW,EAAE;SACb,GAAG,EAAE;SACL,QAAQ,CAAC,EAAC,iBAAiB,EAAE,IAAI,EAAC,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC;IACrC,MAAM,MAAM,GAAG,gBAAgB,CAAC,UAAU,IAAI,gBAAgB,CAAC,MAAM,CAAC;IACtE,MAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,IAAI,CAAC,CAAC;IAC/C,OAAO;QACL,KAAK,EAAE,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAC3E,IAAI,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC;QAC1B,KAAK;QACL,MAAM;QACN,UAAU,EAAE,CAAC;QACb,MAAM,EAAE,CAAC,UAAU,CAAC;KACrB,CAAC;AACJ,CAAC"}
|
package/dist/polyfills/index.cjs
CHANGED
|
@@ -5,14 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __esm = (fn, res, err) => function __init() {
|
|
9
|
-
if (err) throw err[0];
|
|
10
|
-
try {
|
|
11
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
12
|
-
} catch (e) {
|
|
13
|
-
throw err = [e], e;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
8
|
var __export = (target, all) => {
|
|
17
9
|
for (var name in all)
|
|
18
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -35,105 +27,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
35
27
|
));
|
|
36
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
29
|
|
|
38
|
-
// src/polyfills/images/node-image-formats.ts
|
|
39
|
-
var NODE_FORMAT_SUPPORT;
|
|
40
|
-
var init_node_image_formats = __esm({
|
|
41
|
-
"src/polyfills/images/node-image-formats.ts"() {
|
|
42
|
-
"use strict";
|
|
43
|
-
NODE_FORMAT_SUPPORT = ["image/png", "image/jpeg", "image/gif"];
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// src/polyfills/images/parse-image-node.ts
|
|
48
|
-
var parse_image_node_exports = {};
|
|
49
|
-
__export(parse_image_node_exports, {
|
|
50
|
-
NODE_FORMAT_SUPPORT: () => NODE_FORMAT_SUPPORT,
|
|
51
|
-
parseImageNode: () => parseImageNode
|
|
52
|
-
});
|
|
53
|
-
async function parseImageNode(arrayBuffer, mimeType) {
|
|
54
|
-
if (!mimeType) {
|
|
55
|
-
throw new Error("MIMEType is required to parse image under Node.js");
|
|
56
|
-
}
|
|
57
|
-
const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);
|
|
58
|
-
const ndarray2 = await getPixelsAsync(buffer, mimeType);
|
|
59
|
-
return ndarray2;
|
|
60
|
-
}
|
|
61
|
-
function getPixelsAsync(buffer, mimeType) {
|
|
62
|
-
return new Promise(
|
|
63
|
-
(resolve) => (0, import_get_pixels.default)(buffer, mimeType, (err, ndarray2) => {
|
|
64
|
-
if (err) {
|
|
65
|
-
throw err;
|
|
66
|
-
}
|
|
67
|
-
const shape = [...ndarray2.shape];
|
|
68
|
-
const layers = ndarray2.shape.length === 4 ? ndarray2.shape.shift() : 1;
|
|
69
|
-
const data = ndarray2.data instanceof Buffer ? new Uint8Array(ndarray2.data) : ndarray2.data;
|
|
70
|
-
resolve({
|
|
71
|
-
shape,
|
|
72
|
-
data,
|
|
73
|
-
width: ndarray2.shape[0],
|
|
74
|
-
height: ndarray2.shape[1],
|
|
75
|
-
components: ndarray2.shape[2],
|
|
76
|
-
// TODO - error
|
|
77
|
-
layers: layers ? [layers] : []
|
|
78
|
-
});
|
|
79
|
-
})
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
var import_get_pixels;
|
|
83
|
-
var init_parse_image_node = __esm({
|
|
84
|
-
"src/polyfills/images/parse-image-node.ts"() {
|
|
85
|
-
"use strict";
|
|
86
|
-
import_get_pixels = __toESM(require("get-pixels"), 1);
|
|
87
|
-
init_node_image_formats();
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// src/polyfills/buffer/to-array-buffer.node.ts
|
|
92
|
-
function bufferToArrayBuffer(buffer) {
|
|
93
|
-
if (Buffer.isBuffer(buffer)) {
|
|
94
|
-
const typedArray = new Uint8Array(buffer);
|
|
95
|
-
return typedArray.buffer;
|
|
96
|
-
}
|
|
97
|
-
return buffer;
|
|
98
|
-
}
|
|
99
|
-
var init_to_array_buffer_node = __esm({
|
|
100
|
-
"src/polyfills/buffer/to-array-buffer.node.ts"() {
|
|
101
|
-
"use strict";
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// src/polyfills/images/encode-image-node.ts
|
|
106
|
-
var encode_image_node_exports = {};
|
|
107
|
-
__export(encode_image_node_exports, {
|
|
108
|
-
encodeImageNode: () => encodeImageNode,
|
|
109
|
-
encodeImageToStreamNode: () => encodeImageToStreamNode
|
|
110
|
-
});
|
|
111
|
-
function encodeImageToStreamNode(image, options) {
|
|
112
|
-
const type = options.type ? options.type.replace("image/", "") : "jpeg";
|
|
113
|
-
const pixels = (0, import_ndarray.default)(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);
|
|
114
|
-
return (0, import_save_pixels.default)(pixels, type, options);
|
|
115
|
-
}
|
|
116
|
-
function encodeImageNode(image, options) {
|
|
117
|
-
const imageStream = encodeImageToStreamNode(image, options);
|
|
118
|
-
return new Promise((resolve) => {
|
|
119
|
-
const buffers = [];
|
|
120
|
-
imageStream.on("data", (buffer) => buffers.push(buffer));
|
|
121
|
-
imageStream.on("end", () => {
|
|
122
|
-
const buffer = Buffer.concat(buffers);
|
|
123
|
-
resolve(bufferToArrayBuffer(buffer));
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
var import_save_pixels, import_ndarray;
|
|
128
|
-
var init_encode_image_node = __esm({
|
|
129
|
-
"src/polyfills/images/encode-image-node.ts"() {
|
|
130
|
-
"use strict";
|
|
131
|
-
import_save_pixels = __toESM(require("save-pixels"), 1);
|
|
132
|
-
import_ndarray = __toESM(require("ndarray"), 1);
|
|
133
|
-
init_to_array_buffer_node();
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
|
|
137
30
|
// src/polyfills/index.ts
|
|
138
31
|
var index_exports = {};
|
|
139
32
|
__export(index_exports, {
|
|
@@ -1675,31 +1568,84 @@ function btoa(base64) {
|
|
|
1675
1568
|
return Buffer.from(base64, "base64").toString("ascii");
|
|
1676
1569
|
}
|
|
1677
1570
|
|
|
1678
|
-
// src/polyfills/images/
|
|
1679
|
-
|
|
1680
|
-
async function parseImageNode2(...parameters) {
|
|
1681
|
-
let decoder;
|
|
1571
|
+
// src/polyfills/images/load-sharp.ts
|
|
1572
|
+
async function loadSharp() {
|
|
1682
1573
|
try {
|
|
1683
|
-
|
|
1574
|
+
return (await import("sharp")).default;
|
|
1684
1575
|
} catch (error) {
|
|
1685
1576
|
throw new Error(
|
|
1686
|
-
"Node image decoding
|
|
1577
|
+
"Node image decoding and encoding require the optional 'sharp' package. Install it with 'npm install sharp'.",
|
|
1687
1578
|
{ cause: error }
|
|
1688
1579
|
);
|
|
1689
1580
|
}
|
|
1690
|
-
return decoder.parseImageNode(...parameters);
|
|
1691
1581
|
}
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1582
|
+
|
|
1583
|
+
// src/polyfills/images/node-image-formats.ts
|
|
1584
|
+
var NODE_FORMAT_SUPPORT = [
|
|
1585
|
+
"image/png",
|
|
1586
|
+
"image/jpeg",
|
|
1587
|
+
"image/gif",
|
|
1588
|
+
"image/webp",
|
|
1589
|
+
"image/avif",
|
|
1590
|
+
"image/tiff",
|
|
1591
|
+
"image/svg+xml"
|
|
1592
|
+
];
|
|
1593
|
+
|
|
1594
|
+
// src/polyfills/images/parse-image-node.ts
|
|
1595
|
+
async function parseImageNode(arrayBuffer, _mimeType) {
|
|
1596
|
+
const sharp = await loadSharp();
|
|
1597
|
+
const { data, info: imageInformation } = await sharp(Buffer.from(arrayBuffer), { animated: true }).toColourspace("srgb").ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
1598
|
+
const width = imageInformation.width;
|
|
1599
|
+
const height = imageInformation.pageHeight || imageInformation.height;
|
|
1600
|
+
const frameCount = imageInformation.pages || 1;
|
|
1601
|
+
return {
|
|
1602
|
+
shape: frameCount > 1 ? [frameCount, width, height, 4] : [width, height, 4],
|
|
1603
|
+
data: new Uint8Array(data),
|
|
1604
|
+
width,
|
|
1605
|
+
height,
|
|
1606
|
+
components: 4,
|
|
1607
|
+
layers: [frameCount]
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
// src/polyfills/utils/buffer-utils.ts
|
|
1612
|
+
function toArrayBuffer(data) {
|
|
1613
|
+
if (data instanceof ArrayBuffer) {
|
|
1614
|
+
return data;
|
|
1701
1615
|
}
|
|
1702
|
-
|
|
1616
|
+
if (ArrayBuffer.isView(data)) {
|
|
1617
|
+
return ensureArrayBuffer(data);
|
|
1618
|
+
}
|
|
1619
|
+
return ensureArrayBuffer(data);
|
|
1620
|
+
}
|
|
1621
|
+
function ensureArrayBuffer(data) {
|
|
1622
|
+
if (data instanceof ArrayBuffer) {
|
|
1623
|
+
return data;
|
|
1624
|
+
}
|
|
1625
|
+
if (ArrayBuffer.isView(data)) {
|
|
1626
|
+
const { buffer, byteOffset, byteLength } = data;
|
|
1627
|
+
if (buffer instanceof ArrayBuffer && byteOffset === 0 && byteLength === buffer.byteLength) {
|
|
1628
|
+
return buffer;
|
|
1629
|
+
}
|
|
1630
|
+
return copyArrayBufferRange(buffer, byteOffset, byteLength);
|
|
1631
|
+
}
|
|
1632
|
+
return copyArrayBufferRange(data);
|
|
1633
|
+
}
|
|
1634
|
+
function copyArrayBufferRange(buffer, offset = 0, length = buffer.byteLength - offset) {
|
|
1635
|
+
const copy = new Uint8Array(length);
|
|
1636
|
+
copy.set(new Uint8Array(buffer, offset, length));
|
|
1637
|
+
return copy.buffer;
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
// src/polyfills/images/encode-image-node.ts
|
|
1641
|
+
async function encodeImageNode(image, options = {}) {
|
|
1642
|
+
const sharp = await loadSharp();
|
|
1643
|
+
const requestedFormat = (options.type || "jpeg").toLowerCase().replace(/^image\//, "");
|
|
1644
|
+
const format = requestedFormat === "jpg" ? "jpeg" : requestedFormat;
|
|
1645
|
+
const encodedImage = await sharp(Buffer.from(image.data), {
|
|
1646
|
+
raw: { width: image.width, height: image.height, channels: 4 }
|
|
1647
|
+
}).toFormat(format).toBuffer();
|
|
1648
|
+
return toArrayBuffer(encodedImage);
|
|
1703
1649
|
}
|
|
1704
1650
|
|
|
1705
1651
|
// src/polyfills/images/node-image-bitmap.ts
|
|
@@ -1892,28 +1838,6 @@ var import_stream = require("stream");
|
|
|
1892
1838
|
|
|
1893
1839
|
// src/polyfills/filesystems/stream-utils.node.ts
|
|
1894
1840
|
var import_zlib = __toESM(require("zlib"), 1);
|
|
1895
|
-
|
|
1896
|
-
// src/polyfills/utils/buffer-utils.ts
|
|
1897
|
-
function ensureArrayBuffer(data) {
|
|
1898
|
-
if (data instanceof ArrayBuffer) {
|
|
1899
|
-
return data;
|
|
1900
|
-
}
|
|
1901
|
-
if (ArrayBuffer.isView(data)) {
|
|
1902
|
-
const { buffer, byteOffset, byteLength } = data;
|
|
1903
|
-
if (buffer instanceof ArrayBuffer && byteOffset === 0 && byteLength === buffer.byteLength) {
|
|
1904
|
-
return buffer;
|
|
1905
|
-
}
|
|
1906
|
-
return copyArrayBufferRange(buffer, byteOffset, byteLength);
|
|
1907
|
-
}
|
|
1908
|
-
return copyArrayBufferRange(data);
|
|
1909
|
-
}
|
|
1910
|
-
function copyArrayBufferRange(buffer, offset = 0, length = buffer.byteLength - offset) {
|
|
1911
|
-
const copy = new Uint8Array(length);
|
|
1912
|
-
copy.set(new Uint8Array(buffer, offset, length));
|
|
1913
|
-
return copy.buffer;
|
|
1914
|
-
}
|
|
1915
|
-
|
|
1916
|
-
// src/polyfills/filesystems/stream-utils.node.ts
|
|
1917
1841
|
function decompressReadStream(readStream, headers) {
|
|
1918
1842
|
switch (headers?.get("content-encoding")) {
|
|
1919
1843
|
case "br":
|
|
@@ -2265,8 +2189,8 @@ if (!("atob" in globalThis) && atob) {
|
|
|
2265
2189
|
if (!("btoa" in globalThis) && btoa) {
|
|
2266
2190
|
globalThis["btoa"] = btoa;
|
|
2267
2191
|
}
|
|
2268
|
-
globalThis.loaders.encodeImageNode =
|
|
2269
|
-
globalThis.loaders.parseImageNode =
|
|
2192
|
+
globalThis.loaders.encodeImageNode = encodeImageNode;
|
|
2193
|
+
globalThis.loaders.parseImageNode = parseImageNode;
|
|
2270
2194
|
globalThis.loaders.imageFormatsNode = NODE_FORMAT_SUPPORT;
|
|
2271
2195
|
globalThis.loaders.createImageBitmapNode = createImageBitmapNode;
|
|
2272
2196
|
globalThis.loaders.getImageBitmapDataNode = getImageBitmapDataNode;
|
|
@@ -2277,7 +2201,7 @@ if (!globalThis.ImageBitmap) {
|
|
|
2277
2201
|
if (!("getImageBitmapData" in globalThis)) {
|
|
2278
2202
|
globalThis.getImageBitmapData = getImageBitmapDataNode;
|
|
2279
2203
|
}
|
|
2280
|
-
globalThis._parseImageNode =
|
|
2204
|
+
globalThis._parseImageNode = parseImageNode;
|
|
2281
2205
|
globalThis._imageFormatsNode = NODE_FORMAT_SUPPORT;
|
|
2282
2206
|
globalThis.loaders.readFileAsArrayBuffer = readFileAsArrayBuffer;
|
|
2283
2207
|
globalThis.loaders.readFileAsText = readFileAsText;
|