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.
Files changed (126) hide show
  1. package/README.md +3 -3
  2. package/contrib/auto-render/{auto-render.js → auto-render.ts} +41 -19
  3. package/contrib/auto-render/{splitAtDelimiters.js → splitAtDelimiters.ts} +18 -4
  4. package/contrib/auto-render/test/{auto-render-spec.js → auto-render-spec.ts} +10 -2
  5. package/contrib/copy-tex/README.md +2 -2
  6. package/contrib/copy-tex/{copy-tex.js → copy-tex.ts} +4 -6
  7. package/contrib/copy-tex/{katex2tex.js → katex2tex.ts} +2 -3
  8. package/contrib/mathtex-script-type/README.md +5 -5
  9. package/contrib/mhchem/README.md +1 -1
  10. package/contrib/render-a11y-string/{render-a11y-string.js → render-a11y-string.ts} +18 -33
  11. package/contrib/render-a11y-string/test/{render-a11y-string-spec.js → render-a11y-string-spec.ts} +0 -1
  12. package/dist/README.md +3 -3
  13. package/dist/contrib/auto-render.js +24 -57
  14. package/dist/contrib/auto-render.min.js +1 -1
  15. package/dist/contrib/auto-render.mjs +16586 -210
  16. package/dist/contrib/copy-tex.js +23 -37
  17. package/dist/contrib/copy-tex.min.js +1 -1
  18. package/dist/contrib/copy-tex.mjs +77 -95
  19. package/dist/contrib/mathtex-script-type.js +0 -3
  20. package/dist/contrib/mathtex-script-type.mjs +16427 -4
  21. package/dist/contrib/mhchem.js +55 -303
  22. package/dist/contrib/mhchem.mjs +12884 -723
  23. package/dist/contrib/render-a11y-string.js +13 -108
  24. package/dist/contrib/render-a11y-string.min.js +1 -1
  25. package/dist/contrib/render-a11y-string.mjs +17020 -760
  26. package/dist/katex-swap.css +2 -1
  27. package/dist/katex-swap.min.css +1 -1
  28. package/dist/katex.css +2 -1
  29. package/dist/katex.js +4547 -5680
  30. package/dist/katex.min.css +1 -1
  31. package/dist/katex.min.js +1 -1
  32. package/dist/katex.mjs +11854 -13828
  33. package/{katex.js → katex.ts} +8 -5
  34. package/package.json +34 -31
  35. package/src/{Lexer.js → Lexer.ts} +1 -2
  36. package/src/{MacroExpander.js → MacroExpander.ts} +11 -15
  37. package/src/{Namespace.js → Namespace.ts} +4 -6
  38. package/src/{Options.js → Options.ts} +7 -12
  39. package/src/{ParseError.js → ParseError.ts} +16 -26
  40. package/src/{Parser.js → Parser.ts} +68 -56
  41. package/src/{Settings.js → Settings.ts} +70 -70
  42. package/src/{SourceLocation.js → SourceLocation.ts} +6 -7
  43. package/src/{Style.js → Style.ts} +4 -5
  44. package/src/{Token.js → Token.ts} +8 -6
  45. package/src/{buildCommon.js → buildCommon.ts} +62 -55
  46. package/src/{buildHTML.js → buildHTML.ts} +29 -25
  47. package/src/{buildMathML.js → buildMathML.ts} +15 -13
  48. package/src/{buildTree.js → buildTree.ts} +1 -2
  49. package/src/{defineEnvironment.js → defineEnvironment.ts} +26 -27
  50. package/src/{defineFunction.js → defineFunction.ts} +54 -56
  51. package/src/{defineMacro.js → defineMacro.ts} +12 -13
  52. package/src/{delimiter.js → delimiter.ts} +19 -17
  53. package/src/{domTree.js → domTree.ts} +94 -103
  54. package/src/environments/{array.js → array.ts} +109 -99
  55. package/src/environments/{cd.js → cd.ts} +9 -11
  56. package/src/{environments.js → environments.ts} +0 -1
  57. package/src/{fontMetrics.js → fontMetrics.ts} +10 -12
  58. package/src/fontMetricsData.d.ts +3 -0
  59. package/src/functions/{accent.js → accent.ts} +1 -2
  60. package/src/functions/{accentunder.js → accentunder.ts} +0 -1
  61. package/src/functions/{arrow.js → arrow.ts} +4 -6
  62. package/src/functions/{char.js → char.ts} +0 -1
  63. package/src/functions/{color.js → color.ts} +5 -6
  64. package/src/functions/{cr.js → cr.ts} +0 -1
  65. package/src/functions/{def.js → def.ts} +9 -7
  66. package/src/functions/{delimsizing.js → delimsizing.ts} +11 -9
  67. package/src/functions/{enclose.js → enclose.ts} +3 -4
  68. package/src/functions/{environment.js → environment.ts} +2 -3
  69. package/src/functions/{font.js → font.ts} +4 -4
  70. package/src/functions/{genfrac.js → genfrac.ts} +14 -15
  71. package/src/functions/{hbox.js → hbox.ts} +0 -1
  72. package/src/functions/{horizBrace.js → horizBrace.ts} +4 -5
  73. package/src/functions/{href.js → href.ts} +4 -4
  74. package/src/functions/{html.js → html.ts} +3 -3
  75. package/src/functions/{htmlmathml.js → htmlmathml.ts} +0 -1
  76. package/src/functions/{includegraphics.js → includegraphics.ts} +0 -1
  77. package/src/functions/{kern.js → kern.ts} +0 -1
  78. package/src/functions/{lap.js → lap.ts} +0 -1
  79. package/src/functions/{math.js → math.ts} +0 -1
  80. package/src/functions/{mathchoice.js → mathchoice.ts} +2 -2
  81. package/src/functions/{mclass.js → mclass.ts} +5 -6
  82. package/src/functions/{op.js → op.ts} +9 -11
  83. package/src/functions/{operatorname.js → operatorname.ts} +4 -7
  84. package/src/functions/{ordgroup.js → ordgroup.ts} +0 -2
  85. package/src/functions/{overline.js → overline.ts} +0 -1
  86. package/src/functions/{phantom.js → phantom.ts} +0 -1
  87. package/src/functions/{pmb.js → pmb.ts} +0 -1
  88. package/src/functions/{raisebox.js → raisebox.ts} +0 -1
  89. package/src/functions/{relax.js → relax.ts} +0 -1
  90. package/src/functions/{rule.js → rule.ts} +0 -1
  91. package/src/functions/{sizing.js → sizing.ts} +0 -1
  92. package/src/functions/{smash.js → smash.ts} +2 -4
  93. package/src/functions/{sqrt.js → sqrt.ts} +0 -1
  94. package/src/functions/{styling.js → styling.ts} +3 -3
  95. package/src/functions/{supsub.js → supsub.ts} +6 -8
  96. package/src/functions/{symbolsOp.js → symbolsOp.ts} +0 -2
  97. package/src/functions/{symbolsOrd.js → symbolsOrd.ts} +1 -2
  98. package/src/functions/{symbolsSpacing.js → symbolsSpacing.ts} +2 -3
  99. package/src/functions/{tag.js → tag.ts} +0 -2
  100. package/src/functions/{text.js → text.ts} +7 -6
  101. package/src/functions/{underline.js → underline.ts} +0 -1
  102. package/src/functions/utils/{assembleSupSub.js → assembleSupSub.ts} +2 -3
  103. package/src/functions/{vcenter.js → vcenter.ts} +0 -2
  104. package/src/functions/{verb.js → verb.ts} +0 -1
  105. package/src/{functions.js → functions.ts} +0 -1
  106. package/src/{macros.js → macros.ts} +10 -8
  107. package/src/{mathMLTree.js → mathMLTree.ts} +5 -6
  108. package/src/parseNode.ts +522 -0
  109. package/src/{parseTree.js → parseTree.ts} +5 -3
  110. package/src/{spacingData.js → spacingData.ts} +11 -12
  111. package/src/{stretchy.js → stretchy.ts} +7 -7
  112. package/src/styles/katex-swap.scss +1 -4
  113. package/src/styles/katex.scss +9 -0
  114. package/src/{svgGeometry.js → svgGeometry.ts} +1 -2
  115. package/src/{symbols.js → symbols.ts} +6 -6
  116. package/src/{tree.js → tree.ts} +5 -7
  117. package/src/{types.js → types.ts} +1 -2
  118. package/src/unicodeAccents.js +4 -1
  119. package/src/{unicodeScripts.js → unicodeScripts.ts} +1 -3
  120. package/src/{unicodeSupOrSub.js → unicodeSupOrSub.ts} +1 -1
  121. package/src/unicodeSymbols.js +4 -3
  122. package/src/{units.js → units.ts} +2 -4
  123. package/src/{utils.js → utils.ts} +2 -3
  124. package/src/{wide-character.js → wide-character.ts} +8 -10
  125. package/types/katex.d.ts +13 -12
  126. package/src/parseNode.js +0 -523
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  import type {CssStyle, HtmlDomNode} from "./domTree";
4
2
  import type {MathDomNode} from "./mathMLTree";
5
3
 
@@ -16,16 +14,16 @@ export interface VirtualNode {
16
14
  * placed into the DOM doesn't have any representation itself. It only contains
17
15
  * children and doesn't have any DOM node properties.
18
16
  */
19
- export class DocumentFragment<ChildType: VirtualNode>
17
+ export class DocumentFragment<ChildType extends VirtualNode>
20
18
  implements HtmlDomNode, MathDomNode {
21
- children: $ReadOnlyArray<ChildType>;
19
+ children: ReadonlyArray<ChildType>;
22
20
  classes: string[];
23
21
  height: number;
24
22
  depth: number;
25
23
  maxFontSize: number;
26
24
  style: CssStyle; // Never used; needed for satisfying interface.
27
25
 
28
- constructor(children: $ReadOnlyArray<ChildType>) {
26
+ constructor(children: ReadonlyArray<ChildType>) {
29
27
  this.children = children;
30
28
  this.classes = [];
31
29
  this.height = 0;
@@ -68,8 +66,8 @@ export class DocumentFragment<ChildType: VirtualNode>
68
66
  toText(): string {
69
67
  // To avoid this, we would subclass documentFragment separately for
70
68
  // MathML, but polyfills for subclassing is expensive per PR 1469.
71
- // $FlowFixMe: Only works for ChildType = MathDomNode.
72
- const toText = (child: ChildType): string => child.toText();
69
+ // TODO(ts): Only works for ChildType = MathDomNode.
70
+ const toText = (child: ChildType): string => (child as unknown as MathDomNode).toText();
73
71
  return this.children.map(toText).join("");
74
72
  }
75
73
  }
@@ -1,7 +1,6 @@
1
- // @flow
2
1
 
3
2
  /**
4
- * This file consists only of basic flow types used in multiple places.
3
+ * This file consists only of basic types used in multiple places.
5
4
  * For types with javascript, create separate files by themselves.
6
5
  */
7
6
 
@@ -2,7 +2,8 @@
2
2
  // math mode (when they exist).
3
3
  // This exports a CommonJS module, allowing to be required in unicodeSymbols
4
4
  // without transpiling.
5
- module.exports = {
5
+ /** @type {Record<string, {text: string, math?: string}>} */
6
+ const unicodeAccents = {
6
7
  '\u0301': {text: "\\'", math: '\\acute'},
7
8
  '\u0300': {text: '\\`', math: '\\grave'},
8
9
  '\u0308': {text: '\\"', math: '\\ddot'},
@@ -16,3 +17,5 @@ module.exports = {
16
17
  '\u030b': {text: '\\H'},
17
18
  '\u0327': {text: '\\c'},
18
19
  };
20
+
21
+ module.exports = unicodeAccents;
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  /*
4
2
  * This file defines the Unicode scripts and script families that we
5
3
  * support. To add new scripts or families, just add a new entry to the
@@ -88,7 +86,7 @@ const scriptData: Array<Script> = [
88
86
  * Given a codepoint, return the name of the script or script family
89
87
  * it is from, or null if it is not part of a known block
90
88
  */
91
- export function scriptFromCodepoint(codepoint: number): ?string {
89
+ export function scriptFromCodepoint(codepoint: number): string | null | undefined {
92
90
  for (let i = 0; i < scriptData.length; i++) {
93
91
  const script = scriptData[i];
94
92
  for (let i = 0; i < script.blocks.length; i++) {
@@ -2,7 +2,7 @@
2
2
 
3
3
  export const unicodeSubRegEx = /^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/;
4
4
 
5
- export const uSubsAndSups = Object.freeze({
5
+ export const uSubsAndSups: Readonly<Record<string, string>> = Object.freeze({
6
6
  '₊': '+',
7
7
  '₋': '-',
8
8
  '₌': '=',
@@ -1,12 +1,13 @@
1
- // @flow
1
+ // @ts-check
2
2
  // This is an internal module, not part of the KaTeX distribution,
3
3
  // whose purpose is to generate `unicodeSymbols` in Parser.js
4
4
  // In this way, only this module, and not the distribution/browser,
5
5
  // needs String's normalize function. As this file is not transpiled,
6
- // Flow comment types syntax is used.
6
+ // JSDoc type syntax is used.
7
7
  const accents = require('./unicodeAccents');
8
8
 
9
- const result /*: {[string]: string}*/ = {};
9
+ /** @type {Record<string, string>} */
10
+ const result = {};
10
11
  const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +
11
12
  "αβγδεϵζηθϑικλμνξοπϖρϱςστυφϕχψωΓΔΘΛΞΠΣΥΦΨΩ";
12
13
  for (const letter of letters) {
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  /**
4
2
  * This file does conversion between units. In particular, it provides
5
3
  * calculateSize to convert other units into ems.
@@ -12,7 +10,7 @@ import Options from "./Options";
12
10
  // Thus, multiplying a length by this number converts the length from units
13
11
  // into pts. Dividing the result by ptPerEm gives the number of ems
14
12
  // *assuming* a font size of ptPerEm (normal size, normal style).
15
- const ptPerUnit = {
13
+ const ptPerUnit: Record<string, number> = {
16
14
  // https://en.wikibooks.org/wiki/LaTeX/Lengths and
17
15
  // https://tex.stackexchange.com/a/8263
18
16
  "pt": 1, // TeX point
@@ -37,7 +35,7 @@ const relativeUnit = {
37
35
  "mu": true,
38
36
  };
39
37
 
40
- export type Measurement = {| number: number, unit: string |};
38
+ export type Measurement = { number: number, unit: string };
41
39
 
42
40
  /**
43
41
  * Determine whether the specified unit (either a string defining the unit
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  /**
3
2
  * This file contains a list of utility functions which are useful in other
4
3
  * files.
@@ -11,7 +10,7 @@ const uppercase = /([A-Z])/g;
11
10
  export const hyphenate = (str: string): string =>
12
11
  str.replace(uppercase, "-$1").toLowerCase();
13
12
 
14
- const ESCAPE_LOOKUP = {
13
+ const ESCAPE_LOOKUP: Record<string, string> = {
15
14
  "&": "&amp;",
16
15
  ">": "&gt;",
17
16
  "<": "&lt;",
@@ -24,7 +23,7 @@ const ESCAPE_REGEX = /[&><"']/g;
24
23
  /**
25
24
  * Escapes text to prevent scripting attacks.
26
25
  */
27
- export const escape = (text: mixed): string =>
26
+ export const escape = (text: unknown): string =>
28
27
  String(text).replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]);
29
28
 
30
29
  /**
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  /**
4
2
  * This file provides support for Unicode range U+1D400 to U+1D7FF,
5
3
  * Mathematical Alphanumeric Symbols.
@@ -21,7 +19,7 @@ import ParseError from "./ParseError";
21
19
  * * The font name, so that KaTeX can get font metrics.
22
20
  */
23
21
 
24
- const wideLatinLetterData: Array<[string, string, string]> = [
22
+ const wideLatinLetterData = [
25
23
  ["mathbf", "textbf", "Main-Bold"], // A-Z bold upright
26
24
  ["mathbf", "textbf", "Main-Bold"], // a-z bold upright
27
25
 
@@ -63,20 +61,20 @@ const wideLatinLetterData: Array<[string, string, string]> = [
63
61
 
64
62
  ["mathtt", "texttt", "Typewriter-Regular"], // A-Z monospace
65
63
  ["mathtt", "texttt", "Typewriter-Regular"], // a-z monospace
66
- ];
64
+ ] as const satisfies readonly (readonly [string, string, string])[];
67
65
 
68
- const wideNumeralData: Array<[string, string, string]> = [
66
+ const wideNumeralData = [
69
67
  ["mathbf", "textbf", "Main-Bold"], // 0-9 bold
70
68
  ["", "", ""], // 0-9 double-struck. No KaTeX font.
71
69
  ["mathsf", "textsf", "SansSerif-Regular"], // 0-9 sans-serif
72
70
  ["mathboldsf", "textboldsf", "SansSerif-Bold"], // 0-9 bold sans-serif
73
71
  ["mathtt", "texttt", "Typewriter-Regular"], // 0-9 monospace
74
- ];
72
+ ] as const satisfies readonly (readonly [string, string, string])[];
75
73
 
76
- export const wideCharacterFont = function(
74
+ export const wideCharacterFont = (
77
75
  wideChar: string,
78
76
  mode: Mode,
79
- ): [string, string] {
77
+ ): [string, string] => {
80
78
 
81
79
  // IE doesn't support codePointAt(). So work with the surrogate pair.
82
80
  const H = wideChar.charCodeAt(0); // high surrogate
@@ -89,12 +87,12 @@ export const wideCharacterFont = function(
89
87
  // wideLatinLetterData contains exactly 26 chars on each row.
90
88
  // So we can calculate the relevant row. No traverse necessary.
91
89
  const i = Math.floor((codePoint - 0x1D400) / 26);
92
- return [wideLatinLetterData[i][2], wideLatinLetterData[i][j]];
90
+ return [wideLatinLetterData[i]![2], wideLatinLetterData[i]![j]];
93
91
 
94
92
  } else if (0x1D7CE <= codePoint && codePoint <= 0x1D7FF) {
95
93
  // Numerals, ten per row.
96
94
  const i = Math.floor((codePoint - 0x1D7CE) / 10);
97
- return [wideNumeralData[i][2], wideNumeralData[i][j]];
95
+ return [wideNumeralData[i]![2], wideNumeralData[i]![j]];
98
96
 
99
97
  } else if (codePoint === 0x1D6A5 || codePoint === 0x1D6A6) {
100
98
  // dotless i or j
package/types/katex.d.ts CHANGED
@@ -66,7 +66,7 @@ export interface KatexOptions {
66
66
  * If `true` the math will be rendered in display mode.
67
67
  * If `false` the math will be rendered in inline mode.
68
68
  * @see https://katex.org/docs/options
69
- *
69
+ *
70
70
  * @default false
71
71
  */
72
72
  displayMode?: boolean;
@@ -76,21 +76,21 @@ export interface KatexOptions {
76
76
  * - `mathml`: Outputs KaTeX in MathML only.
77
77
  * - `htmlAndMathml`: Outputs HTML for visual rendering and includes MathML
78
78
  * for accessibility.
79
- *
79
+ *
80
80
  * @default "htmlAndMathml"
81
81
  */
82
82
  output?: "html" | "mathml" | "htmlAndMathml";
83
83
  /**
84
84
  * If `true`, display math has `\tag`s rendered on the left instead of the
85
85
  * right, like `\usepackage[leqno]{amsmath}` in LaTeX.
86
- *
86
+ *
87
87
  * @default false
88
88
  */
89
89
  leqno?: boolean;
90
90
  /**
91
91
  * If `true`, display math renders flush left with a `2em` left margin,
92
92
  * like `\documentclass[fleqn]` in LaTeX with the `amsmath` package.
93
- *
93
+ *
94
94
  * @default false
95
95
  */
96
96
  fleqn?: boolean;
@@ -100,7 +100,7 @@ export interface KatexOptions {
100
100
  * If `false`, KaTeX will render unsupported commands as text, and render
101
101
  * invalid LaTeX as its source code with hover text giving the error, in
102
102
  * the color given by `errorColor`.
103
- *
103
+ *
104
104
  * @default true
105
105
  */
106
106
  throwOnError?: boolean;
@@ -108,7 +108,7 @@ export interface KatexOptions {
108
108
  * A color string given in the format `"#XXX"` or `"#XXXXXX"`. This option
109
109
  * determines the color that unsupported commands and invalid LaTeX are
110
110
  * rendered in when `throwOnError` is set to `false`.
111
- *
111
+ *
112
112
  * @default "#cc0000"
113
113
  */
114
114
  errorColor?: string;
@@ -116,7 +116,8 @@ export interface KatexOptions {
116
116
  * A collection of custom macros.
117
117
  * @see https://katex.org/docs/options
118
118
  */
119
- macros?: Record<string, string | object | ((macroExpander:object) => string | object)>;
119
+ macros?: Record<string, string | object | ((macroExpander:object)
120
+ => string | object)>;
120
121
  /**
121
122
  * Specifies a minimum thickness, in ems, for fraction lines, `\sqrt` top
122
123
  * lines, `{array}` vertical lines, `\hline`, `\hdashline`, `\underline`,
@@ -138,7 +139,7 @@ export interface KatexOptions {
138
139
  * All user-specified sizes, e.g. in `\rule{500em}{500em}`, will be capped
139
140
  * to `maxSize` ems. If set to `Infinity` (the default), users can make
140
141
  * elements and spaces arbitrarily large.
141
- *
142
+ *
142
143
  * @default Infinity
143
144
  */
144
145
  maxSize?: number;
@@ -147,7 +148,7 @@ export interface KatexOptions {
147
148
  * e.g. infinite macro loops. `\edef` expansion counts all expanded tokens.
148
149
  * If set to `Infinity`, the macro expander will try to fully expand as in
149
150
  * LaTeX.
150
- *
151
+ *
151
152
  * @default 1000
152
153
  */
153
154
  maxExpand?: number;
@@ -164,7 +165,7 @@ export interface KatexOptions {
164
165
  * can also return `"ignore"`, `"error"`, or `"warn"` to use a built-in
165
166
  * behavior.
166
167
  * @see https://katex.org/docs/options
167
- *
168
+ *
168
169
  * @default "warn"
169
170
  */
170
171
  strict?:
@@ -179,7 +180,7 @@ export interface KatexOptions {
179
180
  * Provide a custom function `handler(context)` to customize behavior
180
181
  * depending on the context (command, arguments e.g. a URL, etc.).
181
182
  * @see https://katex.org/docs/options
182
- *
183
+ *
183
184
  * @default false
184
185
  */
185
186
  trust?: boolean | ((context: TrustContext) => boolean);
@@ -190,7 +191,7 @@ export interface KatexOptions {
190
191
  * constructs such as `\begin{equation}` and `$$` create a local group and
191
192
  * prevent definitions other than `\gdef` from becoming visible outside of
192
193
  * those blocks, so this is KaTeX's default behavior.
193
- *
194
+ *
194
195
  * @default false
195
196
  */
196
197
  globalGroup?: boolean;