agglomerative-clustering 3.1.0 → 3.1.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/dist/clustering.wasm +0 -0
- package/dist/shared.cjs +2 -2
- package/dist/shared.mjs +2 -2
- package/dist/worker.cjs +10 -3
- package/dist/worker.mjs +10 -3
- package/package.json +1 -1
package/dist/clustering.wasm
CHANGED
|
Binary file
|
package/dist/shared.cjs
CHANGED
|
@@ -13,7 +13,7 @@ exports.version = exports.tooLarge = exports.snapshot = exports.sizeText = expor
|
|
|
13
13
|
|
|
14
14
|
// The library's version: package.json is the source, and scripts/sync-version.mjs keeps this line (and the copy the .wasm
|
|
15
15
|
// is built from, src/version.hpp) in step with it. Do not edit it by hand.
|
|
16
|
-
const version = exports.version = '3.1.
|
|
16
|
+
const version = exports.version = '3.1.1';
|
|
17
17
|
const colorSpaceCodes = exports.colorSpaceCodes = {
|
|
18
18
|
'rgb': 0,
|
|
19
19
|
'oklab': 1
|
|
@@ -186,7 +186,7 @@ const ditherMethods = exports.ditherMethods = Object.freeze(Object.keys(ditherMe
|
|
|
186
186
|
const ditherSteps = exports.ditherSteps = Object.freeze([2, 4, 8, 16, 32, 64]);
|
|
187
187
|
|
|
188
188
|
// A short description of a value for an error message.
|
|
189
|
-
const describe = value => typeof value === 'string' ? `'${value}'` : typeof value === 'number' || typeof value === 'boolean' || value === null ? String(value) : Array.isArray(value) ? 'an array' : typeof value === 'object' ? `a ${Object.prototype.toString.call(value).slice(8, -1)}` : typeof value
|
|
189
|
+
const describe = value => typeof value === 'string' ? `'${value}'` : typeof value === 'number' || typeof value === 'boolean' || value === null ? String(value) : Array.isArray(value) ? 'an array' : typeof value === 'object' ? `a ${Object.prototype.toString.call(value).slice(8, -1)}` : `a ${typeof value}`;
|
|
190
190
|
|
|
191
191
|
// Reads every form of the dither option: false/undefined (off), true or a strength from 0 to 1 (Floyd-Steinberg, as in
|
|
192
192
|
// 3.0), a method name, or an object { method, strength, steps } that the plain forms are shorthands for.
|
package/dist/shared.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
// The library's version: package.json is the source, and scripts/sync-version.mjs keeps this line (and the copy the .wasm
|
|
6
6
|
// is built from, src/version.hpp) in step with it. Do not edit it by hand.
|
|
7
|
-
export const version = '3.1.
|
|
7
|
+
export const version = '3.1.1';
|
|
8
8
|
export const colorSpaceCodes = {
|
|
9
9
|
'rgb': 0,
|
|
10
10
|
'oklab': 1
|
|
@@ -162,7 +162,7 @@ export const ditherMethods = Object.freeze(Object.keys(ditherMethodCodes));
|
|
|
162
162
|
export const ditherSteps = Object.freeze([2, 4, 8, 16, 32, 64]);
|
|
163
163
|
|
|
164
164
|
// A short description of a value for an error message.
|
|
165
|
-
const describe = value => typeof value === 'string' ? `'${value}'` : typeof value === 'number' || typeof value === 'boolean' || value === null ? String(value) : Array.isArray(value) ? 'an array' : typeof value === 'object' ? `a ${Object.prototype.toString.call(value).slice(8, -1)}` : typeof value
|
|
165
|
+
const describe = value => typeof value === 'string' ? `'${value}'` : typeof value === 'number' || typeof value === 'boolean' || value === null ? String(value) : Array.isArray(value) ? 'an array' : typeof value === 'object' ? `a ${Object.prototype.toString.call(value).slice(8, -1)}` : `a ${typeof value}`;
|
|
166
166
|
|
|
167
167
|
// Reads every form of the dither option: false/undefined (off), true or a strength from 0 to 1 (Floyd-Steinberg, as in
|
|
168
168
|
// 3.0), a method name, or an object { method, strength, steps } that the plain forms are shorthands for.
|
package/dist/worker.cjs
CHANGED
|
@@ -468,7 +468,7 @@ const initOptions = (options, allowScript) => {
|
|
|
468
468
|
|
|
469
469
|
// A signal and a progress callback can't cross to the worker, so they stay on this side: the options are sent without
|
|
470
470
|
// them, a cancel message is sent when the signal aborts, and the worker's progress messages call the callback.
|
|
471
|
-
const takeControls = (options, progressAllowed = true) => {
|
|
471
|
+
const takeControls = (options, progressAllowed = true, ditherAllowed = true) => {
|
|
472
472
|
// Anything but an ordinary object goes on as it is, for the worker's own validation to reject. An ordinary one is copied
|
|
473
473
|
// once first: structured cloning drops inherited properties, and the copy is what gets validated and sent.
|
|
474
474
|
if (!(0, _shared.isOptionsObject)(options)) {
|
|
@@ -481,6 +481,11 @@ const takeControls = (options, progressAllowed = true) => {
|
|
|
481
481
|
options = (0, _shared.snapshot)(options);
|
|
482
482
|
// The dither setting is an object of its own, which structured cloning would copy without its inherited keys (or not
|
|
483
483
|
// at all, for a Proxy or a function): read it here the way the main entry does, and send a plain copy.
|
|
484
|
+
// A function that takes no dither option rejects the key whatever its value, as the main entry does: send a value that
|
|
485
|
+
// can cross, for the worker's validation to name the option.
|
|
486
|
+
if (!ditherAllowed && 'dither' in options) {
|
|
487
|
+
options.dither = null;
|
|
488
|
+
}
|
|
484
489
|
if (options.dither !== null && (typeof options.dither === 'object' || typeof options.dither === 'function' || typeof options.dither === 'symbol')) {
|
|
485
490
|
// One read of each setting (a getter could answer differently twice): the copy is what is checked and sent.
|
|
486
491
|
const copy = (0, _shared.isOptionsObject)(options.dither) ? Object.assign({}, (0, _shared.snapshot)(options.dither)) : options.dither;
|
|
@@ -537,6 +542,8 @@ const abortReason = signal => signal.reason !== undefined ? signal.reason : new
|
|
|
537
542
|
const imageFunctions = ['getClustering', 'getPalette', 'getSwatches', 'quantize', 'quantizeFromClustering', 'quantizeWithPalette', 'quantizeToIndices', 'quantizeToIndicesFromClustering', 'quantizeToIndicesWithPalette'];
|
|
538
543
|
const mappedImageFunctions = ['quantize', 'quantizeFromClustering', 'quantizeWithPalette'];
|
|
539
544
|
// These only map pixels, so they take a signal but no progress callback (see mapOptions in index.js).
|
|
545
|
+
// The functions that only cluster, and so take no dither option.
|
|
546
|
+
const clusteringOnlyFunctions = ['getClustering', 'getPalette', 'getSwatches'];
|
|
540
547
|
const mappingOnlyFunctions = ['quantizeFromClustering', 'quantizeWithPalette', 'quantizeToIndicesFromClustering', 'quantizeToIndicesWithPalette'];
|
|
541
548
|
const otherFunctions = ['getPaletteFromClustering', 'getSwatchesFromClustering', 'getClusteringInfo'];
|
|
542
549
|
|
|
@@ -841,7 +848,7 @@ const makeWorker = (options, allowScript) => {
|
|
|
841
848
|
options,
|
|
842
849
|
signal,
|
|
843
850
|
onProgress
|
|
844
|
-
} = takeControls(rest[position], !mappingOnlyFunctions.includes(name));
|
|
851
|
+
} = takeControls(rest[position], !mappingOnlyFunctions.includes(name), !clusteringOnlyFunctions.includes(name));
|
|
845
852
|
// Checked before the image is copied or transferred away, so an aborted call leaves it with the caller.
|
|
846
853
|
if (signal && signal.aborted) {
|
|
847
854
|
throw abortReason(signal);
|
|
@@ -898,7 +905,7 @@ const makeWorker = (options, allowScript) => {
|
|
|
898
905
|
options,
|
|
899
906
|
signal,
|
|
900
907
|
onProgress
|
|
901
|
-
} = takeControls(clusterOptions);
|
|
908
|
+
} = takeControls(clusterOptions, true, false);
|
|
902
909
|
if (signal && signal.aborted) {
|
|
903
910
|
throw abortReason(signal);
|
|
904
911
|
}
|
package/dist/worker.mjs
CHANGED
|
@@ -400,7 +400,7 @@ const initOptions = (options, allowScript) => {
|
|
|
400
400
|
|
|
401
401
|
// A signal and a progress callback can't cross to the worker, so they stay on this side: the options are sent without
|
|
402
402
|
// them, a cancel message is sent when the signal aborts, and the worker's progress messages call the callback.
|
|
403
|
-
const takeControls = (options, progressAllowed = true) => {
|
|
403
|
+
const takeControls = (options, progressAllowed = true, ditherAllowed = true) => {
|
|
404
404
|
// Anything but an ordinary object goes on as it is, for the worker's own validation to reject. An ordinary one is copied
|
|
405
405
|
// once first: structured cloning drops inherited properties, and the copy is what gets validated and sent.
|
|
406
406
|
if (!isOptionsObject(options)) {
|
|
@@ -413,6 +413,11 @@ const takeControls = (options, progressAllowed = true) => {
|
|
|
413
413
|
options = snapshot(options);
|
|
414
414
|
// The dither setting is an object of its own, which structured cloning would copy without its inherited keys (or not
|
|
415
415
|
// at all, for a Proxy or a function): read it here the way the main entry does, and send a plain copy.
|
|
416
|
+
// A function that takes no dither option rejects the key whatever its value, as the main entry does: send a value that
|
|
417
|
+
// can cross, for the worker's validation to name the option.
|
|
418
|
+
if (!ditherAllowed && 'dither' in options) {
|
|
419
|
+
options.dither = null;
|
|
420
|
+
}
|
|
416
421
|
if (options.dither !== null && (typeof options.dither === 'object' || typeof options.dither === 'function' || typeof options.dither === 'symbol')) {
|
|
417
422
|
// One read of each setting (a getter could answer differently twice): the copy is what is checked and sent.
|
|
418
423
|
const copy = isOptionsObject(options.dither) ? Object.assign({}, snapshot(options.dither)) : options.dither;
|
|
@@ -469,6 +474,8 @@ const abortReason = signal => signal.reason !== undefined ? signal.reason : new
|
|
|
469
474
|
const imageFunctions = ['getClustering', 'getPalette', 'getSwatches', 'quantize', 'quantizeFromClustering', 'quantizeWithPalette', 'quantizeToIndices', 'quantizeToIndicesFromClustering', 'quantizeToIndicesWithPalette'];
|
|
470
475
|
const mappedImageFunctions = ['quantize', 'quantizeFromClustering', 'quantizeWithPalette'];
|
|
471
476
|
// These only map pixels, so they take a signal but no progress callback (see mapOptions in index.js).
|
|
477
|
+
// The functions that only cluster, and so take no dither option.
|
|
478
|
+
const clusteringOnlyFunctions = ['getClustering', 'getPalette', 'getSwatches'];
|
|
472
479
|
const mappingOnlyFunctions = ['quantizeFromClustering', 'quantizeWithPalette', 'quantizeToIndicesFromClustering', 'quantizeToIndicesWithPalette'];
|
|
473
480
|
const otherFunctions = ['getPaletteFromClustering', 'getSwatchesFromClustering', 'getClusteringInfo'];
|
|
474
481
|
|
|
@@ -773,7 +780,7 @@ const makeWorker = (options, allowScript) => {
|
|
|
773
780
|
options,
|
|
774
781
|
signal,
|
|
775
782
|
onProgress
|
|
776
|
-
} = takeControls(rest[position], !mappingOnlyFunctions.includes(name));
|
|
783
|
+
} = takeControls(rest[position], !mappingOnlyFunctions.includes(name), !clusteringOnlyFunctions.includes(name));
|
|
777
784
|
// Checked before the image is copied or transferred away, so an aborted call leaves it with the caller.
|
|
778
785
|
if (signal && signal.aborted) {
|
|
779
786
|
throw abortReason(signal);
|
|
@@ -830,7 +837,7 @@ const makeWorker = (options, allowScript) => {
|
|
|
830
837
|
options,
|
|
831
838
|
signal,
|
|
832
839
|
onProgress
|
|
833
|
-
} = takeControls(clusterOptions);
|
|
840
|
+
} = takeControls(clusterOptions, true, false);
|
|
834
841
|
if (signal && signal.aborted) {
|
|
835
842
|
throw abortReason(signal);
|
|
836
843
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agglomerative-clustering",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.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",
|