melonjs 14.0.1 → 14.1.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.
Files changed (214) hide show
  1. package/README.md +2 -0
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +10 -0
  3. package/dist/melonjs.mjs/_virtual/arraymultimap.js +10 -0
  4. package/dist/melonjs.mjs/_virtual/earcut.js +10 -0
  5. package/dist/melonjs.mjs/_virtual/howler.js +10 -0
  6. package/dist/melonjs.mjs/_virtual/index.js +10 -0
  7. package/dist/melonjs.mjs/_virtual/index2.js +10 -0
  8. package/dist/melonjs.mjs/_virtual/multimap.js +10 -0
  9. package/dist/melonjs.mjs/_virtual/setmultimap.js +10 -0
  10. package/dist/melonjs.mjs/application/application.js +240 -0
  11. package/dist/melonjs.mjs/audio/audio.js +536 -0
  12. package/dist/melonjs.mjs/camera/camera2d.js +732 -0
  13. package/dist/melonjs.mjs/entity/entity.js +248 -0
  14. package/dist/melonjs.mjs/game.js +29 -0
  15. package/dist/melonjs.mjs/geometries/ellipse.js +275 -0
  16. package/dist/melonjs.mjs/geometries/line.js +116 -0
  17. package/dist/melonjs.mjs/geometries/path2d.js +319 -0
  18. package/dist/melonjs.mjs/geometries/point.js +89 -0
  19. package/dist/melonjs.mjs/geometries/poly.js +500 -0
  20. package/dist/melonjs.mjs/geometries/rectangle.js +375 -0
  21. package/dist/melonjs.mjs/geometries/roundrect.js +168 -0
  22. package/dist/melonjs.mjs/index.js +248 -0
  23. package/dist/melonjs.mjs/input/gamepad.js +501 -0
  24. package/dist/melonjs.mjs/input/input.js +26 -0
  25. package/dist/melonjs.mjs/input/keyboard.js +470 -0
  26. package/dist/melonjs.mjs/input/pointer.js +393 -0
  27. package/dist/melonjs.mjs/input/pointerevent.js +818 -0
  28. package/dist/melonjs.mjs/lang/deprecated.js +157 -0
  29. package/dist/melonjs.mjs/level/level.js +297 -0
  30. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +141 -0
  31. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +448 -0
  32. package/dist/melonjs.mjs/level/tiled/TMXObject.js +355 -0
  33. package/dist/melonjs.mjs/level/tiled/TMXTile.js +194 -0
  34. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +639 -0
  35. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +311 -0
  36. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +83 -0
  37. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +367 -0
  38. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +506 -0
  39. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +220 -0
  40. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +157 -0
  41. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +125 -0
  42. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +109 -0
  43. package/dist/melonjs.mjs/loader/loader.js +801 -0
  44. package/dist/melonjs.mjs/loader/loadingscreen.js +120 -0
  45. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +11 -0
  46. package/dist/melonjs.mjs/math/color.js +618 -0
  47. package/dist/melonjs.mjs/math/math.js +218 -0
  48. package/dist/melonjs.mjs/math/matrix2.js +503 -0
  49. package/dist/melonjs.mjs/math/matrix3.js +681 -0
  50. package/dist/melonjs.mjs/math/observable_vector2.js +471 -0
  51. package/dist/melonjs.mjs/math/observable_vector3.js +561 -0
  52. package/dist/melonjs.mjs/math/vector2.js +528 -0
  53. package/dist/melonjs.mjs/math/vector3.js +569 -0
  54. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +73 -0
  55. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +21 -0
  56. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +324 -0
  57. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +69 -0
  58. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +691 -0
  59. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +350 -0
  60. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +3241 -0
  61. package/dist/melonjs.mjs/particles/emitter.js +267 -0
  62. package/dist/melonjs.mjs/particles/particle.js +188 -0
  63. package/dist/melonjs.mjs/particles/settings.js +319 -0
  64. package/dist/melonjs.mjs/physics/body.js +704 -0
  65. package/dist/melonjs.mjs/physics/bounds.js +460 -0
  66. package/dist/melonjs.mjs/physics/collision.js +132 -0
  67. package/dist/melonjs.mjs/physics/detector.js +194 -0
  68. package/dist/melonjs.mjs/physics/quadtree.js +391 -0
  69. package/dist/melonjs.mjs/physics/response.js +57 -0
  70. package/dist/melonjs.mjs/physics/sat.js +483 -0
  71. package/dist/melonjs.mjs/physics/world.js +221 -0
  72. package/dist/melonjs.mjs/plugin/plugin.js +141 -0
  73. package/dist/melonjs.mjs/renderable/collectable.js +62 -0
  74. package/dist/melonjs.mjs/renderable/colorlayer.js +80 -0
  75. package/dist/melonjs.mjs/renderable/container.js +1018 -0
  76. package/dist/melonjs.mjs/renderable/dragndrop.js +224 -0
  77. package/dist/melonjs.mjs/renderable/imagelayer.js +306 -0
  78. package/dist/melonjs.mjs/renderable/light2d.js +156 -0
  79. package/dist/melonjs.mjs/renderable/nineslicesprite.js +247 -0
  80. package/dist/melonjs.mjs/renderable/renderable.js +783 -0
  81. package/dist/melonjs.mjs/renderable/sprite.js +654 -0
  82. package/dist/melonjs.mjs/renderable/trigger.js +157 -0
  83. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +213 -0
  84. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +226 -0
  85. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +128 -0
  86. package/dist/melonjs.mjs/state/stage.js +237 -0
  87. package/dist/melonjs.mjs/state/state.js +596 -0
  88. package/dist/melonjs.mjs/system/device.js +909 -0
  89. package/dist/melonjs.mjs/system/dom.js +78 -0
  90. package/dist/melonjs.mjs/system/event.js +537 -0
  91. package/dist/melonjs.mjs/system/platform.js +41 -0
  92. package/dist/melonjs.mjs/system/pooling.js +209 -0
  93. package/dist/melonjs.mjs/system/save.js +157 -0
  94. package/dist/melonjs.mjs/system/timer.js +286 -0
  95. package/dist/melonjs.mjs/text/bitmaptext.js +364 -0
  96. package/dist/melonjs.mjs/text/bitmaptextdata.js +199 -0
  97. package/dist/melonjs.mjs/text/glyph.js +66 -0
  98. package/dist/melonjs.mjs/text/text.js +453 -0
  99. package/dist/melonjs.mjs/text/textmetrics.js +176 -0
  100. package/dist/melonjs.mjs/text/textstyle.js +23 -0
  101. package/dist/melonjs.mjs/tweens/easing.js +336 -0
  102. package/dist/melonjs.mjs/tweens/interpolation.js +112 -0
  103. package/dist/melonjs.mjs/tweens/tween.js +480 -0
  104. package/dist/melonjs.mjs/utils/agent.js +76 -0
  105. package/dist/melonjs.mjs/utils/array.js +63 -0
  106. package/dist/melonjs.mjs/utils/file.js +42 -0
  107. package/dist/melonjs.mjs/utils/function.js +70 -0
  108. package/dist/melonjs.mjs/utils/string.js +82 -0
  109. package/dist/melonjs.mjs/utils/utils.js +173 -0
  110. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +807 -0
  111. package/dist/melonjs.mjs/video/renderer.js +411 -0
  112. package/dist/melonjs.mjs/video/texture/atlas.js +519 -0
  113. package/dist/melonjs.mjs/video/texture/cache.js +143 -0
  114. package/dist/melonjs.mjs/video/texture/canvas_texture.js +144 -0
  115. package/dist/melonjs.mjs/video/video.js +462 -0
  116. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +143 -0
  117. package/dist/melonjs.mjs/video/webgl/glshader.js +168 -0
  118. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +10 -0
  119. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +10 -0
  120. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +10 -0
  121. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +10 -0
  122. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +25 -0
  123. package/dist/melonjs.mjs/video/webgl/utils/precision.js +20 -0
  124. package/dist/melonjs.mjs/video/webgl/utils/program.js +67 -0
  125. package/dist/melonjs.mjs/video/webgl/utils/string.js +25 -0
  126. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +92 -0
  127. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +495 -0
  128. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +1036 -0
  129. package/dist/melonjs.module.d.ts +1163 -1163
  130. package/dist/melonjs.module.js +1903 -3274
  131. package/package.json +22 -17
  132. package/src/application/application.js +3 -3
  133. package/src/audio/audio.js +32 -32
  134. package/src/camera/camera2d.js +31 -31
  135. package/src/entity/entity.js +17 -17
  136. package/src/geometries/ellipse.js +16 -16
  137. package/src/geometries/line.js +5 -5
  138. package/src/geometries/path2d.js +32 -32
  139. package/src/geometries/poly.js +15 -15
  140. package/src/geometries/rectangle.js +18 -18
  141. package/src/geometries/roundrect.js +8 -8
  142. package/src/input/gamepad.js +15 -15
  143. package/src/input/keyboard.js +12 -12
  144. package/src/input/pointer.js +6 -6
  145. package/src/input/pointerevent.js +12 -12
  146. package/src/lang/deprecated.js +12 -12
  147. package/src/level/level.js +25 -25
  148. package/src/level/tiled/TMXLayer.js +22 -22
  149. package/src/level/tiled/TMXTile.js +5 -5
  150. package/src/level/tiled/TMXTileMap.js +6 -6
  151. package/src/level/tiled/TMXTileset.js +2 -2
  152. package/src/level/tiled/TMXUtils.js +5 -5
  153. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
  154. package/src/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
  155. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  156. package/src/level/tiled/renderer/TMXRenderer.js +19 -19
  157. package/src/loader/loader.js +20 -20
  158. package/src/math/color.js +20 -20
  159. package/src/math/math.js +16 -16
  160. package/src/math/matrix2.js +16 -16
  161. package/src/math/matrix3.js +25 -25
  162. package/src/math/observable_vector2.js +14 -14
  163. package/src/math/observable_vector3.js +16 -16
  164. package/src/math/vector2.js +9 -9
  165. package/src/math/vector3.js +10 -10
  166. package/src/particles/emitter.js +6 -6
  167. package/src/particles/particle.js +2 -2
  168. package/src/physics/body.js +28 -28
  169. package/src/physics/bounds.js +8 -8
  170. package/src/physics/collision.js +2 -2
  171. package/src/physics/detector.js +6 -6
  172. package/src/physics/quadtree.js +11 -11
  173. package/src/physics/sat.js +31 -31
  174. package/src/physics/world.js +5 -5
  175. package/src/plugin/plugin.js +5 -5
  176. package/src/renderable/collectable.js +3 -3
  177. package/src/renderable/colorlayer.js +5 -5
  178. package/src/renderable/container.js +21 -21
  179. package/src/renderable/dragndrop.js +14 -14
  180. package/src/renderable/imagelayer.js +13 -13
  181. package/src/renderable/light2d.js +3 -3
  182. package/src/renderable/nineslicesprite.js +16 -16
  183. package/src/renderable/renderable.js +23 -23
  184. package/src/renderable/sprite.js +28 -28
  185. package/src/renderable/trigger.js +15 -15
  186. package/src/renderable/ui/uibaseelement.js +7 -7
  187. package/src/renderable/ui/uispriteelement.js +6 -6
  188. package/src/renderable/ui/uitextbutton.js +13 -13
  189. package/src/state/stage.js +7 -7
  190. package/src/state/state.js +17 -17
  191. package/src/system/device.js +11 -11
  192. package/src/system/event.js +10 -10
  193. package/src/system/pooling.js +9 -9
  194. package/src/system/save.js +2 -2
  195. package/src/system/timer.js +10 -10
  196. package/src/text/bitmaptext.js +18 -18
  197. package/src/text/bitmaptextdata.js +2 -2
  198. package/src/text/text.js +23 -23
  199. package/src/text/textmetrics.js +8 -8
  200. package/src/tweens/tween.js +19 -19
  201. package/src/utils/agent.js +5 -5
  202. package/src/utils/array.js +4 -4
  203. package/src/utils/file.js +2 -2
  204. package/src/utils/function.js +6 -6
  205. package/src/utils/string.js +5 -5
  206. package/src/utils/utils.js +4 -4
  207. package/src/video/canvas/canvas_renderer.js +70 -70
  208. package/src/video/renderer.js +26 -26
  209. package/src/video/texture/atlas.js +22 -22
  210. package/src/video/texture/canvas_texture.js +9 -9
  211. package/src/video/video.js +17 -17
  212. package/src/video/webgl/glshader.js +10 -10
  213. package/src/video/webgl/webgl_compositor.js +41 -41
  214. package/src/video/webgl/webgl_renderer.js +75 -75
@@ -0,0 +1,411 @@
1
+ /*!
2
+ * melonJS Game Engine - v14.1.0
3
+ * http://www.melonjs.org
4
+ * melonjs is licensed under the MIT License.
5
+ * http://www.opensource.org/licenses/mit-license
6
+ * @copyright (C) 2011 - 2022 Olivier Biot (AltByte Pte Ltd)
7
+ */
8
+ import Color from '../math/color.js';
9
+ import Matrix3d from '../math/matrix3.js';
10
+ import { createCanvas, renderer } from './video.js';
11
+ import { on, GAME_RESET, emit, CANVAS_ONRESIZE } from '../system/event.js';
12
+ import { platform } from '../system/device.js';
13
+ import { setPrefixed } from '../utils/agent.js';
14
+ import Rect from '../geometries/rectangle.js';
15
+ import RoundRect from '../geometries/roundrect.js';
16
+ import Ellipse from '../geometries/ellipse.js';
17
+ import Polygon from '../geometries/poly.js';
18
+ import Line from '../geometries/line.js';
19
+ import Bounds from '../physics/bounds.js';
20
+ import Path2D from '../geometries/path2d.js';
21
+ import Point from '../geometries/point.js';
22
+
23
+ /**
24
+ * @classdesc
25
+ * a base renderer object
26
+ */
27
+ class Renderer {
28
+ /**
29
+ * @param {object} options - The renderer parameters
30
+ * @param {number} options.width - The width of the canvas without scaling
31
+ * @param {number} options.height - The height of the canvas without scaling
32
+ * @param {HTMLCanvasElement} [options.canvas] - The html canvas to draw to on screen
33
+ * @param {boolean} [options.antiAlias=false] - Whether to enable anti-aliasing, use false (default) for a pixelated effect.
34
+ * @param {boolean} [options.failIfMajorPerformanceCaveat=true] - If true, the renderer will switch to CANVAS mode if the performances of a WebGL context would be dramatically lower than that of a native application making equivalent OpenGL calls.
35
+ * @param {boolean} [options.transparent=false] - Whether to enable transparency on the canvas
36
+ * @param {boolean} [options.premultipliedAlpha=true] - in WebGL, whether the renderer will assume that colors have premultiplied alpha when canvas transparency is enabled
37
+ * @param {boolean} [options.blendMode="normal"] - the default blend mode to use ("normal", "multiply")
38
+ * @param {boolean} [options.subPixel=false] - Whether to enable subpixel rendering (performance hit when enabled)
39
+ * @param {boolean} [options.verbose=false] - Enable the verbose mode that provides additional details as to what the renderer is doing
40
+ * @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
41
+ * @param {number} [options.zoomY=height] - The actual height of the canvas with scaling applied
42
+ */
43
+ constructor(options) {
44
+ /**
45
+ * The given constructor options
46
+ * @public
47
+ * @type {object}
48
+ */
49
+ this.settings = options;
50
+
51
+ /**
52
+ * true if the current rendering context is valid
53
+ * @default true
54
+ * @type {boolean}
55
+ */
56
+ this.isContextValid = true;
57
+
58
+ /**
59
+ * The Path2D instance used by the renderer to draw primitives
60
+ * @type {Path2D}
61
+ */
62
+ this.path2D = new Path2D();
63
+
64
+ /**
65
+ * @ignore
66
+ */
67
+ this.currentScissor = new Int32Array([ 0, 0, this.settings.width, this.settings.height ]);
68
+
69
+ /**
70
+ * @ignore
71
+ */
72
+ this.maskLevel = 0;
73
+
74
+ /**
75
+ * @ignore
76
+ */
77
+ this.currentBlendMode = "none";
78
+
79
+ // create the main screen canvas
80
+ if (platform.ejecta === true) {
81
+ // a main canvas is already automatically created by Ejecta
82
+ this.canvas = document.getElementById("canvas");
83
+ } else if (typeof globalThis.canvas !== "undefined") {
84
+ // a global canvas is available, e.g. webapp adapter for wechat
85
+ this.canvas = globalThis.canvas;
86
+ } else if (typeof this.settings.canvas !== "undefined") {
87
+ this.canvas = this.settings.canvas;
88
+ } else {
89
+ this.canvas = createCanvas(this.settings.width, this.settings.height);
90
+ }
91
+
92
+ // global color
93
+ this.currentColor = new Color(0, 0, 0, 1.0);
94
+
95
+ // global tint color
96
+ this.currentTint = new Color(255, 255, 255, 1.0);
97
+
98
+ // the projectionMatrix (set through setProjection)
99
+ this.projectionMatrix = new Matrix3d();
100
+
101
+ // default uvOffset
102
+ this.uvOffset = 0;
103
+
104
+ // reset the instantiated renderer on game reset
105
+ on(GAME_RESET, () => {
106
+ renderer.reset();
107
+ });
108
+ }
109
+
110
+ /**
111
+ * prepare the framebuffer for drawing a new frame
112
+ */
113
+ clear() {}
114
+
115
+ /**
116
+ * render the main framebuffer on screen
117
+ */
118
+ flush() {}
119
+
120
+ /**
121
+ * Reset context state
122
+ */
123
+ reset() {
124
+ this.resetTransform();
125
+ this.setBlendMode(this.settings.blendMode);
126
+ this.setColor("#000000");
127
+ this.clearTint();
128
+ this.cache.clear();
129
+ this.currentScissor[0] = 0;
130
+ this.currentScissor[1] = 0;
131
+ this.currentScissor[2] = this.getCanvas().width;
132
+ this.currentScissor[3] = this.getCanvas().height;
133
+ this.clearMask();
134
+ }
135
+
136
+ /**
137
+ * return a reference to the canvas which this renderer draws to
138
+ * @returns {HTMLCanvasElement}
139
+ */
140
+ getCanvas() {
141
+ return this.canvas;
142
+ }
143
+
144
+
145
+ /**
146
+ * return a reference to this renderer canvas corresponding Context
147
+ * @returns {CanvasRenderingContext2D|WebGLRenderingContext}
148
+ */
149
+ getContext() {
150
+ return this.context;
151
+ }
152
+
153
+ /**
154
+ * returns the current blend mode for this renderer
155
+ * @returns {string} blend mode
156
+ */
157
+ getBlendMode() {
158
+ return this.currentBlendMode;
159
+ }
160
+
161
+ /**
162
+ * Returns the 2D Context object of the given Canvas<br>
163
+ * Also configures anti-aliasing and blend modes based on constructor options.
164
+ * @param {HTMLCanvasElement} canvas
165
+ * @param {boolean} [transparent=true] - use false to disable transparency
166
+ * @returns {CanvasRenderingContext2D}
167
+ */
168
+ getContext2d(canvas, transparent) {
169
+ if (typeof canvas === "undefined" || canvas === null) {
170
+ throw new Error(
171
+ "You must pass a canvas element in order to create " +
172
+ "a 2d context"
173
+ );
174
+ }
175
+
176
+ if (typeof canvas.getContext === "undefined") {
177
+ throw new Error(
178
+ "Your browser does not support HTML5 canvas."
179
+ );
180
+ }
181
+
182
+ if (typeof transparent !== "boolean") {
183
+ transparent = true;
184
+ }
185
+
186
+ var _context = canvas.getContext("2d", {
187
+ "alpha" : transparent
188
+ });
189
+
190
+ if (!_context.canvas) {
191
+ _context.canvas = canvas;
192
+ }
193
+ this.setAntiAlias(_context, this.settings.antiAlias);
194
+ return _context;
195
+ }
196
+
197
+ /**
198
+ * return the width of the system Canvas
199
+ * @returns {number}
200
+ */
201
+ getWidth() {
202
+ return this.getCanvas().width;
203
+ }
204
+
205
+ /**
206
+ * return the height of the system Canvas
207
+ * @returns {number} height of the system Canvas
208
+ */
209
+ getHeight() {
210
+ return this.getCanvas().height;
211
+ }
212
+
213
+ /**
214
+ * get the current fill & stroke style color.
215
+ * @returns {Color} current global color
216
+ */
217
+ getColor() {
218
+ return this.currentColor;
219
+ }
220
+
221
+ /**
222
+ * return the current global alpha
223
+ * @returns {number}
224
+ */
225
+ globalAlpha() {
226
+ return this.currentColor.glArray[3];
227
+ }
228
+
229
+ /**
230
+ * check if the given rect or bounds overlaps with the renderer screen coordinates
231
+ * @param {Rect|Bounds} bounds
232
+ * @returns {boolean} true if overlaps
233
+ */
234
+ overlaps(bounds) {
235
+ return (
236
+ bounds.left <= this.getWidth() && bounds.right >= 0 &&
237
+ bounds.top <= this.getHeight() && bounds.bottom >= 0
238
+ );
239
+ }
240
+
241
+
242
+ /**
243
+ * resizes the system canvas
244
+ * @param {number} width - new width of the canvas
245
+ * @param {number} height - new height of the canvas
246
+ */
247
+ resize(width, height) {
248
+ var canvas = this.getCanvas();
249
+ if (width !== canvas.width || height !== canvas.height) {
250
+ canvas.width = width;
251
+ canvas.height = height;
252
+ this.currentScissor[0] = 0;
253
+ this.currentScissor[1] = 0;
254
+ this.currentScissor[2] = width;
255
+ this.currentScissor[3] = height;
256
+ // publish the corresponding event
257
+ emit(CANVAS_ONRESIZE, width, height);
258
+ }
259
+ }
260
+
261
+ /**
262
+ * enable/disable image smoothing (scaling interpolation) for the given context
263
+ * @param {CanvasRenderingContext2D} context
264
+ * @param {boolean} [enable=false]
265
+ */
266
+ setAntiAlias(context, enable) {
267
+ var canvas = context.canvas;
268
+
269
+ // enable/disable antialis on the given Context2d object
270
+ setPrefixed("imageSmoothingEnabled", enable === true, context);
271
+
272
+ // set antialias CSS property on the main canvas
273
+ if (enable !== true) {
274
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering
275
+ canvas.style["image-rendering"] = "optimizeSpeed"; // legal fallback
276
+ canvas.style["image-rendering"] = "-moz-crisp-edges"; // Firefox
277
+ canvas.style["image-rendering"] = "-o-crisp-edges"; // Opera
278
+ canvas.style["image-rendering"] = "-webkit-optimize-contrast"; // Safari
279
+ canvas.style["image-rendering"] = "optimize-contrast"; // CSS 3
280
+ canvas.style["image-rendering"] = "crisp-edges"; // CSS 4
281
+ canvas.style["image-rendering"] = "pixelated"; // CSS 4
282
+ canvas.style.msInterpolationMode = "nearest-neighbor"; // IE8+
283
+ } else {
284
+ canvas.style["image-rendering"] = "auto";
285
+ }
286
+ }
287
+
288
+ /**
289
+ * set/change the current projection matrix (WebGL only)
290
+ * @param {Matrix3d} matrix
291
+ */
292
+ setProjection(matrix) {
293
+ this.projectionMatrix.copy(matrix);
294
+ }
295
+
296
+ /**
297
+ * stroke the given shape
298
+ * @param {Rect|RoundRect|Polygon|Line|Ellipse} shape - a shape object to stroke
299
+ * @param {boolean} [fill=false] - fill the shape with the current color if true
300
+ */
301
+ stroke(shape, fill) {
302
+ if (shape instanceof RoundRect) {
303
+ this.strokeRoundRect(shape.left, shape.top, shape.width, shape.height, shape.radius, fill);
304
+ return;
305
+ }
306
+ if (shape instanceof Rect || shape instanceof Bounds) {
307
+ this.strokeRect(shape.left, shape.top, shape.width, shape.height, fill);
308
+ return;
309
+ }
310
+ if (shape instanceof Line || shape instanceof Polygon) {
311
+ this.strokePolygon(shape, fill);
312
+ return;
313
+ }
314
+ if (shape instanceof Ellipse) {
315
+ this.strokeEllipse(
316
+ shape.pos.x,
317
+ shape.pos.y,
318
+ shape.radiusV.x,
319
+ shape.radiusV.y,
320
+ fill
321
+ );
322
+ return;
323
+ }
324
+ if (shape instanceof Point) {
325
+ this.strokePoint(shape.x, shape.y);
326
+ return;
327
+ }
328
+ throw new Error("Invalid geometry for fill/stroke");
329
+ }
330
+
331
+ /**
332
+ * fill the given shape
333
+ * @name fill
334
+ * @memberof Renderer
335
+ * @param {Rect|RoundRect|Polygon|Line|Ellipse} shape - a shape object to fill
336
+ */
337
+ fill(shape) {
338
+ this.stroke(shape, true);
339
+ }
340
+
341
+ /**
342
+ * tint the given image or canvas using the given color
343
+ * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} src - the source image to be tinted
344
+ * @param {Color|string} color - the color that will be used to tint the image
345
+ * @param {string} [mode="multiply"] - the composition mode used to tint the image
346
+ * @returns {HTMLCanvasElement|OffscreenCanvas} a new canvas element representing the tinted image
347
+ */
348
+ tint(src, color, mode) {
349
+ var canvas = createCanvas(src.width, src.height, true);
350
+ var context = this.getContext2d(canvas);
351
+
352
+ context.save();
353
+
354
+ context.fillStyle = color instanceof Color ? color.toRGB() : color;
355
+ context.fillRect(0, 0, src.width, src.height);
356
+
357
+ context.globalCompositeOperation = mode || "multiply";
358
+ context.drawImage(src, 0, 0);
359
+ context.globalCompositeOperation = "destination-atop";
360
+ context.drawImage(src, 0, 0);
361
+
362
+ context.restore();
363
+
364
+ return canvas;
365
+ }
366
+
367
+ /**
368
+ * A mask limits rendering elements to the shape and position of the given mask object.
369
+ * So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
370
+ * Mask are not preserved through renderer context save and restore.
371
+ * @param {Rect|RoundRect|Polygon|Line|Ellipse} [mask] - the shape defining the mask to be applied
372
+ * @param {boolean} [invert=false] - either the given shape should define what is visible (default) or the opposite
373
+ */
374
+ // eslint-disable-next-line no-unused-vars
375
+ setMask(mask) {}
376
+
377
+ /**
378
+ * disable (remove) the rendering mask set through setMask.
379
+ * @see Renderer#setMask
380
+ */
381
+ clearMask() {}
382
+
383
+ /**
384
+ * set a coloring tint for sprite based renderables
385
+ * @param {Color} tint - the tint color
386
+ * @param {number} [alpha] - an alpha value to be applied to the tint
387
+ */
388
+ setTint(tint, alpha = tint.alpha) {
389
+ // global tint color
390
+ this.currentTint.copy(tint);
391
+ this.currentTint.alpha *= alpha;
392
+ }
393
+
394
+ /**
395
+ * clear the rendering tint set through setTint.
396
+ * @see Renderer#setTint
397
+ */
398
+ clearTint() {
399
+ // reset to default
400
+ this.currentTint.setColor(255, 255, 255, 1.0);
401
+ }
402
+
403
+ /**
404
+ * @ignore
405
+ */
406
+ drawFont(/*bounds*/) {}
407
+
408
+ }
409
+ var Renderer$1 = Renderer;
410
+
411
+ export { Renderer$1 as default };