mtable.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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 __values = (this && this.__values) || function(o) {
  43. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  44. if (m) return m.call(o);
  45. if (o && typeof o.length === "number") return {
  46. next: function () {
  47. if (o && i >= o.length) o = void 0;
  48. return { value: o && o[i++], done: !o };
  49. }
  50. };
  51. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  52. };
  53. Object.defineProperty(exports, "__esModule", { value: true });
  54. exports.CommonMtableMixin = void 0;
  55. var BBox_js_1 = require("../../../util/BBox.js");
  56. var string_js_1 = require("../../../util/string.js");
  57. var numeric_js_1 = require("../../../util/numeric.js");
  58. function CommonMtableMixin(Base) {
  59. return (function (_super) {
  60. __extends(class_1, _super);
  61. function class_1() {
  62. var args = [];
  63. for (var _i = 0; _i < arguments.length; _i++) {
  64. args[_i] = arguments[_i];
  65. }
  66. var _this = _super.apply(this, __spreadArray([], __read(args), false)) || this;
  67. _this.numCols = 0;
  68. _this.numRows = 0;
  69. _this.data = null;
  70. _this.pwidthCells = [];
  71. _this.pWidth = 0;
  72. _this.numCols = (0, numeric_js_1.max)(_this.tableRows.map(function (row) { return row.numCells; }));
  73. _this.numRows = _this.childNodes.length;
  74. _this.hasLabels = _this.childNodes.reduce(function (value, row) { return value || row.node.isKind('mlabeledtr'); }, false);
  75. _this.findContainer();
  76. _this.isTop = !_this.container || (_this.container.node.isKind('math') && !_this.container.parent);
  77. if (_this.isTop) {
  78. _this.jax.table = _this;
  79. }
  80. _this.getPercentageWidth();
  81. var attributes = _this.node.attributes;
  82. _this.frame = attributes.get('frame') !== 'none';
  83. _this.fLine = (_this.frame && attributes.get('frame') ? .07 : 0);
  84. _this.fSpace = (_this.frame ? _this.convertLengths(_this.getAttributeArray('framespacing')) : [0, 0]);
  85. _this.cSpace = _this.convertLengths(_this.getColumnAttributes('columnspacing'));
  86. _this.rSpace = _this.convertLengths(_this.getRowAttributes('rowspacing'));
  87. _this.cLines = _this.getColumnAttributes('columnlines').map(function (x) { return (x === 'none' ? 0 : .07); });
  88. _this.rLines = _this.getRowAttributes('rowlines').map(function (x) { return (x === 'none' ? 0 : .07); });
  89. _this.cWidths = _this.getColumnWidths();
  90. _this.stretchRows();
  91. _this.stretchColumns();
  92. return _this;
  93. }
  94. Object.defineProperty(class_1.prototype, "tableRows", {
  95. get: function () {
  96. return this.childNodes;
  97. },
  98. enumerable: false,
  99. configurable: true
  100. });
  101. class_1.prototype.findContainer = function () {
  102. var node = this;
  103. var parent = node.parent;
  104. while (parent && (parent.node.notParent || parent.node.isKind('mrow'))) {
  105. node = parent;
  106. parent = parent.parent;
  107. }
  108. this.container = parent;
  109. this.containerI = node.node.childPosition();
  110. };
  111. class_1.prototype.getPercentageWidth = function () {
  112. if (this.hasLabels) {
  113. this.bbox.pwidth = BBox_js_1.BBox.fullWidth;
  114. }
  115. else {
  116. var width = this.node.attributes.get('width');
  117. if ((0, string_js_1.isPercent)(width)) {
  118. this.bbox.pwidth = width;
  119. }
  120. }
  121. };
  122. class_1.prototype.stretchRows = function () {
  123. var equal = this.node.attributes.get('equalrows');
  124. var HD = (equal ? this.getEqualRowHeight() : 0);
  125. var _a = (equal ? this.getTableData() : { H: [0], D: [0] }), H = _a.H, D = _a.D;
  126. var rows = this.tableRows;
  127. for (var i = 0; i < this.numRows; i++) {
  128. var hd = (equal ? [(HD + H[i] - D[i]) / 2, (HD - H[i] + D[i]) / 2] : null);
  129. rows[i].stretchChildren(hd);
  130. }
  131. };
  132. class_1.prototype.stretchColumns = function () {
  133. for (var i = 0; i < this.numCols; i++) {
  134. var width = (typeof this.cWidths[i] === 'number' ? this.cWidths[i] : null);
  135. this.stretchColumn(i, width);
  136. }
  137. };
  138. class_1.prototype.stretchColumn = function (i, W) {
  139. var e_1, _a, e_2, _b, e_3, _c;
  140. var stretchy = [];
  141. try {
  142. for (var _d = __values(this.tableRows), _e = _d.next(); !_e.done; _e = _d.next()) {
  143. var row = _e.value;
  144. var cell = row.getChild(i);
  145. if (cell) {
  146. var child = cell.childNodes[0];
  147. if (child.stretch.dir === 0 &&
  148. child.canStretch(2)) {
  149. stretchy.push(child);
  150. }
  151. }
  152. }
  153. }
  154. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  155. finally {
  156. try {
  157. if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
  158. }
  159. finally { if (e_1) throw e_1.error; }
  160. }
  161. var count = stretchy.length;
  162. var nodeCount = this.childNodes.length;
  163. if (count && nodeCount > 1) {
  164. if (W === null) {
  165. W = 0;
  166. var all = (count > 1 && count === nodeCount);
  167. try {
  168. for (var _f = __values(this.tableRows), _g = _f.next(); !_g.done; _g = _f.next()) {
  169. var row = _g.value;
  170. var cell = row.getChild(i);
  171. if (cell) {
  172. var child = cell.childNodes[0];
  173. var noStretch = (child.stretch.dir === 0);
  174. if (all || noStretch) {
  175. var w = child.getBBox(noStretch).w;
  176. if (w > W) {
  177. W = w;
  178. }
  179. }
  180. }
  181. }
  182. }
  183. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  184. finally {
  185. try {
  186. if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
  187. }
  188. finally { if (e_2) throw e_2.error; }
  189. }
  190. }
  191. try {
  192. for (var stretchy_1 = __values(stretchy), stretchy_1_1 = stretchy_1.next(); !stretchy_1_1.done; stretchy_1_1 = stretchy_1.next()) {
  193. var child = stretchy_1_1.value;
  194. child.coreMO().getStretchedVariant([W]);
  195. }
  196. }
  197. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  198. finally {
  199. try {
  200. if (stretchy_1_1 && !stretchy_1_1.done && (_c = stretchy_1.return)) _c.call(stretchy_1);
  201. }
  202. finally { if (e_3) throw e_3.error; }
  203. }
  204. }
  205. };
  206. class_1.prototype.getTableData = function () {
  207. if (this.data) {
  208. return this.data;
  209. }
  210. var H = new Array(this.numRows).fill(0);
  211. var D = new Array(this.numRows).fill(0);
  212. var W = new Array(this.numCols).fill(0);
  213. var NH = new Array(this.numRows);
  214. var ND = new Array(this.numRows);
  215. var LW = [0];
  216. var rows = this.tableRows;
  217. for (var j = 0; j < rows.length; j++) {
  218. var M = 0;
  219. var row = rows[j];
  220. var align = row.node.attributes.get('rowalign');
  221. for (var i = 0; i < row.numCells; i++) {
  222. var cell = row.getChild(i);
  223. M = this.updateHDW(cell, i, j, align, H, D, W, M);
  224. this.recordPWidthCell(cell, i);
  225. }
  226. NH[j] = H[j];
  227. ND[j] = D[j];
  228. if (row.labeled) {
  229. M = this.updateHDW(row.childNodes[0], 0, j, align, H, D, LW, M);
  230. }
  231. this.extendHD(j, H, D, M);
  232. this.extendHD(j, NH, ND, M);
  233. }
  234. var L = LW[0];
  235. this.data = { H: H, D: D, W: W, NH: NH, ND: ND, L: L };
  236. return this.data;
  237. };
  238. class_1.prototype.updateHDW = function (cell, i, j, align, H, D, W, M) {
  239. var _a = cell.getBBox(), h = _a.h, d = _a.d, w = _a.w;
  240. var scale = cell.parent.bbox.rscale;
  241. if (cell.parent.bbox.rscale !== 1) {
  242. h *= scale;
  243. d *= scale;
  244. w *= scale;
  245. }
  246. if (this.node.getProperty('useHeight')) {
  247. if (h < .75)
  248. h = .75;
  249. if (d < .25)
  250. d = .25;
  251. }
  252. var m = 0;
  253. align = cell.node.attributes.get('rowalign') || align;
  254. if (align !== 'baseline' && align !== 'axis') {
  255. m = h + d;
  256. h = d = 0;
  257. }
  258. if (h > H[j])
  259. H[j] = h;
  260. if (d > D[j])
  261. D[j] = d;
  262. if (m > M)
  263. M = m;
  264. if (W && w > W[i])
  265. W[i] = w;
  266. return M;
  267. };
  268. class_1.prototype.extendHD = function (i, H, D, M) {
  269. var d = (M - (H[i] + D[i])) / 2;
  270. if (d < .00001)
  271. return;
  272. H[i] += d;
  273. D[i] += d;
  274. };
  275. class_1.prototype.recordPWidthCell = function (cell, i) {
  276. if (cell.childNodes[0] && cell.childNodes[0].getBBox().pwidth) {
  277. this.pwidthCells.push([cell, i]);
  278. }
  279. };
  280. class_1.prototype.computeBBox = function (bbox, _recompute) {
  281. if (_recompute === void 0) { _recompute = false; }
  282. var _a = this.getTableData(), H = _a.H, D = _a.D;
  283. var height, width;
  284. if (this.node.attributes.get('equalrows')) {
  285. var HD = this.getEqualRowHeight();
  286. height = (0, numeric_js_1.sum)([].concat(this.rLines, this.rSpace)) + HD * this.numRows;
  287. }
  288. else {
  289. height = (0, numeric_js_1.sum)(H.concat(D, this.rLines, this.rSpace));
  290. }
  291. height += 2 * (this.fLine + this.fSpace[1]);
  292. var CW = this.getComputedWidths();
  293. width = (0, numeric_js_1.sum)(CW.concat(this.cLines, this.cSpace)) + 2 * (this.fLine + this.fSpace[0]);
  294. var w = this.node.attributes.get('width');
  295. if (w !== 'auto') {
  296. width = Math.max(this.length2em(w, 0) + 2 * this.fLine, width);
  297. }
  298. var _b = __read(this.getBBoxHD(height), 2), h = _b[0], d = _b[1];
  299. bbox.h = h;
  300. bbox.d = d;
  301. bbox.w = width;
  302. var _c = __read(this.getBBoxLR(), 2), L = _c[0], R = _c[1];
  303. bbox.L = L;
  304. bbox.R = R;
  305. if (!(0, string_js_1.isPercent)(w)) {
  306. this.setColumnPWidths();
  307. }
  308. };
  309. class_1.prototype.setChildPWidths = function (_recompute, cwidth, _clear) {
  310. var width = this.node.attributes.get('width');
  311. if (!(0, string_js_1.isPercent)(width))
  312. return false;
  313. if (!this.hasLabels) {
  314. this.bbox.pwidth = '';
  315. this.container.bbox.pwidth = '';
  316. }
  317. var _a = this.bbox, w = _a.w, L = _a.L, R = _a.R;
  318. var labelInWidth = this.node.attributes.get('data-width-includes-label');
  319. var W = Math.max(w, this.length2em(width, Math.max(cwidth, L + w + R))) - (labelInWidth ? L + R : 0);
  320. var cols = (this.node.attributes.get('equalcolumns') ?
  321. Array(this.numCols).fill(this.percent(1 / Math.max(1, this.numCols))) :
  322. this.getColumnAttributes('columnwidth', 0));
  323. this.cWidths = this.getColumnWidthsFixed(cols, W);
  324. var CW = this.getComputedWidths();
  325. this.pWidth = (0, numeric_js_1.sum)(CW.concat(this.cLines, this.cSpace)) + 2 * (this.fLine + this.fSpace[0]);
  326. if (this.isTop) {
  327. this.bbox.w = this.pWidth;
  328. }
  329. this.setColumnPWidths();
  330. if (this.pWidth !== w) {
  331. this.parent.invalidateBBox();
  332. }
  333. return this.pWidth !== w;
  334. };
  335. class_1.prototype.setColumnPWidths = function () {
  336. var e_4, _a;
  337. var W = this.cWidths;
  338. try {
  339. for (var _b = __values(this.pwidthCells), _c = _b.next(); !_c.done; _c = _b.next()) {
  340. var _d = __read(_c.value, 2), cell = _d[0], i = _d[1];
  341. if (cell.setChildPWidths(false, W[i])) {
  342. cell.invalidateBBox();
  343. cell.getBBox();
  344. }
  345. }
  346. }
  347. catch (e_4_1) { e_4 = { error: e_4_1 }; }
  348. finally {
  349. try {
  350. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  351. }
  352. finally { if (e_4) throw e_4.error; }
  353. }
  354. };
  355. class_1.prototype.getBBoxHD = function (height) {
  356. var _a = __read(this.getAlignmentRow(), 2), align = _a[0], row = _a[1];
  357. if (row === null) {
  358. var a = this.font.params.axis_height;
  359. var h2 = height / 2;
  360. var HD = {
  361. top: [0, height],
  362. center: [h2, h2],
  363. bottom: [height, 0],
  364. baseline: [h2, h2],
  365. axis: [h2 + a, h2 - a]
  366. };
  367. return HD[align] || [h2, h2];
  368. }
  369. else {
  370. var y = this.getVerticalPosition(row, align);
  371. return [y, height - y];
  372. }
  373. };
  374. class_1.prototype.getBBoxLR = function () {
  375. if (this.hasLabels) {
  376. var attributes = this.node.attributes;
  377. var side = attributes.get('side');
  378. var _a = __read(this.getPadAlignShift(side), 2), pad = _a[0], align = _a[1];
  379. var labels = this.hasLabels && !!attributes.get('data-width-includes-label');
  380. if (labels && this.frame && this.fSpace[0]) {
  381. pad -= this.fSpace[0];
  382. }
  383. return (align === 'center' && !labels ? [pad, pad] :
  384. side === 'left' ? [pad, 0] : [0, pad]);
  385. }
  386. return [0, 0];
  387. };
  388. class_1.prototype.getPadAlignShift = function (side) {
  389. var L = this.getTableData().L;
  390. var sep = this.length2em(this.node.attributes.get('minlabelspacing'));
  391. var pad = L + sep;
  392. var _a = __read((this.styles == null ? ['', ''] :
  393. [this.styles.get('padding-left'), this.styles.get('padding-right')]), 2), lpad = _a[0], rpad = _a[1];
  394. if (lpad || rpad) {
  395. pad = Math.max(pad, this.length2em(lpad || '0'), this.length2em(rpad || '0'));
  396. }
  397. var _b = __read(this.getAlignShift(), 2), align = _b[0], shift = _b[1];
  398. if (align === side) {
  399. shift = (side === 'left' ? Math.max(pad, shift) - pad : Math.min(-pad, shift) + pad);
  400. }
  401. return [pad, align, shift];
  402. };
  403. class_1.prototype.getAlignShift = function () {
  404. return (this.isTop ? _super.prototype.getAlignShift.call(this) :
  405. [this.container.getChildAlign(this.containerI), 0]);
  406. };
  407. class_1.prototype.getWidth = function () {
  408. return this.pWidth || this.getBBox().w;
  409. };
  410. class_1.prototype.getEqualRowHeight = function () {
  411. var _a = this.getTableData(), H = _a.H, D = _a.D;
  412. var HD = Array.from(H.keys()).map(function (i) { return H[i] + D[i]; });
  413. return Math.max.apply(Math, HD);
  414. };
  415. class_1.prototype.getComputedWidths = function () {
  416. var _this = this;
  417. var W = this.getTableData().W;
  418. var CW = Array.from(W.keys()).map(function (i) {
  419. return (typeof _this.cWidths[i] === 'number' ? _this.cWidths[i] : W[i]);
  420. });
  421. if (this.node.attributes.get('equalcolumns')) {
  422. CW = Array(CW.length).fill((0, numeric_js_1.max)(CW));
  423. }
  424. return CW;
  425. };
  426. class_1.prototype.getColumnWidths = function () {
  427. var width = this.node.attributes.get('width');
  428. if (this.node.attributes.get('equalcolumns')) {
  429. return this.getEqualColumns(width);
  430. }
  431. var swidths = this.getColumnAttributes('columnwidth', 0);
  432. if (width === 'auto') {
  433. return this.getColumnWidthsAuto(swidths);
  434. }
  435. if ((0, string_js_1.isPercent)(width)) {
  436. return this.getColumnWidthsPercent(swidths);
  437. }
  438. return this.getColumnWidthsFixed(swidths, this.length2em(width));
  439. };
  440. class_1.prototype.getEqualColumns = function (width) {
  441. var n = Math.max(1, this.numCols);
  442. var cwidth;
  443. if (width === 'auto') {
  444. var W = this.getTableData().W;
  445. cwidth = (0, numeric_js_1.max)(W);
  446. }
  447. else if ((0, string_js_1.isPercent)(width)) {
  448. cwidth = this.percent(1 / n);
  449. }
  450. else {
  451. var w = (0, numeric_js_1.sum)([].concat(this.cLines, this.cSpace)) + 2 * this.fSpace[0];
  452. cwidth = Math.max(0, this.length2em(width) - w) / n;
  453. }
  454. return Array(this.numCols).fill(cwidth);
  455. };
  456. class_1.prototype.getColumnWidthsAuto = function (swidths) {
  457. var _this = this;
  458. return swidths.map(function (x) {
  459. if (x === 'auto' || x === 'fit')
  460. return null;
  461. if ((0, string_js_1.isPercent)(x))
  462. return x;
  463. return _this.length2em(x);
  464. });
  465. };
  466. class_1.prototype.getColumnWidthsPercent = function (swidths) {
  467. var _this = this;
  468. var hasFit = swidths.indexOf('fit') >= 0;
  469. var W = (hasFit ? this.getTableData() : { W: null }).W;
  470. return Array.from(swidths.keys()).map(function (i) {
  471. var x = swidths[i];
  472. if (x === 'fit')
  473. return null;
  474. if (x === 'auto')
  475. return (hasFit ? W[i] : null);
  476. if ((0, string_js_1.isPercent)(x))
  477. return x;
  478. return _this.length2em(x);
  479. });
  480. };
  481. class_1.prototype.getColumnWidthsFixed = function (swidths, width) {
  482. var _this = this;
  483. var indices = Array.from(swidths.keys());
  484. var fit = indices.filter(function (i) { return swidths[i] === 'fit'; });
  485. var auto = indices.filter(function (i) { return swidths[i] === 'auto'; });
  486. var n = fit.length || auto.length;
  487. var W = (n ? this.getTableData() : { W: null }).W;
  488. var cwidth = width - (0, numeric_js_1.sum)([].concat(this.cLines, this.cSpace)) - 2 * this.fSpace[0];
  489. var dw = cwidth;
  490. indices.forEach(function (i) {
  491. var x = swidths[i];
  492. dw -= (x === 'fit' || x === 'auto' ? W[i] : _this.length2em(x, cwidth));
  493. });
  494. var fw = (n && dw > 0 ? dw / n : 0);
  495. return indices.map(function (i) {
  496. var x = swidths[i];
  497. if (x === 'fit')
  498. return W[i] + fw;
  499. if (x === 'auto')
  500. return W[i] + (fit.length === 0 ? fw : 0);
  501. return _this.length2em(x, cwidth);
  502. });
  503. };
  504. class_1.prototype.getVerticalPosition = function (i, align) {
  505. var equal = this.node.attributes.get('equalrows');
  506. var _a = this.getTableData(), H = _a.H, D = _a.D;
  507. var HD = (equal ? this.getEqualRowHeight() : 0);
  508. var space = this.getRowHalfSpacing();
  509. var y = this.fLine;
  510. for (var j = 0; j < i; j++) {
  511. y += space[j] + (equal ? HD : H[j] + D[j]) + space[j + 1] + this.rLines[j];
  512. }
  513. var _b = __read((equal ? [(HD + H[i] - D[i]) / 2, (HD - H[i] + D[i]) / 2] : [H[i], D[i]]), 2), h = _b[0], d = _b[1];
  514. var offset = {
  515. top: 0,
  516. center: space[i] + (h + d) / 2,
  517. bottom: space[i] + h + d + space[i + 1],
  518. baseline: space[i] + h,
  519. axis: space[i] + h - .25
  520. };
  521. y += offset[align] || 0;
  522. return y;
  523. };
  524. class_1.prototype.getEmHalfSpacing = function (fspace, space, scale) {
  525. if (scale === void 0) { scale = 1; }
  526. var fspaceEm = this.em(fspace * scale);
  527. var spaceEm = this.addEm(space, 2 / scale);
  528. spaceEm.unshift(fspaceEm);
  529. spaceEm.push(fspaceEm);
  530. return spaceEm;
  531. };
  532. class_1.prototype.getRowHalfSpacing = function () {
  533. var space = this.rSpace.map(function (x) { return x / 2; });
  534. space.unshift(this.fSpace[1]);
  535. space.push(this.fSpace[1]);
  536. return space;
  537. };
  538. class_1.prototype.getColumnHalfSpacing = function () {
  539. var space = this.cSpace.map(function (x) { return x / 2; });
  540. space.unshift(this.fSpace[0]);
  541. space.push(this.fSpace[0]);
  542. return space;
  543. };
  544. class_1.prototype.getAlignmentRow = function () {
  545. var _a = __read((0, string_js_1.split)(this.node.attributes.get('align')), 2), align = _a[0], row = _a[1];
  546. if (row == null)
  547. return [align, null];
  548. var i = parseInt(row);
  549. if (i < 0)
  550. i += this.numRows + 1;
  551. return [align, i < 1 || i > this.numRows ? null : i - 1];
  552. };
  553. class_1.prototype.getColumnAttributes = function (name, i) {
  554. if (i === void 0) { i = 1; }
  555. var n = this.numCols - i;
  556. var columns = this.getAttributeArray(name);
  557. if (columns.length === 0)
  558. return null;
  559. while (columns.length < n) {
  560. columns.push(columns[columns.length - 1]);
  561. }
  562. if (columns.length > n) {
  563. columns.splice(n);
  564. }
  565. return columns;
  566. };
  567. class_1.prototype.getRowAttributes = function (name, i) {
  568. if (i === void 0) { i = 1; }
  569. var n = this.numRows - i;
  570. var rows = this.getAttributeArray(name);
  571. if (rows.length === 0)
  572. return null;
  573. while (rows.length < n) {
  574. rows.push(rows[rows.length - 1]);
  575. }
  576. if (rows.length > n) {
  577. rows.splice(n);
  578. }
  579. return rows;
  580. };
  581. class_1.prototype.getAttributeArray = function (name) {
  582. var value = this.node.attributes.get(name);
  583. if (!value)
  584. return [this.node.attributes.getDefault(name)];
  585. return (0, string_js_1.split)(value);
  586. };
  587. class_1.prototype.addEm = function (list, n) {
  588. var _this = this;
  589. if (n === void 0) { n = 1; }
  590. if (!list)
  591. return null;
  592. return list.map(function (x) { return _this.em(x / n); });
  593. };
  594. class_1.prototype.convertLengths = function (list) {
  595. var _this = this;
  596. if (!list)
  597. return null;
  598. return list.map(function (x) { return _this.length2em(x); });
  599. };
  600. return class_1;
  601. }(Base));
  602. }
  603. exports.CommonMtableMixin = CommonMtableMixin;
  604. //# sourceMappingURL=mtable.js.map