mpadded.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.CommonMpaddedMixin = void 0;
  35. function CommonMpaddedMixin(Base) {
  36. return (function (_super) {
  37. __extends(class_1, _super);
  38. function class_1() {
  39. return _super !== null && _super.apply(this, arguments) || this;
  40. }
  41. class_1.prototype.getDimens = function () {
  42. var values = this.node.attributes.getList('width', 'height', 'depth', 'lspace', 'voffset');
  43. var bbox = this.childNodes[0].getBBox();
  44. var w = bbox.w, h = bbox.h, d = bbox.d;
  45. var W = w, H = h, D = d, x = 0, y = 0, dx = 0;
  46. if (values.width !== '')
  47. w = this.dimen(values.width, bbox, 'w', 0);
  48. if (values.height !== '')
  49. h = this.dimen(values.height, bbox, 'h', 0);
  50. if (values.depth !== '')
  51. d = this.dimen(values.depth, bbox, 'd', 0);
  52. if (values.voffset !== '')
  53. y = this.dimen(values.voffset, bbox);
  54. if (values.lspace !== '')
  55. x = this.dimen(values.lspace, bbox);
  56. var align = this.node.attributes.get('data-align');
  57. if (align) {
  58. dx = this.getAlignX(w, bbox, align);
  59. }
  60. return [H, D, W, h - H, d - D, w - W, x, y, dx];
  61. };
  62. class_1.prototype.dimen = function (length, bbox, d, m) {
  63. if (d === void 0) { d = ''; }
  64. if (m === void 0) { m = null; }
  65. length = String(length);
  66. var match = length.match(/width|height|depth/);
  67. var size = (match ? bbox[match[0].charAt(0)] :
  68. (d ? bbox[d] : 0));
  69. var dimen = (this.length2em(length, size) || 0);
  70. if (length.match(/^[-+]/) && d) {
  71. dimen += size;
  72. }
  73. if (m != null) {
  74. dimen = Math.max(m, dimen);
  75. }
  76. return dimen;
  77. };
  78. class_1.prototype.computeBBox = function (bbox, recompute) {
  79. if (recompute === void 0) { recompute = false; }
  80. var _a = __read(this.getDimens(), 6), H = _a[0], D = _a[1], W = _a[2], dh = _a[3], dd = _a[4], dw = _a[5];
  81. bbox.w = W + dw;
  82. bbox.h = H + dh;
  83. bbox.d = D + dd;
  84. this.setChildPWidths(recompute, bbox.w);
  85. };
  86. class_1.prototype.getWrapWidth = function (_i) {
  87. return this.getBBox().w;
  88. };
  89. class_1.prototype.getChildAlign = function (_i) {
  90. return this.node.attributes.get('data-align') || 'left';
  91. };
  92. return class_1;
  93. }(Base));
  94. }
  95. exports.CommonMpaddedMixin = CommonMpaddedMixin;
  96. //# sourceMappingURL=mpadded.js.map