|
27 | 27 | var assert = (condition, message = "Assertion failed") => { |
28 | 28 | if (!condition) throw new Error(message); |
29 | 29 | }; |
30 | | - var version = "0.95.0"; |
| 30 | + var version = "0.96.0"; |
31 | 31 | function litecanvas(settings = {}) { |
32 | 32 | const root = window, math = Math, TWO_PI = math.PI * 2, raf = requestAnimationFrame, _browserEventListeners = [], on = (elem, evt, callback) => { |
33 | 33 | elem.addEventListener(evt, callback, false); |
|
122 | 122 | round: (n, precision = 0) => { |
123 | 123 | DEV: assert(isNumber(n), "[litecanvas] round() 1st param must be a number"); |
124 | 124 | DEV: assert( |
125 | | - null == precision || isNumber(precision) && precision >= 0, |
| 125 | + isNumber(precision) && precision >= 0, |
126 | 126 | "[litecanvas] round() 2nd param must be a positive number or zero" |
127 | 127 | ); |
128 | 128 | if (!precision) { |
|
508 | 508 | instance.stroke(color); |
509 | 509 | }, |
510 | 510 | /** |
511 | | - * Sets the thickness of lines |
| 511 | + * Sets the thickness of the lines |
512 | 512 | * |
513 | 513 | * @param {number} value |
514 | 514 | * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineWidth |
515 | 515 | */ |
516 | 516 | linewidth(value) { |
517 | 517 | DEV: assert( |
518 | | - isNumber(value) && ~~value > 0, |
519 | | - "[litecanvas] linewidth() 1st param must be a positive number" |
| 518 | + isNumber(value) && value >= 0, |
| 519 | + "[litecanvas] linewidth() 1st param must be a positive number or zero" |
520 | 520 | ); |
521 | 521 | _ctx.lineWidth = ~~value; |
522 | 522 | _outline_fix = 0 === ~~value % 2 ? 0 : 0.5; |
|
695 | 695 | * |
696 | 696 | * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/save |
697 | 697 | */ |
698 | | - push: () => _ctx.save(), |
| 698 | + push() { |
| 699 | + _ctx.save(); |
| 700 | + }, |
699 | 701 | /** |
700 | 702 | * restores the drawing style settings and transformations |
701 | 703 | * |
702 | 704 | * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/restore |
703 | 705 | */ |
704 | | - pop: () => _ctx.restore(), |
| 706 | + pop() { |
| 707 | + _ctx.restore(); |
| 708 | + }, |
705 | 709 | /** |
706 | 710 | * Adds a translation to the transformation matrix. |
707 | 711 | * |
708 | 712 | * @param {number} x |
709 | 713 | * @param {number} y |
710 | 714 | */ |
711 | | - translate: (x, y) => { |
| 715 | + translate(x, y) { |
712 | 716 | DEV: assert(isNumber(x), "[litecanvas] translate() 1st param must be a number"); |
713 | 717 | DEV: assert(isNumber(y), "[litecanvas] translate() 2nd param must be a number"); |
714 | | - return _ctx.translate(~~x, ~~y); |
| 718 | + _ctx.translate(~~x, ~~y); |
715 | 719 | }, |
716 | 720 | /** |
717 | 721 | * Adds a scaling transformation to the canvas units horizontally and/or vertically. |
718 | 722 | * |
719 | 723 | * @param {number} x |
720 | 724 | * @param {number} [y] |
721 | 725 | */ |
722 | | - scale: (x, y) => { |
| 726 | + scale(x, y) { |
723 | 727 | DEV: assert(isNumber(x), "[litecanvas] scale() 1st param must be a number"); |
724 | 728 | DEV: assert(null == y || isNumber(y), "[litecanvas] scale() 2nd param must be a number"); |
725 | | - return _ctx.scale(x, y || x); |
| 729 | + _ctx.scale(x, y || x); |
726 | 730 | }, |
727 | 731 | /** |
728 | 732 | * Adds a rotation to the transformation matrix. |
729 | 733 | * |
730 | 734 | * @param {number} radians |
731 | 735 | */ |
732 | | - rotate: (radians) => { |
| 736 | + rotate(radians) { |
733 | 737 | DEV: assert(isNumber(radians), "[litecanvas] rotate() 1st param must be a number"); |
734 | | - return _ctx.rotate(radians); |
| 738 | + _ctx.rotate(radians); |
735 | 739 | }, |
736 | 740 | /** |
737 | 741 | * Sets the alpha (opacity) value to apply when drawing new shapes and images |
|
956 | 960 | /** |
957 | 961 | * Returns information about that engine instance. |
958 | 962 | * |
959 | | - * @param {number} n |
| 963 | + * @param {number|string} index |
960 | 964 | * @returns {any} |
961 | 965 | */ |
962 | | - stat(n) { |
963 | | - DEV: assert(isNumber(n) && n >= 0, "[litecanvas] stat() 1st param must be a number"); |
964 | | - const list = [ |
| 966 | + stat(index) { |
| 967 | + DEV: assert( |
| 968 | + isNumber(index) || "string" === typeof index, |
| 969 | + "[litecanvas] stat() 1st param must be a number or string" |
| 970 | + ); |
| 971 | + const internals = [ |
965 | 972 | // 0 |
966 | 973 | settings, |
967 | 974 | // 1 |
|
987 | 994 | // 11 |
988 | 995 | _fontFamily |
989 | 996 | ]; |
990 | | - const data = { index: n, value: list[n] }; |
| 997 | + const data = { index, value: internals[index] }; |
991 | 998 | instance.emit("stat", data); |
992 | 999 | return data.value; |
993 | 1000 | }, |
|
0 commit comments