@eva/plugin-renderer-text 2.0.1-beta.18 → 2.0.1-beta.19

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.
@@ -86,7 +86,6 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
86
86
  super(...arguments);
87
87
  this.name = 'Text';
88
88
  this.texts = {};
89
- this._lastFontFamily = undefined;
90
89
  }
91
90
  init() {
92
91
  this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
@@ -97,13 +96,19 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
97
96
  if (changed.componentName !== 'Text') return;
98
97
  if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
99
98
  const component = changed.component;
100
- const text = new rendererAdapter.Text(component.text, component.style);
99
+ const styleWithoutFont = _extends({}, component.style);
100
+ const fontFamily = styleWithoutFont.fontFamily;
101
+ delete styleWithoutFont.fontFamily;
102
+ const text = new rendererAdapter.Text(component.text, styleWithoutFont);
101
103
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
102
104
  this.texts[changed.gameObject.id] = {
103
105
  text,
104
106
  component: changed.component
105
107
  };
106
108
  this.setSize(changed);
109
+ if (fontFamily) {
110
+ yield this.waitForFontResource(text, changed, fontFamily);
111
+ }
107
112
  } else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
108
113
  this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
109
114
  this.texts[changed.gameObject.id].text.destroy({
@@ -113,6 +118,30 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
113
118
  } else {
114
119
  this.change(changed);
115
120
  this.setSize(changed);
121
+ const component = changed.component;
122
+ if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
123
+ const {
124
+ text
125
+ } = this.texts[changed.gameObject.id];
126
+ yield this.waitForFontResource(text, changed, component.style.fontFamily);
127
+ }
128
+ }
129
+ });
130
+ }
131
+ waitForFontResource(text, changed, fontFamily) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ if (!fontFamily) {
134
+ return;
135
+ }
136
+ try {
137
+ const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
138
+ const asyncId = this.increaseAsyncId(changed.gameObject.id);
139
+ yield eva_js.resource.getResource(fontName);
140
+ if (!this.validateAsyncId(changed.gameObject.id, asyncId)) return;
141
+ text.style.fontFamily = fontFamily;
142
+ this.setSize(changed);
143
+ } catch (error) {
144
+ console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
116
145
  }
117
146
  });
118
147
  }
@@ -126,31 +155,6 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
126
155
  } else if (changed.prop.prop[0] === 'style') {
127
156
  _extends(text.style, changed.component.style);
128
157
  }
129
- if (text.style.fontFamily && text.style.fontFamily !== this._lastFontFamily) {
130
- this._lastFontFamily = text.style.fontFamily;
131
- this.asyncChangeTextStyle(text, text.style);
132
- }
133
- }
134
- asyncChangeTextStyle(text, textStyle) {
135
- if (textStyle.fontFamily) {
136
- const fontFamily = textStyle.fontFamily;
137
- textStyle.fontFamily = '';
138
- this.asyncUpdateFontFamily(text, fontFamily);
139
- }
140
- _extends(text.style, textStyle);
141
- }
142
- asyncUpdateFontFamily(text, fontFamily) {
143
- if (fontFamily) {
144
- if (Array.isArray(fontFamily)) {
145
- Promise.all(fontFamily.map(font => eva_js.resource.getResource(font))).finally(() => {
146
- text.style.fontFamily = fontFamily;
147
- });
148
- } else {
149
- eva_js.resource.getResource(fontFamily).finally(() => {
150
- text.style.fontFamily = fontFamily;
151
- });
152
- }
153
- }
154
158
  }
155
159
  setSize(changed) {
156
160
  const {
@@ -1 +1 @@
1
- function _extends(){return _extends=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var s in n)({}).hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},_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(t,e,n,s,r){"use strict";function i(t,e,n,s){var r,i=arguments.length,o=i<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,n):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,n,s);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(o=(i<3?r(o):i>3?r(e,n,o):r(e,n))||o);return i>3&&o&&Object.defineProperty(e,n,o),o}function o(t,e,n,s){return new(n||(n=Promise))((function(r,i){function o(t){try{l(s.next(t))}catch(t){i(t)}}function a(t){try{l(s.throw(t))}catch(t){i(t)}}function l(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,a)}l((s=s.apply(t,e||[])).next())}))}class a extends n.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){const n=new e.TextStyle({fontSize:20}),s={};for(const t in n)0===t.indexOf("_")&&(s[t.substring(1)]=n[t]);delete s.styleKey,this.style=s,t&&(this.text=t.text,_extends(this.style,t.style))}}a.componentName="Text",i([function(t){return function(e,n){var s=function(t,e){return t.constructor.IDEProps||(t.constructor.IDEProps={}),t.constructor.IDEProps[e]||(t.constructor.IDEProps[e]={}),t.constructor.IDEProps[e]}(e,n);s.key=n,s.type=t}}("string")],a.prototype,"text",void 0);let l=class extends s.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={},this._lastFontFamily=void 0}init(){this.renderSystem=this.game.getSystem(s.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(t){return o(this,void 0,void 0,(function*(){if("Text"===t.componentName)if(t.type===n.OBSERVER_TYPE.ADD){const e=t.component,n=new r.Text(e.text,e.style);this.containerManager.getContainer(t.gameObject.id).addChildAt(n,0),this.texts[t.gameObject.id]={text:n,component:t.component},this.setSize(t)}else t.type===n.OBSERVER_TYPE.REMOVE?(this.containerManager.getContainer(t.gameObject.id).removeChild(this.texts[t.gameObject.id].text),this.texts[t.gameObject.id].text.destroy({children:!0}),delete this.texts[t.gameObject.id]):(this.change(t),this.setSize(t))}))}change(t){const{text:e,component:n}=this.texts[t.gameObject.id];"text"===t.prop.prop[0]?e.text=n.text:"style"===t.prop.prop[0]&&_extends(e.style,t.component.style),e.style.fontFamily&&e.style.fontFamily!==this._lastFontFamily&&(this._lastFontFamily=e.style.fontFamily,this.asyncChangeTextStyle(e,e.style))}asyncChangeTextStyle(t,e){if(e.fontFamily){const n=e.fontFamily;e.fontFamily="",this.asyncUpdateFontFamily(t,n)}_extends(t.style,e)}asyncUpdateFontFamily(t,e){e&&(Array.isArray(e)?Promise.all(e.map((t=>n.resource.getResource(t)))).finally((()=>{t.style.fontFamily=e})):n.resource.getResource(e).finally((()=>{t.style.fontFamily=e})))}setSize(t){const{transform:e}=t.gameObject;e&&(e.size.width=this.texts[t.gameObject.id].text.width,e.size.height=this.texts[t.gameObject.id].text.height)}};l.systemName="Text",l=i([n.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}]})],l);var c=l;return t.Text=a,t.TextSystem=c,Object.defineProperty(t,"__esModule",{value:!0}),t}({},PIXI,EVA,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 n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}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,n,r,s){"use strict";function i(e,t,n,r){var s,i=arguments.length,o=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,r);else for(var c=e.length-1;c>=0;c--)(s=e[c])&&(o=(i<3?s(o):i>3?s(t,n,o):s(t,n))||o);return i>3&&o&&Object.defineProperty(t,n,o),o}function o(e,t,n,r){return new(n||(n=Promise))((function(s,i){function o(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}a((r=r.apply(e,t||[])).next())}))}class c extends n.Component{constructor(){super(...arguments),this.text="",this.style={}}init(e){const n=new t.TextStyle({fontSize:20}),r={};for(const e in n)0===e.indexOf("_")&&(r[e.substring(1)]=n[e]);delete r.styleKey,this.style=r,e&&(this.text=e.text,_extends(this.style,e.style))}}c.componentName="Text",i([function(e){return function(t,n){var r=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,n);r.key=n,r.type=e}}("string")],c.prototype,"text",void 0);let a=class extends r.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={}}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){return o(this,void 0,void 0,(function*(){if("Text"===e.componentName)if(e.type===n.OBSERVER_TYPE.ADD){const t=e.component,n=_extends({},t.style),r=n.fontFamily;delete n.fontFamily;const i=new s.Text(t.text,n);this.containerManager.getContainer(e.gameObject.id).addChildAt(i,0),this.texts[e.gameObject.id]={text:i,component:e.component},this.setSize(e),r&&(yield this.waitForFontResource(i,e,r))}else if(e.type===n.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),this.setSize(e);const t=e.component;if("style"===e.prop.prop[0]&&t.style&&t.style.fontFamily){const{text:n}=this.texts[e.gameObject.id];yield this.waitForFontResource(n,e,t.style.fontFamily)}}}))}waitForFontResource(e,t,r){return o(this,void 0,void 0,(function*(){if(r)try{const s=Array.isArray(r)?r[0]:r,i=this.increaseAsyncId(t.gameObject.id);if(yield n.resource.getResource(s),!this.validateAsyncId(t.gameObject.id,i))return;e.style.fontFamily=r,this.setSize(t)}catch(e){console.warn(`字体资源 ${r} 加载失败:`,e)}}))}change(e){const{text:t,component:n}=this.texts[e.gameObject.id];"text"===e.prop.prop[0]?t.text=n.text:"style"===e.prop.prop[0]&&_extends(t.style,e.component.style)}setSize(e){const{transform:t}=e.gameObject;t&&(t.size.width=this.texts[e.gameObject.id].text.width,t.size.height=this.texts[e.gameObject.id].text.height)}};a.systemName="Text",a=i([n.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}]})],a);var l=a;return e.Text=c,e.TextSystem=l,Object.defineProperty(e,"__esModule",{value:!0}),e}({},PIXI,EVA,EVA.plugin.renderer,EVA.rendererAdapter);globalThis.EVA.plugin.renderer.text=globalThis.EVA.plugin.renderer.text||_EVA_IIFE_text;
@@ -73,7 +73,6 @@ let Text = class Text extends pluginRenderer.Renderer {
73
73
  super(...arguments);
74
74
  this.name = 'Text';
75
75
  this.texts = {};
76
- this._lastFontFamily = undefined;
77
76
  }
78
77
  init() {
79
78
  this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
@@ -85,13 +84,19 @@ let Text = class Text extends pluginRenderer.Renderer {
85
84
  return;
86
85
  if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
87
86
  const component = changed.component;
88
- const text = new rendererAdapter.Text(component.text, component.style);
87
+ const styleWithoutFont = Object.assign({}, component.style);
88
+ const fontFamily = styleWithoutFont.fontFamily;
89
+ delete styleWithoutFont.fontFamily;
90
+ const text = new rendererAdapter.Text(component.text, styleWithoutFont);
89
91
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
90
92
  this.texts[changed.gameObject.id] = {
91
93
  text,
92
94
  component: changed.component,
93
95
  };
94
96
  this.setSize(changed);
97
+ if (fontFamily) {
98
+ yield this.waitForFontResource(text, changed, fontFamily);
99
+ }
95
100
  }
96
101
  else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
97
102
  this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
@@ -101,6 +106,30 @@ let Text = class Text extends pluginRenderer.Renderer {
101
106
  else {
102
107
  this.change(changed);
103
108
  this.setSize(changed);
109
+ const component = changed.component;
110
+ if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
111
+ const { text } = this.texts[changed.gameObject.id];
112
+ yield this.waitForFontResource(text, changed, component.style.fontFamily);
113
+ }
114
+ }
115
+ });
116
+ }
117
+ waitForFontResource(text, changed, fontFamily) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ if (!fontFamily) {
120
+ return;
121
+ }
122
+ try {
123
+ const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
124
+ const asyncId = this.increaseAsyncId(changed.gameObject.id);
125
+ yield eva_js.resource.getResource(fontName);
126
+ if (!this.validateAsyncId(changed.gameObject.id, asyncId))
127
+ return;
128
+ text.style.fontFamily = fontFamily;
129
+ this.setSize(changed);
130
+ }
131
+ catch (error) {
132
+ console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
104
133
  }
105
134
  });
106
135
  }
@@ -112,32 +141,6 @@ let Text = class Text extends pluginRenderer.Renderer {
112
141
  else if (changed.prop.prop[0] === 'style') {
113
142
  Object.assign(text.style, changed.component.style);
114
143
  }
115
- if (text.style.fontFamily && text.style.fontFamily !== this._lastFontFamily) {
116
- this._lastFontFamily = text.style.fontFamily;
117
- this.asyncChangeTextStyle(text, text.style);
118
- }
119
- }
120
- asyncChangeTextStyle(text, textStyle) {
121
- if (textStyle.fontFamily) {
122
- const fontFamily = textStyle.fontFamily;
123
- textStyle.fontFamily = '';
124
- this.asyncUpdateFontFamily(text, fontFamily);
125
- }
126
- Object.assign(text.style, textStyle);
127
- }
128
- asyncUpdateFontFamily(text, fontFamily) {
129
- if (fontFamily) {
130
- if (Array.isArray(fontFamily)) {
131
- Promise.all(fontFamily.map(font => eva_js.resource.getResource(font))).finally(() => {
132
- text.style.fontFamily = fontFamily;
133
- });
134
- }
135
- else {
136
- eva_js.resource.getResource(fontFamily).finally(() => {
137
- text.style.fontFamily = fontFamily;
138
- });
139
- }
140
- }
141
144
  }
142
145
  setSize(changed) {
143
146
  const { transform } = changed.gameObject;
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("pixi.js"),t=require("@eva/eva.js"),s=require("@eva/inspector-decorator"),n=require("@eva/plugin-renderer"),i=require("@eva/renderer-adapter");
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("pixi.js"),t=require("@eva/eva.js"),s=require("@eva/inspector-decorator"),i=require("@eva/plugin-renderer"),n=require("@eva/renderer-adapter");
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
@@ -13,4 +13,4 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
13
13
  See the Apache Version 2.0 License for specific language governing permissions
14
14
  and limitations under the License.
15
15
  ***************************************************************************** */
16
- function r(e,t,s,n){var i,r=arguments.length,o=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,s):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,s,n);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(o=(r<3?i(o):r>3?i(t,s,o):i(t,s))||o);return r>3&&o&&Object.defineProperty(t,s,o),o}class o extends t.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){const s=new e.TextStyle({fontSize:20}),n={};for(const e in s)0===e.indexOf("_")&&(n[e.substring(1)]=s[e]);delete n.styleKey,this.style=n,t&&(this.text=t.text,Object.assign(this.style,t.style))}}o.componentName="Text",r([s.type("string")],o.prototype,"text",void 0);let a=class extends n.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={},this._lastFontFamily=void 0}init(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){return s=this,n=void 0,o=function*(){if("Text"===e.componentName)if(e.type===t.OBSERVER_TYPE.ADD){const t=e.component,s=new i.Text(t.text,t.style);this.containerManager.getContainer(e.gameObject.id).addChildAt(s,0),this.texts[e.gameObject.id]={text:s,component:e.component},this.setSize(e)}else 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]):(this.change(e),this.setSize(e))},new((r=void 0)||(r=Promise))((function(e,t){function i(e){try{c(o.next(e))}catch(e){t(e)}}function a(e){try{c(o.throw(e))}catch(e){t(e)}}function c(t){t.done?e(t.value):new r((function(e){e(t.value)})).then(i,a)}c((o=o.apply(s,n||[])).next())}));var s,n,r,o}change(e){const{text:t,component:s}=this.texts[e.gameObject.id];"text"===e.prop.prop[0]?t.text=s.text:"style"===e.prop.prop[0]&&Object.assign(t.style,e.component.style),t.style.fontFamily&&t.style.fontFamily!==this._lastFontFamily&&(this._lastFontFamily=t.style.fontFamily,this.asyncChangeTextStyle(t,t.style))}asyncChangeTextStyle(e,t){if(t.fontFamily){const s=t.fontFamily;t.fontFamily="",this.asyncUpdateFontFamily(e,s)}Object.assign(e.style,t)}asyncUpdateFontFamily(e,s){s&&(Array.isArray(s)?Promise.all(s.map((e=>t.resource.getResource(e)))).finally((()=>{e.style.fontFamily=s})):t.resource.getResource(s).finally((()=>{e.style.fontFamily=s})))}setSize(e){const{transform:t}=e.gameObject;t&&(t.size.width=this.texts[e.gameObject.id].text.width,t.size.height=this.texts[e.gameObject.id].text.height)}};a.systemName="Text",a=r([t.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}]})],a);var c=a;exports.Text=o,exports.TextSystem=c;
16
+ function r(e,t,s,i){var n,r=arguments.length,o=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,s,i);else for(var c=e.length-1;c>=0;c--)(n=e[c])&&(o=(r<3?n(o):r>3?n(t,s,o):n(t,s))||o);return r>3&&o&&Object.defineProperty(t,s,o),o}function o(e,t,s,i){return new(s||(s=Promise))((function(n,r){function o(e){try{a(i.next(e))}catch(e){r(e)}}function c(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){e.done?n(e.value):new s((function(t){t(e.value)})).then(o,c)}a((i=i.apply(e,t||[])).next())}))}class c extends t.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){const s=new e.TextStyle({fontSize:20}),i={};for(const e in s)0===e.indexOf("_")&&(i[e.substring(1)]=s[e]);delete i.styleKey,this.style=i,t&&(this.text=t.text,Object.assign(this.style,t.style))}}c.componentName="Text",r([s.type("string")],c.prototype,"text",void 0);let a=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 o(this,void 0,void 0,(function*(){if("Text"===e.componentName)if(e.type===t.OBSERVER_TYPE.ADD){const t=e.component,s=Object.assign({},t.style),i=s.fontFamily;delete s.fontFamily;const r=new n.Text(t.text,s);this.containerManager.getContainer(e.gameObject.id).addChildAt(r,0),this.texts[e.gameObject.id]={text:r,component:e.component},this.setSize(e),i&&(yield this.waitForFontResource(r,e,i))}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),this.setSize(e);const t=e.component;if("style"===e.prop.prop[0]&&t.style&&t.style.fontFamily){const{text:s}=this.texts[e.gameObject.id];yield this.waitForFontResource(s,e,t.style.fontFamily)}}}))}waitForFontResource(e,s,i){return o(this,void 0,void 0,(function*(){if(i)try{const n=Array.isArray(i)?i[0]:i,r=this.increaseAsyncId(s.gameObject.id);if(yield t.resource.getResource(n),!this.validateAsyncId(s.gameObject.id,r))return;e.style.fontFamily=i,this.setSize(s)}catch(e){console.warn(`字体资源 ${i} 加载失败:`,e)}}))}change(e){const{text:t,component:s}=this.texts[e.gameObject.id];"text"===e.prop.prop[0]?t.text=s.text:"style"===e.prop.prop[0]&&Object.assign(t.style,e.component.style)}setSize(e){const{transform:t}=e.gameObject;t&&(t.size.width=this.texts[e.gameObject.id].text.width,t.size.height=this.texts[e.gameObject.id].text.height)}};a.systemName="Text",a=r([t.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}]})],a);var d=a;exports.Text=c,exports.TextSystem=d;
@@ -67,12 +67,10 @@ export declare class TextSystem extends Renderer {
67
67
  renderSystem: RendererSystem;
68
68
  rendererManager: RendererManager;
69
69
  containerManager: ContainerManager;
70
- _lastFontFamily: string | string[] | undefined;
71
70
  init(): void;
72
71
  componentChanged(changed: ComponentChanged): Promise<void>;
72
+ private waitForFontResource;
73
73
  change(changed: ComponentChanged): void;
74
- asyncChangeTextStyle(text: Text_3, textStyle: TextParams['style']): void;
75
- asyncUpdateFontFamily(text: Text_3, fontFamily: string | string[] | undefined): void;
76
74
  setSize(changed: ComponentChanged): void;
77
75
  }
78
76
 
@@ -1,5 +1,5 @@
1
1
  import { TextStyle } from 'pixi.js';
2
- import { Component, resource, decorators, OBSERVER_TYPE } from '@eva/eva.js';
2
+ import { Component, decorators, OBSERVER_TYPE, resource } from '@eva/eva.js';
3
3
  import { type } from '@eva/inspector-decorator';
4
4
  import { Renderer, RendererSystem } from '@eva/plugin-renderer';
5
5
  import { Text as Text$3 } from '@eva/renderer-adapter';
@@ -69,7 +69,6 @@ let Text = class Text extends Renderer {
69
69
  super(...arguments);
70
70
  this.name = 'Text';
71
71
  this.texts = {};
72
- this._lastFontFamily = undefined;
73
72
  }
74
73
  init() {
75
74
  this.renderSystem = this.game.getSystem(RendererSystem);
@@ -81,13 +80,19 @@ let Text = class Text extends Renderer {
81
80
  return;
82
81
  if (changed.type === OBSERVER_TYPE.ADD) {
83
82
  const component = changed.component;
84
- const text = new Text$3(component.text, component.style);
83
+ const styleWithoutFont = Object.assign({}, component.style);
84
+ const fontFamily = styleWithoutFont.fontFamily;
85
+ delete styleWithoutFont.fontFamily;
86
+ const text = new Text$3(component.text, styleWithoutFont);
85
87
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
86
88
  this.texts[changed.gameObject.id] = {
87
89
  text,
88
90
  component: changed.component,
89
91
  };
90
92
  this.setSize(changed);
93
+ if (fontFamily) {
94
+ yield this.waitForFontResource(text, changed, fontFamily);
95
+ }
91
96
  }
92
97
  else if (changed.type === OBSERVER_TYPE.REMOVE) {
93
98
  this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
@@ -97,6 +102,30 @@ let Text = class Text extends Renderer {
97
102
  else {
98
103
  this.change(changed);
99
104
  this.setSize(changed);
105
+ const component = changed.component;
106
+ if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
107
+ const { text } = this.texts[changed.gameObject.id];
108
+ yield this.waitForFontResource(text, changed, component.style.fontFamily);
109
+ }
110
+ }
111
+ });
112
+ }
113
+ waitForFontResource(text, changed, fontFamily) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ if (!fontFamily) {
116
+ return;
117
+ }
118
+ try {
119
+ const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
120
+ const asyncId = this.increaseAsyncId(changed.gameObject.id);
121
+ yield resource.getResource(fontName);
122
+ if (!this.validateAsyncId(changed.gameObject.id, asyncId))
123
+ return;
124
+ text.style.fontFamily = fontFamily;
125
+ this.setSize(changed);
126
+ }
127
+ catch (error) {
128
+ console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
100
129
  }
101
130
  });
102
131
  }
@@ -108,32 +137,6 @@ let Text = class Text extends Renderer {
108
137
  else if (changed.prop.prop[0] === 'style') {
109
138
  Object.assign(text.style, changed.component.style);
110
139
  }
111
- if (text.style.fontFamily && text.style.fontFamily !== this._lastFontFamily) {
112
- this._lastFontFamily = text.style.fontFamily;
113
- this.asyncChangeTextStyle(text, text.style);
114
- }
115
- }
116
- asyncChangeTextStyle(text, textStyle) {
117
- if (textStyle.fontFamily) {
118
- const fontFamily = textStyle.fontFamily;
119
- textStyle.fontFamily = '';
120
- this.asyncUpdateFontFamily(text, fontFamily);
121
- }
122
- Object.assign(text.style, textStyle);
123
- }
124
- asyncUpdateFontFamily(text, fontFamily) {
125
- if (fontFamily) {
126
- if (Array.isArray(fontFamily)) {
127
- Promise.all(fontFamily.map(font => resource.getResource(font))).finally(() => {
128
- text.style.fontFamily = fontFamily;
129
- });
130
- }
131
- else {
132
- resource.getResource(fontFamily).finally(() => {
133
- text.style.fontFamily = fontFamily;
134
- });
135
- }
136
- }
137
140
  }
138
141
  setSize(changed) {
139
142
  const { transform } = changed.gameObject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-text",
3
- "version": "2.0.1-beta.18",
3
+ "version": "2.0.1-beta.19",
4
4
  "description": "@eva/plugin-renderer-text",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-text.esm.js",
@@ -19,9 +19,9 @@
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
21
  "@eva/inspector-decorator": "^0.0.5",
22
- "@eva/plugin-renderer": "2.0.1-beta.18",
23
- "@eva/renderer-adapter": "2.0.1-beta.18",
24
- "@eva/eva.js": "2.0.1-beta.18",
22
+ "@eva/plugin-renderer": "2.0.1-beta.19",
23
+ "@eva/renderer-adapter": "2.0.1-beta.19",
24
+ "@eva/eva.js": "2.0.1-beta.19",
25
25
  "pixi.js": "^8.8.1"
26
26
  }
27
27
  }