@eva/plugin-renderer-text 2.0.1-beta.9 → 2.0.1

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.
@@ -1,6 +1,8 @@
1
+ import { BitmapText as BitmapText_2 } from '@eva/renderer-adapter';
1
2
  import { Component } from '@eva/eva.js';
2
3
  import { ComponentChanged } from '@eva/eva.js';
3
4
  import { ContainerManager } from '@eva/plugin-renderer';
5
+ import { HTMLText as HTMLText_2 } from '@eva/renderer-adapter';
4
6
  import { Renderer } from '@eva/plugin-renderer';
5
7
  import { RendererManager } from '@eva/plugin-renderer';
6
8
  import { RendererSystem } from '@eva/plugin-renderer';
@@ -12,10 +14,228 @@ import { TextStyleFontWeight } from 'pixi.js';
12
14
  import { TextStyleTextBaseline } from 'pixi.js';
13
15
  import { TextStyleWhiteSpace } from 'pixi.js';
14
16
 
17
+ /**
18
+ * 位图文本组件
19
+ *
20
+ * BitmapText 组件使用位图字体渲染文本,性能优于 Canvas 文本渲染。
21
+ * 适用于频繁更新的文本场景,如计分板、倒计时等。
22
+ *
23
+ * 支持两种字体模式:
24
+ * - 动态生成:指定 TextStyle,PixiJS 自动生成 bitmap font
25
+ * - 预加载字体:通过 BitmapFont.install() 预安装或从 .fnt 文件加载
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const score = new GameObject('score');
30
+ * score.addComponent(new BitmapText({
31
+ * text: 'Score: 0',
32
+ * style: {
33
+ * fontSize: 32,
34
+ * fill: '#ffffff',
35
+ * fontFamily: 'Arial'
36
+ * }
37
+ * }));
38
+ * ```
39
+ */
40
+ export declare class BitmapText extends Component<BitmapTextParams> {
41
+ static componentName: string;
42
+ text: string;
43
+ style: BitmapTextStyleOptions;
44
+ init(obj?: BitmapTextParams): void;
45
+ }
46
+
47
+ export declare interface BitmapTextParams {
48
+ text: string;
49
+ style?: BitmapTextStyleOptions;
50
+ }
51
+
52
+ declare interface BitmapTextStyleOptions {
53
+ fontFamily?: string | string[];
54
+ fontSize?: number | string;
55
+ fill?: string | number;
56
+ align?: 'left' | 'center' | 'right' | 'justify';
57
+ letterSpacing?: number;
58
+ padding?: number;
59
+ stroke?: string | number;
60
+ strokeThickness?: number;
61
+ fontWeight?: TextStyleFontWeight;
62
+ fontStyle?: TextStyleFontStyle;
63
+ }
64
+
65
+ /**
66
+ * HTML 富文本组件
67
+ *
68
+ * HTMLText 组件支持渲染带有 HTML 标签的富文本内容。
69
+ * 可以在文本中使用 HTML 标签(如 `<b>`, `<i>`, `<span>` 等)来实现丰富的文本样式,
70
+ * 适用于聊天对话、新闻内容、富文本显示等需要多样式文本的场景。
71
+ *
72
+ * 支持的 HTML 标签:
73
+ * - `<b>` - 粗体
74
+ * - `<i>` - 斜体
75
+ * - `<span style="color:#ff0000">` - 自定义样式
76
+ * - `<br>` - 换行
77
+ * 以及更多标准 HTML 文本标签
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * // 基础富文本
82
+ * const label = new GameObject('label');
83
+ * label.addComponent(new HTMLText({
84
+ * text: '这是<b>粗体</b>和<i>斜体</i>文本',
85
+ * style: {
86
+ * fontSize: 24,
87
+ * fill: '#000000',
88
+ * fontFamily: 'Arial'
89
+ * }
90
+ * }));
91
+ *
92
+ * // 带颜色的富文本
93
+ * label.addComponent(new HTMLText({
94
+ * text: '欢迎 <span style="color:#ff0000">玩家123</span> 加入游戏!',
95
+ * style: {
96
+ * fontSize: 20,
97
+ * wordWrap: true,
98
+ * wordWrapWidth: 300
99
+ * }
100
+ * }));
101
+ *
102
+ * // 自定义标签样式
103
+ * label.addComponent(new HTMLText({
104
+ * text: '获得 <gold>100</gold> 金币',
105
+ * style: {
106
+ * fontSize: 18,
107
+ * tagStyles: {
108
+ * gold: {
109
+ * fill: '#ffd700',
110
+ * fontWeight: 'bold'
111
+ * }
112
+ * }
113
+ * }
114
+ * }));
115
+ *
116
+ * // 高分辨率渲染(推荐使用 Render 组件的 resolution 属性)
117
+ * label.addComponent(new HTMLText({
118
+ * text: '高清文本',
119
+ * textureStyle: {
120
+ * scaleMode: 'linear'
121
+ * }
122
+ * }));
123
+ * label.addComponent(new Render({ resolution: 2 }));
124
+ * ```
125
+ */
126
+ export declare class HTMLText extends Component<HTMLTextParams> {
127
+ /** 组件名称 */
128
+ static componentName: string;
129
+ /** 富文本内容(支持 HTML 标签) */
130
+ text: string;
131
+ /** 文本样式配置 */
132
+ style: HTMLTextParams['style'];
133
+ /** 纹理渲染配置 */
134
+ textureStyle: HTMLTextParams['textureStyle'];
135
+ /**
136
+ * 初始化组件
137
+ * @param obj - 初始化参数
138
+ * @param obj.text - 富文本内容
139
+ * @param obj.style - 文本样式
140
+ * @param obj.textureStyle - 纹理配置
141
+ */
142
+ init(obj?: HTMLTextParams): void;
143
+ }
144
+
145
+ export declare interface HTMLTextParams {
146
+ text: string;
147
+ style?: HTMLTextStyleOptions & {
148
+ cssOverrides?: string[];
149
+ wordWrap?: boolean;
150
+ wordWrapWidth?: number;
151
+ tagStyles?: Record<string, HTMLTextStyleOptions>;
152
+ };
153
+ textureStyle?: {
154
+ scaleMode?: 'linear' | 'nearest';
155
+ resolution?: number;
156
+ };
157
+ }
158
+
159
+ declare interface HTMLTextStyleOptions {
160
+ fontFamily?: string | string[];
161
+ fontSize?: number | string;
162
+ fill?: string | number;
163
+ align?: 'left' | 'center' | 'right' | 'justify';
164
+ breakWords?: boolean;
165
+ letterSpacing?: number;
166
+ lineHeight?: number;
167
+ padding?: number;
168
+ stroke?: string | number;
169
+ strokeThickness?: number;
170
+ dropShadow?: boolean;
171
+ dropShadowAlpha?: number;
172
+ dropShadowAngle?: number;
173
+ dropShadowBlur?: number;
174
+ dropShadowColor?: string | number;
175
+ dropShadowDistance?: number;
176
+ trim?: boolean;
177
+ fontWeight?: string;
178
+ fontStyle?: string;
179
+ fontVariant?: string;
180
+ textBaseline?: string;
181
+ whiteSpace?: string;
182
+ }
183
+
184
+ /**
185
+ * 文本组件(基于 PixiJS Text)
186
+ *
187
+ * Text 组件用于渲染文本内容,支持丰富的文本样式配置。
188
+ * 它基于 PixiJS 的 Text 实现,支持字体、颜色、描边、阴影、对齐等多种样式。
189
+ *
190
+ * 主要特性:
191
+ * - 支持多种字体和字号
192
+ * - 支持文本颜色、渐变填充
193
+ * - 支持描边和投影效果
194
+ * - 支持文本对齐和换行
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * // 基础文本
199
+ * const label = new GameObject('label');
200
+ * label.addComponent(new Text({
201
+ * text: 'Hello EVA!',
202
+ * style: {
203
+ * fontSize: 32,
204
+ * fill: 0xffffff
205
+ * }
206
+ * }));
207
+ *
208
+ * // 带样式的文本
209
+ * label.addComponent(new Text({
210
+ * text: '得分: 9999',
211
+ * style: {
212
+ * fontFamily: 'Arial',
213
+ * fontSize: 48,
214
+ * fontWeight: 'bold',
215
+ * fill: ['#ff0000', '#ffff00'], // 渐变色
216
+ * stroke: '#000000',
217
+ * strokeThickness: 4,
218
+ * dropShadow: true,
219
+ * dropShadowDistance: 3
220
+ * }
221
+ * }));
222
+ * // 如需高清渲染,使用 Render 组件的 resolution 属性
223
+ * label.addComponent(new Render({ resolution: 2 }));
224
+ * ```
225
+ */
15
226
  declare class Text_2 extends Component<TextParams> {
227
+ /** 组件名称 */
16
228
  static componentName: string;
229
+ /** 文本内容 */
17
230
  text: string;
231
+ /** 文本样式配置 */
18
232
  style: TextParams['style'];
233
+ /**
234
+ * 初始化组件
235
+ * @param obj - 初始化参数
236
+ * @param obj.text - 文本内容
237
+ * @param obj.style - 文本样式
238
+ */
19
239
  init(obj?: TextParams): void;
20
240
  }
21
241
  export { Text_2 as Text }
@@ -60,8 +280,8 @@ export declare class TextSystem extends Renderer {
60
280
  name: string;
61
281
  texts: {
62
282
  [propName: number]: {
63
- text: Text_3;
64
- component: Text_2;
283
+ text: Text_3 | HTMLText_2 | BitmapText_2;
284
+ component: Text_2 | HTMLText | BitmapText;
65
285
  };
66
286
  };
67
287
  renderSystem: RendererSystem;
@@ -69,9 +289,18 @@ export declare class TextSystem extends Renderer {
69
289
  containerManager: ContainerManager;
70
290
  init(): void;
71
291
  componentChanged(changed: ComponentChanged): Promise<void>;
292
+ private addTextComponent;
293
+ private addHTMLTextComponent;
294
+ private addBitmapTextComponent;
295
+ /**
296
+ * 等待字体资源加载完成并更新文本
297
+ */
298
+ private waitForFontResource;
299
+ /**
300
+ * 将 Eva.js 的样式格式转换为 PixiJS v8 格式
301
+ */
302
+ private processStyle;
72
303
  change(changed: ComponentChanged): void;
73
- asyncChangeTextStyle(text: Text_3, textStyle: TextParams['style']): void;
74
- asyncUpdateFontFamily(text: Text_3, fontFamily: string | string[] | undefined): void;
75
304
  setSize(changed: ComponentChanged): void;
76
305
  }
77
306