rapier-math 1.1.1 → 2.1.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 +15 -5
  2. package/dist/accessible.css +6 -0
  3. package/dist/accessible.d.ts +10 -0
  4. package/dist/accessible.mjs +18 -0
  5. package/dist/classic.d.ts +8 -2
  6. package/dist/combined.d.ts +4 -0
  7. package/dist/combined.mjs +2 -0
  8. package/dist/index.d.ts +11 -0
  9. package/dist/index.mjs +6 -2980
  10. package/dist/integration.d.ts +11 -2
  11. package/dist/integration.mjs +96 -13
  12. package/dist/markdown-it.d.ts +7 -0
  13. package/dist/markdown-it.mjs +33 -19
  14. package/dist/mathml.d.ts +5 -0
  15. package/dist/mathml.mjs +3 -0
  16. package/dist/rapier-math.js +595 -143
  17. package/dist/rehype.d.ts +7 -0
  18. package/dist/rehype.mjs +28 -7
  19. package/dist/reuse.mjs +110 -0
  20. package/dist/stream.d.ts +36 -3
  21. package/dist/stream.mjs +63 -38
  22. package/docs/api.md +155 -26
  23. package/docs/math-components.json +6 -5
  24. package/docs/math-resources.json +170 -68
  25. package/docs/semantics.md +228 -0
  26. package/examples/README.md +15 -2
  27. package/examples/accessible.html +27 -0
  28. package/examples/accessible.mjs +42 -0
  29. package/examples/markdown.mjs +21 -4
  30. package/examples/semantic.mjs +11 -0
  31. package/examples/stream.mjs +31 -11
  32. package/examples/unified.mjs +17 -3
  33. package/package.json +16 -2
  34. package/src/math/api.js +16 -55
  35. package/src/math/browser.js +4 -0
  36. package/src/math/classic.js +7 -0
  37. package/src/math/combined.js +13 -0
  38. package/src/math/fallbacks.js +5 -0
  39. package/src/math/font.js +3 -0
  40. package/src/math/layout.js +6 -37
  41. package/src/math/mathml.js +406 -0
  42. package/src/math/package-build.mjs +24 -11
  43. package/src/math/package-layout.mjs +3 -0
  44. package/src/math/package-readme.mjs +14 -4
  45. package/src/math/parser.js +14 -11
  46. package/src/math/responsive.js +4 -0
  47. package/src/math/semantic-api.js +12 -0
  48. package/src/math/source.js +67 -0
  49. package/src/math/symbols.js +3 -0
  50. package/src/math/variants.js +41 -0
  51. package/src/tools/build-math.mjs +20 -11
  52. package/tests/adoption.mjs +112 -9
  53. package/tests/check.mjs +20 -5
  54. package/tests/semantics.mjs +340 -0
  55. package/tests/verify.mjs +6 -3
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Rapier Math
2
2
 
3
- A self-contained TeX-to-SVG renderer with Latin Modern outlines. Synchronous, no runtime downloads.
3
+ Offline TeX formulas as SVG or structured MathML. Embedded Latin Modern outlines for SVG; font-free native MathML. Synchronous, with no runtime downloads.
4
4
 
5
5
  ## Use
6
6
 
@@ -15,16 +15,26 @@ const svg = renderToString(String.raw`\frac{a}{b}`);
15
15
 
16
16
  For a browser script, load [dist/rapier-math.js](dist/rapier-math.js) and use
17
17
  `globalThis.RapierMath`. The native ESM entry is [dist/index.mjs](dist/index.mjs).
18
- Both include the font and return synchronously. Type declarations accompany the runtime files.
18
+ For one-file copying or inline-script embedding, use the classic file above. The native
19
+ ESM entry imports relative `src/math/` modules: install/serve the whole package or bundle
20
+ that import; copying only `dist/index.mjs` is insufficient. A CDN must retain that graph
21
+ or bundle it. Formula rendering stays synchronous and offline after its chosen script
22
+ or module graph has loaded.
23
+
24
+ The SVG entry and classic script include the font. Use `rapier-math/mathml` for font-free MathML,
25
+ `rapier-math/combined` for one-parse SVG and MathML, or `rapier-math/accessible` with its stylesheet
26
+ for host composition. All return synchronously. Type declarations accompany the runtime files.
19
27
 
20
28
  - [API and integration guide](docs/api.md)
29
+ - [MathML, accessibility and source contracts](docs/semantics.md)
21
30
  - [Runnable examples](examples/README.md)
22
31
  - [Font source and regeneration](docs/font-source.md)
23
32
 
24
33
  ## Develop
25
34
 
26
- The current runtime formats live in `dist/`; editable renderer source and its build tools live in
27
- `src/`. Optional adapters have one source copy in `dist/`. Examples, documentation and tests each
35
+ The classic script and native entry points live in `dist/`. Native entries import the editable
36
+ modules in `src/math/` directly, sharing one parser without a duplicate generated renderer. Build
37
+ tools live in `src/tools/`. Optional adapters have one source copy in `dist/`. Examples, documentation and tests each
28
38
  have their own directory. Only the current release is kept in this checkout.
29
39
 
30
40
  From a repository checkout, run `node tests/check.mjs` and `node tests/verify.mjs` to check the package and rebuild its exact bytes.
@@ -38,4 +48,4 @@ licensed under the GUST Font License. [LICENSE](LICENSE) contains both complete
38
48
  [Component provenance](docs/math-components.json) and [source hashes](docs/math-resources.json)
39
49
  travel with the package.
40
50
 
41
- Version 1.1.1. Classic payload: 714051 bytes; gzip (level 9): 442525 bytes.
51
+ Version 2.1.0. Classic payload: 745053 bytes; gzip (level 9): 451500 bytes.
@@ -0,0 +1,6 @@
1
+ /* SPDX-License-Identifier: MIT */
2
+ .rapier-math-accessible { position: relative; display: inline-block; }
3
+ .rapier-math-assistive {
4
+ position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
5
+ overflow: hidden; clip-path: inset(50%); white-space: nowrap;
6
+ }
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import type {RenderOptions, SemanticRenderResult} from './index.js';
3
+ export interface AccessibleResult extends SemanticRenderResult {
4
+ /** Empty on refusal; retain original input for the host's escaped fallback. */
5
+ html: string;
6
+ /** Authored links use visible native MathML, with standalone SVG still returned. */
7
+ presentation: 'svg-mathml' | 'mathml' | 'refused';
8
+ }
9
+ /** Include accessible.css when inserting the combined SVG/MathML composition. */
10
+ export function renderAccessible(source: unknown, options?: RenderOptions): AccessibleResult;
@@ -0,0 +1,18 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import {renderWithMathML} from './combined.mjs';
3
+
4
+ // Only a fresh renderer result reaches this composition. No caller-supplied markup.
5
+ export function renderAccessible(source, options = {}) {
6
+ const result = renderWithMathML(source, options), semantic = result.semantics;
7
+ const refuse = errors => ({...result, errors, html: '', presentation: 'refused'});
8
+ if (result.errors.length) return refuse(result.errors);
9
+ if (semantic.status === 'refused') return refuse(semantic.errors);
10
+ // Native MathML links stay visible and focusable; their SVG is returned but never
11
+ // inserted beneath aria-hidden. Ordinary formulas keep the exact visual SVG.
12
+ if (semantic.metrics.links) return {...result, html: semantic.mathml, presentation: 'mathml'};
13
+ if (result.svg.length + semantic.mathml.length + 256 > 40 * 1024 * 1024)
14
+ return refuse([{code: 'resource-limit', offset: 0, message: 'The accessible formula exceeds its output budget.'}]);
15
+ return {...result, presentation: 'svg-mathml', html: '<span class="rapier-math-accessible">' +
16
+ '<span aria-hidden="true">' + result.svg + '</span>' +
17
+ '<span class="rapier-math-assistive">' + semantic.mathml + '</span></span>'};
18
+ }
package/dist/classic.d.ts CHANGED
@@ -1,4 +1,10 @@
1
1
  // SPDX-License-Identifier: MIT
2
- import type API from './index.js';
3
- declare global {var RapierMath: typeof API;}
2
+ import type RapierMath from './index.js';
3
+ import type {toMathML} from './mathml.js';
4
+ import type {renderWithMathML} from './combined.js';
5
+ declare global {
6
+ const RapierMath: typeof import('./index.js').default & Readonly<{
7
+ toMathML: typeof toMathML; renderWithMathML: typeof renderWithMathML;
8
+ }>;
9
+ }
4
10
  export {};
@@ -0,0 +1,4 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import type {RenderOptions, SemanticRenderResult} from './index.js';
3
+ /** Render SVG and MathML from one admitted parse; check each result independently. */
4
+ export function renderWithMathML(source: unknown, options?: RenderOptions): SemanticRenderResult;
@@ -0,0 +1,2 @@
1
+ // SPDX-License-Identifier: MIT
2
+ export {mathRenderWithMathML as renderWithMathML} from '../src/math/combined.js';
package/dist/index.d.ts CHANGED
@@ -24,6 +24,17 @@ export interface RenderResult {
24
24
  fitted: boolean;
25
25
  errors: MathError[];
26
26
  }
27
+ export interface MathMLOptions {displayMode?: boolean}
28
+ export interface MathMLResult {
29
+ mathml: string;
30
+ /** Complete mapping is presentation structure, not theorem or speech semantics. */
31
+ status: 'complete' | 'presentation-fallback' | 'refused';
32
+ /** Fallback notices or refusal diagnostics; an empty array for a complete mapping. */
33
+ errors: MathError[];
34
+ source: {encoding: 'application/x-tex' | 'application/x-rapier-tex-utf16' | null; omitted?: boolean};
35
+ metrics: {nodes: number; depth: number; outputCodeUnits: number; links: number};
36
+ }
37
+ export interface SemanticRenderResult extends RenderResult {semantics: MathMLResult}
27
38
  /** Parser nodes are inspectable; the internal node vocabulary can grow. */
28
39
  export interface MathNode {type: string; [field: string]: unknown}
29
40
  /** Browser nodes (including Element, Document and DocumentFragment) satisfy this