math.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.CHTMLmath = void 0;
  35. var Wrapper_js_1 = require("../Wrapper.js");
  36. var math_js_1 = require("../../common/Wrappers/math.js");
  37. var math_js_2 = require("../../../core/MmlTree/MmlNodes/math.js");
  38. var BBox_js_1 = require("../../../util/BBox.js");
  39. var CHTMLmath = (function (_super) {
  40. __extends(CHTMLmath, _super);
  41. function CHTMLmath() {
  42. return _super !== null && _super.apply(this, arguments) || this;
  43. }
  44. CHTMLmath.prototype.toCHTML = function (parent) {
  45. _super.prototype.toCHTML.call(this, parent);
  46. var chtml = this.chtml;
  47. var adaptor = this.adaptor;
  48. var display = (this.node.attributes.get('display') === 'block');
  49. if (display) {
  50. adaptor.setAttribute(chtml, 'display', 'true');
  51. adaptor.setAttribute(parent, 'display', 'true');
  52. this.handleDisplay(parent);
  53. }
  54. else {
  55. this.handleInline(parent);
  56. }
  57. adaptor.addClass(chtml, 'MJX-TEX');
  58. };
  59. CHTMLmath.prototype.handleDisplay = function (parent) {
  60. var adaptor = this.adaptor;
  61. var _a = __read(this.getAlignShift(), 2), align = _a[0], shift = _a[1];
  62. if (align !== 'center') {
  63. adaptor.setAttribute(parent, 'justify', align);
  64. }
  65. if (this.bbox.pwidth === BBox_js_1.BBox.fullWidth) {
  66. adaptor.setAttribute(parent, 'width', 'full');
  67. if (this.jax.table) {
  68. var _b = this.jax.table.getOuterBBox(), L = _b.L, w = _b.w, R = _b.R;
  69. if (align === 'right') {
  70. R = Math.max(R || -shift, -shift);
  71. }
  72. else if (align === 'left') {
  73. L = Math.max(L || shift, shift);
  74. }
  75. else if (align === 'center') {
  76. w += 2 * Math.abs(shift);
  77. }
  78. var W = this.em(Math.max(0, L + w + R));
  79. adaptor.setStyle(parent, 'min-width', W);
  80. adaptor.setStyle(this.jax.table.chtml, 'min-width', W);
  81. }
  82. }
  83. else {
  84. this.setIndent(this.chtml, align, shift);
  85. }
  86. };
  87. CHTMLmath.prototype.handleInline = function (parent) {
  88. var adaptor = this.adaptor;
  89. var margin = adaptor.getStyle(this.chtml, 'margin-right');
  90. if (margin) {
  91. adaptor.setStyle(this.chtml, 'margin-right', '');
  92. adaptor.setStyle(parent, 'margin-right', margin);
  93. adaptor.setStyle(parent, 'width', '0');
  94. }
  95. };
  96. CHTMLmath.prototype.setChildPWidths = function (recompute, w, clear) {
  97. if (w === void 0) { w = null; }
  98. if (clear === void 0) { clear = true; }
  99. return (this.parent ? _super.prototype.setChildPWidths.call(this, recompute, w, clear) : false);
  100. };
  101. CHTMLmath.kind = math_js_2.MmlMath.prototype.kind;
  102. CHTMLmath.styles = {
  103. 'mjx-math': {
  104. 'line-height': 0,
  105. 'text-align': 'left',
  106. 'text-indent': 0,
  107. 'font-style': 'normal',
  108. 'font-weight': 'normal',
  109. 'font-size': '100%',
  110. 'font-size-adjust': 'none',
  111. 'letter-spacing': 'normal',
  112. 'border-collapse': 'collapse',
  113. 'word-wrap': 'normal',
  114. 'word-spacing': 'normal',
  115. 'white-space': 'nowrap',
  116. 'direction': 'ltr',
  117. 'padding': '1px 0'
  118. },
  119. 'mjx-container[jax="CHTML"][display="true"]': {
  120. display: 'block',
  121. 'text-align': 'center',
  122. margin: '1em 0'
  123. },
  124. 'mjx-container[jax="CHTML"][display="true"][width="full"]': {
  125. display: 'flex'
  126. },
  127. 'mjx-container[jax="CHTML"][display="true"] mjx-math': {
  128. padding: 0
  129. },
  130. 'mjx-container[jax="CHTML"][justify="left"]': {
  131. 'text-align': 'left'
  132. },
  133. 'mjx-container[jax="CHTML"][justify="right"]': {
  134. 'text-align': 'right'
  135. }
  136. };
  137. return CHTMLmath;
  138. }((0, math_js_1.CommonMathMixin)(Wrapper_js_1.CHTMLWrapper)));
  139. exports.CHTMLmath = CHTMLmath;
  140. //# sourceMappingURL=math.js.map