litecanvas 0.300.0 → 0.301.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +162 -152
- package/dist/dist.js +11 -6
- package/dist/dist.min.js +1 -1
- package/package.json +1 -1
- package/src/index.js +170 -145
- package/src/version.js +1 -1
- package/types/global.d.ts +8 -0
- package/types/types.d.ts +8 -0
package/dist/dist.dev.js
CHANGED
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
var assert = (condition, message = "Assertion failed") => {
|
|
116
116
|
if (!condition) throw new Error("[Litecanvas] " + message);
|
|
117
117
|
};
|
|
118
|
-
var version = "0.
|
|
118
|
+
var version = "0.301.1";
|
|
119
119
|
function litecanvas(settings = {}) {
|
|
120
120
|
const root = window,
|
|
121
121
|
math = Math,
|
|
@@ -146,11 +146,11 @@
|
|
|
146
146
|
};
|
|
147
147
|
DEV: assert(
|
|
148
148
|
null == settings || "object" === typeof settings,
|
|
149
|
-
"litecanvas() 1st
|
|
149
|
+
"litecanvas() 1st argument must be a object",
|
|
150
150
|
);
|
|
151
151
|
settings = Object.assign(defaults, settings);
|
|
152
152
|
let _loop = settings.loop,
|
|
153
|
-
_initialized
|
|
153
|
+
_initialized,
|
|
154
154
|
_paused,
|
|
155
155
|
_canvas,
|
|
156
156
|
_canvasScale = 1,
|
|
@@ -178,32 +178,32 @@
|
|
|
178
178
|
MY: -1,
|
|
179
179
|
TAU,
|
|
180
180
|
lerp: (start, end, t) => {
|
|
181
|
-
DEV: assert(isNumber(start), "lerp() 1st
|
|
182
|
-
DEV: assert(isNumber(end), "lerp() 2nd
|
|
183
|
-
DEV: assert(isNumber(t), "lerp() 3rd
|
|
181
|
+
DEV: assert(isNumber(start), "lerp() 1st argument must be a number");
|
|
182
|
+
DEV: assert(isNumber(end), "lerp() 2nd argument must be a number");
|
|
183
|
+
DEV: assert(isNumber(t), "lerp() 3rd argument must be a number");
|
|
184
184
|
return start + t * (end - start);
|
|
185
185
|
},
|
|
186
186
|
deg2rad: (degs) => {
|
|
187
|
-
DEV: assert(isNumber(degs), "deg2rad() 1st
|
|
187
|
+
DEV: assert(isNumber(degs), "deg2rad() 1st argument must be a number");
|
|
188
188
|
return (math.PI / 180) * degs;
|
|
189
189
|
},
|
|
190
190
|
rad2deg: (rads) => {
|
|
191
|
-
DEV: assert(isNumber(rads), "rad2deg() 1st
|
|
191
|
+
DEV: assert(isNumber(rads), "rad2deg() 1st argument must be a number");
|
|
192
192
|
return (180 / math.PI) * rads;
|
|
193
193
|
},
|
|
194
194
|
mod(a, b) {
|
|
195
|
-
DEV: assert(isNumber(a), "mod() 1st
|
|
195
|
+
DEV: assert(isNumber(a), "mod() 1st argument must be a number");
|
|
196
196
|
DEV: assert(
|
|
197
197
|
isNumber(b) && b >= 0,
|
|
198
|
-
"mod() 2nd
|
|
198
|
+
"mod() 2nd argument must be a non-negative number",
|
|
199
199
|
);
|
|
200
200
|
return ((a % b) + b) % b || 0;
|
|
201
201
|
},
|
|
202
202
|
round: (n, precision = 0) => {
|
|
203
|
-
DEV: assert(isNumber(n), "round() 1st
|
|
203
|
+
DEV: assert(isNumber(n), "round() 1st argument must be a number");
|
|
204
204
|
DEV: assert(
|
|
205
205
|
isNumber(precision) && precision >= 0,
|
|
206
|
-
"round() 2nd
|
|
206
|
+
"round() 2nd argument must be a non-negative number",
|
|
207
207
|
);
|
|
208
208
|
if (!precision) {
|
|
209
209
|
return math.round(n);
|
|
@@ -212,64 +212,64 @@
|
|
|
212
212
|
return math.round(n * multiplier) / multiplier;
|
|
213
213
|
},
|
|
214
214
|
clamp: (value, min, max) => {
|
|
215
|
-
DEV: assert(isNumber(value), "clamp() 1st
|
|
216
|
-
DEV: assert(isNumber(min), "clamp() 2nd
|
|
217
|
-
DEV: assert(isNumber(max), "clamp() 3rd
|
|
215
|
+
DEV: assert(isNumber(value), "clamp() 1st argument must be a number");
|
|
216
|
+
DEV: assert(isNumber(min), "clamp() 2nd argument must be a number");
|
|
217
|
+
DEV: assert(isNumber(max), "clamp() 3rd argument must be a number");
|
|
218
218
|
DEV: assert(
|
|
219
219
|
max >= min,
|
|
220
|
-
"clamp() the 2nd
|
|
220
|
+
"clamp() the 2nd argument must be less than the 3rd argument",
|
|
221
221
|
);
|
|
222
222
|
if (value < min) return min;
|
|
223
223
|
if (value > max) return max;
|
|
224
224
|
return value;
|
|
225
225
|
},
|
|
226
226
|
dist: (x1, y1, x2, y2) => {
|
|
227
|
-
DEV: assert(isNumber(x1), "dist() 1st
|
|
228
|
-
DEV: assert(isNumber(y1), "dist() 2nd
|
|
229
|
-
DEV: assert(isNumber(x2), "dist() 3rd
|
|
230
|
-
DEV: assert(isNumber(y2), "dist() 4th
|
|
227
|
+
DEV: assert(isNumber(x1), "dist() 1st argument must be a number");
|
|
228
|
+
DEV: assert(isNumber(y1), "dist() 2nd argument must be a number");
|
|
229
|
+
DEV: assert(isNumber(x2), "dist() 3rd argument must be a number");
|
|
230
|
+
DEV: assert(isNumber(y2), "dist() 4th argument must be a number");
|
|
231
231
|
return math.hypot(x2 - x1, y2 - y1);
|
|
232
232
|
},
|
|
233
233
|
wrap: (value, min, max) => {
|
|
234
|
-
DEV: assert(isNumber(value), "wrap() 1st
|
|
235
|
-
DEV: assert(isNumber(min), "wrap() 2nd
|
|
236
|
-
DEV: assert(isNumber(max), "wrap() 3rd
|
|
234
|
+
DEV: assert(isNumber(value), "wrap() 1st argument must be a number");
|
|
235
|
+
DEV: assert(isNumber(min), "wrap() 2nd argument must be a number");
|
|
236
|
+
DEV: assert(isNumber(max), "wrap() 3rd argument must be a number");
|
|
237
237
|
DEV: assert(
|
|
238
238
|
max > min,
|
|
239
|
-
"wrap() the 2nd
|
|
239
|
+
"wrap() the 2nd argument must be less than the 3rd argument",
|
|
240
240
|
);
|
|
241
241
|
return value - (max - min) * math.floor((value - min) / (max - min));
|
|
242
242
|
},
|
|
243
243
|
map(value, start1, stop1, start2, stop2, withinBounds) {
|
|
244
|
-
DEV: assert(isNumber(value), "map() 1st
|
|
245
|
-
DEV: assert(isNumber(start1), "map() 2nd
|
|
246
|
-
DEV: assert(isNumber(stop1), "map() 3rd
|
|
247
|
-
DEV: assert(isNumber(start2), "map() 4th
|
|
248
|
-
DEV: assert(isNumber(stop2), "map() 5th
|
|
244
|
+
DEV: assert(isNumber(value), "map() 1st argument must be a number");
|
|
245
|
+
DEV: assert(isNumber(start1), "map() 2nd argument must be a number");
|
|
246
|
+
DEV: assert(isNumber(stop1), "map() 3rd argument must be a number");
|
|
247
|
+
DEV: assert(isNumber(start2), "map() 4th argument must be a number");
|
|
248
|
+
DEV: assert(isNumber(stop2), "map() 5th argument must be a number");
|
|
249
249
|
DEV: assert(
|
|
250
250
|
stop1 !== start1,
|
|
251
|
-
"map() the 2nd
|
|
251
|
+
"map() the 2nd argument must be different than the 3rd argument",
|
|
252
252
|
);
|
|
253
253
|
const result =
|
|
254
254
|
((value - start1) / (stop1 - start1)) * (stop2 - start2) + start2;
|
|
255
255
|
return withinBounds ? instance.clamp(result, start2, stop2) : result;
|
|
256
256
|
},
|
|
257
257
|
norm: (value, start, stop) => {
|
|
258
|
-
DEV: assert(isNumber(value), "norm() 1st
|
|
259
|
-
DEV: assert(isNumber(start), "norm() 2nd
|
|
260
|
-
DEV: assert(isNumber(stop), "norm() 3rd
|
|
258
|
+
DEV: assert(isNumber(value), "norm() 1st argument must be a number");
|
|
259
|
+
DEV: assert(isNumber(start), "norm() 2nd argument must be a number");
|
|
260
|
+
DEV: assert(isNumber(stop), "norm() 3rd argument must be a number");
|
|
261
261
|
DEV: assert(
|
|
262
262
|
start !== stop,
|
|
263
|
-
"norm() the 2nd
|
|
263
|
+
"norm() the 2nd argument must be different than the 3rd argument",
|
|
264
264
|
);
|
|
265
265
|
return instance.map(value, start, stop, 0, 1);
|
|
266
266
|
},
|
|
267
267
|
rand: (min = 0, max = 1) => {
|
|
268
|
-
DEV: assert(isNumber(min), "rand() 1st
|
|
269
|
-
DEV: assert(isNumber(max), "rand() 2nd
|
|
268
|
+
DEV: assert(isNumber(min), "rand() 1st argument must be a number");
|
|
269
|
+
DEV: assert(isNumber(max), "rand() 2nd argument must be a number");
|
|
270
270
|
DEV: assert(
|
|
271
271
|
max >= min,
|
|
272
|
-
"rand() the 1st
|
|
272
|
+
"rand() the 1st argument must be less than the 2nd argument",
|
|
273
273
|
);
|
|
274
274
|
const a = 1664525;
|
|
275
275
|
const c = 1013904223;
|
|
@@ -278,25 +278,25 @@
|
|
|
278
278
|
return (_rngSeed / m) * (max - min) + min;
|
|
279
279
|
},
|
|
280
280
|
randi: (min = 0, max = 1) => {
|
|
281
|
-
DEV: assert(isNumber(min), "randi() 1st
|
|
282
|
-
DEV: assert(isNumber(max), "randi() 2nd
|
|
281
|
+
DEV: assert(isNumber(min), "randi() 1st argument must be a number");
|
|
282
|
+
DEV: assert(isNumber(max), "randi() 2nd argument must be a number");
|
|
283
283
|
DEV: assert(
|
|
284
284
|
max >= min,
|
|
285
|
-
"randi() the 1st
|
|
285
|
+
"randi() the 1st argument must be less than the 2nd argument",
|
|
286
286
|
);
|
|
287
287
|
return ~~instance.rand(min, max + 1);
|
|
288
288
|
},
|
|
289
289
|
rseed(value) {
|
|
290
290
|
DEV: assert(
|
|
291
291
|
isNumber(value) && value >= 0,
|
|
292
|
-
"rseed() 1st
|
|
292
|
+
"rseed() 1st argument must be a non-negative integer",
|
|
293
293
|
);
|
|
294
294
|
_rngSeed = ~~value;
|
|
295
295
|
},
|
|
296
296
|
cls(color) {
|
|
297
297
|
DEV: assert(
|
|
298
298
|
null == color || (isNumber(color) && color >= 0),
|
|
299
|
-
"cls() 1st
|
|
299
|
+
"cls() 1st argument must be a non-negative number",
|
|
300
300
|
);
|
|
301
301
|
if (null == color) {
|
|
302
302
|
_ctx.clearRect(0, 0, instance.W, instance.H);
|
|
@@ -305,25 +305,25 @@
|
|
|
305
305
|
}
|
|
306
306
|
},
|
|
307
307
|
rect(x, y, width, height, color, radii) {
|
|
308
|
-
DEV: assert(isNumber(x), "rect() 1st
|
|
309
|
-
DEV: assert(isNumber(y), "rect() 2nd
|
|
308
|
+
DEV: assert(isNumber(x), "rect() 1st argument must be a number");
|
|
309
|
+
DEV: assert(isNumber(y), "rect() 2nd argument must be a number");
|
|
310
310
|
DEV: assert(
|
|
311
311
|
isNumber(width) && width > 0,
|
|
312
|
-
"rect() 3rd
|
|
312
|
+
"rect() 3rd argument must be a positive number",
|
|
313
313
|
);
|
|
314
314
|
DEV: assert(
|
|
315
315
|
isNumber(height) && height >= 0,
|
|
316
|
-
"rect() 4th
|
|
316
|
+
"rect() 4th argument must be a non-negative number",
|
|
317
317
|
);
|
|
318
318
|
DEV: assert(
|
|
319
319
|
null == color || (isNumber(color) && color >= 0),
|
|
320
|
-
"rect() 5th
|
|
320
|
+
"rect() 5th argument must be a non-negative number",
|
|
321
321
|
);
|
|
322
322
|
DEV: assert(
|
|
323
323
|
null == radii ||
|
|
324
324
|
isNumber(radii) ||
|
|
325
325
|
(Array.isArray(radii) && radii.length >= 1),
|
|
326
|
-
"rect() 6th
|
|
326
|
+
"rect() 6th argument must be a number or array of numbers",
|
|
327
327
|
);
|
|
328
328
|
beginPath(_ctx);
|
|
329
329
|
_ctx[radii ? "roundRect" : "rect"](
|
|
@@ -336,102 +336,102 @@
|
|
|
336
336
|
instance.stroke(color);
|
|
337
337
|
},
|
|
338
338
|
rectfill(x, y, width, height, color, radii) {
|
|
339
|
-
DEV: assert(isNumber(x), "rectfill() 1st
|
|
340
|
-
DEV: assert(isNumber(y), "rectfill() 2nd
|
|
339
|
+
DEV: assert(isNumber(x), "rectfill() 1st argument must be a number");
|
|
340
|
+
DEV: assert(isNumber(y), "rectfill() 2nd argument must be a number");
|
|
341
341
|
DEV: assert(
|
|
342
342
|
isNumber(width) && width >= 0,
|
|
343
|
-
"rectfill() 3rd
|
|
343
|
+
"rectfill() 3rd argument must be a non-negative number",
|
|
344
344
|
);
|
|
345
345
|
DEV: assert(
|
|
346
346
|
isNumber(height) && height >= 0,
|
|
347
|
-
"rectfill() 4th
|
|
347
|
+
"rectfill() 4th argument must be a non-negative number",
|
|
348
348
|
);
|
|
349
349
|
DEV: assert(
|
|
350
350
|
null == color || (isNumber(color) && color >= 0),
|
|
351
|
-
"rectfill() 5th
|
|
351
|
+
"rectfill() 5th argument must be a non-negative number",
|
|
352
352
|
);
|
|
353
353
|
DEV: assert(
|
|
354
354
|
null == radii ||
|
|
355
355
|
isNumber(radii) ||
|
|
356
356
|
(Array.isArray(radii) && radii.length >= 1),
|
|
357
|
-
"rectfill() 6th
|
|
357
|
+
"rectfill() 6th argument must be a number or array of at least 2 numbers",
|
|
358
358
|
);
|
|
359
359
|
beginPath(_ctx);
|
|
360
360
|
_ctx[radii ? "roundRect" : "rect"](~~x, ~~y, ~~width, ~~height, radii);
|
|
361
361
|
instance.fill(color);
|
|
362
362
|
},
|
|
363
363
|
oval(x, y, radiusX, radiusY, color) {
|
|
364
|
-
DEV: assert(isNumber(x), "oval() 1st
|
|
365
|
-
DEV: assert(isNumber(y), "oval() 2nd
|
|
364
|
+
DEV: assert(isNumber(x), "oval() 1st argument must be a number");
|
|
365
|
+
DEV: assert(isNumber(y), "oval() 2nd argument must be a number");
|
|
366
366
|
DEV: assert(
|
|
367
367
|
isNumber(radiusX) && radiusX >= 0,
|
|
368
|
-
"oval() 3rd
|
|
368
|
+
"oval() 3rd argument must be a non-negative number",
|
|
369
369
|
);
|
|
370
370
|
DEV: assert(
|
|
371
371
|
isNumber(radiusY) && radiusY >= 0,
|
|
372
|
-
"oval() 4th
|
|
372
|
+
"oval() 4th argument must be a non-negative number",
|
|
373
373
|
);
|
|
374
374
|
DEV: assert(
|
|
375
375
|
null == color || (isNumber(color) && color >= 0),
|
|
376
|
-
"oval() 5th
|
|
376
|
+
"oval() 5th argument must be a non-negative number",
|
|
377
377
|
);
|
|
378
378
|
beginPath(_ctx);
|
|
379
379
|
_ctx.ellipse(~~x, ~~y, ~~radiusX, ~~radiusY, 0, 0, TAU);
|
|
380
380
|
instance.stroke(color);
|
|
381
381
|
},
|
|
382
382
|
ovalfill(x, y, radiusX, radiusY, color) {
|
|
383
|
-
DEV: assert(isNumber(x), "ovalfill() 1st
|
|
384
|
-
DEV: assert(isNumber(y), "ovalfill() 2nd
|
|
383
|
+
DEV: assert(isNumber(x), "ovalfill() 1st argument must be a number");
|
|
384
|
+
DEV: assert(isNumber(y), "ovalfill() 2nd argument must be a number");
|
|
385
385
|
DEV: assert(
|
|
386
386
|
isNumber(radiusX) && radiusX >= 0,
|
|
387
|
-
"ovalfill() 3rd
|
|
387
|
+
"ovalfill() 3rd argument must be a non-negative number",
|
|
388
388
|
);
|
|
389
389
|
DEV: assert(
|
|
390
390
|
isNumber(radiusY) && radiusY >= 0,
|
|
391
|
-
"ovalfill() 4th
|
|
391
|
+
"ovalfill() 4th argument must be a non-negative number",
|
|
392
392
|
);
|
|
393
393
|
DEV: assert(
|
|
394
394
|
null == color || (isNumber(color) && color >= 0),
|
|
395
|
-
"ovalfill() 5th
|
|
395
|
+
"ovalfill() 5th argument must be a non-negative number",
|
|
396
396
|
);
|
|
397
397
|
beginPath(_ctx);
|
|
398
398
|
_ctx.ellipse(~~x, ~~y, ~~radiusX, ~~radiusY, 0, 0, TAU);
|
|
399
399
|
instance.fill(color);
|
|
400
400
|
},
|
|
401
401
|
circ(x, y, radius, color) {
|
|
402
|
-
DEV: assert(isNumber(x), "circ() 1st
|
|
403
|
-
DEV: assert(isNumber(y), "circ() 2nd
|
|
402
|
+
DEV: assert(isNumber(x), "circ() 1st argument must be a number");
|
|
403
|
+
DEV: assert(isNumber(y), "circ() 2nd argument must be a number");
|
|
404
404
|
DEV: assert(
|
|
405
405
|
isNumber(radius) && radius >= 0,
|
|
406
|
-
"circ() 3rd
|
|
406
|
+
"circ() 3rd argument must be a non-negative number",
|
|
407
407
|
);
|
|
408
408
|
DEV: assert(
|
|
409
409
|
null == color || (isNumber(color) && color >= 0),
|
|
410
|
-
"circ() 4th
|
|
410
|
+
"circ() 4th argument must be a non-negative number",
|
|
411
411
|
);
|
|
412
412
|
instance.oval(x, y, radius, radius, color);
|
|
413
413
|
},
|
|
414
414
|
circfill(x, y, radius, color) {
|
|
415
|
-
DEV: assert(isNumber(x), "circfill() 1st
|
|
416
|
-
DEV: assert(isNumber(y), "circfill() 2nd
|
|
415
|
+
DEV: assert(isNumber(x), "circfill() 1st argument must be a number");
|
|
416
|
+
DEV: assert(isNumber(y), "circfill() 2nd argument must be a number");
|
|
417
417
|
DEV: assert(
|
|
418
418
|
isNumber(radius) && radius >= 0,
|
|
419
|
-
"circfill() 3rd
|
|
419
|
+
"circfill() 3rd argument must be a non-negative number",
|
|
420
420
|
);
|
|
421
421
|
DEV: assert(
|
|
422
422
|
null == color || (isNumber(color) && color >= 0),
|
|
423
|
-
"circfill() 4th
|
|
423
|
+
"circfill() 4th argument must be a non-negative number",
|
|
424
424
|
);
|
|
425
425
|
instance.ovalfill(x, y, radius, radius, color);
|
|
426
426
|
},
|
|
427
427
|
shape(points) {
|
|
428
428
|
DEV: assert(
|
|
429
429
|
Array.isArray(points),
|
|
430
|
-
"shape() 1st
|
|
430
|
+
"shape() 1st argument must be an array of numbers",
|
|
431
431
|
);
|
|
432
432
|
DEV: assert(
|
|
433
433
|
points.length >= 6,
|
|
434
|
-
"shape() 1st
|
|
434
|
+
"shape() 1st argument must be an array with at least 6 numbers (3 points)",
|
|
435
435
|
);
|
|
436
436
|
beginPath(_ctx);
|
|
437
437
|
for (let i = 0; i < points.length; i += 2) {
|
|
@@ -444,19 +444,19 @@
|
|
|
444
444
|
_ctx.lineTo(~~points[0], ~~points[1]);
|
|
445
445
|
},
|
|
446
446
|
line(x1, y1, x2, y2, color) {
|
|
447
|
-
DEV: assert(isNumber(x1), "line() 1st
|
|
448
|
-
DEV: assert(isNumber(y1), "line() 2nd
|
|
447
|
+
DEV: assert(isNumber(x1), "line() 1st argument must be a number");
|
|
448
|
+
DEV: assert(isNumber(y1), "line() 2nd argument must be a number");
|
|
449
449
|
DEV: assert(
|
|
450
450
|
isNumber(x2),
|
|
451
|
-
"line() 3rd
|
|
451
|
+
"line() 3rd argument must be a non-negative number",
|
|
452
452
|
);
|
|
453
453
|
DEV: assert(
|
|
454
454
|
isNumber(y2),
|
|
455
|
-
"line() 4th
|
|
455
|
+
"line() 4th argument must be a non-negative number",
|
|
456
456
|
);
|
|
457
457
|
DEV: assert(
|
|
458
458
|
null == color || (isNumber(color) && color >= 0),
|
|
459
|
-
"line() 5th
|
|
459
|
+
"line() 5th argument must be a non-negative number",
|
|
460
460
|
);
|
|
461
461
|
beginPath(_ctx);
|
|
462
462
|
let xfix = _outline_fix && ~~x1 === ~~x2 ? 0.5 : 0;
|
|
@@ -468,7 +468,7 @@
|
|
|
468
468
|
linewidth(value) {
|
|
469
469
|
DEV: assert(
|
|
470
470
|
isNumber(value) && value >= 0,
|
|
471
|
-
"linewidth() 1st
|
|
471
|
+
"linewidth() 1st argument must be a non-negative integer",
|
|
472
472
|
);
|
|
473
473
|
_ctx.lineWidth = ~~value;
|
|
474
474
|
_outline_fix = ~~value % 2 ? 0.5 : 0;
|
|
@@ -476,25 +476,25 @@
|
|
|
476
476
|
linedash(segments, offset = 0) {
|
|
477
477
|
DEV: assert(
|
|
478
478
|
Array.isArray(segments) && segments.length > 0,
|
|
479
|
-
"linedash() 1st
|
|
479
|
+
"linedash() 1st argument must be an array of numbers",
|
|
480
480
|
);
|
|
481
481
|
DEV: assert(
|
|
482
482
|
isNumber(offset),
|
|
483
|
-
"linedash() 2nd
|
|
483
|
+
"linedash() 2nd argument must be a number",
|
|
484
484
|
);
|
|
485
485
|
_ctx.setLineDash(segments);
|
|
486
486
|
_ctx.lineDashOffset = offset;
|
|
487
487
|
},
|
|
488
488
|
text(x, y, message, color = _defaultTextColor, fontStyle = "normal") {
|
|
489
|
-
DEV: assert(isNumber(x), "text() 1st
|
|
490
|
-
DEV: assert(isNumber(y), "text() 2nd
|
|
489
|
+
DEV: assert(isNumber(x), "text() 1st argument must be a number");
|
|
490
|
+
DEV: assert(isNumber(y), "text() 2nd argument must be a number");
|
|
491
491
|
DEV: assert(
|
|
492
492
|
null == color || (isNumber(color) && color >= 0),
|
|
493
|
-
"text() 4th
|
|
493
|
+
"text() 4th argument must be a non-negative number",
|
|
494
494
|
);
|
|
495
495
|
DEV: assert(
|
|
496
496
|
"string" === typeof fontStyle,
|
|
497
|
-
"text() 5th
|
|
497
|
+
"text() 5th argument must be a string",
|
|
498
498
|
);
|
|
499
499
|
_ctx.font = `${fontStyle} ${_fontSize}px ${_fontFamily}`;
|
|
500
500
|
_ctx.fillStyle = getColor(color);
|
|
@@ -508,31 +508,25 @@
|
|
|
508
508
|
}
|
|
509
509
|
},
|
|
510
510
|
textgap(value) {
|
|
511
|
-
DEV: assert(
|
|
512
|
-
isNumber(value),
|
|
513
|
-
"textgap() 1st parameter must be a number",
|
|
514
|
-
);
|
|
511
|
+
DEV: assert(isNumber(value), "textgap() 1st argument must be a number");
|
|
515
512
|
_fontLineHeight = value;
|
|
516
513
|
},
|
|
517
514
|
textfont(family) {
|
|
518
515
|
DEV: assert(
|
|
519
516
|
"string" === typeof family,
|
|
520
|
-
"textfont() 1st
|
|
517
|
+
"textfont() 1st argument must be a string",
|
|
521
518
|
);
|
|
522
519
|
_fontFamily = family;
|
|
523
520
|
},
|
|
524
521
|
textsize(size) {
|
|
525
|
-
DEV: assert(
|
|
526
|
-
isNumber(size),
|
|
527
|
-
"textsize() 1st parameter must be a number",
|
|
528
|
-
);
|
|
522
|
+
DEV: assert(isNumber(size), "textsize() 1st argument must be a number");
|
|
529
523
|
_fontSize = size;
|
|
530
524
|
},
|
|
531
525
|
textalign(align, baseline) {
|
|
532
526
|
DEV: assert(
|
|
533
527
|
null == align ||
|
|
534
528
|
["left", "right", "center", "start", "end"].includes(align),
|
|
535
|
-
"textalign() 1st
|
|
529
|
+
"textalign() 1st argument must be null or one of the following strings: center, left, right, start or end.",
|
|
536
530
|
);
|
|
537
531
|
DEV: assert(
|
|
538
532
|
null == baseline ||
|
|
@@ -544,22 +538,22 @@
|
|
|
544
538
|
"alphabetic",
|
|
545
539
|
"ideographic",
|
|
546
540
|
].includes(baseline),
|
|
547
|
-
"textalign() 2nd
|
|
541
|
+
"textalign() 2nd argument must be null or one of the following strings: middle, top, bottom, hanging, alphabetic or ideographic.",
|
|
548
542
|
);
|
|
549
543
|
if (align) _ctx.textAlign = align;
|
|
550
544
|
if (baseline) _ctx.textBaseline = baseline;
|
|
551
545
|
},
|
|
552
546
|
image(x, y, source) {
|
|
553
|
-
DEV: assert(isNumber(x), "image() 1st
|
|
554
|
-
DEV: assert(isNumber(y), "image() 2nd
|
|
547
|
+
DEV: assert(isNumber(x), "image() 1st argument must be a number");
|
|
548
|
+
DEV: assert(isNumber(y), "image() 2nd argument must be a number");
|
|
555
549
|
_ctx.drawImage(source, ~~x, ~~y);
|
|
556
550
|
},
|
|
557
551
|
spr(x, y, pixels) {
|
|
558
|
-
DEV: assert(isNumber(x), "spr() 1st
|
|
559
|
-
DEV: assert(isNumber(y), "spr() 2nd
|
|
552
|
+
DEV: assert(isNumber(x), "spr() 1st argument must be a number");
|
|
553
|
+
DEV: assert(isNumber(y), "spr() 2nd argument must be a number");
|
|
560
554
|
DEV: assert(
|
|
561
555
|
"string" === typeof pixels,
|
|
562
|
-
"spr() 3rd
|
|
556
|
+
"spr() 3rd argument must be a string",
|
|
563
557
|
);
|
|
564
558
|
const rows = pixels
|
|
565
559
|
.replace(/[^\w.\n]/g, "")
|
|
@@ -582,25 +576,25 @@
|
|
|
582
576
|
paint(width, height, callback, options = {}) {
|
|
583
577
|
DEV: assert(
|
|
584
578
|
isNumber(width) && width >= 1,
|
|
585
|
-
"paint() 1st
|
|
579
|
+
"paint() 1st argument must be a number >= 1",
|
|
586
580
|
);
|
|
587
581
|
DEV: assert(
|
|
588
582
|
isNumber(height) && height >= 1,
|
|
589
|
-
"paint() 2nd
|
|
583
|
+
"paint() 2nd argument must be a number >= 1",
|
|
590
584
|
);
|
|
591
585
|
DEV: assert(
|
|
592
586
|
"function" === typeof callback,
|
|
593
|
-
"paint() 3rd
|
|
587
|
+
"paint() 3rd argument must be a function",
|
|
594
588
|
);
|
|
595
589
|
DEV: assert(
|
|
596
590
|
(options && null == options.scale) ||
|
|
597
591
|
(isNumber(options.scale) && options.scale > 0),
|
|
598
|
-
"paint() 4th
|
|
592
|
+
"paint() 4th argument (options.scale) must be a positive number",
|
|
599
593
|
);
|
|
600
594
|
DEV: assert(
|
|
601
595
|
(options && null == options.canvas) ||
|
|
602
596
|
options.canvas instanceof OffscreenCanvas,
|
|
603
|
-
"paint() 4th
|
|
597
|
+
"paint() 4th argument (options.canvas) must be an OffscreenCanvas",
|
|
604
598
|
);
|
|
605
599
|
const canvas = options.canvas || new OffscreenCanvas(1, 1),
|
|
606
600
|
scale = options.scale || 1,
|
|
@@ -618,7 +612,7 @@
|
|
|
618
612
|
null == context ||
|
|
619
613
|
context instanceof CanvasRenderingContext2D ||
|
|
620
614
|
context instanceof OffscreenCanvasRenderingContext2D,
|
|
621
|
-
"ctx() 1st
|
|
615
|
+
"ctx() 1st argument must be an [Offscreen]CanvasRenderingContext2D",
|
|
622
616
|
);
|
|
623
617
|
if (context) {
|
|
624
618
|
_ctx = context;
|
|
@@ -634,18 +628,15 @@
|
|
|
634
628
|
) {
|
|
635
629
|
DEV: assert(
|
|
636
630
|
isNumber(translateX),
|
|
637
|
-
"push() 1st
|
|
631
|
+
"push() 1st argument must be a number",
|
|
638
632
|
);
|
|
639
633
|
DEV: assert(
|
|
640
634
|
isNumber(translateY),
|
|
641
|
-
"push() 2nd
|
|
635
|
+
"push() 2nd argument must be a number",
|
|
642
636
|
);
|
|
643
|
-
DEV: assert(
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
);
|
|
647
|
-
DEV: assert(isNumber(scaleX), "push() 4th parameter must be a number");
|
|
648
|
-
DEV: assert(isNumber(scaleY), "push() 5th parameter must be a number");
|
|
637
|
+
DEV: assert(isNumber(rotation), "push() 3rd argument must be a number");
|
|
638
|
+
DEV: assert(isNumber(scaleX), "push() 4th argument must be a number");
|
|
639
|
+
DEV: assert(isNumber(scaleY), "push() 5th argument must be a number");
|
|
649
640
|
_ctx.save();
|
|
650
641
|
instance.translate(translateX, translateY);
|
|
651
642
|
instance.rotate(rotation);
|
|
@@ -655,30 +646,30 @@
|
|
|
655
646
|
_ctx.restore();
|
|
656
647
|
},
|
|
657
648
|
translate(x, y) {
|
|
658
|
-
DEV: assert(isNumber(x), "translate() 1st
|
|
659
|
-
DEV: assert(isNumber(y), "translate() 2nd
|
|
649
|
+
DEV: assert(isNumber(x), "translate() 1st argument must be a number");
|
|
650
|
+
DEV: assert(isNumber(y), "translate() 2nd argument must be a number");
|
|
660
651
|
_ctx.translate(~~x, ~~y);
|
|
661
652
|
},
|
|
662
653
|
scale(x, y = x) {
|
|
663
|
-
DEV: assert(isNumber(x), "scale() 1st
|
|
664
|
-
DEV: assert(isNumber(y), "scale() 2nd
|
|
654
|
+
DEV: assert(isNumber(x), "scale() 1st argument must be a number");
|
|
655
|
+
DEV: assert(isNumber(y), "scale() 2nd argument must be a number");
|
|
665
656
|
_ctx.scale(x, y);
|
|
666
657
|
},
|
|
667
658
|
rotate(radians) {
|
|
668
659
|
DEV: assert(
|
|
669
660
|
isNumber(radians),
|
|
670
|
-
"rotate() 1st
|
|
661
|
+
"rotate() 1st argument must be a number",
|
|
671
662
|
);
|
|
672
663
|
_ctx.rotate(radians);
|
|
673
664
|
},
|
|
674
665
|
alpha(value) {
|
|
675
|
-
DEV: assert(isNumber(value), "alpha() 1st
|
|
666
|
+
DEV: assert(isNumber(value), "alpha() 1st argument must be a number");
|
|
676
667
|
_ctx.globalAlpha = instance.clamp(value, 0, 1);
|
|
677
668
|
},
|
|
678
669
|
fill(color) {
|
|
679
670
|
DEV: assert(
|
|
680
671
|
null == color || (isNumber(color) && color >= 0),
|
|
681
|
-
"fill() 1st
|
|
672
|
+
"fill() 1st argument must be a non-negative number",
|
|
682
673
|
);
|
|
683
674
|
_ctx.fillStyle = getColor(color);
|
|
684
675
|
_ctx.fill();
|
|
@@ -686,7 +677,7 @@
|
|
|
686
677
|
stroke(color) {
|
|
687
678
|
DEV: assert(
|
|
688
679
|
null == color || (isNumber(color) && color >= 0),
|
|
689
|
-
"stroke() 1st
|
|
680
|
+
"stroke() 1st argument must be a non-negative number",
|
|
690
681
|
);
|
|
691
682
|
_ctx.strokeStyle = getColor(color);
|
|
692
683
|
_ctx.stroke();
|
|
@@ -694,7 +685,7 @@
|
|
|
694
685
|
clip(callback) {
|
|
695
686
|
DEV: assert(
|
|
696
687
|
"function" === typeof callback,
|
|
697
|
-
"clip() 1st
|
|
688
|
+
"clip() 1st argument must be a function (ctx) => void",
|
|
698
689
|
);
|
|
699
690
|
beginPath(_ctx);
|
|
700
691
|
callback(_ctx);
|
|
@@ -703,15 +694,15 @@
|
|
|
703
694
|
sfx(zzfxParams, pitchSlide, volumeFactor) {
|
|
704
695
|
DEV: assert(
|
|
705
696
|
null == zzfxParams || Array.isArray(zzfxParams),
|
|
706
|
-
"sfx() 1st
|
|
697
|
+
"sfx() 1st argument must be an array",
|
|
707
698
|
);
|
|
708
699
|
DEV: assert(
|
|
709
700
|
null == pitchSlide || isNumber(pitchSlide),
|
|
710
|
-
"sfx() 2nd
|
|
701
|
+
"sfx() 2nd argument must be a number",
|
|
711
702
|
);
|
|
712
703
|
DEV: assert(
|
|
713
704
|
null == volumeFactor || isNumber(volumeFactor),
|
|
714
|
-
"sfx() 3rd
|
|
705
|
+
"sfx() 3rd argument must be a number",
|
|
715
706
|
);
|
|
716
707
|
if (
|
|
717
708
|
!root.zzfxV ||
|
|
@@ -731,7 +722,7 @@
|
|
|
731
722
|
volume(value) {
|
|
732
723
|
DEV: assert(
|
|
733
724
|
isNumber(value) && value >= 0,
|
|
734
|
-
"volume() 1st
|
|
725
|
+
"volume() 1st argument must be a non-negative number",
|
|
735
726
|
);
|
|
736
727
|
root.zzfxV = value;
|
|
737
728
|
},
|
|
@@ -739,22 +730,42 @@
|
|
|
739
730
|
use(callback, config = {}) {
|
|
740
731
|
DEV: assert(
|
|
741
732
|
"function" === typeof callback,
|
|
742
|
-
"use() 1st
|
|
733
|
+
"use() 1st argument must be a function (instance, config) => any",
|
|
743
734
|
);
|
|
744
735
|
DEV: assert(
|
|
745
736
|
"object" === typeof config,
|
|
746
|
-
"use() 2nd
|
|
737
|
+
"use() 2nd argument must be an object",
|
|
747
738
|
);
|
|
748
739
|
loadPlugin(callback, config);
|
|
749
740
|
},
|
|
741
|
+
resize(width, height = width, autoscale) {
|
|
742
|
+
DEV: assert(
|
|
743
|
+
isNumber(width) && width >= 1,
|
|
744
|
+
"resize() 1st argument must be a number >= 1",
|
|
745
|
+
);
|
|
746
|
+
DEV: assert(
|
|
747
|
+
isNumber(height) && height >= 1,
|
|
748
|
+
"resize() 2nd argument must be a number >= 1",
|
|
749
|
+
);
|
|
750
|
+
DEV: assert(
|
|
751
|
+
null == autoscale ||
|
|
752
|
+
"boolean" === typeof autoscale ||
|
|
753
|
+
(isNumber(autoscale) && autoscale > 1),
|
|
754
|
+
"resize() 3rd argument must be a boolean or a number > 1",
|
|
755
|
+
);
|
|
756
|
+
settings.width = width;
|
|
757
|
+
settings.height = height;
|
|
758
|
+
settings.autoscale = null == autoscale ? settings.autoscale : autoscale;
|
|
759
|
+
resizeCanvas();
|
|
760
|
+
},
|
|
750
761
|
listen: (eventName, callback) => {
|
|
751
762
|
DEV: assert(
|
|
752
763
|
"string" === typeof eventName,
|
|
753
|
-
"listen() 1st
|
|
764
|
+
"listen() 1st argument must be a string",
|
|
754
765
|
);
|
|
755
766
|
DEV: assert(
|
|
756
767
|
"function" === typeof callback,
|
|
757
|
-
"listen() 2nd
|
|
768
|
+
"listen() 2nd argument must be a function",
|
|
758
769
|
);
|
|
759
770
|
eventName = lowerCase(eventName);
|
|
760
771
|
_eventListeners[eventName] = _eventListeners[eventName] || new Set();
|
|
@@ -763,11 +774,11 @@
|
|
|
763
774
|
unlisten: (eventName, callback) => {
|
|
764
775
|
DEV: assert(
|
|
765
776
|
"string" === typeof eventName,
|
|
766
|
-
"unlisten() 1st
|
|
777
|
+
"unlisten() 1st argument must be a string",
|
|
767
778
|
);
|
|
768
779
|
DEV: assert(
|
|
769
780
|
"function" === typeof callback,
|
|
770
|
-
"unlisten() 2nd
|
|
781
|
+
"unlisten() 2nd argument must be a function",
|
|
771
782
|
);
|
|
772
783
|
eventName = lowerCase(eventName);
|
|
773
784
|
if (_eventListeners[eventName]) {
|
|
@@ -777,7 +788,7 @@
|
|
|
777
788
|
emit(eventName, arg1, arg2, arg3, arg4) {
|
|
778
789
|
DEV: assert(
|
|
779
790
|
"string" === typeof eventName,
|
|
780
|
-
"emit() 1st
|
|
791
|
+
"emit() 1st argument must be a string",
|
|
781
792
|
);
|
|
782
793
|
if (_initialized) {
|
|
783
794
|
eventName = lowerCase(eventName);
|
|
@@ -797,11 +808,11 @@
|
|
|
797
808
|
pal(colors, textColor = 3) {
|
|
798
809
|
DEV: assert(
|
|
799
810
|
null == colors || (Array.isArray(colors) && colors.length > 0),
|
|
800
|
-
"pal() 1st
|
|
811
|
+
"pal() 1st argument must be null or an array of colors",
|
|
801
812
|
);
|
|
802
813
|
DEV: assert(
|
|
803
814
|
isNumber(textColor) && textColor >= 0,
|
|
804
|
-
"pal() 2nd
|
|
815
|
+
"pal() 2nd argument must be a non-negative number",
|
|
805
816
|
);
|
|
806
817
|
_colorPalette = colors || defaultPalette;
|
|
807
818
|
_colorPaletteState = [];
|
|
@@ -811,11 +822,11 @@
|
|
|
811
822
|
palc(a, b) {
|
|
812
823
|
DEV: assert(
|
|
813
824
|
null == a || (isNumber(a) && a >= 0),
|
|
814
|
-
"palc() 1st
|
|
825
|
+
"palc() 1st argument must be a positive number",
|
|
815
826
|
);
|
|
816
827
|
DEV: assert(
|
|
817
828
|
isNumber(a) ? isNumber(b) && b >= 0 : null == b,
|
|
818
|
-
"palc() 2nd
|
|
829
|
+
"palc() 2nd argument must be a positive number",
|
|
819
830
|
);
|
|
820
831
|
if (null == a) {
|
|
821
832
|
_colorPaletteState = [];
|
|
@@ -826,7 +837,7 @@
|
|
|
826
837
|
def(key, value) {
|
|
827
838
|
DEV: assert(
|
|
828
839
|
"string" === typeof key,
|
|
829
|
-
"def() 1st
|
|
840
|
+
"def() 1st argument must be a string",
|
|
830
841
|
);
|
|
831
842
|
DEV: if (null == value) {
|
|
832
843
|
console.warn(
|
|
@@ -841,19 +852,19 @@
|
|
|
841
852
|
timescale(value) {
|
|
842
853
|
DEV: assert(
|
|
843
854
|
isNumber(value) && value >= 0,
|
|
844
|
-
"timescale() 1st
|
|
855
|
+
"timescale() 1st argument must be a non-negative number",
|
|
845
856
|
);
|
|
846
857
|
_timeScale = value;
|
|
847
858
|
},
|
|
848
859
|
framerate(value) {
|
|
849
860
|
DEV: assert(
|
|
850
861
|
isNumber(value) && value >= 1,
|
|
851
|
-
"framerate() 1st
|
|
862
|
+
"framerate() 1st argument must be a number >= 1",
|
|
852
863
|
);
|
|
853
864
|
_fpsInterval = 1e3 / ~~value;
|
|
854
865
|
},
|
|
855
866
|
stat(index) {
|
|
856
|
-
DEV: assert(isNumber(index), "stat() 1st
|
|
867
|
+
DEV: assert(isNumber(index), "stat() 1st argument must be a number");
|
|
857
868
|
const internals = [
|
|
858
869
|
settings,
|
|
859
870
|
_initialized,
|
|
@@ -872,7 +883,7 @@
|
|
|
872
883
|
];
|
|
873
884
|
DEV: assert(
|
|
874
885
|
index >= 0 && index < internals.length,
|
|
875
|
-
"stat() 1st
|
|
886
|
+
"stat() 1st argument must be a number between 0 and " +
|
|
876
887
|
(internals.length - 1),
|
|
877
888
|
);
|
|
878
889
|
return internals[index];
|
|
@@ -930,7 +941,6 @@
|
|
|
930
941
|
}
|
|
931
942
|
}
|
|
932
943
|
function init() {
|
|
933
|
-
resizeCanvas();
|
|
934
944
|
if (settings.autoscale) {
|
|
935
945
|
on(root, "resize", resizeCanvas);
|
|
936
946
|
}
|
|
@@ -1031,9 +1041,9 @@
|
|
|
1031
1041
|
const _keysPress = new Set();
|
|
1032
1042
|
const keyCheck = (keySet, key = "") => {
|
|
1033
1043
|
key = lowerCase(key);
|
|
1034
|
-
return
|
|
1035
|
-
? keySet.
|
|
1036
|
-
: keySet.
|
|
1044
|
+
return key
|
|
1045
|
+
? keySet.has("space" === key ? " " : key)
|
|
1046
|
+
: keySet.size > 0;
|
|
1037
1047
|
};
|
|
1038
1048
|
let _lastKey = "";
|
|
1039
1049
|
on(root, "keydown", (event) => {
|
|
@@ -1052,14 +1062,14 @@
|
|
|
1052
1062
|
instance.def("iskeydown", (key) => {
|
|
1053
1063
|
DEV: assert(
|
|
1054
1064
|
null == key || "string" === typeof key,
|
|
1055
|
-
"iskeydown() 1st
|
|
1065
|
+
"iskeydown() 1st argument must be a string",
|
|
1056
1066
|
);
|
|
1057
1067
|
return keyCheck(_keysDown, key);
|
|
1058
1068
|
});
|
|
1059
1069
|
instance.def("iskeypressed", (key) => {
|
|
1060
1070
|
DEV: assert(
|
|
1061
1071
|
null == key || "string" === typeof key,
|
|
1062
|
-
"iskeypressed() 1st
|
|
1072
|
+
"iskeypressed() 1st argument must be a string",
|
|
1063
1073
|
);
|
|
1064
1074
|
return keyCheck(_keysPress, key);
|
|
1065
1075
|
});
|
|
@@ -1114,7 +1124,6 @@
|
|
|
1114
1124
|
d.body.appendChild(_canvas);
|
|
1115
1125
|
}
|
|
1116
1126
|
_canvas.oncontextmenu = () => false;
|
|
1117
|
-
resizeCanvas();
|
|
1118
1127
|
}
|
|
1119
1128
|
function resizeCanvas() {
|
|
1120
1129
|
DEV: assert(
|
|
@@ -1191,6 +1200,7 @@
|
|
|
1191
1200
|
DEV: console.info(`[litecanvas] version ${version} started`);
|
|
1192
1201
|
DEV: console.debug(`[litecanvas] litecanvas() options =`, settings);
|
|
1193
1202
|
setupCanvas();
|
|
1203
|
+
resizeCanvas();
|
|
1194
1204
|
if (_loop) {
|
|
1195
1205
|
for (const eventName in _loop) {
|
|
1196
1206
|
if (_loop[eventName]) instance.listen(eventName, _loop[eventName]);
|