|
28 | 28 | if (!condition) throw new Error(message);
|
29 | 29 | };
|
30 | 30 | function litecanvas(settings = {}) {
|
31 |
| - const root = globalThis, math = Math, TWO_PI = math.PI * 2, raf = requestAnimationFrame, _browserEventListeners = [], on = (elem, evt, callback) => { |
| 31 | + const root = window, math = Math, TWO_PI = math.PI * 2, raf = requestAnimationFrame, _browserEventListeners = [], on = (elem, evt, callback) => { |
32 | 32 | elem.addEventListener(evt, callback, false);
|
33 | 33 | _browserEventListeners.push(() => elem.removeEventListener(evt, callback, false));
|
34 |
| - }, zzfx = setupZzFX(root), isNumber = Number.isFinite, defaults = { |
| 34 | + }, isNumber = Number.isFinite, zzfx = setupZzFX(root), defaults = { |
35 | 35 | width: null,
|
36 | 36 | height: null,
|
37 | 37 | autoscale: true,
|
|
551 | 551 | * @see https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
|
552 | 552 | */
|
553 | 553 | paint(width, height, drawing, options = {}) {
|
554 |
| - DEV: assert(isNumber(width), "paint: 1st param must be a number"); |
555 |
| - DEV: assert(isNumber(height), "paint: 2nd param must be a number"); |
| 554 | + DEV: assert(isNumber(width) && width >= 1, "paint: 1st param must be a positive number"); |
| 555 | + DEV: assert( |
| 556 | + isNumber(height) && height >= 1, |
| 557 | + "paint: 2nd param must be a positive number" |
| 558 | + ); |
556 | 559 | DEV: assert(
|
557 | 560 | "function" === typeof drawing || Array.isArray(drawing),
|
558 | 561 | "paint: 3rd param must be a function or array"
|
|
561 | 564 | options && !options.scale || isNumber(options.scale),
|
562 | 565 | "paint: 4th param (options.scale) must be a number"
|
563 | 566 | );
|
| 567 | + DEV: assert( |
| 568 | + options && !options.canvas || options.canvas instanceof OffscreenCanvas, |
| 569 | + "paint: 4th param (options.canvas) must be an OffscreenCanvas" |
| 570 | + ); |
564 | 571 | const canvas = options.canvas || new OffscreenCanvas(1, 1), scale = options.scale || 1, contextOriginal = _ctx;
|
565 | 572 | canvas.width = width * scale;
|
566 | 573 | canvas.height = height * scale;
|
567 | 574 | _ctx = canvas.getContext("2d");
|
568 | 575 | _ctx.scale(scale, scale);
|
569 |
| - if (drawing.push) { |
| 576 | + if (Array.isArray(drawing)) { |
570 | 577 | let x = 0, y = 0;
|
571 | 578 | _ctx.imageSmoothingEnabled = false;
|
572 | 579 | for (const str of drawing) {
|
|
743 | 750 | );
|
744 | 751 | DEV: assert(isNumber(pitchSlide), "sfx: 2nd param must be a number");
|
745 | 752 | DEV: assert(isNumber(volumeFactor), "sfx: 3rd param must be a number");
|
746 |
| - if (root.zzfxV <= 0 || navigator.userActivation && !navigator.userActivation.hasBeenActive) { |
| 753 | + if ( |
| 754 | + // @ts-ignore |
| 755 | + root.zzfxV <= 0 || navigator.userActivation && !navigator.userActivation.hasBeenActive |
| 756 | + ) { |
747 | 757 | return false;
|
748 | 758 | }
|
749 | 759 | zzfxParams = zzfxParams || _defaultSound;
|
|
771 | 781 | *
|
772 | 782 | * @returns {HTMLCanvasElement}
|
773 | 783 | */
|
774 |
| - canvas() { |
775 |
| - return _canvas; |
776 |
| - }, |
| 784 | + canvas: () => _canvas, |
777 | 785 | /**
|
778 | 786 | * Prepares a plugin to be loaded
|
779 | 787 | *
|
|
882 | 890 | * @returns {any}
|
883 | 891 | */
|
884 | 892 | stat(n) {
|
885 |
| - DEV: assert(isNumber(n) && n >= 0, "stat: 1st param must be a positive number"); |
| 893 | + DEV: assert(isNumber(n) && n >= 0, "stat: 1st param must be a number"); |
886 | 894 | const list = [
|
887 | 895 | // 0
|
888 | 896 | settings,
|
|
901 | 909 | // 7
|
902 | 910 | _timeScale,
|
903 | 911 | // 8
|
| 912 | + // @ts-ignore |
904 | 913 | root.zzfxV || 1,
|
905 | 914 | // 9
|
906 | 915 | _rngSeed,
|
|
930 | 939 | }
|
931 | 940 | delete root.ENGINE;
|
932 | 941 | }
|
| 942 | + _initialized = false; |
933 | 943 | }
|
934 | 944 | };
|
935 | 945 | for (const k of "PI,sin,cos,atan2,hypot,tan,abs,ceil,floor,trunc,min,max,pow,sqrt,sign,exp".split(",")) {
|
|
0 commit comments