agglomerative-clustering 3.7.0 → 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 +33 -7
- package/dist/index.mjs +33 -7
- 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.
|
|
@@ -190,7 +194,13 @@ const isBrowserLike = () => typeof document !== 'undefined' || typeof WorkerGlob
|
|
|
190
194
|
const deployAdvice = "In a serverless deployment (AWS Lambda, Vercel or Netlify functions), the bundler or file tracer may have left the package's dist/ files out: include node_modules/agglomerative-clustering/dist in the function's files, or leave the package unbundled (external).";
|
|
191
195
|
// Emscripten appends advice about its own debug build, which doesn't apply to this package's users.
|
|
192
196
|
const assertionsAdvice = /\s*\(?Build with -sASSERTIONS for more info\.?\)?/;
|
|
193
|
-
|
|
197
|
+
// Whether init({ wasm }) was given bytes that start with gzip's magic (1f 8b): a gzipped module passed without decompressing.
|
|
198
|
+
const isGzipped = wasm => {
|
|
199
|
+
const tag = Object.prototype.toString.call(wasm);
|
|
200
|
+
const bytes = tag === '[object ArrayBuffer]' ? new Uint8Array(wasm) : ArrayBuffer.isView(wasm) ? new Uint8Array(wasm.buffer, wasm.byteOffset, wasm.byteLength) : null;
|
|
201
|
+
return bytes !== null && bytes.length >= 2 && bytes[0] === 0x1f && bytes[1] === 0x8b;
|
|
202
|
+
};
|
|
203
|
+
const wasmLoadFailed = (cause, given, gzipped = false) => {
|
|
194
204
|
const text = String(cause && cause.message !== undefined ? cause.message : cause).split('\n')[0];
|
|
195
205
|
// Emscripten wraps a failed compile in Aborted(...), which is how it stops itself, not part of the reason.
|
|
196
206
|
let reason = text.replace(assertionsAdvice, '').trim().replace(/\.+$/, '');
|
|
@@ -221,6 +231,10 @@ const wasmLoadFailed = (cause, given) => {
|
|
|
221
231
|
advice = "A Content-Security-Policy blocks compiling WebAssembly: add 'wasm-unsafe-eval' to the script-src of the policy that applies. That is the page's for a page and for the worker entry's worker (also when started from a content script, whose worker follows the page's policy); for a browser extension's own pages, offscreen document and service worker, it is content_security_policy.extension_pages in the manifest.";
|
|
222
232
|
} else if (!hasSimd()) {
|
|
223
233
|
advice = "This engine has no WebAssembly SIMD, which the module needs (Chrome and Edge 91, Firefox 89, Safari 16.4, Node 16.4 or newer).";
|
|
234
|
+
} else if (gzipped) {
|
|
235
|
+
// Engines word this differently (V8 and Firefox name the magic number, Safari doesn't), so it goes by the bytes.
|
|
236
|
+
reason = `the bytes given to init({ wasm }) are gzipped (they start with 1f 8b), not a WebAssembly module (${reason})`;
|
|
237
|
+
advice = "Decompress them first, for example with new Response(new Blob([bytes]).stream().pipeThrough(new DecompressionStream('gzip'))).arrayBuffer(), and pass the result (see Plugins and single-file hosts in https://github.com/RohanFredriksson/agglomerative-clustering/blob/master/docs/environments.md).";
|
|
224
238
|
} else if (/magic (word|number)|BufferSource argument is empty|wasm validation error: at offset [0-4]:/i.test(text)) {
|
|
225
239
|
// What a 404 page, or a server's fallback HTML page, looks like once it has been compiled as WebAssembly.
|
|
226
240
|
if (given === true) {
|
|
@@ -250,16 +264,21 @@ const wasmLoadFailed = (cause, given) => {
|
|
|
250
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).`;
|
|
251
265
|
} else if (isNodeLike) {
|
|
252
266
|
// The glue's `new URL('clustering.wasm', import.meta.url)`, with import.meta emptied by a CommonJS bundle.
|
|
253
|
-
if (
|
|
267
|
+
if (badUrl.test(reason)) {
|
|
254
268
|
reason = "the package doesn't know where clustering.wasm is (bundled into CommonJS, it has lost its own URL)";
|
|
255
269
|
}
|
|
256
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}`;
|
|
257
271
|
} else if (!isBrowserLike()) {
|
|
258
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.
|
|
259
|
-
if (
|
|
273
|
+
if (badUrl.test(reason)) {
|
|
260
274
|
reason = "the package can't tell where clustering.wasm is in this runtime";
|
|
261
275
|
}
|
|
262
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).";
|
|
263
282
|
} else {
|
|
264
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 }).";
|
|
265
284
|
}
|
|
@@ -398,13 +417,16 @@ const acquire = async options => {
|
|
|
398
417
|
// way Node resolves packages, from the working directory; if that fails too, the first error is reported.
|
|
399
418
|
const fallback = wasm === undefined && isNodeLike ? await packagedWasm().catch(() => null) : null;
|
|
400
419
|
if (!fallback) {
|
|
401
|
-
throw wasmLoadFailed(error, typeof wasm === 'string' ? wasm : isURL(wasm) ? wasm.href : wasm !== undefined);
|
|
420
|
+
throw wasmLoadFailed(error, typeof wasm === 'string' ? wasm : isURL(wasm) ? wasm.href : wasm !== undefined, isGzipped(wasm));
|
|
402
421
|
}
|
|
403
422
|
instance = await instantiate(fallback).catch(() => {
|
|
404
423
|
throw wasmLoadFailed(error, false);
|
|
405
424
|
});
|
|
406
425
|
}
|
|
407
426
|
checkWasmVersion(instance);
|
|
427
|
+
if (instance.HEAPU8) {
|
|
428
|
+
startSizes.set(instance, instance.HEAPU8.length);
|
|
429
|
+
}
|
|
408
430
|
Module = instance;
|
|
409
431
|
return instance;
|
|
410
432
|
})().catch(error => {
|
|
@@ -436,10 +458,14 @@ const discard = instance => {
|
|
|
436
458
|
// WebAssembly memory only grows: an instance that once held a huge image keeps all that memory for the life of the process.
|
|
437
459
|
// So when a call leaves the heap larger than this, the instance is retired like an aborted one: calls already running keep
|
|
438
460
|
// it, the next call loads a fresh one (a few milliseconds, next to the seconds such an image took), and the old memory is
|
|
439
|
-
// freed when nothing uses it any more.
|
|
440
|
-
|
|
461
|
+
// freed when nothing uses it any more. The limit counts growth from the size the instance started at (32 MB in the
|
|
462
|
+
// release build), so a build that starts larger, such as the sanitized one scripts/asan-test.sh uses (512 MB, for its
|
|
463
|
+
// shadow memory), isn't retired after every call.
|
|
464
|
+
const releaseStart = 32 * 1024 * 1024; // INITIAL_MEMORY in build:wasm
|
|
465
|
+
const retireAfter = 256 * 1024 * 1024 - releaseStart; // so the release build retires above 256 MB, as before
|
|
466
|
+
const startSizes = new WeakMap();
|
|
441
467
|
const retireIfLarge = instance => {
|
|
442
|
-
if (instance.HEAPU8 && instance.HEAPU8.length >
|
|
468
|
+
if (instance.HEAPU8 && instance.HEAPU8.length > (startSizes.get(instance) ?? releaseStart) + retireAfter) {
|
|
443
469
|
discard(instance);
|
|
444
470
|
}
|
|
445
471
|
};
|
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.
|
|
@@ -115,7 +119,13 @@ const isBrowserLike = () => typeof document !== 'undefined' || typeof WorkerGlob
|
|
|
115
119
|
const deployAdvice = "In a serverless deployment (AWS Lambda, Vercel or Netlify functions), the bundler or file tracer may have left the package's dist/ files out: include node_modules/agglomerative-clustering/dist in the function's files, or leave the package unbundled (external).";
|
|
116
120
|
// Emscripten appends advice about its own debug build, which doesn't apply to this package's users.
|
|
117
121
|
const assertionsAdvice = /\s*\(?Build with -sASSERTIONS for more info\.?\)?/;
|
|
118
|
-
|
|
122
|
+
// Whether init({ wasm }) was given bytes that start with gzip's magic (1f 8b): a gzipped module passed without decompressing.
|
|
123
|
+
const isGzipped = wasm => {
|
|
124
|
+
const tag = Object.prototype.toString.call(wasm);
|
|
125
|
+
const bytes = tag === '[object ArrayBuffer]' ? new Uint8Array(wasm) : ArrayBuffer.isView(wasm) ? new Uint8Array(wasm.buffer, wasm.byteOffset, wasm.byteLength) : null;
|
|
126
|
+
return bytes !== null && bytes.length >= 2 && bytes[0] === 0x1f && bytes[1] === 0x8b;
|
|
127
|
+
};
|
|
128
|
+
const wasmLoadFailed = (cause, given, gzipped = false) => {
|
|
119
129
|
const text = String(cause && cause.message !== undefined ? cause.message : cause).split('\n')[0];
|
|
120
130
|
// Emscripten wraps a failed compile in Aborted(...), which is how it stops itself, not part of the reason.
|
|
121
131
|
let reason = text.replace(assertionsAdvice, '').trim().replace(/\.+$/, '');
|
|
@@ -146,6 +156,10 @@ const wasmLoadFailed = (cause, given) => {
|
|
|
146
156
|
advice = "A Content-Security-Policy blocks compiling WebAssembly: add 'wasm-unsafe-eval' to the script-src of the policy that applies. That is the page's for a page and for the worker entry's worker (also when started from a content script, whose worker follows the page's policy); for a browser extension's own pages, offscreen document and service worker, it is content_security_policy.extension_pages in the manifest.";
|
|
147
157
|
} else if (!hasSimd()) {
|
|
148
158
|
advice = "This engine has no WebAssembly SIMD, which the module needs (Chrome and Edge 91, Firefox 89, Safari 16.4, Node 16.4 or newer).";
|
|
159
|
+
} else if (gzipped) {
|
|
160
|
+
// Engines word this differently (V8 and Firefox name the magic number, Safari doesn't), so it goes by the bytes.
|
|
161
|
+
reason = `the bytes given to init({ wasm }) are gzipped (they start with 1f 8b), not a WebAssembly module (${reason})`;
|
|
162
|
+
advice = "Decompress them first, for example with new Response(new Blob([bytes]).stream().pipeThrough(new DecompressionStream('gzip'))).arrayBuffer(), and pass the result (see Plugins and single-file hosts in https://github.com/RohanFredriksson/agglomerative-clustering/blob/master/docs/environments.md).";
|
|
149
163
|
} else if (/magic (word|number)|BufferSource argument is empty|wasm validation error: at offset [0-4]:/i.test(text)) {
|
|
150
164
|
// What a 404 page, or a server's fallback HTML page, looks like once it has been compiled as WebAssembly.
|
|
151
165
|
if (given === true) {
|
|
@@ -175,16 +189,21 @@ const wasmLoadFailed = (cause, given) => {
|
|
|
175
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).`;
|
|
176
190
|
} else if (isNodeLike) {
|
|
177
191
|
// The glue's `new URL('clustering.wasm', import.meta.url)`, with import.meta emptied by a CommonJS bundle.
|
|
178
|
-
if (
|
|
192
|
+
if (badUrl.test(reason)) {
|
|
179
193
|
reason = "the package doesn't know where clustering.wasm is (bundled into CommonJS, it has lost its own URL)";
|
|
180
194
|
}
|
|
181
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}`;
|
|
182
196
|
} else if (!isBrowserLike()) {
|
|
183
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.
|
|
184
|
-
if (
|
|
198
|
+
if (badUrl.test(reason)) {
|
|
185
199
|
reason = "the package can't tell where clustering.wasm is in this runtime";
|
|
186
200
|
}
|
|
187
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).";
|
|
188
207
|
} else {
|
|
189
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 }).";
|
|
190
209
|
}
|
|
@@ -323,13 +342,16 @@ const acquire = async options => {
|
|
|
323
342
|
// way Node resolves packages, from the working directory; if that fails too, the first error is reported.
|
|
324
343
|
const fallback = wasm === undefined && isNodeLike ? await packagedWasm().catch(() => null) : null;
|
|
325
344
|
if (!fallback) {
|
|
326
|
-
throw wasmLoadFailed(error, typeof wasm === 'string' ? wasm : isURL(wasm) ? wasm.href : wasm !== undefined);
|
|
345
|
+
throw wasmLoadFailed(error, typeof wasm === 'string' ? wasm : isURL(wasm) ? wasm.href : wasm !== undefined, isGzipped(wasm));
|
|
327
346
|
}
|
|
328
347
|
instance = await instantiate(fallback).catch(() => {
|
|
329
348
|
throw wasmLoadFailed(error, false);
|
|
330
349
|
});
|
|
331
350
|
}
|
|
332
351
|
checkWasmVersion(instance);
|
|
352
|
+
if (instance.HEAPU8) {
|
|
353
|
+
startSizes.set(instance, instance.HEAPU8.length);
|
|
354
|
+
}
|
|
333
355
|
Module = instance;
|
|
334
356
|
return instance;
|
|
335
357
|
})().catch(error => {
|
|
@@ -360,10 +382,14 @@ const discard = instance => {
|
|
|
360
382
|
// WebAssembly memory only grows: an instance that once held a huge image keeps all that memory for the life of the process.
|
|
361
383
|
// So when a call leaves the heap larger than this, the instance is retired like an aborted one: calls already running keep
|
|
362
384
|
// it, the next call loads a fresh one (a few milliseconds, next to the seconds such an image took), and the old memory is
|
|
363
|
-
// freed when nothing uses it any more.
|
|
364
|
-
|
|
385
|
+
// freed when nothing uses it any more. The limit counts growth from the size the instance started at (32 MB in the
|
|
386
|
+
// release build), so a build that starts larger, such as the sanitized one scripts/asan-test.sh uses (512 MB, for its
|
|
387
|
+
// shadow memory), isn't retired after every call.
|
|
388
|
+
const releaseStart = 32 * 1024 * 1024; // INITIAL_MEMORY in build:wasm
|
|
389
|
+
const retireAfter = 256 * 1024 * 1024 - releaseStart; // so the release build retires above 256 MB, as before
|
|
390
|
+
const startSizes = new WeakMap();
|
|
365
391
|
const retireIfLarge = instance => {
|
|
366
|
-
if (instance.HEAPU8 && instance.HEAPU8.length >
|
|
392
|
+
if (instance.HEAPU8 && instance.HEAPU8.length > (startSizes.get(instance) ?? releaseStart) + retireAfter) {
|
|
367
393
|
discard(instance);
|
|
368
394
|
}
|
|
369
395
|
};
|
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",
|