mo.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 __values = (this && this.__values) || function(o) {
  18. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  19. if (m) return m.call(o);
  20. if (o && typeof o.length === "number") return {
  21. next: function () {
  22. if (o && i >= o.length) o = void 0;
  23. return { value: o && o[i++], done: !o };
  24. }
  25. };
  26. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  27. };
  28. Object.defineProperty(exports, "__esModule", { value: true });
  29. exports.CHTMLmo = void 0;
  30. var Wrapper_js_1 = require("../Wrapper.js");
  31. var mo_js_1 = require("../../common/Wrappers/mo.js");
  32. var mo_js_2 = require("../../../core/MmlTree/MmlNodes/mo.js");
  33. var CHTMLmo = (function (_super) {
  34. __extends(CHTMLmo, _super);
  35. function CHTMLmo() {
  36. return _super !== null && _super.apply(this, arguments) || this;
  37. }
  38. CHTMLmo.prototype.toCHTML = function (parent) {
  39. var e_1, _a;
  40. var attributes = this.node.attributes;
  41. var symmetric = attributes.get('symmetric') && this.stretch.dir !== 2;
  42. var stretchy = this.stretch.dir !== 0;
  43. if (stretchy && this.size === null) {
  44. this.getStretchedVariant([]);
  45. }
  46. var chtml = this.standardCHTMLnode(parent);
  47. if (stretchy && this.size < 0) {
  48. this.stretchHTML(chtml);
  49. }
  50. else {
  51. if (symmetric || attributes.get('largeop')) {
  52. var u = this.em(this.getCenterOffset());
  53. if (u !== '0') {
  54. this.adaptor.setStyle(chtml, 'verticalAlign', u);
  55. }
  56. }
  57. if (this.node.getProperty('mathaccent')) {
  58. this.adaptor.setStyle(chtml, 'width', '0');
  59. this.adaptor.setStyle(chtml, 'margin-left', this.em(this.getAccentOffset()));
  60. }
  61. try {
  62. for (var _b = __values(this.childNodes), _c = _b.next(); !_c.done; _c = _b.next()) {
  63. var child = _c.value;
  64. child.toCHTML(chtml);
  65. }
  66. }
  67. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  68. finally {
  69. try {
  70. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  71. }
  72. finally { if (e_1) throw e_1.error; }
  73. }
  74. }
  75. };
  76. CHTMLmo.prototype.stretchHTML = function (chtml) {
  77. var c = this.getText().codePointAt(0);
  78. this.font.delimUsage.add(c);
  79. this.childNodes[0].markUsed();
  80. var delim = this.stretch;
  81. var stretch = delim.stretch;
  82. var content = [];
  83. if (stretch[0]) {
  84. content.push(this.html('mjx-beg', {}, [this.html('mjx-c')]));
  85. }
  86. content.push(this.html('mjx-ext', {}, [this.html('mjx-c')]));
  87. if (stretch.length === 4) {
  88. content.push(this.html('mjx-mid', {}, [this.html('mjx-c')]), this.html('mjx-ext', {}, [this.html('mjx-c')]));
  89. }
  90. if (stretch[2]) {
  91. content.push(this.html('mjx-end', {}, [this.html('mjx-c')]));
  92. }
  93. var styles = {};
  94. var _a = this.bbox, h = _a.h, d = _a.d, w = _a.w;
  95. if (delim.dir === 1) {
  96. content.push(this.html('mjx-mark'));
  97. styles.height = this.em(h + d);
  98. styles.verticalAlign = this.em(-d);
  99. }
  100. else {
  101. styles.width = this.em(w);
  102. }
  103. var dir = mo_js_1.DirectionVH[delim.dir];
  104. var properties = { class: this.char(delim.c || c), style: styles };
  105. var html = this.html('mjx-stretchy-' + dir, properties, content);
  106. this.adaptor.append(chtml, html);
  107. };
  108. CHTMLmo.kind = mo_js_2.MmlMo.prototype.kind;
  109. CHTMLmo.styles = {
  110. 'mjx-stretchy-h': {
  111. display: 'inline-table',
  112. width: '100%'
  113. },
  114. 'mjx-stretchy-h > *': {
  115. display: 'table-cell',
  116. width: 0
  117. },
  118. 'mjx-stretchy-h > * > mjx-c': {
  119. display: 'inline-block',
  120. transform: 'scalex(1.0000001)'
  121. },
  122. 'mjx-stretchy-h > * > mjx-c::before': {
  123. display: 'inline-block',
  124. width: 'initial'
  125. },
  126. 'mjx-stretchy-h > mjx-ext': {
  127. '/* IE */ overflow': 'hidden',
  128. '/* others */ overflow': 'clip visible',
  129. width: '100%'
  130. },
  131. 'mjx-stretchy-h > mjx-ext > mjx-c::before': {
  132. transform: 'scalex(500)'
  133. },
  134. 'mjx-stretchy-h > mjx-ext > mjx-c': {
  135. width: 0
  136. },
  137. 'mjx-stretchy-h > mjx-beg > mjx-c': {
  138. 'margin-right': '-.1em'
  139. },
  140. 'mjx-stretchy-h > mjx-end > mjx-c': {
  141. 'margin-left': '-.1em'
  142. },
  143. 'mjx-stretchy-v': {
  144. display: 'inline-block'
  145. },
  146. 'mjx-stretchy-v > *': {
  147. display: 'block'
  148. },
  149. 'mjx-stretchy-v > mjx-beg': {
  150. height: 0
  151. },
  152. 'mjx-stretchy-v > mjx-end > mjx-c': {
  153. display: 'block'
  154. },
  155. 'mjx-stretchy-v > * > mjx-c': {
  156. transform: 'scaley(1.0000001)',
  157. 'transform-origin': 'left center',
  158. overflow: 'hidden'
  159. },
  160. 'mjx-stretchy-v > mjx-ext': {
  161. display: 'block',
  162. height: '100%',
  163. 'box-sizing': 'border-box',
  164. border: '0px solid transparent',
  165. '/* IE */ overflow': 'hidden',
  166. '/* others */ overflow': 'visible clip',
  167. },
  168. 'mjx-stretchy-v > mjx-ext > mjx-c::before': {
  169. width: 'initial',
  170. 'box-sizing': 'border-box'
  171. },
  172. 'mjx-stretchy-v > mjx-ext > mjx-c': {
  173. transform: 'scaleY(500) translateY(.075em)',
  174. overflow: 'visible'
  175. },
  176. 'mjx-mark': {
  177. display: 'inline-block',
  178. height: '0px'
  179. }
  180. };
  181. return CHTMLmo;
  182. }((0, mo_js_1.CommonMoMixin)(Wrapper_js_1.CHTMLWrapper)));
  183. exports.CHTMLmo = CHTMLmo;
  184. //# sourceMappingURL=mo.js.map