From b2a72658f1097bfa874992fdd4547f5c6af6207e Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 2 Jul 2025 09:53:50 -0400 Subject: [PATCH 1/3] Allow Chrome to load speech worker from CDN in a page from a file:// URL --- components/mjs/a11y/speech/speech.js | 2 +- components/mjs/a11y/sre/worker/config.json | 1 - ts/a11y/sre/package.json | 3 --- ts/a11y/sre/speech-worker.ts | 11 ++++++----- ts/adaptors/HTMLAdaptor.ts | 4 ++-- 5 files changed, 9 insertions(+), 12 deletions(-) delete mode 100644 ts/a11y/sre/package.json diff --git a/components/mjs/a11y/speech/speech.js b/components/mjs/a11y/speech/speech.js index d17ba6d74..a4c474b4d 100644 --- a/components/mjs/a11y/speech/speech.js +++ b/components/mjs/a11y/speech/speech.js @@ -14,7 +14,7 @@ if (MathJax.loader) { } else { const REQUIRE = typeof require !== 'undefined' ? require : MathJax.config.loader.require; if (REQUIRE?.resolve) { - path = REQUIRE.resolve(`${path}/package.json`).replace(/\/[^\/]*$/, ''); + path = REQUIRE.resolve(`${path}/require.mjs`).replace(/\/[^\/]*$/, ''); maps = REQUIRE.resolve(`${maps}/base.json`).replace(/\/[^\/]*$/, ''); } else { path = maps = ''; diff --git a/components/mjs/a11y/sre/worker/config.json b/components/mjs/a11y/sre/worker/config.json index cc2247763..c1303a29f 100644 --- a/components/mjs/a11y/sre/worker/config.json +++ b/components/mjs/a11y/sre/worker/config.json @@ -6,7 +6,6 @@ "to": "../../../../../bundle/sre", "from": "../../../../../ts/a11y/sre", "copy": [ - "package.json", "require.mjs", "require.d.mts" ] diff --git a/ts/a11y/sre/package.json b/ts/a11y/sre/package.json deleted file mode 100644 index 3dbc1ca59..000000000 --- a/ts/a11y/sre/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/ts/a11y/sre/speech-worker.ts b/ts/a11y/sre/speech-worker.ts index ac2da3fed..fa8adf7e6 100644 --- a/ts/a11y/sre/speech-worker.ts +++ b/ts/a11y/sre/speech-worker.ts @@ -110,11 +110,12 @@ declare const SRE: any; // // Load SRE // - await import('./sre.js') - .catch((_) => import(/* webpackIgnore: true */ './sre-lab.js')) // for use in the lab - .then((SRE) => { - global.SRE = SRE; - }); + await ( + global.isLab + ? import(/* webpackIgnore: true */ './sre-lab.js') // for use in the lab + : import('./sre.js') + ) + .then((SRE) => (global.SRE = SRE)); /*****************************************************************/ diff --git a/ts/adaptors/HTMLAdaptor.ts b/ts/adaptors/HTMLAdaptor.ts index 1e48c5344..c1a9d68dc 100644 --- a/ts/adaptors/HTMLAdaptor.ts +++ b/ts/adaptors/HTMLAdaptor.ts @@ -627,12 +627,12 @@ export class HTMLAdaptor< const file = `${path}/${worker}`; const content = ` self.maps = '${quoted(maps)}'; - import('${quoted(file)}'); + importScripts('${quoted(file)}'); `; const url = URL.createObjectURL( new Blob([content], { type: 'text/javascript' }) ); - const webworker = new Worker(url, { type: 'module' }); + const webworker = new Worker(url); webworker.onmessage = listener; URL.revokeObjectURL(url); return webworker; From 9d140d35a23e15bdae6650d06cb708d9e65f8bf8 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 2 Jul 2025 10:29:25 -0400 Subject: [PATCH 2/3] Don't need to make the worker be a module anymore --- components/mjs/a11y/sre/worker/webpack.cjs | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/mjs/a11y/sre/worker/webpack.cjs b/components/mjs/a11y/sre/worker/webpack.cjs index 29b5bc4de..43ef657fa 100644 --- a/components/mjs/a11y/sre/worker/webpack.cjs +++ b/components/mjs/a11y/sre/worker/webpack.cjs @@ -1,8 +1,6 @@ const webpack = require('webpack'); module.exports = (pkg) => { - pkg.experiments = {outputModule: true}; - pkg.output.library = {type: 'module'}; pkg.plugins.push( new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1, From e6b134d34409e721cb3fbf3017de701448d3e0fe Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 9 Jul 2025 16:28:00 -0400 Subject: [PATCH 3/3] Fix formatting --- ts/a11y/sre/speech-worker.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ts/a11y/sre/speech-worker.ts b/ts/a11y/sre/speech-worker.ts index fa8adf7e6..3dd12a20a 100644 --- a/ts/a11y/sre/speech-worker.ts +++ b/ts/a11y/sre/speech-worker.ts @@ -114,8 +114,7 @@ declare const SRE: any; global.isLab ? import(/* webpackIgnore: true */ './sre-lab.js') // for use in the lab : import('./sre.js') - ) - .then((SRE) => (global.SRE = SRE)); + ).then((SRE) => (global.SRE = SRE)); /*****************************************************************/