@vpmedia/phaser 1.113.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 +402 -379
- 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 +65 -31
- 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 +136 -0
- package/src/phaser/display/text.ts +183 -119
- 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
|
@@ -9,46 +9,104 @@ import { getBounds, renderCanvas, renderWebGL } from './sprite_util.js';
|
|
|
9
9
|
import { textureFromCanvas } from './webgl/texture_util.js';
|
|
10
10
|
import type { Game } from '../core/game.js';
|
|
11
11
|
import type { Matrix } from '../geom/matrix.js';
|
|
12
|
+
import type { RenderSession } from './render_session.js';
|
|
13
|
+
|
|
14
|
+
/** The font shorthand split into its CSS parts. */
|
|
15
|
+
export type FontComponents = {
|
|
16
|
+
font?: string;
|
|
17
|
+
fontStyle?: string;
|
|
18
|
+
fontVariant?: string;
|
|
19
|
+
fontWeight?: string | number;
|
|
20
|
+
fontSize?: string | number;
|
|
21
|
+
fontFamily?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Style accepted by Text, as supplied by callers; setStyle fills in every default. */
|
|
25
|
+
export type TextStyle = FontComponents & {
|
|
26
|
+
align?: string;
|
|
27
|
+
backgroundColor?: string | null;
|
|
28
|
+
boundsAlignH?: string;
|
|
29
|
+
boundsAlignV?: string;
|
|
30
|
+
fill?: string;
|
|
31
|
+
maxLines?: number;
|
|
32
|
+
shadowBlur?: number;
|
|
33
|
+
shadowColor?: string;
|
|
34
|
+
shadowFill?: boolean;
|
|
35
|
+
shadowOffsetX?: number;
|
|
36
|
+
shadowOffsetY?: number;
|
|
37
|
+
shadowStroke?: boolean;
|
|
38
|
+
stroke?: string;
|
|
39
|
+
strokeThickness?: number;
|
|
40
|
+
tabs?: number | number[];
|
|
41
|
+
wordWrap?: boolean;
|
|
42
|
+
wordWrapWidth?: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** The same style once setStyle has applied every default. */
|
|
46
|
+
export type ResolvedTextStyle = Required<
|
|
47
|
+
Pick<
|
|
48
|
+
TextStyle,
|
|
49
|
+
| 'align'
|
|
50
|
+
| 'boundsAlignH'
|
|
51
|
+
| 'boundsAlignV'
|
|
52
|
+
| 'fill'
|
|
53
|
+
| 'font'
|
|
54
|
+
| 'maxLines'
|
|
55
|
+
| 'shadowBlur'
|
|
56
|
+
| 'shadowColor'
|
|
57
|
+
| 'shadowOffsetX'
|
|
58
|
+
| 'shadowOffsetY'
|
|
59
|
+
| 'stroke'
|
|
60
|
+
| 'strokeThickness'
|
|
61
|
+
| 'tabs'
|
|
62
|
+
| 'wordWrap'
|
|
63
|
+
| 'wordWrapWidth'
|
|
64
|
+
>
|
|
65
|
+
> &
|
|
66
|
+
TextStyle & { backgroundColor: string | null };
|
|
12
67
|
|
|
13
68
|
export class Text extends Image {
|
|
14
69
|
declare public type: number;
|
|
15
|
-
public canvas!:
|
|
16
|
-
public context!:
|
|
70
|
+
public canvas!: HTMLCanvasElement;
|
|
71
|
+
public context!: CanvasRenderingContext2D;
|
|
17
72
|
public padding!: Point;
|
|
18
73
|
public textBounds!: Rectangle | null;
|
|
19
|
-
public style!:
|
|
20
|
-
public colors!:
|
|
21
|
-
public strokeColors!:
|
|
22
|
-
public fontStyles!:
|
|
23
|
-
public fontWeights!:
|
|
74
|
+
public style!: ResolvedTextStyle;
|
|
75
|
+
public colors!: (string | null)[];
|
|
76
|
+
public strokeColors!: (string | null)[];
|
|
77
|
+
public fontStyles!: (string | null)[];
|
|
78
|
+
public fontWeights!: (string | null)[];
|
|
24
79
|
public autoRound!: boolean;
|
|
25
80
|
public useAdvancedWrap!: boolean;
|
|
26
81
|
public _res!: number;
|
|
27
82
|
public _text!: string;
|
|
28
|
-
public _fontComponents!:
|
|
83
|
+
public _fontComponents!: FontComponents;
|
|
29
84
|
public _lineSpacing!: number;
|
|
30
85
|
public _charCount!: number;
|
|
31
|
-
declare public _width:
|
|
32
|
-
declare public _height:
|
|
86
|
+
declare public _width: number;
|
|
87
|
+
declare public _height: number;
|
|
33
88
|
public dirty!: boolean;
|
|
34
89
|
/**
|
|
35
90
|
* Creates a new Text object.
|
|
36
91
|
* @param {Game} game - The game instance this text belongs to.
|
|
37
92
|
* @param {number} x - The x position of the text.
|
|
38
93
|
* @param {number} y - The y position of the text.
|
|
39
|
-
* @param {string} text - The text content to display.
|
|
94
|
+
* @param {string | number} text - The text content to display.
|
|
40
95
|
* @param {object} style - The style settings for the text.
|
|
41
96
|
*/
|
|
42
|
-
public constructor(game: Game, x: number, y: number, text = '', style:
|
|
97
|
+
public constructor(game: Game, x: number, y: number, text: string | number = '', style: TextStyle = {}) {
|
|
43
98
|
super(game, x, y, null);
|
|
44
99
|
this.game = game;
|
|
45
100
|
/** @type {number} */
|
|
46
101
|
this.type = TEXT;
|
|
47
102
|
this.canvas = create(this);
|
|
48
|
-
|
|
103
|
+
const context = this.canvas.getContext('2d', { willReadFrequently: false });
|
|
104
|
+
if (!context) {
|
|
105
|
+
throw new Error(ENGINE_ERROR_CREATING_CANVAS_2D_CONTEXT);
|
|
106
|
+
}
|
|
107
|
+
this.context = context;
|
|
49
108
|
this.padding = new Point();
|
|
50
109
|
this.textBounds = null;
|
|
51
|
-
this.style = null;
|
|
52
110
|
/** @type {string[]} */
|
|
53
111
|
this.colors = [];
|
|
54
112
|
/** @type {string[]} */
|
|
@@ -60,8 +118,7 @@ export class Text extends Image {
|
|
|
60
118
|
this.autoRound = false;
|
|
61
119
|
this.useAdvancedWrap = false;
|
|
62
120
|
this._res = game.renderer.resolution;
|
|
63
|
-
this._text = text;
|
|
64
|
-
this._fontComponents = null;
|
|
121
|
+
this._text = text.toString();
|
|
65
122
|
/** @type {number} */
|
|
66
123
|
this._lineSpacing = 0;
|
|
67
124
|
/** @type {number} */
|
|
@@ -83,17 +140,12 @@ export class Text extends Image {
|
|
|
83
140
|
public override destroy() {
|
|
84
141
|
this.texture.destroy(true);
|
|
85
142
|
remove(this);
|
|
86
|
-
this.canvas = null;
|
|
87
|
-
this.context = null;
|
|
88
143
|
this.textBounds = null;
|
|
89
|
-
this.
|
|
90
|
-
this.
|
|
91
|
-
this.
|
|
92
|
-
this.
|
|
93
|
-
this.
|
|
94
|
-
this.padding = null!;
|
|
95
|
-
this._text = null!;
|
|
96
|
-
this._fontComponents = null;
|
|
144
|
+
this.colors = [];
|
|
145
|
+
this.strokeColors = [];
|
|
146
|
+
this.fontStyles = [];
|
|
147
|
+
this.fontWeights = [];
|
|
148
|
+
this._text = '';
|
|
97
149
|
super.destroy();
|
|
98
150
|
}
|
|
99
151
|
|
|
@@ -124,43 +176,46 @@ export class Text extends Image {
|
|
|
124
176
|
* @param {boolean} update - Whether to update the text immediately.
|
|
125
177
|
* @returns {Text} This Text object for chaining.
|
|
126
178
|
*/
|
|
127
|
-
public setStyle(style:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
179
|
+
public setStyle(style: TextStyle | null = null, update = false) {
|
|
180
|
+
const source: TextStyle = structuredClone(style) ?? {};
|
|
181
|
+
const resolved: ResolvedTextStyle = {
|
|
182
|
+
...source,
|
|
183
|
+
font: source.font ?? 'bold 20pt Arial',
|
|
184
|
+
backgroundColor: source.backgroundColor ?? null,
|
|
185
|
+
fill: source.fill ?? 'black',
|
|
186
|
+
align: source.align ?? 'left',
|
|
187
|
+
boundsAlignH: source.boundsAlignH ?? 'left',
|
|
188
|
+
boundsAlignV: source.boundsAlignV ?? 'top',
|
|
189
|
+
// provide a default, see: https://github.com/GoodBoyDigital/pixi.js/issues/136
|
|
190
|
+
stroke: source.stroke ?? 'black',
|
|
191
|
+
strokeThickness: source.strokeThickness ?? 0,
|
|
192
|
+
wordWrap: source.wordWrap ?? false,
|
|
193
|
+
wordWrapWidth: source.wordWrapWidth ?? 100,
|
|
194
|
+
maxLines: source.maxLines ?? 0,
|
|
195
|
+
shadowOffsetX: source.shadowOffsetX ?? 0,
|
|
196
|
+
shadowOffsetY: source.shadowOffsetY ?? 0,
|
|
197
|
+
shadowColor: source.shadowColor ?? 'rgba(0,0,0,0)',
|
|
198
|
+
shadowBlur: source.shadowBlur ?? 0,
|
|
199
|
+
tabs: source.tabs ?? 0,
|
|
200
|
+
};
|
|
201
|
+
const components = this.fontToComponents(resolved.font);
|
|
202
|
+
if (resolved.fontStyle) {
|
|
203
|
+
components.fontStyle = resolved.fontStyle;
|
|
204
|
+
}
|
|
205
|
+
if (resolved.fontVariant) {
|
|
206
|
+
components.fontVariant = resolved.fontVariant;
|
|
207
|
+
}
|
|
208
|
+
if (resolved.fontWeight) {
|
|
209
|
+
components.fontWeight = String(resolved.fontWeight);
|
|
210
|
+
}
|
|
211
|
+
if (resolved.fontSize) {
|
|
212
|
+
const fontSize = typeof resolved.fontSize === 'number' ? `${resolved.fontSize}px` : resolved.fontSize;
|
|
213
|
+
resolved.fontSize = fontSize;
|
|
214
|
+
components.fontSize = fontSize;
|
|
160
215
|
}
|
|
161
216
|
this._fontComponents = components;
|
|
162
|
-
|
|
163
|
-
this.style =
|
|
217
|
+
resolved.font = this.componentsToFont(components);
|
|
218
|
+
this.style = resolved;
|
|
164
219
|
this.dirty = true;
|
|
165
220
|
if (update) {
|
|
166
221
|
this.updateText();
|
|
@@ -231,7 +286,7 @@ export class Text extends Image {
|
|
|
231
286
|
section = Math.ceil(this.context.measureText(line[c]).width);
|
|
232
287
|
}
|
|
233
288
|
if (c > 0) {
|
|
234
|
-
tab += tabs[c - 1]
|
|
289
|
+
tab += tabs[c - 1]!;
|
|
235
290
|
}
|
|
236
291
|
lineWidth = tab + section;
|
|
237
292
|
}
|
|
@@ -310,7 +365,7 @@ export class Text extends Image {
|
|
|
310
365
|
this.updateLine(lines[i], linePositionX, linePositionY);
|
|
311
366
|
} else {
|
|
312
367
|
if (this.style.stroke && this.style.strokeThickness) {
|
|
313
|
-
this.updateShadow(this.style.shadowStroke);
|
|
368
|
+
this.updateShadow(this.style.shadowStroke ?? false);
|
|
314
369
|
if (tabs === 0) {
|
|
315
370
|
this.context.strokeText(lines[i], linePositionX, linePositionY);
|
|
316
371
|
} else {
|
|
@@ -318,7 +373,7 @@ export class Text extends Image {
|
|
|
318
373
|
}
|
|
319
374
|
}
|
|
320
375
|
if (this.style.fill) {
|
|
321
|
-
this.updateShadow(this.style.shadowFill);
|
|
376
|
+
this.updateShadow(this.style.shadowFill ?? false);
|
|
322
377
|
if (tabs === 0) {
|
|
323
378
|
this.context.fillText(lines[i], linePositionX, linePositionY);
|
|
324
379
|
} else {
|
|
@@ -346,24 +401,24 @@ export class Text extends Image {
|
|
|
346
401
|
let tab = 0;
|
|
347
402
|
for (let c = 0; c < text.length; c += 1) {
|
|
348
403
|
if (c > 0) {
|
|
349
|
-
tab += tabs[c - 1]
|
|
404
|
+
tab += tabs[c - 1]!;
|
|
350
405
|
}
|
|
351
406
|
snap = x + tab;
|
|
352
407
|
if (fill) {
|
|
353
|
-
this.context.fillText(text[c]
|
|
408
|
+
this.context.fillText(text[c]!, snap, y);
|
|
354
409
|
} else {
|
|
355
|
-
this.context.strokeText(text[c]
|
|
410
|
+
this.context.strokeText(text[c]!, snap, y);
|
|
356
411
|
}
|
|
357
412
|
}
|
|
358
413
|
} else {
|
|
359
414
|
for (let c = 0; c < text.length; c += 1) {
|
|
360
|
-
const section = Math.ceil(this.context.measureText(text[c]).width);
|
|
415
|
+
const section = Math.ceil(this.context.measureText(text[c]!).width);
|
|
361
416
|
// How far to the next tab?
|
|
362
417
|
snap = snapToCeil(x, tabs);
|
|
363
418
|
if (fill) {
|
|
364
|
-
this.context.fillText(text[c]
|
|
419
|
+
this.context.fillText(text[c]!, snap, y);
|
|
365
420
|
} else {
|
|
366
|
-
this.context.strokeText(text[c]
|
|
421
|
+
this.context.strokeText(text[c]!, snap, y);
|
|
367
422
|
}
|
|
368
423
|
x = snap + section;
|
|
369
424
|
}
|
|
@@ -374,7 +429,7 @@ export class Text extends Image {
|
|
|
374
429
|
* Updates the shadow properties for this text.
|
|
375
430
|
* @param {string} state - The shadow state to update ('stroke' or 'fill').
|
|
376
431
|
*/
|
|
377
|
-
public updateShadow(state:
|
|
432
|
+
public updateShadow(state: boolean) {
|
|
378
433
|
if (state) {
|
|
379
434
|
this.context.shadowOffsetX = this.style.shadowOffsetX;
|
|
380
435
|
this.context.shadowOffsetY = this.style.shadowOffsetY;
|
|
@@ -383,7 +438,7 @@ export class Text extends Image {
|
|
|
383
438
|
} else {
|
|
384
439
|
this.context.shadowOffsetX = 0;
|
|
385
440
|
this.context.shadowOffsetY = 0;
|
|
386
|
-
this.context.shadowColor = 0;
|
|
441
|
+
this.context.shadowColor = 'rgba(0,0,0,0)';
|
|
387
442
|
this.context.shadowBlur = 0;
|
|
388
443
|
}
|
|
389
444
|
}
|
|
@@ -398,25 +453,29 @@ export class Text extends Image {
|
|
|
398
453
|
for (const letter of line) {
|
|
399
454
|
if (this.fontWeights.length > 0 || this.fontStyles.length > 0) {
|
|
400
455
|
const components = this.fontToComponents(this.context.font);
|
|
401
|
-
|
|
402
|
-
|
|
456
|
+
const charFontStyle = this.fontStyles[this._charCount];
|
|
457
|
+
const charFontWeight = this.fontWeights[this._charCount];
|
|
458
|
+
if (charFontStyle) {
|
|
459
|
+
components.fontStyle = charFontStyle;
|
|
403
460
|
}
|
|
404
|
-
if (
|
|
405
|
-
components.fontWeight =
|
|
461
|
+
if (charFontWeight) {
|
|
462
|
+
components.fontWeight = charFontWeight;
|
|
406
463
|
}
|
|
407
464
|
this.context.font = this.componentsToFont(components);
|
|
408
465
|
}
|
|
409
466
|
if (this.style.stroke && this.style.strokeThickness) {
|
|
410
|
-
|
|
411
|
-
|
|
467
|
+
const charStrokeColor = this.strokeColors[this._charCount];
|
|
468
|
+
if (charStrokeColor) {
|
|
469
|
+
this.context.strokeStyle = charStrokeColor;
|
|
412
470
|
}
|
|
413
|
-
this.updateShadow(this.style.shadowStroke);
|
|
471
|
+
this.updateShadow(this.style.shadowStroke ?? false);
|
|
414
472
|
}
|
|
415
473
|
if (this.style.fill) {
|
|
416
|
-
|
|
417
|
-
|
|
474
|
+
const charFillColor = this.colors[this._charCount];
|
|
475
|
+
if (charFillColor) {
|
|
476
|
+
this.context.fillStyle = charFillColor;
|
|
418
477
|
}
|
|
419
|
-
this.updateShadow(this.style.shadowFill);
|
|
478
|
+
this.updateShadow(this.style.shadowFill ?? false);
|
|
420
479
|
}
|
|
421
480
|
lineLength += this.context.measureText(letter).width;
|
|
422
481
|
this._charCount += 1;
|
|
@@ -434,26 +493,30 @@ export class Text extends Image {
|
|
|
434
493
|
for (const letter of line) {
|
|
435
494
|
if (this.fontWeights.length > 0 || this.fontStyles.length > 0) {
|
|
436
495
|
const components = this.fontToComponents(this.context.font);
|
|
437
|
-
|
|
438
|
-
|
|
496
|
+
const charFontStyle = this.fontStyles[this._charCount];
|
|
497
|
+
const charFontWeight = this.fontWeights[this._charCount];
|
|
498
|
+
if (charFontStyle) {
|
|
499
|
+
components.fontStyle = charFontStyle;
|
|
439
500
|
}
|
|
440
|
-
if (
|
|
441
|
-
components.fontWeight =
|
|
501
|
+
if (charFontWeight) {
|
|
502
|
+
components.fontWeight = charFontWeight;
|
|
442
503
|
}
|
|
443
504
|
this.context.font = this.componentsToFont(components);
|
|
444
505
|
}
|
|
445
506
|
if (this.style.stroke && this.style.strokeThickness) {
|
|
446
|
-
|
|
447
|
-
|
|
507
|
+
const charStrokeColor = this.strokeColors[this._charCount];
|
|
508
|
+
if (charStrokeColor) {
|
|
509
|
+
this.context.strokeStyle = charStrokeColor;
|
|
448
510
|
}
|
|
449
|
-
this.updateShadow(this.style.shadowStroke);
|
|
511
|
+
this.updateShadow(this.style.shadowStroke ?? false);
|
|
450
512
|
this.context.strokeText(letter, x, y);
|
|
451
513
|
}
|
|
452
514
|
if (this.style.fill) {
|
|
453
|
-
|
|
454
|
-
|
|
515
|
+
const charFillColor = this.colors[this._charCount];
|
|
516
|
+
if (charFillColor) {
|
|
517
|
+
this.context.fillStyle = charFillColor;
|
|
455
518
|
}
|
|
456
|
-
this.updateShadow(this.style.shadowFill);
|
|
519
|
+
this.updateShadow(this.style.shadowFill ?? false);
|
|
457
520
|
this.context.fillText(letter, x, y);
|
|
458
521
|
}
|
|
459
522
|
x += this.context.measureText(letter).width;
|
|
@@ -501,7 +564,7 @@ export class Text extends Image {
|
|
|
501
564
|
* @param {number} position - The character position to apply the stroke color at.
|
|
502
565
|
* @returns {Text} This Text object for chaining.
|
|
503
566
|
*/
|
|
504
|
-
public addStrokeColor(color:
|
|
567
|
+
public addStrokeColor(color: string, position: number) {
|
|
505
568
|
this.strokeColors[position] = color;
|
|
506
569
|
this.dirty = true;
|
|
507
570
|
return this;
|
|
@@ -513,7 +576,7 @@ export class Text extends Image {
|
|
|
513
576
|
* @param {number} position - The character position to apply the font style at.
|
|
514
577
|
* @returns {Text} This Text object for chaining.
|
|
515
578
|
*/
|
|
516
|
-
public addFontStyle(style:
|
|
579
|
+
public addFontStyle(style: string, position: number) {
|
|
517
580
|
this.fontStyles[position] = style;
|
|
518
581
|
this.dirty = true;
|
|
519
582
|
return this;
|
|
@@ -525,7 +588,7 @@ export class Text extends Image {
|
|
|
525
588
|
* @param {number} position - The character position to apply the font weight at.
|
|
526
589
|
* @returns {Text} This Text object for chaining.
|
|
527
590
|
*/
|
|
528
|
-
public addFontWeight(weight:
|
|
591
|
+
public addFontWeight(weight: string, position: number) {
|
|
529
592
|
this.fontWeights[position] = weight;
|
|
530
593
|
this.dirty = true;
|
|
531
594
|
return this;
|
|
@@ -548,7 +611,7 @@ export class Text extends Image {
|
|
|
548
611
|
* @param {string} text - The text to run word wrap on.
|
|
549
612
|
* @returns {string} The wrapped text.
|
|
550
613
|
*/
|
|
551
|
-
public runWordWrap(text:
|
|
614
|
+
public runWordWrap(text: string) {
|
|
552
615
|
if (this.useAdvancedWrap) {
|
|
553
616
|
return this.advancedWordWrap(text);
|
|
554
617
|
}
|
|
@@ -675,7 +738,7 @@ export class Text extends Image {
|
|
|
675
738
|
* Updates the font properties based on the given components.
|
|
676
739
|
* @param {object} components - The font components to update from.
|
|
677
740
|
*/
|
|
678
|
-
public updateFont(components:
|
|
741
|
+
public updateFont(components: FontComponents) {
|
|
679
742
|
const font = this.componentsToFont(components);
|
|
680
743
|
if (this.style.font !== font) {
|
|
681
744
|
this.style.font = font;
|
|
@@ -728,7 +791,7 @@ export class Text extends Image {
|
|
|
728
791
|
* @param {object} components - The font components to convert.
|
|
729
792
|
* @returns {string} The font string.
|
|
730
793
|
*/
|
|
731
|
-
public componentsToFont(components:
|
|
794
|
+
public componentsToFont(components: FontComponents) {
|
|
732
795
|
const parts = [];
|
|
733
796
|
let v;
|
|
734
797
|
v = components.fontStyle;
|
|
@@ -764,7 +827,7 @@ export class Text extends Image {
|
|
|
764
827
|
* @param {boolean} immediate - If true, updates the text immediately.
|
|
765
828
|
* @returns {Text} This Text object for chaining.
|
|
766
829
|
*/
|
|
767
|
-
public setText(text:
|
|
830
|
+
public setText(text: string | number, immediate = false) {
|
|
768
831
|
this.text = text.toString() ?? '';
|
|
769
832
|
if (immediate) {
|
|
770
833
|
this.updateText();
|
|
@@ -873,7 +936,7 @@ export class Text extends Image {
|
|
|
873
936
|
* Renders this text object using WebGL.
|
|
874
937
|
* @param {object} renderSession - The render session to use.
|
|
875
938
|
*/
|
|
876
|
-
public override renderWebGL(renderSession:
|
|
939
|
+
public override renderWebGL(renderSession: RenderSession) {
|
|
877
940
|
if (this.dirty) {
|
|
878
941
|
this.updateText();
|
|
879
942
|
this.dirty = false;
|
|
@@ -885,7 +948,7 @@ export class Text extends Image {
|
|
|
885
948
|
* Renders this text object using Canvas.
|
|
886
949
|
* @param {object} renderSession - The render session to use.
|
|
887
950
|
*/
|
|
888
|
-
public override renderCanvas(renderSession:
|
|
951
|
+
public override renderCanvas(renderSession: RenderSession) {
|
|
889
952
|
if (this.dirty) {
|
|
890
953
|
this.updateText();
|
|
891
954
|
this.dirty = false;
|
|
@@ -1091,7 +1154,7 @@ export class Text extends Image {
|
|
|
1091
1154
|
* @returns {number} The font family.
|
|
1092
1155
|
*/
|
|
1093
1156
|
public get font() {
|
|
1094
|
-
return this._fontComponents.fontFamily;
|
|
1157
|
+
return this._fontComponents.fontFamily ?? '';
|
|
1095
1158
|
}
|
|
1096
1159
|
|
|
1097
1160
|
/**
|
|
@@ -1114,12 +1177,17 @@ export class Text extends Image {
|
|
|
1114
1177
|
* Gets the font size of this object.
|
|
1115
1178
|
* @returns {number} The font size.
|
|
1116
1179
|
*/
|
|
1117
|
-
public get fontSize() {
|
|
1180
|
+
public get fontSize(): number {
|
|
1118
1181
|
const size = this._fontComponents.fontSize;
|
|
1182
|
+
if (typeof size === 'number') {
|
|
1183
|
+
return size;
|
|
1184
|
+
}
|
|
1119
1185
|
if (size && /(?:^0$|px$)/.exec(size)) {
|
|
1120
|
-
|
|
1186
|
+
// Number() cannot read the value here: the string carries a px suffix.
|
|
1187
|
+
// eslint-disable-next-line unicorn/prefer-number-coercion
|
|
1188
|
+
return Number.parseInt(size, 10);
|
|
1121
1189
|
}
|
|
1122
|
-
return
|
|
1190
|
+
return 0;
|
|
1123
1191
|
}
|
|
1124
1192
|
|
|
1125
1193
|
/**
|
|
@@ -1127,11 +1195,7 @@ export class Text extends Image {
|
|
|
1127
1195
|
* @param {number} value - The new font size to set.
|
|
1128
1196
|
*/
|
|
1129
1197
|
public set fontSize(value: number) {
|
|
1130
|
-
|
|
1131
|
-
if (typeof mutatedValue === 'number') {
|
|
1132
|
-
mutatedValue = `${mutatedValue}px`;
|
|
1133
|
-
}
|
|
1134
|
-
this._fontComponents.fontSize = mutatedValue;
|
|
1198
|
+
this._fontComponents.fontSize = value ? `${value}px` : '0';
|
|
1135
1199
|
this.updateFont(this._fontComponents);
|
|
1136
1200
|
}
|
|
1137
1201
|
|
|
@@ -1139,8 +1203,8 @@ export class Text extends Image {
|
|
|
1139
1203
|
* Gets the font weight of this object.
|
|
1140
1204
|
* @returns {string} The font weight.
|
|
1141
1205
|
*/
|
|
1142
|
-
public get fontWeight() {
|
|
1143
|
-
return this._fontComponents.fontWeight ?? 'normal';
|
|
1206
|
+
public get fontWeight(): string {
|
|
1207
|
+
return String(this._fontComponents.fontWeight ?? 'normal');
|
|
1144
1208
|
}
|
|
1145
1209
|
|
|
1146
1210
|
/**
|
|
@@ -1255,7 +1319,7 @@ export class Text extends Image {
|
|
|
1255
1319
|
* Sets the tabs setting of this object.
|
|
1256
1320
|
* @param {number} value - The new tabs setting to set.
|
|
1257
1321
|
*/
|
|
1258
|
-
public set tabs(value: number) {
|
|
1322
|
+
public set tabs(value: number | number[]) {
|
|
1259
1323
|
if (value !== this.style.tabs) {
|
|
1260
1324
|
this.style.tabs = value;
|
|
1261
1325
|
this.dirty = true;
|
|
@@ -1274,7 +1338,7 @@ export class Text extends Image {
|
|
|
1274
1338
|
* Sets the horizontal bounds alignment of this object.
|
|
1275
1339
|
* @param {number} value - The new horizontal bounds alignment to set.
|
|
1276
1340
|
*/
|
|
1277
|
-
public set boundsAlignH(value:
|
|
1341
|
+
public set boundsAlignH(value: string) {
|
|
1278
1342
|
if (value !== this.style.boundsAlignH) {
|
|
1279
1343
|
this.style.boundsAlignH = value;
|
|
1280
1344
|
this.dirty = true;
|
|
@@ -1293,7 +1357,7 @@ export class Text extends Image {
|
|
|
1293
1357
|
* Sets the vertical bounds alignment of this object.
|
|
1294
1358
|
* @param {number} value - The new vertical bounds alignment to set.
|
|
1295
1359
|
*/
|
|
1296
|
-
public set boundsAlignV(value:
|
|
1360
|
+
public set boundsAlignV(value: string) {
|
|
1297
1361
|
if (value !== this.style.boundsAlignV) {
|
|
1298
1362
|
this.style.boundsAlignV = value;
|
|
1299
1363
|
this.dirty = true;
|
|
@@ -1388,9 +1452,9 @@ export class Text extends Image {
|
|
|
1388
1452
|
* Sets the line spacing of this object.
|
|
1389
1453
|
* @param {number} value - The new line spacing to set.
|
|
1390
1454
|
*/
|
|
1391
|
-
public set lineSpacing(value:
|
|
1455
|
+
public set lineSpacing(value: number) {
|
|
1392
1456
|
if (value !== this._lineSpacing) {
|
|
1393
|
-
this._lineSpacing =
|
|
1457
|
+
this._lineSpacing = value;
|
|
1394
1458
|
this.dirty = true;
|
|
1395
1459
|
if (this.parent) {
|
|
1396
1460
|
this.updateTransform();
|
|
@@ -1479,7 +1543,7 @@ export class Text extends Image {
|
|
|
1479
1543
|
* @returns {number} The shadow stroke setting.
|
|
1480
1544
|
*/
|
|
1481
1545
|
public get shadowStroke() {
|
|
1482
|
-
return this.style.shadowStroke;
|
|
1546
|
+
return this.style.shadowStroke ?? false;
|
|
1483
1547
|
}
|
|
1484
1548
|
|
|
1485
1549
|
/**
|
|
@@ -1498,7 +1562,7 @@ export class Text extends Image {
|
|
|
1498
1562
|
* @returns {number} The shadow fill setting.
|
|
1499
1563
|
*/
|
|
1500
1564
|
public get shadowFill() {
|
|
1501
|
-
return this.style.shadowFill;
|
|
1565
|
+
return this.style.shadowFill ?? false;
|
|
1502
1566
|
}
|
|
1503
1567
|
|
|
1504
1568
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { removeByCanvas } from '../canvas/pool.js';
|
|
2
2
|
|
|
3
3
|
export class BaseTexture {
|
|
4
|
-
public resolution:
|
|
5
|
-
public width:
|
|
6
|
-
public height:
|
|
4
|
+
public resolution: number = 1;
|
|
5
|
+
public width: number = 100;
|
|
6
|
+
public height: number = 100;
|
|
7
7
|
public scaleMode!: any;
|
|
8
8
|
public hasLoaded!: any;
|
|
9
9
|
public source!: any;
|