litecanvas 0.75.0 → 0.75.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 +293 -384
- package/dist/dist.js +1 -383
- package/package.json +2 -2
- package/src/index.js +349 -397
package/src/index.js
CHANGED
|
@@ -163,11 +163,10 @@ export default function litecanvas(settings = {}) {
|
|
|
163
163
|
* @tutorial https://gamedev.net/tutorials/programming/general-and-gameplay-programming/a-brief-introduction-to-lerp-r4954/
|
|
164
164
|
*/
|
|
165
165
|
lerp: (start, end, t) => {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
166
|
+
DEV: assert(isFinite(start), 'lerp: 1st param must be a number')
|
|
167
|
+
DEV: assert(isFinite(end), 'lerp: 2nd param must be a number')
|
|
168
|
+
DEV: assert(isFinite(t), 'lerp: 3rd param must be a number')
|
|
169
|
+
|
|
171
170
|
return t * (end - start) + start
|
|
172
171
|
},
|
|
173
172
|
|
|
@@ -178,9 +177,8 @@ export default function litecanvas(settings = {}) {
|
|
|
178
177
|
* @returns {number} the value in radians
|
|
179
178
|
*/
|
|
180
179
|
deg2rad: (degs) => {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
180
|
+
DEV: assert(isFinite(degs), 'deg2rad: 1st param must be a number')
|
|
181
|
+
|
|
184
182
|
return (PI / 180) * degs
|
|
185
183
|
},
|
|
186
184
|
|
|
@@ -191,9 +189,8 @@ export default function litecanvas(settings = {}) {
|
|
|
191
189
|
* @returns {number} the value in degrees
|
|
192
190
|
*/
|
|
193
191
|
rad2deg: (rads) => {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
192
|
+
DEV: assert(isFinite(rads), 'rad2deg: 1st param must be a number')
|
|
193
|
+
|
|
197
194
|
return (180 / PI) * rads
|
|
198
195
|
},
|
|
199
196
|
|
|
@@ -206,15 +203,14 @@ export default function litecanvas(settings = {}) {
|
|
|
206
203
|
* @returns {number}
|
|
207
204
|
*/
|
|
208
205
|
clamp: (value, min, max) => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
206
|
+
DEV: assert(isFinite(value), 'clamp: 1st param must be a number')
|
|
207
|
+
DEV: assert(isFinite(min), 'clamp: 2nd param must be a number')
|
|
208
|
+
DEV: assert(isFinite(max), 'clamp: 3rd param must be a number')
|
|
209
|
+
DEV: assert(
|
|
210
|
+
max > min,
|
|
211
|
+
'randi: the 2nd param must be less than the 3rd param'
|
|
212
|
+
)
|
|
213
|
+
|
|
218
214
|
if (value < min) return min
|
|
219
215
|
if (value > max) return max
|
|
220
216
|
return value
|
|
@@ -229,19 +225,18 @@ export default function litecanvas(settings = {}) {
|
|
|
229
225
|
* @returns {number}
|
|
230
226
|
*/
|
|
231
227
|
wrap: (value, min, max) => {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
228
|
+
DEV: assert(isFinite(value), 'wrap: 1st param must be a number')
|
|
229
|
+
DEV: assert(isFinite(min), 'wrap: 2nd param must be a number')
|
|
230
|
+
DEV: assert(isFinite(max), 'wrap: 3rd param must be a number')
|
|
231
|
+
DEV: assert(
|
|
232
|
+
max > min,
|
|
233
|
+
'randi: the 2nd param must be less than the 3rd param'
|
|
234
|
+
)
|
|
235
|
+
DEV: assert(
|
|
236
|
+
max !== min,
|
|
237
|
+
'randi: the 2nd param must be not equal to the 3rd param'
|
|
238
|
+
)
|
|
239
|
+
|
|
245
240
|
return value - (max - min) * Math.floor((value - min) / (max - min))
|
|
246
241
|
},
|
|
247
242
|
|
|
@@ -257,13 +252,12 @@ export default function litecanvas(settings = {}) {
|
|
|
257
252
|
* @returns {number} the remapped number
|
|
258
253
|
*/
|
|
259
254
|
map(value, start1, stop1, start2, stop2, withinBounds) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
255
|
+
DEV: assert(isFinite(value), 'map: 1st param must be a number')
|
|
256
|
+
DEV: assert(isFinite(start1), 'map: 2nd param must be a number')
|
|
257
|
+
DEV: assert(isFinite(stop1), 'map: 3rd param must be a number')
|
|
258
|
+
DEV: assert(isFinite(start2), 'map: 4th param must be a number')
|
|
259
|
+
DEV: assert(isFinite(stop2), 'map: 5th param must be a number')
|
|
260
|
+
|
|
267
261
|
// prettier-ignore
|
|
268
262
|
const result = ((value - start1) / (stop1 - start1)) * (stop2 - start2) + start2
|
|
269
263
|
return withinBounds ? instance.clamp(result, start2, stop2) : result
|
|
@@ -280,11 +274,10 @@ export default function litecanvas(settings = {}) {
|
|
|
280
274
|
* @returns {number} the normalized number.
|
|
281
275
|
*/
|
|
282
276
|
norm: (value, start, stop) => {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
277
|
+
DEV: assert(isFinite(value), 'norm: 1st param must be a number')
|
|
278
|
+
DEV: assert(isFinite(start), 'norm: 2nd param must be a number')
|
|
279
|
+
DEV: assert(isFinite(stop), 'norm: 3rd param must be a number')
|
|
280
|
+
|
|
288
281
|
return instance.map(value, start, stop, 0, 1)
|
|
289
282
|
},
|
|
290
283
|
|
|
@@ -298,14 +291,13 @@ export default function litecanvas(settings = {}) {
|
|
|
298
291
|
* @returns {number} the random number
|
|
299
292
|
*/
|
|
300
293
|
rand: (min = 0.0, max = 1.0) => {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
294
|
+
DEV: assert(isFinite(min), 'rand: 1st param must be a number')
|
|
295
|
+
DEV: assert(isFinite(max), 'rand: 2nd param must be a number')
|
|
296
|
+
DEV: assert(
|
|
297
|
+
max > min,
|
|
298
|
+
'rand: the 1st param must be less than the 2nd param'
|
|
299
|
+
)
|
|
300
|
+
|
|
309
301
|
const a = 1664525
|
|
310
302
|
const c = 1013904223
|
|
311
303
|
const m = 4294967296
|
|
@@ -323,14 +315,13 @@ export default function litecanvas(settings = {}) {
|
|
|
323
315
|
* @returns {number} the random number
|
|
324
316
|
*/
|
|
325
317
|
randi: (min = 0, max = 1) => {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
318
|
+
DEV: assert(isFinite(min), 'randi: 1st param must be a number')
|
|
319
|
+
DEV: assert(isFinite(max), 'randi: 2nd param must be a number')
|
|
320
|
+
DEV: assert(
|
|
321
|
+
max > min,
|
|
322
|
+
'randi: the 1st param must be less than the 2nd param'
|
|
323
|
+
)
|
|
324
|
+
|
|
334
325
|
return Math.floor(instance.rand(min, max + 1))
|
|
335
326
|
},
|
|
336
327
|
|
|
@@ -342,12 +333,11 @@ export default function litecanvas(settings = {}) {
|
|
|
342
333
|
* @returns {number} the seed state
|
|
343
334
|
*/
|
|
344
335
|
seed: (value) => {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
336
|
+
DEV: assert(
|
|
337
|
+
null == value || (isFinite(value) && value >= 0),
|
|
338
|
+
'seed: 1st param must be a positive number or zero'
|
|
339
|
+
)
|
|
340
|
+
|
|
351
341
|
return null == value ? _rng_seed : (_rng_seed = ~~value)
|
|
352
342
|
},
|
|
353
343
|
|
|
@@ -358,12 +348,11 @@ export default function litecanvas(settings = {}) {
|
|
|
358
348
|
* @param {number?} color The background color (index) or null (for transparent)
|
|
359
349
|
*/
|
|
360
350
|
cls(color) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
}
|
|
351
|
+
DEV: assert(
|
|
352
|
+
null == color || (isFinite(color) && color >= 0),
|
|
353
|
+
'cls: 1st param must be a positive number or zero or null'
|
|
354
|
+
)
|
|
355
|
+
|
|
367
356
|
if (null == color) {
|
|
368
357
|
_ctx.clearRect(0, 0, _ctx.canvas.width, _ctx.canvas.height)
|
|
369
358
|
} else {
|
|
@@ -388,28 +377,27 @@ export default function litecanvas(settings = {}) {
|
|
|
388
377
|
* @param {number|number[]} [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
|
|
389
378
|
*/
|
|
390
379
|
rect(x, y, width, height, color, radii = null) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}
|
|
380
|
+
DEV: assert(isFinite(x), 'rect: 1st param must be a number')
|
|
381
|
+
DEV: assert(isFinite(y), 'rect: 2nd param must be a number')
|
|
382
|
+
DEV: assert(
|
|
383
|
+
isFinite(width) && width > 0,
|
|
384
|
+
'rect: 3rd param must be a positive number'
|
|
385
|
+
)
|
|
386
|
+
DEV: assert(
|
|
387
|
+
isFinite(height) && height >= 0,
|
|
388
|
+
'rect: 4th param must be a positive number or zero'
|
|
389
|
+
)
|
|
390
|
+
DEV: assert(
|
|
391
|
+
null == color || (isFinite(color) && color >= 0),
|
|
392
|
+
'rect: 5th param must be a positive number or zero'
|
|
393
|
+
)
|
|
394
|
+
DEV: assert(
|
|
395
|
+
null == radii ||
|
|
396
|
+
isFinite(radii) ||
|
|
397
|
+
(Array.isArray(radii) && radii.length >= 1),
|
|
398
|
+
'rect: 6th param must be a number or array of numbers'
|
|
399
|
+
)
|
|
400
|
+
|
|
413
401
|
_ctx.beginPath()
|
|
414
402
|
_ctx[radii ? 'roundRect' : 'rect'](
|
|
415
403
|
~~x - _outline_fix,
|
|
@@ -432,28 +420,27 @@ export default function litecanvas(settings = {}) {
|
|
|
432
420
|
* @param {number|number[]} [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
|
|
433
421
|
*/
|
|
434
422
|
rectfill(x, y, width, height, color, radii = null) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
423
|
+
DEV: assert(isFinite(x), 'rectfill: 1st param must be a number')
|
|
424
|
+
DEV: assert(isFinite(y), 'rectfill: 2nd param must be a number')
|
|
425
|
+
DEV: assert(
|
|
426
|
+
isFinite(width) && width >= 0,
|
|
427
|
+
'rectfill: 3rd param must be a positive number or zero'
|
|
428
|
+
)
|
|
429
|
+
DEV: assert(
|
|
430
|
+
isFinite(height) && height >= 0,
|
|
431
|
+
'rectfill: 4th param must be a positive number or zero'
|
|
432
|
+
)
|
|
433
|
+
DEV: assert(
|
|
434
|
+
null == color || (isFinite(color) && color >= 0),
|
|
435
|
+
'rectfill: 5th param must be a positive number or zero'
|
|
436
|
+
)
|
|
437
|
+
DEV: assert(
|
|
438
|
+
null == radii ||
|
|
439
|
+
isFinite(radii) ||
|
|
440
|
+
(Array.isArray(radii) && radii.length >= 1),
|
|
441
|
+
'rectfill: 6th param must be a number or array of at least 2 numbers'
|
|
442
|
+
)
|
|
443
|
+
|
|
457
444
|
_ctx.beginPath()
|
|
458
445
|
_ctx[radii ? 'roundRect' : 'rect'](
|
|
459
446
|
~~x,
|
|
@@ -474,18 +461,17 @@ export default function litecanvas(settings = {}) {
|
|
|
474
461
|
* @param {number} [color=0] the color index
|
|
475
462
|
*/
|
|
476
463
|
circ(x, y, radius, color) {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
}
|
|
464
|
+
DEV: assert(isFinite(x), 'circ: 1st param must be a number')
|
|
465
|
+
DEV: assert(isFinite(y), 'circ: 2nd param must be a number')
|
|
466
|
+
DEV: assert(
|
|
467
|
+
isFinite(radius) && radius >= 0,
|
|
468
|
+
'circ: 3rd param must be a positive number or zero'
|
|
469
|
+
)
|
|
470
|
+
DEV: assert(
|
|
471
|
+
null == color || (isFinite(color) && color >= 0),
|
|
472
|
+
'circ: 4th param must be a positive number or zero'
|
|
473
|
+
)
|
|
474
|
+
|
|
489
475
|
_ctx.beginPath()
|
|
490
476
|
_ctx.arc(~~x, ~~y, ~~radius, 0, TWO_PI)
|
|
491
477
|
instance.stroke(color)
|
|
@@ -500,18 +486,17 @@ export default function litecanvas(settings = {}) {
|
|
|
500
486
|
* @param {number} [color=0] the color index
|
|
501
487
|
*/
|
|
502
488
|
circfill(x, y, radius, color) {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
}
|
|
489
|
+
DEV: assert(isFinite(x), 'circfill: 1st param must be a number')
|
|
490
|
+
DEV: assert(isFinite(y), 'circfill: 2nd param must be a number')
|
|
491
|
+
DEV: assert(
|
|
492
|
+
isFinite(radius) && radius >= 0,
|
|
493
|
+
'circfill: 3rd param must be a positive number or zero'
|
|
494
|
+
)
|
|
495
|
+
DEV: assert(
|
|
496
|
+
null == color || (isFinite(color) && color >= 0),
|
|
497
|
+
'circfill: 4th param must be a positive number or zero'
|
|
498
|
+
)
|
|
499
|
+
|
|
515
500
|
_ctx.beginPath()
|
|
516
501
|
_ctx.arc(~~x, ~~y, ~~radius, 0, TWO_PI)
|
|
517
502
|
instance.fill(color)
|
|
@@ -527,22 +512,21 @@ export default function litecanvas(settings = {}) {
|
|
|
527
512
|
* @param {number} [color=0] the color index
|
|
528
513
|
*/
|
|
529
514
|
line(x1, y1, x2, y2, color) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
}
|
|
515
|
+
DEV: assert(isFinite(x1), 'line: 1st param must be a number')
|
|
516
|
+
DEV: assert(isFinite(y1), 'line: 2nd param must be a number')
|
|
517
|
+
DEV: assert(
|
|
518
|
+
isFinite(x2),
|
|
519
|
+
'line: 3rd param must be a positive number or zero'
|
|
520
|
+
)
|
|
521
|
+
DEV: assert(
|
|
522
|
+
isFinite(y2),
|
|
523
|
+
'line: 4th param must be a positive number or zero'
|
|
524
|
+
)
|
|
525
|
+
DEV: assert(
|
|
526
|
+
null == color || (isFinite(color) && color >= 0),
|
|
527
|
+
'line: 5th param must be a positive number or zero'
|
|
528
|
+
)
|
|
529
|
+
|
|
546
530
|
_ctx.beginPath()
|
|
547
531
|
|
|
548
532
|
let xfix = _outline_fix !== 0 && ~~x1 === ~~x2 ? 0.5 : 0
|
|
@@ -561,12 +545,11 @@ export default function litecanvas(settings = {}) {
|
|
|
561
545
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineWidth
|
|
562
546
|
*/
|
|
563
547
|
linewidth(value) {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
}
|
|
548
|
+
DEV: assert(
|
|
549
|
+
isFinite(value) && ~~value > 0,
|
|
550
|
+
'linewidth: 1st param must be a positive number'
|
|
551
|
+
)
|
|
552
|
+
|
|
570
553
|
_ctx.lineWidth = ~~value
|
|
571
554
|
_outline_fix = ~~value % 2 === 0 ? 0 : 0.5
|
|
572
555
|
},
|
|
@@ -580,13 +563,15 @@ export default function litecanvas(settings = {}) {
|
|
|
580
563
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
|
|
581
564
|
*/
|
|
582
565
|
linedash(segments, offset = 0) {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
566
|
+
DEV: assert(
|
|
567
|
+
Array.isArray(segments) && segments.length > 0,
|
|
568
|
+
'linedash: 1st param must be an array of numbers'
|
|
569
|
+
)
|
|
570
|
+
DEV: assert(
|
|
571
|
+
isFinite(offset),
|
|
572
|
+
'linedash: 2nd param must be a number'
|
|
573
|
+
)
|
|
574
|
+
|
|
590
575
|
_ctx.setLineDash(segments)
|
|
591
576
|
_ctx.lineDashOffset = offset
|
|
592
577
|
},
|
|
@@ -602,22 +587,21 @@ export default function litecanvas(settings = {}) {
|
|
|
602
587
|
* @param {string} [fontStyle] can be "normal" (default), "italic" and/or "bold".
|
|
603
588
|
*/
|
|
604
589
|
text(x, y, message, color = 3, fontStyle = 'normal') {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
}
|
|
590
|
+
DEV: assert(isFinite(x), 'text: 1st param must be a number')
|
|
591
|
+
DEV: assert(isFinite(y), 'text: 2nd param must be a number')
|
|
592
|
+
// DEV: assert(
|
|
593
|
+
// 'string' === typeof message,
|
|
594
|
+
// 'text: 3rd param must be a string'
|
|
595
|
+
// )
|
|
596
|
+
DEV: assert(
|
|
597
|
+
null == color || (isFinite(color) && color >= 0),
|
|
598
|
+
'text: 4th param must be a positive number or zero'
|
|
599
|
+
)
|
|
600
|
+
DEV: assert(
|
|
601
|
+
'string' === typeof fontStyle,
|
|
602
|
+
'text: 5th param must be a string'
|
|
603
|
+
)
|
|
604
|
+
|
|
621
605
|
_ctx.font = `${fontStyle} ${_fontSize}px ${_fontFamily}`
|
|
622
606
|
_ctx.fillStyle = instance.getcolor(color)
|
|
623
607
|
_ctx.fillText(message, ~~x, ~~y)
|
|
@@ -629,12 +613,11 @@ export default function litecanvas(settings = {}) {
|
|
|
629
613
|
* @param {string} family
|
|
630
614
|
*/
|
|
631
615
|
textfont(family) {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
}
|
|
616
|
+
DEV: assert(
|
|
617
|
+
'string' === typeof family,
|
|
618
|
+
'textfont: 1st param must be a string'
|
|
619
|
+
)
|
|
620
|
+
|
|
638
621
|
_fontFamily = family
|
|
639
622
|
},
|
|
640
623
|
|
|
@@ -644,9 +627,8 @@ export default function litecanvas(settings = {}) {
|
|
|
644
627
|
* @param {number} size
|
|
645
628
|
*/
|
|
646
629
|
textsize(size) {
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
}
|
|
630
|
+
DEV: assert(isFinite(size), 'textsize: 1st param must be a number')
|
|
631
|
+
|
|
650
632
|
_fontSize = size
|
|
651
633
|
},
|
|
652
634
|
|
|
@@ -659,27 +641,24 @@ export default function litecanvas(settings = {}) {
|
|
|
659
641
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
|
|
660
642
|
*/
|
|
661
643
|
textalign(align, baseline) {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
'textalign: 2nd param must be a string'
|
|
681
|
-
)
|
|
682
|
-
}
|
|
644
|
+
DEV: assert(
|
|
645
|
+
null == align ||
|
|
646
|
+
['left', 'right', 'center', 'start', 'end'].includes(align),
|
|
647
|
+
'textalign: 1st param must be a string'
|
|
648
|
+
)
|
|
649
|
+
DEV: assert(
|
|
650
|
+
null == baseline ||
|
|
651
|
+
[
|
|
652
|
+
'top',
|
|
653
|
+
'bottom',
|
|
654
|
+
'middle',
|
|
655
|
+
'hanging',
|
|
656
|
+
'alphabetic',
|
|
657
|
+
'ideographic',
|
|
658
|
+
].includes(baseline),
|
|
659
|
+
'textalign: 2nd param must be a string'
|
|
660
|
+
)
|
|
661
|
+
|
|
683
662
|
if (align) _ctx.textAlign = align
|
|
684
663
|
if (baseline) _ctx.textBaseline = baseline
|
|
685
664
|
},
|
|
@@ -693,10 +672,9 @@ export default function litecanvas(settings = {}) {
|
|
|
693
672
|
* @param {OffscreenCanvas|HTMLImageElement|HTMLCanvasElement} source
|
|
694
673
|
*/
|
|
695
674
|
image(x, y, source) {
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
}
|
|
675
|
+
DEV: assert(isFinite(x), 'image: 1st param must be a number')
|
|
676
|
+
DEV: assert(isFinite(y), 'image: 2nd param must be a number')
|
|
677
|
+
|
|
700
678
|
_ctx.drawImage(source, ~~x, ~~y)
|
|
701
679
|
},
|
|
702
680
|
|
|
@@ -713,18 +691,17 @@ export default function litecanvas(settings = {}) {
|
|
|
713
691
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
|
|
714
692
|
*/
|
|
715
693
|
paint(width, height, drawing, options = {}) {
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
}
|
|
694
|
+
DEV: assert(isFinite(width), 'paint: 1st param must be a number')
|
|
695
|
+
DEV: assert(isFinite(height), 'paint: 2nd param must be a number')
|
|
696
|
+
DEV: assert(
|
|
697
|
+
'function' === typeof drawing || Array.isArray(drawing),
|
|
698
|
+
'paint: 3rd param must be a function or array'
|
|
699
|
+
)
|
|
700
|
+
DEV: assert(
|
|
701
|
+
(options && !options.scale) || isFinite(options.scale),
|
|
702
|
+
'paint: 4th param (options.scale) must be a number'
|
|
703
|
+
)
|
|
704
|
+
|
|
728
705
|
const canvas = options.canvas || new OffscreenCanvas(1, 1),
|
|
729
706
|
scale = options.scale || 1,
|
|
730
707
|
contextOriginal = _ctx
|
|
@@ -771,9 +748,6 @@ export default function litecanvas(settings = {}) {
|
|
|
771
748
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D
|
|
772
749
|
*/
|
|
773
750
|
ctx(context) {
|
|
774
|
-
if (DEV_BUILD) {
|
|
775
|
-
// TODO
|
|
776
|
-
}
|
|
777
751
|
if (context) {
|
|
778
752
|
_ctx = context
|
|
779
753
|
}
|
|
@@ -801,10 +775,9 @@ export default function litecanvas(settings = {}) {
|
|
|
801
775
|
* @param {number} y
|
|
802
776
|
*/
|
|
803
777
|
translate: (x, y) => {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
}
|
|
778
|
+
DEV: assert(isFinite(x), 'translate: 1st param must be a number')
|
|
779
|
+
DEV: assert(isFinite(y), 'translate: 2nd param must be a number')
|
|
780
|
+
|
|
808
781
|
return _ctx.translate(~~x, ~~y)
|
|
809
782
|
},
|
|
810
783
|
|
|
@@ -815,13 +788,12 @@ export default function litecanvas(settings = {}) {
|
|
|
815
788
|
* @param {number} [y]
|
|
816
789
|
*/
|
|
817
790
|
scale: (x, y) => {
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
}
|
|
791
|
+
DEV: assert(isFinite(x), 'scale: 1st param must be a number')
|
|
792
|
+
DEV: assert(
|
|
793
|
+
y == null || isFinite(y),
|
|
794
|
+
'scale: 2nd param must be a number'
|
|
795
|
+
)
|
|
796
|
+
|
|
825
797
|
return _ctx.scale(x, y || x)
|
|
826
798
|
},
|
|
827
799
|
|
|
@@ -831,9 +803,8 @@ export default function litecanvas(settings = {}) {
|
|
|
831
803
|
* @param {number} radians
|
|
832
804
|
*/
|
|
833
805
|
rotate: (radians) => {
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
}
|
|
806
|
+
DEV: assert(isFinite(radians), 'rotate: 1st param must be a number')
|
|
807
|
+
|
|
837
808
|
return _ctx.rotate(radians)
|
|
838
809
|
},
|
|
839
810
|
|
|
@@ -844,9 +815,8 @@ export default function litecanvas(settings = {}) {
|
|
|
844
815
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalAlpha
|
|
845
816
|
*/
|
|
846
817
|
alpha(value) {
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
}
|
|
818
|
+
DEV: assert(isFinite(value), 'alpha: 1st param must be a number')
|
|
819
|
+
|
|
850
820
|
_ctx.globalAlpha = instance.clamp(value, 0, 1)
|
|
851
821
|
},
|
|
852
822
|
|
|
@@ -860,14 +830,11 @@ export default function litecanvas(settings = {}) {
|
|
|
860
830
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Path2D/Path2D
|
|
861
831
|
*/
|
|
862
832
|
path: (arg) => {
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
'path: 1st param must be a string or a Path2D instance'
|
|
869
|
-
)
|
|
870
|
-
}
|
|
833
|
+
DEV: assert(
|
|
834
|
+
null == arg || 'string' === typeof arg || arg instanceof Path2D,
|
|
835
|
+
'path: 1st param must be a string or a Path2D instance'
|
|
836
|
+
)
|
|
837
|
+
|
|
871
838
|
return new Path2D(arg)
|
|
872
839
|
},
|
|
873
840
|
|
|
@@ -878,16 +845,15 @@ export default function litecanvas(settings = {}) {
|
|
|
878
845
|
* @param {Path2D} [path]
|
|
879
846
|
*/
|
|
880
847
|
fill(color, path) {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
}
|
|
848
|
+
DEV: assert(
|
|
849
|
+
null == color || (isFinite(color) && color >= 0),
|
|
850
|
+
'fill: 1st param must be a positive number or zero'
|
|
851
|
+
)
|
|
852
|
+
DEV: assert(
|
|
853
|
+
null == path || path instanceof Path2D,
|
|
854
|
+
'fill: 2nd param must be a Path2D instance'
|
|
855
|
+
)
|
|
856
|
+
|
|
891
857
|
_ctx.fillStyle = instance.getcolor(color)
|
|
892
858
|
if (path) {
|
|
893
859
|
_ctx.fill(path)
|
|
@@ -903,16 +869,15 @@ export default function litecanvas(settings = {}) {
|
|
|
903
869
|
* @param {Path2D} [path]
|
|
904
870
|
*/
|
|
905
871
|
stroke(color, path) {
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
}
|
|
872
|
+
DEV: assert(
|
|
873
|
+
null == color || (isFinite(color) && color >= 0),
|
|
874
|
+
'stroke: 1st param must be a positive number or zero'
|
|
875
|
+
)
|
|
876
|
+
DEV: assert(
|
|
877
|
+
null == path || path instanceof Path2D,
|
|
878
|
+
'stroke: 2nd param must be a Path2D instance'
|
|
879
|
+
)
|
|
880
|
+
|
|
916
881
|
_ctx.strokeStyle = instance.getcolor(color)
|
|
917
882
|
if (path) {
|
|
918
883
|
_ctx.stroke(path)
|
|
@@ -928,12 +893,11 @@ export default function litecanvas(settings = {}) {
|
|
|
928
893
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clip
|
|
929
894
|
*/
|
|
930
895
|
clip(path) {
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
}
|
|
896
|
+
DEV: assert(
|
|
897
|
+
path instanceof Path2D,
|
|
898
|
+
'clip: 1st param must be a Path2D instance'
|
|
899
|
+
)
|
|
900
|
+
|
|
937
901
|
_ctx.clip(path)
|
|
938
902
|
},
|
|
939
903
|
|
|
@@ -950,17 +914,16 @@ export default function litecanvas(settings = {}) {
|
|
|
950
914
|
* @see https://github.com/KilledByAPixel/ZzFX
|
|
951
915
|
*/
|
|
952
916
|
sfx(zzfxParams, pitchSlide = 0, volumeFactor = 1) {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
}
|
|
917
|
+
DEV: assert(
|
|
918
|
+
null == zzfxParams || Array.isArray(zzfxParams),
|
|
919
|
+
'sfx: 1st param must be an array'
|
|
920
|
+
)
|
|
921
|
+
DEV: assert(isFinite(pitchSlide), 'sfx: 2nd param must be a number')
|
|
922
|
+
DEV: assert(
|
|
923
|
+
isFinite(volumeFactor),
|
|
924
|
+
'sfx: 3rd param must be a number'
|
|
925
|
+
)
|
|
926
|
+
|
|
964
927
|
if (
|
|
965
928
|
root.zzfxV <= 0 ||
|
|
966
929
|
(navigator.userActivation &&
|
|
@@ -990,9 +953,8 @@ export default function litecanvas(settings = {}) {
|
|
|
990
953
|
* @param {number} value
|
|
991
954
|
*/
|
|
992
955
|
volume(value) {
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
}
|
|
956
|
+
DEV: assert(isFinite(value), 'volume: 1st param must be a number')
|
|
957
|
+
|
|
996
958
|
root.zzfxV = value
|
|
997
959
|
},
|
|
998
960
|
|
|
@@ -1011,16 +973,15 @@ export default function litecanvas(settings = {}) {
|
|
|
1011
973
|
* @returns {boolean}
|
|
1012
974
|
*/
|
|
1013
975
|
colrect: (x1, y1, w1, h1, x2, y2, w2, h2) => {
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
}
|
|
976
|
+
DEV: assert(isFinite(x1), 'colrect: 1st param must be a number')
|
|
977
|
+
DEV: assert(isFinite(y1), 'colrect: 2nd param must be a number')
|
|
978
|
+
DEV: assert(isFinite(w1), 'colrect: 3rd param must be a number')
|
|
979
|
+
DEV: assert(isFinite(h1), 'colrect: 4th param must be a number')
|
|
980
|
+
DEV: assert(isFinite(x2), 'colrect: 5th param must be a number')
|
|
981
|
+
DEV: assert(isFinite(y2), 'colrect: 6th param must be a number')
|
|
982
|
+
DEV: assert(isFinite(w2), 'colrect: 7th param must be a number')
|
|
983
|
+
DEV: assert(isFinite(h2), 'colrect: 8th param must be a number')
|
|
984
|
+
|
|
1024
985
|
return x1 < x2 + w2 && x1 + w1 > x2 && y1 < y2 + h2 && y1 + h1 > y2
|
|
1025
986
|
},
|
|
1026
987
|
|
|
@@ -1036,14 +997,13 @@ export default function litecanvas(settings = {}) {
|
|
|
1036
997
|
* @returns {boolean}
|
|
1037
998
|
*/
|
|
1038
999
|
colcirc: (x1, y1, r1, x2, y2, r2) => {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
}
|
|
1000
|
+
DEV: assert(isFinite(x1), 'colcirc: 1st param must be a number')
|
|
1001
|
+
DEV: assert(isFinite(y1), 'colcirc: 2nd param must be a number')
|
|
1002
|
+
DEV: assert(isFinite(r1), 'colcirc: 3rd param must be a number')
|
|
1003
|
+
DEV: assert(isFinite(x2), 'colcirc: 4th param must be a number')
|
|
1004
|
+
DEV: assert(isFinite(y2), 'colcirc: 5th param must be a number')
|
|
1005
|
+
DEV: assert(isFinite(r2), 'colcirc: 6th param must be a number')
|
|
1006
|
+
|
|
1047
1007
|
return (
|
|
1048
1008
|
(x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) <=
|
|
1049
1009
|
(r1 + r2) * (r1 + r2)
|
|
@@ -1057,16 +1017,15 @@ export default function litecanvas(settings = {}) {
|
|
|
1057
1017
|
* @param {pluginCallback} callback
|
|
1058
1018
|
*/
|
|
1059
1019
|
use(callback, config = {}) {
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
}
|
|
1020
|
+
DEV: assert(
|
|
1021
|
+
'function' === typeof callback,
|
|
1022
|
+
'use: 1st param must be a function'
|
|
1023
|
+
)
|
|
1024
|
+
DEV: assert(
|
|
1025
|
+
'object' === typeof config,
|
|
1026
|
+
'use: 2nd param must be an object'
|
|
1027
|
+
)
|
|
1028
|
+
|
|
1070
1029
|
_initialized
|
|
1071
1030
|
? loadPlugin(callback, config)
|
|
1072
1031
|
: _plugins.push([callback, config])
|
|
@@ -1080,16 +1039,15 @@ export default function litecanvas(settings = {}) {
|
|
|
1080
1039
|
* @returns {Function} a function to remove the listener
|
|
1081
1040
|
*/
|
|
1082
1041
|
listen(eventName, callback) {
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
}
|
|
1042
|
+
DEV: assert(
|
|
1043
|
+
'string' === typeof eventName,
|
|
1044
|
+
'listen: 1st param must be a string'
|
|
1045
|
+
)
|
|
1046
|
+
DEV: assert(
|
|
1047
|
+
'function' === typeof callback,
|
|
1048
|
+
'listen: 2nd param must be a function'
|
|
1049
|
+
)
|
|
1050
|
+
|
|
1093
1051
|
_events[eventName] = _events[eventName] || new Set()
|
|
1094
1052
|
_events[eventName].add(callback)
|
|
1095
1053
|
|
|
@@ -1107,12 +1065,11 @@ export default function litecanvas(settings = {}) {
|
|
|
1107
1065
|
* @param {*} [arg4] any data to be passed over the listeners
|
|
1108
1066
|
*/
|
|
1109
1067
|
emit(eventName, arg1, arg2, arg3, arg4) {
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
}
|
|
1068
|
+
DEV: assert(
|
|
1069
|
+
'string' === typeof eventName,
|
|
1070
|
+
'emit: 1st param must be a string'
|
|
1071
|
+
)
|
|
1072
|
+
|
|
1116
1073
|
triggerEvent('before:' + eventName, arg1, arg2, arg3, arg4)
|
|
1117
1074
|
triggerEvent(eventName, arg1, arg2, arg3, arg4)
|
|
1118
1075
|
triggerEvent('after:' + eventName, arg1, arg2, arg3, arg4)
|
|
@@ -1125,12 +1082,11 @@ export default function litecanvas(settings = {}) {
|
|
|
1125
1082
|
* @returns {string} the color code
|
|
1126
1083
|
*/
|
|
1127
1084
|
getcolor: (index) => {
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
}
|
|
1085
|
+
DEV: assert(
|
|
1086
|
+
null == index || (isFinite(index) && index >= 0),
|
|
1087
|
+
'getcolor: 1st param must be a number'
|
|
1088
|
+
)
|
|
1089
|
+
|
|
1134
1090
|
return colors[~~index % colors.length]
|
|
1135
1091
|
},
|
|
1136
1092
|
|
|
@@ -1141,15 +1097,14 @@ export default function litecanvas(settings = {}) {
|
|
|
1141
1097
|
* @param {*} value
|
|
1142
1098
|
*/
|
|
1143
1099
|
setvar(key, value) {
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
console.warn(`setvar: key "${key}" was defined as ${value}`)
|
|
1151
|
-
}
|
|
1100
|
+
DEV: assert(
|
|
1101
|
+
'string' === typeof key,
|
|
1102
|
+
'setvar: 1st param must be a string'
|
|
1103
|
+
)
|
|
1104
|
+
if (value == null) {
|
|
1105
|
+
console.warn(`setvar: key "${key}" was defined as ${value}`)
|
|
1152
1106
|
}
|
|
1107
|
+
|
|
1153
1108
|
instance[key] = value
|
|
1154
1109
|
if (_global) {
|
|
1155
1110
|
root[key] = value
|
|
@@ -1163,10 +1118,9 @@ export default function litecanvas(settings = {}) {
|
|
|
1163
1118
|
* @param {number} height
|
|
1164
1119
|
*/
|
|
1165
1120
|
resize(width, height) {
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
}
|
|
1121
|
+
DEV: assert(isFinite(width), 'resize: 1st param must be a number')
|
|
1122
|
+
DEV: assert(isFinite(height), 'resize: 2nd param must be a number')
|
|
1123
|
+
|
|
1170
1124
|
instance.setvar('WIDTH', (_canvas.width = width))
|
|
1171
1125
|
instance.setvar('HEIGHT', (_canvas.height = height))
|
|
1172
1126
|
pageResized()
|
|
@@ -1180,9 +1134,11 @@ export default function litecanvas(settings = {}) {
|
|
|
1180
1134
|
* @param {number} value
|
|
1181
1135
|
*/
|
|
1182
1136
|
timescale(value) {
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1137
|
+
DEV: assert(
|
|
1138
|
+
isFinite(value),
|
|
1139
|
+
'timescale: 1st param must be a number'
|
|
1140
|
+
)
|
|
1141
|
+
|
|
1186
1142
|
_timeScale = value
|
|
1187
1143
|
},
|
|
1188
1144
|
|
|
@@ -1192,12 +1148,11 @@ export default function litecanvas(settings = {}) {
|
|
|
1192
1148
|
* @param {number} value
|
|
1193
1149
|
*/
|
|
1194
1150
|
setfps(value) {
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
}
|
|
1151
|
+
DEV: assert(
|
|
1152
|
+
isFinite(value) && value >= 1,
|
|
1153
|
+
'setfps: 1st param must be a positive number'
|
|
1154
|
+
)
|
|
1155
|
+
|
|
1201
1156
|
_deltaTime = 1 / ~~value
|
|
1202
1157
|
},
|
|
1203
1158
|
|
|
@@ -1382,12 +1337,11 @@ export default function litecanvas(settings = {}) {
|
|
|
1382
1337
|
* @returns {boolean}
|
|
1383
1338
|
*/
|
|
1384
1339
|
const iskeydown = (key) => {
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
}
|
|
1340
|
+
DEV: assert(
|
|
1341
|
+
'string' === typeof key,
|
|
1342
|
+
'iskeydown: 1st param must be a string'
|
|
1343
|
+
)
|
|
1344
|
+
|
|
1391
1345
|
return 'any' === key
|
|
1392
1346
|
? _keys.size > 0
|
|
1393
1347
|
: _keys.has(key.toLowerCase())
|
|
@@ -1472,20 +1426,18 @@ export default function litecanvas(settings = {}) {
|
|
|
1472
1426
|
? document.querySelector(_canvas)
|
|
1473
1427
|
: _canvas
|
|
1474
1428
|
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
)
|
|
1488
|
-
}
|
|
1429
|
+
DEV: assert(
|
|
1430
|
+
_canvas && _canvas.tagName === 'CANVAS',
|
|
1431
|
+
'Invalid canvas element'
|
|
1432
|
+
)
|
|
1433
|
+
DEV: assert(
|
|
1434
|
+
null === instance.WIDTH || instance.WIDTH > 0,
|
|
1435
|
+
'Litecanvas\' "width" option should be null or a positive number'
|
|
1436
|
+
)
|
|
1437
|
+
DEV: assert(
|
|
1438
|
+
null === instance.HEIGHT || instance.HEIGHT > 0,
|
|
1439
|
+
'Litecanvas\' "width" option should be null or a positive number'
|
|
1440
|
+
)
|
|
1489
1441
|
|
|
1490
1442
|
instance.setvar('CANVAS', _canvas)
|
|
1491
1443
|
_ctx = _canvas.getContext('2d')
|
|
@@ -1555,12 +1507,12 @@ export default function litecanvas(settings = {}) {
|
|
|
1555
1507
|
*/
|
|
1556
1508
|
function loadPlugin(callback, config) {
|
|
1557
1509
|
const pluginData = callback(instance, _helpers, config)
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1510
|
+
|
|
1511
|
+
DEV: assert(
|
|
1512
|
+
null == pluginData || 'object' === typeof pluginData,
|
|
1513
|
+
'Litecanvas plugins should return an object or nothing'
|
|
1514
|
+
)
|
|
1515
|
+
|
|
1564
1516
|
for (const key in pluginData) {
|
|
1565
1517
|
instance.setvar(key, pluginData[key])
|
|
1566
1518
|
}
|