temml 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -0
  3. package/contrib/auto-render/README.md +89 -0
  4. package/contrib/auto-render/auto-render.js +128 -0
  5. package/contrib/auto-render/dist/auto-render.js +217 -0
  6. package/contrib/auto-render/dist/auto-render.min.js +1 -0
  7. package/contrib/auto-render/splitAtDelimiters.js +84 -0
  8. package/contrib/auto-render/test/auto-render-spec.js +234 -0
  9. package/contrib/auto-render/test/auto-render.js +217 -0
  10. package/contrib/auto-render/test/test_page.html +59 -0
  11. package/contrib/mhchem/README.md +26 -0
  12. package/contrib/mhchem/mhchem.js +1705 -0
  13. package/contrib/mhchem/mhchem.min.js +1 -0
  14. package/contrib/physics/README.md +20 -0
  15. package/contrib/physics/physics.js +131 -0
  16. package/contrib/texvc/README.md +23 -0
  17. package/contrib/texvc/texvc.js +61 -0
  18. package/dist/Temml-Asana.css +201 -0
  19. package/dist/Temml-Latin-Modern.css +216 -0
  20. package/dist/Temml-Libertinus.css +214 -0
  21. package/dist/Temml-Local.css +194 -0
  22. package/dist/Temml-STIX2.css +203 -0
  23. package/dist/Temml.woff2 +0 -0
  24. package/dist/temml.cjs +13122 -0
  25. package/dist/temml.js +11225 -0
  26. package/dist/temml.min.js +1 -0
  27. package/dist/temml.mjs +13120 -0
  28. package/dist/temmlPostProcess.js +70 -0
  29. package/package.json +34 -0
  30. package/src/Lexer.js +121 -0
  31. package/src/MacroExpander.js +437 -0
  32. package/src/Namespace.js +107 -0
  33. package/src/ParseError.js +64 -0
  34. package/src/Parser.js +977 -0
  35. package/src/Settings.js +49 -0
  36. package/src/SourceLocation.js +29 -0
  37. package/src/Style.js +144 -0
  38. package/src/Token.js +40 -0
  39. package/src/buildMathML.js +235 -0
  40. package/src/constants.js +25 -0
  41. package/src/defineEnvironment.js +25 -0
  42. package/src/defineFunction.js +69 -0
  43. package/src/defineMacro.js +11 -0
  44. package/src/domTree.js +185 -0
  45. package/src/environments/array.js +791 -0
  46. package/src/environments/cd.js +252 -0
  47. package/src/environments.js +8 -0
  48. package/src/functions/accent.js +127 -0
  49. package/src/functions/accentunder.js +38 -0
  50. package/src/functions/arrow.js +204 -0
  51. package/src/functions/cancelto.js +36 -0
  52. package/src/functions/char.js +33 -0
  53. package/src/functions/color.js +253 -0
  54. package/src/functions/cr.js +46 -0
  55. package/src/functions/def.js +259 -0
  56. package/src/functions/delimsizing.js +304 -0
  57. package/src/functions/enclose.js +193 -0
  58. package/src/functions/envTag.js +38 -0
  59. package/src/functions/environment.js +59 -0
  60. package/src/functions/font.js +123 -0
  61. package/src/functions/genfrac.js +333 -0
  62. package/src/functions/hbox.js +29 -0
  63. package/src/functions/horizBrace.js +32 -0
  64. package/src/functions/href.js +90 -0
  65. package/src/functions/html.js +95 -0
  66. package/src/functions/includegraphics.js +131 -0
  67. package/src/functions/kern.js +75 -0
  68. package/src/functions/label.js +29 -0
  69. package/src/functions/lap.js +75 -0
  70. package/src/functions/math.js +40 -0
  71. package/src/functions/mathchoice.js +41 -0
  72. package/src/functions/mclass.js +201 -0
  73. package/src/functions/multiscript.js +91 -0
  74. package/src/functions/not.js +46 -0
  75. package/src/functions/op.js +338 -0
  76. package/src/functions/operatorname.js +139 -0
  77. package/src/functions/ordgroup.js +9 -0
  78. package/src/functions/phantom.js +73 -0
  79. package/src/functions/pmb.js +31 -0
  80. package/src/functions/raise.js +68 -0
  81. package/src/functions/ref.js +28 -0
  82. package/src/functions/relax.js +16 -0
  83. package/src/functions/rule.js +52 -0
  84. package/src/functions/sizing.js +64 -0
  85. package/src/functions/smash.js +66 -0
  86. package/src/functions/sqrt.js +31 -0
  87. package/src/functions/styling.js +58 -0
  88. package/src/functions/supsub.js +135 -0
  89. package/src/functions/symbolsOp.js +53 -0
  90. package/src/functions/symbolsOrd.js +102 -0
  91. package/src/functions/symbolsSpacing.js +53 -0
  92. package/src/functions/tag.js +8 -0
  93. package/src/functions/text.js +75 -0
  94. package/src/functions/tip.js +63 -0
  95. package/src/functions/toggle.js +13 -0
  96. package/src/functions/verb.js +33 -0
  97. package/src/functions.js +57 -0
  98. package/src/linebreaking.js +159 -0
  99. package/src/macros.js +708 -0
  100. package/src/mathMLTree.js +175 -0
  101. package/src/parseNode.js +42 -0
  102. package/src/parseTree.js +40 -0
  103. package/src/postProcess.js +57 -0
  104. package/src/replace.js +225 -0
  105. package/src/stretchy.js +66 -0
  106. package/src/svg.js +110 -0
  107. package/src/symbols.js +972 -0
  108. package/src/tree.js +50 -0
  109. package/src/unicodeAccents.js +16 -0
  110. package/src/unicodeScripts.js +119 -0
  111. package/src/unicodeSupOrSub.js +108 -0
  112. package/src/unicodeSymbolBuilder.js +31 -0
  113. package/src/unicodeSymbols.js +320 -0
  114. package/src/units.js +109 -0
  115. package/src/utils.js +109 -0
  116. package/src/variant.js +103 -0
  117. package/temml.js +181 -0
package/src/domTree.js ADDED
@@ -0,0 +1,185 @@
1
+ /**
2
+ * These objects store the data about the DOM nodes we create, as well as some
3
+ * extra data. They can then be transformed into real DOM nodes with the
4
+ * `toNode` function or HTML markup using `toMarkup`. They are useful for both
5
+ * storing extra properties on the nodes, as well as providing a way to easily
6
+ * work with the DOM.
7
+ *
8
+ * Similar functions for working with MathML nodes exist in mathMLTree.js.
9
+ *
10
+ */
11
+ import utils from "./utils";
12
+
13
+ /**
14
+ * Create an HTML className based on a list of classes. In addition to joining
15
+ * with spaces, we also remove empty classes.
16
+ */
17
+ export const createClass = function(classes) {
18
+ return classes.filter((cls) => cls).join(" ");
19
+ };
20
+
21
+ const initNode = function(classes, style) {
22
+ this.classes = classes || [];
23
+ this.attributes = {};
24
+ this.style = style || {};
25
+ };
26
+
27
+ /**
28
+ * Convert into an HTML node
29
+ */
30
+ const toNode = function(tagName) {
31
+ const node = document.createElement(tagName);
32
+
33
+ // Apply the class
34
+ node.className = createClass(this.classes);
35
+
36
+ // Apply inline styles
37
+ for (const style in this.style) {
38
+ if (Object.prototype.hasOwnProperty.call(this.style, style )) {
39
+ node.style[style] = this.style[style];
40
+ }
41
+ }
42
+
43
+ // Apply attributes
44
+ for (const attr in this.attributes) {
45
+ if (Object.prototype.hasOwnProperty.call(this.attributes, attr )) {
46
+ node.setAttribute(attr, this.attributes[attr]);
47
+ }
48
+ }
49
+
50
+ // Append the children, also as HTML nodes
51
+ for (let i = 0; i < this.children.length; i++) {
52
+ node.appendChild(this.children[i].toNode());
53
+ }
54
+
55
+ return node;
56
+ };
57
+
58
+ /**
59
+ * Convert into an HTML markup string
60
+ */
61
+ const toMarkup = function(tagName) {
62
+ let markup = `<${tagName}`;
63
+
64
+ // Add the class
65
+ if (this.classes.length) {
66
+ markup += ` class="${utils.escape(createClass(this.classes))}"`;
67
+ }
68
+
69
+ let styles = "";
70
+
71
+ // Add the styles, after hyphenation
72
+ for (const style in this.style) {
73
+ if (Object.prototype.hasOwnProperty.call(this.style, style )) {
74
+ styles += `${utils.hyphenate(style)}:${this.style[style]};`;
75
+ }
76
+ }
77
+
78
+ if (styles) {
79
+ markup += ` style="${styles}"`;
80
+ }
81
+
82
+ // Add the attributes
83
+ for (const attr in this.attributes) {
84
+ if (Object.prototype.hasOwnProperty.call(this.attributes, attr )) {
85
+ markup += ` ${attr}="${utils.escape(this.attributes[attr])}"`;
86
+ }
87
+ }
88
+
89
+ markup += ">";
90
+
91
+ // Add the markup of the children, also as markup
92
+ for (let i = 0; i < this.children.length; i++) {
93
+ markup += this.children[i].toMarkup();
94
+ }
95
+
96
+ markup += `</${tagName}>`;
97
+
98
+ return markup;
99
+ };
100
+
101
+ /**
102
+ * This node represents a span node, with a className, a list of children, and
103
+ * an inline style.
104
+ *
105
+ */
106
+ export class Span {
107
+ constructor(classes, children, style) {
108
+ initNode.call(this, classes, style);
109
+ this.children = children || [];
110
+ }
111
+
112
+ setAttribute(attribute, value) {
113
+ this.attributes[attribute] = value;
114
+ }
115
+
116
+ toNode() {
117
+ return toNode.call(this, "span");
118
+ }
119
+
120
+ toMarkup() {
121
+ return toMarkup.call(this, "span");
122
+ }
123
+ }
124
+
125
+ export class TextNode {
126
+ constructor(text) {
127
+ this.text = text;
128
+ }
129
+ toNode() {
130
+ return document.createTextNode(this.text);
131
+ }
132
+ toMarkup() {
133
+ return utils.escape(this.text);
134
+ }
135
+ }
136
+
137
+ /**
138
+ * This node represents an image embed (<img>) element.
139
+ */
140
+ export class Img {
141
+ constructor(src, alt, style) {
142
+ this.alt = alt;
143
+ this.src = src;
144
+ this.classes = ["mord"];
145
+ this.style = style;
146
+ }
147
+
148
+ hasClass(className) {
149
+ return this.classes.includes(className);
150
+ }
151
+
152
+ toNode() {
153
+ const node = document.createElement("img");
154
+ node.src = this.src;
155
+ node.alt = this.alt;
156
+ node.className = "mord";
157
+
158
+ // Apply inline styles
159
+ for (const style in this.style) {
160
+ if (Object.prototype.hasOwnProperty.call(this.style, style )) {
161
+ node.style[style] = this.style[style];
162
+ }
163
+ }
164
+
165
+ return node;
166
+ }
167
+
168
+ toMarkup() {
169
+ let markup = `<img src='${this.src}' alt='${this.alt}'`;
170
+
171
+ // Add the styles, after hyphenation
172
+ let styles = "";
173
+ for (const style in this.style) {
174
+ if (Object.prototype.hasOwnProperty.call(this.style, style )) {
175
+ styles += `${utils.hyphenate(style)}:${this.style[style]};`;
176
+ }
177
+ }
178
+ if (styles) {
179
+ markup += ` style="${utils.escape(styles)}"`;
180
+ }
181
+
182
+ markup += "/>";
183
+ return markup;
184
+ }
185
+ }