MmlNode.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. var __assign = (this && this.__assign) || function () {
  18. __assign = Object.assign || function(t) {
  19. for (var s, i = 1, n = arguments.length; i < n; i++) {
  20. s = arguments[i];
  21. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  22. t[p] = s[p];
  23. }
  24. return t;
  25. };
  26. return __assign.apply(this, arguments);
  27. };
  28. var __values = (this && this.__values) || function(o) {
  29. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  30. if (m) return m.call(o);
  31. if (o && typeof o.length === "number") return {
  32. next: function () {
  33. if (o && i >= o.length) o = void 0;
  34. return { value: o && o[i++], done: !o };
  35. }
  36. };
  37. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  38. };
  39. var __read = (this && this.__read) || function (o, n) {
  40. var m = typeof Symbol === "function" && o[Symbol.iterator];
  41. if (!m) return o;
  42. var i = m.call(o), r, ar = [], e;
  43. try {
  44. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  45. }
  46. catch (error) { e = { error: error }; }
  47. finally {
  48. try {
  49. if (r && !r.done && (m = i["return"])) m.call(i);
  50. }
  51. finally { if (e) throw e.error; }
  52. }
  53. return ar;
  54. };
  55. Object.defineProperty(exports, "__esModule", { value: true });
  56. exports.XMLNode = exports.TextNode = exports.AbstractMmlEmptyNode = exports.AbstractMmlBaseNode = exports.AbstractMmlLayoutNode = exports.AbstractMmlTokenNode = exports.AbstractMmlNode = exports.indentAttributes = exports.TEXCLASSNAMES = exports.TEXCLASS = void 0;
  57. var Attributes_js_1 = require("./Attributes.js");
  58. var Node_js_1 = require("../Tree/Node.js");
  59. exports.TEXCLASS = {
  60. ORD: 0,
  61. OP: 1,
  62. BIN: 2,
  63. REL: 3,
  64. OPEN: 4,
  65. CLOSE: 5,
  66. PUNCT: 6,
  67. INNER: 7,
  68. VCENTER: 8,
  69. NONE: -1
  70. };
  71. exports.TEXCLASSNAMES = ['ORD', 'OP', 'BIN', 'REL', 'OPEN', 'CLOSE', 'PUNCT', 'INNER', 'VCENTER'];
  72. var TEXSPACELENGTH = ['', 'thinmathspace', 'mediummathspace', 'thickmathspace'];
  73. var TEXSPACE = [
  74. [0, -1, 2, 3, 0, 0, 0, 1],
  75. [-1, -1, 0, 3, 0, 0, 0, 1],
  76. [2, 2, 0, 0, 2, 0, 0, 2],
  77. [3, 3, 0, 0, 3, 0, 0, 3],
  78. [0, 0, 0, 0, 0, 0, 0, 0],
  79. [0, -1, 2, 3, 0, 0, 0, 1],
  80. [1, 1, 0, 1, 1, 1, 1, 1],
  81. [1, -1, 2, 3, 1, 0, 1, 1]
  82. ];
  83. exports.indentAttributes = [
  84. 'indentalign', 'indentalignfirst',
  85. 'indentshift', 'indentshiftfirst'
  86. ];
  87. var AbstractMmlNode = (function (_super) {
  88. __extends(AbstractMmlNode, _super);
  89. function AbstractMmlNode(factory, attributes, children) {
  90. if (attributes === void 0) { attributes = {}; }
  91. if (children === void 0) { children = []; }
  92. var _this = _super.call(this, factory) || this;
  93. _this.prevClass = null;
  94. _this.prevLevel = null;
  95. _this.texclass = null;
  96. if (_this.arity < 0) {
  97. _this.childNodes = [factory.create('inferredMrow')];
  98. _this.childNodes[0].parent = _this;
  99. }
  100. _this.setChildren(children);
  101. _this.attributes = new Attributes_js_1.Attributes(factory.getNodeClass(_this.kind).defaults, factory.getNodeClass('math').defaults);
  102. _this.attributes.setList(attributes);
  103. return _this;
  104. }
  105. AbstractMmlNode.prototype.copy = function (keepIds) {
  106. var e_1, _a, e_2, _b;
  107. if (keepIds === void 0) { keepIds = false; }
  108. var node = this.factory.create(this.kind);
  109. node.properties = __assign({}, this.properties);
  110. if (this.attributes) {
  111. var attributes = this.attributes.getAllAttributes();
  112. try {
  113. for (var _c = __values(Object.keys(attributes)), _d = _c.next(); !_d.done; _d = _c.next()) {
  114. var name_1 = _d.value;
  115. if (name_1 !== 'id' || keepIds) {
  116. node.attributes.set(name_1, attributes[name_1]);
  117. }
  118. }
  119. }
  120. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  121. finally {
  122. try {
  123. if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
  124. }
  125. finally { if (e_1) throw e_1.error; }
  126. }
  127. }
  128. if (this.childNodes && this.childNodes.length) {
  129. var children = this.childNodes;
  130. if (children.length === 1 && children[0].isInferred) {
  131. children = children[0].childNodes;
  132. }
  133. try {
  134. for (var children_1 = __values(children), children_1_1 = children_1.next(); !children_1_1.done; children_1_1 = children_1.next()) {
  135. var child = children_1_1.value;
  136. if (child) {
  137. node.appendChild(child.copy());
  138. }
  139. else {
  140. node.childNodes.push(null);
  141. }
  142. }
  143. }
  144. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  145. finally {
  146. try {
  147. if (children_1_1 && !children_1_1.done && (_b = children_1.return)) _b.call(children_1);
  148. }
  149. finally { if (e_2) throw e_2.error; }
  150. }
  151. }
  152. return node;
  153. };
  154. Object.defineProperty(AbstractMmlNode.prototype, "texClass", {
  155. get: function () {
  156. return this.texclass;
  157. },
  158. set: function (texClass) {
  159. this.texclass = texClass;
  160. },
  161. enumerable: false,
  162. configurable: true
  163. });
  164. Object.defineProperty(AbstractMmlNode.prototype, "isToken", {
  165. get: function () {
  166. return false;
  167. },
  168. enumerable: false,
  169. configurable: true
  170. });
  171. Object.defineProperty(AbstractMmlNode.prototype, "isEmbellished", {
  172. get: function () {
  173. return false;
  174. },
  175. enumerable: false,
  176. configurable: true
  177. });
  178. Object.defineProperty(AbstractMmlNode.prototype, "isSpacelike", {
  179. get: function () {
  180. return false;
  181. },
  182. enumerable: false,
  183. configurable: true
  184. });
  185. Object.defineProperty(AbstractMmlNode.prototype, "linebreakContainer", {
  186. get: function () {
  187. return false;
  188. },
  189. enumerable: false,
  190. configurable: true
  191. });
  192. Object.defineProperty(AbstractMmlNode.prototype, "hasNewLine", {
  193. get: function () {
  194. return false;
  195. },
  196. enumerable: false,
  197. configurable: true
  198. });
  199. Object.defineProperty(AbstractMmlNode.prototype, "arity", {
  200. get: function () {
  201. return Infinity;
  202. },
  203. enumerable: false,
  204. configurable: true
  205. });
  206. Object.defineProperty(AbstractMmlNode.prototype, "isInferred", {
  207. get: function () {
  208. return false;
  209. },
  210. enumerable: false,
  211. configurable: true
  212. });
  213. Object.defineProperty(AbstractMmlNode.prototype, "Parent", {
  214. get: function () {
  215. var parent = this.parent;
  216. while (parent && parent.notParent) {
  217. parent = parent.Parent;
  218. }
  219. return parent;
  220. },
  221. enumerable: false,
  222. configurable: true
  223. });
  224. Object.defineProperty(AbstractMmlNode.prototype, "notParent", {
  225. get: function () {
  226. return false;
  227. },
  228. enumerable: false,
  229. configurable: true
  230. });
  231. AbstractMmlNode.prototype.setChildren = function (children) {
  232. if (this.arity < 0) {
  233. return this.childNodes[0].setChildren(children);
  234. }
  235. return _super.prototype.setChildren.call(this, children);
  236. };
  237. AbstractMmlNode.prototype.appendChild = function (child) {
  238. var e_3, _a;
  239. var _this = this;
  240. if (this.arity < 0) {
  241. this.childNodes[0].appendChild(child);
  242. return child;
  243. }
  244. if (child.isInferred) {
  245. if (this.arity === Infinity) {
  246. child.childNodes.forEach(function (node) { return _super.prototype.appendChild.call(_this, node); });
  247. return child;
  248. }
  249. var original = child;
  250. child = this.factory.create('mrow');
  251. child.setChildren(original.childNodes);
  252. child.attributes = original.attributes;
  253. try {
  254. for (var _b = __values(original.getPropertyNames()), _c = _b.next(); !_c.done; _c = _b.next()) {
  255. var name_2 = _c.value;
  256. child.setProperty(name_2, original.getProperty(name_2));
  257. }
  258. }
  259. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  260. finally {
  261. try {
  262. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  263. }
  264. finally { if (e_3) throw e_3.error; }
  265. }
  266. }
  267. return _super.prototype.appendChild.call(this, child);
  268. };
  269. AbstractMmlNode.prototype.replaceChild = function (newChild, oldChild) {
  270. if (this.arity < 0) {
  271. this.childNodes[0].replaceChild(newChild, oldChild);
  272. return newChild;
  273. }
  274. return _super.prototype.replaceChild.call(this, newChild, oldChild);
  275. };
  276. AbstractMmlNode.prototype.core = function () {
  277. return this;
  278. };
  279. AbstractMmlNode.prototype.coreMO = function () {
  280. return this;
  281. };
  282. AbstractMmlNode.prototype.coreIndex = function () {
  283. return 0;
  284. };
  285. AbstractMmlNode.prototype.childPosition = function () {
  286. var e_4, _a;
  287. var child = this;
  288. var parent = child.parent;
  289. while (parent && parent.notParent) {
  290. child = parent;
  291. parent = parent.parent;
  292. }
  293. if (parent) {
  294. var i = 0;
  295. try {
  296. for (var _b = __values(parent.childNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
  297. var node = _c.value;
  298. if (node === child) {
  299. return i;
  300. }
  301. i++;
  302. }
  303. }
  304. catch (e_4_1) { e_4 = { error: e_4_1 }; }
  305. finally {
  306. try {
  307. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  308. }
  309. finally { if (e_4) throw e_4.error; }
  310. }
  311. }
  312. return null;
  313. };
  314. AbstractMmlNode.prototype.setTeXclass = function (prev) {
  315. this.getPrevClass(prev);
  316. return (this.texClass != null ? this : prev);
  317. };
  318. AbstractMmlNode.prototype.updateTeXclass = function (core) {
  319. if (core) {
  320. this.prevClass = core.prevClass;
  321. this.prevLevel = core.prevLevel;
  322. core.prevClass = core.prevLevel = null;
  323. this.texClass = core.texClass;
  324. }
  325. };
  326. AbstractMmlNode.prototype.getPrevClass = function (prev) {
  327. if (prev) {
  328. this.prevClass = prev.texClass;
  329. this.prevLevel = prev.attributes.get('scriptlevel');
  330. }
  331. };
  332. AbstractMmlNode.prototype.texSpacing = function () {
  333. var prevClass = (this.prevClass != null ? this.prevClass : exports.TEXCLASS.NONE);
  334. var texClass = this.texClass || exports.TEXCLASS.ORD;
  335. if (prevClass === exports.TEXCLASS.NONE || texClass === exports.TEXCLASS.NONE) {
  336. return '';
  337. }
  338. if (prevClass === exports.TEXCLASS.VCENTER) {
  339. prevClass = exports.TEXCLASS.ORD;
  340. }
  341. if (texClass === exports.TEXCLASS.VCENTER) {
  342. texClass = exports.TEXCLASS.ORD;
  343. }
  344. var space = TEXSPACE[prevClass][texClass];
  345. if ((this.prevLevel > 0 || this.attributes.get('scriptlevel') > 0) && space >= 0) {
  346. return '';
  347. }
  348. return TEXSPACELENGTH[Math.abs(space)];
  349. };
  350. AbstractMmlNode.prototype.hasSpacingAttributes = function () {
  351. return this.isEmbellished && this.coreMO().hasSpacingAttributes();
  352. };
  353. AbstractMmlNode.prototype.setInheritedAttributes = function (attributes, display, level, prime) {
  354. var e_5, _a;
  355. if (attributes === void 0) { attributes = {}; }
  356. if (display === void 0) { display = false; }
  357. if (level === void 0) { level = 0; }
  358. if (prime === void 0) { prime = false; }
  359. var defaults = this.attributes.getAllDefaults();
  360. try {
  361. for (var _b = __values(Object.keys(attributes)), _c = _b.next(); !_c.done; _c = _b.next()) {
  362. var key = _c.value;
  363. if (defaults.hasOwnProperty(key) || AbstractMmlNode.alwaysInherit.hasOwnProperty(key)) {
  364. var _d = __read(attributes[key], 2), node = _d[0], value = _d[1];
  365. var noinherit = (AbstractMmlNode.noInherit[node] || {})[this.kind] || {};
  366. if (!noinherit[key]) {
  367. this.attributes.setInherited(key, value);
  368. }
  369. }
  370. }
  371. }
  372. catch (e_5_1) { e_5 = { error: e_5_1 }; }
  373. finally {
  374. try {
  375. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  376. }
  377. finally { if (e_5) throw e_5.error; }
  378. }
  379. var displaystyle = this.attributes.getExplicit('displaystyle');
  380. if (displaystyle === undefined) {
  381. this.attributes.setInherited('displaystyle', display);
  382. }
  383. var scriptlevel = this.attributes.getExplicit('scriptlevel');
  384. if (scriptlevel === undefined) {
  385. this.attributes.setInherited('scriptlevel', level);
  386. }
  387. if (prime) {
  388. this.setProperty('texprimestyle', prime);
  389. }
  390. var arity = this.arity;
  391. if (arity >= 0 && arity !== Infinity && ((arity === 1 && this.childNodes.length === 0) ||
  392. (arity !== 1 && this.childNodes.length !== arity))) {
  393. if (arity < this.childNodes.length) {
  394. this.childNodes = this.childNodes.slice(0, arity);
  395. }
  396. else {
  397. while (this.childNodes.length < arity) {
  398. this.appendChild(this.factory.create('mrow'));
  399. }
  400. }
  401. }
  402. this.setChildInheritedAttributes(attributes, display, level, prime);
  403. };
  404. AbstractMmlNode.prototype.setChildInheritedAttributes = function (attributes, display, level, prime) {
  405. var e_6, _a;
  406. try {
  407. for (var _b = __values(this.childNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
  408. var child = _c.value;
  409. child.setInheritedAttributes(attributes, display, level, prime);
  410. }
  411. }
  412. catch (e_6_1) { e_6 = { error: e_6_1 }; }
  413. finally {
  414. try {
  415. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  416. }
  417. finally { if (e_6) throw e_6.error; }
  418. }
  419. };
  420. AbstractMmlNode.prototype.addInheritedAttributes = function (current, attributes) {
  421. var e_7, _a;
  422. var updated = __assign({}, current);
  423. try {
  424. for (var _b = __values(Object.keys(attributes)), _c = _b.next(); !_c.done; _c = _b.next()) {
  425. var name_3 = _c.value;
  426. if (name_3 !== 'displaystyle' && name_3 !== 'scriptlevel' && name_3 !== 'style') {
  427. updated[name_3] = [this.kind, attributes[name_3]];
  428. }
  429. }
  430. }
  431. catch (e_7_1) { e_7 = { error: e_7_1 }; }
  432. finally {
  433. try {
  434. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  435. }
  436. finally { if (e_7) throw e_7.error; }
  437. }
  438. return updated;
  439. };
  440. AbstractMmlNode.prototype.inheritAttributesFrom = function (node) {
  441. var attributes = node.attributes;
  442. var display = attributes.get('displaystyle');
  443. var scriptlevel = attributes.get('scriptlevel');
  444. var defaults = (!attributes.isSet('mathsize') ? {} : {
  445. mathsize: ['math', attributes.get('mathsize')]
  446. });
  447. var prime = node.getProperty('texprimestyle') || false;
  448. this.setInheritedAttributes(defaults, display, scriptlevel, prime);
  449. };
  450. AbstractMmlNode.prototype.verifyTree = function (options) {
  451. if (options === void 0) { options = null; }
  452. if (options === null) {
  453. return;
  454. }
  455. this.verifyAttributes(options);
  456. var arity = this.arity;
  457. if (options['checkArity']) {
  458. if (arity >= 0 && arity !== Infinity &&
  459. ((arity === 1 && this.childNodes.length === 0) ||
  460. (arity !== 1 && this.childNodes.length !== arity))) {
  461. this.mError('Wrong number of children for "' + this.kind + '" node', options, true);
  462. }
  463. }
  464. this.verifyChildren(options);
  465. };
  466. AbstractMmlNode.prototype.verifyAttributes = function (options) {
  467. var e_8, _a;
  468. if (options['checkAttributes']) {
  469. var attributes = this.attributes;
  470. var bad = [];
  471. try {
  472. for (var _b = __values(attributes.getExplicitNames()), _c = _b.next(); !_c.done; _c = _b.next()) {
  473. var name_4 = _c.value;
  474. if (name_4.substr(0, 5) !== 'data-' && attributes.getDefault(name_4) === undefined &&
  475. !name_4.match(/^(?:class|style|id|(?:xlink:)?href)$/)) {
  476. bad.push(name_4);
  477. }
  478. }
  479. }
  480. catch (e_8_1) { e_8 = { error: e_8_1 }; }
  481. finally {
  482. try {
  483. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  484. }
  485. finally { if (e_8) throw e_8.error; }
  486. }
  487. if (bad.length) {
  488. this.mError('Unknown attributes for ' + this.kind + ' node: ' + bad.join(', '), options);
  489. }
  490. }
  491. };
  492. AbstractMmlNode.prototype.verifyChildren = function (options) {
  493. var e_9, _a;
  494. try {
  495. for (var _b = __values(this.childNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
  496. var child = _c.value;
  497. child.verifyTree(options);
  498. }
  499. }
  500. catch (e_9_1) { e_9 = { error: e_9_1 }; }
  501. finally {
  502. try {
  503. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  504. }
  505. finally { if (e_9) throw e_9.error; }
  506. }
  507. };
  508. AbstractMmlNode.prototype.mError = function (message, options, short) {
  509. if (short === void 0) { short = false; }
  510. if (this.parent && this.parent.isKind('merror')) {
  511. return null;
  512. }
  513. var merror = this.factory.create('merror');
  514. merror.attributes.set('data-mjx-message', message);
  515. if (options['fullErrors'] || short) {
  516. var mtext = this.factory.create('mtext');
  517. var text = this.factory.create('text');
  518. text.setText(options['fullErrors'] ? message : this.kind);
  519. mtext.appendChild(text);
  520. merror.appendChild(mtext);
  521. this.parent.replaceChild(merror, this);
  522. }
  523. else {
  524. this.parent.replaceChild(merror, this);
  525. merror.appendChild(this);
  526. }
  527. return merror;
  528. };
  529. AbstractMmlNode.defaults = {
  530. mathbackground: Attributes_js_1.INHERIT,
  531. mathcolor: Attributes_js_1.INHERIT,
  532. mathsize: Attributes_js_1.INHERIT,
  533. dir: Attributes_js_1.INHERIT
  534. };
  535. AbstractMmlNode.noInherit = {
  536. mstyle: {
  537. mpadded: { width: true, height: true, depth: true, lspace: true, voffset: true },
  538. mtable: { width: true, height: true, depth: true, align: true }
  539. },
  540. maligngroup: {
  541. mrow: { groupalign: true },
  542. mtable: { groupalign: true }
  543. }
  544. };
  545. AbstractMmlNode.alwaysInherit = {
  546. scriptminsize: true,
  547. scriptsizemultiplier: true
  548. };
  549. AbstractMmlNode.verifyDefaults = {
  550. checkArity: true,
  551. checkAttributes: false,
  552. fullErrors: false,
  553. fixMmultiscripts: true,
  554. fixMtables: true
  555. };
  556. return AbstractMmlNode;
  557. }(Node_js_1.AbstractNode));
  558. exports.AbstractMmlNode = AbstractMmlNode;
  559. var AbstractMmlTokenNode = (function (_super) {
  560. __extends(AbstractMmlTokenNode, _super);
  561. function AbstractMmlTokenNode() {
  562. return _super !== null && _super.apply(this, arguments) || this;
  563. }
  564. Object.defineProperty(AbstractMmlTokenNode.prototype, "isToken", {
  565. get: function () {
  566. return true;
  567. },
  568. enumerable: false,
  569. configurable: true
  570. });
  571. AbstractMmlTokenNode.prototype.getText = function () {
  572. var e_10, _a;
  573. var text = '';
  574. try {
  575. for (var _b = __values(this.childNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
  576. var child = _c.value;
  577. if (child instanceof TextNode) {
  578. text += child.getText();
  579. }
  580. }
  581. }
  582. catch (e_10_1) { e_10 = { error: e_10_1 }; }
  583. finally {
  584. try {
  585. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  586. }
  587. finally { if (e_10) throw e_10.error; }
  588. }
  589. return text;
  590. };
  591. AbstractMmlTokenNode.prototype.setChildInheritedAttributes = function (attributes, display, level, prime) {
  592. var e_11, _a;
  593. try {
  594. for (var _b = __values(this.childNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
  595. var child = _c.value;
  596. if (child instanceof AbstractMmlNode) {
  597. child.setInheritedAttributes(attributes, display, level, prime);
  598. }
  599. }
  600. }
  601. catch (e_11_1) { e_11 = { error: e_11_1 }; }
  602. finally {
  603. try {
  604. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  605. }
  606. finally { if (e_11) throw e_11.error; }
  607. }
  608. };
  609. AbstractMmlTokenNode.prototype.walkTree = function (func, data) {
  610. var e_12, _a;
  611. func(this, data);
  612. try {
  613. for (var _b = __values(this.childNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
  614. var child = _c.value;
  615. if (child instanceof AbstractMmlNode) {
  616. child.walkTree(func, data);
  617. }
  618. }
  619. }
  620. catch (e_12_1) { e_12 = { error: e_12_1 }; }
  621. finally {
  622. try {
  623. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  624. }
  625. finally { if (e_12) throw e_12.error; }
  626. }
  627. return data;
  628. };
  629. AbstractMmlTokenNode.defaults = __assign(__assign({}, AbstractMmlNode.defaults), { mathvariant: 'normal', mathsize: Attributes_js_1.INHERIT });
  630. return AbstractMmlTokenNode;
  631. }(AbstractMmlNode));
  632. exports.AbstractMmlTokenNode = AbstractMmlTokenNode;
  633. var AbstractMmlLayoutNode = (function (_super) {
  634. __extends(AbstractMmlLayoutNode, _super);
  635. function AbstractMmlLayoutNode() {
  636. return _super !== null && _super.apply(this, arguments) || this;
  637. }
  638. Object.defineProperty(AbstractMmlLayoutNode.prototype, "isSpacelike", {
  639. get: function () {
  640. return this.childNodes[0].isSpacelike;
  641. },
  642. enumerable: false,
  643. configurable: true
  644. });
  645. Object.defineProperty(AbstractMmlLayoutNode.prototype, "isEmbellished", {
  646. get: function () {
  647. return this.childNodes[0].isEmbellished;
  648. },
  649. enumerable: false,
  650. configurable: true
  651. });
  652. Object.defineProperty(AbstractMmlLayoutNode.prototype, "arity", {
  653. get: function () {
  654. return -1;
  655. },
  656. enumerable: false,
  657. configurable: true
  658. });
  659. AbstractMmlLayoutNode.prototype.core = function () {
  660. return this.childNodes[0];
  661. };
  662. AbstractMmlLayoutNode.prototype.coreMO = function () {
  663. return this.childNodes[0].coreMO();
  664. };
  665. AbstractMmlLayoutNode.prototype.setTeXclass = function (prev) {
  666. prev = this.childNodes[0].setTeXclass(prev);
  667. this.updateTeXclass(this.childNodes[0]);
  668. return prev;
  669. };
  670. AbstractMmlLayoutNode.defaults = AbstractMmlNode.defaults;
  671. return AbstractMmlLayoutNode;
  672. }(AbstractMmlNode));
  673. exports.AbstractMmlLayoutNode = AbstractMmlLayoutNode;
  674. var AbstractMmlBaseNode = (function (_super) {
  675. __extends(AbstractMmlBaseNode, _super);
  676. function AbstractMmlBaseNode() {
  677. return _super !== null && _super.apply(this, arguments) || this;
  678. }
  679. Object.defineProperty(AbstractMmlBaseNode.prototype, "isEmbellished", {
  680. get: function () {
  681. return this.childNodes[0].isEmbellished;
  682. },
  683. enumerable: false,
  684. configurable: true
  685. });
  686. AbstractMmlBaseNode.prototype.core = function () {
  687. return this.childNodes[0];
  688. };
  689. AbstractMmlBaseNode.prototype.coreMO = function () {
  690. return this.childNodes[0].coreMO();
  691. };
  692. AbstractMmlBaseNode.prototype.setTeXclass = function (prev) {
  693. var e_13, _a;
  694. this.getPrevClass(prev);
  695. this.texClass = exports.TEXCLASS.ORD;
  696. var base = this.childNodes[0];
  697. if (base) {
  698. if (this.isEmbellished || base.isKind('mi')) {
  699. prev = base.setTeXclass(prev);
  700. this.updateTeXclass(this.core());
  701. }
  702. else {
  703. base.setTeXclass(null);
  704. prev = this;
  705. }
  706. }
  707. else {
  708. prev = this;
  709. }
  710. try {
  711. for (var _b = __values(this.childNodes.slice(1)), _c = _b.next(); !_c.done; _c = _b.next()) {
  712. var child = _c.value;
  713. if (child) {
  714. child.setTeXclass(null);
  715. }
  716. }
  717. }
  718. catch (e_13_1) { e_13 = { error: e_13_1 }; }
  719. finally {
  720. try {
  721. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  722. }
  723. finally { if (e_13) throw e_13.error; }
  724. }
  725. return prev;
  726. };
  727. AbstractMmlBaseNode.defaults = AbstractMmlNode.defaults;
  728. return AbstractMmlBaseNode;
  729. }(AbstractMmlNode));
  730. exports.AbstractMmlBaseNode = AbstractMmlBaseNode;
  731. var AbstractMmlEmptyNode = (function (_super) {
  732. __extends(AbstractMmlEmptyNode, _super);
  733. function AbstractMmlEmptyNode() {
  734. return _super !== null && _super.apply(this, arguments) || this;
  735. }
  736. Object.defineProperty(AbstractMmlEmptyNode.prototype, "isToken", {
  737. get: function () {
  738. return false;
  739. },
  740. enumerable: false,
  741. configurable: true
  742. });
  743. Object.defineProperty(AbstractMmlEmptyNode.prototype, "isEmbellished", {
  744. get: function () {
  745. return false;
  746. },
  747. enumerable: false,
  748. configurable: true
  749. });
  750. Object.defineProperty(AbstractMmlEmptyNode.prototype, "isSpacelike", {
  751. get: function () {
  752. return false;
  753. },
  754. enumerable: false,
  755. configurable: true
  756. });
  757. Object.defineProperty(AbstractMmlEmptyNode.prototype, "linebreakContainer", {
  758. get: function () {
  759. return false;
  760. },
  761. enumerable: false,
  762. configurable: true
  763. });
  764. Object.defineProperty(AbstractMmlEmptyNode.prototype, "hasNewLine", {
  765. get: function () {
  766. return false;
  767. },
  768. enumerable: false,
  769. configurable: true
  770. });
  771. Object.defineProperty(AbstractMmlEmptyNode.prototype, "arity", {
  772. get: function () {
  773. return 0;
  774. },
  775. enumerable: false,
  776. configurable: true
  777. });
  778. Object.defineProperty(AbstractMmlEmptyNode.prototype, "isInferred", {
  779. get: function () {
  780. return false;
  781. },
  782. enumerable: false,
  783. configurable: true
  784. });
  785. Object.defineProperty(AbstractMmlEmptyNode.prototype, "notParent", {
  786. get: function () {
  787. return false;
  788. },
  789. enumerable: false,
  790. configurable: true
  791. });
  792. Object.defineProperty(AbstractMmlEmptyNode.prototype, "Parent", {
  793. get: function () {
  794. return this.parent;
  795. },
  796. enumerable: false,
  797. configurable: true
  798. });
  799. Object.defineProperty(AbstractMmlEmptyNode.prototype, "texClass", {
  800. get: function () {
  801. return exports.TEXCLASS.NONE;
  802. },
  803. enumerable: false,
  804. configurable: true
  805. });
  806. Object.defineProperty(AbstractMmlEmptyNode.prototype, "prevClass", {
  807. get: function () {
  808. return exports.TEXCLASS.NONE;
  809. },
  810. enumerable: false,
  811. configurable: true
  812. });
  813. Object.defineProperty(AbstractMmlEmptyNode.prototype, "prevLevel", {
  814. get: function () {
  815. return 0;
  816. },
  817. enumerable: false,
  818. configurable: true
  819. });
  820. AbstractMmlEmptyNode.prototype.hasSpacingAttributes = function () {
  821. return false;
  822. };
  823. Object.defineProperty(AbstractMmlEmptyNode.prototype, "attributes", {
  824. get: function () {
  825. return null;
  826. },
  827. enumerable: false,
  828. configurable: true
  829. });
  830. AbstractMmlEmptyNode.prototype.core = function () {
  831. return this;
  832. };
  833. AbstractMmlEmptyNode.prototype.coreMO = function () {
  834. return this;
  835. };
  836. AbstractMmlEmptyNode.prototype.coreIndex = function () {
  837. return 0;
  838. };
  839. AbstractMmlEmptyNode.prototype.childPosition = function () {
  840. return 0;
  841. };
  842. AbstractMmlEmptyNode.prototype.setTeXclass = function (prev) {
  843. return prev;
  844. };
  845. AbstractMmlEmptyNode.prototype.texSpacing = function () {
  846. return '';
  847. };
  848. AbstractMmlEmptyNode.prototype.setInheritedAttributes = function (_attributes, _display, _level, _prime) { };
  849. AbstractMmlEmptyNode.prototype.inheritAttributesFrom = function (_node) { };
  850. AbstractMmlEmptyNode.prototype.verifyTree = function (_options) { };
  851. AbstractMmlEmptyNode.prototype.mError = function (_message, _options, _short) {
  852. if (_short === void 0) { _short = false; }
  853. return null;
  854. };
  855. return AbstractMmlEmptyNode;
  856. }(Node_js_1.AbstractEmptyNode));
  857. exports.AbstractMmlEmptyNode = AbstractMmlEmptyNode;
  858. var TextNode = (function (_super) {
  859. __extends(TextNode, _super);
  860. function TextNode() {
  861. var _this = _super !== null && _super.apply(this, arguments) || this;
  862. _this.text = '';
  863. return _this;
  864. }
  865. Object.defineProperty(TextNode.prototype, "kind", {
  866. get: function () {
  867. return 'text';
  868. },
  869. enumerable: false,
  870. configurable: true
  871. });
  872. TextNode.prototype.getText = function () {
  873. return this.text;
  874. };
  875. TextNode.prototype.setText = function (text) {
  876. this.text = text;
  877. return this;
  878. };
  879. TextNode.prototype.copy = function () {
  880. return this.factory.create(this.kind).setText(this.getText());
  881. };
  882. TextNode.prototype.toString = function () {
  883. return this.text;
  884. };
  885. return TextNode;
  886. }(AbstractMmlEmptyNode));
  887. exports.TextNode = TextNode;
  888. var XMLNode = (function (_super) {
  889. __extends(XMLNode, _super);
  890. function XMLNode() {
  891. var _this = _super !== null && _super.apply(this, arguments) || this;
  892. _this.xml = null;
  893. _this.adaptor = null;
  894. return _this;
  895. }
  896. Object.defineProperty(XMLNode.prototype, "kind", {
  897. get: function () {
  898. return 'XML';
  899. },
  900. enumerable: false,
  901. configurable: true
  902. });
  903. XMLNode.prototype.getXML = function () {
  904. return this.xml;
  905. };
  906. XMLNode.prototype.setXML = function (xml, adaptor) {
  907. if (adaptor === void 0) { adaptor = null; }
  908. this.xml = xml;
  909. this.adaptor = adaptor;
  910. return this;
  911. };
  912. XMLNode.prototype.getSerializedXML = function () {
  913. return this.adaptor.serializeXML(this.xml);
  914. };
  915. XMLNode.prototype.copy = function () {
  916. return this.factory.create(this.kind).setXML(this.adaptor.clone(this.xml));
  917. };
  918. XMLNode.prototype.toString = function () {
  919. return 'XML data';
  920. };
  921. return XMLNode;
  922. }(AbstractMmlEmptyNode));
  923. exports.XMLNode = XMLNode;
  924. //# sourceMappingURL=MmlNode.js.map