jclic 2.1.21 → 2.1.23

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 (175) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/jclic-node.js +9 -8
  3. package/dist/jclic-node.js.map +1 -1
  4. package/dist/jclic.min.js +2 -2
  5. package/dist/jclic.min.js.map +1 -1
  6. package/package.json +4 -4
  7. package/src/GlobalData.js +1 -1
  8. package/src/JClicPlayer.js +2 -2
  9. package/src/bags/MediaBag.js +6 -5
  10. package/dist/1078.jclic-node.js +0 -282
  11. package/dist/1078.jclic-node.js.map +0 -1
  12. package/dist/1196.jclic-node.js +0 -808
  13. package/dist/1196.jclic-node.js.map +0 -1
  14. package/dist/1253.jclic-node.js +0 -1432
  15. package/dist/1253.jclic-node.js.map +0 -1
  16. package/dist/13.jclic-node.js +0 -103
  17. package/dist/13.jclic-node.js.map +0 -1
  18. package/dist/1567.jclic-node.js +0 -2313
  19. package/dist/1567.jclic-node.js.map +0 -1
  20. package/dist/1588.jclic-node.js +0 -602
  21. package/dist/1588.jclic-node.js.map +0 -1
  22. package/dist/1725.jclic-node.js +0 -836
  23. package/dist/1725.jclic-node.js.map +0 -1
  24. package/dist/1731.jclic-node.js +0 -438
  25. package/dist/1731.jclic-node.js.map +0 -1
  26. package/dist/1842.jclic-node.js +0 -651
  27. package/dist/1842.jclic-node.js.map +0 -1
  28. package/dist/2160.jclic-node.js +0 -1016
  29. package/dist/2160.jclic-node.js.map +0 -1
  30. package/dist/222.jclic-node.js +0 -129
  31. package/dist/222.jclic-node.js.map +0 -1
  32. package/dist/2316.jclic-node.js +0 -949
  33. package/dist/2316.jclic-node.js.map +0 -1
  34. package/dist/2355.jclic-node.js +0 -371
  35. package/dist/2355.jclic-node.js.map +0 -1
  36. package/dist/2366.jclic-node.js +0 -431
  37. package/dist/2366.jclic-node.js.map +0 -1
  38. package/dist/2379.jclic-node.js +0 -202
  39. package/dist/2379.jclic-node.js.map +0 -1
  40. package/dist/2437.jclic-node.js +0 -450
  41. package/dist/2437.jclic-node.js.map +0 -1
  42. package/dist/2531.jclic-node.js +0 -869
  43. package/dist/2531.jclic-node.js.map +0 -1
  44. package/dist/2608.jclic-node.js +0 -160
  45. package/dist/2608.jclic-node.js.map +0 -1
  46. package/dist/2715.jclic-node.js +0 -554
  47. package/dist/2715.jclic-node.js.map +0 -1
  48. package/dist/277.jclic-node.js +0 -22
  49. package/dist/277.jclic-node.js.map +0 -1
  50. package/dist/2921.jclic-node.js +0 -660
  51. package/dist/2921.jclic-node.js.map +0 -1
  52. package/dist/2952.jclic-node.js +0 -101
  53. package/dist/2952.jclic-node.js.map +0 -1
  54. package/dist/3018.jclic-node.js +0 -421
  55. package/dist/3018.jclic-node.js.map +0 -1
  56. package/dist/3019.jclic-node.js +0 -682
  57. package/dist/3019.jclic-node.js.map +0 -1
  58. package/dist/3231.jclic-node.js +0 -274
  59. package/dist/3231.jclic-node.js.map +0 -1
  60. package/dist/331.jclic-node.js +0 -115
  61. package/dist/331.jclic-node.js.map +0 -1
  62. package/dist/3391.jclic-node.js +0 -276
  63. package/dist/3391.jclic-node.js.map +0 -1
  64. package/dist/3502.jclic-node.js +0 -671
  65. package/dist/3502.jclic-node.js.map +0 -1
  66. package/dist/3653.jclic-node.js +0 -982
  67. package/dist/3653.jclic-node.js.map +0 -1
  68. package/dist/371.jclic.min.js +0 -2
  69. package/dist/371.jclic.min.js.map +0 -1
  70. package/dist/3856.jclic-node.js +0 -575
  71. package/dist/3856.jclic-node.js.map +0 -1
  72. package/dist/4112.jclic-node.js +0 -659
  73. package/dist/4112.jclic-node.js.map +0 -1
  74. package/dist/4123.jclic-node.js +0 -910
  75. package/dist/4123.jclic-node.js.map +0 -1
  76. package/dist/427.jclic-node.js +0 -894
  77. package/dist/427.jclic-node.js.map +0 -1
  78. package/dist/4483.jclic-node.js +0 -327
  79. package/dist/4483.jclic-node.js.map +0 -1
  80. package/dist/4548.jclic-node.js +0 -1078
  81. package/dist/4548.jclic-node.js.map +0 -1
  82. package/dist/466.jclic-node.js +0 -99
  83. package/dist/466.jclic-node.js.map +0 -1
  84. package/dist/485.jclic-node.js +0 -783
  85. package/dist/485.jclic-node.js.map +0 -1
  86. package/dist/4921.jclic-node.js +0 -500
  87. package/dist/4921.jclic-node.js.map +0 -1
  88. package/dist/5091.jclic-node.js +0 -239
  89. package/dist/5091.jclic-node.js.map +0 -1
  90. package/dist/520.jclic-node.js +0 -550
  91. package/dist/520.jclic-node.js.map +0 -1
  92. package/dist/5312.jclic-node.js +0 -1126
  93. package/dist/5312.jclic-node.js.map +0 -1
  94. package/dist/5338.jclic-node.js +0 -212
  95. package/dist/5338.jclic-node.js.map +0 -1
  96. package/dist/5344.jclic-node.js +0 -229
  97. package/dist/5344.jclic-node.js.map +0 -1
  98. package/dist/5550.jclic-node.js +0 -238
  99. package/dist/5550.jclic-node.js.map +0 -1
  100. package/dist/5626.jclic-node.js +0 -614
  101. package/dist/5626.jclic-node.js.map +0 -1
  102. package/dist/5977.jclic-node.js +0 -1081
  103. package/dist/5977.jclic-node.js.map +0 -1
  104. package/dist/6148.jclic-node.js +0 -345
  105. package/dist/6148.jclic-node.js.map +0 -1
  106. package/dist/6176.jclic-node.js +0 -481
  107. package/dist/6176.jclic-node.js.map +0 -1
  108. package/dist/6221.jclic-node.js +0 -1072
  109. package/dist/6221.jclic-node.js.map +0 -1
  110. package/dist/6238.jclic-node.js +0 -718
  111. package/dist/6238.jclic-node.js.map +0 -1
  112. package/dist/6454.jclic-node.js +0 -1413
  113. package/dist/6454.jclic-node.js.map +0 -1
  114. package/dist/6565.jclic-node.js +0 -294
  115. package/dist/6565.jclic-node.js.map +0 -1
  116. package/dist/6579.jclic-node.js +0 -719
  117. package/dist/6579.jclic-node.js.map +0 -1
  118. package/dist/6715.jclic-node.js +0 -148
  119. package/dist/6715.jclic-node.js.map +0 -1
  120. package/dist/6777.jclic-node.js +0 -171
  121. package/dist/6777.jclic-node.js.map +0 -1
  122. package/dist/6782.jclic-node.js +0 -1611
  123. package/dist/6782.jclic-node.js.map +0 -1
  124. package/dist/6847.jclic-node.js +0 -601
  125. package/dist/6847.jclic-node.js.map +0 -1
  126. package/dist/6856.jclic-node.js +0 -252
  127. package/dist/6856.jclic-node.js.map +0 -1
  128. package/dist/696.jclic-node.js +0 -1821
  129. package/dist/696.jclic-node.js.map +0 -1
  130. package/dist/698.jclic-node.js +0 -583
  131. package/dist/698.jclic-node.js.map +0 -1
  132. package/dist/704.jclic-node.js +0 -80
  133. package/dist/704.jclic-node.js.map +0 -1
  134. package/dist/7046.jclic-node.js +0 -735
  135. package/dist/7046.jclic-node.js.map +0 -1
  136. package/dist/7220.jclic-node.js +0 -156
  137. package/dist/7220.jclic-node.js.map +0 -1
  138. package/dist/7257.jclic-node.js +0 -931
  139. package/dist/7257.jclic-node.js.map +0 -1
  140. package/dist/743.jclic-node.js +0 -583
  141. package/dist/743.jclic-node.js.map +0 -1
  142. package/dist/757.jclic-node.js +0 -1072
  143. package/dist/757.jclic-node.js.map +0 -1
  144. package/dist/7781.jclic-node.js +0 -202
  145. package/dist/7781.jclic-node.js.map +0 -1
  146. package/dist/7912.jclic-node.js +0 -2103
  147. package/dist/7912.jclic-node.js.map +0 -1
  148. package/dist/827.jclic-node.js +0 -708
  149. package/dist/827.jclic-node.js.map +0 -1
  150. package/dist/8276.jclic-node.js +0 -409
  151. package/dist/8276.jclic-node.js.map +0 -1
  152. package/dist/8322.jclic-node.js +0 -498
  153. package/dist/8322.jclic-node.js.map +0 -1
  154. package/dist/8641.jclic-node.js +0 -360
  155. package/dist/8641.jclic-node.js.map +0 -1
  156. package/dist/8837.jclic-node.js +0 -651
  157. package/dist/8837.jclic-node.js.map +0 -1
  158. package/dist/8895.jclic-node.js +0 -151
  159. package/dist/8895.jclic-node.js.map +0 -1
  160. package/dist/9072.jclic-node.js +0 -1285
  161. package/dist/9072.jclic-node.js.map +0 -1
  162. package/dist/9078.jclic-node.js +0 -935
  163. package/dist/9078.jclic-node.js.map +0 -1
  164. package/dist/9103.jclic-node.js +0 -718
  165. package/dist/9103.jclic-node.js.map +0 -1
  166. package/dist/9359.jclic-node.js +0 -145
  167. package/dist/9359.jclic-node.js.map +0 -1
  168. package/dist/9409.jclic-node.js +0 -921
  169. package/dist/9409.jclic-node.js.map +0 -1
  170. package/dist/9513.jclic-node.js +0 -720
  171. package/dist/9513.jclic-node.js.map +0 -1
  172. package/dist/9704.jclic-node.js +0 -81
  173. package/dist/9704.jclic-node.js.map +0 -1
  174. package/dist/9950.jclic-node.js +0 -827
  175. package/dist/9950.jclic-node.js.map +0 -1
@@ -1,583 +0,0 @@
1
- "use strict";
2
- exports.id = 698;
3
- exports.ids = [698,8276];
4
- exports.modules = {
5
-
6
- /***/ 698:
7
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
8
-
9
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
10
- /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
11
- /* harmony export */ });
12
- /* unused harmony export JigSaw */
13
- /* harmony import */ var _Shaper_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8276);
14
- /* harmony import */ var _AWT_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(7912);
15
- /**
16
- * File : shapers/JigSaw.js
17
- * Created : 01/04/2015
18
- * By : Francesc Busquets <francesc@gmail.com>
19
- *
20
- * JClic.js
21
- * An HTML5 player of JClic activities
22
- * https://projectestac.github.io/jclic.js
23
- *
24
- * @source https://github.com/projectestac/jclic.js
25
- *
26
- * @license EUPL-1.2
27
- * @licstart
28
- * (c) 2000-2020 Educational Telematic Network of Catalonia (XTEC)
29
- *
30
- * Licensed under the EUPL, Version 1.1 or -as soon they will be approved by
31
- * the European Commission- subsequent versions of the EUPL (the "Licence");
32
- * You may not use this work except in compliance with the Licence.
33
- *
34
- * You may obtain a copy of the Licence at:
35
- * https://joinup.ec.europa.eu/software/page/eupl
36
- *
37
- * Unless required by applicable law or agreed to in writing, software
38
- * distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
39
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
40
- * Licence for the specific language governing permissions and limitations
41
- * under the Licence.
42
- * @licend
43
- * @module
44
- */
45
-
46
-
47
-
48
-
49
- /**
50
- *
51
- * This {@link module:shapers/Shaper.Shaper Shaper} returns a set of rectangular shapes with teeth and slots that fit between them.
52
- * @extends module:shapers/Shaper.Shaper
53
- */
54
- class JigSaw extends _Shaper_js__WEBPACK_IMPORTED_MODULE_0__["default"] {
55
- /**
56
- * JigSaw constructor
57
- * @param {number} nx - Number of columns
58
- * @param {number} ny - Number of rows
59
- */
60
- constructor(nx, ny) {
61
- super(nx, ny);
62
- }
63
-
64
- /**
65
- * Builds the jigsaw shapes based on the number of rows and columns
66
- * @override
67
- */
68
- buildShapes() {
69
- // Create two two-dimension arrays for storing the type of horizontal and vertical lines
70
- let hLineType = [], vLineType = [];
71
- for (let i = 0; i <= this.nRows; i++) {
72
- hLineType[i] = [];
73
- vLineType[i] = [];
74
- }
75
-
76
- for (let row = 0; row < this.nRows; row++) {
77
- for (let col = 0; col < this.nCols; col++) {
78
- hLineType[row][col] = row === 0 ? 0 : 1 + (this.randomLines ? Math.round(Math.random() * 9) : row + col) % 2;
79
- vLineType[row][col] = col === 0 ? 0 : 1 + (this.randomLines ? Math.round(Math.random() * 9) : col + row + 1) % 2;
80
- if (col === this.nCols - 1)
81
- vLineType[row][col + 1] = 0;
82
- if (row === this.nRows - 1)
83
- hLineType[row + 1][col] = 0;
84
- }
85
- }
86
-
87
- const w = 1 / this.nCols, h = 1 / this.nRows;
88
- for (let r = 0; r < this.nRows; r++) {
89
- for (let c = 0; c < this.nCols; c++) {
90
- const x = w * c;
91
- const y = h * r;
92
- const sd = new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .Path */ .wA([new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .PathStroke */ .kg('M', [x, y])]);
93
- this.hLine(sd, hLineType[r][c], x + 0, y + 0, w, h, false);
94
- this.vLine(sd, vLineType[r][c + 1], x + w, y + 0, w, h, false);
95
- this.hLine(sd, hLineType[r + 1][c], x + w, y + h, w, h, true);
96
- this.vLine(sd, vLineType[r][c], x + 0, y + h, w, h, true);
97
- sd.addStroke(new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .PathStroke */ .kg('X'));
98
- sd.calcEnclosingRect();
99
- // Save the Path in `shapeData`
100
- this.shapeData[r * this.nCols + c] = sd;
101
- }
102
- }
103
- this.initiated = true;
104
- }
105
-
106
- /**
107
- * Adds an horizontal line to the provided path
108
- * @param {module:AWT.Path} sd - The Path to which the line will be added
109
- * @param {number} type - Type of tooth: 0 is flat (no tooth), 1 means tooth up, and 2 means tooth down
110
- * @param {number} x - X coordinate of the starting point
111
- * @param {number} y - Y coordinate of the starting point
112
- * @param {number} w - Width of the piece
113
- * @param {number} h - Height of the piece
114
- * @param {boolean} inv - The line must be drawn right to left
115
- */
116
- hLine(sd, type, x, y, w, h, inv) {
117
- const
118
- kx = inv ? -1 : 1,
119
- ky = type === 1 ? 1 : -1;
120
-
121
- if (type === 0)
122
- // Flat line
123
- sd.addStroke(new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .PathStroke */ .kg('L', [x + w * kx, y]));
124
- else {
125
- const x0 = x + (w - w * this.baseWidthFactor) / 2 * kx;
126
- const wb = w * this.baseWidthFactor * kx;
127
- // Approximation to the tooth:
128
- sd.addStroke(new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .PathStroke */ .kg('L', [x0, y]));
129
- // The tooth:
130
- const hb = h * this.toothHeightFactor * ky;
131
- sd.addStroke(new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .PathStroke */ .kg('L', [x0, y + hb]));
132
- sd.addStroke(new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .PathStroke */ .kg('L', [x0 + wb, y + hb]));
133
- sd.addStroke(new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .PathStroke */ .kg('L', [x0 + wb, y]));
134
- // Draw the remaining of the line
135
- sd.addStroke(new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .PathStroke */ .kg('L', [x + w * kx, y]));
136
- }
137
- }
138
-
139
- /**
140
- *
141
- * Adds a vertical line to the provided path
142
- * @param {module:AWT.Path} sd - The Path to which the line will be added
143
- * @param {number} type - Type of tooth: 0 is flat (no tooth), 1 means tooth right, and 2 means tooth left
144
- * @param {number} x - X coordinate of the starting point
145
- * @param {number} y - Y coordinate of the starting point
146
- * @param {number} w - Width of the piece
147
- * @param {number} h - Height of the piece
148
- * @param {boolean} inv - The line must be drawn bottom to top
149
- */
150
- vLine(sd, type, x, y, w, h, inv) {
151
- const
152
- ky = inv ? -1 : 1,
153
- kx = type === 1 ? 1 : -1;
154
-
155
- if (type === 0) {
156
- // Flat line
157
- sd.addStroke(new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .PathStroke */ .kg('L', [x, y + h * ky]));
158
- } else {
159
- const y0 = y + (h - h * this.baseWidthFactor) / 2 * ky;
160
- const hb = h * this.baseWidthFactor * ky;
161
- // Approximation to the tooth:
162
- sd.addStroke(new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .PathStroke */ .kg('L', [x, y0]));
163
- // The tooth:
164
- const wb = w * this.toothHeightFactor * kx;
165
- sd.addStroke(new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .PathStroke */ .kg('L', [x + wb, y0]));
166
- sd.addStroke(new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .PathStroke */ .kg('L', [x + wb, y0 + hb]));
167
- sd.addStroke(new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .PathStroke */ .kg('L', [x, y0 + hb]));
168
- // Draw the remaining line
169
- sd.addStroke(new _AWT_js__WEBPACK_IMPORTED_MODULE_1__/* .PathStroke */ .kg('L', [x, y + h * ky]));
170
- }
171
- }
172
- }
173
-
174
- // Register this class in the list of known shapers
175
- /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_Shaper_js__WEBPACK_IMPORTED_MODULE_0__["default"].registerClass('@JigSaw', JigSaw));
176
-
177
-
178
- /***/ }),
179
-
180
- /***/ 8276:
181
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
182
-
183
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
184
- /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
185
- /* harmony export */ });
186
- /* unused harmony export Shaper */
187
- /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7750);
188
- /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
189
- /* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1253);
190
- /* harmony import */ var _AWT_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(7912);
191
- /**
192
- * File : shapers/Shaper.js
193
- * Created : 13/04/2015
194
- * By : Francesc Busquets <francesc@gmail.com>
195
- *
196
- * JClic.js
197
- * An HTML5 player of JClic activities
198
- * https://projectestac.github.io/jclic.js
199
- *
200
- * @source https://github.com/projectestac/jclic.js
201
- *
202
- * @license EUPL-1.2
203
- * @licstart
204
- * (c) 2000-2020 Educational Telematic Network of Catalonia (XTEC)
205
- *
206
- * Licensed under the EUPL, Version 1.1 or -as soon they will be approved by
207
- * the European Commission- subsequent versions of the EUPL (the "Licence");
208
- * You may not use this work except in compliance with the Licence.
209
- *
210
- * You may obtain a copy of the Licence at:
211
- * https://joinup.ec.europa.eu/software/page/eupl
212
- *
213
- * Unless required by applicable law or agreed to in writing, software
214
- * distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
215
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
216
- * Licence for the specific language governing permissions and limitations
217
- * under the Licence.
218
- * @licend
219
- * @module
220
- */
221
-
222
-
223
-
224
-
225
-
226
- /**
227
- * The function of this class and its subclasses is to draw a set of "shapes" that will be used to
228
- * place {@link module:boxes/ActiveBox.ActiveBox ActiveBox} objects at a specific position, and to determine its dimension and
229
- * appearance.
230
- */
231
- class Shaper {
232
- /**
233
- * Shaper constructor
234
- * @param {number} nx - Number of columns (in grid-based shapers)
235
- * @param {number} ny - Number of rows (in grid-based shapers)
236
- */
237
- constructor(nx, ny) {
238
- this.reset(nx, ny);
239
- }
240
-
241
- /**
242
- * Registers a new type of shaper
243
- * @param {string} shaperName - The name used to identify this shaper
244
- * @param {function} shaperClass - The shaper class, usually extending Shaper
245
- * @returns {module:shapers/Shaper.Shaper} - The provided shaper class
246
- */
247
- static registerClass(shaperName, shaperClass) {
248
- Shaper.CLASSES[shaperName] = shaperClass;
249
- return shaperClass;
250
- }
251
-
252
- /**
253
- * Factory constructor that returns a Shaper of the requested class.
254
- * @param {string} className - The class name of the requested Shaper.
255
- * @param {number} nx - Number of columns (in grid-based shapers)
256
- * @param {number} ny - Number of rows (in grid-based shapers)
257
- * @returns {module:shapers/Shaper.Shaper}
258
- */
259
- static getShaper(className, nx, ny) {
260
- const cl = Shaper.CLASSES[(className || '').replace(/^edu\.xtec\.jclic\.shapers\./, '@')];
261
- if (!cl)
262
- (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__/* .log */ .Rm)('error', `Unknown shaper: ${className}`);
263
- return cl ? new cl(nx, ny) : null;
264
- }
265
-
266
- /**
267
- * Initializes this Shaper to default values
268
- * @param {number} nCols - Number of columns
269
- * @param {number} nRows - Number of rows
270
- */
271
- reset(nCols, nRows) {
272
- this.nCols = nCols;
273
- this.nRows = nRows;
274
- this.nCells = nRows * nCols;
275
- this.initiated = false;
276
- this.shapeData = [];
277
- for (let i = 0; i < this.nCells; i++)
278
- this.shapeData[i] = new _AWT_js__WEBPACK_IMPORTED_MODULE_2__/* .Shape */ .yp();
279
- }
280
-
281
- /**
282
- * Loads this shaper settings from a specific JQuery XML element
283
- * @param {external:jQuery} $xml - The XML element with the shaper data
284
- */
285
- setProperties($xml) {
286
- (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__/* .attrForEach */ .GM)($xml.get(0).attributes, (name, value) => {
287
- switch (name) {
288
- case 'class':
289
- this.className = value;
290
- break;
291
- case 'cols':
292
- this.nCols = Number(value);
293
- break;
294
- case 'rows':
295
- this.nRows = Number(value);
296
- break;
297
- case 'baseWidthFactor':
298
- case 'toothHeightFactor':
299
- case 'scaleX':
300
- case 'scaleY':
301
- this[name] = Number(value);
302
- break;
303
- case 'randomLines':
304
- case 'showEnclosure':
305
- this[name] = (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__/* .getBoolean */ .pW)(value, true);
306
- break;
307
- }
308
- });
309
-
310
- // Reads the 'enclosing'
311
- // (main shape area where the other shape elements are placed)
312
- $xml.children('enclosing:first').each((_n, child) => {
313
- jquery__WEBPACK_IMPORTED_MODULE_0___default()(child).children('shape:first').each((_n, child2) => {
314
- let sh = Shaper.readShapeData(child2, this.scaleX, this.scaleY);
315
- this.enclosing = sh;
316
- this.showEnclosure = true;
317
- this.hasRemainder = true;
318
- });
319
- });
320
-
321
- // Read the shape elements
322
- $xml.children('shape').each((n, child) => {
323
- this.shapeData[n] = Shaper.readShapeData(child, this.scaleX, this.scaleY);
324
- });
325
-
326
- // Correction needed for '@Holes' shaper
327
- if (this.shapeData.length > 0 /* && this.shapeData.length !== this.nRows * this.nCols */) {
328
- //this.nRows = this.shapeData.length
329
- //this.nCols = 1
330
- //this.nCells = this.nCols * this.nRows
331
- this.nCells = this.shapeData.length;
332
- }
333
- return this;
334
- }
335
-
336
- /**
337
- * Reads an individual shape from an XML element.
338
- * Shapes are arrays of `stroke` objects.
339
- * Each `stroke` has an `action` (_move to_, _line to_, _quad to_...) and associated `data`.
340
- * @param {external:jQuery} $xml - The XML element with the shape data
341
- * @param {number} scaleX
342
- * @param {number} scaleY
343
- * @returns {module:AWT.Shape}
344
- */
345
- static readShapeData(xml, scaleX, scaleY) {
346
- const shd = [];
347
- let result = null;
348
- jquery__WEBPACK_IMPORTED_MODULE_0___default().each(xml.textContent.split('|'), (_n, txt) => {
349
- const sd = txt.split(':');
350
- // Possible strokes are: `rectangle`, `ellipse`, `M`, `L`, `Q`, `B`, `X`
351
- // Also possible, but not currently used in JClic: `roundRectangle` and `pie`
352
- let data = sd.length > 1 ? sd[1].split(',') : null;
353
- //
354
- // Data should be always divided by the scale (X or Y)
355
- if (data)
356
- data = data.map((d, n) => d / (n % 2 ? scaleY : scaleX));
357
-
358
- switch (sd[0]) {
359
- case 'rectangle':
360
- result = new _AWT_js__WEBPACK_IMPORTED_MODULE_2__/* .Rectangle */ .M_(data[0], data[1], data[2], data[3]);
361
- break;
362
- case 'ellipse':
363
- result = new _AWT_js__WEBPACK_IMPORTED_MODULE_2__/* .Ellipse */ .Pp(data[0], data[1], data[2], data[3]);
364
- break;
365
- default:
366
- // It's an `AWT.PathStroke`
367
- shd.push(new _AWT_js__WEBPACK_IMPORTED_MODULE_2__/* .PathStroke */ .kg(sd[0], data));
368
- break;
369
- }
370
- });
371
-
372
- return !result && shd.length > 0 ? new _AWT_js__WEBPACK_IMPORTED_MODULE_2__/* .Path */ .wA(shd) : result;
373
- }
374
-
375
- /**
376
- * Gets a object with the basic attributes needed to rebuild this instance excluding functions,
377
- * parent references, constants and also attributes retaining the default value.
378
- * The resulting object is commonly usued to serialize elements in JSON format.
379
- * @returns {object} - The resulting object, with minimal attrributes
380
- */
381
- getAttributes() {
382
- const fields = [
383
- 'className', 'nCols', 'nRows',
384
- 'baseWidthFactor', 'toothHeightFactor',
385
- 'scaleX', 'scaleY',
386
- 'randomLines',
387
- ];
388
-
389
- if (this.customShapes) {
390
- ['showEnclosure', 'hasRemainder',
391
- 'enclosing', 'shapeData', // Array of AWT.Rectangle, AWT.Ellipse or (AWT.Path -> AWT.PathStroke)
392
- ].forEach(f => fields.push(f));
393
- }
394
-
395
- return (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__/* .getAttr */ .iu)(this, fields);
396
- }
397
-
398
- /**
399
- * Builds a new shaper, based on the properties specified in a data object
400
- * @param {object} data - The data object to be parsed
401
- * @returns {module:shapers/Shaper.Shaper}
402
- */
403
- static factory(data) {
404
- const result = Shaper.getShaper(data.className, data.nCols, data.nRows);
405
- (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__/* .setAttr */ .ob)(result, data, [
406
- 'className', 'nCols', 'nRows',
407
- 'baseWidthFactor', 'toothHeightFactor',
408
- 'scaleX', 'scaleY',
409
- 'randomLines',
410
- 'showEnclosure', 'hasRemainder',
411
- { key: 'enclosing', fn: _AWT_js__WEBPACK_IMPORTED_MODULE_2__/* .Shape */ .yp },
412
- { key: 'shapeData', fn: _AWT_js__WEBPACK_IMPORTED_MODULE_2__/* .Shape */ .yp, group: 'array' },
413
- ]);
414
-
415
- result.nCells = result.shapeData.length || result.nCols * result.nRows;
416
-
417
- return result;
418
- }
419
-
420
- /**
421
- * Builds the individual shapes that will form this Shaper
422
- */
423
- buildShapes() {
424
- }
425
-
426
- /**
427
- * Gets a clone of the nth Shape object, scaled and located inside a Rectangle
428
- * @param {number} n
429
- * @param {module:AWT.Rectangle} rect
430
- * @returns {module:AWT.Shape}
431
- */
432
- getShape(n, rect) {
433
- if (!this.initiated)
434
- this.buildShapes();
435
- if (n >= this.nCells || this.shapeData[n] === null)
436
- return null;
437
- return this.shapeData[n].getShape(rect);
438
- }
439
-
440
- /**
441
- * Gets the nth Shape data object
442
- * @param {number} n
443
- * @returns {object}
444
- */
445
- getShapeData(n) {
446
- return n >= 0 && n < this.shapeData.length ? this.shapeData[n] : null;
447
- }
448
-
449
- /**
450
- * Gets the AWT.Rectangle that contains all shapes of this Shaper.
451
- * @returns {module:AWT.Rectangle}
452
- */
453
- getEnclosingShapeData() {
454
- return new _AWT_js__WEBPACK_IMPORTED_MODULE_2__/* .Rectangle */ .M_(0, 0, 1, 1);
455
- }
456
-
457
- /**
458
- * When `hasRemainder` is true, this method gets the rectangle containing the full surface where
459
- * the Shaper develops.
460
- * @param {module:AWT.Rectangle} rect - The frame where to move and scale all the shapes
461
- * @returns {module:AWT.Rectangle}
462
- */
463
- getRemainderShape(rect) {
464
- if (!this.hasRemainder)
465
- return null;
466
-
467
- if (!this.initiated)
468
- this.buildShapes();
469
-
470
- const sh = this.getEnclosingShapeData();
471
- const r = sh ? sh.getShape(rect) : new _AWT_js__WEBPACK_IMPORTED_MODULE_2__/* .Rectangle */ .M_();
472
- for (let i = 0; i < this.nCells; i++) {
473
- if (this.shapeData[i])
474
- r.add(this.shapeData[i].getShape(rect), false);
475
- }
476
- return r;
477
- }
478
- }
479
-
480
- Object.assign(Shaper.prototype, {
481
- /**
482
- * This shaper class name
483
- * @name module:shapers/Shaper.Shaper#className
484
- * @type {string} */
485
- className: 'Shaper',
486
- /**
487
- * Number of columns (useful in grid-based shapers)
488
- * @name module:shapers/Shaper.Shaper#nCols
489
- * @type {number} */
490
- nCols: 0,
491
- /**
492
- * Number of rows (useful in grid-based shapers)
493
- * @name module:shapers/Shaper.Shaper#nRows
494
- * @type {number} */
495
- nRows: 0,
496
- /**
497
- * Number of cells managed by this shaper
498
- * @name module:shapers/Shaper.Shaper#nCells
499
- * @type {number} */
500
- nCells: 0,
501
- /**
502
- * Contains the specific definition of each shape
503
- * @name module:shapers/Shaper.Shaper#shapeData
504
- * @type {object} */
505
- shapeData: null,
506
- /**
507
- * Flag used to check if the `Shaper` has been initialized against a real surface
508
- * @name module:shapers/Shaper.Shaper#initiated
509
- * @type {boolean} */
510
- initiated: false,
511
- //
512
- // Fields used only in JigSaw shapers
513
- /**
514
- * In {@link module:shapers/JigSaw.JigSaw JigSaw}, ratio between the base width of the tooth and the total length of the side.
515
- * @name module:shapers/Shaper.Shaper#baseWidthFactor
516
- * @type {number} */
517
- baseWidthFactor: 1.0 / 3,
518
- /**
519
- * In {@link module:shapers/JigSaw.JigSaw JigSaw}, ratio between the tooth height and the total length of the side.
520
- * @name module:shapers/Shaper.Shaper#toothHeightFactor
521
- * @type {number} */
522
- toothHeightFactor: 1.0 / 6,
523
- /**
524
- * In {@link module:shapers/JigSaw.JigSaw JigSaw}, whether the tooths take random directions or not
525
- * @name module:shapers/Shaper.Shaper#randomLines
526
- * @type {boolean} */
527
- randomLines: false,
528
- //
529
- // Fields used only in the `Holes` shaper
530
- /**
531
- * In {@link module:shapers/Holes.Holes Holes}, scale to be applied to horizontal positions and lengths to achieve the real
532
- * value of the shape placed on a real surface.
533
- * @name module:shapers/Shaper.Shaper#scaleX
534
- * @type {number} */
535
- scaleX: 1.0,
536
- /**
537
- * In {@link module:shapers/Holes.Holes Holes}, scale to be applied to vertical positions and lengths to achieve the real
538
- * value of the shape placed on a real surface.
539
- * @name module:shapers/Shaper.Shaper#scaleY
540
- * @type {number} */
541
- scaleY: 1.0,
542
- /**
543
- * In {@link module:shapers/Holes.Holes Holes}, the enclosing area where all shapes are placed.
544
- * @name module:shapers/Shaper.Shaper#enclosing
545
- * @type {module:AWT.Shape} */
546
- enclosing: null,
547
- /**
548
- * In {@link module:shapers/Holes.Holes Holes}, when `true`, the enclosing area will be drawn
549
- * @name module:shapers/Shaper.Shaper#showEnclosure
550
- * @type {boolean} */
551
- showEnclosure: false,
552
- /**
553
- * Flag indicating if this shaper organizes its cells in rows and columns
554
- * @name module:shapers/Shaper.Shaper#rectangularShapes
555
- * @type {boolean} */
556
- rectangularShapes: false,
557
- /**
558
- * Flag indicating if this Shaper deploys over a surface biggest than the rectangle enclosing
559
- * all its shapes
560
- * @name module:shapers/Shaper.Shaper#hasRemainder
561
- * @type {boolean} */
562
- hasRemainder: false,
563
- /**
564
- * Only the `Holes` shaper has this flag activated
565
- * @name module:shapers/Shaper.Shaper#customShapes
566
- * @type {boolean} */
567
- customShapes: false,
568
- });
569
-
570
- /**
571
- * List of known classes derived from Shaper. It should be filled by real shaper classes at
572
- * declaration time.
573
- * @type {object} */
574
- Shaper.CLASSES = {};
575
-
576
- /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Shaper);
577
-
578
-
579
- /***/ })
580
-
581
- };
582
- ;
583
- //# sourceMappingURL=698.jclic-node.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"698.jclic-node.js","mappings":";;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEiC;AACY;;AAE7C;AACA;AACA,SAAS,2CAA2C;AACpD;AACA;AACO,qBAAqB,kDAAM;AAClC;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,iBAAiB;AACrC;AACA;AACA;;AAEA,sBAAsB,kBAAkB;AACxC,wBAAwB,kBAAkB;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,oBAAoB,gBAAgB;AACpC,sBAAsB,gBAAgB;AACtC;AACA;AACA,uBAAuB,mDAAI,MAAM,yDAAU;AAC3C;AACA;AACA;AACA;AACA,yBAAyB,yDAAU;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,iBAAiB;AAC9B,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,aAAa,SAAS;AACtB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,uBAAuB,yDAAU;AACjC;AACA;AACA;AACA;AACA,uBAAuB,yDAAU;AACjC;AACA;AACA,uBAAuB,yDAAU;AACjC,uBAAuB,yDAAU;AACjC,uBAAuB,yDAAU;AACjC;AACA,uBAAuB,yDAAU;AACjC;AACA;;AAEA;AACA;AACA;AACA,aAAa,iBAAiB;AAC9B,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,aAAa,SAAS;AACtB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,uBAAuB,yDAAU;AACjC,MAAM;AACN;AACA;AACA;AACA,uBAAuB,yDAAU;AACjC;AACA;AACA,uBAAuB,yDAAU;AACjC,uBAAuB,yDAAU;AACjC,uBAAuB,yDAAU;AACjC;AACA,uBAAuB,yDAAU;AACjC;AACA;AACA;;AAEA;AACA,iEAAe,kDAAM,iCAAiC,EAAC;;;;;;;;;;;;;;;;AChKvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEuB;AACsD;AACL;;AAExE;AACA;AACA,UAAU,kDAAkD;AAC5D;AACA;AACO;AACP;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,UAAU;AACvB,eAAe,8BAA8B;AAC7C;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,eAAe;AACf;AACA;AACA;AACA;AACA,MAAM,wDAAG,6BAA6B,UAAU;AAChD;AACA;;AAEA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,iBAAiB;AACrC,8BAA8B,oDAAK;AACnC;;AAEA;AACA;AACA,aAAa,iBAAiB;AAC9B;AACA;AACA,IAAI,gEAAW;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uBAAuB,+DAAU;AACjC;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA,MAAM,6CAAC;AACP;AACA;AACA;AACA;AACA,OAAO;AACP,KAAK;;AAEL;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,aAAa,iBAAiB;AAC9B,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,eAAe;AACf;AACA;AACA;AACA;AACA,IAAI,kDAAM;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,uBAAuB,wDAAS;AAChC;AACA;AACA,uBAAuB,sDAAO;AAC9B;AACA;AACA;AACA,uBAAuB,yDAAU;AACjC;AACA;AACA,KAAK;;AAEL,2CAA2C,mDAAI;AAC/C;;AAEA;AACA;AACA;AACA;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,WAAW,4DAAO;AAClB;;AAEA;AACA;AACA,aAAa,QAAQ;AACrB,eAAe;AACf;AACA;AACA;AACA,IAAI,4DAAO;AACX;AACA;AACA;AACA;AACA;AACA,QAAQ,sBAAsB,oDAAK,EAAE;AACrC,QAAQ,sBAAsB,oDAAK,kBAAkB;AACrD;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,sBAAsB;AACnC,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,QAAQ;AACrB,eAAe;AACf;AACA;AACA;AACA;;AAEA;AACA;AACA,eAAe;AACf;AACA;AACA,eAAe,wDAAS;AACxB;;AAEA;AACA;AACA;AACA,aAAa,sBAAsB;AACnC,eAAe;AACf;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA,2CAA2C,wDAAS;AACpD,oBAAoB,iBAAiB;AACrC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,YAAY,QAAQ;AACpB;AACA;AACA;AACA;AACA,YAAY,QAAQ;AACpB;AACA;AACA;AACA;AACA,YAAY,QAAQ;AACpB;AACA;AACA;AACA;AACA,YAAY,QAAQ;AACpB;AACA;AACA;AACA;AACA,YAAY,QAAQ;AACpB;AACA;AACA;AACA;AACA,YAAY,SAAS;AACrB;AACA;AACA;AACA;AACA,SAAS,0CAA0C;AACnD;AACA,YAAY,QAAQ;AACpB;AACA;AACA,SAAS,0CAA0C;AACnD;AACA,YAAY,QAAQ;AACpB;AACA;AACA,SAAS,0CAA0C;AACnD;AACA,YAAY,SAAS;AACrB;AACA;AACA;AACA;AACA,SAAS,uCAAuC;AAChD;AACA;AACA,YAAY,QAAQ;AACpB;AACA;AACA,SAAS,uCAAuC;AAChD;AACA;AACA,YAAY,QAAQ;AACpB;AACA;AACA,SAAS,uCAAuC;AAChD;AACA,YAAY,kBAAkB;AAC9B;AACA;AACA,SAAS,uCAAuC;AAChD;AACA,YAAY,SAAS;AACrB;AACA;AACA;AACA;AACA,YAAY,SAAS;AACrB;AACA;AACA;AACA;AACA;AACA,YAAY,SAAS;AACrB;AACA;AACA;AACA;AACA,YAAY,SAAS;AACrB;AACA,CAAC;;AAED;AACA;AACA;AACA,UAAU,QAAQ;AAClB;;AAEA,iEAAe,MAAM,EAAC","sources":["webpack://jclic/./src/shapers/JigSaw.js","webpack://jclic/./src/shapers/Shaper.js"],"sourcesContent":["/**\n * File : shapers/JigSaw.js\n * Created : 01/04/2015\n * By : Francesc Busquets <francesc@gmail.com>\n *\n * JClic.js\n * An HTML5 player of JClic activities\n * https://projectestac.github.io/jclic.js\n *\n * @source https://github.com/projectestac/jclic.js\n *\n * @license EUPL-1.2\n * @licstart\n * (c) 2000-2020 Educational Telematic Network of Catalonia (XTEC)\n *\n * Licensed under the EUPL, Version 1.1 or -as soon they will be approved by\n * the European Commission- subsequent versions of the EUPL (the \"Licence\");\n * You may not use this work except in compliance with the Licence.\n *\n * You may obtain a copy of the Licence at:\n * https://joinup.ec.europa.eu/software/page/eupl\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the Licence is distributed on an \"AS IS\" basis, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * Licence for the specific language governing permissions and limitations\n * under the Licence.\n * @licend\n * @module\n */\n\nimport Shaper from './Shaper.js';\nimport { Path, PathStroke } from '../AWT.js';\n\n/**\n *\n * This {@link module:shapers/Shaper.Shaper Shaper} returns a set of rectangular shapes with teeth and slots that fit between them.\n * @extends module:shapers/Shaper.Shaper\n */\nexport class JigSaw extends Shaper {\n /**\n * JigSaw constructor\n * @param {number} nx - Number of columns\n * @param {number} ny - Number of rows\n */\n constructor(nx, ny) {\n super(nx, ny);\n }\n\n /**\n * Builds the jigsaw shapes based on the number of rows and columns\n * @override\n */\n buildShapes() {\n // Create two two-dimension arrays for storing the type of horizontal and vertical lines\n let hLineType = [], vLineType = [];\n for (let i = 0; i <= this.nRows; i++) {\n hLineType[i] = [];\n vLineType[i] = [];\n }\n\n for (let row = 0; row < this.nRows; row++) {\n for (let col = 0; col < this.nCols; col++) {\n hLineType[row][col] = row === 0 ? 0 : 1 + (this.randomLines ? Math.round(Math.random() * 9) : row + col) % 2;\n vLineType[row][col] = col === 0 ? 0 : 1 + (this.randomLines ? Math.round(Math.random() * 9) : col + row + 1) % 2;\n if (col === this.nCols - 1)\n vLineType[row][col + 1] = 0;\n if (row === this.nRows - 1)\n hLineType[row + 1][col] = 0;\n }\n }\n\n const w = 1 / this.nCols, h = 1 / this.nRows;\n for (let r = 0; r < this.nRows; r++) {\n for (let c = 0; c < this.nCols; c++) {\n const x = w * c;\n const y = h * r;\n const sd = new Path([new PathStroke('M', [x, y])]);\n this.hLine(sd, hLineType[r][c], x + 0, y + 0, w, h, false);\n this.vLine(sd, vLineType[r][c + 1], x + w, y + 0, w, h, false);\n this.hLine(sd, hLineType[r + 1][c], x + w, y + h, w, h, true);\n this.vLine(sd, vLineType[r][c], x + 0, y + h, w, h, true);\n sd.addStroke(new PathStroke('X'));\n sd.calcEnclosingRect();\n // Save the Path in `shapeData`\n this.shapeData[r * this.nCols + c] = sd;\n }\n }\n this.initiated = true;\n }\n\n /**\n * Adds an horizontal line to the provided path\n * @param {module:AWT.Path} sd - The Path to which the line will be added\n * @param {number} type - Type of tooth: 0 is flat (no tooth), 1 means tooth up, and 2 means tooth down\n * @param {number} x - X coordinate of the starting point\n * @param {number} y - Y coordinate of the starting point\n * @param {number} w - Width of the piece\n * @param {number} h - Height of the piece\n * @param {boolean} inv - The line must be drawn right to left\n */\n hLine(sd, type, x, y, w, h, inv) {\n const\n kx = inv ? -1 : 1,\n ky = type === 1 ? 1 : -1;\n\n if (type === 0)\n // Flat line\n sd.addStroke(new PathStroke('L', [x + w * kx, y]));\n else {\n const x0 = x + (w - w * this.baseWidthFactor) / 2 * kx;\n const wb = w * this.baseWidthFactor * kx;\n // Approximation to the tooth:\n sd.addStroke(new PathStroke('L', [x0, y]));\n // The tooth:\n const hb = h * this.toothHeightFactor * ky;\n sd.addStroke(new PathStroke('L', [x0, y + hb]));\n sd.addStroke(new PathStroke('L', [x0 + wb, y + hb]));\n sd.addStroke(new PathStroke('L', [x0 + wb, y]));\n // Draw the remaining of the line\n sd.addStroke(new PathStroke('L', [x + w * kx, y]));\n }\n }\n\n /**\n *\n * Adds a vertical line to the provided path\n * @param {module:AWT.Path} sd - The Path to which the line will be added\n * @param {number} type - Type of tooth: 0 is flat (no tooth), 1 means tooth right, and 2 means tooth left\n * @param {number} x - X coordinate of the starting point\n * @param {number} y - Y coordinate of the starting point\n * @param {number} w - Width of the piece\n * @param {number} h - Height of the piece\n * @param {boolean} inv - The line must be drawn bottom to top\n */\n vLine(sd, type, x, y, w, h, inv) {\n const\n ky = inv ? -1 : 1,\n kx = type === 1 ? 1 : -1;\n\n if (type === 0) {\n // Flat line\n sd.addStroke(new PathStroke('L', [x, y + h * ky]));\n } else {\n const y0 = y + (h - h * this.baseWidthFactor) / 2 * ky;\n const hb = h * this.baseWidthFactor * ky;\n // Approximation to the tooth:\n sd.addStroke(new PathStroke('L', [x, y0]));\n // The tooth:\n const wb = w * this.toothHeightFactor * kx;\n sd.addStroke(new PathStroke('L', [x + wb, y0]));\n sd.addStroke(new PathStroke('L', [x + wb, y0 + hb]));\n sd.addStroke(new PathStroke('L', [x, y0 + hb]));\n // Draw the remaining line\n sd.addStroke(new PathStroke('L', [x, y + h * ky]));\n }\n }\n}\n\n// Register this class in the list of known shapers\nexport default Shaper.registerClass('@JigSaw', JigSaw);\n","/**\n * File : shapers/Shaper.js\n * Created : 13/04/2015\n * By : Francesc Busquets <francesc@gmail.com>\n *\n * JClic.js\n * An HTML5 player of JClic activities\n * https://projectestac.github.io/jclic.js\n *\n * @source https://github.com/projectestac/jclic.js\n *\n * @license EUPL-1.2\n * @licstart\n * (c) 2000-2020 Educational Telematic Network of Catalonia (XTEC)\n *\n * Licensed under the EUPL, Version 1.1 or -as soon they will be approved by\n * the European Commission- subsequent versions of the EUPL (the \"Licence\");\n * You may not use this work except in compliance with the Licence.\n *\n * You may obtain a copy of the Licence at:\n * https://joinup.ec.europa.eu/software/page/eupl\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the Licence is distributed on an \"AS IS\" basis, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * Licence for the specific language governing permissions and limitations\n * under the Licence.\n * @licend\n * @module\n */\n\nimport $ from 'jquery';\nimport { log, attrForEach, getBoolean, getAttr, setAttr } from '../Utils.js';\nimport { Shape, Rectangle, Ellipse, PathStroke, Path } from '../AWT.js';\n\n/**\n * The function of this class and its subclasses is to draw a set of \"shapes\" that will be used to\n * place {@link module:boxes/ActiveBox.ActiveBox ActiveBox} objects at a specific position, and to determine its dimension and\n * appearance.\n */\nexport class Shaper {\n /**\n * Shaper constructor\n * @param {number} nx - Number of columns (in grid-based shapers)\n * @param {number} ny - Number of rows (in grid-based shapers)\n */\n constructor(nx, ny) {\n this.reset(nx, ny);\n }\n\n /**\n * Registers a new type of shaper\n * @param {string} shaperName - The name used to identify this shaper\n * @param {function} shaperClass - The shaper class, usually extending Shaper\n * @returns {module:shapers/Shaper.Shaper} - The provided shaper class\n */\n static registerClass(shaperName, shaperClass) {\n Shaper.CLASSES[shaperName] = shaperClass;\n return shaperClass;\n }\n\n /**\n * Factory constructor that returns a Shaper of the requested class.\n * @param {string} className - The class name of the requested Shaper.\n * @param {number} nx - Number of columns (in grid-based shapers)\n * @param {number} ny - Number of rows (in grid-based shapers)\n * @returns {module:shapers/Shaper.Shaper}\n */\n static getShaper(className, nx, ny) {\n const cl = Shaper.CLASSES[(className || '').replace(/^edu\\.xtec\\.jclic\\.shapers\\./, '@')];\n if (!cl)\n log('error', `Unknown shaper: ${className}`);\n return cl ? new cl(nx, ny) : null;\n }\n\n /**\n * Initializes this Shaper to default values\n * @param {number} nCols - Number of columns\n * @param {number} nRows - Number of rows\n */\n reset(nCols, nRows) {\n this.nCols = nCols;\n this.nRows = nRows;\n this.nCells = nRows * nCols;\n this.initiated = false;\n this.shapeData = [];\n for (let i = 0; i < this.nCells; i++)\n this.shapeData[i] = new Shape();\n }\n\n /**\n * Loads this shaper settings from a specific JQuery XML element\n * @param {external:jQuery} $xml - The XML element with the shaper data\n */\n setProperties($xml) {\n attrForEach($xml.get(0).attributes, (name, value) => {\n switch (name) {\n case 'class':\n this.className = value;\n break;\n case 'cols':\n this.nCols = Number(value);\n break;\n case 'rows':\n this.nRows = Number(value);\n break;\n case 'baseWidthFactor':\n case 'toothHeightFactor':\n case 'scaleX':\n case 'scaleY':\n this[name] = Number(value);\n break;\n case 'randomLines':\n case 'showEnclosure':\n this[name] = getBoolean(value, true);\n break;\n }\n });\n\n // Reads the 'enclosing'\n // (main shape area where the other shape elements are placed)\n $xml.children('enclosing:first').each((_n, child) => {\n $(child).children('shape:first').each((_n, child2) => {\n let sh = Shaper.readShapeData(child2, this.scaleX, this.scaleY);\n this.enclosing = sh;\n this.showEnclosure = true;\n this.hasRemainder = true;\n });\n });\n\n // Read the shape elements\n $xml.children('shape').each((n, child) => {\n this.shapeData[n] = Shaper.readShapeData(child, this.scaleX, this.scaleY);\n });\n\n // Correction needed for '@Holes' shaper\n if (this.shapeData.length > 0 /* && this.shapeData.length !== this.nRows * this.nCols */) {\n //this.nRows = this.shapeData.length\n //this.nCols = 1\n //this.nCells = this.nCols * this.nRows\n this.nCells = this.shapeData.length;\n }\n return this;\n }\n\n /**\n * Reads an individual shape from an XML element.\n * Shapes are arrays of `stroke` objects.\n * Each `stroke` has an `action` (_move to_, _line to_, _quad to_...) and associated `data`.\n * @param {external:jQuery} $xml - The XML element with the shape data\n * @param {number} scaleX\n * @param {number} scaleY\n * @returns {module:AWT.Shape}\n */\n static readShapeData(xml, scaleX, scaleY) {\n const shd = [];\n let result = null;\n $.each(xml.textContent.split('|'), (_n, txt) => {\n const sd = txt.split(':');\n // Possible strokes are: `rectangle`, `ellipse`, `M`, `L`, `Q`, `B`, `X`\n // Also possible, but not currently used in JClic: `roundRectangle` and `pie`\n let data = sd.length > 1 ? sd[1].split(',') : null;\n //\n // Data should be always divided by the scale (X or Y)\n if (data)\n data = data.map((d, n) => d / (n % 2 ? scaleY : scaleX));\n\n switch (sd[0]) {\n case 'rectangle':\n result = new Rectangle(data[0], data[1], data[2], data[3]);\n break;\n case 'ellipse':\n result = new Ellipse(data[0], data[1], data[2], data[3]);\n break;\n default:\n // It's an `AWT.PathStroke`\n shd.push(new PathStroke(sd[0], data));\n break;\n }\n });\n\n return !result && shd.length > 0 ? new Path(shd) : result;\n }\n\n /**\n * Gets a object with the basic attributes needed to rebuild this instance excluding functions,\n * parent references, constants and also attributes retaining the default value.\n * The resulting object is commonly usued to serialize elements in JSON format.\n * @returns {object} - The resulting object, with minimal attrributes\n */\n getAttributes() {\n const fields = [\n 'className', 'nCols', 'nRows',\n 'baseWidthFactor', 'toothHeightFactor',\n 'scaleX', 'scaleY',\n 'randomLines',\n ];\n\n if (this.customShapes) {\n ['showEnclosure', 'hasRemainder',\n 'enclosing', 'shapeData', // Array of AWT.Rectangle, AWT.Ellipse or (AWT.Path -> AWT.PathStroke)\n ].forEach(f => fields.push(f));\n }\n\n return getAttr(this, fields);\n }\n\n /**\n * Builds a new shaper, based on the properties specified in a data object\n * @param {object} data - The data object to be parsed\n * @returns {module:shapers/Shaper.Shaper}\n */\n static factory(data) {\n const result = Shaper.getShaper(data.className, data.nCols, data.nRows);\n setAttr(result, data, [\n 'className', 'nCols', 'nRows',\n 'baseWidthFactor', 'toothHeightFactor',\n 'scaleX', 'scaleY',\n 'randomLines',\n 'showEnclosure', 'hasRemainder',\n { key: 'enclosing', fn: Shape },\n { key: 'shapeData', fn: Shape, group: 'array' },\n ]);\n\n result.nCells = result.shapeData.length || result.nCols * result.nRows;\n\n return result;\n }\n\n /**\n * Builds the individual shapes that will form this Shaper\n */\n buildShapes() {\n }\n\n /**\n * Gets a clone of the nth Shape object, scaled and located inside a Rectangle\n * @param {number} n\n * @param {module:AWT.Rectangle} rect\n * @returns {module:AWT.Shape}\n */\n getShape(n, rect) {\n if (!this.initiated)\n this.buildShapes();\n if (n >= this.nCells || this.shapeData[n] === null)\n return null;\n return this.shapeData[n].getShape(rect);\n }\n\n /**\n * Gets the nth Shape data object\n * @param {number} n\n * @returns {object}\n */\n getShapeData(n) {\n return n >= 0 && n < this.shapeData.length ? this.shapeData[n] : null;\n }\n\n /**\n * Gets the AWT.Rectangle that contains all shapes of this Shaper.\n * @returns {module:AWT.Rectangle}\n */\n getEnclosingShapeData() {\n return new Rectangle(0, 0, 1, 1);\n }\n\n /**\n * When `hasRemainder` is true, this method gets the rectangle containing the full surface where\n * the Shaper develops.\n * @param {module:AWT.Rectangle} rect - The frame where to move and scale all the shapes\n * @returns {module:AWT.Rectangle}\n */\n getRemainderShape(rect) {\n if (!this.hasRemainder)\n return null;\n\n if (!this.initiated)\n this.buildShapes();\n\n const sh = this.getEnclosingShapeData();\n const r = sh ? sh.getShape(rect) : new Rectangle();\n for (let i = 0; i < this.nCells; i++) {\n if (this.shapeData[i])\n r.add(this.shapeData[i].getShape(rect), false);\n }\n return r;\n }\n}\n\nObject.assign(Shaper.prototype, {\n /**\n * This shaper class name\n * @name module:shapers/Shaper.Shaper#className\n * @type {string} */\n className: 'Shaper',\n /**\n * Number of columns (useful in grid-based shapers)\n * @name module:shapers/Shaper.Shaper#nCols\n * @type {number} */\n nCols: 0,\n /**\n * Number of rows (useful in grid-based shapers)\n * @name module:shapers/Shaper.Shaper#nRows\n * @type {number} */\n nRows: 0,\n /**\n * Number of cells managed by this shaper\n * @name module:shapers/Shaper.Shaper#nCells\n * @type {number} */\n nCells: 0,\n /**\n * Contains the specific definition of each shape\n * @name module:shapers/Shaper.Shaper#shapeData\n * @type {object} */\n shapeData: null,\n /**\n * Flag used to check if the `Shaper` has been initialized against a real surface\n * @name module:shapers/Shaper.Shaper#initiated\n * @type {boolean} */\n initiated: false,\n //\n // Fields used only in JigSaw shapers\n /**\n * In {@link module:shapers/JigSaw.JigSaw JigSaw}, ratio between the base width of the tooth and the total length of the side.\n * @name module:shapers/Shaper.Shaper#baseWidthFactor\n * @type {number} */\n baseWidthFactor: 1.0 / 3,\n /**\n * In {@link module:shapers/JigSaw.JigSaw JigSaw}, ratio between the tooth height and the total length of the side.\n * @name module:shapers/Shaper.Shaper#toothHeightFactor\n * @type {number} */\n toothHeightFactor: 1.0 / 6,\n /**\n * In {@link module:shapers/JigSaw.JigSaw JigSaw}, whether the tooths take random directions or not\n * @name module:shapers/Shaper.Shaper#randomLines\n * @type {boolean} */\n randomLines: false,\n //\n // Fields used only in the `Holes` shaper\n /**\n * In {@link module:shapers/Holes.Holes Holes}, scale to be applied to horizontal positions and lengths to achieve the real\n * value of the shape placed on a real surface.\n * @name module:shapers/Shaper.Shaper#scaleX\n * @type {number} */\n scaleX: 1.0,\n /**\n * In {@link module:shapers/Holes.Holes Holes}, scale to be applied to vertical positions and lengths to achieve the real\n * value of the shape placed on a real surface.\n * @name module:shapers/Shaper.Shaper#scaleY\n * @type {number} */\n scaleY: 1.0,\n /**\n * In {@link module:shapers/Holes.Holes Holes}, the enclosing area where all shapes are placed.\n * @name module:shapers/Shaper.Shaper#enclosing\n * @type {module:AWT.Shape} */\n enclosing: null,\n /**\n * In {@link module:shapers/Holes.Holes Holes}, when `true`, the enclosing area will be drawn\n * @name module:shapers/Shaper.Shaper#showEnclosure\n * @type {boolean} */\n showEnclosure: false,\n /**\n * Flag indicating if this shaper organizes its cells in rows and columns\n * @name module:shapers/Shaper.Shaper#rectangularShapes\n * @type {boolean} */\n rectangularShapes: false,\n /**\n * Flag indicating if this Shaper deploys over a surface biggest than the rectangle enclosing\n * all its shapes\n * @name module:shapers/Shaper.Shaper#hasRemainder\n * @type {boolean} */\n hasRemainder: false,\n /**\n * Only the `Holes` shaper has this flag activated\n * @name module:shapers/Shaper.Shaper#customShapes\n * @type {boolean} */\n customShapes: false,\n});\n\n/**\n * List of known classes derived from Shaper. It should be filled by real shaper classes at\n * declaration time.\n * @type {object} */\nShaper.CLASSES = {};\n\nexport default Shaper;\n"],"names":[],"sourceRoot":""}