litecanvas 0.74.3 → 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.js CHANGED
@@ -1,27 +1,10 @@
1
1
  (() => {
2
2
  // src/zzfx.js
3
3
  var zzfxX = /* @__PURE__ */ new AudioContext();
4
- var zzfx = (p = 1, k = 0.05, b = 220, e = 0, r = 0, t = 0.1, q = 0, D = 1, u = 0, y = 0, v = 0, z = 0, l = 0, E = 0, A = 0, F = 0, c = 0, w = 1, m = 0, B = 0, N = 0) => {
5
- let M = Math, d = 2 * M.PI, R = 44100, G = u *= 500 * d / R / R, C = b *= (1 - k + 2 * k * M.random(k = [])) * d / R, g = 0, H = 0, a = 0, n = 1, I = 0, J = 0, f = 0, h = N < 0 ? -1 : 1, x = d * h * N * 2 / R, L = M.cos(x), Z = M.sin, K = Z(x) / 4, O = 1 + K, X = -2 * L / O, Y = (1 - K) / O, P = (1 + h * L) / 2 / O, Q = -(h + L) / O, S = P, T = 0, U = 0, V = 0, W = 0;
6
- e = R * e + 9;
7
- m *= R;
8
- r *= R;
9
- t *= R;
10
- c *= R;
11
- y *= 500 * d / R ** 3;
12
- A *= d / R;
13
- v *= d / R;
14
- z *= R;
15
- l = R * l | 0;
16
- p *= 0.3 * (globalThis.zzfxV || 1);
17
- for (h = e + m + r + t + c | 0; a < h; k[a++] = f * p)
18
- ++J % (100 * F | 0) || (f = q ? 1 < q ? 2 < q ? 3 < q ? Z(g * g) : M.max(M.min(M.tan(g), 1), -1) : 1 - (2 * g / d % 2 + 2) % 2 : 1 - 4 * M.abs(M.round(g / d) - g / d) : Z(g), f = (l ? 1 - B + B * Z(d * a / l) : 1) * (f < 0 ? -1 : 1) * M.abs(f) ** D * (a < e ? a / e : a < e + m ? 1 - (a - e) / m * (1 - w) : a < e + m + r ? w : a < h - c ? (h - a - c) / t * w : 0), f = c ? f / 2 + (c > a ? 0 : (a < h - c ? 1 : (h - a) / c) * k[a - c | 0] / 2 / p) : f, N ? f = W = S * T + Q * (T = U) + P * (U = f) - Y * V - X * (V = W) : 0), x = (b += u += y) * M.cos(A * H++), g += x + x * E * Z(a ** 5), n && ++n > z && (b += v, C += v, n = 0), !l || ++I % l || (b = C, u = G, n = n || 1);
19
- p = zzfxX.createBuffer(1, h, R);
20
- p.getChannelData(0).set(k);
21
- b = zzfxX.createBufferSource();
22
- b.buffer = p;
23
- b.connect(zzfxX.destination);
24
- b.start();
4
+ var zzfx = (i = 1, d = 0.05, z = 220, e = 0, P = 0, S = 0.1, I = 0, c = 1, T = 0, H = 0, V = 0, J = 0, h = 0, j = 0, K = 0, E = 0, r = 0, B = 1, X = 0, L = 0, D = 0) => {
5
+ let n = Math, t = 2 * n.PI, a = 44100, F = T *= 500 * t / a / a, O = z *= (1 - d + 2 * d * n.random(d = [])) * t / a, x = 0, _ = 0, f = 0, g = 1, $ = 0, l = 0, o = 0, s = D < 0 ? -1 : 1, u = t * s * D * 2 / a, G = n.cos(u), C = n.sin, Q = C(u) / 4, M = 1 + Q, m = -2 * G / M, y = (1 - Q) / M, R = (1 + s * G) / 2 / M, A = -(s + G) / M, v = R, U = 0, W = 0, Y = 0, Z = 0;
6
+ for (e = a * e + 9, X *= a, P *= a, S *= a, r *= a, H *= 500 * t / a ** 3, K *= t / a, V *= t / a, J *= a, h = a * h | 0, i *= 0.3 * (globalThis.zzfxV || 1), s = e + X + P + S + r | 0; f < s; d[f++] = o * i) ++l % (100 * E | 0) || (o = I ? 1 < I ? 2 < I ? 3 < I ? C(x * x) : n.max(n.min(n.tan(x), 1), -1) : 1 - (2 * x / t % 2 + 2) % 2 : 1 - 4 * n.abs(n.round(x / t) - x / t) : C(x), o = (h ? 1 - L + L * C(t * f / h) : 1) * (o < 0 ? -1 : 1) * n.abs(o) ** c * (f < e ? f / e : f < e + X ? 1 - (f - e) / X * (1 - B) : f < e + X + P ? B : f < s - r ? (s - f - r) / S * B : 0), o = r ? o / 2 + (r > f ? 0 : (f < s - r ? 1 : (s - f) / r) * d[f - r | 0] / 2 / i) : o, D && (o = Z = v * U + A * (U = W) + R * (W = o) - y * Y - m * (Y = Z))), u = (z += T += H) * n.cos(K * _++), x += u + u * j * C(f ** 5), g && ++g > J && (z += V, O += V, g = 0), !h || ++$ % h || (z = O, T = F, g = g || 1);
7
+ i = zzfxX.createBuffer(1, s, a), i.getChannelData(0).set(d), z = zzfxX.createBufferSource(), z.buffer = i, z.connect(zzfxX.destination), z.start();
25
8
  };
26
9
 
27
10
  // src/palette.js
@@ -96,13 +79,6 @@
96
79
  /** @type {number[]} */
97
80
  DEFAULT_SFX: [0.5, , 1675, , 0.06, 0.2, 1, 1.8, , , 637, 0.06],
98
81
  /** MATH API */
99
- /**
100
- * The value of the mathematical constant PI (π).
101
- * Approximately 3.14159
102
- *
103
- * @type {number}
104
- */
105
- PI,
106
82
  /**
107
83
  * Twice the value of the mathematical constant PI (π).
108
84
  * Approximately 6.28318
@@ -119,7 +95,7 @@
119
95
  *
120
96
  * @type {number}
121
97
  */
122
- HALF_PI: PI * 0.5,
98
+ HALF_PI: PI / 2,
123
99
  /**
124
100
  * Calculates a linear (interpolation) value over t%.
125
101
  *
@@ -130,12 +106,7 @@
130
106
  * @tutorial https://gamedev.net/tutorials/programming/general-and-gameplay-programming/a-brief-introduction-to-lerp-r4954/
131
107
  */
132
108
  lerp: (start, end, t) => {
133
- if (false) {
134
- assert(isFinite(start), "lerp: 1st param must be a number");
135
- assert(isFinite(end), "lerp: 2nd param must be a number");
136
- assert(isFinite(t), "lerp: 3rd param must be a number");
137
- }
138
- return start + t * (end - start);
109
+ return t * (end - start) + start;
139
110
  },
140
111
  /**
141
112
  * Convert degrees to radians
@@ -144,9 +115,6 @@
144
115
  * @returns {number} the value in radians
145
116
  */
146
117
  deg2rad: (degs) => {
147
- if (false) {
148
- assert(isFinite(degs), "deg2rad: 1st param must be a number");
149
- }
150
118
  return PI / 180 * degs;
151
119
  },
152
120
  /**
@@ -156,9 +124,6 @@
156
124
  * @returns {number} the value in degrees
157
125
  */
158
126
  rad2deg: (rads) => {
159
- if (false) {
160
- assert(isFinite(rads), "rad2deg: 1st param must be a number");
161
- }
162
127
  return 180 / PI * rads;
163
128
  },
164
129
  /**
@@ -170,15 +135,6 @@
170
135
  * @returns {number}
171
136
  */
172
137
  clamp: (value, min, max) => {
173
- if (false) {
174
- assert(isFinite(value), "clamp: 1st param must be a number");
175
- assert(isFinite(min), "clamp: 2nd param must be a number");
176
- assert(isFinite(max), "clamp: 3rd param must be a number");
177
- assert(
178
- max > min,
179
- "randi: the 2nd param must be less than the 3rd param"
180
- );
181
- }
182
138
  if (value < min) return min;
183
139
  if (value > max) return max;
184
140
  return value;
@@ -192,19 +148,6 @@
192
148
  * @returns {number}
193
149
  */
194
150
  wrap: (value, min, max) => {
195
- if (false) {
196
- assert(isFinite(value), "wrap: 1st param must be a number");
197
- assert(isFinite(min), "wrap: 2nd param must be a number");
198
- assert(isFinite(max), "wrap: 3rd param must be a number");
199
- assert(
200
- max > min,
201
- "randi: the 2nd param must be less than the 3rd param"
202
- );
203
- assert(
204
- max !== min,
205
- "randi: the 2nd param must be not equal to the 3rd param"
206
- );
207
- }
208
151
  return value - (max - min) * Math.floor((value - min) / (max - min));
209
152
  },
210
153
  /**
@@ -219,13 +162,6 @@
219
162
  * @returns {number} the remapped number
220
163
  */
221
164
  map(value, start1, stop1, start2, stop2, withinBounds) {
222
- if (false) {
223
- assert(isFinite(value), "map: 1st param must be a number");
224
- assert(isFinite(start1), "map: 2nd param must be a number");
225
- assert(isFinite(stop1), "map: 3rd param must be a number");
226
- assert(isFinite(start2), "map: 4th param must be a number");
227
- assert(isFinite(stop2), "map: 5th param must be a number");
228
- }
229
165
  const result = (value - start1) / (stop1 - start1) * (stop2 - start2) + start2;
230
166
  return withinBounds ? instance.clamp(result, start2, stop2) : result;
231
167
  },
@@ -240,11 +176,6 @@
240
176
  * @returns {number} the normalized number.
241
177
  */
242
178
  norm: (value, start, stop) => {
243
- if (false) {
244
- assert(isFinite(value), "norm: 1st param must be a number");
245
- assert(isFinite(start), "norm: 2nd param must be a number");
246
- assert(isFinite(stop), "norm: 3rd param must be a number");
247
- }
248
179
  return instance.map(value, start, stop, 0, 1);
249
180
  },
250
181
  /** RNG API */
@@ -257,14 +188,6 @@
257
188
  * @returns {number} the random number
258
189
  */
259
190
  rand: (min = 0, max = 1) => {
260
- if (false) {
261
- assert(isFinite(min), "rand: 1st param must be a number");
262
- assert(isFinite(max), "rand: 2nd param must be a number");
263
- assert(
264
- max > min,
265
- "rand: the 1st param must be less than the 2nd param"
266
- );
267
- }
268
191
  const a = 1664525;
269
192
  const c = 1013904223;
270
193
  const m = 4294967296;
@@ -279,14 +202,6 @@
279
202
  * @returns {number} the random number
280
203
  */
281
204
  randi: (min = 0, max = 1) => {
282
- if (false) {
283
- assert(isFinite(min), "randi: 1st param must be a number");
284
- assert(isFinite(max), "randi: 2nd param must be a number");
285
- assert(
286
- max > min,
287
- "randi: the 1st param must be less than the 2nd param"
288
- );
289
- }
290
205
  return Math.floor(instance.rand(min, max + 1));
291
206
  },
292
207
  /**
@@ -297,12 +212,6 @@
297
212
  * @returns {number} the seed state
298
213
  */
299
214
  seed: (value) => {
300
- if (false) {
301
- assert(
302
- null == value || isFinite(value) && value >= 0,
303
- "seed: 1st param must be a positive number or zero"
304
- );
305
- }
306
215
  return null == value ? _rng_seed : _rng_seed = ~~value;
307
216
  },
308
217
  /** BASIC GRAPHICS API */
@@ -312,12 +221,6 @@
312
221
  * @param {number?} color The background color (index) or null (for transparent)
313
222
  */
314
223
  cls(color) {
315
- if (false) {
316
- assert(
317
- null == color || isFinite(color) && color >= 0,
318
- "cls: 1st param must be a positive number or zero or null"
319
- );
320
- }
321
224
  if (null == color) {
322
225
  _ctx.clearRect(0, 0, _ctx.canvas.width, _ctx.canvas.height);
323
226
  } else {
@@ -341,26 +244,6 @@
341
244
  * @param {number|number[]} [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
342
245
  */
343
246
  rect(x, y, width, height, color, radii = null) {
344
- if (false) {
345
- assert(isFinite(x), "rect: 1st param must be a number");
346
- assert(isFinite(y), "rect: 2nd param must be a number");
347
- assert(
348
- isFinite(width) && width > 0,
349
- "rect: 3rd param must be a positive number"
350
- );
351
- assert(
352
- isFinite(height) && height >= 0,
353
- "rect: 4th param must be a positive number or zero"
354
- );
355
- assert(
356
- null == color || isFinite(color) && color >= 0,
357
- "rect: 5th param must be a positive number or zero"
358
- );
359
- assert(
360
- null == radii || isFinite(radii) || Array.isArray(radii) && radii.length >= 1,
361
- "rect: 6th param must be a number or array of numbers"
362
- );
363
- }
364
247
  _ctx.beginPath();
365
248
  _ctx[radii ? "roundRect" : "rect"](
366
249
  ~~x - _outline_fix,
@@ -382,26 +265,6 @@
382
265
  * @param {number|number[]} [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
383
266
  */
384
267
  rectfill(x, y, width, height, color, radii = null) {
385
- if (false) {
386
- assert(isFinite(x), "rectfill: 1st param must be a number");
387
- assert(isFinite(y), "rectfill: 2nd param must be a number");
388
- assert(
389
- isFinite(width) && width >= 0,
390
- "rectfill: 3rd param must be a positive number or zero"
391
- );
392
- assert(
393
- isFinite(height) && height >= 0,
394
- "rectfill: 4th param must be a positive number or zero"
395
- );
396
- assert(
397
- null == color || isFinite(color) && color >= 0,
398
- "rectfill: 5th param must be a positive number or zero"
399
- );
400
- assert(
401
- null == radii || isFinite(radii) || Array.isArray(radii) && radii.length >= 1,
402
- "rectfill: 6th param must be a number or array of at least 2 numbers"
403
- );
404
- }
405
268
  _ctx.beginPath();
406
269
  _ctx[radii ? "roundRect" : "rect"](
407
270
  ~~x,
@@ -421,18 +284,6 @@
421
284
  * @param {number} [color=0] the color index
422
285
  */
423
286
  circ(x, y, radius, color) {
424
- if (false) {
425
- assert(isFinite(x), "circ: 1st param must be a number");
426
- assert(isFinite(y), "circ: 2nd param must be a number");
427
- assert(
428
- isFinite(radius) && radius >= 0,
429
- "circ: 3rd param must be a positive number or zero"
430
- );
431
- assert(
432
- null == color || isFinite(color) && color >= 0,
433
- "circ: 4th param must be a positive number or zero"
434
- );
435
- }
436
287
  _ctx.beginPath();
437
288
  _ctx.arc(~~x, ~~y, ~~radius, 0, TWO_PI);
438
289
  instance.stroke(color);
@@ -446,18 +297,6 @@
446
297
  * @param {number} [color=0] the color index
447
298
  */
448
299
  circfill(x, y, radius, color) {
449
- if (false) {
450
- assert(isFinite(x), "circfill: 1st param must be a number");
451
- assert(isFinite(y), "circfill: 2nd param must be a number");
452
- assert(
453
- isFinite(radius) && radius >= 0,
454
- "circfill: 3rd param must be a positive number or zero"
455
- );
456
- assert(
457
- null == color || isFinite(color) && color >= 0,
458
- "circfill: 4th param must be a positive number or zero"
459
- );
460
- }
461
300
  _ctx.beginPath();
462
301
  _ctx.arc(~~x, ~~y, ~~radius, 0, TWO_PI);
463
302
  instance.fill(color);
@@ -472,22 +311,6 @@
472
311
  * @param {number} [color=0] the color index
473
312
  */
474
313
  line(x1, y1, x2, y2, color) {
475
- if (false) {
476
- assert(isFinite(x1), "line: 1st param must be a number");
477
- assert(isFinite(y1), "line: 2nd param must be a number");
478
- assert(
479
- isFinite(x2),
480
- "line: 3rd param must be a positive number or zero"
481
- );
482
- assert(
483
- isFinite(y2),
484
- "line: 4th param must be a positive number or zero"
485
- );
486
- assert(
487
- null == color || isFinite(color) && color >= 0,
488
- "line: 5th param must be a positive number or zero"
489
- );
490
- }
491
314
  _ctx.beginPath();
492
315
  let xfix = _outline_fix !== 0 && ~~x1 === ~~x2 ? 0.5 : 0;
493
316
  let yfix = _outline_fix !== 0 && ~~y1 === ~~y2 ? 0.5 : 0;
@@ -502,12 +325,6 @@
502
325
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineWidth
503
326
  */
504
327
  linewidth(value) {
505
- if (false) {
506
- assert(
507
- isFinite(value) && ~~value > 0,
508
- "linewidth: 1st param must be a positive number"
509
- );
510
- }
511
328
  _ctx.lineWidth = ~~value;
512
329
  _outline_fix = ~~value % 2 === 0 ? 0 : 0.5;
513
330
  },
@@ -520,13 +337,6 @@
520
337
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
521
338
  */
522
339
  linedash(segments, offset = 0) {
523
- if (false) {
524
- assert(
525
- Array.isArray(segments) && segments.length > 0,
526
- "linedash: 1st param must be an array of numbers"
527
- );
528
- assert(isFinite(offset), "linedash: 2nd param must be a number");
529
- }
530
340
  _ctx.setLineDash(segments);
531
341
  _ctx.lineDashOffset = offset;
532
342
  },
@@ -541,18 +351,6 @@
541
351
  * @param {string} [fontStyle] can be "normal" (default), "italic" and/or "bold".
542
352
  */
543
353
  text(x, y, message, color = 3, fontStyle = "normal") {
544
- if (false) {
545
- assert(isFinite(x), "text: 1st param must be a number");
546
- assert(isFinite(y), "text: 2nd param must be a number");
547
- assert(
548
- null == color || isFinite(color) && color >= 0,
549
- "text: 4th param must be a positive number or zero"
550
- );
551
- assert(
552
- "string" === typeof fontStyle,
553
- "text: 5th param must be a string"
554
- );
555
- }
556
354
  _ctx.font = `${fontStyle} ${_fontSize}px ${_fontFamily}`;
557
355
  _ctx.fillStyle = instance.getcolor(color);
558
356
  _ctx.fillText(message, ~~x, ~~y);
@@ -563,12 +361,6 @@
563
361
  * @param {string} family
564
362
  */
565
363
  textfont(family) {
566
- if (false) {
567
- assert(
568
- "string" === typeof family,
569
- "textfont: 1st param must be a string"
570
- );
571
- }
572
364
  _fontFamily = family;
573
365
  },
574
366
  /**
@@ -577,9 +369,6 @@
577
369
  * @param {number} size
578
370
  */
579
371
  textsize(size) {
580
- if (false) {
581
- assert(isFinite(size), "textsize: 1st param must be a number");
582
- }
583
372
  _fontSize = size;
584
373
  },
585
374
  /**
@@ -591,25 +380,6 @@
591
380
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
592
381
  */
593
382
  textalign(align, baseline) {
594
- if (false) {
595
- assert(
596
- null == align || ["left", "right", "center", "start", "end"].includes(
597
- align
598
- ),
599
- "textalign: 1st param must be a string"
600
- );
601
- assert(
602
- null == baseline || [
603
- "top",
604
- "bottom",
605
- "middle",
606
- "hanging",
607
- "alphabetic",
608
- "ideographic"
609
- ].includes(baseline),
610
- "textalign: 2nd param must be a string"
611
- );
612
- }
613
383
  if (align) _ctx.textAlign = align;
614
384
  if (baseline) _ctx.textBaseline = baseline;
615
385
  },
@@ -622,10 +392,6 @@
622
392
  * @param {OffscreenCanvas|HTMLImageElement|HTMLCanvasElement} source
623
393
  */
624
394
  image(x, y, source) {
625
- if (false) {
626
- assert(isFinite(x), "image: 1st param must be a number");
627
- assert(isFinite(y), "image: 2nd param must be a number");
628
- }
629
395
  _ctx.drawImage(source, ~~x, ~~y);
630
396
  },
631
397
  /**
@@ -641,18 +407,6 @@
641
407
  * @see https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
642
408
  */
643
409
  paint(width, height, drawing, options = {}) {
644
- if (false) {
645
- assert(isFinite(width), "paint: 1st param must be a number");
646
- assert(isFinite(height), "paint: 2nd param must be a number");
647
- assert(
648
- "function" === typeof drawing || Array.isArray(drawing),
649
- "paint: 3rd param must be a function or array"
650
- );
651
- assert(
652
- options && !options.scale || isFinite(options.scale),
653
- "paint: 4th param (options.scale) must be a number"
654
- );
655
- }
656
410
  const canvas = options.canvas || new OffscreenCanvas(1, 1), scale = options.scale || 1, contextOriginal = _ctx;
657
411
  canvas.width = width * scale;
658
412
  canvas.height = height * scale;
@@ -686,8 +440,6 @@
686
440
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D
687
441
  */
688
442
  ctx(context) {
689
- if (false) {
690
- }
691
443
  if (context) {
692
444
  _ctx = context;
693
445
  }
@@ -712,10 +464,6 @@
712
464
  * @param {number} y
713
465
  */
714
466
  translate: (x, y) => {
715
- if (false) {
716
- assert(isFinite(x), "translate: 1st param must be a number");
717
- assert(isFinite(y), "translate: 2nd param must be a number");
718
- }
719
467
  return _ctx.translate(~~x, ~~y);
720
468
  },
721
469
  /**
@@ -725,13 +473,6 @@
725
473
  * @param {number} [y]
726
474
  */
727
475
  scale: (x, y) => {
728
- if (false) {
729
- assert(isFinite(x), "scale: 1st param must be a number");
730
- assert(
731
- y == null || isFinite(y),
732
- "scale: 2nd param must be a number"
733
- );
734
- }
735
476
  return _ctx.scale(x, y || x);
736
477
  },
737
478
  /**
@@ -740,9 +481,6 @@
740
481
  * @param {number} radians
741
482
  */
742
483
  rotate: (radians) => {
743
- if (false) {
744
- assert(isFinite(radians), "rotate: 1st param must be a number");
745
- }
746
484
  return _ctx.rotate(radians);
747
485
  },
748
486
  /**
@@ -752,9 +490,6 @@
752
490
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalAlpha
753
491
  */
754
492
  alpha(value) {
755
- if (false) {
756
- assert(isFinite(value), "alpha: 1st param must be a number");
757
- }
758
493
  _ctx.globalAlpha = instance.clamp(value, 0, 1);
759
494
  },
760
495
  /**
@@ -767,12 +502,6 @@
767
502
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Path2D/Path2D
768
503
  */
769
504
  path: (arg) => {
770
- if (false) {
771
- assert(
772
- null == arg || "string" === typeof arg || arg instanceof Path2D,
773
- "path: 1st param must be a string or a Path2D instance"
774
- );
775
- }
776
505
  return new Path2D(arg);
777
506
  },
778
507
  /**
@@ -782,16 +511,6 @@
782
511
  * @param {Path2D} [path]
783
512
  */
784
513
  fill(color, path) {
785
- if (false) {
786
- assert(
787
- null == color || isFinite(color) && color >= 0,
788
- "fill: 1st param must be a positive number or zero"
789
- );
790
- assert(
791
- null == path || path instanceof Path2D,
792
- "fill: 2nd param must be a Path2D instance"
793
- );
794
- }
795
514
  _ctx.fillStyle = instance.getcolor(color);
796
515
  if (path) {
797
516
  _ctx.fill(path);
@@ -806,16 +525,6 @@
806
525
  * @param {Path2D} [path]
807
526
  */
808
527
  stroke(color, path) {
809
- if (false) {
810
- assert(
811
- null == color || isFinite(color) && color >= 0,
812
- "stroke: 1st param must be a positive number or zero"
813
- );
814
- assert(
815
- null == path || path instanceof Path2D,
816
- "stroke: 2nd param must be a Path2D instance"
817
- );
818
- }
819
528
  _ctx.strokeStyle = instance.getcolor(color);
820
529
  if (path) {
821
530
  _ctx.stroke(path);
@@ -830,12 +539,6 @@
830
539
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clip
831
540
  */
832
541
  clip(path) {
833
- if (false) {
834
- assert(
835
- path instanceof Path2D,
836
- "clip: 1st param must be a Path2D instance"
837
- );
838
- }
839
542
  _ctx.clip(path);
840
543
  },
841
544
  /** SOUND API */
@@ -851,17 +554,6 @@
851
554
  * @see https://github.com/KilledByAPixel/ZzFX
852
555
  */
853
556
  sfx(zzfxParams, pitchSlide = 0, volumeFactor = 1) {
854
- if (false) {
855
- assert(
856
- null == zzfxParams || Array.isArray(zzfxParams),
857
- "sfx: 1st param must be an array"
858
- );
859
- assert(isFinite(pitchSlide), "sfx: 2nd param must be a number");
860
- assert(
861
- isFinite(volumeFactor),
862
- "sfx: 3rd param must be a number"
863
- );
864
- }
865
557
  if (root.zzfxV <= 0 || navigator.userActivation && !navigator.userActivation.hasBeenActive) {
866
558
  return false;
867
559
  }
@@ -881,9 +573,6 @@
881
573
  * @param {number} value
882
574
  */
883
575
  volume(value) {
884
- if (false) {
885
- assert(isFinite(value), "volume: 1st param must be a number");
886
- }
887
576
  root.zzfxV = value;
888
577
  },
889
578
  /** UTILS API */
@@ -901,16 +590,6 @@
901
590
  * @returns {boolean}
902
591
  */
903
592
  colrect: (x1, y1, w1, h1, x2, y2, w2, h2) => {
904
- if (false) {
905
- assert(isFinite(x1), "colrect: 1st param must be a number");
906
- assert(isFinite(y1), "colrect: 2nd param must be a number");
907
- assert(isFinite(w1), "colrect: 3rd param must be a number");
908
- assert(isFinite(h1), "colrect: 4th param must be a number");
909
- assert(isFinite(x2), "colrect: 5th param must be a number");
910
- assert(isFinite(y2), "colrect: 6th param must be a number");
911
- assert(isFinite(w2), "colrect: 7th param must be a number");
912
- assert(isFinite(h2), "colrect: 8th param must be a number");
913
- }
914
593
  return x1 < x2 + w2 && x1 + w1 > x2 && y1 < y2 + h2 && y1 + h1 > y2;
915
594
  },
916
595
  /**
@@ -925,14 +604,6 @@
925
604
  * @returns {boolean}
926
605
  */
927
606
  colcirc: (x1, y1, r1, x2, y2, r2) => {
928
- if (false) {
929
- assert(isFinite(x1), "colcirc: 1st param must be a number");
930
- assert(isFinite(y1), "colcirc: 2nd param must be a number");
931
- assert(isFinite(r1), "colcirc: 3rd param must be a number");
932
- assert(isFinite(x2), "colcirc: 4th param must be a number");
933
- assert(isFinite(y2), "colcirc: 5th param must be a number");
934
- assert(isFinite(r2), "colcirc: 6th param must be a number");
935
- }
936
607
  return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) <= (r1 + r2) * (r1 + r2);
937
608
  },
938
609
  /** PLUGINS API */
@@ -942,16 +613,6 @@
942
613
  * @param {pluginCallback} callback
943
614
  */
944
615
  use(callback, config = {}) {
945
- if (false) {
946
- assert(
947
- "function" === typeof callback,
948
- "use: 1st param must be a function"
949
- );
950
- assert(
951
- "object" === typeof config,
952
- "use: 2nd param must be an object"
953
- );
954
- }
955
616
  _initialized ? loadPlugin(callback, config) : _plugins.push([callback, config]);
956
617
  },
957
618
  /**
@@ -962,16 +623,6 @@
962
623
  * @returns {Function} a function to remove the listener
963
624
  */
964
625
  listen(eventName, callback) {
965
- if (false) {
966
- assert(
967
- "string" === typeof eventName,
968
- "listen: 1st param must be a string"
969
- );
970
- assert(
971
- "function" === typeof callback,
972
- "listen: 2nd param must be a function"
973
- );
974
- }
975
626
  _events[eventName] = _events[eventName] || /* @__PURE__ */ new Set();
976
627
  _events[eventName].add(callback);
977
628
  return () => _events[eventName].delete(callback);
@@ -986,12 +637,6 @@
986
637
  * @param {*} [arg4] any data to be passed over the listeners
987
638
  */
988
639
  emit(eventName, arg1, arg2, arg3, arg4) {
989
- if (false) {
990
- assert(
991
- "string" === typeof eventName,
992
- "emit: 1st param must be a string"
993
- );
994
- }
995
640
  triggerEvent("before:" + eventName, arg1, arg2, arg3, arg4);
996
641
  triggerEvent(eventName, arg1, arg2, arg3, arg4);
997
642
  triggerEvent("after:" + eventName, arg1, arg2, arg3, arg4);
@@ -1003,12 +648,6 @@
1003
648
  * @returns {string} the color code
1004
649
  */
1005
650
  getcolor: (index) => {
1006
- if (false) {
1007
- assert(
1008
- null == index || isFinite(index) && index >= 0,
1009
- "getcolor: 1st param must be a number"
1010
- );
1011
- }
1012
651
  return colors[~~index % colors.length];
1013
652
  },
1014
653
  /**
@@ -1018,13 +657,7 @@
1018
657
  * @param {*} value
1019
658
  */
1020
659
  setvar(key, value) {
1021
- if (false) {
1022
- assert(
1023
- "string" === typeof key,
1024
- "setvar: 1st param must be a string"
1025
- );
1026
- if (value == null) {
1027
- }
660
+ if (value == null) {
1028
661
  }
1029
662
  instance[key] = value;
1030
663
  if (_global) {
@@ -1038,10 +671,6 @@
1038
671
  * @param {number} height
1039
672
  */
1040
673
  resize(width, height) {
1041
- if (false) {
1042
- assert(isFinite(width), "resize: 1st param must be a number");
1043
- assert(isFinite(height), "resize: 2nd param must be a number");
1044
- }
1045
674
  instance.setvar("WIDTH", _canvas.width = width);
1046
675
  instance.setvar("HEIGHT", _canvas.height = height);
1047
676
  pageResized();
@@ -1054,9 +683,6 @@
1054
683
  * @param {number} value
1055
684
  */
1056
685
  timescale(value) {
1057
- if (false) {
1058
- assert(isFinite(value), "timescale: 1st param must be a number");
1059
- }
1060
686
  _timeScale = value;
1061
687
  },
1062
688
  /**
@@ -1065,12 +691,6 @@
1065
691
  * @param {number} value
1066
692
  */
1067
693
  setfps(value) {
1068
- if (false) {
1069
- assert(
1070
- isFinite(value) && value >= 1,
1071
- "setfps: 1st param must be a positive number"
1072
- );
1073
- }
1074
694
  _deltaTime = 1 / ~~value;
1075
695
  },
1076
696
  /**
@@ -1091,24 +711,7 @@
1091
711
  }
1092
712
  }
1093
713
  };
1094
- for (const k of [
1095
- "sin",
1096
- "cos",
1097
- "atan2",
1098
- "hypot",
1099
- "tan",
1100
- "abs",
1101
- "ceil",
1102
- "round",
1103
- "floor",
1104
- "trunc",
1105
- "min",
1106
- "max",
1107
- "pow",
1108
- "sqrt",
1109
- "sign",
1110
- "exp"
1111
- ]) {
714
+ for (const k of "PI,sin,cos,atan2,hypot,tan,abs,ceil,round,floor,trunc,min,max,pow,sqrt,sign,exp".split(",")) {
1112
715
  instance[k] = Math[k];
1113
716
  }
1114
717
  function init() {
@@ -1143,17 +746,32 @@
1143
746
  const tap = _taps.get(id) || _registerTap(id);
1144
747
  tap.x = x;
1145
748
  tap.y = y;
1146
- }, _checkTapped = (tap) => tap && performance.now() - tap.ts <= 200;
749
+ }, _checkTapped = (tap) => tap && performance.now() - tap.ts <= 200, preventDefault = (ev) => ev.preventDefault();
1147
750
  let _pressingMouse = false;
1148
751
  on(_canvas, "mousedown", (ev) => {
1149
- ev.preventDefault();
1150
- const [x, y] = _getXY(ev.pageX, ev.pageY);
1151
- instance.emit("tap", x, y, 0);
1152
- _registerTap(0, x, y);
1153
- _pressingMouse = true;
752
+ if (ev.button === 0) {
753
+ preventDefault(ev);
754
+ const [x, y] = _getXY(ev.pageX, ev.pageY);
755
+ instance.emit("tap", x, y, 0);
756
+ _registerTap(0, x, y);
757
+ _pressingMouse = true;
758
+ }
759
+ });
760
+ on(_canvas, "mouseup", (ev) => {
761
+ if (ev.button === 0) {
762
+ preventDefault(ev);
763
+ const tap = _taps.get(0);
764
+ const [x, y] = _getXY(ev.pageX, ev.pageY);
765
+ if (_checkTapped(tap)) {
766
+ instance.emit("tapped", tap.startX, tap.startY, 0);
767
+ }
768
+ instance.emit("untap", x, y, 0);
769
+ _taps.delete(0);
770
+ _pressingMouse = false;
771
+ }
1154
772
  });
1155
773
  on(_canvas, "mousemove", (ev) => {
1156
- ev.preventDefault();
774
+ preventDefault(ev);
1157
775
  const [x, y] = _getXY(ev.pageX, ev.pageY);
1158
776
  instance.setvar("MOUSEX", x);
1159
777
  instance.setvar("MOUSEY", y);
@@ -1161,19 +779,8 @@
1161
779
  instance.emit("tapping", x, y, 0);
1162
780
  _updateTap(0, x, y);
1163
781
  });
1164
- on(_canvas, "mouseup", (ev) => {
1165
- ev.preventDefault();
1166
- const tap = _taps.get(0);
1167
- const [x, y] = _getXY(ev.pageX, ev.pageY);
1168
- if (_checkTapped(tap)) {
1169
- instance.emit("tapped", tap.startX, tap.startY, 0);
1170
- }
1171
- instance.emit("untap", x, y, 0);
1172
- _taps.delete(0);
1173
- _pressingMouse = false;
1174
- });
1175
782
  on(_canvas, "touchstart", (ev) => {
1176
- ev.preventDefault();
783
+ preventDefault(ev);
1177
784
  const touches = ev.changedTouches;
1178
785
  for (const touch of touches) {
1179
786
  const [x, y] = _getXY(touch.pageX, touch.pageY);
@@ -1182,7 +789,7 @@
1182
789
  }
1183
790
  });
1184
791
  on(_canvas, "touchmove", (ev) => {
1185
- ev.preventDefault();
792
+ preventDefault(ev);
1186
793
  const touches = ev.changedTouches;
1187
794
  for (const touch of touches) {
1188
795
  const [x, y] = _getXY(touch.pageX, touch.pageY);
@@ -1191,7 +798,7 @@
1191
798
  }
1192
799
  });
1193
800
  const _touchEndHandler = (ev) => {
1194
- ev.preventDefault();
801
+ preventDefault(ev);
1195
802
  const existing = [];
1196
803
  if (ev.targetTouches.length > 0) {
1197
804
  for (const touch of ev.targetTouches) {
@@ -1220,12 +827,6 @@
1220
827
  if (settings.keyboardEvents) {
1221
828
  const _keys = /* @__PURE__ */ new Set();
1222
829
  const iskeydown = (key) => {
1223
- if (false) {
1224
- assert(
1225
- "string" === typeof key,
1226
- "iskeydown: 1st param must be a string"
1227
- );
1228
- }
1229
830
  return "any" === key ? _keys.size > 0 : _keys.has(key.toLowerCase());
1230
831
  };
1231
832
  instance.setvar("iskeydown", iskeydown);
@@ -1258,7 +859,8 @@
1258
859
  }
1259
860
  let updated = 0, frameTime = (now - _lastFrameTime) / 1e3;
1260
861
  _lastFrameTime = now;
1261
- if (frameTime > 1) return;
862
+ if (frameTime > _deltaTime * 30)
863
+ return void 0;
1262
864
  _accumulated += frameTime;
1263
865
  if (!_animated) {
1264
866
  _accumulated = _deltaTime;
@@ -1311,7 +913,7 @@
1311
913
  instance.setvar("CENTERY", instance.HEIGHT / 2);
1312
914
  if (!settings.antialias || settings.pixelart) {
1313
915
  _ctx.imageSmoothingEnabled = false;
1314
- _canvas.style.imageRendering = "pixelated";
916
+ styles.imageRendering = "pixelated";
1315
917
  }
1316
918
  instance.emit("resized", _scale);
1317
919
  if (!_animated) {
@@ -1326,10 +928,8 @@
1326
928
  }
1327
929
  function loadPlugin(callback, config) {
1328
930
  const pluginData = callback(instance, _helpers, config);
1329
- if ("object" === typeof pluginData) {
1330
- for (const key of Object.keys(pluginData)) {
1331
- instance.setvar(key, pluginData[key]);
1332
- }
931
+ for (const key in pluginData) {
932
+ instance.setvar(key, pluginData[key]);
1333
933
  }
1334
934
  }
1335
935
  if (_global) {