litecanvas 0.209.0 → 0.301.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist/dist.dev.js +174 -160
- package/dist/dist.js +18 -14
- package/dist/dist.min.js +1 -1
- package/package.json +4 -4
- package/src/index.js +190 -172
- package/src/version.js +1 -1
- package/types/global.d.ts +11 -11
- package/types/types.d.ts +11 -11
package/src/index.js
CHANGED
|
@@ -14,7 +14,7 @@ export default function litecanvas(settings = {}) {
|
|
|
14
14
|
const root = window,
|
|
15
15
|
math = Math,
|
|
16
16
|
perf = performance,
|
|
17
|
-
|
|
17
|
+
TAU = math.PI * 2,
|
|
18
18
|
raf = requestAnimationFrame,
|
|
19
19
|
isNumber = Number.isFinite,
|
|
20
20
|
/** @type {Function[]} */
|
|
@@ -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} */
|
|
@@ -117,20 +117,9 @@ export default function litecanvas(settings = {}) {
|
|
|
117
117
|
* Twice the value of the mathematical constant PI (π).
|
|
118
118
|
* Approximately 6.28318
|
|
119
119
|
*
|
|
120
|
-
* Note: TWO_PI radians equals 360°, PI radians equals 180°,
|
|
121
|
-
* HALF_PI radians equals 90°, and HALF_PI/2 radians equals 45°.
|
|
122
|
-
*
|
|
123
|
-
* @type {number}
|
|
124
|
-
*/
|
|
125
|
-
TWO_PI,
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Half the value of the mathematical constant PI (π).
|
|
129
|
-
* Approximately 1.57079
|
|
130
|
-
*
|
|
131
120
|
* @type {number}
|
|
132
121
|
*/
|
|
133
|
-
|
|
122
|
+
TAU,
|
|
134
123
|
|
|
135
124
|
/**
|
|
136
125
|
* Calculates a linear (interpolation) value over t%.
|
|
@@ -142,9 +131,9 @@ export default function litecanvas(settings = {}) {
|
|
|
142
131
|
* @tutorial https://gamedev.net/tutorials/programming/general-and-gameplay-programming/a-brief-introduction-to-lerp-r4954/
|
|
143
132
|
*/
|
|
144
133
|
lerp: (start, end, t) => {
|
|
145
|
-
DEV: assert(isNumber(start), 'lerp() 1st
|
|
146
|
-
DEV: assert(isNumber(end), 'lerp() 2nd
|
|
147
|
-
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')
|
|
148
137
|
|
|
149
138
|
return start + t * (end - start)
|
|
150
139
|
},
|
|
@@ -156,7 +145,7 @@ export default function litecanvas(settings = {}) {
|
|
|
156
145
|
* @returns {number} the value in radians
|
|
157
146
|
*/
|
|
158
147
|
deg2rad: (degs) => {
|
|
159
|
-
DEV: assert(isNumber(degs), 'deg2rad() 1st
|
|
148
|
+
DEV: assert(isNumber(degs), 'deg2rad() 1st argument must be a number')
|
|
160
149
|
|
|
161
150
|
return (math.PI / 180) * degs
|
|
162
151
|
},
|
|
@@ -168,7 +157,7 @@ export default function litecanvas(settings = {}) {
|
|
|
168
157
|
* @returns {number} the value in degrees
|
|
169
158
|
*/
|
|
170
159
|
rad2deg: (rads) => {
|
|
171
|
-
DEV: assert(isNumber(rads), 'rad2deg() 1st
|
|
160
|
+
DEV: assert(isNumber(rads), 'rad2deg() 1st argument must be a number')
|
|
172
161
|
|
|
173
162
|
return (180 / math.PI) * rads
|
|
174
163
|
},
|
|
@@ -181,13 +170,10 @@ export default function litecanvas(settings = {}) {
|
|
|
181
170
|
* @param {number} a dividend
|
|
182
171
|
* @param {number} b divisor
|
|
183
172
|
* @returns {number} the remainder
|
|
184
|
-
* @example
|
|
185
|
-
* mod(-1, 5) // => 4
|
|
186
|
-
* -1 % 5 // => -1
|
|
187
173
|
*/
|
|
188
174
|
mod(a, b) {
|
|
189
|
-
DEV: assert(isNumber(a), 'mod() 1st
|
|
190
|
-
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')
|
|
191
177
|
|
|
192
178
|
return ((a % b) + b) % b || 0
|
|
193
179
|
},
|
|
@@ -202,10 +188,10 @@ export default function litecanvas(settings = {}) {
|
|
|
202
188
|
* @returns {number} rounded number.
|
|
203
189
|
*/
|
|
204
190
|
round: (n, precision = 0) => {
|
|
205
|
-
DEV: assert(isNumber(n), 'round() 1st
|
|
191
|
+
DEV: assert(isNumber(n), 'round() 1st argument must be a number')
|
|
206
192
|
DEV: assert(
|
|
207
193
|
isNumber(precision) && precision >= 0,
|
|
208
|
-
'round() 2nd
|
|
194
|
+
'round() 2nd argument must be a non-negative number'
|
|
209
195
|
)
|
|
210
196
|
|
|
211
197
|
if (!precision) {
|
|
@@ -224,10 +210,10 @@ export default function litecanvas(settings = {}) {
|
|
|
224
210
|
* @returns {number}
|
|
225
211
|
*/
|
|
226
212
|
clamp: (value, min, max) => {
|
|
227
|
-
DEV: assert(isNumber(value), 'clamp() 1st
|
|
228
|
-
DEV: assert(isNumber(min), 'clamp() 2nd
|
|
229
|
-
DEV: assert(isNumber(max), 'clamp() 3rd
|
|
230
|
-
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')
|
|
231
217
|
|
|
232
218
|
if (value < min) return min
|
|
233
219
|
if (value > max) return max
|
|
@@ -244,10 +230,10 @@ export default function litecanvas(settings = {}) {
|
|
|
244
230
|
* @returns {number}
|
|
245
231
|
*/
|
|
246
232
|
dist: (x1, y1, x2, y2) => {
|
|
247
|
-
DEV: assert(isNumber(x1), 'dist() 1st
|
|
248
|
-
DEV: assert(isNumber(y1), 'dist() 2nd
|
|
249
|
-
DEV: assert(isNumber(x2), 'dist() 3rd
|
|
250
|
-
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')
|
|
251
237
|
|
|
252
238
|
return math.hypot(x2 - x1, y2 - y1)
|
|
253
239
|
},
|
|
@@ -261,10 +247,10 @@ export default function litecanvas(settings = {}) {
|
|
|
261
247
|
* @returns {number}
|
|
262
248
|
*/
|
|
263
249
|
wrap: (value, min, max) => {
|
|
264
|
-
DEV: assert(isNumber(value), 'wrap() 1st
|
|
265
|
-
DEV: assert(isNumber(min), 'wrap() 2nd
|
|
266
|
-
DEV: assert(isNumber(max), 'wrap() 3rd
|
|
267
|
-
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')
|
|
268
254
|
|
|
269
255
|
return value - (max - min) * math.floor((value - min) / (max - min))
|
|
270
256
|
},
|
|
@@ -281,14 +267,14 @@ export default function litecanvas(settings = {}) {
|
|
|
281
267
|
* @returns {number} the remapped number
|
|
282
268
|
*/
|
|
283
269
|
map(value, start1, stop1, start2, stop2, withinBounds) {
|
|
284
|
-
DEV: assert(isNumber(value), 'map() 1st
|
|
285
|
-
DEV: assert(isNumber(start1), 'map() 2nd
|
|
286
|
-
DEV: assert(isNumber(stop1), 'map() 3rd
|
|
287
|
-
DEV: assert(isNumber(start2), 'map() 4th
|
|
288
|
-
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')
|
|
289
275
|
DEV: assert(
|
|
290
276
|
stop1 !== start1,
|
|
291
|
-
'map() the 2nd
|
|
277
|
+
'map() the 2nd argument must be different than the 3rd argument'
|
|
292
278
|
)
|
|
293
279
|
|
|
294
280
|
// prettier-ignore
|
|
@@ -307,12 +293,12 @@ export default function litecanvas(settings = {}) {
|
|
|
307
293
|
* @returns {number} the normalized number.
|
|
308
294
|
*/
|
|
309
295
|
norm: (value, start, stop) => {
|
|
310
|
-
DEV: assert(isNumber(value), 'norm() 1st
|
|
311
|
-
DEV: assert(isNumber(start), 'norm() 2nd
|
|
312
|
-
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')
|
|
313
299
|
DEV: assert(
|
|
314
300
|
start !== stop,
|
|
315
|
-
'norm() the 2nd
|
|
301
|
+
'norm() the 2nd argument must be different than the 3rd argument'
|
|
316
302
|
)
|
|
317
303
|
|
|
318
304
|
return instance.map(value, start, stop, 0, 1)
|
|
@@ -328,9 +314,9 @@ export default function litecanvas(settings = {}) {
|
|
|
328
314
|
* @returns {number} the random number
|
|
329
315
|
*/
|
|
330
316
|
rand: (min = 0.0, max = 1.0) => {
|
|
331
|
-
DEV: assert(isNumber(min), 'rand() 1st
|
|
332
|
-
DEV: assert(isNumber(max), 'rand() 2nd
|
|
333
|
-
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')
|
|
334
320
|
|
|
335
321
|
const a = 1664525
|
|
336
322
|
const c = 1013904223
|
|
@@ -349,9 +335,9 @@ export default function litecanvas(settings = {}) {
|
|
|
349
335
|
* @returns {number} the random number
|
|
350
336
|
*/
|
|
351
337
|
randi: (min = 0, max = 1) => {
|
|
352
|
-
DEV: assert(isNumber(min), 'randi() 1st
|
|
353
|
-
DEV: assert(isNumber(max), 'randi() 2nd
|
|
354
|
-
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')
|
|
355
341
|
|
|
356
342
|
return ~~instance.rand(min, max + 1)
|
|
357
343
|
},
|
|
@@ -366,7 +352,7 @@ export default function litecanvas(settings = {}) {
|
|
|
366
352
|
rseed(value) {
|
|
367
353
|
DEV: assert(
|
|
368
354
|
isNumber(value) && value >= 0,
|
|
369
|
-
'rseed() 1st
|
|
355
|
+
'rseed() 1st argument must be a non-negative integer'
|
|
370
356
|
)
|
|
371
357
|
|
|
372
358
|
_rngSeed = ~~value
|
|
@@ -381,7 +367,7 @@ export default function litecanvas(settings = {}) {
|
|
|
381
367
|
cls(color) {
|
|
382
368
|
DEV: assert(
|
|
383
369
|
null == color || (isNumber(color) && color >= 0),
|
|
384
|
-
'cls() 1st
|
|
370
|
+
'cls() 1st argument must be a non-negative number'
|
|
385
371
|
)
|
|
386
372
|
|
|
387
373
|
if (null == color) {
|
|
@@ -404,23 +390,23 @@ export default function litecanvas(settings = {}) {
|
|
|
404
390
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/roundRect
|
|
405
391
|
*/
|
|
406
392
|
rect(x, y, width, height, color, radii) {
|
|
407
|
-
DEV: assert(isNumber(x), 'rect() 1st
|
|
408
|
-
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')
|
|
409
395
|
DEV: assert(
|
|
410
396
|
isNumber(width) && width > 0,
|
|
411
|
-
'rect() 3rd
|
|
397
|
+
'rect() 3rd argument must be a positive number'
|
|
412
398
|
)
|
|
413
399
|
DEV: assert(
|
|
414
400
|
isNumber(height) && height >= 0,
|
|
415
|
-
'rect() 4th
|
|
401
|
+
'rect() 4th argument must be a non-negative number'
|
|
416
402
|
)
|
|
417
403
|
DEV: assert(
|
|
418
404
|
null == color || (isNumber(color) && color >= 0),
|
|
419
|
-
'rect() 5th
|
|
405
|
+
'rect() 5th argument must be a non-negative number'
|
|
420
406
|
)
|
|
421
407
|
DEV: assert(
|
|
422
408
|
null == radii || isNumber(radii) || (Array.isArray(radii) && radii.length >= 1),
|
|
423
|
-
'rect() 6th
|
|
409
|
+
'rect() 6th argument must be a number or array of numbers'
|
|
424
410
|
)
|
|
425
411
|
|
|
426
412
|
beginPath(_ctx)
|
|
@@ -446,24 +432,24 @@ export default function litecanvas(settings = {}) {
|
|
|
446
432
|
* @param {number|number[]} [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
|
|
447
433
|
*/
|
|
448
434
|
rectfill(x, y, width, height, color, radii) {
|
|
449
|
-
DEV: assert(isNumber(x), 'rectfill() 1st
|
|
450
|
-
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')
|
|
451
437
|
DEV: assert(
|
|
452
438
|
isNumber(width) && width >= 0,
|
|
453
|
-
'rectfill() 3rd
|
|
439
|
+
'rectfill() 3rd argument must be a non-negative number'
|
|
454
440
|
)
|
|
455
441
|
DEV: assert(
|
|
456
442
|
isNumber(height) && height >= 0,
|
|
457
|
-
'rectfill() 4th
|
|
443
|
+
'rectfill() 4th argument must be a non-negative number'
|
|
458
444
|
)
|
|
459
445
|
DEV: assert(
|
|
460
446
|
null == color || (isNumber(color) && color >= 0),
|
|
461
|
-
'rectfill() 5th
|
|
447
|
+
'rectfill() 5th argument must be a non-negative number'
|
|
462
448
|
)
|
|
463
449
|
DEV: assert(
|
|
464
450
|
null == radii || isNumber(radii) || (Array.isArray(radii) && radii.length >= 1),
|
|
465
451
|
|
|
466
|
-
'rectfill() 6th
|
|
452
|
+
'rectfill() 6th argument must be a number or array of at least 2 numbers'
|
|
467
453
|
)
|
|
468
454
|
|
|
469
455
|
beginPath(_ctx)
|
|
@@ -482,24 +468,24 @@ export default function litecanvas(settings = {}) {
|
|
|
482
468
|
* @param {number} [color=0] the color index
|
|
483
469
|
*/
|
|
484
470
|
oval(x, y, radiusX, radiusY, color) {
|
|
485
|
-
DEV: assert(isNumber(x), 'oval() 1st
|
|
486
|
-
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')
|
|
487
473
|
DEV: assert(
|
|
488
474
|
isNumber(radiusX) && radiusX >= 0,
|
|
489
|
-
'oval() 3rd
|
|
475
|
+
'oval() 3rd argument must be a non-negative number'
|
|
490
476
|
)
|
|
491
477
|
DEV: assert(
|
|
492
478
|
isNumber(radiusY) && radiusY >= 0,
|
|
493
|
-
'oval() 4th
|
|
479
|
+
'oval() 4th argument must be a non-negative number'
|
|
494
480
|
)
|
|
495
481
|
DEV: assert(
|
|
496
482
|
null == color || (isNumber(color) && color >= 0),
|
|
497
|
-
'oval() 5th
|
|
483
|
+
'oval() 5th argument must be a non-negative number'
|
|
498
484
|
)
|
|
499
485
|
|
|
500
486
|
beginPath(_ctx)
|
|
501
487
|
|
|
502
|
-
_ctx.ellipse(~~x, ~~y, ~~radiusX, ~~radiusY, 0, 0,
|
|
488
|
+
_ctx.ellipse(~~x, ~~y, ~~radiusX, ~~radiusY, 0, 0, TAU)
|
|
503
489
|
instance.stroke(color)
|
|
504
490
|
},
|
|
505
491
|
|
|
@@ -513,24 +499,24 @@ export default function litecanvas(settings = {}) {
|
|
|
513
499
|
* @param {number} [color=0] the color index
|
|
514
500
|
*/
|
|
515
501
|
ovalfill(x, y, radiusX, radiusY, color) {
|
|
516
|
-
DEV: assert(isNumber(x), 'ovalfill() 1st
|
|
517
|
-
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')
|
|
518
504
|
DEV: assert(
|
|
519
505
|
isNumber(radiusX) && radiusX >= 0,
|
|
520
|
-
'ovalfill() 3rd
|
|
506
|
+
'ovalfill() 3rd argument must be a non-negative number'
|
|
521
507
|
)
|
|
522
508
|
DEV: assert(
|
|
523
509
|
isNumber(radiusY) && radiusY >= 0,
|
|
524
|
-
'ovalfill() 4th
|
|
510
|
+
'ovalfill() 4th argument must be a non-negative number'
|
|
525
511
|
)
|
|
526
512
|
DEV: assert(
|
|
527
513
|
null == color || (isNumber(color) && color >= 0),
|
|
528
|
-
'ovalfill() 5th
|
|
514
|
+
'ovalfill() 5th argument must be a non-negative number'
|
|
529
515
|
)
|
|
530
516
|
|
|
531
517
|
beginPath(_ctx)
|
|
532
518
|
|
|
533
|
-
_ctx.ellipse(~~x, ~~y, ~~radiusX, ~~radiusY, 0, 0,
|
|
519
|
+
_ctx.ellipse(~~x, ~~y, ~~radiusX, ~~radiusY, 0, 0, TAU)
|
|
534
520
|
instance.fill(color)
|
|
535
521
|
},
|
|
536
522
|
|
|
@@ -543,15 +529,15 @@ export default function litecanvas(settings = {}) {
|
|
|
543
529
|
* @param {number} [color=0] the color index
|
|
544
530
|
*/
|
|
545
531
|
circ(x, y, radius, color) {
|
|
546
|
-
DEV: assert(isNumber(x), 'circ() 1st
|
|
547
|
-
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')
|
|
548
534
|
DEV: assert(
|
|
549
535
|
isNumber(radius) && radius >= 0,
|
|
550
|
-
'circ() 3rd
|
|
536
|
+
'circ() 3rd argument must be a non-negative number'
|
|
551
537
|
)
|
|
552
538
|
DEV: assert(
|
|
553
539
|
null == color || (isNumber(color) && color >= 0),
|
|
554
|
-
'circ() 4th
|
|
540
|
+
'circ() 4th argument must be a non-negative number'
|
|
555
541
|
)
|
|
556
542
|
|
|
557
543
|
instance.oval(x, y, radius, radius, color)
|
|
@@ -566,15 +552,15 @@ export default function litecanvas(settings = {}) {
|
|
|
566
552
|
* @param {number} [color=0] the color index
|
|
567
553
|
*/
|
|
568
554
|
circfill(x, y, radius, color) {
|
|
569
|
-
DEV: assert(isNumber(x), 'circfill() 1st
|
|
570
|
-
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')
|
|
571
557
|
DEV: assert(
|
|
572
558
|
isNumber(radius) && radius >= 0,
|
|
573
|
-
'circfill() 3rd
|
|
559
|
+
'circfill() 3rd argument must be a non-negative number'
|
|
574
560
|
)
|
|
575
561
|
DEV: assert(
|
|
576
562
|
null == color || (isNumber(color) && color >= 0),
|
|
577
|
-
'circfill() 4th
|
|
563
|
+
'circfill() 4th argument must be a non-negative number'
|
|
578
564
|
)
|
|
579
565
|
|
|
580
566
|
instance.ovalfill(x, y, radius, radius, color)
|
|
@@ -587,10 +573,10 @@ export default function litecanvas(settings = {}) {
|
|
|
587
573
|
* @param {number[]} points an array of Xs and Ys coordinates
|
|
588
574
|
*/
|
|
589
575
|
shape(points) {
|
|
590
|
-
DEV: assert(Array.isArray(points), 'shape() 1st
|
|
576
|
+
DEV: assert(Array.isArray(points), 'shape() 1st argument must be an array of numbers')
|
|
591
577
|
DEV: assert(
|
|
592
578
|
points.length >= 6,
|
|
593
|
-
'shape() 1st
|
|
579
|
+
'shape() 1st argument must be an array with at least 6 numbers (3 points)'
|
|
594
580
|
)
|
|
595
581
|
|
|
596
582
|
beginPath(_ctx)
|
|
@@ -615,13 +601,13 @@ export default function litecanvas(settings = {}) {
|
|
|
615
601
|
* @param {number} [color=0] the color index
|
|
616
602
|
*/
|
|
617
603
|
line(x1, y1, x2, y2, color) {
|
|
618
|
-
DEV: assert(isNumber(x1), 'line() 1st
|
|
619
|
-
DEV: assert(isNumber(y1), 'line() 2nd
|
|
620
|
-
DEV: assert(isNumber(x2), 'line() 3rd
|
|
621
|
-
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')
|
|
622
608
|
DEV: assert(
|
|
623
609
|
null == color || (isNumber(color) && color >= 0),
|
|
624
|
-
'line() 5th
|
|
610
|
+
'line() 5th argument must be a non-negative number'
|
|
625
611
|
)
|
|
626
612
|
|
|
627
613
|
beginPath(_ctx)
|
|
@@ -644,7 +630,7 @@ export default function litecanvas(settings = {}) {
|
|
|
644
630
|
linewidth(value) {
|
|
645
631
|
DEV: assert(
|
|
646
632
|
isNumber(value) && value >= 0,
|
|
647
|
-
'linewidth() 1st
|
|
633
|
+
'linewidth() 1st argument must be a non-negative integer'
|
|
648
634
|
)
|
|
649
635
|
|
|
650
636
|
_ctx.lineWidth = ~~value
|
|
@@ -662,9 +648,9 @@ export default function litecanvas(settings = {}) {
|
|
|
662
648
|
linedash(segments, offset = 0) {
|
|
663
649
|
DEV: assert(
|
|
664
650
|
Array.isArray(segments) && segments.length > 0,
|
|
665
|
-
'linedash() 1st
|
|
651
|
+
'linedash() 1st argument must be an array of numbers'
|
|
666
652
|
)
|
|
667
|
-
DEV: assert(isNumber(offset), 'linedash() 2nd
|
|
653
|
+
DEV: assert(isNumber(offset), 'linedash() 2nd argument must be a number')
|
|
668
654
|
|
|
669
655
|
_ctx.setLineDash(segments)
|
|
670
656
|
_ctx.lineDashOffset = offset
|
|
@@ -681,13 +667,13 @@ export default function litecanvas(settings = {}) {
|
|
|
681
667
|
* @param {string} [fontStyle] can be "normal" (default), "italic" and/or "bold".
|
|
682
668
|
*/
|
|
683
669
|
text(x, y, message, color = _defaultTextColor, fontStyle = 'normal') {
|
|
684
|
-
DEV: assert(isNumber(x), 'text() 1st
|
|
685
|
-
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')
|
|
686
672
|
DEV: assert(
|
|
687
673
|
null == color || (isNumber(color) && color >= 0),
|
|
688
|
-
'text() 4th
|
|
674
|
+
'text() 4th argument must be a non-negative number'
|
|
689
675
|
)
|
|
690
|
-
DEV: assert('string' === typeof fontStyle, 'text() 5th
|
|
676
|
+
DEV: assert('string' === typeof fontStyle, 'text() 5th argument must be a string')
|
|
691
677
|
|
|
692
678
|
_ctx.font = `${fontStyle} ${_fontSize}px ${_fontFamily}`
|
|
693
679
|
_ctx.fillStyle = getColor(color)
|
|
@@ -706,7 +692,7 @@ export default function litecanvas(settings = {}) {
|
|
|
706
692
|
* @param {number} value
|
|
707
693
|
*/
|
|
708
694
|
textgap(value) {
|
|
709
|
-
DEV: assert(isNumber(value), 'textgap() 1st
|
|
695
|
+
DEV: assert(isNumber(value), 'textgap() 1st argument must be a number')
|
|
710
696
|
|
|
711
697
|
_fontLineHeight = value
|
|
712
698
|
},
|
|
@@ -717,7 +703,7 @@ export default function litecanvas(settings = {}) {
|
|
|
717
703
|
* @param {string} family
|
|
718
704
|
*/
|
|
719
705
|
textfont(family) {
|
|
720
|
-
DEV: assert('string' === typeof family, 'textfont() 1st
|
|
706
|
+
DEV: assert('string' === typeof family, 'textfont() 1st argument must be a string')
|
|
721
707
|
|
|
722
708
|
_fontFamily = family
|
|
723
709
|
},
|
|
@@ -728,7 +714,7 @@ export default function litecanvas(settings = {}) {
|
|
|
728
714
|
* @param {number} size
|
|
729
715
|
*/
|
|
730
716
|
textsize(size) {
|
|
731
|
-
DEV: assert(isNumber(size), 'textsize() 1st
|
|
717
|
+
DEV: assert(isNumber(size), 'textsize() 1st argument must be a number')
|
|
732
718
|
|
|
733
719
|
_fontSize = size
|
|
734
720
|
},
|
|
@@ -745,7 +731,7 @@ export default function litecanvas(settings = {}) {
|
|
|
745
731
|
DEV: assert(
|
|
746
732
|
null == align || ['left', 'right', 'center', 'start', 'end'].includes(align),
|
|
747
733
|
|
|
748
|
-
'textalign() 1st
|
|
734
|
+
'textalign() 1st argument must be null or one of the following strings: center, left, right, start or end.'
|
|
749
735
|
)
|
|
750
736
|
DEV: assert(
|
|
751
737
|
null == baseline ||
|
|
@@ -753,7 +739,7 @@ export default function litecanvas(settings = {}) {
|
|
|
753
739
|
baseline
|
|
754
740
|
),
|
|
755
741
|
|
|
756
|
-
'textalign() 2nd
|
|
742
|
+
'textalign() 2nd argument must be null or one of the following strings: middle, top, bottom, hanging, alphabetic or ideographic.'
|
|
757
743
|
)
|
|
758
744
|
|
|
759
745
|
if (align) _ctx.textAlign = align
|
|
@@ -769,8 +755,8 @@ export default function litecanvas(settings = {}) {
|
|
|
769
755
|
* @param {CanvasImageSource} source
|
|
770
756
|
*/
|
|
771
757
|
image(x, y, source) {
|
|
772
|
-
DEV: assert(isNumber(x), 'image() 1st
|
|
773
|
-
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')
|
|
774
760
|
|
|
775
761
|
_ctx.drawImage(source, ~~x, ~~y)
|
|
776
762
|
},
|
|
@@ -787,9 +773,9 @@ export default function litecanvas(settings = {}) {
|
|
|
787
773
|
* @param {string} pixels
|
|
788
774
|
*/
|
|
789
775
|
spr(x, y, pixels) {
|
|
790
|
-
DEV: assert(isNumber(x), 'spr() 1st
|
|
791
|
-
DEV: assert(isNumber(y), 'spr() 2nd
|
|
792
|
-
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')
|
|
793
779
|
|
|
794
780
|
const rows = pixels
|
|
795
781
|
.replace(/[^\w.\n]/g, '')
|
|
@@ -818,23 +804,20 @@ export default function litecanvas(settings = {}) {
|
|
|
818
804
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
|
|
819
805
|
*/
|
|
820
806
|
paint(width, height, callback, options = {}) {
|
|
821
|
-
DEV: assert(
|
|
822
|
-
isNumber(width) && width >= 1,
|
|
823
|
-
'paint() 1st parameter must be a positive number'
|
|
824
|
-
)
|
|
807
|
+
DEV: assert(isNumber(width) && width >= 1, 'paint() 1st argument must be a number >= 1')
|
|
825
808
|
DEV: assert(
|
|
826
809
|
isNumber(height) && height >= 1,
|
|
827
|
-
'paint() 2nd
|
|
810
|
+
'paint() 2nd argument must be a number >= 1'
|
|
828
811
|
)
|
|
829
|
-
DEV: assert('function' === typeof callback, 'paint() 3rd
|
|
812
|
+
DEV: assert('function' === typeof callback, 'paint() 3rd argument must be a function')
|
|
830
813
|
DEV: assert(
|
|
831
814
|
(options && null == options.scale) ||
|
|
832
815
|
(isNumber(options.scale) && options.scale > 0),
|
|
833
|
-
'paint() 4th
|
|
816
|
+
'paint() 4th argument (options.scale) must be a positive number'
|
|
834
817
|
)
|
|
835
818
|
DEV: assert(
|
|
836
819
|
(options && null == options.canvas) || options.canvas instanceof OffscreenCanvas,
|
|
837
|
-
'paint() 4th
|
|
820
|
+
'paint() 4th argument (options.canvas) must be an OffscreenCanvas'
|
|
838
821
|
)
|
|
839
822
|
|
|
840
823
|
const /** @type {OffscreenCanvas} */
|
|
@@ -867,7 +850,7 @@ export default function litecanvas(settings = {}) {
|
|
|
867
850
|
null == context ||
|
|
868
851
|
context instanceof CanvasRenderingContext2D ||
|
|
869
852
|
context instanceof OffscreenCanvasRenderingContext2D,
|
|
870
|
-
'ctx() 1st
|
|
853
|
+
'ctx() 1st argument must be an [Offscreen]CanvasRenderingContext2D'
|
|
871
854
|
)
|
|
872
855
|
|
|
873
856
|
if (context) {
|
|
@@ -889,11 +872,11 @@ export default function litecanvas(settings = {}) {
|
|
|
889
872
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save
|
|
890
873
|
*/
|
|
891
874
|
push(translateX = 0, translateY = translateX, rotation = 0, scaleX = 1, scaleY = scaleX) {
|
|
892
|
-
DEV: assert(isNumber(translateX), 'push() 1st
|
|
893
|
-
DEV: assert(isNumber(translateY), 'push() 2nd
|
|
894
|
-
DEV: assert(isNumber(rotation), 'push() 3rd
|
|
895
|
-
DEV: assert(isNumber(scaleX), 'push() 4th
|
|
896
|
-
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')
|
|
897
880
|
|
|
898
881
|
_ctx.save()
|
|
899
882
|
instance.translate(translateX, translateY)
|
|
@@ -917,8 +900,8 @@ export default function litecanvas(settings = {}) {
|
|
|
917
900
|
* @param {number} y
|
|
918
901
|
*/
|
|
919
902
|
translate(x, y) {
|
|
920
|
-
DEV: assert(isNumber(x), 'translate() 1st
|
|
921
|
-
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')
|
|
922
905
|
|
|
923
906
|
_ctx.translate(~~x, ~~y)
|
|
924
907
|
},
|
|
@@ -930,8 +913,8 @@ export default function litecanvas(settings = {}) {
|
|
|
930
913
|
* @param {number} [y]
|
|
931
914
|
*/
|
|
932
915
|
scale(x, y = x) {
|
|
933
|
-
DEV: assert(isNumber(x), 'scale() 1st
|
|
934
|
-
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')
|
|
935
918
|
|
|
936
919
|
_ctx.scale(x, y)
|
|
937
920
|
},
|
|
@@ -942,7 +925,7 @@ export default function litecanvas(settings = {}) {
|
|
|
942
925
|
* @param {number} radians
|
|
943
926
|
*/
|
|
944
927
|
rotate(radians) {
|
|
945
|
-
DEV: assert(isNumber(radians), 'rotate() 1st
|
|
928
|
+
DEV: assert(isNumber(radians), 'rotate() 1st argument must be a number')
|
|
946
929
|
|
|
947
930
|
_ctx.rotate(radians)
|
|
948
931
|
},
|
|
@@ -954,7 +937,7 @@ export default function litecanvas(settings = {}) {
|
|
|
954
937
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalAlpha
|
|
955
938
|
*/
|
|
956
939
|
alpha(value) {
|
|
957
|
-
DEV: assert(isNumber(value), 'alpha() 1st
|
|
940
|
+
DEV: assert(isNumber(value), 'alpha() 1st argument must be a number')
|
|
958
941
|
|
|
959
942
|
_ctx.globalAlpha = instance.clamp(value, 0, 1)
|
|
960
943
|
},
|
|
@@ -967,7 +950,7 @@ export default function litecanvas(settings = {}) {
|
|
|
967
950
|
fill(color) {
|
|
968
951
|
DEV: assert(
|
|
969
952
|
null == color || (isNumber(color) && color >= 0),
|
|
970
|
-
'fill() 1st
|
|
953
|
+
'fill() 1st argument must be a non-negative number'
|
|
971
954
|
)
|
|
972
955
|
|
|
973
956
|
_ctx.fillStyle = getColor(color)
|
|
@@ -982,7 +965,7 @@ export default function litecanvas(settings = {}) {
|
|
|
982
965
|
stroke(color) {
|
|
983
966
|
DEV: assert(
|
|
984
967
|
null == color || (isNumber(color) && color >= 0),
|
|
985
|
-
'stroke() 1st
|
|
968
|
+
'stroke() 1st argument must be a non-negative number'
|
|
986
969
|
)
|
|
987
970
|
|
|
988
971
|
_ctx.strokeStyle = getColor(color)
|
|
@@ -998,7 +981,7 @@ export default function litecanvas(settings = {}) {
|
|
|
998
981
|
clip(callback) {
|
|
999
982
|
DEV: assert(
|
|
1000
983
|
'function' === typeof callback,
|
|
1001
|
-
'clip() 1st
|
|
984
|
+
'clip() 1st argument must be a function (ctx) => void'
|
|
1002
985
|
)
|
|
1003
986
|
|
|
1004
987
|
beginPath(_ctx)
|
|
@@ -1021,15 +1004,15 @@ export default function litecanvas(settings = {}) {
|
|
|
1021
1004
|
sfx(zzfxParams, pitchSlide, volumeFactor) {
|
|
1022
1005
|
DEV: assert(
|
|
1023
1006
|
null == zzfxParams || Array.isArray(zzfxParams),
|
|
1024
|
-
'sfx() 1st
|
|
1007
|
+
'sfx() 1st argument must be an array'
|
|
1025
1008
|
)
|
|
1026
1009
|
DEV: assert(
|
|
1027
1010
|
null == pitchSlide || isNumber(pitchSlide),
|
|
1028
|
-
'sfx() 2nd
|
|
1011
|
+
'sfx() 2nd argument must be a number'
|
|
1029
1012
|
)
|
|
1030
1013
|
DEV: assert(
|
|
1031
1014
|
null == volumeFactor || isNumber(volumeFactor),
|
|
1032
|
-
'sfx() 3rd
|
|
1015
|
+
'sfx() 3rd argument must be a number'
|
|
1033
1016
|
)
|
|
1034
1017
|
|
|
1035
1018
|
if (
|
|
@@ -1062,7 +1045,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1062
1045
|
volume(value) {
|
|
1063
1046
|
DEV: assert(
|
|
1064
1047
|
isNumber(value) && value >= 0,
|
|
1065
|
-
'volume() 1st
|
|
1048
|
+
'volume() 1st argument must be a non-negative number'
|
|
1066
1049
|
)
|
|
1067
1050
|
|
|
1068
1051
|
root.zzfxV = value
|
|
@@ -1085,13 +1068,42 @@ export default function litecanvas(settings = {}) {
|
|
|
1085
1068
|
use(callback, config = {}) {
|
|
1086
1069
|
DEV: assert(
|
|
1087
1070
|
'function' === typeof callback,
|
|
1088
|
-
'use() 1st
|
|
1071
|
+
'use() 1st argument must be a function (instance, config) => any'
|
|
1089
1072
|
)
|
|
1090
|
-
DEV: assert('object' === typeof config, 'use() 2nd
|
|
1073
|
+
DEV: assert('object' === typeof config, 'use() 2nd argument must be an object')
|
|
1091
1074
|
|
|
1092
1075
|
loadPlugin(callback, config)
|
|
1093
1076
|
},
|
|
1094
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.height = height
|
|
1102
|
+
settings.autoscale = null == autoscale ? settings.autoscale : autoscale
|
|
1103
|
+
|
|
1104
|
+
resizeCanvas()
|
|
1105
|
+
},
|
|
1106
|
+
|
|
1095
1107
|
/**
|
|
1096
1108
|
* Add a game event listener.
|
|
1097
1109
|
*
|
|
@@ -1099,8 +1111,8 @@ export default function litecanvas(settings = {}) {
|
|
|
1099
1111
|
* @param {Function} callback the function that is called when the event occurs
|
|
1100
1112
|
*/
|
|
1101
1113
|
listen: (eventName, callback) => {
|
|
1102
|
-
DEV: assert('string' === typeof eventName, 'listen() 1st
|
|
1103
|
-
DEV: assert('function' === typeof callback, 'listen() 2nd
|
|
1114
|
+
DEV: assert('string' === typeof eventName, 'listen() 1st argument must be a string')
|
|
1115
|
+
DEV: assert('function' === typeof callback, 'listen() 2nd argument must be a function')
|
|
1104
1116
|
|
|
1105
1117
|
eventName = lowerCase(eventName)
|
|
1106
1118
|
|
|
@@ -1115,10 +1127,10 @@ export default function litecanvas(settings = {}) {
|
|
|
1115
1127
|
* @param {Function} callback the function that is called when the event occurs
|
|
1116
1128
|
*/
|
|
1117
1129
|
unlisten: (eventName, callback) => {
|
|
1118
|
-
DEV: assert('string' === typeof eventName, 'unlisten() 1st
|
|
1130
|
+
DEV: assert('string' === typeof eventName, 'unlisten() 1st argument must be a string')
|
|
1119
1131
|
DEV: assert(
|
|
1120
1132
|
'function' === typeof callback,
|
|
1121
|
-
'unlisten() 2nd
|
|
1133
|
+
'unlisten() 2nd argument must be a function'
|
|
1122
1134
|
)
|
|
1123
1135
|
|
|
1124
1136
|
eventName = lowerCase(eventName)
|
|
@@ -1143,7 +1155,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1143
1155
|
* @returns {any} always returns the second argument
|
|
1144
1156
|
*/
|
|
1145
1157
|
emit(eventName, arg1, arg2, arg3, arg4) {
|
|
1146
|
-
DEV: assert('string' === typeof eventName, 'emit() 1st
|
|
1158
|
+
DEV: assert('string' === typeof eventName, 'emit() 1st argument must be a string')
|
|
1147
1159
|
|
|
1148
1160
|
if (_initialized) {
|
|
1149
1161
|
eventName = lowerCase(eventName)
|
|
@@ -1178,11 +1190,11 @@ export default function litecanvas(settings = {}) {
|
|
|
1178
1190
|
pal(colors, textColor = 3) {
|
|
1179
1191
|
DEV: assert(
|
|
1180
1192
|
null == colors || (Array.isArray(colors) && colors.length > 0),
|
|
1181
|
-
'pal() 1st
|
|
1193
|
+
'pal() 1st argument must be null or an array of colors'
|
|
1182
1194
|
)
|
|
1183
1195
|
DEV: assert(
|
|
1184
1196
|
isNumber(textColor) && textColor >= 0,
|
|
1185
|
-
'pal() 2nd
|
|
1197
|
+
'pal() 2nd argument must be a non-negative number'
|
|
1186
1198
|
)
|
|
1187
1199
|
|
|
1188
1200
|
_colorPalette = colors || defaultPalette
|
|
@@ -1205,11 +1217,11 @@ export default function litecanvas(settings = {}) {
|
|
|
1205
1217
|
palc(a, b) {
|
|
1206
1218
|
DEV: assert(
|
|
1207
1219
|
null == a || (isNumber(a) && a >= 0),
|
|
1208
|
-
'palc() 1st
|
|
1220
|
+
'palc() 1st argument must be a positive number'
|
|
1209
1221
|
)
|
|
1210
1222
|
DEV: assert(
|
|
1211
1223
|
isNumber(a) ? isNumber(b) && b >= 0 : null == b,
|
|
1212
|
-
'palc() 2nd
|
|
1224
|
+
'palc() 2nd argument must be a positive number'
|
|
1213
1225
|
)
|
|
1214
1226
|
|
|
1215
1227
|
if (null == a) {
|
|
@@ -1231,7 +1243,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1231
1243
|
* @param {any} value the property value
|
|
1232
1244
|
*/
|
|
1233
1245
|
def(key, value) {
|
|
1234
|
-
DEV: assert('string' === typeof key, 'def() 1st
|
|
1246
|
+
DEV: assert('string' === typeof key, 'def() 1st argument must be a string')
|
|
1235
1247
|
DEV: if (null == value) {
|
|
1236
1248
|
console.warn(
|
|
1237
1249
|
`[litecanvas] def() changed the key "${key}" to null (previous value was ${instance[key]})`
|
|
@@ -1254,7 +1266,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1254
1266
|
timescale(value) {
|
|
1255
1267
|
DEV: assert(
|
|
1256
1268
|
isNumber(value) && value >= 0,
|
|
1257
|
-
'timescale() 1st
|
|
1269
|
+
'timescale() 1st argument must be a non-negative number'
|
|
1258
1270
|
)
|
|
1259
1271
|
|
|
1260
1272
|
_timeScale = value
|
|
@@ -1268,7 +1280,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1268
1280
|
framerate(value) {
|
|
1269
1281
|
DEV: assert(
|
|
1270
1282
|
isNumber(value) && value >= 1,
|
|
1271
|
-
'framerate() 1st
|
|
1283
|
+
'framerate() 1st argument must be a number >= 1'
|
|
1272
1284
|
)
|
|
1273
1285
|
|
|
1274
1286
|
_fpsInterval = 1000 / ~~value
|
|
@@ -1281,7 +1293,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1281
1293
|
* @returns {any}
|
|
1282
1294
|
*/
|
|
1283
1295
|
stat(index) {
|
|
1284
|
-
DEV: assert(isNumber(index), 'stat() 1st
|
|
1296
|
+
DEV: assert(isNumber(index), 'stat() 1st argument must be a number')
|
|
1285
1297
|
|
|
1286
1298
|
const internals = [
|
|
1287
1299
|
// 0
|
|
@@ -1330,12 +1342,21 @@ export default function litecanvas(settings = {}) {
|
|
|
1330
1342
|
DEV: assert(
|
|
1331
1343
|
index >= 0 && index < internals.length,
|
|
1332
1344
|
|
|
1333
|
-
'stat() 1st
|
|
1345
|
+
'stat() 1st argument must be a number between 0 and ' + (internals.length - 1)
|
|
1334
1346
|
)
|
|
1335
1347
|
|
|
1336
1348
|
return internals[index]
|
|
1337
1349
|
},
|
|
1338
1350
|
|
|
1351
|
+
/**
|
|
1352
|
+
* Returns `true` if the engine loop is paused.
|
|
1353
|
+
*
|
|
1354
|
+
* @returns {boolean}
|
|
1355
|
+
*/
|
|
1356
|
+
ispaused() {
|
|
1357
|
+
return _paused
|
|
1358
|
+
},
|
|
1359
|
+
|
|
1339
1360
|
/**
|
|
1340
1361
|
* Pauses the engine loop (update & draw).
|
|
1341
1362
|
*/
|
|
@@ -1363,15 +1384,6 @@ export default function litecanvas(settings = {}) {
|
|
|
1363
1384
|
}
|
|
1364
1385
|
},
|
|
1365
1386
|
|
|
1366
|
-
/**
|
|
1367
|
-
* Returns `true` if the engine loop is paused.
|
|
1368
|
-
*
|
|
1369
|
-
* @returns {boolean}
|
|
1370
|
-
*/
|
|
1371
|
-
ispaused() {
|
|
1372
|
-
return _paused
|
|
1373
|
-
},
|
|
1374
|
-
|
|
1375
1387
|
/**
|
|
1376
1388
|
* Shutdown the litecanvas instance and remove all event listeners.
|
|
1377
1389
|
*/
|
|
@@ -1622,7 +1634,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1622
1634
|
*/
|
|
1623
1635
|
const keyCheck = (keySet, key = '') => {
|
|
1624
1636
|
key = lowerCase(key)
|
|
1625
|
-
return
|
|
1637
|
+
return key ? keySet.has('space' === key ? ' ' : key) : keySet.size > 0
|
|
1626
1638
|
}
|
|
1627
1639
|
|
|
1628
1640
|
/** @type {string} */
|
|
@@ -1653,7 +1665,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1653
1665
|
(key) => {
|
|
1654
1666
|
DEV: assert(
|
|
1655
1667
|
null == key || 'string' === typeof key,
|
|
1656
|
-
'iskeydown() 1st
|
|
1668
|
+
'iskeydown() 1st argument must be a string'
|
|
1657
1669
|
)
|
|
1658
1670
|
return keyCheck(_keysDown, key)
|
|
1659
1671
|
}
|
|
@@ -1668,7 +1680,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1668
1680
|
(key) => {
|
|
1669
1681
|
DEV: assert(
|
|
1670
1682
|
null == key || 'string' === typeof key,
|
|
1671
|
-
'iskeypressed() 1st
|
|
1683
|
+
'iskeypressed() 1st argument must be a string'
|
|
1672
1684
|
)
|
|
1673
1685
|
return keyCheck(_keysPress, key)
|
|
1674
1686
|
}
|
|
@@ -1748,14 +1760,10 @@ export default function litecanvas(settings = {}) {
|
|
|
1748
1760
|
|
|
1749
1761
|
on(_canvas, 'click', () => focus())
|
|
1750
1762
|
|
|
1751
|
-
resizeCanvas()
|
|
1752
|
-
|
|
1753
1763
|
if (!_canvas.parentNode) {
|
|
1754
1764
|
d.body.appendChild(_canvas)
|
|
1755
1765
|
}
|
|
1756
1766
|
|
|
1757
|
-
_canvas.style.imageRendering = 'pixelated'
|
|
1758
|
-
|
|
1759
1767
|
// disable default browser's right click in canvas
|
|
1760
1768
|
_canvas.oncontextmenu = () => false
|
|
1761
1769
|
}
|
|
@@ -1774,6 +1782,11 @@ export default function litecanvas(settings = {}) {
|
|
|
1774
1782
|
|
|
1775
1783
|
'litecanvas() option "width" is required when the option "height" is defined'
|
|
1776
1784
|
)
|
|
1785
|
+
DEV: assert(
|
|
1786
|
+
'boolean' === typeof settings.autoscale ||
|
|
1787
|
+
(isNumber(settings.autoscale) && settings.autoscale > 1),
|
|
1788
|
+
'litecanvas() option "autoscale" must be boolean or a number > 1'
|
|
1789
|
+
)
|
|
1777
1790
|
|
|
1778
1791
|
const width = settings.width > 0 ? settings.width : innerWidth,
|
|
1779
1792
|
height = settings.width > 0 ? settings.height || settings.width : innerHeight
|
|
@@ -1784,6 +1797,9 @@ export default function litecanvas(settings = {}) {
|
|
|
1784
1797
|
_canvas.width = width
|
|
1785
1798
|
_canvas.height = height
|
|
1786
1799
|
|
|
1800
|
+
/** @ts-ignore */
|
|
1801
|
+
_canvas.style = 'image-rendering:pixelated'
|
|
1802
|
+
|
|
1787
1803
|
if (settings.autoscale) {
|
|
1788
1804
|
let maxScale = +settings.autoscale
|
|
1789
1805
|
if (!_canvas.style.display) {
|
|
@@ -1863,8 +1879,10 @@ export default function litecanvas(settings = {}) {
|
|
|
1863
1879
|
|
|
1864
1880
|
// setup the canvas
|
|
1865
1881
|
setupCanvas()
|
|
1882
|
+
resizeCanvas()
|
|
1866
1883
|
|
|
1867
1884
|
// setup default event listeners
|
|
1885
|
+
// they have high priority
|
|
1868
1886
|
if (_loop) {
|
|
1869
1887
|
for (const eventName in _loop) {
|
|
1870
1888
|
if (_loop[eventName]) instance.listen(eventName, _loop[eventName])
|