mfrac.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. Object.defineProperty(exports, "__esModule", { value: true });
  43. exports.CommonMfracMixin = void 0;
  44. function CommonMfracMixin(Base) {
  45. return (function (_super) {
  46. __extends(class_1, _super);
  47. function class_1() {
  48. var args = [];
  49. for (var _i = 0; _i < arguments.length; _i++) {
  50. args[_i] = arguments[_i];
  51. }
  52. var _this = _super.apply(this, __spreadArray([], __read(args), false)) || this;
  53. _this.bevel = null;
  54. _this.pad = (_this.node.getProperty('withDelims') ? 0 : _this.font.params.nulldelimiterspace);
  55. if (_this.node.attributes.get('bevelled')) {
  56. var H = _this.getBevelData(_this.isDisplay()).H;
  57. var bevel = _this.bevel = _this.createMo('/');
  58. bevel.node.attributes.set('symmetric', true);
  59. bevel.canStretch(1);
  60. bevel.getStretchedVariant([H], true);
  61. }
  62. return _this;
  63. }
  64. class_1.prototype.computeBBox = function (bbox, recompute) {
  65. if (recompute === void 0) { recompute = false; }
  66. bbox.empty();
  67. var _a = this.node.attributes.getList('linethickness', 'bevelled'), linethickness = _a.linethickness, bevelled = _a.bevelled;
  68. var display = this.isDisplay();
  69. var w = null;
  70. if (bevelled) {
  71. this.getBevelledBBox(bbox, display);
  72. }
  73. else {
  74. var thickness = this.length2em(String(linethickness), .06);
  75. w = -2 * this.pad;
  76. if (thickness === 0) {
  77. this.getAtopBBox(bbox, display);
  78. }
  79. else {
  80. this.getFractionBBox(bbox, display, thickness);
  81. w -= .2;
  82. }
  83. w += bbox.w;
  84. }
  85. bbox.clean();
  86. this.setChildPWidths(recompute, w);
  87. };
  88. class_1.prototype.getFractionBBox = function (bbox, display, t) {
  89. var nbox = this.childNodes[0].getOuterBBox();
  90. var dbox = this.childNodes[1].getOuterBBox();
  91. var tex = this.font.params;
  92. var a = tex.axis_height;
  93. var _a = this.getTUV(display, t), T = _a.T, u = _a.u, v = _a.v;
  94. bbox.combine(nbox, 0, a + T + Math.max(nbox.d * nbox.rscale, u));
  95. bbox.combine(dbox, 0, a - T - Math.max(dbox.h * dbox.rscale, v));
  96. bbox.w += 2 * this.pad + .2;
  97. };
  98. class_1.prototype.getTUV = function (display, t) {
  99. var tex = this.font.params;
  100. var a = tex.axis_height;
  101. var T = (display ? 3.5 : 1.5) * t;
  102. return { T: (display ? 3.5 : 1.5) * t,
  103. u: (display ? tex.num1 : tex.num2) - a - T,
  104. v: (display ? tex.denom1 : tex.denom2) + a - T };
  105. };
  106. class_1.prototype.getAtopBBox = function (bbox, display) {
  107. var _a = this.getUVQ(display), u = _a.u, v = _a.v, nbox = _a.nbox, dbox = _a.dbox;
  108. bbox.combine(nbox, 0, u);
  109. bbox.combine(dbox, 0, -v);
  110. bbox.w += 2 * this.pad;
  111. };
  112. class_1.prototype.getUVQ = function (display) {
  113. var nbox = this.childNodes[0].getOuterBBox();
  114. var dbox = this.childNodes[1].getOuterBBox();
  115. var tex = this.font.params;
  116. var _a = __read((display ? [tex.num1, tex.denom1] : [tex.num3, tex.denom2]), 2), u = _a[0], v = _a[1];
  117. var p = (display ? 7 : 3) * tex.rule_thickness;
  118. var q = (u - nbox.d * nbox.scale) - (dbox.h * dbox.scale - v);
  119. if (q < p) {
  120. u += (p - q) / 2;
  121. v += (p - q) / 2;
  122. q = p;
  123. }
  124. return { u: u, v: v, q: q, nbox: nbox, dbox: dbox };
  125. };
  126. class_1.prototype.getBevelledBBox = function (bbox, display) {
  127. var _a = this.getBevelData(display), u = _a.u, v = _a.v, delta = _a.delta, nbox = _a.nbox, dbox = _a.dbox;
  128. var lbox = this.bevel.getOuterBBox();
  129. bbox.combine(nbox, 0, u);
  130. bbox.combine(lbox, bbox.w - delta / 2, 0);
  131. bbox.combine(dbox, bbox.w - delta / 2, v);
  132. };
  133. class_1.prototype.getBevelData = function (display) {
  134. var nbox = this.childNodes[0].getOuterBBox();
  135. var dbox = this.childNodes[1].getOuterBBox();
  136. var delta = (display ? .4 : .15);
  137. var H = Math.max(nbox.scale * (nbox.h + nbox.d), dbox.scale * (dbox.h + dbox.d)) + 2 * delta;
  138. var a = this.font.params.axis_height;
  139. var u = nbox.scale * (nbox.d - nbox.h) / 2 + a + delta;
  140. var v = dbox.scale * (dbox.d - dbox.h) / 2 + a - delta;
  141. return { H: H, delta: delta, u: u, v: v, nbox: nbox, dbox: dbox };
  142. };
  143. class_1.prototype.canStretch = function (_direction) {
  144. return false;
  145. };
  146. class_1.prototype.isDisplay = function () {
  147. var _a = this.node.attributes.getList('displaystyle', 'scriptlevel'), displaystyle = _a.displaystyle, scriptlevel = _a.scriptlevel;
  148. return displaystyle && scriptlevel === 0;
  149. };
  150. class_1.prototype.getWrapWidth = function (i) {
  151. var attributes = this.node.attributes;
  152. if (attributes.get('bevelled')) {
  153. return this.childNodes[i].getOuterBBox().w;
  154. }
  155. var w = this.getBBox().w;
  156. var thickness = this.length2em(attributes.get('linethickness'));
  157. return w - (thickness ? .2 : 0) - 2 * this.pad;
  158. };
  159. class_1.prototype.getChildAlign = function (i) {
  160. var attributes = this.node.attributes;
  161. return (attributes.get('bevelled') ? 'left' : attributes.get(['numalign', 'denomalign'][i]));
  162. };
  163. return class_1;
  164. }(Base));
  165. }
  166. exports.CommonMfracMixin = CommonMfracMixin;
  167. //# sourceMappingURL=mfrac.js.map