AmsItems.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 __importDefault = (this && this.__importDefault) || function (mod) {
  29. return (mod && mod.__esModule) ? mod : { "default": mod };
  30. };
  31. Object.defineProperty(exports, "__esModule", { value: true });
  32. exports.FlalignItem = exports.MultlineItem = void 0;
  33. var BaseItems_js_1 = require("../base/BaseItems.js");
  34. var ParseUtil_js_1 = __importDefault(require("../ParseUtil.js"));
  35. var NodeUtil_js_1 = __importDefault(require("../NodeUtil.js"));
  36. var TexError_js_1 = __importDefault(require("../TexError.js"));
  37. var TexConstants_js_1 = require("../TexConstants.js");
  38. var MultlineItem = (function (_super) {
  39. __extends(MultlineItem, _super);
  40. function MultlineItem(factory) {
  41. var args = [];
  42. for (var _i = 1; _i < arguments.length; _i++) {
  43. args[_i - 1] = arguments[_i];
  44. }
  45. var _this = _super.call(this, factory) || this;
  46. _this.factory.configuration.tags.start('multline', true, args[0]);
  47. return _this;
  48. }
  49. Object.defineProperty(MultlineItem.prototype, "kind", {
  50. get: function () {
  51. return 'multline';
  52. },
  53. enumerable: false,
  54. configurable: true
  55. });
  56. MultlineItem.prototype.EndEntry = function () {
  57. if (this.table.length) {
  58. ParseUtil_js_1.default.fixInitialMO(this.factory.configuration, this.nodes);
  59. }
  60. var shove = this.getProperty('shove');
  61. var mtd = this.create('node', 'mtd', this.nodes, shove ? { columnalign: shove } : {});
  62. this.setProperty('shove', null);
  63. this.row.push(mtd);
  64. this.Clear();
  65. };
  66. MultlineItem.prototype.EndRow = function () {
  67. if (this.row.length !== 1) {
  68. throw new TexError_js_1.default('MultlineRowsOneCol', 'The rows within the %1 environment must have exactly one column', 'multline');
  69. }
  70. var row = this.create('node', 'mtr', this.row);
  71. this.table.push(row);
  72. this.row = [];
  73. };
  74. MultlineItem.prototype.EndTable = function () {
  75. _super.prototype.EndTable.call(this);
  76. if (this.table.length) {
  77. var m = this.table.length - 1, label = -1;
  78. if (!NodeUtil_js_1.default.getAttribute(NodeUtil_js_1.default.getChildren(this.table[0])[0], 'columnalign')) {
  79. NodeUtil_js_1.default.setAttribute(NodeUtil_js_1.default.getChildren(this.table[0])[0], 'columnalign', TexConstants_js_1.TexConstant.Align.LEFT);
  80. }
  81. if (!NodeUtil_js_1.default.getAttribute(NodeUtil_js_1.default.getChildren(this.table[m])[0], 'columnalign')) {
  82. NodeUtil_js_1.default.setAttribute(NodeUtil_js_1.default.getChildren(this.table[m])[0], 'columnalign', TexConstants_js_1.TexConstant.Align.RIGHT);
  83. }
  84. var tag = this.factory.configuration.tags.getTag();
  85. if (tag) {
  86. label = (this.arraydef.side === TexConstants_js_1.TexConstant.Align.LEFT ? 0 : this.table.length - 1);
  87. var mtr = this.table[label];
  88. var mlabel = this.create('node', 'mlabeledtr', [tag].concat(NodeUtil_js_1.default.getChildren(mtr)));
  89. NodeUtil_js_1.default.copyAttributes(mtr, mlabel);
  90. this.table[label] = mlabel;
  91. }
  92. }
  93. this.factory.configuration.tags.end();
  94. };
  95. return MultlineItem;
  96. }(BaseItems_js_1.ArrayItem));
  97. exports.MultlineItem = MultlineItem;
  98. var FlalignItem = (function (_super) {
  99. __extends(FlalignItem, _super);
  100. function FlalignItem(factory, name, numbered, padded, center) {
  101. var _this = _super.call(this, factory) || this;
  102. _this.name = name;
  103. _this.numbered = numbered;
  104. _this.padded = padded;
  105. _this.center = center;
  106. _this.factory.configuration.tags.start(name, numbered, numbered);
  107. return _this;
  108. }
  109. Object.defineProperty(FlalignItem.prototype, "kind", {
  110. get: function () {
  111. return 'flalign';
  112. },
  113. enumerable: false,
  114. configurable: true
  115. });
  116. FlalignItem.prototype.EndEntry = function () {
  117. _super.prototype.EndEntry.call(this);
  118. var n = this.getProperty('xalignat');
  119. if (!n)
  120. return;
  121. if (this.row.length > n) {
  122. throw new TexError_js_1.default('XalignOverflow', 'Extra %1 in row of %2', '&', this.name);
  123. }
  124. };
  125. FlalignItem.prototype.EndRow = function () {
  126. var cell;
  127. var row = this.row;
  128. var n = this.getProperty('xalignat');
  129. while (row.length < n) {
  130. row.push(this.create('node', 'mtd'));
  131. }
  132. this.row = [];
  133. if (this.padded) {
  134. this.row.push(this.create('node', 'mtd'));
  135. }
  136. while ((cell = row.shift())) {
  137. this.row.push(cell);
  138. cell = row.shift();
  139. if (cell)
  140. this.row.push(cell);
  141. if (row.length || this.padded) {
  142. this.row.push(this.create('node', 'mtd'));
  143. }
  144. }
  145. if (this.row.length > this.maxrow) {
  146. this.maxrow = this.row.length;
  147. }
  148. _super.prototype.EndRow.call(this);
  149. var mtr = this.table[this.table.length - 1];
  150. if (this.getProperty('zeroWidthLabel') && mtr.isKind('mlabeledtr')) {
  151. var mtd = NodeUtil_js_1.default.getChildren(mtr)[0];
  152. var side = this.factory.configuration.options['tagSide'];
  153. var def = __assign({ width: 0 }, (side === 'right' ? { lspace: '-1width' } : {}));
  154. var mpadded = this.create('node', 'mpadded', NodeUtil_js_1.default.getChildren(mtd), def);
  155. mtd.setChildren([mpadded]);
  156. }
  157. };
  158. FlalignItem.prototype.EndTable = function () {
  159. _super.prototype.EndTable.call(this);
  160. if (this.center) {
  161. if (this.maxrow <= 2) {
  162. var def = this.arraydef;
  163. delete def.width;
  164. delete this.global.indentalign;
  165. }
  166. }
  167. };
  168. return FlalignItem;
  169. }(BaseItems_js_1.EqnArrayItem));
  170. exports.FlalignItem = FlalignItem;
  171. //# sourceMappingURL=AmsItems.js.map