msqrt.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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.CommonMsqrtMixin = void 0;
  44. var BBox_js_1 = require("../../../util/BBox.js");
  45. function CommonMsqrtMixin(Base) {
  46. return (function (_super) {
  47. __extends(class_1, _super);
  48. function class_1() {
  49. var args = [];
  50. for (var _i = 0; _i < arguments.length; _i++) {
  51. args[_i] = arguments[_i];
  52. }
  53. var _this = _super.apply(this, __spreadArray([], __read(args), false)) || this;
  54. var surd = _this.createMo('\u221A');
  55. surd.canStretch(1);
  56. var _a = _this.childNodes[_this.base].getOuterBBox(), h = _a.h, d = _a.d;
  57. var t = _this.font.params.rule_thickness;
  58. var p = (_this.node.attributes.get('displaystyle') ? _this.font.params.x_height : t);
  59. _this.surdH = h + d + 2 * t + p / 4;
  60. surd.getStretchedVariant([_this.surdH - d, d], true);
  61. return _this;
  62. }
  63. Object.defineProperty(class_1.prototype, "base", {
  64. get: function () {
  65. return 0;
  66. },
  67. enumerable: false,
  68. configurable: true
  69. });
  70. Object.defineProperty(class_1.prototype, "surd", {
  71. get: function () {
  72. return 1;
  73. },
  74. enumerable: false,
  75. configurable: true
  76. });
  77. Object.defineProperty(class_1.prototype, "root", {
  78. get: function () {
  79. return null;
  80. },
  81. enumerable: false,
  82. configurable: true
  83. });
  84. class_1.prototype.createMo = function (text) {
  85. var node = _super.prototype.createMo.call(this, text);
  86. this.childNodes.push(node);
  87. return node;
  88. };
  89. class_1.prototype.computeBBox = function (bbox, recompute) {
  90. if (recompute === void 0) { recompute = false; }
  91. var surdbox = this.childNodes[this.surd].getBBox();
  92. var basebox = new BBox_js_1.BBox(this.childNodes[this.base].getOuterBBox());
  93. var q = this.getPQ(surdbox)[1];
  94. var t = this.font.params.rule_thickness;
  95. var H = basebox.h + q + t;
  96. var _a = __read(this.getRootDimens(surdbox, H), 1), x = _a[0];
  97. bbox.h = H + t;
  98. this.combineRootBBox(bbox, surdbox, H);
  99. bbox.combine(surdbox, x, H - surdbox.h);
  100. bbox.combine(basebox, x + surdbox.w, 0);
  101. bbox.clean();
  102. this.setChildPWidths(recompute);
  103. };
  104. class_1.prototype.combineRootBBox = function (_bbox, _sbox, _H) {
  105. };
  106. class_1.prototype.getPQ = function (sbox) {
  107. var t = this.font.params.rule_thickness;
  108. var p = (this.node.attributes.get('displaystyle') ? this.font.params.x_height : t);
  109. var q = (sbox.h + sbox.d > this.surdH ?
  110. ((sbox.h + sbox.d) - (this.surdH - 2 * t - p / 2)) / 2 :
  111. t + p / 4);
  112. return [p, q];
  113. };
  114. class_1.prototype.getRootDimens = function (_sbox, _H) {
  115. return [0, 0, 0, 0];
  116. };
  117. return class_1;
  118. }(Base));
  119. }
  120. exports.CommonMsqrtMixin = CommonMsqrtMixin;
  121. //# sourceMappingURL=msqrt.js.map