katex 0.16.32 → 0.16.34
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 +3 -3
- package/contrib/auto-render/{auto-render.js → auto-render.ts} +41 -19
- package/contrib/auto-render/{splitAtDelimiters.js → splitAtDelimiters.ts} +18 -4
- package/contrib/auto-render/test/{auto-render-spec.js → auto-render-spec.ts} +10 -2
- package/contrib/copy-tex/README.md +2 -2
- package/contrib/copy-tex/{copy-tex.js → copy-tex.ts} +4 -6
- package/contrib/copy-tex/{katex2tex.js → katex2tex.ts} +2 -3
- package/contrib/mathtex-script-type/README.md +5 -5
- package/contrib/mhchem/README.md +1 -1
- package/contrib/render-a11y-string/{render-a11y-string.js → render-a11y-string.ts} +18 -33
- package/contrib/render-a11y-string/test/{render-a11y-string-spec.js → render-a11y-string-spec.ts} +0 -1
- package/dist/README.md +3 -3
- package/dist/contrib/auto-render.js +24 -57
- package/dist/contrib/auto-render.min.js +1 -1
- package/dist/contrib/auto-render.mjs +16586 -210
- package/dist/contrib/copy-tex.js +23 -37
- package/dist/contrib/copy-tex.min.js +1 -1
- package/dist/contrib/copy-tex.mjs +77 -95
- package/dist/contrib/mathtex-script-type.js +0 -3
- package/dist/contrib/mathtex-script-type.mjs +16427 -4
- package/dist/contrib/mhchem.js +55 -303
- package/dist/contrib/mhchem.mjs +12884 -723
- package/dist/contrib/render-a11y-string.js +13 -108
- package/dist/contrib/render-a11y-string.min.js +1 -1
- package/dist/contrib/render-a11y-string.mjs +17020 -760
- package/dist/katex-swap.css +2 -1
- package/dist/katex-swap.min.css +1 -1
- package/dist/katex.css +2 -1
- package/dist/katex.js +4547 -5680
- package/dist/katex.min.css +1 -1
- package/dist/katex.min.js +1 -1
- package/dist/katex.mjs +11854 -13828
- package/{katex.js → katex.ts} +8 -5
- package/package.json +34 -31
- package/src/{Lexer.js → Lexer.ts} +1 -2
- package/src/{MacroExpander.js → MacroExpander.ts} +11 -15
- package/src/{Namespace.js → Namespace.ts} +4 -6
- package/src/{Options.js → Options.ts} +7 -12
- package/src/{ParseError.js → ParseError.ts} +16 -26
- package/src/{Parser.js → Parser.ts} +68 -56
- package/src/{Settings.js → Settings.ts} +70 -70
- package/src/{SourceLocation.js → SourceLocation.ts} +6 -7
- package/src/{Style.js → Style.ts} +4 -5
- package/src/{Token.js → Token.ts} +8 -6
- package/src/{buildCommon.js → buildCommon.ts} +62 -55
- package/src/{buildHTML.js → buildHTML.ts} +29 -25
- package/src/{buildMathML.js → buildMathML.ts} +15 -13
- package/src/{buildTree.js → buildTree.ts} +1 -2
- package/src/{defineEnvironment.js → defineEnvironment.ts} +26 -27
- package/src/{defineFunction.js → defineFunction.ts} +54 -56
- package/src/{defineMacro.js → defineMacro.ts} +12 -13
- package/src/{delimiter.js → delimiter.ts} +19 -17
- package/src/{domTree.js → domTree.ts} +94 -103
- package/src/environments/{array.js → array.ts} +109 -99
- package/src/environments/{cd.js → cd.ts} +9 -11
- package/src/{environments.js → environments.ts} +0 -1
- package/src/{fontMetrics.js → fontMetrics.ts} +10 -12
- package/src/fontMetricsData.d.ts +3 -0
- package/src/functions/{accent.js → accent.ts} +1 -2
- package/src/functions/{accentunder.js → accentunder.ts} +0 -1
- package/src/functions/{arrow.js → arrow.ts} +4 -6
- package/src/functions/{char.js → char.ts} +0 -1
- package/src/functions/{color.js → color.ts} +5 -6
- package/src/functions/{cr.js → cr.ts} +0 -1
- package/src/functions/{def.js → def.ts} +9 -7
- package/src/functions/{delimsizing.js → delimsizing.ts} +11 -9
- package/src/functions/{enclose.js → enclose.ts} +3 -4
- package/src/functions/{environment.js → environment.ts} +2 -3
- package/src/functions/{font.js → font.ts} +4 -4
- package/src/functions/{genfrac.js → genfrac.ts} +14 -15
- package/src/functions/{hbox.js → hbox.ts} +0 -1
- package/src/functions/{horizBrace.js → horizBrace.ts} +4 -5
- package/src/functions/{href.js → href.ts} +4 -4
- package/src/functions/{html.js → html.ts} +3 -3
- package/src/functions/{htmlmathml.js → htmlmathml.ts} +0 -1
- package/src/functions/{includegraphics.js → includegraphics.ts} +0 -1
- package/src/functions/{kern.js → kern.ts} +0 -1
- package/src/functions/{lap.js → lap.ts} +0 -1
- package/src/functions/{math.js → math.ts} +0 -1
- package/src/functions/{mathchoice.js → mathchoice.ts} +2 -2
- package/src/functions/{mclass.js → mclass.ts} +5 -6
- package/src/functions/{op.js → op.ts} +9 -11
- package/src/functions/{operatorname.js → operatorname.ts} +4 -7
- package/src/functions/{ordgroup.js → ordgroup.ts} +0 -2
- package/src/functions/{overline.js → overline.ts} +0 -1
- package/src/functions/{phantom.js → phantom.ts} +0 -1
- package/src/functions/{pmb.js → pmb.ts} +0 -1
- package/src/functions/{raisebox.js → raisebox.ts} +0 -1
- package/src/functions/{relax.js → relax.ts} +0 -1
- package/src/functions/{rule.js → rule.ts} +0 -1
- package/src/functions/{sizing.js → sizing.ts} +0 -1
- package/src/functions/{smash.js → smash.ts} +2 -4
- package/src/functions/{sqrt.js → sqrt.ts} +0 -1
- package/src/functions/{styling.js → styling.ts} +3 -3
- package/src/functions/{supsub.js → supsub.ts} +6 -8
- package/src/functions/{symbolsOp.js → symbolsOp.ts} +0 -2
- package/src/functions/{symbolsOrd.js → symbolsOrd.ts} +1 -2
- package/src/functions/{symbolsSpacing.js → symbolsSpacing.ts} +2 -3
- package/src/functions/{tag.js → tag.ts} +0 -2
- package/src/functions/{text.js → text.ts} +7 -6
- package/src/functions/{underline.js → underline.ts} +0 -1
- package/src/functions/utils/{assembleSupSub.js → assembleSupSub.ts} +2 -3
- package/src/functions/{vcenter.js → vcenter.ts} +0 -2
- package/src/functions/{verb.js → verb.ts} +0 -1
- package/src/{functions.js → functions.ts} +0 -1
- package/src/{macros.js → macros.ts} +10 -8
- package/src/{mathMLTree.js → mathMLTree.ts} +5 -6
- package/src/parseNode.ts +522 -0
- package/src/{parseTree.js → parseTree.ts} +5 -3
- package/src/{spacingData.js → spacingData.ts} +11 -12
- package/src/{stretchy.js → stretchy.ts} +7 -7
- package/src/styles/katex-swap.scss +1 -4
- package/src/styles/katex.scss +9 -0
- package/src/{svgGeometry.js → svgGeometry.ts} +1 -2
- package/src/{symbols.js → symbols.ts} +6 -6
- package/src/{tree.js → tree.ts} +5 -7
- package/src/{types.js → types.ts} +1 -2
- package/src/unicodeAccents.js +4 -1
- package/src/{unicodeScripts.js → unicodeScripts.ts} +1 -3
- package/src/{unicodeSupOrSub.js → unicodeSupOrSub.ts} +1 -1
- package/src/unicodeSymbols.js +4 -3
- package/src/{units.js → units.ts} +2 -4
- package/src/{utils.js → utils.ts} +2 -3
- package/src/{wide-character.js → wide-character.ts} +8 -10
- package/types/katex.d.ts +13 -12
- package/src/parseNode.js +0 -523
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import type Parser from "./Parser";
|
|
3
2
|
import type {ParseNode, AnyParseNode, NodeType, UnsupportedCmdParseNode}
|
|
4
3
|
from "./parseNode";
|
|
@@ -9,95 +8,94 @@ import type {Token} from "./Token";
|
|
|
9
8
|
import type {MathDomNode} from "./mathMLTree";
|
|
10
9
|
|
|
11
10
|
/** Context provided to function handlers for error messages. */
|
|
12
|
-
export type FunctionContext = {
|
|
13
|
-
funcName: string
|
|
14
|
-
parser: Parser
|
|
15
|
-
token?: Token
|
|
16
|
-
breakOnTokenText?: BreakToken
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export type FunctionHandler<NODETYPE
|
|
11
|
+
export type FunctionContext = {
|
|
12
|
+
funcName: string;
|
|
13
|
+
parser: Parser;
|
|
14
|
+
token?: Token;
|
|
15
|
+
breakOnTokenText?: BreakToken;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type FunctionHandler<NODETYPE extends NodeType> = (
|
|
20
19
|
context: FunctionContext,
|
|
21
20
|
args: AnyParseNode[],
|
|
22
|
-
optArgs: (
|
|
21
|
+
optArgs: (AnyParseNode | null | undefined)[],
|
|
23
22
|
) => UnsupportedCmdParseNode | ParseNode<NODETYPE>;
|
|
24
23
|
// Note: reverse the order of the return type union will cause a flow error.
|
|
25
24
|
// See https://github.com/facebook/flow/issues/3663.
|
|
26
25
|
|
|
27
|
-
export type HtmlBuilder<NODETYPE> =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
options: Options
|
|
31
|
-
) => MathDomNode;
|
|
26
|
+
export type HtmlBuilder<NODETYPE extends NodeType> =
|
|
27
|
+
(group: ParseNode<NODETYPE>, options: Options) => HtmlDomNode;
|
|
28
|
+
export type MathMLBuilder<NODETYPE extends NodeType> =
|
|
29
|
+
(group: ParseNode<NODETYPE>, options: Options) => MathDomNode;
|
|
32
30
|
|
|
33
31
|
// More general version of `HtmlBuilder` for nodes (e.g. \sum, accent types)
|
|
34
32
|
// whose presence impacts super/subscripting. In this case, ParseNode<"supsub">
|
|
35
33
|
// delegates its HTML building to the HtmlBuilder corresponding to these nodes.
|
|
36
|
-
export type HtmlBuilderSupSub<NODETYPE> =
|
|
37
|
-
(ParseNode<"supsub"> | ParseNode<NODETYPE>, Options) => HtmlDomNode;
|
|
34
|
+
export type HtmlBuilderSupSub<NODETYPE extends NodeType> =
|
|
35
|
+
(group: ParseNode<"supsub"> | ParseNode<NODETYPE>, options: Options) => HtmlDomNode;
|
|
38
36
|
|
|
39
37
|
export type FunctionPropSpec = {
|
|
40
38
|
// The number of arguments the function takes.
|
|
41
|
-
numArgs: number
|
|
39
|
+
numArgs: number;
|
|
42
40
|
|
|
43
41
|
// An array corresponding to each argument of the function, giving the
|
|
44
42
|
// type of argument that should be parsed. Its length should be equal
|
|
45
43
|
// to `numOptionalArgs + numArgs`, and types for optional arguments
|
|
46
44
|
// should appear before types for mandatory arguments.
|
|
47
|
-
argTypes?: ArgType[]
|
|
45
|
+
argTypes?: ArgType[];
|
|
48
46
|
|
|
49
47
|
// Whether it expands to a single token or a braced group of tokens.
|
|
50
48
|
// If it's grouped, it can be used as an argument to primitive commands,
|
|
51
49
|
// such as \sqrt (without the optional argument) and super/subscript.
|
|
52
|
-
allowedInArgument?: boolean
|
|
50
|
+
allowedInArgument?: boolean;
|
|
53
51
|
|
|
54
52
|
// Whether or not the function is allowed inside text mode
|
|
55
53
|
// (default false)
|
|
56
|
-
allowedInText?: boolean
|
|
54
|
+
allowedInText?: boolean;
|
|
57
55
|
|
|
58
56
|
// Whether or not the function is allowed inside text mode
|
|
59
57
|
// (default true)
|
|
60
|
-
allowedInMath?: boolean
|
|
58
|
+
allowedInMath?: boolean;
|
|
61
59
|
|
|
62
60
|
// (optional) The number of optional arguments the function
|
|
63
61
|
// should parse. If the optional arguments aren't found,
|
|
64
62
|
// `null` will be passed to the handler in their place.
|
|
65
63
|
// (default 0)
|
|
66
|
-
numOptionalArgs?: number
|
|
64
|
+
numOptionalArgs?: number;
|
|
67
65
|
|
|
68
66
|
// Must be true if the function is an infix operator.
|
|
69
|
-
infix?: boolean
|
|
67
|
+
infix?: boolean;
|
|
70
68
|
|
|
71
69
|
// Whether or not the function is a TeX primitive.
|
|
72
|
-
primitive?: boolean
|
|
70
|
+
primitive?: boolean;
|
|
73
71
|
};
|
|
74
72
|
|
|
75
|
-
type FunctionDefSpec<NODETYPE
|
|
73
|
+
type FunctionDefSpec<NODETYPE extends NodeType> = {
|
|
76
74
|
// Unique string to differentiate parse nodes.
|
|
77
75
|
// Also determines the type of the value returned by `handler`.
|
|
78
|
-
type: NODETYPE
|
|
76
|
+
type: NODETYPE;
|
|
79
77
|
|
|
80
78
|
// The first argument to defineFunction is a single name or a list of names.
|
|
81
79
|
// All functions named in such a list will share a single implementation.
|
|
82
|
-
names: Array<string
|
|
80
|
+
names: Array<string>;
|
|
83
81
|
|
|
84
82
|
// Properties that control how the functions are parsed.
|
|
85
|
-
props: FunctionPropSpec
|
|
83
|
+
props: FunctionPropSpec;
|
|
86
84
|
|
|
87
85
|
// The handler is called to handle these functions and their arguments and
|
|
88
86
|
// returns a `ParseNode`.
|
|
89
|
-
handler:
|
|
87
|
+
handler: FunctionHandler<NODETYPE> | null | undefined;
|
|
90
88
|
|
|
91
89
|
// This function returns an object representing the DOM structure to be
|
|
92
90
|
// created when rendering the defined LaTeX function.
|
|
93
91
|
// This should not modify the `ParseNode`.
|
|
94
|
-
htmlBuilder?: HtmlBuilder<NODETYPE
|
|
92
|
+
htmlBuilder?: HtmlBuilder<NODETYPE>;
|
|
95
93
|
|
|
96
94
|
// This function returns an object representing the MathML structure to be
|
|
97
95
|
// created when rendering the defined LaTeX function.
|
|
98
96
|
// This should not modify the `ParseNode`.
|
|
99
|
-
mathmlBuilder?: MathMLBuilder<NODETYPE
|
|
100
|
-
|
|
97
|
+
mathmlBuilder?: MathMLBuilder<NODETYPE>;
|
|
98
|
+
};
|
|
101
99
|
|
|
102
100
|
/**
|
|
103
101
|
* Final function spec for use at parse time.
|
|
@@ -106,16 +104,16 @@ type FunctionDefSpec<NODETYPE: NodeType> = {|
|
|
|
106
104
|
* 2. requires all arguments except argTypes.
|
|
107
105
|
* It is generated by `defineFunction()` below.
|
|
108
106
|
*/
|
|
109
|
-
export type FunctionSpec<NODETYPE
|
|
110
|
-
type: NODETYPE
|
|
111
|
-
numArgs: number
|
|
112
|
-
argTypes?: ArgType[]
|
|
113
|
-
allowedInArgument: boolean
|
|
114
|
-
allowedInText: boolean
|
|
115
|
-
allowedInMath: boolean
|
|
116
|
-
numOptionalArgs: number
|
|
117
|
-
infix: boolean
|
|
118
|
-
primitive: boolean
|
|
107
|
+
export type FunctionSpec<NODETYPE extends NodeType> = {
|
|
108
|
+
type: NODETYPE; // Need to use the type to avoid error. See NOTES below.
|
|
109
|
+
numArgs: number;
|
|
110
|
+
argTypes?: ArgType[];
|
|
111
|
+
allowedInArgument: boolean;
|
|
112
|
+
allowedInText: boolean;
|
|
113
|
+
allowedInMath: boolean;
|
|
114
|
+
numOptionalArgs: number;
|
|
115
|
+
infix: boolean;
|
|
116
|
+
primitive: boolean;
|
|
119
117
|
|
|
120
118
|
// FLOW TYPE NOTES: Doing either one of the following two
|
|
121
119
|
//
|
|
@@ -132,29 +130,29 @@ export type FunctionSpec<NODETYPE: NodeType> = {|
|
|
|
132
130
|
// _functions is typed FunctionSpec<*> (it stores all TeX function specs).
|
|
133
131
|
|
|
134
132
|
// Must be specified unless it's handled directly in the parser.
|
|
135
|
-
handler:
|
|
136
|
-
|
|
133
|
+
handler: FunctionHandler<any> | null | undefined;
|
|
134
|
+
};
|
|
137
135
|
|
|
138
136
|
/**
|
|
139
137
|
* All registered functions.
|
|
140
138
|
* `functions.js` just exports this same dictionary again and makes it public.
|
|
141
139
|
* `Parser.js` requires this dictionary.
|
|
142
140
|
*/
|
|
143
|
-
export const _functions:
|
|
141
|
+
export const _functions: Record<string, FunctionSpec<any>> = {};
|
|
144
142
|
|
|
145
143
|
/**
|
|
146
144
|
* All HTML builders. Should be only used in the `define*` and the `build*ML`
|
|
147
145
|
* functions.
|
|
148
146
|
*/
|
|
149
|
-
export const _htmlGroupBuilders:
|
|
147
|
+
export const _htmlGroupBuilders: Record<string, HtmlBuilder<any>> = {};
|
|
150
148
|
|
|
151
149
|
/**
|
|
152
150
|
* All MathML builders. Should be only used in the `define*` and the `build*ML`
|
|
153
151
|
* functions.
|
|
154
152
|
*/
|
|
155
|
-
export const _mathmlGroupBuilders:
|
|
153
|
+
export const _mathmlGroupBuilders: Record<string, MathMLBuilder<any>> = {};
|
|
156
154
|
|
|
157
|
-
export default function defineFunction<NODETYPE
|
|
155
|
+
export default function defineFunction<NODETYPE extends NodeType>({
|
|
158
156
|
type,
|
|
159
157
|
names,
|
|
160
158
|
props,
|
|
@@ -175,7 +173,7 @@ export default function defineFunction<NODETYPE: NodeType>({
|
|
|
175
173
|
numOptionalArgs: props.numOptionalArgs || 0,
|
|
176
174
|
infix: !!props.infix,
|
|
177
175
|
primitive: !!props.primitive,
|
|
178
|
-
handler
|
|
176
|
+
handler,
|
|
179
177
|
};
|
|
180
178
|
for (let i = 0; i < names.length; ++i) {
|
|
181
179
|
_functions[names[i]] = data;
|
|
@@ -195,13 +193,13 @@ export default function defineFunction<NODETYPE: NodeType>({
|
|
|
195
193
|
* if the function's ParseNode is generated in Parser.js rather than via a
|
|
196
194
|
* stand-alone handler provided to `defineFunction`).
|
|
197
195
|
*/
|
|
198
|
-
export function defineFunctionBuilders<NODETYPE
|
|
196
|
+
export function defineFunctionBuilders<NODETYPE extends NodeType>({
|
|
199
197
|
type, htmlBuilder, mathmlBuilder,
|
|
200
|
-
}: {
|
|
201
|
-
type: NODETYPE
|
|
202
|
-
htmlBuilder?: HtmlBuilder<NODETYPE
|
|
203
|
-
mathmlBuilder: MathMLBuilder<NODETYPE
|
|
204
|
-
|
|
198
|
+
}: {
|
|
199
|
+
type: NODETYPE;
|
|
200
|
+
htmlBuilder?: HtmlBuilder<NODETYPE>;
|
|
201
|
+
mathmlBuilder: MathMLBuilder<NODETYPE>;
|
|
202
|
+
}) {
|
|
205
203
|
defineFunction({
|
|
206
204
|
type,
|
|
207
205
|
names: [],
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
|
|
3
2
|
import {Token} from "./Token";
|
|
4
3
|
import type Namespace from "./Namespace";
|
|
@@ -53,13 +52,13 @@ export interface MacroContextInterface {
|
|
|
53
52
|
* Fully expand the given macro name and return the resulting list of
|
|
54
53
|
* tokens, or return `undefined` if no such macro is defined.
|
|
55
54
|
*/
|
|
56
|
-
expandMacro(name: string): Token[] |
|
|
55
|
+
expandMacro(name: string): Token[] | undefined;
|
|
57
56
|
|
|
58
57
|
/**
|
|
59
58
|
* Fully expand the given macro name and return the result as a string,
|
|
60
59
|
* or return `undefined` if no such macro is defined.
|
|
61
60
|
*/
|
|
62
|
-
expandMacroAsText(name: string): string |
|
|
61
|
+
expandMacroAsText(name: string): string | undefined;
|
|
63
62
|
|
|
64
63
|
/**
|
|
65
64
|
* Fully expand the given token stream and return the resulting list of
|
|
@@ -72,7 +71,7 @@ export interface MacroContextInterface {
|
|
|
72
71
|
* Consume an argument from the token stream, and return the resulting array
|
|
73
72
|
* of tokens and start/end token.
|
|
74
73
|
*/
|
|
75
|
-
consumeArg(delims?:
|
|
74
|
+
consumeArg(delims?: string[] | null | undefined): MacroArg;
|
|
76
75
|
|
|
77
76
|
/**
|
|
78
77
|
* Consume the specified number of arguments from the token stream,
|
|
@@ -95,22 +94,22 @@ export interface MacroContextInterface {
|
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
export type MacroArg = {
|
|
98
|
-
tokens: Token[]
|
|
99
|
-
start: Token
|
|
100
|
-
end: Token
|
|
97
|
+
tokens: Token[];
|
|
98
|
+
start: Token;
|
|
99
|
+
end: Token;
|
|
101
100
|
};
|
|
102
101
|
|
|
103
102
|
/** Macro tokens (in reverse order). */
|
|
104
103
|
export type MacroExpansion = {
|
|
105
|
-
tokens: Token[]
|
|
106
|
-
numArgs: number
|
|
107
|
-
delimiters?: string[][]
|
|
108
|
-
unexpandable?: boolean
|
|
104
|
+
tokens: Token[];
|
|
105
|
+
numArgs: number;
|
|
106
|
+
delimiters?: string[][];
|
|
107
|
+
unexpandable?: boolean; // used in \let
|
|
109
108
|
};
|
|
110
109
|
|
|
111
110
|
export type MacroDefinition = string | MacroExpansion |
|
|
112
|
-
(MacroContextInterface =>
|
|
113
|
-
export type MacroMap =
|
|
111
|
+
((arg0: MacroContextInterface) => string | MacroExpansion);
|
|
112
|
+
export type MacroMap = Record<string, MacroDefinition>;
|
|
114
113
|
|
|
115
114
|
/**
|
|
116
115
|
* All registered global/built-in macros.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
/**
|
|
3
2
|
* This file deals with creating delimiters of various sizes. The TeXbook
|
|
4
3
|
* discusses these routines on page 441-442, in the "Another subroutine sets box
|
|
@@ -39,6 +38,8 @@ import type {Mode} from "./types";
|
|
|
39
38
|
import type {StyleInterface} from "./Style";
|
|
40
39
|
import type {VListElem} from "./buildCommon";
|
|
41
40
|
|
|
41
|
+
type StackedDelimiterFont = "Size1-Regular" | "Size4-Regular";
|
|
42
|
+
|
|
42
43
|
/**
|
|
43
44
|
* Get the metrics for a given symbol and font, after transformation (i.e.
|
|
44
45
|
* after following replacement from symbols.js)
|
|
@@ -136,7 +137,7 @@ const mathrmSize = function(
|
|
|
136
137
|
* Makes a large delimiter. This is a delimiter that comes in the Size1, Size2,
|
|
137
138
|
* Size3, or Size4 fonts. It is always rendered in textstyle.
|
|
138
139
|
*/
|
|
139
|
-
const makeLargeDelim = function(delim,
|
|
140
|
+
const makeLargeDelim = function(delim: string,
|
|
140
141
|
size: number,
|
|
141
142
|
center: boolean,
|
|
142
143
|
options: Options,
|
|
@@ -159,7 +160,7 @@ const makeLargeDelim = function(delim,
|
|
|
159
160
|
*/
|
|
160
161
|
const makeGlyphSpan = function(
|
|
161
162
|
symbol: string,
|
|
162
|
-
font:
|
|
163
|
+
font: StackedDelimiterFont,
|
|
163
164
|
mode: Mode,
|
|
164
165
|
): VListElem {
|
|
165
166
|
let sizeClass;
|
|
@@ -206,7 +207,7 @@ const makeInner = function(
|
|
|
206
207
|
|
|
207
208
|
// Helpers for makeStackedDelim
|
|
208
209
|
const lapInEms = 0.008;
|
|
209
|
-
const lap = {type: "kern", size: -1 * lapInEms};
|
|
210
|
+
const lap: {type: "kern"; size: number} = {type: "kern", size: -1 * lapInEms};
|
|
210
211
|
const verts = new Set(["|", "\\lvert", "\\rvert", "\\vert"]);
|
|
211
212
|
const doubleVerts = new Set(["\\|", "\\lVert", "\\rVert", "\\Vert"]);
|
|
212
213
|
|
|
@@ -233,7 +234,7 @@ const makeStackedDelim = function(
|
|
|
233
234
|
top = repeat = bottom = delim;
|
|
234
235
|
middle = null;
|
|
235
236
|
// Also keep track of what font the delimiters are in
|
|
236
|
-
let font = "Size1-Regular";
|
|
237
|
+
let font: StackedDelimiterFont = "Size1-Regular";
|
|
237
238
|
|
|
238
239
|
// We set the parts and font based on the symbol. Note that we use
|
|
239
240
|
// '\u23d0' instead of '|' and '\u2016' instead of '\\|' for the
|
|
@@ -388,7 +389,7 @@ const makeStackedDelim = function(
|
|
|
388
389
|
|
|
389
390
|
// Now, we start building the pieces that will go into the vlist
|
|
390
391
|
// Keep a list of the pieces of the stacked delimiter
|
|
391
|
-
const stack = [];
|
|
392
|
+
const stack: Array<VListElem | {type: "kern"; size: number}> = [];
|
|
392
393
|
|
|
393
394
|
if (svgLabel.length > 0) {
|
|
394
395
|
// Instead of stacking glyphs, create a single SVG.
|
|
@@ -649,7 +650,7 @@ type Delimiter =
|
|
|
649
650
|
{type: "stack"};
|
|
650
651
|
|
|
651
652
|
// Delimiters that never stack try small delimiters and large delimiters only
|
|
652
|
-
const stackNeverDelimiterSequence = [
|
|
653
|
+
const stackNeverDelimiterSequence: Delimiter[] = [
|
|
653
654
|
{type: "small", style: Style.SCRIPTSCRIPT},
|
|
654
655
|
{type: "small", style: Style.SCRIPT},
|
|
655
656
|
{type: "small", style: Style.TEXT},
|
|
@@ -660,7 +661,7 @@ const stackNeverDelimiterSequence = [
|
|
|
660
661
|
];
|
|
661
662
|
|
|
662
663
|
// Delimiters that always stack try the small delimiters first, then stack
|
|
663
|
-
const stackAlwaysDelimiterSequence = [
|
|
664
|
+
const stackAlwaysDelimiterSequence: Delimiter[] = [
|
|
664
665
|
{type: "small", style: Style.SCRIPTSCRIPT},
|
|
665
666
|
{type: "small", style: Style.SCRIPT},
|
|
666
667
|
{type: "small", style: Style.TEXT},
|
|
@@ -669,7 +670,7 @@ const stackAlwaysDelimiterSequence = [
|
|
|
669
670
|
|
|
670
671
|
// Delimiters that stack when large try the small and then large delimiters, and
|
|
671
672
|
// stack afterwards
|
|
672
|
-
const stackLargeDelimiterSequence = [
|
|
673
|
+
const stackLargeDelimiterSequence: Delimiter[] = [
|
|
673
674
|
{type: "small", style: Style.SCRIPTSCRIPT},
|
|
674
675
|
{type: "small", style: Style.SCRIPT},
|
|
675
676
|
{type: "small", style: Style.TEXT},
|
|
@@ -692,7 +693,8 @@ const delimTypeToFont = function(type: Delimiter): string {
|
|
|
692
693
|
} else if (type.type === "stack") {
|
|
693
694
|
return "Size4-Regular";
|
|
694
695
|
} else {
|
|
695
|
-
|
|
696
|
+
const delimKind = (type as Delimiter).type;
|
|
697
|
+
throw new Error(`Add support for delim type '${delimKind}' here.`);
|
|
696
698
|
}
|
|
697
699
|
};
|
|
698
700
|
|
|
@@ -712,25 +714,25 @@ const traverseSequence = function(
|
|
|
712
714
|
// at index 3-2=1, text starts at 3-1=2, and display starts at min(2,3-0)=2
|
|
713
715
|
const start = Math.min(2, 3 - options.style.size);
|
|
714
716
|
for (let i = start; i < sequence.length; i++) {
|
|
715
|
-
|
|
717
|
+
const delimType = sequence[i];
|
|
718
|
+
if (delimType.type === "stack") {
|
|
716
719
|
// This is always the last delimiter, so we just break the loop now.
|
|
717
720
|
break;
|
|
718
721
|
}
|
|
719
722
|
|
|
720
|
-
const metrics = getMetrics(delim, delimTypeToFont(
|
|
723
|
+
const metrics = getMetrics(delim, delimTypeToFont(delimType), "math");
|
|
721
724
|
let heightDepth = metrics.height + metrics.depth;
|
|
722
725
|
|
|
723
726
|
// Small delimiters are scaled down versions of the same font, so we
|
|
724
727
|
// account for the style change size.
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
const newOptions = options.havingBaseStyle(sequence[i].style);
|
|
728
|
+
if (delimType.type === "small") {
|
|
729
|
+
const newOptions = options.havingBaseStyle(delimType.style);
|
|
728
730
|
heightDepth *= newOptions.sizeMultiplier;
|
|
729
731
|
}
|
|
730
732
|
|
|
731
733
|
// Check if the delimiter at this size works for the given height.
|
|
732
734
|
if (heightDepth > height) {
|
|
733
|
-
return
|
|
735
|
+
return delimType;
|
|
734
736
|
}
|
|
735
737
|
}
|
|
736
738
|
|
|
@@ -757,7 +759,7 @@ export const makeCustomSizedDelim = function(
|
|
|
757
759
|
}
|
|
758
760
|
|
|
759
761
|
// Decide what sequence to use
|
|
760
|
-
let sequence;
|
|
762
|
+
let sequence: Delimiter[];
|
|
761
763
|
if (stackNeverDelimiters.has(delim)) {
|
|
762
764
|
sequence = stackNeverDelimiterSequence;
|
|
763
765
|
} else if (stackLargeDelimiters.has(delim)) {
|