math.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 __values = (this && this.__values) || function(o) {
  34. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  35. if (m) return m.call(o);
  36. if (o && typeof o.length === "number") return {
  37. next: function () {
  38. if (o && i >= o.length) o = void 0;
  39. return { value: o && o[i++], done: !o };
  40. }
  41. };
  42. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  43. };
  44. Object.defineProperty(exports, "__esModule", { value: true });
  45. exports.SVGmath = void 0;
  46. var Wrapper_js_1 = require("../Wrapper.js");
  47. var math_js_1 = require("../../common/Wrappers/math.js");
  48. var math_js_2 = require("../../../core/MmlTree/MmlNodes/math.js");
  49. var BBox_js_1 = require("../../../util/BBox.js");
  50. var SVGmath = (function (_super) {
  51. __extends(SVGmath, _super);
  52. function SVGmath() {
  53. return _super !== null && _super.apply(this, arguments) || this;
  54. }
  55. SVGmath.prototype.toSVG = function (parent) {
  56. _super.prototype.toSVG.call(this, parent);
  57. var adaptor = this.adaptor;
  58. var display = (this.node.attributes.get('display') === 'block');
  59. if (display) {
  60. adaptor.setAttribute(this.jax.container, 'display', 'true');
  61. this.handleDisplay();
  62. }
  63. if (this.jax.document.options.internalSpeechTitles) {
  64. this.handleSpeech();
  65. }
  66. };
  67. SVGmath.prototype.handleDisplay = function () {
  68. var _a = __read(this.getAlignShift(), 2), align = _a[0], shift = _a[1];
  69. if (align !== 'center') {
  70. this.adaptor.setAttribute(this.jax.container, 'justify', align);
  71. }
  72. if (this.bbox.pwidth === BBox_js_1.BBox.fullWidth) {
  73. this.adaptor.setAttribute(this.jax.container, 'width', 'full');
  74. if (this.jax.table) {
  75. var _b = this.jax.table.getOuterBBox(), L = _b.L, w = _b.w, R = _b.R;
  76. if (align === 'right') {
  77. R = Math.max(R || -shift, -shift);
  78. }
  79. else if (align === 'left') {
  80. L = Math.max(L || shift, shift);
  81. }
  82. else if (align === 'center') {
  83. w += 2 * Math.abs(shift);
  84. }
  85. this.jax.minwidth = Math.max(0, L + w + R);
  86. }
  87. }
  88. else {
  89. this.jax.shift = shift;
  90. }
  91. };
  92. SVGmath.prototype.handleSpeech = function () {
  93. var e_1, _a;
  94. var adaptor = this.adaptor;
  95. var attributes = this.node.attributes;
  96. var speech = (attributes.get('aria-label') || attributes.get('data-semantic-speech'));
  97. if (speech) {
  98. var id = this.getTitleID();
  99. var label = this.svg('title', { id: id }, [this.text(speech)]);
  100. adaptor.insert(label, adaptor.firstChild(this.element));
  101. adaptor.setAttribute(this.element, 'aria-labeledby', id);
  102. adaptor.removeAttribute(this.element, 'aria-label');
  103. try {
  104. for (var _b = __values(this.childNodes[0].childNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
  105. var child = _c.value;
  106. adaptor.setAttribute(child.element, 'aria-hidden', 'true');
  107. }
  108. }
  109. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  110. finally {
  111. try {
  112. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  113. }
  114. finally { if (e_1) throw e_1.error; }
  115. }
  116. }
  117. };
  118. SVGmath.prototype.getTitleID = function () {
  119. return 'mjx-svg-title-' + String(this.jax.options.titleID++);
  120. };
  121. SVGmath.prototype.setChildPWidths = function (recompute, w, _clear) {
  122. if (w === void 0) { w = null; }
  123. if (_clear === void 0) { _clear = true; }
  124. return _super.prototype.setChildPWidths.call(this, recompute, this.parent ? w : this.metrics.containerWidth / this.jax.pxPerEm, false);
  125. };
  126. SVGmath.kind = math_js_2.MmlMath.prototype.kind;
  127. SVGmath.styles = {
  128. 'mjx-container[jax="SVG"][display="true"]': {
  129. display: 'block',
  130. 'text-align': 'center',
  131. margin: '1em 0'
  132. },
  133. 'mjx-container[jax="SVG"][display="true"][width="full"]': {
  134. display: 'flex'
  135. },
  136. 'mjx-container[jax="SVG"][justify="left"]': {
  137. 'text-align': 'left'
  138. },
  139. 'mjx-container[jax="SVG"][justify="right"]': {
  140. 'text-align': 'right'
  141. }
  142. };
  143. return SVGmath;
  144. }((0, math_js_1.CommonMathMixin)(Wrapper_js_1.SVGWrapper)));
  145. exports.SVGmath = SVGmath;
  146. //# sourceMappingURL=math.js.map