@oat-sa/tao-core-ui 1.67.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/README.md +17 -16
  2. package/dist/animable/absorbable/css/absorb.css +25 -29
  3. package/dist/animable/absorbable/css/absorb.css.map +1 -1
  4. package/dist/animable/pulsable/css/pulse.css +20 -23
  5. package/dist/animable/pulsable/css/pulse.css.map +1 -1
  6. package/dist/autocomplete/css/autocomplete.css +20 -21
  7. package/dist/autocomplete/css/autocomplete.css.map +1 -1
  8. package/dist/badge/css/badge.css +67 -79
  9. package/dist/badge/css/badge.css.map +1 -1
  10. package/dist/breadcrumbs/css/breadcrumbs.css +54 -61
  11. package/dist/breadcrumbs/css/breadcrumbs.css.map +1 -1
  12. package/dist/bulkActionPopup/css/bulkActionPopup.css +27 -42
  13. package/dist/bulkActionPopup/css/bulkActionPopup.css.map +1 -1
  14. package/dist/calculator/css/calculator.css +91 -112
  15. package/dist/calculator/css/calculator.css.map +1 -1
  16. package/dist/class/css/selector.css +83 -97
  17. package/dist/class/css/selector.css.map +1 -1
  18. package/dist/component/css/components.css +351 -406
  19. package/dist/component/css/components.css.map +1 -1
  20. package/dist/component/css/windowComponent.css +19 -28
  21. package/dist/component/css/windowComponent.css.map +1 -1
  22. package/dist/contextualPopup/css/contextualPopup.css +42 -55
  23. package/dist/contextualPopup/css/contextualPopup.css.map +1 -1
  24. package/dist/dashboard/css/dashboard.css +43 -57
  25. package/dist/dashboard/css/dashboard.css.map +1 -1
  26. package/dist/datalist/css/datalist.css +63 -88
  27. package/dist/datalist/css/datalist.css.map +1 -1
  28. package/dist/datatable/css/datatable.css +84 -113
  29. package/dist/datatable/css/datatable.css.map +1 -1
  30. package/dist/dateRange/css/dateRange.css +1 -2
  31. package/dist/dateRange/css/dateRange.css.map +1 -1
  32. package/dist/datetime/css/picker.css +71 -103
  33. package/dist/datetime/css/picker.css.map +1 -1
  34. package/dist/destination/css/selector.css +17 -24
  35. package/dist/destination/css/selector.css.map +1 -1
  36. package/dist/documentViewer/css/documentViewer.css +137 -162
  37. package/dist/documentViewer/css/documentViewer.css.map +1 -1
  38. package/dist/dropdown/css/dropdown.css +55 -72
  39. package/dist/dropdown/css/dropdown.css.map +1 -1
  40. package/dist/dynamicComponent/css/dynamicComponent.css +78 -91
  41. package/dist/dynamicComponent/css/dynamicComponent.css.map +1 -1
  42. package/dist/form/css/dropdownForm.css +36 -45
  43. package/dist/form/css/dropdownForm.css.map +1 -1
  44. package/dist/form/css/form.css +12 -16
  45. package/dist/form/css/form.css.map +1 -1
  46. package/dist/form/validator/css/validator.css +5 -7
  47. package/dist/form/validator/css/validator.css.map +1 -1
  48. package/dist/form/widget/css/widget.css +26 -34
  49. package/dist/form/widget/css/widget.css.map +1 -1
  50. package/dist/generis/form/css/form.css +14 -18
  51. package/dist/generis/form/css/form.css.map +1 -1
  52. package/dist/generis/validator/css/validator.css +5 -7
  53. package/dist/generis/validator/css/validator.css.map +1 -1
  54. package/dist/generis/widget/css/widget.css +29 -38
  55. package/dist/generis/widget/css/widget.css.map +1 -1
  56. package/dist/itemButtonList/css/item-button-list.css +135 -172
  57. package/dist/itemButtonList/css/item-button-list.css.map +1 -1
  58. package/dist/listbox/css/listbox.css +64 -84
  59. package/dist/listbox/css/listbox.css.map +1 -1
  60. package/dist/loadingButton/css/button.css +20 -29
  61. package/dist/loadingButton/css/button.css.map +1 -1
  62. package/dist/maths/calculator/basicCalculator.js +4 -4
  63. package/dist/maths/calculator/calculatorComponent.js +22 -25
  64. package/dist/maths/calculator/core/board.js +12327 -720
  65. package/dist/maths/calculator/core/labels.js +7918 -138
  66. package/dist/maths/calculator/core/plugin.js +4 -5
  67. package/dist/maths/calculator/css/calculator.css +224 -270
  68. package/dist/maths/calculator/css/calculator.css.map +1 -1
  69. package/dist/maths/calculator/defaultCalculator.js +10 -6
  70. package/dist/maths/calculator/plugins/keyboard/templateKeyboard/templateKeyboard.js +23 -25
  71. package/dist/maths/calculator/plugins/screen/simpleScreen/simpleScreen.js +7973 -194
  72. package/dist/maths/calculator/scientificCalculator.js +7 -12
  73. package/dist/mediaplayer/css/player.css +281 -370
  74. package/dist/mediaplayer/css/player.css.map +1 -1
  75. package/dist/pagination/css/pagination.css +38 -49
  76. package/dist/pagination/css/pagination.css.map +1 -1
  77. package/dist/propertySelector/css/propertySelector.css +34 -44
  78. package/dist/propertySelector/css/propertySelector.css.map +1 -1
  79. package/dist/resource/css/selector.css +400 -490
  80. package/dist/resource/css/selector.css.map +1 -1
  81. package/dist/resourcemgr/css/resourcemgr.css +192 -237
  82. package/dist/resourcemgr/css/resourcemgr.css.map +1 -1
  83. package/dist/searchModal/css/advancedSearch.css +92 -121
  84. package/dist/searchModal/css/advancedSearch.css.map +1 -1
  85. package/dist/searchModal/css/searchModal.css +261 -333
  86. package/dist/searchModal/css/searchModal.css.map +1 -1
  87. package/dist/switch/css/switch.css +36 -47
  88. package/dist/switch/css/switch.css.map +1 -1
  89. package/dist/tabs/css/tabs.css +32 -40
  90. package/dist/tabs/css/tabs.css.map +1 -1
  91. package/dist/taskQueue/css/taskQueue.css +17 -27
  92. package/dist/taskQueue/css/taskQueue.css.map +1 -1
  93. package/dist/taskQueueButton/css/taskable.css +1 -2
  94. package/dist/taskQueueButton/css/taskable.css.map +1 -1
  95. package/dist/taskQueueButton/css/treeButton.css +20 -26
  96. package/dist/taskQueueButton/css/treeButton.css.map +1 -1
  97. package/dist/tristateCheckboxGroup/css/tristateCheckboxGroup.css +3 -5
  98. package/dist/tristateCheckboxGroup/css/tristateCheckboxGroup.css.map +1 -1
  99. package/dist/waitingDialog/css/waitingDialog.css +18 -23
  100. package/dist/waitingDialog/css/waitingDialog.css.map +1 -1
  101. package/package.json +20 -24
  102. package/scss/inc/_base.scss +9 -8
  103. package/scss/inc/_flex-grid.scss +1 -1
  104. package/scss/inc/_forms.scss +5 -5
  105. package/scss/inc/_functions.scss +8 -8
  106. package/scss/inc/fonts/_tao-icon-classes.scss +230 -230
  107. package/src/animable/absorbable/css/absorb.css +25 -29
  108. package/src/animable/absorbable/css/absorb.css.map +1 -1
  109. package/src/animable/pulsable/css/pulse.css +20 -23
  110. package/src/animable/pulsable/css/pulse.css.map +1 -1
  111. package/src/autocomplete/css/autocomplete.css +20 -21
  112. package/src/autocomplete/css/autocomplete.css.map +1 -1
  113. package/src/badge/css/badge.css +67 -79
  114. package/src/badge/css/badge.css.map +1 -1
  115. package/src/breadcrumbs/css/breadcrumbs.css +54 -61
  116. package/src/breadcrumbs/css/breadcrumbs.css.map +1 -1
  117. package/src/bulkActionPopup/css/bulkActionPopup.css +27 -42
  118. package/src/bulkActionPopup/css/bulkActionPopup.css.map +1 -1
  119. package/src/calculator/css/calculator.css +91 -112
  120. package/src/calculator/css/calculator.css.map +1 -1
  121. package/src/calculator/scss/calculator.scss +1 -1
  122. package/src/class/css/selector.css +83 -97
  123. package/src/class/css/selector.css.map +1 -1
  124. package/src/component/css/components.css +351 -406
  125. package/src/component/css/components.css.map +1 -1
  126. package/src/component/css/windowComponent.css +19 -28
  127. package/src/component/css/windowComponent.css.map +1 -1
  128. package/src/contextualPopup/css/contextualPopup.css +42 -55
  129. package/src/contextualPopup/css/contextualPopup.css.map +1 -1
  130. package/src/css/basic.css +4000 -4374
  131. package/src/css/basic.css.map +1 -1
  132. package/src/dashboard/css/dashboard.css +43 -57
  133. package/src/dashboard/css/dashboard.css.map +1 -1
  134. package/src/datalist/css/datalist.css +63 -88
  135. package/src/datalist/css/datalist.css.map +1 -1
  136. package/src/datatable/css/datatable.css +84 -113
  137. package/src/datatable/css/datatable.css.map +1 -1
  138. package/src/dateRange/css/dateRange.css +1 -2
  139. package/src/dateRange/css/dateRange.css.map +1 -1
  140. package/src/datetime/css/picker.css +71 -103
  141. package/src/datetime/css/picker.css.map +1 -1
  142. package/src/destination/css/selector.css +17 -24
  143. package/src/destination/css/selector.css.map +1 -1
  144. package/src/documentViewer/css/documentViewer.css +137 -162
  145. package/src/documentViewer/css/documentViewer.css.map +1 -1
  146. package/src/dropdown/css/dropdown.css +55 -72
  147. package/src/dropdown/css/dropdown.css.map +1 -1
  148. package/src/dynamicComponent/css/dynamicComponent.css +78 -91
  149. package/src/dynamicComponent/css/dynamicComponent.css.map +1 -1
  150. package/src/form/css/dropdownForm.css +36 -45
  151. package/src/form/css/dropdownForm.css.map +1 -1
  152. package/src/form/css/form.css +12 -16
  153. package/src/form/css/form.css.map +1 -1
  154. package/src/form/validator/css/validator.css +5 -7
  155. package/src/form/validator/css/validator.css.map +1 -1
  156. package/src/form/widget/css/widget.css +26 -34
  157. package/src/form/widget/css/widget.css.map +1 -1
  158. package/src/generis/form/css/form.css +14 -18
  159. package/src/generis/form/css/form.css.map +1 -1
  160. package/src/generis/validator/css/validator.css +5 -7
  161. package/src/generis/validator/css/validator.css.map +1 -1
  162. package/src/generis/widget/css/widget.css +29 -38
  163. package/src/generis/widget/css/widget.css.map +1 -1
  164. package/src/itemButtonList/css/item-button-list.css +135 -172
  165. package/src/itemButtonList/css/item-button-list.css.map +1 -1
  166. package/src/listbox/css/listbox.css +64 -84
  167. package/src/listbox/css/listbox.css.map +1 -1
  168. package/src/listbox/scss/listbox.scss +8 -8
  169. package/src/loadingButton/css/button.css +20 -29
  170. package/src/loadingButton/css/button.css.map +1 -1
  171. package/src/maths/calculator/basicCalculator.js +1 -4
  172. package/src/maths/calculator/calculatorComponent.js +49 -60
  173. package/src/maths/calculator/core/board.js +372 -493
  174. package/src/maths/calculator/core/labels.js +46 -48
  175. package/src/maths/calculator/core/plugin.js +3 -5
  176. package/src/maths/calculator/core/tpl/terms.tpl +7 -1
  177. package/src/maths/calculator/css/calculator.css +224 -270
  178. package/src/maths/calculator/css/calculator.css.map +1 -1
  179. package/src/maths/calculator/defaultCalculator.js +7 -9
  180. package/src/maths/calculator/plugins/keyboard/templateKeyboard/defaultTemplate.tpl +3 -3
  181. package/src/maths/calculator/plugins/keyboard/templateKeyboard/templateKeyboard.js +17 -20
  182. package/src/maths/calculator/plugins/screen/simpleScreen/simpleScreen.js +102 -108
  183. package/src/maths/calculator/scientificCalculator.js +2 -10
  184. package/src/maths/calculator/scss/calculator.scss +20 -7
  185. package/src/maths/calculator/tpl/basicKeyboard.tpl +3 -3
  186. package/src/maths/calculator/tpl/scientificKeyboard.tpl +4 -4
  187. package/src/mediaplayer/css/player.css +281 -370
  188. package/src/mediaplayer/css/player.css.map +1 -1
  189. package/src/pagination/css/pagination.css +38 -49
  190. package/src/pagination/css/pagination.css.map +1 -1
  191. package/src/propertySelector/css/propertySelector.css +34 -44
  192. package/src/propertySelector/css/propertySelector.css.map +1 -1
  193. package/src/resource/css/selector.css +400 -490
  194. package/src/resource/css/selector.css.map +1 -1
  195. package/src/resourcemgr/css/resourcemgr.css +192 -237
  196. package/src/resourcemgr/css/resourcemgr.css.map +1 -1
  197. package/src/searchModal/css/advancedSearch.css +92 -121
  198. package/src/searchModal/css/advancedSearch.css.map +1 -1
  199. package/src/searchModal/css/searchModal.css +261 -333
  200. package/src/searchModal/css/searchModal.css.map +1 -1
  201. package/src/searchModal/scss/searchModal.scss +1 -1
  202. package/src/switch/css/switch.css +36 -47
  203. package/src/switch/css/switch.css.map +1 -1
  204. package/src/tabs/css/tabs.css +32 -40
  205. package/src/tabs/css/tabs.css.map +1 -1
  206. package/src/taskQueue/css/taskQueue.css +17 -27
  207. package/src/taskQueue/css/taskQueue.css.map +1 -1
  208. package/src/taskQueueButton/css/taskable.css +1 -2
  209. package/src/taskQueueButton/css/taskable.css.map +1 -1
  210. package/src/taskQueueButton/css/treeButton.css +20 -26
  211. package/src/taskQueueButton/css/treeButton.css.map +1 -1
  212. package/src/tristateCheckboxGroup/css/tristateCheckboxGroup.css +3 -5
  213. package/src/tristateCheckboxGroup/css/tristateCheckboxGroup.css.map +1 -1
  214. package/src/waitingDialog/css/waitingDialog.css +18 -23
  215. package/src/waitingDialog/css/waitingDialog.css.map +1 -1
  216. package/dist/maths/calculator/core/areaBroker.js +0 -43
  217. package/dist/maths/calculator/core/expression.js +0 -463
  218. package/dist/maths/calculator/core/terms.js +0 -456
  219. package/dist/maths/calculator/core/tokenizer.js +0 -229
  220. package/dist/maths/calculator/core/tokens.js +0 -167
  221. package/dist/maths/calculator/plugins/core/degrad.js +0 -71
  222. package/dist/maths/calculator/plugins/core/history.js +0 -149
  223. package/dist/maths/calculator/plugins/core/remind.js +0 -76
  224. package/dist/maths/calculator/plugins/core/stepNavigation.js +0 -148
  225. package/dist/maths/calculator/plugins/modifiers/pow10.js +0 -136
  226. package/dist/maths/calculator/plugins/modifiers/sign.js +0 -314
  227. package/dist/maths/calculator/pluginsLoader.js +0 -47
  228. package/src/maths/calculator/core/areaBroker.js +0 -38
  229. package/src/maths/calculator/core/expression.js +0 -430
  230. package/src/maths/calculator/core/terms.js +0 -459
  231. package/src/maths/calculator/core/tokenizer.js +0 -245
  232. package/src/maths/calculator/core/tokens.js +0 -178
  233. package/src/maths/calculator/plugins/core/degrad.js +0 -90
  234. package/src/maths/calculator/plugins/core/history.js +0 -166
  235. package/src/maths/calculator/plugins/core/remind.js +0 -96
  236. package/src/maths/calculator/plugins/core/stepNavigation.js +0 -175
  237. package/src/maths/calculator/plugins/modifiers/pow10.js +0 -143
  238. package/src/maths/calculator/plugins/modifiers/sign.js +0 -339
  239. package/src/maths/calculator/pluginsLoader.js +0 -46
@@ -1,430 +0,0 @@
1
- /**
2
- * This program is free software; you can redistribute it and/or
3
- * modify it under the terms of the GNU General Public License
4
- * as published by the Free Software Foundation; under version 2
5
- * of the License (non-upgradable).
6
- *
7
- * This program is distributed in the hope that it will be useful,
8
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- * GNU General Public License for more details.
11
- *
12
- * You should have received a copy of the GNU General Public License
13
- * along with this program; if not, write to the Free Software
14
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15
- *
16
- * Copyright (c) 2019 Open Assessment Technologies SA ;
17
- */
18
- /**
19
- * Helper that takes care of expressions
20
- * @author Jean-Sébastien Conan <jean-sebastien@taotesting.com>
21
- */
22
- import _ from 'lodash';
23
- import registeredTerms from 'ui/maths/calculator/core/terms';
24
- import tokensHelper from 'ui/maths/calculator/core/tokens';
25
- import tokenizerFactory from 'ui/maths/calculator/core/tokenizer';
26
- import termsTpl from 'ui/maths/calculator/core/tpl/terms';
27
-
28
- /**
29
- * @typedef {term} renderTerm - Represents a renderable tokenizable term
30
- * @property {Array} startExponent - List of exponent starts (will produce exponent notation for the term)
31
- * @property {Array} endExponent - List of exponent ends (will finish exponent notation for the term)
32
- * @property {Boolean} prefixed - Tells if the term is prefixed (i.e. function treated as binary operator)
33
- * @property {Boolean} elide - Allows to hide the term when operands exist on each side
34
- */
35
-
36
- /**
37
- * Name of the variable that contains the last result
38
- * @type {String}
39
- */
40
- var lastResultVariableName = registeredTerms.ANS.value;
41
-
42
- /**
43
- * Regex that matches the prefixed function operators
44
- * @type {RegExp}
45
- */
46
- var rePrefixedTerm = /^@[a-zA-Z_]\w*$/;
47
-
48
- /**
49
- * Regex that matches the usual error tokens in a result
50
- * @type {RegExp}
51
- */
52
- var reErrorValue = /(NaN|[+-]?Infinity)/;
53
-
54
- /**
55
- * Regex that matches the last result variable
56
- * @type {RegExp}
57
- */
58
- var reAnsVar = new RegExp('\\b' + lastResultVariableName + '\\b', 'g');
59
-
60
- /**
61
- * List of tokens representing sign or sum
62
- * @type {String[]}
63
- */
64
- var signOperators = ['NEG', 'POS', 'SUB', 'ADD'];
65
-
66
- /**
67
- * List of tokens representing sub exponent parts to continue
68
- * @type {String[]}
69
- */
70
- var continueExponent = ['POW', 'NTHRT'];
71
-
72
- /**
73
- * Default number of significant digits used to round displayed variables
74
- * @type {Number}
75
- */
76
- var defaultDecimalDigits = 5;
77
-
78
- /**
79
- * List of helpers that apply on expression
80
- * @type {Object}
81
- */
82
- var expressionHelper = {
83
- /**
84
- * Checks if an expression contains an error token
85
- * @param {String|Number|Object} expression
86
- * @returns {Boolean}
87
- */
88
- containsError: function containsError(expression) {
89
- return reErrorValue.test(tokensHelper.stringValue(expression));
90
- },
91
-
92
- /**
93
- * Replace the last result variable by a particular value in an expression
94
- * @param {String|Number|Object} expression
95
- * @param {String|Number|Object} value
96
- * @returns {String}
97
- */
98
- replaceLastResult: function replaceLastResult(expression, value) {
99
- return tokensHelper.stringValue(expression).replace(reAnsVar, tokensHelper.stringValue(value || '0'));
100
- },
101
-
102
- /**
103
- * Rounds the value of a variable
104
- * @param {Object} variable
105
- * @param {Number} [decimalDigits=5]
106
- * @returns {String}
107
- */
108
- roundVariable: function roundVariable(variable, decimalDigits) {
109
- var resultString = tokensHelper.stringValue(variable);
110
- var fullString = resultString;
111
- var value = variable && variable.result;
112
-
113
- decimalDigits = decimalDigits || defaultDecimalDigits;
114
-
115
- if ('undefined' !== typeof value) {
116
- if (value.toExponential && resultString.indexOf(registeredTerms.EXP10.value) > 0) {
117
- resultString = value.toExponential(decimalDigits).toString();
118
- } else if (value.toDecimalPlaces && resultString.indexOf(registeredTerms.DOT.value) > 0) {
119
- resultString = value.toDecimalPlaces(decimalDigits).toString();
120
- }
121
-
122
- if (resultString.length < fullString.length) {
123
- resultString += registeredTerms.ELLIPSIS.value;
124
- } else {
125
- resultString = fullString;
126
- }
127
- }
128
- return resultString;
129
- },
130
-
131
- /**
132
- * Rounds the value of the last result variable
133
- * @param {Object} variables
134
- * @param {Number} [decimalDigits=5]
135
- * @returns {Object}
136
- */
137
- roundLastResultVariable: function roundLastResultVariable(variables, decimalDigits) {
138
- if (variables && 'undefined' !== typeof variables[lastResultVariableName]) {
139
- variables[lastResultVariableName] = expressionHelper.roundVariable(
140
- variables[lastResultVariableName],
141
- decimalDigits
142
- );
143
- }
144
- return variables;
145
- },
146
-
147
- /**
148
- * Replace sign operators by a proper symbol
149
- * @param {String|Number|Object} expression
150
- * @returns {String}
151
- */
152
- renderSign: function renderSign(expression) {
153
- return tokensHelper
154
- .stringValue(expression)
155
- .replace(registeredTerms.SUB.value, registeredTerms.NEG.label)
156
- .replace(registeredTerms.ADD.value, registeredTerms.POS.label);
157
- },
158
-
159
- /**
160
- * Renders an expression into a HTML string, using the display label of each extracted token .
161
- * @param {String|Number|Object|token[]} expression
162
- * @param {Object} [variables]
163
- * @param {calculatorTokenizer} [tokenizer]
164
- * @returns {String}
165
- */
166
- render: function render(expression, variables, tokenizer) {
167
- var tokens = expression;
168
- var exponents = [];
169
- var terms = [];
170
- var previous;
171
-
172
- /**
173
- * Transform an operator to a sign
174
- * @param {renderTerm} term
175
- * @param {String} token
176
- */
177
- function toSignOperator(term, token) {
178
- if (
179
- !previous ||
180
- tokensHelper.isModifier(previous.type) ||
181
- previous.token === 'LPAR' ||
182
- previous.token === 'EXP10'
183
- ) {
184
- term.label = registeredTerms[token].label;
185
- term.token = token;
186
- }
187
- }
188
-
189
- // the expression might be already tokenized, if not we need to tokenize it
190
- if (!_.isArray(expression)) {
191
- // we need a valid tokenizer, so if none is provided we must build one
192
- if (!tokenizer || !tokenizer.tokenize) {
193
- tokenizer = tokenizerFactory();
194
- }
195
- tokens = tokenizer.tokenize(expression);
196
- }
197
-
198
- variables = variables || {};
199
-
200
- // each token needs to be translated into a displayable term
201
- _.forEach(tokens, function(token, index) {
202
- var registeredTerm = registeredTerms[token.type];
203
-
204
- /**
205
- * @type {renderTerm}
206
- */
207
- var term = {
208
- type: token.type,
209
- token: token.type,
210
- value: token.value,
211
- label: token.value,
212
- description: token.value,
213
- exponent: null,
214
- startExponent: [],
215
- endExponent: [],
216
- prefixed: rePrefixedTerm.test(token.value),
217
- elide: false
218
- };
219
-
220
- if (registeredTerm) {
221
- _.merge(term, registeredTerm);
222
-
223
- // always display the actual value of the last result variable
224
- // also takes care of the value's sign
225
- if (term.value === lastResultVariableName && 'undefined' !== typeof variables[term.value]) {
226
- term.label = expressionHelper.render(variables[term.value], variables, tokenizer);
227
- }
228
- } else if (term.token === 'term') {
229
- // unspecified token can be a variable
230
- if ('undefined' !== typeof variables[term.value]) {
231
- term.type = 'variable';
232
- } else {
233
- term.type = 'unknown';
234
- }
235
- }
236
-
237
- // take care of the value's sign
238
- if (term.token === 'SUB') {
239
- toSignOperator(term, 'NEG');
240
- } else if (term.token === 'ADD') {
241
- toSignOperator(term, 'POS');
242
- }
243
-
244
- terms.push(term);
245
-
246
- // exponents will be processed in a second pass
247
- // for now we just need to keep track of the position
248
- if (term.exponent) {
249
- exponents.push(index);
250
- }
251
-
252
- previous = term;
253
- });
254
-
255
- // if any exponent has been discovered, we need to process them now
256
- _.forEach(exponents, function(index) {
257
- var term = terms[index];
258
- if (term.exponent === 'left' && index > 0) {
259
- exponentOnTheLeft(index, terms);
260
- } else if (term.exponent === 'right' && index < terms.length - 1) {
261
- exponentOnTheRight(index, terms);
262
- }
263
- });
264
-
265
- return termsTpl(terms);
266
- }
267
- };
268
-
269
- /**
270
- * Search for the full operand on the left, then tag the edges with exponent flags
271
- * @param {Number} index
272
- * @param {renderTerm[]} terms
273
- */
274
- function exponentOnTheLeft(index, terms) {
275
- var parenthesis = 0;
276
- var next = terms[index];
277
- var term = terms[--index];
278
-
279
- /**
280
- * Simply moves the cursor to the next term to examine.
281
- * Here the move is made from the right to the left.
282
- */
283
- function nextTerm() {
284
- next = term;
285
- term = terms[--index];
286
- }
287
-
288
- // only take care of actual operand value or sub expression (starting from the right)
289
- if (term && (tokensHelper.isOperand(term.type) || term.token === 'RPAR')) {
290
- term.endExponent.push(term.endExponent.length);
291
-
292
- if (term.token === 'RPAR') {
293
- // closing parenthesis, we need to find the opening parenthesis
294
- parenthesis++;
295
- while (index > 0 && parenthesis > 0) {
296
- nextTerm();
297
-
298
- if (term.token === 'RPAR') {
299
- parenthesis++;
300
- } else if (term.token === 'LPAR') {
301
- parenthesis--;
302
- }
303
- }
304
-
305
- // a function could be attached to the sub expression, if so we must keep the link
306
- // however, the prefixed functions are particular as they act as a binary operators,
307
- // and therefore are not considered as function here
308
- if (index > 0 && tokensHelper.isFunction(terms[index - 1]) && !terms[index - 1].prefixed) {
309
- nextTerm();
310
- }
311
- } else if (tokensHelper.isDigit(term.type)) {
312
- // chain of digits should be treated as a single operand
313
- while (index && tokensHelper.isDigit(term.type)) {
314
- nextTerm();
315
- }
316
- // if the end of the chain has been overflown, we must step back one token
317
- if (!tokensHelper.isDigit(term.type)) {
318
- term = next;
319
- }
320
- }
321
- term.startExponent.push(term.startExponent.length);
322
- }
323
- }
324
-
325
- /**
326
- * Search for the full operand on the right, then tag the edges with exponent flags
327
- * @param {Number} index
328
- * @param {renderTerm[]} terms
329
- */
330
- function exponentOnTheRight(index, terms) {
331
- var last = terms.length - 1;
332
- var parenthesis = 0;
333
- var startAt = index;
334
- var previous = terms[index];
335
- var term = terms[++index];
336
- var shouldContinue;
337
-
338
- /**
339
- * Simply moves the cursor to the next term to examine.
340
- * Here the move is made from the left to the right.
341
- */
342
- function nextTerm() {
343
- previous = term;
344
- term = terms[++index];
345
- }
346
-
347
- /**
348
- * Simply moves back the cursor to the previous term.
349
- * Here the move is made from the right to the left.
350
- */
351
- function previousTerm() {
352
- term = previous;
353
- previous = terms[--index];
354
- }
355
-
356
- // only take care of actual operand value or sub expression (starting from the left)
357
- if (
358
- term &&
359
- (tokensHelper.isOperand(term.type) || term.token === 'LPAR' || signOperators.indexOf(term.token) >= 0)
360
- ) {
361
- term.startExponent.push(term.startExponent.length);
362
-
363
- // we use an internal loop as exponents could be chained
364
- do {
365
- shouldContinue = false;
366
-
367
- // functions are attached to an operand, and this link should be kept
368
- while (index < last && (tokensHelper.isFunction(term.type) || signOperators.indexOf(term.token) >= 0)) {
369
- nextTerm();
370
- }
371
-
372
- // if the end has been reached, step back one token
373
- if (!term) {
374
- previousTerm();
375
- }
376
-
377
- if (term.token === 'LPAR') {
378
- // opening parenthesis, we need to find the closing parenthesis
379
- parenthesis++;
380
- while (index < last && parenthesis > 0) {
381
- nextTerm();
382
-
383
- if (term.token === 'LPAR') {
384
- parenthesis++;
385
- } else if (term.token === 'RPAR') {
386
- parenthesis--;
387
- }
388
- }
389
- } else if (tokensHelper.isDigit(term.type)) {
390
- // chain of digits should be treated as a single operand
391
- while (index < last && tokensHelper.isDigit(term.type)) {
392
- nextTerm();
393
- }
394
- // if the end of the chain has been overflown, we must step back one token
395
- if (!term || !tokensHelper.isDigit(term.type)) {
396
- previousTerm();
397
- }
398
- }
399
-
400
- // factorial is a special case, as the operator can be placed either on the right or on the left
401
- // in any case it should be attached to its operand
402
- while (index < last && terms[index + 1].token === 'FAC') {
403
- nextTerm();
404
- }
405
-
406
- // sometimes a sub exponent continues the chain and should be part of the expression to put in exponent
407
- if (index < last && continueExponent.indexOf(terms[index + 1].token) >= 0) {
408
- // the next term should be ignored as we already know it is an exponent operator
409
- // then the term after have to be set as the current one
410
- nextTerm();
411
- nextTerm();
412
- shouldContinue = true;
413
- }
414
- } while (shouldContinue);
415
-
416
- term.endExponent.push(term.endExponent.length);
417
-
418
- // elide the operator if operands are complete
419
- if (
420
- startAt > 0 &&
421
- startAt < last &&
422
- terms[startAt].token === 'POW' &&
423
- terms[startAt + 1].startExponent.length
424
- ) {
425
- terms[startAt].elide = true;
426
- }
427
- }
428
- }
429
-
430
- export default expressionHelper;