agglomerative-clustering 3.7.2 → 4.0.0-beta.1
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 +9 -8
- package/dist/choose.cjs +166 -0
- package/dist/choose.mjs +160 -0
- package/dist/clustering.cjs +1 -1
- package/dist/clustering.js +1 -1
- package/dist/clustering.wasm +0 -0
- package/dist/index.cjs +103 -64
- package/dist/index.d.cts +80 -19
- package/dist/index.d.ts +80 -19
- package/dist/index.mjs +102 -63
- package/dist/shared.cjs +129 -5
- package/dist/shared.mjs +123 -3
- package/dist/worker-thread.mjs +13 -2
- package/dist/worker.cjs +183 -64
- package/dist/worker.d.cts +51 -8
- package/dist/worker.d.ts +51 -8
- package/dist/worker.mjs +184 -65
- package/package.json +2 -2
package/dist/worker.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// handle, so re-cutting and re-mapping it copies nothing across. The functions exported directly use one shared
|
|
5
5
|
// worker, started on first use.
|
|
6
6
|
|
|
7
|
-
import { fail, isCodedError, detachedError, isOptionsObject, snapshot, parseDither, mark, revive, latestVersion, imageHint, isDetached, imageDataLike, isImageData, checkImageDataPixels, maxBytes, tooLarge, bareImageWarning, warnOnce } from "./shared.mjs";
|
|
7
|
+
import { fail, isCodedError, detachedError, isOptionsObject, isUint8Array, isUint8ClampedArray, snapshot, parseDither, mark, revive, latestVersion, imageHint, isDetached, imageDataLike, isImageData, checkImageDataPixels, maxBytes, tooLarge, bareImageWarning, warnOnce, readHeader, checkImageObject } from "./shared.mjs";
|
|
8
8
|
|
|
9
9
|
// The same version, types and data-format version as the main entry (one implementation, in shared.js).
|
|
10
10
|
export { version, Palette, Clustering, errorCodes, isCodedError, ditherMethods, ditherSteps, colorSpaces, imageFormats, alphaModes } from "./shared.mjs";
|
|
@@ -138,7 +138,7 @@ const start = async (receive, chosen) => {
|
|
|
138
138
|
// A page with an opaque origin (a sandboxed iframe without allow-same-origin, as plugin hosts such as Figma use) can't
|
|
139
139
|
// start a worker from any http(s) script, nor, in Chromium, from a blob: URL; a data: URL module can, and imports it.
|
|
140
140
|
const opaque = !crossOrigin && isOpaqueOrigin() && webOrigins.includes(script.protocol);
|
|
141
|
-
const scriptHint = "Check that worker-thread.mjs is served (open its URL), with index.mjs, shared.mjs, clustering.js and clustering.wasm next to it, which it imports, or say where your copy of dist/ is with createWorker({ script }) or, for the shared worker, init({ script }).";
|
|
141
|
+
const scriptHint = "Check that worker-thread.mjs is served (open its URL), with index.mjs, shared.mjs, choose.mjs, clustering.js and clustering.wasm next to it, which it imports, or say where your copy of dist/ is with createWorker({ script }) or, for the shared worker, init({ script }).";
|
|
142
142
|
let worker,
|
|
143
143
|
source = null;
|
|
144
144
|
try {
|
|
@@ -199,7 +199,7 @@ const start = async (receive, chosen) => {
|
|
|
199
199
|
// Yarn Plug'n'Play keeps packages in zip archives, which Node reads ES modules from only through Yarn's loader.
|
|
200
200
|
const inZip = error => /\.zip[\\/]/.test(String(error && error.message));
|
|
201
201
|
worker.on('error', error => receive({
|
|
202
|
-
failure: missing(error) ? inZip(error) ? `${String(error.message).split('\n')[0]}. Under Yarn Plug'n'Play the package sits in a zip archive, which a worker thread can load its ES modules from only through Yarn's loader: run the app with yarn node (or node --require ./.pnp.cjs --loader ./.pnp.loader.mjs), or unplug the package (yarn unplug agglomerative-clustering). Otherwise keep dist/ together and say where it is with createWorker({ script }).` : `${String(error.message).split('\n')[0]}. The worker script (worker-thread.mjs) needs index.mjs, shared.mjs, clustering.js and clustering.wasm next to it: keep dist/ together, and say where it is with createWorker({ script }) or, for the shared worker, init({ script }) (a path, or a file: URL). In a serverless deployment (AWS Lambda, Vercel or Netlify functions), the file tracer may have left them out: include node_modules/agglomerative-clustering/dist in the function's files.` : error.message
|
|
202
|
+
failure: missing(error) ? inZip(error) ? `${String(error.message).split('\n')[0]}. Under Yarn Plug'n'Play the package sits in a zip archive, which a worker thread can load its ES modules from only through Yarn's loader: run the app with yarn node (or node --require ./.pnp.cjs --loader ./.pnp.loader.mjs), or unplug the package (yarn unplug agglomerative-clustering). Otherwise keep dist/ together and say where it is with createWorker({ script }).` : `${String(error.message).split('\n')[0]}. The worker script (worker-thread.mjs) needs index.mjs, shared.mjs, choose.mjs, clustering.js and clustering.wasm next to it: keep dist/ together, and say where it is with createWorker({ script }) or, for the shared worker, init({ script }) (a path, or a file: URL). In a serverless deployment (AWS Lambda, Vercel or Netlify functions), the file tracer may have left them out: include node_modules/agglomerative-clustering/dist in the function's files.` : error.message
|
|
203
203
|
}));
|
|
204
204
|
worker.on('exit', code => receive({
|
|
205
205
|
failure: `The worker exited unexpectedly (code ${code}).`
|
|
@@ -275,10 +275,20 @@ const send = image => {
|
|
|
275
275
|
};
|
|
276
276
|
}
|
|
277
277
|
if (image && typeof image === 'object' && !ArrayBuffer.isView(image) && ArrayBuffer.isView(image.data)) {
|
|
278
|
+
// The main entry's checks (shape, unknown keys, premultiplied) run here, in its order, before anything is posted. Data of another
|
|
279
|
+
// type, or no format, goes on as it is for the worker's own error.
|
|
278
280
|
const sent = {
|
|
279
281
|
data: image.data,
|
|
280
282
|
format: image.format
|
|
281
283
|
};
|
|
284
|
+
if (image.format && (isUint8Array(image.data) || isUint8ClampedArray(image.data))) {
|
|
285
|
+
const premultiplied = checkImageObject(image);
|
|
286
|
+
if (image.premultiplied !== undefined) {
|
|
287
|
+
sent.premultiplied = premultiplied;
|
|
288
|
+
}
|
|
289
|
+
} else if (image.premultiplied !== undefined) {
|
|
290
|
+
sent.premultiplied = image.premultiplied;
|
|
291
|
+
}
|
|
282
292
|
if (image.width !== undefined) {
|
|
283
293
|
sent.width = image.width;
|
|
284
294
|
}
|
|
@@ -891,6 +901,152 @@ const makeWorker = (options, allowScript) => {
|
|
|
891
901
|
return invoke('init', checked === undefined || Object.keys(checked).length === 0 ? [] : [checked], [], origin).then(() => undefined);
|
|
892
902
|
};
|
|
893
903
|
|
|
904
|
+
// Whether a value is an image where a palette size was expected (a pixel array, an ImageData or `{data, ...}`).
|
|
905
|
+
const looksLikeImage = value => value !== null && typeof value === 'object' && (isUint8Array(value) || isUint8ClampedArray(value) || isImageData(value) || 'data' in value);
|
|
906
|
+
// Builds the handle object for what the worker keeps under `id`: `kind` is 'image' (from `cluster`: an image and its
|
|
907
|
+
// clustering) or 'clustering' (from `load`: a clustering alone). `output` turns a mapped result back into the type of the image given.
|
|
908
|
+
const makeHandle = (id, kind, output) => {
|
|
909
|
+
let released = false;
|
|
910
|
+
// Every method goes through `use`, which refers to `handle`, so a method kept after the handle itself is dropped
|
|
911
|
+
// keeps it alive and it is not reclaimed while still in use.
|
|
912
|
+
const use = (method, args, controls) => {
|
|
913
|
+
if (released || !handle) {
|
|
914
|
+
return Promise.reject(fail('invalid-handle', "Invalid handle: it was released."));
|
|
915
|
+
}
|
|
916
|
+
return invoke(method, [id, ...args], [], new Error(), controls);
|
|
917
|
+
};
|
|
918
|
+
// Calls with mapping options, whose signal and progress callback stay on this side (see takeControls).
|
|
919
|
+
const withControls = (method, leading, mapOptions) => {
|
|
920
|
+
let taken;
|
|
921
|
+
try {
|
|
922
|
+
taken = takeControls(mapOptions);
|
|
923
|
+
} catch (error) {
|
|
924
|
+
return Promise.reject(error);
|
|
925
|
+
}
|
|
926
|
+
return use(method, [...leading, taken.options], {
|
|
927
|
+
signal: taken.signal,
|
|
928
|
+
onProgress: taken.onProgress
|
|
929
|
+
});
|
|
930
|
+
};
|
|
931
|
+
// The cuts take no options (the handle's clustering already says how it was made): one passed anyway is an error,
|
|
932
|
+
// as in the main entry, rather than silently ignored.
|
|
933
|
+
const plain = (method, name, args, extra) => extra.some(value => value !== undefined) ? Promise.reject(fail('invalid-argument', `Invalid arguments: handle.${name} takes no options. To map pixels with options, use handle.quantize.`, 'options')) : use(method, args);
|
|
934
|
+
// An image where k belongs is a mix-up between the two kinds of handle: say so, rather than "k must be an integer".
|
|
935
|
+
const imageAsK = (name, k) => looksLikeImage(k) ? Promise.reject(fail('invalid-argument', `Invalid k: this handle holds an image (from worker.cluster) and maps it with ${name}(k); pass k, not an image. To map other images with a stored clustering, use worker.load(clustering).`, 'k')) : null;
|
|
936
|
+
const handle = {
|
|
937
|
+
getPalette: (k, ...extra) => plain('handleGetPalette', 'getPalette', [k], extra),
|
|
938
|
+
getSwatches: (k, ...extra) => plain('handleGetSwatches', 'getSwatches', [k], extra),
|
|
939
|
+
getClusteringInfo: (...extra) => plain('handleGetClusteringInfo', 'getClusteringInfo', [], extra),
|
|
940
|
+
// Takes the signal only: the main entry's chooseFrom takes no progress callback, so one given crosses as null for
|
|
941
|
+
// the thread to reject with the main entry's own error.
|
|
942
|
+
// That relies on the thread injecting a progress poster only for calls that have one (see `optionsIndex` in
|
|
943
|
+
// worker-thread.js): the null is then the only onProgress it sees, so its own option check rejects it.
|
|
944
|
+
chooseFrom: (palette, k, chooseOptions) => {
|
|
945
|
+
let taken;
|
|
946
|
+
try {
|
|
947
|
+
taken = takeControls(chooseOptions, false);
|
|
948
|
+
} catch (error) {
|
|
949
|
+
return Promise.reject(error);
|
|
950
|
+
}
|
|
951
|
+
const sent = taken.onProgress !== undefined ? {
|
|
952
|
+
...taken.options,
|
|
953
|
+
onProgress: null
|
|
954
|
+
} : taken.options;
|
|
955
|
+
return use('handleChooseFrom', [palette, k, sent], {
|
|
956
|
+
signal: taken.signal
|
|
957
|
+
});
|
|
958
|
+
},
|
|
959
|
+
release: async () => {
|
|
960
|
+
if (released) {
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
released = true;
|
|
964
|
+
liveHandles--;
|
|
965
|
+
if (reclaim) {
|
|
966
|
+
reclaim.unregister(handle);
|
|
967
|
+
}
|
|
968
|
+
// If the worker has been terminated there is nothing left to free (so `await using` and
|
|
969
|
+
// terminate() can come in either order); any other failure is reported.
|
|
970
|
+
try {
|
|
971
|
+
await invoke('release', [id], [], new Error());
|
|
972
|
+
} catch (error) {
|
|
973
|
+
if (error.code !== 'worker-terminated') {
|
|
974
|
+
throw error;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
stopIfAbandoned();
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
if (kind === 'image') {
|
|
981
|
+
Object.assign(handle, {
|
|
982
|
+
getClustering: (...extra) => plain('handleGetClustering', 'getClustering', [], extra),
|
|
983
|
+
quantize: (k, mapOptions) => imageAsK('quantize', k) || (async () => output(await withControls('handleQuantize', [k], mapOptions)))(),
|
|
984
|
+
quantizeToIndices: (k, mapOptions) => imageAsK('quantizeToIndices', k) || withControls('handleQuantizeToIndices', [k], mapOptions),
|
|
985
|
+
quantizeWithPalette: async (palette, mapOptions) => output(await withControls('handleQuantizeWithPalette', [palette], mapOptions)),
|
|
986
|
+
quantizeToIndicesWithPalette: (palette, mapOptions) => withControls('handleQuantizeToIndicesWithPalette', [palette], mapOptions)
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
if (kind === 'clustering') {
|
|
990
|
+
// The handle holds no image: each call maps the image it is given, and returns the type of that image.
|
|
991
|
+
const mapping = (name, method, mapped) => (image, k, mapOptions) => {
|
|
992
|
+
if (typeof image === 'number') {
|
|
993
|
+
return Promise.reject(fail('invalid-argument', "Invalid image: this handle holds a clustering, not an image (from worker.load); pass the image, then k.", 'image'));
|
|
994
|
+
}
|
|
995
|
+
const origin = new Error();
|
|
996
|
+
return (async () => {
|
|
997
|
+
if (released || !handle) {
|
|
998
|
+
throw fail('invalid-handle', "Invalid handle: it was released.");
|
|
999
|
+
}
|
|
1000
|
+
const {
|
|
1001
|
+
options,
|
|
1002
|
+
signal,
|
|
1003
|
+
onProgress
|
|
1004
|
+
} = takeControls(mapOptions);
|
|
1005
|
+
if (signal && signal.aborted) {
|
|
1006
|
+
// As the functions on the worker do: a wrong argument is reported before the abort.
|
|
1007
|
+
try {
|
|
1008
|
+
await invoke(method, [id, own(send(image)), k, options], [], origin, {
|
|
1009
|
+
check: true
|
|
1010
|
+
});
|
|
1011
|
+
} catch (error) {
|
|
1012
|
+
if (isCodedError(error) && error.argument !== undefined) {
|
|
1013
|
+
throw error;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
throw abortReason(signal);
|
|
1017
|
+
}
|
|
1018
|
+
const warning = bareImageWarning(image);
|
|
1019
|
+
const byteLength = warning ? image.byteLength : 0;
|
|
1020
|
+
let sent = send(image);
|
|
1021
|
+
const ahead = !ready();
|
|
1022
|
+
if (ahead) {
|
|
1023
|
+
sent = take(sent);
|
|
1024
|
+
}
|
|
1025
|
+
const result = await invoke(method, [id, sent, ahead ? own(k) : k, options], pixelBuffers(sent), origin, {
|
|
1026
|
+
signal,
|
|
1027
|
+
onProgress
|
|
1028
|
+
});
|
|
1029
|
+
if (warning) {
|
|
1030
|
+
warnOnce(warning, byteLength);
|
|
1031
|
+
}
|
|
1032
|
+
return mapped ? rebuild(image)(result) : result;
|
|
1033
|
+
})();
|
|
1034
|
+
};
|
|
1035
|
+
Object.assign(handle, {
|
|
1036
|
+
quantize: mapping('quantize', 'handleQuantizeImage', true),
|
|
1037
|
+
quantizeToIndices: mapping('quantizeToIndices', 'handleQuantizeToIndicesImage', false)
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
// `await using handle = await worker.cluster(image)` releases it at the end of the block.
|
|
1041
|
+
if (typeof Symbol.asyncDispose === 'symbol') {
|
|
1042
|
+
handle[Symbol.asyncDispose] = handle.release;
|
|
1043
|
+
}
|
|
1044
|
+
if (reclaim) {
|
|
1045
|
+
reclaim.register(handle, id, handle);
|
|
1046
|
+
}
|
|
1047
|
+
return handle;
|
|
1048
|
+
};
|
|
1049
|
+
|
|
894
1050
|
// Clusters `image` and keeps it, with its clustering, in the worker.
|
|
895
1051
|
instance.cluster = (image, clusterOptions) => {
|
|
896
1052
|
const origin = new Error();
|
|
@@ -928,70 +1084,33 @@ const makeWorker = (options, allowScript) => {
|
|
|
928
1084
|
if (warning) {
|
|
929
1085
|
warnOnce(warning, byteLength);
|
|
930
1086
|
}
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
let taken;
|
|
944
|
-
try {
|
|
945
|
-
taken = takeControls(mapOptions);
|
|
946
|
-
} catch (error) {
|
|
947
|
-
return Promise.reject(error);
|
|
948
|
-
}
|
|
949
|
-
return use(method, [...leading, taken.options], {
|
|
950
|
-
signal: taken.signal,
|
|
951
|
-
onProgress: taken.onProgress
|
|
952
|
-
});
|
|
953
|
-
};
|
|
954
|
-
// The cuts take no options (the handle's clustering already says how it was made): one passed anyway is an error,
|
|
955
|
-
// as in the main entry, rather than silently ignored.
|
|
956
|
-
const plain = (method, name, args, extra) => extra.some(value => value !== undefined) ? Promise.reject(fail('invalid-argument', `Invalid arguments: handle.${name} takes no options. To map pixels with options, use handle.quantize.`, 'options')) : use(method, args);
|
|
957
|
-
const handle = {
|
|
958
|
-
getClustering: (...extra) => plain('handleGetClustering', 'getClustering', [], extra),
|
|
959
|
-
getPalette: (k, ...extra) => plain('handleGetPalette', 'getPalette', [k], extra),
|
|
960
|
-
getSwatches: (k, ...extra) => plain('handleGetSwatches', 'getSwatches', [k], extra),
|
|
961
|
-
getClusteringInfo: (...extra) => plain('handleGetClusteringInfo', 'getClusteringInfo', [], extra),
|
|
962
|
-
quantize: async (k, mapOptions) => output(await withControls('handleQuantize', [k], mapOptions)),
|
|
963
|
-
quantizeToIndices: (k, mapOptions) => withControls('handleQuantizeToIndices', [k], mapOptions),
|
|
964
|
-
quantizeWithPalette: async (palette, mapOptions) => output(await withControls('handleQuantizeWithPalette', [palette], mapOptions)),
|
|
965
|
-
quantizeToIndicesWithPalette: (palette, mapOptions) => withControls('handleQuantizeToIndicesWithPalette', [palette], mapOptions),
|
|
966
|
-
release: async () => {
|
|
967
|
-
if (released) {
|
|
968
|
-
return;
|
|
969
|
-
}
|
|
970
|
-
released = true;
|
|
971
|
-
liveHandles--;
|
|
972
|
-
if (reclaim) {
|
|
973
|
-
reclaim.unregister(handle);
|
|
974
|
-
}
|
|
975
|
-
// If the worker has been terminated there is nothing left to free (so `await using` and
|
|
976
|
-
// terminate() can come in either order); any other failure is reported.
|
|
977
|
-
try {
|
|
978
|
-
await invoke('release', [id], [], new Error());
|
|
979
|
-
} catch (error) {
|
|
980
|
-
if (error.code !== 'worker-terminated') {
|
|
981
|
-
throw error;
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
stopIfAbandoned();
|
|
985
|
-
}
|
|
986
|
-
};
|
|
987
|
-
// `await using handle = await worker.cluster(image)` releases it at the end of the block.
|
|
988
|
-
if (typeof Symbol.asyncDispose === 'symbol') {
|
|
989
|
-
handle[Symbol.asyncDispose] = handle.release;
|
|
1087
|
+
return makeHandle(id, 'image', rebuild(image));
|
|
1088
|
+
})();
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
// Keeps a stored clustering in the worker, for cutting it and mapping images with it without sending it again.
|
|
1092
|
+
instance.load = (clustering, ...extra) => {
|
|
1093
|
+
const origin = new Error();
|
|
1094
|
+
return (async () => {
|
|
1095
|
+
// Checked, and the bytes taken, before anything is awaited (see `own`): a damaged clustering, a palette or an
|
|
1096
|
+
// image is reported here, and nothing is posted.
|
|
1097
|
+
if (extra.length > 0) {
|
|
1098
|
+
throw fail('invalid-argument', "Invalid arguments: load takes the clustering only. Options go to the handle's methods.", 'options');
|
|
990
1099
|
}
|
|
991
|
-
|
|
992
|
-
|
|
1100
|
+
readHeader(clustering);
|
|
1101
|
+
const id = nextHandle++;
|
|
1102
|
+
const sent = ready() ? clustering : take(clustering);
|
|
1103
|
+
liveHandles++;
|
|
1104
|
+
try {
|
|
1105
|
+
await invoke('load', [id, sent], pixelBuffers(sent), origin);
|
|
1106
|
+
} catch (error) {
|
|
1107
|
+
liveHandles--;
|
|
1108
|
+
if (!terminated) {
|
|
1109
|
+
invoke('release', [id], [], new Error()).catch(() => {});
|
|
1110
|
+
}
|
|
1111
|
+
throw error;
|
|
993
1112
|
}
|
|
994
|
-
return
|
|
1113
|
+
return makeHandle(id, 'clustering');
|
|
995
1114
|
})();
|
|
996
1115
|
};
|
|
997
1116
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agglomerative-clustering",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-beta.1",
|
|
4
4
|
"description": "Colour palette extraction and image quantization with exact Ward clustering, in WebAssembly. Cluster an image once, then cut it to a palette of any size.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Rohan Fredriksson",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"README.md"
|
|
82
82
|
],
|
|
83
83
|
"scripts": {
|
|
84
|
-
"build:wasm": "node scripts/check-emsdk.mjs && mkdirp dist && em++ src/clustering.cpp -O3 -msimd128 -s WASM=1 -s MODULARIZE=1 -s EXPORT_ES6=1 -s EXPORT_NAME='createWasmModule' -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=32MB -s MAXIMUM_MEMORY=2147483648 -s EXPORTED_FUNCTIONS=\"['_library_version','_get_clustering','_clustering_job_start','_clustering_job_step','_clustering_job_result','_clustering_job_free','_mapping_job_start','_mapping_job_step','_mapping_job_result','_mapping_job_free','_get_palette','_get_palette_from_clustering','_get_palette_weights','_quantize','_quantize_with_clustering','_quantize_with_palette','_quantize_indices','_quantize_indices_with_clustering','_quantize_indices_with_palette','_malloc','_free']\" -s EXPORTED_RUNTIME_METHODS=\"['HEAPU8']\" -o dist/clustering.js && node scripts/patch-glue.mjs",
|
|
84
|
+
"build:wasm": "node scripts/check-emsdk.mjs && mkdirp dist && em++ src/clustering.cpp -O3 -msimd128 -s WASM=1 -s MODULARIZE=1 -s EXPORT_ES6=1 -s EXPORT_NAME='createWasmModule' -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=32MB -s MAXIMUM_MEMORY=2147483648 -s EXPORTED_FUNCTIONS=\"['_library_version','_unpremultiply','_premultiply','_get_clustering','_clustering_job_start','_clustering_job_step','_clustering_job_result','_clustering_job_free','_mapping_job_start','_mapping_job_step','_mapping_job_result','_mapping_job_free','_get_palette','_get_palette_from_clustering','_get_palette_weights','_quantize','_quantize_with_clustering','_quantize_with_palette','_quantize_indices','_quantize_indices_with_clustering','_quantize_indices_with_palette','_malloc','_free']\" -s EXPORTED_RUNTIME_METHODS=\"['HEAPU8']\" -o dist/clustering.js && node scripts/patch-glue.mjs",
|
|
85
85
|
"build:cjs": "cross-env BABEL_ENV=cjs babel src --out-dir dist --extensions \".js\" --ignore \"src/worker-thread.js\" --out-file-extension .cjs && node scripts/patch-cjs.mjs",
|
|
86
86
|
"build:esm": "cross-env BABEL_ENV=esm babel src --out-dir dist --extensions \".js\" --out-file-extension .mjs",
|
|
87
87
|
"build:types": "mkdirp dist && node -e \"const fs = require('fs'); for (const f of ['index.d.ts', 'worker.d.ts']) {fs.copyFileSync('src/' + f, 'dist/' + f);} fs.copyFileSync('src/index.d.ts', 'dist/index.d.cts'); fs.writeFileSync('dist/worker.d.cts', fs.readFileSync('src/worker.d.ts', 'utf8').replaceAll(\\\"'./index.js'\\\", \\\"'./index.cjs'\\\"));\"",
|