@vpmedia/phaser 1.114.0 → 1.115.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/index.js +400 -377
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts +2 -1
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/array_set.d.ts +1 -1
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/cache.d.ts +1 -1
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts +1 -1
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/game.d.ts +2 -0
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +5 -5
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_event.d.ts +35 -0
- package/dist/phaser/core/input_event.d.ts.map +1 -0
- package/dist/phaser/core/input_handler.d.ts +2 -2
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts +27 -26
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_mspointer.d.ts +16 -15
- package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +9 -8
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts +18 -17
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +64 -30
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/scale_manager.d.ts +1 -1
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts +14 -4
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts +8 -8
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/signal_binding.d.ts +2 -2
- package/dist/phaser/core/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +1 -1
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +3 -3
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts +1 -1
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- package/dist/phaser/core/timer.d.ts +5 -5
- package/dist/phaser/core/timer.d.ts.map +1 -1
- package/dist/phaser/core/timer_event.d.ts +2 -2
- package/dist/phaser/core/timer_event.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +4 -4
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +2 -1
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts +1 -1
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +1 -1
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts +3 -3
- package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/graphics.d.ts +2 -2
- package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
- package/dist/phaser/display/canvas/masker.d.ts +5 -2
- package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts +6 -5
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/tinter.d.ts +2 -1
- package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
- package/dist/phaser/display/canvas/util.d.ts +11 -4
- package/dist/phaser/display/canvas/util.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts +4 -3
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +47 -27
- package/dist/phaser/display/graphics.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data.d.ts +20 -11
- package/dist/phaser/display/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts +4 -3
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/render_session.d.ts +44 -0
- package/dist/phaser/display/render_session.d.ts.map +1 -0
- package/dist/phaser/display/sprite_util.d.ts +4 -3
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +64 -30
- package/dist/phaser/display/text.d.ts.map +1 -1
- package/dist/phaser/display/webgl/base_texture.d.ts +3 -3
- package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts +25 -25
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut_node.d.ts +2 -2
- package/dist/phaser/display/webgl/earcut_node.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +3 -2
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +2 -1
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts +9 -9
- package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/webgl/mask_manager.d.ts +3 -2
- package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts +3 -3
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +5 -4
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts +3 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader_manager.d.ts +10 -4
- package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts +4 -3
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts +4 -3
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts +6 -6
- package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/phaser/core/animation_manager.ts +2 -2
- package/src/phaser/core/array_set.ts +1 -1
- package/src/phaser/core/cache.ts +1 -1
- package/src/phaser/core/factory.ts +1 -1
- package/src/phaser/core/game.ts +2 -0
- package/src/phaser/core/input.ts +7 -6
- package/src/phaser/core/input_event.ts +34 -0
- package/src/phaser/core/input_handler.ts +2 -11
- package/src/phaser/core/input_mouse.ts +53 -36
- package/src/phaser/core/input_mspointer.ts +54 -29
- package/src/phaser/core/input_pointer.test.ts +149 -0
- package/src/phaser/core/input_pointer.ts +20 -21
- package/src/phaser/core/input_touch.ts +48 -31
- package/src/phaser/core/loader.test.ts +139 -0
- package/src/phaser/core/loader.ts +146 -83
- package/src/phaser/core/scale_manager.ts +1 -1
- package/src/phaser/core/scene_manager.ts +16 -8
- package/src/phaser/core/signal.ts +8 -8
- package/src/phaser/core/signal_binding.ts +2 -2
- package/src/phaser/core/sound.ts +4 -4
- package/src/phaser/core/sound_manager.ts +17 -19
- package/src/phaser/core/sound_sprite.ts +2 -2
- package/src/phaser/core/timer.ts +6 -6
- package/src/phaser/core/timer_event.ts +2 -2
- package/src/phaser/core/tween.ts +6 -6
- package/src/phaser/core/tween_data.ts +2 -1
- package/src/phaser/core/tween_manager.ts +1 -1
- package/src/phaser/display/button.ts +1 -1
- package/src/phaser/display/canvas/buffer.ts +3 -3
- package/src/phaser/display/canvas/graphics.ts +24 -20
- package/src/phaser/display/canvas/masker.ts +5 -2
- package/src/phaser/display/canvas/renderer.ts +10 -11
- package/src/phaser/display/canvas/tinter.ts +4 -3
- package/src/phaser/display/canvas/util.ts +15 -5
- package/src/phaser/display/display_object.ts +6 -5
- package/src/phaser/display/graphics.test.ts +122 -0
- package/src/phaser/display/graphics.ts +73 -64
- package/src/phaser/display/graphics_data.ts +22 -12
- package/src/phaser/display/image.ts +4 -3
- package/src/phaser/display/render_session.ts +45 -0
- package/src/phaser/display/sprite_util.ts +10 -8
- package/src/phaser/display/text.test.ts +27 -1
- package/src/phaser/display/text.ts +181 -117
- package/src/phaser/display/webgl/base_texture.ts +3 -3
- package/src/phaser/display/webgl/earcut.test.ts +132 -0
- package/src/phaser/display/webgl/earcut.ts +84 -74
- package/src/phaser/display/webgl/earcut_node.ts +5 -5
- package/src/phaser/display/webgl/fast_sprite_batch.ts +4 -4
- package/src/phaser/display/webgl/filter_manager.ts +1 -1
- package/src/phaser/display/webgl/graphics.ts +26 -17
- package/src/phaser/display/webgl/graphics_data.ts +9 -9
- package/src/phaser/display/webgl/mask_manager.ts +3 -2
- package/src/phaser/display/webgl/render_texture.ts +3 -3
- package/src/phaser/display/webgl/renderer.ts +7 -6
- package/src/phaser/display/webgl/shader/normal.ts +23 -6
- package/src/phaser/display/webgl/shader_manager.ts +15 -6
- package/src/phaser/display/webgl/sprite_batch.ts +4 -3
- package/src/phaser/display/webgl/stencil_manager.ts +10 -3
- package/src/phaser/display/webgl/texture.ts +6 -6
|
@@ -5,7 +5,7 @@ export class SignalBinding {
|
|
|
5
5
|
public _args: any;
|
|
6
6
|
public _priority: number;
|
|
7
7
|
public _isOnce: boolean;
|
|
8
|
-
public context:
|
|
8
|
+
public context: unknown;
|
|
9
9
|
public callCount: number;
|
|
10
10
|
public active: boolean;
|
|
11
11
|
public params: any;
|
|
@@ -23,7 +23,7 @@ export class SignalBinding {
|
|
|
23
23
|
signal: Signal,
|
|
24
24
|
listener: Function,
|
|
25
25
|
isOnce = false,
|
|
26
|
-
listenerContext:
|
|
26
|
+
listenerContext: unknown | null = null,
|
|
27
27
|
priority = 0,
|
|
28
28
|
args: any = null
|
|
29
29
|
) {
|
package/src/phaser/core/sound.ts
CHANGED
|
@@ -9,7 +9,7 @@ export class Sound {
|
|
|
9
9
|
public key!: string;
|
|
10
10
|
public loop!: boolean;
|
|
11
11
|
public markers!: any;
|
|
12
|
-
public context!: AudioContext;
|
|
12
|
+
public context!: AudioContext | null;
|
|
13
13
|
public autoplay!: boolean;
|
|
14
14
|
public totalDuration!: number;
|
|
15
15
|
public startTime!: number;
|
|
@@ -91,7 +91,7 @@ export class Sound {
|
|
|
91
91
|
this.context = this.game.sound.context;
|
|
92
92
|
this.masterGainNode = this.game.sound.masterGain;
|
|
93
93
|
const gainNode: GainNode =
|
|
94
|
-
this.context
|
|
94
|
+
this.context!.createGain === undefined ? (this.context as any).createGainNode() : this.context!.createGain();
|
|
95
95
|
this.gainNode = gainNode;
|
|
96
96
|
gainNode.gain.value = volume * this.game.sound.volume;
|
|
97
97
|
if (connect && this.masterGainNode) {
|
|
@@ -317,7 +317,7 @@ export class Sound {
|
|
|
317
317
|
}
|
|
318
318
|
// Does the sound need decoding?
|
|
319
319
|
if (this.game.cache.isSoundDecoded(this.key)) {
|
|
320
|
-
this._sound = this.context
|
|
320
|
+
this._sound = this.context!.createBufferSource();
|
|
321
321
|
if (this.externalNode) {
|
|
322
322
|
this._sound.connect(this.externalNode);
|
|
323
323
|
} else {
|
|
@@ -389,7 +389,7 @@ export class Sound {
|
|
|
389
389
|
public resume() {
|
|
390
390
|
if (this.paused && this._sound) {
|
|
391
391
|
const p = Math.max(0, this.position + this.pausedPosition / 1000);
|
|
392
|
-
this._sound = this.context
|
|
392
|
+
this._sound = this.context!.createBufferSource();
|
|
393
393
|
this._sound.buffer = this._buffer;
|
|
394
394
|
if (this.externalNode) {
|
|
395
395
|
this._sound.connect(this.externalNode);
|
|
@@ -13,9 +13,9 @@ import { Sound } from './sound.js';
|
|
|
13
13
|
import { SoundSprite } from './sound_sprite.js';
|
|
14
14
|
|
|
15
15
|
export class SoundManager {
|
|
16
|
-
public game!:
|
|
16
|
+
public game!: Game;
|
|
17
17
|
public onChange!: any;
|
|
18
|
-
public context!:
|
|
18
|
+
public context!: AudioContext | null;
|
|
19
19
|
public baseLatency!: any;
|
|
20
20
|
public noAudio!: any;
|
|
21
21
|
public type!: any;
|
|
@@ -102,7 +102,7 @@ export class SoundManager {
|
|
|
102
102
|
}
|
|
103
103
|
this.baseLatency = this.context.baseLatency ?? 256 / (this.context.sampleRate ?? 44_100);
|
|
104
104
|
if (this.context.createGain === undefined) {
|
|
105
|
-
this.masterGain = this.context.createGainNode();
|
|
105
|
+
this.masterGain = (this.context as unknown as { createGainNode: () => GainNode }).createGainNode();
|
|
106
106
|
} else {
|
|
107
107
|
this.masterGain = this.context.createGain();
|
|
108
108
|
}
|
|
@@ -131,7 +131,7 @@ export class SoundManager {
|
|
|
131
131
|
*/
|
|
132
132
|
public onContextStateChange = () => {
|
|
133
133
|
this.game.logger.info('onContextStateChange', {
|
|
134
|
-
state: this.context
|
|
134
|
+
state: this.context!.state,
|
|
135
135
|
isLocked: this.isLocked,
|
|
136
136
|
});
|
|
137
137
|
this.checkUnlockHandlers();
|
|
@@ -142,12 +142,12 @@ export class SoundManager {
|
|
|
142
142
|
*/
|
|
143
143
|
public checkUnlockHandlers = () => {
|
|
144
144
|
this.game.logger.info('checkUnlockHandlers', {
|
|
145
|
-
state: this.context
|
|
145
|
+
state: this.context!.state,
|
|
146
146
|
isLocked: this.isLocked,
|
|
147
147
|
});
|
|
148
|
-
if (!this.isLocked && (this.context
|
|
148
|
+
if (!this.isLocked && (this.context!.state === 'suspended' || this.context!.state === 'interrupted')) {
|
|
149
149
|
this.addUnlockHandlers();
|
|
150
|
-
} else if (this.isLocked && this.context
|
|
150
|
+
} else if (this.isLocked && this.context!.state === 'running') {
|
|
151
151
|
this.removeUnlockHandlers();
|
|
152
152
|
}
|
|
153
153
|
};
|
|
@@ -158,7 +158,7 @@ export class SoundManager {
|
|
|
158
158
|
public addUnlockHandlers = () => {
|
|
159
159
|
this.isLocked = true;
|
|
160
160
|
this.game.logger.info('addUnlockHandlers', {
|
|
161
|
-
state: this.context
|
|
161
|
+
state: this.context!.state,
|
|
162
162
|
isLocked: this.isLocked,
|
|
163
163
|
});
|
|
164
164
|
for (const eventType of ['touchend', 'click', 'keydown']) {
|
|
@@ -172,7 +172,7 @@ export class SoundManager {
|
|
|
172
172
|
public removeUnlockHandlers = () => {
|
|
173
173
|
this.isLocked = false;
|
|
174
174
|
this.game.logger.info('removeUnlockHandlers', {
|
|
175
|
-
state: this.context
|
|
175
|
+
state: this.context!.state,
|
|
176
176
|
isLocked: this.isLocked,
|
|
177
177
|
});
|
|
178
178
|
for (const eventType of ['touchend', 'click', 'keydown']) {
|
|
@@ -185,7 +185,7 @@ export class SoundManager {
|
|
|
185
185
|
* @param {Event} event - The DOM event that triggered the unlock.
|
|
186
186
|
*/
|
|
187
187
|
public onUnlockEvent = (event: Event) => {
|
|
188
|
-
const initialState = this.context
|
|
188
|
+
const initialState = this.context!.state;
|
|
189
189
|
if (initialState !== 'suspended' && initialState !== 'interrupted') {
|
|
190
190
|
this.game.logger.info('onUnlockResumeDenied', {
|
|
191
191
|
state: initialState,
|
|
@@ -200,12 +200,11 @@ export class SoundManager {
|
|
|
200
200
|
isLocked: this.isLocked,
|
|
201
201
|
event,
|
|
202
202
|
});
|
|
203
|
-
this.context
|
|
204
|
-
.resume()
|
|
203
|
+
this.context!.resume()
|
|
205
204
|
.then(() => {
|
|
206
205
|
this.game.logger.info('onContextResumeResult', {
|
|
207
206
|
initialState,
|
|
208
|
-
state: this.context
|
|
207
|
+
state: this.context!.state,
|
|
209
208
|
isLocked: this.isLocked,
|
|
210
209
|
});
|
|
211
210
|
this.removeUnlockHandlers();
|
|
@@ -213,14 +212,14 @@ export class SoundManager {
|
|
|
213
212
|
.catch((error: unknown) => {
|
|
214
213
|
this.game.logger.info('onContextResumeReject', {
|
|
215
214
|
initialState,
|
|
216
|
-
state: this.context
|
|
215
|
+
state: this.context!.state,
|
|
217
216
|
isLocked: this.isLocked,
|
|
218
217
|
error,
|
|
219
218
|
});
|
|
220
219
|
this.removeUnlockHandlers();
|
|
221
220
|
this.game.logger.fatal('SoundManager', {
|
|
222
221
|
error,
|
|
223
|
-
tags: { 'audio.initialState': initialState, 'audio.state': this.context
|
|
222
|
+
tags: { 'audio.initialState': initialState, 'audio.state': this.context!.state },
|
|
224
223
|
});
|
|
225
224
|
});
|
|
226
225
|
};
|
|
@@ -280,8 +279,7 @@ export class SoundManager {
|
|
|
280
279
|
return;
|
|
281
280
|
}
|
|
282
281
|
this.game.cache.updateSound(key, 'isDecoding', true);
|
|
283
|
-
this.context
|
|
284
|
-
.decodeAudioData(soundData)
|
|
282
|
+
this.context!.decodeAudioData(soundData)
|
|
285
283
|
.then((buffer: AudioBuffer) => {
|
|
286
284
|
this.game.cache.decodedSound(key, buffer);
|
|
287
285
|
})
|
|
@@ -304,7 +302,7 @@ export class SoundManager {
|
|
|
304
302
|
* @param {Function} callback - The callback function to call when all files are decoded.
|
|
305
303
|
* @param {object} callbackContext - The context in which to call the callback.
|
|
306
304
|
*/
|
|
307
|
-
public setDecodedCallback(files: any, callback: Function, callbackContext:
|
|
305
|
+
public setDecodedCallback(files: any, callback: Function, callbackContext: unknown) {
|
|
308
306
|
if (typeof files === 'string') {
|
|
309
307
|
files = [files];
|
|
310
308
|
}
|
|
@@ -473,7 +471,7 @@ export class SoundManager {
|
|
|
473
471
|
this._sounds = [];
|
|
474
472
|
this.onChange.dispose();
|
|
475
473
|
if (this.context?.close) {
|
|
476
|
-
this.context.close();
|
|
474
|
+
void this.context.close();
|
|
477
475
|
}
|
|
478
476
|
}
|
|
479
477
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Game } from './game.js';
|
|
2
2
|
export class SoundSprite {
|
|
3
|
-
public game!:
|
|
3
|
+
public game!: Game;
|
|
4
4
|
public key!: any;
|
|
5
5
|
public config!: any;
|
|
6
6
|
public autoplayKey!: any;
|
|
@@ -22,7 +22,7 @@ export class SoundSprite {
|
|
|
22
22
|
for (const k in this.config.spritemap) {
|
|
23
23
|
const marker = this.config.spritemap[k];
|
|
24
24
|
const sound = this.game.sound.add(this.key);
|
|
25
|
-
sound.addMarker(k, marker.start, marker.end - marker.start,
|
|
25
|
+
sound.addMarker(k, marker.start, marker.end - marker.start, undefined, marker.loop);
|
|
26
26
|
this.sounds[k] = sound;
|
|
27
27
|
}
|
|
28
28
|
if (this.config.autoplay) {
|
package/src/phaser/core/timer.ts
CHANGED
|
@@ -66,7 +66,7 @@ export class Timer {
|
|
|
66
66
|
loop: boolean,
|
|
67
67
|
repeatCount: number,
|
|
68
68
|
callback: Function,
|
|
69
|
-
callbackContext:
|
|
69
|
+
callbackContext: unknown | null = null,
|
|
70
70
|
args: any = []
|
|
71
71
|
) {
|
|
72
72
|
const roundedDelay = Math.round(delay);
|
|
@@ -91,7 +91,7 @@ export class Timer {
|
|
|
91
91
|
* @param {...any} args - Arguments to pass to the callback function.
|
|
92
92
|
* @returns {TimerEvent} The created TimerEvent.
|
|
93
93
|
*/
|
|
94
|
-
public add(delay: number, callback: Function, callbackContext:
|
|
94
|
+
public add(delay: number, callback: Function, callbackContext: unknown | null = null, ...args: unknown[]) {
|
|
95
95
|
return this.create(delay, false, 0, callback, callbackContext, args);
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -102,7 +102,7 @@ export class Timer {
|
|
|
102
102
|
* @param {...T} args - Arguments to pass to the resolve function.
|
|
103
103
|
* @returns {Promise<T | T[]>} The created Promise.
|
|
104
104
|
*/
|
|
105
|
-
public wait(delay: number, ...args:
|
|
105
|
+
public wait(delay: number, ...args: unknown[]) {
|
|
106
106
|
return new Promise((resolve) => {
|
|
107
107
|
this.create(delay, false, 0, () => {
|
|
108
108
|
resolve(args.length <= 1 ? args[0] : args);
|
|
@@ -123,8 +123,8 @@ export class Timer {
|
|
|
123
123
|
delay: number,
|
|
124
124
|
repeatCount: number,
|
|
125
125
|
callback: Function,
|
|
126
|
-
callbackContext:
|
|
127
|
-
...args:
|
|
126
|
+
callbackContext: unknown | null = null,
|
|
127
|
+
...args: unknown[]
|
|
128
128
|
) {
|
|
129
129
|
return this.create(delay, false, repeatCount, callback, callbackContext, args);
|
|
130
130
|
}
|
|
@@ -137,7 +137,7 @@ export class Timer {
|
|
|
137
137
|
* @param {...any} args - Arguments to pass to the callback function.
|
|
138
138
|
* @returns {TimerEvent} The created TimerEvent.
|
|
139
139
|
*/
|
|
140
|
-
public loop(delay: number, callback: Function, callbackContext:
|
|
140
|
+
public loop(delay: number, callback: Function, callbackContext: unknown | null = null, ...args: unknown[]) {
|
|
141
141
|
return this.create(delay, true, 0, callback, callbackContext, args);
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -7,7 +7,7 @@ export class TimerEvent {
|
|
|
7
7
|
public repeatCount: number;
|
|
8
8
|
public loop: boolean;
|
|
9
9
|
public callback: Function;
|
|
10
|
-
public callbackContext:
|
|
10
|
+
public callbackContext: unknown;
|
|
11
11
|
public args: unknown[];
|
|
12
12
|
public pendingDelete: boolean;
|
|
13
13
|
|
|
@@ -18,7 +18,7 @@ export class TimerEvent {
|
|
|
18
18
|
repeatCount: number,
|
|
19
19
|
loop: boolean,
|
|
20
20
|
callback: Function,
|
|
21
|
-
callbackContext:
|
|
21
|
+
callbackContext: unknown,
|
|
22
22
|
args: unknown[]
|
|
23
23
|
) {
|
|
24
24
|
this.timer = timer;
|
package/src/phaser/core/tween.ts
CHANGED
|
@@ -26,7 +26,7 @@ export class Tween {
|
|
|
26
26
|
public chainedTween!: Tween | null;
|
|
27
27
|
public isPaused!: boolean;
|
|
28
28
|
public _onUpdateCallback!: Function | null;
|
|
29
|
-
public _onUpdateCallbackContext!:
|
|
29
|
+
public _onUpdateCallbackContext!: unknown;
|
|
30
30
|
public _pausedTime!: number;
|
|
31
31
|
public _codePaused!: boolean;
|
|
32
32
|
public _hasStarted!: boolean;
|
|
@@ -296,7 +296,7 @@ export class Tween {
|
|
|
296
296
|
* @param {number} index - The index in the timeline to apply interpolation to.
|
|
297
297
|
* @returns {Tween} This Tween object for chaining.
|
|
298
298
|
*/
|
|
299
|
-
public interpolation(interpolation: Function, context:
|
|
299
|
+
public interpolation(interpolation: Function, context: unknown = MathUtils, index = 0) {
|
|
300
300
|
this.updateTweenData('interpolationFunction', interpolation, index);
|
|
301
301
|
return this.updateTweenData('interpolationContext', context, index);
|
|
302
302
|
}
|
|
@@ -316,14 +316,14 @@ export class Tween {
|
|
|
316
316
|
* @param {...any} args - The tweens to chain.
|
|
317
317
|
* @returns {Tween} This Tween object for chaining.
|
|
318
318
|
*/
|
|
319
|
-
public chain(...args:
|
|
319
|
+
public chain(...args: Tween[]) {
|
|
320
320
|
let i = args.length;
|
|
321
321
|
while (i) {
|
|
322
322
|
i -= 1;
|
|
323
323
|
if (i > 0) {
|
|
324
|
-
args[i - 1]
|
|
324
|
+
args[i - 1]!.chainedTween = args[i] ?? null;
|
|
325
325
|
} else {
|
|
326
|
-
this.chainedTween = args[i];
|
|
326
|
+
this.chainedTween = args[i] ?? null;
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
329
|
return this;
|
|
@@ -345,7 +345,7 @@ export class Tween {
|
|
|
345
345
|
* @param {object} callbackContext - The context in which to call the callback.
|
|
346
346
|
* @returns {Tween} This Tween object for chaining.
|
|
347
347
|
*/
|
|
348
|
-
public onUpdateCallback(callback: Function, callbackContext:
|
|
348
|
+
public onUpdateCallback(callback: Function, callbackContext: unknown) {
|
|
349
349
|
this._onUpdateCallback = callback;
|
|
350
350
|
this._onUpdateCallbackContext = callbackContext;
|
|
351
351
|
return this;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { Game } from './game.js';
|
|
1
2
|
import * as MathUtils from '../util/math.js';
|
|
2
3
|
import { TWEEN_COMPLETE, TWEEN_LOOPED, TWEEN_PENDING, TWEEN_RUNNING } from './const.js';
|
|
3
4
|
import type { Tween } from './tween.js';
|
|
4
5
|
|
|
5
6
|
export class TweenData {
|
|
6
7
|
public parent!: any;
|
|
7
|
-
public game!:
|
|
8
|
+
public game!: Game;
|
|
8
9
|
public vStart!: any;
|
|
9
10
|
public vStartCache!: any;
|
|
10
11
|
public vEnd!: any;
|
|
@@ -46,7 +46,7 @@ export class Button extends Image {
|
|
|
46
46
|
y = 0,
|
|
47
47
|
key: string | null = null,
|
|
48
48
|
callback: Function | null = null,
|
|
49
|
-
callbackContext:
|
|
49
|
+
callbackContext: unknown | null = null,
|
|
50
50
|
overFrame: string | null = null,
|
|
51
51
|
outFrame: string | null = null,
|
|
52
52
|
downFrame: string | null = null,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { create, removeByCanvas } from './pool.js';
|
|
2
2
|
|
|
3
3
|
export class CanvasBuffer {
|
|
4
|
-
public width!:
|
|
5
|
-
public height!:
|
|
4
|
+
public width!: number;
|
|
5
|
+
public height!: number;
|
|
6
6
|
public canvas!: any;
|
|
7
|
-
public context!:
|
|
7
|
+
public context!: CanvasRenderingContext2D;
|
|
8
8
|
/**
|
|
9
9
|
* Creates a new CanvasBuffer instance.
|
|
10
10
|
* @param {number} width - The width of the canvas buffer.
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { GEOM_CIRCLE, GEOM_ELLIPSE, GEOM_POLYGON, GEOM_RECTANGLE, GEOM_ROUNDED_RECTANGLE } from '../../core/const.js';
|
|
2
1
|
import type { Graphics } from '../graphics.js';
|
|
2
|
+
import { Circle } from '../../geom/circle.js';
|
|
3
|
+
import { Ellipse } from '../../geom/ellipse.js';
|
|
4
|
+
import { Polygon } from '../../geom/polygon.js';
|
|
5
|
+
import { Rectangle } from '../../geom/rectangle.js';
|
|
6
|
+
import { RoundedRectangle } from '../../geom/rounded_rectangle.js';
|
|
3
7
|
|
|
4
8
|
/**
|
|
5
9
|
* Renders a graphics object to canvas.
|
|
@@ -13,7 +17,7 @@ export const updateGraphicsTint = (graphics: Graphics) => {
|
|
|
13
17
|
const tintG = ((graphics.tint >> 8) & 0xff) / 255;
|
|
14
18
|
const tintB = (graphics.tint & 0xff) / 255;
|
|
15
19
|
for (const data of graphics.graphicsData) {
|
|
16
|
-
const fillColor = Math.trunc(data.fillColor);
|
|
20
|
+
const fillColor = Math.trunc(data.fillColor ?? 0);
|
|
17
21
|
const lineColor = Math.trunc(data.lineColor);
|
|
18
22
|
data._fillTint =
|
|
19
23
|
(((((fillColor >> 16) & 0xff) / 255) * tintR * 255) << 16) +
|
|
@@ -31,7 +35,7 @@ export const updateGraphicsTint = (graphics: Graphics) => {
|
|
|
31
35
|
* @param {Graphics} graphics - The graphics object to render.
|
|
32
36
|
* @param {object} context - The canvas rendering context.
|
|
33
37
|
*/
|
|
34
|
-
export const renderGraphics = (graphics: Graphics, context:
|
|
38
|
+
export const renderGraphics = (graphics: Graphics, context: CanvasRenderingContext2D) => {
|
|
35
39
|
const { worldAlpha } = graphics;
|
|
36
40
|
if (graphics.dirty) {
|
|
37
41
|
updateGraphicsTint(graphics);
|
|
@@ -42,7 +46,7 @@ export const renderGraphics = (graphics: Graphics, context: any) => {
|
|
|
42
46
|
const fillColor = data._fillTint;
|
|
43
47
|
const lineColor = data._lineTint;
|
|
44
48
|
context.lineWidth = data.lineWidth;
|
|
45
|
-
if (
|
|
49
|
+
if (shape instanceof Polygon) {
|
|
46
50
|
context.beginPath();
|
|
47
51
|
const { points } = shape;
|
|
48
52
|
context.moveTo(points[0], points[1]);
|
|
@@ -58,7 +62,7 @@ export const renderGraphics = (graphics: Graphics, context: any) => {
|
|
|
58
62
|
}
|
|
59
63
|
if (data.fill) {
|
|
60
64
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
61
|
-
context.fillStyle = `#${`00000${Math.trunc(fillColor).toString(16)}`.slice(-6)}`;
|
|
65
|
+
context.fillStyle = `#${`00000${Math.trunc(fillColor ?? 0).toString(16)}`.slice(-6)}`;
|
|
62
66
|
context.fill();
|
|
63
67
|
}
|
|
64
68
|
if (data.lineWidth) {
|
|
@@ -66,10 +70,10 @@ export const renderGraphics = (graphics: Graphics, context: any) => {
|
|
|
66
70
|
context.strokeStyle = `#${`00000${Math.trunc(lineColor).toString(16)}`.slice(-6)}`;
|
|
67
71
|
context.stroke();
|
|
68
72
|
}
|
|
69
|
-
} else if (
|
|
73
|
+
} else if (shape instanceof Rectangle) {
|
|
70
74
|
if (data.fillColor || data.fillColor === 0) {
|
|
71
75
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
72
|
-
context.fillStyle = `#${`00000${Math.trunc(fillColor).toString(16)}`.slice(-6)}`;
|
|
76
|
+
context.fillStyle = `#${`00000${Math.trunc(fillColor ?? 0).toString(16)}`.slice(-6)}`;
|
|
73
77
|
context.fillRect(shape.x, shape.y, shape.width, shape.height);
|
|
74
78
|
}
|
|
75
79
|
if (data.lineWidth) {
|
|
@@ -77,13 +81,13 @@ export const renderGraphics = (graphics: Graphics, context: any) => {
|
|
|
77
81
|
context.strokeStyle = `#${`00000${Math.trunc(lineColor).toString(16)}`.slice(-6)}`;
|
|
78
82
|
context.strokeRect(shape.x, shape.y, shape.width, shape.height);
|
|
79
83
|
}
|
|
80
|
-
} else if (
|
|
84
|
+
} else if (shape instanceof Circle) {
|
|
81
85
|
context.beginPath();
|
|
82
86
|
context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI);
|
|
83
87
|
context.closePath();
|
|
84
88
|
if (data.fill) {
|
|
85
89
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
86
|
-
context.fillStyle = `#${`00000${Math.trunc(fillColor).toString(16)}`.slice(-6)}`;
|
|
90
|
+
context.fillStyle = `#${`00000${Math.trunc(fillColor ?? 0).toString(16)}`.slice(-6)}`;
|
|
87
91
|
context.fill();
|
|
88
92
|
}
|
|
89
93
|
if (data.lineWidth) {
|
|
@@ -91,7 +95,7 @@ export const renderGraphics = (graphics: Graphics, context: any) => {
|
|
|
91
95
|
context.strokeStyle = `#${`00000${Math.trunc(lineColor).toString(16)}`.slice(-6)}`;
|
|
92
96
|
context.stroke();
|
|
93
97
|
}
|
|
94
|
-
} else if (
|
|
98
|
+
} else if (shape instanceof Ellipse) {
|
|
95
99
|
// ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
|
|
96
100
|
const w = shape.width * 2;
|
|
97
101
|
const h = shape.height * 2;
|
|
@@ -113,7 +117,7 @@ export const renderGraphics = (graphics: Graphics, context: any) => {
|
|
|
113
117
|
context.closePath();
|
|
114
118
|
if (data.fill) {
|
|
115
119
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
116
|
-
context.fillStyle = `#${`00000${Math.trunc(fillColor).toString(16)}`.slice(-6)}`;
|
|
120
|
+
context.fillStyle = `#${`00000${Math.trunc(fillColor ?? 0).toString(16)}`.slice(-6)}`;
|
|
117
121
|
context.fill();
|
|
118
122
|
}
|
|
119
123
|
if (data.lineWidth) {
|
|
@@ -121,7 +125,7 @@ export const renderGraphics = (graphics: Graphics, context: any) => {
|
|
|
121
125
|
context.strokeStyle = `#${`00000${Math.trunc(lineColor).toString(16)}`.slice(-6)}`;
|
|
122
126
|
context.stroke();
|
|
123
127
|
}
|
|
124
|
-
} else if (
|
|
128
|
+
} else if (shape instanceof RoundedRectangle) {
|
|
125
129
|
const rx = shape.x;
|
|
126
130
|
const ry = shape.y;
|
|
127
131
|
const { width } = shape;
|
|
@@ -142,7 +146,7 @@ export const renderGraphics = (graphics: Graphics, context: any) => {
|
|
|
142
146
|
context.closePath();
|
|
143
147
|
if (data.fillColor || data.fillColor === 0) {
|
|
144
148
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
145
|
-
context.fillStyle = `#${`00000${Math.trunc(fillColor).toString(16)}`.slice(-6)}`;
|
|
149
|
+
context.fillStyle = `#${`00000${Math.trunc(fillColor ?? 0).toString(16)}`.slice(-6)}`;
|
|
146
150
|
context.fill();
|
|
147
151
|
}
|
|
148
152
|
if (data.lineWidth) {
|
|
@@ -159,16 +163,16 @@ export const renderGraphics = (graphics: Graphics, context: any) => {
|
|
|
159
163
|
* @param {Graphics} graphics - The graphics object to render.
|
|
160
164
|
* @param {object} context - The canvas rendering context.
|
|
161
165
|
*/
|
|
162
|
-
export const renderGraphicsMask = (graphics: Graphics, context:
|
|
166
|
+
export const renderGraphicsMask = (graphics: Graphics, context: CanvasRenderingContext2D) => {
|
|
163
167
|
const len = graphics.graphicsData.length;
|
|
164
168
|
if (len === 0) {
|
|
165
169
|
return;
|
|
166
170
|
}
|
|
167
171
|
context.beginPath();
|
|
168
172
|
for (let i = 0; i < len; i += 1) {
|
|
169
|
-
const data = graphics.graphicsData[i]
|
|
173
|
+
const data = graphics.graphicsData[i]!;
|
|
170
174
|
const { shape } = data;
|
|
171
|
-
if (
|
|
175
|
+
if (shape instanceof Polygon) {
|
|
172
176
|
const { points } = shape;
|
|
173
177
|
context.moveTo(points[0], points[1]);
|
|
174
178
|
for (let j = 1; j < points.length / 2; j += 1) {
|
|
@@ -178,13 +182,13 @@ export const renderGraphicsMask = (graphics: Graphics, context: any) => {
|
|
|
178
182
|
if (points[0] === points.at(-2) && points[1] === points.at(-1)) {
|
|
179
183
|
context.closePath();
|
|
180
184
|
}
|
|
181
|
-
} else if (
|
|
185
|
+
} else if (shape instanceof Rectangle) {
|
|
182
186
|
context.rect(shape.x, shape.y, shape.width, shape.height);
|
|
183
187
|
context.closePath();
|
|
184
|
-
} else if (
|
|
188
|
+
} else if (shape instanceof Circle) {
|
|
185
189
|
context.arc(shape.x, shape.y, shape.radius, 0, 2 * Math.PI);
|
|
186
190
|
context.closePath();
|
|
187
|
-
} else if (
|
|
191
|
+
} else if (shape instanceof Ellipse) {
|
|
188
192
|
// ellipse code taken from: http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
|
|
189
193
|
const w = shape.width * 2;
|
|
190
194
|
const h = shape.height * 2;
|
|
@@ -203,7 +207,7 @@ export const renderGraphicsMask = (graphics: Graphics, context: any) => {
|
|
|
203
207
|
context.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
|
|
204
208
|
context.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
|
|
205
209
|
context.closePath();
|
|
206
|
-
} else if (
|
|
210
|
+
} else if (shape instanceof RoundedRectangle) {
|
|
207
211
|
const rx = shape.x;
|
|
208
212
|
const ry = shape.y;
|
|
209
213
|
const { width } = shape;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { renderGraphicsMask } from './graphics.js';
|
|
2
|
+
import type { RenderSession } from '../render_session.js';
|
|
3
|
+
import type { Graphics } from '../graphics.js';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Pushes a mask onto the rendering stack.
|
|
5
7
|
* @param {object} maskData - The mask data to apply.
|
|
6
8
|
* @param {object} renderSession - The rendering session object.
|
|
7
9
|
*/
|
|
8
|
-
export const pushMask = (maskData: any, renderSession:
|
|
10
|
+
export const pushMask = (maskData: any, renderSession: RenderSession) => {
|
|
9
11
|
const { context } = renderSession;
|
|
10
12
|
context.save();
|
|
11
13
|
const cacheAlpha = maskData.alpha;
|
|
@@ -26,8 +28,9 @@ export const pushMask = (maskData: any, renderSession: any) => {
|
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* Pops a mask from the rendering stack.
|
|
31
|
+
* @param {object} _maskData - Unused; the canvas path restores whatever was saved.
|
|
29
32
|
* @param {object} renderSession - The rendering session object.
|
|
30
33
|
*/
|
|
31
|
-
export const popMask = (renderSession:
|
|
34
|
+
export const popMask = (_maskData: Graphics | null, renderSession: RenderSession) => {
|
|
32
35
|
renderSession.context.restore();
|
|
33
36
|
};
|
|
@@ -25,22 +25,23 @@ import {
|
|
|
25
25
|
import { ENGINE_ERROR_CREATING_CANVAS_2D_CONTEXT } from '../../core/error_code.js';
|
|
26
26
|
import * as CanvasMaskManager from './masker.js';
|
|
27
27
|
import { detectCapabilities } from './tinter.js';
|
|
28
|
-
import { getSmoothingPrefix } from './util.js';
|
|
28
|
+
import { getSmoothingPrefix, setSmoothing } from './util.js';
|
|
29
|
+
import type { RenderSession } from '../render_session.js';
|
|
29
30
|
|
|
30
31
|
export class CanvasRenderer {
|
|
31
32
|
public type!: any;
|
|
32
|
-
public resolution!:
|
|
33
|
+
public resolution!: number;
|
|
33
34
|
public clearBeforeRender!: any;
|
|
34
35
|
public transparent!: any;
|
|
35
36
|
public autoResize!: any;
|
|
36
37
|
public contextLost!: any;
|
|
37
|
-
public width!:
|
|
38
|
-
public height!:
|
|
38
|
+
public width!: number;
|
|
39
|
+
public height!: number;
|
|
39
40
|
public view!: any;
|
|
40
|
-
public context!:
|
|
41
|
+
public context!: CanvasRenderingContext2D;
|
|
41
42
|
public refresh!: any;
|
|
42
43
|
public count!: any;
|
|
43
|
-
public renderSession!:
|
|
44
|
+
public renderSession!: RenderSession;
|
|
44
45
|
/**
|
|
45
46
|
* Creates a new CanvasRenderer instance.
|
|
46
47
|
* @param {Game} _game - The game instance.
|
|
@@ -64,13 +65,14 @@ export class CanvasRenderer {
|
|
|
64
65
|
}
|
|
65
66
|
this.refresh = true;
|
|
66
67
|
this.count = 0;
|
|
68
|
+
// Only the canvas half of the session applies to this renderer.
|
|
67
69
|
this.renderSession = {
|
|
68
70
|
context: this.context,
|
|
69
71
|
maskManager: CanvasMaskManager,
|
|
70
72
|
scaleMode: game.config.antialias ? SCALE_LINEAR : SCALE_NEAREST,
|
|
71
73
|
smoothProperty: getSmoothingPrefix(this.context),
|
|
72
74
|
roundPixels: game.config.roundPixels,
|
|
73
|
-
};
|
|
75
|
+
} as RenderSession;
|
|
74
76
|
this.mapBlendModes();
|
|
75
77
|
this.resize(this.width, this.height);
|
|
76
78
|
}
|
|
@@ -108,9 +110,6 @@ export class CanvasRenderer {
|
|
|
108
110
|
if (removeView && this.view.parent) {
|
|
109
111
|
this.view.parent.removeChild(this.view);
|
|
110
112
|
}
|
|
111
|
-
this.view = null;
|
|
112
|
-
this.context = null;
|
|
113
|
-
this.renderSession = null;
|
|
114
113
|
}
|
|
115
114
|
|
|
116
115
|
/**
|
|
@@ -128,7 +127,7 @@ export class CanvasRenderer {
|
|
|
128
127
|
this.view.style.height = `${this.height / this.resolution}px`;
|
|
129
128
|
}
|
|
130
129
|
if (this.renderSession.smoothProperty) {
|
|
131
|
-
this.context
|
|
130
|
+
setSmoothing(this.context, this.renderSession.smoothProperty, this.renderSession.scaleMode === SCALE_LINEAR);
|
|
132
131
|
}
|
|
133
132
|
}
|
|
134
133
|
|
|
@@ -3,6 +3,7 @@ import { hex2rgb } from '../../util/math.js';
|
|
|
3
3
|
import { create, removeByCanvas } from './pool.js';
|
|
4
4
|
import { getRegistry } from '../../core/registry.js';
|
|
5
5
|
import type { Game } from '../../core/game.js';
|
|
6
|
+
import type { Image } from '../image.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Tints a sprite with the given color.
|
|
@@ -10,7 +11,7 @@ import type { Game } from '../../core/game.js';
|
|
|
10
11
|
* @param {object} color - The color to tint with.
|
|
11
12
|
* @returns {object} The tinted sprite.
|
|
12
13
|
*/
|
|
13
|
-
export const getTintedTexture = (sprite:
|
|
14
|
+
export const getTintedTexture = (sprite: Image, color: number): HTMLCanvasElement => {
|
|
14
15
|
const canvas = sprite.tintedTexture ?? create('CanvasTinter', 1, 1);
|
|
15
16
|
globalThis.PhaserRegistry.CANVAS_TINT_METHOD(sprite.texture, color, canvas);
|
|
16
17
|
return canvas;
|
|
@@ -135,9 +136,9 @@ export const canUseNewCanvasBlendModes = () => {
|
|
|
135
136
|
// Create test images
|
|
136
137
|
const pngHead = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAABAQMAAADD8p2OAAAAA1BMVEX/';
|
|
137
138
|
const pngEnd = 'AAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==';
|
|
138
|
-
const magenta = new Image();
|
|
139
|
+
const magenta = new globalThis.Image();
|
|
139
140
|
magenta.src = `${pngHead}AP804Oa6${pngEnd}`;
|
|
140
|
-
const yellow = new Image();
|
|
141
|
+
const yellow = new globalThis.Image();
|
|
141
142
|
yellow.src = `${pngHead}/wCKxvRF${pngEnd}`;
|
|
142
143
|
// Create canvas and context
|
|
143
144
|
const canvas = create('CanvasTinter', 6, 1, true);
|
|
@@ -143,16 +143,26 @@ export const getSmoothingPrefix = (context: CanvasRenderingContext2D) => {
|
|
|
143
143
|
return null;
|
|
144
144
|
};
|
|
145
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Writes one of the vendor-prefixed image smoothing properties, which are not on the DOM type.
|
|
148
|
+
* @param {CanvasRenderingContext2D} context - The canvas rendering context.
|
|
149
|
+
* @param {string} property - The smoothing property name to write.
|
|
150
|
+
* @param {boolean} value - The smoothing value to set.
|
|
151
|
+
*/
|
|
152
|
+
export const setSmoothing = (context: CanvasRenderingContext2D, property: string, value: boolean): void => {
|
|
153
|
+
(context as unknown as Record<string, boolean>)[property] = value;
|
|
154
|
+
};
|
|
155
|
+
|
|
146
156
|
/**
|
|
147
157
|
* Sets the smoothing enabled property on a canvas rendering context.
|
|
148
|
-
* @param {
|
|
149
|
-
* @param {
|
|
150
|
-
* @returns {
|
|
158
|
+
* @param {CanvasRenderingContext2D} context - The canvas rendering context.
|
|
159
|
+
* @param {boolean} value - The smoothing enabled value to set.
|
|
160
|
+
* @returns {CanvasRenderingContext2D} The modified rendering context.
|
|
151
161
|
*/
|
|
152
|
-
export const setSmoothingEnabled = (context:
|
|
162
|
+
export const setSmoothingEnabled = (context: CanvasRenderingContext2D, value: boolean) => {
|
|
153
163
|
const s = getSmoothingPrefix(context);
|
|
154
164
|
if (s) {
|
|
155
|
-
context
|
|
165
|
+
setSmoothing(context, s, value);
|
|
156
166
|
}
|
|
157
167
|
return context;
|
|
158
168
|
};
|