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

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