agglomerative-clustering 3.4.1 → 3.4.2

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 CHANGED
@@ -16,7 +16,7 @@ Most colour quantizers answer one question: *give me k colours*. Ask for a diffe
16
16
  - **Transparency-aware.** A logo's transparent background never ends up in its palette. GIF and palette PNG output are built in.
17
17
  - **Off the main thread.** `agglomerative-clustering/worker` runs the same API in a Web Worker or Node worker thread.
18
18
  - **Accurate and fast.** The lowest average error of the six JavaScript quantizers we benchmarked, at about the speed of libimagequant ([benchmarks](#benchmarks)).
19
- - **Small and portable.** About 127 KB of WebAssembly (52 KB gzipped), Node and browsers, TypeScript types, no runtime dependencies, deterministic output.
19
+ - **Small and portable.** About 96 KB of WebAssembly (45 KB gzipped), Node and browsers, TypeScript types, no runtime dependencies, deterministic output.
20
20
 
21
21
  ## Install
22
22
 
@@ -154,7 +154,8 @@ All rows are from one run. Full results at every palette size, on synthetic imag
154
154
 
155
155
  ```sh
156
156
  git clone https://github.com/RohanFredriksson/agglomerative-clustering && cd agglomerative-clustering
157
- npm install && npm run build # building needs Emscripten (em++) on your PATH
157
+ scripts/setup-emsdk.sh && source ~/.local/share/emsdk/emsdk_env.sh # Emscripten, the version CI uses
158
+ npm install && npm run build
158
159
  npm run demo # then open http://localhost:8080/demo/
159
160
  ```
160
161
 
Binary file
package/dist/index.cjs CHANGED
@@ -713,7 +713,7 @@ const parseOptions = (options, allowed, image) => {
713
713
  options = (0, _shared.snapshot)(options);
714
714
  for (const key of Object.keys(options)) {
715
715
  if (!allowed.includes(key)) {
716
- const hint = allowed.includes('dither') && ditherSettings.includes(key) ? ' Dithering settings go inside the dither option: dither: { method, strength, steps }.' : key === 'onProgress' && allowed.includes('signal') ? ' The functions that only map pixels take just signal: they finish in milliseconds, with no progress to report.' : '';
716
+ const hint = allowed.includes('dither') && ditherSettings.includes(key) ? ' Dithering settings go inside the dither option: dither: { method, strength, steps }.' : key === 'onProgress' && allowed.includes('signal') ? ' The functions that only map pixels take just signal, checked before they start: for progress, map the image in strips of rows (https://github.com/RohanFredriksson/agglomerative-clustering/blob/master/docs/guides.md#cancelling-or-showing-progress-while-mapping-a-large-image).' : '';
717
717
  throw (0, _shared.fail)('invalid-argument', `Invalid option '${key}': expected one of ${allowed.join(', ')}.${hint}`, `options.${key}`);
718
718
  }
719
719
  }
@@ -791,8 +791,8 @@ const parseOptions = (options, allowed, image) => {
791
791
  const controlOptions = ['signal', 'onProgress'];
792
792
  const clusterOptions = ['colorSpace', 'precision', 'alpha', 'transparent', ...controlOptions];
793
793
  const quantizeOptions = [...clusterOptions, 'dither', 'width'];
794
- // The functions that only map pixels take just `signal`: they finish in milliseconds, so there is nothing to report progress
795
- // on or to interrupt part way; a signal that is already aborted does no work, which is all it can mean.
794
+ // The functions that only map pixels take just `signal`, checked before they start: mapping runs in one piece (milliseconds
795
+ // for a photo, seconds for a large image dithered; the guides show how to map in strips or cancel through a worker).
796
796
  const mapOptions = ['colorSpace', 'dither', 'width', 'signal'];
797
797
  const quantizeIndexOptions = quantizeOptions;
798
798
  const mapIndexOptions = [...mapOptions, 'transparent'];
package/dist/index.d.cts CHANGED
@@ -183,9 +183,9 @@ export interface CancelOptions {
183
183
  * the signal's `reason` (an `AbortError` by default), like `fetch`; note that it is that reason that is thrown, so it
184
184
  * has the signal's own `name`, not an `ErrorCode`. A signal that is already aborted does no work. On the functions
185
185
  * that only map pixels (`quantizeFromClustering`, `quantizeWithPalette` and their indexed forms) it is checked once,
186
- * before the call starts, since they take milliseconds. Pixel mapping, which follows the clustering, can't be
187
- * interrupted. The call's result is the same as without a signal. In the worker entry the worker itself stops
188
- * working on the call, and a call still waiting its turn never starts.
186
+ * before the call starts. Pixel mapping, which follows the clustering, can't be
187
+ * interrupted (the guides show how to map a large image in strips, or cancel it through a worker). The call's result is the same as without a signal. In the worker entry the worker stops
188
+ * working on a call that clusters, and a call still waiting its turn never starts; a mapping already running finishes.
189
189
  */
190
190
  signal?: AbortSignal | undefined;
191
191
  }
@@ -257,7 +257,7 @@ export type DitherOptions =
257
257
  | { method?: 'floyd-steinberg' | 'atkinson' | undefined; strength?: number | undefined; steps?: undefined }
258
258
  | { method: 'ordered'; strength?: number | undefined; steps?: DitherSteps | undefined };
259
259
 
260
- /** Options for mapping pixels to a palette: `quantizeFromClustering`, `quantizeWithPalette`, and the mapping half of `quantize` and `quantizeToIndices`. They take `signal` but no `onProgress`: mapping takes milliseconds. */
260
+ /** Options for mapping pixels to a palette: `quantizeFromClustering`, `quantizeWithPalette`, and the mapping half of `quantize` and `quantizeToIndices`. They take `signal` (checked before mapping starts) but no `onProgress`: mapping runs in one piece. */
261
261
  export interface MappingOptions extends CancelOptions {
262
262
  /**
263
263
  * The space pixels are matched to their nearest palette colour in. The default is the space the colours were made in:
package/dist/index.d.ts CHANGED
@@ -183,9 +183,9 @@ export interface CancelOptions {
183
183
  * the signal's `reason` (an `AbortError` by default), like `fetch`; note that it is that reason that is thrown, so it
184
184
  * has the signal's own `name`, not an `ErrorCode`. A signal that is already aborted does no work. On the functions
185
185
  * that only map pixels (`quantizeFromClustering`, `quantizeWithPalette` and their indexed forms) it is checked once,
186
- * before the call starts, since they take milliseconds. Pixel mapping, which follows the clustering, can't be
187
- * interrupted. The call's result is the same as without a signal. In the worker entry the worker itself stops
188
- * working on the call, and a call still waiting its turn never starts.
186
+ * before the call starts. Pixel mapping, which follows the clustering, can't be
187
+ * interrupted (the guides show how to map a large image in strips, or cancel it through a worker). The call's result is the same as without a signal. In the worker entry the worker stops
188
+ * working on a call that clusters, and a call still waiting its turn never starts; a mapping already running finishes.
189
189
  */
190
190
  signal?: AbortSignal | undefined;
191
191
  }
@@ -257,7 +257,7 @@ export type DitherOptions =
257
257
  | { method?: 'floyd-steinberg' | 'atkinson' | undefined; strength?: number | undefined; steps?: undefined }
258
258
  | { method: 'ordered'; strength?: number | undefined; steps?: DitherSteps | undefined };
259
259
 
260
- /** Options for mapping pixels to a palette: `quantizeFromClustering`, `quantizeWithPalette`, and the mapping half of `quantize` and `quantizeToIndices`. They take `signal` but no `onProgress`: mapping takes milliseconds. */
260
+ /** Options for mapping pixels to a palette: `quantizeFromClustering`, `quantizeWithPalette`, and the mapping half of `quantize` and `quantizeToIndices`. They take `signal` (checked before mapping starts) but no `onProgress`: mapping runs in one piece. */
261
261
  export interface MappingOptions extends CancelOptions {
262
262
  /**
263
263
  * The space pixels are matched to their nearest palette colour in. The default is the space the colours were made in:
package/dist/index.mjs CHANGED
@@ -637,7 +637,7 @@ const parseOptions = (options, allowed, image) => {
637
637
  options = snapshot(options);
638
638
  for (const key of Object.keys(options)) {
639
639
  if (!allowed.includes(key)) {
640
- const hint = allowed.includes('dither') && ditherSettings.includes(key) ? ' Dithering settings go inside the dither option: dither: { method, strength, steps }.' : key === 'onProgress' && allowed.includes('signal') ? ' The functions that only map pixels take just signal: they finish in milliseconds, with no progress to report.' : '';
640
+ const hint = allowed.includes('dither') && ditherSettings.includes(key) ? ' Dithering settings go inside the dither option: dither: { method, strength, steps }.' : key === 'onProgress' && allowed.includes('signal') ? ' The functions that only map pixels take just signal, checked before they start: for progress, map the image in strips of rows (https://github.com/RohanFredriksson/agglomerative-clustering/blob/master/docs/guides.md#cancelling-or-showing-progress-while-mapping-a-large-image).' : '';
641
641
  throw fail('invalid-argument', `Invalid option '${key}': expected one of ${allowed.join(', ')}.${hint}`, `options.${key}`);
642
642
  }
643
643
  }
@@ -715,8 +715,8 @@ const parseOptions = (options, allowed, image) => {
715
715
  const controlOptions = ['signal', 'onProgress'];
716
716
  const clusterOptions = ['colorSpace', 'precision', 'alpha', 'transparent', ...controlOptions];
717
717
  const quantizeOptions = [...clusterOptions, 'dither', 'width'];
718
- // The functions that only map pixels take just `signal`: they finish in milliseconds, so there is nothing to report progress
719
- // on or to interrupt part way; a signal that is already aborted does no work, which is all it can mean.
718
+ // The functions that only map pixels take just `signal`, checked before they start: mapping runs in one piece (milliseconds
719
+ // for a photo, seconds for a large image dithered; the guides show how to map in strips or cancel through a worker).
720
720
  const mapOptions = ['colorSpace', 'dither', 'width', 'signal'];
721
721
  const quantizeIndexOptions = quantizeOptions;
722
722
  const mapIndexOptions = [...mapOptions, 'transparent'];
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.4.1';
16
+ const version = exports.version = '3.4.2';
17
17
  const colorSpaceCodes = exports.colorSpaceCodes = {
18
18
  'rgb': 0,
19
19
  'oklab': 1
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.4.1';
7
+ export const version = '3.4.2';
8
8
  export const colorSpaceCodes = {
9
9
  'rgb': 0,
10
10
  'oklab': 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agglomerative-clustering",
3
- "version": "3.4.1",
3
+ "version": "3.4.2",
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": "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','_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','_get_clustering','_clustering_job_start','_clustering_job_step','_clustering_job_result','_clustering_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'\\\"));\"",
@@ -103,6 +103,8 @@
103
103
  "@babel/core": "^7.27.4",
104
104
  "@babel/plugin-transform-modules-commonjs": "^7.27.1",
105
105
  "@babel/preset-env": "^7.27.2",
106
+ "@parcel/config-default": "^2.16.4",
107
+ "@parcel/core": "^2.16.4",
106
108
  "@types/node": "^22.20.5",
107
109
  "canvas": "^3.2.3",
108
110
  "cross-env": "^7.0.3",