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
@@ -0,0 +1,27 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <meta charset="utf-8">
4
+ <meta name="viewport" content="width=device-width,initial-scale=1">
5
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; style-src 'self'; style-src-attr 'unsafe-inline'; connect-src 'none'; base-uri 'none'; form-action 'none'">
6
+ <title>Rapier Math: structured output</title>
7
+ <link rel="stylesheet" href="../dist/accessible.css">
8
+ <main>
9
+ <h1>Structured mathematical output</h1>
10
+ <form id="math-example">
11
+ <label for="source">TeX source</label>
12
+ <textarea id="source" rows="4" cols="48">\frac{-b\pm\sqrt{b^2-4ac}}{2a}</textarea>
13
+ <button type="submit">Render</button>
14
+ </form>
15
+ <p id="status" aria-live="polite"></p>
16
+ <div id="equation"></div>
17
+ <details><summary>Generated MathML</summary><pre id="mathml"></pre></details>
18
+ <h2>A link around the complete SVG formula</h2>
19
+ <p><a href="https://www.w3.org/TR/mathml-core/" id="outer-equation"></a></p>
20
+ <p>A host link can wrap the ordinary composition. Its focus target stays outside the hidden SVG.</p>
21
+ <h2>A link inside a formula</h2>
22
+ <p>The link below uses visible native MathML and one keyboard focus target.</p>
23
+ <div id="linked-equation"></div>
24
+ <p>Its source: <code id="linked-source"></code></p>
25
+ </main>
26
+ <script type="module" src="./accessible.mjs"></script>
27
+ </html>
@@ -0,0 +1,42 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import {renderAccessible} from '../dist/accessible.mjs';
3
+ import {observe} from '../dist/index.mjs';
4
+
5
+ const form = document.querySelector('#math-example'), source = document.querySelector('#source');
6
+ const container = document.querySelector('#equation'), status = document.querySelector('#status');
7
+ let stop = () => {};
8
+ function update(event) {
9
+ event?.preventDefault();
10
+ stop(); stop = () => {};
11
+ const exactSource = source.value;
12
+ try {
13
+ const result = renderAccessible(exactSource, {displayMode: true});
14
+ document.querySelector('#mathml').textContent = result.semantics.mathml;
15
+ status.textContent = result.semantics.status + (result.semantics.errors.length
16
+ ? ': ' + result.semantics.errors.map(error => error.message).join(' ') : '');
17
+ if (result.errors.length) container.replaceChildren(document.createTextNode(exactSource));
18
+ else {
19
+ // This sink receives only newly generated package output. Authored TeX stays text.
20
+ container.innerHTML = result.html;
21
+ if (result.presentation === 'svg-mathml') stop = observe(container);
22
+ }
23
+ } catch (error) {
24
+ container.replaceChildren(document.createTextNode(exactSource));
25
+ status.textContent = String(error.message);
26
+ }
27
+ }
28
+ const outer = renderAccessible(String.raw`\frac{12}{\sqrt{x}}`);
29
+ const outerElement = document.querySelector('#outer-equation');
30
+ if (!outer.errors.length) outerElement.innerHTML = outer.html;
31
+ else outerElement.textContent = String.raw`\frac{12}{\sqrt{x}}`;
32
+
33
+ const linkedSource = String.raw`\href{https://www.w3.org/TR/mathml-core/}{\frac{12}{\sqrt{x}}}`;
34
+ const linked = renderAccessible(linkedSource);
35
+ document.querySelector('#linked-source').textContent = linkedSource;
36
+ if (!linked.errors.length) document.querySelector('#linked-equation').innerHTML = linked.html;
37
+ else document.querySelector('#linked-equation').textContent = linkedSource;
38
+
39
+ form.addEventListener('submit', update);
40
+ window.addEventListener('pagehide', () => stop());
41
+ window.addEventListener('pageshow', event => { if (event.persisted) update(); });
42
+ update();
@@ -1,9 +1,26 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  import MarkdownIt from 'markdown-it';
3
3
  import rapierMath from 'rapier-math/markdown-it';
4
+ import {createMathSession} from 'rapier-math/stream';
5
+ import {pathToFileURL} from 'node:url';
4
6
 
5
7
  export const md = new MarkdownIt({html: false}).use(rapierMath);
6
- const source = 'It costs $5 and $10. Code: `$$x$$`. Math: \\(x^2\\).\n\n$$\\frac{1}{2}$$\n';
7
- const env = {};
8
- console.log(md.render(source, env));
9
- console.error(env.rapierMathErrors || []);
8
+ export function renderMarkdown(source, mathSession) {
9
+ const env = {rapierMathSession: mathSession};
10
+ return {html: md.render(source, env), errors: env.rapierMathErrors || []};
11
+ }
12
+
13
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
14
+ const source = 'It costs $5 and $10. Code: `$$x$$`. Math: \\(x^2\\).\n\n$$\\frac{1}{2}$$\n';
15
+ const mathSession = createMathSession();
16
+ try {
17
+ // Replace the host's whole preview. The same formulas can reuse work, while
18
+ // each document render has its own limits and diagnostics.
19
+ for (const preview of [source, source + '\nOne more \\(x^2\\).']) {
20
+ const result = renderMarkdown(preview, mathSession);
21
+ console.log(result.html);
22
+ console.error(result.errors);
23
+ }
24
+ console.error(mathSession.stats);
25
+ } finally { mathSession.dispose(); }
26
+ }
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Node/SSR/worker use: this entry does not load or decode the SVG font.
3
+ import {parse, toMathML} from '../dist/mathml.mjs';
4
+
5
+ const source = String.raw`\frac{12.5}{\sqrt[3]{x^2+1}}`;
6
+ const result = toMathML(source, {displayMode: true});
7
+ if (result.status === 'refused') throw new Error(result.errors.map(error => error.message).join('; '));
8
+ console.log(result.mathml);
9
+ console.log(JSON.stringify({status: result.status, metrics: result.metrics, tree: parse(source)}));
10
+ // Retain source separately for edits. SSR can emit result.mathml visibly without CSS
11
+ // or client-side hydration; speech and navigation still depend on the actual AT stack.
@@ -4,16 +4,36 @@ import rapierMath from 'rapier-math/markdown-it';
4
4
  import {createMarkdownStream} from 'rapier-math/stream';
5
5
 
6
6
  const md = new MarkdownIt({html: false}).use(rapierMath);
7
- const stream = createMarkdownStream(source => md.render(source, {}), {previewEvery: 16});
8
- for (const chunk of ['The answer is \\(', '\\frac{1}', '{2}', '\\)', '. Code: `$$x$$`.']) {
9
- const preview = stream.write(chunk);
10
- if (preview) console.log({phase: 'preview', ...preview});
7
+ const renderMarkdown = (source, session) => md.render(source, {rapierMathSession: session});
8
+ let stream = createMarkdownStream(renderMarkdown, {previewEvery: 16});
9
+ let shown;
10
+ function replacePreview(snapshot) {
11
+ // A UI replaces its entire preview with snapshot.html, and keeps snapshot.source
12
+ // for editing/copying. Neither field is an append-only Markdown prefix.
13
+ shown = snapshot;
14
+ console.log({phase: snapshot.final ? 'complete' : 'preview', ...snapshot});
11
15
  }
12
- const final = stream.finish();
13
- console.log({phase: 'complete', ...final});
14
- if (final.html !== md.render(final.source, {})) throw new Error('Batch mismatch');
15
16
 
16
- // One stream per message. On replacement: cancel its transport, reset, write.
17
- stream.reset();
18
- stream.write('Replacement \\(y\\).');
19
- console.log(stream.finish());
17
+ try {
18
+ for (const chunk of ['The answer is \\(', '\\frac{1}', '{2}', '\\)',
19
+ '. Again: \\(\\frac{1}{2}\\).', ' Code: `$$x$$`.']) {
20
+ const preview = stream.write(chunk);
21
+ if (preview) replacePreview(preview);
22
+ }
23
+ replacePreview(stream.finish());
24
+ if (shown.html !== md.render(shown.source, {})) throw new Error('Batch mismatch');
25
+ } finally {
26
+ stream.abort();
27
+ }
28
+
29
+ // Each asynchronous producer captures its own handle. Cancel its transport too.
30
+ const oldProducer = stream;
31
+ stream = stream.reset();
32
+ try {
33
+ try { oldProducer.write('stale source'); }
34
+ catch (error) { console.log({staleProducer: error.message}); }
35
+ stream.write('Replacement \\(y\\).');
36
+ replacePreview(stream.finish());
37
+ } finally {
38
+ stream.abort();
39
+ }
@@ -6,6 +6,7 @@ import remarkRehype from 'remark-rehype';
6
6
  import rehypeSanitize, {defaultSchema} from 'rehype-sanitize';
7
7
  import rehypeRapierMath from 'rapier-math/rehype';
8
8
  import rehypeStringify from 'rehype-stringify';
9
+ import {createMathSession} from 'rapier-math/stream';
9
10
  import {pathToFileURL} from 'node:url';
10
11
 
11
12
  export const processor = unified().use(remarkParse)
@@ -19,8 +20,21 @@ export const processor = unified().use(remarkParse)
19
20
  })
20
21
  .use(rehypeRapierMath).use(rehypeStringify);
21
22
 
23
+ export function renderMarkdown(source, mathSession) {
24
+ // A new VFile keeps diagnostics local to this whole-source render. Only the
25
+ // explicitly supplied message lifetime carries formula work across previews.
26
+ return processor.processSync({value: source, data: {rapierMathSession: mathSession}});
27
+ }
28
+
22
29
  if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
23
- const file = await processor.process('Price $5. Code `$$x$$`. Math $$x^2$$.\n\n$$\n\\frac{1}{2}\n$$');
24
- console.log(String(file));
25
- console.error(file.messages);
30
+ const source = 'Price $5. Code `$$x$$`. Math $$x^2$$.\n\n$$\n\\frac{1}{2}\n$$';
31
+ const mathSession = createMathSession();
32
+ try {
33
+ for (const preview of [source, source + '\n\nOne more $$x^2$$.']) {
34
+ const file = renderMarkdown(preview, mathSession);
35
+ console.log(String(file));
36
+ console.error(file.messages);
37
+ }
38
+ console.error(mathSession.stats);
39
+ } finally { mathSession.dispose(); }
26
40
  }
package/package.json CHANGED
@@ -1,18 +1,31 @@
1
1
  {
2
2
  "name": "rapier-math",
3
- "version": "1.1.1",
3
+ "version": "2.1.0",
4
4
  "description": "Self-contained offline LaTeX-to-SVG rendering with Latin Modern outlines, optional Markdown integrations and streaming helpers.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
8
8
  "sideEffects": [
9
- "./dist/rapier-math.js"
9
+ "./dist/rapier-math.js",
10
+ "./dist/accessible.css"
10
11
  ],
11
12
  "exports": {
12
13
  ".": {
13
14
  "types": "./dist/index.d.ts",
14
15
  "default": "./dist/index.mjs"
15
16
  },
17
+ "./mathml": {
18
+ "types": "./dist/mathml.d.ts",
19
+ "default": "./dist/mathml.mjs"
20
+ },
21
+ "./combined": {
22
+ "types": "./dist/combined.d.ts",
23
+ "default": "./dist/combined.mjs"
24
+ },
25
+ "./accessible": {
26
+ "types": "./dist/accessible.d.ts",
27
+ "default": "./dist/accessible.mjs"
28
+ },
16
29
  "./delimiters": {
17
30
  "types": "./dist/delimiters.d.ts",
18
31
  "default": "./dist/delimiters.mjs"
@@ -29,6 +42,7 @@
29
42
  "types": "./dist/stream.d.ts",
30
43
  "default": "./dist/stream.mjs"
31
44
  },
45
+ "./accessible.css": "./dist/accessible.css",
32
46
  "./classic": {
33
47
  "types": "./dist/classic.d.ts",
34
48
  "default": "./dist/rapier-math.js"
package/src/math/api.js CHANGED
@@ -25,43 +25,9 @@ function mathSvg(box,source,error,utf16,options={}) {
25
25
  return {svg,width,height,depth,lines:box.lines || 1,fitted:!!box.fitted,errors:error?[error]:[]};
26
26
  }
27
27
 
28
- function mathSourceAlternative(source) {
29
- const alternatives=[],parts=[];
30
- let first=-1,kept=0;
31
- for(let i=0;i<source.length;i++) {
32
- const code=source.charCodeAt(i);
33
- if(code>=0xd800 && code<=0xdbff && i+1<source.length) {
34
- const next=source.charCodeAt(i+1);
35
- if(next>=0xdc00 && next<=0xdfff) {i++;continue;}
36
- }
37
- if((code>=0x20 && code<=0xd7ff) || (code>=0xe000 && code<=0xfffd) || code===9 || code===10 || code===13)continue;
38
- if(first<0)first=i;
39
- if(i>kept)parts.push(source.slice(kept,i));
40
- parts.push('\\u'+code.toString(16).toUpperCase().padStart(4,'0'));kept=i+1;
41
- // Flatten small batches instead of retaining one rope node per bad code unit.
42
- if(parts.length>=1024) {alternatives.push(parts.join(''));parts.length=0;}
43
- }
44
- if(first<0)return {alternative:source};
45
- parts.push(source.slice(kept));alternatives.push(parts.join(''));
46
- // Only malformed XML text needs a separate carrier; each four hex digits keep one original code unit.
47
- const encoded=[];parts.length=0;
48
- for(let i=0;i<source.length;i++) {
49
- parts.push(source.charCodeAt(i).toString(16).padStart(4,'0'));
50
- if(parts.length===1024) {encoded.push(parts.join(''));parts.length=0;}
51
- }
52
- encoded.push(parts.join(''));
53
- return {alternative:alternatives.join(''),utf16:encoded.join(''),error:{code:'invalid-source-character',offset:first,
54
- message:'A source character cannot be embedded in SVG. The text alternative shows Unicode escapes; data-tex-utf16 keeps the original source.'}};
55
- }
56
-
57
- function renderMath(source,options={}) {
58
- const text=String(source ?? '');
59
- // Reject before scanning, escaping or parsing. Keep the diagnostic-return
60
- // contract, but explicitly omit refused source instead of expanding it.
61
- const safe=text.length>1000000?{alternative:'Formula source omitted: source limit exceeded.',error:{
62
- code:'resource-limit',offset:0,sourceOmitted:true,
63
- message:'This formula is too long to render safely. Its source was not embedded; retain the original input.'
64
- }}:mathSourceAlternative(text),context={size:1,level:0,variant:'normal',cramped:false,display:!!options?.displayMode,cache:new WeakMap(),budget:{nodes:0,outlineBytes:0}};
28
+ function mathRenderPrepared(prepared,options={}) {
29
+ const {text,safe,tree,error:parseError}=prepared;
30
+ const context={size:1,level:0,variant:'normal',cramped:false,display:!!options?.displayMode,cache:new WeakMap(),budget:{nodes:0,outlineBytes:0}};
65
31
  try {
66
32
  if(safe.error)throw safe.error;
67
33
  if(options?.screen!==undefined) {
@@ -72,20 +38,14 @@ function renderMath(source,options={}) {
72
38
  throw Object.assign(new Error('Screen font size, pixel ratio and device scale must be positive and finite; dark must be a boolean.'),{code:'invalid-screen'});
73
39
  context.screen={fontSize:scaled,pixelRatio,dark};
74
40
  }
75
- const tree=parseMathTex(text),natural=mathLayout(tree,context),limit=Number(options?.maxWidth);
41
+ if(parseError)throw parseError;
42
+ const natural=mathLayout(tree,context),limit=Number(options?.maxWidth);
76
43
  const maxWidth=Number.isFinite(limit) && limit>.1?limit:undefined;
77
44
  const box=maxWidth && mathInkWidth(natural)>maxWidth-.05?mathResponsiveLayout(tree,context,maxWidth-.05,natural):natural;
78
- return mathSvg(box,safe.alternative,undefined,undefined,{displayMode:context.display,maxWidth,naturalWidth:mathInkWidth(natural)+.05,screen:context.screen});
45
+ return mathSvg(box,safe.alternative,undefined,safe.utf16,{displayMode:context.display,maxWidth,naturalWidth:mathInkWidth(natural)+.05,screen:context.screen});
79
46
  }
80
47
  catch (cause) {
81
- const message=String(cause.message || cause);
82
- const error={code:cause.code || 'invalid-tex',message:message.length>1024?message.slice(0,1024).replace(/[\ud800-\udbff]$/,'')+'…':message,offset:Number.isFinite(cause.offset)?cause.offset:0};
83
- if(message.length>1024)error.messageTruncated=true;
84
- if(cause.sourceOmitted)error.sourceOmitted=true;
85
- if(cause.command) {
86
- error.command=String(cause.command).slice(0,128);
87
- if(cause.command.length>128)error.commandTruncated=true;
88
- }
48
+ const error=mathDiagnostic(cause);
89
49
  // A diagnostic is visible, but remains distinct from a successfully typeset formula.
90
50
  // Diagnostics have an explicit bound. Exact input stays in the source alternative.
91
51
  const label=error.message.length>240?'This formula could not be rendered. The complete diagnostic is in its text description.':error.message.replace(/[^\x20-\x7e]/g,'?');
@@ -99,11 +59,12 @@ function renderMath(source,options={}) {
99
59
  }
100
60
  }
101
61
 
102
- globalThis.RapierMath=Object.freeze({
103
- version:'1.1.1',
104
- parse:parseMathTex,
105
- render:renderMath,
106
- fit:mathFit,
107
- observe:mathObserve,
108
- renderToString(source,options) {return renderMath(source,options).svg;},
109
- });
62
+ function renderMath(source,options={}) {
63
+ return mathRenderPrepared(mathPrepare(source),options);
64
+ }
65
+ function mathRenderToString(source,options) { return renderMath(source,options).svg; }
66
+
67
+ import {mathDiagnostic, mathPrepare} from './source.js';
68
+ import {mathNumber, mathEscape, mathFontRatio, mathText, mathLayout} from './layout.js';
69
+ import {mathInkWidth, mathResponsiveLayout} from './responsive.js';
70
+ export {renderMath, mathRenderPrepared, mathRenderToString};
@@ -185,3 +185,7 @@ function mathObserve(root) {
185
185
  if(current.nodes.size)current.schedule();else current.dispose();
186
186
  };
187
187
  }
188
+
189
+ import {mathNumber, mathFontRatio} from './layout.js';
190
+ import {renderMath} from './api.js';
191
+ export {mathFit, mathObserve};
@@ -0,0 +1,7 @@
1
+ // SPDX-License-Identifier: MIT
2
+ globalThis.RapierMath=Object.freeze({
3
+ version:'2.1.0', parse:parseMathTex,
4
+ render:renderMath, renderToString:mathRenderToString,
5
+ fit:mathFit, observe:mathObserve,
6
+ toMathML:mathToMathML, renderWithMathML:mathRenderWithMathML,
7
+ });
@@ -0,0 +1,13 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // The prepared tree never crosses the public boundary. Both outputs consume it
3
+ // within this call, before any result or caller-mutable parse tree is exposed.
4
+ function mathRenderWithMathML(source, options = {}) {
5
+ const prepared = mathPrepare(source), displayMode = !!options?.displayMode;
6
+ const semantics = mathSemanticPrepared(prepared, {displayMode});
7
+ return {...mathRenderPrepared(prepared, {...options, displayMode}), semantics};
8
+ }
9
+
10
+ import {mathPrepare} from './source.js';
11
+ import {mathRenderPrepared} from './api.js';
12
+ import {mathSemanticPrepared} from './semantic-api.js';
13
+ export {mathRenderWithMathML};
@@ -109,3 +109,8 @@ function mathFallbackGlyph(value,c,extra={}) {
109
109
  }
110
110
  return null;
111
111
  }
112
+
113
+ import {MATH_FONT} from './font.js';
114
+ import {mathStyledCodePoint} from './variants.js';
115
+ import {mathNumber, mathScale, mathScreenStroke, mathConstant, mathBox, mathCompose, mathGlyphIndex, mathRule, mathStretch} from './layout.js';
116
+ export {mathFallbackGlyph};
package/src/math/font.js CHANGED
@@ -545,3 +545,6 @@ complete(r);return remember(profileCache,id,profile,128);
545
545
  MATH_FONT.glyph=id=>glyphRecord(id)?.glyph;
546
546
  MATH_FONT.profile=id=>{const glyph=glyphRecord(id);return glyph&&glyph.profile>=0?profileRecord(glyph.profile):undefined;};
547
547
  }
548
+
549
+
550
+ export {MATH_FONT};
@@ -41,43 +41,6 @@ function mathCompose(items, width, extra = {}) {
41
41
  return mathBox(width, h, d, svg, {left, right, inkTop:Number.isFinite(inkTop)?inkTop:-h, inkBottom:Number.isFinite(inkBottom)?inkBottom:d,...glyph,...extra});
42
42
  }
43
43
 
44
- const MATH_STYLED_RANGES = {
45
- italic: [0x1d434, 0x1d44e, null], bold: [0x1d400, 0x1d41a, 0x1d7ce],
46
- 'bold-italic': [0x1d468, 0x1d482, null], script: [0x1d49c, 0x1d4b6, null],
47
- 'bold-script': [0x1d4d0, 0x1d4ea, null], fraktur: [0x1d504, 0x1d51e, null],
48
- 'bold-fraktur': [0x1d56c, 0x1d586, null], 'double-struck': [0x1d538, 0x1d552, 0x1d7d8],
49
- 'sans-serif': [0x1d5a0, 0x1d5ba, 0x1d7e2], 'sans-serif-bold': [0x1d5d4, 0x1d5ee, 0x1d7ec],
50
- 'sans-serif-italic': [0x1d608, 0x1d622, null], 'sans-serif-bold-italic': [0x1d63c, 0x1d656, null],
51
- monospace: [0x1d670, 0x1d68a, 0x1d7f6],
52
- };
53
- const MATH_STYLED_LEGACY = {
54
- italic: {104: 0x210e},
55
- script: {66:0x212c,69:0x2130,70:0x2131,72:0x210b,73:0x2110,76:0x2112,77:0x2133,82:0x211b,101:0x212f,103:0x210a,111:0x2134},
56
- fraktur: {67:0x212d,72:0x210c,73:0x2111,82:0x211c,90:0x2128},
57
- 'double-struck': {67:0x2102,72:0x210d,78:0x2115,80:0x2119,81:0x211a,82:0x211d,90:0x2124},
58
- };
59
- const MATH_STYLED_GREEK = {bold:0x1d6a8, italic:0x1d6e2, 'bold-italic':0x1d71c, 'sans-serif-bold':0x1d756, 'sans-serif-bold-italic':0x1d790};
60
- const MATH_STYLED_GREEK_SPECIAL = [0x2207,0x2202,0x3f5,0x3d1,0x3f0,0x3d5,0x3f1,0x3d6];
61
- function mathStyledCodePoint(cp, variant) {
62
- if (variant === 'normal') variant = 'italic';
63
- if (MATH_STYLED_LEGACY[variant]?.[cp] !== undefined) return MATH_STYLED_LEGACY[variant][cp];
64
- const r = MATH_STYLED_RANGES[variant];
65
- if (r) {
66
- if (cp >= 65 && cp <= 90) return r[0] + cp - 65;
67
- if (cp >= 97 && cp <= 122) return r[1] + cp - 97;
68
- if (r[2] && cp >= 48 && cp <= 57) return r[2] + cp - 48;
69
- }
70
- const greek = MATH_STYLED_GREEK[variant];
71
- if (greek !== undefined) {
72
- if (cp >= 0x391 && cp <= 0x3a9 && cp !== 0x3a2) return greek + cp - 0x391;
73
- if (cp >= 0x3b1 && cp <= 0x3c9) return greek + 26 + cp - 0x3b1;
74
- const special = MATH_STYLED_GREEK_SPECIAL.indexOf(cp);
75
- if (special === 0) return greek + 25;
76
- if (special > 0) return greek + 50 + special;
77
- }
78
- return cp;
79
- }
80
-
81
44
  function mathGlyphIndex(id, c, extra = {}) {
82
45
  if(c.dotless)id=MATH_FONT.dotless?.[id] ?? id;
83
46
  const alternates=MATH_FONT.scriptAlternates[id],scale=mathScale(c);
@@ -578,3 +541,9 @@ function mathLayout(n,c) {
578
541
  default: throw Object.assign(new Error('Unsupported maths construct: '+n.type),{code:'unsupported-construct'});
579
542
  }
580
543
  }
544
+
545
+ import {MATH_FONT} from './font.js';
546
+ import {mathStyledCodePoint} from './variants.js';
547
+ import {mathFallbackGlyph} from './fallbacks.js';
548
+ import {mathResponsiveLayout} from './responsive.js';
549
+ export {mathNumber, mathScale, mathScreenStroke, mathConstant, mathBox, mathCompose, mathGlyphIndex, mathRule, mathStretch, mathEscape, mathScreenRelayout, mathSpace, mathRow, mathFraction, mathFenceBoxes, mathLayout, mathFontRatio, mathText};