agglomerative-clustering 3.1.1 → 3.3.0

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/worker.d.cts CHANGED
@@ -11,7 +11,10 @@ import type { Palette, Clustering } from './index.cjs';
11
11
  /** The same class as the main entry's `Palette`: flat RGB bytes that know their colour space. */
12
12
  export { Palette } from './index.cjs';
13
13
 
14
- /** The same class as the main entry's `Clustering`: the typed bytes of a clustering. */
14
+ /**
15
+ * The same class as the main entry's `Clustering`. Its methods run on the calling thread and need the main entry imported
16
+ * there; off the thread, use this entry's `…FromClustering` functions or `cluster()`.
17
+ */
15
18
  export { Clustering } from './index.cjs';
16
19
 
17
20
  /** The same list as the main entry's `errorCodes`: the worker entry's errors have the same codes. */
package/dist/worker.d.ts CHANGED
@@ -11,7 +11,10 @@ import type { Palette, Clustering } from './index.js';
11
11
  /** The same class as the main entry's `Palette`: flat RGB bytes that know their colour space. */
12
12
  export { Palette } from './index.js';
13
13
 
14
- /** The same class as the main entry's `Clustering`: the typed bytes of a clustering. */
14
+ /**
15
+ * The same class as the main entry's `Clustering`. Its methods run on the calling thread and need the main entry imported
16
+ * there; off the thread, use this entry's `…FromClustering` functions or `cluster()`.
17
+ */
15
18
  export { Clustering } from './index.js';
16
19
 
17
20
  /** The same list as the main entry's `errorCodes`: the worker entry's errors have the same codes. */
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, isOptionsObject, snapshot, parseDither, mark, revive, latestVersion, imageHint, isDetached, imageDataLike, isImageData, checkImageDataPixels, maxBytes, tooLarge } from "./shared.mjs";
7
+ import { fail, detachedError, isOptionsObject, snapshot, parseDither, mark, revive, latestVersion, imageHint, isDetached, imageDataLike, isImageData, checkImageDataPixels, maxBytes, tooLarge } 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";
@@ -17,7 +17,9 @@ export const formatVersion = latestVersion;
17
17
  // bundlers don't take this for a use of Node's `process` and add a polyfill (Parcel installs one).
18
18
  const runtime = globalThis.process;
19
19
  const scriptUrl = typeof import.meta.url === 'string' ? import.meta.url : '';
20
- const hasNode = !!(runtime && runtime.versions && runtime.versions.node) && (typeof window === 'undefined' || typeof Worker !== 'function');
20
+ // Electron's pages, their Web Workers and service-worker preload realms (process.type 'renderer', 'worker' and
21
+ // 'service-worker') have Node's globals but no worker_threads.
22
+ const hasNode = !!(runtime && runtime.versions && runtime.versions.node) && !['renderer', 'worker', 'service-worker'].includes(runtime.type) && (typeof window === 'undefined' || typeof Worker !== 'function');
21
23
  const isNode = hasNode && scriptUrl.startsWith('file:');
22
24
  // Node itself (or Bun) with this script bundled into CommonJS, where import.meta.url is gone: worker_threads still works, with
23
25
  // the script given, or the package's own copy. Runtimes that imitate Node say what they are in navigator.userAgent.
@@ -254,7 +256,7 @@ const send = image => {
254
256
  // A detached buffer (transferred to a worker created with transfer: true, say) is reported as the main entry reports it.
255
257
  const pixels = ArrayBuffer.isView(image) ? image : image && typeof image === 'object' && ArrayBuffer.isView(image.data) ? image.data : null;
256
258
  if (pixels && isDetached(pixels)) {
257
- throw fail('invalid-argument', "Invalid image: its pixels were transferred away (detached), for example to a worker created with transfer: true, so it has none left. Pass a copy if you need to keep using it.", 'image');
259
+ throw detachedError(ArrayBuffer.isView(image) ? 'bare' : isImageData(image) ? 'imagedata' : 'data');
258
260
  }
259
261
  // Too large for the module, as the main entry reports it, before a copy is made to send (or, from 4 GB, fails to be).
260
262
  if (pixels && pixels.byteLength >= maxBytes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agglomerative-clustering",
3
- "version": "3.1.1",
3
+ "version": "3.3.0",
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",