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