mmultiscripts.js 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. Object.defineProperty(exports, "__esModule", { value: true });
  34. exports.SVGmmultiscripts = exports.AlignX = void 0;
  35. var msubsup_js_1 = require("./msubsup.js");
  36. var mmultiscripts_js_1 = require("../../common/Wrappers/mmultiscripts.js");
  37. var mmultiscripts_js_2 = require("../../../core/MmlTree/MmlNodes/mmultiscripts.js");
  38. var string_js_1 = require("../../../util/string.js");
  39. function AlignX(align) {
  40. return {
  41. left: function (_w, _W) { return 0; },
  42. center: function (w, W) { return (W - w) / 2; },
  43. right: function (w, W) { return W - w; }
  44. }[align] || (function (_w, _W) { return 0; });
  45. }
  46. exports.AlignX = AlignX;
  47. var SVGmmultiscripts = (function (_super) {
  48. __extends(SVGmmultiscripts, _super);
  49. function SVGmmultiscripts() {
  50. return _super !== null && _super.apply(this, arguments) || this;
  51. }
  52. SVGmmultiscripts.prototype.toSVG = function (parent) {
  53. var svg = this.standardSVGnode(parent);
  54. var data = this.scriptData;
  55. var scriptalign = this.node.getProperty('scriptalign') || 'right left';
  56. var _a = __read((0, string_js_1.split)(scriptalign + ' ' + scriptalign), 2), preAlign = _a[0], postAlign = _a[1];
  57. var sub = this.combinePrePost(data.sub, data.psub);
  58. var sup = this.combinePrePost(data.sup, data.psup);
  59. var _b = __read(this.getUVQ(sub, sup), 2), u = _b[0], v = _b[1];
  60. var x = 0;
  61. if (data.numPrescripts) {
  62. x = this.addScripts(.05, u, v, this.firstPrescript, data.numPrescripts, preAlign);
  63. }
  64. var base = this.baseChild;
  65. base.toSVG(svg);
  66. base.place(x, 0);
  67. x += base.getOuterBBox().w;
  68. if (data.numScripts) {
  69. this.addScripts(x, u, v, 1, data.numScripts, postAlign);
  70. }
  71. };
  72. SVGmmultiscripts.prototype.addScripts = function (x, u, v, i, n, align) {
  73. var adaptor = this.adaptor;
  74. var alignX = AlignX(align);
  75. var supRow = adaptor.append(this.element, this.svg('g'));
  76. var subRow = adaptor.append(this.element, this.svg('g'));
  77. this.place(x, u, supRow);
  78. this.place(x, v, subRow);
  79. var m = i + 2 * n;
  80. var dx = 0;
  81. while (i < m) {
  82. var _a = __read([this.childNodes[i++], this.childNodes[i++]], 2), sub = _a[0], sup = _a[1];
  83. var _b = __read([sub.getOuterBBox(), sup.getOuterBBox()], 2), subbox = _b[0], supbox = _b[1];
  84. var _c = __read([subbox.rscale, supbox.rscale], 2), subr = _c[0], supr = _c[1];
  85. var w = Math.max(subbox.w * subr, supbox.w * supr);
  86. sub.toSVG(subRow);
  87. sup.toSVG(supRow);
  88. sub.place(dx + alignX(subbox.w * subr, w), 0);
  89. sup.place(dx + alignX(supbox.w * supr, w), 0);
  90. dx += w;
  91. }
  92. return x + dx;
  93. };
  94. SVGmmultiscripts.kind = mmultiscripts_js_2.MmlMmultiscripts.prototype.kind;
  95. return SVGmmultiscripts;
  96. }((0, mmultiscripts_js_1.CommonMmultiscriptsMixin)(msubsup_js_1.SVGmsubsup)));
  97. exports.SVGmmultiscripts = SVGmmultiscripts;
  98. //# sourceMappingURL=mmultiscripts.js.map