@eva/plugin-renderer-text 2.0.1-beta.9 → 2.0.2-beta.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/EVA.plugin.renderer.text.js +236 -34
- package/dist/EVA.plugin.renderer.text.min.js +1 -1
- package/dist/plugin-renderer-text.cjs.js +402 -46
- package/dist/plugin-renderer-text.cjs.prod.js +1 -16
- package/dist/plugin-renderer-text.d.ts +233 -4
- package/dist/plugin-renderer-text.esm.js +403 -49
- package/package.json +5 -5
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Component, resource, decorators, OBSERVER_TYPE } from '@eva/eva.js';
|
|
1
|
+
import { Component, decorators, OBSERVER_TYPE, resource } from '@eva/eva.js';
|
|
3
2
|
import { type } from '@eva/inspector-decorator';
|
|
3
|
+
import { TextStyle, FillGradient, Color } from 'pixi.js';
|
|
4
4
|
import { Renderer, RendererSystem } from '@eva/plugin-renderer';
|
|
5
|
-
import { Text as Text$3 } from '@eva/renderer-adapter';
|
|
5
|
+
import { HTMLText as HTMLText$1, Text as Text$3, BitmapText as BitmapText$1 } from '@eva/renderer-adapter';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
10
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
11
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
16
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
20
|
***************************************************************************** */
|
|
21
21
|
|
|
22
22
|
function __decorate(decorators, target, key, desc) {
|
|
@@ -27,20 +27,118 @@ function __decorate(decorators, target, key, desc) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
30
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
31
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
32
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
33
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
-
function step(result) { result.done ? resolve(result.value) :
|
|
34
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
35
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
36
|
});
|
|
36
|
-
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
40
|
+
var e = new Error(message);
|
|
41
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 位图文本组件
|
|
46
|
+
*
|
|
47
|
+
* BitmapText 组件使用位图字体渲染文本,性能优于 Canvas 文本渲染。
|
|
48
|
+
* 适用于频繁更新的文本场景,如计分板、倒计时等。
|
|
49
|
+
*
|
|
50
|
+
* 支持两种字体模式:
|
|
51
|
+
* - 动态生成:指定 TextStyle,PixiJS 自动生成 bitmap font
|
|
52
|
+
* - 预加载字体:通过 BitmapFont.install() 预安装或从 .fnt 文件加载
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const score = new GameObject('score');
|
|
57
|
+
* score.addComponent(new BitmapText({
|
|
58
|
+
* text: 'Score: 0',
|
|
59
|
+
* style: {
|
|
60
|
+
* fontSize: 32,
|
|
61
|
+
* fill: '#ffffff',
|
|
62
|
+
* fontFamily: 'Arial'
|
|
63
|
+
* }
|
|
64
|
+
* }));
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
class BitmapText extends Component {
|
|
68
|
+
constructor() {
|
|
69
|
+
super(...arguments);
|
|
70
|
+
this.text = '';
|
|
71
|
+
this.style = {};
|
|
72
|
+
}
|
|
73
|
+
init(obj) {
|
|
74
|
+
this.style = Object.assign({ fontSize: 24, fill: '#000000', fontFamily: 'Arial' }, obj === null || obj === void 0 ? void 0 : obj.style);
|
|
75
|
+
if (obj) {
|
|
76
|
+
this.text = obj.text;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
BitmapText.componentName = 'BitmapText';
|
|
81
|
+
__decorate([
|
|
82
|
+
type('string')
|
|
83
|
+
], BitmapText.prototype, "text", void 0);
|
|
37
84
|
|
|
85
|
+
/**
|
|
86
|
+
* 文本组件(基于 PixiJS Text)
|
|
87
|
+
*
|
|
88
|
+
* Text 组件用于渲染文本内容,支持丰富的文本样式配置。
|
|
89
|
+
* 它基于 PixiJS 的 Text 实现,支持字体、颜色、描边、阴影、对齐等多种样式。
|
|
90
|
+
*
|
|
91
|
+
* 主要特性:
|
|
92
|
+
* - 支持多种字体和字号
|
|
93
|
+
* - 支持文本颜色、渐变填充
|
|
94
|
+
* - 支持描边和投影效果
|
|
95
|
+
* - 支持文本对齐和换行
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* // 基础文本
|
|
100
|
+
* const label = new GameObject('label');
|
|
101
|
+
* label.addComponent(new Text({
|
|
102
|
+
* text: 'Hello EVA!',
|
|
103
|
+
* style: {
|
|
104
|
+
* fontSize: 32,
|
|
105
|
+
* fill: 0xffffff
|
|
106
|
+
* }
|
|
107
|
+
* }));
|
|
108
|
+
*
|
|
109
|
+
* // 带样式的文本
|
|
110
|
+
* label.addComponent(new Text({
|
|
111
|
+
* text: '得分: 9999',
|
|
112
|
+
* style: {
|
|
113
|
+
* fontFamily: 'Arial',
|
|
114
|
+
* fontSize: 48,
|
|
115
|
+
* fontWeight: 'bold',
|
|
116
|
+
* fill: ['#ff0000', '#ffff00'], // 渐变色
|
|
117
|
+
* stroke: '#000000',
|
|
118
|
+
* strokeThickness: 4,
|
|
119
|
+
* dropShadow: true,
|
|
120
|
+
* dropShadowDistance: 3
|
|
121
|
+
* }
|
|
122
|
+
* }));
|
|
123
|
+
* // 如需高清渲染,使用 Render 组件的 resolution 属性
|
|
124
|
+
* label.addComponent(new Render({ resolution: 2 }));
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
38
127
|
class Text$2 extends Component {
|
|
39
128
|
constructor() {
|
|
40
129
|
super(...arguments);
|
|
130
|
+
/** 文本内容 */
|
|
41
131
|
this.text = '';
|
|
132
|
+
/** 文本样式配置 */
|
|
133
|
+
// @decorators.IDEProp 复杂编辑后续添加
|
|
42
134
|
this.style = {};
|
|
43
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* 初始化组件
|
|
138
|
+
* @param obj - 初始化参数
|
|
139
|
+
* @param obj.text - 文本内容
|
|
140
|
+
* @param obj.style - 文本样式
|
|
141
|
+
*/
|
|
44
142
|
init(obj) {
|
|
45
143
|
const style = new TextStyle({
|
|
46
144
|
fontSize: 20,
|
|
@@ -59,11 +157,104 @@ class Text$2 extends Component {
|
|
|
59
157
|
}
|
|
60
158
|
}
|
|
61
159
|
}
|
|
160
|
+
/** 组件名称 */
|
|
62
161
|
Text$2.componentName = 'Text';
|
|
63
162
|
__decorate([
|
|
64
163
|
type('string')
|
|
65
164
|
], Text$2.prototype, "text", void 0);
|
|
66
165
|
|
|
166
|
+
/**
|
|
167
|
+
* HTML 富文本组件
|
|
168
|
+
*
|
|
169
|
+
* HTMLText 组件支持渲染带有 HTML 标签的富文本内容。
|
|
170
|
+
* 可以在文本中使用 HTML 标签(如 `<b>`, `<i>`, `<span>` 等)来实现丰富的文本样式,
|
|
171
|
+
* 适用于聊天对话、新闻内容、富文本显示等需要多样式文本的场景。
|
|
172
|
+
*
|
|
173
|
+
* 支持的 HTML 标签:
|
|
174
|
+
* - `<b>` - 粗体
|
|
175
|
+
* - `<i>` - 斜体
|
|
176
|
+
* - `<span style="color:#ff0000">` - 自定义样式
|
|
177
|
+
* - `<br>` - 换行
|
|
178
|
+
* 以及更多标准 HTML 文本标签
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* // 基础富文本
|
|
183
|
+
* const label = new GameObject('label');
|
|
184
|
+
* label.addComponent(new HTMLText({
|
|
185
|
+
* text: '这是<b>粗体</b>和<i>斜体</i>文本',
|
|
186
|
+
* style: {
|
|
187
|
+
* fontSize: 24,
|
|
188
|
+
* fill: '#000000',
|
|
189
|
+
* fontFamily: 'Arial'
|
|
190
|
+
* }
|
|
191
|
+
* }));
|
|
192
|
+
*
|
|
193
|
+
* // 带颜色的富文本
|
|
194
|
+
* label.addComponent(new HTMLText({
|
|
195
|
+
* text: '欢迎 <span style="color:#ff0000">玩家123</span> 加入游戏!',
|
|
196
|
+
* style: {
|
|
197
|
+
* fontSize: 20,
|
|
198
|
+
* wordWrap: true,
|
|
199
|
+
* wordWrapWidth: 300
|
|
200
|
+
* }
|
|
201
|
+
* }));
|
|
202
|
+
*
|
|
203
|
+
* // 自定义标签样式
|
|
204
|
+
* label.addComponent(new HTMLText({
|
|
205
|
+
* text: '获得 <gold>100</gold> 金币',
|
|
206
|
+
* style: {
|
|
207
|
+
* fontSize: 18,
|
|
208
|
+
* tagStyles: {
|
|
209
|
+
* gold: {
|
|
210
|
+
* fill: '#ffd700',
|
|
211
|
+
* fontWeight: 'bold'
|
|
212
|
+
* }
|
|
213
|
+
* }
|
|
214
|
+
* }
|
|
215
|
+
* }));
|
|
216
|
+
*
|
|
217
|
+
* // 高分辨率渲染(推荐使用 Render 组件的 resolution 属性)
|
|
218
|
+
* label.addComponent(new HTMLText({
|
|
219
|
+
* text: '高清文本',
|
|
220
|
+
* textureStyle: {
|
|
221
|
+
* scaleMode: 'linear'
|
|
222
|
+
* }
|
|
223
|
+
* }));
|
|
224
|
+
* label.addComponent(new Render({ resolution: 2 }));
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
class HTMLText extends Component {
|
|
228
|
+
constructor() {
|
|
229
|
+
super(...arguments);
|
|
230
|
+
/** 富文本内容(支持 HTML 标签) */
|
|
231
|
+
this.text = '';
|
|
232
|
+
/** 文本样式配置 */
|
|
233
|
+
this.style = {};
|
|
234
|
+
/** 纹理渲染配置 */
|
|
235
|
+
this.textureStyle = {};
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* 初始化组件
|
|
239
|
+
* @param obj - 初始化参数
|
|
240
|
+
* @param obj.text - 富文本内容
|
|
241
|
+
* @param obj.style - 文本样式
|
|
242
|
+
* @param obj.textureStyle - 纹理配置
|
|
243
|
+
*/
|
|
244
|
+
init(obj) {
|
|
245
|
+
this.style = Object.assign({ fontSize: 24, fill: '#000000', fontFamily: 'Arial' }, obj === null || obj === void 0 ? void 0 : obj.style);
|
|
246
|
+
this.textureStyle = Object.assign({ scaleMode: 'linear', resolution: window.devicePixelRatio || 1 }, obj === null || obj === void 0 ? void 0 : obj.textureStyle);
|
|
247
|
+
if (obj) {
|
|
248
|
+
this.text = obj.text;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/** 组件名称 */
|
|
253
|
+
HTMLText.componentName = 'HTMLText';
|
|
254
|
+
__decorate([
|
|
255
|
+
type('string')
|
|
256
|
+
], HTMLText.prototype, "text", void 0);
|
|
257
|
+
|
|
67
258
|
let Text = class Text extends Renderer {
|
|
68
259
|
constructor() {
|
|
69
260
|
super(...arguments);
|
|
@@ -76,16 +267,21 @@ let Text = class Text extends Renderer {
|
|
|
76
267
|
}
|
|
77
268
|
componentChanged(changed) {
|
|
78
269
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
|
|
270
|
+
const isText = changed.componentName === 'Text';
|
|
271
|
+
const isHTMLText = changed.componentName === 'HTMLText';
|
|
272
|
+
const isBitmapText = changed.componentName === 'BitmapText';
|
|
273
|
+
if (!isText && !isHTMLText && !isBitmapText)
|
|
80
274
|
return;
|
|
81
275
|
if (changed.type === OBSERVER_TYPE.ADD) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
276
|
+
if (isText) {
|
|
277
|
+
yield this.addTextComponent(changed);
|
|
278
|
+
}
|
|
279
|
+
else if (isHTMLText) {
|
|
280
|
+
yield this.addHTMLTextComponent(changed);
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
yield this.addBitmapTextComponent(changed);
|
|
284
|
+
}
|
|
89
285
|
this.setSize(changed);
|
|
90
286
|
}
|
|
91
287
|
else if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
@@ -95,55 +291,213 @@ let Text = class Text extends Renderer {
|
|
|
95
291
|
}
|
|
96
292
|
else {
|
|
97
293
|
this.change(changed);
|
|
294
|
+
// 如果样式改变且涉及字体,也需要等待字体资源加载
|
|
295
|
+
const component = changed.component;
|
|
296
|
+
if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
|
|
297
|
+
const { text } = this.texts[changed.gameObject.id];
|
|
298
|
+
yield this.waitForFontResource(text, changed, component.style.fontFamily);
|
|
299
|
+
}
|
|
98
300
|
this.setSize(changed);
|
|
99
301
|
}
|
|
100
302
|
});
|
|
101
303
|
}
|
|
304
|
+
addTextComponent(changed) {
|
|
305
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
+
const component = changed.component;
|
|
307
|
+
// 创建文本样式副本,先不设置 fontFamily
|
|
308
|
+
const styleWithoutFont = Object.assign({}, component.style);
|
|
309
|
+
const fontFamily = styleWithoutFont.fontFamily;
|
|
310
|
+
delete styleWithoutFont.fontFamily;
|
|
311
|
+
const initialText = fontFamily ? '' : component.text;
|
|
312
|
+
const text = new Text$3(initialText, styleWithoutFont);
|
|
313
|
+
this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
|
|
314
|
+
this.texts[changed.gameObject.id] = {
|
|
315
|
+
text,
|
|
316
|
+
component,
|
|
317
|
+
};
|
|
318
|
+
// 如果指定了字体资源,等待资源加载完成后设置 fontFamily
|
|
319
|
+
if (fontFamily) {
|
|
320
|
+
yield this.waitForFontResource(text, changed, fontFamily);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
addHTMLTextComponent(changed) {
|
|
325
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
326
|
+
const component = changed.component;
|
|
327
|
+
// 创建样式副本,先不设置 fontFamily
|
|
328
|
+
const styleWithoutFont = Object.assign({}, component.style);
|
|
329
|
+
const fontFamily = styleWithoutFont.fontFamily;
|
|
330
|
+
delete styleWithoutFont.fontFamily;
|
|
331
|
+
const initialText = fontFamily ? '' : component.text;
|
|
332
|
+
const htmlText = new HTMLText$1(Object.assign({ text: initialText, style: styleWithoutFont }, (component.textureStyle && { textureStyle: component.textureStyle })));
|
|
333
|
+
this.containerManager.getContainer(changed.gameObject.id).addChildAt(htmlText, 0);
|
|
334
|
+
this.texts[changed.gameObject.id] = {
|
|
335
|
+
text: htmlText,
|
|
336
|
+
component,
|
|
337
|
+
};
|
|
338
|
+
// 如果指定了字体资源,等待资源加载完成后设置 fontFamily
|
|
339
|
+
if (fontFamily) {
|
|
340
|
+
yield this.waitForFontResource(htmlText, changed, fontFamily);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
addBitmapTextComponent(changed) {
|
|
345
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
346
|
+
const component = changed.component;
|
|
347
|
+
// 创建样式副本,先不设置 fontFamily
|
|
348
|
+
const styleWithoutFont = Object.assign({}, component.style);
|
|
349
|
+
const fontFamily = styleWithoutFont.fontFamily;
|
|
350
|
+
delete styleWithoutFont.fontFamily;
|
|
351
|
+
const initialText = fontFamily ? '' : component.text;
|
|
352
|
+
const bitmapText = new BitmapText$1(initialText, styleWithoutFont);
|
|
353
|
+
this.containerManager.getContainer(changed.gameObject.id).addChildAt(bitmapText, 0);
|
|
354
|
+
this.texts[changed.gameObject.id] = {
|
|
355
|
+
text: bitmapText,
|
|
356
|
+
component,
|
|
357
|
+
};
|
|
358
|
+
// 如果指定了字体资源,等待资源加载完成后设置 fontFamily
|
|
359
|
+
if (fontFamily) {
|
|
360
|
+
yield this.waitForFontResource(bitmapText, changed, fontFamily);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* 等待字体资源加载完成并更新文本
|
|
366
|
+
*/
|
|
367
|
+
waitForFontResource(text, changed, fontFamily) {
|
|
368
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
369
|
+
if (!fontFamily) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
try {
|
|
373
|
+
const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
|
|
374
|
+
// 通过 resource 系统获取字体资源
|
|
375
|
+
const asyncId = this.increaseAsyncId(changed.gameObject.id);
|
|
376
|
+
yield resource.getResource(fontName);
|
|
377
|
+
// 验证异步操作是否仍然有效(防止组件已被移除)
|
|
378
|
+
if (!this.validateAsyncId(changed.gameObject.id, asyncId))
|
|
379
|
+
return;
|
|
380
|
+
// 字体资源加载成功后,设置 fontFamily 并重新设置文本内容以触发重新渲染
|
|
381
|
+
const component = this.texts[changed.gameObject.id].component;
|
|
382
|
+
text.style.fontFamily = fontFamily;
|
|
383
|
+
text.text = component.text;
|
|
384
|
+
// 更新尺寸
|
|
385
|
+
}
|
|
386
|
+
catch (error) {
|
|
387
|
+
console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* 将 Eva.js 的样式格式转换为 PixiJS v8 格式
|
|
393
|
+
*/
|
|
394
|
+
processStyle(style) {
|
|
395
|
+
const processed = Object.assign({}, style);
|
|
396
|
+
// stroke + strokeThickness -> stroke: { color, width }
|
|
397
|
+
if (processed.strokeThickness) {
|
|
398
|
+
const color = processed.stroke;
|
|
399
|
+
processed.stroke = {
|
|
400
|
+
color,
|
|
401
|
+
width: processed.strokeThickness,
|
|
402
|
+
};
|
|
403
|
+
delete processed.strokeThickness;
|
|
404
|
+
}
|
|
405
|
+
// dropShadow* -> dropShadow: { color, distance, angle, alpha, blur }
|
|
406
|
+
if (processed.dropShadow) {
|
|
407
|
+
const dropShadowConfig = {};
|
|
408
|
+
if (processed.dropShadowColor != null) {
|
|
409
|
+
dropShadowConfig.color = processed.dropShadowColor;
|
|
410
|
+
}
|
|
411
|
+
if (processed.dropShadowDistance != null) {
|
|
412
|
+
dropShadowConfig.distance = processed.dropShadowDistance;
|
|
413
|
+
}
|
|
414
|
+
if (processed.dropShadowAngle != null) {
|
|
415
|
+
dropShadowConfig.angle = processed.dropShadowAngle;
|
|
416
|
+
}
|
|
417
|
+
if (processed.dropShadowAlpha != null) {
|
|
418
|
+
dropShadowConfig.alpha = processed.dropShadowAlpha;
|
|
419
|
+
}
|
|
420
|
+
if (processed.dropShadowBlur != null) {
|
|
421
|
+
dropShadowConfig.blur = processed.dropShadowBlur;
|
|
422
|
+
}
|
|
423
|
+
processed.dropShadow = dropShadowConfig;
|
|
424
|
+
delete processed.dropShadowColor;
|
|
425
|
+
delete processed.dropShadowDistance;
|
|
426
|
+
delete processed.dropShadowAngle;
|
|
427
|
+
delete processed.dropShadowAlpha;
|
|
428
|
+
delete processed.dropShadowBlur;
|
|
429
|
+
}
|
|
430
|
+
// fill 数组 -> 取第一个值 (deprecated)
|
|
431
|
+
if (Array.isArray(processed.fill)) {
|
|
432
|
+
processed.fill = processed.fill[0];
|
|
433
|
+
}
|
|
434
|
+
// fillGradientStops -> FillGradient 对象
|
|
435
|
+
if (Array.isArray(processed.fillGradientStops)) {
|
|
436
|
+
let fontSize;
|
|
437
|
+
if (processed.fontSize == null) {
|
|
438
|
+
fontSize = TextStyle.defaultTextStyle.fontSize;
|
|
439
|
+
}
|
|
440
|
+
else if (typeof processed.fontSize === 'string') {
|
|
441
|
+
fontSize = parseInt(processed.fontSize, 10);
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
fontSize = processed.fontSize;
|
|
445
|
+
}
|
|
446
|
+
const gradientFill = new FillGradient(0, 0, 0, fontSize * 1.7);
|
|
447
|
+
const fills = processed.fillGradientStops.map((color) => Color.shared.setValue(color).toNumber());
|
|
448
|
+
fills.forEach((number, index) => {
|
|
449
|
+
const ratio = index / (fills.length - 1);
|
|
450
|
+
gradientFill.addColorStop(ratio, number);
|
|
451
|
+
});
|
|
452
|
+
processed.fill = { fill: gradientFill };
|
|
453
|
+
delete processed.fillGradientStops;
|
|
454
|
+
}
|
|
455
|
+
return processed;
|
|
456
|
+
}
|
|
102
457
|
change(changed) {
|
|
103
458
|
const { text, component } = this.texts[changed.gameObject.id];
|
|
459
|
+
const isHTMLText = changed.componentName === 'HTMLText';
|
|
104
460
|
if (changed.prop.prop[0] === 'text') {
|
|
105
461
|
text.text = component.text;
|
|
106
462
|
}
|
|
107
463
|
else if (changed.prop.prop[0] === 'style') {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
asyncChangeTextStyle(text, textStyle) {
|
|
112
|
-
if (textStyle.fontFamily) {
|
|
113
|
-
const fontFamily = textStyle.fontFamily;
|
|
114
|
-
textStyle.fontFamily = '';
|
|
115
|
-
this.asyncUpdateFontFamily(text, fontFamily);
|
|
464
|
+
const processedStyle = this.processStyle(component.style);
|
|
465
|
+
Object.assign(text.style, processedStyle);
|
|
116
466
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
467
|
+
else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
|
|
468
|
+
// HTMLText 纹理样式变化需要重新创建
|
|
469
|
+
const htmlComponent = component;
|
|
470
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
471
|
+
const index = container.getChildIndex(text);
|
|
472
|
+
container.removeChild(text);
|
|
473
|
+
text.destroy({ children: true });
|
|
474
|
+
const newText = new HTMLText$1({
|
|
475
|
+
text: htmlComponent.text,
|
|
476
|
+
style: htmlComponent.style,
|
|
477
|
+
textureStyle: htmlComponent.textureStyle
|
|
478
|
+
});
|
|
479
|
+
container.addChildAt(newText, index);
|
|
480
|
+
this.texts[changed.gameObject.id].text = newText;
|
|
131
481
|
}
|
|
132
482
|
}
|
|
133
483
|
setSize(changed) {
|
|
134
484
|
const { transform } = changed.gameObject;
|
|
135
485
|
if (!transform)
|
|
136
486
|
return;
|
|
137
|
-
|
|
138
|
-
|
|
487
|
+
const { text } = this.texts[changed.gameObject.id];
|
|
488
|
+
const size = text.getSize();
|
|
489
|
+
transform.size.width = size.width;
|
|
490
|
+
transform.size.height = size.height;
|
|
139
491
|
}
|
|
140
492
|
};
|
|
141
493
|
Text.systemName = 'Text';
|
|
142
494
|
Text = __decorate([
|
|
143
495
|
decorators.componentObserver({
|
|
144
496
|
Text: ['text', { prop: ['style'], deep: true }],
|
|
497
|
+
HTMLText: ['text', { prop: ['style'], deep: true }, { prop: ['textureStyle'], deep: true }],
|
|
498
|
+
BitmapText: ['text', { prop: ['style'], deep: true }],
|
|
145
499
|
})
|
|
146
500
|
], Text);
|
|
147
501
|
var Text$1 = Text;
|
|
148
502
|
|
|
149
|
-
export { Text$2 as Text, Text$1 as TextSystem };
|
|
503
|
+
export { BitmapText, HTMLText, Text$2 as Text, Text$1 as TextSystem };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-text",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2-beta.0",
|
|
4
4
|
"description": "@eva/plugin-renderer-text",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-renderer-text.esm.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@eva/inspector-decorator": "^0.0.5",
|
|
22
|
-
"@eva/plugin-renderer": "2.0.
|
|
23
|
-
"@eva/renderer-adapter": "2.0.
|
|
24
|
-
"@eva/eva.js": "2.0.
|
|
25
|
-
"pixi.js": "^8.
|
|
22
|
+
"@eva/plugin-renderer": "2.0.2-beta.0",
|
|
23
|
+
"@eva/renderer-adapter": "2.0.2-beta.0",
|
|
24
|
+
"@eva/eva.js": "2.0.2-beta.0",
|
|
25
|
+
"pixi.js": "^8.17.0"
|
|
26
26
|
}
|
|
27
27
|
}
|