mfrac.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.SVGmfrac = void 0;
  35. var Wrapper_js_1 = require("../Wrapper.js");
  36. var mfrac_js_1 = require("../../common/Wrappers/mfrac.js");
  37. var mfrac_js_2 = require("../../../core/MmlTree/MmlNodes/mfrac.js");
  38. var SVGmfrac = (function (_super) {
  39. __extends(SVGmfrac, _super);
  40. function SVGmfrac() {
  41. return _super !== null && _super.apply(this, arguments) || this;
  42. }
  43. SVGmfrac.prototype.toSVG = function (parent) {
  44. this.standardSVGnode(parent);
  45. var _a = this.node.attributes.getList('linethickness', 'bevelled'), linethickness = _a.linethickness, bevelled = _a.bevelled;
  46. var display = this.isDisplay();
  47. if (bevelled) {
  48. this.makeBevelled(display);
  49. }
  50. else {
  51. var thickness = this.length2em(String(linethickness), .06);
  52. if (thickness === 0) {
  53. this.makeAtop(display);
  54. }
  55. else {
  56. this.makeFraction(display, thickness);
  57. }
  58. }
  59. };
  60. SVGmfrac.prototype.makeFraction = function (display, t) {
  61. var svg = this.element;
  62. var _a = this.node.attributes.getList('numalign', 'denomalign'), numalign = _a.numalign, denomalign = _a.denomalign;
  63. var _b = __read(this.childNodes, 2), num = _b[0], den = _b[1];
  64. var nbox = num.getOuterBBox();
  65. var dbox = den.getOuterBBox();
  66. var tex = this.font.params;
  67. var a = tex.axis_height;
  68. var d = .1;
  69. var pad = (this.node.getProperty('withDelims') ? 0 : tex.nulldelimiterspace);
  70. var W = Math.max((nbox.L + nbox.w + nbox.R) * nbox.rscale, (dbox.L + dbox.w + dbox.R) * dbox.rscale);
  71. var nx = this.getAlignX(W, nbox, numalign) + d + pad;
  72. var dx = this.getAlignX(W, dbox, denomalign) + d + pad;
  73. var _c = this.getTUV(display, t), T = _c.T, u = _c.u, v = _c.v;
  74. num.toSVG(svg);
  75. num.place(nx, a + T + Math.max(nbox.d * nbox.rscale, u));
  76. den.toSVG(svg);
  77. den.place(dx, a - T - Math.max(dbox.h * dbox.rscale, v));
  78. this.adaptor.append(svg, this.svg('rect', {
  79. width: this.fixed(W + 2 * d), height: this.fixed(t),
  80. x: this.fixed(pad), y: this.fixed(a - t / 2)
  81. }));
  82. };
  83. SVGmfrac.prototype.makeAtop = function (display) {
  84. var svg = this.element;
  85. var _a = this.node.attributes.getList('numalign', 'denomalign'), numalign = _a.numalign, denomalign = _a.denomalign;
  86. var _b = __read(this.childNodes, 2), num = _b[0], den = _b[1];
  87. var nbox = num.getOuterBBox();
  88. var dbox = den.getOuterBBox();
  89. var tex = this.font.params;
  90. var pad = (this.node.getProperty('withDelims') ? 0 : tex.nulldelimiterspace);
  91. var W = Math.max((nbox.L + nbox.w + nbox.R) * nbox.rscale, (dbox.L + dbox.w + dbox.R) * dbox.rscale);
  92. var nx = this.getAlignX(W, nbox, numalign) + pad;
  93. var dx = this.getAlignX(W, dbox, denomalign) + pad;
  94. var _c = this.getUVQ(display), u = _c.u, v = _c.v;
  95. num.toSVG(svg);
  96. num.place(nx, u);
  97. den.toSVG(svg);
  98. den.place(dx, -v);
  99. };
  100. SVGmfrac.prototype.makeBevelled = function (display) {
  101. var svg = this.element;
  102. var _a = __read(this.childNodes, 2), num = _a[0], den = _a[1];
  103. var _b = this.getBevelData(display), u = _b.u, v = _b.v, delta = _b.delta, nbox = _b.nbox, dbox = _b.dbox;
  104. var w = (nbox.L + nbox.w + nbox.R) * nbox.rscale;
  105. num.toSVG(svg);
  106. this.bevel.toSVG(svg);
  107. den.toSVG(svg);
  108. num.place(nbox.L * nbox.rscale, u);
  109. this.bevel.place(w - delta / 2, 0);
  110. den.place(w + this.bevel.getOuterBBox().w + dbox.L * dbox.rscale - delta, v);
  111. };
  112. SVGmfrac.kind = mfrac_js_2.MmlMfrac.prototype.kind;
  113. return SVGmfrac;
  114. }((0, mfrac_js_1.CommonMfracMixin)(Wrapper_js_1.SVGWrapper)));
  115. exports.SVGmfrac = SVGmfrac;
  116. //# sourceMappingURL=mfrac.js.map