rapier-math 2.0.0 → 2.2.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 +15 -5
- package/dist/accessible.css +6 -0
- package/dist/accessible.d.ts +10 -0
- package/dist/accessible.mjs +18 -0
- package/dist/classic.d.ts +8 -2
- package/dist/combined.d.ts +4 -0
- package/dist/combined.mjs +2 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.mjs +6 -2980
- package/dist/integration.d.ts +3 -1
- package/dist/integration.mjs +13 -19
- package/dist/markdown-it.mjs +7 -4
- package/dist/mathml.d.ts +5 -0
- package/dist/mathml.mjs +3 -0
- package/dist/rapier-math.js +674 -173
- package/dist/rehype.mjs +13 -3
- package/docs/api.md +42 -4
- package/docs/math-components.json +6 -5
- package/docs/math-resources.json +150 -54
- package/docs/semantics.md +228 -0
- package/examples/README.md +10 -0
- package/examples/accessible.html +27 -0
- package/examples/accessible.mjs +42 -0
- package/examples/semantic.mjs +11 -0
- package/package.json +16 -2
- package/src/math/api.js +16 -55
- package/src/math/browser.js +4 -0
- package/src/math/classic.js +7 -0
- package/src/math/combined.js +13 -0
- package/src/math/fallbacks.js +5 -0
- package/src/math/font.js +3 -0
- package/src/math/layout.js +56 -53
- package/src/math/mathml.js +408 -0
- package/src/math/package-build.mjs +24 -11
- package/src/math/package-layout.mjs +3 -0
- package/src/math/package-readme.mjs +14 -4
- package/src/math/parser.js +36 -20
- package/src/math/responsive.js +4 -0
- package/src/math/semantic-api.js +12 -0
- package/src/math/source.js +67 -0
- package/src/math/symbols.js +6 -3
- package/src/math/variants.js +41 -0
- package/src/tools/build-math.mjs +18 -10
- package/tests/adoption.mjs +34 -0
- package/tests/check.mjs +13 -5
- package/tests/semantics.mjs +340 -0
- package/tests/verify.mjs +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Rapier Math
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
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
|
|
27
|
-
`src
|
|
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 2.
|
|
51
|
+
Version 2.2.0. Classic payload: 749536 bytes; gzip (level 9): 453279 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
|
|
3
|
-
|
|
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;
|
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
|