menclose.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 __values = (this && this.__values) || function(o) {
  41. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  42. if (m) return m.call(o);
  43. if (o && typeof o.length === "number") return {
  44. next: function () {
  45. if (o && i >= o.length) o = void 0;
  46. return { value: o && o[i++], done: !o };
  47. }
  48. };
  49. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  50. };
  51. var __read = (this && this.__read) || function (o, n) {
  52. var m = typeof Symbol === "function" && o[Symbol.iterator];
  53. if (!m) return o;
  54. var i = m.call(o), r, ar = [], e;
  55. try {
  56. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  57. }
  58. catch (error) { e = { error: error }; }
  59. finally {
  60. try {
  61. if (r && !r.done && (m = i["return"])) m.call(i);
  62. }
  63. finally { if (e) throw e.error; }
  64. }
  65. return ar;
  66. };
  67. Object.defineProperty(exports, "__esModule", { value: true });
  68. exports.SVGmenclose = void 0;
  69. var Wrapper_js_1 = require("../Wrapper.js");
  70. var menclose_js_1 = require("../../common/Wrappers/menclose.js");
  71. var Notation = __importStar(require("../Notation.js"));
  72. var menclose_js_2 = require("../../../core/MmlTree/MmlNodes/menclose.js");
  73. var SVGmenclose = (function (_super) {
  74. __extends(SVGmenclose, _super);
  75. function SVGmenclose() {
  76. return _super !== null && _super.apply(this, arguments) || this;
  77. }
  78. SVGmenclose.prototype.toSVG = function (parent) {
  79. var e_1, _a;
  80. var svg = this.standardSVGnode(parent);
  81. var left = this.getBBoxExtenders()[3];
  82. var def = {};
  83. if (left > 0) {
  84. def.transform = 'translate(' + this.fixed(left) + ', 0)';
  85. }
  86. var block = this.adaptor.append(svg, this.svg('g', def));
  87. if (this.renderChild) {
  88. this.renderChild(this, block);
  89. }
  90. else {
  91. this.childNodes[0].toSVG(block);
  92. }
  93. try {
  94. for (var _b = __values(Object.keys(this.notations)), _c = _b.next(); !_c.done; _c = _b.next()) {
  95. var name_1 = _c.value;
  96. var notation = this.notations[name_1];
  97. !notation.renderChild && notation.renderer(this, svg);
  98. }
  99. }
  100. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  101. finally {
  102. try {
  103. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  104. }
  105. finally { if (e_1) throw e_1.error; }
  106. }
  107. };
  108. SVGmenclose.prototype.arrow = function (W, a, double, offset, dist) {
  109. if (offset === void 0) { offset = ''; }
  110. if (dist === void 0) { dist = 0; }
  111. var _a = this.getBBox(), w = _a.w, h = _a.h, d = _a.d;
  112. var dw = (W - w) / 2;
  113. var m = (h - d) / 2;
  114. var t = this.thickness;
  115. var t2 = t / 2;
  116. var _b = __read([t * this.arrowhead.x, t * this.arrowhead.y, t * this.arrowhead.dx], 3), x = _b[0], y = _b[1], dx = _b[2];
  117. var arrow = (double ?
  118. this.fill('M', w + dw, m, 'l', -(x + dx), y, 'l', dx, t2 - y, 'L', x - dw, m + t2, 'l', dx, y - t2, 'l', -(x + dx), -y, 'l', x + dx, -y, 'l', -dx, y - t2, 'L', w + dw - x, m - t2, 'l', -dx, t2 - y, 'Z') :
  119. this.fill('M', w + dw, m, 'l', -(x + dx), y, 'l', dx, t2 - y, 'L', -dw, m + t2, 'l', 0, -t, 'L', w + dw - x, m - t2, 'l', -dx, t2 - y, 'Z'));
  120. var transform = [];
  121. if (dist) {
  122. transform.push(offset === 'X' ? "translate(".concat(this.fixed(-dist), " 0)") : "translate(0 ".concat(this.fixed(dist), ")"));
  123. }
  124. if (a) {
  125. var A = this.jax.fixed(-a * 180 / Math.PI);
  126. transform.push("rotate(".concat(A, " ").concat(this.fixed(w / 2), " ").concat(this.fixed(m), ")"));
  127. }
  128. if (transform.length) {
  129. this.adaptor.setAttribute(arrow, 'transform', transform.join(' '));
  130. }
  131. return arrow;
  132. };
  133. SVGmenclose.prototype.line = function (pq) {
  134. var _a = __read(pq, 4), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3];
  135. return this.svg('line', {
  136. x1: this.fixed(x1), y1: this.fixed(y1),
  137. x2: this.fixed(x2), y2: this.fixed(y2),
  138. 'stroke-width': this.fixed(this.thickness)
  139. });
  140. };
  141. SVGmenclose.prototype.box = function (w, h, d, r) {
  142. if (r === void 0) { r = 0; }
  143. var t = this.thickness;
  144. var def = {
  145. x: this.fixed(t / 2), y: this.fixed(t / 2 - d),
  146. width: this.fixed(w - t), height: this.fixed(h + d - t),
  147. fill: 'none', 'stroke-width': this.fixed(t)
  148. };
  149. if (r) {
  150. def.rx = this.fixed(r);
  151. }
  152. return this.svg('rect', def);
  153. };
  154. SVGmenclose.prototype.ellipse = function (w, h, d) {
  155. var t = this.thickness;
  156. return this.svg('ellipse', {
  157. rx: this.fixed((w - t) / 2), ry: this.fixed((h + d - t) / 2),
  158. cx: this.fixed(w / 2), cy: this.fixed((h - d) / 2),
  159. 'fill': 'none', 'stroke-width': this.fixed(t)
  160. });
  161. };
  162. SVGmenclose.prototype.path = function (join) {
  163. var _this = this;
  164. var P = [];
  165. for (var _i = 1; _i < arguments.length; _i++) {
  166. P[_i - 1] = arguments[_i];
  167. }
  168. return this.svg('path', {
  169. d: P.map(function (x) { return (typeof x === 'string' ? x : _this.fixed(x)); }).join(' '),
  170. style: { 'stroke-width': this.fixed(this.thickness) },
  171. 'stroke-linecap': 'round', 'stroke-linejoin': join,
  172. fill: 'none'
  173. });
  174. };
  175. SVGmenclose.prototype.fill = function () {
  176. var _this = this;
  177. var P = [];
  178. for (var _i = 0; _i < arguments.length; _i++) {
  179. P[_i] = arguments[_i];
  180. }
  181. return this.svg('path', {
  182. d: P.map(function (x) { return (typeof x === 'string' ? x : _this.fixed(x)); }).join(' ')
  183. });
  184. };
  185. SVGmenclose.kind = menclose_js_2.MmlMenclose.prototype.kind;
  186. SVGmenclose.notations = new Map([
  187. Notation.Border('top'),
  188. Notation.Border('right'),
  189. Notation.Border('bottom'),
  190. Notation.Border('left'),
  191. Notation.Border2('actuarial', 'top', 'right'),
  192. Notation.Border2('madruwb', 'bottom', 'right'),
  193. Notation.DiagonalStrike('up'),
  194. Notation.DiagonalStrike('down'),
  195. ['horizontalstrike', {
  196. renderer: Notation.RenderLine('horizontal', 'Y'),
  197. bbox: function (node) { return [0, node.padding, 0, node.padding]; }
  198. }],
  199. ['verticalstrike', {
  200. renderer: Notation.RenderLine('vertical', 'X'),
  201. bbox: function (node) { return [node.padding, 0, node.padding, 0]; }
  202. }],
  203. ['box', {
  204. renderer: function (node, _child) {
  205. var _a = node.getBBox(), w = _a.w, h = _a.h, d = _a.d;
  206. node.adaptor.append(node.element, node.box(w, h, d));
  207. },
  208. bbox: Notation.fullBBox,
  209. border: Notation.fullBorder,
  210. remove: 'left right top bottom'
  211. }],
  212. ['roundedbox', {
  213. renderer: function (node, _child) {
  214. var _a = node.getBBox(), w = _a.w, h = _a.h, d = _a.d;
  215. var r = node.thickness + node.padding;
  216. node.adaptor.append(node.element, node.box(w, h, d, r));
  217. },
  218. bbox: Notation.fullBBox
  219. }],
  220. ['circle', {
  221. renderer: function (node, _child) {
  222. var _a = node.getBBox(), w = _a.w, h = _a.h, d = _a.d;
  223. node.adaptor.append(node.element, node.ellipse(w, h, d));
  224. },
  225. bbox: Notation.fullBBox
  226. }],
  227. ['phasorangle', {
  228. renderer: function (node, _child) {
  229. var _a = node.getBBox(), w = _a.w, h = _a.h, d = _a.d;
  230. var a = node.getArgMod(1.75 * node.padding, h + d)[0];
  231. var t = node.thickness / 2;
  232. var HD = h + d;
  233. var cos = Math.cos(a);
  234. node.adaptor.append(node.element, node.path('mitre', 'M', w, t - d, 'L', t + cos * t, t - d, 'L', cos * HD + t, HD - d - t));
  235. },
  236. bbox: function (node) {
  237. var p = node.padding / 2;
  238. var t = node.thickness;
  239. return [2 * p, p, p + t, 3 * p + t];
  240. },
  241. border: function (node) { return [0, 0, node.thickness, 0]; },
  242. remove: 'bottom'
  243. }],
  244. Notation.Arrow('up'),
  245. Notation.Arrow('down'),
  246. Notation.Arrow('left'),
  247. Notation.Arrow('right'),
  248. Notation.Arrow('updown'),
  249. Notation.Arrow('leftright'),
  250. Notation.DiagonalArrow('updiagonal'),
  251. Notation.DiagonalArrow('northeast'),
  252. Notation.DiagonalArrow('southeast'),
  253. Notation.DiagonalArrow('northwest'),
  254. Notation.DiagonalArrow('southwest'),
  255. Notation.DiagonalArrow('northeastsouthwest'),
  256. Notation.DiagonalArrow('northwestsoutheast'),
  257. ['longdiv', {
  258. renderer: function (node, _child) {
  259. var _a = node.getBBox(), w = _a.w, h = _a.h, d = _a.d;
  260. var t = node.thickness / 2;
  261. var p = node.padding;
  262. node.adaptor.append(node.element, node.path('round', 'M', t, t - d, 'a', p - t / 2, (h + d) / 2 - 4 * t, 0, '0,1', 0, h + d - 2 * t, 'L', w - t, h - t));
  263. },
  264. bbox: function (node) {
  265. var p = node.padding;
  266. var t = node.thickness;
  267. return [p + t, p, p, 2 * p + t / 2];
  268. }
  269. }],
  270. ['radical', {
  271. renderer: function (node, child) {
  272. node.msqrt.toSVG(child);
  273. var left = node.sqrtTRBL()[3];
  274. node.place(-left, 0, child);
  275. },
  276. init: function (node) {
  277. node.msqrt = node.createMsqrt(node.childNodes[0]);
  278. },
  279. bbox: function (node) { return node.sqrtTRBL(); },
  280. renderChild: true
  281. }]
  282. ]);
  283. return SVGmenclose;
  284. }((0, menclose_js_1.CommonMencloseMixin)(Wrapper_js_1.SVGWrapper)));
  285. exports.SVGmenclose = SVGmenclose;
  286. //# sourceMappingURL=menclose.js.map