litecanvas 0.85.1 → 0.87.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +241 -117
- package/dist/dist.js +36 -6
- package/dist/dist.min.js +1 -1
- package/package.json +8 -5
- package/src/index.js +245 -117
- package/types/index.d.ts +20 -0
- package/types/types.d.ts +20 -0
package/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { setupZzFX } from './zzfx.js'
|
|
3
3
|
import { defaultPalette } from './palette.js'
|
|
4
4
|
import { assert } from './dev.js'
|
|
5
|
+
import { version } from '../version.js'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* The litecanvas constructor
|
|
@@ -131,9 +132,9 @@ export default function litecanvas(settings = {}) {
|
|
|
131
132
|
* @tutorial https://gamedev.net/tutorials/programming/general-and-gameplay-programming/a-brief-introduction-to-lerp-r4954/
|
|
132
133
|
*/
|
|
133
134
|
lerp: (start, end, t) => {
|
|
134
|
-
DEV: assert(isNumber(start), 'lerp
|
|
135
|
-
DEV: assert(isNumber(end), 'lerp
|
|
136
|
-
DEV: assert(isNumber(t), 'lerp
|
|
135
|
+
DEV: assert(isNumber(start), '[litecanvas] lerp() 1st param must be a number')
|
|
136
|
+
DEV: assert(isNumber(end), '[litecanvas] lerp() 2nd param must be a number')
|
|
137
|
+
DEV: assert(isNumber(t), '[litecanvas] lerp() 3rd param must be a number')
|
|
137
138
|
|
|
138
139
|
return t * (end - start) + start
|
|
139
140
|
},
|
|
@@ -172,10 +173,10 @@ export default function litecanvas(settings = {}) {
|
|
|
172
173
|
* @returns {number} rounded number.
|
|
173
174
|
*/
|
|
174
175
|
round: (n, precision = 0) => {
|
|
175
|
-
DEV: assert(isNumber(n), 'round
|
|
176
|
+
DEV: assert(isNumber(n), '[litecanvas] round() 1st param must be a number')
|
|
176
177
|
DEV: assert(
|
|
177
178
|
null == precision || (isNumber(precision) && precision >= 0),
|
|
178
|
-
'round
|
|
179
|
+
'[litecanvas] round() 2nd param must be a positive number or zero'
|
|
179
180
|
)
|
|
180
181
|
if (!precision) {
|
|
181
182
|
return math.round(n)
|
|
@@ -193,10 +194,13 @@ export default function litecanvas(settings = {}) {
|
|
|
193
194
|
* @returns {number}
|
|
194
195
|
*/
|
|
195
196
|
clamp: (value, min, max) => {
|
|
196
|
-
DEV: assert(isNumber(value), 'clamp
|
|
197
|
-
DEV: assert(isNumber(min), 'clamp
|
|
198
|
-
DEV: assert(isNumber(max), 'clamp
|
|
199
|
-
DEV: assert(
|
|
197
|
+
DEV: assert(isNumber(value), '[litecanvas] clamp() 1st param must be a number')
|
|
198
|
+
DEV: assert(isNumber(min), '[litecanvas] clamp() 2nd param must be a number')
|
|
199
|
+
DEV: assert(isNumber(max), '[litecanvas] clamp() 3rd param must be a number')
|
|
200
|
+
DEV: assert(
|
|
201
|
+
max > min,
|
|
202
|
+
'[litecanvas] clamp() the 2nd param must be less than the 3rd param'
|
|
203
|
+
)
|
|
200
204
|
|
|
201
205
|
if (value < min) return min
|
|
202
206
|
if (value > max) return max
|
|
@@ -212,10 +216,13 @@ export default function litecanvas(settings = {}) {
|
|
|
212
216
|
* @returns {number}
|
|
213
217
|
*/
|
|
214
218
|
wrap: (value, min, max) => {
|
|
215
|
-
DEV: assert(isNumber(value), 'wrap
|
|
216
|
-
DEV: assert(isNumber(min), 'wrap
|
|
217
|
-
DEV: assert(isNumber(max), 'wrap
|
|
218
|
-
DEV: assert(
|
|
219
|
+
DEV: assert(isNumber(value), '[litecanvas] wrap() 1st param must be a number')
|
|
220
|
+
DEV: assert(isNumber(min), '[litecanvas] wrap() 2nd param must be a number')
|
|
221
|
+
DEV: assert(isNumber(max), '[litecanvas] wrap() 3rd param must be a number')
|
|
222
|
+
DEV: assert(
|
|
223
|
+
max > min,
|
|
224
|
+
'[litecanvas] wrap() the 2nd param must be less than the 3rd param'
|
|
225
|
+
)
|
|
219
226
|
|
|
220
227
|
return value - (max - min) * math.floor((value - min) / (max - min))
|
|
221
228
|
},
|
|
@@ -232,12 +239,15 @@ export default function litecanvas(settings = {}) {
|
|
|
232
239
|
* @returns {number} the remapped number
|
|
233
240
|
*/
|
|
234
241
|
map(value, start1, stop1, start2, stop2, withinBounds) {
|
|
235
|
-
DEV: assert(isNumber(value), 'map
|
|
236
|
-
DEV: assert(isNumber(start1), 'map
|
|
237
|
-
DEV: assert(isNumber(stop1), 'map
|
|
238
|
-
DEV: assert(isNumber(start2), 'map
|
|
239
|
-
DEV: assert(isNumber(stop2), 'map
|
|
240
|
-
DEV: assert(
|
|
242
|
+
DEV: assert(isNumber(value), '[litecanvas] map() 1st param must be a number')
|
|
243
|
+
DEV: assert(isNumber(start1), '[litecanvas] map() 2nd param must be a number')
|
|
244
|
+
DEV: assert(isNumber(stop1), '[litecanvas] map() 3rd param must be a number')
|
|
245
|
+
DEV: assert(isNumber(start2), '[litecanvas] map() 4th param must be a number')
|
|
246
|
+
DEV: assert(isNumber(stop2), '[litecanvas] map() 5th param must be a number')
|
|
247
|
+
DEV: assert(
|
|
248
|
+
stop1 !== start1,
|
|
249
|
+
'[litecanvas] map() the 2nd param must be different than the 3rd param'
|
|
250
|
+
)
|
|
241
251
|
|
|
242
252
|
// prettier-ignore
|
|
243
253
|
const result = ((value - start1) / (stop1 - start1)) * (stop2 - start2) + start2
|
|
@@ -255,9 +265,13 @@ export default function litecanvas(settings = {}) {
|
|
|
255
265
|
* @returns {number} the normalized number.
|
|
256
266
|
*/
|
|
257
267
|
norm: (value, start, stop) => {
|
|
258
|
-
DEV: assert(isNumber(value), 'norm
|
|
259
|
-
DEV: assert(isNumber(start), 'norm
|
|
260
|
-
DEV: assert(isNumber(stop), 'norm
|
|
268
|
+
DEV: assert(isNumber(value), '[litecanvas] norm() 1st param must be a number')
|
|
269
|
+
DEV: assert(isNumber(start), '[litecanvas] norm() 2nd param must be a number')
|
|
270
|
+
DEV: assert(isNumber(stop), '[litecanvas] norm() 3rd param must be a number')
|
|
271
|
+
DEV: assert(
|
|
272
|
+
start !== stop,
|
|
273
|
+
'[litecanvas] norm() the 2nd param must be different than the 3rd param'
|
|
274
|
+
)
|
|
261
275
|
|
|
262
276
|
return instance.map(value, start, stop, 0, 1)
|
|
263
277
|
},
|
|
@@ -271,12 +285,12 @@ export default function litecanvas(settings = {}) {
|
|
|
271
285
|
* @param {(n: number) => number} [fn] - the periodic function (which default to `Math.sin`)
|
|
272
286
|
*/
|
|
273
287
|
wave: (from, to, t, fn = Math.sin) => {
|
|
274
|
-
DEV: assert(isNumber(from), 'wave
|
|
275
|
-
DEV: assert(isNumber(to), 'wave
|
|
276
|
-
DEV: assert(isNumber(t), 'wave
|
|
288
|
+
DEV: assert(isNumber(from), '[litecanvas] wave() 1st param must be a number')
|
|
289
|
+
DEV: assert(isNumber(to), '[litecanvas] wave() 2nd param must be a number')
|
|
290
|
+
DEV: assert(isNumber(t), '[litecanvas] wave() 3rd param must be a number')
|
|
277
291
|
DEV: assert(
|
|
278
292
|
'function' === typeof fn,
|
|
279
|
-
'wave
|
|
293
|
+
'[litecanvas] wave() 4rd param must be a function (n: number) => number'
|
|
280
294
|
)
|
|
281
295
|
return from + ((fn(t) + 1) / 2) * (to - from)
|
|
282
296
|
},
|
|
@@ -291,9 +305,12 @@ export default function litecanvas(settings = {}) {
|
|
|
291
305
|
* @returns {number} the random number
|
|
292
306
|
*/
|
|
293
307
|
rand: (min = 0.0, max = 1.0) => {
|
|
294
|
-
DEV: assert(isNumber(min), 'rand
|
|
295
|
-
DEV: assert(isNumber(max), 'rand
|
|
296
|
-
DEV: assert(
|
|
308
|
+
DEV: assert(isNumber(min), '[litecanvas] rand() 1st param must be a number')
|
|
309
|
+
DEV: assert(isNumber(max), '[litecanvas] rand() 2nd param must be a number')
|
|
310
|
+
DEV: assert(
|
|
311
|
+
max > min,
|
|
312
|
+
'[litecanvas] rand() the 1st param must be less than the 2nd param'
|
|
313
|
+
)
|
|
297
314
|
|
|
298
315
|
const a = 1664525
|
|
299
316
|
const c = 1013904223
|
|
@@ -312,9 +329,12 @@ export default function litecanvas(settings = {}) {
|
|
|
312
329
|
* @returns {number} the random number
|
|
313
330
|
*/
|
|
314
331
|
randi: (min = 0, max = 1) => {
|
|
315
|
-
DEV: assert(isNumber(min), 'randi
|
|
316
|
-
DEV: assert(isNumber(max), 'randi
|
|
317
|
-
DEV: assert(
|
|
332
|
+
DEV: assert(isNumber(min), '[litecanvas] randi() 1st param must be a number')
|
|
333
|
+
DEV: assert(isNumber(max), '[litecanvas] randi() 2nd param must be a number')
|
|
334
|
+
DEV: assert(
|
|
335
|
+
max > min,
|
|
336
|
+
'[litecanvas] randi() the 1st param must be less than the 2nd param'
|
|
337
|
+
)
|
|
318
338
|
|
|
319
339
|
return math.floor(instance.rand(min, max + 1))
|
|
320
340
|
},
|
|
@@ -329,7 +349,7 @@ export default function litecanvas(settings = {}) {
|
|
|
329
349
|
rseed(value) {
|
|
330
350
|
DEV: assert(
|
|
331
351
|
null == value || (isNumber(value) && value >= 0),
|
|
332
|
-
'rseed
|
|
352
|
+
'[litecanvas] rseed() 1st param must be a positive number or zero'
|
|
333
353
|
)
|
|
334
354
|
|
|
335
355
|
_rngSeed = ~~value
|
|
@@ -344,7 +364,7 @@ export default function litecanvas(settings = {}) {
|
|
|
344
364
|
cls(color) {
|
|
345
365
|
DEV: assert(
|
|
346
366
|
null == color || (isNumber(color) && color >= 0),
|
|
347
|
-
'cls
|
|
367
|
+
'[litecanvas] cls() 1st param must be a positive number or zero or undefined'
|
|
348
368
|
)
|
|
349
369
|
|
|
350
370
|
if (null == color) {
|
|
@@ -367,20 +387,23 @@ export default function litecanvas(settings = {}) {
|
|
|
367
387
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/roundRect
|
|
368
388
|
*/
|
|
369
389
|
rect(x, y, width, height, color, radii) {
|
|
370
|
-
DEV: assert(isNumber(x), 'rect
|
|
371
|
-
DEV: assert(isNumber(y), 'rect
|
|
372
|
-
DEV: assert(
|
|
390
|
+
DEV: assert(isNumber(x), '[litecanvas] rect() 1st param must be a number')
|
|
391
|
+
DEV: assert(isNumber(y), '[litecanvas] rect() 2nd param must be a number')
|
|
392
|
+
DEV: assert(
|
|
393
|
+
isNumber(width) && width > 0,
|
|
394
|
+
'[litecanvas] rect() 3rd param must be a positive number'
|
|
395
|
+
)
|
|
373
396
|
DEV: assert(
|
|
374
397
|
isNumber(height) && height >= 0,
|
|
375
|
-
'rect
|
|
398
|
+
'[litecanvas] rect() 4th param must be a positive number or zero'
|
|
376
399
|
)
|
|
377
400
|
DEV: assert(
|
|
378
401
|
null == color || (isNumber(color) && color >= 0),
|
|
379
|
-
'rect
|
|
402
|
+
'[litecanvas] rect() 5th param must be a positive number or zero'
|
|
380
403
|
)
|
|
381
404
|
DEV: assert(
|
|
382
405
|
null == radii || isNumber(radii) || (Array.isArray(radii) && radii.length >= 1),
|
|
383
|
-
'rect
|
|
406
|
+
'[litecanvas] rect() 6th param must be a number or array of numbers'
|
|
384
407
|
)
|
|
385
408
|
|
|
386
409
|
_ctx.beginPath()
|
|
@@ -405,23 +428,23 @@ export default function litecanvas(settings = {}) {
|
|
|
405
428
|
* @param {number|number[]} [radii] A number or list specifying the radii used to draw a rounded-borders rectangle
|
|
406
429
|
*/
|
|
407
430
|
rectfill(x, y, width, height, color, radii) {
|
|
408
|
-
DEV: assert(isNumber(x), 'rectfill
|
|
409
|
-
DEV: assert(isNumber(y), 'rectfill
|
|
431
|
+
DEV: assert(isNumber(x), '[litecanvas] rectfill() 1st param must be a number')
|
|
432
|
+
DEV: assert(isNumber(y), '[litecanvas] rectfill() 2nd param must be a number')
|
|
410
433
|
DEV: assert(
|
|
411
434
|
isNumber(width) && width >= 0,
|
|
412
|
-
'rectfill
|
|
435
|
+
'[litecanvas] rectfill() 3rd param must be a positive number or zero'
|
|
413
436
|
)
|
|
414
437
|
DEV: assert(
|
|
415
438
|
isNumber(height) && height >= 0,
|
|
416
|
-
'rectfill
|
|
439
|
+
'[litecanvas] rectfill() 4th param must be a positive number or zero'
|
|
417
440
|
)
|
|
418
441
|
DEV: assert(
|
|
419
442
|
null == color || (isNumber(color) && color >= 0),
|
|
420
|
-
'rectfill
|
|
443
|
+
'[litecanvas] rectfill() 5th param must be a positive number or zero'
|
|
421
444
|
)
|
|
422
445
|
DEV: assert(
|
|
423
446
|
null == radii || isNumber(radii) || (Array.isArray(radii) && radii.length >= 1),
|
|
424
|
-
'rectfill
|
|
447
|
+
'[litecanvas] rectfill() 6th param must be a number or array of at least 2 numbers'
|
|
425
448
|
)
|
|
426
449
|
|
|
427
450
|
_ctx.beginPath()
|
|
@@ -438,15 +461,15 @@ export default function litecanvas(settings = {}) {
|
|
|
438
461
|
* @param {number} [color=0] the color index
|
|
439
462
|
*/
|
|
440
463
|
circ(x, y, radius, color) {
|
|
441
|
-
DEV: assert(isNumber(x), 'circ
|
|
442
|
-
DEV: assert(isNumber(y), 'circ
|
|
464
|
+
DEV: assert(isNumber(x), '[litecanvas] circ() 1st param must be a number')
|
|
465
|
+
DEV: assert(isNumber(y), '[litecanvas] circ() 2nd param must be a number')
|
|
443
466
|
DEV: assert(
|
|
444
467
|
isNumber(radius) && radius >= 0,
|
|
445
|
-
'circ
|
|
468
|
+
'[litecanvas] circ() 3rd param must be a positive number or zero'
|
|
446
469
|
)
|
|
447
470
|
DEV: assert(
|
|
448
471
|
null == color || (isNumber(color) && color >= 0),
|
|
449
|
-
'circ
|
|
472
|
+
'[litecanvas] circ() 4th param must be a positive number or zero'
|
|
450
473
|
)
|
|
451
474
|
|
|
452
475
|
_ctx.beginPath()
|
|
@@ -463,15 +486,15 @@ export default function litecanvas(settings = {}) {
|
|
|
463
486
|
* @param {number} [color=0] the color index
|
|
464
487
|
*/
|
|
465
488
|
circfill(x, y, radius, color) {
|
|
466
|
-
DEV: assert(isNumber(x), 'circfill
|
|
467
|
-
DEV: assert(isNumber(y), 'circfill
|
|
489
|
+
DEV: assert(isNumber(x), '[litecanvas] circfill() 1st param must be a number')
|
|
490
|
+
DEV: assert(isNumber(y), '[litecanvas] circfill() 2nd param must be a number')
|
|
468
491
|
DEV: assert(
|
|
469
492
|
isNumber(radius) && radius >= 0,
|
|
470
|
-
'circfill
|
|
493
|
+
'[litecanvas] circfill() 3rd param must be a positive number or zero'
|
|
471
494
|
)
|
|
472
495
|
DEV: assert(
|
|
473
496
|
null == color || (isNumber(color) && color >= 0),
|
|
474
|
-
'circfill
|
|
497
|
+
'[litecanvas] circfill() 4th param must be a positive number or zero'
|
|
475
498
|
)
|
|
476
499
|
|
|
477
500
|
_ctx.beginPath()
|
|
@@ -479,6 +502,66 @@ export default function litecanvas(settings = {}) {
|
|
|
479
502
|
instance.fill(color)
|
|
480
503
|
},
|
|
481
504
|
|
|
505
|
+
/**
|
|
506
|
+
* Draw a ellipse outline
|
|
507
|
+
*
|
|
508
|
+
* @param {number} x
|
|
509
|
+
* @param {number} y
|
|
510
|
+
* @param {number} radiusX
|
|
511
|
+
* @param {number} radiusY
|
|
512
|
+
* @param {number} [color=0] the color index
|
|
513
|
+
*/
|
|
514
|
+
oval(x, y, radiusX, radiusY, color) {
|
|
515
|
+
DEV: assert(isNumber(x), '[litecanvas] oval() 1st param must be a number')
|
|
516
|
+
DEV: assert(isNumber(y), '[litecanvas] oval() 2nd param must be a number')
|
|
517
|
+
DEV: assert(
|
|
518
|
+
isNumber(radiusX) && radiusX >= 0,
|
|
519
|
+
'[litecanvas] oval() 3rd param must be a positive number or zero'
|
|
520
|
+
)
|
|
521
|
+
DEV: assert(
|
|
522
|
+
isNumber(radiusY) && radiusY >= 0,
|
|
523
|
+
'[litecanvas] oval() 4th param must be a positive number or zero'
|
|
524
|
+
)
|
|
525
|
+
DEV: assert(
|
|
526
|
+
null == color || (isNumber(color) && color >= 0),
|
|
527
|
+
'[litecanvas] oval() 5th param must be a positive number or zero'
|
|
528
|
+
)
|
|
529
|
+
|
|
530
|
+
_ctx.beginPath()
|
|
531
|
+
_ctx.ellipse(~~x, ~~y, ~~radiusX, ~~radiusY, 0, 0, TWO_PI)
|
|
532
|
+
instance.stroke(color)
|
|
533
|
+
},
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Draw a color-filled ellipse
|
|
537
|
+
*
|
|
538
|
+
* @param {number} x
|
|
539
|
+
* @param {number} y
|
|
540
|
+
* @param {number} radiusX
|
|
541
|
+
* @param {number} radiusY
|
|
542
|
+
* @param {number} [color=0] the color index
|
|
543
|
+
*/
|
|
544
|
+
ovalfill(x, y, radiusX, radiusY, color) {
|
|
545
|
+
DEV: assert(isNumber(x), '[litecanvas] ovalfill() 1st param must be a number')
|
|
546
|
+
DEV: assert(isNumber(y), '[litecanvas] ovalfill() 2nd param must be a number')
|
|
547
|
+
DEV: assert(
|
|
548
|
+
isNumber(radiusX) && radiusX >= 0,
|
|
549
|
+
'[litecanvas] ovalfill() 3rd param must be a positive number or zero'
|
|
550
|
+
)
|
|
551
|
+
DEV: assert(
|
|
552
|
+
isNumber(radiusY) && radiusY >= 0,
|
|
553
|
+
'[litecanvas] ovalfill() 4th param must be a positive number or zero'
|
|
554
|
+
)
|
|
555
|
+
DEV: assert(
|
|
556
|
+
null == color || (isNumber(color) && color >= 0),
|
|
557
|
+
'[litecanvas] ovalfill() 5th param must be a positive number or zero'
|
|
558
|
+
)
|
|
559
|
+
|
|
560
|
+
_ctx.beginPath()
|
|
561
|
+
_ctx.ellipse(~~x, ~~y, ~~radiusX, ~~radiusY, 0, 0, TWO_PI)
|
|
562
|
+
instance.fill(color)
|
|
563
|
+
},
|
|
564
|
+
|
|
482
565
|
/**
|
|
483
566
|
* Draw a line
|
|
484
567
|
*
|
|
@@ -489,13 +572,19 @@ export default function litecanvas(settings = {}) {
|
|
|
489
572
|
* @param {number} [color=0] the color index
|
|
490
573
|
*/
|
|
491
574
|
line(x1, y1, x2, y2, color) {
|
|
492
|
-
DEV: assert(isNumber(x1), 'line
|
|
493
|
-
DEV: assert(isNumber(y1), 'line
|
|
494
|
-
DEV: assert(
|
|
495
|
-
|
|
575
|
+
DEV: assert(isNumber(x1), '[litecanvas] line() 1st param must be a number')
|
|
576
|
+
DEV: assert(isNumber(y1), '[litecanvas] line() 2nd param must be a number')
|
|
577
|
+
DEV: assert(
|
|
578
|
+
isNumber(x2),
|
|
579
|
+
'[litecanvas] line() 3rd param must be a positive number or zero'
|
|
580
|
+
)
|
|
581
|
+
DEV: assert(
|
|
582
|
+
isNumber(y2),
|
|
583
|
+
'[litecanvas] line() 4th param must be a positive number or zero'
|
|
584
|
+
)
|
|
496
585
|
DEV: assert(
|
|
497
586
|
null == color || (isNumber(color) && color >= 0),
|
|
498
|
-
'line
|
|
587
|
+
'[litecanvas] line() 5th param must be a positive number or zero'
|
|
499
588
|
)
|
|
500
589
|
|
|
501
590
|
_ctx.beginPath()
|
|
@@ -518,7 +607,7 @@ export default function litecanvas(settings = {}) {
|
|
|
518
607
|
linewidth(value) {
|
|
519
608
|
DEV: assert(
|
|
520
609
|
isNumber(value) && ~~value > 0,
|
|
521
|
-
'linewidth
|
|
610
|
+
'[litecanvas] linewidth() 1st param must be a positive number'
|
|
522
611
|
)
|
|
523
612
|
|
|
524
613
|
_ctx.lineWidth = ~~value
|
|
@@ -536,9 +625,9 @@ export default function litecanvas(settings = {}) {
|
|
|
536
625
|
linedash(segments, offset = 0) {
|
|
537
626
|
DEV: assert(
|
|
538
627
|
Array.isArray(segments) && segments.length > 0,
|
|
539
|
-
'linedash
|
|
628
|
+
'[litecanvas] linedash() 1st param must be an array of numbers'
|
|
540
629
|
)
|
|
541
|
-
DEV: assert(isNumber(offset), 'linedash
|
|
630
|
+
DEV: assert(isNumber(offset), '[litecanvas] linedash() 2nd param must be a number')
|
|
542
631
|
|
|
543
632
|
_ctx.setLineDash(segments)
|
|
544
633
|
_ctx.lineDashOffset = offset
|
|
@@ -555,13 +644,16 @@ export default function litecanvas(settings = {}) {
|
|
|
555
644
|
* @param {string} [fontStyle] can be "normal" (default), "italic" and/or "bold".
|
|
556
645
|
*/
|
|
557
646
|
text(x, y, message, color = 3, fontStyle = 'normal') {
|
|
558
|
-
DEV: assert(isNumber(x), 'text
|
|
559
|
-
DEV: assert(isNumber(y), 'text
|
|
647
|
+
DEV: assert(isNumber(x), '[litecanvas] text() 1st param must be a number')
|
|
648
|
+
DEV: assert(isNumber(y), '[litecanvas] text() 2nd param must be a number')
|
|
560
649
|
DEV: assert(
|
|
561
650
|
null == color || (isNumber(color) && color >= 0),
|
|
562
|
-
'text
|
|
651
|
+
'[litecanvas] text() 4th param must be a positive number or zero'
|
|
652
|
+
)
|
|
653
|
+
DEV: assert(
|
|
654
|
+
'string' === typeof fontStyle,
|
|
655
|
+
'[litecanvas] text() 5th param must be a string'
|
|
563
656
|
)
|
|
564
|
-
DEV: assert('string' === typeof fontStyle, 'text: 5th param must be a string')
|
|
565
657
|
|
|
566
658
|
_ctx.font = `${fontStyle} ${_fontSize}px ${_fontFamily}`
|
|
567
659
|
_ctx.fillStyle = _colors[~~color % _colors.length]
|
|
@@ -574,7 +666,10 @@ export default function litecanvas(settings = {}) {
|
|
|
574
666
|
* @param {string} family
|
|
575
667
|
*/
|
|
576
668
|
textfont(family) {
|
|
577
|
-
DEV: assert(
|
|
669
|
+
DEV: assert(
|
|
670
|
+
'string' === typeof family,
|
|
671
|
+
'[litecanvas] textfont() 1st param must be a string'
|
|
672
|
+
)
|
|
578
673
|
|
|
579
674
|
_fontFamily = family
|
|
580
675
|
},
|
|
@@ -585,7 +680,7 @@ export default function litecanvas(settings = {}) {
|
|
|
585
680
|
* @param {number} size
|
|
586
681
|
*/
|
|
587
682
|
textsize(size) {
|
|
588
|
-
DEV: assert(isNumber(size), 'textsize
|
|
683
|
+
DEV: assert(isNumber(size), '[litecanvas] textsize() 1st param must be a number')
|
|
589
684
|
|
|
590
685
|
_fontSize = size
|
|
591
686
|
},
|
|
@@ -601,14 +696,14 @@ export default function litecanvas(settings = {}) {
|
|
|
601
696
|
textalign(align, baseline) {
|
|
602
697
|
DEV: assert(
|
|
603
698
|
null == align || ['left', 'right', 'center', 'start', 'end'].includes(align),
|
|
604
|
-
'textalign
|
|
699
|
+
'[litecanvas] textalign() 1st param must be null or one of the following strings: center, left, right, start or end.'
|
|
605
700
|
)
|
|
606
701
|
DEV: assert(
|
|
607
702
|
null == baseline ||
|
|
608
703
|
['top', 'bottom', 'middle', 'hanging', 'alphabetic', 'ideographic'].includes(
|
|
609
704
|
baseline
|
|
610
705
|
),
|
|
611
|
-
'textalign
|
|
706
|
+
'[litecanvas] textalign() 2nd param must be null or one of the following strings: middle, top, bottom, hanging, alphabetic or ideographic.'
|
|
612
707
|
)
|
|
613
708
|
|
|
614
709
|
if (align) _ctx.textAlign = align
|
|
@@ -624,8 +719,8 @@ export default function litecanvas(settings = {}) {
|
|
|
624
719
|
* @param {OffscreenCanvas|HTMLImageElement|HTMLCanvasElement} source
|
|
625
720
|
*/
|
|
626
721
|
image(x, y, source) {
|
|
627
|
-
DEV: assert(isNumber(x), 'image
|
|
628
|
-
DEV: assert(isNumber(y), 'image
|
|
722
|
+
DEV: assert(isNumber(x), '[litecanvas] image() 1st param must be a number')
|
|
723
|
+
DEV: assert(isNumber(y), '[litecanvas] image() 2nd param must be a number')
|
|
629
724
|
|
|
630
725
|
_ctx.drawImage(source, ~~x, ~~y)
|
|
631
726
|
},
|
|
@@ -643,22 +738,25 @@ export default function litecanvas(settings = {}) {
|
|
|
643
738
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
|
|
644
739
|
*/
|
|
645
740
|
paint(width, height, drawing, options = {}) {
|
|
646
|
-
DEV: assert(
|
|
741
|
+
DEV: assert(
|
|
742
|
+
isNumber(width) && width >= 1,
|
|
743
|
+
'[litecanvas] paint() 1st param must be a positive number'
|
|
744
|
+
)
|
|
647
745
|
DEV: assert(
|
|
648
746
|
isNumber(height) && height >= 1,
|
|
649
|
-
'paint
|
|
747
|
+
'[litecanvas] paint() 2nd param must be a positive number'
|
|
650
748
|
)
|
|
651
749
|
DEV: assert(
|
|
652
750
|
'function' === typeof drawing || Array.isArray(drawing),
|
|
653
|
-
'paint
|
|
751
|
+
'[litecanvas] paint() 3rd param must be a function or array'
|
|
654
752
|
)
|
|
655
753
|
DEV: assert(
|
|
656
754
|
(options && null == options.scale) || isNumber(options.scale),
|
|
657
|
-
'paint
|
|
755
|
+
'[litecanvas] paint() 4th param (options.scale) must be a number'
|
|
658
756
|
)
|
|
659
757
|
DEV: assert(
|
|
660
758
|
(options && null == options.canvas) || options.canvas instanceof OffscreenCanvas,
|
|
661
|
-
'paint
|
|
759
|
+
'[litecanvas] paint() 4th param (options.canvas) must be an OffscreenCanvas'
|
|
662
760
|
)
|
|
663
761
|
|
|
664
762
|
const /** @type {OffscreenCanvas} */
|
|
@@ -735,8 +833,8 @@ export default function litecanvas(settings = {}) {
|
|
|
735
833
|
* @param {number} y
|
|
736
834
|
*/
|
|
737
835
|
translate: (x, y) => {
|
|
738
|
-
DEV: assert(isNumber(x), 'translate
|
|
739
|
-
DEV: assert(isNumber(y), 'translate
|
|
836
|
+
DEV: assert(isNumber(x), '[litecanvas] translate() 1st param must be a number')
|
|
837
|
+
DEV: assert(isNumber(y), '[litecanvas] translate() 2nd param must be a number')
|
|
740
838
|
|
|
741
839
|
return _ctx.translate(~~x, ~~y)
|
|
742
840
|
},
|
|
@@ -748,8 +846,8 @@ export default function litecanvas(settings = {}) {
|
|
|
748
846
|
* @param {number} [y]
|
|
749
847
|
*/
|
|
750
848
|
scale: (x, y) => {
|
|
751
|
-
DEV: assert(isNumber(x), 'scale
|
|
752
|
-
DEV: assert(null == y || isNumber(y), 'scale
|
|
849
|
+
DEV: assert(isNumber(x), '[litecanvas] scale() 1st param must be a number')
|
|
850
|
+
DEV: assert(null == y || isNumber(y), '[litecanvas] scale() 2nd param must be a number')
|
|
753
851
|
|
|
754
852
|
return _ctx.scale(x, y || x)
|
|
755
853
|
},
|
|
@@ -760,7 +858,7 @@ export default function litecanvas(settings = {}) {
|
|
|
760
858
|
* @param {number} radians
|
|
761
859
|
*/
|
|
762
860
|
rotate: (radians) => {
|
|
763
|
-
DEV: assert(isNumber(radians), 'rotate
|
|
861
|
+
DEV: assert(isNumber(radians), '[litecanvas] rotate() 1st param must be a number')
|
|
764
862
|
|
|
765
863
|
return _ctx.rotate(radians)
|
|
766
864
|
},
|
|
@@ -772,7 +870,7 @@ export default function litecanvas(settings = {}) {
|
|
|
772
870
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalAlpha
|
|
773
871
|
*/
|
|
774
872
|
alpha(value) {
|
|
775
|
-
DEV: assert(isNumber(value), 'alpha
|
|
873
|
+
DEV: assert(isNumber(value), '[litecanvas] alpha() 1st param must be a number')
|
|
776
874
|
|
|
777
875
|
_ctx.globalAlpha = instance.clamp(value, 0, 1)
|
|
778
876
|
},
|
|
@@ -789,7 +887,7 @@ export default function litecanvas(settings = {}) {
|
|
|
789
887
|
path: (arg) => {
|
|
790
888
|
DEV: assert(
|
|
791
889
|
null == arg || 'string' === typeof arg || arg instanceof Path2D,
|
|
792
|
-
'path
|
|
890
|
+
'[litecanvas] path() 1st param must be a string or a Path2D instance'
|
|
793
891
|
)
|
|
794
892
|
|
|
795
893
|
return new Path2D(arg)
|
|
@@ -804,11 +902,11 @@ export default function litecanvas(settings = {}) {
|
|
|
804
902
|
fill(color, path) {
|
|
805
903
|
DEV: assert(
|
|
806
904
|
null == color || (isNumber(color) && color >= 0),
|
|
807
|
-
'fill
|
|
905
|
+
'[litecanvas] fill() 1st param must be a positive number or zero'
|
|
808
906
|
)
|
|
809
907
|
DEV: assert(
|
|
810
908
|
null == path || path instanceof Path2D,
|
|
811
|
-
'fill
|
|
909
|
+
'[litecanvas] fill() 2nd param must be a Path2D instance'
|
|
812
910
|
)
|
|
813
911
|
|
|
814
912
|
_ctx.fillStyle = _colors[~~color % _colors.length]
|
|
@@ -828,11 +926,11 @@ export default function litecanvas(settings = {}) {
|
|
|
828
926
|
stroke(color, path) {
|
|
829
927
|
DEV: assert(
|
|
830
928
|
null == color || (isNumber(color) && color >= 0),
|
|
831
|
-
'stroke
|
|
929
|
+
'[litecanvas] stroke() 1st param must be a positive number or zero'
|
|
832
930
|
)
|
|
833
931
|
DEV: assert(
|
|
834
932
|
null == path || path instanceof Path2D,
|
|
835
|
-
'stroke
|
|
933
|
+
'[litecanvas] stroke() 2nd param must be a Path2D instance'
|
|
836
934
|
)
|
|
837
935
|
|
|
838
936
|
_ctx.strokeStyle = _colors[~~color % _colors.length]
|
|
@@ -852,7 +950,10 @@ export default function litecanvas(settings = {}) {
|
|
|
852
950
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/clip
|
|
853
951
|
*/
|
|
854
952
|
clip(path) {
|
|
855
|
-
DEV: assert(
|
|
953
|
+
DEV: assert(
|
|
954
|
+
path instanceof Path2D,
|
|
955
|
+
'[litecanvas] clip() 1st param must be a Path2D instance'
|
|
956
|
+
)
|
|
856
957
|
|
|
857
958
|
_ctx.clip(path)
|
|
858
959
|
},
|
|
@@ -872,10 +973,10 @@ export default function litecanvas(settings = {}) {
|
|
|
872
973
|
sfx(zzfxParams, pitchSlide = 0, volumeFactor = 1) {
|
|
873
974
|
DEV: assert(
|
|
874
975
|
null == zzfxParams || Array.isArray(zzfxParams),
|
|
875
|
-
'sfx
|
|
976
|
+
'[litecanvas] sfx() 1st param must be an array'
|
|
876
977
|
)
|
|
877
|
-
DEV: assert(isNumber(pitchSlide), 'sfx
|
|
878
|
-
DEV: assert(isNumber(volumeFactor), 'sfx
|
|
978
|
+
DEV: assert(isNumber(pitchSlide), '[litecanvas] sfx() 2nd param must be a number')
|
|
979
|
+
DEV: assert(isNumber(volumeFactor), '[litecanvas] sfx() 3rd param must be a number')
|
|
879
980
|
|
|
880
981
|
if (
|
|
881
982
|
// @ts-ignore
|
|
@@ -906,7 +1007,7 @@ export default function litecanvas(settings = {}) {
|
|
|
906
1007
|
* @param {number} value
|
|
907
1008
|
*/
|
|
908
1009
|
volume(value) {
|
|
909
|
-
DEV: assert(isNumber(value), 'volume
|
|
1010
|
+
DEV: assert(isNumber(value), '[litecanvas] volume() 1st param must be a number')
|
|
910
1011
|
|
|
911
1012
|
// @ts-ignore
|
|
912
1013
|
root.zzfxV = value
|
|
@@ -925,8 +1026,14 @@ export default function litecanvas(settings = {}) {
|
|
|
925
1026
|
* @param {pluginCallback} callback
|
|
926
1027
|
*/
|
|
927
1028
|
use(callback, config = {}) {
|
|
928
|
-
DEV: assert(
|
|
929
|
-
|
|
1029
|
+
DEV: assert(
|
|
1030
|
+
'function' === typeof callback,
|
|
1031
|
+
'[litecanvas] use() 1st param must be a function'
|
|
1032
|
+
)
|
|
1033
|
+
DEV: assert(
|
|
1034
|
+
'object' === typeof config,
|
|
1035
|
+
'[litecanvas] use() 2nd param must be an object'
|
|
1036
|
+
)
|
|
930
1037
|
|
|
931
1038
|
if (_initialized) {
|
|
932
1039
|
// load the plugin now
|
|
@@ -945,8 +1052,14 @@ export default function litecanvas(settings = {}) {
|
|
|
945
1052
|
* @returns {Function} a function to remove the listener
|
|
946
1053
|
*/
|
|
947
1054
|
listen(eventName, callback) {
|
|
948
|
-
DEV: assert(
|
|
949
|
-
|
|
1055
|
+
DEV: assert(
|
|
1056
|
+
'string' === typeof eventName,
|
|
1057
|
+
'[litecanvas] listen() 1st param must be a string'
|
|
1058
|
+
)
|
|
1059
|
+
DEV: assert(
|
|
1060
|
+
'function' === typeof callback,
|
|
1061
|
+
'[litecanvas] listen() 2nd param must be a function'
|
|
1062
|
+
)
|
|
950
1063
|
|
|
951
1064
|
eventName = eventName.toLowerCase()
|
|
952
1065
|
|
|
@@ -967,7 +1080,10 @@ export default function litecanvas(settings = {}) {
|
|
|
967
1080
|
* @param {*} [arg4] any data to be passed over the listeners
|
|
968
1081
|
*/
|
|
969
1082
|
emit(eventName, arg1, arg2, arg3, arg4) {
|
|
970
|
-
DEV: assert(
|
|
1083
|
+
DEV: assert(
|
|
1084
|
+
'string' === typeof eventName,
|
|
1085
|
+
'[litecanvas] emit() 1st param must be a string'
|
|
1086
|
+
)
|
|
971
1087
|
if (_initialized) {
|
|
972
1088
|
eventName = eventName.toLowerCase()
|
|
973
1089
|
|
|
@@ -985,7 +1101,7 @@ export default function litecanvas(settings = {}) {
|
|
|
985
1101
|
pal(colors = defaultPalette) {
|
|
986
1102
|
DEV: assert(
|
|
987
1103
|
Array.isArray(colors) && colors.length > 0,
|
|
988
|
-
'pal
|
|
1104
|
+
'[litecanvas] pal() 1st param must be a array of strings'
|
|
989
1105
|
)
|
|
990
1106
|
_colors = colors
|
|
991
1107
|
},
|
|
@@ -997,7 +1113,7 @@ export default function litecanvas(settings = {}) {
|
|
|
997
1113
|
* @param {*} value
|
|
998
1114
|
*/
|
|
999
1115
|
def(key, value) {
|
|
1000
|
-
DEV: assert('string' === typeof key, 'def
|
|
1116
|
+
DEV: assert('string' === typeof key, '[litecanvas] def() 1st param must be a string')
|
|
1001
1117
|
DEV: if (null == value) {
|
|
1002
1118
|
console.warn(`def: key "${key}" was defined as ${value} but now is null`)
|
|
1003
1119
|
}
|
|
@@ -1018,7 +1134,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1018
1134
|
timescale(value) {
|
|
1019
1135
|
DEV: assert(
|
|
1020
1136
|
isNumber(value) && value >= 0,
|
|
1021
|
-
'timescale
|
|
1137
|
+
'[litecanvas] timescale() 1st param must be a positive number or zero'
|
|
1022
1138
|
)
|
|
1023
1139
|
|
|
1024
1140
|
_timeScale = value
|
|
@@ -1032,7 +1148,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1032
1148
|
framerate(value) {
|
|
1033
1149
|
DEV: assert(
|
|
1034
1150
|
isNumber(value) && value >= 1,
|
|
1035
|
-
'framerate
|
|
1151
|
+
'[litecanvas] framerate() 1st param must be a positive number'
|
|
1036
1152
|
)
|
|
1037
1153
|
|
|
1038
1154
|
_deltaTime = 1 / ~~value
|
|
@@ -1045,7 +1161,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1045
1161
|
* @returns {any}
|
|
1046
1162
|
*/
|
|
1047
1163
|
stat(n) {
|
|
1048
|
-
DEV: assert(isNumber(n) && n >= 0, 'stat
|
|
1164
|
+
DEV: assert(isNumber(n) && n >= 0, '[litecanvas] stat() 1st param must be a number')
|
|
1049
1165
|
|
|
1050
1166
|
const list = [
|
|
1051
1167
|
// 0
|
|
@@ -1127,6 +1243,9 @@ export default function litecanvas(settings = {}) {
|
|
|
1127
1243
|
// setup default event listeners
|
|
1128
1244
|
const source = settings.loop ? settings.loop : root
|
|
1129
1245
|
for (const event of _coreEvents.split(',')) {
|
|
1246
|
+
DEV: if (root === source && source[event]) {
|
|
1247
|
+
console.info(`[litecanvas] using window.${event}()`)
|
|
1248
|
+
}
|
|
1130
1249
|
if (source[event]) instance.listen(event, source[event])
|
|
1131
1250
|
}
|
|
1132
1251
|
|
|
@@ -1362,7 +1481,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1362
1481
|
(key) => {
|
|
1363
1482
|
DEV: assert(
|
|
1364
1483
|
null == key || 'string' === typeof key,
|
|
1365
|
-
'iskeydown
|
|
1484
|
+
'[litecanvas] iskeydown() 1st param must be a string or undefined'
|
|
1366
1485
|
)
|
|
1367
1486
|
return keyCheck(_keysDown, key)
|
|
1368
1487
|
}
|
|
@@ -1380,7 +1499,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1380
1499
|
(key) => {
|
|
1381
1500
|
DEV: assert(
|
|
1382
1501
|
null == key || 'string' === typeof key,
|
|
1383
|
-
'iskeypressed
|
|
1502
|
+
'[litecanvas] iskeypressed() 1st param must be a string or undefined'
|
|
1384
1503
|
)
|
|
1385
1504
|
return keyCheck(_keysPress, key)
|
|
1386
1505
|
}
|
|
@@ -1437,7 +1556,10 @@ export default function litecanvas(settings = {}) {
|
|
|
1437
1556
|
function setupCanvas() {
|
|
1438
1557
|
if ('string' === typeof settings.canvas) {
|
|
1439
1558
|
_canvas = document.querySelector(settings.canvas)
|
|
1440
|
-
DEV: assert(
|
|
1559
|
+
DEV: assert(
|
|
1560
|
+
null != _canvas,
|
|
1561
|
+
'[litecanvas] litecanvas() option "canvas" is an invalid CSS selector'
|
|
1562
|
+
)
|
|
1441
1563
|
} else {
|
|
1442
1564
|
_canvas = settings.canvas
|
|
1443
1565
|
}
|
|
@@ -1446,7 +1568,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1446
1568
|
|
|
1447
1569
|
DEV: assert(
|
|
1448
1570
|
'CANVAS' === _canvas.tagName,
|
|
1449
|
-
'
|
|
1571
|
+
'[litecanvas] litecanvas() option "canvas" should be a canvas element or string (CSS selector)'
|
|
1450
1572
|
)
|
|
1451
1573
|
|
|
1452
1574
|
_ctx = _canvas.getContext('2d')
|
|
@@ -1466,22 +1588,25 @@ export default function litecanvas(settings = {}) {
|
|
|
1466
1588
|
function resizeCanvas() {
|
|
1467
1589
|
DEV: assert(
|
|
1468
1590
|
null == settings.width || (isNumber(settings.width) && settings.width > 0),
|
|
1469
|
-
'
|
|
1591
|
+
'[litecanvas] litecanvas() option "width" should be a positive number when defined'
|
|
1470
1592
|
)
|
|
1471
1593
|
DEV: assert(
|
|
1472
1594
|
null == settings.height || (isNumber(settings.height) && settings.height > 0),
|
|
1473
|
-
'
|
|
1595
|
+
'[litecanvas] litecanvas() option "height" should be a positive number when defined'
|
|
1474
1596
|
)
|
|
1475
1597
|
DEV: assert(
|
|
1476
1598
|
null == settings.height || (settings.width > 0 && settings.height > 0),
|
|
1477
|
-
'
|
|
1599
|
+
'[litecanvas] litecanvas() option "width" is required when the option "height" is defined'
|
|
1478
1600
|
)
|
|
1479
1601
|
|
|
1480
1602
|
const width = settings.width || root.innerWidth,
|
|
1481
1603
|
height = settings.height || settings.width || root.innerHeight
|
|
1482
1604
|
|
|
1483
|
-
instance.def('W',
|
|
1484
|
-
instance.def('H',
|
|
1605
|
+
instance.def('W', width)
|
|
1606
|
+
instance.def('H', height)
|
|
1607
|
+
|
|
1608
|
+
_canvas.width = width
|
|
1609
|
+
_canvas.height = height
|
|
1485
1610
|
|
|
1486
1611
|
if (settings.autoscale) {
|
|
1487
1612
|
if (!_canvas.style.display) {
|
|
@@ -1489,11 +1614,11 @@ export default function litecanvas(settings = {}) {
|
|
|
1489
1614
|
_canvas.style.margin = 'auto'
|
|
1490
1615
|
}
|
|
1491
1616
|
|
|
1492
|
-
_scale = math.min(root.innerWidth /
|
|
1617
|
+
_scale = math.min(root.innerWidth / width, root.innerHeight / height)
|
|
1493
1618
|
_scale = (settings.pixelart ? ~~_scale : _scale) || 1
|
|
1494
1619
|
|
|
1495
|
-
_canvas.style.width =
|
|
1496
|
-
_canvas.style.height =
|
|
1620
|
+
_canvas.style.width = width * _scale + 'px'
|
|
1621
|
+
_canvas.style.height = height * _scale + 'px'
|
|
1497
1622
|
}
|
|
1498
1623
|
|
|
1499
1624
|
// restore canvas image rendering properties
|
|
@@ -1537,7 +1662,7 @@ export default function litecanvas(settings = {}) {
|
|
|
1537
1662
|
|
|
1538
1663
|
DEV: assert(
|
|
1539
1664
|
null == pluginData || 'object' === typeof pluginData,
|
|
1540
|
-
'
|
|
1665
|
+
'[litecanvas] litecanvas() plugins should return an object or nothing'
|
|
1541
1666
|
)
|
|
1542
1667
|
|
|
1543
1668
|
for (const key in pluginData) {
|
|
@@ -1548,13 +1673,16 @@ export default function litecanvas(settings = {}) {
|
|
|
1548
1673
|
if (settings.global) {
|
|
1549
1674
|
// @ts-ignore
|
|
1550
1675
|
if (root.ENGINE) {
|
|
1551
|
-
throw new Error('
|
|
1676
|
+
throw new Error('only one global litecanvas is allowed')
|
|
1552
1677
|
}
|
|
1553
1678
|
Object.assign(root, instance)
|
|
1554
1679
|
// @ts-ignore
|
|
1555
1680
|
root.ENGINE = instance
|
|
1556
1681
|
}
|
|
1557
1682
|
|
|
1683
|
+
DEV: console.info(`[litecanvas] version ${version} started`)
|
|
1684
|
+
DEV: console.debug(`[litecanvas] litecanvas() options =`, settings)
|
|
1685
|
+
|
|
1558
1686
|
setupCanvas()
|
|
1559
1687
|
|
|
1560
1688
|
if ('loading' === document.readyState) {
|