litecanvas 0.207.0 → 0.207.2
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.
- package/dist/dist.dev.js +149 -339
- package/dist/dist.js +4 -7
- package/dist/dist.min.js +1 -1
- package/package.json +1 -1
- package/src/dev.js +1 -1
- package/src/index.js +157 -208
- package/src/version.js +1 -1
package/src/index.js
CHANGED
|
@@ -15,7 +15,6 @@ export default function litecanvas(settings = {}) {
|
|
|
15
15
|
math = Math,
|
|
16
16
|
perf = performance,
|
|
17
17
|
TWO_PI = math.PI * 2,
|
|
18
|
-
loggerPrefix = '[Litecanvas] ',
|
|
19
18
|
raf = requestAnimationFrame,
|
|
20
19
|
isNumber = Number.isFinite,
|
|
21
20
|
/** @type {Function[]} */
|
|
@@ -44,6 +43,11 @@ export default function litecanvas(settings = {}) {
|
|
|
44
43
|
keyboardEvents: true,
|
|
45
44
|
}
|
|
46
45
|
|
|
46
|
+
DEV: assert(
|
|
47
|
+
null == settings || 'object' === typeof settings,
|
|
48
|
+
'litecanvas() 1st parameter must be a object or null'
|
|
49
|
+
)
|
|
50
|
+
|
|
47
51
|
// setup the settings default values
|
|
48
52
|
settings = Object.assign(defaults, settings)
|
|
49
53
|
|
|
@@ -138,9 +142,9 @@ export default function litecanvas(settings = {}) {
|
|
|
138
142
|
* @tutorial https://gamedev.net/tutorials/programming/general-and-gameplay-programming/a-brief-introduction-to-lerp-r4954/
|
|
139
143
|
*/
|
|
140
144
|
lerp: (start, end, t) => {
|
|
141
|
-
DEV: assert(isNumber(start),
|
|
142
|
-
DEV: assert(isNumber(end),
|
|
143
|
-
DEV: assert(isNumber(t),
|
|
145
|
+
DEV: assert(isNumber(start), 'lerp() 1st parameter must be a number')
|
|
146
|
+
DEV: assert(isNumber(end), 'lerp() 2nd parameter must be a number')
|
|
147
|
+
DEV: assert(isNumber(t), 'lerp() 3rd parameter must be a number')
|
|
144
148
|
|
|
145
149
|
return start + t * (end - start)
|
|
146
150
|
},
|
|
@@ -152,7 +156,7 @@ export default function litecanvas(settings = {}) {
|
|
|
152
156
|
* @returns {number} the value in radians
|
|
153
157
|
*/
|
|
154
158
|
deg2rad: (degs) => {
|
|
155
|
-
DEV: assert(isNumber(degs), 'deg2rad() 1st
|
|
159
|
+
DEV: assert(isNumber(degs), 'deg2rad() 1st parameter must be a number')
|
|
156
160
|
|
|
157
161
|
return (math.PI / 180) * degs
|
|
158
162
|
},
|
|
@@ -164,7 +168,7 @@ export default function litecanvas(settings = {}) {
|
|
|
164
168
|
* @returns {number} the value in degrees
|
|
165
169
|
*/
|
|
166
170
|
rad2deg: (rads) => {
|
|
167
|
-
DEV: assert(isNumber(rads), 'rad2deg() 1st
|
|
171
|
+
DEV: assert(isNumber(rads), 'rad2deg() 1st parameter must be a number')
|
|
168
172
|
|
|
169
173
|
return (180 / math.PI) * rads
|
|
170
174
|
},
|
|
@@ -179,10 +183,10 @@ export default function litecanvas(settings = {}) {
|
|
|
179
183
|
* @returns {number} rounded number.
|
|
180
184
|
*/
|
|
181
185
|
round: (n, precision = 0) => {
|
|
182
|
-
DEV: assert(isNumber(n),
|
|
186
|
+
DEV: assert(isNumber(n), 'round() 1st parameter must be a number')
|
|
183
187
|
DEV: assert(
|
|
184
188
|
isNumber(precision) && precision >= 0,
|
|
185
|
-
|
|
189
|
+
'round() 2nd parameter must be a positive number or zero'
|
|
186
190
|
)
|
|
187
191
|
|
|
188
192
|
if (!precision) {
|
|
@@ -201,13 +205,10 @@ export default function litecanvas(settings = {}) {
|
|
|
201
205
|
* @returns {number}
|
|
202
206
|
*/
|
|
203
207
|
clamp: (value, min, max) => {
|
|
204
|
-
DEV: assert(isNumber(value),
|
|
205
|
-
DEV: assert(isNumber(min),
|
|
206
|
-
DEV: assert(isNumber(max),
|
|
207
|
-
DEV: assert(
|
|
208
|
-
max >= min,
|
|
209
|
-
loggerPrefix + 'clamp() the 2nd param must be less than the 3rd param'
|
|
210
|
-
)
|
|
208
|
+
DEV: assert(isNumber(value), 'clamp() 1st parameter must be a number')
|
|
209
|
+
DEV: assert(isNumber(min), 'clamp() 2nd parameter must be a number')
|
|
210
|
+
DEV: assert(isNumber(max), 'clamp() 3rd parameter must be a number')
|
|
211
|
+
DEV: assert(max >= min, 'clamp() the 2nd parameter must be less than the 3rd parameter')
|
|
211
212
|
|
|
212
213
|
if (value < min) return min
|
|
213
214
|
if (value > max) return max
|
|
@@ -224,10 +225,10 @@ export default function litecanvas(settings = {}) {
|
|
|
224
225
|
* @returns {number}
|
|
225
226
|
*/
|
|
226
227
|
dist: (x1, y1, x2, y2) => {
|
|
227
|
-
DEV: assert(isNumber(x1),
|
|
228
|
-
DEV: assert(isNumber(y1),
|
|
229
|
-
DEV: assert(isNumber(x2),
|
|
230
|
-
DEV: assert(isNumber(y2),
|
|
228
|
+
DEV: assert(isNumber(x1), 'dist() 1st parameter must be a number')
|
|
229
|
+
DEV: assert(isNumber(y1), 'dist() 2nd parameter must be a number')
|
|
230
|
+
DEV: assert(isNumber(x2), 'dist() 3rd parameter must be a number')
|
|
231
|
+
DEV: assert(isNumber(y2), 'dist() 4th parameter must be a number')
|
|
231
232
|
|
|
232
233
|
return math.hypot(x2 - x1, y2 - y1)
|
|
233
234
|
},
|
|
@@ -241,13 +242,10 @@ export default function litecanvas(settings = {}) {
|
|
|
241
242
|
* @returns {number}
|
|
242
243
|
*/
|
|
243
244
|
wrap: (value, min, max) => {
|
|
244
|
-
DEV: assert(isNumber(value),
|
|
245
|
-
DEV: assert(isNumber(min),
|
|
246
|
-
DEV: assert(isNumber(max),
|
|
247
|
-
DEV: assert(
|
|
248
|
-
max > min,
|
|
249
|
-
loggerPrefix + 'wrap() the 2nd param must be less than the 3rd param'
|
|
250
|
-
)
|
|
245
|
+
DEV: assert(isNumber(value), 'wrap() 1st parameter must be a number')
|
|
246
|
+
DEV: assert(isNumber(min), 'wrap() 2nd parameter must be a number')
|
|
247
|
+
DEV: assert(isNumber(max), 'wrap() 3rd parameter must be a number')
|
|
248
|
+
DEV: assert(max > min, 'wrap() the 2nd parameter must be less than the 3rd parameter')
|
|
251
249
|
|
|
252
250
|
return value - (max - min) * math.floor((value - min) / (max - min))
|
|
253
251
|
},
|
|
@@ -264,14 +262,14 @@ export default function litecanvas(settings = {}) {
|
|
|
264
262
|
* @returns {number} the remapped number
|
|
265
263
|
*/
|
|
266
264
|
map(value, start1, stop1, start2, stop2, withinBounds) {
|
|
267
|
-
DEV: assert(isNumber(value),
|
|
268
|
-
DEV: assert(isNumber(start1),
|
|
269
|
-
DEV: assert(isNumber(stop1),
|
|
270
|
-
DEV: assert(isNumber(start2),
|
|
271
|
-
DEV: assert(isNumber(stop2),
|
|
265
|
+
DEV: assert(isNumber(value), 'map() 1st parameter must be a number')
|
|
266
|
+
DEV: assert(isNumber(start1), 'map() 2nd parameter must be a number')
|
|
267
|
+
DEV: assert(isNumber(stop1), 'map() 3rd parameter must be a number')
|
|
268
|
+
DEV: assert(isNumber(start2), 'map() 4th parameter must be a number')
|
|
269
|
+
DEV: assert(isNumber(stop2), 'map() 5th parameter must be a number')
|
|
272
270
|
DEV: assert(
|
|
273
271
|
stop1 !== start1,
|
|
274
|
-
|
|
272
|
+
'map() the 2nd parameter must be different than the 3rd parameter'
|
|
275
273
|
)
|
|
276
274
|
|
|
277
275
|
// prettier-ignore
|
|
@@ -290,12 +288,12 @@ export default function litecanvas(settings = {}) {
|
|
|
290
288
|
* @returns {number} the normalized number.
|
|
291
289
|
*/
|
|
292
290
|
norm: (value, start, stop) => {
|
|
293
|
-
DEV: assert(isNumber(value),
|
|
294
|
-
DEV: assert(isNumber(start),
|
|
295
|
-
DEV: assert(isNumber(stop),
|
|
291
|
+
DEV: assert(isNumber(value), 'norm() 1st parameter must be a number')
|
|
292
|
+
DEV: assert(isNumber(start), 'norm() 2nd parameter must be a number')
|
|
293
|
+
DEV: assert(isNumber(stop), 'norm() 3rd parameter must be a number')
|
|
296
294
|
DEV: assert(
|
|
297
295
|
start !== stop,
|
|
298
|
-
|
|
296
|
+
'norm() the 2nd parameter must be different than the 3rd parameter'
|
|
299
297
|
)
|
|
300
298
|
|
|
301
299
|
return instance.map(value, start, stop, 0, 1)
|
|
@@ -311,12 +309,9 @@ export default function litecanvas(settings = {}) {
|
|
|
311
309
|
* @returns {number} the random number
|
|
312
310
|
*/
|
|
313
311
|
rand: (min = 0.0, max = 1.0) => {
|
|
314
|
-
DEV: assert(isNumber(min),
|
|
315
|
-
DEV: assert(isNumber(max),
|
|
316
|
-
DEV: assert(
|
|
317
|
-
max >= min,
|
|
318
|
-
loggerPrefix + 'rand() the 1st param must be less than the 2nd param'
|
|
319
|
-
)
|
|
312
|
+
DEV: assert(isNumber(min), 'rand() 1st parameter must be a number')
|
|
313
|
+
DEV: assert(isNumber(max), 'rand() 2nd parameter must be a number')
|
|
314
|
+
DEV: assert(max >= min, 'rand() the 1st parameter must be less than the 2nd parameter')
|
|
320
315
|
|
|
321
316
|
const a = 1664525
|
|
322
317
|
const c = 1013904223
|
|
@@ -335,12 +330,9 @@ export default function litecanvas(settings = {}) {
|
|
|
335
330
|
* @returns {number} the random number
|
|
336
331
|
*/
|
|
337
332
|
randi: (min = 0, max = 1) => {
|
|
338
|
-
DEV: assert(isNumber(min),
|
|
339
|
-
DEV: assert(isNumber(max),
|
|
340
|
-
DEV: assert(
|
|
341
|
-
max >= min,
|
|
342
|
-
loggerPrefix + 'randi() the 1st param must be less than the 2nd param'
|
|
343
|
-
)
|
|
333
|
+
DEV: assert(isNumber(min), 'randi() 1st parameter must be a number')
|
|
334
|
+
DEV: assert(isNumber(max), 'randi() 2nd parameter must be a number')
|
|
335
|
+
DEV: assert(max >= min, 'randi() the 1st parameter must be less than the 2nd parameter')
|
|
344
336
|
|
|
345
337
|
return ~~instance.rand(min, max + 1)
|
|
346
338
|
},
|
|
@@ -355,7 +347,7 @@ export default function litecanvas(settings = {}) {
|
|
|
355
347
|
rseed(value) {
|
|
356
348
|
DEV: assert(
|
|
357
349
|
isNumber(value) && value >= 0,
|
|
358
|
-
|
|
350
|
+
'rseed() 1st parameter must be a positive integer or zero'
|
|
359
351
|
)
|
|
360
352
|
|
|
361
353
|
_rngSeed = ~~value
|
|
@@ -370,7 +362,7 @@ export default function litecanvas(settings = {}) {
|
|
|
370
362
|
cls(color) {
|
|
371
363
|
DEV: assert(
|
|
372
364
|
null == color || (isNumber(color) && color >= 0),
|
|
373
|
-
|
|
365
|
+
'cls() 1st parameter must be a positive number or zero or undefined'
|
|
374
366
|
)
|
|
375
367
|
|
|
376
368
|
if (null == color) {
|
|
@@ -393,23 +385,23 @@ export default function litecanvas(settings = {}) {
|
|
|
393
385
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/roundRect
|
|
394
386
|
*/
|
|
395
387
|
rect(x, y, width, height, color, radii) {
|
|
396
|
-
DEV: assert(isNumber(x),
|
|
397
|
-
DEV: assert(isNumber(y),
|
|
388
|
+
DEV: assert(isNumber(x), 'rect() 1st parameter must be a number')
|
|
389
|
+
DEV: assert(isNumber(y), 'rect() 2nd parameter must be a number')
|
|
398
390
|
DEV: assert(
|
|
399
391
|
isNumber(width) && width > 0,
|
|
400
|
-
|
|
392
|
+
'rect() 3rd parameter must be a positive number'
|
|
401
393
|
)
|
|
402
394
|
DEV: assert(
|
|
403
395
|
isNumber(height) && height >= 0,
|
|
404
|
-
|
|
396
|
+
'rect() 4th parameter must be a positive number or zero'
|
|
405
397
|
)
|
|
406
398
|
DEV: assert(
|
|
407
399
|
null == color || (isNumber(color) && color >= 0),
|
|
408
|
-
|
|
400
|
+
'rect() 5th parameter must be a positive number or zero'
|
|
409
401
|
)
|
|
410
402
|
DEV: assert(
|
|
411
403
|
null == radii || isNumber(radii) || (Array.isArray(radii) && radii.length >= 1),
|
|
412
|
-
|
|
404
|
+
'rect() 6th parameter must be a number or array of numbers'
|
|
413
405
|
)
|
|
414
406
|
|
|
415
407
|
beginPath(_ctx)
|
|
@@ -434,24 +426,24 @@ export default function litecanvas(settings = {}) {
|
|
|
434
426
|
* @param {number|number[]} [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
|
|
435
427
|
*/
|
|
436
428
|
rectfill(x, y, width, height, color, radii) {
|
|
437
|
-
DEV: assert(isNumber(x),
|
|
438
|
-
DEV: assert(isNumber(y),
|
|
429
|
+
DEV: assert(isNumber(x), 'rectfill() 1st parameter must be a number')
|
|
430
|
+
DEV: assert(isNumber(y), 'rectfill() 2nd parameter must be a number')
|
|
439
431
|
DEV: assert(
|
|
440
432
|
isNumber(width) && width >= 0,
|
|
441
|
-
|
|
433
|
+
'rectfill() 3rd parameter must be a positive number or zero'
|
|
442
434
|
)
|
|
443
435
|
DEV: assert(
|
|
444
436
|
isNumber(height) && height >= 0,
|
|
445
|
-
|
|
437
|
+
'rectfill() 4th parameter must be a positive number or zero'
|
|
446
438
|
)
|
|
447
439
|
DEV: assert(
|
|
448
440
|
null == color || (isNumber(color) && color >= 0),
|
|
449
|
-
|
|
441
|
+
'rectfill() 5th parameter must be a positive number or zero'
|
|
450
442
|
)
|
|
451
443
|
DEV: assert(
|
|
452
444
|
null == radii || isNumber(radii) || (Array.isArray(radii) && radii.length >= 1),
|
|
453
|
-
|
|
454
|
-
|
|
445
|
+
|
|
446
|
+
'rectfill() 6th parameter must be a number or array of at least 2 numbers'
|
|
455
447
|
)
|
|
456
448
|
|
|
457
449
|
beginPath(_ctx)
|
|
@@ -469,19 +461,19 @@ export default function litecanvas(settings = {}) {
|
|
|
469
461
|
* @param {number} [color=0] the color index
|
|
470
462
|
*/
|
|
471
463
|
oval(x, y, radiusX, radiusY, color) {
|
|
472
|
-
DEV: assert(isNumber(x),
|
|
473
|
-
DEV: assert(isNumber(y),
|
|
464
|
+
DEV: assert(isNumber(x), 'oval() 1st parameter must be a number')
|
|
465
|
+
DEV: assert(isNumber(y), 'oval() 2nd parameter must be a number')
|
|
474
466
|
DEV: assert(
|
|
475
467
|
isNumber(radiusX) && radiusX >= 0,
|
|
476
|
-
|
|
468
|
+
'oval() 3rd parameter must be a positive number or zero'
|
|
477
469
|
)
|
|
478
470
|
DEV: assert(
|
|
479
471
|
isNumber(radiusY) && radiusY >= 0,
|
|
480
|
-
|
|
472
|
+
'oval() 4th parameter must be a positive number or zero'
|
|
481
473
|
)
|
|
482
474
|
DEV: assert(
|
|
483
475
|
null == color || (isNumber(color) && color >= 0),
|
|
484
|
-
|
|
476
|
+
'oval() 5th parameter must be a positive number or zero'
|
|
485
477
|
)
|
|
486
478
|
|
|
487
479
|
beginPath(_ctx)
|
|
@@ -499,19 +491,19 @@ export default function litecanvas(settings = {}) {
|
|
|
499
491
|
* @param {number} [color=0] the color index
|
|
500
492
|
*/
|
|
501
493
|
ovalfill(x, y, radiusX, radiusY, color) {
|
|
502
|
-
DEV: assert(isNumber(x),
|
|
503
|
-
DEV: assert(isNumber(y),
|
|
494
|
+
DEV: assert(isNumber(x), 'ovalfill() 1st parameter must be a number')
|
|
495
|
+
DEV: assert(isNumber(y), 'ovalfill() 2nd parameter must be a number')
|
|
504
496
|
DEV: assert(
|
|
505
497
|
isNumber(radiusX) && radiusX >= 0,
|
|
506
|
-
|
|
498
|
+
'ovalfill() 3rd parameter must be a positive number or zero'
|
|
507
499
|
)
|
|
508
500
|
DEV: assert(
|
|
509
501
|
isNumber(radiusY) && radiusY >= 0,
|
|
510
|
-
|
|
502
|
+
'ovalfill() 4th parameter must be a positive number or zero'
|
|
511
503
|
)
|
|
512
504
|
DEV: assert(
|
|
513
505
|
null == color || (isNumber(color) && color >= 0),
|
|
514
|
-
|
|
506
|
+
'ovalfill() 5th parameter must be a positive number or zero'
|
|
515
507
|
)
|
|
516
508
|
|
|
517
509
|
beginPath(_ctx)
|
|
@@ -528,15 +520,15 @@ export default function litecanvas(settings = {}) {
|
|
|
528
520
|
* @param {number} [color=0] the color index
|
|
529
521
|
*/
|
|
530
522
|
circ(x, y, radius, color) {
|
|
531
|
-
DEV: assert(isNumber(x),
|
|
532
|
-
DEV: assert(isNumber(y),
|
|
523
|
+
DEV: assert(isNumber(x), 'circ() 1st parameter must be a number')
|
|
524
|
+
DEV: assert(isNumber(y), 'circ() 2nd parameter must be a number')
|
|
533
525
|
DEV: assert(
|
|
534
526
|
isNumber(radius) && radius >= 0,
|
|
535
|
-
|
|
527
|
+
'circ() 3rd parameter must be a positive number or zero'
|
|
536
528
|
)
|
|
537
529
|
DEV: assert(
|
|
538
530
|
null == color || (isNumber(color) && color >= 0),
|
|
539
|
-
|
|
531
|
+
'circ() 4th parameter must be a positive number or zero'
|
|
540
532
|
)
|
|
541
533
|
|
|
542
534
|
instance.oval(x, y, radius, radius, color)
|
|
@@ -551,15 +543,15 @@ export default function litecanvas(settings = {}) {
|
|
|
551
543
|
* @param {number} [color=0] the color index
|
|
552
544
|
*/
|
|
553
545
|
circfill(x, y, radius, color) {
|
|
554
|
-
DEV: assert(isNumber(x),
|
|
555
|
-
DEV: assert(isNumber(y),
|
|
546
|
+
DEV: assert(isNumber(x), 'circfill() 1st parameter must be a number')
|
|
547
|
+
DEV: assert(isNumber(y), 'circfill() 2nd parameter must be a number')
|
|
556
548
|
DEV: assert(
|
|
557
549
|
isNumber(radius) && radius >= 0,
|
|
558
|
-
|
|
550
|
+
'circfill() 3rd parameter must be a positive number or zero'
|
|
559
551
|
)
|
|
560
552
|
DEV: assert(
|
|
561
553
|
null == color || (isNumber(color) && color >= 0),
|
|
562
|
-
|
|
554
|
+
'circfill() 4th parameter must be a positive number or zero'
|
|
563
555
|
)
|
|
564
556
|
|
|
565
557
|
instance.ovalfill(x, y, radius, radius, color)
|
|
@@ -572,14 +564,11 @@ export default function litecanvas(settings = {}) {
|
|
|
572
564
|
* @param {number[]} points an array of Xs and Ys coordinates
|
|
573
565
|
*/
|
|
574
566
|
shape(points) {
|
|
575
|
-
DEV: assert(
|
|
576
|
-
Array.isArray(points),
|
|
577
|
-
loggerPrefix + 'shape() 1st param must be an array of numbers'
|
|
578
|
-
)
|
|
567
|
+
DEV: assert(Array.isArray(points), 'shape() 1st parameter must be an array of numbers')
|
|
579
568
|
DEV: assert(
|
|
580
569
|
points.length >= 6,
|
|
581
|
-
|
|
582
|
-
|
|
570
|
+
|
|
571
|
+
'shape() 1st parameter must be an array with at least 6 numbers (3 points)'
|
|
583
572
|
)
|
|
584
573
|
beginPath(_ctx)
|
|
585
574
|
for (let i = 0; i < points.length; i += 2) {
|
|
@@ -602,19 +591,13 @@ export default function litecanvas(settings = {}) {
|
|
|
602
591
|
* @param {number} [color=0] the color index
|
|
603
592
|
*/
|
|
604
593
|
line(x1, y1, x2, y2, color) {
|
|
605
|
-
DEV: assert(isNumber(x1),
|
|
606
|
-
DEV: assert(isNumber(y1),
|
|
607
|
-
DEV: assert(
|
|
608
|
-
|
|
609
|
-
loggerPrefix + 'line() 3rd param must be a positive number or zero'
|
|
610
|
-
)
|
|
611
|
-
DEV: assert(
|
|
612
|
-
isNumber(y2),
|
|
613
|
-
loggerPrefix + 'line() 4th param must be a positive number or zero'
|
|
614
|
-
)
|
|
594
|
+
DEV: assert(isNumber(x1), 'line() 1st parameter must be a number')
|
|
595
|
+
DEV: assert(isNumber(y1), 'line() 2nd parameter must be a number')
|
|
596
|
+
DEV: assert(isNumber(x2), 'line() 3rd parameter must be a positive number or zero')
|
|
597
|
+
DEV: assert(isNumber(y2), 'line() 4th parameter must be a positive number or zero')
|
|
615
598
|
DEV: assert(
|
|
616
599
|
null == color || (isNumber(color) && color >= 0),
|
|
617
|
-
|
|
600
|
+
'line() 5th parameter must be a positive number or zero'
|
|
618
601
|
)
|
|
619
602
|
|
|
620
603
|
beginPath(_ctx)
|
|
@@ -637,7 +620,7 @@ export default function litecanvas(settings = {}) {
|
|
|
637
620
|
linewidth(value) {
|
|
638
621
|
DEV: assert(
|
|
639
622
|
isNumber(value) && value >= 0,
|
|
640
|
-
|
|
623
|
+
'linewidth() 1st parameter must be a positive number or zero'
|
|
641
624
|
)
|
|
642
625
|
|
|
643
626
|
_ctx.lineWidth = ~~value
|
|
@@ -655,9 +638,9 @@ export default function litecanvas(settings = {}) {
|
|
|
655
638
|
linedash(segments, offset = 0) {
|
|
656
639
|
DEV: assert(
|
|
657
640
|
Array.isArray(segments) && segments.length > 0,
|
|
658
|
-
|
|
641
|
+
'linedash() 1st parameter must be an array of numbers'
|
|
659
642
|
)
|
|
660
|
-
DEV: assert(isNumber(offset),
|
|
643
|
+
DEV: assert(isNumber(offset), 'linedash() 2nd parameter must be a number')
|
|
661
644
|
|
|
662
645
|
_ctx.setLineDash(segments)
|
|
663
646
|
_ctx.lineDashOffset = offset
|
|
@@ -674,16 +657,13 @@ export default function litecanvas(settings = {}) {
|
|
|
674
657
|
* @param {string} [fontStyle] can be "normal" (default), "italic" and/or "bold".
|
|
675
658
|
*/
|
|
676
659
|
text(x, y, message, color = _defaultTextColor, fontStyle = 'normal') {
|
|
677
|
-
DEV: assert(isNumber(x),
|
|
678
|
-
DEV: assert(isNumber(y),
|
|
660
|
+
DEV: assert(isNumber(x), 'text() 1st parameter must be a number')
|
|
661
|
+
DEV: assert(isNumber(y), 'text() 2nd parameter must be a number')
|
|
679
662
|
DEV: assert(
|
|
680
663
|
null == color || (isNumber(color) && color >= 0),
|
|
681
|
-
|
|
682
|
-
)
|
|
683
|
-
DEV: assert(
|
|
684
|
-
'string' === typeof fontStyle,
|
|
685
|
-
loggerPrefix + 'text() 5th param must be a string'
|
|
664
|
+
'text() 4th parameter must be a positive number or zero'
|
|
686
665
|
)
|
|
666
|
+
DEV: assert('string' === typeof fontStyle, 'text() 5th parameter must be a string')
|
|
687
667
|
|
|
688
668
|
_ctx.font = `${fontStyle} ${_fontSize}px ${_fontFamily}`
|
|
689
669
|
_ctx.fillStyle = getColor(color)
|
|
@@ -702,7 +682,7 @@ export default function litecanvas(settings = {}) {
|
|
|
702
682
|
* @param {number} value
|
|
703
683
|
*/
|
|
704
684
|
textgap(value) {
|
|
705
|
-
DEV: assert(isNumber(value),
|
|
685
|
+
DEV: assert(isNumber(value), 'textgap() 1st parameter must be a number')
|
|
706
686
|
|
|
707
687
|
_fontLineHeight = value
|
|
708
688
|
},
|
|
@@ -713,10 +693,7 @@ export default function litecanvas(settings = {}) {
|
|
|
713
693
|
* @param {string} family
|
|
714
694
|
*/
|
|
715
695
|
textfont(family) {
|
|
716
|
-
DEV: assert(
|
|
717
|
-
'string' === typeof family,
|
|
718
|
-
loggerPrefix + 'textfont() 1st param must be a string'
|
|
719
|
-
)
|
|
696
|
+
DEV: assert('string' === typeof family, 'textfont() 1st parameter must be a string')
|
|
720
697
|
|
|
721
698
|
_fontFamily = family
|
|
722
699
|
},
|
|
@@ -727,7 +704,7 @@ export default function litecanvas(settings = {}) {
|
|
|
727
704
|
* @param {number} size
|
|
728
705
|
*/
|
|
729
706
|
textsize(size) {
|
|
730
|
-
DEV: assert(isNumber(size),
|
|
707
|
+
DEV: assert(isNumber(size), 'textsize() 1st parameter must be a number')
|
|
731
708
|
|
|
732
709
|
_fontSize = size
|
|
733
710
|
},
|
|
@@ -743,16 +720,16 @@ export default function litecanvas(settings = {}) {
|
|
|
743
720
|
textalign(align, baseline) {
|
|
744
721
|
DEV: assert(
|
|
745
722
|
null == align || ['left', 'right', 'center', 'start', 'end'].includes(align),
|
|
746
|
-
|
|
747
|
-
|
|
723
|
+
|
|
724
|
+
'textalign() 1st parameter must be null or one of the following strings: center, left, right, start or end.'
|
|
748
725
|
)
|
|
749
726
|
DEV: assert(
|
|
750
727
|
null == baseline ||
|
|
751
728
|
['top', 'bottom', 'middle', 'hanging', 'alphabetic', 'ideographic'].includes(
|
|
752
729
|
baseline
|
|
753
730
|
),
|
|
754
|
-
|
|
755
|
-
|
|
731
|
+
|
|
732
|
+
'textalign() 2nd parameter must be null or one of the following strings: middle, top, bottom, hanging, alphabetic or ideographic.'
|
|
756
733
|
)
|
|
757
734
|
|
|
758
735
|
if (align) _ctx.textAlign = align
|
|
@@ -768,8 +745,8 @@ export default function litecanvas(settings = {}) {
|
|
|
768
745
|
* @param {CanvasImageSource} source
|
|
769
746
|
*/
|
|
770
747
|
image(x, y, source) {
|
|
771
|
-
DEV: assert(isNumber(x),
|
|
772
|
-
DEV: assert(isNumber(y),
|
|
748
|
+
DEV: assert(isNumber(x), 'image() 1st parameter must be a number')
|
|
749
|
+
DEV: assert(isNumber(y), 'image() 2nd parameter must be a number')
|
|
773
750
|
|
|
774
751
|
_ctx.drawImage(source, ~~x, ~~y)
|
|
775
752
|
},
|
|
@@ -782,12 +759,9 @@ export default function litecanvas(settings = {}) {
|
|
|
782
759
|
* @param {string} pixels
|
|
783
760
|
*/
|
|
784
761
|
spr(x, y, pixels) {
|
|
785
|
-
DEV: assert(isNumber(x),
|
|
786
|
-
DEV: assert(isNumber(y),
|
|
787
|
-
DEV: assert(
|
|
788
|
-
'string' === typeof pixels,
|
|
789
|
-
loggerPrefix + 'spr() 3rd param must be a string'
|
|
790
|
-
)
|
|
762
|
+
DEV: assert(isNumber(x), 'spr() 1st parameter must be a number')
|
|
763
|
+
DEV: assert(isNumber(y), 'spr() 2nd parameter must be a number')
|
|
764
|
+
DEV: assert('string' === typeof pixels, 'spr() 3rd parameter must be a string')
|
|
791
765
|
|
|
792
766
|
const rows = pixels.trim().split('\n')
|
|
793
767
|
|
|
@@ -817,24 +791,21 @@ export default function litecanvas(settings = {}) {
|
|
|
817
791
|
paint(width, height, callback, options = {}) {
|
|
818
792
|
DEV: assert(
|
|
819
793
|
isNumber(width) && width >= 1,
|
|
820
|
-
|
|
794
|
+
'paint() 1st parameter must be a positive number'
|
|
821
795
|
)
|
|
822
796
|
DEV: assert(
|
|
823
797
|
isNumber(height) && height >= 1,
|
|
824
|
-
|
|
825
|
-
)
|
|
826
|
-
DEV: assert(
|
|
827
|
-
'function' === typeof callback,
|
|
828
|
-
loggerPrefix + 'paint() 3rd param must be a function'
|
|
798
|
+
'paint() 2nd parameter must be a positive number'
|
|
829
799
|
)
|
|
800
|
+
DEV: assert('function' === typeof callback, 'paint() 3rd parameter must be a function')
|
|
830
801
|
DEV: assert(
|
|
831
802
|
(options && null == options.scale) ||
|
|
832
803
|
(isNumber(options.scale) && options.scale > 0),
|
|
833
|
-
|
|
804
|
+
'paint() 4th parameter (options.scale) must be a positive number'
|
|
834
805
|
)
|
|
835
806
|
DEV: assert(
|
|
836
807
|
(options && null == options.canvas) || options.canvas instanceof OffscreenCanvas,
|
|
837
|
-
|
|
808
|
+
'paint() 4th parameter (options.canvas) must be an OffscreenCanvas'
|
|
838
809
|
)
|
|
839
810
|
|
|
840
811
|
const /** @type {OffscreenCanvas} */
|
|
@@ -867,7 +838,7 @@ export default function litecanvas(settings = {}) {
|
|
|
867
838
|
null == context ||
|
|
868
839
|
context instanceof CanvasRenderingContext2D ||
|
|
869
840
|
context instanceof OffscreenCanvasRenderingContext2D,
|
|
870
|
-
|
|
841
|
+
'ctx() 1st parameter must be an [Offscreen]CanvasRenderingContext2D'
|
|
871
842
|
)
|
|
872
843
|
|
|
873
844
|
if (context) {
|
|
@@ -901,8 +872,8 @@ export default function litecanvas(settings = {}) {
|
|
|
901
872
|
* @param {number} y
|
|
902
873
|
*/
|
|
903
874
|
translate(x, y) {
|
|
904
|
-
DEV: assert(isNumber(x),
|
|
905
|
-
DEV: assert(isNumber(y),
|
|
875
|
+
DEV: assert(isNumber(x), 'translate() 1st parameter must be a number')
|
|
876
|
+
DEV: assert(isNumber(y), 'translate() 2nd parameter must be a number')
|
|
906
877
|
|
|
907
878
|
_ctx.translate(~~x, ~~y)
|
|
908
879
|
},
|
|
@@ -914,8 +885,8 @@ export default function litecanvas(settings = {}) {
|
|
|
914
885
|
* @param {number} [y]
|
|
915
886
|
*/
|
|
916
887
|
scale(x, y = x) {
|
|
917
|
-
DEV: assert(isNumber(x),
|
|
918
|
-
DEV: assert(isNumber(y),
|
|
888
|
+
DEV: assert(isNumber(x), 'scale() 1st parameter must be a number')
|
|
889
|
+
DEV: assert(isNumber(y), 'scale() 2nd parameter must be a number')
|
|
919
890
|
|
|
920
891
|
_ctx.scale(x, y)
|
|
921
892
|
},
|
|
@@ -926,7 +897,7 @@ export default function litecanvas(settings = {}) {
|
|
|
926
897
|
* @param {number} radians
|
|
927
898
|
*/
|
|
928
899
|
rotate(radians) {
|
|
929
|
-
DEV: assert(isNumber(radians),
|
|
900
|
+
DEV: assert(isNumber(radians), 'rotate() 1st parameter must be a number')
|
|
930
901
|
|
|
931
902
|
_ctx.rotate(radians)
|
|
932
903
|
},
|
|
@@ -938,7 +909,7 @@ export default function litecanvas(settings = {}) {
|
|
|
938
909
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalAlpha
|
|
939
910
|
*/
|
|
940
911
|
alpha(value) {
|
|
941
|
-
DEV: assert(isNumber(value),
|
|
912
|
+
DEV: assert(isNumber(value), 'alpha() 1st parameter must be a number')
|
|
942
913
|
|
|
943
914
|
_ctx.globalAlpha = instance.clamp(value, 0, 1)
|
|
944
915
|
},
|
|
@@ -951,7 +922,7 @@ export default function litecanvas(settings = {}) {
|
|
|
951
922
|
fill(color) {
|
|
952
923
|
DEV: assert(
|
|
953
924
|
null == color || (isNumber(color) && color >= 0),
|
|
954
|
-
|
|
925
|
+
'fill() 1st parameter must be a positive number or zero'
|
|
955
926
|
)
|
|
956
927
|
|
|
957
928
|
_ctx.fillStyle = getColor(color)
|
|
@@ -966,7 +937,7 @@ export default function litecanvas(settings = {}) {
|
|
|
966
937
|
stroke(color) {
|
|
967
938
|
DEV: assert(
|
|
968
939
|
null == color || (isNumber(color) && color >= 0),
|
|
969
|
-
|
|
940
|
+
'stroke() 1st parameter must be a positive number or zero'
|
|
970
941
|
)
|
|
971
942
|
|
|
972
943
|
_ctx.strokeStyle = getColor(color)
|
|
@@ -982,7 +953,7 @@ export default function litecanvas(settings = {}) {
|
|
|
982
953
|
clip(callback) {
|
|
983
954
|
DEV: assert(
|
|
984
955
|
'function' === typeof callback,
|
|
985
|
-
|
|
956
|
+
'clip() 1st parameter must be a function (ctx) => void'
|
|
986
957
|
)
|
|
987
958
|
|
|
988
959
|
beginPath(_ctx)
|
|
@@ -995,7 +966,7 @@ export default function litecanvas(settings = {}) {
|
|
|
995
966
|
* Play a sound effects using ZzFX library.
|
|
996
967
|
* If the first argument is omitted, plays an default sound.
|
|
997
968
|
*
|
|
998
|
-
* @param {number[]} [zzfxParams] a ZzFX array of
|
|
969
|
+
* @param {number[]} [zzfxParams] a ZzFX array of parameters
|
|
999
970
|
* @param {number} [pitchSlide] a value to increment/decrement the pitch
|
|
1000
971
|
* @param {number} [volumeFactor] the volume factor
|
|
1001
972
|
* @returns {number[] | boolean} The sound that was played or `false`
|
|
@@ -1005,15 +976,15 @@ export default function litecanvas(settings = {}) {
|
|
|
1005
976
|
sfx(zzfxParams, pitchSlide, volumeFactor) {
|
|
1006
977
|
DEV: assert(
|
|
1007
978
|
null == zzfxParams || Array.isArray(zzfxParams),
|
|
1008
|
-
|
|
979
|
+
'sfx() 1st parameter must be an array'
|
|
1009
980
|
)
|
|
1010
981
|
DEV: assert(
|
|
1011
982
|
null == pitchSlide || isNumber(pitchSlide),
|
|
1012
|
-
|
|
983
|
+
'sfx() 2nd parameter must be a number'
|
|
1013
984
|
)
|
|
1014
985
|
DEV: assert(
|
|
1015
986
|
null == volumeFactor || isNumber(volumeFactor),
|
|
1016
|
-
|
|
987
|
+
'sfx() 3rd parameter must be a number'
|
|
1017
988
|
)
|
|
1018
989
|
|
|
1019
990
|
if (
|
|
@@ -1026,9 +997,9 @@ export default function litecanvas(settings = {}) {
|
|
|
1026
997
|
zzfxParams ||= _defaultSound
|
|
1027
998
|
|
|
1028
999
|
// if has other arguments, copy the sound to not change the original
|
|
1029
|
-
if (pitchSlide || volumeFactor) {
|
|
1000
|
+
if (pitchSlide || volumeFactor >= 0) {
|
|
1030
1001
|
zzfxParams = zzfxParams.slice()
|
|
1031
|
-
zzfxParams[0] =
|
|
1002
|
+
zzfxParams[0] = volumeFactor * (zzfxParams[0] || 1)
|
|
1032
1003
|
zzfxParams[10] = ~~zzfxParams[10] + pitchSlide
|
|
1033
1004
|
}
|
|
1034
1005
|
|
|
@@ -1046,7 +1017,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1046
1017
|
volume(value) {
|
|
1047
1018
|
DEV: assert(
|
|
1048
1019
|
isNumber(value) && value >= 0,
|
|
1049
|
-
|
|
1020
|
+
'volume() 1st parameter must be a positive number or zero'
|
|
1050
1021
|
)
|
|
1051
1022
|
|
|
1052
1023
|
root.zzfxV = value
|
|
@@ -1069,12 +1040,9 @@ export default function litecanvas(settings = {}) {
|
|
|
1069
1040
|
use(callback, config = {}) {
|
|
1070
1041
|
DEV: assert(
|
|
1071
1042
|
'function' === typeof callback,
|
|
1072
|
-
|
|
1073
|
-
)
|
|
1074
|
-
DEV: assert(
|
|
1075
|
-
'object' === typeof config,
|
|
1076
|
-
loggerPrefix + 'use() 2nd param must be an object'
|
|
1043
|
+
'use() 1st parameter must be a function (instance, config) => any'
|
|
1077
1044
|
)
|
|
1045
|
+
DEV: assert('object' === typeof config, 'use() 2nd parameter must be an object')
|
|
1078
1046
|
|
|
1079
1047
|
loadPlugin(callback, config)
|
|
1080
1048
|
},
|
|
@@ -1086,14 +1054,8 @@ export default function litecanvas(settings = {}) {
|
|
|
1086
1054
|
* @param {Function} callback the function that is called when the event occurs
|
|
1087
1055
|
*/
|
|
1088
1056
|
listen: (eventName, callback) => {
|
|
1089
|
-
DEV: assert(
|
|
1090
|
-
|
|
1091
|
-
loggerPrefix + 'listen() 1st param must be a string'
|
|
1092
|
-
)
|
|
1093
|
-
DEV: assert(
|
|
1094
|
-
'function' === typeof callback,
|
|
1095
|
-
loggerPrefix + 'listen() 2nd param must be a function'
|
|
1096
|
-
)
|
|
1057
|
+
DEV: assert('string' === typeof eventName, 'listen() 1st parameter must be a string')
|
|
1058
|
+
DEV: assert('function' === typeof callback, 'listen() 2nd parameter must be a function')
|
|
1097
1059
|
|
|
1098
1060
|
eventName = lowerCase(eventName)
|
|
1099
1061
|
|
|
@@ -1108,13 +1070,10 @@ export default function litecanvas(settings = {}) {
|
|
|
1108
1070
|
* @param {Function} callback the function that is called when the event occurs
|
|
1109
1071
|
*/
|
|
1110
1072
|
unlisten: (eventName, callback) => {
|
|
1111
|
-
DEV: assert(
|
|
1112
|
-
'string' === typeof eventName,
|
|
1113
|
-
loggerPrefix + 'unlisten() 1st param must be a string'
|
|
1114
|
-
)
|
|
1073
|
+
DEV: assert('string' === typeof eventName, 'unlisten() 1st parameter must be a string')
|
|
1115
1074
|
DEV: assert(
|
|
1116
1075
|
'function' === typeof callback,
|
|
1117
|
-
|
|
1076
|
+
'unlisten() 2nd parameter must be a function'
|
|
1118
1077
|
)
|
|
1119
1078
|
|
|
1120
1079
|
eventName = lowerCase(eventName)
|
|
@@ -1139,10 +1098,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1139
1098
|
* @returns {any} always returns the second argument
|
|
1140
1099
|
*/
|
|
1141
1100
|
emit(eventName, arg1, arg2, arg3, arg4) {
|
|
1142
|
-
DEV: assert(
|
|
1143
|
-
'string' === typeof eventName,
|
|
1144
|
-
loggerPrefix + 'emit() 1st param must be a string'
|
|
1145
|
-
)
|
|
1101
|
+
DEV: assert('string' === typeof eventName, 'emit() 1st parameter must be a string')
|
|
1146
1102
|
|
|
1147
1103
|
if (_initialized) {
|
|
1148
1104
|
eventName = lowerCase(eventName)
|
|
@@ -1177,11 +1133,11 @@ export default function litecanvas(settings = {}) {
|
|
|
1177
1133
|
pal(colors, textColor = 3) {
|
|
1178
1134
|
DEV: assert(
|
|
1179
1135
|
null == colors || (Array.isArray(colors) && colors.length > 0),
|
|
1180
|
-
|
|
1136
|
+
'pal() 1st parameter must be null or an array of colors'
|
|
1181
1137
|
)
|
|
1182
1138
|
DEV: assert(
|
|
1183
1139
|
isNumber(textColor) && textColor >= 0,
|
|
1184
|
-
|
|
1140
|
+
'pal() 2nd parameter must be a positive number or zero'
|
|
1185
1141
|
)
|
|
1186
1142
|
|
|
1187
1143
|
_colorPalette = colors || defaultPalette
|
|
@@ -1204,11 +1160,11 @@ export default function litecanvas(settings = {}) {
|
|
|
1204
1160
|
palc(a, b) {
|
|
1205
1161
|
DEV: assert(
|
|
1206
1162
|
null == a || (isNumber(a) && a >= 0),
|
|
1207
|
-
|
|
1163
|
+
'palc() 1st parameter must be a positive number'
|
|
1208
1164
|
)
|
|
1209
1165
|
DEV: assert(
|
|
1210
1166
|
isNumber(a) ? isNumber(b) && b >= 0 : null == b,
|
|
1211
|
-
|
|
1167
|
+
'palc() 2nd parameter must be a positive number'
|
|
1212
1168
|
)
|
|
1213
1169
|
|
|
1214
1170
|
if (a == null) {
|
|
@@ -1230,11 +1186,10 @@ export default function litecanvas(settings = {}) {
|
|
|
1230
1186
|
* @param {any} value the property value
|
|
1231
1187
|
*/
|
|
1232
1188
|
def(key, value) {
|
|
1233
|
-
DEV: assert('string' === typeof key,
|
|
1189
|
+
DEV: assert('string' === typeof key, 'def() 1st parameter must be a string')
|
|
1234
1190
|
DEV: if (null == value) {
|
|
1235
1191
|
console.warn(
|
|
1236
|
-
|
|
1237
|
-
`def() changed the key "${key}" to null (previous value was ${instance[key]})`
|
|
1192
|
+
`[litecanvas] def() changed the key "${key}" to null (previous value was ${instance[key]})`
|
|
1238
1193
|
)
|
|
1239
1194
|
}
|
|
1240
1195
|
|
|
@@ -1254,7 +1209,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1254
1209
|
timescale(value) {
|
|
1255
1210
|
DEV: assert(
|
|
1256
1211
|
isNumber(value) && value >= 0,
|
|
1257
|
-
|
|
1212
|
+
'timescale() 1st parameter must be a positive number or zero'
|
|
1258
1213
|
)
|
|
1259
1214
|
|
|
1260
1215
|
_timeScale = value
|
|
@@ -1268,7 +1223,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1268
1223
|
framerate(value) {
|
|
1269
1224
|
DEV: assert(
|
|
1270
1225
|
isNumber(value) && value >= 1,
|
|
1271
|
-
|
|
1226
|
+
'framerate() 1st parameter must be a positive number'
|
|
1272
1227
|
)
|
|
1273
1228
|
|
|
1274
1229
|
_fpsInterval = 1000 / ~~value
|
|
@@ -1281,7 +1236,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1281
1236
|
* @returns {any}
|
|
1282
1237
|
*/
|
|
1283
1238
|
stat(index) {
|
|
1284
|
-
DEV: assert(isNumber(index),
|
|
1239
|
+
DEV: assert(isNumber(index), 'stat() 1st parameter must be a number')
|
|
1285
1240
|
|
|
1286
1241
|
const internals = [
|
|
1287
1242
|
// 0
|
|
@@ -1329,9 +1284,8 @@ export default function litecanvas(settings = {}) {
|
|
|
1329
1284
|
|
|
1330
1285
|
DEV: assert(
|
|
1331
1286
|
index >= 0 && index < internals.length,
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
(internals.length - 1)
|
|
1287
|
+
|
|
1288
|
+
'stat() 1st parameter must be a number between 0 and ' + (internals.length - 1)
|
|
1335
1289
|
)
|
|
1336
1290
|
|
|
1337
1291
|
return internals[index]
|
|
@@ -1354,8 +1308,8 @@ export default function litecanvas(settings = {}) {
|
|
|
1354
1308
|
resume() {
|
|
1355
1309
|
DEV: assert(
|
|
1356
1310
|
_initialized,
|
|
1357
|
-
|
|
1358
|
-
|
|
1311
|
+
|
|
1312
|
+
'resume() cannot be called before the "init" event and neither after the quit() function'
|
|
1359
1313
|
)
|
|
1360
1314
|
if (_initialized && _paused) {
|
|
1361
1315
|
startGameLoop()
|
|
@@ -1402,7 +1356,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1402
1356
|
delete root.ENGINE
|
|
1403
1357
|
}
|
|
1404
1358
|
|
|
1405
|
-
DEV: console.warn(
|
|
1359
|
+
DEV: console.warn('[litecanvas] quit() terminated a Litecanvas instance.')
|
|
1406
1360
|
},
|
|
1407
1361
|
}
|
|
1408
1362
|
|
|
@@ -1579,10 +1533,8 @@ export default function litecanvas(settings = {}) {
|
|
|
1579
1533
|
preventDefault(ev)
|
|
1580
1534
|
const existing = []
|
|
1581
1535
|
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
existing.push(touch.identifier + 1)
|
|
1585
|
-
}
|
|
1536
|
+
for (const touch of ev.targetTouches) {
|
|
1537
|
+
existing.push(touch.identifier + 1)
|
|
1586
1538
|
}
|
|
1587
1539
|
|
|
1588
1540
|
for (const [id, tap] of _taps) {
|
|
@@ -1653,7 +1605,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1653
1605
|
(key) => {
|
|
1654
1606
|
DEV: assert(
|
|
1655
1607
|
null == key || 'string' === typeof key,
|
|
1656
|
-
|
|
1608
|
+
'iskeydown() 1st parameter must be a string or undefined'
|
|
1657
1609
|
)
|
|
1658
1610
|
return keyCheck(_keysDown, key)
|
|
1659
1611
|
}
|
|
@@ -1668,7 +1620,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1668
1620
|
(key) => {
|
|
1669
1621
|
DEV: assert(
|
|
1670
1622
|
null == key || 'string' === typeof key,
|
|
1671
|
-
|
|
1623
|
+
'iskeypressed() 1st parameter must be a string or undefined'
|
|
1672
1624
|
)
|
|
1673
1625
|
return keyCheck(_keysPress, key)
|
|
1674
1626
|
}
|
|
@@ -1731,10 +1683,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1731
1683
|
|
|
1732
1684
|
if ('string' === typeof settings.canvas) {
|
|
1733
1685
|
_canvas = d.querySelector(settings.canvas)
|
|
1734
|
-
DEV: assert(
|
|
1735
|
-
null != _canvas,
|
|
1736
|
-
loggerPrefix + 'litecanvas() option "canvas" is an invalid CSS selector'
|
|
1737
|
-
)
|
|
1686
|
+
DEV: assert(null != _canvas, 'litecanvas() option "canvas" is an invalid CSS selector')
|
|
1738
1687
|
} else {
|
|
1739
1688
|
_canvas = settings.canvas
|
|
1740
1689
|
}
|
|
@@ -1743,8 +1692,8 @@ export default function litecanvas(settings = {}) {
|
|
|
1743
1692
|
|
|
1744
1693
|
DEV: assert(
|
|
1745
1694
|
_canvas instanceof HTMLElement && 'CANVAS' === _canvas.tagName,
|
|
1746
|
-
|
|
1747
|
-
|
|
1695
|
+
|
|
1696
|
+
'litecanvas() option "canvas" should be a canvas element or string (CSS selector of a canvas)'
|
|
1748
1697
|
)
|
|
1749
1698
|
|
|
1750
1699
|
_ctx = _canvas.getContext('2d')
|
|
@@ -1766,16 +1715,16 @@ export default function litecanvas(settings = {}) {
|
|
|
1766
1715
|
function resizeCanvas() {
|
|
1767
1716
|
DEV: assert(
|
|
1768
1717
|
null == settings.width || (isNumber(settings.width) && settings.width > 0),
|
|
1769
|
-
|
|
1718
|
+
'litecanvas() option "width" should be a positive number when defined'
|
|
1770
1719
|
)
|
|
1771
1720
|
DEV: assert(
|
|
1772
1721
|
null == settings.height || (isNumber(settings.height) && settings.height > 0),
|
|
1773
|
-
|
|
1722
|
+
'litecanvas() option "height" should be a positive number when defined'
|
|
1774
1723
|
)
|
|
1775
1724
|
DEV: assert(
|
|
1776
1725
|
null == settings.height || (settings.width > 0 && settings.height > 0),
|
|
1777
|
-
|
|
1778
|
-
|
|
1726
|
+
|
|
1727
|
+
'litecanvas() option "width" is required when the option "height" is defined'
|
|
1779
1728
|
)
|
|
1780
1729
|
|
|
1781
1730
|
const width = settings.width > 0 ? settings.width : innerWidth,
|
|
@@ -1836,7 +1785,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1836
1785
|
|
|
1837
1786
|
DEV: assert(
|
|
1838
1787
|
null == pluginData || 'object' === typeof pluginData,
|
|
1839
|
-
|
|
1788
|
+
'litecanvas() plugins should return an object or nothing'
|
|
1840
1789
|
)
|
|
1841
1790
|
|
|
1842
1791
|
for (const key in pluginData) {
|
|
@@ -1861,8 +1810,8 @@ export default function litecanvas(settings = {}) {
|
|
|
1861
1810
|
root.ENGINE = instance
|
|
1862
1811
|
}
|
|
1863
1812
|
|
|
1864
|
-
DEV: console.info(
|
|
1865
|
-
DEV: console.debug(
|
|
1813
|
+
DEV: console.info(`[litecanvas] version ${version} started`)
|
|
1814
|
+
DEV: console.debug(`[litecanvas] litecanvas() options =`, settings)
|
|
1866
1815
|
|
|
1867
1816
|
// setup the canvas
|
|
1868
1817
|
setupCanvas()
|