agglomerative-clustering 3.7.1 → 3.7.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/dist/clustering.wasm +0 -0
- package/dist/index.cjs +11 -2
- package/dist/index.mjs +11 -2
- package/dist/shared.cjs +1 -1
- package/dist/shared.mjs +1 -1
- package/dist/worker.cjs +3 -1
- package/dist/worker.mjs +3 -1
- package/package.json +1 -1
package/dist/clustering.wasm
CHANGED
|
Binary file
|
package/dist/index.cjs
CHANGED
|
@@ -168,6 +168,10 @@ const wasmSettings = (wasm, onError) => {
|
|
|
168
168
|
throw (0, _shared.fail)('invalid-argument', "Invalid wasm: must be a URL or path string, a URL, an ArrayBuffer or typed array of the .wasm bytes, or a WebAssembly.Module.", 'options.wasm');
|
|
169
169
|
};
|
|
170
170
|
|
|
171
|
+
// How each engine words a URL that can't be resolved: Chromium and Node "Invalid URL", Firefox "… is not a valid URL",
|
|
172
|
+
// WebKit "… cannot be parsed as a URL".
|
|
173
|
+
const badUrl = /Invalid URL|not a valid URL|cannot be parsed as a URL/i;
|
|
174
|
+
|
|
171
175
|
// A module that cannot be loaded is the commonest first-run failure: a 404, a Content-Security-Policy that blocks it, a
|
|
172
176
|
// bundler that moved the file, an engine without WebAssembly SIMD. The engine's own error (a CompileError, a failed fetch)
|
|
173
177
|
// says little about which, so the message leads with what happened and then gives the likely fix for where it ran.
|
|
@@ -260,16 +264,21 @@ const wasmLoadFailed = (cause, given, gzipped = false) => {
|
|
|
260
264
|
advice = `Check what init({ wasm }) was given${where}: it must be this package's clustering.wasm (its URL or path, its bytes, or the module compiled from it).`;
|
|
261
265
|
} else if (isNodeLike) {
|
|
262
266
|
// The glue's `new URL('clustering.wasm', import.meta.url)`, with import.meta emptied by a CommonJS bundle.
|
|
263
|
-
if (
|
|
267
|
+
if (badUrl.test(reason)) {
|
|
264
268
|
reason = "the package doesn't know where clustering.wasm is (bundled into CommonJS, it has lost its own URL)";
|
|
265
269
|
}
|
|
266
270
|
advice = `If the package was bundled (a server build, a CommonJS bundle from esbuild or Rollup, a plugin's single file), the bundler moved clustering.wasm or dropped what tells the package where it is, and the package's own copy wasn't found from the working directory either: leave the package out of the bundle (mark it external; in Next.js, serverExternalPackages: ['agglomerative-clustering']), or say where the file is with init({ wasm: path }) or give its bytes. ${deployAdvice}`;
|
|
267
271
|
} else if (!isBrowserLike()) {
|
|
268
272
|
// A server runtime that isn't Node (an edge runtime, Deno Deploy): it has no page, so a CSP or a 404 page are unlikely.
|
|
269
|
-
if (
|
|
273
|
+
if (badUrl.test(reason)) {
|
|
270
274
|
reason = "the package can't tell where clustering.wasm is in this runtime";
|
|
271
275
|
}
|
|
272
276
|
advice = "Give the module to init({ wasm }) before the first call: in an edge runtime (Cloudflare Workers, Vercel's), import clustering.wasm as a compiled module (the docs show how for Cloudflare Workers and Next.js: https://github.com/RohanFredriksson/agglomerative-clustering/blob/master/docs/environments.md); elsewhere its bytes or URL.";
|
|
277
|
+
} else if (badUrl.test(reason) && /^(data|blob|about):$/.test(String(globalThis.location && globalThis.location.protocol))) {
|
|
278
|
+
// The code runs from a data: or blob: URL (a bundled worker script in a single-file host) or an about:srcdoc page, so
|
|
279
|
+
// there is nothing to find clustering.wasm next to. (In a worker, location is the worker script's own URL.)
|
|
280
|
+
reason = `the package can't tell where clustering.wasm is: it runs from a ${globalThis.location.protocol} URL, with nothing next to it (${reason})`;
|
|
281
|
+
advice = "Pass the module itself: createWorker({ script, wasm: bytes }) for a worker you start, init({ wasm: bytes }) for the main entry or the worker entry's shared worker (the bytes, a URL, or a compiled module; see \"Plugins and single-file hosts\" in https://github.com/RohanFredriksson/agglomerative-clustering/blob/master/docs/environments.md).";
|
|
273
282
|
} else {
|
|
274
283
|
advice = "Check that clustering.wasm is served next to the script (not a 404, and with the application/wasm type) and allowed by the page's Content-Security-Policy, or say where it is with init({ wasm }).";
|
|
275
284
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -93,6 +93,10 @@ const wasmSettings = (wasm, onError) => {
|
|
|
93
93
|
throw fail('invalid-argument', "Invalid wasm: must be a URL or path string, a URL, an ArrayBuffer or typed array of the .wasm bytes, or a WebAssembly.Module.", 'options.wasm');
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
+
// How each engine words a URL that can't be resolved: Chromium and Node "Invalid URL", Firefox "… is not a valid URL",
|
|
97
|
+
// WebKit "… cannot be parsed as a URL".
|
|
98
|
+
const badUrl = /Invalid URL|not a valid URL|cannot be parsed as a URL/i;
|
|
99
|
+
|
|
96
100
|
// A module that cannot be loaded is the commonest first-run failure: a 404, a Content-Security-Policy that blocks it, a
|
|
97
101
|
// bundler that moved the file, an engine without WebAssembly SIMD. The engine's own error (a CompileError, a failed fetch)
|
|
98
102
|
// says little about which, so the message leads with what happened and then gives the likely fix for where it ran.
|
|
@@ -185,16 +189,21 @@ const wasmLoadFailed = (cause, given, gzipped = false) => {
|
|
|
185
189
|
advice = `Check what init({ wasm }) was given${where}: it must be this package's clustering.wasm (its URL or path, its bytes, or the module compiled from it).`;
|
|
186
190
|
} else if (isNodeLike) {
|
|
187
191
|
// The glue's `new URL('clustering.wasm', import.meta.url)`, with import.meta emptied by a CommonJS bundle.
|
|
188
|
-
if (
|
|
192
|
+
if (badUrl.test(reason)) {
|
|
189
193
|
reason = "the package doesn't know where clustering.wasm is (bundled into CommonJS, it has lost its own URL)";
|
|
190
194
|
}
|
|
191
195
|
advice = `If the package was bundled (a server build, a CommonJS bundle from esbuild or Rollup, a plugin's single file), the bundler moved clustering.wasm or dropped what tells the package where it is, and the package's own copy wasn't found from the working directory either: leave the package out of the bundle (mark it external; in Next.js, serverExternalPackages: ['agglomerative-clustering']), or say where the file is with init({ wasm: path }) or give its bytes. ${deployAdvice}`;
|
|
192
196
|
} else if (!isBrowserLike()) {
|
|
193
197
|
// A server runtime that isn't Node (an edge runtime, Deno Deploy): it has no page, so a CSP or a 404 page are unlikely.
|
|
194
|
-
if (
|
|
198
|
+
if (badUrl.test(reason)) {
|
|
195
199
|
reason = "the package can't tell where clustering.wasm is in this runtime";
|
|
196
200
|
}
|
|
197
201
|
advice = "Give the module to init({ wasm }) before the first call: in an edge runtime (Cloudflare Workers, Vercel's), import clustering.wasm as a compiled module (the docs show how for Cloudflare Workers and Next.js: https://github.com/RohanFredriksson/agglomerative-clustering/blob/master/docs/environments.md); elsewhere its bytes or URL.";
|
|
202
|
+
} else if (badUrl.test(reason) && /^(data|blob|about):$/.test(String(globalThis.location && globalThis.location.protocol))) {
|
|
203
|
+
// The code runs from a data: or blob: URL (a bundled worker script in a single-file host) or an about:srcdoc page, so
|
|
204
|
+
// there is nothing to find clustering.wasm next to. (In a worker, location is the worker script's own URL.)
|
|
205
|
+
reason = `the package can't tell where clustering.wasm is: it runs from a ${globalThis.location.protocol} URL, with nothing next to it (${reason})`;
|
|
206
|
+
advice = "Pass the module itself: createWorker({ script, wasm: bytes }) for a worker you start, init({ wasm: bytes }) for the main entry or the worker entry's shared worker (the bytes, a URL, or a compiled module; see \"Plugins and single-file hosts\" in https://github.com/RohanFredriksson/agglomerative-clustering/blob/master/docs/environments.md).";
|
|
198
207
|
} else {
|
|
199
208
|
advice = "Check that clustering.wasm is served next to the script (not a 404, and with the application/wasm type) and allowed by the page's Content-Security-Policy, or say where it is with init({ wasm }).";
|
|
200
209
|
}
|
package/dist/shared.cjs
CHANGED
|
@@ -13,7 +13,7 @@ exports.warnOnce = exports.version = exports.tooLarge = exports.sniffImageFormat
|
|
|
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.7.
|
|
16
|
+
const version = exports.version = '3.7.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.7.
|
|
7
|
+
export const version = '3.7.2';
|
|
8
8
|
export const colorSpaceCodes = {
|
|
9
9
|
'rgb': 0,
|
|
10
10
|
'oklab': 1
|
package/dist/worker.cjs
CHANGED
|
@@ -243,7 +243,9 @@ const start = async (receive, chosen) => {
|
|
|
243
243
|
}
|
|
244
244
|
worker.addEventListener('message', event => receive(event.data));
|
|
245
245
|
worker.addEventListener('error', event => receive({
|
|
246
|
-
failure: event.message ? `${event.message} ${scriptHint}` : crossOrigin ? `The worker failed to start: its script comes from another origin (${script.origin}), so it was started through a blob: URL, which also failed. Check that the server sends CORS headers, and that a Content-Security-Policy allows the worker: worker-src needs both blob: and ${script.origin} (the blob: worker imports the script from there). Or serve a copy of dist/ from this origin and say where with createWorker({ script }) or init({ script }).` : opaque ? `The worker failed to start from this page, whose origin is opaque (a sandboxed iframe): it was started from a data: URL importing ${script.href}, which needs CORS headers on that script and on what it imports. Or bundle worker-thread.mjs and its imports into one file, and pass it as a data: URL with createWorker({ script }).` :
|
|
246
|
+
failure: event.message ? `${event.message} ${scriptHint}` : crossOrigin ? `The worker failed to start: its script comes from another origin (${script.origin}), so it was started through a blob: URL, which also failed. Check that the server sends CORS headers, and that a Content-Security-Policy allows the worker: worker-src needs both blob: and ${script.origin} (the blob: worker imports the script from there). Or serve a copy of dist/ from this origin and say where with createWorker({ script }) or init({ script }).` : opaque ? `The worker failed to start from this page, whose origin is opaque (a sandboxed iframe): it was started from a data: URL importing ${script.href}, which needs CORS headers on that script and on what it imports. Or bundle worker-thread.mjs and its imports into one file, and pass it as a data: URL with createWorker({ script }).` : script.protocol === 'blob:' && isOpaqueOrigin()
|
|
247
|
+
// Chromium refuses blob: workers in an opaque origin; the docs' single-file recipe uses a data: URL.
|
|
248
|
+
? `The worker failed to start from ${script.href}: in a sandboxed iframe (an opaque origin, as plugin hosts such as Figma use) Chromium can't start a worker from a blob: URL. Pass the bundled worker script as a data: URL instead, createWorker({ script: 'data:text/javascript;base64,…', wasm: bytes }) (see "Plugins and single-file hosts" in https://github.com/RohanFredriksson/agglomerative-clustering/blob/master/docs/environments.md).` : `The worker failed to start${chosen ? ` from ${script.href}` : ''}. ${scriptHint} A Content-Security-Policy must also allow it as a worker (worker-src).`
|
|
247
249
|
}));
|
|
248
250
|
return {
|
|
249
251
|
post: (message, transfer) => worker.postMessage(message, transfer),
|
package/dist/worker.mjs
CHANGED
|
@@ -174,7 +174,9 @@ const start = async (receive, chosen) => {
|
|
|
174
174
|
}
|
|
175
175
|
worker.addEventListener('message', event => receive(event.data));
|
|
176
176
|
worker.addEventListener('error', event => receive({
|
|
177
|
-
failure: event.message ? `${event.message} ${scriptHint}` : crossOrigin ? `The worker failed to start: its script comes from another origin (${script.origin}), so it was started through a blob: URL, which also failed. Check that the server sends CORS headers, and that a Content-Security-Policy allows the worker: worker-src needs both blob: and ${script.origin} (the blob: worker imports the script from there). Or serve a copy of dist/ from this origin and say where with createWorker({ script }) or init({ script }).` : opaque ? `The worker failed to start from this page, whose origin is opaque (a sandboxed iframe): it was started from a data: URL importing ${script.href}, which needs CORS headers on that script and on what it imports. Or bundle worker-thread.mjs and its imports into one file, and pass it as a data: URL with createWorker({ script }).` :
|
|
177
|
+
failure: event.message ? `${event.message} ${scriptHint}` : crossOrigin ? `The worker failed to start: its script comes from another origin (${script.origin}), so it was started through a blob: URL, which also failed. Check that the server sends CORS headers, and that a Content-Security-Policy allows the worker: worker-src needs both blob: and ${script.origin} (the blob: worker imports the script from there). Or serve a copy of dist/ from this origin and say where with createWorker({ script }) or init({ script }).` : opaque ? `The worker failed to start from this page, whose origin is opaque (a sandboxed iframe): it was started from a data: URL importing ${script.href}, which needs CORS headers on that script and on what it imports. Or bundle worker-thread.mjs and its imports into one file, and pass it as a data: URL with createWorker({ script }).` : script.protocol === 'blob:' && isOpaqueOrigin()
|
|
178
|
+
// Chromium refuses blob: workers in an opaque origin; the docs' single-file recipe uses a data: URL.
|
|
179
|
+
? `The worker failed to start from ${script.href}: in a sandboxed iframe (an opaque origin, as plugin hosts such as Figma use) Chromium can't start a worker from a blob: URL. Pass the bundled worker script as a data: URL instead, createWorker({ script: 'data:text/javascript;base64,…', wasm: bytes }) (see "Plugins and single-file hosts" in https://github.com/RohanFredriksson/agglomerative-clustering/blob/master/docs/environments.md).` : `The worker failed to start${chosen ? ` from ${script.href}` : ''}. ${scriptHint} A Content-Security-Policy must also allow it as a worker (worker-src).`
|
|
178
180
|
}));
|
|
179
181
|
return {
|
|
180
182
|
post: (message, transfer) => worker.postMessage(message, transfer),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agglomerative-clustering",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.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",
|