@eva/plugin-renderer-text 2.1.0-beta.1 → 2.1.0-beta.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-text",
3
- "version": "2.1.0-beta.1",
3
+ "version": "2.1.0-beta.3",
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": "^2.0.0-beta.0",
22
- "@eva/plugin-renderer": "2.1.0-beta.1",
23
- "@eva/renderer-adapter": "2.1.0-beta.1",
24
- "@eva/eva.js": "2.1.0-beta.1",
22
+ "@eva/plugin-renderer": "2.1.0-beta.3",
23
+ "@eva/renderer-adapter": "2.1.0-beta.3",
24
+ "@eva/eva.js": "2.1.0-beta.3",
25
25
  "pixi.js": "^8.17.0"
26
26
  }
27
27
  }
@@ -1,471 +0,0 @@
1
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- globalThis.EVA = globalThis.EVA || {};
3
- globalThis.EVA.plugin = globalThis.EVA.plugin || {};
4
- globalThis.EVA.plugin.renderer = globalThis.EVA.plugin.renderer || {};
5
- var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendererAdapter) {
6
- 'use strict';
7
- function __decorate(decorators, target, key, desc) {
8
- var c = arguments.length,
9
- r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
10
- d;
11
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
12
- return c > 3 && r && Object.defineProperty(target, key, r), r;
13
- }
14
- function __metadata(metadataKey, metadataValue) {
15
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
16
- }
17
- function __awaiter(thisArg, _arguments, P, generator) {
18
- function adopt(value) {
19
- return value instanceof P ? value : new P(function (resolve) {
20
- resolve(value);
21
- });
22
- }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) {
25
- try {
26
- step(generator.next(value));
27
- } catch (e) {
28
- reject(e);
29
- }
30
- }
31
- function rejected(value) {
32
- try {
33
- step(generator["throw"](value));
34
- } catch (e) {
35
- reject(e);
36
- }
37
- }
38
- function step(result) {
39
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
40
- }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- }
44
- class BitmapTextStyleMetadata {}
45
- __decorate([eva_js.type('string'), __metadata("design:type", Object)], BitmapTextStyleMetadata.prototype, "fontFamily", void 0);
46
- __decorate([eva_js.type('number'), __metadata("design:type", Object)], BitmapTextStyleMetadata.prototype, "fontSize", void 0);
47
- __decorate([eva_js.Field({
48
- type: 'color'
49
- }), __metadata("design:type", Object)], BitmapTextStyleMetadata.prototype, "fill", void 0);
50
- __decorate([eva_js.type('string'), __metadata("design:type", String)], BitmapTextStyleMetadata.prototype, "align", void 0);
51
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], BitmapTextStyleMetadata.prototype, "letterSpacing", void 0);
52
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], BitmapTextStyleMetadata.prototype, "padding", void 0);
53
- __decorate([eva_js.Field({
54
- type: 'color'
55
- }), __metadata("design:type", Object)], BitmapTextStyleMetadata.prototype, "stroke", void 0);
56
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], BitmapTextStyleMetadata.prototype, "strokeThickness", void 0);
57
- __decorate([eva_js.type('string'), __metadata("design:type", String)], BitmapTextStyleMetadata.prototype, "fontWeight", void 0);
58
- __decorate([eva_js.type('string'), __metadata("design:type", String)], BitmapTextStyleMetadata.prototype, "fontStyle", void 0);
59
- class BitmapText extends eva_js.Component {
60
- constructor() {
61
- super(...arguments);
62
- this.text = '';
63
- this.style = {};
64
- }
65
- init(obj) {
66
- this.style = _extends({
67
- fontSize: 24,
68
- fill: '#000000',
69
- fontFamily: 'Arial'
70
- }, obj === null || obj === void 0 ? void 0 : obj.style);
71
- if (obj) {
72
- this.text = obj.text;
73
- }
74
- }
75
- }
76
- BitmapText.componentName = 'BitmapText';
77
- __decorate([eva_js.type('string'), __metadata("design:type", String)], BitmapText.prototype, "text", void 0);
78
- __decorate([eva_js.Field(() => BitmapTextStyleMetadata), __metadata("design:type", Object)], BitmapText.prototype, "style", void 0);
79
- class TextStyleStrokeMetadata {}
80
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleStrokeMetadata.prototype, "alpha", void 0);
81
- __decorate([eva_js.Field({
82
- type: 'color'
83
- }), __metadata("design:type", Object)], TextStyleStrokeMetadata.prototype, "color", void 0);
84
- __decorate([eva_js.type('string'), __metadata("design:type", String)], TextStyleStrokeMetadata.prototype, "join", void 0);
85
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleStrokeMetadata.prototype, "miterLimit", void 0);
86
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleStrokeMetadata.prototype, "width", void 0);
87
- class TextStyleDropShadowMetadata {}
88
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleDropShadowMetadata.prototype, "alpha", void 0);
89
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleDropShadowMetadata.prototype, "angle", void 0);
90
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleDropShadowMetadata.prototype, "blur", void 0);
91
- __decorate([eva_js.Field({
92
- type: 'color'
93
- }), __metadata("design:type", Object)], TextStyleDropShadowMetadata.prototype, "color", void 0);
94
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleDropShadowMetadata.prototype, "distance", void 0);
95
- __decorate([eva_js.type('boolean'), __metadata("design:type", Boolean)], TextStyleDropShadowMetadata.prototype, "enabled", void 0);
96
- class TextStyleMetadata {}
97
- __decorate([eva_js.type('string'), __metadata("design:type", String)], TextStyleMetadata.prototype, "align", void 0);
98
- __decorate([eva_js.type('boolean'), __metadata("design:type", Boolean)], TextStyleMetadata.prototype, "breakWords", void 0);
99
- __decorate([eva_js.Field(() => TextStyleDropShadowMetadata), __metadata("design:type", Object)], TextStyleMetadata.prototype, "dropShadow", void 0);
100
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleMetadata.prototype, "dropShadowAlpha", void 0);
101
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleMetadata.prototype, "dropShadowAngle", void 0);
102
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleMetadata.prototype, "dropShadowBlur", void 0);
103
- __decorate([eva_js.Field({
104
- type: 'color'
105
- }), __metadata("design:type", Object)], TextStyleMetadata.prototype, "dropShadowColor", void 0);
106
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleMetadata.prototype, "dropShadowDistance", void 0);
107
- __decorate([eva_js.Field({
108
- type: 'color'
109
- }), __metadata("design:type", Object)], TextStyleMetadata.prototype, "fill", void 0);
110
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleMetadata.prototype, "fillGradientType", void 0);
111
- __decorate([eva_js.type('number'), __metadata("design:type", Array)], TextStyleMetadata.prototype, "fillGradientStops", void 0);
112
- __decorate([eva_js.type('string'), __metadata("design:type", Object)], TextStyleMetadata.prototype, "fontFamily", void 0);
113
- __decorate([eva_js.type('number'), __metadata("design:type", Object)], TextStyleMetadata.prototype, "fontSize", void 0);
114
- __decorate([eva_js.type('string'), __metadata("design:type", String)], TextStyleMetadata.prototype, "fontStyle", void 0);
115
- __decorate([eva_js.type('string'), __metadata("design:type", String)], TextStyleMetadata.prototype, "fontVariant", void 0);
116
- __decorate([eva_js.type('string'), __metadata("design:type", String)], TextStyleMetadata.prototype, "fontWeight", void 0);
117
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleMetadata.prototype, "leading", void 0);
118
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleMetadata.prototype, "letterSpacing", void 0);
119
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleMetadata.prototype, "lineHeight", void 0);
120
- __decorate([eva_js.type('string'), __metadata("design:type", String)], TextStyleMetadata.prototype, "lineJoin", void 0);
121
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleMetadata.prototype, "miterLimit", void 0);
122
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleMetadata.prototype, "padding", void 0);
123
- __decorate([eva_js.Field(() => TextStyleStrokeMetadata), __metadata("design:type", Object)], TextStyleMetadata.prototype, "stroke", void 0);
124
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleMetadata.prototype, "strokeThickness", void 0);
125
- __decorate([eva_js.type('string'), __metadata("design:type", String)], TextStyleMetadata.prototype, "textBaseline", void 0);
126
- __decorate([eva_js.type('string'), __metadata("design:type", String)], TextStyleMetadata.prototype, "verticalAlign", void 0);
127
- __decorate([eva_js.type('boolean'), __metadata("design:type", Boolean)], TextStyleMetadata.prototype, "trim", void 0);
128
- __decorate([eva_js.type('string'), __metadata("design:type", String)], TextStyleMetadata.prototype, "whiteSpace", void 0);
129
- __decorate([eva_js.type('boolean'), __metadata("design:type", Boolean)], TextStyleMetadata.prototype, "wordWrap", void 0);
130
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], TextStyleMetadata.prototype, "wordWrapWidth", void 0);
131
- class Text$2 extends eva_js.Component {
132
- constructor(params) {
133
- super(params);
134
- this.text = '';
135
- this.style = {};
136
- this.init(params);
137
- }
138
- init(obj) {
139
- const style = new pixi_js.TextStyle({
140
- fontSize: 20
141
- });
142
- const newStyle = {};
143
- for (const key in style) {
144
- if (key.indexOf('_') === 0) {
145
- newStyle[key.substring(1)] = style[key];
146
- }
147
- }
148
- delete newStyle['styleKey'];
149
- this.style = newStyle;
150
- if (obj) {
151
- this.text = obj.text;
152
- _extends(this.style, obj.style);
153
- }
154
- }
155
- }
156
- Text$2.componentName = 'Text';
157
- __decorate([eva_js.type('string'), __metadata("design:type", String)], Text$2.prototype, "text", void 0);
158
- __decorate([eva_js.Field(() => TextStyleMetadata), __metadata("design:type", Object)], Text$2.prototype, "style", void 0);
159
- class HTMLTextTextureStyleMetadata {}
160
- __decorate([eva_js.type('string'), __metadata("design:type", String)], HTMLTextTextureStyleMetadata.prototype, "scaleMode", void 0);
161
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], HTMLTextTextureStyleMetadata.prototype, "resolution", void 0);
162
- class HTMLTextStyleMetadata {}
163
- __decorate([eva_js.type('string'), __metadata("design:type", Object)], HTMLTextStyleMetadata.prototype, "fontFamily", void 0);
164
- __decorate([eva_js.type('number'), __metadata("design:type", Object)], HTMLTextStyleMetadata.prototype, "fontSize", void 0);
165
- __decorate([eva_js.type('string'), __metadata("design:type", String)], HTMLTextStyleMetadata.prototype, "fontWeight", void 0);
166
- __decorate([eva_js.type('string'), __metadata("design:type", String)], HTMLTextStyleMetadata.prototype, "fontStyle", void 0);
167
- __decorate([eva_js.type('string'), __metadata("design:type", String)], HTMLTextStyleMetadata.prototype, "fontVariant", void 0);
168
- __decorate([eva_js.type('string'), __metadata("design:type", String)], HTMLTextStyleMetadata.prototype, "align", void 0);
169
- __decorate([eva_js.type('string'), __metadata("design:type", String)], HTMLTextStyleMetadata.prototype, "textBaseline", void 0);
170
- __decorate([eva_js.Field({
171
- type: 'color'
172
- }), __metadata("design:type", Object)], HTMLTextStyleMetadata.prototype, "fill", void 0);
173
- __decorate([eva_js.Field({
174
- type: 'color'
175
- }), __metadata("design:type", Object)], HTMLTextStyleMetadata.prototype, "stroke", void 0);
176
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], HTMLTextStyleMetadata.prototype, "strokeThickness", void 0);
177
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], HTMLTextStyleMetadata.prototype, "lineHeight", void 0);
178
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], HTMLTextStyleMetadata.prototype, "letterSpacing", void 0);
179
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], HTMLTextStyleMetadata.prototype, "padding", void 0);
180
- __decorate([eva_js.type('boolean'), __metadata("design:type", Boolean)], HTMLTextStyleMetadata.prototype, "wordWrap", void 0);
181
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], HTMLTextStyleMetadata.prototype, "wordWrapWidth", void 0);
182
- __decorate([eva_js.type('boolean'), __metadata("design:type", Boolean)], HTMLTextStyleMetadata.prototype, "breakWords", void 0);
183
- __decorate([eva_js.type('string'), __metadata("design:type", String)], HTMLTextStyleMetadata.prototype, "whiteSpace", void 0);
184
- __decorate([eva_js.type('boolean'), __metadata("design:type", Boolean)], HTMLTextStyleMetadata.prototype, "dropShadow", void 0);
185
- __decorate([eva_js.Field({
186
- type: 'color'
187
- }), __metadata("design:type", Object)], HTMLTextStyleMetadata.prototype, "dropShadowColor", void 0);
188
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], HTMLTextStyleMetadata.prototype, "dropShadowAlpha", void 0);
189
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], HTMLTextStyleMetadata.prototype, "dropShadowAngle", void 0);
190
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], HTMLTextStyleMetadata.prototype, "dropShadowBlur", void 0);
191
- __decorate([eva_js.type('number'), __metadata("design:type", Number)], HTMLTextStyleMetadata.prototype, "dropShadowDistance", void 0);
192
- __decorate([eva_js.type('object'), __metadata("design:type", Array)], HTMLTextStyleMetadata.prototype, "cssOverrides", void 0);
193
- __decorate([eva_js.type('object'), __metadata("design:type", Object)], HTMLTextStyleMetadata.prototype, "tagStyles", void 0);
194
- __decorate([eva_js.type('boolean'), __metadata("design:type", Boolean)], HTMLTextStyleMetadata.prototype, "trim", void 0);
195
- class HTMLText extends eva_js.Component {
196
- constructor() {
197
- super(...arguments);
198
- this.text = '';
199
- this.style = {};
200
- this.textureStyle = {};
201
- }
202
- init(obj) {
203
- this.style = _extends({
204
- fontSize: 24,
205
- fill: '#000000',
206
- fontFamily: 'Arial'
207
- }, obj === null || obj === void 0 ? void 0 : obj.style);
208
- this.textureStyle = _extends({
209
- scaleMode: 'linear',
210
- resolution: window.devicePixelRatio || 1
211
- }, obj === null || obj === void 0 ? void 0 : obj.textureStyle);
212
- if (obj) {
213
- this.text = obj.text;
214
- }
215
- }
216
- }
217
- HTMLText.componentName = 'HTMLText';
218
- __decorate([eva_js.type('string'), __metadata("design:type", String)], HTMLText.prototype, "text", void 0);
219
- __decorate([eva_js.Field(() => HTMLTextStyleMetadata), __metadata("design:type", Object)], HTMLText.prototype, "style", void 0);
220
- __decorate([eva_js.Field(() => HTMLTextTextureStyleMetadata), __metadata("design:type", Object)], HTMLText.prototype, "textureStyle", void 0);
221
- let Text = class Text extends pluginRenderer.Renderer {
222
- constructor() {
223
- super(...arguments);
224
- this.name = 'Text';
225
- this.texts = {};
226
- }
227
- init() {
228
- this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
229
- this.renderSystem.rendererManager.register(this);
230
- }
231
- componentChanged(changed) {
232
- return __awaiter(this, void 0, void 0, function* () {
233
- const isText = changed.componentName === 'Text';
234
- const isHTMLText = changed.componentName === 'HTMLText';
235
- const isBitmapText = changed.componentName === 'BitmapText';
236
- if (!isText && !isHTMLText && !isBitmapText) return;
237
- if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
238
- if (isText) {
239
- yield this.addTextComponent(changed);
240
- } else if (isHTMLText) {
241
- yield this.addHTMLTextComponent(changed);
242
- } else {
243
- yield this.addBitmapTextComponent(changed);
244
- }
245
- this.setSize(changed);
246
- } else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
247
- this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
248
- this.texts[changed.gameObject.id].text.destroy({
249
- children: true
250
- });
251
- delete this.texts[changed.gameObject.id];
252
- } else {
253
- this.change(changed);
254
- const component = changed.component;
255
- if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
256
- const {
257
- text
258
- } = this.texts[changed.gameObject.id];
259
- yield this.waitForFontResource(text, changed, component.style.fontFamily);
260
- }
261
- this.setSize(changed);
262
- }
263
- });
264
- }
265
- addTextComponent(changed) {
266
- return __awaiter(this, void 0, void 0, function* () {
267
- const component = changed.component;
268
- const styleWithoutFont = _extends({}, component.style);
269
- const fontFamily = styleWithoutFont.fontFamily;
270
- delete styleWithoutFont.fontFamily;
271
- const initialText = fontFamily ? '' : component.text;
272
- const text = new rendererAdapter.Text(initialText, styleWithoutFont);
273
- this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
274
- this.texts[changed.gameObject.id] = {
275
- text,
276
- component
277
- };
278
- if (fontFamily) {
279
- yield this.waitForFontResource(text, changed, fontFamily);
280
- }
281
- });
282
- }
283
- addHTMLTextComponent(changed) {
284
- return __awaiter(this, void 0, void 0, function* () {
285
- const component = changed.component;
286
- const styleWithoutFont = _extends({}, component.style);
287
- const fontFamily = styleWithoutFont.fontFamily;
288
- delete styleWithoutFont.fontFamily;
289
- const initialText = fontFamily ? '' : component.text;
290
- const htmlText = new rendererAdapter.HTMLText(_extends({
291
- text: initialText,
292
- style: styleWithoutFont
293
- }, component.textureStyle && {
294
- textureStyle: component.textureStyle
295
- }));
296
- this.containerManager.getContainer(changed.gameObject.id).addChildAt(htmlText, 0);
297
- this.texts[changed.gameObject.id] = {
298
- text: htmlText,
299
- component
300
- };
301
- if (fontFamily) {
302
- yield this.waitForFontResource(htmlText, changed, fontFamily);
303
- }
304
- });
305
- }
306
- addBitmapTextComponent(changed) {
307
- return __awaiter(this, void 0, void 0, function* () {
308
- const component = changed.component;
309
- const styleWithoutFont = _extends({}, component.style);
310
- const fontFamily = styleWithoutFont.fontFamily;
311
- delete styleWithoutFont.fontFamily;
312
- const initialText = fontFamily ? '' : component.text;
313
- const bitmapText = new rendererAdapter.BitmapText(initialText, styleWithoutFont);
314
- this.containerManager.getContainer(changed.gameObject.id).addChildAt(bitmapText, 0);
315
- this.texts[changed.gameObject.id] = {
316
- text: bitmapText,
317
- component
318
- };
319
- if (fontFamily) {
320
- yield this.waitForFontResource(bitmapText, changed, fontFamily);
321
- }
322
- });
323
- }
324
- waitForFontResource(text, changed, fontFamily) {
325
- return __awaiter(this, void 0, void 0, function* () {
326
- if (!fontFamily) {
327
- return;
328
- }
329
- try {
330
- const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
331
- const asyncId = this.increaseAsyncId(changed.gameObject.id);
332
- yield eva_js.resource.getResource(fontName);
333
- if (!this.validateAsyncId(changed.gameObject.id, asyncId)) return;
334
- const component = this.texts[changed.gameObject.id].component;
335
- text.style.fontFamily = fontFamily;
336
- text.text = component.text;
337
- } catch (error) {
338
- console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
339
- }
340
- });
341
- }
342
- processStyle(style) {
343
- const processed = _extends({}, style);
344
- if (processed.strokeThickness) {
345
- const color = processed.stroke;
346
- processed.stroke = {
347
- color,
348
- width: processed.strokeThickness
349
- };
350
- delete processed.strokeThickness;
351
- }
352
- const hasFlatDropShadowAlias = processed.dropShadowColor != null || processed.dropShadowDistance != null || processed.dropShadowAngle != null || processed.dropShadowAlpha != null || processed.dropShadowBlur != null;
353
- if (processed.dropShadow && hasFlatDropShadowAlias) {
354
- const base = processed.dropShadow && typeof processed.dropShadow === 'object' && !Array.isArray(processed.dropShadow) ? _extends({}, processed.dropShadow) : {};
355
- if (processed.dropShadowColor != null) {
356
- base.color = processed.dropShadowColor;
357
- }
358
- if (processed.dropShadowDistance != null) {
359
- base.distance = processed.dropShadowDistance;
360
- }
361
- if (processed.dropShadowAngle != null) {
362
- base.angle = processed.dropShadowAngle;
363
- }
364
- if (processed.dropShadowAlpha != null) {
365
- base.alpha = processed.dropShadowAlpha;
366
- }
367
- if (processed.dropShadowBlur != null) {
368
- base.blur = processed.dropShadowBlur;
369
- }
370
- processed.dropShadow = base;
371
- }
372
- delete processed.dropShadowColor;
373
- delete processed.dropShadowDistance;
374
- delete processed.dropShadowAngle;
375
- delete processed.dropShadowAlpha;
376
- delete processed.dropShadowBlur;
377
- if (Array.isArray(processed.fill)) {
378
- processed.fill = processed.fill[0];
379
- }
380
- if (Array.isArray(processed.fillGradientStops)) {
381
- let fontSize;
382
- if (processed.fontSize == null) {
383
- fontSize = pixi_js.TextStyle.defaultTextStyle.fontSize;
384
- } else if (typeof processed.fontSize === 'string') {
385
- fontSize = parseInt(processed.fontSize, 10);
386
- } else {
387
- fontSize = processed.fontSize;
388
- }
389
- const gradientFill = new pixi_js.FillGradient(0, 0, 0, fontSize * 1.7);
390
- const fills = processed.fillGradientStops.map(color => pixi_js.Color.shared.setValue(color).toNumber());
391
- fills.forEach((number, index) => {
392
- const ratio = index / (fills.length - 1);
393
- gradientFill.addColorStop(ratio, number);
394
- });
395
- processed.fill = {
396
- fill: gradientFill
397
- };
398
- delete processed.fillGradientStops;
399
- }
400
- return processed;
401
- }
402
- change(changed) {
403
- const {
404
- text,
405
- component
406
- } = this.texts[changed.gameObject.id];
407
- const isHTMLText = changed.componentName === 'HTMLText';
408
- if (changed.prop.prop[0] === 'text') {
409
- text.text = component.text;
410
- } else if (changed.prop.prop[0] === 'style') {
411
- const processedStyle = this.processStyle(component.style);
412
- _extends(text.style, processedStyle);
413
- } else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
414
- const htmlComponent = component;
415
- const container = this.containerManager.getContainer(changed.gameObject.id);
416
- const index = container.getChildIndex(text);
417
- container.removeChild(text);
418
- text.destroy({
419
- children: true
420
- });
421
- const newText = new rendererAdapter.HTMLText({
422
- text: htmlComponent.text,
423
- style: htmlComponent.style,
424
- textureStyle: htmlComponent.textureStyle
425
- });
426
- container.addChildAt(newText, index);
427
- this.texts[changed.gameObject.id].text = newText;
428
- }
429
- }
430
- setSize(changed) {
431
- const {
432
- transform
433
- } = changed.gameObject;
434
- if (!transform) return;
435
- const {
436
- text
437
- } = this.texts[changed.gameObject.id];
438
- const size = text.getSize();
439
- transform.size.width = size.width;
440
- transform.size.height = size.height;
441
- }
442
- };
443
- Text.systemName = 'Text';
444
- Text = __decorate([eva_js.decorators.componentObserver({
445
- Text: ['text', {
446
- prop: ['style'],
447
- deep: true
448
- }],
449
- HTMLText: ['text', {
450
- prop: ['style'],
451
- deep: true
452
- }, {
453
- prop: ['textureStyle'],
454
- deep: true
455
- }],
456
- BitmapText: ['text', {
457
- prop: ['style'],
458
- deep: true
459
- }]
460
- })], Text);
461
- var Text$1 = Text;
462
- exports.BitmapText = BitmapText;
463
- exports.HTMLText = HTMLText;
464
- exports.Text = Text$2;
465
- exports.TextSystem = Text$1;
466
- Object.defineProperty(exports, '__esModule', {
467
- value: true
468
- });
469
- return exports;
470
- }({}, EVA, PIXI, EVA.plugin.renderer, EVA.rendererAdapter);
471
- globalThis.EVA.plugin.renderer.text = globalThis.EVA.plugin.renderer.text || _EVA_IIFE_text;
@@ -1 +0,0 @@
1
- function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var i in o)({}).hasOwnProperty.call(o,i)&&(e[i]=o[i])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_text=function(e,t,o,i,n){"use strict";function r(e,t,o,i){var n,r=arguments.length,p=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)p=Reflect.decorate(e,t,o,i);else for(var d=e.length-1;d>=0;d--)(n=e[d])&&(p=(r<3?n(p):r>3?n(t,o,p):n(t,o))||p);return r>3&&p&&Object.defineProperty(t,o,p),p}function p(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function d(e,t,o,i){return new(o||(o=Promise))(function(n,r){function p(e){try{s(i.next(e))}catch(e){r(e)}}function d(e){try{s(i.throw(e))}catch(e){r(e)}}function s(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o(function(e){e(t)})).then(p,d)}s((i=i.apply(e,t||[])).next())})}class s{}r([t.type("string"),p("design:type",Object)],s.prototype,"fontFamily",void 0),r([t.type("number"),p("design:type",Object)],s.prototype,"fontSize",void 0),r([t.Field({type:"color"}),p("design:type",Object)],s.prototype,"fill",void 0),r([t.type("string"),p("design:type",String)],s.prototype,"align",void 0),r([t.type("number"),p("design:type",Number)],s.prototype,"letterSpacing",void 0),r([t.type("number"),p("design:type",Number)],s.prototype,"padding",void 0),r([t.Field({type:"color"}),p("design:type",Object)],s.prototype,"stroke",void 0),r([t.type("number"),p("design:type",Number)],s.prototype,"strokeThickness",void 0),r([t.type("string"),p("design:type",String)],s.prototype,"fontWeight",void 0),r([t.type("string"),p("design:type",String)],s.prototype,"fontStyle",void 0);class y extends t.Component{constructor(){super(...arguments),this.text="",this.style={}}init(e){this.style=_extends({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==e?void 0:e.style),e&&(this.text=e.text)}}y.componentName="BitmapText",r([t.type("string"),p("design:type",String)],y.prototype,"text",void 0),r([t.Field(()=>s),p("design:type",Object)],y.prototype,"style",void 0);class l{}r([t.type("number"),p("design:type",Number)],l.prototype,"alpha",void 0),r([t.Field({type:"color"}),p("design:type",Object)],l.prototype,"color",void 0),r([t.type("string"),p("design:type",String)],l.prototype,"join",void 0),r([t.type("number"),p("design:type",Number)],l.prototype,"miterLimit",void 0),r([t.type("number"),p("design:type",Number)],l.prototype,"width",void 0);class a{}r([t.type("number"),p("design:type",Number)],a.prototype,"alpha",void 0),r([t.type("number"),p("design:type",Number)],a.prototype,"angle",void 0),r([t.type("number"),p("design:type",Number)],a.prototype,"blur",void 0),r([t.Field({type:"color"}),p("design:type",Object)],a.prototype,"color",void 0),r([t.type("number"),p("design:type",Number)],a.prototype,"distance",void 0),r([t.type("boolean"),p("design:type",Boolean)],a.prototype,"enabled",void 0);class g{}r([t.type("string"),p("design:type",String)],g.prototype,"align",void 0),r([t.type("boolean"),p("design:type",Boolean)],g.prototype,"breakWords",void 0),r([t.Field(()=>a),p("design:type",Object)],g.prototype,"dropShadow",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"dropShadowAlpha",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"dropShadowAngle",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"dropShadowBlur",void 0),r([t.Field({type:"color"}),p("design:type",Object)],g.prototype,"dropShadowColor",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"dropShadowDistance",void 0),r([t.Field({type:"color"}),p("design:type",Object)],g.prototype,"fill",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"fillGradientType",void 0),r([t.type("number"),p("design:type",Array)],g.prototype,"fillGradientStops",void 0),r([t.type("string"),p("design:type",Object)],g.prototype,"fontFamily",void 0),r([t.type("number"),p("design:type",Object)],g.prototype,"fontSize",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"fontStyle",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"fontVariant",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"fontWeight",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"leading",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"letterSpacing",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"lineHeight",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"lineJoin",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"miterLimit",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"padding",void 0),r([t.Field(()=>l),p("design:type",Object)],g.prototype,"stroke",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"strokeThickness",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"textBaseline",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"verticalAlign",void 0),r([t.type("boolean"),p("design:type",Boolean)],g.prototype,"trim",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"whiteSpace",void 0),r([t.type("boolean"),p("design:type",Boolean)],g.prototype,"wordWrap",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"wordWrapWidth",void 0);class c extends t.Component{constructor(e){super(e),this.text="",this.style={},this.init(e)}init(e){const t=new o.TextStyle({fontSize:20}),i={};for(const e in t)0===e.indexOf("_")&&(i[e.substring(1)]=t[e]);delete i.styleKey,this.style=i,e&&(this.text=e.text,_extends(this.style,e.style))}}c.componentName="Text",r([t.type("string"),p("design:type",String)],c.prototype,"text",void 0),r([t.Field(()=>g),p("design:type",Object)],c.prototype,"style",void 0);class u{}r([t.type("string"),p("design:type",String)],u.prototype,"scaleMode",void 0),r([t.type("number"),p("design:type",Number)],u.prototype,"resolution",void 0);class m{}r([t.type("string"),p("design:type",Object)],m.prototype,"fontFamily",void 0),r([t.type("number"),p("design:type",Object)],m.prototype,"fontSize",void 0),r([t.type("string"),p("design:type",String)],m.prototype,"fontWeight",void 0),r([t.type("string"),p("design:type",String)],m.prototype,"fontStyle",void 0),r([t.type("string"),p("design:type",String)],m.prototype,"fontVariant",void 0),r([t.type("string"),p("design:type",String)],m.prototype,"align",void 0),r([t.type("string"),p("design:type",String)],m.prototype,"textBaseline",void 0),r([t.Field({type:"color"}),p("design:type",Object)],m.prototype,"fill",void 0),r([t.Field({type:"color"}),p("design:type",Object)],m.prototype,"stroke",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"strokeThickness",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"lineHeight",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"letterSpacing",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"padding",void 0),r([t.type("boolean"),p("design:type",Boolean)],m.prototype,"wordWrap",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"wordWrapWidth",void 0),r([t.type("boolean"),p("design:type",Boolean)],m.prototype,"breakWords",void 0),r([t.type("string"),p("design:type",String)],m.prototype,"whiteSpace",void 0),r([t.type("boolean"),p("design:type",Boolean)],m.prototype,"dropShadow",void 0),r([t.Field({type:"color"}),p("design:type",Object)],m.prototype,"dropShadowColor",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"dropShadowAlpha",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"dropShadowAngle",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"dropShadowBlur",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"dropShadowDistance",void 0),r([t.type("object"),p("design:type",Array)],m.prototype,"cssOverrides",void 0),r([t.type("object"),p("design:type",Object)],m.prototype,"tagStyles",void 0),r([t.type("boolean"),p("design:type",Boolean)],m.prototype,"trim",void 0);class h extends t.Component{constructor(){super(...arguments),this.text="",this.style={},this.textureStyle={}}init(e){this.style=_extends({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==e?void 0:e.style),this.textureStyle=_extends({scaleMode:"linear",resolution:window.devicePixelRatio||1},null==e?void 0:e.textureStyle),e&&(this.text=e.text)}}h.componentName="HTMLText",r([t.type("string"),p("design:type",String)],h.prototype,"text",void 0),r([t.Field(()=>m),p("design:type",Object)],h.prototype,"style",void 0),r([t.Field(()=>u),p("design:type",Object)],h.prototype,"textureStyle",void 0);let b=class extends i.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){return d(this,void 0,void 0,function*(){const o="Text"===e.componentName,i="HTMLText"===e.componentName,n="BitmapText"===e.componentName;if(o||i||n)if(e.type===t.OBSERVER_TYPE.ADD)o?yield this.addTextComponent(e):i?yield this.addHTMLTextComponent(e):yield this.addBitmapTextComponent(e),this.setSize(e);else if(e.type===t.OBSERVER_TYPE.REMOVE)this.containerManager.getContainer(e.gameObject.id).removeChild(this.texts[e.gameObject.id].text),this.texts[e.gameObject.id].text.destroy({children:!0}),delete this.texts[e.gameObject.id];else{this.change(e);const t=e.component;if("style"===e.prop.prop[0]&&t.style&&t.style.fontFamily){const{text:o}=this.texts[e.gameObject.id];yield this.waitForFontResource(o,e,t.style.fontFamily)}this.setSize(e)}})}addTextComponent(e){return d(this,void 0,void 0,function*(){const t=e.component,o=_extends({},t.style),i=o.fontFamily;delete o.fontFamily;const r=i?"":t.text,p=new n.Text(r,o);this.containerManager.getContainer(e.gameObject.id).addChildAt(p,0),this.texts[e.gameObject.id]={text:p,component:t},i&&(yield this.waitForFontResource(p,e,i))})}addHTMLTextComponent(e){return d(this,void 0,void 0,function*(){const t=e.component,o=_extends({},t.style),i=o.fontFamily;delete o.fontFamily;const r=i?"":t.text,p=new n.HTMLText(_extends({text:r,style:o},t.textureStyle&&{textureStyle:t.textureStyle}));this.containerManager.getContainer(e.gameObject.id).addChildAt(p,0),this.texts[e.gameObject.id]={text:p,component:t},i&&(yield this.waitForFontResource(p,e,i))})}addBitmapTextComponent(e){return d(this,void 0,void 0,function*(){const t=e.component,o=_extends({},t.style),i=o.fontFamily;delete o.fontFamily;const r=i?"":t.text,p=new n.BitmapText(r,o);this.containerManager.getContainer(e.gameObject.id).addChildAt(p,0),this.texts[e.gameObject.id]={text:p,component:t},i&&(yield this.waitForFontResource(p,e,i))})}waitForFontResource(e,o,i){return d(this,void 0,void 0,function*(){if(i)try{const n=Array.isArray(i)?i[0]:i,r=this.increaseAsyncId(o.gameObject.id);if(yield t.resource.getResource(n),!this.validateAsyncId(o.gameObject.id,r))return;const p=this.texts[o.gameObject.id].component;e.style.fontFamily=i,e.text=p.text}catch(e){console.warn(`字体资源 ${i} 加载失败:`,e)}})}processStyle(e){const t=_extends({},e);if(t.strokeThickness){const e=t.stroke;t.stroke={color:e,width:t.strokeThickness},delete t.strokeThickness}const i=null!=t.dropShadowColor||null!=t.dropShadowDistance||null!=t.dropShadowAngle||null!=t.dropShadowAlpha||null!=t.dropShadowBlur;if(t.dropShadow&&i){const e=t.dropShadow&&"object"==typeof t.dropShadow&&!Array.isArray(t.dropShadow)?_extends({},t.dropShadow):{};null!=t.dropShadowColor&&(e.color=t.dropShadowColor),null!=t.dropShadowDistance&&(e.distance=t.dropShadowDistance),null!=t.dropShadowAngle&&(e.angle=t.dropShadowAngle),null!=t.dropShadowAlpha&&(e.alpha=t.dropShadowAlpha),null!=t.dropShadowBlur&&(e.blur=t.dropShadowBlur),t.dropShadow=e}if(delete t.dropShadowColor,delete t.dropShadowDistance,delete t.dropShadowAngle,delete t.dropShadowAlpha,delete t.dropShadowBlur,Array.isArray(t.fill)&&(t.fill=t.fill[0]),Array.isArray(t.fillGradientStops)){let e;e=null==t.fontSize?o.TextStyle.defaultTextStyle.fontSize:"string"==typeof t.fontSize?parseInt(t.fontSize,10):t.fontSize;const i=new o.FillGradient(0,0,0,1.7*e),n=t.fillGradientStops.map(e=>o.Color.shared.setValue(e).toNumber());n.forEach((e,t)=>{const o=t/(n.length-1);i.addColorStop(o,e)}),t.fill={fill:i},delete t.fillGradientStops}return t}change(e){const{text:t,component:o}=this.texts[e.gameObject.id],i="HTMLText"===e.componentName;if("text"===e.prop.prop[0])t.text=o.text;else if("style"===e.prop.prop[0]){const e=this.processStyle(o.style);_extends(t.style,e)}else if("textureStyle"===e.prop.prop[0]&&i){const i=o,r=this.containerManager.getContainer(e.gameObject.id),p=r.getChildIndex(t);r.removeChild(t),t.destroy({children:!0});const d=new n.HTMLText({text:i.text,style:i.style,textureStyle:i.textureStyle});r.addChildAt(d,p),this.texts[e.gameObject.id].text=d}}setSize(e){const{transform:t}=e.gameObject;if(!t)return;const{text:o}=this.texts[e.gameObject.id],i=o.getSize();t.size.width=i.width,t.size.height=i.height}};b.systemName="Text",b=r([t.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}],HTMLText:["text",{prop:["style"],deep:!0},{prop:["textureStyle"],deep:!0}],BitmapText:["text",{prop:["style"],deep:!0}]})],b);var v=b;return e.BitmapText=y,e.HTMLText=h,e.Text=c,e.TextSystem=v,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,PIXI,EVA.plugin.renderer,EVA.rendererAdapter);globalThis.EVA.plugin.renderer.text=globalThis.EVA.plugin.renderer.text||_EVA_IIFE_text;