@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
|
@@ -85,7 +85,7 @@ export type StrictLoaderOptions = Pick<WorkerOptions, 'signal' | 'onProgress'> &
|
|
|
85
85
|
maxConcurrency?: number;
|
|
86
86
|
/** Number of concurrent workers (per loader) on mobile browsers */
|
|
87
87
|
maxMobileConcurrency?: number;
|
|
88
|
-
/**
|
|
88
|
+
/** @deprecated Task handles close after each atomic call or stream. */
|
|
89
89
|
reuseWorkers?: boolean;
|
|
90
90
|
/** Controls whether worker result transfer prepares standalone ArrayBuffers. */
|
|
91
91
|
workerTransferBufferCopy?: 'none' | 'sliced' | 'all';
|
|
@@ -142,7 +142,7 @@ export type LoaderOptions = Pick<WorkerOptions, 'signal' | 'onProgress'> & {
|
|
|
142
142
|
maxConcurrency?: number;
|
|
143
143
|
/** @deprecated Use options.core.maxMobileConcurrency */
|
|
144
144
|
maxMobileConcurrency?: number;
|
|
145
|
-
/** @deprecated
|
|
145
|
+
/** @deprecated Task handles close after each atomic call or stream. */
|
|
146
146
|
reuseWorkers?: boolean;
|
|
147
147
|
/** @deprecated Use options.core.workerTransferBufferCopy */
|
|
148
148
|
workerTransferBufferCopy?: 'none' | 'sliced' | 'all';
|
package/src/polyfills/README.md
CHANGED
|
@@ -9,8 +9,8 @@ Under Node.js, importing `@loaders.gl/core/polyfills` also installs the minimal
|
|
|
9
9
|
- a global `ImageBitmap` polyfill backed by decoded pixel data
|
|
10
10
|
- a global `getImageBitmapData(image)` helper that unwraps that bitmap back to `{data, width, height}`
|
|
11
11
|
|
|
12
|
-
This image support is intentionally minimal. It is designed for `
|
|
12
|
+
This image support is intentionally minimal. It is designed for `ImageLoader` and parsed-image helpers, not as a full `createImageBitmap()` implementation.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
Node image decoding and encoding require the optional `sharp` peer dependency (`npm install sharp`). Other polyfills work without it, and it is loaded only when an image operation is requested.
|
|
15
15
|
|
|
16
16
|
For documentation please visit the [website](https://loaders.gl).
|
|
@@ -1,45 +1,52 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
1
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
import {PassThrough} from 'node:stream';
|
|
4
|
+
import {loadSharp} from './load-sharp';
|
|
5
|
+
import {toArrayBuffer} from '../utils/buffer-utils';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/** Raw RGBA image accepted by the Node encoder. */
|
|
8
|
+
type NodeImageData = {
|
|
9
|
+
/** Interleaved RGBA pixels. */
|
|
10
|
+
data: Uint8Array;
|
|
11
|
+
/** Width in pixels. */
|
|
12
|
+
width: number;
|
|
13
|
+
/** Height in pixels. */
|
|
14
|
+
height: number;
|
|
15
|
+
};
|
|
10
16
|
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* @param options.dataURI - Whether to include a data URI header
|
|
19
|
-
* @return {*} bytes
|
|
20
|
-
*/
|
|
21
|
-
export function encodeImageToStreamNode(
|
|
22
|
-
image: {data: any; width: number; height: number},
|
|
23
|
-
options: {type?: string; dataURI?: string}
|
|
24
|
-
) {
|
|
25
|
-
// Support MIME type strings
|
|
26
|
-
const type = options.type ? options.type.replace('image/', '') : 'jpeg';
|
|
27
|
-
const pixels = ndarray(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);
|
|
17
|
+
/** Options for the Node image encoder. */
|
|
18
|
+
type NodeImageEncoderOptions = {
|
|
19
|
+
/** Output format name or MIME type; defaults to JPEG. */
|
|
20
|
+
type?: string;
|
|
21
|
+
/** Legacy option retained for callers. */
|
|
22
|
+
dataURI?: string;
|
|
23
|
+
};
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
/** Encodes raw RGBA pixels with the optional Sharp backend. */
|
|
26
|
+
export async function encodeImageNode(
|
|
27
|
+
image: NodeImageData,
|
|
28
|
+
options: NodeImageEncoderOptions = {}
|
|
29
|
+
): Promise<ArrayBuffer> {
|
|
30
|
+
const sharp = await loadSharp();
|
|
31
|
+
const requestedFormat = (options.type || 'jpeg').toLowerCase().replace(/^image\//, '');
|
|
32
|
+
const format = requestedFormat === 'jpg' ? 'jpeg' : requestedFormat;
|
|
33
|
+
const encodedImage = await sharp(Buffer.from(image.data), {
|
|
34
|
+
raw: {width: image.width, height: image.height, channels: 4}
|
|
35
|
+
})
|
|
36
|
+
.toFormat(format as keyof import('sharp').FormatEnum)
|
|
37
|
+
.toBuffer();
|
|
38
|
+
return toArrayBuffer(encodedImage);
|
|
31
39
|
}
|
|
32
40
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
41
|
+
/** Streams an encoded image and forwards codec loading and encoding failures. */
|
|
42
|
+
export function encodeImageToStreamNode(
|
|
43
|
+
image: NodeImageData,
|
|
44
|
+
options: NodeImageEncoderOptions = {}
|
|
45
|
+
): PassThrough {
|
|
46
|
+
const stream = new PassThrough();
|
|
47
|
+
void encodeImageNode(image, options).then(
|
|
48
|
+
arrayBuffer => stream.end(Buffer.from(arrayBuffer)),
|
|
49
|
+
error => stream.destroy(error)
|
|
50
|
+
);
|
|
51
|
+
return stream;
|
|
45
52
|
}
|
|
@@ -1,40 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
1
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {parseImageNode as parseImageImplementation} from './parse-image-node';
|
|
6
|
-
import type {encodeImageNode as encodeImageImplementation} from './encode-image-node';
|
|
7
2
|
|
|
3
|
+
export {parseImageNode} from './parse-image-node';
|
|
4
|
+
export {encodeImageNode} from './encode-image-node';
|
|
8
5
|
export {NODE_FORMAT_SUPPORT} from './node-image-formats';
|
|
9
|
-
|
|
10
|
-
/** Loads the optional image decoder only when pixel decoding is requested. */
|
|
11
|
-
export async function parseImageNode(
|
|
12
|
-
...parameters: Parameters<typeof parseImageImplementation>
|
|
13
|
-
): Promise<Awaited<ReturnType<typeof parseImageImplementation>>> {
|
|
14
|
-
let decoder: typeof import('./parse-image-node');
|
|
15
|
-
try {
|
|
16
|
-
decoder = await import('./parse-image-node');
|
|
17
|
-
} catch (error) {
|
|
18
|
-
throw new Error(
|
|
19
|
-
'Node image decoding requires get-pixels. Install get-pixels to decode images.',
|
|
20
|
-
{cause: error}
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
return decoder.parseImageNode(...parameters);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Loads the optional image encoder only when image encoding is requested. */
|
|
27
|
-
export async function encodeImageNode(
|
|
28
|
-
...parameters: Parameters<typeof encodeImageImplementation>
|
|
29
|
-
): Promise<Awaited<ReturnType<typeof encodeImageImplementation>>> {
|
|
30
|
-
let encoder: typeof import('./encode-image-node');
|
|
31
|
-
try {
|
|
32
|
-
encoder = await import('./encode-image-node');
|
|
33
|
-
} catch (error) {
|
|
34
|
-
throw new Error(
|
|
35
|
-
'Node image encoding requires save-pixels and ndarray. Install save-pixels and ndarray to encode images.',
|
|
36
|
-
{cause: error}
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
return encoder.encodeImageNode(...parameters);
|
|
40
|
-
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
/** Loads the optional Node image codec only when image processing is requested. */
|
|
4
|
+
export async function loadSharp(): Promise<typeof import('sharp').default> {
|
|
5
|
+
try {
|
|
6
|
+
return (await import('sharp')).default;
|
|
7
|
+
} catch (error) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"Node image decoding and encoding require the optional 'sharp' package. Install it with 'npm install sharp'.",
|
|
10
|
+
{cause: error}
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -10,7 +10,7 @@ type NodeImageData = {
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Minimal Node.js `ImageBitmap` polyfill backed by decoded pixel data.
|
|
13
|
-
* This is intentionally limited to the functionality needed by `
|
|
13
|
+
* This is intentionally limited to the functionality needed by `ImageLoader`
|
|
14
14
|
* and `getImageBitmapData()`.
|
|
15
15
|
*/
|
|
16
16
|
export class NodeImageBitmap {
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
1
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
2
|
|
|
5
|
-
/** Image MIME types supported
|
|
6
|
-
export const NODE_FORMAT_SUPPORT = [
|
|
3
|
+
/** Image MIME types supported by the optional Sharp Node backend. */
|
|
4
|
+
export const NODE_FORMAT_SUPPORT = [
|
|
5
|
+
'image/png',
|
|
6
|
+
'image/jpeg',
|
|
7
|
+
'image/gif',
|
|
8
|
+
'image/webp',
|
|
9
|
+
'image/avif',
|
|
10
|
+
'image/tiff',
|
|
11
|
+
'image/svg+xml'
|
|
12
|
+
];
|
|
@@ -1,54 +1,45 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
1
|
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
2
|
|
|
5
|
-
import
|
|
3
|
+
import {loadSharp} from './load-sharp';
|
|
6
4
|
|
|
7
5
|
export {NODE_FORMAT_SUPPORT} from './node-image-formats';
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
type
|
|
7
|
+
/** Decoded Node image pixels and dimensions. */
|
|
8
|
+
type NodeImageData = {
|
|
9
|
+
/** Pixel layout, including a frame dimension for animations. */
|
|
11
10
|
shape: number[];
|
|
11
|
+
/** Interleaved RGBA pixels. */
|
|
12
12
|
data: Uint8Array;
|
|
13
|
+
/** Frame width in pixels. */
|
|
13
14
|
width: number;
|
|
15
|
+
/** Frame height in pixels. */
|
|
14
16
|
height: number;
|
|
17
|
+
/** Number of components per pixel. */
|
|
15
18
|
components: number;
|
|
19
|
+
/** Number of animation frames. */
|
|
16
20
|
layers: number[];
|
|
17
21
|
};
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// extract width/height etc
|
|
43
|
-
resolve({
|
|
44
|
-
shape,
|
|
45
|
-
data,
|
|
46
|
-
width: ndarray.shape[0],
|
|
47
|
-
height: ndarray.shape[1],
|
|
48
|
-
components: ndarray.shape[2],
|
|
49
|
-
// TODO - error
|
|
50
|
-
layers: layers ? [layers] : []
|
|
51
|
-
});
|
|
52
|
-
})
|
|
53
|
-
);
|
|
23
|
+
/** Decodes encoded image bytes into RGBA pixels, detecting the format from the bytes. */
|
|
24
|
+
export async function parseImageNode(
|
|
25
|
+
arrayBuffer: ArrayBuffer,
|
|
26
|
+
_mimeType?: string
|
|
27
|
+
): Promise<NodeImageData> {
|
|
28
|
+
const sharp = await loadSharp();
|
|
29
|
+
const {data, info: imageInformation} = await sharp(Buffer.from(arrayBuffer), {animated: true})
|
|
30
|
+
.toColourspace('srgb')
|
|
31
|
+
.ensureAlpha()
|
|
32
|
+
.raw()
|
|
33
|
+
.toBuffer({resolveWithObject: true});
|
|
34
|
+
const width = imageInformation.width;
|
|
35
|
+
const height = imageInformation.pageHeight || imageInformation.height;
|
|
36
|
+
const frameCount = imageInformation.pages || 1;
|
|
37
|
+
return {
|
|
38
|
+
shape: frameCount > 1 ? [frameCount, width, height, 4] : [width, height, 4],
|
|
39
|
+
data: new Uint8Array(data),
|
|
40
|
+
width,
|
|
41
|
+
height,
|
|
42
|
+
components: 4,
|
|
43
|
+
layers: [frameCount]
|
|
44
|
+
};
|
|
54
45
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './scan/vector-table-scan-source.js';
|
|
@@ -14,26 +14,28 @@ export type {
|
|
|
14
14
|
WorkerContext,
|
|
15
15
|
WorkerJobContext,
|
|
16
16
|
Process,
|
|
17
|
-
ProcessInBatches
|
|
18
|
-
// Protocol
|
|
19
|
-
WorkerMessage,
|
|
20
|
-
WorkerMessageType,
|
|
21
|
-
WorkerMessageData,
|
|
22
|
-
WorkerMessagePayload
|
|
17
|
+
ProcessInBatches
|
|
23
18
|
} from './types';
|
|
24
19
|
|
|
25
20
|
// GENERAL UTILS
|
|
26
21
|
export {assert} from './lib/env-utils/assert';
|
|
27
22
|
export {isBrowser, isWorker} from './lib/env-utils/globals';
|
|
28
23
|
|
|
29
|
-
//
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
// Public task lifecycle and typed task definitions.
|
|
25
|
+
export {TaskRunner, preloadTasks, createTypedTaskDispatcher} from '@math.gl/core/tasks';
|
|
26
|
+
export {initializeTaskWorker} from './lib/worker-api/task-runtime';
|
|
27
|
+
export type {
|
|
28
|
+
Task,
|
|
29
|
+
TaskTypes,
|
|
30
|
+
TaskContext,
|
|
31
|
+
TaskRunControls,
|
|
32
|
+
TaskInitializationControls,
|
|
33
|
+
TaskOperation,
|
|
34
|
+
TaskOperationRequest,
|
|
35
|
+
TaskOperationResult,
|
|
36
|
+
TypedTaskDispatcher,
|
|
37
|
+
TaskRunnerOptions
|
|
38
|
+
} from '@math.gl/core/tasks';
|
|
37
39
|
|
|
38
40
|
// PROCESS ON WORKER
|
|
39
41
|
export type {ProcessOnWorkerOptions} from './lib/worker-api/process-on-worker';
|
|
@@ -42,6 +44,7 @@ export {
|
|
|
42
44
|
processOnWorker,
|
|
43
45
|
processOnWorkerInBatches,
|
|
44
46
|
preloadWorker,
|
|
47
|
+
destroyWorkerTasks,
|
|
45
48
|
canProcessOnWorker,
|
|
46
49
|
canProcessOnWorkerInBatches
|
|
47
50
|
} from './lib/worker-api/process-on-worker';
|
|
@@ -60,9 +63,6 @@ export {
|
|
|
60
63
|
type LoadLibraryOptions
|
|
61
64
|
} from './lib/library-utils/library-utils';
|
|
62
65
|
|
|
63
|
-
// PARSER UTILS
|
|
64
|
-
export {default as AsyncQueue} from './lib/async-queue/async-queue';
|
|
65
|
-
|
|
66
66
|
// PROCESS UTILS
|
|
67
67
|
export {default as ChildProcessProxy} from './lib/process-utils/child-process-proxy';
|
|
68
68
|
|
|
@@ -2,204 +2,105 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from '
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/** Counter for jobs */
|
|
19
|
-
let requestId = 0;
|
|
20
|
-
let activeInputBatches: AsyncQueue<any> | null = null;
|
|
21
|
-
let activeOutputAcknowledgements: AsyncQueue<void> | null = null;
|
|
22
|
-
|
|
23
|
-
export type ProcessOnMainThread = (
|
|
24
|
-
data: any,
|
|
25
|
-
options?: {[key: string]: any},
|
|
26
|
-
jobContext?: WorkerJobContext
|
|
27
|
-
) => any;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Set up a WebWorkerGlobalScope to talk with the main thread
|
|
31
|
-
*/
|
|
5
|
+
import type {TaskContext} from '@math.gl/core/tasks';
|
|
6
|
+
import type {Process, ProcessInBatches, WorkerContext} from '../../types';
|
|
7
|
+
import {
|
|
8
|
+
initializeTaskWorker,
|
|
9
|
+
isWorkerThread,
|
|
10
|
+
normalizeTaskProgress,
|
|
11
|
+
type WorkerTask,
|
|
12
|
+
type WorkerTaskState
|
|
13
|
+
} from './task-runtime';
|
|
14
|
+
import {getTransferList} from '../worker-utils/get-transfer-list';
|
|
15
|
+
|
|
16
|
+
/** Installs a loader processor using math.gl's public task worker protocol. */
|
|
32
17
|
export async function createWorker(
|
|
33
18
|
process: Process,
|
|
34
19
|
processInBatches?: ProcessInBatches
|
|
35
20
|
): Promise<void> {
|
|
36
|
-
if (!(await
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const context: WorkerContext = {
|
|
41
|
-
process: processOnMainThread
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// eslint-disable-next-line complexity
|
|
45
|
-
WorkerBody.onmessage = async (type: WorkerMessageType, payload: WorkerMessagePayload) => {
|
|
46
|
-
const reporter =
|
|
47
|
-
type === 'process' || type === 'process-in-batches' ? createProgressReporter() : undefined;
|
|
48
|
-
const jobContext = {...context, reportProgress: reporter?.report};
|
|
49
|
-
try {
|
|
50
|
-
switch (type) {
|
|
51
|
-
case 'preload':
|
|
52
|
-
WorkerBody.postMessage('done', {});
|
|
53
|
-
break;
|
|
54
|
-
|
|
55
|
-
case 'process':
|
|
56
|
-
if (!process) {
|
|
57
|
-
throw new Error('Worker does not support atomic processing');
|
|
58
|
-
}
|
|
59
|
-
const result = await process(
|
|
60
|
-
payload.input,
|
|
61
|
-
payload.options || {},
|
|
62
|
-
jobContext,
|
|
63
|
-
payload.context || {}
|
|
64
|
-
);
|
|
65
|
-
reporter?.finish();
|
|
66
|
-
WorkerBody.postMessage('done', {result});
|
|
67
|
-
break;
|
|
21
|
+
if (!(await isWorkerThread())) return;
|
|
22
|
+
await initializeTaskWorker(createWorkerTask(process, processInBatches));
|
|
23
|
+
}
|
|
68
24
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
25
|
+
/** @internal Builds the loader adapter independently of worker installation. */
|
|
26
|
+
export function createWorkerTask(
|
|
27
|
+
process: Process,
|
|
28
|
+
processInBatches?: ProcessInBatches
|
|
29
|
+
): WorkerTask {
|
|
30
|
+
return {
|
|
31
|
+
id: 'loaders.gl',
|
|
32
|
+
initialize: state => state,
|
|
33
|
+
destroy: state => state.port?.close(),
|
|
34
|
+
process: async ({value}, options, context) => {
|
|
35
|
+
if (!process) throw new Error('Worker does not support atomic processing');
|
|
36
|
+
return {value: await process(value, options, createContext(context), context.state.context)};
|
|
37
|
+
},
|
|
38
|
+
...(processInBatches
|
|
39
|
+
? ({
|
|
40
|
+
processInBatches: async function* (inputs, options, context) {
|
|
41
|
+
/** Unwraps task records while preserving upstream demand and backpressure. */
|
|
42
|
+
async function* values() {
|
|
43
|
+
for await (const input of inputs) yield input.value;
|
|
44
|
+
}
|
|
45
|
+
for await (const value of processInBatches(
|
|
46
|
+
values(),
|
|
47
|
+
options,
|
|
48
|
+
createContext(context),
|
|
49
|
+
context.state.context
|
|
50
|
+
)) {
|
|
51
|
+
yield {value};
|
|
87
52
|
}
|
|
88
|
-
reporter?.finish();
|
|
89
|
-
await WorkerBody.postMessage('done', {});
|
|
90
|
-
} finally {
|
|
91
|
-
activeInputBatches = null;
|
|
92
|
-
activeOutputAcknowledgements = null;
|
|
93
|
-
}
|
|
94
|
-
break;
|
|
95
|
-
|
|
96
|
-
case 'input-batch':
|
|
97
|
-
if (!activeInputBatches) {
|
|
98
|
-
throw new Error('Worker has no active batched processing session');
|
|
99
|
-
}
|
|
100
|
-
activeInputBatches.push(payload.input);
|
|
101
|
-
break;
|
|
102
|
-
|
|
103
|
-
case 'input-done':
|
|
104
|
-
if (!activeInputBatches) {
|
|
105
|
-
throw new Error('Worker has no active batched processing session');
|
|
106
|
-
}
|
|
107
|
-
activeInputBatches.close();
|
|
108
|
-
break;
|
|
109
|
-
|
|
110
|
-
case 'output-ack':
|
|
111
|
-
if (!activeOutputAcknowledgements) {
|
|
112
|
-
throw new Error('Worker has no active batched processing session');
|
|
113
53
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
default:
|
|
118
|
-
}
|
|
119
|
-
} catch (error) {
|
|
120
|
-
reporter?.finish();
|
|
121
|
-
const message = error instanceof Error ? error.message : '';
|
|
122
|
-
WorkerBody.postMessage('error', {error: message});
|
|
123
|
-
}
|
|
54
|
+
} satisfies Partial<WorkerTask>)
|
|
55
|
+
: {})
|
|
124
56
|
};
|
|
125
57
|
}
|
|
126
58
|
|
|
127
|
-
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const nextBatch = await inputBatches.next();
|
|
132
|
-
if (nextBatch.done) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
yield nextBatch.value;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function processOnMainThread(arrayBuffer: ArrayBuffer, options = {}, jobContext = {}) {
|
|
140
|
-
return new Promise((resolve, reject) => {
|
|
141
|
-
const id = requestId++;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
*/
|
|
145
|
-
const onMessage = (type: string, payload: WorkerMessagePayload) => {
|
|
146
|
-
if (payload.id !== id) {
|
|
147
|
-
// not ours
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
switch (type) {
|
|
152
|
-
case 'done':
|
|
153
|
-
WorkerBody.removeEventListener(onMessage);
|
|
154
|
-
resolve(payload.result);
|
|
155
|
-
break;
|
|
156
|
-
|
|
157
|
-
case 'error':
|
|
158
|
-
WorkerBody.removeEventListener(onMessage);
|
|
159
|
-
reject(payload.error);
|
|
160
|
-
break;
|
|
161
|
-
|
|
162
|
-
default:
|
|
163
|
-
// ignore
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
WorkerBody.addEventListener(onMessage);
|
|
168
|
-
|
|
169
|
-
// Ask the main thread to decode data
|
|
170
|
-
const payload = {id, input: arrayBuffer, options, context: jobContext};
|
|
171
|
-
WorkerBody.postMessage('process', payload);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** Coalesces same-phase reports per event-loop turn and flushes before settlement. */
|
|
176
|
-
function createProgressReporter() {
|
|
177
|
-
let pending: WorkerProgress | undefined;
|
|
178
|
-
let finished = false;
|
|
179
|
-
let scheduled = false;
|
|
180
|
-
/** Posts the latest pending measurement. */
|
|
181
|
-
const flush = (): void => {
|
|
182
|
-
scheduled = false;
|
|
183
|
-
if (pending) {
|
|
184
|
-
WorkerBody.postMessage('progress', {progress: pending});
|
|
185
|
-
pending = undefined;
|
|
186
|
-
}
|
|
187
|
-
};
|
|
59
|
+
/** Adds loader labels and optional calling-thread requests to the task context. */
|
|
60
|
+
function createContext(context: TaskContext<WorkerTaskState>): WorkerContext {
|
|
61
|
+
let requestIdentifier = 0;
|
|
62
|
+
const port = context.state.port;
|
|
188
63
|
return {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
64
|
+
signal: context.signal,
|
|
65
|
+
throwIfAborted: () => context.throwIfAborted(),
|
|
66
|
+
reportProgress: progress => context.reportProgress(normalizeTaskProgress(progress)),
|
|
67
|
+
process: port
|
|
68
|
+
? (input, options = {}, jobContext = {}) => {
|
|
69
|
+
context.throwIfAborted();
|
|
70
|
+
const identifier = ++requestIdentifier;
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
/** Settles only the matching response on this handle's private channel. */
|
|
73
|
+
const onMessage = (event: MessageEvent) => {
|
|
74
|
+
if (event.data.identifier !== identifier) return;
|
|
75
|
+
cleanup();
|
|
76
|
+
if (event.data.error) {
|
|
77
|
+
const error = new Error(event.data.error.message);
|
|
78
|
+
error.name = event.data.error.name;
|
|
79
|
+
reject(error);
|
|
80
|
+
} else resolve(event.data.value);
|
|
81
|
+
};
|
|
82
|
+
/** Stops waiting if this task is cancelled. */
|
|
83
|
+
const onAbort = () => {
|
|
84
|
+
cleanup();
|
|
85
|
+
reject(context.signal.reason);
|
|
86
|
+
};
|
|
87
|
+
/** Removes per-request listeners on completion or cancellation. */
|
|
88
|
+
const cleanup = () => {
|
|
89
|
+
port.removeEventListener('message', onMessage);
|
|
90
|
+
context.signal.removeEventListener('abort', onAbort);
|
|
91
|
+
};
|
|
92
|
+
port.addEventListener('message', onMessage);
|
|
93
|
+
context.signal.addEventListener('abort', onAbort, {once: true});
|
|
94
|
+
port.start();
|
|
95
|
+
try {
|
|
96
|
+
const request = {identifier, input, options, context: jobContext};
|
|
97
|
+
port.postMessage(request, getTransferList(request));
|
|
98
|
+
} catch (error) {
|
|
99
|
+
cleanup();
|
|
100
|
+
reject(error);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
: undefined
|
|
204
105
|
};
|
|
205
106
|
}
|