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
|
/**
|
|
3
2
|
* These objects store the data about the DOM nodes we create, as well as some
|
|
4
3
|
* extra data. They can then be transformed into real DOM nodes with the
|
|
@@ -21,7 +20,6 @@ import ParseError from "./ParseError";
|
|
|
21
20
|
|
|
22
21
|
import type {VirtualNode} from "./tree";
|
|
23
22
|
|
|
24
|
-
|
|
25
23
|
/**
|
|
26
24
|
* Create an HTML className based on a list of classes. In addition to joining
|
|
27
25
|
* with spaces, we also remove empty classes.
|
|
@@ -30,7 +28,21 @@ export const createClass = function(classes: string[]): string {
|
|
|
30
28
|
return classes.filter(cls => cls).join(" ");
|
|
31
29
|
};
|
|
32
30
|
|
|
31
|
+
type InitNodeData = {
|
|
32
|
+
classes: string[];
|
|
33
|
+
attributes: Record<string, string>;
|
|
34
|
+
height: number;
|
|
35
|
+
depth: number;
|
|
36
|
+
maxFontSize: number;
|
|
37
|
+
style: CssStyle;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type HtmlNodeData = InitNodeData & {
|
|
41
|
+
children: VirtualNode[];
|
|
42
|
+
};
|
|
43
|
+
|
|
33
44
|
const initNode = function(
|
|
45
|
+
this: InitNodeData,
|
|
34
46
|
classes?: string[],
|
|
35
47
|
options?: Options,
|
|
36
48
|
style?: CssStyle,
|
|
@@ -55,25 +67,20 @@ const initNode = function(
|
|
|
55
67
|
/**
|
|
56
68
|
* Convert into an HTML node
|
|
57
69
|
*/
|
|
58
|
-
const toNode = function(tagName: string): HTMLElement {
|
|
70
|
+
const toNode = function(this: HtmlNodeData, tagName: string): HTMLElement {
|
|
59
71
|
const node = document.createElement(tagName);
|
|
60
72
|
|
|
61
73
|
// Apply the class
|
|
62
74
|
node.className = createClass(this.classes);
|
|
63
75
|
|
|
64
76
|
// Apply inline styles
|
|
65
|
-
for (const
|
|
66
|
-
|
|
67
|
-
// $FlowFixMe Flow doesn't seem to understand span.style's type.
|
|
68
|
-
node.style[style] = this.style[style];
|
|
69
|
-
}
|
|
77
|
+
for (const key of Object.keys(this.style) as Array<keyof CssStyle>) {
|
|
78
|
+
(node.style as any)[key] = this.style[key];
|
|
70
79
|
}
|
|
71
80
|
|
|
72
81
|
// Apply attributes
|
|
73
|
-
for (const attr
|
|
74
|
-
|
|
75
|
-
node.setAttribute(attr, this.attributes[attr]);
|
|
76
|
-
}
|
|
82
|
+
for (const attr of Object.keys(this.attributes)) {
|
|
83
|
+
node.setAttribute(attr, this.attributes[attr]);
|
|
77
84
|
}
|
|
78
85
|
|
|
79
86
|
// Append the children, also as HTML nodes
|
|
@@ -97,7 +104,7 @@ const invalidAttributeNameRegex = /[\s"'>/=\x00-\x1f]/;
|
|
|
97
104
|
/**
|
|
98
105
|
* Convert into an HTML markup string
|
|
99
106
|
*/
|
|
100
|
-
const toMarkup = function(tagName: string): string {
|
|
107
|
+
const toMarkup = function(this: HtmlNodeData, tagName: string): string {
|
|
101
108
|
let markup = `<${tagName}`;
|
|
102
109
|
|
|
103
110
|
// Add the class
|
|
@@ -108,10 +115,8 @@ const toMarkup = function(tagName: string): string {
|
|
|
108
115
|
let styles = "";
|
|
109
116
|
|
|
110
117
|
// Add the styles, after hyphenation
|
|
111
|
-
for (const
|
|
112
|
-
|
|
113
|
-
styles += `${hyphenate(style)}:${this.style[style]};`;
|
|
114
|
-
}
|
|
118
|
+
for (const key of Object.keys(this.style) as Array<keyof CssStyle>) {
|
|
119
|
+
styles += `${hyphenate(key)}:${this.style[key]};`;
|
|
115
120
|
}
|
|
116
121
|
|
|
117
122
|
if (styles) {
|
|
@@ -119,13 +124,11 @@ const toMarkup = function(tagName: string): string {
|
|
|
119
124
|
}
|
|
120
125
|
|
|
121
126
|
// Add the attributes
|
|
122
|
-
for (const attr
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
throw new ParseError(`Invalid attribute name '${attr}'`);
|
|
126
|
-
}
|
|
127
|
-
markup += ` ${attr}="${escape(this.attributes[attr])}"`;
|
|
127
|
+
for (const attr of Object.keys(this.attributes)) {
|
|
128
|
+
if (invalidAttributeNameRegex.test(attr)) {
|
|
129
|
+
throw new ParseError(`Invalid attribute name '${attr}'`);
|
|
128
130
|
}
|
|
131
|
+
markup += ` ${attr}="${escape(this.attributes[attr])}"`;
|
|
129
132
|
}
|
|
130
133
|
|
|
131
134
|
markup += ">";
|
|
@@ -147,30 +150,30 @@ const toMarkup = function(tagName: string): string {
|
|
|
147
150
|
// above.
|
|
148
151
|
// This type does not include all CSS properties. Additional properties should
|
|
149
152
|
// be added as needed.
|
|
150
|
-
export type CssStyle =
|
|
151
|
-
backgroundColor: string
|
|
152
|
-
borderBottomWidth: string
|
|
153
|
-
borderColor: string
|
|
154
|
-
borderRightStyle: string
|
|
155
|
-
borderRightWidth: string
|
|
156
|
-
borderTopWidth: string
|
|
153
|
+
export type CssStyle = Partial<{
|
|
154
|
+
backgroundColor: string;
|
|
155
|
+
borderBottomWidth: string;
|
|
156
|
+
borderColor: string;
|
|
157
|
+
borderRightStyle: string;
|
|
158
|
+
borderRightWidth: string;
|
|
159
|
+
borderTopWidth: string;
|
|
157
160
|
borderStyle: string;
|
|
158
|
-
borderWidth: string
|
|
159
|
-
bottom: string
|
|
160
|
-
color: string
|
|
161
|
-
height: string
|
|
162
|
-
left: string
|
|
163
|
-
margin: string
|
|
164
|
-
marginLeft: string
|
|
165
|
-
marginRight: string
|
|
166
|
-
marginTop: string
|
|
167
|
-
minWidth: string
|
|
168
|
-
paddingLeft: string
|
|
169
|
-
position: string
|
|
170
|
-
textShadow: string
|
|
171
|
-
top: string
|
|
172
|
-
width: string
|
|
173
|
-
verticalAlign: string
|
|
161
|
+
borderWidth: string;
|
|
162
|
+
bottom: string;
|
|
163
|
+
color: string;
|
|
164
|
+
height: string;
|
|
165
|
+
left: string;
|
|
166
|
+
margin: string;
|
|
167
|
+
marginLeft: string;
|
|
168
|
+
marginRight: string;
|
|
169
|
+
marginTop: string;
|
|
170
|
+
minWidth: string;
|
|
171
|
+
paddingLeft: string;
|
|
172
|
+
position: string;
|
|
173
|
+
textShadow: string;
|
|
174
|
+
top: string;
|
|
175
|
+
width: string;
|
|
176
|
+
verticalAlign: string;
|
|
174
177
|
}> & {};
|
|
175
178
|
|
|
176
179
|
export interface HtmlDomNode extends VirtualNode {
|
|
@@ -179,7 +182,6 @@ export interface HtmlDomNode extends VirtualNode {
|
|
|
179
182
|
depth: number;
|
|
180
183
|
maxFontSize: number;
|
|
181
184
|
style: CssStyle;
|
|
182
|
-
|
|
183
185
|
hasClass(className: string): boolean;
|
|
184
186
|
}
|
|
185
187
|
|
|
@@ -191,7 +193,6 @@ export type SvgSpan = Span<SvgNode>;
|
|
|
191
193
|
export type SvgChildNode = PathNode | LineNode;
|
|
192
194
|
export type documentFragment = DocumentFragment<HtmlDomNode>;
|
|
193
195
|
|
|
194
|
-
|
|
195
196
|
/**
|
|
196
197
|
* This node represents a span node, with a className, a list of children, and
|
|
197
198
|
* an inline style. It also contains information about its height, depth, and
|
|
@@ -201,15 +202,15 @@ export type documentFragment = DocumentFragment<HtmlDomNode>;
|
|
|
201
202
|
* otherwise. This typesafety is important when HTML builders access a span's
|
|
202
203
|
* children.
|
|
203
204
|
*/
|
|
204
|
-
export class Span<ChildType
|
|
205
|
+
export class Span<ChildType extends VirtualNode> implements HtmlDomNode {
|
|
205
206
|
children: ChildType[];
|
|
206
|
-
attributes
|
|
207
|
-
classes
|
|
208
|
-
height
|
|
209
|
-
depth
|
|
210
|
-
width:
|
|
211
|
-
maxFontSize
|
|
212
|
-
style
|
|
207
|
+
attributes!: Record<string, string>;
|
|
208
|
+
classes!: string[];
|
|
209
|
+
height!: number;
|
|
210
|
+
depth!: number;
|
|
211
|
+
width: number | null | undefined;
|
|
212
|
+
maxFontSize!: number;
|
|
213
|
+
style!: CssStyle;
|
|
213
214
|
|
|
214
215
|
constructor(
|
|
215
216
|
classes?: string[],
|
|
@@ -249,12 +250,12 @@ export class Span<ChildType: VirtualNode> implements HtmlDomNode {
|
|
|
249
250
|
*/
|
|
250
251
|
export class Anchor implements HtmlDomNode {
|
|
251
252
|
children: HtmlDomNode[];
|
|
252
|
-
attributes
|
|
253
|
-
classes
|
|
254
|
-
height
|
|
255
|
-
depth
|
|
256
|
-
maxFontSize
|
|
257
|
-
style
|
|
253
|
+
attributes!: Record<string, string>;
|
|
254
|
+
classes!: string[];
|
|
255
|
+
height!: number;
|
|
256
|
+
depth!: number;
|
|
257
|
+
maxFontSize!: number;
|
|
258
|
+
style!: CssStyle;
|
|
258
259
|
|
|
259
260
|
constructor(
|
|
260
261
|
href: string,
|
|
@@ -304,6 +305,9 @@ export class Img implements VirtualNode {
|
|
|
304
305
|
this.alt = alt;
|
|
305
306
|
this.src = src;
|
|
306
307
|
this.classes = ["mord"];
|
|
308
|
+
this.height = 0;
|
|
309
|
+
this.depth = 0;
|
|
310
|
+
this.maxFontSize = 0;
|
|
307
311
|
this.style = style;
|
|
308
312
|
}
|
|
309
313
|
|
|
@@ -318,11 +322,8 @@ export class Img implements VirtualNode {
|
|
|
318
322
|
node.className = "mord";
|
|
319
323
|
|
|
320
324
|
// Apply inline styles
|
|
321
|
-
for (const
|
|
322
|
-
|
|
323
|
-
// $FlowFixMe
|
|
324
|
-
node.style[style] = this.style[style];
|
|
325
|
-
}
|
|
325
|
+
for (const key of Object.keys(this.style) as Array<keyof CssStyle>) {
|
|
326
|
+
(node.style as any)[key] = this.style[key];
|
|
326
327
|
}
|
|
327
328
|
|
|
328
329
|
return node;
|
|
@@ -334,10 +335,8 @@ export class Img implements VirtualNode {
|
|
|
334
335
|
|
|
335
336
|
// Add the styles, after hyphenation
|
|
336
337
|
let styles = "";
|
|
337
|
-
for (const
|
|
338
|
-
|
|
339
|
-
styles += `${hyphenate(style)}:${this.style[style]};`;
|
|
340
|
-
}
|
|
338
|
+
for (const key of Object.keys(this.style) as Array<keyof CssStyle>) {
|
|
339
|
+
styles += `${hyphenate(key)}:${this.style[key]};`;
|
|
341
340
|
}
|
|
342
341
|
if (styles) {
|
|
343
342
|
markup += ` style="${escape(styles)}"`;
|
|
@@ -348,7 +347,7 @@ export class Img implements VirtualNode {
|
|
|
348
347
|
}
|
|
349
348
|
}
|
|
350
349
|
|
|
351
|
-
const iCombinations = {
|
|
350
|
+
const iCombinations: Record<string, string> = {
|
|
352
351
|
'î': '\u0131\u0302',
|
|
353
352
|
'ï': '\u0131\u0308',
|
|
354
353
|
'í': '\u0131\u0301',
|
|
@@ -431,12 +430,9 @@ export class SymbolNode implements HtmlDomNode {
|
|
|
431
430
|
span.className = createClass(this.classes);
|
|
432
431
|
}
|
|
433
432
|
|
|
434
|
-
for (const
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
// $FlowFixMe Flow doesn't seem to understand span.style's type.
|
|
438
|
-
span.style[style] = this.style[style];
|
|
439
|
-
}
|
|
433
|
+
for (const key of Object.keys(this.style) as Array<keyof CssStyle>) {
|
|
434
|
+
span = span || document.createElement("span");
|
|
435
|
+
(span.style as any)[key] = this.style[key];
|
|
440
436
|
}
|
|
441
437
|
|
|
442
438
|
if (span) {
|
|
@@ -469,10 +465,8 @@ export class SymbolNode implements HtmlDomNode {
|
|
|
469
465
|
if (this.italic > 0) {
|
|
470
466
|
styles += "margin-right:" + this.italic + "em;";
|
|
471
467
|
}
|
|
472
|
-
for (const
|
|
473
|
-
|
|
474
|
-
styles += hyphenate(style) + ":" + this.style[style] + ";";
|
|
475
|
-
}
|
|
468
|
+
for (const key of Object.keys(this.style) as Array<keyof CssStyle>) {
|
|
469
|
+
styles += hyphenate(key) + ":" + this.style[key] + ";";
|
|
476
470
|
}
|
|
477
471
|
|
|
478
472
|
if (styles) {
|
|
@@ -497,9 +491,12 @@ export class SymbolNode implements HtmlDomNode {
|
|
|
497
491
|
*/
|
|
498
492
|
export class SvgNode implements VirtualNode {
|
|
499
493
|
children: SvgChildNode[];
|
|
500
|
-
attributes:
|
|
494
|
+
attributes: Record<string, string>;
|
|
501
495
|
|
|
502
|
-
constructor(
|
|
496
|
+
constructor(
|
|
497
|
+
children?: SvgChildNode[],
|
|
498
|
+
attributes?: Record<string, string>,
|
|
499
|
+
) {
|
|
503
500
|
this.children = children || [];
|
|
504
501
|
this.attributes = attributes || {};
|
|
505
502
|
}
|
|
@@ -509,10 +506,8 @@ export class SvgNode implements VirtualNode {
|
|
|
509
506
|
const node = document.createElementNS(svgNS, "svg");
|
|
510
507
|
|
|
511
508
|
// Apply attributes
|
|
512
|
-
for (const attr
|
|
513
|
-
|
|
514
|
-
node.setAttribute(attr, this.attributes[attr]);
|
|
515
|
-
}
|
|
509
|
+
for (const attr of Object.keys(this.attributes)) {
|
|
510
|
+
node.setAttribute(attr, this.attributes[attr]);
|
|
516
511
|
}
|
|
517
512
|
|
|
518
513
|
for (let i = 0; i < this.children.length; i++) {
|
|
@@ -525,10 +520,8 @@ export class SvgNode implements VirtualNode {
|
|
|
525
520
|
let markup = `<svg xmlns="http://www.w3.org/2000/svg"`;
|
|
526
521
|
|
|
527
522
|
// Apply attributes
|
|
528
|
-
for (const attr
|
|
529
|
-
|
|
530
|
-
markup += ` ${attr}="${escape(this.attributes[attr])}"`;
|
|
531
|
-
}
|
|
523
|
+
for (const attr of Object.keys(this.attributes)) {
|
|
524
|
+
markup += ` ${attr}="${escape(this.attributes[attr])}"`;
|
|
532
525
|
}
|
|
533
526
|
|
|
534
527
|
markup += ">";
|
|
@@ -546,7 +539,7 @@ export class SvgNode implements VirtualNode {
|
|
|
546
539
|
|
|
547
540
|
export class PathNode implements VirtualNode {
|
|
548
541
|
pathName: string;
|
|
549
|
-
alternate:
|
|
542
|
+
alternate: string | null | undefined;
|
|
550
543
|
|
|
551
544
|
constructor(pathName: string, alternate?: string) {
|
|
552
545
|
this.pathName = pathName;
|
|
@@ -576,9 +569,11 @@ export class PathNode implements VirtualNode {
|
|
|
576
569
|
}
|
|
577
570
|
|
|
578
571
|
export class LineNode implements VirtualNode {
|
|
579
|
-
attributes:
|
|
572
|
+
attributes: Record<string, string>;
|
|
580
573
|
|
|
581
|
-
constructor(
|
|
574
|
+
constructor(
|
|
575
|
+
attributes?: Record<string, string>,
|
|
576
|
+
) {
|
|
582
577
|
this.attributes = attributes || {};
|
|
583
578
|
}
|
|
584
579
|
|
|
@@ -587,10 +582,8 @@ export class LineNode implements VirtualNode {
|
|
|
587
582
|
const node = document.createElementNS(svgNS, "line");
|
|
588
583
|
|
|
589
584
|
// Apply attributes
|
|
590
|
-
for (const attr
|
|
591
|
-
|
|
592
|
-
node.setAttribute(attr, this.attributes[attr]);
|
|
593
|
-
}
|
|
585
|
+
for (const attr of Object.keys(this.attributes)) {
|
|
586
|
+
node.setAttribute(attr, this.attributes[attr]);
|
|
594
587
|
}
|
|
595
588
|
|
|
596
589
|
return node;
|
|
@@ -599,10 +592,8 @@ export class LineNode implements VirtualNode {
|
|
|
599
592
|
toMarkup(): string {
|
|
600
593
|
let markup = "<line";
|
|
601
594
|
|
|
602
|
-
for (const attr
|
|
603
|
-
|
|
604
|
-
markup += ` ${attr}="${escape(this.attributes[attr])}"`;
|
|
605
|
-
}
|
|
595
|
+
for (const attr of Object.keys(this.attributes)) {
|
|
596
|
+
markup += ` ${attr}="${escape(this.attributes[attr])}"`;
|
|
606
597
|
}
|
|
607
598
|
|
|
608
599
|
markup += "/>";
|