1 | import { isNode } from '../../utils/is.js';
|
2 | import { factory } from '../../utils/factory.js';
|
3 | var name = 'ParenthesisNode';
|
4 | var dependencies = ['Node'];
|
5 | export var createParenthesisNode = factory(name, dependencies, (_ref) => {
|
6 | var {
|
7 | Node
|
8 | } = _ref;
|
9 |
|
10 | |
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function ParenthesisNode(content) {
|
18 | if (!(this instanceof ParenthesisNode)) {
|
19 | throw new SyntaxError('Constructor must be called with the new operator');
|
20 | }
|
21 |
|
22 |
|
23 | if (!isNode(content)) {
|
24 | throw new TypeError('Node expected for parameter "content"');
|
25 | }
|
26 |
|
27 | this.content = content;
|
28 | }
|
29 |
|
30 | ParenthesisNode.prototype = new Node();
|
31 | ParenthesisNode.prototype.type = 'ParenthesisNode';
|
32 | ParenthesisNode.prototype.isParenthesisNode = true;
|
33 | |
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | ParenthesisNode.prototype._compile = function (math, argNames) {
|
48 | return this.content._compile(math, argNames);
|
49 | };
|
50 | |
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | ParenthesisNode.prototype.getContent = function () {
|
58 | return this.content.getContent();
|
59 | };
|
60 | |
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | ParenthesisNode.prototype.forEach = function (callback) {
|
67 | callback(this.content, 'content', this);
|
68 | };
|
69 | |
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | ParenthesisNode.prototype.map = function (callback) {
|
78 | var content = callback(this.content, 'content', this);
|
79 | return new ParenthesisNode(content);
|
80 | };
|
81 | |
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | ParenthesisNode.prototype.clone = function () {
|
88 | return new ParenthesisNode(this.content);
|
89 | };
|
90 | |
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | ParenthesisNode.prototype._toString = function (options) {
|
99 | if (!options || options && !options.parenthesis || options && options.parenthesis === 'keep') {
|
100 | return '(' + this.content.toString(options) + ')';
|
101 | }
|
102 |
|
103 | return this.content.toString(options);
|
104 | };
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | ParenthesisNode.prototype.toJSON = function () {
|
112 | return {
|
113 | mathjs: 'ParenthesisNode',
|
114 | content: this.content
|
115 | };
|
116 | };
|
117 | |
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | ParenthesisNode.fromJSON = function (json) {
|
127 | return new ParenthesisNode(json.content);
|
128 | };
|
129 | |
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | ParenthesisNode.prototype.toHTML = function (options) {
|
138 | if (!options || options && !options.parenthesis || options && options.parenthesis === 'keep') {
|
139 | return '<span class="math-parenthesis math-round-parenthesis">(</span>' + this.content.toHTML(options) + '<span class="math-parenthesis math-round-parenthesis">)</span>';
|
140 | }
|
141 |
|
142 | return this.content.toHTML(options);
|
143 | };
|
144 | |
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 | ParenthesisNode.prototype._toTex = function (options) {
|
153 | if (!options || options && !options.parenthesis || options && options.parenthesis === 'keep') {
|
154 | return "\\left(".concat(this.content.toTex(options), "\\right)");
|
155 | }
|
156 |
|
157 | return this.content.toTex(options);
|
158 | };
|
159 |
|
160 | return ParenthesisNode;
|
161 | }, {
|
162 | isClass: true,
|
163 | isNode: true
|
164 | }); |
\ | No newline at end of file |