BaseItems.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  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 __read = (this && this.__read) || function (o, n) {
  18. var m = typeof Symbol === "function" && o[Symbol.iterator];
  19. if (!m) return o;
  20. var i = m.call(o), r, ar = [], e;
  21. try {
  22. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  23. }
  24. catch (error) { e = { error: error }; }
  25. finally {
  26. try {
  27. if (r && !r.done && (m = i["return"])) m.call(i);
  28. }
  29. finally { if (e) throw e.error; }
  30. }
  31. return ar;
  32. };
  33. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  34. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  35. if (ar || !(i in from)) {
  36. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  37. ar[i] = from[i];
  38. }
  39. }
  40. return to.concat(ar || Array.prototype.slice.call(from));
  41. };
  42. var __importDefault = (this && this.__importDefault) || function (mod) {
  43. return (mod && mod.__esModule) ? mod : { "default": mod };
  44. };
  45. Object.defineProperty(exports, "__esModule", { value: true });
  46. exports.EquationItem = exports.EqnArrayItem = exports.ArrayItem = exports.DotsItem = exports.NonscriptItem = exports.NotItem = exports.FnItem = exports.MmlItem = exports.CellItem = exports.PositionItem = exports.StyleItem = exports.EndItem = exports.BeginItem = exports.RightItem = exports.Middle = exports.LeftItem = exports.OverItem = exports.SubsupItem = exports.PrimeItem = exports.CloseItem = exports.OpenItem = exports.StopItem = exports.StartItem = void 0;
  47. var MapHandler_js_1 = require("../MapHandler.js");
  48. var Entities_js_1 = require("../../../util/Entities.js");
  49. var MmlNode_js_1 = require("../../../core/MmlTree/MmlNode.js");
  50. var TexError_js_1 = __importDefault(require("../TexError.js"));
  51. var ParseUtil_js_1 = __importDefault(require("../ParseUtil.js"));
  52. var NodeUtil_js_1 = __importDefault(require("../NodeUtil.js"));
  53. var StackItem_js_1 = require("../StackItem.js");
  54. var StartItem = (function (_super) {
  55. __extends(StartItem, _super);
  56. function StartItem(factory, global) {
  57. var _this = _super.call(this, factory) || this;
  58. _this.global = global;
  59. return _this;
  60. }
  61. Object.defineProperty(StartItem.prototype, "kind", {
  62. get: function () {
  63. return 'start';
  64. },
  65. enumerable: false,
  66. configurable: true
  67. });
  68. Object.defineProperty(StartItem.prototype, "isOpen", {
  69. get: function () {
  70. return true;
  71. },
  72. enumerable: false,
  73. configurable: true
  74. });
  75. StartItem.prototype.checkItem = function (item) {
  76. if (item.isKind('stop')) {
  77. var node = this.toMml();
  78. if (!this.global.isInner) {
  79. node = this.factory.configuration.tags.finalize(node, this.env);
  80. }
  81. return [[this.factory.create('mml', node)], true];
  82. }
  83. return _super.prototype.checkItem.call(this, item);
  84. };
  85. return StartItem;
  86. }(StackItem_js_1.BaseItem));
  87. exports.StartItem = StartItem;
  88. var StopItem = (function (_super) {
  89. __extends(StopItem, _super);
  90. function StopItem() {
  91. return _super !== null && _super.apply(this, arguments) || this;
  92. }
  93. Object.defineProperty(StopItem.prototype, "kind", {
  94. get: function () {
  95. return 'stop';
  96. },
  97. enumerable: false,
  98. configurable: true
  99. });
  100. Object.defineProperty(StopItem.prototype, "isClose", {
  101. get: function () {
  102. return true;
  103. },
  104. enumerable: false,
  105. configurable: true
  106. });
  107. return StopItem;
  108. }(StackItem_js_1.BaseItem));
  109. exports.StopItem = StopItem;
  110. var OpenItem = (function (_super) {
  111. __extends(OpenItem, _super);
  112. function OpenItem() {
  113. return _super !== null && _super.apply(this, arguments) || this;
  114. }
  115. Object.defineProperty(OpenItem.prototype, "kind", {
  116. get: function () {
  117. return 'open';
  118. },
  119. enumerable: false,
  120. configurable: true
  121. });
  122. Object.defineProperty(OpenItem.prototype, "isOpen", {
  123. get: function () {
  124. return true;
  125. },
  126. enumerable: false,
  127. configurable: true
  128. });
  129. OpenItem.prototype.checkItem = function (item) {
  130. if (item.isKind('close')) {
  131. var mml = this.toMml();
  132. var node = this.create('node', 'TeXAtom', [mml]);
  133. return [[this.factory.create('mml', node)], true];
  134. }
  135. return _super.prototype.checkItem.call(this, item);
  136. };
  137. OpenItem.errors = Object.assign(Object.create(StackItem_js_1.BaseItem.errors), {
  138. 'stop': ['ExtraOpenMissingClose',
  139. 'Extra open brace or missing close brace']
  140. });
  141. return OpenItem;
  142. }(StackItem_js_1.BaseItem));
  143. exports.OpenItem = OpenItem;
  144. var CloseItem = (function (_super) {
  145. __extends(CloseItem, _super);
  146. function CloseItem() {
  147. return _super !== null && _super.apply(this, arguments) || this;
  148. }
  149. Object.defineProperty(CloseItem.prototype, "kind", {
  150. get: function () {
  151. return 'close';
  152. },
  153. enumerable: false,
  154. configurable: true
  155. });
  156. Object.defineProperty(CloseItem.prototype, "isClose", {
  157. get: function () {
  158. return true;
  159. },
  160. enumerable: false,
  161. configurable: true
  162. });
  163. return CloseItem;
  164. }(StackItem_js_1.BaseItem));
  165. exports.CloseItem = CloseItem;
  166. var PrimeItem = (function (_super) {
  167. __extends(PrimeItem, _super);
  168. function PrimeItem() {
  169. return _super !== null && _super.apply(this, arguments) || this;
  170. }
  171. Object.defineProperty(PrimeItem.prototype, "kind", {
  172. get: function () {
  173. return 'prime';
  174. },
  175. enumerable: false,
  176. configurable: true
  177. });
  178. PrimeItem.prototype.checkItem = function (item) {
  179. var _a = __read(this.Peek(2), 2), top0 = _a[0], top1 = _a[1];
  180. if (!NodeUtil_js_1.default.isType(top0, 'msubsup') || NodeUtil_js_1.default.isType(top0, 'msup')) {
  181. var node = this.create('node', 'msup', [top0, top1]);
  182. return [[node, item], true];
  183. }
  184. NodeUtil_js_1.default.setChild(top0, top0.sup, top1);
  185. return [[top0, item], true];
  186. };
  187. return PrimeItem;
  188. }(StackItem_js_1.BaseItem));
  189. exports.PrimeItem = PrimeItem;
  190. var SubsupItem = (function (_super) {
  191. __extends(SubsupItem, _super);
  192. function SubsupItem() {
  193. return _super !== null && _super.apply(this, arguments) || this;
  194. }
  195. Object.defineProperty(SubsupItem.prototype, "kind", {
  196. get: function () {
  197. return 'subsup';
  198. },
  199. enumerable: false,
  200. configurable: true
  201. });
  202. SubsupItem.prototype.checkItem = function (item) {
  203. if (item.isKind('open') || item.isKind('left')) {
  204. return StackItem_js_1.BaseItem.success;
  205. }
  206. var top = this.First;
  207. var position = this.getProperty('position');
  208. if (item.isKind('mml')) {
  209. if (this.getProperty('primes')) {
  210. if (position !== 2) {
  211. NodeUtil_js_1.default.setChild(top, 2, this.getProperty('primes'));
  212. }
  213. else {
  214. NodeUtil_js_1.default.setProperty(this.getProperty('primes'), 'variantForm', true);
  215. var node = this.create('node', 'mrow', [this.getProperty('primes'), item.First]);
  216. item.First = node;
  217. }
  218. }
  219. NodeUtil_js_1.default.setChild(top, position, item.First);
  220. if (this.getProperty('movesupsub') != null) {
  221. NodeUtil_js_1.default.setProperty(top, 'movesupsub', this.getProperty('movesupsub'));
  222. }
  223. var result = this.factory.create('mml', top);
  224. return [[result], true];
  225. }
  226. if (_super.prototype.checkItem.call(this, item)[1]) {
  227. var error = this.getErrors(['', 'sub', 'sup'][position]);
  228. throw new (TexError_js_1.default.bind.apply(TexError_js_1.default, __spreadArray([void 0, error[0], error[1]], __read(error.splice(2)), false)))();
  229. }
  230. return null;
  231. };
  232. SubsupItem.errors = Object.assign(Object.create(StackItem_js_1.BaseItem.errors), {
  233. 'stop': ['MissingScript',
  234. 'Missing superscript or subscript argument'],
  235. 'sup': ['MissingOpenForSup',
  236. 'Missing open brace for superscript'],
  237. 'sub': ['MissingOpenForSub',
  238. 'Missing open brace for subscript']
  239. });
  240. return SubsupItem;
  241. }(StackItem_js_1.BaseItem));
  242. exports.SubsupItem = SubsupItem;
  243. var OverItem = (function (_super) {
  244. __extends(OverItem, _super);
  245. function OverItem(factory) {
  246. var _this = _super.call(this, factory) || this;
  247. _this.setProperty('name', '\\over');
  248. return _this;
  249. }
  250. Object.defineProperty(OverItem.prototype, "kind", {
  251. get: function () {
  252. return 'over';
  253. },
  254. enumerable: false,
  255. configurable: true
  256. });
  257. Object.defineProperty(OverItem.prototype, "isClose", {
  258. get: function () {
  259. return true;
  260. },
  261. enumerable: false,
  262. configurable: true
  263. });
  264. OverItem.prototype.checkItem = function (item) {
  265. if (item.isKind('over')) {
  266. throw new TexError_js_1.default('AmbiguousUseOf', 'Ambiguous use of %1', item.getName());
  267. }
  268. if (item.isClose) {
  269. var mml = this.create('node', 'mfrac', [this.getProperty('num'), this.toMml(false)]);
  270. if (this.getProperty('thickness') != null) {
  271. NodeUtil_js_1.default.setAttribute(mml, 'linethickness', this.getProperty('thickness'));
  272. }
  273. if (this.getProperty('open') || this.getProperty('close')) {
  274. NodeUtil_js_1.default.setProperty(mml, 'withDelims', true);
  275. mml = ParseUtil_js_1.default.fixedFence(this.factory.configuration, this.getProperty('open'), mml, this.getProperty('close'));
  276. }
  277. return [[this.factory.create('mml', mml), item], true];
  278. }
  279. return _super.prototype.checkItem.call(this, item);
  280. };
  281. OverItem.prototype.toString = function () {
  282. return 'over[' + this.getProperty('num') +
  283. ' / ' + this.nodes.join('; ') + ']';
  284. };
  285. return OverItem;
  286. }(StackItem_js_1.BaseItem));
  287. exports.OverItem = OverItem;
  288. var LeftItem = (function (_super) {
  289. __extends(LeftItem, _super);
  290. function LeftItem(factory, delim) {
  291. var _this = _super.call(this, factory) || this;
  292. _this.setProperty('delim', delim);
  293. return _this;
  294. }
  295. Object.defineProperty(LeftItem.prototype, "kind", {
  296. get: function () {
  297. return 'left';
  298. },
  299. enumerable: false,
  300. configurable: true
  301. });
  302. Object.defineProperty(LeftItem.prototype, "isOpen", {
  303. get: function () {
  304. return true;
  305. },
  306. enumerable: false,
  307. configurable: true
  308. });
  309. LeftItem.prototype.checkItem = function (item) {
  310. if (item.isKind('right')) {
  311. return [[this.factory.create('mml', ParseUtil_js_1.default.fenced(this.factory.configuration, this.getProperty('delim'), this.toMml(), item.getProperty('delim'), '', item.getProperty('color')))], true];
  312. }
  313. if (item.isKind('middle')) {
  314. var def = { stretchy: true };
  315. if (item.getProperty('color')) {
  316. def.mathcolor = item.getProperty('color');
  317. }
  318. this.Push(this.create('node', 'TeXAtom', [], { texClass: MmlNode_js_1.TEXCLASS.CLOSE }), this.create('token', 'mo', def, item.getProperty('delim')), this.create('node', 'TeXAtom', [], { texClass: MmlNode_js_1.TEXCLASS.OPEN }));
  319. this.env = {};
  320. return [[this], true];
  321. }
  322. return _super.prototype.checkItem.call(this, item);
  323. };
  324. LeftItem.errors = Object.assign(Object.create(StackItem_js_1.BaseItem.errors), {
  325. 'stop': ['ExtraLeftMissingRight',
  326. 'Extra \\left or missing \\right']
  327. });
  328. return LeftItem;
  329. }(StackItem_js_1.BaseItem));
  330. exports.LeftItem = LeftItem;
  331. var Middle = (function (_super) {
  332. __extends(Middle, _super);
  333. function Middle(factory, delim, color) {
  334. var _this = _super.call(this, factory) || this;
  335. _this.setProperty('delim', delim);
  336. color && _this.setProperty('color', color);
  337. return _this;
  338. }
  339. Object.defineProperty(Middle.prototype, "kind", {
  340. get: function () {
  341. return 'middle';
  342. },
  343. enumerable: false,
  344. configurable: true
  345. });
  346. Object.defineProperty(Middle.prototype, "isClose", {
  347. get: function () {
  348. return true;
  349. },
  350. enumerable: false,
  351. configurable: true
  352. });
  353. return Middle;
  354. }(StackItem_js_1.BaseItem));
  355. exports.Middle = Middle;
  356. var RightItem = (function (_super) {
  357. __extends(RightItem, _super);
  358. function RightItem(factory, delim, color) {
  359. var _this = _super.call(this, factory) || this;
  360. _this.setProperty('delim', delim);
  361. color && _this.setProperty('color', color);
  362. return _this;
  363. }
  364. Object.defineProperty(RightItem.prototype, "kind", {
  365. get: function () {
  366. return 'right';
  367. },
  368. enumerable: false,
  369. configurable: true
  370. });
  371. Object.defineProperty(RightItem.prototype, "isClose", {
  372. get: function () {
  373. return true;
  374. },
  375. enumerable: false,
  376. configurable: true
  377. });
  378. return RightItem;
  379. }(StackItem_js_1.BaseItem));
  380. exports.RightItem = RightItem;
  381. var BeginItem = (function (_super) {
  382. __extends(BeginItem, _super);
  383. function BeginItem() {
  384. return _super !== null && _super.apply(this, arguments) || this;
  385. }
  386. Object.defineProperty(BeginItem.prototype, "kind", {
  387. get: function () {
  388. return 'begin';
  389. },
  390. enumerable: false,
  391. configurable: true
  392. });
  393. Object.defineProperty(BeginItem.prototype, "isOpen", {
  394. get: function () {
  395. return true;
  396. },
  397. enumerable: false,
  398. configurable: true
  399. });
  400. BeginItem.prototype.checkItem = function (item) {
  401. if (item.isKind('end')) {
  402. if (item.getName() !== this.getName()) {
  403. throw new TexError_js_1.default('EnvBadEnd', '\\begin{%1} ended with \\end{%2}', this.getName(), item.getName());
  404. }
  405. if (!this.getProperty('end')) {
  406. return [[this.factory.create('mml', this.toMml())], true];
  407. }
  408. return StackItem_js_1.BaseItem.fail;
  409. }
  410. if (item.isKind('stop')) {
  411. throw new TexError_js_1.default('EnvMissingEnd', 'Missing \\end{%1}', this.getName());
  412. }
  413. return _super.prototype.checkItem.call(this, item);
  414. };
  415. return BeginItem;
  416. }(StackItem_js_1.BaseItem));
  417. exports.BeginItem = BeginItem;
  418. var EndItem = (function (_super) {
  419. __extends(EndItem, _super);
  420. function EndItem() {
  421. return _super !== null && _super.apply(this, arguments) || this;
  422. }
  423. Object.defineProperty(EndItem.prototype, "kind", {
  424. get: function () {
  425. return 'end';
  426. },
  427. enumerable: false,
  428. configurable: true
  429. });
  430. Object.defineProperty(EndItem.prototype, "isClose", {
  431. get: function () {
  432. return true;
  433. },
  434. enumerable: false,
  435. configurable: true
  436. });
  437. return EndItem;
  438. }(StackItem_js_1.BaseItem));
  439. exports.EndItem = EndItem;
  440. var StyleItem = (function (_super) {
  441. __extends(StyleItem, _super);
  442. function StyleItem() {
  443. return _super !== null && _super.apply(this, arguments) || this;
  444. }
  445. Object.defineProperty(StyleItem.prototype, "kind", {
  446. get: function () {
  447. return 'style';
  448. },
  449. enumerable: false,
  450. configurable: true
  451. });
  452. StyleItem.prototype.checkItem = function (item) {
  453. if (!item.isClose) {
  454. return _super.prototype.checkItem.call(this, item);
  455. }
  456. var mml = this.create('node', 'mstyle', this.nodes, this.getProperty('styles'));
  457. return [[this.factory.create('mml', mml), item], true];
  458. };
  459. return StyleItem;
  460. }(StackItem_js_1.BaseItem));
  461. exports.StyleItem = StyleItem;
  462. var PositionItem = (function (_super) {
  463. __extends(PositionItem, _super);
  464. function PositionItem() {
  465. return _super !== null && _super.apply(this, arguments) || this;
  466. }
  467. Object.defineProperty(PositionItem.prototype, "kind", {
  468. get: function () {
  469. return 'position';
  470. },
  471. enumerable: false,
  472. configurable: true
  473. });
  474. PositionItem.prototype.checkItem = function (item) {
  475. if (item.isClose) {
  476. throw new TexError_js_1.default('MissingBoxFor', 'Missing box for %1', this.getName());
  477. }
  478. if (item.isFinal) {
  479. var mml = item.toMml();
  480. switch (this.getProperty('move')) {
  481. case 'vertical':
  482. mml = this.create('node', 'mpadded', [mml], { height: this.getProperty('dh'),
  483. depth: this.getProperty('dd'),
  484. voffset: this.getProperty('dh') });
  485. return [[this.factory.create('mml', mml)], true];
  486. case 'horizontal':
  487. return [[this.factory.create('mml', this.getProperty('left')), item,
  488. this.factory.create('mml', this.getProperty('right'))], true];
  489. }
  490. }
  491. return _super.prototype.checkItem.call(this, item);
  492. };
  493. return PositionItem;
  494. }(StackItem_js_1.BaseItem));
  495. exports.PositionItem = PositionItem;
  496. var CellItem = (function (_super) {
  497. __extends(CellItem, _super);
  498. function CellItem() {
  499. return _super !== null && _super.apply(this, arguments) || this;
  500. }
  501. Object.defineProperty(CellItem.prototype, "kind", {
  502. get: function () {
  503. return 'cell';
  504. },
  505. enumerable: false,
  506. configurable: true
  507. });
  508. Object.defineProperty(CellItem.prototype, "isClose", {
  509. get: function () {
  510. return true;
  511. },
  512. enumerable: false,
  513. configurable: true
  514. });
  515. return CellItem;
  516. }(StackItem_js_1.BaseItem));
  517. exports.CellItem = CellItem;
  518. var MmlItem = (function (_super) {
  519. __extends(MmlItem, _super);
  520. function MmlItem() {
  521. return _super !== null && _super.apply(this, arguments) || this;
  522. }
  523. Object.defineProperty(MmlItem.prototype, "isFinal", {
  524. get: function () {
  525. return true;
  526. },
  527. enumerable: false,
  528. configurable: true
  529. });
  530. Object.defineProperty(MmlItem.prototype, "kind", {
  531. get: function () {
  532. return 'mml';
  533. },
  534. enumerable: false,
  535. configurable: true
  536. });
  537. return MmlItem;
  538. }(StackItem_js_1.BaseItem));
  539. exports.MmlItem = MmlItem;
  540. var FnItem = (function (_super) {
  541. __extends(FnItem, _super);
  542. function FnItem() {
  543. return _super !== null && _super.apply(this, arguments) || this;
  544. }
  545. Object.defineProperty(FnItem.prototype, "kind", {
  546. get: function () {
  547. return 'fn';
  548. },
  549. enumerable: false,
  550. configurable: true
  551. });
  552. FnItem.prototype.checkItem = function (item) {
  553. var top = this.First;
  554. if (top) {
  555. if (item.isOpen) {
  556. return StackItem_js_1.BaseItem.success;
  557. }
  558. if (!item.isKind('fn')) {
  559. var mml = item.First;
  560. if (!item.isKind('mml') || !mml) {
  561. return [[top, item], true];
  562. }
  563. if ((NodeUtil_js_1.default.isType(mml, 'mstyle') && mml.childNodes.length &&
  564. NodeUtil_js_1.default.isType(mml.childNodes[0].childNodes[0], 'mspace')) ||
  565. NodeUtil_js_1.default.isType(mml, 'mspace')) {
  566. return [[top, item], true];
  567. }
  568. if (NodeUtil_js_1.default.isEmbellished(mml)) {
  569. mml = NodeUtil_js_1.default.getCoreMO(mml);
  570. }
  571. var form = NodeUtil_js_1.default.getForm(mml);
  572. if (form != null && [0, 0, 1, 1, 0, 1, 1, 0, 0, 0][form[2]]) {
  573. return [[top, item], true];
  574. }
  575. }
  576. var node = this.create('token', 'mo', { texClass: MmlNode_js_1.TEXCLASS.NONE }, Entities_js_1.entities.ApplyFunction);
  577. return [[top, node, item], true];
  578. }
  579. return _super.prototype.checkItem.apply(this, arguments);
  580. };
  581. return FnItem;
  582. }(StackItem_js_1.BaseItem));
  583. exports.FnItem = FnItem;
  584. var NotItem = (function (_super) {
  585. __extends(NotItem, _super);
  586. function NotItem() {
  587. var _this = _super !== null && _super.apply(this, arguments) || this;
  588. _this.remap = MapHandler_js_1.MapHandler.getMap('not_remap');
  589. return _this;
  590. }
  591. Object.defineProperty(NotItem.prototype, "kind", {
  592. get: function () {
  593. return 'not';
  594. },
  595. enumerable: false,
  596. configurable: true
  597. });
  598. NotItem.prototype.checkItem = function (item) {
  599. var mml;
  600. var c;
  601. var textNode;
  602. if (item.isKind('open') || item.isKind('left')) {
  603. return StackItem_js_1.BaseItem.success;
  604. }
  605. if (item.isKind('mml') &&
  606. (NodeUtil_js_1.default.isType(item.First, 'mo') || NodeUtil_js_1.default.isType(item.First, 'mi') ||
  607. NodeUtil_js_1.default.isType(item.First, 'mtext'))) {
  608. mml = item.First;
  609. c = NodeUtil_js_1.default.getText(mml);
  610. if (c.length === 1 && !NodeUtil_js_1.default.getProperty(mml, 'movesupsub') &&
  611. NodeUtil_js_1.default.getChildren(mml).length === 1) {
  612. if (this.remap.contains(c)) {
  613. textNode = this.create('text', this.remap.lookup(c).char);
  614. NodeUtil_js_1.default.setChild(mml, 0, textNode);
  615. }
  616. else {
  617. textNode = this.create('text', '\u0338');
  618. NodeUtil_js_1.default.appendChildren(mml, [textNode]);
  619. }
  620. return [[item], true];
  621. }
  622. }
  623. textNode = this.create('text', '\u29F8');
  624. var mtextNode = this.create('node', 'mtext', [], {}, textNode);
  625. var paddedNode = this.create('node', 'mpadded', [mtextNode], { width: 0 });
  626. mml = this.create('node', 'TeXAtom', [paddedNode], { texClass: MmlNode_js_1.TEXCLASS.REL });
  627. return [[mml, item], true];
  628. };
  629. return NotItem;
  630. }(StackItem_js_1.BaseItem));
  631. exports.NotItem = NotItem;
  632. var NonscriptItem = (function (_super) {
  633. __extends(NonscriptItem, _super);
  634. function NonscriptItem() {
  635. return _super !== null && _super.apply(this, arguments) || this;
  636. }
  637. Object.defineProperty(NonscriptItem.prototype, "kind", {
  638. get: function () {
  639. return 'nonscript';
  640. },
  641. enumerable: false,
  642. configurable: true
  643. });
  644. NonscriptItem.prototype.checkItem = function (item) {
  645. if (item.isKind('mml') && item.Size() === 1) {
  646. var mml = item.First;
  647. if (mml.isKind('mstyle') && mml.notParent) {
  648. mml = NodeUtil_js_1.default.getChildren(NodeUtil_js_1.default.getChildren(mml)[0])[0];
  649. }
  650. if (mml.isKind('mspace')) {
  651. if (mml !== item.First) {
  652. var mrow = this.create('node', 'mrow', [item.Pop()]);
  653. item.Push(mrow);
  654. }
  655. this.factory.configuration.addNode('nonscript', item.First);
  656. }
  657. }
  658. return [[item], true];
  659. };
  660. return NonscriptItem;
  661. }(StackItem_js_1.BaseItem));
  662. exports.NonscriptItem = NonscriptItem;
  663. var DotsItem = (function (_super) {
  664. __extends(DotsItem, _super);
  665. function DotsItem() {
  666. return _super !== null && _super.apply(this, arguments) || this;
  667. }
  668. Object.defineProperty(DotsItem.prototype, "kind", {
  669. get: function () {
  670. return 'dots';
  671. },
  672. enumerable: false,
  673. configurable: true
  674. });
  675. DotsItem.prototype.checkItem = function (item) {
  676. if (item.isKind('open') || item.isKind('left')) {
  677. return StackItem_js_1.BaseItem.success;
  678. }
  679. var dots = this.getProperty('ldots');
  680. var top = item.First;
  681. if (item.isKind('mml') && NodeUtil_js_1.default.isEmbellished(top)) {
  682. var tclass = NodeUtil_js_1.default.getTexClass(NodeUtil_js_1.default.getCoreMO(top));
  683. if (tclass === MmlNode_js_1.TEXCLASS.BIN || tclass === MmlNode_js_1.TEXCLASS.REL) {
  684. dots = this.getProperty('cdots');
  685. }
  686. }
  687. return [[dots, item], true];
  688. };
  689. return DotsItem;
  690. }(StackItem_js_1.BaseItem));
  691. exports.DotsItem = DotsItem;
  692. var ArrayItem = (function (_super) {
  693. __extends(ArrayItem, _super);
  694. function ArrayItem() {
  695. var _this = _super !== null && _super.apply(this, arguments) || this;
  696. _this.table = [];
  697. _this.row = [];
  698. _this.frame = [];
  699. _this.hfill = [];
  700. _this.arraydef = {};
  701. _this.dashed = false;
  702. return _this;
  703. }
  704. Object.defineProperty(ArrayItem.prototype, "kind", {
  705. get: function () {
  706. return 'array';
  707. },
  708. enumerable: false,
  709. configurable: true
  710. });
  711. Object.defineProperty(ArrayItem.prototype, "isOpen", {
  712. get: function () {
  713. return true;
  714. },
  715. enumerable: false,
  716. configurable: true
  717. });
  718. Object.defineProperty(ArrayItem.prototype, "copyEnv", {
  719. get: function () {
  720. return false;
  721. },
  722. enumerable: false,
  723. configurable: true
  724. });
  725. ArrayItem.prototype.checkItem = function (item) {
  726. if (item.isClose && !item.isKind('over')) {
  727. if (item.getProperty('isEntry')) {
  728. this.EndEntry();
  729. this.clearEnv();
  730. return StackItem_js_1.BaseItem.fail;
  731. }
  732. if (item.getProperty('isCR')) {
  733. this.EndEntry();
  734. this.EndRow();
  735. this.clearEnv();
  736. return StackItem_js_1.BaseItem.fail;
  737. }
  738. this.EndTable();
  739. this.clearEnv();
  740. var newItem = this.factory.create('mml', this.createMml());
  741. if (this.getProperty('requireClose')) {
  742. if (item.isKind('close')) {
  743. return [[newItem], true];
  744. }
  745. throw new TexError_js_1.default('MissingCloseBrace', 'Missing close brace');
  746. }
  747. return [[newItem, item], true];
  748. }
  749. return _super.prototype.checkItem.call(this, item);
  750. };
  751. ArrayItem.prototype.createMml = function () {
  752. var scriptlevel = this.arraydef['scriptlevel'];
  753. delete this.arraydef['scriptlevel'];
  754. var mml = this.create('node', 'mtable', this.table, this.arraydef);
  755. if (scriptlevel) {
  756. mml.setProperty('scriptlevel', scriptlevel);
  757. }
  758. if (this.frame.length === 4) {
  759. NodeUtil_js_1.default.setAttribute(mml, 'frame', this.dashed ? 'dashed' : 'solid');
  760. }
  761. else if (this.frame.length) {
  762. if (this.arraydef['rowlines']) {
  763. this.arraydef['rowlines'] =
  764. this.arraydef['rowlines'].replace(/none( none)+$/, 'none');
  765. }
  766. NodeUtil_js_1.default.setAttribute(mml, 'frame', '');
  767. mml = this.create('node', 'menclose', [mml], { notation: this.frame.join(' ') });
  768. if ((this.arraydef['columnlines'] || 'none') !== 'none' ||
  769. (this.arraydef['rowlines'] || 'none') !== 'none') {
  770. NodeUtil_js_1.default.setAttribute(mml, 'data-padding', 0);
  771. }
  772. }
  773. if (this.getProperty('open') || this.getProperty('close')) {
  774. mml = ParseUtil_js_1.default.fenced(this.factory.configuration, this.getProperty('open'), mml, this.getProperty('close'));
  775. }
  776. return mml;
  777. };
  778. ArrayItem.prototype.EndEntry = function () {
  779. var mtd = this.create('node', 'mtd', this.nodes);
  780. if (this.hfill.length) {
  781. if (this.hfill[0] === 0) {
  782. NodeUtil_js_1.default.setAttribute(mtd, 'columnalign', 'right');
  783. }
  784. if (this.hfill[this.hfill.length - 1] === this.Size()) {
  785. NodeUtil_js_1.default.setAttribute(mtd, 'columnalign', NodeUtil_js_1.default.getAttribute(mtd, 'columnalign') ? 'center' : 'left');
  786. }
  787. }
  788. this.row.push(mtd);
  789. this.Clear();
  790. this.hfill = [];
  791. };
  792. ArrayItem.prototype.EndRow = function () {
  793. var node;
  794. if (this.getProperty('isNumbered') && this.row.length === 3) {
  795. this.row.unshift(this.row.pop());
  796. node = this.create('node', 'mlabeledtr', this.row);
  797. }
  798. else {
  799. node = this.create('node', 'mtr', this.row);
  800. }
  801. this.table.push(node);
  802. this.row = [];
  803. };
  804. ArrayItem.prototype.EndTable = function () {
  805. if (this.Size() || this.row.length) {
  806. this.EndEntry();
  807. this.EndRow();
  808. }
  809. this.checkLines();
  810. };
  811. ArrayItem.prototype.checkLines = function () {
  812. if (this.arraydef['rowlines']) {
  813. var lines = this.arraydef['rowlines'].split(/ /);
  814. if (lines.length === this.table.length) {
  815. this.frame.push('bottom');
  816. lines.pop();
  817. this.arraydef['rowlines'] = lines.join(' ');
  818. }
  819. else if (lines.length < this.table.length - 1) {
  820. this.arraydef['rowlines'] += ' none';
  821. }
  822. }
  823. if (this.getProperty('rowspacing')) {
  824. var rows = this.arraydef['rowspacing'].split(/ /);
  825. while (rows.length < this.table.length) {
  826. rows.push(this.getProperty('rowspacing') + 'em');
  827. }
  828. this.arraydef['rowspacing'] = rows.join(' ');
  829. }
  830. };
  831. ArrayItem.prototype.addRowSpacing = function (spacing) {
  832. if (this.arraydef['rowspacing']) {
  833. var rows = this.arraydef['rowspacing'].split(/ /);
  834. if (!this.getProperty('rowspacing')) {
  835. var dimem = ParseUtil_js_1.default.dimen2em(rows[0]);
  836. this.setProperty('rowspacing', dimem);
  837. }
  838. var rowspacing = this.getProperty('rowspacing');
  839. while (rows.length < this.table.length) {
  840. rows.push(ParseUtil_js_1.default.Em(rowspacing));
  841. }
  842. rows[this.table.length - 1] = ParseUtil_js_1.default.Em(Math.max(0, rowspacing + ParseUtil_js_1.default.dimen2em(spacing)));
  843. this.arraydef['rowspacing'] = rows.join(' ');
  844. }
  845. };
  846. return ArrayItem;
  847. }(StackItem_js_1.BaseItem));
  848. exports.ArrayItem = ArrayItem;
  849. var EqnArrayItem = (function (_super) {
  850. __extends(EqnArrayItem, _super);
  851. function EqnArrayItem(factory) {
  852. var args = [];
  853. for (var _i = 1; _i < arguments.length; _i++) {
  854. args[_i - 1] = arguments[_i];
  855. }
  856. var _this = _super.call(this, factory) || this;
  857. _this.maxrow = 0;
  858. _this.factory.configuration.tags.start(args[0], args[2], args[1]);
  859. return _this;
  860. }
  861. Object.defineProperty(EqnArrayItem.prototype, "kind", {
  862. get: function () {
  863. return 'eqnarray';
  864. },
  865. enumerable: false,
  866. configurable: true
  867. });
  868. EqnArrayItem.prototype.EndEntry = function () {
  869. if (this.row.length) {
  870. ParseUtil_js_1.default.fixInitialMO(this.factory.configuration, this.nodes);
  871. }
  872. var node = this.create('node', 'mtd', this.nodes);
  873. this.row.push(node);
  874. this.Clear();
  875. };
  876. EqnArrayItem.prototype.EndRow = function () {
  877. if (this.row.length > this.maxrow) {
  878. this.maxrow = this.row.length;
  879. }
  880. var mtr = 'mtr';
  881. var tag = this.factory.configuration.tags.getTag();
  882. if (tag) {
  883. this.row = [tag].concat(this.row);
  884. mtr = 'mlabeledtr';
  885. }
  886. this.factory.configuration.tags.clearTag();
  887. var node = this.create('node', mtr, this.row);
  888. this.table.push(node);
  889. this.row = [];
  890. };
  891. EqnArrayItem.prototype.EndTable = function () {
  892. _super.prototype.EndTable.call(this);
  893. this.factory.configuration.tags.end();
  894. this.extendArray('columnalign', this.maxrow);
  895. this.extendArray('columnwidth', this.maxrow);
  896. this.extendArray('columnspacing', this.maxrow - 1);
  897. };
  898. EqnArrayItem.prototype.extendArray = function (name, max) {
  899. if (!this.arraydef[name])
  900. return;
  901. var repeat = this.arraydef[name].split(/ /);
  902. var columns = __spreadArray([], __read(repeat), false);
  903. if (columns.length > 1) {
  904. while (columns.length < max) {
  905. columns.push.apply(columns, __spreadArray([], __read(repeat), false));
  906. }
  907. this.arraydef[name] = columns.slice(0, max).join(' ');
  908. }
  909. };
  910. return EqnArrayItem;
  911. }(ArrayItem));
  912. exports.EqnArrayItem = EqnArrayItem;
  913. var EquationItem = (function (_super) {
  914. __extends(EquationItem, _super);
  915. function EquationItem(factory) {
  916. var args = [];
  917. for (var _i = 1; _i < arguments.length; _i++) {
  918. args[_i - 1] = arguments[_i];
  919. }
  920. var _this = _super.call(this, factory) || this;
  921. _this.factory.configuration.tags.start('equation', true, args[0]);
  922. return _this;
  923. }
  924. Object.defineProperty(EquationItem.prototype, "kind", {
  925. get: function () {
  926. return 'equation';
  927. },
  928. enumerable: false,
  929. configurable: true
  930. });
  931. Object.defineProperty(EquationItem.prototype, "isOpen", {
  932. get: function () {
  933. return true;
  934. },
  935. enumerable: false,
  936. configurable: true
  937. });
  938. EquationItem.prototype.checkItem = function (item) {
  939. if (item.isKind('end')) {
  940. var mml = this.toMml();
  941. var tag = this.factory.configuration.tags.getTag();
  942. this.factory.configuration.tags.end();
  943. return [[tag ? this.factory.configuration.tags.enTag(mml, tag) : mml, item], true];
  944. }
  945. if (item.isKind('stop')) {
  946. throw new TexError_js_1.default('EnvMissingEnd', 'Missing \\end{%1}', this.getName());
  947. }
  948. return _super.prototype.checkItem.call(this, item);
  949. };
  950. return EquationItem;
  951. }(StackItem_js_1.BaseItem));
  952. exports.EquationItem = EquationItem;
  953. //# sourceMappingURL=BaseItems.js.map