menclose.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  18. if (k2 === undefined) k2 = k;
  19. var desc = Object.getOwnPropertyDescriptor(m, k);
  20. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  21. desc = { enumerable: true, get: function() { return m[k]; } };
  22. }
  23. Object.defineProperty(o, k2, desc);
  24. }) : (function(o, m, k, k2) {
  25. if (k2 === undefined) k2 = k;
  26. o[k2] = m[k];
  27. }));
  28. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  29. Object.defineProperty(o, "default", { enumerable: true, value: v });
  30. }) : function(o, v) {
  31. o["default"] = v;
  32. });
  33. var __importStar = (this && this.__importStar) || function (mod) {
  34. if (mod && mod.__esModule) return mod;
  35. var result = {};
  36. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  37. __setModuleDefault(result, mod);
  38. return result;
  39. };
  40. var __read = (this && this.__read) || function (o, n) {
  41. var m = typeof Symbol === "function" && o[Symbol.iterator];
  42. if (!m) return o;
  43. var i = m.call(o), r, ar = [], e;
  44. try {
  45. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  46. }
  47. catch (error) { e = { error: error }; }
  48. finally {
  49. try {
  50. if (r && !r.done && (m = i["return"])) m.call(i);
  51. }
  52. finally { if (e) throw e.error; }
  53. }
  54. return ar;
  55. };
  56. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  57. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  58. if (ar || !(i in from)) {
  59. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  60. ar[i] = from[i];
  61. }
  62. }
  63. return to.concat(ar || Array.prototype.slice.call(from));
  64. };
  65. var __values = (this && this.__values) || function(o) {
  66. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  67. if (m) return m.call(o);
  68. if (o && typeof o.length === "number") return {
  69. next: function () {
  70. if (o && i >= o.length) o = void 0;
  71. return { value: o && o[i++], done: !o };
  72. }
  73. };
  74. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  75. };
  76. Object.defineProperty(exports, "__esModule", { value: true });
  77. exports.CommonMencloseMixin = void 0;
  78. var Notation = __importStar(require("../Notation.js"));
  79. var string_js_1 = require("../../../util/string.js");
  80. function CommonMencloseMixin(Base) {
  81. return (function (_super) {
  82. __extends(class_1, _super);
  83. function class_1() {
  84. var args = [];
  85. for (var _i = 0; _i < arguments.length; _i++) {
  86. args[_i] = arguments[_i];
  87. }
  88. var _this = _super.apply(this, __spreadArray([], __read(args), false)) || this;
  89. _this.notations = {};
  90. _this.renderChild = null;
  91. _this.msqrt = null;
  92. _this.padding = Notation.PADDING;
  93. _this.thickness = Notation.THICKNESS;
  94. _this.arrowhead = { x: Notation.ARROWX, y: Notation.ARROWY, dx: Notation.ARROWDX };
  95. _this.TRBL = [0, 0, 0, 0];
  96. _this.getParameters();
  97. _this.getNotations();
  98. _this.removeRedundantNotations();
  99. _this.initializeNotations();
  100. _this.TRBL = _this.getBBoxExtenders();
  101. return _this;
  102. }
  103. class_1.prototype.getParameters = function () {
  104. var attributes = this.node.attributes;
  105. var padding = attributes.get('data-padding');
  106. if (padding !== undefined) {
  107. this.padding = this.length2em(padding, Notation.PADDING);
  108. }
  109. var thickness = attributes.get('data-thickness');
  110. if (thickness !== undefined) {
  111. this.thickness = this.length2em(thickness, Notation.THICKNESS);
  112. }
  113. var arrowhead = attributes.get('data-arrowhead');
  114. if (arrowhead !== undefined) {
  115. var _b = __read((0, string_js_1.split)(arrowhead), 3), x = _b[0], y = _b[1], dx = _b[2];
  116. this.arrowhead = {
  117. x: (x ? parseFloat(x) : Notation.ARROWX),
  118. y: (y ? parseFloat(y) : Notation.ARROWY),
  119. dx: (dx ? parseFloat(dx) : Notation.ARROWDX)
  120. };
  121. }
  122. };
  123. class_1.prototype.getNotations = function () {
  124. var e_1, _b;
  125. var Notations = this.constructor.notations;
  126. try {
  127. for (var _c = __values((0, string_js_1.split)(this.node.attributes.get('notation'))), _d = _c.next(); !_d.done; _d = _c.next()) {
  128. var name_1 = _d.value;
  129. var notation = Notations.get(name_1);
  130. if (notation) {
  131. this.notations[name_1] = notation;
  132. if (notation.renderChild) {
  133. this.renderChild = notation.renderer;
  134. }
  135. }
  136. }
  137. }
  138. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  139. finally {
  140. try {
  141. if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
  142. }
  143. finally { if (e_1) throw e_1.error; }
  144. }
  145. };
  146. class_1.prototype.removeRedundantNotations = function () {
  147. var e_2, _b, e_3, _c;
  148. try {
  149. for (var _d = __values(Object.keys(this.notations)), _e = _d.next(); !_e.done; _e = _d.next()) {
  150. var name_2 = _e.value;
  151. if (this.notations[name_2]) {
  152. var remove = this.notations[name_2].remove || '';
  153. try {
  154. for (var _f = (e_3 = void 0, __values(remove.split(/ /))), _g = _f.next(); !_g.done; _g = _f.next()) {
  155. var notation = _g.value;
  156. delete this.notations[notation];
  157. }
  158. }
  159. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  160. finally {
  161. try {
  162. if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
  163. }
  164. finally { if (e_3) throw e_3.error; }
  165. }
  166. }
  167. }
  168. }
  169. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  170. finally {
  171. try {
  172. if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
  173. }
  174. finally { if (e_2) throw e_2.error; }
  175. }
  176. };
  177. class_1.prototype.initializeNotations = function () {
  178. var e_4, _b;
  179. try {
  180. for (var _c = __values(Object.keys(this.notations)), _d = _c.next(); !_d.done; _d = _c.next()) {
  181. var name_3 = _d.value;
  182. var init = this.notations[name_3].init;
  183. init && init(this);
  184. }
  185. }
  186. catch (e_4_1) { e_4 = { error: e_4_1 }; }
  187. finally {
  188. try {
  189. if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
  190. }
  191. finally { if (e_4) throw e_4.error; }
  192. }
  193. };
  194. class_1.prototype.computeBBox = function (bbox, recompute) {
  195. if (recompute === void 0) { recompute = false; }
  196. var _b = __read(this.TRBL, 4), T = _b[0], R = _b[1], B = _b[2], L = _b[3];
  197. var child = this.childNodes[0].getBBox();
  198. bbox.combine(child, L, 0);
  199. bbox.h += T;
  200. bbox.d += B;
  201. bbox.w += R;
  202. this.setChildPWidths(recompute);
  203. };
  204. class_1.prototype.getBBoxExtenders = function () {
  205. var e_5, _b;
  206. var TRBL = [0, 0, 0, 0];
  207. try {
  208. for (var _c = __values(Object.keys(this.notations)), _d = _c.next(); !_d.done; _d = _c.next()) {
  209. var name_4 = _d.value;
  210. this.maximizeEntries(TRBL, this.notations[name_4].bbox(this));
  211. }
  212. }
  213. catch (e_5_1) { e_5 = { error: e_5_1 }; }
  214. finally {
  215. try {
  216. if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
  217. }
  218. finally { if (e_5) throw e_5.error; }
  219. }
  220. return TRBL;
  221. };
  222. class_1.prototype.getPadding = function () {
  223. var e_6, _b;
  224. var _this = this;
  225. var BTRBL = [0, 0, 0, 0];
  226. try {
  227. for (var _c = __values(Object.keys(this.notations)), _d = _c.next(); !_d.done; _d = _c.next()) {
  228. var name_5 = _d.value;
  229. var border = this.notations[name_5].border;
  230. if (border) {
  231. this.maximizeEntries(BTRBL, border(this));
  232. }
  233. }
  234. }
  235. catch (e_6_1) { e_6 = { error: e_6_1 }; }
  236. finally {
  237. try {
  238. if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
  239. }
  240. finally { if (e_6) throw e_6.error; }
  241. }
  242. return [0, 1, 2, 3].map(function (i) { return _this.TRBL[i] - BTRBL[i]; });
  243. };
  244. class_1.prototype.maximizeEntries = function (X, Y) {
  245. for (var i = 0; i < X.length; i++) {
  246. if (X[i] < Y[i]) {
  247. X[i] = Y[i];
  248. }
  249. }
  250. };
  251. class_1.prototype.getOffset = function (direction) {
  252. var _b = __read(this.TRBL, 4), T = _b[0], R = _b[1], B = _b[2], L = _b[3];
  253. var d = (direction === 'X' ? R - L : B - T) / 2;
  254. return (Math.abs(d) > .001 ? d : 0);
  255. };
  256. class_1.prototype.getArgMod = function (w, h) {
  257. return [Math.atan2(h, w), Math.sqrt(w * w + h * h)];
  258. };
  259. class_1.prototype.arrow = function (_w, _a, _double, _offset, _dist) {
  260. if (_offset === void 0) { _offset = ''; }
  261. if (_dist === void 0) { _dist = 0; }
  262. return null;
  263. };
  264. class_1.prototype.arrowData = function () {
  265. var _b = __read([this.padding, this.thickness], 2), p = _b[0], t = _b[1];
  266. var r = t * (this.arrowhead.x + Math.max(1, this.arrowhead.dx));
  267. var _c = this.childNodes[0].getBBox(), h = _c.h, d = _c.d, w = _c.w;
  268. var H = h + d;
  269. var R = Math.sqrt(H * H + w * w);
  270. var x = Math.max(p, r * w / R);
  271. var y = Math.max(p, r * H / R);
  272. var _d = __read(this.getArgMod(w + 2 * x, H + 2 * y), 2), a = _d[0], W = _d[1];
  273. return { a: a, W: W, x: x, y: y };
  274. };
  275. class_1.prototype.arrowAW = function () {
  276. var _b = this.childNodes[0].getBBox(), h = _b.h, d = _b.d, w = _b.w;
  277. var _c = __read(this.TRBL, 4), T = _c[0], R = _c[1], B = _c[2], L = _c[3];
  278. return this.getArgMod(L + w + R, T + h + d + B);
  279. };
  280. class_1.prototype.createMsqrt = function (child) {
  281. var mmlFactory = this.node.factory;
  282. var mml = mmlFactory.create('msqrt');
  283. mml.inheritAttributesFrom(this.node);
  284. mml.childNodes[0] = child.node;
  285. var node = this.wrap(mml);
  286. node.parent = this;
  287. return node;
  288. };
  289. class_1.prototype.sqrtTRBL = function () {
  290. var bbox = this.msqrt.getBBox();
  291. var cbox = this.msqrt.childNodes[0].getBBox();
  292. return [bbox.h - cbox.h, 0, bbox.d - cbox.d, bbox.w - cbox.w];
  293. };
  294. return class_1;
  295. }(Base));
  296. }
  297. exports.CommonMencloseMixin = CommonMencloseMixin;
  298. //# sourceMappingURL=menclose.js.map