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,500 +0,0 @@
1
- /**
2
- * File : boxes/BoxBag.js
3
- * Created : 21/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 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 AbstractBox from './AbstractBox.js';
33
- import { Rectangle, Dimension, Point } from '../AWT.js';
34
- import { settings } from '../Utils.js';
35
-
36
- /**
37
- * BoxBag is a class derived from {@link module:boxes/AbstractBox.AbstractBox AbstractBox} that contains a collection of "boxes"
38
- * (objects also derived from {@link module:boxes/AbstractBox.AbstractBox AbstractBox}). This class implements methods to add, remove
39
- * and retrieve boxes, and to manage some of its properties like visibility, status, location and size.
40
- * @extends module:boxes/AbstractBox.AbstractBox
41
- */
42
- export class BoxBag extends AbstractBox {
43
- /**
44
- * BoxBag constructor
45
- * @param {module:boxes/AbstractBox.AbstractBox} [parent] - The AbstractBox to which this box bag belongs
46
- * @param {module:AWT.Container} [container] - The container where this box bag is placed.
47
- * @param {module:boxes/BoxBase.BoxBase} [boxBase] - The object where colors, fonts, border and other graphic properties
48
- */
49
- constructor(parent, container, boxBase) {
50
- // BoxBag extends AbstractBox
51
- super(parent, container, boxBase);
52
- this.preferredBounds = new Rectangle();
53
- this.cells = [];
54
- }
55
-
56
- /**
57
- * Static method that sets the position and dimension of a `Resizable` object based on a
58
- * preferred maximum dimension and a margin.
59
- * @param {module:AWT.Dimension} preferredMaxSize - The preferred maximum size
60
- * @param {Resizable} rs - A resizable object implementing the methods described in the
61
- * {@link http://projectestac.github.io/jclic/apidoc/edu/xtec/jclic/boxes/Resizable.html Resizable}
62
- * interface of JClic. Currently a {@link module:boxes/BoxBag.BoxBag BoxBag} or {@link module:boxes/TextGrid.TextGrid TextGrid}.
63
- * @param {number} margin - The margin between the available area and the BoxBag
64
- * @returns {module:AWT.Dimension} - The resulting size of the container
65
- */
66
- static layoutSingle(preferredMaxSize, rs, margin) {
67
-
68
- // Avoid exceptions when rs is null
69
- if (!rs)
70
- return preferredMaxSize;
71
-
72
- // optimal, maximal and minimal dimensions
73
- let
74
- d = rs.getPreferredSize(),
75
- minSize = rs.getMinimumSize(),
76
- maxSize = preferredMaxSize;
77
-
78
- // remove margins
79
- maxSize.width -= 2 * margin;
80
- maxSize.height -= 2 * margin;
81
- // correct maxSize if less than minSize
82
- if (minSize.width > maxSize.width || minSize.height > maxSize.height) {
83
- maxSize = minSize;
84
- }
85
- // compute scale factor
86
- let scale = d.width > maxSize.width ? maxSize.width / d.width : 1;
87
- if (scale * d.height > maxSize.height)
88
- scale = maxSize.height / d.height;
89
-
90
- // resize the `Resizable` object
91
- d = rs.getScaledSize(scale);
92
- rs.setBounds(margin, margin, d.width, d.height);
93
-
94
- // restore margins
95
- d.width += 2 * margin;
96
- d.height += 2 * margin;
97
-
98
- return d;
99
- }
100
-
101
- /**
102
- * Static method that sets the position and dimension of two `Resizable` objects based on a
103
- * preferred maximum size, a layout schema and a margin.
104
- * @param {module:AWT.Dimension} desiredMaxSize - The preferred maximum size
105
- * @param {Resizable} rsA - First resizable object implementing the methods described in the
106
- * {@link http://projectestac.github.io/jclic/apidoc/edu/xtec/jclic/boxes/Resizable.html Resizable}
107
- * interface of JClic. Currently a {@link module:boxes/BoxBag.BoxBag BoxBag} or {@link module:boxes/TextGrid.TextGrid TextGrid}.
108
- * @param {Resizable} rsB - Second resizable object
109
- * @param {string} boxGridPos - The layout schema. Possible values are:
110
- * - "AB" (_A_ at left, _B_ at right)
111
- * - "BA" (_B_ at left, _A_ at right)
112
- * - "AUB" (_A_ above _B_)
113
- * - "BUA" (_A_ below _B_).
114
- * @param {number} margin - The margin between the available area and the BoxBag
115
- * @returns {module:AWT.Dimension} - The resulting size of the container
116
- */
117
- static layoutDouble(desiredMaxSize, rsA, rsB, boxGridPos, margin) {
118
- // number of horizontal and vertical grid lines
119
- let
120
- isHLayout = false,
121
- nbh = 1,
122
- nbv = 1;
123
- switch (boxGridPos) {
124
- case 'AB':
125
- case 'BA':
126
- nbh = 2;
127
- nbv = 1;
128
- isHLayout = true;
129
- break;
130
- case 'AUB':
131
- case 'BUA':
132
- nbh = 1;
133
- nbv = 2;
134
- isHLayout = false;
135
- break;
136
- }
137
- const
138
- ra = rsA.getBounds(),
139
- rb = rsB.getBounds();
140
-
141
- // optimal dimensions
142
- let
143
- da = rsA.getPreferredSize(),
144
- db = rsB.getPreferredSize();
145
-
146
- const d = new Dimension(
147
- isHLayout ? da.width + db.width : Math.max(da.width, db.width),
148
- isHLayout ? Math.max(da.height, db.height) : da.height + db.height
149
- );
150
-
151
- // minimal dimensions
152
- const
153
- minSizeA = rsA.getMinimumSize(),
154
- minSizeB = rsB.getMinimumSize(),
155
- minSize = new Dimension(
156
- isHLayout ? minSizeA.width + minSizeB.width : Math.max(minSizeA.width, minSizeB.width),
157
- isHLayout ? Math.max(minSizeA.height, minSizeB.height) : minSizeA.height + minSizeB.height
158
- ),
159
- maxSize = desiredMaxSize;
160
-
161
- // remove margins
162
- maxSize.width -= (1 + nbh) * margin;
163
- maxSize.height -= (1 + nbv) * margin;
164
-
165
- // correct maxSize if less than minSize
166
- if (minSize.width > maxSize.width || minSize.height > maxSize.height)
167
- maxSize.setDimension(minSize);
168
-
169
- // compute scale factor
170
- let scale = d.width > maxSize.width ? maxSize.width / d.width : 1;
171
- if (scale * d.height > maxSize.height)
172
- scale = maxSize.height / d.height;
173
-
174
- //
175
- // correct possible minimal infractions
176
- // ...
177
- // resize
178
- da = rsA.getScaledSize(scale);
179
- db = rsB.getScaledSize(scale);
180
-
181
- // set margins to center one box relative to the other
182
- let
183
- dah = db.width > da.width ? (db.width - da.width) / 2 : 0,
184
- dbh = da.width > db.width ? (da.width - db.width) / 2 : 0,
185
- dav = db.height > da.height ? (db.height - da.height) / 2 : 0,
186
- dbv = da.height > db.height ? (da.height - db.height) / 2 : 0;
187
-
188
- switch (boxGridPos) {
189
- case 'AB':
190
- rsA.setBounds(margin, margin + dav, da.width, da.height);
191
- rsB.setBounds(2 * margin + da.width, margin + dbv, db.width, db.height);
192
- break;
193
- case 'BA':
194
- rsB.setBounds(margin, margin + dbv, db.width, db.height);
195
- rsA.setBounds(2 * margin + db.width, margin + dav, da.width, da.height);
196
- break;
197
- case 'AUB':
198
- rsA.setBounds(margin + dah, margin, da.width, da.height);
199
- rsB.setBounds(margin + dbh, 2 * margin + da.height, db.width, db.height);
200
- break;
201
- case 'BUA':
202
- rsB.setBounds(margin + dbh, margin, db.width, db.height);
203
- rsA.setBounds(margin + dah, 2 * margin + db.height, da.width, da.height);
204
- break;
205
- default:
206
- rsA.setBounds(
207
- Math.round(margin + scale * ra.pos.x),
208
- Math.round(margin + scale * ra.pos.y),
209
- da.width, da.height);
210
- rsB.setBounds(
211
- Math.round(margin + scale * rb.pos.x),
212
- Math.round(margin + scale * rb.pos.y),
213
- da.width, da.height);
214
- break;
215
- }
216
-
217
- // recompute 'd' adding margins
218
- const r = new Rectangle(rsA.getBounds());
219
- r.add(rsB.getBounds());
220
- d.width = r.dim.width + 2 * margin;
221
- d.height = r.dim.height + 2 * margin;
222
-
223
- return d;
224
- }
225
-
226
- /**
227
- * Gets the preferred size of this `BoxBag`
228
- * @returns {module:AWT.Dimension}
229
- */
230
- getPreferredSize() {
231
- return this.preferredBounds.dim;
232
- }
233
-
234
- /**
235
- * Gets the minimum size requested by this `BoxBag`
236
- * @returns {module:AWT.Dimension}
237
- */
238
- getMinimumSize() {
239
- const d = this.getPreferredSize();
240
- return new Dimension(
241
- Math.max(settings.MIN_CELL_SIZE, d.width),
242
- Math.max(settings.MIN_CELL_SIZE, d.height));
243
- }
244
-
245
- /**
246
- * Scales the current size of this box bag, multiplying all values by a specific factor
247
- * @param {number} scale - The scale factor
248
- * @returns {module:AWT.Dimension}
249
- */
250
- getScaledSize(scale) {
251
- const d = this.getPreferredSize();
252
- return new Dimension(Math.round(scale * d.width), Math.round(scale * d.height));
253
- }
254
-
255
- /**
256
- * Adds an {@link module:boxes/AbstractBox.AbstractBox AbstractBox} to the collection of cells
257
- * @param {module:boxes/AbstractBox.AbstractBox} bx - The box to add
258
- */
259
- addBox(bx) {
260
- this.cells.push(bx);
261
- bx.setParent(this);
262
-
263
- if (this.cells.length === 1)
264
- Rectangle.prototype.setBounds.call(this, bx);
265
- else
266
- this.add(bx);
267
-
268
- this.preferredBounds.setBounds(this.getBounds());
269
- }
270
-
271
- /**
272
- * Returns the index of a specific box in the `cells` array
273
- * @param {module:boxes/AbstractBox.AbstractBox} bx
274
- * @returns {number}
275
- */
276
- boxIndex(bx) {
277
- return bx === null ? -1 : this.cells.indexOf(bx);
278
- }
279
-
280
- /**
281
- * Returns the box at a specific index in the `cells` array
282
- * @param {number} n - The index
283
- * @returns {module:boxes/AbstractBox.AbstractBox}
284
- */
285
- getBox(n) {
286
- return n < 0 || n >= this.cells.length ? null : this.cells[n];
287
- }
288
-
289
- /**
290
- * Gets the background box
291
- * @returns {module:boxes/AbstractBox.AbstractBox}
292
- */
293
- getBackgroundBox() {
294
- return this.backgroundBox;
295
- }
296
-
297
- /**
298
- * Sets the background box
299
- * @param {module:boxes/AbstractBox.AbstractBox} bx
300
- */
301
- setBackgroundBox(bx) {
302
- this.backgroundBox = bx;
303
- if (bx !== null) {
304
- bx.setParent(this);
305
- bx.isBackground = true;
306
- }
307
- // Add the `backgroundbox` rectangle to the global BoxBag rectangle
308
- Rectangle.prototype.add.call(this, bx);
309
- this.preferredBounds.setBounds(this.getBounds());
310
- }
311
-
312
- /**
313
- * Recalculates the total size of this BoxBag (useful after direct additions o deletions of
314
- * elements in the `cells` array).
315
- * Updates `preferredBounds` and the current position and size of the box bag.
316
- */
317
- recalcSize() {
318
- let r = this.backgroundBox ? new Rectangle(this.backgroundBox.pos, this.backgroundBox.dim) : null;
319
- this.cells.forEach(cell => {
320
- if (!r)
321
- r = new Rectangle(cell.pos, cell.dim);
322
- else
323
- r.add(cell);
324
- });
325
- if (!r)
326
- r = new Rectangle(this.pos.x, this.pos.y, 0, 0);
327
- this.preferredBounds.setRect(r);
328
- this.x = r.pos.x;
329
- this.y = r.pos.y;
330
- this.dim.width = r.dim.width;
331
- this.dim.height = r.dim.height;
332
- }
333
-
334
- /**
335
- * Returns the number of cells stored in this BoxBag
336
- * @returns {number}
337
- */
338
- getNumCells() {
339
- return this.cells.length;
340
- }
341
-
342
- /**
343
- * Sets the specified key - value pair to all cells of this bag.
344
- * @param {string} key - The key to be established
345
- * @param {any} value - The value, of any type
346
- */
347
- setCellAttr(key, value) {
348
- this.cells.forEach(bx => bx[key] = value);
349
- if (this.backgroundBox)
350
- this.backgroundBox[key] = value;
351
- }
352
-
353
- /**
354
- * Overrides {@link module:boxes/AbstractBox.AbstractBox#setBorder} iterating over all the cells stored in this box bag.
355
- * @override
356
- * @param {boolean} newVal - Whether to set or unset the border
357
- */
358
- setBorder(newVal) {
359
- this.cells.forEach(bx => bx.setBorder(newVal));
360
- }
361
-
362
- /**
363
- * Overrides {@link module:boxes/AbstractBox.AbstractBox#setVisible} iterating over all the cells stored in this box bag.
364
- * @override
365
- * @param {boolean} newVal - Whether to set the cells visible or not
366
- */
367
- setVisible(newVal) {
368
- this.cells.forEach(bx => bx.setVisible(newVal));
369
- }
370
-
371
- /**
372
- * Overrides {@link module:boxes/AbstractBox.AbstractBox#setAlternative} iterating over all the cells stored in this box bag.
373
- * @override
374
- * @param {boolean} newVal - Whether to set or unset the cells in "alternative" mode
375
- */
376
- setAlternative(newVal) {
377
- super.setAlternative(newVal);
378
- this.cells.forEach(bx => bx.setAlternative(newVal));
379
- }
380
-
381
- /**
382
- * Overrides {@link module:boxes/AbstractBox.AbstractBox#setBounds} adjusting the position and size of all cells
383
- * @override
384
- * @param {(AWT.Rectangle|number)} rect - An AWT.Rectangle object, or the `x` coordinate of the
385
- * upper-left corner of a new rectangle.
386
- * @param {number} [ry] - `y` coordinate of the upper-left corner of the new rectangle.
387
- * @param {number} [rw] - Width of the new rectangle.
388
- * @param {number} [rh] - Height of the new rectangle.
389
- */
390
- setBounds(rect, ry, rw, rh) {
391
- if (typeof rect === 'number') {
392
- // Arguments are co-ordinates and size
393
- rect = new Rectangle(rect, ry, rw, rh);
394
- }
395
- if (rect.getSurface() > 0 && !rect.equals(this)) {
396
- const
397
- scaleW = rect.dim.width / this.dim.width,
398
- scaleH = rect.dim.height / this.dim.height,
399
- dx = rect.pos.x - this.pos.x,
400
- dy = rect.pos.y - this.pos.y;
401
- this.cells.forEach(bx => {
402
- const p = new Point(bx.pos.x - this.pos.x, bx.pos.y - this.pos.y);
403
- bx.setBounds(
404
- dx + this.pos.x + scaleW * p.x,
405
- dy + this.pos.y + scaleH * p.y,
406
- scaleW * bx.dim.width,
407
- scaleH * bx.dim.height);
408
- // Clear pos0
409
- bx.pos0 = null;
410
- });
411
- if (this.backgroundBox !== null) {
412
- const
413
- bx = this.backgroundBox,
414
- p = new Point(bx.pos.x - this.pos.x, bx.pos.y - this.pos.y);
415
- bx.setBounds(
416
- dx + this.pos.x + scaleW * p.x,
417
- dy + this.pos.y + scaleH * p.y,
418
- scaleW * bx.dim.width,
419
- scaleH * bx.dim.height);
420
- }
421
- }
422
- super.setBounds(rect);
423
- }
424
-
425
- /**
426
- * Performs graphics operations for each cell.
427
- * Overrides {@link module:boxes/AbstractBox.AbstractBox#update}
428
- * @override
429
- * @param {external:CanvasRenderingContext2D} ctx - The canvas rendering context used to draw the
430
- * box contents.
431
- * @param {module:AWT.Rectangle} [dirtyRegion] - The area that must be repainted. `null` refers to the whole box.
432
- */
433
- update(ctx, dirtyRegion) {
434
- if (this.isEmpty() || !this.isVisible() || this.isTemporaryHidden())
435
- return false;
436
-
437
- if (dirtyRegion && !this.intersects(dirtyRegion))
438
- return false;
439
-
440
- if (this.backgroundBox !== null)
441
- this.backgroundBox.update(ctx, dirtyRegion);
442
-
443
- this.cells.forEach(bx => {
444
- if (!bx.isMarked())
445
- bx.update(ctx, dirtyRegion);
446
- });
447
-
448
- // Make a second loop to repaint marked cells
449
- this.cells.forEach(bx => {
450
- if (bx.isMarked())
451
- bx.update(ctx, dirtyRegion);
452
- });
453
- return true;
454
- }
455
-
456
- /**
457
- * Finds the first visible {@link module:boxes/AbstractBox.AbstractBox AbstractBox} located under the specified point
458
- * @param {module:AWT.Point} p
459
- * @returns {module:boxes/AbstractBox.AbstractBox}
460
- */
461
- findBox(p) {
462
- let result = null;
463
- for (let i = this.cells.length - 1; i >= 0; i--) {
464
- const bx = this.getBox(i);
465
- if (bx.isVisible() && bx.contains(p)) {
466
- result = bx;
467
- break;
468
- }
469
- }
470
- return result;
471
- }
472
-
473
- /**
474
- * Count the number of cells of this BoxBag that are in "inactive" state
475
- * @returns {number}
476
- */
477
- countInactiveCells() {
478
- return this.cells.reduce((n, bx) => bx.isInactive() ? ++n : n, 0);
479
- }
480
- }
481
-
482
- Object.assign(BoxBag.prototype, {
483
- /**
484
- * The array of cells
485
- * @name module:boxes/BoxBag.BoxBag#cells
486
- * @type {module:boxes/AbstractBox.AbstractBox[]} */
487
- cells: [],
488
- /**
489
- * Rectangle containing the preferred bounds of the BoxBag
490
- * @name module:boxes/BoxBag.BoxBag#preferredBounds
491
- * @type {module:AWT.Rectangle} */
492
- preferredBounds: new Rectangle(),
493
- /**
494
- * An optional box used as a background by this BoxBag
495
- * @name module:boxes/BoxBag.BoxBag#backgroundBox
496
- * @type {module:boxes/AbstractBox.AbstractBox} */
497
- backgroundBox: null,
498
- });
499
-
500
- export default BoxBag;