@danielsimonjr/sciengjs 0.3.1 → 0.4.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/README.md CHANGED
@@ -10,7 +10,7 @@ sciengjs turns diagram source into images on your own machine. It sends no sourc
10
10
 
11
11
  ## What this release does
12
12
 
13
- Release 0.3.1 holds three input types: **Graphviz DOT**, **Mermaid** (every diagram type) and **HTML** (to PNG and PDF). The browser stage draws the Mermaid types other than class, state and sequence, and every PDF.
13
+ Release 0.4.0 holds four input types: **Graphviz DOT**, **Mermaid** (every diagram type), **LaTeX math** (to SVG, PNG and PDF) and **HTML** (to PNG and PDF). The browser stage draws the Mermaid types other than class, state and sequence, and every PDF.
14
14
 
15
15
  | Input | Output | Engine |
16
16
  |---|---|---|
@@ -82,7 +82,7 @@ for (const pair of await capabilities()) {
82
82
  }
83
83
  ```
84
84
 
85
- `capabilities` reports each input and output pair of the design, the stage that the pair needs, and whether the stage is ready here. In this release only `dot -> svg` and `dot -> png` are ready.
85
+ `capabilities` reports each input and output pair of the design, the stage that the pair needs, and whether the stage is ready here. Ready pairs include `dot -> svg`, `dot -> png`, `math -> svg` and `math -> png`. A pair that needs the browser stage is ready only when a browser is configured.
86
86
 
87
87
  ## Errors
88
88
 
@@ -99,7 +99,7 @@ try {
99
99
  | Code | Means |
100
100
  |---|---|
101
101
  | `E_INPUT` | the source or an option is not valid |
102
- | `E_UNSUPPORTED` | this build has no backend for the pair, for example `math` to `svg` |
102
+ | `E_UNSUPPORTED` | this build has no backend for the pair, for example `tikz` to `svg` |
103
103
  | `E_LIMIT` | the source, the heap or the PNG pixels are over a limit |
104
104
  | `E_TIMEOUT` | the render took longer than `timeoutMs` |
105
105
  | `E_STAGE_MISSING` | a file that a stage needs, for example the bundled font, is missing |
@@ -157,6 +157,19 @@ const { bytes, warnings } = await render({ type: "mermaid", source, format: "svg
157
157
 
158
158
  Other Mermaid diagram types (for example flowchart and gantt) go through the browser stage. They need `SCIENG_BROWSER`. Without it they reject with `E_STAGE_MISSING`. The pinned Mermaid build ships in the package, and the browser stage serves it to the page, so no request leaves the process.
159
159
 
160
+ ## Math
161
+
162
+ The `math` input renders LaTeX math through MathJax. The output draws each glyph as a path, so it needs no font. The packages `ams`, `boldsymbol`, `color` and `mhchem` are loaded. A `\require` of a loaded package has no effect. A `\require` of a different package rejects with `E_UNSUPPORTED`. A character that the math font does not hold also rejects with `E_UNSUPPORTED`. The message names the character.
163
+
164
+ A `png` takes the option `scale` (a finite number above 0, default 1). The `svg` takes no option.
165
+
166
+ ```js
167
+ import { render } from "@danielsimonjr/sciengjs";
168
+
169
+ const svg = await render({ type: "math", source: "\\frac{a}{b}", format: "svg" });
170
+ const png = await render({ type: "math", source: "\\ce{H2O + CO2 -> H2CO3}", format: "png", options: { scale: 2 } });
171
+ ```
172
+
160
173
  ## Roadmap
161
174
 
162
175
  The [build plan](docs/superpowers/plans/2026-11-01-scieng-engine-build.md) gives the order of the increments. Each increment adds one input type, its tests and one release. The [design](docs/superpowers/specs/2026-11-01-scieng-engine-design.md) gives the API, the stages, the security controls and the licence of each engine.
@@ -165,7 +178,7 @@ The [build plan](docs/superpowers/plans/2026-11-01-scieng-engine-build.md) gives
165
178
  |---|---|---|
166
179
  | DOT | graph, raster | released in 0.1.0 |
167
180
  | Mermaid | graph, mermaid, browser | class, state and sequence: released in 0.2.0; other types: released in 0.3.0 |
168
- | LaTeX math | math (MathJax) | planned |
181
+ | LaTeX math | math (MathJax) | svg, png and pdf are built; pdf needs the browser stage |
169
182
  | TikZ, circuitikz, LaTeX | tex (an own WASM build of `tex.web`) | trial builds pass |
170
183
  | Plots | plot | planned |
171
184
  | SysML v2 | sysml | planned |
@@ -11,7 +11,7 @@ Version: each row gives the version that the engine pins.
11
11
  | Stage | Engine | Licence | Status |
12
12
  |---|---|---|---|
13
13
  | graph | `@viz-js/viz` 3.31.0 (Graphviz 16.1.0 compiled to WASM) | Wrapper: MIT. Graphviz: EPL-2.0 | a dependency |
14
- | math | `@mathjax/src` | Apache-2.0 | not yet a dependency |
14
+ | math | `@mathjax/src` 4.1.3 (MathJax, with the Newcm math font and the packages it installs; see "MathJax") | Apache-2.0 for MathJax and the math font; the other packages are listed under "MathJax" | a dependency |
15
15
  | tex | The own WASM build of `tex.web` with `etex.ch` (trials T5 and T6) | The "tex" stage of the design gives the licence of each input | not yet a dependency |
16
16
  | tex | TeX packages (bundles) | LPPL or public domain only. Each package keeps its own licence | not yet a dependency |
17
17
  | mesh | `occt-import-js` (OpenCascade compiled to WASM) | LGPL-2.1 | not yet a dependency |
@@ -29,6 +29,33 @@ Version: each row gives the version that the engine pins.
29
29
 
30
30
  The Eclipse Public License 2.0 applies to Graphviz. The MIT licence applies to the wrapper `@viz-js/viz`. The package does not ship a Graphviz licence file. The licence text of Graphviz is in `assets/licenses/EPL-2.0.txt`. The MIT licence text of the wrapper is in `assets/licenses/MIT-viz-js.txt`, copied from the tag `release-viz-3.31.0` of the source repository https://github.com/mdaines/viz-js. The npm package does not ship this file.
31
31
 
32
+ ### MathJax (Apache-2.0, with other licences for transitive packages)
33
+
34
+ `@mathjax/src` 4.1.3 and `@mathjax/mathjax-newcm-font` 4.1.3 are under the Apache License 2.0. The math stage bundles the font ranges into the package. The package installs the packages in the table below. The engine loads `@mathjax/src` only, so the other packages are not in the render path. The table gives each installed package, its version and its licence, from its `package.json`.
35
+
36
+ | Package | Version | Licence |
37
+ |---|---|---|
38
+ | `@mathjax/src` | 4.1.3 | Apache-2.0 |
39
+ | `@mathjax/mathjax-newcm-font` | 4.1.3 | Apache-2.0 |
40
+ | `mhchemparser` | 4.2.1 | Apache-2.0 |
41
+ | `mj-context-menu` | 1.0.0 | Apache-2.0 |
42
+ | `speech-rule-engine` | 5.0.0-rc.4 | Apache-2.0 |
43
+ | `@xmldom/xmldom` | 0.9.12 | MIT |
44
+ | `wicked-good-xpath` | 1.3.0 | MIT |
45
+ | `commander` | 14.0.3 (installed under `speech-rule-engine`) | MIT |
46
+ | `balanced-match` | 4.0.4 | MIT |
47
+ | `brace-expansion` | 5.0.12 | MIT |
48
+ | `@isaacs/nonrecursive-glob-match` | 1.0.3 | BlueOak-1.0.0 |
49
+ | `glob` | 14.0.3 | BlueOak-1.0.0 |
50
+ | `minimatch` | 11.0.4 | BlueOak-1.0.0 |
51
+ | `minipass` | 7.1.3 | BlueOak-1.0.0 |
52
+ | `package-json-from-dist` | 1.0.1 | BlueOak-1.0.0 |
53
+ | `path-scurry` | 3.0.0 | BlueOak-1.0.0 |
54
+ | `lru-cache` | 11.5.3 | BlueOak-1.0.0 |
55
+ | `rimraf` | 6.1.4 | BlueOak-1.0.0 |
56
+
57
+ The Apache License 2.0 applies to the MathJax packages. The BlueOak Model License 1.0.0 applies to the glob packages. The MIT licence applies to the other packages. Each package keeps its own licence text in its installed folder. The `dist/` folder holds the compiled code of this package only. It holds no code of the packages in the table: npm installs them as dependencies.
58
+
32
59
  ### Mermaid (MIT)
33
60
 
34
61
  The MIT licence applies to `mermaid` 11.17.2. The build writes the file mermaid.min.js into the assets folder. That file is generated at build time and is not committed. The licence text is in `assets/licenses/MIT-mermaid.txt`.
@@ -0,0 +1,3 @@
1
+ import type { BackendOutput, WorkerJob } from "../worker/protocol.ts";
2
+ /** Renders math to pdf: the SVG of the formula, then the pdf of that SVG in the browser stage. The backend takes no options. */
3
+ export declare function render(request: WorkerJob["request"]): Promise<BackendOutput>;
@@ -0,0 +1,14 @@
1
+ import { RenderError } from "../errors.js";
2
+ import { drawSvgToPdf } from "../mermaid/browser.js";
3
+ import { mathToSvg } from "./tex.js";
4
+ /** Renders math to pdf: the SVG of the formula, then the pdf of that SVG in the browser stage. The backend takes no options. */
5
+ export async function render(request) {
6
+ const names = Object.keys(request.options);
7
+ if (names.length > 0) {
8
+ throw new RenderError("E_INPUT", "math to pdf takes no options; got " + names.join(", "));
9
+ }
10
+ const svg = await mathToSvg(String(request.source), { display: true });
11
+ const draw = await drawSvgToPdf(svg, request.settings);
12
+ return { bytes: draw.bytes, warnings: draw.warnings, backend: "math/mathjax+browser/chromium" };
13
+ }
14
+ //# sourceMappingURL=backend-pdf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-pdf.js","sourceRoot":"","sources":["../../src/math/backend-pdf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,gIAAgI;AAChI,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAA6B;IACxD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,WAAW,CAAC,SAAS,EAAE,oCAAoC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5F,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACvE,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvD,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,+BAA+B,EAAE,CAAC;AAClG,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { BackendOutput, WorkerJob } from "../worker/protocol.ts";
2
+ /** Renders math to png: the SVG of the formula, then the PNG of that SVG at the option scale. */
3
+ export declare function render(request: WorkerJob["request"]): Promise<BackendOutput>;
@@ -0,0 +1,15 @@
1
+ import { RenderError } from "../errors.js";
2
+ import { readScale, svgDocumentToPng } from "../graph/backend-png.js";
3
+ import { mathToSvg } from "./tex.js";
4
+ /** Renders math to png: the SVG of the formula, then the PNG of that SVG at the option scale. */
5
+ export async function render(request) {
6
+ for (const key of Object.keys(request.options)) {
7
+ if (key !== "scale") {
8
+ throw new RenderError("E_INPUT", "math to png takes no option " + key);
9
+ }
10
+ }
11
+ const scale = readScale(request.options);
12
+ const svg = await mathToSvg(String(request.source), { display: true });
13
+ return svgDocumentToPng(svg, request, scale);
14
+ }
15
+ //# sourceMappingURL=backend-png.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-png.js","sourceRoot":"","sources":["../../src/math/backend-png.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEtE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,iGAAiG;AACjG,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAA6B;IACxD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/C,IAAI,GAAG,KAAK,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,WAAW,CAAC,SAAS,EAAE,8BAA8B,GAAG,GAAG,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;IACD,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACvE,OAAO,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { BackendOutput, WorkerJob } from "../worker/protocol.ts";
2
+ /** Renders math to svg. The backend takes no options, so any option is an input error. */
3
+ export declare function render(request: WorkerJob["request"]): Promise<BackendOutput>;
@@ -0,0 +1,12 @@
1
+ import { RenderError } from "../errors.js";
2
+ import { mathToSvg } from "./tex.js";
3
+ /** Renders math to svg. The backend takes no options, so any option is an input error. */
4
+ export async function render(request) {
5
+ const names = Object.keys(request.options);
6
+ if (names.length > 0) {
7
+ throw new RenderError("E_INPUT", "math to svg takes no options; got " + names.join(", "));
8
+ }
9
+ const svg = await mathToSvg(String(request.source), { display: true });
10
+ return { bytes: new TextEncoder().encode(svg), warnings: [] };
11
+ }
12
+ //# sourceMappingURL=backend-svg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-svg.js","sourceRoot":"","sources":["../../src/math/backend-svg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,0FAA0F;AAC1F,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAA6B;IACxD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3C,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,WAAW,CAAC,SAAS,EAAE,oCAAoC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5F,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACvE,OAAO,EAAE,KAAK,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;AAChE,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Static imports of every dynamic font range of MathJax-Newcm, the default math font. Each import
3
+ * registers one range with the font class. loadFontRanges() copies the ranges into a font instance,
4
+ * so no range loads at run time and no network or file fetch happens.
5
+ */
6
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/PUA.js";
7
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/accents-b-i.js";
8
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/accents.js";
9
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/arabic.js";
10
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/arrows.js";
11
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/braille-d.js";
12
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/braille.js";
13
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/calligraphic.js";
14
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/cherokee.js";
15
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/cyrillic-ss.js";
16
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/cyrillic.js";
17
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/devanagari.js";
18
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/double-struck.js";
19
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/fraktur.js";
20
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/greek-ss.js";
21
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/greek.js";
22
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/hebrew.js";
23
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/latin-b.js";
24
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/latin-bi.js";
25
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/latin-i.js";
26
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/latin.js";
27
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/marrows.js";
28
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/math.js";
29
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/monospace-ex.js";
30
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/monospace-l.js";
31
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/monospace.js";
32
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/mshapes.js";
33
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/phonetics-ss.js";
34
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/phonetics.js";
35
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/sans-serif-b.js";
36
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/sans-serif-bi.js";
37
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/sans-serif-ex.js";
38
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/sans-serif-i.js";
39
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/sans-serif-r.js";
40
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/sans-serif.js";
41
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/script.js";
42
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/shapes.js";
43
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/symbols-b-i.js";
44
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/symbols.js";
45
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/variants.js";
46
+ /** Copies every dynamic range of the font class into the font instance. Synchronous; no file read. */
47
+ export declare function loadFontRanges(font: object): void;
48
+ /**
49
+ * The private-use arrow code points of the TeX mhchem extension, each with the standard arrow that
50
+ * the bundled font holds. The mhchem font extension, which owns the private-use glyphs, is not installed.
51
+ */
52
+ export declare const MHCHEM_ALIASES: ReadonlyArray<readonly [pua: number, real: number]>;
53
+ /**
54
+ * Adds the variant -mhchem to a font instance and gives each mhchem arrow code point the glyph of its
55
+ * standard arrow. The alias goes into the -mhchem variant (plain arrows) and the normal variant
56
+ * (labelled arrows such as `->[x]`, which MathJax draws in the normal variant). The stretchy delimiter
57
+ * data of the standard arrow also goes to the code point, so a labelled arrow stretches.
58
+ */
59
+ export declare function defineMhchemVariant(font: object): void;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Static imports of every dynamic font range of MathJax-Newcm, the default math font. Each import
3
+ * registers one range with the font class. loadFontRanges() copies the ranges into a font instance,
4
+ * so no range loads at run time and no network or file fetch happens.
5
+ */
6
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/PUA.js";
7
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/accents-b-i.js";
8
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/accents.js";
9
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/arabic.js";
10
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/arrows.js";
11
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/braille-d.js";
12
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/braille.js";
13
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/calligraphic.js";
14
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/cherokee.js";
15
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/cyrillic-ss.js";
16
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/cyrillic.js";
17
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/devanagari.js";
18
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/double-struck.js";
19
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/fraktur.js";
20
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/greek-ss.js";
21
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/greek.js";
22
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/hebrew.js";
23
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/latin-b.js";
24
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/latin-bi.js";
25
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/latin-i.js";
26
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/latin.js";
27
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/marrows.js";
28
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/math.js";
29
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/monospace-ex.js";
30
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/monospace-l.js";
31
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/monospace.js";
32
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/mshapes.js";
33
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/phonetics-ss.js";
34
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/phonetics.js";
35
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/sans-serif-b.js";
36
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/sans-serif-bi.js";
37
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/sans-serif-ex.js";
38
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/sans-serif-i.js";
39
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/sans-serif-r.js";
40
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/sans-serif.js";
41
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/script.js";
42
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/shapes.js";
43
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/symbols-b-i.js";
44
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/symbols.js";
45
+ import "@mathjax/mathjax-newcm-font/js/svg/dynamic/variants.js";
46
+ /** Copies every dynamic range of the font class into the font instance. Synchronous; no file read. */
47
+ export function loadFontRanges(font) {
48
+ const ranges = font.constructor.dynamicFiles;
49
+ for (const range of Object.values(ranges)) {
50
+ range.setup(font);
51
+ }
52
+ }
53
+ /**
54
+ * The private-use arrow code points of the TeX mhchem extension, each with the standard arrow that
55
+ * the bundled font holds. The mhchem font extension, which owns the private-use glyphs, is not installed.
56
+ */
57
+ export const MHCHEM_ALIASES = [
58
+ [0xe408, 0x21cc], // \mhchemlongrightleftharpoons (<=>) -> right over left harpoons
59
+ [0xe409, 0x21cc], // \mhchemlongRightleftharpoons (<=>>) -> right over left harpoons
60
+ [0xe40a, 0x21cb], // \mhchemlongLeftrightharpoons (<<=>) -> left over right harpoons
61
+ [0xe428, 0x27f5], // \mhchemlongleftarrow (<-) -> long left arrow
62
+ [0xe429, 0x27f6], // \mhchemlongrightarrow (->) -> long right arrow
63
+ [0xe42a, 0x27f7], // \mhchemlongleftrightarrow (<->) -> long left right arrow
64
+ [0xe42b, 0x21c6], // \mhchemlongleftrightarrows (<-->) -> left arrow over right arrow
65
+ [0xe42c, 0x2190], // \mhchemleftarrow -> left arrow
66
+ [0xe42d, 0x2192], // \mhchemrightarrow -> right arrow
67
+ [0xe42e, 0x2194], // \mhchemleftrightarrow -> left right arrow
68
+ ];
69
+ /**
70
+ * Adds the variant -mhchem to a font instance and gives each mhchem arrow code point the glyph of its
71
+ * standard arrow. The alias goes into the -mhchem variant (plain arrows) and the normal variant
72
+ * (labelled arrows such as `->[x]`, which MathJax draws in the normal variant). The stretchy delimiter
73
+ * data of the standard arrow also goes to the code point, so a labelled arrow stretches.
74
+ */
75
+ export function defineMhchemVariant(font) {
76
+ const f = font;
77
+ f.createVariant("-mhchem", "normal");
78
+ const chars = {};
79
+ for (const [pua, real] of MHCHEM_ALIASES) {
80
+ const glyph = f.variant["normal"].chars[real];
81
+ if (glyph === undefined) {
82
+ throw new Error(`the normal variant holds no glyph for U+${real.toString(16).toUpperCase()}`);
83
+ }
84
+ chars[pua] = glyph;
85
+ const delimiter = f.delimiters[real];
86
+ if (delimiter !== undefined && f.delimiters[pua] === undefined) {
87
+ f.delimiters[pua] = { ...delimiter, c: delimiter.c ?? real };
88
+ }
89
+ }
90
+ f.defineChars("normal", chars);
91
+ f.defineChars("-mhchem", chars);
92
+ }
93
+ //# sourceMappingURL=font-ranges.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"font-ranges.js","sourceRo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,EAAE,EAAE,CAAC,CAAC;QAChG,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACnB,MAAM,SAAS,GAAG,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;YAC/D,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,SAAS,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;QAC/D,CAAC;IACH,CAAC;IACD,CAAC,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC,CAAC,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** The math stage: LaTeX math to SVG through MathJax. */
2
+ export { mathToSvg } from "./tex.ts";
3
+ export type { MathOptions } from "./tex.ts";
@@ -0,0 +1,3 @@
1
+ /** The math stage: LaTeX math to SVG through MathJax. */
2
+ export { mathToSvg } from "./tex.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/math/index.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,39 @@
1
+ import "@mathjax/src/js/input/tex/base/BaseConfiguration.js";
2
+ import "@mathjax/src/js/input/tex/ams/AmsConfiguration.js";
3
+ import "@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js";
4
+ import "@mathjax/src/js/input/tex/color/ColorConfiguration.js";
5
+ import "@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js";
6
+ /** The TeX packages that this build holds. Each one is imported above; no other package loads. */
7
+ export declare const MATH_PACKAGES: readonly string[];
8
+ /** Options of one math render. */
9
+ export interface MathOptions {
10
+ /** True for display style (a block), false for inline. */
11
+ display: boolean;
12
+ }
13
+ /**
14
+ * Removes each `\require{...}` command from the source and returns the rest. The build loads every
15
+ * held package before the render and holds no require package, so a `\require` of held packages is a
16
+ * no-op. A `\require` of a package that this build does not hold rejects with E_UNSUPPORTED and names
17
+ * the package. MathJax never fetches a package.
18
+ */
19
+ export declare function stripRequires(source: string): string;
20
+ /**
21
+ * Rejects an SVG that draws a character as system-font text. MathJax writes a `<text>` element with a
22
+ * `font-family` when the math font holds no glyph for a character. Such output depends on the fonts of
23
+ * the viewer, and the PNG stage has no font. The error names each such character and its code point.
24
+ */
25
+ export declare function rejectFontFallback(svg: string): void;
26
+ /** Converts a MathJax size string such as "2.5ex" to pixels, rounded to 3 decimals. */
27
+ export declare function exToPx(value: string): string;
28
+ /**
29
+ * Keeps the `<svg>` element of a MathJax container and sets the standalone attributes:
30
+ * the SVG namespace, the sizes in px and the viewBox. Only the SVG element leaves this function,
31
+ * so the assistive MathML of the container is removed.
32
+ */
33
+ export declare function standaloneSvg(container: string): string;
34
+ /**
35
+ * Renders LaTeX math to a standalone SVG with the glyphs as paths. The XML serializer escapes `<`, `>`,
36
+ * `&` and `"` in the attribute values, so the TeX source in the data-latex attributes keeps the SVG
37
+ * well-formed. Rejects with E_INPUT or E_UNSUPPORTED.
38
+ */
39
+ export declare function mathToSvg(source: string, options: MathOptions): Promise<string>;
@@ -0,0 +1,130 @@
1
+ import { liteAdaptor } from "@mathjax/src/js/adaptors/liteAdaptor.js";
2
+ import { RegisterHTMLHandler } from "@mathjax/src/js/handlers/html.js";
3
+ import { mathjax } from "@mathjax/src/js/mathjax.js";
4
+ import { TeX } from "@mathjax/src/js/input/tex.js";
5
+ import { SVG } from "@mathjax/src/js/output/svg.js";
6
+ import "@mathjax/src/js/input/tex/base/BaseConfiguration.js";
7
+ import "@mathjax/src/js/input/tex/ams/AmsConfiguration.js";
8
+ import "@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js";
9
+ import "@mathjax/src/js/input/tex/color/ColorConfiguration.js";
10
+ import "@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js";
11
+ import { RenderError } from "../errors.js";
12
+ import { defineMhchemVariant, loadFontRanges } from "./font-ranges.js";
13
+ /** The TeX packages that this build holds. Each one is imported above; no other package loads. */
14
+ export const MATH_PACKAGES = ["base", "ams", "boldsymbol", "color", "mhchem"];
15
+ /** Pixels per MathJax ex unit. MathJax reports sizes in ex; the SVG attributes state pixels. */
16
+ const EX_PX = 8;
17
+ /** Matches one `\require{...}` command and captures its package list. */
18
+ const REQUIRE = /\\require\s*\{([^}]*)\}/g;
19
+ /**
20
+ * Removes each `\require{...}` command from the source and returns the rest. The build loads every
21
+ * held package before the render and holds no require package, so a `\require` of held packages is a
22
+ * no-op. A `\require` of a package that this build does not hold rejects with E_UNSUPPORTED and names
23
+ * the package. MathJax never fetches a package.
24
+ */
25
+ export function stripRequires(source) {
26
+ for (const match of source.matchAll(REQUIRE)) {
27
+ for (const raw of match[1].split(",")) {
28
+ const name = raw.trim();
29
+ if (name !== "" && !MATH_PACKAGES.includes(name)) {
30
+ throw new RenderError("E_UNSUPPORTED", `the math stage does not hold the package ${name}`);
31
+ }
32
+ }
33
+ }
34
+ return source.replace(REQUIRE, "");
35
+ }
36
+ /** The five named XML entities, by name. */
37
+ const XML_ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
38
+ /** Decodes the numeric and the five named XML entities of a text. */
39
+ function decodeXml(text) {
40
+ return text.replace(/&(?:#x([0-9A-Fa-f]+)|#(\d+)|(amp|lt|gt|quot|apos));/g, (whole, hex, dec, name) => {
41
+ if (hex !== undefined)
42
+ return String.fromCodePoint(parseInt(hex, 16));
43
+ if (dec !== undefined)
44
+ return String.fromCodePoint(parseInt(dec, 10));
45
+ return XML_ENTITIES[name] ?? whole;
46
+ });
47
+ }
48
+ /**
49
+ * Rejects an SVG that draws a character as system-font text. MathJax writes a `<text>` element with a
50
+ * `font-family` when the math font holds no glyph for a character. Such output depends on the fonts of
51
+ * the viewer, and the PNG stage has no font. The error names each such character and its code point.
52
+ */
53
+ export function rejectFontFallback(svg) {
54
+ if (!svg.includes("<text") && !svg.includes("font-family"))
55
+ return;
56
+ const chars = new Set();
57
+ for (const match of svg.matchAll(/<text\b[^>]*>([^<]*)<\/text>/g)) {
58
+ for (const ch of decodeXml(match[1]))
59
+ chars.add(ch);
60
+ }
61
+ if (chars.size === 0) {
62
+ throw new RenderError("E_UNSUPPORTED", "the math svg uses a system font");
63
+ }
64
+ const names = [...chars].map((ch) => `${ch} (U+${ch.codePointAt(0).toString(16).toUpperCase().padStart(4, "0")})`);
65
+ throw new RenderError("E_UNSUPPORTED", `the math font holds no glyph for ${names.join(", ")}`);
66
+ }
67
+ /** Converts a MathJax size string such as "2.5ex" to pixels, rounded to 3 decimals. */
68
+ export function exToPx(value) {
69
+ const match = /^(-?[\d.]+)ex$/.exec(value);
70
+ if (match === null) {
71
+ throw new RenderError("E_INTERNAL", `unexpected MathJax size: ${value}`);
72
+ }
73
+ return String(Math.round(Number(match[1]) * EX_PX * 1000) / 1000);
74
+ }
75
+ /**
76
+ * Keeps the `<svg>` element of a MathJax container and sets the standalone attributes:
77
+ * the SVG namespace, the sizes in px and the viewBox. Only the SVG element leaves this function,
78
+ * so the assistive MathML of the container is removed.
79
+ */
80
+ export function standaloneSvg(container) {
81
+ const start = container.indexOf("<svg");
82
+ const end = container.lastIndexOf("</svg>");
83
+ if (start === -1 || end === -1) {
84
+ throw new RenderError("E_INTERNAL", "MathJax produced no svg element");
85
+ }
86
+ const element = container.slice(start, end + "</svg>".length);
87
+ const open = /^<svg([^>]*)>/.exec(element);
88
+ if (open === null) {
89
+ throw new RenderError("E_INTERNAL", "MathJax produced a malformed svg element");
90
+ }
91
+ const attrs = open[1];
92
+ const width = /\swidth="([^"]+)"/.exec(attrs)?.[1];
93
+ const height = /\sheight="([^"]+)"/.exec(attrs)?.[1];
94
+ const viewBox = /\sviewBox="([^"]+)"/.exec(attrs)?.[1];
95
+ if (width === undefined || height === undefined || viewBox === undefined) {
96
+ throw new RenderError("E_INTERNAL", "MathJax svg has no width, height or viewBox");
97
+ }
98
+ const head = `<svg xmlns="http://www.w3.org/2000/svg" width="${exToPx(width)}px" height="${exToPx(height)}px" viewBox="${viewBox}"`;
99
+ return head + element.slice(open[0].length - 1);
100
+ }
101
+ /**
102
+ * Renders LaTeX math to a standalone SVG with the glyphs as paths. The XML serializer escapes `<`, `>`,
103
+ * `&` and `"` in the attribute values, so the TeX source in the data-latex attributes keeps the SVG
104
+ * well-formed. Rejects with E_INPUT or E_UNSUPPORTED.
105
+ */
106
+ export async function mathToSvg(source, options) {
107
+ const tex = stripRequires(source);
108
+ const adaptor = liteAdaptor();
109
+ RegisterHTMLHandler(adaptor);
110
+ let inputError;
111
+ const input = new TeX({
112
+ packages: [...MATH_PACKAGES],
113
+ formatError: (jax, err) => {
114
+ inputError ??= err.message;
115
+ return jax.formatError(err);
116
+ },
117
+ });
118
+ const output = new SVG({ fontCache: "none" });
119
+ loadFontRanges(output.font);
120
+ defineMhchemVariant(output.font);
121
+ const doc = mathjax.document("", { InputJax: input, OutputJax: output });
122
+ const node = doc.convert(tex, { display: options.display });
123
+ if (inputError !== undefined) {
124
+ throw new RenderError("E_INPUT", `TeX input error: ${inputError}`);
125
+ }
126
+ const svg = standaloneSvg(adaptor.serializeXML(node));
127
+ rejectFontFallback(svg);
128
+ return svg;
129
+ }
130
+ //# sourceMappingURL=tex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tex.js","sourceRoot":"","sources":["../../src/math/tex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,8BAA8B,CAAC;AAC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AC;KACF,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9C,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;IACzE,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,EAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3D,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,MAAM,IAAI,WAAW,CAAC,SAAS,EAAE,oBAAoB,UAAU,EAAE,CAAC,CAAC;IACrE,CAAC;IACD,MAAM,GAAG,GAAG,aAAa,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;IACtD,kBAAkB,CAAC,GAAG,CAAC,CAAC;IACxB,OAAO,GAAG,CAAC;AACb,CAAC"}
package/dist/registry.js CHANGED
@@ -9,6 +9,9 @@ function backendUrl(name) {
9
9
  export const DEFAULT_REGISTRY = {
10
10
  "dot:svg": { backend: "graph/viz", moduleUrl: backendUrl("graph/backend-svg") },
11
11
  "dot:png": { backend: "graph/viz+raster/resvg", moduleUrl: backendUrl("graph/backend-png") },
12
+ "math:svg": { backend: "math/mathjax", moduleUrl: backendUrl("math/backend-svg") },
13
+ "math:png": { backend: "math/mathjax+raster/resvg", moduleUrl: backendUrl("math/backend-png") },
14
+ "math:pdf": { backend: "math/mathjax+browser/chromium", moduleUrl: backendUrl("math/backend-pdf") },
12
15
  "mermaid:svg": { backend: "mermaid/native", moduleUrl: backendUrl("mermaid/backend-svg") },
13
16
  "mermaid:png": { backend: "mermaid/native+raster/resvg", moduleUrl: backendUrl("mermaid/backend-png") },
14
17
  "dot:pdf": { backend: "graph/viz+browser/chromium", moduleUrl: backendUrl("graph/backend-pdf") },
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAazC,iHAAiH;AACjH,SAAS,UAAU,CAAC,IAAY;IAC9B,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,OAAO,IAAI,GAAG,CAAC,KAAK,IAAI,GAAG,SAAS,EAAE,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AAChE,CAAC;AAED,kCAAkC;AAClC,MAAM,CAAC,MAAM,gBAAgB,GAAa;IACxC,SAAS,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,CAAC,mBAAmB,CAAC,EAAE;IAC/E,SAAS,EAAE,EAAE,OAAO,EAAE,wBAAwB,EAAE,SAAS,EAAE,UAAU,CAAC,mBAAmB,CAAC,EAAE;IAC5F,aAAa,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAAE;IAC1F,aAAa,EAAE,EAAE,OAAO,EAAE,6BAA6B,EAAE,SAAS,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAAE;IACvG,SAAS,EAAE,EAAE,OAAO,EAAE,4BAA4B,EAAE,SAAS,EAAE,UAAU,CAAC,mBAAmB,CAAC,EAAE;IAChG,aAAa,EAAE,EAAE,OAAO,EAAE,0BAA0B,EAAE,SAAS,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAAE;IACpG,UAAU,EAAE,EAAE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,UAAU,CAAC,qBAAqB,CAAC,EA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EAAE,SAAS,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAAE;IAC1F,aAAa,EAAE,EAAE,OAAO,EAAE,6BAA6B,EAAE,SAAS,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAAE;IACvG,SAAS,EAAE,EAAE,OAAO,EAAE,4BAA4B,EAAE,SAAS,EAAE,UAAU,CAAC,mBAAmB,CAAC,EAAE;IAChG,aAAa,EAAE,EAAE,OAAO,EAAE,0BAA0B,EAAE,SAAS,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAAE;IACpG,UAAU,EAAE,EAAE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAAE;IACzF,UAAU,EAAE,EAAE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,UAAU,CAAC,qBAAqB,CAAC,EAAE;CAC1F,CAAC;AAEF,yCAAyC;AACzC,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,MAAc;IACtD,OAAO,GAAG,IAAI,IAAI,MAAM,EAAE,CAAC;AAC7B,CAAC"}
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const ENGINE_VERSION = "0.3.1";
1
+ export declare const ENGINE_VERSION = "0.4.0";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Generated by scripts/prepare-build.mjs from package.json. Do not edit this file by hand.
2
- export const ENGINE_VERSION = "0.3.1";
2
+ export const ENGINE_VERSION = "0.4.0";
3
3
  //# sourceMappingURL=version.js.map
@@ -1,4 +1,4 @@
1
- import { Worker } from "node:worker_threads";
1
+ import { Worker, type WorkerOptions } from "node:worker_threads";
2
2
  import type { BackendOutput, WorkerJob } from "./protocol.ts";
3
3
  /** The exit of one worker. The exit code is the code that `Worker.terminate` reports. */
4
4
  export interface WorkerExit {
@@ -27,6 +27,17 @@ export interface WorkerLimits {
27
27
  * in the same order, with no change.
28
28
  */
29
29
  export declare function workerExecArgv(parentArgv: readonly string[]): string[];
30
+ /**
31
+ * Creates a worker with the parent flags that a worker can take. The parent execArgv can hold flags
32
+ * that a worker rejects, such as the expanded defaults of `node --test` and `--stack-trace-limit`.
33
+ * Rules:
34
+ * 1. When workerExecArgv removes no flag, the worker gets no execArgv key. Node then inherits the parent flags.
35
+ * 2. When it removes a flag, the worker gets the filtered list.
36
+ * 3. When the constructor throws `ERR_WORKER_INVALID_EXEC_ARGV`, the worker is constructed again with an empty list.
37
+ * The empty list drops every parent flag, also `--conditions`, `--import` and `--require`. The built worker entry needs none of them.
38
+ * Other errors pass through. `ctor` receives the options and returns the worker. Tests pass a double.
39
+ */
40
+ export declare function constructWorker(ctor: (options: WorkerOptions) => Worker, base: WorkerOptions, parentArgv: readonly string[]): Worker;
30
41
  /**
31
42
  * Runs one render in a fresh worker. The worker ends at the first of: its message, its error,
32
43
  * its exit, or the time limit. The promise settles only after the worker has exited.
@@ -38,12 +38,33 @@ export function workerExecArgv(parentArgv) {
38
38
  }
39
39
  return kept;
40
40
  }
41
+ /** The error code that Node throws when a worker rejects the execArgv it receives. */
42
+ const INVALID_EXEC_ARGV = "ERR_WORKER_INVALID_EXEC_ARGV";
43
+ /**
44
+ * Creates a worker with the parent flags that a worker can take. The parent execArgv can hold flags
45
+ * that a worker rejects, such as the expanded defaults of `node --test` and `--stack-trace-limit`.
46
+ * Rules:
47
+ * 1. When workerExecArgv removes no flag, the worker gets no execArgv key. Node then inherits the parent flags.
48
+ * 2. When it removes a flag, the worker gets the filtered list.
49
+ * 3. When the constructor throws `ERR_WORKER_INVALID_EXEC_ARGV`, the worker is constructed again with an empty list.
50
+ * The empty list drops every parent flag, also `--conditions`, `--import` and `--require`. The built worker entry needs none of them.
51
+ * Other errors pass through. `ctor` receives the options and returns the worker. Tests pass a double.
52
+ */
53
+ export function constructWorker(ctor, base, parentArgv) {
54
+ const kept = workerExecArgv(parentArgv);
55
+ const removedAny = kept.length !== parentArgv.length;
56
+ try {
57
+ return ctor(removedAny ? { ...base, execArgv: kept } : { ...base });
58
+ }
59
+ catch (err) {
60
+ if (err?.code === INVALID_EXEC_ARGV) {
61
+ return ctor({ ...base, execArgv: [] });
62
+ }
63
+ throw err;
64
+ }
65
+ }
41
66
  function createDefaultWorker(entry, data, maxMemoryMb) {
42
- return new Worker(entry, {
43
- workerData: data,
44
- execArgv: workerExecArgv(process.execArgv),
45
- resourceLimits: { maxOldGenerationSizeMb: maxMemoryMb },
46
- });
67
+ return constructWorker((options) => new Worker(entry, options), { workerData: data, resourceLimits: { maxOldGenerationSizeMb: maxMemoryMb } }, process.execArgv);
47
68
  }
48
69
  /** Terminates the worker. It rejects when terminate throws, rejects or does not resolve within the wait. */
49
70
  function stopWorker(worker, waitMs) {
@@ -1 +1 @@
1
- {"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/worker/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAyB3C,mGAAmG;AACnG,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAEvC,iFAAiF;AACjF,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;AAE/E,8EAA8E;AAC9E,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;AAErE,mGAAmG;AACnG,MAAM,WAAW,GAAG,eAAe,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,UAA6B;IAC1D,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EA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tD,MAAM,CAAC,GAAG,EAAE;gBACV,IAAI,GAAG,CAAC,IAAI,KAAK,0BAA0B,EAAE,CAAC;oBAC5C,MAAM,CAAC,IAAI,WAAW,CAAC,SAAS,EAAE,qCAAqC,MAAM,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC;gBACnG,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,IAAI,WAAW,CAAC,YAAY,EAAE,yBAAyB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBAChF,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;YACnC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,YAAY,EAAE,kCAAkC,IAAI,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACnH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielsimonjr/sciengjs",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "private": false,
5
5
  "description": "A local rendering engine for science and engineering diagrams, documents and models",
6
6
  "license": "MIT",
@@ -29,6 +29,10 @@
29
29
  "types": "./dist/mermaid/index.d.ts",
30
30
  "default": "./dist/mermaid/index.js"
31
31
  },
32
+ "./math": {
33
+ "types": "./dist/math/index.d.ts",
34
+ "default": "./dist/math/index.js"
35
+ },
32
36
  "./package.json": "./package.json"
33
37
  },
34
38
  "files": [
@@ -44,7 +48,7 @@
44
48
  "test": "bun test",
45
49
  "smoke": "node test/smoke/smoke.mjs",
46
50
  "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
47
- "test:node": "node --test test/node/worker.node.mjs test/node/eval-render.node.mjs"
51
+ "test:node": "node --test test/node/worker.node.mjs test/node/eval-render.node.mjs test/node/worker-execargv.node.mjs test/node/math.node.mjs"
48
52
  },
49
53
  "keywords": [
50
54
  "graphviz",
@@ -74,6 +78,7 @@
74
78
  "typescript": "^7.0.2"
75
79
  },
76
80
  "dependencies": {
81
+ "@mathjax/src": "4.1.3",
77
82
  "@resvg/resvg-wasm": "2.6.2",
78
83
  "@viz-js/viz": "3.31.0"
79
84
  }