@pie-element/shared-math-rendering-mathjax 0.1.2 → 0.1.3-next.20261007003844

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.
@@ -0,0 +1,42 @@
1
+ /**
2
+ * MathJax generates speech in a web worker it starts from a `blob:` script that imports
3
+ * `speech-worker.js` from the speech path. A worker that never starts, because the page's content
4
+ * security policy refuses it or its script fails to load, leaves every speech task waiting for it,
5
+ * and with them the typeset that asked for speech and every typeset after it. A document whose
6
+ * worker fails before it is ready ends speech instead: the waiting tasks fail, later ones fail at
7
+ * once, and math goes on rendering without speech, braille or the explorer.
8
+ *
9
+ * The browser build starts the worker itself, from the speech directory or the URLs a bundle lists
10
+ * for its files.
11
+ */
12
+ import { type MathjaxAssets } from './assets.js';
13
+ /** The parts of MathJax's `WorkerHandler` this module uses. */
14
+ interface WorkerHandler {
15
+ ready: boolean;
16
+ Post: (...args: unknown[]) => Promise<unknown>;
17
+ Terminate: () => unknown;
18
+ }
19
+ /** The parts of a MathJax 4 document with speech that this module uses. */
20
+ export interface SpeechDocument {
21
+ adaptor?: {
22
+ createWorker?: (listener: unknown, options: unknown) => Promise<Worker>;
23
+ };
24
+ webworker?: WorkerHandler | null;
25
+ options?: {
26
+ enableSpeech?: boolean;
27
+ enableBraille?: boolean;
28
+ speechError?: (...args: unknown[]) => void;
29
+ };
30
+ }
31
+ /** Ends speech for `mathDocument` when a worker it starts fails before it is ready. */
32
+ export declare function endSpeechOnWorkerFailure(mathDocument: SpeechDocument | undefined): void;
33
+ /**
34
+ * The `blob:` script of the speech worker for `assets`. As MathJax's adaptor writes it, it sets the
35
+ * mathmaps directory and imports `speech-worker.js`, which fetches each mathmap as
36
+ * `<self.maps>/<file>`; a mathmap `assets.urls` lists is fetched from its URL. Undefined without a
37
+ * speech worker.
38
+ */
39
+ export declare function speechWorkerScript(assets: MathjaxAssets): string | undefined;
40
+ /** Starts a worker running `script` from a `blob:` URL, as MathJax's adaptor does. */
41
+ export declare function startWorker(script: string, listener: (event: MessageEvent) => void): Worker;
42
+ export {};
package/dist/types.d.ts CHANGED
@@ -19,10 +19,38 @@ export interface MathjaxOptions {
19
19
  */
20
20
  loadFonts?: boolean;
21
21
  /**
22
- * Override the MathJax script URL. Defaults to MathJax 4.1.3 `tex-mml-chtml.js` on jsDelivr.
23
- * The browser ESM build bundles its MathJax and ignores it.
22
+ * Override the MathJax script URL, which defaults to `mathjax@4.1.3/tex-mml-chtml.js` under the
23
+ * asset root. The browser ESM build bundles its MathJax and ignores it.
24
24
  */
25
25
  srcUrl?: string;
26
+ /**
27
+ * The npm root MathJax's files load from: a URL under which `<package>@<version>/<path>` serves
28
+ * that file of the package, such as `https://cdn.jsdelivr.net/npm`. Defaults to the page's
29
+ * `window['@pie-lib/math-rendering@2'].opts.assetRoot`, then to the npm root of the URL this
30
+ * module loaded from. With none, the browser ESM build renders without web fonts and speech, and
31
+ * the npm build loads no MathJax unless `srcUrl` names one.
32
+ */
33
+ assetRoot?: string;
34
+ /**
35
+ * The URL of individual files, by npm path: `{ '@mathjax/mathjax-newcm-font@4.1.3/chtml/woff2/
36
+ * mjx-ncm-n.woff2': url }`. A listed file loads from its URL, others from the asset root and
37
+ * `speechPath`. Defaults to the page's `opts.assetUrls`. A bundle gives each file a
38
+ * `new URL('./…', import.meta.url)` here, which its host's bundler emits. Read by the browser ESM
39
+ * build, for its fonts, speech worker and mathmaps; the npm build's MathJax loads its files
40
+ * itself and ignores it.
41
+ */
42
+ assetUrls?: Readonly<Record<string, string>>;
43
+ /**
44
+ * The directory of the speech worker, `speech-worker.js`, and its rule files, `mathmaps/`.
45
+ * Defaults to the page's `opts.speechPath`, then to `mathjax@4.1.3/sre` under the asset root.
46
+ */
47
+ speechPath?: string;
48
+ /**
49
+ * The speech locales the MathJax menu lists, by locale id, with a menu label for each when given
50
+ * as an object. A locale SRE does not ship needs a speech worker built with it. Defaults to the
51
+ * page's `opts.speechLocales`, then to every locale SRE ships.
52
+ */
53
+ speechLocales?: readonly string[] | Readonly<Record<string, string>>;
26
54
  }
27
55
  /**
28
56
  * Shared renderer contract used by players.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/shared-math-rendering-mathjax",
3
- "version": "0.1.2",
3
+ "version": "0.1.3-next.20261007003844",
4
4
  "description": "MathJax adapter for PIE math rendering",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -10,7 +10,8 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "pie-browser-esm": "./dist/browser/index.js",
12
12
  "default": "./dist/index.js"
13
- }
13
+ },
14
+ "./package.json": "./package.json"
14
15
  },
15
16
  "files": [
16
17
  "dist"
@@ -23,6 +24,13 @@
23
24
  "clean": "rm -rf dist"
24
25
  },
25
26
  "dependencies": {},
27
+ "pie": {
28
+ "assetPackages": {
29
+ "mathjax": "4.1.3",
30
+ "@mathjax/mathjax-newcm-font": "4.1.3",
31
+ "@mathjax/mathjax-mhchem-font-extension": "4.1.3"
32
+ }
33
+ },
26
34
  "publishConfig": {
27
35
  "access": "public"
28
36
  },