litecanvas 0.300.0 → 0.301.1
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 +162 -152
- package/dist/dist.js +11 -6
- package/dist/dist.min.js +1 -1
- package/package.json +1 -1
- package/src/index.js +170 -145
- package/src/version.js +1 -1
- package/types/global.d.ts +8 -0
- package/types/types.d.ts +8 -0
package/src/index.js
CHANGED
|
@@ -45,7 +45,7 @@ export default function litecanvas(settings = {}) {
|
|
|
45
45
|
|
|
46
46
|
DEV: assert(
|
|
47
47
|
null == settings || 'object' === typeof settings,
|
|
48
|
-
'litecanvas() 1st
|
|
48
|
+
'litecanvas() 1st argument must be a object'
|
|
49
49
|
)
|
|
50
50
|
|
|
51
51
|
// setup the settings default values
|
|
@@ -53,7 +53,7 @@ export default function litecanvas(settings = {}) {
|
|
|
53
53
|
|
|
54
54
|
let _loop = settings.loop,
|
|
55
55
|
/** @type {boolean} */
|
|
56
|
-
_initialized
|
|
56
|
+
_initialized,
|
|
57
57
|
/** @type {boolean} */
|
|
58
58
|
_paused,
|
|
59
59
|
/** @type {HTMLCanvasElement} */
|
|
@@ -131,9 +131,9 @@ export default function litecanvas(settings = {}) {
|
|
|
131
131
|
* @tutorial https://gamedev.net/tutorials/programming/general-and-gameplay-programming/a-brief-introduction-to-lerp-r4954/
|
|
132
132
|
*/
|
|
133
133
|
lerp: (start, end, t) => {
|
|
134
|
-
DEV: assert(isNumber(start), 'lerp() 1st
|
|
135
|
-
DEV: assert(isNumber(end), 'lerp() 2nd
|
|
136
|
-
DEV: assert(isNumber(t), 'lerp() 3rd
|
|
134
|
+
DEV: assert(isNumber(start), 'lerp() 1st argument must be a number')
|
|
135
|
+
DEV: assert(isNumber(end), 'lerp() 2nd argument must be a number')
|
|
136
|
+
DEV: assert(isNumber(t), 'lerp() 3rd argument must be a number')
|
|
137
137
|
|
|
138
138
|
return start + t * (end - start)
|
|
139
139
|
},
|
|
@@ -145,7 +145,7 @@ export default function litecanvas(settings = {}) {
|
|
|
145
145
|
* @returns {number} the value in radians
|
|
146
146
|
*/
|
|
147
147
|
deg2rad: (degs) => {
|
|
148
|
-
DEV: assert(isNumber(degs), 'deg2rad() 1st
|
|
148
|
+
DEV: assert(isNumber(degs), 'deg2rad() 1st argument must be a number')
|
|
149
149
|
|
|
150
150
|
return (math.PI / 180) * degs
|
|
151
151
|
},
|
|
@@ -157,7 +157,7 @@ export default function litecanvas(settings = {}) {
|
|
|
157
157
|
* @returns {number} the value in degrees
|
|
158
158
|
*/
|
|
159
159
|
rad2deg: (rads) => {
|
|
160
|
-
DEV: assert(isNumber(rads), 'rad2deg() 1st
|
|
160
|
+
DEV: assert(isNumber(rads), 'rad2deg() 1st argument must be a number')
|
|
161
161
|
|
|
162
162
|
return (180 / math.PI) * rads
|
|
163
163
|
},
|
|
@@ -172,8 +172,8 @@ export default function litecanvas(settings = {}) {
|
|
|
172
172
|
* @returns {number} the remainder
|
|
173
173
|
*/
|
|
174
174
|
mod(a, b) {
|
|
175
|
-
DEV: assert(isNumber(a), 'mod() 1st
|
|
176
|
-
DEV: assert(isNumber(b) && b >= 0, 'mod() 2nd
|
|
175
|
+
DEV: assert(isNumber(a), 'mod() 1st argument must be a number')
|
|
176
|
+
DEV: assert(isNumber(b) && b >= 0, 'mod() 2nd argument must be a non-negative number')
|
|
177
177
|
|
|
178
178
|
return ((a % b) + b) % b || 0
|
|
179
179
|
},
|
|
@@ -188,10 +188,10 @@ export default function litecanvas(settings = {}) {
|
|
|
188
188
|
* @returns {number} rounded number.
|
|
189
189
|
*/
|
|
190
190
|
round: (n, precision = 0) => {
|
|
191
|
-
DEV: assert(isNumber(n), 'round() 1st
|
|
191
|
+
DEV: assert(isNumber(n), 'round() 1st argument must be a number')
|
|
192
192
|
DEV: assert(
|
|
193
193
|
isNumber(precision) && precision >= 0,
|
|
194
|
-
'round() 2nd
|
|
194
|
+
'round() 2nd argument must be a non-negative number'
|
|
195
195
|
)
|
|
196
196
|
|
|
197
197
|
if (!precision) {
|
|
@@ -210,10 +210,10 @@ export default function litecanvas(settings = {}) {
|
|
|
210
210
|
* @returns {number}
|
|
211
211
|
*/
|
|
212
212
|
clamp: (value, min, max) => {
|
|
213
|
-
DEV: assert(isNumber(value), 'clamp() 1st
|
|
214
|
-
DEV: assert(isNumber(min), 'clamp() 2nd
|
|
215
|
-
DEV: assert(isNumber(max), 'clamp() 3rd
|
|
216
|
-
DEV: assert(max >= min, 'clamp() the 2nd
|
|
213
|
+
DEV: assert(isNumber(value), 'clamp() 1st argument must be a number')
|
|
214
|
+
DEV: assert(isNumber(min), 'clamp() 2nd argument must be a number')
|
|
215
|
+
DEV: assert(isNumber(max), 'clamp() 3rd argument must be a number')
|
|
216
|
+
DEV: assert(max >= min, 'clamp() the 2nd argument must be less than the 3rd argument')
|
|
217
217
|
|
|
218
218
|
if (value < min) return min
|
|
219
219
|
if (value > max) return max
|
|
@@ -230,10 +230,10 @@ export default function litecanvas(settings = {}) {
|
|
|
230
230
|
* @returns {number}
|
|
231
231
|
*/
|
|
232
232
|
dist: (x1, y1, x2, y2) => {
|
|
233
|
-
DEV: assert(isNumber(x1), 'dist() 1st
|
|
234
|
-
DEV: assert(isNumber(y1), 'dist() 2nd
|
|
235
|
-
DEV: assert(isNumber(x2), 'dist() 3rd
|
|
236
|
-
DEV: assert(isNumber(y2), 'dist() 4th
|
|
233
|
+
DEV: assert(isNumber(x1), 'dist() 1st argument must be a number')
|
|
234
|
+
DEV: assert(isNumber(y1), 'dist() 2nd argument must be a number')
|
|
235
|
+
DEV: assert(isNumber(x2), 'dist() 3rd argument must be a number')
|
|
236
|
+
DEV: assert(isNumber(y2), 'dist() 4th argument must be a number')
|
|
237
237
|
|
|
238
238
|
return math.hypot(x2 - x1, y2 - y1)
|
|
239
239
|
},
|
|
@@ -247,10 +247,10 @@ export default function litecanvas(settings = {}) {
|
|
|
247
247
|
* @returns {number}
|
|
248
248
|
*/
|
|
249
249
|
wrap: (value, min, max) => {
|
|
250
|
-
DEV: assert(isNumber(value), 'wrap() 1st
|
|
251
|
-
DEV: assert(isNumber(min), 'wrap() 2nd
|
|
252
|
-
DEV: assert(isNumber(max), 'wrap() 3rd
|
|
253
|
-
DEV: assert(max > min, 'wrap() the 2nd
|
|
250
|
+
DEV: assert(isNumber(value), 'wrap() 1st argument must be a number')
|
|
251
|
+
DEV: assert(isNumber(min), 'wrap() 2nd argument must be a number')
|
|
252
|
+
DEV: assert(isNumber(max), 'wrap() 3rd argument must be a number')
|
|
253
|
+
DEV: assert(max > min, 'wrap() the 2nd argument must be less than the 3rd argument')
|
|
254
254
|
|
|
255
255
|
return value - (max - min) * math.floor((value - min) / (max - min))
|
|
256
256
|
},
|
|
@@ -267,14 +267,14 @@ export default function litecanvas(settings = {}) {
|
|
|
267
267
|
* @returns {number} the remapped number
|
|
268
268
|
*/
|
|
269
269
|
map(value, start1, stop1, start2, stop2, withinBounds) {
|
|
270
|
-
DEV: assert(isNumber(value), 'map() 1st
|
|
271
|
-
DEV: assert(isNumber(start1), 'map() 2nd
|
|
272
|
-
DEV: assert(isNumber(stop1), 'map() 3rd
|
|
273
|
-
DEV: assert(isNumber(start2), 'map() 4th
|
|
274
|
-
DEV: assert(isNumber(stop2), 'map() 5th
|
|
270
|
+
DEV: assert(isNumber(value), 'map() 1st argument must be a number')
|
|
271
|
+
DEV: assert(isNumber(start1), 'map() 2nd argument must be a number')
|
|
272
|
+
DEV: assert(isNumber(stop1), 'map() 3rd argument must be a number')
|
|
273
|
+
DEV: assert(isNumber(start2), 'map() 4th argument must be a number')
|
|
274
|
+
DEV: assert(isNumber(stop2), 'map() 5th argument must be a number')
|
|
275
275
|
DEV: assert(
|
|
276
276
|
stop1 !== start1,
|
|
277
|
-
'map() the 2nd
|
|
277
|
+
'map() the 2nd argument must be different than the 3rd argument'
|
|
278
278
|
)
|
|
279
279
|
|
|
280
280
|
// prettier-ignore
|
|
@@ -293,12 +293,12 @@ export default function litecanvas(settings = {}) {
|
|
|
293
293
|
* @returns {number} the normalized number.
|
|
294
294
|
*/
|
|
295
295
|
norm: (value, start, stop) => {
|
|
296
|
-
DEV: assert(isNumber(value), 'norm() 1st
|
|
297
|
-
DEV: assert(isNumber(start), 'norm() 2nd
|
|
298
|
-
DEV: assert(isNumber(stop), 'norm() 3rd
|
|
296
|
+
DEV: assert(isNumber(value), 'norm() 1st argument must be a number')
|
|
297
|
+
DEV: assert(isNumber(start), 'norm() 2nd argument must be a number')
|
|
298
|
+
DEV: assert(isNumber(stop), 'norm() 3rd argument must be a number')
|
|
299
299
|
DEV: assert(
|
|
300
300
|
start !== stop,
|
|
301
|
-
'norm() the 2nd
|
|
301
|
+
'norm() the 2nd argument must be different than the 3rd argument'
|
|
302
302
|
)
|
|
303
303
|
|
|
304
304
|
return instance.map(value, start, stop, 0, 1)
|
|
@@ -314,9 +314,9 @@ export default function litecanvas(settings = {}) {
|
|
|
314
314
|
* @returns {number} the random number
|
|
315
315
|
*/
|
|
316
316
|
rand: (min = 0.0, max = 1.0) => {
|
|
317
|
-
DEV: assert(isNumber(min), 'rand() 1st
|
|
318
|
-
DEV: assert(isNumber(max), 'rand() 2nd
|
|
319
|
-
DEV: assert(max >= min, 'rand() the 1st
|
|
317
|
+
DEV: assert(isNumber(min), 'rand() 1st argument must be a number')
|
|
318
|
+
DEV: assert(isNumber(max), 'rand() 2nd argument must be a number')
|
|
319
|
+
DEV: assert(max >= min, 'rand() the 1st argument must be less than the 2nd argument')
|
|
320
320
|
|
|
321
321
|
const a = 1664525
|
|
322
322
|
const c = 1013904223
|
|
@@ -335,9 +335,9 @@ export default function litecanvas(settings = {}) {
|
|
|
335
335
|
* @returns {number} the random number
|
|
336
336
|
*/
|
|
337
337
|
randi: (min = 0, max = 1) => {
|
|
338
|
-
DEV: assert(isNumber(min), 'randi() 1st
|
|
339
|
-
DEV: assert(isNumber(max), 'randi() 2nd
|
|
340
|
-
DEV: assert(max >= min, 'randi() the 1st
|
|
338
|
+
DEV: assert(isNumber(min), 'randi() 1st argument must be a number')
|
|
339
|
+
DEV: assert(isNumber(max), 'randi() 2nd argument must be a number')
|
|
340
|
+
DEV: assert(max >= min, 'randi() the 1st argument must be less than the 2nd argument')
|
|
341
341
|
|
|
342
342
|
return ~~instance.rand(min, max + 1)
|
|
343
343
|
},
|
|
@@ -352,7 +352,7 @@ export default function litecanvas(settings = {}) {
|
|
|
352
352
|
rseed(value) {
|
|
353
353
|
DEV: assert(
|
|
354
354
|
isNumber(value) && value >= 0,
|
|
355
|
-
'rseed() 1st
|
|
355
|
+
'rseed() 1st argument must be a non-negative integer'
|
|
356
356
|
)
|
|
357
357
|
|
|
358
358
|
_rngSeed = ~~value
|
|
@@ -367,7 +367,7 @@ export default function litecanvas(settings = {}) {
|
|
|
367
367
|
cls(color) {
|
|
368
368
|
DEV: assert(
|
|
369
369
|
null == color || (isNumber(color) && color >= 0),
|
|
370
|
-
'cls() 1st
|
|
370
|
+
'cls() 1st argument must be a non-negative number'
|
|
371
371
|
)
|
|
372
372
|
|
|
373
373
|
if (null == color) {
|
|
@@ -390,23 +390,23 @@ export default function litecanvas(settings = {}) {
|
|
|
390
390
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/roundRect
|
|
391
391
|
*/
|
|
392
392
|
rect(x, y, width, height, color, radii) {
|
|
393
|
-
DEV: assert(isNumber(x), 'rect() 1st
|
|
394
|
-
DEV: assert(isNumber(y), 'rect() 2nd
|
|
393
|
+
DEV: assert(isNumber(x), 'rect() 1st argument must be a number')
|
|
394
|
+
DEV: assert(isNumber(y), 'rect() 2nd argument must be a number')
|
|
395
395
|
DEV: assert(
|
|
396
396
|
isNumber(width) && width > 0,
|
|
397
|
-
'rect() 3rd
|
|
397
|
+
'rect() 3rd argument must be a positive number'
|
|
398
398
|
)
|
|
399
399
|
DEV: assert(
|
|
400
400
|
isNumber(height) && height >= 0,
|
|
401
|
-
'rect() 4th
|
|
401
|
+
'rect() 4th argument must be a non-negative number'
|
|
402
402
|
)
|
|
403
403
|
DEV: assert(
|
|
404
404
|
null == color || (isNumber(color) && color >= 0),
|
|
405
|
-
'rect() 5th
|
|
405
|
+
'rect() 5th argument must be a non-negative number'
|
|
406
406
|
)
|
|
407
407
|
DEV: assert(
|
|
408
408
|
null == radii || isNumber(radii) || (Array.isArray(radii) && radii.length >= 1),
|
|
409
|
-
'rect() 6th
|
|
409
|
+
'rect() 6th argument must be a number or array of numbers'
|
|
410
410
|
)
|
|
411
411
|
|
|
412
412
|
beginPath(_ctx)
|
|
@@ -432,24 +432,24 @@ export default function litecanvas(settings = {}) {
|
|
|
432
432
|
* @param {number|number[]} [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
|
|
433
433
|
*/
|
|
434
434
|
rectfill(x, y, width, height, color, radii) {
|
|
435
|
-
DEV: assert(isNumber(x), 'rectfill() 1st
|
|
436
|
-
DEV: assert(isNumber(y), 'rectfill() 2nd
|
|
435
|
+
DEV: assert(isNumber(x), 'rectfill() 1st argument must be a number')
|
|
436
|
+
DEV: assert(isNumber(y), 'rectfill() 2nd argument must be a number')
|
|
437
437
|
DEV: assert(
|
|
438
438
|
isNumber(width) && width >= 0,
|
|
439
|
-
'rectfill() 3rd
|
|
439
|
+
'rectfill() 3rd argument must be a non-negative number'
|
|
440
440
|
)
|
|
441
441
|
DEV: assert(
|
|
442
442
|
isNumber(height) && height >= 0,
|
|
443
|
-
'rectfill() 4th
|
|
443
|
+
'rectfill() 4th argument must be a non-negative number'
|
|
444
444
|
)
|
|
445
445
|
DEV: assert(
|
|
446
446
|
null == color || (isNumber(color) && color >= 0),
|
|
447
|
-
'rectfill() 5th
|
|
447
|
+
'rectfill() 5th argument must be a non-negative number'
|
|
448
448
|
)
|
|
449
449
|
DEV: assert(
|
|
450
450
|
null == radii || isNumber(radii) || (Array.isArray(radii) && radii.length >= 1),
|
|
451
451
|
|
|
452
|
-
'rectfill() 6th
|
|
452
|
+
'rectfill() 6th argument must be a number or array of at least 2 numbers'
|
|
453
453
|
)
|
|
454
454
|
|
|
455
455
|
beginPath(_ctx)
|
|
@@ -468,19 +468,19 @@ export default function litecanvas(settings = {}) {
|
|
|
468
468
|
* @param {number} [color=0] the color index
|
|
469
469
|
*/
|
|
470
470
|
oval(x, y, radiusX, radiusY, color) {
|
|
471
|
-
DEV: assert(isNumber(x), 'oval() 1st
|
|
472
|
-
DEV: assert(isNumber(y), 'oval() 2nd
|
|
471
|
+
DEV: assert(isNumber(x), 'oval() 1st argument must be a number')
|
|
472
|
+
DEV: assert(isNumber(y), 'oval() 2nd argument must be a number')
|
|
473
473
|
DEV: assert(
|
|
474
474
|
isNumber(radiusX) && radiusX >= 0,
|
|
475
|
-
'oval() 3rd
|
|
475
|
+
'oval() 3rd argument must be a non-negative number'
|
|
476
476
|
)
|
|
477
477
|
DEV: assert(
|
|
478
478
|
isNumber(radiusY) && radiusY >= 0,
|
|
479
|
-
'oval() 4th
|
|
479
|
+
'oval() 4th argument must be a non-negative number'
|
|
480
480
|
)
|
|
481
481
|
DEV: assert(
|
|
482
482
|
null == color || (isNumber(color) && color >= 0),
|
|
483
|
-
'oval() 5th
|
|
483
|
+
'oval() 5th argument must be a non-negative number'
|
|
484
484
|
)
|
|
485
485
|
|
|
486
486
|
beginPath(_ctx)
|
|
@@ -499,19 +499,19 @@ export default function litecanvas(settings = {}) {
|
|
|
499
499
|
* @param {number} [color=0] the color index
|
|
500
500
|
*/
|
|
501
501
|
ovalfill(x, y, radiusX, radiusY, color) {
|
|
502
|
-
DEV: assert(isNumber(x), 'ovalfill() 1st
|
|
503
|
-
DEV: assert(isNumber(y), 'ovalfill() 2nd
|
|
502
|
+
DEV: assert(isNumber(x), 'ovalfill() 1st argument must be a number')
|
|
503
|
+
DEV: assert(isNumber(y), 'ovalfill() 2nd argument must be a number')
|
|
504
504
|
DEV: assert(
|
|
505
505
|
isNumber(radiusX) && radiusX >= 0,
|
|
506
|
-
'ovalfill() 3rd
|
|
506
|
+
'ovalfill() 3rd argument must be a non-negative number'
|
|
507
507
|
)
|
|
508
508
|
DEV: assert(
|
|
509
509
|
isNumber(radiusY) && radiusY >= 0,
|
|
510
|
-
'ovalfill() 4th
|
|
510
|
+
'ovalfill() 4th argument must be a non-negative number'
|
|
511
511
|
)
|
|
512
512
|
DEV: assert(
|
|
513
513
|
null == color || (isNumber(color) && color >= 0),
|
|
514
|
-
'ovalfill() 5th
|
|
514
|
+
'ovalfill() 5th argument must be a non-negative number'
|
|
515
515
|
)
|
|
516
516
|
|
|
517
517
|
beginPath(_ctx)
|
|
@@ -529,15 +529,15 @@ export default function litecanvas(settings = {}) {
|
|
|
529
529
|
* @param {number} [color=0] the color index
|
|
530
530
|
*/
|
|
531
531
|
circ(x, y, radius, color) {
|
|
532
|
-
DEV: assert(isNumber(x), 'circ() 1st
|
|
533
|
-
DEV: assert(isNumber(y), 'circ() 2nd
|
|
532
|
+
DEV: assert(isNumber(x), 'circ() 1st argument must be a number')
|
|
533
|
+
DEV: assert(isNumber(y), 'circ() 2nd argument must be a number')
|
|
534
534
|
DEV: assert(
|
|
535
535
|
isNumber(radius) && radius >= 0,
|
|
536
|
-
'circ() 3rd
|
|
536
|
+
'circ() 3rd argument must be a non-negative number'
|
|
537
537
|
)
|
|
538
538
|
DEV: assert(
|
|
539
539
|
null == color || (isNumber(color) && color >= 0),
|
|
540
|
-
'circ() 4th
|
|
540
|
+
'circ() 4th argument must be a non-negative number'
|
|
541
541
|
)
|
|
542
542
|
|
|
543
543
|
instance.oval(x, y, radius, radius, color)
|
|
@@ -552,15 +552,15 @@ export default function litecanvas(settings = {}) {
|
|
|
552
552
|
* @param {number} [color=0] the color index
|
|
553
553
|
*/
|
|
554
554
|
circfill(x, y, radius, color) {
|
|
555
|
-
DEV: assert(isNumber(x), 'circfill() 1st
|
|
556
|
-
DEV: assert(isNumber(y), 'circfill() 2nd
|
|
555
|
+
DEV: assert(isNumber(x), 'circfill() 1st argument must be a number')
|
|
556
|
+
DEV: assert(isNumber(y), 'circfill() 2nd argument must be a number')
|
|
557
557
|
DEV: assert(
|
|
558
558
|
isNumber(radius) && radius >= 0,
|
|
559
|
-
'circfill() 3rd
|
|
559
|
+
'circfill() 3rd argument must be a non-negative number'
|
|
560
560
|
)
|
|
561
561
|
DEV: assert(
|
|
562
562
|
null == color || (isNumber(color) && color >= 0),
|
|
563
|
-
'circfill() 4th
|
|
563
|
+
'circfill() 4th argument must be a non-negative number'
|
|
564
564
|
)
|
|
565
565
|
|
|
566
566
|
instance.ovalfill(x, y, radius, radius, color)
|
|
@@ -573,10 +573,10 @@ export default function litecanvas(settings = {}) {
|
|
|
573
573
|
* @param {number[]} points an array of Xs and Ys coordinates
|
|
574
574
|
*/
|
|
575
575
|
shape(points) {
|
|
576
|
-
DEV: assert(Array.isArray(points), 'shape() 1st
|
|
576
|
+
DEV: assert(Array.isArray(points), 'shape() 1st argument must be an array of numbers')
|
|
577
577
|
DEV: assert(
|
|
578
578
|
points.length >= 6,
|
|
579
|
-
'shape() 1st
|
|
579
|
+
'shape() 1st argument must be an array with at least 6 numbers (3 points)'
|
|
580
580
|
)
|
|
581
581
|
|
|
582
582
|
beginPath(_ctx)
|
|
@@ -601,13 +601,13 @@ export default function litecanvas(settings = {}) {
|
|
|
601
601
|
* @param {number} [color=0] the color index
|
|
602
602
|
*/
|
|
603
603
|
line(x1, y1, x2, y2, color) {
|
|
604
|
-
DEV: assert(isNumber(x1), 'line() 1st
|
|
605
|
-
DEV: assert(isNumber(y1), 'line() 2nd
|
|
606
|
-
DEV: assert(isNumber(x2), 'line() 3rd
|
|
607
|
-
DEV: assert(isNumber(y2), 'line() 4th
|
|
604
|
+
DEV: assert(isNumber(x1), 'line() 1st argument must be a number')
|
|
605
|
+
DEV: assert(isNumber(y1), 'line() 2nd argument must be a number')
|
|
606
|
+
DEV: assert(isNumber(x2), 'line() 3rd argument must be a non-negative number')
|
|
607
|
+
DEV: assert(isNumber(y2), 'line() 4th argument must be a non-negative number')
|
|
608
608
|
DEV: assert(
|
|
609
609
|
null == color || (isNumber(color) && color >= 0),
|
|
610
|
-
'line() 5th
|
|
610
|
+
'line() 5th argument must be a non-negative number'
|
|
611
611
|
)
|
|
612
612
|
|
|
613
613
|
beginPath(_ctx)
|
|
@@ -630,7 +630,7 @@ export default function litecanvas(settings = {}) {
|
|
|
630
630
|
linewidth(value) {
|
|
631
631
|
DEV: assert(
|
|
632
632
|
isNumber(value) && value >= 0,
|
|
633
|
-
'linewidth() 1st
|
|
633
|
+
'linewidth() 1st argument must be a non-negative integer'
|
|
634
634
|
)
|
|
635
635
|
|
|
636
636
|
_ctx.lineWidth = ~~value
|
|
@@ -648,9 +648,9 @@ export default function litecanvas(settings = {}) {
|
|
|
648
648
|
linedash(segments, offset = 0) {
|
|
649
649
|
DEV: assert(
|
|
650
650
|
Array.isArray(segments) && segments.length > 0,
|
|
651
|
-
'linedash() 1st
|
|
651
|
+
'linedash() 1st argument must be an array of numbers'
|
|
652
652
|
)
|
|
653
|
-
DEV: assert(isNumber(offset), 'linedash() 2nd
|
|
653
|
+
DEV: assert(isNumber(offset), 'linedash() 2nd argument must be a number')
|
|
654
654
|
|
|
655
655
|
_ctx.setLineDash(segments)
|
|
656
656
|
_ctx.lineDashOffset = offset
|
|
@@ -667,13 +667,13 @@ export default function litecanvas(settings = {}) {
|
|
|
667
667
|
* @param {string} [fontStyle] can be "normal" (default), "italic" and/or "bold".
|
|
668
668
|
*/
|
|
669
669
|
text(x, y, message, color = _defaultTextColor, fontStyle = 'normal') {
|
|
670
|
-
DEV: assert(isNumber(x), 'text() 1st
|
|
671
|
-
DEV: assert(isNumber(y), 'text() 2nd
|
|
670
|
+
DEV: assert(isNumber(x), 'text() 1st argument must be a number')
|
|
671
|
+
DEV: assert(isNumber(y), 'text() 2nd argument must be a number')
|
|
672
672
|
DEV: assert(
|
|
673
673
|
null == color || (isNumber(color) && color >= 0),
|
|
674
|
-
'text() 4th
|
|
674
|
+
'text() 4th argument must be a non-negative number'
|
|
675
675
|
)
|
|
676
|
-
DEV: assert('string' === typeof fontStyle, 'text() 5th
|
|
676
|
+
DEV: assert('string' === typeof fontStyle, 'text() 5th argument must be a string')
|
|
677
677
|
|
|
678
678
|
_ctx.font = `${fontStyle} ${_fontSize}px ${_fontFamily}`
|
|
679
679
|
_ctx.fillStyle = getColor(color)
|
|
@@ -692,7 +692,7 @@ export default function litecanvas(settings = {}) {
|
|
|
692
692
|
* @param {number} value
|
|
693
693
|
*/
|
|
694
694
|
textgap(value) {
|
|
695
|
-
DEV: assert(isNumber(value), 'textgap() 1st
|
|
695
|
+
DEV: assert(isNumber(value), 'textgap() 1st argument must be a number')
|
|
696
696
|
|
|
697
697
|
_fontLineHeight = value
|
|
698
698
|
},
|
|
@@ -703,7 +703,7 @@ export default function litecanvas(settings = {}) {
|
|
|
703
703
|
* @param {string} family
|
|
704
704
|
*/
|
|
705
705
|
textfont(family) {
|
|
706
|
-
DEV: assert('string' === typeof family, 'textfont() 1st
|
|
706
|
+
DEV: assert('string' === typeof family, 'textfont() 1st argument must be a string')
|
|
707
707
|
|
|
708
708
|
_fontFamily = family
|
|
709
709
|
},
|
|
@@ -714,7 +714,7 @@ export default function litecanvas(settings = {}) {
|
|
|
714
714
|
* @param {number} size
|
|
715
715
|
*/
|
|
716
716
|
textsize(size) {
|
|
717
|
-
DEV: assert(isNumber(size), 'textsize() 1st
|
|
717
|
+
DEV: assert(isNumber(size), 'textsize() 1st argument must be a number')
|
|
718
718
|
|
|
719
719
|
_fontSize = size
|
|
720
720
|
},
|
|
@@ -731,7 +731,7 @@ export default function litecanvas(settings = {}) {
|
|
|
731
731
|
DEV: assert(
|
|
732
732
|
null == align || ['left', 'right', 'center', 'start', 'end'].includes(align),
|
|
733
733
|
|
|
734
|
-
'textalign() 1st
|
|
734
|
+
'textalign() 1st argument must be null or one of the following strings: center, left, right, start or end.'
|
|
735
735
|
)
|
|
736
736
|
DEV: assert(
|
|
737
737
|
null == baseline ||
|
|
@@ -739,7 +739,7 @@ export default function litecanvas(settings = {}) {
|
|
|
739
739
|
baseline
|
|
740
740
|
),
|
|
741
741
|
|
|
742
|
-
'textalign() 2nd
|
|
742
|
+
'textalign() 2nd argument must be null or one of the following strings: middle, top, bottom, hanging, alphabetic or ideographic.'
|
|
743
743
|
)
|
|
744
744
|
|
|
745
745
|
if (align) _ctx.textAlign = align
|
|
@@ -755,8 +755,8 @@ export default function litecanvas(settings = {}) {
|
|
|
755
755
|
* @param {CanvasImageSource} source
|
|
756
756
|
*/
|
|
757
757
|
image(x, y, source) {
|
|
758
|
-
DEV: assert(isNumber(x), 'image() 1st
|
|
759
|
-
DEV: assert(isNumber(y), 'image() 2nd
|
|
758
|
+
DEV: assert(isNumber(x), 'image() 1st argument must be a number')
|
|
759
|
+
DEV: assert(isNumber(y), 'image() 2nd argument must be a number')
|
|
760
760
|
|
|
761
761
|
_ctx.drawImage(source, ~~x, ~~y)
|
|
762
762
|
},
|
|
@@ -773,9 +773,9 @@ export default function litecanvas(settings = {}) {
|
|
|
773
773
|
* @param {string} pixels
|
|
774
774
|
*/
|
|
775
775
|
spr(x, y, pixels) {
|
|
776
|
-
DEV: assert(isNumber(x), 'spr() 1st
|
|
777
|
-
DEV: assert(isNumber(y), 'spr() 2nd
|
|
778
|
-
DEV: assert('string' === typeof pixels, 'spr() 3rd
|
|
776
|
+
DEV: assert(isNumber(x), 'spr() 1st argument must be a number')
|
|
777
|
+
DEV: assert(isNumber(y), 'spr() 2nd argument must be a number')
|
|
778
|
+
DEV: assert('string' === typeof pixels, 'spr() 3rd argument must be a string')
|
|
779
779
|
|
|
780
780
|
const rows = pixels
|
|
781
781
|
.replace(/[^\w.\n]/g, '')
|
|
@@ -804,23 +804,20 @@ export default function litecanvas(settings = {}) {
|
|
|
804
804
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
|
|
805
805
|
*/
|
|
806
806
|
paint(width, height, callback, options = {}) {
|
|
807
|
-
DEV: assert(
|
|
808
|
-
isNumber(width) && width >= 1,
|
|
809
|
-
'paint() 1st parameter must be a positive number'
|
|
810
|
-
)
|
|
807
|
+
DEV: assert(isNumber(width) && width >= 1, 'paint() 1st argument must be a number >= 1')
|
|
811
808
|
DEV: assert(
|
|
812
809
|
isNumber(height) && height >= 1,
|
|
813
|
-
'paint() 2nd
|
|
810
|
+
'paint() 2nd argument must be a number >= 1'
|
|
814
811
|
)
|
|
815
|
-
DEV: assert('function' === typeof callback, 'paint() 3rd
|
|
812
|
+
DEV: assert('function' === typeof callback, 'paint() 3rd argument must be a function')
|
|
816
813
|
DEV: assert(
|
|
817
814
|
(options && null == options.scale) ||
|
|
818
815
|
(isNumber(options.scale) && options.scale > 0),
|
|
819
|
-
'paint() 4th
|
|
816
|
+
'paint() 4th argument (options.scale) must be a positive number'
|
|
820
817
|
)
|
|
821
818
|
DEV: assert(
|
|
822
819
|
(options && null == options.canvas) || options.canvas instanceof OffscreenCanvas,
|
|
823
|
-
'paint() 4th
|
|
820
|
+
'paint() 4th argument (options.canvas) must be an OffscreenCanvas'
|
|
824
821
|
)
|
|
825
822
|
|
|
826
823
|
const /** @type {OffscreenCanvas} */
|
|
@@ -853,7 +850,7 @@ export default function litecanvas(settings = {}) {
|
|
|
853
850
|
null == context ||
|
|
854
851
|
context instanceof CanvasRenderingContext2D ||
|
|
855
852
|
context instanceof OffscreenCanvasRenderingContext2D,
|
|
856
|
-
'ctx() 1st
|
|
853
|
+
'ctx() 1st argument must be an [Offscreen]CanvasRenderingContext2D'
|
|
857
854
|
)
|
|
858
855
|
|
|
859
856
|
if (context) {
|
|
@@ -875,11 +872,11 @@ export default function litecanvas(settings = {}) {
|
|
|
875
872
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
|
|
876
873
|
*/
|
|
877
874
|
push(translateX = 0, translateY = translateX, rotation = 0, scaleX = 1, scaleY = scaleX) {
|
|
878
|
-
DEV: assert(isNumber(translateX), 'push() 1st
|
|
879
|
-
DEV: assert(isNumber(translateY), 'push() 2nd
|
|
880
|
-
DEV: assert(isNumber(rotation), 'push() 3rd
|
|
881
|
-
DEV: assert(isNumber(scaleX), 'push() 4th
|
|
882
|
-
DEV: assert(isNumber(scaleY), 'push() 5th
|
|
875
|
+
DEV: assert(isNumber(translateX), 'push() 1st argument must be a number')
|
|
876
|
+
DEV: assert(isNumber(translateY), 'push() 2nd argument must be a number')
|
|
877
|
+
DEV: assert(isNumber(rotation), 'push() 3rd argument must be a number')
|
|
878
|
+
DEV: assert(isNumber(scaleX), 'push() 4th argument must be a number')
|
|
879
|
+
DEV: assert(isNumber(scaleY), 'push() 5th argument must be a number')
|
|
883
880
|
|
|
884
881
|
_ctx.save()
|
|
885
882
|
instance.translate(translateX, translateY)
|
|
@@ -903,8 +900,8 @@ export default function litecanvas(settings = {}) {
|
|
|
903
900
|
* @param {number} y
|
|
904
901
|
*/
|
|
905
902
|
translate(x, y) {
|
|
906
|
-
DEV: assert(isNumber(x), 'translate() 1st
|
|
907
|
-
DEV: assert(isNumber(y), 'translate() 2nd
|
|
903
|
+
DEV: assert(isNumber(x), 'translate() 1st argument must be a number')
|
|
904
|
+
DEV: assert(isNumber(y), 'translate() 2nd argument must be a number')
|
|
908
905
|
|
|
909
906
|
_ctx.translate(~~x, ~~y)
|
|
910
907
|
},
|
|
@@ -916,8 +913,8 @@ export default function litecanvas(settings = {}) {
|
|
|
916
913
|
* @param {number} [y]
|
|
917
914
|
*/
|
|
918
915
|
scale(x, y = x) {
|
|
919
|
-
DEV: assert(isNumber(x), 'scale() 1st
|
|
920
|
-
DEV: assert(isNumber(y), 'scale() 2nd
|
|
916
|
+
DEV: assert(isNumber(x), 'scale() 1st argument must be a number')
|
|
917
|
+
DEV: assert(isNumber(y), 'scale() 2nd argument must be a number')
|
|
921
918
|
|
|
922
919
|
_ctx.scale(x, y)
|
|
923
920
|
},
|
|
@@ -928,7 +925,7 @@ export default function litecanvas(settings = {}) {
|
|
|
928
925
|
* @param {number} radians
|
|
929
926
|
*/
|
|
930
927
|
rotate(radians) {
|
|
931
|
-
DEV: assert(isNumber(radians), 'rotate() 1st
|
|
928
|
+
DEV: assert(isNumber(radians), 'rotate() 1st argument must be a number')
|
|
932
929
|
|
|
933
930
|
_ctx.rotate(radians)
|
|
934
931
|
},
|
|
@@ -940,7 +937,7 @@ export default function litecanvas(settings = {}) {
|
|
|
940
937
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalAlpha
|
|
941
938
|
*/
|
|
942
939
|
alpha(value) {
|
|
943
|
-
DEV: assert(isNumber(value), 'alpha() 1st
|
|
940
|
+
DEV: assert(isNumber(value), 'alpha() 1st argument must be a number')
|
|
944
941
|
|
|
945
942
|
_ctx.globalAlpha = instance.clamp(value, 0, 1)
|
|
946
943
|
},
|
|
@@ -953,7 +950,7 @@ export default function litecanvas(settings = {}) {
|
|
|
953
950
|
fill(color) {
|
|
954
951
|
DEV: assert(
|
|
955
952
|
null == color || (isNumber(color) && color >= 0),
|
|
956
|
-
'fill() 1st
|
|
953
|
+
'fill() 1st argument must be a non-negative number'
|
|
957
954
|
)
|
|
958
955
|
|
|
959
956
|
_ctx.fillStyle = getColor(color)
|
|
@@ -968,7 +965,7 @@ export default function litecanvas(settings = {}) {
|
|
|
968
965
|
stroke(color) {
|
|
969
966
|
DEV: assert(
|
|
970
967
|
null == color || (isNumber(color) && color >= 0),
|
|
971
|
-
'stroke() 1st
|
|
968
|
+
'stroke() 1st argument must be a non-negative number'
|
|
972
969
|
)
|
|
973
970
|
|
|
974
971
|
_ctx.strokeStyle = getColor(color)
|
|
@@ -984,7 +981,7 @@ export default function litecanvas(settings = {}) {
|
|
|
984
981
|
clip(callback) {
|
|
985
982
|
DEV: assert(
|
|
986
983
|
'function' === typeof callback,
|
|
987
|
-
'clip() 1st
|
|
984
|
+
'clip() 1st argument must be a function (ctx) => void'
|
|
988
985
|
)
|
|
989
986
|
|
|
990
987
|
beginPath(_ctx)
|
|
@@ -1007,15 +1004,15 @@ export default function litecanvas(settings = {}) {
|
|
|
1007
1004
|
sfx(zzfxParams, pitchSlide, volumeFactor) {
|
|
1008
1005
|
DEV: assert(
|
|
1009
1006
|
null == zzfxParams || Array.isArray(zzfxParams),
|
|
1010
|
-
'sfx() 1st
|
|
1007
|
+
'sfx() 1st argument must be an array'
|
|
1011
1008
|
)
|
|
1012
1009
|
DEV: assert(
|
|
1013
1010
|
null == pitchSlide || isNumber(pitchSlide),
|
|
1014
|
-
'sfx() 2nd
|
|
1011
|
+
'sfx() 2nd argument must be a number'
|
|
1015
1012
|
)
|
|
1016
1013
|
DEV: assert(
|
|
1017
1014
|
null == volumeFactor || isNumber(volumeFactor),
|
|
1018
|
-
'sfx() 3rd
|
|
1015
|
+
'sfx() 3rd argument must be a number'
|
|
1019
1016
|
)
|
|
1020
1017
|
|
|
1021
1018
|
if (
|
|
@@ -1048,7 +1045,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1048
1045
|
volume(value) {
|
|
1049
1046
|
DEV: assert(
|
|
1050
1047
|
isNumber(value) && value >= 0,
|
|
1051
|
-
'volume() 1st
|
|
1048
|
+
'volume() 1st argument must be a non-negative number'
|
|
1052
1049
|
)
|
|
1053
1050
|
|
|
1054
1051
|
root.zzfxV = value
|
|
@@ -1071,13 +1068,43 @@ export default function litecanvas(settings = {}) {
|
|
|
1071
1068
|
use(callback, config = {}) {
|
|
1072
1069
|
DEV: assert(
|
|
1073
1070
|
'function' === typeof callback,
|
|
1074
|
-
'use() 1st
|
|
1071
|
+
'use() 1st argument must be a function (instance, config) => any'
|
|
1075
1072
|
)
|
|
1076
|
-
DEV: assert('object' === typeof config, 'use() 2nd
|
|
1073
|
+
DEV: assert('object' === typeof config, 'use() 2nd argument must be an object')
|
|
1077
1074
|
|
|
1078
1075
|
loadPlugin(callback, config)
|
|
1079
1076
|
},
|
|
1080
1077
|
|
|
1078
|
+
/**
|
|
1079
|
+
* Resizes the canvas
|
|
1080
|
+
*
|
|
1081
|
+
* @param {number} width
|
|
1082
|
+
* @param {number} [height]
|
|
1083
|
+
* @param {boolean|number} [autoscale]
|
|
1084
|
+
*/
|
|
1085
|
+
resize(width, height = width, autoscale) {
|
|
1086
|
+
DEV: assert(
|
|
1087
|
+
isNumber(width) && width >= 1,
|
|
1088
|
+
'resize() 1st argument must be a number >= 1'
|
|
1089
|
+
)
|
|
1090
|
+
DEV: assert(
|
|
1091
|
+
isNumber(height) && height >= 1,
|
|
1092
|
+
'resize() 2nd argument must be a number >= 1'
|
|
1093
|
+
)
|
|
1094
|
+
DEV: assert(
|
|
1095
|
+
null == autoscale ||
|
|
1096
|
+
'boolean' === typeof autoscale ||
|
|
1097
|
+
(isNumber(autoscale) && autoscale > 1),
|
|
1098
|
+
'resize() 3rd argument must be a boolean or a number > 1'
|
|
1099
|
+
)
|
|
1100
|
+
|
|
1101
|
+
settings.width = width
|
|
1102
|
+
settings.height = height
|
|
1103
|
+
settings.autoscale = null == autoscale ? settings.autoscale : autoscale
|
|
1104
|
+
|
|
1105
|
+
resizeCanvas()
|
|
1106
|
+
},
|
|
1107
|
+
|
|
1081
1108
|
/**
|
|
1082
1109
|
* Add a game event listener.
|
|
1083
1110
|
*
|
|
@@ -1085,8 +1112,8 @@ export default function litecanvas(settings = {}) {
|
|
|
1085
1112
|
* @param {Function} callback the function that is called when the event occurs
|
|
1086
1113
|
*/
|
|
1087
1114
|
listen: (eventName, callback) => {
|
|
1088
|
-
DEV: assert('string' === typeof eventName, 'listen() 1st
|
|
1089
|
-
DEV: assert('function' === typeof callback, 'listen() 2nd
|
|
1115
|
+
DEV: assert('string' === typeof eventName, 'listen() 1st argument must be a string')
|
|
1116
|
+
DEV: assert('function' === typeof callback, 'listen() 2nd argument must be a function')
|
|
1090
1117
|
|
|
1091
1118
|
eventName = lowerCase(eventName)
|
|
1092
1119
|
|
|
@@ -1101,10 +1128,10 @@ export default function litecanvas(settings = {}) {
|
|
|
1101
1128
|
* @param {Function} callback the function that is called when the event occurs
|
|
1102
1129
|
*/
|
|
1103
1130
|
unlisten: (eventName, callback) => {
|
|
1104
|
-
DEV: assert('string' === typeof eventName, 'unlisten() 1st
|
|
1131
|
+
DEV: assert('string' === typeof eventName, 'unlisten() 1st argument must be a string')
|
|
1105
1132
|
DEV: assert(
|
|
1106
1133
|
'function' === typeof callback,
|
|
1107
|
-
'unlisten() 2nd
|
|
1134
|
+
'unlisten() 2nd argument must be a function'
|
|
1108
1135
|
)
|
|
1109
1136
|
|
|
1110
1137
|
eventName = lowerCase(eventName)
|
|
@@ -1129,7 +1156,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1129
1156
|
* @returns {any} always returns the second argument
|
|
1130
1157
|
*/
|
|
1131
1158
|
emit(eventName, arg1, arg2, arg3, arg4) {
|
|
1132
|
-
DEV: assert('string' === typeof eventName, 'emit() 1st
|
|
1159
|
+
DEV: assert('string' === typeof eventName, 'emit() 1st argument must be a string')
|
|
1133
1160
|
|
|
1134
1161
|
if (_initialized) {
|
|
1135
1162
|
eventName = lowerCase(eventName)
|
|
@@ -1164,11 +1191,11 @@ export default function litecanvas(settings = {}) {
|
|
|
1164
1191
|
pal(colors, textColor = 3) {
|
|
1165
1192
|
DEV: assert(
|
|
1166
1193
|
null == colors || (Array.isArray(colors) && colors.length > 0),
|
|
1167
|
-
'pal() 1st
|
|
1194
|
+
'pal() 1st argument must be null or an array of colors'
|
|
1168
1195
|
)
|
|
1169
1196
|
DEV: assert(
|
|
1170
1197
|
isNumber(textColor) && textColor >= 0,
|
|
1171
|
-
'pal() 2nd
|
|
1198
|
+
'pal() 2nd argument must be a non-negative number'
|
|
1172
1199
|
)
|
|
1173
1200
|
|
|
1174
1201
|
_colorPalette = colors || defaultPalette
|
|
@@ -1191,11 +1218,11 @@ export default function litecanvas(settings = {}) {
|
|
|
1191
1218
|
palc(a, b) {
|
|
1192
1219
|
DEV: assert(
|
|
1193
1220
|
null == a || (isNumber(a) && a >= 0),
|
|
1194
|
-
'palc() 1st
|
|
1221
|
+
'palc() 1st argument must be a positive number'
|
|
1195
1222
|
)
|
|
1196
1223
|
DEV: assert(
|
|
1197
1224
|
isNumber(a) ? isNumber(b) && b >= 0 : null == b,
|
|
1198
|
-
'palc() 2nd
|
|
1225
|
+
'palc() 2nd argument must be a positive number'
|
|
1199
1226
|
)
|
|
1200
1227
|
|
|
1201
1228
|
if (null == a) {
|
|
@@ -1217,7 +1244,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1217
1244
|
* @param {any} value the property value
|
|
1218
1245
|
*/
|
|
1219
1246
|
def(key, value) {
|
|
1220
|
-
DEV: assert('string' === typeof key, 'def() 1st
|
|
1247
|
+
DEV: assert('string' === typeof key, 'def() 1st argument must be a string')
|
|
1221
1248
|
DEV: if (null == value) {
|
|
1222
1249
|
console.warn(
|
|
1223
1250
|
`[litecanvas] def() changed the key "${key}" to null (previous value was ${instance[key]})`
|
|
@@ -1240,7 +1267,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1240
1267
|
timescale(value) {
|
|
1241
1268
|
DEV: assert(
|
|
1242
1269
|
isNumber(value) && value >= 0,
|
|
1243
|
-
'timescale() 1st
|
|
1270
|
+
'timescale() 1st argument must be a non-negative number'
|
|
1244
1271
|
)
|
|
1245
1272
|
|
|
1246
1273
|
_timeScale = value
|
|
@@ -1254,7 +1281,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1254
1281
|
framerate(value) {
|
|
1255
1282
|
DEV: assert(
|
|
1256
1283
|
isNumber(value) && value >= 1,
|
|
1257
|
-
'framerate() 1st
|
|
1284
|
+
'framerate() 1st argument must be a number >= 1'
|
|
1258
1285
|
)
|
|
1259
1286
|
|
|
1260
1287
|
_fpsInterval = 1000 / ~~value
|
|
@@ -1267,7 +1294,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1267
1294
|
* @returns {any}
|
|
1268
1295
|
*/
|
|
1269
1296
|
stat(index) {
|
|
1270
|
-
DEV: assert(isNumber(index), 'stat() 1st
|
|
1297
|
+
DEV: assert(isNumber(index), 'stat() 1st argument must be a number')
|
|
1271
1298
|
|
|
1272
1299
|
const internals = [
|
|
1273
1300
|
// 0
|
|
@@ -1316,7 +1343,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1316
1343
|
DEV: assert(
|
|
1317
1344
|
index >= 0 && index < internals.length,
|
|
1318
1345
|
|
|
1319
|
-
'stat() 1st
|
|
1346
|
+
'stat() 1st argument must be a number between 0 and ' + (internals.length - 1)
|
|
1320
1347
|
)
|
|
1321
1348
|
|
|
1322
1349
|
return internals[index]
|
|
@@ -1407,8 +1434,6 @@ export default function litecanvas(settings = {}) {
|
|
|
1407
1434
|
}
|
|
1408
1435
|
|
|
1409
1436
|
function init() {
|
|
1410
|
-
resizeCanvas()
|
|
1411
|
-
|
|
1412
1437
|
// listen window resize event when "autoscale" is enabled
|
|
1413
1438
|
if (settings.autoscale) {
|
|
1414
1439
|
on(root, 'resize', resizeCanvas)
|
|
@@ -1610,7 +1635,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1610
1635
|
*/
|
|
1611
1636
|
const keyCheck = (keySet, key = '') => {
|
|
1612
1637
|
key = lowerCase(key)
|
|
1613
|
-
return
|
|
1638
|
+
return key ? keySet.has('space' === key ? ' ' : key) : keySet.size > 0
|
|
1614
1639
|
}
|
|
1615
1640
|
|
|
1616
1641
|
/** @type {string} */
|
|
@@ -1641,7 +1666,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1641
1666
|
(key) => {
|
|
1642
1667
|
DEV: assert(
|
|
1643
1668
|
null == key || 'string' === typeof key,
|
|
1644
|
-
'iskeydown() 1st
|
|
1669
|
+
'iskeydown() 1st argument must be a string'
|
|
1645
1670
|
)
|
|
1646
1671
|
return keyCheck(_keysDown, key)
|
|
1647
1672
|
}
|
|
@@ -1656,7 +1681,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1656
1681
|
(key) => {
|
|
1657
1682
|
DEV: assert(
|
|
1658
1683
|
null == key || 'string' === typeof key,
|
|
1659
|
-
'iskeypressed() 1st
|
|
1684
|
+
'iskeypressed() 1st argument must be a string'
|
|
1660
1685
|
)
|
|
1661
1686
|
return keyCheck(_keysPress, key)
|
|
1662
1687
|
}
|
|
@@ -1742,8 +1767,6 @@ export default function litecanvas(settings = {}) {
|
|
|
1742
1767
|
|
|
1743
1768
|
// disable default browser's right click in canvas
|
|
1744
1769
|
_canvas.oncontextmenu = () => false
|
|
1745
|
-
|
|
1746
|
-
resizeCanvas()
|
|
1747
1770
|
}
|
|
1748
1771
|
|
|
1749
1772
|
function resizeCanvas() {
|
|
@@ -1857,8 +1880,10 @@ export default function litecanvas(settings = {}) {
|
|
|
1857
1880
|
|
|
1858
1881
|
// setup the canvas
|
|
1859
1882
|
setupCanvas()
|
|
1883
|
+
resizeCanvas()
|
|
1860
1884
|
|
|
1861
1885
|
// setup default event listeners
|
|
1886
|
+
// they have high priority
|
|
1862
1887
|
if (_loop) {
|
|
1863
1888
|
for (const eventName in _loop) {
|
|
1864
1889
|
if (_loop[eventName]) instance.listen(eventName, _loop[eventName])
|