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,519 +0,0 @@
1
- /**
2
- * File : activities/associations/SimpleAssociation.js
3
- * Created : 02/06/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 Catalan Educational Telematic Network (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
- import $ from 'jquery';
33
- import { Activity, ActivityPanel } from '../../Activity.js';
34
- import ActiveBoxGrid from '../../boxes/ActiveBoxGrid.js';
35
- import BoxBag from '../../boxes/BoxBag.js';
36
- import BoxConnector from '../../boxes/BoxConnector.js';
37
- import { Rectangle, Point } from '../../AWT.js';
38
- import { getMsg } from '../../Utils.js';
39
-
40
- /**
41
- * This class of {@link module:Activity.Activity Activity} uses two panels (`primary` and `secondary`) formed by
42
- * {@link module:boxes/ActiveBox.ActiveBox ActiveBox} objects filled with data stored in {@link module:boxes/ActiveBagContent.ActiveBagContent ActiveBagContent} repositories.
43
- *
44
- * Both panels have the same number of elements, associated one-to-one. A third {@link module:boxes/ActiveBagContent.ActiveBagContent ActiveBagContent}
45
- * can be used as alternative content, that will be revealed in the `primary` panel as the pairings
46
- * of its cells are solved.
47
- * @extends module:Activity.Activity
48
- */
49
- export class SimpleAssociation extends Activity {
50
- /**
51
- * SimpleAssociation constructor
52
- * @param {module:project/JClicProject.JClicProject} project - The JClic project to which this activity belongs
53
- */
54
- constructor(project) {
55
- super(project);
56
- }
57
-
58
- /**
59
- * Retrieves the minimum number of actions needed to solve this activity.
60
- * @override
61
- * @returns {number}
62
- */
63
- getMinNumActions() {
64
- return this.abc.primary.getNumCells();
65
- }
66
-
67
- /**
68
- * Whether or not the activity uses random to shuffle internal components
69
- * @override
70
- * @returns {boolean}
71
- */
72
- hasRandom() {
73
- return true;
74
- }
75
-
76
- /**
77
- * When `true`, the activity must always be shuffled
78
- * @override
79
- * @returns {boolean}
80
- */
81
- shuffleAlways() {
82
- return true;
83
- }
84
-
85
- /**
86
- * Whether the activity allows the user to request help.
87
- * @override
88
- * @returns {boolean}
89
- */
90
- helpSolutionAllowed() {
91
- return true;
92
- }
93
- }
94
-
95
- Object.assign(SimpleAssociation.prototype, {
96
- /**
97
- * When `true`, the cell's `idAss` field will be used to check pairing matches.
98
- * @name module:activities/associations/SimpleAssociation.SimpleAssociation#useIdAss
99
- * @type {boolean} */
100
- useIdAss: false,
101
- });
102
-
103
- /**
104
- * The {@link module:Activity.ActivityPanel ActivityPanel} where {@link module:activities/associations/SimpleAssociation.SimpleAssociation SimpleAssociation} activities are played.
105
- * @extends module:Activity.ActivityPanel ActivityPanel
106
- */
107
- export class SimpleAssociationPanel extends ActivityPanel {
108
- /**
109
- * SimpleAssociationPanel constructor
110
- * @param {module:Activity.Activity} act - The {@link module:Activity.Activity Activity} to which this Panel belongs
111
- * @param {module:JClicPlayer.JClicPlayer} ps - Any object implementing the methods defined in the
112
- * [PlayStation](http://projectestac.github.io/jclic/apidoc/edu/xtec/jclic/PlayStation.html) Java interface.
113
- * @param {external:jQuery} [$div] - The jQuery DOM element where this Panel will deploy
114
- */
115
- constructor(act, ps, $div) {
116
- super(act, ps, $div);
117
- }
118
-
119
- /**
120
- * Performs miscellaneous cleaning operations
121
- * @override
122
- */
123
- clear() {
124
- if (this.bgA) {
125
- this.bgA.end();
126
- this.bgA = null;
127
- }
128
- if (this.bgB) {
129
- this.bgB.end();
130
- this.bgB = null;
131
- }
132
- }
133
-
134
- /**
135
- * Prepares the visual components of the activity
136
- * @override
137
- */
138
- buildVisualComponents() {
139
- if (this.firstRun)
140
- super.buildVisualComponents();
141
-
142
- this.clear();
143
-
144
- const
145
- abcA = this.act.abc['primary'],
146
- abcB = this.act.abc['secondary'],
147
- solved = this.act.abc['solvedPrimary'];
148
-
149
- if (abcA && abcB) {
150
- if (abcA.image) {
151
- abcA.setImgContent(this.act.project.mediaBag, null, false);
152
- if (abcA.animatedGifFile && !abcA.shaper.rectangularShapes && !this.act.shuffleA)
153
- this.$animatedBg = $('<span/>').css({
154
- 'background-image': `url(${abcA.animatedGifFile})`,
155
- 'background-position': 'center',
156
- 'background-repeat': 'no-repeat',
157
- position: 'absolute'
158
- }).appendTo(this.$div);
159
- }
160
-
161
- if (abcB.image) {
162
- abcB.setImgContent(this.act.project.mediaBag, null, false);
163
- if (abcB.animatedGifFile && !abcB.shaper.rectangularShapes && !this.act.shuffleB)
164
- this.$animatedBgB = $('<span/>').css({
165
- 'background-image': `url(${abcB.animatedGifFile})`,
166
- 'background-position': 'center',
167
- 'background-repeat': 'no-repeat',
168
- position: 'absolute'
169
- }).appendTo(this.$div);
170
- }
171
-
172
- if (solved && solved.image)
173
- solved.setImgContent(this.act.project.mediaBag, null, false);
174
-
175
- if (this.act.acp !== null) {
176
- const contentKit = [abcA, abcB];
177
- if (solved)
178
- contentKit.push(solved);
179
- this.act.acp.generateContent(abcA.nch, abcA.ncw, contentKit, false);
180
- }
181
-
182
- this.bgA = ActiveBoxGrid.createEmptyGrid(null, this, this.act.margin, this.act.margin, abcA);
183
- this.bgB = ActiveBoxGrid.createEmptyGrid(null, this, this.act.margin, this.act.margin, abcB);
184
-
185
- this.bgA.setContent(abcA, solved ? solved : null);
186
- if (this.$animatedBg)
187
- this.bgA.setCellAttr('tmpTrans', true);
188
-
189
- this.bgB.setContent(abcB);
190
- if (this.$animatedBgB)
191
- this.bgB.setCellAttr('tmpTrans', true);
192
-
193
- this.bgA.accessibleText = getMsg('source');
194
- this.bgB.accessibleText = getMsg('target');
195
-
196
- this.bgA.setVisible(true);
197
- this.bgB.setVisible(true);
198
- }
199
- }
200
-
201
- /**
202
- * Basic initialization procedure
203
- * @override
204
- */
205
- initActivity() {
206
- super.initActivity();
207
- if (!this.firstRun)
208
- this.buildVisualComponents();
209
- else
210
- this.firstRun = false;
211
-
212
- if (this.bgA && this.bgB) {
213
- // Scramble cells
214
- const shuffleArray = [];
215
- if (this.act.shuffleA)
216
- shuffleArray.push(this.bgA);
217
- if (this.act.shuffleB)
218
- shuffleArray.push(this.bgB);
219
- if (shuffleArray.length > 0) {
220
- this.shuffle(shuffleArray, true, true);
221
- }
222
-
223
- if (this.useOrder)
224
- this.currentItem = this.bgA.getNextItem(-1);
225
-
226
- this.invalidate().update();
227
- this.setAndPlayMsg('initial', 'start');
228
- this.playing = true;
229
- }
230
- }
231
-
232
- /**
233
- * Updates the graphic content of this panel.
234
- * This method will be called from {@link module:AWT.Container#update} when needed.
235
- * @override
236
- * @param {module:AWT.Rectangle} dirtyRegion - Specifies the area to be updated. When `null`,
237
- * it's the whole panel.
238
- */
239
- updateContent(dirtyRegion) {
240
- super.updateContent(dirtyRegion);
241
- if (this.bgA && this.bgB && this.$canvas) {
242
- const
243
- canvas = this.$canvas.get(-1),
244
- ctx = canvas.getContext('2d');
245
- if (!dirtyRegion)
246
- dirtyRegion = new Rectangle(0, 0, canvas.width, canvas.height);
247
- ctx.clearRect(dirtyRegion.pos.x, dirtyRegion.pos.y, dirtyRegion.dim.width, dirtyRegion.dim.height);
248
- this.bgA.update(ctx, dirtyRegion);
249
- this.bgB.update(ctx, dirtyRegion);
250
- }
251
- return this;
252
- }
253
-
254
- /**
255
- * Sets the real dimension of this panel.
256
- * @override
257
- * @param {module:AWT.Dimension} preferredMaxSize - The maximum surface available for the activity panel
258
- * @returns {module:AWT.Dimension}
259
- */
260
- setDimension(preferredMaxSize) {
261
- return !this.bgA || !this.bgB || this.getBounds().equals(preferredMaxSize) ?
262
- preferredMaxSize :
263
- BoxBag.layoutDouble(preferredMaxSize, this.bgA, this.bgB, this.act.boxGridPos, this.act.margin);
264
- }
265
-
266
- /**
267
- * Sets the size and position of this activity panel
268
- * @override
269
- * @param {module:AWT.Rectangle} rect
270
- */
271
- setBounds(rect) {
272
- if (this.$canvas)
273
- this.$canvas.remove();
274
-
275
- super.setBounds(rect);
276
- if (this.bgA || this.bgB) {
277
- // Create the main canvas
278
- this.$canvas = $(`<canvas width="${rect.dim.width}" height="${rect.dim.height}"/>`).css({
279
- position: 'absolute',
280
- top: 0,
281
- left: 0
282
- });
283
- // Resize animated gif background A
284
- if (this.$animatedBg && this.bgA) {
285
- const bgRect = this.bgA.getBounds();
286
- this.$animatedBg.css({
287
- left: bgRect.pos.x,
288
- top: bgRect.pos.y,
289
- width: bgRect.dim.width + 'px',
290
- height: bgRect.dim.height + 'px',
291
- 'background-size': `${bgRect.dim.width}px ${bgRect.dim.height}px`
292
- });
293
- }
294
- // Resize animated gif background B
295
- if (this.$animatedBgB && this.bgB) {
296
- const bgRectB = this.bgB.getBounds();
297
- this.$animatedBgB.css({
298
- left: bgRectB.pos.x,
299
- top: bgRectB.pos.y,
300
- width: bgRectB.dim.width + 'px',
301
- height: bgRectB.dim.height + 'px',
302
- 'background-size': `${bgRectB.dim.width}px ${bgRectB.dim.height}px`
303
- });
304
- }
305
- this.$div.append(this.$canvas);
306
-
307
- // Create a [BoxConnector](BoxConnector.html) and attach it to the canvas context
308
- this.bc = new BoxConnector(this, this.$canvas);
309
-
310
- // Repaint all
311
- this.invalidate().update();
312
- }
313
- }
314
-
315
- /**
316
- * Builds the accessible components needed for this ActivityPanel
317
- * This method is called when all main elements are placed and visible, when the activity is ready
318
- * to start or when resized.
319
- * @override
320
- */
321
- buildAccessibleComponents() {
322
- if (this.$canvas && this.accessibleCanvas) {
323
- super.buildAccessibleComponents();
324
- if (this.bgA)
325
- this.bgA.buildAccessibleElements(this.$canvas, this.$div, 'mousedown');
326
- if (this.bgB)
327
- this.bgB.buildAccessibleElements(this.$canvas, this.$div, 'mousedown');
328
- }
329
- }
330
-
331
- /**
332
- * Main handler used to process mouse, touch, keyboard and edit events
333
- * @override
334
- * @param {external:Event} event - The HTML event to be processed
335
- * @returns {boolean} - When this event handler returns `false`, jQuery will stop its
336
- * propagation through the DOM tree. See: {@link http://api.jquery.com/on}
337
- */
338
- processEvent(event) {
339
- if (this.bc && this.playing) {
340
- //
341
- // The [AWT.Point](AWT.html#Point) where the mouse or touch event has been originated
342
- // and two [ActiveBox](ActiveBox.html) pointers used for the [BoxConnector](BoxConnector.html)
343
- // `origin` and `dest` points.
344
- let p = null, bx1, bx2;
345
- //
346
- // _touchend_ event don't provide pageX nor pageY information
347
- if (event.type === 'touchend')
348
- p = this.bc.active ? this.bc.dest.clone() : new Point();
349
- else {
350
- // Touch events can have more than one touch, so `pageX` must be obtained from `touches[0]`
351
- const
352
- x = event.originalEvent && event.originalEvent.touches ? event.originalEvent.touches[0].pageX : event.pageX,
353
- y = event.originalEvent && event.originalEvent.touches ? event.originalEvent.touches[0].pageY : event.pageY;
354
- p = new Point(x - this.$div.offset().left, y - this.$div.offset().top);
355
- }
356
-
357
- // Flag for tracking `mouseup` events
358
- let up = false,
359
- // Flag for assuring that only one media plays per event (avoid event sounds overlapping
360
- // cell's media sounds)
361
- m = false,
362
- // Flag for tracking clicks on the background of grid A
363
- clickOnBg0 = false,
364
- // Array to be filled with actions to be executed at the end of event processing
365
- delayedActions = [];
366
-
367
- switch (event.type) {
368
- case 'touchcancel':
369
- // Canvel movement
370
- if (this.bc.active)
371
- this.bc.end();
372
- break;
373
-
374
- case 'mouseup':
375
- // Don't consider drag moves below 3 pixels. Can be a "trembling click"
376
- if (this.bc.active && p.distanceTo(this.bc.origin) <= 3) {
377
- break;
378
- }
379
- up = true;
380
- /* falls through */
381
- case 'touchend':
382
- case 'touchstart':
383
- case 'mousedown':
384
- if (!this.bc.active) {
385
- // A new pairing starts
386
- //
387
- // Pairings can never start with a `mouseup` event
388
- if (up)
389
- break;
390
-
391
- this.ps.stopMedia(1);
392
- //
393
- // Determine if click was done on panel A or panel B
394
- bx1 = this.bgA ? this.bgA.findActiveBox(p) : null;
395
- bx2 = this.bgB ? this.bgB.findActiveBox(p) : null;
396
- if (bx1 && (!this.act.useOrder || bx1.idOrder === this.currentItem) ||
397
- !this.act.useOrder && bx2 && bx2.idAss !== -1) {
398
- // Start the [BoxConnector](BoxConnector.html)
399
- if (this.act.dragCells)
400
- this.bc.begin(p, bx1 || bx2);
401
- else
402
- this.bc.begin(p);
403
- // Play cell media or event sound
404
- m = m || (bx1 || bx2).playMedia(this.ps, delayedActions);
405
- if (!m)
406
- this.playEvent('click');
407
-
408
- // Move the focus to the opposite accessible group
409
- let bg = bx1 ? this.bgA : this.bgB;
410
- if (bg && bg.$accessibleDiv) {
411
- bg = bx1 ? this.bgB : this.bgA;
412
- if (bg && bg.$accessibleDiv)
413
- bg.$accessibleDiv.trigger('focus');
414
- }
415
- }
416
- } else {
417
- this.ps.stopMedia(1);
418
- // Pairing completed
419
- //
420
- // Find the active boxes behind `bc.origin` and `p`
421
- const origin = this.bc.origin;
422
- this.bc.end();
423
- bx1 = this.bgA ? this.bgA.findActiveBox(origin) : null;
424
- if (bx1) {
425
- bx2 = this.bgB ? this.bgB.findActiveBox(p) : null;
426
- } else {
427
- bx2 = this.bgB ? this.bgB.findActiveBox(origin) : null;
428
- if (bx2) {
429
- bx1 = this.bgA ? this.bgA.findActiveBox(p) : null;
430
- clickOnBg0 = true;
431
- }
432
- }
433
- // Check if the pairing was correct
434
- if (bx1 && bx2 && bx1.idAss !== -1 && bx2.idAss !== -1 && this.act.abc['secondary']) {
435
- let ok = false;
436
- const
437
- src = bx1.getDescription(),
438
- dest = bx2.getDescription(),
439
- matchingDest = this.act.abc['secondary'].getActiveBoxContent(bx1.idOrder);
440
- if (bx1.idOrder === bx2.idOrder || bx2.getContent().isEquivalent(matchingDest, true)) {
441
- // Pairing is OK. Play media and disable involved cells
442
- ok = true;
443
- bx1.idAss = -1;
444
- bx2.idAss = -1;
445
- if (this.act.abc['solvedPrimary']) {
446
- bx1.switchToAlt(this.ps);
447
- m = m || bx1.playMedia(this.ps, delayedActions);
448
- } else {
449
- if (clickOnBg0)
450
- m = m || bx1.playMedia(this.ps, delayedActions);
451
- else
452
- m = m || bx2.playMedia(this.ps, delayedActions);
453
- bx1.clear();
454
- }
455
- bx2.clear();
456
-
457
- if (this.act.useOrder && this.bgA)
458
- // Load next item
459
- this.currentItem = this.bgA.getNextItem(this.currentItem);
460
- }
461
- // Check results and notify action
462
- const cellsPlaced = this.bgB ? this.bgB.countCellsWithIdAss(-1) : 0;
463
- this.ps.reportNewAction(this.act, 'MATCH', src, dest, ok, cellsPlaced);
464
- // End activity or play event sound
465
- if (ok && cellsPlaced === this.bgB.getNumCells())
466
- this.finishActivity(true);
467
- else if (!m)
468
- this.playEvent(ok ? 'actionOk' : 'actionError');
469
- }
470
- this.update();
471
-
472
- // Move the focus to the `source` accessible group
473
- if (this.bgA && this.bgA.$accessibleDiv)
474
- this.bgA.$accessibleDiv.trigger('focus');
475
- }
476
- break;
477
-
478
- case 'mousemove':
479
- case 'touchmove':
480
- this.bc.moveTo(p);
481
- break;
482
- }
483
- delayedActions.forEach(action => action());
484
- event.preventDefault();
485
- }
486
- }
487
- }
488
-
489
- Object.assign(SimpleAssociationPanel.prototype, {
490
- /**
491
- * The {@link module:boxes/ActiveBoxbag.ActiveBoxBag ActiveBoxBag} object containing the information to be displayed in the `primary` panel
492
- * @name module:activities/associations/SimpleAssociation.SimpleAssociationPanel#bgA
493
- * @type {module:boxes/ActiveBoxBag.ActiveBoxBag} */
494
- bgA: null,
495
- /**
496
- * The {@link module:boxes/ActiveBoxbag.ActiveBoxBag ActiveBoxBag} object containing the information to be displayed in the `secondary` panel
497
- * @name module:activities/associations/SimpleAssociation.SimpleAssociationPanel#bgB
498
- * @type {module:boxes/ActiveBoxBag.ActiveBoxBag} */
499
- bgB: null,
500
- /**
501
- * The box connector
502
- * @name module:activities/associations/SimpleAssociation.SimpleAssociationPanel#bc
503
- * @type {module:boxes/BoxConnector.BoxConnector} */
504
- bc: null,
505
- /**
506
- * List of mouse, touch and keyboard events intercepted by this panel
507
- * @override
508
- * @name module:activities/associations/SimpleAssociation.SimpleAssociationPanel#events
509
- * @type {string[]} */
510
- events: ['mousedown', 'mouseup', 'mousemove', 'touchstart', 'touchend', 'touchmove', 'touchcancel'],
511
- });
512
-
513
- /**
514
- * Panel class associated to this type of activity: {@link module:activities/associations/SimpleAssociation.SimpleAssociationPanel SimpleAssociationPanel}
515
- * @type {class} */
516
- SimpleAssociation.Panel = SimpleAssociationPanel;
517
-
518
- // Register activity class
519
- export default Activity.registerClass('@associations.SimpleAssociation', SimpleAssociation);