@eva/plugin-renderer-text 2.1.0-beta.13 → 2.1.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,18 @@
1
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
+ var globalThis = typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : Function('return this')();
2
3
  globalThis.EVA = globalThis.EVA || {};
3
4
  globalThis.EVA.plugin = globalThis.EVA.plugin || {};
4
5
  globalThis.EVA.plugin.renderer = globalThis.EVA.plugin.renderer || {};
5
6
  var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendererAdapter) {
6
7
  'use strict';
8
+ function __rest(s, e) {
9
+ var t = {};
10
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
11
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
12
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
13
+ }
14
+ return t;
15
+ }
7
16
  function __decorate(decorators, target, key, desc) {
8
17
  var c = arguments.length,
9
18
  r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
@@ -41,10 +50,6 @@ var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendere
41
50
  step((generator = generator.apply(thisArg, _arguments || [])).next());
42
51
  });
43
52
  }
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
53
  class BitmapTextStyleMetadata {}
49
54
  __decorate([eva_js.type('string'), __metadata("design:type", Object)], BitmapTextStyleMetadata.prototype, "fontFamily", void 0);
50
55
  __decorate([eva_js.type('number'), __metadata("design:type", Object)], BitmapTextStyleMetadata.prototype, "fontSize", void 0);
@@ -226,132 +231,263 @@ var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendere
226
231
  constructor() {
227
232
  super(...arguments);
228
233
  this.name = 'Text';
234
+ this.presentationAddFlushEnabled = true;
229
235
  this.texts = {};
236
+ this.retired = false;
237
+ this.pendingHTMLTextComponents = {};
238
+ this.fontIdentityIds = new WeakMap();
239
+ this.nextFontIdentityId = 1;
230
240
  }
231
241
  init() {
232
242
  this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
233
243
  this.renderSystem.rendererManager.register(this);
234
244
  }
245
+ shouldFlushPresentationAddition(changed) {
246
+ return changed.componentName === 'Text' || changed.componentName === 'HTMLText' || changed.componentName === 'BitmapText';
247
+ }
235
248
  componentChanged(changed) {
249
+ var _a, _b, _c, _d, _e;
236
250
  return __awaiter(this, void 0, void 0, function* () {
251
+ if (this.retired) return;
237
252
  const isText = changed.componentName === 'Text';
238
253
  const isHTMLText = changed.componentName === 'HTMLText';
239
254
  const isBitmapText = changed.componentName === 'BitmapText';
240
255
  if (!isText && !isHTMLText && !isBitmapText) return;
256
+ const gameObjectId = changed.gameObject.id;
241
257
  if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
242
258
  if (isText) {
243
- yield this.addTextComponent(changed);
259
+ const loading = this.addTextComponent(changed);
260
+ if (loading) yield loading;
244
261
  } else if (isHTMLText) {
245
- yield this.addHTMLTextComponent(changed);
262
+ const loading = this.addHTMLTextComponent(changed);
263
+ if (loading) yield loading;
246
264
  } else {
247
- yield this.addBitmapTextComponent(changed);
265
+ const loading = this.addBitmapTextComponent(changed);
266
+ if (loading) yield loading;
267
+ }
268
+ if (((_a = this.texts[gameObjectId]) === null || _a === void 0 ? void 0 : _a.component) === changed.component) {
269
+ this.setSize(changed);
248
270
  }
249
- this.setSize(changed);
250
271
  } 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({
272
+ if (((_b = this.texts[gameObjectId]) === null || _b === void 0 ? void 0 : _b.component) !== changed.component && this.pendingHTMLTextComponents[gameObjectId] !== changed.component) return;
273
+ this.increaseAsyncId(gameObjectId);
274
+ if (this.pendingHTMLTextComponents[gameObjectId] === changed.component) {
275
+ delete this.pendingHTMLTextComponents[gameObjectId];
276
+ }
277
+ const current = this.texts[gameObjectId];
278
+ if (!current || current.component !== changed.component) return;
279
+ this.containerManager.getContainer(gameObjectId).removeChild(current.text);
280
+ current.text.destroy({
253
281
  children: true
254
282
  });
255
- delete this.texts[changed.gameObject.id];
283
+ delete this.texts[gameObjectId];
256
284
  } else {
257
- this.change(changed);
258
285
  const component = changed.component;
259
- if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
286
+ const propPath = changed.prop.prop;
287
+ const fontFamilyChanged = propPath[0] === 'style' && (propPath.length === 1 || propPath[1] === 'fontFamily');
288
+ const current = this.texts[gameObjectId];
289
+ if (!current) {
290
+ if (isHTMLText && this.pendingHTMLTextComponents[gameObjectId] === component && fontFamilyChanged) {
291
+ yield this.addHTMLTextComponent(changed);
292
+ if (((_c = this.texts[gameObjectId]) === null || _c === void 0 ? void 0 : _c.component) === component) {
293
+ this.setSize(changed);
294
+ }
295
+ }
296
+ return;
297
+ }
298
+ if (current.component !== component) return;
299
+ const waitsForFontResource = fontFamilyChanged && component.style && this.needsFontLoad(component.style.fontFamily);
300
+ if (fontFamilyChanged && !waitsForFontResource) {
301
+ this.increaseAsyncId(gameObjectId);
302
+ }
303
+ this.change(changed);
304
+ if (waitsForFontResource) {
260
305
  const {
261
306
  text
262
- } = this.texts[changed.gameObject.id];
307
+ } = current;
263
308
  yield this.waitForFontResource(text, changed, component.style.fontFamily);
264
309
  }
265
- this.setSize(changed);
310
+ if (((_d = this.texts[gameObjectId]) === null || _d === void 0 ? void 0 : _d.text) === current.text && ((_e = this.texts[gameObjectId]) === null || _e === void 0 ? void 0 : _e.component) === component) {
311
+ this.setSize(changed);
312
+ }
266
313
  }
267
314
  });
268
315
  }
269
316
  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
- });
317
+ const component = changed.component;
318
+ const styleWithoutFont = this.processStyle(component.style);
319
+ const fontFamily = styleWithoutFont.fontFamily;
320
+ const waitsForFontResource = this.needsFontLoad(fontFamily);
321
+ if (waitsForFontResource) delete styleWithoutFont.fontFamily;
322
+ const initialText = waitsForFontResource ? '' : component.text;
323
+ const text = new rendererAdapter.Text(initialText, styleWithoutFont);
324
+ this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
325
+ this.texts[changed.gameObject.id] = {
326
+ text,
327
+ component,
328
+ awaitingInitialFont: waitsForFontResource
329
+ };
330
+ if (waitsForFontResource) {
331
+ return this.waitForFontResource(text, changed, fontFamily);
332
+ }
286
333
  }
287
334
  addHTMLTextComponent(changed) {
335
+ const component = changed.component;
336
+ const gameObjectId = changed.gameObject.id;
337
+ const initialStyle = this.processStyle(component.style);
338
+ const fontFamily = initialStyle.fontFamily;
339
+ const waitsForFontResource = this.needsFontLoad(fontFamily);
340
+ if (waitsForFontResource) {
341
+ this.pendingHTMLTextComponents[gameObjectId] = component;
342
+ return this.addHTMLTextAfterFont(changed, component, fontFamily, this.increaseAsyncId(gameObjectId));
343
+ } else if (this.pendingHTMLTextComponents[gameObjectId] === component) {
344
+ delete this.pendingHTMLTextComponents[gameObjectId];
345
+ }
346
+ this.mountHTMLText(changed, component);
347
+ }
348
+ addHTMLTextAfterFont(changed, component, fontFamily, asyncId) {
349
+ var _a;
288
350
  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
- }
351
+ const gameObjectId = changed.gameObject.id;
352
+ const fontName = this.getFontName(fontFamily);
353
+ const loaded = yield this.loadFontResource(fontFamily);
354
+ if (!loaded || this.retired || changed.gameObject.destroyed || !this.validateAsyncId(gameObjectId, asyncId) || this.pendingHTMLTextComponents[gameObjectId] !== component || this.getFontName((_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily) !== fontName) return;
355
+ this.mountHTMLText(changed, component);
356
+ });
357
+ }
358
+ mountHTMLText(changed, component) {
359
+ const gameObjectId = changed.gameObject.id;
360
+ const style = this.processStyle(component.style);
361
+ const _a = component.textureStyle || {},
362
+ sampling = __rest(_a, ["resolution"]);
363
+ const htmlText = new rendererAdapter.HTMLText({
364
+ text: component.text,
365
+ style,
366
+ textureStyle: _extends({}, sampling)
308
367
  });
368
+ htmlText.rasterCacheFontIdentity = families => this.getHTMLRasterFontIdentity(families);
369
+ this.applyHTMLResolution(htmlText, component, changed);
370
+ this.containerManager.getContainer(gameObjectId).addChildAt(htmlText, 0);
371
+ this.texts[gameObjectId] = {
372
+ text: htmlText,
373
+ component
374
+ };
375
+ delete this.pendingHTMLTextComponents[gameObjectId];
376
+ }
377
+ getHTMLRasterFontIdentity(families) {
378
+ var _a;
379
+ const uniqueFamilies = [...new Set(families.filter(family => typeof family === 'string').map(family => family.replace(/["']/g, '').trim()).filter(Boolean))];
380
+ if (!uniqueFamilies.length) return 'external:<default>';
381
+ const describe = face => [this.objectIdentity(face), face.family, face.style, face.weight, face.stretch, face.unicodeRange, face.variant, face.featureSettings, face.display].map(value => String(value !== null && value !== void 0 ? value : '')).join(':');
382
+ const identities = [];
383
+ for (const family of uniqueFamilies) {
384
+ const current = eva_js.resource.resourcesMap[family];
385
+ if (!current || current.type !== eva_js.RESOURCE_TYPE.FONT) {
386
+ identities.push(`external:${family}`);
387
+ continue;
388
+ }
389
+ if (current.complete !== true) return null;
390
+ const rawFaces = (_a = current.data) === null || _a === void 0 ? void 0 : _a.font;
391
+ const faces = Array.isArray(rawFaces) ? rawFaces : [rawFaces];
392
+ if (!faces.length || faces.some(face => !face || typeof face !== 'object' || face.status !== 'loaded')) return null;
393
+ identities.push(`${family}|resource:${this.objectIdentity(current)}|faces:${faces.map(describe).join(',')}`);
394
+ }
395
+ return identities.join(';');
396
+ }
397
+ objectIdentity(value) {
398
+ let id = this.fontIdentityIds.get(value);
399
+ if (!id) {
400
+ id = this.nextFontIdentityId++;
401
+ this.fontIdentityIds.set(value, id);
402
+ }
403
+ return id;
309
404
  }
310
405
  addBitmapTextComponent(changed) {
406
+ const component = changed.component;
407
+ const styleWithoutFont = this.processStyle(component.style);
408
+ const fontFamily = styleWithoutFont.fontFamily;
409
+ const waitsForFontResource = this.needsFontLoad(fontFamily);
410
+ if (waitsForFontResource) delete styleWithoutFont.fontFamily;
411
+ const initialText = waitsForFontResource ? '' : component.text;
412
+ const bitmapText = new rendererAdapter.BitmapText(initialText, styleWithoutFont);
413
+ this.containerManager.getContainer(changed.gameObject.id).addChildAt(bitmapText, 0);
414
+ this.texts[changed.gameObject.id] = {
415
+ text: bitmapText,
416
+ component,
417
+ awaitingInitialFont: waitsForFontResource
418
+ };
419
+ if (waitsForFontResource) {
420
+ return this.waitForFontResource(bitmapText, changed, fontFamily);
421
+ }
422
+ }
423
+ hasRegisteredFont(fontFamily) {
424
+ var _a;
425
+ if (!fontFamily) return false;
426
+ const fontName = this.getFontName(fontFamily);
427
+ return ((_a = eva_js.resource.resourcesMap[fontName]) === null || _a === void 0 ? void 0 : _a.type) === eva_js.RESOURCE_TYPE.FONT;
428
+ }
429
+ needsFontLoad(fontFamily) {
430
+ if (!this.hasRegisteredFont(fontFamily)) return false;
431
+ return eva_js.resource.resourcesMap[this.getFontName(fontFamily)].complete !== true;
432
+ }
433
+ getFontName(fontFamily) {
434
+ if (!fontFamily) return undefined;
435
+ return Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
436
+ }
437
+ loadFontResource(fontFamily) {
311
438
  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);
439
+ const fontName = this.getFontName(fontFamily);
440
+ if (!fontName || !this.hasRegisteredFont(fontFamily)) return false;
441
+ const expectedResource = eva_js.resource.resourcesMap[fontName];
442
+ try {
443
+ const loaded = yield eva_js.resource.getResource(fontName);
444
+ return loaded === expectedResource && loaded.complete === true && eva_js.resource.resourcesMap[fontName] === expectedResource;
445
+ } catch (error) {
446
+ console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
447
+ return false;
325
448
  }
326
449
  });
327
450
  }
328
451
  waitForFontResource(text, changed, fontFamily) {
452
+ var _a;
329
453
  return __awaiter(this, void 0, void 0, function* () {
330
454
  if (!fontFamily) {
331
455
  return;
332
456
  }
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);
457
+ const gameObjectId = changed.gameObject.id;
458
+ const fontName = this.getFontName(fontFamily);
459
+ if (!fontName || !this.hasRegisteredFont(fontFamily)) return;
460
+ const asyncId = this.increaseAsyncId(gameObjectId);
461
+ const loaded = yield this.loadFontResource(fontFamily);
462
+ const current = this.texts[gameObjectId];
463
+ if (!loaded || this.retired || changed.gameObject.destroyed || !this.validateAsyncId(gameObjectId, asyncId) || !current || current.text !== text || current.component !== changed.component) {
464
+ return;
343
465
  }
466
+ const currentFontFamily = (_a = current.component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
467
+ if (this.getFontName(currentFontFamily) !== fontName) return;
468
+ text.style.fontFamily = currentFontFamily;
469
+ current.awaitingInitialFont = false;
470
+ text.text = current.component.text;
344
471
  });
345
472
  }
346
473
  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
474
+ const processed = this.cloneStyleValue(style);
475
+ if (processed.strokeThickness != null || processed.lineJoin != null || processed.miterLimit != null) {
476
+ const stroke = processed.stroke;
477
+ const isOptions = stroke && typeof stroke === 'object' && ['color', 'width', 'fill', 'texture', 'join'].some(key => key in stroke);
478
+ const merged = isOptions ? _extends({}, stroke) : {
479
+ color: stroke !== null && stroke !== void 0 ? stroke : 0x000000
353
480
  };
354
- delete processed.strokeThickness;
481
+ if (processed.strokeThickness != null) merged.width = processed.strokeThickness;
482
+ if (processed.lineJoin != null) merged.join = processed.lineJoin;
483
+ if (processed.miterLimit != null) merged.miterLimit = processed.miterLimit;
484
+ if (stroke != null || processed.strokeThickness != null) processed.stroke = merged;
485
+ }
486
+ delete processed.strokeThickness;
487
+ delete processed.lineJoin;
488
+ delete processed.miterLimit;
489
+ if (processed.dropShadow && typeof processed.dropShadow === 'object' && !Array.isArray(processed.dropShadow)) {
490
+ if (processed.dropShadow.enabled === false) processed.dropShadow = false;else delete processed.dropShadow.enabled;
355
491
  }
356
492
  const hasFlatDropShadowAlias = processed.dropShadowColor != null || processed.dropShadowDistance != null || processed.dropShadowAngle != null || processed.dropShadowAlpha != null || processed.dropShadowBlur != null;
357
493
  if (processed.dropShadow && hasFlatDropShadowAlias) {
@@ -379,57 +515,119 @@ var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendere
379
515
  delete processed.dropShadowAlpha;
380
516
  delete processed.dropShadowBlur;
381
517
  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);
518
+ const colors = processed.fill;
519
+ if (colors.length > 1) {
520
+ const supplied = processed.fillGradientStops;
521
+ const stops = Array.isArray(supplied) && supplied.length === colors.length ? supplied : colors.map((_, index) => index / (colors.length - 1));
522
+ const horizontal = processed.fillGradientType === 1;
523
+ const gradient = new pixi_js.FillGradient({
524
+ start: {
525
+ x: 0,
526
+ y: 0
527
+ },
528
+ end: horizontal ? {
529
+ x: 1,
530
+ y: 0
531
+ } : {
532
+ x: 0,
533
+ y: 1
534
+ },
535
+ textureSpace: 'local'
536
+ });
537
+ colors.forEach((color, index) => {
538
+ gradient.addColorStop(stops[index], pixi_js.Color.shared.setValue(color).toNumber());
539
+ });
540
+ processed.fill = {
541
+ fill: gradient
542
+ };
390
543
  } else {
391
- fontSize = processed.fontSize;
544
+ processed.fill = colors[0];
392
545
  }
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
546
  }
547
+ delete processed.fillGradientStops;
548
+ delete processed.fillGradientType;
404
549
  return processed;
405
550
  }
406
551
  change(changed) {
552
+ var _a, _b, _c, _d, _e, _f, _g, _h;
553
+ const current = this.texts[changed.gameObject.id];
407
554
  const {
408
555
  text,
409
556
  component
410
- } = this.texts[changed.gameObject.id];
557
+ } = current;
411
558
  const isHTMLText = changed.componentName === 'HTMLText';
412
559
  if (changed.prop.prop[0] === 'text') {
413
- text.text = component.text;
560
+ if (!current.awaitingInitialFont) text.text = component.text;
414
561
  } else if (changed.prop.prop[0] === 'style') {
415
562
  const processedStyle = this.processStyle(component.style);
563
+ if (this.needsFontLoad(processedStyle.fontFamily)) delete processedStyle.fontFamily;
416
564
  _extends(text.style, processedStyle);
565
+ if (current.awaitingInitialFont && !this.needsFontLoad((_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily)) {
566
+ current.awaitingInitialFont = false;
567
+ text.text = component.text;
568
+ }
417
569
  } else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
418
570
  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({
571
+ const htmlText = text;
572
+ const _j = htmlComponent.textureStyle || {},
573
+ sampling = __rest(_j, ["resolution"]);
574
+ if (htmlText.textureStyle) {
575
+ const options = _extends(_extends({}, (pixi_js.TextureStyle === null || pixi_js.TextureStyle === void 0 ? void 0 : pixi_js.TextureStyle.defaultOptions) || {
576
+ addressMode: 'clamp-to-edge',
577
+ scaleMode: 'linear'
578
+ }), sampling);
579
+ htmlText.textureStyle.addressMode = options.addressMode;
580
+ htmlText.textureStyle.scaleMode = options.scaleMode;
581
+ _extends(htmlText.textureStyle, {
582
+ addressModeU: (_b = options.addressModeU) !== null && _b !== void 0 ? _b : options.addressMode,
583
+ addressModeV: (_c = options.addressModeV) !== null && _c !== void 0 ? _c : options.addressMode,
584
+ addressModeW: (_d = options.addressModeW) !== null && _d !== void 0 ? _d : options.addressMode,
585
+ magFilter: (_e = options.magFilter) !== null && _e !== void 0 ? _e : options.scaleMode,
586
+ minFilter: (_f = options.minFilter) !== null && _f !== void 0 ? _f : options.scaleMode,
587
+ mipmapFilter: (_g = options.mipmapFilter) !== null && _g !== void 0 ? _g : options.scaleMode,
588
+ lodMinClamp: options.lodMinClamp,
589
+ lodMaxClamp: options.lodMaxClamp,
590
+ compare: options.compare,
591
+ maxAnisotropy: (_h = options.maxAnisotropy) !== null && _h !== void 0 ? _h : 1
592
+ });
593
+ htmlText.textureStyle.update();
594
+ } else {
595
+ htmlText.textureStyle = new pixi_js.TextureStyle(sampling);
596
+ }
597
+ this.applyHTMLResolution(htmlText, htmlComponent, changed);
598
+ }
599
+ }
600
+ applyHTMLResolution(text, component, changed) {
601
+ var _a, _b, _c, _d;
602
+ const render = (_b = (_a = changed.gameObject).getComponent) === null || _b === void 0 ? void 0 : _b.call(_a, 'Render');
603
+ const resolution = (_c = render === null || render === void 0 ? void 0 : render.resolution) !== null && _c !== void 0 ? _c : (_d = component.textureStyle) === null || _d === void 0 ? void 0 : _d.resolution;
604
+ if (typeof resolution === 'number' && Number.isFinite(resolution) && resolution > 0 && text.resolution !== resolution) {
605
+ text.resolution = resolution;
606
+ } else if (resolution == null) {
607
+ text.resolution = null;
608
+ }
609
+ }
610
+ onDestroy() {
611
+ var _a, _b;
612
+ this.retired = true;
613
+ for (const id of Object.keys(this.asyncIdMap)) this.increaseAsyncId(Number(id));
614
+ this.pendingHTMLTextComponents = {};
615
+ for (const {
616
+ text
617
+ } of Object.values(this.texts)) {
618
+ (_a = text.parent) === null || _a === void 0 ? void 0 : _a.removeChild(text);
619
+ if (!text.destroyed) (_b = text.destroy) === null || _b === void 0 ? void 0 : _b.call(text, {
423
620
  children: true
424
621
  });
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
622
  }
623
+ this.texts = {};
624
+ }
625
+ cloneStyleValue(value) {
626
+ if (Array.isArray(value)) return value.map(item => this.cloneStyleValue(item));
627
+ if (value && Object.getPrototypeOf(value) === Object.prototype) {
628
+ return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, this.cloneStyleValue(child)]));
629
+ }
630
+ return value;
433
631
  }
434
632
  setSize(changed) {
435
633
  const {
@@ -440,8 +638,10 @@ var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendere
440
638
  text
441
639
  } = this.texts[changed.gameObject.id];
442
640
  const size = text.getSize();
641
+ if (transform.size.width === size.width && transform.size.height === size.height) return;
443
642
  transform.size.width = size.width;
444
643
  transform.size.height = size.height;
644
+ this.renderSystem.commitIntrinsicSize(changed.gameObject);
445
645
  }
446
646
  };
447
647
  Text.systemName = 'Text';
@@ -1 +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;
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 n in o)({}).hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e},_extends.apply(null,arguments)}var globalThis="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();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,n,i){"use strict";function r(e,t){var o={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(o[n[i]]=e[n[i]])}return o}function s(e,t,o,n){var i,r=arguments.length,s=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,n);else for(var d=e.length-1;d>=0;d--)(i=e[d])&&(s=(r<3?i(s):r>3?i(t,o,s):i(t,o))||s);return r>3&&s&&Object.defineProperty(t,o,s),s}function d(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function p(e,t,o,n){return new(o||(o=Promise))(function(i,r){function s(e){try{p(n.next(e))}catch(e){r(e)}}function d(e){try{p(n.throw(e))}catch(e){r(e)}}function p(e){var t;e.done?i(e.value):(t=e.value,t instanceof o?t:new o(function(e){e(t)})).then(s,d)}p((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class l{}s([t.type("string"),d("design:type",Object)],l.prototype,"fontFamily",void 0),s([t.type("number"),d("design:type",Object)],l.prototype,"fontSize",void 0),s([t.Field({type:"color"}),d("design:type",Object)],l.prototype,"fill",void 0),s([t.type("string"),d("design:type",String)],l.prototype,"align",void 0),s([t.type("number"),d("design:type",Number)],l.prototype,"letterSpacing",void 0),s([t.type("number"),d("design:type",Number)],l.prototype,"padding",void 0),s([t.Field({type:"color"}),d("design:type",Object)],l.prototype,"stroke",void 0),s([t.type("number"),d("design:type",Number)],l.prototype,"strokeThickness",void 0),s([t.type("string"),d("design:type",String)],l.prototype,"fontWeight",void 0),s([t.type("string"),d("design:type",String)],l.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",s([t.type("string"),d("design:type",String)],y.prototype,"text",void 0),s([t.Field(()=>l),d("design:type",Object)],y.prototype,"style",void 0);class a{}s([t.type("number"),d("design:type",Number)],a.prototype,"alpha",void 0),s([t.Field({type:"color"}),d("design:type",Object)],a.prototype,"color",void 0),s([t.type("string"),d("design:type",String)],a.prototype,"join",void 0),s([t.type("number"),d("design:type",Number)],a.prototype,"miterLimit",void 0),s([t.type("number"),d("design:type",Number)],a.prototype,"width",void 0);class c{}s([t.type("number"),d("design:type",Number)],c.prototype,"alpha",void 0),s([t.type("number"),d("design:type",Number)],c.prototype,"angle",void 0),s([t.type("number"),d("design:type",Number)],c.prototype,"blur",void 0),s([t.Field({type:"color"}),d("design:type",Object)],c.prototype,"color",void 0),s([t.type("number"),d("design:type",Number)],c.prototype,"distance",void 0),s([t.type("boolean"),d("design:type",Boolean)],c.prototype,"enabled",void 0);class u{}s([t.type("string"),d("design:type",String)],u.prototype,"align",void 0),s([t.type("boolean"),d("design:type",Boolean)],u.prototype,"breakWords",void 0),s([t.Field(()=>c),d("design:type",Object)],u.prototype,"dropShadow",void 0),s([t.type("number"),d("design:type",Number)],u.prototype,"dropShadowAlpha",void 0),s([t.type("number"),d("design:type",Number)],u.prototype,"dropShadowAngle",void 0),s([t.type("number"),d("design:type",Number)],u.prototype,"dropShadowBlur",void 0),s([t.Field({type:"color"}),d("design:type",Object)],u.prototype,"dropShadowColor",void 0),s([t.type("number"),d("design:type",Number)],u.prototype,"dropShadowDistance",void 0),s([t.Field({type:"color"}),d("design:type",Object)],u.prototype,"fill",void 0),s([t.type("number"),d("design:type",Number)],u.prototype,"fillGradientType",void 0),s([t.type("number"),d("design:type",Array)],u.prototype,"fillGradientStops",void 0),s([t.type("string"),d("design:type",Object)],u.prototype,"fontFamily",void 0),s([t.type("number"),d("design:type",Object)],u.prototype,"fontSize",void 0),s([t.type("string"),d("design:type",String)],u.prototype,"fontStyle",void 0),s([t.type("string"),d("design:type",String)],u.prototype,"fontVariant",void 0),s([t.type("string"),d("design:type",String)],u.prototype,"fontWeight",void 0),s([t.type("number"),d("design:type",Number)],u.prototype,"leading",void 0),s([t.type("number"),d("design:type",Number)],u.prototype,"letterSpacing",void 0),s([t.type("number"),d("design:type",Number)],u.prototype,"lineHeight",void 0),s([t.type("string"),d("design:type",String)],u.prototype,"lineJoin",void 0),s([t.type("number"),d("design:type",Number)],u.prototype,"miterLimit",void 0),s([t.type("number"),d("design:type",Number)],u.prototype,"padding",void 0),s([t.Field(()=>a),d("design:type",Object)],u.prototype,"stroke",void 0),s([t.type("number"),d("design:type",Number)],u.prototype,"strokeThickness",void 0),s([t.type("string"),d("design:type",String)],u.prototype,"textBaseline",void 0),s([t.type("string"),d("design:type",String)],u.prototype,"verticalAlign",void 0),s([t.type("boolean"),d("design:type",Boolean)],u.prototype,"trim",void 0),s([t.type("string"),d("design:type",String)],u.prototype,"whiteSpace",void 0),s([t.type("boolean"),d("design:type",Boolean)],u.prototype,"wordWrap",void 0),s([t.type("number"),d("design:type",Number)],u.prototype,"wordWrapWidth",void 0);class g extends t.Component{constructor(e){super(e),this.text="",this.style={},this.init(e)}init(e){const t=new o.TextStyle({fontSize:20}),n={};for(const e in t)0===e.indexOf("_")&&(n[e.substring(1)]=t[e]);delete n.styleKey,this.style=n,e&&(this.text=e.text,_extends(this.style,e.style))}}g.componentName="Text",s([t.type("string"),d("design:type",String)],g.prototype,"text",void 0),s([t.Field(()=>u),d("design:type",Object)],g.prototype,"style",void 0);class m{}s([t.type("string"),d("design:type",String)],m.prototype,"scaleMode",void 0),s([t.type("number"),d("design:type",Number)],m.prototype,"resolution",void 0);class h{}s([t.type("string"),d("design:type",Object)],h.prototype,"fontFamily",void 0),s([t.type("number"),d("design:type",Object)],h.prototype,"fontSize",void 0),s([t.type("string"),d("design:type",String)],h.prototype,"fontWeight",void 0),s([t.type("string"),d("design:type",String)],h.prototype,"fontStyle",void 0),s([t.type("string"),d("design:type",String)],h.prototype,"fontVariant",void 0),s([t.type("string"),d("design:type",String)],h.prototype,"align",void 0),s([t.type("string"),d("design:type",String)],h.prototype,"textBaseline",void 0),s([t.Field({type:"color"}),d("design:type",Object)],h.prototype,"fill",void 0),s([t.Field({type:"color"}),d("design:type",Object)],h.prototype,"stroke",void 0),s([t.type("number"),d("design:type",Number)],h.prototype,"strokeThickness",void 0),s([t.type("number"),d("design:type",Number)],h.prototype,"lineHeight",void 0),s([t.type("number"),d("design:type",Number)],h.prototype,"letterSpacing",void 0),s([t.type("number"),d("design:type",Number)],h.prototype,"padding",void 0),s([t.type("boolean"),d("design:type",Boolean)],h.prototype,"wordWrap",void 0),s([t.type("number"),d("design:type",Number)],h.prototype,"wordWrapWidth",void 0),s([t.type("boolean"),d("design:type",Boolean)],h.prototype,"breakWords",void 0),s([t.type("string"),d("design:type",String)],h.prototype,"whiteSpace",void 0),s([t.type("boolean"),d("design:type",Boolean)],h.prototype,"dropShadow",void 0),s([t.Field({type:"color"}),d("design:type",Object)],h.prototype,"dropShadowColor",void 0),s([t.type("number"),d("design:type",Number)],h.prototype,"dropShadowAlpha",void 0),s([t.type("number"),d("design:type",Number)],h.prototype,"dropShadowAngle",void 0),s([t.type("number"),d("design:type",Number)],h.prototype,"dropShadowBlur",void 0),s([t.type("number"),d("design:type",Number)],h.prototype,"dropShadowDistance",void 0),s([t.type("object"),d("design:type",Array)],h.prototype,"cssOverrides",void 0),s([t.type("object"),d("design:type",Object)],h.prototype,"tagStyles",void 0),s([t.type("boolean"),d("design:type",Boolean)],h.prototype,"trim",void 0);class v 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)}}v.componentName="HTMLText",s([t.type("string"),d("design:type",String)],v.prototype,"text",void 0),s([t.Field(()=>h),d("design:type",Object)],v.prototype,"style",void 0),s([t.Field(()=>m),d("design:type",Object)],v.prototype,"textureStyle",void 0);let b=class extends n.Renderer{constructor(){super(...arguments),this.name="Text",this.presentationAddFlushEnabled=!0,this.texts={},this.retired=!1,this.pendingHTMLTextComponents={},this.fontIdentityIds=new WeakMap,this.nextFontIdentityId=1}init(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)}shouldFlushPresentationAddition(e){return"Text"===e.componentName||"HTMLText"===e.componentName||"BitmapText"===e.componentName}componentChanged(e){var o,n,i,r,s;return p(this,void 0,void 0,function*(){if(this.retired)return;const d="Text"===e.componentName,p="HTMLText"===e.componentName,l="BitmapText"===e.componentName;if(!d&&!p&&!l)return;const y=e.gameObject.id;if(e.type===t.OBSERVER_TYPE.ADD){if(d){const t=this.addTextComponent(e);t&&(yield t)}else if(p){const t=this.addHTMLTextComponent(e);t&&(yield t)}else{const t=this.addBitmapTextComponent(e);t&&(yield t)}(null===(o=this.texts[y])||void 0===o?void 0:o.component)===e.component&&this.setSize(e)}else if(e.type===t.OBSERVER_TYPE.REMOVE){if((null===(n=this.texts[y])||void 0===n?void 0:n.component)!==e.component&&this.pendingHTMLTextComponents[y]!==e.component)return;this.increaseAsyncId(y),this.pendingHTMLTextComponents[y]===e.component&&delete this.pendingHTMLTextComponents[y];const t=this.texts[y];if(!t||t.component!==e.component)return;this.containerManager.getContainer(y).removeChild(t.text),t.text.destroy({children:!0}),delete this.texts[y]}else{const t=e.component,o=e.prop.prop,n="style"===o[0]&&(1===o.length||"fontFamily"===o[1]),d=this.texts[y];if(!d)return void(p&&this.pendingHTMLTextComponents[y]===t&&n&&(yield this.addHTMLTextComponent(e),(null===(i=this.texts[y])||void 0===i?void 0:i.component)===t&&this.setSize(e)));if(d.component!==t)return;const l=n&&t.style&&this.needsFontLoad(t.style.fontFamily);if(n&&!l&&this.increaseAsyncId(y),this.change(e),l){const{text:o}=d;yield this.waitForFontResource(o,e,t.style.fontFamily)}(null===(r=this.texts[y])||void 0===r?void 0:r.text)===d.text&&(null===(s=this.texts[y])||void 0===s?void 0:s.component)===t&&this.setSize(e)}})}addTextComponent(e){const t=e.component,o=this.processStyle(t.style),n=o.fontFamily,r=this.needsFontLoad(n);r&&delete o.fontFamily;const s=r?"":t.text,d=new i.Text(s,o);if(this.containerManager.getContainer(e.gameObject.id).addChildAt(d,0),this.texts[e.gameObject.id]={text:d,component:t,awaitingInitialFont:r},r)return this.waitForFontResource(d,e,n)}addHTMLTextComponent(e){const t=e.component,o=e.gameObject.id,n=this.processStyle(t.style).fontFamily;if(this.needsFontLoad(n))return this.pendingHTMLTextComponents[o]=t,this.addHTMLTextAfterFont(e,t,n,this.increaseAsyncId(o));this.pendingHTMLTextComponents[o]===t&&delete this.pendingHTMLTextComponents[o],this.mountHTMLText(e,t)}addHTMLTextAfterFont(e,t,o,n){var i;return p(this,void 0,void 0,function*(){const r=e.gameObject.id,s=this.getFontName(o);(yield this.loadFontResource(o))&&!this.retired&&!e.gameObject.destroyed&&this.validateAsyncId(r,n)&&this.pendingHTMLTextComponents[r]===t&&this.getFontName(null===(i=t.style)||void 0===i?void 0:i.fontFamily)===s&&this.mountHTMLText(e,t)})}mountHTMLText(e,t){const o=e.gameObject.id,n=this.processStyle(t.style),s=r(t.textureStyle||{},["resolution"]),d=new i.HTMLText({text:t.text,style:n,textureStyle:_extends({},s)});d.rasterCacheFontIdentity=e=>this.getHTMLRasterFontIdentity(e),this.applyHTMLResolution(d,t,e),this.containerManager.getContainer(o).addChildAt(d,0),this.texts[o]={text:d,component:t},delete this.pendingHTMLTextComponents[o]}getHTMLRasterFontIdentity(e){var o;const n=[...new Set(e.filter(e=>"string"==typeof e).map(e=>e.replace(/["']/g,"").trim()).filter(Boolean))];if(!n.length)return"external:<default>";const i=e=>[this.objectIdentity(e),e.family,e.style,e.weight,e.stretch,e.unicodeRange,e.variant,e.featureSettings,e.display].map(e=>String(null!=e?e:"")).join(":"),r=[];for(const e of n){const n=t.resource.resourcesMap[e];if(!n||n.type!==t.RESOURCE_TYPE.FONT){r.push(`external:${e}`);continue}if(!0!==n.complete)return null;const s=null===(o=n.data)||void 0===o?void 0:o.font,d=Array.isArray(s)?s:[s];if(!d.length||d.some(e=>!e||"object"!=typeof e||"loaded"!==e.status))return null;r.push(`${e}|resource:${this.objectIdentity(n)}|faces:${d.map(i).join(",")}`)}return r.join(";")}objectIdentity(e){let t=this.fontIdentityIds.get(e);return t||(t=this.nextFontIdentityId++,this.fontIdentityIds.set(e,t)),t}addBitmapTextComponent(e){const t=e.component,o=this.processStyle(t.style),n=o.fontFamily,r=this.needsFontLoad(n);r&&delete o.fontFamily;const s=r?"":t.text,d=new i.BitmapText(s,o);if(this.containerManager.getContainer(e.gameObject.id).addChildAt(d,0),this.texts[e.gameObject.id]={text:d,component:t,awaitingInitialFont:r},r)return this.waitForFontResource(d,e,n)}hasRegisteredFont(e){var o;if(!e)return!1;const n=this.getFontName(e);return(null===(o=t.resource.resourcesMap[n])||void 0===o?void 0:o.type)===t.RESOURCE_TYPE.FONT}needsFontLoad(e){return!!this.hasRegisteredFont(e)&&!0!==t.resource.resourcesMap[this.getFontName(e)].complete}getFontName(e){if(e)return Array.isArray(e)?e[0]:e}loadFontResource(e){return p(this,void 0,void 0,function*(){const o=this.getFontName(e);if(!o||!this.hasRegisteredFont(e))return!1;const n=t.resource.resourcesMap[o];try{const e=yield t.resource.getResource(o);return e===n&&!0===e.complete&&t.resource.resourcesMap[o]===n}catch(t){return console.warn(`字体资源 ${e} 加载失败:`,t),!1}})}waitForFontResource(e,t,o){var n;return p(this,void 0,void 0,function*(){if(!o)return;const i=t.gameObject.id,r=this.getFontName(o);if(!r||!this.hasRegisteredFont(o))return;const s=this.increaseAsyncId(i),d=yield this.loadFontResource(o),p=this.texts[i];if(!d||this.retired||t.gameObject.destroyed||!this.validateAsyncId(i,s)||!p||p.text!==e||p.component!==t.component)return;const l=null===(n=p.component.style)||void 0===n?void 0:n.fontFamily;this.getFontName(l)===r&&(e.style.fontFamily=l,p.awaitingInitialFont=!1,e.text=p.component.text)})}processStyle(e){const t=this.cloneStyleValue(e);if(null!=t.strokeThickness||null!=t.lineJoin||null!=t.miterLimit){const e=t.stroke,o=e&&"object"==typeof e&&["color","width","fill","texture","join"].some(t=>t in e)?_extends({},e):{color:null!=e?e:0};null!=t.strokeThickness&&(o.width=t.strokeThickness),null!=t.lineJoin&&(o.join=t.lineJoin),null!=t.miterLimit&&(o.miterLimit=t.miterLimit),null==e&&null==t.strokeThickness||(t.stroke=o)}delete t.strokeThickness,delete t.lineJoin,delete t.miterLimit,t.dropShadow&&"object"==typeof t.dropShadow&&!Array.isArray(t.dropShadow)&&(!1===t.dropShadow.enabled?t.dropShadow=!1:delete t.dropShadow.enabled);const n=null!=t.dropShadowColor||null!=t.dropShadowDistance||null!=t.dropShadowAngle||null!=t.dropShadowAlpha||null!=t.dropShadowBlur;if(t.dropShadow&&n){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)){const e=t.fill;if(e.length>1){const n=t.fillGradientStops,i=Array.isArray(n)&&n.length===e.length?n:e.map((t,o)=>o/(e.length-1)),r=1===t.fillGradientType,s=new o.FillGradient({start:{x:0,y:0},end:r?{x:1,y:0}:{x:0,y:1},textureSpace:"local"});e.forEach((e,t)=>{s.addColorStop(i[t],o.Color.shared.setValue(e).toNumber())}),t.fill={fill:s}}else t.fill=e[0]}return delete t.fillGradientStops,delete t.fillGradientType,t}change(e){var t,n,i,s,d,p,l,y;const a=this.texts[e.gameObject.id],{text:c,component:u}=a,g="HTMLText"===e.componentName;if("text"===e.prop.prop[0])a.awaitingInitialFont||(c.text=u.text);else if("style"===e.prop.prop[0]){const e=this.processStyle(u.style);this.needsFontLoad(e.fontFamily)&&delete e.fontFamily,_extends(c.style,e),a.awaitingInitialFont&&!this.needsFontLoad(null===(t=u.style)||void 0===t?void 0:t.fontFamily)&&(a.awaitingInitialFont=!1,c.text=u.text)}else if("textureStyle"===e.prop.prop[0]&&g){const t=u,a=c,g=r(t.textureStyle||{},["resolution"]);if(a.textureStyle){const e=_extends(_extends({},(null===o.TextureStyle||void 0===o.TextureStyle?void 0:o.TextureStyle.defaultOptions)||{addressMode:"clamp-to-edge",scaleMode:"linear"}),g);a.textureStyle.addressMode=e.addressMode,a.textureStyle.scaleMode=e.scaleMode,_extends(a.textureStyle,{addressModeU:null!==(n=e.addressModeU)&&void 0!==n?n:e.addressMode,addressModeV:null!==(i=e.addressModeV)&&void 0!==i?i:e.addressMode,addressModeW:null!==(s=e.addressModeW)&&void 0!==s?s:e.addressMode,magFilter:null!==(d=e.magFilter)&&void 0!==d?d:e.scaleMode,minFilter:null!==(p=e.minFilter)&&void 0!==p?p:e.scaleMode,mipmapFilter:null!==(l=e.mipmapFilter)&&void 0!==l?l:e.scaleMode,lodMinClamp:e.lodMinClamp,lodMaxClamp:e.lodMaxClamp,compare:e.compare,maxAnisotropy:null!==(y=e.maxAnisotropy)&&void 0!==y?y:1}),a.textureStyle.update()}else a.textureStyle=new o.TextureStyle(g);this.applyHTMLResolution(a,t,e)}}applyHTMLResolution(e,t,o){var n,i,r,s;const d=null===(i=(n=o.gameObject).getComponent)||void 0===i?void 0:i.call(n,"Render"),p=null!==(r=null==d?void 0:d.resolution)&&void 0!==r?r:null===(s=t.textureStyle)||void 0===s?void 0:s.resolution;"number"==typeof p&&Number.isFinite(p)&&p>0&&e.resolution!==p?e.resolution=p:null==p&&(e.resolution=null)}onDestroy(){var e,t;this.retired=!0;for(const e of Object.keys(this.asyncIdMap))this.increaseAsyncId(Number(e));this.pendingHTMLTextComponents={};for(const{text:o}of Object.values(this.texts))null===(e=o.parent)||void 0===e||e.removeChild(o),o.destroyed||null===(t=o.destroy)||void 0===t||t.call(o,{children:!0});this.texts={}}cloneStyleValue(e){return Array.isArray(e)?e.map(e=>this.cloneStyleValue(e)):e&&Object.getPrototypeOf(e)===Object.prototype?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,this.cloneStyleValue(t)])):e}setSize(e){const{transform:t}=e.gameObject;if(!t)return;const{text:o}=this.texts[e.gameObject.id],n=o.getSize();t.size.width===n.width&&t.size.height===n.height||(t.size.width=n.width,t.size.height=n.height,this.renderSystem.commitIntrinsicSize(e.gameObject))}};b.systemName="Text",b=s([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 f=b;return e.BitmapText=y,e.HTMLText=v,e.Text=g,e.TextSystem=f,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;