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,699 +0,0 @@
1
- /**
2
- * File : boxes/AbstractBox.js
3
- * Created : 18/04/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
- import { Rectangle, Point, Dimension, Stroke } from '../AWT.js';
33
- import BoxBase from './BoxBase.js';
34
-
35
- /**
36
- * This abstract class is the base for most graphic components of JClic. It describes an area
37
- * (by default an {@link module:AWT.Rectangle}) with some special properties that determine how it must
38
- * be drawn on screen.
39
- *
40
- * Some types of boxes can act as containers for other boxes, establishing a hierarchy of dependences.
41
- * @abstract
42
- * @extends module:AWT.Rectangle
43
- */
44
- export class AbstractBox extends Rectangle {
45
- /**
46
- * AbstractBox constructor
47
- * @param {module:AbstractBox} parent - The AbstractBox to which this one belongs
48
- * @param {module:AWT.Container} container - The container where this box is placed.
49
- * @param {module:BoxBase} boxBase - The object where colors, fonts, border and other graphic properties
50
- * of this box are defined.
51
- */
52
- constructor(parent, container, boxBase) {
53
- // AbstractBox extends AWT.Rectangle
54
- super();
55
- this.container = container;
56
- this.parent = parent;
57
- this.boxBase = boxBase;
58
- this.shape = this;
59
- this.specialShape = false;
60
- this.visible = true;
61
- }
62
-
63
- /**
64
- * Setter method for `parent`
65
- * @param {module:boxes/AbstractBox.AbstractBox} parent - The new parent of this box
66
- */
67
- setParent(parent) {
68
- this.parent = parent;
69
- }
70
-
71
- /**
72
- * Gets the current parent of this box
73
- * @returns {module:boxes/AbstractBox.AbstractBox}
74
- */
75
- getParent() {
76
- return this.parent;
77
- }
78
-
79
- /**
80
- * Finisher method
81
- */
82
- end() {
83
- }
84
-
85
- /**
86
- * Setter method for `container`
87
- * @param {module:AWT.Container} newContainer - The new Container assigned to this box
88
- */
89
- setContainer(newContainer) {
90
- this.container = newContainer;
91
- if (this.$hostedComponent && this.container && this.container.$div) {
92
- this.$hostedComponent.detach();
93
- this.container.$div.append(this.$hostedComponent);
94
- }
95
- }
96
-
97
- /**
98
- * Gets the `container` attribute of this box, without checking its parent
99
- * @returns {module:AWT.Container}
100
- */
101
- getContainerX() {
102
- return this.container;
103
- }
104
-
105
- /**
106
- * Gets the container associated to this box, asking its parents when `null`.
107
- * @returns {module:AWT.Container}
108
- */
109
- getContainerResolve() {
110
- let ab = this;
111
- while (ab.container === null && ab.parent !== null)
112
- ab = ab.parent;
113
- return ab.container;
114
- }
115
-
116
- /**
117
- * Invalidates the zone corresponding to this box in the associated {@link module:AWT.Container}, if any.
118
- * @param {module:AWT.Rectangle} rect - The rectangle to be invalidated. When `null`, it's the full
119
- * container area.
120
- */
121
- invalidate(rect) {
122
- const cnt = this.getContainerResolve();
123
- if (cnt)
124
- cnt.invalidate(rect);
125
- }
126
-
127
- /**
128
- * Sets the {@link module:boxes/BoxBase.BoxBase BoxBase} of this box
129
- * @param {module:boxes/BoxBase.BoxBase} boxBase - The new BoxBase
130
- */
131
- setBoxBase(boxBase) {
132
- this.boxBase = boxBase;
133
- this.invalidate();
134
- }
135
-
136
- /**
137
- * Gets the real {@link module:boxes/BoxBase.BoxBase BoxBase} associated to this box, scanning down parent relationships.
138
- * @returns {module:boxes/BoxBase.BoxBase}
139
- */
140
- getBoxBaseResolve() {
141
- let ab = this;
142
- while (!ab.boxBase && ab.parent)
143
- ab = ab.parent;
144
- return ab.boxBase || BoxBase.DEFAULT_BOX_BASE;
145
- }
146
-
147
- /**
148
- * Sets the shape used to draw the content of this box
149
- * @param {module:AWT.Shape} sh - The shape to be set
150
- */
151
- setShape(sh) {
152
- this.shape = sh;
153
- this.specialShape = true;
154
- this.invalidate();
155
- super.setBounds(sh.getBounds());
156
- this.invalidate();
157
- }
158
-
159
- /**
160
- * Gets the current shape used in this box
161
- * @returns {module:AWT.Shape}
162
- */
163
- getShape() {
164
- return this.shape;
165
- }
166
-
167
- /**
168
- * Check if this box contains the specified point
169
- * @override
170
- * @param {module:AWT.Point} p - The point to be checked
171
- * @returns {boolean}
172
- */
173
- contains(p) {
174
- return this.shape === this ? super.contains(p) : this.shape.contains(p);
175
- }
176
-
177
- /**
178
- * Sets a new size and/or dimension to this box
179
- * @override
180
- * @param {AWT.Rectangle|number} rect - An AWT.Rectangle object, or the `x` coordinate of the
181
- * upper-left corner of a new rectangle.
182
- * @param {number} [y] - `y` coordinate of the upper-left corner of the new rectangle.
183
- * @param {number} [w] - Width of the new rectangle.
184
- * @param {number} [h] - Height of the new rectangle.
185
- */
186
- setBounds(rect, y, w, h) {
187
- if (typeof rect === 'number')
188
- // arguments are co-ordinates and size
189
- rect = new Rectangle(rect, y, w, h);
190
- // Rectangle comparision
191
- if (this.equals(rect))
192
- return;
193
-
194
- const sizeChanged = !this.dim.equals(rect.dim);
195
- if (this.specialShape) {
196
- if (sizeChanged) {
197
- this.shape.scaleBy(new Dimension(rect.dim.width / this.dim.width, rect.dim.height / this.dim.height));
198
- this.setShape(this.shape);
199
- }
200
- if (!this.pos.equals(rect.pos)) {
201
- this.shape.moveTo(rect.pos);
202
- }
203
- this.setShape(this.shape);
204
- } else
205
- super.setBounds(rect);
206
-
207
- if (this.$hostedComponent)
208
- this.setHostedComponentBounds(sizeChanged);
209
-
210
- return this;
211
- }
212
-
213
- /**
214
- * Sets a new location for this box. In JClic this method was named `setLocation`
215
- * @param {AWT.Point|number} newPos - A point or the `x` coordinate of a new point.
216
- * @param {number} [y] - The `y` coordinate of a new point.
217
- */
218
- moveTo(newPos, y) {
219
- if (typeof newPos === 'number')
220
- newPos = new Point(newPos, y);
221
- this.setBounds((new Rectangle(this)).moveTo(newPos));
222
- }
223
-
224
- /**
225
- * Sets a new location to this box. In JClic this method was named `translate`.
226
- * @param {number} dx - The displacement on the X axis
227
- * @param {number} dy - The displacement on the Y axis
228
- */
229
- moveBy(dx, dy) {
230
- this.setBounds((new Rectangle(this)).moveBy(dx, dy));
231
- }
232
-
233
- /**
234
- * Changes the size of this box
235
- * @param {number} width
236
- * @param {number} height
237
- */
238
- setSize(width, height) {
239
- this.setBounds(new Rectangle(this.pos, new Dimension(width, height)));
240
- }
241
-
242
- /**
243
- * Checks if this box has border
244
- * @returns {boolean}
245
- */
246
- hasBorder() {
247
- return this.border;
248
- }
249
-
250
- /**
251
- * Sets/unsets a border to this box
252
- * @param {boolean} newVal - `true` to set a border.
253
- */
254
- setBorder(newVal) {
255
- if (!newVal)
256
- this.invalidate();
257
- this.border = newVal;
258
- if (newVal)
259
- this.invalidate();
260
- }
261
-
262
- /**
263
- * Checks if this box is fully visible
264
- * @returns {boolean}
265
- */
266
- isVisible() {
267
- return this.visible;
268
- }
269
-
270
- /**
271
- * Sets this box visible or invisible
272
- * @param {boolean} newVal - `true` for visible
273
- */
274
- setVisible(newVal) {
275
- this.visible = newVal;
276
- this.setHostedComponentVisible();
277
- this.invalidate();
278
- }
279
-
280
- /**
281
- * Makes {@link module:boxes/AbstractBox.AbstractBox#$hostedComponent} visible or invisible, based on the value of
282
- * the AbstractBox `visible` flag.
283
- */
284
- setHostedComponentVisible() {
285
- if (this.$hostedComponent)
286
- this.$hostedComponent.css('visibility', this.visible ? 'visible' : 'hidden');
287
- }
288
-
289
- /**
290
- * Checks if this box is temporary hidden
291
- * @returns {boolean}
292
- */
293
- isTemporaryHidden() {
294
- return this.temporaryHidden;
295
- }
296
-
297
- /**
298
- * Makes this box temporary hidden (newVal `true`) or resets its original state (newVal `false`)
299
- * @param {boolean} newVal
300
- */
301
- setTemporaryHidden(newVal) {
302
- this.temporaryHidden = newVal;
303
- }
304
-
305
- /**
306
- * Checks if this box is currently inactive.
307
- * @returns {boolean}
308
- */
309
- isInactive() {
310
- return this.inactive;
311
- }
312
-
313
- /**
314
- * Makes this box active (`false`) or inactive (`true`)
315
- * @param {boolean} newVal
316
- */
317
- setInactive(newVal) {
318
- this.inactive = newVal;
319
- if (this.$hostedComponent) {
320
- this.setHostedComponentColors();
321
- this.setHostedComponentVisible();
322
- } else {
323
- if (this.$accessibleElement) {
324
- const disabled = this.isInactive() && !this.accessibleAlwaysActive;
325
- this.$accessibleElement.prop({
326
- disabled: disabled,
327
- tabindex: disabled ? -1 : 0
328
- });
329
- }
330
- this.invalidate();
331
- }
332
- }
333
-
334
- /**
335
- * Checks if this box is in `inverted` state.
336
- * @returns {boolean}
337
- */
338
- isInverted() {
339
- return this.inverted;
340
- }
341
-
342
-
343
- /**
344
- * Puts this box in `inverted` mode or restores its original state.
345
- * @param {boolean} newVal
346
- */
347
- setInverted(newVal) {
348
- this.inverted = newVal;
349
- if (this.$hostedComponent)
350
- this.setHostedComponentColors();
351
- else
352
- this.invalidate();
353
- }
354
-
355
- /**
356
- * Checks if this box is `marked`
357
- * @returns {boolean}
358
- */
359
- isMarked() {
360
- return this.marked;
361
- }
362
-
363
- /**
364
- * Sets this box in `marked` mode, or restores its original state.
365
- * @param {boolean} newVal
366
- */
367
- setMarked(newVal) {
368
- if (!newVal)
369
- this.invalidate();
370
- this.marked = newVal;
371
- if (this.$hostedComponent) {
372
- this.setHostedComponentColors();
373
- this.setHostedComponentBorder();
374
- } else if (newVal)
375
- this.invalidate();
376
- }
377
-
378
- /**
379
- * Checks if this box has the input focus
380
- * @returns {boolean}
381
- */
382
- isFocused() {
383
- return this.focused;
384
- }
385
-
386
- /**
387
- *
388
- * Sets or unsets the input focus to this box.
389
- * @param {boolean} newVal
390
- */
391
- setFocused(newVal) {
392
- if (!newVal)
393
- this.invalidate();
394
- this.focused = newVal;
395
- if (newVal)
396
- this.invalidate();
397
- // Put hosted component on top
398
- if (this.$hostedComponent)
399
- this.$hostedComponent.css('z-index', this.focused ? 20 : 2);
400
- }
401
-
402
- /**
403
- * Checks if this box is in `alternative` state.
404
- * @returns {boolean}
405
- */
406
- isAlternative() {
407
- return this.alternative;
408
- }
409
-
410
- /**
411
- * Sets this box in `alternative` mode, or restores its original state.
412
- * @param {boolean} newVal
413
- */
414
- setAlternative(newVal) {
415
- this.alternative = newVal;
416
- this.invalidate();
417
- }
418
-
419
- /**
420
- * Draws the content of this box on an HTML `canvas` element. At this level, only background
421
- * and border are painted/stroked. Derived classes should implement specific drawing tasks in
422
- * {@link module:boxes/AbstractBox.AbstractBox#updateContent}.
423
- * @param {external:CanvasRenderingContext2D} ctx - The canvas rendering context used to draw the
424
- * box content.
425
- * @param {module:AWT.Rectangle} [dirtyRegion=null] - The area that must be repainted. `null` refers to the whole box.
426
- */
427
- update(ctx, dirtyRegion = null) {
428
- if (this.isEmpty() || !this.isVisible() || this.isTemporaryHidden())
429
- return false;
430
-
431
- if (dirtyRegion && !this.shape.intersects(dirtyRegion))
432
- return false;
433
-
434
- /**
435
- * TODO: Implement clipping
436
- Shape saveClip=new Area(g2.getClip())
437
- Area clip=new Area(saveClip)
438
- clip.intersect(new Area(shape))
439
- g2.setClip(clip)
440
- */
441
-
442
- const style = this.getBoxBaseResolve();
443
- if (!style.transparent && !style.dontFill && !this.tmpTrans) {
444
- if (!style.bgGradient || style.bgGradient.hasTransparency()) {
445
- // Prepare the rendering context
446
- ctx.fillStyle = this.inactive ?
447
- style.inactiveColor :
448
- this.inverted ? style.textColor : style.backColor;
449
- // Fill the shape
450
- this.shape.fill(ctx, dirtyRegion);
451
- }
452
- if (style.bgGradient) {
453
- ctx.fillStyle = style.bgGradient.getGradient(ctx, this.shape.getBounds());
454
- this.shape.fill(ctx, dirtyRegion);
455
- }
456
- // Reset the canvas context
457
- ctx.fillStyle = 'black';
458
- }
459
-
460
- if (!this.$hostedComponent)
461
- this.updateContent(ctx, dirtyRegion);
462
-
463
- this.drawBorder(ctx);
464
- return true;
465
- }
466
-
467
- /**
468
- * Here is where classes derived from {@link module:boxes/AbstractBox.AbstractBox AbstractBox} should implement the drawing of its
469
- * content. Background and border are already painted in {@link module:boxes/AbstractBox.AbstractBox#update}.
470
- * @param {external:CanvasRenderingContext2D} _ctx - The canvas rendering context used to draw the
471
- * box content.
472
- * @param {module:AWT.Rectangle} [_dirtyRegion] - The area that must be repainted. `null` refers to the whole box.
473
- */
474
- //
475
- // Abstract method, to be implemented in subclasses
476
- updateContent(_ctx, _dirtyRegion) {
477
- }
478
-
479
- /**
480
- * Draws the box border
481
- * @param {external:CanvasRenderingContext2D} ctx - The canvas rendering context where the border
482
- * will be drawn.
483
- */
484
- drawBorder(ctx) {
485
- if (this.border || this.marked) {
486
- const style = this.getBoxBaseResolve();
487
-
488
- // Prepare stroke settings
489
- ctx.strokeStyle = style.borderColor;
490
- style[this.marked ? 'markerStroke' : 'borderStroke'].setStroke(ctx);
491
- if (this.marked)
492
- ctx.globalCompositeOperation = 'xor';
493
-
494
- // Draw border
495
- this.shape.stroke(ctx);
496
-
497
- // Reset ctx default values
498
- if (this.marked)
499
- ctx.globalCompositeOperation = 'source-over';
500
- ctx.strokeStyle = 'black';
501
- Stroke.prototype.setStroke(ctx);
502
- }
503
- }
504
-
505
- /**
506
- * Returns the enclosing Rectangle of this box including its border (if any)
507
- * @returns {module:AWT.Rectangle}
508
- */
509
- getBorderBounds() {
510
- const result = new Rectangle(this.getBounds());
511
- if (this.border || this.marked) {
512
- const style = this.getBoxBaseResolve();
513
- const w = style[this.marked ? 'markerStroke' : 'borderStroke'].lineWidth;
514
- result.moveBy(-w / 2, -w / 2);
515
- result.dim.width += w;
516
- result.dim.height += w;
517
- }
518
- return result;
519
- }
520
-
521
- /**
522
- * Sets the {@link module:boxes/AbstractBox.AbstractBox#$hostedComponent $hostedComponent} member.
523
- * @param {external:jQuery} $hc - The jQuery DOM component hosted by this box.
524
- */
525
- setHostedComponent($hc) {
526
- if (this.$hostedComponent)
527
- this.$hostedComponent.detach();
528
-
529
- this.$hostedComponent = $hc;
530
-
531
- if (this.$hostedComponent) {
532
- this.setContainer(this.container);
533
- this.setHostedComponentColors();
534
- this.setHostedComponentBorder();
535
- this.setHostedComponentBounds(true);
536
- this.setHostedComponentVisible();
537
- this.setFocused(this.focused);
538
- }
539
- }
540
-
541
- /**
542
- * Gets the current {@link module:boxes/AbstractBox.AbstractBox#$hostedComponent|$hostedComponent} member
543
- * @returns {external:jQuery}
544
- */
545
- getHostedComponent() {
546
- return this.$hostedComponent;
547
- }
548
-
549
- /**
550
- * Sets {@link module:boxes/AbstractBox.AbstractBox#$hostedComponent|$hostedComponent} colors and other css properties
551
- * based on the current {@link module:boxes/BoxBase.BoxBase BoxBase} of this box.
552
- */
553
- setHostedComponentColors() {
554
- if (this.$hostedComponent) {
555
- const style = this.getBoxBaseResolve();
556
- const css = style.getCSS(null, this.inactive, this.inverted, this.alternative);
557
- // Check if cell has background gradient and animated gif
558
- if (this.$hostedComponent.data('background-image') && css['background-image'])
559
- css['background-image'] = `${this.$hostedComponent.data('background-image')},${css['background-image']}`;
560
- this.$hostedComponent.css(css);
561
- }
562
- }
563
-
564
- /**
565
- * Sets the {@link module:boxes/AbstractBox.AbstractBox#$hostedComponent|$hostedComponent} border, based on the current
566
- * {@link module:boxes/BoxBase.BoxBase BoxBase} of this box.
567
- */
568
- setHostedComponentBorder() {
569
- if (this.$hostedComponent && (this.border || this.marked)) {
570
- const style = this.getBoxBaseResolve();
571
- this.$hostedComponent.css({
572
- 'border-width': `${style.get(this.marked ? 'markerStroke' : 'borderStroke').lineWidth}px`,
573
- 'border-style': 'solid',
574
- 'border-color': style.get('borderColor')
575
- });
576
- }
577
- }
578
-
579
- /**
580
- * Places and resizes {@link module:boxes/AbstractBox.AbstractBox#$hostedComponent|$hostedComponent}, based on the size
581
- * and position of this box.
582
- * @param {boolean} _sizeChanged - `true` when this {@link module:boxes/ActiveBox.ActiveBox ActiveBox} has changed its size
583
- */
584
- setHostedComponentBounds(_sizeChanged) {
585
- if (this.$hostedComponent) {
586
- const
587
- r = this.getBounds(),
588
- b = this.border || this.marked ? this.getBoxBaseResolve().get(this.marked ? 'markerStroke' : 'borderStroke').lineWidth : 0;
589
- this.$hostedComponent.css({
590
- position: 'absolute',
591
- width: r.dim.width - 2 * b + 'px',
592
- height: r.dim.height - 2 * b + 'px',
593
- top: r.pos.y + 'px',
594
- left: r.pos.x + 'px'
595
- });
596
- }
597
- }
598
- }
599
-
600
- Object.assign(AbstractBox.prototype, {
601
- /**
602
- * The parent AbstractBox (can be `null`)
603
- * @name module:boxes/AbstractBox.AbstractBox#parent
604
- * @type {module:boxes/AbstractBox.AbstractBox} */
605
- parent: null,
606
- /**
607
- * The Container to which this AbstractBox belongs
608
- * @name module:boxes/AbstractBox.AbstractBox#container
609
- * @type {module:AWT.Container} */
610
- container: null,
611
- /**
612
- * The {@link module:boxes/BoxBase.BoxBase BoxBase} related to this AbstractBox. When `null`, the parent can provide an
613
- * alternative one.
614
- * @name module:boxes/AbstractBox.AbstractBox#boxBase
615
- * @type {module:boxes/BoxBase.BoxBase} */
616
- boxBase: null,
617
- /**
618
- * Whether this box has a border or not
619
- * @name module:boxes/AbstractBox.AbstractBox#border
620
- * @type {boolean} */
621
- border: false,
622
- /**
623
- * The shape of this box (the box Rectangle or a special Shape, if set)
624
- * @name module:boxes/AbstractBox.AbstractBox#shape
625
- * @type {module:AWT.Shape} */
626
- shape: null,
627
- /**
628
- * Whether this box has a shape that is not a rectangle
629
- * @name module:boxes/AbstractBox.AbstractBox#specialShape
630
- * @type {boolean} */
631
- specialShape: false,
632
- /**
633
- * Whether this box is visible or not
634
- * @name module:boxes/AbstractBox.AbstractBox#visible
635
- * @type {boolean} */
636
- visible: true,
637
- /**
638
- * Used to temporary hide a box while other drawing operations are done
639
- * @name module:boxes/AbstractBox.AbstractBox#temporaryHidden
640
- * @type {boolean} */
641
- temporaryHidden: false,
642
- /**
643
- * Cells with this attribute will be transparent but with painted border
644
- * @name module:boxes/AbstractBox.AbstractBox#tmpTrans
645
- * @type {boolean}*/
646
- tmpTrans: false,
647
- /**
648
- * Whether this box is active or inactive
649
- * @name module:boxes/AbstractBox.AbstractBox#inactive
650
- * @type {boolean} */
651
- inactive: false,
652
- /**
653
- * Whether this box must be displayed with inverted or regular colors
654
- * @name module:boxes/AbstractBox.AbstractBox#inverted
655
- * @type {boolean} */
656
- inverted: false,
657
- /**
658
- * Whether this box must be displayed with alternative or regular color and font settings
659
- * @name module:boxes/AbstractBox.AbstractBox#alternative
660
- * @type {boolean} */
661
- alternative: false,
662
- /**
663
- * Whether this box is marked (selected) or not
664
- * @name module:boxes/AbstractBox.AbstractBox#marked
665
- * @type {boolean} */
666
- marked: false,
667
- /**
668
- * Whether this box holds the input focus
669
- * @name module:boxes/AbstractBox.AbstractBox#focused
670
- * @type {boolean} */
671
- focused: false,
672
- /**
673
- * Text to be used in accessible contexts
674
- * @name module:boxes/AbstractBox.AbstractBox#accessibleText
675
- * @type {string} */
676
- accessibleText: '',
677
- /**
678
- * Describes the main role of this box on the activity. Useful in wai-aria descriptions.
679
- * @name module:boxes/AbstractBox.AbstractBox#role
680
- * @type {string} */
681
- role: 'cell',
682
- /**
683
- * DOM element used to display this cell content in wai-aria contexts
684
- * @name module:boxes/AbstractBox.AbstractBox#$accessibleElement
685
- * @type {external:jQuery} */
686
- $accessibleElement: null,
687
- /**
688
- * Flag indicating that $accessibleElement should be always active
689
- * @name module:boxes/AbstractBox.AbstractBox#accessibleAlwaysActive
690
- * @type {boolean} */
691
- accessibleAlwaysActive: false,
692
- /**
693
- * An external JQuery DOM element hosted by this box
694
- * @name module:boxes/AbstractBox.AbstractBox#$hostedComponent
695
- * @type {external:jQuery} */
696
- $hostedComponent: null,
697
- });
698
-
699
- export default AbstractBox;