@danielsimonjr/sciengjs 0.3.2 → 0.5.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.
Files changed (55) hide show
  1. package/README.md +119 -5
  2. package/THIRD_PARTY_NOTICES.md +33 -1
  3. package/dist/browser/page.d.ts +7 -0
  4. package/dist/browser/page.js +27 -1
  5. package/dist/browser/page.js.map +1 -1
  6. package/dist/browser/pinned.d.ts +8 -0
  7. package/dist/browser/pinned.js +8 -0
  8. package/dist/browser/pinned.js.map +1 -1
  9. package/dist/math/backend-pdf.d.ts +3 -0
  10. package/dist/math/backend-pdf.js +14 -0
  11. package/dist/math/backend-pdf.js.map +1 -0
  12. package/dist/math/backend-png.d.ts +3 -0
  13. package/dist/math/backend-png.js +15 -0
  14. package/dist/math/backend-png.js.map +1 -0
  15. package/dist/math/backend-svg.d.ts +3 -0
  16. package/dist/math/backend-svg.js +12 -0
  17. package/dist/math/backend-svg.js.map +1 -0
  18. package/dist/math/font-ranges.d.ts +59 -0
  19. package/dist/math/font-ranges.js +93 -0
  20. package/dist/math/font-ranges.js.map +1 -0
  21. package/dist/math/index.d.ts +3 -0
  22. package/dist/math/index.js +3 -0
  23. package/dist/math/index.js.map +1 -0
  24. package/dist/math/tex.d.ts +39 -0
  25. package/dist/math/tex.js +130 -0
  26. package/dist/math/tex.js.map +1 -0
  27. package/dist/plot/backend-html.d.ts +3 -0
  28. package/dist/plot/backend-html.js +13 -0
  29. package/dist/plot/backend-html.js.map +1 -0
  30. package/dist/plot/backend-png.d.ts +3 -0
  31. package/dist/plot/backend-png.js +12 -0
  32. package/dist/plot/backend-png.js.map +1 -0
  33. package/dist/plot/backend-svg.d.ts +7 -0
  34. package/dist/plot/backend-svg.js +21 -0
  35. package/dist/plot/backend-svg.js.map +1 -0
  36. package/dist/plot/control.d.ts +93 -0
  37. package/dist/plot/control.js +811 -0
  38. package/dist/plot/control.js.map +1 -0
  39. package/dist/plot/index.d.ts +6 -0
  40. package/dist/plot/index.js +6 -0
  41. package/dist/plot/index.js.map +1 -0
  42. package/dist/plot/plotter.d.ts +7 -0
  43. package/dist/plot/plotter.js +491 -0
  44. package/dist/plot/plotter.js.map +1 -0
  45. package/dist/plot/reader.d.ts +10 -0
  46. package/dist/plot/reader.js +266 -0
  47. package/dist/plot/reader.js.map +1 -0
  48. package/dist/plot/ticks.d.ts +13 -0
  49. package/dist/plot/ticks.js +67 -0
  50. package/dist/plot/ticks.js.map +1 -0
  51. package/dist/registry.js +6 -0
  52. package/dist/registry.js.map +1 -1
  53. package/dist/version.d.ts +1 -1
  54. package/dist/version.js +1 -1
  55. package/package.json +12 -2
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.2 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.5.0 holds five input types: **Graphviz DOT**, **Mermaid** (every diagram type), **LaTeX math** (to SVG, PNG and PDF), **Plotly plots** (to SVG, PNG and HTML) 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,120 @@ 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
+
173
+ ## Plots
174
+
175
+ The `plot` input draws a chart from JSON. The source is a JSON text with the keys `data` and `layout`. The output formats are `svg`, `png` and `html`. The `svg` and `png` outputs make no network request.
176
+
177
+ ```js
178
+ import { render } from "@danielsimonjr/sciengjs";
179
+
180
+ const source = JSON.stringify({
181
+ data: [{ type: "scatter", mode: "lines+markers", x: [0, 1, 2], y: [0, 1, 4], name: "y = x^2" }],
182
+ layout: { title: { text: "Square" } },
183
+ });
184
+ const { bytes } = await render({ type: "plot", source, format: "svg" }, {});
185
+ ```
186
+
187
+ The engine reads a subset of the Plotly figure format. The subset holds `scatter` traces, page and grid layout keys, `line` and `rect` shapes, and linear or log axes. A key outside the subset rejects with `E_INPUT` and the key path. Set `lenient` to `true` to skip such a key and get a warning. The `html` output is a page that draws the figure with Plotly 4.2.0, the pinned build. The page loads that build from a CDN, with a subresource integrity hash. The package does not ship Plotly. The full subset is in the [design](docs/superpowers/specs/2026-11-01-scieng-engine-design.md), section PLOT.
188
+
189
+ The reader applies these rules:
190
+
191
+ - A figure has the top-level keys `data` and `layout` only.
192
+ - The first axis of each letter is `xaxis` or `yaxis`. The other axes are `xaxis2`, `xaxis3` and up, with no leading zero. Plotly also accepts `xaxis1` for the first axis. This reader rejects `xaxis1`, so that each axis has one name.
193
+ - An axis key must name an axis of a subplot in `layout.grid`.
194
+ - `tickformat` is `.Nf` only, with N from 0 to 20. N sets the fixed decimals of the tick labels.
195
+ - `dtick`, `width` and `height` must be above zero.
196
+ - One axis has 1000 ticks at most. A `dtick` that gives more ticks rejects with `E_INPUT` and the key path, for example `layout.xaxis.dtick`.
197
+
198
+ A tick label that needs more than 20 decimals uses exponent form, for example `1e-300`. A log axis that spans too many decades for minor ticks shows major ticks only.
199
+
200
+ ### Control helpers
201
+
202
+ The `./plot` subpath has six helpers. Each helper takes a transfer function `{ num, den }` with the coefficients of the numerator and the denominator, highest power first. Each helper returns `{ figure, numbers }`. The `figure` is a plot figure. Pass it to `render` as JSON text to draw it. The `numbers` hold the key values that the analysis derives from the same model.
203
+
204
+ Frequencies are in rad/s. Margins and phases are in degrees. Overshoot is in percent.
205
+
206
+ `bode` returns the crossover frequencies and the margins:
207
+
208
+ ```js
209
+ import { bode } from "@danielsimonjr/sciengjs/plot";
210
+
211
+ const { figure, numbers } = bode({ num: [10], den: [1, 1, 0] });
212
+ // numbers.gainCrossover is about 3.08, numbers.phaseMargin is about 17.96
213
+ ```
214
+
215
+ `step` returns the final value, the rise time, the settling time, the overshoot and the peak time:
216
+
217
+ ```js
218
+ import { step } from "@danielsimonjr/sciengjs/plot";
219
+
220
+ const { figure, numbers } = step({ num: [1], den: [1, 0.6, 1] });
221
+ // numbers.overshoot is about 37.2, numbers.riseTime is about 1.32
222
+ ```
223
+
224
+ The step helper measures the peak and the overshoot in the direction of the final value, so a negative DC gain gives a correct overshoot. A response with no peak before the end of the time grid has a `peakTime` of `null` and an `overshoot` of 0. A system with a pole on or right of the imaginary axis has no final value: each number is `null`. The rise and settling times are interpolated between samples.
225
+
226
+ The helpers reject with `E_INPUT` when the roots of the model do not converge, or when a computed value is not finite. A pole or a zero at 0 is exact and does not set the frequency range.
227
+
228
+ `impulse` returns the peak value and its time:
229
+
230
+ ```js
231
+ import { impulse } from "@danielsimonjr/sciengjs/plot";
232
+
233
+ const { figure, numbers } = impulse({ num: [1], den: [1, 1] });
234
+ // numbers.peak is 1, numbers.peakTime is 0
235
+ ```
236
+
237
+ `nyquist` returns the least distance from the curve to the point -1:
238
+
239
+ ```js
240
+ import { nyquist } from "@danielsimonjr/sciengjs/plot";
241
+
242
+ const { figure, numbers } = nyquist({ num: [10], den: [1, 1, 0] });
243
+ // numbers.minDistanceToMinusOne is about 0.299
244
+ ```
245
+
246
+ `poleZero` returns the poles and the zeros:
247
+
248
+ ```js
249
+ import { poleZero } from "@danielsimonjr/sciengjs/plot";
250
+
251
+ const { figure, numbers } = poleZero({ num: [1, 3], den: [1, 2, 5] });
252
+ // the poles are -1 + 2j and -1 - 2j, the zero is -3
253
+ ```
254
+
255
+ `rootLocus` returns the breakaway points and the gain at each point:
256
+
257
+ ```js
258
+ import { rootLocus } from "@danielsimonjr/sciengjs/plot";
259
+
260
+ const { figure, numbers } = rootLocus({ num: [1], den: [1, 3, 2] });
261
+ // numbers.breakawayPoints[0] is { re: -1.5, k: 0.25 }
262
+ ```
263
+
264
+ To draw a helper figure, pass it to `render`:
265
+
266
+ ```js
267
+ import { render } from "@danielsimonjr/sciengjs";
268
+ import { bode } from "@danielsimonjr/sciengjs/plot";
269
+
270
+ const { figure } = bode({ num: [10], den: [1, 1, 0] });
271
+ const { bytes } = await render({ type: "plot", source: JSON.stringify(figure), format: "html" }, {});
272
+ ```
273
+
160
274
  ## Roadmap
161
275
 
162
276
  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,9 +279,9 @@ The [build plan](docs/superpowers/plans/2026-11-01-scieng-engine-build.md) gives
165
279
  |---|---|---|
166
280
  | DOT | graph, raster | released in 0.1.0 |
167
281
  | 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 |
282
+ | LaTeX math | math (MathJax) | svg, png and pdf are built; pdf needs the browser stage |
169
283
  | TikZ, circuitikz, LaTeX | tex (an own WASM build of `tex.web`) | trial builds pass |
170
- | Plots | plot | planned |
284
+ | Plots | plot | svg, png and html are built, not yet released; pdf is not planned |
171
285
  | SysML v2 | sysml | planned |
172
286
  | STEP, IGES, BREP | mesh (OpenCascade WASM) | trial build passes |
173
287
  | HTML to PNG, PDF and Markdown | html, browser | PNG and PDF: released in 0.3.0; Markdown: 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 |
@@ -21,6 +21,7 @@ Version: each row gives the version that the engine pins.
21
21
  | raster | `@resvg/resvg-wasm` 2.6.2 | MPL-2.0 | a dependency |
22
22
  | raster | Liberation Serif Regular 2.1.5 (font, in `assets/fonts/`) | SIL Open Font License 1.1 | bundled |
23
23
  | html | `parse5` | MIT | not yet a dependency |
24
+ | plot (html output) | `plotly.js-dist-min` 4.2.0 (the pinned Plotly build, loaded by the html page from a CDN with a subresource integrity hash) | MIT | a devDependency. The package does not ship the build. The html page loads it from the CDN |
24
25
  | browser | Chromium or Google Chrome | Installed by the user. The engine does not ship it | not a package dependency |
25
26
 
26
27
  ## Notices
@@ -29,6 +30,37 @@ Version: each row gives the version that the engine pins.
29
30
 
30
31
  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
32
 
33
+ ### MathJax (Apache-2.0, with other licences for transitive packages)
34
+
35
+ `@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`.
36
+
37
+ | Package | Version | Licence |
38
+ |---|---|---|
39
+ | `@mathjax/src` | 4.1.3 | Apache-2.0 |
40
+ | `@mathjax/mathjax-newcm-font` | 4.1.3 | Apache-2.0 |
41
+ | `mhchemparser` | 4.2.1 | Apache-2.0 |
42
+ | `mj-context-menu` | 1.0.0 | Apache-2.0 |
43
+ | `speech-rule-engine` | 5.0.0-rc.4 | Apache-2.0 |
44
+ | `@xmldom/xmldom` | 0.9.12 | MIT |
45
+ | `wicked-good-xpath` | 1.3.0 | MIT |
46
+ | `commander` | 14.0.3 (installed under `speech-rule-engine`) | MIT |
47
+ | `balanced-match` | 4.0.4 | MIT |
48
+ | `brace-expansion` | 5.0.12 | MIT |
49
+ | `@isaacs/nonrecursive-glob-match` | 1.0.3 | BlueOak-1.0.0 |
50
+ | `glob` | 14.0.3 | BlueOak-1.0.0 |
51
+ | `minimatch` | 11.0.4 | BlueOak-1.0.0 |
52
+ | `minipass` | 7.1.3 | BlueOak-1.0.0 |
53
+ | `package-json-from-dist` | 1.0.1 | BlueOak-1.0.0 |
54
+ | `path-scurry` | 3.0.0 | BlueOak-1.0.0 |
55
+ | `lru-cache` | 11.5.3 | BlueOak-1.0.0 |
56
+ | `rimraf` | 6.1.4 | BlueOak-1.0.0 |
57
+
58
+ 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.
59
+
60
+ ### Plotly (MIT)
61
+
62
+ The MIT licence applies to `plotly.js-dist-min` 4.2.0. The package is a devDependency. The engine does not bundle the build into the package and does not copy it into the assets folder. The html output of the `plot` stage is a page that loads the pinned build from the CDN URL in the engine, with a subresource integrity hash. The page makes that request when a reader opens it. The licence text is in the installed package at `node_modules/plotly.js-dist-min/LICENSE`.
63
+
32
64
  ### Mermaid (MIT)
33
65
 
34
66
  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`.
@@ -1,5 +1,12 @@
1
1
  /** Writes a value as a JavaScript literal that cannot end a script element or break a line. */
2
2
  export declare function scriptJson(text: string): string;
3
+ /** Writes a JSON value as a JavaScript object literal that cannot end a script element. */
4
+ export declare function scriptData(value: unknown): string;
5
+ /**
6
+ * A page that loads the pinned Plotly build with its Subresource Integrity value and draws one figure.
7
+ * The figure object comes from the engine after the reader accepts it. The page title is the title argument.
8
+ */
9
+ export declare function plotlyPageHtml(figure: unknown, cdnUrl: string, sri: string, title?: string): string;
3
10
  /** A page that shows one SVG document. The SVG text comes from the engine, not from the caller. */
4
11
  export declare function svgPageHtml(svg: string): string;
5
12
  /**
@@ -1,7 +1,33 @@
1
1
  const PAGE_STYLE = "html,body{margin:0;background:#fff}";
2
2
  /** Writes a value as a JavaScript literal that cannot end a script element or break a line. */
3
3
  export function scriptJson(text) {
4
- return JSON.stringify(text).replace(/[<>&\u2028\u2029]/g, (ch) => "\\u" + ch.charCodeAt(0).toString(16).padStart(4, "0"));
4
+ return escapeScriptText(JSON.stringify(text));
5
+ }
6
+ /** Writes a JSON value as a JavaScript object literal that cannot end a script element. */
7
+ export function scriptData(value) {
8
+ return escapeScriptText(JSON.stringify(value));
9
+ }
10
+ /** Escapes the characters that could end a script element or break a line in JavaScript source. */
11
+ function escapeScriptText(text) {
12
+ return text.replace(/[<>&\u2028\u2029]/g, (ch) => "\\u" + ch.charCodeAt(0).toString(16).padStart(4, "0"));
13
+ }
14
+ /** Escapes text for an HTML element body. */
15
+ function escapeHtmlText(text) {
16
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
17
+ }
18
+ /**
19
+ * A page that loads the pinned Plotly build with its Subresource Integrity value and draws one figure.
20
+ * The figure object comes from the engine after the reader accepts it. The page title is the title argument.
21
+ */
22
+ export function plotlyPageHtml(figure, cdnUrl, sri, title = "plot") {
23
+ return ('<!DOCTYPE html><html><head><meta charset="utf-8">' +
24
+ '<meta name="viewport" content="width=device-width, initial-scale=1">' +
25
+ `<title>${escapeHtmlText(title)}</title><style>${PAGE_STYLE}</style></head><body>` +
26
+ '<div id="sciengjs-diagram"></div>' +
27
+ `<script src="${cdnUrl}" integrity="${sri}" crossorigin="anonymous"></script>` +
28
+ `<script>(function () { const fig = ${scriptData(figure)}; ` +
29
+ 'Plotly.newPlot(document.getElementById("sciengjs-diagram"), fig.data, fig.layout, { responsive: false }); })();</script>' +
30
+ "</body></html>");
5
31
  }
6
32
  /** A page that shows one SVG document. The SVG text comes from the engine, not from the caller. */
7
33
  export function svgPageHtml(svg) {
@@ -1 +1 @@
1
- {"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/browser/page.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,qCAAqC,CAAC;AAEzD,+FAA+F;AAC/F,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,CACjC,oBAAoB,EACpB,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAC/D,CAAC;AACJ,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,OAAO,2DAA2D,UAAU,mDAAmD,GAAG,sBAAsB,CAAC;AAC3J,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,MAAc;IAC5D,MAAM,MAAM,GACV,yJAAyJ;QACzJ,6EAA6E;QAC7E,2DAA2D,UAAU,CAAC,MAAM,CAAC,KAAK;QAClF,kFAAkF;QAClF,sHAAsH;QACtH,2FAA2F;QAC3F,6CAA6C;QAC7C,kHAAkH;QAClH,0CAA0C;QAC1C,oEAAoE;QACpE,gDAAgD;QAChD,sGAAsG,CAAC;IACzG,OAAO,CACL,2DAA2D,UAAU,uBAAuB;QAC5F,mCAAmC;QACnC,gBAAgB,MAAM,aAAa;QACnC,0BAA0B,MAAM,+BAA+B,CAChE,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/browser/page.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,qCAAqC,CAAC;AAEzD,+FAA+F;AAC/F,MAAM,UAAU,UAAU,CAAC,IAAY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,MAAc;IAC5D,MAAM,MAAM,GACV,yJAAyJ;QACzJ,6EAA6E;QAC7E,2DAA2D,UAAU,CAAC,MAAM,CAAC,KAAK;QAClF,kFAAkF;QAClF,sHAAsH;QACtH,2FAA2F;QAC3F,6CAA6C;QAC7C,kHAAkH;QAClH,0CAA0C;QAC1C,oEAAoE;QACpE,gDAAgD;QAChD,sGAAsG,CAAC;IACzG,OAAO,CACL,2DAA2D,UAAU,uBAAuB;QAC5F,mCAAmC;QACnC,gBAAgB,MAAM,aAAa;QACnC,0BAA0B,MAAM,+BAA+B,CAChE,CAAC;AACJ,CAAC"}
@@ -14,3 +14,11 @@ export interface PinnedAsset {
14
14
  }
15
15
  /** The pinned builds of the engine. Each entry names the URL of the CDN and the local file. */
16
16
  export declare const PINNED_ASSETS: readonly PinnedAsset[];
17
+ /** The pinned Plotly version. It equals the exact devDependency plotly.js-dist-min of the repository. */
18
+ export declare const PLOTLY_VERSION = "4.2.0";
19
+ /** The SHA-256 of the pinned Plotly build, in hex. */
20
+ export declare const PLOTLY_SHA256 = "fde93964a7511bfa54c5745c49b5d0e41715cbde0cc5ebeae3f9a02de0396cae";
21
+ /** The Subresource Integrity value of the pinned Plotly build. The browser refuses other bytes. */
22
+ export declare const PLOTLY_SRI = "sha256-/ek5ZKdRG/pUxXRcSbXQ5BcVy94Mxevq4/mgLeA5bK4=";
23
+ /** The address that a plot page names for the pinned Plotly build. */
24
+ export declare const PLOTLY_CDN_URL = "https://cdn.jsdelivr.net/npm/plotly.js-dist-min@4.2.0/plotly.min.js";
@@ -10,4 +10,12 @@ export const MERMAID_CDN_URL = `https://cdn.jsdelivr.net/npm/mermaid@${MERMAID_V
10
10
  export const PINNED_ASSETS = [
11
11
  { url: MERMAID_CDN_URL, file: MERMAID_FILE, mime: "application/javascript" },
12
12
  ];
13
+ /** The pinned Plotly version. It equals the exact devDependency plotly.js-dist-min of the repository. */
14
+ export const PLOTLY_VERSION = "4.2.0";
15
+ /** The SHA-256 of the pinned Plotly build, in hex. */
16
+ export const PLOTLY_SHA256 = "fde93964a7511bfa54c5745c49b5d0e41715cbde0cc5ebeae3f9a02de0396cae";
17
+ /** The Subresource Integrity value of the pinned Plotly build. The browser refuses other bytes. */
18
+ export const PLOTLY_SRI = "sha256-/ek5ZKdRG/pUxXRcSbXQ5BcVy94Mxevq4/mgLeA5bK4=";
19
+ /** The address that a plot page names for the pinned Plotly build. */
20
+ export const PLOTLY_CDN_URL = `https://cdn.jsdelivr.net/npm/plotly.js-dist-min@${PLOTLY_VERSION}/plotly.min.js`;
13
21
  //# sourceMappingURL=pinned.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pinned.js","sourceRoot":"","sources":["../../src/browser/pinned.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC;AACzC,iGAAiG;AACjG,MAAM,CAAC,MAAM,cAAc,GAAG,kEAAkE,CAAC;AACjG,gGAAgG;AAChG,MAAM,CAAC,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAC7C,gHAAgH;AAChH,MAAM,CAAC,MAAM,eAAe,GAAG,wCAAwC,eAAe,sBAAsB,CAAC;AAS7G,+FAA+F;AAC/F,MAAM,CAAC,MAAM,aAAa,GAA2B;IACnD,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,wBAAwB,EAAE;CAC7E,CAAC"}
1
+ {"version":3,"file":"pinned.js","sourceRoot":"","sources":["../../src/browser/pinned.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC;AACzC,iGAAiG;AACjG,MAAM,CAAC,MAAM,cAAc,GAAG,kEAAkE,CAAC;AACjG,gGAAgG;AAChG,MAAM,CAAC,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAC7C,gHAAgH;AAChH,MAAM,CAAC,MAAM,eAAe,GAAG,wCAAwC,eAAe,sBAAsB,CAAC;AAS7G,+FAA+F;AAC/F,MAAM,CAAC,MAAM,aAAa,GAA2B;IACnD,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,wBAAwB,EAAE;CAC7E,CAAC;AAEF,yGAAyG;AACzG,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AACtC,sDAAsD;AACtD,MAAM,CAAC,MAAM,aAAa,GAAG,kEAAkE,CAAC;AAChG,mGAAmG;AACnG,MAAM,CAAC,MAAM,UAAU,GAAG,qDAAqD,CAAC;AAChF,sEAAsE;AACtE,MAAM,CAAC,MAAM,cAAc,GAAG,mDAAmD,cAAc,gBAAgB,CAAC"}
@@ -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","sourceRoot":"","sources":["../../src/math/font-ranges.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,mDAAmD,CAAC;AAC3D,OAAO,2DAA2D,CAAC;AACnE,OAAO,uDAAuD,CAAC;AAC/D,OAAO,sDAAsD,CAAC;AAC9D,OAAO,sDAAsD,CAAC;AAC9D,OAAO,yDAAyD,CAAC;AACjE,OAAO,uDAAuD,CAAC;AAC/D,OAAO,4DAA4D,CAAC;AACpE,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AG,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>;