jclic 2.2.0 → 2.3.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 (177) hide show
  1. package/README.md +5 -7
  2. package/dist-node/jclic-node.js +14157 -0
  3. package/dist-node/jclic-node.umd.cjs +530 -0
  4. package/package.json +38 -26
  5. package/.vscode/launch.json +0 -33
  6. package/.vscode/settings.json +0 -13
  7. package/CHANGELOG.md +0 -664
  8. package/TRANSLATIONS.md +0 -11
  9. package/build-locales.mjs +0 -82
  10. package/dist/jclic-node.js +0 -31678
  11. package/dist/jclic-node.js.map +0 -1
  12. package/dist/jclic.components.LICENSE +0 -2254
  13. package/dist/jclic.min.js +0 -27
  14. package/dist/jclic.min.js.map +0 -1
  15. package/eslint.config.mjs +0 -31
  16. package/jsdoc.config.js +0 -71
  17. package/locales/ar.po +0 -244
  18. package/locales/ast.po +0 -246
  19. package/locales/bs.po +0 -247
  20. package/locales/ca.po +0 -248
  21. package/locales/ca_ES@valencia.po +0 -248
  22. package/locales/cs.po +0 -244
  23. package/locales/da.po +0 -244
  24. package/locales/de.po +0 -246
  25. package/locales/el.po +0 -244
  26. package/locales/es.po +0 -248
  27. package/locales/eu.po +0 -244
  28. package/locales/fr.po +0 -244
  29. package/locales/gl.po +0 -244
  30. package/locales/he.po +0 -244
  31. package/locales/hr.po +0 -245
  32. package/locales/it.po +0 -246
  33. package/locales/ja.po +0 -242
  34. package/locales/jclic.js.pot +0 -241
  35. package/locales/nb_NO.po +0 -244
  36. package/locales/nl.po +0 -244
  37. package/locales/pl.po +0 -244
  38. package/locales/pt.po +0 -244
  39. package/locales/pt_BR.po +0 -248
  40. package/locales/ro.po +0 -248
  41. package/locales/ru.po +0 -245
  42. package/locales/ta.po +0 -244
  43. package/locales/tr.po +0 -246
  44. package/locales/uk.po +0 -247
  45. package/locales/vec.po +0 -244
  46. package/locales/zh_TW.po +0 -246
  47. package/patches/po2json+1.0.0-beta-3.patch +0 -12
  48. package/src/AWT.js +0 -2067
  49. package/src/Activity.js +0 -1311
  50. package/src/Deps.js +0 -232
  51. package/src/GlobalData.js +0 -5
  52. package/src/JClic.js +0 -196
  53. package/src/JClicPlayer.js +0 -1308
  54. package/src/PlayerHistory.js +0 -305
  55. package/src/Utils.js +0 -1355
  56. package/src/activities/associations/ComplexAssociation.js +0 -321
  57. package/src/activities/associations/SimpleAssociation.js +0 -519
  58. package/src/activities/memory/MemoryGame.js +0 -423
  59. package/src/activities/panels/Explore.js +0 -349
  60. package/src/activities/panels/Identify.js +0 -356
  61. package/src/activities/panels/InformationScreen.js +0 -262
  62. package/src/activities/panels/Menu.js +0 -209
  63. package/src/activities/panels/icons/ico00.png +0 -0
  64. package/src/activities/panels/icons/ico01.png +0 -0
  65. package/src/activities/panels/icons/ico02.png +0 -0
  66. package/src/activities/panels/icons/ico03.png +0 -0
  67. package/src/activities/panels/icons/icofolder.png +0 -0
  68. package/src/activities/puzzles/DoublePuzzle.js +0 -424
  69. package/src/activities/puzzles/ExchangePuzzle.js +0 -374
  70. package/src/activities/puzzles/HolePuzzle.js +0 -360
  71. package/src/activities/text/Complete.js +0 -127
  72. package/src/activities/text/Evaluator.js +0 -534
  73. package/src/activities/text/FillInBlanks.js +0 -426
  74. package/src/activities/text/IdentifyText.js +0 -253
  75. package/src/activities/text/OrderText.js +0 -421
  76. package/src/activities/text/TextActivityBase.js +0 -557
  77. package/src/activities/text/TextActivityDocument.js +0 -658
  78. package/src/activities/text/WrittenAnswer.js +0 -557
  79. package/src/activities/textGrid/CrossWord.js +0 -565
  80. package/src/activities/textGrid/WordSearch.js +0 -458
  81. package/src/activities/textGrid/icons/hIcon.svg +0 -3
  82. package/src/activities/textGrid/icons/vIcon.svg +0 -3
  83. package/src/automation/AutoContentProvider.js +0 -182
  84. package/src/automation/arith/Arith.js +0 -864
  85. package/src/bags/ActivitySequence.js +0 -318
  86. package/src/bags/ActivitySequenceElement.js +0 -161
  87. package/src/bags/ActivitySequenceJump.js +0 -140
  88. package/src/bags/ConditionalJumpInfo.js +0 -113
  89. package/src/bags/JumpInfo.js +0 -136
  90. package/src/bags/MediaBag.js +0 -215
  91. package/src/bags/MediaBagElement.js +0 -516
  92. package/src/boxes/AbstractBox.js +0 -699
  93. package/src/boxes/ActiveBagContent.js +0 -494
  94. package/src/boxes/ActiveBox.js +0 -810
  95. package/src/boxes/ActiveBoxBag.js +0 -357
  96. package/src/boxes/ActiveBoxContent.js +0 -484
  97. package/src/boxes/ActiveBoxGrid.js +0 -179
  98. package/src/boxes/BoxBag.js +0 -500
  99. package/src/boxes/BoxBase.js +0 -398
  100. package/src/boxes/BoxConnector.js +0 -325
  101. package/src/boxes/TextGrid.js +0 -887
  102. package/src/boxes/TextGridContent.js +0 -215
  103. package/src/init-jsdom.js +0 -65
  104. package/src/jclic-node.js +0 -219
  105. package/src/media/ActiveMediaBag.js +0 -145
  106. package/src/media/ActiveMediaPlayer.js +0 -297
  107. package/src/media/AudioBuffer.js +0 -219
  108. package/src/media/EventSounds.js +0 -169
  109. package/src/media/EventSoundsElement.js +0 -155
  110. package/src/media/MediaContent.js +0 -328
  111. package/src/media/MidiAudioPlayer.js +0 -254
  112. package/src/media/icons/audio.svg +0 -3
  113. package/src/media/icons/generic.svg +0 -3
  114. package/src/media/icons/mic.svg +0 -3
  115. package/src/media/icons/movie.svg +0 -3
  116. package/src/media/icons/music.svg +0 -3
  117. package/src/media/icons/url.svg +0 -3
  118. package/src/media/sounds/actionError.mp3 +0 -0
  119. package/src/media/sounds/actionOk.mp3 +0 -0
  120. package/src/media/sounds/click.mp3 +0 -0
  121. package/src/media/sounds/finishedError.mp3 +0 -0
  122. package/src/media/sounds/finishedOk.mp3 +0 -0
  123. package/src/media/sounds/start.mp3 +0 -0
  124. package/src/project/JClicProject.js +0 -282
  125. package/src/project/ProjectSettings.js +0 -273
  126. package/src/report/ActionReg.js +0 -123
  127. package/src/report/ActivityReg.js +0 -271
  128. package/src/report/EncryptMin.js +0 -210
  129. package/src/report/Reporter.js +0 -727
  130. package/src/report/SCORM.js +0 -272
  131. package/src/report/SequenceReg.js +0 -275
  132. package/src/report/SessionReg.js +0 -340
  133. package/src/report/SessionStorageReporter.js +0 -131
  134. package/src/report/TCPReporter.js +0 -628
  135. package/src/shapers/ClassicJigSaw.js +0 -138
  136. package/src/shapers/Holes.js +0 -77
  137. package/src/shapers/JigSaw.js +0 -161
  138. package/src/shapers/Rectangular.js +0 -78
  139. package/src/shapers/Shaper.js +0 -386
  140. package/src/shapers/TriangularJigSaw.js +0 -121
  141. package/src/skins/BlueSkin.js +0 -80
  142. package/src/skins/Counter.js +0 -152
  143. package/src/skins/CustomSkin.js +0 -412
  144. package/src/skins/DefaultSkin.js +0 -376
  145. package/src/skins/EmptySkin.js +0 -82
  146. package/src/skins/GreenSkin.js +0 -94
  147. package/src/skins/MiniSkin.js +0 -130
  148. package/src/skins/OrangeSkin.js +0 -78
  149. package/src/skins/SimpleSkin.js +0 -92
  150. package/src/skins/Skin.js +0 -1021
  151. package/src/skins/assets/actionsIcon.svg +0 -3
  152. package/src/skins/assets/appLogo.svg +0 -8
  153. package/src/skins/assets/basic.css +0 -41
  154. package/src/skins/assets/closeDialogIcon.svg +0 -3
  155. package/src/skins/assets/closeIcon.svg +0 -3
  156. package/src/skins/assets/copyIcon.svg +0 -3
  157. package/src/skins/assets/fullScreenExitIcon.svg +0 -3
  158. package/src/skins/assets/fullScreenIcon.svg +0 -3
  159. package/src/skins/assets/infoIcon.svg +0 -3
  160. package/src/skins/assets/main.css +0 -43
  161. package/src/skins/assets/mainHalf.css +0 -23
  162. package/src/skins/assets/mainTwoThirds.css +0 -23
  163. package/src/skins/assets/mini.css +0 -15
  164. package/src/skins/assets/nextIcon.svg +0 -3
  165. package/src/skins/assets/okDialogIcon.svg +0 -3
  166. package/src/skins/assets/prevIcon.svg +0 -3
  167. package/src/skins/assets/reports.css +0 -156
  168. package/src/skins/assets/reportsIcon.svg +0 -3
  169. package/src/skins/assets/scoreIcon.svg +0 -3
  170. package/src/skins/assets/simple.css +0 -16
  171. package/src/skins/assets/simpleHalf.css +0 -11
  172. package/src/skins/assets/simpleTwoThirds.css +0 -11
  173. package/src/skins/assets/timeIcon.svg +0 -4
  174. package/src/skins/assets/waitAnim.css +0 -54
  175. package/src/skins/assets/waitImgBig.svg +0 -3
  176. package/src/skins/assets/waitImgSmall.svg +0 -3
  177. package/webpack.config.mjs +0 -169
@@ -1,864 +0,0 @@
1
- /**
2
- * File : automation/arith/Arith.js
3
- * Created : 28/05/2015
4
- * By : Francesc Busquets <francesc@gmail.com>
5
- *
6
- * JClic.js
7
- * An HTML5 player of JClic activities
8
- * https://projectestac.github.io/jclic.js
9
- *
10
- * @source https://github.com/projectestac/jclic.js
11
- *
12
- * @license EUPL-1.2
13
- * @licstart
14
- * (c) 2000-2020 Educational Telematic Network of Catalonia (XTEC)
15
- *
16
- * Licensed under the EUPL, Version 1.1 or -as soon they will be approved by
17
- * the European Commission- subsequent versions of the EUPL (the "Licence");
18
- * You may not use this work except in compliance with the Licence.
19
- *
20
- * You may obtain a copy of the Licence at:
21
- * https://joinup.ec.europa.eu/software/page/eupl
22
- *
23
- * Unless required by applicable law or agreed to in writing, software
24
- * distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
25
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
26
- * Licence for the specific language governing permissions and limitations
27
- * under the Licence.
28
- * @licend
29
- * @module
30
- */
31
-
32
- /* global Intl */
33
-
34
- import $ from 'jquery';
35
- import AutoContentProvider from '../AutoContentProvider.js';
36
- import { getNumber, getBoolean, getAttr, setAttr, attrForEach } from '../../Utils.js';
37
-
38
- //
39
- // Miscellaneous constants used by Arith:
40
- const
41
- NMAXLOOPS = 60,
42
- OPSTR = ['+', '-', String.fromCharCode(215), ':'],
43
- RES = -12345,
44
- // Use comma as a decimal separator, based on current locale settings
45
- // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl
46
- DOTASCOMMA = Intl && Intl.NumberFormat().format(1.1).indexOf(',') > 0;
47
-
48
- /**
49
- * Arith provides randomly generated mental arithmetics operations, ready to be used in JClic activities.
50
- *
51
- * The operations can be additions, subtractions, multiplications or divides. The unknown of these
52
- * operations can be the result of the operation (`A op B = ?`), any of the two operators
53
- * (`A op ? = C` or `? op B = C`) or also the operator itself (`A ? B = C`).
54
- * @extends module:automation/AutoContentProvider.AutoContentProvider
55
- */
56
- export class Arith extends AutoContentProvider {
57
- /**
58
- * Arith constructor
59
- */
60
- constructor() {
61
- super();
62
- this.className = '@arith.Arith';
63
- this.numericContent = true;
64
- this.opA = new Arith.Operator();
65
- this.opB = new Arith.Operator();
66
- }
67
-
68
- /**
69
- * Formats the number with a fixed number of decimals, optionally filling the result with leading
70
- * zeroes to have a fixed number of digits.
71
- * @param {number} val - The value to format
72
- * @param {number} dec - Number of decimals
73
- * @param {number} pre - Minimal number of digits before dot.
74
- * @returns {string}
75
- */
76
- static DecFormat(val, dec, pre) {
77
- let result = val.toFixed(dec);
78
- if (pre) {
79
- let n = result.indexOf('.');
80
- if (n < 0)
81
- n = result.length;
82
- for (; n < pre; n++)
83
- result = `0${result}`;
84
- }
85
- return result;
86
- }
87
-
88
- /**
89
- * Loads the object settings from a specific JQuery XML element
90
- * @override
91
- * @param {external:jQuery} $xml - The XML element to parse
92
- */
93
- setProperties($xml) {
94
- $xml.children().each((_n, child) => {
95
- const $node = $(child);
96
- let xNum = '';
97
- switch (child.nodeName) {
98
- case 'operand':
99
- switch ($node.attr('id')) {
100
- case 'A':
101
- this.opA.setProperties($node);
102
- break;
103
- case 'B':
104
- this.opB.setProperties($node);
105
- break;
106
- }
107
- break;
108
- case 'operations':
109
- this.use_add = getBoolean($node.attr('plus'));
110
- this.use_subst = getBoolean($node.attr('minus'));
111
- this.use_mult = getBoolean($node.attr('multiply'));
112
- this.use_div = getBoolean($node.attr('divide'));
113
- break;
114
- case 'unknown':
115
- this.exp_abx = getBoolean($node.attr('result'));
116
- this.exp_xbc = getBoolean($node.attr('first'));
117
- this.exp_axc = getBoolean($node.attr('last'));
118
- this.exp_axbc = getBoolean($node.attr('operand'));
119
- this.exp_caxb = getBoolean($node.attr('inverse'));
120
- break;
121
- case 'result':
122
- xNum = $node.attr('from');
123
- this.resultLimInf = getNumber(xNum === 'x' ? 0 : xNum, this.resultLimInf);
124
- xNum = $node.attr('to');
125
- this.resultLimSup = getNumber(xNum === 'x' ? 0 : xNum, this.resultLimSup);
126
- this.resultCarry = getBoolean($node.attr('notCarry'), this.resultCarry);
127
- this.resultNoDup = !getBoolean($node.attr('duplicates'), !this.resultNoDup);
128
- let s = $node.attr('order');
129
- this.resultOrder = s === 'ascending' ? 'SORTASC' : s === 'descending' ? 'SORTDESC' : 'NOSORT';
130
- s = $node.attr('condition');
131
- this.opCond = s === 'firstBig' ? 'AGB' : s === 'lastBig' ? 'BGA' : 'INDIF';
132
- break;
133
- }
134
- });
135
- return this;
136
- }
137
-
138
- /**
139
- * Gets a object with the basic attributes needed to rebuild this instance excluding functions,
140
- * parent references, constants and also attributes retaining the default value.
141
- * The resulting object is commonly usued to serialize elements in JSON format.
142
- * @returns {object} - The resulting object, with minimal attrributes
143
- */
144
- getAttributes() {
145
- return getAttr(this, [
146
- 'className',
147
- 'opA', 'opB', // Operator
148
- 'use_add', 'use_subst', 'use_mult', 'use_div',
149
- 'exp_abx|true', 'exp_axc|false', 'exp_xbc|false', 'exp_axbc|false', 'exp_caxb|false',
150
- 'resultLimInf|0', 'resultLimSup|9999', 'resultCarry|false', 'resultNoDup|false', 'resultOrder|NOSORT',
151
- 'opCond|INDIF'
152
- ]);
153
- }
154
-
155
- /**
156
- * Reads the properties of this Arith object from a dataset
157
- * @param {object} data - The data object to be parsed
158
- * @returns {object}
159
- */
160
- setAttributes(data) {
161
- return setAttr(this, data, [
162
- 'className',
163
- { key: 'opA', fn: Arith.Operator },
164
- { key: 'opB', fn: Arith.Operator },
165
- 'use_add', 'use_subst', 'use_mult', 'use_div',
166
- 'exp_abx', 'exp_axc', 'exp_xbc', 'exp_axbc', 'exp_caxb',
167
- 'resultLimInf', 'resultLimSup', 'resultCarry', 'resultNoDup', 'resultOrder',
168
- 'opCond',
169
- ]);
170
- }
171
-
172
- /**
173
- * Fills the `n` parameter (an {@link module:automation/arith/Arith.Num Num}) with a value in accordance with the
174
- * specifications of `op` (an {@link module:automation/arith/Arith.Operator Operator}), between two limits.
175
- * @param {module:automation/arith/Arith.Num} n - The number
176
- * @param {module:automation/arith/Arith.Operator} op - The operator
177
- * @param {number} limInf2 - Lower limit
178
- * @param {number} limSup2 - Upper limit
179
- * @returns {boolean} - `true` if all was OK
180
- */
181
- genNum(n, op, limInf2, limSup2) {
182
- let solved = false;
183
- n.c = op.numDec;
184
- const exp = n.c === 0 ? 1 : n.c === 1 ? 10 : 100;
185
-
186
- let ls = op.limSup;
187
- if (limSup2 !== RES && limSup2 < ls)
188
- ls = limSup2;
189
- let li = op.limInf;
190
- if (limInf2 !== RES && limInf2 > li)
191
- li = limInf2;
192
-
193
- if (op.fromList > 0) {
194
- n.vf = op.lst[Math.floor(Math.random() * op.fromList)];
195
- solved = true;
196
- }
197
- if (!solved) {
198
- const r = Math.floor(Math.random() * 100);
199
- if (op.wZero && r <= 10) {
200
- n.vf = 0;
201
- solved = true;
202
- } else if (op.wOne && r > 10 && r <= 20) {
203
- n.vf = 1;
204
- solved = true;
205
- } else if (op.wMinusOne && r > 20 && r <= 30) {
206
- n.vf = -1;
207
- solved = true;
208
- }
209
- }
210
- if (!solved) {
211
- if (li > ls) {
212
- const k = li;
213
- li = ls;
214
- ls = k;
215
- }
216
- let rang = Math.floor(ls - li + 1);
217
- if (rang < 0)
218
- rang = 1;
219
- let v = (Math.floor(Math.random() * rang) + li) * exp;
220
- if (exp > 1)
221
- v += Math.floor(Math.random() * exp);
222
- n.vf = v / exp;
223
- }
224
- return true;
225
- }
226
-
227
- /**
228
- * Fills the provided {@link module:automation/arith/Arith.Operator Operator} with real values
229
- * @param {module:automation/arith/Arith.Operator} o - The operator to use to generate the operation
230
- * @returns {boolean} - `true` if all was OK
231
- */
232
- genOp(o) {
233
- let i, ri2, rs2, q, va, vb, bufa, bufb;
234
- const
235
- ops = [],
236
- rlinf = this.resultLimInf,
237
- rlsup = this.resultLimSup;
238
-
239
- let nops = 0;
240
- if (this.use_add)
241
- ops[nops++] = 'SUM';
242
- if (this.use_subst)
243
- ops[nops++] = 'REST';
244
- if (this.use_mult)
245
- ops[nops++] = 'MULT';
246
- if (this.use_div)
247
- ops[nops++] = 'DIV';
248
-
249
- const op = ops[Math.floor(Math.random() * nops)];
250
- switch (op) {
251
- case 'SUM':
252
- for (i = 0; i < NMAXLOOPS; i++) {
253
- this.genNum(o.numA, this.opA, this.RES, rlsup);
254
- ri2 = o.numA.vf < rlinf ? rlinf - Math.floor(o.numA.vf) : this.RES;
255
- rs2 = rlsup - Math.floor(o.numA.vf);
256
- switch (this.opCond) {
257
- case 'AGB':
258
- if (rs2 === this.RES || rs2 > o.numA.vf)
259
- rs2 = Math.floor(o.numA.vf);
260
- break;
261
- case 'BGA':
262
- if (ri2 === this.RES || ri2 < o.numA.vf)
263
- ri2 = Math.floor(o.numA.vf);
264
- break;
265
- }
266
- this.genNum(o.numB, this.opB, ri2, rs2);
267
- o.numR.vf = o.numA.vf + o.numB.vf;
268
- if (o.numR.vf >= rlinf && o.numR.vf <= rlsup)
269
- break;
270
- }
271
- o.numR.c = o.numA.c > o.numB.c ? o.numA.c : o.numB.c;
272
- o.op = 0;
273
- if (this.resultCarry && o.numA.vf > 0 && o.numB.vf > 0) {
274
- q = o.numR.c === 2 ? 100 : o.numR.c === 1 ? 10 : 1;
275
-
276
- bufa = Arith.DecFormat(Math.floor(o.numA.vf * q + 0.5), 0, 10).split('');
277
- bufb = Arith.DecFormat(Math.floor(o.numB.vf * q + 0.5), 0, 10).split('');
278
- for (i = 0; i < 10; i++)
279
- if (bufa[i] !== '0' || bufb[i] !== '0')
280
- break;
281
- for (; i < 10; i++) {
282
- va = parseInt(bufa[i]);
283
- vb = parseInt(bufb[i]);
284
- if (va + vb < 10)
285
- continue;
286
- while (va + vb > 9) {
287
- if (va > vb)
288
- va = va > 0 ? Math.floor(Math.random() * va) : 0;
289
- else
290
- vb = vb > 0 ? Math.floor(Math.random() * vb) : 0;
291
- }
292
- bufa[i] = va.toFixed(0);
293
- bufb[i] = vb.toFixed(0);
294
- }
295
-
296
- o.numA.vf = parseInt(bufa.join('')) / q;
297
- o.numB.vf = parseInt(bufb.join('')) / q;
298
- // Corrected 2019/02/11: Factors should be multiplied by 'q'!
299
- // INCORRECT: o.numR.vf = Math.floor(o.numA.vf + o.numB.vf + 0.5) / q
300
- o.numR.vf = Math.floor(o.numA.vf * q + o.numB.vf * q + 0.5) / q;
301
- }
302
- break;
303
-
304
- case 'REST':
305
- for (i = 0; i < NMAXLOOPS; i++) {
306
- this.genNum(o.numA, this.opA, rlinf, this.RES);
307
- ri2 = o.numA.vf > rlsup ? Math.floor(o.numA.vf - rlsup) : this.RES;
308
- rs2 = Math.floor(o.numA.vf - rlinf);
309
- switch (this.opCond) {
310
- case 'AGB':
311
- if (rs2 === this.RES || rs2 > o.numA.vf)
312
- rs2 = Math.floor(o.numA.vf);
313
- break;
314
- case 'BGA':
315
- if (ri2 === this.RES || ri2 < o.numA.vf)
316
- ri2 = Math.floor(o.numA.vf);
317
- break;
318
- }
319
- this.genNum(o.numB, this.opB, ri2, rs2);
320
- o.numR.vf = o.numA.vf - o.numB.vf;
321
- if (o.numR.vf >= rlinf && o.numR.vf <= rlsup)
322
- break;
323
- }
324
- o.numR.c = o.numA.c > o.numB.c ? o.numA.c : o.numB.c;
325
- o.op = 1;
326
- if (this.resultCarry && o.numA.vf > 0 && o.numB.vf > 0 && o.numA.vf >= o.numB.vf) {
327
- q = o.numR.c === 2 ? 100 : o.numR.c === 1 ? 10 : 1;
328
- bufa = Arith.DecFormat(Math.floor(o.numA.vf * q + 0.5), 0, 10).split('');
329
- bufb = Arith.DecFormat(Math.floor(o.numB.vf * q + 0.5), 0, 10).split('');
330
- for (i = 0; i < 10; i++)
331
- if (bufb[i] !== '0')
332
- break;
333
- for (; i < 10; i++) {
334
- va = parseInt(bufa[i]);
335
- vb = parseInt(bufb[i]);
336
- if (va >= vb)
337
- continue;
338
- vb = va > 0 ? Math.floor(Math.random() * va) : 0;
339
- bufb[i] = vb.toFixed(0);
340
- }
341
-
342
- o.numA.vf = parseInt(bufa.join('')) / q;
343
- o.numB.vf = parseInt(bufb.join('')) / q;
344
- // Corrected 2019/02/11: Factors should be multiplied by 'q'!
345
- // o.numR.vf = Math.floor(o.numA.vf - o.numB.vf + 0.5) / q
346
- o.numR.vf = Math.floor(o.numA.vf * q - o.numB.vf * q + 0.5) / q;
347
- }
348
- break;
349
-
350
- case 'MULT':
351
- for (i = 0; i < NMAXLOOPS; i++) {
352
- this.genNum(o.numA, this.opA, this.RES, this.RES);
353
- ri2 = this.opB.limInf;
354
- rs2 = this.opB.limSup;
355
- switch (this.opCond) {
356
- case 'AGB':
357
- if (rs2 > o.numA.vf)
358
- rs2 = Math.floor(o.numA.vf);
359
- break;
360
- case 'BGA':
361
- if (ri2 < o.numA.vf)
362
- ri2 = Math.floor(o.numA.vf);
363
- break;
364
- }
365
- this.genNum(o.numB, this.opB, ri2, rs2);
366
- o.numR.vf = o.numA.vf * o.numB.vf;
367
- if (o.numR.vf >= rlinf && o.numR.vf <= rlsup)
368
- break;
369
- }
370
- o.numR.c = o.numA.c + o.numB.c;
371
- o.op = 2;
372
- break;
373
-
374
- case 'DIV':
375
- for (i = 0; i < NMAXLOOPS; i++) {
376
- this.genNum(o.numA, this.opA, this.RES, this.RES);
377
- ri2 = this.opB.limInf;
378
- rs2 = this.opB.limSup;
379
- switch (this.opCond) {
380
- case 'AGB':
381
- if (rs2 > o.numA.vf)
382
- rs2 = Math.floor(o.numA.vf);
383
- break;
384
- case 'BGA':
385
- if (ri2 < o.numA.vf)
386
- ri2 = Math.floor(o.numA.vf);
387
- break;
388
- }
389
- this.genNum(o.numB, this.opB, ri2, rs2);
390
- if (o.numB.vf !== 0 &&
391
- Math.abs(o.numA.vf) >= Math.abs(o.numB.vf) &&
392
- (o.numR.vf = o.numA.vf / o.numB.vf) >= rlinf &&
393
- o.numR.vf <= rlsup)
394
- break;
395
- }
396
- if (o.numB.vf === 0)
397
- o.numB.vf = 1;
398
- o.numR.vf = o.numA.vf / o.numB.vf;
399
- i = o.numA.c - o.numB.c;
400
- q = Math.pow(10, i);
401
- o.numA.vf *= q;
402
- o.numR.vf *= q;
403
- o.numR.vf = Math.floor(o.numR.vf);
404
- o.numA.vf = o.numR.vf * o.numB.vf;
405
- o.numA.vf /= q;
406
- o.numR.vf /= q;
407
- o.numR.c = i > 0 ? i : 0;
408
- o.op = 3;
409
- break;
410
-
411
- default:
412
- return false;
413
- }
414
- return true;
415
- }
416
-
417
- /**
418
- * Fills the provided ActiveBagContentKit with randomly generated operations
419
- * @override
420
- * @param {module:automation/AutoContentProvider.ActiveBagContentKit} kit - The composite object to be filled with data.
421
- * @returns {boolean} - `true` if all was OK
422
- */
423
- process(kit) {
424
- let nRows = kit.nRows,
425
- nCols = kit.nCols,
426
- content = kit.content, //Array of ActiveBagContent
427
- useIds = kit.useIds,
428
- i, j, k,
429
- o, op = [], // Array of Arith.Operation
430
- tipus = [],
431
- numTipus, tipX,
432
- tipInv = this.exp_caxb,
433
- va = '', vb = '', vc = '', operator = '',
434
- stra = [], strb = [], strc = [],
435
- nColsB = nCols, nRowsB = nRows,
436
- nCells = nRows * nCols,
437
- ass = null;
438
-
439
- if (nRows <= 0 || nCols <= 0 ||
440
- content === null || content.length < 1 || content[0] === null)
441
- return false;
442
-
443
- if (nCells < 2)
444
- return false;
445
-
446
- numTipus = 0;
447
- if (this.exp_abx)
448
- tipus[numTipus++] = 'ABX';
449
- if (this.exp_axc)
450
- tipus[numTipus++] = 'AXC';
451
- if (this.exp_xbc)
452
- tipus[numTipus++] = 'XBC';
453
- if (this.exp_axbc)
454
- tipus[numTipus++] = 'AXBC';
455
- if (numTipus === 0)
456
- return false;
457
-
458
- for (i = 0; i < nCells; i++) {
459
- o = new Arith.Operation();
460
- for (j = 0; j < NMAXLOOPS; j++) {
461
- this.genOp(o);
462
- if (this.resultNoDup) {
463
- for (k = 0; k < i; k++) {
464
- if (o.numR.vf === op[k].numR.vf)
465
- break;
466
- }
467
- if (k === i)
468
- break;
469
- } else
470
- break;
471
- }
472
- op[i] = o;
473
- }
474
-
475
- if (this.resultOrder !== 0) {
476
- for (i = nCells - 1; i > 0; i--) {
477
- for (j = 0; j < i; j++) {
478
- if (this.resultOrder === 'SORTASC' && op[j].numR.vf > op[j + 1].numR.vf ||
479
- this.resultOrder === 'SORTDESC' && op[j].numR.vf < op[j + 1].numR.vf) {
480
- // Switch values
481
- o = op[j];
482
- op[j] = op[j + 1];
483
- op[j + 1] = o;
484
- }
485
- }
486
- }
487
- }
488
-
489
- for (i = 0; i < nCells; i++) {
490
- tipX = tipus[Math.floor(Math.random() * numTipus)];
491
- va = Arith.DecFormat(op[i].numA.vf, op[0].numA.c);
492
- vb = Arith.DecFormat(op[i].numB.vf, op[0].numB.c);
493
- vc = Arith.DecFormat(op[i].numR.vf, op[0].numR.c);
494
- operator = OPSTR[op[i].op];
495
-
496
- // Use the special blank space ASCII 160 (\xA0) instead of regular blank spaces
497
-
498
- if (tipInv)
499
- strc[i] = `${vc}\xA0=\xA0${va}\xA0${operator}\xA0${vb}`;
500
- else
501
- strc[i] = `${va}\xA0${operator}\xA0${vb}\xA0=\xA0${vc}`;
502
-
503
- switch (tipX) {
504
- case 'AXC':
505
- strb[i] = vb;
506
- stra[i] = tipInv ? `${vc}\xA0=\xA0${va}\xA0${operator}\xA0?` : `${va}\xA0${operator}\xA0?\xA0=\xA0${vc}`;
507
- break;
508
-
509
- case 'XBC':
510
- strb[i] = va;
511
- stra[i] = tipInv ? `${vc}\xA0=\xA0?\xA0${operator}\xA0${vb}` : `?\xA0${operator}\xA0${vb}\xA0=\xA0${vc}`;
512
- break;
513
-
514
- case 'AXBC':
515
- strb[i] = operator;
516
- stra[i] = tipInv ? `${vc}\xA0=\xA0${va}\xA0?\xA0${vb}` : `${va}\xA0?\xA0${vb}\xA0=\xA0${vc}`;
517
- break;
518
-
519
- default:
520
- strb[i] = vc;
521
- stra[i] = tipInv ? `?\xA0=\xA0${va}\xA0${operator}\xA0${vb}` : `${va}\xA0${operator}\xA0${vb}\xA0=`;
522
- break;
523
- }
524
- }
525
-
526
- if (useIds) {
527
- ass = [];
528
- let strbx = [];
529
- k = 0;
530
- for (i = 0; i < nCells; i++) {
531
- for (j = 0; j < k; j++)
532
- if (strb[i] === strbx[j])
533
- break;
534
- if (j === k) {
535
- strbx[k] = strb[i];
536
- ass[i] = k;
537
- k++;
538
- } else
539
- ass[i] = j;
540
- }
541
-
542
- strb = [];
543
- for (i = 0; i < k; i++)
544
- strb[i] = strbx[i];
545
-
546
- if (nRowsB * nColsB !== k) {
547
- let distH = false;
548
- switch (k) {
549
- case 6:
550
- nRowsB = distH ? 2 : 3;
551
- nColsB = distH ? 3 : 2;
552
- break;
553
-
554
- case 8:
555
- nRowsB = distH ? 2 : 4;
556
- nColsB = distH ? 4 : 2;
557
- break;
558
-
559
- case 9:
560
- nRowsB = 3;
561
- nColsB = 3;
562
- break;
563
-
564
- case 10:
565
- nRowsB = distH ? 2 : 5;
566
- nColsB = distH ? 5 : 2;
567
- break;
568
-
569
- case 12:
570
- nRowsB = distH ? 3 : 4;
571
- nColsB = distH ? 4 : 3;
572
- break;
573
-
574
- case 14:
575
- nRowsB = distH ? 2 : 7;
576
- nColsB = distH ? 7 : 2;
577
- break;
578
-
579
- case 15:
580
- nRowsB = distH ? 3 : 5;
581
- nColsB = distH ? 3 : 5;
582
- break;
583
-
584
- case 16:
585
- nRowsB = 4;
586
- nColsB = 4;
587
- break;
588
-
589
- case 18:
590
- nRowsB = distH ? 6 : 3;
591
- nColsB = distH ? 3 : 6;
592
- break;
593
-
594
- case 20:
595
- nRowsB = distH ? 4 : 5;
596
- nColsB = distH ? 5 : 4;
597
- break;
598
-
599
- default:
600
- nRowsB = distH ? 1 : k;
601
- nColsB = distH ? k : 1;
602
- break;
603
- }
604
- }
605
- }
606
-
607
- // Added 2019/02/11
608
- // Use comma instead of dot for decimal separator, accordingly to current locale
609
- if (DOTASCOMMA) {
610
- function replaceDot(s) { return s.replace(/\./g, ','); }
611
- stra = stra.map(replaceDot);
612
- strb = strb.map(replaceDot);
613
- strc = strc.map(replaceDot);
614
- }
615
-
616
- content[0].setTextContent(stra, nCols, nRows);
617
- if (ass !== null)
618
- content[0].setIds(ass);
619
- if (content.length > 1 && content[1] !== null) {
620
- content[1].setTextContent(strb, nColsB, nRowsB);
621
- content[1].getShaper().reset(nColsB, nRowsB);
622
- }
623
- if (content.length > 2 && content[2] !== null)
624
- content[2].setTextContent(strc, nCols, nRows);
625
-
626
- return true;
627
- }
628
- }
629
-
630
- Object.assign(Arith.prototype, {
631
- //
632
- // Operations use two operators:
633
- /**
634
- * First operator
635
- * @name module:automation/arith/Arith.Arith#opA
636
- * @type {module:automation/arith/Arith.Operator} */
637
- opA: null,
638
- /**
639
- * Second operator
640
- * @name module:automation/arith/Arith.Arith#opB
641
- * @type {module:automation/arith/Arith.Operator} */
642
- opB: null,
643
- /**
644
- * Allow additions
645
- * @name module:automation/arith/Arith.Arith#use_add
646
- * @type {boolean} */
647
- use_add: true,
648
- /**
649
- * Allow subtractions
650
- * @name module:automation/arith/Arith.Arith#use_subst
651
- * @type {boolean} */
652
- use_subst: false,
653
- /**
654
- * Allow multiplications
655
- * @name module:automation/arith/Arith.Arith#use_mult
656
- * @type {boolean} */
657
- use_mult: false,
658
- /**
659
- * Allow divides
660
- * @name module:automation/arith/Arith.Arith#use_div
661
- * @type {boolean} */
662
- use_div: false,
663
- /**
664
- * Allow expressions of type `A op B = X`
665
- * @name module:automation/arith/Arith.Arith#exp_abx
666
- * @type {boolean} */
667
- exp_abx: true,
668
- /**
669
- * Allow expressions of type `A op X = C`
670
- * @name module:automation/arith/Arith.Arith#exp_axc
671
- * @type {boolean} */
672
- exp_axc: false,
673
- /**
674
- * Allow expressions of type `X op B = C`
675
- * @name module:automation/arith/Arith.Arith#exp_xbc
676
- * @type {boolean} */
677
- exp_xbc: false,
678
- /**
679
- * Allow expressions of type `A x B = C`
680
- * @name module:automation/arith/Arith.Arith#exp_axbc
681
- * @type {boolean} */
682
- exp_axbc: false,
683
- /**
684
- * Allow inverse expressions, like `C = A op B`
685
- * @name module:automation/arith/Arith.Arith#exp_caxb
686
- * @type {boolean} */
687
- exp_caxb: false,
688
- /**
689
- * Lower limit of the result
690
- * @name module:automation/arith/Arith.Arith#resultLimInf
691
- * @type {number} */
692
- resultLimInf: 0,
693
- /**
694
- * Upper limit of the result
695
- * @name module:automation/arith/Arith.Arith#resultLimSup
696
- * @type {number} */
697
- resultLimSup: 9999,
698
- /**
699
- * Allow carry operations
700
- * @see {@link https://en.wikipedia.org/wiki/Carry_(arithmetic)}
701
- * @name module:automation/arith/Arith.Arith#resultCarry
702
- * @type {boolean} */
703
- resultCarry: false,
704
- /**
705
- * Avoid operations with the same result
706
- * @name module:automation/arith/Arith.Arith#resultNoDup
707
- * @type {boolean} */
708
- resultNoDup: false,
709
- /**
710
- * Type of sorting of results. Possible values are: 'NOSORT', 'SORTASC' and 'SORTDESC'
711
- * @name module:automation/arith/Arith.Arith#resultOrder
712
- * @type {string} */
713
- resultOrder: 'NOSORT',
714
- /**
715
- * Sorting of the operands in commutative operations. Possible values are: 'AGB' (_A greater than B_),
716
- * 'BGA' (_B greater tan A_) and 'INDIF' (default)
717
- * @name module:automation/arith/Arith.Arith#opCond
718
- * @type {string} */
719
- opCond: 'INDIF',
720
- });
721
-
722
- /**
723
- * Operator is an Utility class used by Arith to encapsulate the properties and methods related
724
- * to the members of the operations.
725
- */
726
- Arith.Operator = class {
727
- constructor() {
728
- }
729
-
730
- /**
731
- * Loads Operator settings from a specific JQuery XML element
732
- * @param {external:jQuery} $xml - The XML element to parse
733
- */
734
- setProperties($xml) {
735
- // Read attributes
736
- attrForEach($xml.get(0).attributes, (name, val) => {
737
- switch (name) {
738
- case 'decimals':
739
- this.numDec = Number(val);
740
- break;
741
-
742
- case 'values':
743
- this.lst = val.split(' ').map(v => Number(v));
744
- this.fromList = this.lst.length;
745
- break;
746
-
747
- case 'from':
748
- this.limInf = Number(val === 'x' ? 0 : val);
749
- break;
750
-
751
- case 'to':
752
- this.limSup = Number(val === 'x' ? 0 : val);
753
- break;
754
- }
755
-
756
- $xml.children().each((_n, child) => {
757
- const $node = $(child);
758
- switch (child.nodeName) {
759
- case 'include':
760
- this.wZero = getBoolean($node.attr('zero'));
761
- this.wOne = getBoolean($node.attr('one'));
762
- this.wMinusOne = getBoolean($node.attr('minusOne'));
763
- break;
764
- }
765
- });
766
- });
767
- return this;
768
- }
769
-
770
- /**
771
- * Gets a object with the basic attributes needed to rebuild this instance excluding functions,
772
- * parent references, constants and also attributes retaining the default value.
773
- * The resulting object is commonly usued to serialize elements in JSON format.
774
- * @returns {object} - The resulting object, with minimal attrributes
775
- */
776
- getAttributes() {
777
- return getAttr(this, [
778
- 'limInf', 'limSup',
779
- 'numDec|0',
780
- 'wZero|false', 'wOne|false', 'wMinusOne|false',
781
- 'fromList|0', 'lst',
782
- ]);
783
- }
784
-
785
- /**
786
- * Reads the properties of this operator from a dataset
787
- * @param {object} data - The data object to be parsed
788
- * @returns {module:automation/arith/Arith.Arith}
789
- */
790
- setAttributes(data) {
791
- return setAttr(this, data, [
792
- 'limInf', 'limSup',
793
- 'numDec',
794
- 'wZero', 'wOne', 'wMinusOne',
795
- 'fromList', 'lst',
796
- ]);
797
- }
798
- };
799
-
800
- Object.assign(Arith.Operator.prototype, {
801
- /**
802
- * Lower limit
803
- * @name module:automation/arith/Arith.Arith.Operator#limInf
804
- * @type {number} */
805
- limInf: 0,
806
- /**
807
- * Upper limit
808
- * @name module:automation/arith/Arith.Arith.Operator#limSup
809
- * @type {number} */
810
- limSup: 10,
811
- /**
812
- * Number of decimal places
813
- * @name module:automation/arith/Arith.Arith.Operator#numDec
814
- * @type {number} */
815
- numDec: 0,
816
- /**
817
- * Including 0
818
- * @name module:automation/arith/Arith.Arith.Operator#wZero
819
- * @type {boolean} */
820
- wZero: false,
821
- /**
822
- * Including 1
823
- * @name module:automation/arith/Arith.Arith.Operator#wOne
824
- * @type {boolean} */
825
- wOne: false,
826
- /**
827
- * Including -1
828
- * @name module:automation/arith/Arith.Arith.Operator#wMinusOne
829
- * @type {boolean} */
830
- wMinusOne: false,
831
- /**
832
- * Take values from list. This member stores the list length.
833
- * @name module:automation/arith/Arith.Arith.Operator#fromList
834
- * @type {number} */
835
- fromList: 0,
836
- /**
837
- * The list of possible values
838
- * @name module:automation/arith/Arith.Arith.Operator#lst
839
- * @type {number[]} */
840
- lst: [],
841
- });
842
-
843
- Arith.Num = class {
844
- constructor() {
845
- this.vf = 0.0; // The number value
846
- this.c = 0; // Number of decimals to be used when representing the number
847
- }
848
-
849
- format() {
850
- return Arith.DecFormat(this.vf, this.c);
851
- }
852
- };
853
-
854
- Arith.Operation = class {
855
- constructor() {
856
- this.numA = new Arith.Num();
857
- this.numB = new Arith.Num();
858
- this.numR = new Arith.Num();
859
- this.op = 0;
860
- }
861
- };
862
-
863
- // Register class in AutoContentProvider.CLASSES
864
- export default AutoContentProvider.registerClass('@arith.Arith', Arith);