rapier-math 1.0.2 → 1.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.
- package/README.md +187 -85
- package/adoption-check.mjs +149 -0
- package/check.mjs +21 -0
- package/classic.d.ts +4 -0
- package/delimiters.d.ts +8 -0
- package/delimiters.mjs +39 -0
- package/examples/README.md +25 -0
- package/examples/browser.html +10 -0
- package/examples/browser.mjs +24 -0
- package/examples/formula.mjs +12 -0
- package/examples/markdown.mjs +9 -0
- package/examples/react.tsx +19 -0
- package/examples/stream.mjs +19 -0
- package/examples/unified.mjs +26 -0
- package/examples/worker.mjs +7 -0
- package/index.d.ts +43 -0
- package/index.mjs +43 -15
- package/integration.d.ts +9 -0
- package/integration.mjs +28 -0
- package/markdown-it.d.ts +6 -0
- package/markdown-it.mjs +45 -0
- package/markdown-rules.mjs +65 -0
- package/math-components.json +6 -6
- package/package.json +78 -5
- package/{rapier-math-1.0.2.js → rapier-math-1.1.0.js} +43 -15
- package/rehype.d.ts +6 -0
- package/rehype.mjs +37 -0
- package/src/math/README.md +210 -0
- package/src/math/adoption-verify.mjs +149 -0
- package/src/math/api.js +35 -13
- package/src/math/browser.js +7 -1
- package/src/math/classic.d.ts +4 -0
- package/src/math/delimiters.d.ts +8 -0
- package/src/math/delimiters.mjs +39 -0
- package/src/math/examples/README.md +25 -0
- package/src/math/examples/browser.html +10 -0
- package/src/math/examples/browser.mjs +24 -0
- package/src/math/examples/formula.mjs +12 -0
- package/src/math/examples/markdown.mjs +9 -0
- package/src/math/examples/react.tsx +19 -0
- package/src/math/examples/stream.mjs +19 -0
- package/src/math/examples/unified.mjs +26 -0
- package/src/math/examples/worker.mjs +7 -0
- package/src/math/index.d.ts +43 -0
- package/src/math/integration.d.ts +9 -0
- package/src/math/integration.mjs +28 -0
- package/src/math/layout.js +1 -1
- package/src/math/markdown-it.d.ts +6 -0
- package/src/math/markdown-it.mjs +45 -0
- package/src/math/markdown-rules.mjs +65 -0
- package/src/math/package-build.mjs +4 -4
- package/src/math/package-check.mjs +118 -0
- package/src/math/package-readme.mjs +8 -0
- package/src/math/package-verify.mjs +7 -2
- package/src/math/rehype.d.ts +6 -0
- package/src/math/rehype.mjs +37 -0
- package/src/math/stream.d.ts +14 -0
- package/src/math/stream.mjs +46 -0
- package/src/package.json +1 -1
- package/src/shell/math-resources.json +176 -17
- package/src/tools/build-math.mjs +19 -3
- package/stream.d.ts +14 -0
- package/stream.mjs +46 -0
- package/verify.mjs +7 -2
package/src/math/browser.js
CHANGED
|
@@ -88,12 +88,18 @@ function mathFitElement(svg, printing = false) {
|
|
|
88
88
|
if(screenKey!==state.screen || (target===null)!==(state.width===null) || target!==null && Math.abs(target-state.width)>.005) {
|
|
89
89
|
const rendered=renderMath(source,{displayMode:display,maxWidth:(screenKey!==state.screen?width:target) || undefined,screen});
|
|
90
90
|
if(!rendered.errors.length) {
|
|
91
|
+
const active=doc.activeElement,links=active && svg.contains(active)?[...svg.querySelectorAll('a')]:[];
|
|
92
|
+
const focusIndex=links.indexOf(active),focusHref=focusIndex<0?null:active.getAttribute('href');
|
|
91
93
|
const replacement=new view.DOMParser().parseFromString(rendered.svg,'image/svg+xml').documentElement;
|
|
92
|
-
for(const name of ['width','height','viewBox','data-math-natural-width','data-math-max-width','data-math-lines','data-math-screen']) {
|
|
94
|
+
for(const name of ['role','width','height','viewBox','data-math-natural-width','data-math-max-width','data-math-lines','data-math-screen']) {
|
|
93
95
|
if(replacement.hasAttribute(name))svg.setAttribute(name,replacement.getAttribute(name));else svg.removeAttribute(name);
|
|
94
96
|
}
|
|
95
97
|
svg.style.verticalAlign=replacement.style.verticalAlign;
|
|
96
98
|
svg.replaceChildren(...Array.from(replacement.childNodes,node=>doc.importNode(node,true)));
|
|
99
|
+
if(focusIndex>=0 && (!doc.activeElement || doc.activeElement===doc.body)) {
|
|
100
|
+
const link=svg.querySelectorAll('a')[focusIndex];
|
|
101
|
+
if(link?.getAttribute('href')===focusHref)link.focus({preventScroll:true});
|
|
102
|
+
}
|
|
97
103
|
state.natural=Number(svg.getAttribute('data-math-natural-width'));state.screen=screenKey;
|
|
98
104
|
state.width=state.natural>width?width:null;
|
|
99
105
|
if(state.width===null)svg.removeAttribute('data-math-max-width');
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
export interface DelimiterOptions {singleDollar?: boolean; brackets?: boolean}
|
|
3
|
+
export interface MathSpan {
|
|
4
|
+
start: number; end: number; bodyStart: number; bodyEnd: number;
|
|
5
|
+
open: string; close: string; displayMode: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** Index a raw, host-owned text region. Does not parse Markdown or unescape source. */
|
|
8
|
+
export function createMathMatcher(source: string, options?: DelimiterOptions): (start: number, limit?: number) => MathSpan | null;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// A boundary index for a host-owned text region, not a Markdown parser.
|
|
3
|
+
export function createMathMatcher(source, {singleDollar = false, brackets = true} = {}) {
|
|
4
|
+
if (typeof source !== 'string') throw new TypeError('Math boundaries require source text.');
|
|
5
|
+
const markers = new Map(), next = Object.create(null);
|
|
6
|
+
let slashes = 0, line = 0;
|
|
7
|
+
for (let at = 0; at < source.length;) {
|
|
8
|
+
const char = source[at];
|
|
9
|
+
if (char === '\\') { slashes++; at++; continue; }
|
|
10
|
+
if (char === '\n' || char === '\r') line++;
|
|
11
|
+
if (char === '$') {
|
|
12
|
+
let end = at + 1;
|
|
13
|
+
while (source[end] === '$') end++;
|
|
14
|
+
const count = end - at;
|
|
15
|
+
if (!(slashes & 1) && (count === 2 || count === 1 && singleDollar))
|
|
16
|
+
markers.set(at, {at, marker: count === 2 ? '$$' : '$', line});
|
|
17
|
+
at = end;
|
|
18
|
+
} else {
|
|
19
|
+
if (brackets && slashes & 1 && '()[]'.includes(char))
|
|
20
|
+
markers.set(at - 1, {at: at - 1, marker: '\\' + char, line});
|
|
21
|
+
at++;
|
|
22
|
+
}
|
|
23
|
+
slashes = 0;
|
|
24
|
+
}
|
|
25
|
+
for (const entry of [...markers.values()].reverse()) {
|
|
26
|
+
const closing = entry.marker === '\\(' ? '\\)' : entry.marker === '\\[' ? '\\]' : entry.marker;
|
|
27
|
+
entry.close = next[closing];
|
|
28
|
+
next[entry.marker] = entry;
|
|
29
|
+
}
|
|
30
|
+
return function match(start, limit = source.length) {
|
|
31
|
+
const open = markers.get(start), close = open?.close;
|
|
32
|
+
if (!close || open.marker === '\\)' || open.marker === '\\]' || close.at + close.marker.length > limit) return null;
|
|
33
|
+
const bodyStart = start + open.marker.length, bodyEnd = close.at;
|
|
34
|
+
if (open.marker === '$' && (open.line !== close.line || bodyStart === bodyEnd ||
|
|
35
|
+
/\s/.test(source[bodyStart]) || /\s/.test(source[bodyEnd - 1]) || /[0-9]/.test(source[bodyEnd + 1] || ''))) return null;
|
|
36
|
+
return {start, end: bodyEnd + close.marker.length, bodyStart, bodyEnd,
|
|
37
|
+
open: open.marker, close: close.marker, displayMode: open.marker === '$$' || open.marker === '\\['};
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Run the installed examples
|
|
2
|
+
|
|
3
|
+
From a consumer directory, install `rapier-math`, then run
|
|
4
|
+
`node node_modules/rapier-math/examples/formula.mjs`.
|
|
5
|
+
|
|
6
|
+
For Markdown and streaming, also install `markdown-it` and run `markdown.mjs` or `stream.mjs`.
|
|
7
|
+
For unified, install `unified remark-parse remark-math remark-rehype rehype-sanitize rehype-stringify hast-util-from-html`
|
|
8
|
+
and run `unified.mjs`. The remark example uses remark's syntax; it does not recognize backslash delimiters.
|
|
9
|
+
|
|
10
|
+
Serve the package directory over HTTP and open `examples/browser.html`. Its external module imports the
|
|
11
|
+
installed ESM renderer, fits the output and releases observation before replacement and on page exit.
|
|
12
|
+
Start `new Worker('./worker.mjs', {type: 'module'})` from this directory and post `{id, source}`.
|
|
13
|
+
Use an id owned by the current message and ignore stale replies. Workers render SVG; they do not call `observe`.
|
|
14
|
+
|
|
15
|
+
`react.tsx` is a small React 19/SSR component to copy into an existing TypeScript application. Install
|
|
16
|
+
`react react-dom` and the development types `@types/react @types/react-dom`. No framework is required by the core.
|
|
17
|
+
|
|
18
|
+
For streamed UTF-8, use `TextDecoderStream` or `decoder.decode(bytes, {stream: true})` and flush the decoder
|
|
19
|
+
at EOF. Feed decoded strings into one stream per message. Append incoming chunks to a text node for immediate
|
|
20
|
+
literal progress, and replace the whole preview when `write` returns a snapshot. Replace it with `finish()` at EOF.
|
|
21
|
+
Do not concatenate transport data into HTML. On cancellation call `abort`; on replacement cancel the old producer
|
|
22
|
+
before `reset`. A producer that still runs needs its own generation check before calling `write`.
|
|
23
|
+
|
|
24
|
+
The examples retain the original source as the editable/copyable authority. Markdown hosts can normalize
|
|
25
|
+
newlines or escapes in their syntax nodes; an HTML serialization is not an exact source archive.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<meta charset="utf-8">
|
|
3
|
+
<meta name="viewport" content="width=device-width">
|
|
4
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; style-src-attr 'unsafe-inline'; style-src-elem 'none'; worker-src 'self'; connect-src 'none'; base-uri 'none'">
|
|
5
|
+
<title>Rapier Math example</title>
|
|
6
|
+
<label>TeX <textarea id="source">\frac{-b\pm\sqrt{b^2-4ac}}{2a}</textarea></label>
|
|
7
|
+
<button id="render" type="button">Render</button>
|
|
8
|
+
<main id="equation"></main>
|
|
9
|
+
<pre id="errors"></pre>
|
|
10
|
+
<script type="module" src="./browser.mjs"></script>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import {render, observe} from '../index.mjs';
|
|
3
|
+
const container = document.querySelector('#equation');
|
|
4
|
+
const source = document.querySelector('#source');
|
|
5
|
+
let stop = () => {};
|
|
6
|
+
function update() {
|
|
7
|
+
stop();
|
|
8
|
+
try {
|
|
9
|
+
const result = render(source.value, {displayMode: true});
|
|
10
|
+
document.querySelector('#errors').textContent = JSON.stringify(result.errors);
|
|
11
|
+
if (result.errors.length) container.replaceChildren(document.createTextNode(source.value));
|
|
12
|
+
else {
|
|
13
|
+
// Only this renderer's freshly returned SVG reaches the HTML sink.
|
|
14
|
+
container.innerHTML = result.svg;
|
|
15
|
+
stop = observe(container);
|
|
16
|
+
}
|
|
17
|
+
} catch (error) {
|
|
18
|
+
container.replaceChildren(document.createTextNode(source.value));
|
|
19
|
+
document.querySelector('#errors').textContent = error.message;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
document.querySelector('#render').addEventListener('click', update);
|
|
23
|
+
window.addEventListener('pagehide', () => stop());
|
|
24
|
+
update();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import {render, renderToString} from 'rapier-math';
|
|
3
|
+
|
|
4
|
+
// Works in Node/SSR: the result needs no browser JavaScript or remote font.
|
|
5
|
+
const source = String.raw`\frac{-b\pm\sqrt{b^2-4ac}}{2a}`;
|
|
6
|
+
const result = render(source, {displayMode: true});
|
|
7
|
+
if (result.errors.length) throw new Error(JSON.stringify(result.errors));
|
|
8
|
+
console.log(result.svg);
|
|
9
|
+
console.log(renderToString('E=mc^2'));
|
|
10
|
+
const failure = render(String.raw`\unsupported{x}`);
|
|
11
|
+
console.error({source: String.raw`\unsupported{x}`, errors: failure.errors});
|
|
12
|
+
// Retain the original source for editing/copying, even if admission throws.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import MarkdownIt from 'markdown-it';
|
|
3
|
+
import rapierMath from 'rapier-math/markdown-it';
|
|
4
|
+
|
|
5
|
+
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 || []);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import {useEffect, useMemo, useRef} from 'react';
|
|
3
|
+
import {render, observe} from 'rapier-math';
|
|
4
|
+
|
|
5
|
+
export function Equation({source, displayMode = false}: {source: string; displayMode?: boolean}) {
|
|
6
|
+
const ref = useRef<HTMLSpanElement>(null);
|
|
7
|
+
const result = useMemo(() => {
|
|
8
|
+
try { return render(source, {displayMode}); }
|
|
9
|
+
catch { return null; }
|
|
10
|
+
}, [source, displayMode]);
|
|
11
|
+
const svg = result && result.errors.length === 0 ? result.svg : null;
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (ref.current && svg) return observe(ref.current);
|
|
14
|
+
}, [svg]); // Cleanup runs before replacement setup and on unmount.
|
|
15
|
+
if (!svg) return <code>{source}</code>;
|
|
16
|
+
// The server and initial client render use identical source/options. Fit only
|
|
17
|
+
// after hydration; never pass authored HTML to dangerouslySetInnerHTML.
|
|
18
|
+
return <span ref={ref} dangerouslySetInnerHTML={{__html: svg}} />;
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import MarkdownIt from 'markdown-it';
|
|
3
|
+
import rapierMath from 'rapier-math/markdown-it';
|
|
4
|
+
import {createMarkdownStream} from 'rapier-math/stream';
|
|
5
|
+
|
|
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});
|
|
11
|
+
}
|
|
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
|
+
// One stream per message. On replacement: cancel its transport, reset, write.
|
|
17
|
+
stream.reset();
|
|
18
|
+
stream.write('Replacement \\(y\\).');
|
|
19
|
+
console.log(stream.finish());
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import {unified} from 'unified';
|
|
3
|
+
import remarkParse from 'remark-parse';
|
|
4
|
+
import remarkMath from 'remark-math';
|
|
5
|
+
import remarkRehype from 'remark-rehype';
|
|
6
|
+
import rehypeSanitize, {defaultSchema} from 'rehype-sanitize';
|
|
7
|
+
import rehypeRapierMath from 'rapier-math/rehype';
|
|
8
|
+
import rehypeStringify from 'rehype-stringify';
|
|
9
|
+
import {pathToFileURL} from 'node:url';
|
|
10
|
+
|
|
11
|
+
export const processor = unified().use(remarkParse)
|
|
12
|
+
.use(remarkMath, {singleDollarTextMath: false}).use(remarkRehype)
|
|
13
|
+
.use(rehypeSanitize, {
|
|
14
|
+
...defaultSchema,
|
|
15
|
+
attributes: {...defaultSchema.attributes, code: [
|
|
16
|
+
...(defaultSchema.attributes.code || []).filter(rule => !(Array.isArray(rule) && rule[0] === 'className')),
|
|
17
|
+
['className', 'language-math', 'math-inline', 'math-display'],
|
|
18
|
+
]},
|
|
19
|
+
})
|
|
20
|
+
.use(rehypeRapierMath).use(rehypeStringify);
|
|
21
|
+
|
|
22
|
+
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);
|
|
26
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import {render} from '../index.mjs';
|
|
3
|
+
self.onmessage = ({data: {id, source}}) => {
|
|
4
|
+
try { self.postMessage({id, source, result: render(source)}); }
|
|
5
|
+
catch (error) { self.postMessage({id, source, error: {code: error.code, message: error.message}}); }
|
|
6
|
+
};
|
|
7
|
+
// Keep a request id per message; install a reply only if it is still current.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
export interface MathError {
|
|
3
|
+
code: string;
|
|
4
|
+
message: string;
|
|
5
|
+
/** Zero-based UTF-16 offset in the formula. */
|
|
6
|
+
offset: number;
|
|
7
|
+
command?: string;
|
|
8
|
+
messageTruncated?: boolean;
|
|
9
|
+
commandTruncated?: boolean;
|
|
10
|
+
/** True only when refused oversized source is not embedded in diagnostic SVG. */
|
|
11
|
+
sourceOmitted?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface RenderOptions {
|
|
14
|
+
displayMode?: boolean;
|
|
15
|
+
maxWidth?: number;
|
|
16
|
+
screen?: {fontSize: number; pixelRatio: number; dark: boolean};
|
|
17
|
+
}
|
|
18
|
+
export interface RenderResult {
|
|
19
|
+
svg: string;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
depth: number;
|
|
23
|
+
lines: number;
|
|
24
|
+
fitted: boolean;
|
|
25
|
+
errors: MathError[];
|
|
26
|
+
}
|
|
27
|
+
/** Parser nodes are inspectable; the internal node vocabulary can grow. */
|
|
28
|
+
export interface MathNode {type: string; [field: string]: unknown}
|
|
29
|
+
/** Browser nodes (including Element, Document and DocumentFragment) satisfy this
|
|
30
|
+
* structural type without requiring the DOM type library in server projects. */
|
|
31
|
+
export interface MathContainer {readonly nodeType: number}
|
|
32
|
+
export const version: string;
|
|
33
|
+
/** Oversized source returns a bounded resource-limit diagnostic with sourceOmitted. */
|
|
34
|
+
export function render(source: unknown, options?: RenderOptions): RenderResult;
|
|
35
|
+
export function renderToString(source: unknown, options?: RenderOptions): string;
|
|
36
|
+
export function parse(source: string): MathNode;
|
|
37
|
+
export function fit(container: MathContainer): number;
|
|
38
|
+
export function observe(container: MathContainer): () => void;
|
|
39
|
+
declare const RapierMath: Readonly<{
|
|
40
|
+
version: typeof version; render: typeof render; renderToString: typeof renderToString;
|
|
41
|
+
parse: typeof parse; fit: typeof fit; observe: typeof observe;
|
|
42
|
+
}>;
|
|
43
|
+
export default RapierMath;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import type {RenderOptions} from './index.js';
|
|
3
|
+
export interface IntegrationOptions {
|
|
4
|
+
renderOptions?: RenderOptions;
|
|
5
|
+
/** Per document. Default 1024. Exhaustion leaves subsequent math as source. */
|
|
6
|
+
maxFormulas?: number;
|
|
7
|
+
/** Combined successful SVG code units per document. Default 16 * 1024 * 1024. */
|
|
8
|
+
maxOutputLength?: number;
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import {render} from './index.mjs';
|
|
3
|
+
|
|
4
|
+
export const escapeText = text => text.replace(/[&<>"'\r]/g, char =>
|
|
5
|
+
({'&': '&', '<': '<', '>': '>', '"': '"', "'": ''', '\r': ' '}[char]));
|
|
6
|
+
|
|
7
|
+
// One budget per document render. Rejection leaves the host's text node intact.
|
|
8
|
+
export function createFormulaRenderer(options = {}) {
|
|
9
|
+
const maxFormulas = options.maxFormulas ?? 1024, maxOutputLength = options.maxOutputLength ?? 16 * 1024 * 1024;
|
|
10
|
+
for (const value of [maxFormulas, maxOutputLength])
|
|
11
|
+
if (!Number.isSafeInteger(value) || value < 0) throw new RangeError('Math integration budgets must be finite nonnegative integers.');
|
|
12
|
+
let count = 0, length = 0;
|
|
13
|
+
return (source, displayMode) => {
|
|
14
|
+
let result;
|
|
15
|
+
if (count >= maxFormulas || length >= maxOutputLength) return {errors: [{code: 'resource-limit', offset: 0,
|
|
16
|
+
message: 'The document math budget is exhausted.'}]};
|
|
17
|
+
count++;
|
|
18
|
+
try { result = render(source, {...options.renderOptions, displayMode}); }
|
|
19
|
+
catch (error) { return {errors: [{code: error.code || 'invalid-tex', message: String(error.message), offset: error.offset || 0}]}; }
|
|
20
|
+
if (result.errors.length) return {errors: result.errors};
|
|
21
|
+
if (result.svg.length > maxOutputLength - length) {
|
|
22
|
+
length = maxOutputLength;
|
|
23
|
+
return {errors: [{code: 'resource-limit', offset: 0, message: 'The document math output budget is exhausted.'}]};
|
|
24
|
+
}
|
|
25
|
+
length += result.svg.length;
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
}
|
package/src/math/layout.js
CHANGED
|
@@ -574,7 +574,7 @@ function mathLayout(n,c) {
|
|
|
574
574
|
case 'smash': {const b=mathLayout(n.body,c);return {...b,h:n.mode==='b'?b.h:0,d:n.mode==='t'?b.d:0};}
|
|
575
575
|
case 'raise': {const b=mathLayout(n.body,c),s=mathScale(c);return mathCompose([[b,0,-n.amount*s]],b.w,{class:b.class,...(n.height===undefined?{}:{h:n.height*s}),...(n.depth===undefined?{}:{d:n.depth*s})});}
|
|
576
576
|
case 'rule': {const s=mathScale(c);return mathRule(n.width*s,(n.height+n.depth)*s,-n.height*s);}
|
|
577
|
-
case 'link': {const b=mathLayout(n.body,c);const url=new URL(n.href);if(!['http:','https:'].includes(url.protocol))throw Object.assign(new Error('Unsupported equation link'),{code:'unsafe-url'});b.svg='<a href="'+mathEscape(n.href)+'" target="_blank" rel="noopener noreferrer">'+b.svg+'</a>';return b;}
|
|
577
|
+
case 'link': {const b=mathLayout(n.body,c);const url=new URL(n.href);if(!['http:','https:'].includes(url.protocol))throw Object.assign(new Error('Unsupported equation link'),{code:'unsafe-url'});b.svg='<a href="'+mathEscape(n.href)+'" aria-label="'+mathEscape(n.href)+'" tabindex="0" target="_blank" rel="noopener noreferrer">'+b.svg+'</a>';return b;}
|
|
578
578
|
default: throw Object.assign(new Error('Unsupported maths construct: '+n.type),{code:'unsupported-construct'});
|
|
579
579
|
}
|
|
580
580
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import type MarkdownIt from 'markdown-it';
|
|
3
|
+
import type {DelimiterOptions} from './delimiters.js';
|
|
4
|
+
import type {IntegrationOptions} from './integration.js';
|
|
5
|
+
export interface MarkdownMathOptions extends DelimiterOptions, IntegrationOptions {}
|
|
6
|
+
export default function rapierMath(md: InstanceType<typeof MarkdownIt>, options?: MarkdownMathOptions): void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import {installMathRules} from './markdown-rules.mjs';
|
|
3
|
+
import {createFormulaRenderer, escapeText} from './integration.mjs';
|
|
4
|
+
|
|
5
|
+
export default function rapierMath(md, options = {}) {
|
|
6
|
+
installMathRules(md, options);
|
|
7
|
+
let session;
|
|
8
|
+
function withSession(renderer, render, tokens, opts, env) {
|
|
9
|
+
const previous = session, current = {render: createFormulaRenderer(options), children: new WeakSet()};
|
|
10
|
+
const visit = tokens => {
|
|
11
|
+
for (const token of tokens) {
|
|
12
|
+
if (token.children) { current.children.add(token.children); visit(token.children); }
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
visit(tokens);
|
|
16
|
+
session = current;
|
|
17
|
+
try { return render.call(renderer, tokens, opts, env); }
|
|
18
|
+
finally { session = previous; }
|
|
19
|
+
}
|
|
20
|
+
const render = md.renderer.render, renderInline = md.renderer.renderInline;
|
|
21
|
+
md.renderer.render = function(tokens, opts, env) {
|
|
22
|
+
return withSession(this, render, tokens, opts, env);
|
|
23
|
+
};
|
|
24
|
+
md.renderer.renderInline = function(tokens, opts, env) {
|
|
25
|
+
// The block renderer's inline children share its document budget. A separate
|
|
26
|
+
// inline tree, including a nested host renderInline call, owns a fresh one.
|
|
27
|
+
if (session?.children.has(tokens)) return renderInline.call(this, tokens, opts, env);
|
|
28
|
+
return withSession(this, renderInline, tokens, opts, env);
|
|
29
|
+
};
|
|
30
|
+
function formula(tokens, index, _options, env) {
|
|
31
|
+
const token = tokens[index], display = token.type === 'math_block';
|
|
32
|
+
const result = (session?.render || createFormulaRenderer(options))(token.content, display);
|
|
33
|
+
if (result.errors.length) {
|
|
34
|
+
(env.rapierMathErrors ||= []).push({source: token.content, errors: result.errors});
|
|
35
|
+
return '<code data-math-error="' + escapeText(result.errors[0].code) + '">' +
|
|
36
|
+
escapeText(token.meta?.mathSource ?? token.content) + '</code>';
|
|
37
|
+
}
|
|
38
|
+
return result.svg;
|
|
39
|
+
}
|
|
40
|
+
md.renderer.rules.math_inline = formula;
|
|
41
|
+
md.renderer.rules.math_block = (tokens, index, opts, env) => {
|
|
42
|
+
const result = formula(tokens, index, opts, env);
|
|
43
|
+
return tokens[index].block ? '<div class="math-display">' + result + '</div>\n' : result;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Original neutral adapter. The host owns Markdown structure and normalization.
|
|
3
|
+
import {createMathMatcher} from './delimiters.mjs';
|
|
4
|
+
|
|
5
|
+
export function installMathRules(md, {singleDollar = false, brackets = true, ruleName = 'rapier_math', inLink = false} = {}) {
|
|
6
|
+
// The host's image-alt renderer ignores unknown token types. Keep math as
|
|
7
|
+
// literal source in text-only output, while leaving escaping to that host.
|
|
8
|
+
const renderText = md.renderer.renderInlineAsText;
|
|
9
|
+
md.renderer.renderInlineAsText = function(tokens, options, env) {
|
|
10
|
+
return renderText.call(this, tokens.map(token =>
|
|
11
|
+
token.type === 'math_inline' || token.type === 'math_block'
|
|
12
|
+
? {...token, type: 'text', content: token.meta?.mathSource ?? token.content}
|
|
13
|
+
: token), options, env);
|
|
14
|
+
};
|
|
15
|
+
const matchers = new WeakMap();
|
|
16
|
+
function match(state, at, limit) {
|
|
17
|
+
let entry = matchers.get(state);
|
|
18
|
+
if (!entry || entry.source !== state.src) {
|
|
19
|
+
entry = {source: state.src, match: createMathMatcher(state.src, {singleDollar, brackets})};
|
|
20
|
+
matchers.set(state, entry);
|
|
21
|
+
}
|
|
22
|
+
return entry.match(at, limit);
|
|
23
|
+
}
|
|
24
|
+
md.inline.ruler.before('escape', ruleName, (state, silent) => {
|
|
25
|
+
if (!inLink && state.linkLevel > 0) return false;
|
|
26
|
+
if (state.src[state.pos] !== '$' && state.src[state.pos] !== '\\') return false;
|
|
27
|
+
const span = match(state, state.pos, state.posMax);
|
|
28
|
+
if (!span) return false;
|
|
29
|
+
if (!silent) {
|
|
30
|
+
const token = state.push(span.displayMode ? 'math_block' : 'math_inline', '', 0);
|
|
31
|
+
token.markup = span.open;
|
|
32
|
+
token.content = state.src.slice(span.bodyStart, span.bodyEnd);
|
|
33
|
+
token.meta = {mathSource: state.src.slice(span.start, span.end)};
|
|
34
|
+
}
|
|
35
|
+
state.pos = span.end;
|
|
36
|
+
return true;
|
|
37
|
+
});
|
|
38
|
+
md.block.ruler.before('fence', ruleName, (state, startLine, endLine, silent) => {
|
|
39
|
+
// An indented code block belongs to the host even when it begins with dollars.
|
|
40
|
+
if (state.sCount[startLine] - state.blkIndent >= 4) return false;
|
|
41
|
+
const start = state.bMarks[startLine] + state.tShift[startLine];
|
|
42
|
+
if (state.src.slice(start, start + 2) !== '$$' && (!brackets || state.src.slice(start, start + 2) !== '\\[')) return false;
|
|
43
|
+
const span = match(state, start, state.eMarks[endLine - 1]);
|
|
44
|
+
if (!span?.displayMode) return false;
|
|
45
|
+
let last = startLine;
|
|
46
|
+
while (last < endLine && state.eMarks[last] < span.end) last++;
|
|
47
|
+
if (last >= endLine || span.bodyEnd < state.bMarks[last] + state.tShift[last] ||
|
|
48
|
+
state.src.slice(span.end, state.eMarks[last]).trim()) return false;
|
|
49
|
+
if (silent) return true;
|
|
50
|
+
const parts = [];
|
|
51
|
+
for (let line = startLine; line <= last; line++) {
|
|
52
|
+
const from = line === startLine ? span.bodyStart : state.bMarks[line] + state.tShift[line];
|
|
53
|
+
const to = line === last ? span.bodyEnd : state.eMarks[line];
|
|
54
|
+
parts.push(state.src.slice(from, to));
|
|
55
|
+
}
|
|
56
|
+
const token = state.push('math_block', 'math', 0);
|
|
57
|
+
token.block = true;
|
|
58
|
+
token.markup = span.open;
|
|
59
|
+
token.content = parts.join('\n');
|
|
60
|
+
token.meta = {mathSource: span.open + token.content + span.close};
|
|
61
|
+
token.map = [startLine, last + 1];
|
|
62
|
+
state.line = last + 1;
|
|
63
|
+
return true;
|
|
64
|
+
}, {alt: ['paragraph', 'reference', 'blockquote', 'list']});
|
|
65
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
// The module has the exact classic renderer body, with module-local exports.
|
|
3
|
-
import {
|
|
3
|
+
import {writeFile} from 'node:fs/promises';
|
|
4
4
|
import {dirname, resolve} from 'node:path';
|
|
5
5
|
import {fileURLToPath} from 'node:url';
|
|
6
6
|
|
|
@@ -19,9 +19,9 @@ export function mathModule(bundle) {
|
|
|
19
19
|
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
20
20
|
if (!process.argv[2]) throw new Error('usage: node src/math/package-build.mjs <module-file>');
|
|
21
21
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
22
|
-
const {
|
|
23
|
-
const
|
|
24
|
-
const text = mathModule(
|
|
22
|
+
const {assembleMath} = await import('../tools/build-math.mjs');
|
|
23
|
+
const {bytes} = await assembleMath({root});
|
|
24
|
+
const text = mathModule(bytes);
|
|
25
25
|
await writeFile(resolve(process.argv[2]), text);
|
|
26
26
|
console.log(JSON.stringify({file: process.argv[2], bytes: Buffer.byteLength(text)}));
|
|
27
27
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Package entry, exact authored text and hostile-content boundaries; no appearance assertions.
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import {readFile} from 'node:fs/promises';
|
|
5
|
+
import {Script, createContext} from 'node:vm';
|
|
6
|
+
import {mathModule} from './src/math/package-build.mjs';
|
|
7
|
+
|
|
8
|
+
const read = path => readFile(new URL(path, import.meta.url), 'utf8');
|
|
9
|
+
const pkg = JSON.parse(await read('./package.json'));
|
|
10
|
+
const resources = JSON.parse(await read('./src/shell/math-resources.json'));
|
|
11
|
+
const classicSource = await read('./' + resources.bundle);
|
|
12
|
+
assert.equal(pkg.name, 'rapier-math');
|
|
13
|
+
assert.equal(pkg.version, resources.version);
|
|
14
|
+
assert.equal(pkg.type, 'module');
|
|
15
|
+
assert.equal(pkg.license, 'SEE LICENSE IN LICENSE');
|
|
16
|
+
assert.equal(Object.keys(pkg.dependencies || {}).length, 0);
|
|
17
|
+
assert.equal(Object.keys(pkg.scripts || {}).length, 0);
|
|
18
|
+
assert.equal(await read('./index.mjs'), mathModule(classicSource), 'exact generated module');
|
|
19
|
+
const rendererLicense = await read('./LICENSE-MIT'), fontLicense = await read('./math-font-LICENSE.txt');
|
|
20
|
+
for (const name of ['./LICENSE', './index.mjs', './' + resources.bundle]) {
|
|
21
|
+
const text = await read(name);
|
|
22
|
+
assert(text.includes(rendererLicense.trim()), name + ': renderer license');
|
|
23
|
+
assert(text.includes(fontLicense.trim()), name + ': complete font license');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Initialize Node's lazy Web API globals before observing module purity. This
|
|
27
|
+
// allocates a local Response only; no network request or renderer evaluation.
|
|
28
|
+
new Response();
|
|
29
|
+
const globals = Object.getOwnPropertyDescriptors(globalThis);
|
|
30
|
+
const module = await import('./index.mjs');
|
|
31
|
+
const afterImport = Object.getOwnPropertyDescriptors(globalThis);
|
|
32
|
+
assert.deepEqual(Reflect.ownKeys(afterImport), Reflect.ownKeys(globals), 'module adds no globals');
|
|
33
|
+
for (const key of Reflect.ownKeys(globals)) for (const field of Object.keys(globals[key]))
|
|
34
|
+
assert(Object.is(afterImport[key][field], globals[key][field]), 'module preserves global ' + String(key));
|
|
35
|
+
assert.deepEqual(Object.keys(module).sort(), ['default', 'fit', 'observe', 'parse', 'render', 'renderToString', 'version']);
|
|
36
|
+
for (const name of Object.keys(module.default)) assert.equal(module[name], module.default[name], 'named/default export ' + name);
|
|
37
|
+
assert.equal(module.version, resources.version);
|
|
38
|
+
assert(Object.isFrozen(module.default));
|
|
39
|
+
|
|
40
|
+
const context = createContext({atob, URL});
|
|
41
|
+
new Script(classicSource, {filename: resources.bundle}).runInContext(context);
|
|
42
|
+
const classic = context.RapierMath;
|
|
43
|
+
const plain = value => JSON.parse(JSON.stringify(value));
|
|
44
|
+
const unescape = text => text.replace(/&(amp|lt|gt|quot|apos|#\d+|#x[\da-f]+);/gi, (_, entity) =>
|
|
45
|
+
entity[0] === '#' ? String.fromCodePoint(entity[1] === 'x' ? parseInt(entity.slice(2), 16) : Number(entity.slice(1))) :
|
|
46
|
+
({amp: '&', lt: '<', gt: '>', quot: '"', apos: "'"})[entity]);
|
|
47
|
+
function sourceAlternative(result, source) {
|
|
48
|
+
const label = /\baria-label="([^"]*)"/.exec(result.svg)?.[1];
|
|
49
|
+
const title = /<title>([^<]*)<\/title>/.exec(result.svg)?.[1];
|
|
50
|
+
const utf16 = /\bdata-tex-utf16="([0-9a-f]+)"/.exec(result.svg)?.[1];
|
|
51
|
+
if (utf16) assert.equal(utf16.match(/.{4}/g).map(part => String.fromCharCode(parseInt(part, 16))).join(''), source, 'exact UTF-16 alternative');
|
|
52
|
+
else { assert.equal(unescape(label), source, 'exact aria alternative'); assert.equal(unescape(title), source, 'exact title alternative'); }
|
|
53
|
+
}
|
|
54
|
+
function inert(svg) {
|
|
55
|
+
assert(!/<\s*(?:script|foreignObject|iframe|object|embed|image|style|animate|set)\b/i.test(svg), 'no executable or remote SVG element');
|
|
56
|
+
for (const tag of svg.match(/<[^>]+>/g) || []) {
|
|
57
|
+
const attributes = [...tag.matchAll(/\s([^\s=]+)="([^"]*)"/g)];
|
|
58
|
+
for (const [, name, value] of attributes) {
|
|
59
|
+
assert(!/^on/i.test(name), 'no event attribute');
|
|
60
|
+
if (/^(?:href|xlink:href)$/i.test(name)) assert(/^https?:\/\//i.test(unescape(value)), 'only HTTP(S) links');
|
|
61
|
+
if (!/^(?:aria-label|data-tex-utf16)$/.test(name)) assert(!/url\s*\(|javascript:|vbscript:/i.test(unescape(value)), 'no executable attribute');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const examples = [
|
|
67
|
+
[String.raw`\frac{-b\pm\sqrt{b^2-4ac}}{2a}`, {displayMode: true}],
|
|
68
|
+
[String.raw`\begin{aligned}a&=b+c\\d&=e+f\end{aligned}`, {displayMode: true, maxWidth: 4}],
|
|
69
|
+
[String.raw`\newcommand{\squareof}[1]{#1^2}\squareof{x}`, {screen: {fontSize: 16, pixelRatio: 2, dark: false}}],
|
|
70
|
+
[String.raw`\text{A < B & "C" 'D'} + α`, {}],
|
|
71
|
+
[String.raw`\href{https://example.com/?a=1&b=2}{x}`, {}],
|
|
72
|
+
[String.raw`\unsupported{content}`, {}],
|
|
73
|
+
['x\u0000y\ud800z\udfff', {}],
|
|
74
|
+
];
|
|
75
|
+
for (const [source, options] of examples) {
|
|
76
|
+
const result = module.render(source, options);
|
|
77
|
+
assert.deepEqual(plain(result), plain(classic.render(source, options)), 'module/classic result');
|
|
78
|
+
assert.equal(module.renderToString(source, options), result.svg, 'string export agrees with render');
|
|
79
|
+
sourceAlternative(result, source); inert(result.svg);
|
|
80
|
+
}
|
|
81
|
+
assert.deepEqual(plain(module.parse(examples[0][0])), plain(classic.parse(examples[0][0])), 'module/classic parse');
|
|
82
|
+
assert.equal(module.render(examples.at(-1)[0]).errors[0].code, 'invalid-source-character');
|
|
83
|
+
assert.equal(module.render(examples.at(-2)[0]).errors[0].code, 'unsupported-command');
|
|
84
|
+
|
|
85
|
+
const hostile = [
|
|
86
|
+
String.raw`\text{</title><script>alert(1)</script>}`,
|
|
87
|
+
String.raw`\href{javascript:alert(1)}{x}`,
|
|
88
|
+
String.raw`\href{data:text/html,test}{x}`,
|
|
89
|
+
String.raw`\href{https://example.com/" onload="alert(1)}{x}`,
|
|
90
|
+
String.raw`\color{url(https://example.com/payload)}x`,
|
|
91
|
+
String.raw`\def\again{\again}\again`,
|
|
92
|
+
];
|
|
93
|
+
for (const source of hostile) {
|
|
94
|
+
const result = module.render(source);
|
|
95
|
+
sourceAlternative(result, source); inert(result.svg);
|
|
96
|
+
assert.deepEqual(plain(result), plain(classic.render(source)), 'module/classic hostile result');
|
|
97
|
+
}
|
|
98
|
+
for (const source of hostile.slice(1)) assert(module.render(source).errors.length, 'unsafe or exhausted input produces a diagnostic');
|
|
99
|
+
for (const source of ['x'.repeat(1_000_001), '\ud800'.repeat(1_000_001), '&'.repeat(8_000_000)]) {
|
|
100
|
+
const result = module.render(source);
|
|
101
|
+
assert.equal(result.errors[0].code, 'resource-limit');
|
|
102
|
+
assert.equal(result.errors[0].sourceOmitted, true);
|
|
103
|
+
assert(result.svg.includes('data-math-source-omitted="true"'));
|
|
104
|
+
assert(!result.svg.includes('data-tex-utf16'), 'refused source never creates a carrier');
|
|
105
|
+
assert(result.svg.length < 100_000, 'refusal diagnostic is fixed-size');
|
|
106
|
+
assert.equal(module.renderToString(source), result.svg);
|
|
107
|
+
assert.deepEqual(plain(result), plain(classic.render(source)), 'module/classic refusal result');
|
|
108
|
+
inert(result.svg);
|
|
109
|
+
}
|
|
110
|
+
const longCommand = '\\' + 'a'.repeat(10_000), diagnostic = module.render(longCommand);
|
|
111
|
+
assert(diagnostic.errors[0].messageTruncated && diagnostic.errors[0].commandTruncated);
|
|
112
|
+
sourceAlternative(diagnostic, longCommand);
|
|
113
|
+
assert(diagnostic.errors[0].message.length <= 1025 && diagnostic.errors[0].command.length <= 128);
|
|
114
|
+
const unicodeFailure = module.render('\\begin{' + '😀'.repeat(600) + '}x');
|
|
115
|
+
assert(unicodeFailure.errors[0].message.isWellFormed(), 'diagnostic admission cannot split a source surrogate pair');
|
|
116
|
+
assert.equal(module.render('x+1').errors.length, 0, 'refused input cannot poison later rendering');
|
|
117
|
+
console.log(JSON.stringify({name: pkg.name, version: module.version, module: 'native ESM; no global changes',
|
|
118
|
+
rebuild: 'exact module', classicAgreement: examples.length + hostile.length, sourceAlternatives: 'exact', hostileContent: 'inert', licenses: 'complete'}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import {readFileSync} from 'node:fs';
|
|
3
|
+
export function mathReadme(resources) {
|
|
4
|
+
return readFileSync(new URL('./README.md', import.meta.url), 'utf8')
|
|
5
|
+
.replace('rapier-math-VERSION.js', resources.bundle) +
|
|
6
|
+
'\nBuild: ' + resources.version + '. Classic payload: ' + resources.bytes +
|
|
7
|
+
' bytes; gzip (level 9): ' + resources.gzipBytes + ' bytes.\nSHA-384: `' + resources.sha384 + '`\n';
|
|
8
|
+
}
|
|
@@ -15,10 +15,11 @@ const payload = await read(resources.bundle);
|
|
|
15
15
|
assert.equal(payload.length, resources.bytes, 'payload length');
|
|
16
16
|
assert.equal(hash(payload), resources.sha256, 'payload SHA-256');
|
|
17
17
|
assert.equal(hash(payload, 'sha384', 'base64'), resources.sha384, 'payload SHA-384');
|
|
18
|
-
for (const input of [...resources.sources, ...resources.recipe]) {
|
|
18
|
+
for (const input of [...resources.sources, ...resources.recipe, ...resources.adoption]) {
|
|
19
19
|
const bytes = await read('src/' + input.file);
|
|
20
20
|
assert.equal(bytes.length, input.bytes, input.file + ': length');
|
|
21
21
|
assert.equal(hash(bytes), input.sha256, input.file + ': SHA-256');
|
|
22
|
+
if (input.packageFile) assert.deepEqual(await read(input.packageFile), bytes, input.packageFile + ': exact adoption source');
|
|
22
23
|
}
|
|
23
24
|
const rendererLicense = await read('src/math/LICENSE-MIT');
|
|
24
25
|
for (const file of ['LICENSE-MIT', 'math-LICENSE.txt']) assert.deepEqual(await read(file), rendererLicense, file);
|
|
@@ -34,7 +35,11 @@ assert.equal(font.licenseDeclared, resources.font.license, 'font license identit
|
|
|
34
35
|
assert.equal(sbom.hasExtractedLicensingInfos.find(item => item.licenseId === resources.font.license)?.extractedText,
|
|
35
36
|
fontLicense.toString('utf8'), 'complete extracted font license');
|
|
36
37
|
const {buildMath} = await import('./src/tools/build-math.mjs');
|
|
38
|
+
const {mathReadme} = await import('./src/math/package-readme.mjs');
|
|
39
|
+
assert.equal((await read('README.md')).toString('utf8'), mathReadme(resources), 'generated README source');
|
|
40
|
+
for (const [file, owner] of [['check.mjs', 'package-check.mjs'], ['verify.mjs', 'package-verify.mjs'], ['adoption-check.mjs', 'adoption-verify.mjs']])
|
|
41
|
+
assert.deepEqual(await read(file), await read('src/math/' + owner), file + ': exact carried owner');
|
|
37
42
|
await buildMath({root: source, updatePins: false});
|
|
38
43
|
assert.deepEqual(await read('src/shell/vendor/' + resources.bundle), payload, 'rebuilt payload bytes');
|
|
39
44
|
console.log(JSON.stringify({file: resources.bundle, bytes: payload.length, sha256: resources.sha256,
|
|
40
|
-
sources: resources.sources.length + resources.recipe.length, rebuild: 'exact', licenses: 'complete'}));
|
|
45
|
+
sources: resources.sources.length + resources.recipe.length, adoptionFiles: resources.adoption.length, rebuild: 'exact', licenses: 'complete'}));
|