@minamorl/flashmath 0.0.0-stage → 0.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/LICENSE +225 -0
- package/NOTICE +25 -0
- package/README.md +188 -2
- package/dist/ast.d.ts +107 -0
- package/dist/chunk-2BLNXHV2.js +1 -0
- package/dist/chunk-BCYDUHHK.js +1 -0
- package/dist/chunk-IHTB7IDO.js +1 -0
- package/dist/chunk-KDAOMSCC.js +1 -0
- package/dist/chunk-TXV67IQS.js +1 -0
- package/dist/chunk-WZSFAGJH.js +1 -0
- package/dist/chunk-X6BR56FI.js +1 -0
- package/dist/configuration-cache.d.ts +4 -0
- package/dist/configuration-cache.js +1 -0
- package/dist/configuration.d.ts +13 -0
- package/dist/configuration.js +1 -0
- package/dist/fonts/mjx-ncm-c.woff2 +0 -0
- package/dist/fonts/mjx-ncm-cb.woff2 +0 -0
- package/dist/fonts/mjx-ncm-s.woff2 +0 -0
- package/dist/fonts/mjx-ncm-sb.woff2 +0 -0
- package/dist/fonts/provenance.json +24 -0
- package/dist/fonts.css +29 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1 -0
- package/dist/mathml.d.ts +18 -0
- package/dist/native-layout.d.ts +7 -0
- package/dist/native-variants.d.ts +2 -0
- package/dist/native-variants.js +1 -0
- package/dist/output.d.ts +4 -0
- package/dist/output.js +1 -0
- package/dist/package-mark.d.ts +5 -0
- package/dist/packages/action.d.ts +17 -0
- package/dist/packages/ams.d.ts +19 -0
- package/dist/packages/amscd.d.ts +30 -0
- package/dist/packages/autoload.d.ts +16 -0
- package/dist/packages/base.d.ts +22 -0
- package/dist/packages/bbm.d.ts +24 -0
- package/dist/packages/bboldx.d.ts +12 -0
- package/dist/packages/bbox.d.ts +11 -0
- package/dist/packages/begingroup.d.ts +9 -0
- package/dist/packages/boldsymbol.d.ts +11 -0
- package/dist/packages/braket.d.ts +9 -0
- package/dist/packages/bussproofs-layout.d.ts +5 -0
- package/dist/packages/bussproofs-metrics.d.ts +1 -0
- package/dist/packages/bussproofs.d.ts +13 -0
- package/dist/packages/cancel.d.ts +8 -0
- package/dist/packages/cases.d.ts +16 -0
- package/dist/packages/centernot.d.ts +15 -0
- package/dist/packages/color.d.ts +30 -0
- package/dist/packages/colortbl.d.ts +10 -0
- package/dist/packages/colorv2.d.ts +15 -0
- package/dist/packages/configmacros.d.ts +11 -0
- package/dist/packages/dsfont.d.ts +12 -0
- package/dist/packages/empheq.d.ts +17 -0
- package/dist/packages/enclose.d.ts +13 -0
- package/dist/packages/extpfeil.d.ts +10 -0
- package/dist/packages/fontsizev3.d.ts +11 -0
- package/dist/packages/gensymb.d.ts +11 -0
- package/dist/packages/html.d.ts +8 -0
- package/dist/packages/mathtools.d.ts +17 -0
- package/dist/packages/mhchem-grammar.d.ts +179 -0
- package/dist/packages/mhchem-machine.d.ts +50 -0
- package/dist/packages/mhchem.d.ts +8 -0
- package/dist/packages/newcommand.d.ts +13 -0
- package/dist/packages/noerrors.d.ts +23 -0
- package/dist/packages/noundefined.d.ts +9 -0
- package/dist/packages/physics.d.ts +14 -0
- package/dist/packages/registry.d.ts +4 -0
- package/dist/packages/registry.js +1 -0
- package/dist/packages/require.d.ts +17 -0
- package/dist/packages/retry.d.ts +11 -0
- package/dist/packages/setoptions.d.ts +20 -0
- package/dist/packages/tagformat.d.ts +19 -0
- package/dist/packages/texhtml.d.ts +14 -0
- package/dist/packages/textcomp.d.ts +13 -0
- package/dist/packages/textmacros.d.ts +16 -0
- package/dist/packages/types.d.ts +47 -0
- package/dist/packages/unicode.d.ts +18 -0
- package/dist/packages/units.d.ts +19 -0
- package/dist/packages/upgreek.d.ts +11 -0
- package/dist/packages/verb.d.ts +11 -0
- package/dist/parser.d.ts +149 -0
- package/dist/preamble.d.ts +23 -0
- package/dist/react.d.ts +5 -0
- package/dist/react.js +1 -0
- package/dist/scanner.d.ts +40 -0
- package/dist/serialize.d.ts +3 -0
- package/dist/session-state.d.ts +18 -0
- package/dist/symbols.d.ts +544 -0
- package/package.json +56 -4
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { K } from "./ast.js";
|
|
2
|
+
import type { Node, ParseOptions, MathMLNode } from "./ast.js";
|
|
3
|
+
import { Stream } from "./scanner.js";
|
|
4
|
+
import type { Token, Macro, TokenSpan } from "./scanner.js";
|
|
5
|
+
import type { Preamble } from "./preamble.js";
|
|
6
|
+
import type { SessionState, Reference } from "./session-state.js";
|
|
7
|
+
import type { ActivePackageConfiguration, RegisteredCommand } from "./packages/types.js";
|
|
8
|
+
import type { Definition } from "./symbols.js";
|
|
9
|
+
type Attrs = Record<string, string>;
|
|
10
|
+
interface Frame {
|
|
11
|
+
argumentScope?: boolean;
|
|
12
|
+
tokenTransform?: (node: Node) => void;
|
|
13
|
+
missingMessage?: string;
|
|
14
|
+
nodes: Node[];
|
|
15
|
+
stop: number;
|
|
16
|
+
single: boolean;
|
|
17
|
+
done: (nodes: Node[]) => void;
|
|
18
|
+
font: string;
|
|
19
|
+
multi: boolean;
|
|
20
|
+
level: number;
|
|
21
|
+
display: boolean;
|
|
22
|
+
env: string;
|
|
23
|
+
table: Table | null;
|
|
24
|
+
fraction: {
|
|
25
|
+
num: Node[];
|
|
26
|
+
attrs: Attrs;
|
|
27
|
+
left: string;
|
|
28
|
+
right: string;
|
|
29
|
+
} | null;
|
|
30
|
+
}
|
|
31
|
+
interface Table {
|
|
32
|
+
rows: Node[][];
|
|
33
|
+
cells: Node[];
|
|
34
|
+
align: string;
|
|
35
|
+
spacing: string;
|
|
36
|
+
rowspacing: string;
|
|
37
|
+
rowspacingBase?: number;
|
|
38
|
+
display: boolean;
|
|
39
|
+
lines: string[];
|
|
40
|
+
rowlines: string[];
|
|
41
|
+
frame: string;
|
|
42
|
+
top: string;
|
|
43
|
+
bottom: string;
|
|
44
|
+
position: string;
|
|
45
|
+
latex: boolean;
|
|
46
|
+
plan: Preamble;
|
|
47
|
+
originalFont: string;
|
|
48
|
+
fill: string;
|
|
49
|
+
rowBreak: Record<number, string>;
|
|
50
|
+
cellBreak: Record<string, string>;
|
|
51
|
+
tableBreak: boolean;
|
|
52
|
+
labels: string[];
|
|
53
|
+
noNumbers: Set<number>;
|
|
54
|
+
rowspaces: string[];
|
|
55
|
+
numbered: boolean;
|
|
56
|
+
taggable: boolean;
|
|
57
|
+
tagCells: Map<number, Node>;
|
|
58
|
+
explicitTags?: Map<number, string>;
|
|
59
|
+
colors?: {
|
|
60
|
+
cell: string;
|
|
61
|
+
row: string;
|
|
62
|
+
columns: string[];
|
|
63
|
+
rowIndex: number;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export declare class Parser {
|
|
67
|
+
readonly tex: string;
|
|
68
|
+
readonly options: ParseOptions;
|
|
69
|
+
configuration: ActivePackageConfiguration;
|
|
70
|
+
readonly session: SessionState;
|
|
71
|
+
get characters(): ReadonlyMap<number, readonly RegisteredCommand[]>;
|
|
72
|
+
readonly stream: Stream;
|
|
73
|
+
readonly macros: Map<string, Macro>;
|
|
74
|
+
readonly environments: Map<string, {
|
|
75
|
+
begin: Macro;
|
|
76
|
+
end: Macro;
|
|
77
|
+
}>;
|
|
78
|
+
readonly localLabels: Map<string, Reference>;
|
|
79
|
+
readonly frames: Frame[];
|
|
80
|
+
nodes: number;
|
|
81
|
+
expansions: number;
|
|
82
|
+
position: number;
|
|
83
|
+
readonly columns: Map<string, {
|
|
84
|
+
count: number;
|
|
85
|
+
body: string;
|
|
86
|
+
}>;
|
|
87
|
+
label: string;
|
|
88
|
+
numbered: boolean;
|
|
89
|
+
hasTaggableEnvironment: boolean;
|
|
90
|
+
readonly envStack: string[];
|
|
91
|
+
hsize: string;
|
|
92
|
+
inline: boolean;
|
|
93
|
+
nonscript: boolean;
|
|
94
|
+
pendingBreak: string;
|
|
95
|
+
result: Node[];
|
|
96
|
+
currentCommand: string;
|
|
97
|
+
constructor(tex: string, options: ParseOptions, configuration?: ActivePackageConfiguration, session?: SessionState);
|
|
98
|
+
error(message: string): never;
|
|
99
|
+
node(kind: K, children?: Node[], text?: string, attributes?: Attrs, start?: number): Node;
|
|
100
|
+
row(nodes: Node[], force?: boolean): Node;
|
|
101
|
+
atom(nodes: Node[], texclass?: string): Node;
|
|
102
|
+
fixInitialMO(nodes: Node[]): void;
|
|
103
|
+
get f(): Frame;
|
|
104
|
+
frame(stop: number, single: boolean, done: (nodes: Node[]) => void, env?: string, table?: Table | null): void;
|
|
105
|
+
append(n: Node): void;
|
|
106
|
+
close(): void;
|
|
107
|
+
argument(done: (n: Node) => void, keepGroup?: boolean, name?: string): void;
|
|
108
|
+
args(count: number, done: (nodes: Node[]) => void, name?: string): void;
|
|
109
|
+
tokensArgument(name?: string): Token[];
|
|
110
|
+
argumentSpan(name?: string): TokenSpan;
|
|
111
|
+
optional(): Token[] | null;
|
|
112
|
+
parseTokens(tokens: readonly Token[], done: (n: Node) => void): void;
|
|
113
|
+
parseSpan(span: TokenSpan, done: (n: Node) => void): void;
|
|
114
|
+
substitute(m: Macro, args: readonly Token[][]): Token[];
|
|
115
|
+
expand(m: Macro): void;
|
|
116
|
+
delimiter(): string;
|
|
117
|
+
delimiterNode(text: string, big?: string, texclass?: string): Node;
|
|
118
|
+
symbol(t: Token, id: number, d?: Definition): Node;
|
|
119
|
+
character(t: Token): Node;
|
|
120
|
+
number(t: Token): Node;
|
|
121
|
+
script(sup: boolean, prime?: boolean): void;
|
|
122
|
+
dimension(): string;
|
|
123
|
+
text(tokens: Token[], font?: string): Node;
|
|
124
|
+
/** Tags use the same text/math grammar as text boxes, in a fresh math scope. */
|
|
125
|
+
tagText(text: string): Node[];
|
|
126
|
+
renderText(input: Token[] | TokenSpan, font?: string, style?: boolean): void;
|
|
127
|
+
tableStart(name: string, align: string, stop: number, done?: (n: Node) => void): void;
|
|
128
|
+
startCell(t: Table): void;
|
|
129
|
+
finishCell(t: Table, nodes: Node[]): void;
|
|
130
|
+
completeTable(t: Table, name: string, done: (n: Node) => void): void;
|
|
131
|
+
tagTable(): Table | undefined;
|
|
132
|
+
setLabel(label: string): void;
|
|
133
|
+
reference(label: string, formatted?: boolean): void;
|
|
134
|
+
tagRow(table: Table): void;
|
|
135
|
+
labelCell(label: string, explicit?: string, starred?: boolean): Node;
|
|
136
|
+
tableNode(t: Table, name: string): Node;
|
|
137
|
+
run(): MathMLNode;
|
|
138
|
+
linebreak(): void;
|
|
139
|
+
decorationBase(n: Node): Node;
|
|
140
|
+
clean(n: Node, index: number, length: number): void;
|
|
141
|
+
functionArgument(node: Node): boolean;
|
|
142
|
+
finish(nodes: Node[]): void;
|
|
143
|
+
}
|
|
144
|
+
export interface MathMLParserSession {
|
|
145
|
+
parse(tex: string, options?: Pick<ParseOptions, 'display' | 'output'>): MathMLNode;
|
|
146
|
+
}
|
|
147
|
+
export declare function createMathMLParser(input?: ParseOptions): MathMLParserSession;
|
|
148
|
+
export declare function parseToMathMLAst(tex: string, options?: ParseOptions): MathMLNode;
|
|
149
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Token } from './scanner.js';
|
|
2
|
+
export interface Column {
|
|
3
|
+
align: string;
|
|
4
|
+
width: string;
|
|
5
|
+
before: Token[];
|
|
6
|
+
after: Token[];
|
|
7
|
+
insert: Token[] | null;
|
|
8
|
+
separator: string;
|
|
9
|
+
gap: string;
|
|
10
|
+
vertical: string;
|
|
11
|
+
}
|
|
12
|
+
export interface Preamble {
|
|
13
|
+
columns: Column[];
|
|
14
|
+
left: string;
|
|
15
|
+
right: string;
|
|
16
|
+
padding: string;
|
|
17
|
+
spacing: string;
|
|
18
|
+
}
|
|
19
|
+
/** The array preamble is a separate, cold grammar; its expansion is bounded. */
|
|
20
|
+
export declare function preamble(source: string, max: number, custom: Map<string, {
|
|
21
|
+
count: number;
|
|
22
|
+
body: string;
|
|
23
|
+
}>): Preamble;
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import type { MathMLNode, ParseOptions, OutputOptions } from './ast.js';
|
|
3
|
+
/** Real React MathML elements, with no HTML injection. */
|
|
4
|
+
export declare function parseToReact(tex: string, options?: ParseOptions): ReactElement;
|
|
5
|
+
export declare function mathMLAstToReact(ast: MathMLNode, options?: OutputOptions): ReactElement;
|
package/dist/react.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as g}from"./chunk-BCYDUHHK.js";import{a as d}from"./chunk-2BLNXHV2.js";import"./chunk-TXV67IQS.js";import"./chunk-X6BR56FI.js";import"./chunk-IHTB7IDO.js";import"./chunk-KDAOMSCC.js";import"./chunk-WZSFAGJH.js";import{createElement as u}from"react";function x(n){let s={},a=0,i=-1,t=0,c=0;for(let r=0;r<=n.length;r++){let o=n.charCodeAt(r);if(c?o===92?r++:o===c&&(c=0):o===34||o===39?c=o:o===40?t++:o===41?t--:o===58&&i<0&&(i=r),r===n.length||o===59&&!t&&!c){if(i>=a){let f=n.slice(a,i).trim(),e=f.startsWith("--")?f:f.toLowerCase(),l="";if(e.startsWith("--"))l=e;else for(let p=0;p<e.length;p++)if(e.charCodeAt(p)===45&&p+1<e.length){let h=e.charCodeAt(++p);l+=String.fromCharCode(p===1&&h===109&&e.charCodeAt(2)===115?h:h>=97&&h<=122?h-32:h)}else l+=e[p];l&&(s[l]=n.slice(i+1,r).trim())}a=r+1,i=-1}}return s}var m={class:"className",for:"htmlFor","http-equiv":"httpEquiv","accept-charset":"acceptCharset"};for(let n of"accessKey allowFullScreen autoCapitalize autoComplete autoFocus cellPadding cellSpacing charSet classID colSpan contentEditable contextMenu crossOrigin dateTime encType enterKeyHint fetchPriority formAction formEncType formMethod formNoValidate formTarget frameBorder hrefLang inputMode itemID itemProp itemRef itemScope itemType marginHeight marginWidth maxLength minLength noModule noValidate playsInline readOnly referrerPolicy rowSpan spellCheck srcDoc srcLang srcSet tabIndex useMap fontFamily fontSize fontSizeAdjust fontStretch fontStyle fontVariant fontWeight strokeWidth strokeLinecap strokeLinejoin strokeMiterlimit strokeDasharray strokeDashoffset strokeOpacity fillOpacity fillRule clipPath clipRule xmlLang xmlSpace xlinkHref xmlnsXlink".split(" "))m[n.toLowerCase()]=n,m[n.replace(/[A-Z]/g,s=>"-"+s.toLowerCase())]=n;Object.assign(m,{"xml:lang":"xmlLang","xml:space":"xmlSpace","xlink:href":"xlinkHref","xmlns:xlink":"xmlnsXlink"});function S(n,s={}){return y(g(n,s),s)}function y(n,s={}){let a=[{node:d(n,s),visited:!1,key:0}],i=[];for(;a.length;){let{node:t,visited:c,key:r}=a.pop();if(!c){a.push({node:t,visited:!0,key:r});for(let e=t.children.length-1;e>=0;e--)a.push({node:t.children[e],visited:!1,key:t.children[e].start*(t.children.length+1)+e});continue}if(t.kind==="#text"){i.push(t.text);continue}let o=i.splice(i.length-t.children.length,t.children.length),f={key:r};for(let[e,l]of Object.entries(t.attributes))e==="href"&&l===""||(f[m[e]??e]=e==="style"?x(l):l);i.push(u(t.kind,f,t.text?[t.text,...o]:o))}return i[0]}export{y as mathMLAstToReact,S as parseToReact};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type Token = readonly [code: number, start: number, end: number, source: string];
|
|
2
|
+
export declare const letter: (c: number) => boolean;
|
|
3
|
+
export declare const space: (c: number) => c is 9 | 10 | 13 | 32 | 160;
|
|
4
|
+
export declare function scan(source: string, max?: number): Token[];
|
|
5
|
+
export declare const spelling: (t: Token) => string;
|
|
6
|
+
export declare const builtin: (t: Token | undefined) => number;
|
|
7
|
+
export declare const raw: (tokens: readonly Token[]) => string;
|
|
8
|
+
export interface Macro {
|
|
9
|
+
body: readonly Token[];
|
|
10
|
+
count: number;
|
|
11
|
+
optional: readonly Token[] | null;
|
|
12
|
+
prefix: readonly Token[];
|
|
13
|
+
delimiters: readonly (readonly Token[])[];
|
|
14
|
+
}
|
|
15
|
+
export interface TokenSpan {
|
|
16
|
+
tokens: readonly Token[];
|
|
17
|
+
start: number;
|
|
18
|
+
end: number;
|
|
19
|
+
}
|
|
20
|
+
/** Build once per source buffer; argument views share this index. */
|
|
21
|
+
export declare function groupEnd(tokens: readonly Token[], start: number): number | undefined;
|
|
22
|
+
export declare class Stream {
|
|
23
|
+
private max;
|
|
24
|
+
private streams;
|
|
25
|
+
private cached;
|
|
26
|
+
consumed: number;
|
|
27
|
+
constructor(tokens: readonly Token[], max: number);
|
|
28
|
+
push(tokens: readonly Token[]): void;
|
|
29
|
+
pushSpan(span: TokenSpan): void;
|
|
30
|
+
/** Called immediately after an opening brace was read. */
|
|
31
|
+
takeGroup(): TokenSpan | undefined;
|
|
32
|
+
/** Text math delimiters are matched at this brace level, skipping groups. */
|
|
33
|
+
takeMath(dollar: boolean): TokenSpan | undefined;
|
|
34
|
+
peek(): Token | undefined;
|
|
35
|
+
next(): Token | undefined;
|
|
36
|
+
skip(): void;
|
|
37
|
+
/** Consume raw source through a delimiter without dispatching each token. */
|
|
38
|
+
takeThrough(source: string, end: number): Token | undefined;
|
|
39
|
+
private read;
|
|
40
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Macro } from "./scanner.js";
|
|
2
|
+
export interface Reference {
|
|
3
|
+
tag: string;
|
|
4
|
+
id: string;
|
|
5
|
+
}
|
|
6
|
+
/** Owned by one document/session; never shared between independent parser calls. */
|
|
7
|
+
export interface SessionState {
|
|
8
|
+
packageData: Map<string, unknown>;
|
|
9
|
+
macros: Map<string, Macro>;
|
|
10
|
+
environments: Map<string, {
|
|
11
|
+
begin: Macro;
|
|
12
|
+
end: Macro;
|
|
13
|
+
}>;
|
|
14
|
+
labels: Map<string, Reference>;
|
|
15
|
+
counter: number;
|
|
16
|
+
initialized: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function sessionState(): SessionState;
|