@eva/plugin-renderer-text 2.0.1-beta.20 → 2.0.1-beta.21

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.
@@ -146,12 +146,12 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
146
146
  });
147
147
  }
148
148
  addTextComponent(changed) {
149
+ var _a;
149
150
  return __awaiter(this, void 0, void 0, function* () {
150
151
  const component = changed.component;
151
- const styleWithoutFont = _extends({}, component.style);
152
- const fontFamily = styleWithoutFont.fontFamily;
153
- delete styleWithoutFont.fontFamily;
154
- const text = new rendererAdapter.Text(component.text, styleWithoutFont);
152
+ const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
153
+ const initialText = fontFamily ? '' : component.text;
154
+ const text = new rendererAdapter.Text(initialText, component.style);
155
155
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
156
156
  this.texts[changed.gameObject.id] = {
157
157
  text,
@@ -164,14 +164,14 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
164
164
  });
165
165
  }
166
166
  addHTMLTextComponent(changed) {
167
+ var _a;
167
168
  return __awaiter(this, void 0, void 0, function* () {
168
169
  const component = changed.component;
169
- const styleWithoutFont = _extends({}, component.style);
170
- const fontFamily = styleWithoutFont.fontFamily;
171
- delete styleWithoutFont.fontFamily;
170
+ const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
171
+ const initialText = fontFamily ? '' : component.text;
172
172
  const htmlText = new rendererAdapter.HTMLText(_extends({
173
- text: component.text,
174
- style: styleWithoutFont
173
+ text: initialText,
174
+ style: component.style
175
175
  }, component.textureStyle && {
176
176
  textureStyle: component.textureStyle
177
177
  }));
@@ -196,7 +196,8 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
196
196
  const asyncId = this.increaseAsyncId(changed.gameObject.id);
197
197
  yield eva_js.resource.getResource(fontName);
198
198
  if (!this.validateAsyncId(changed.gameObject.id, asyncId)) return;
199
- text.style.fontFamily = fontFamily;
199
+ const component = this.texts[changed.gameObject.id].component;
200
+ text.text = component.text;
200
201
  this.setSize(changed);
201
202
  } catch (error) {
202
203
  console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
@@ -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 i in n)({}).hasOwnProperty.call(n,i)&&(t[i]=n[i])}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,i,o){"use strict";function s(t,e,n,i){var o,s=arguments.length,r=s<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,i);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(r=(s<3?o(r):s>3?o(e,n,r):o(e,n))||r);return s>3&&r&&Object.defineProperty(e,n,r),r}function r(t,e,n,i){return new(n||(n=Promise))((function(o,s){function r(t){try{l(i.next(t))}catch(t){s(t)}}function c(t){try{l(i.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(r,c)}l((i=i.apply(t,e||[])).next())}))}function c(t){return function(e,n){var i=function(t,e){return t.constructor.IDEProps||(t.constructor.IDEProps={}),t.constructor.IDEProps[e]||(t.constructor.IDEProps[e]={}),t.constructor.IDEProps[e]}(e,n);i.key=n,i.type=t}}class l extends n.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){const n=new e.TextStyle({fontSize:20}),i={};for(const t in n)0===t.indexOf("_")&&(i[t.substring(1)]=n[t]);delete i.styleKey,this.style=i,t&&(this.text=t.text,_extends(this.style,t.style))}}l.componentName="Text",s([c("string")],l.prototype,"text",void 0);class a extends n.Component{constructor(){super(...arguments),this.text="",this.style={},this.textureStyle={}}init(t){this.style=_extends({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==t?void 0:t.style),this.textureStyle=_extends({scaleMode:"linear",resolution:window.devicePixelRatio||1},null==t?void 0:t.textureStyle),t&&(this.text=t.text)}}a.componentName="HTMLText",s([c("string")],a.prototype,"text",void 0);let d=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(t){return r(this,void 0,void 0,(function*(){const e="Text"===t.componentName,i="HTMLText"===t.componentName;if(e||i)if(t.type===n.OBSERVER_TYPE.ADD)e?yield this.addTextComponent(t):yield this.addHTMLTextComponent(t);else if(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];else{this.change(t),this.setSize(t);const e=t.component;if("style"===t.prop.prop[0]&&e.style&&e.style.fontFamily){const{text:n}=this.texts[t.gameObject.id];yield this.waitForFontResource(n,t,e.style.fontFamily)}}}))}addTextComponent(t){return r(this,void 0,void 0,(function*(){const e=t.component,n=_extends({},e.style),i=n.fontFamily;delete n.fontFamily;const s=new o.Text(e.text,n);this.containerManager.getContainer(t.gameObject.id).addChildAt(s,0),this.texts[t.gameObject.id]={text:s,component:e},this.setSize(t),i&&(yield this.waitForFontResource(s,t,i))}))}addHTMLTextComponent(t){return r(this,void 0,void 0,(function*(){const e=t.component,n=_extends({},e.style),i=n.fontFamily;delete n.fontFamily;const s=new o.HTMLText(_extends({text:e.text,style:n},e.textureStyle&&{textureStyle:e.textureStyle}));this.containerManager.getContainer(t.gameObject.id).addChildAt(s,0),this.texts[t.gameObject.id]={text:s,component:e},this.setSize(t),i&&(yield this.waitForFontResource(s,t,i))}))}waitForFontResource(t,e,i){return r(this,void 0,void 0,(function*(){if(i)try{const o=Array.isArray(i)?i[0]:i,s=this.increaseAsyncId(e.gameObject.id);if(yield n.resource.getResource(o),!this.validateAsyncId(e.gameObject.id,s))return;t.style.fontFamily=i,this.setSize(e)}catch(t){console.warn(`字体资源 ${i} 加载失败:`,t)}}))}change(t){const{text:e,component:n}=this.texts[t.gameObject.id],i="HTMLText"===t.componentName;if("text"===t.prop.prop[0])e.text=n.text;else if("style"===t.prop.prop[0])_extends(e.style,n.style);else if("textureStyle"===t.prop.prop[0]&&i){const i=n,s=this.containerManager.getContainer(t.gameObject.id),r=s.getChildIndex(e);s.removeChild(e),e.destroy({children:!0});const c=new o.HTMLText({text:i.text,style:i.style,textureStyle:i.textureStyle});s.addChildAt(c,r),this.texts[t.gameObject.id].text=c}}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)}};d.systemName="Text",d=s([n.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}],HTMLText:["text",{prop:["style"],deep:!0},{prop:["textureStyle"],deep:!0}]})],d);var x=d;return t.HTMLText=a,t.Text=l,t.TextSystem=x,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(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)({}).hasOwnProperty.call(n,i)&&(t[i]=n[i])}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,i,o){"use strict";function s(t,e,n,i){var o,s=arguments.length,r=s<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,i);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(r=(s<3?o(r):s>3?o(e,n,r):o(e,n))||r);return s>3&&r&&Object.defineProperty(e,n,r),r}function r(t,e,n,i){return new(n||(n=Promise))((function(o,s){function r(t){try{l(i.next(t))}catch(t){s(t)}}function c(t){try{l(i.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(r,c)}l((i=i.apply(t,e||[])).next())}))}function c(t){return function(e,n){var i=function(t,e){return t.constructor.IDEProps||(t.constructor.IDEProps={}),t.constructor.IDEProps[e]||(t.constructor.IDEProps[e]={}),t.constructor.IDEProps[e]}(e,n);i.key=n,i.type=t}}class l extends n.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){const n=new e.TextStyle({fontSize:20}),i={};for(const t in n)0===t.indexOf("_")&&(i[t.substring(1)]=n[t]);delete i.styleKey,this.style=i,t&&(this.text=t.text,_extends(this.style,t.style))}}l.componentName="Text",s([c("string")],l.prototype,"text",void 0);class a extends n.Component{constructor(){super(...arguments),this.text="",this.style={},this.textureStyle={}}init(t){this.style=_extends({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==t?void 0:t.style),this.textureStyle=_extends({scaleMode:"linear",resolution:window.devicePixelRatio||1},null==t?void 0:t.textureStyle),t&&(this.text=t.text)}}a.componentName="HTMLText",s([c("string")],a.prototype,"text",void 0);let d=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(t){return r(this,void 0,void 0,(function*(){const e="Text"===t.componentName,i="HTMLText"===t.componentName;if(e||i)if(t.type===n.OBSERVER_TYPE.ADD)e?yield this.addTextComponent(t):yield this.addHTMLTextComponent(t);else if(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];else{this.change(t),this.setSize(t);const e=t.component;if("style"===t.prop.prop[0]&&e.style&&e.style.fontFamily){const{text:n}=this.texts[t.gameObject.id];yield this.waitForFontResource(n,t,e.style.fontFamily)}}}))}addTextComponent(t){var e;return r(this,void 0,void 0,(function*(){const n=t.component,i=null===(e=n.style)||void 0===e?void 0:e.fontFamily,s=i?"":n.text,r=new o.Text(s,n.style);this.containerManager.getContainer(t.gameObject.id).addChildAt(r,0),this.texts[t.gameObject.id]={text:r,component:n},this.setSize(t),i&&(yield this.waitForFontResource(r,t,i))}))}addHTMLTextComponent(t){var e;return r(this,void 0,void 0,(function*(){const n=t.component,i=null===(e=n.style)||void 0===e?void 0:e.fontFamily,s=i?"":n.text,r=new o.HTMLText(_extends({text:s,style:n.style},n.textureStyle&&{textureStyle:n.textureStyle}));this.containerManager.getContainer(t.gameObject.id).addChildAt(r,0),this.texts[t.gameObject.id]={text:r,component:n},this.setSize(t),i&&(yield this.waitForFontResource(r,t,i))}))}waitForFontResource(t,e,i){return r(this,void 0,void 0,(function*(){if(i)try{const o=Array.isArray(i)?i[0]:i,s=this.increaseAsyncId(e.gameObject.id);if(yield n.resource.getResource(o),!this.validateAsyncId(e.gameObject.id,s))return;const r=this.texts[e.gameObject.id].component;t.text=r.text,this.setSize(e)}catch(t){console.warn(`字体资源 ${i} 加载失败:`,t)}}))}change(t){const{text:e,component:n}=this.texts[t.gameObject.id],i="HTMLText"===t.componentName;if("text"===t.prop.prop[0])e.text=n.text;else if("style"===t.prop.prop[0])_extends(e.style,n.style);else if("textureStyle"===t.prop.prop[0]&&i){const i=n,s=this.containerManager.getContainer(t.gameObject.id),r=s.getChildIndex(e);s.removeChild(e),e.destroy({children:!0});const c=new o.HTMLText({text:i.text,style:i.style,textureStyle:i.textureStyle});s.addChildAt(c,r),this.texts[t.gameObject.id].text=c}}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)}};d.systemName="Text",d=s([n.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}],HTMLText:["text",{prop:["style"],deep:!0},{prop:["textureStyle"],deep:!0}]})],d);var x=d;return t.HTMLText=a,t.Text=l,t.TextSystem=x,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;
@@ -129,12 +129,12 @@ let Text = class Text extends pluginRenderer.Renderer {
129
129
  });
130
130
  }
131
131
  addTextComponent(changed) {
132
+ var _a;
132
133
  return __awaiter(this, void 0, void 0, function* () {
133
134
  const component = changed.component;
134
- const styleWithoutFont = Object.assign({}, component.style);
135
- const fontFamily = styleWithoutFont.fontFamily;
136
- delete styleWithoutFont.fontFamily;
137
- const text = new rendererAdapter.Text(component.text, styleWithoutFont);
135
+ const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
136
+ const initialText = fontFamily ? '' : component.text;
137
+ const text = new rendererAdapter.Text(initialText, component.style);
138
138
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
139
139
  this.texts[changed.gameObject.id] = {
140
140
  text,
@@ -147,12 +147,12 @@ let Text = class Text extends pluginRenderer.Renderer {
147
147
  });
148
148
  }
149
149
  addHTMLTextComponent(changed) {
150
+ var _a;
150
151
  return __awaiter(this, void 0, void 0, function* () {
151
152
  const component = changed.component;
152
- const styleWithoutFont = Object.assign({}, component.style);
153
- const fontFamily = styleWithoutFont.fontFamily;
154
- delete styleWithoutFont.fontFamily;
155
- const htmlText = new rendererAdapter.HTMLText(Object.assign({ text: component.text, style: styleWithoutFont }, (component.textureStyle && { textureStyle: component.textureStyle })));
153
+ const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
154
+ const initialText = fontFamily ? '' : component.text;
155
+ const htmlText = new rendererAdapter.HTMLText(Object.assign({ text: initialText, style: component.style }, (component.textureStyle && { textureStyle: component.textureStyle })));
156
156
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(htmlText, 0);
157
157
  this.texts[changed.gameObject.id] = {
158
158
  text: htmlText,
@@ -175,7 +175,8 @@ let Text = class Text extends pluginRenderer.Renderer {
175
175
  yield eva_js.resource.getResource(fontName);
176
176
  if (!this.validateAsyncId(changed.gameObject.id, asyncId))
177
177
  return;
178
- text.style.fontFamily = fontFamily;
178
+ const component = this.texts[changed.gameObject.id].component;
179
+ text.text = component.text;
179
180
  this.setSize(changed);
180
181
  }
181
182
  catch (error) {
@@ -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 o(e,t,i,n){var s,o=arguments.length,r=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,n);else for(var c=e.length-1;c>=0;c--)(s=e[c])&&(r=(o<3?s(r):o>3?s(t,i,r):s(t,i))||r);return o>3&&r&&Object.defineProperty(t,i,r),r}function r(e,t,i,n){return new(i||(i=Promise))((function(s,o){function r(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){e.done?s(e.value):new i((function(t){t(e.value)})).then(r,c)}a((n=n.apply(e,t||[])).next())}))}class c extends t.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){const i=new e.TextStyle({fontSize:20}),n={};for(const e in i)0===e.indexOf("_")&&(n[e.substring(1)]=i[e]);delete n.styleKey,this.style=n,t&&(this.text=t.text,Object.assign(this.style,t.style))}}c.componentName="Text",o([i.type("string")],c.prototype,"text",void 0);class a extends t.Component{constructor(){super(...arguments),this.text="",this.style={},this.textureStyle={}}init(e){this.style=Object.assign({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==e?void 0:e.style),this.textureStyle=Object.assign({scaleMode:"linear",resolution:window.devicePixelRatio||1},null==e?void 0:e.textureStyle),e&&(this.text=e.text)}}a.componentName="HTMLText",o([i.type("string")],a.prototype,"text",void 0);let d=class extends n.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={}}init(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){return r(this,void 0,void 0,(function*(){const i="Text"===e.componentName,n="HTMLText"===e.componentName;if(i||n)if(e.type===t.OBSERVER_TYPE.ADD)i?yield this.addTextComponent(e):yield this.addHTMLTextComponent(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),this.setSize(e);const t=e.component;if("style"===e.prop.prop[0]&&t.style&&t.style.fontFamily){const{text:i}=this.texts[e.gameObject.id];yield this.waitForFontResource(i,e,t.style.fontFamily)}}}))}addTextComponent(e){return r(this,void 0,void 0,(function*(){const t=e.component,i=Object.assign({},t.style),n=i.fontFamily;delete i.fontFamily;const o=new s.Text(t.text,i);this.containerManager.getContainer(e.gameObject.id).addChildAt(o,0),this.texts[e.gameObject.id]={text:o,component:t},this.setSize(e),n&&(yield this.waitForFontResource(o,e,n))}))}addHTMLTextComponent(e){return r(this,void 0,void 0,(function*(){const t=e.component,i=Object.assign({},t.style),n=i.fontFamily;delete i.fontFamily;const o=new s.HTMLText(Object.assign({text:t.text,style:i},t.textureStyle&&{textureStyle:t.textureStyle}));this.containerManager.getContainer(e.gameObject.id).addChildAt(o,0),this.texts[e.gameObject.id]={text:o,component:t},this.setSize(e),n&&(yield this.waitForFontResource(o,e,n))}))}waitForFontResource(e,i,n){return r(this,void 0,void 0,(function*(){if(n)try{const s=Array.isArray(n)?n[0]:n,o=this.increaseAsyncId(i.gameObject.id);if(yield t.resource.getResource(s),!this.validateAsyncId(i.gameObject.id,o))return;e.style.fontFamily=n,this.setSize(i)}catch(e){console.warn(`字体资源 ${n} 加载失败:`,e)}}))}change(e){const{text:t,component:i}=this.texts[e.gameObject.id],n="HTMLText"===e.componentName;if("text"===e.prop.prop[0])t.text=i.text;else if("style"===e.prop.prop[0])Object.assign(t.style,i.style);else if("textureStyle"===e.prop.prop[0]&&n){const n=i,o=this.containerManager.getContainer(e.gameObject.id),r=o.getChildIndex(t);o.removeChild(t),t.destroy({children:!0});const c=new s.HTMLText({text:n.text,style:n.style,textureStyle:n.textureStyle});o.addChildAt(c,r),this.texts[e.gameObject.id].text=c}}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)}};d.systemName="Text",d=o([t.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}],HTMLText:["text",{prop:["style"],deep:!0},{prop:["textureStyle"],deep:!0}]})],d);var l=d;exports.HTMLText=a,exports.Text=c,exports.TextSystem=l;
16
+ function o(e,t,i,n){var s,o=arguments.length,r=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,n);else for(var c=e.length-1;c>=0;c--)(s=e[c])&&(r=(o<3?s(r):o>3?s(t,i,r):s(t,i))||r);return o>3&&r&&Object.defineProperty(t,i,r),r}function r(e,t,i,n){return new(i||(i=Promise))((function(s,o){function r(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){e.done?s(e.value):new i((function(t){t(e.value)})).then(r,c)}a((n=n.apply(e,t||[])).next())}))}class c extends t.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){const i=new e.TextStyle({fontSize:20}),n={};for(const e in i)0===e.indexOf("_")&&(n[e.substring(1)]=i[e]);delete n.styleKey,this.style=n,t&&(this.text=t.text,Object.assign(this.style,t.style))}}c.componentName="Text",o([i.type("string")],c.prototype,"text",void 0);class a extends t.Component{constructor(){super(...arguments),this.text="",this.style={},this.textureStyle={}}init(e){this.style=Object.assign({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==e?void 0:e.style),this.textureStyle=Object.assign({scaleMode:"linear",resolution:window.devicePixelRatio||1},null==e?void 0:e.textureStyle),e&&(this.text=e.text)}}a.componentName="HTMLText",o([i.type("string")],a.prototype,"text",void 0);let d=class extends n.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={}}init(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){return r(this,void 0,void 0,(function*(){const i="Text"===e.componentName,n="HTMLText"===e.componentName;if(i||n)if(e.type===t.OBSERVER_TYPE.ADD)i?yield this.addTextComponent(e):yield this.addHTMLTextComponent(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),this.setSize(e);const t=e.component;if("style"===e.prop.prop[0]&&t.style&&t.style.fontFamily){const{text:i}=this.texts[e.gameObject.id];yield this.waitForFontResource(i,e,t.style.fontFamily)}}}))}addTextComponent(e){var t;return r(this,void 0,void 0,(function*(){const i=e.component,n=null===(t=i.style)||void 0===t?void 0:t.fontFamily,o=n?"":i.text,r=new s.Text(o,i.style);this.containerManager.getContainer(e.gameObject.id).addChildAt(r,0),this.texts[e.gameObject.id]={text:r,component:i},this.setSize(e),n&&(yield this.waitForFontResource(r,e,n))}))}addHTMLTextComponent(e){var t;return r(this,void 0,void 0,(function*(){const i=e.component,n=null===(t=i.style)||void 0===t?void 0:t.fontFamily,o=n?"":i.text,r=new s.HTMLText(Object.assign({text:o,style:i.style},i.textureStyle&&{textureStyle:i.textureStyle}));this.containerManager.getContainer(e.gameObject.id).addChildAt(r,0),this.texts[e.gameObject.id]={text:r,component:i},this.setSize(e),n&&(yield this.waitForFontResource(r,e,n))}))}waitForFontResource(e,i,n){return r(this,void 0,void 0,(function*(){if(n)try{const s=Array.isArray(n)?n[0]:n,o=this.increaseAsyncId(i.gameObject.id);if(yield t.resource.getResource(s),!this.validateAsyncId(i.gameObject.id,o))return;const r=this.texts[i.gameObject.id].component;e.text=r.text,this.setSize(i)}catch(e){console.warn(`字体资源 ${n} 加载失败:`,e)}}))}change(e){const{text:t,component:i}=this.texts[e.gameObject.id],n="HTMLText"===e.componentName;if("text"===e.prop.prop[0])t.text=i.text;else if("style"===e.prop.prop[0])Object.assign(t.style,i.style);else if("textureStyle"===e.prop.prop[0]&&n){const n=i,o=this.containerManager.getContainer(e.gameObject.id),r=o.getChildIndex(t);o.removeChild(t),t.destroy({children:!0});const c=new s.HTMLText({text:n.text,style:n.style,textureStyle:n.textureStyle});o.addChildAt(c,r),this.texts[e.gameObject.id].text=c}}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)}};d.systemName="Text",d=o([t.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}],HTMLText:["text",{prop:["style"],deep:!0},{prop:["textureStyle"],deep:!0}]})],d);var l=d;exports.HTMLText=a,exports.Text=c,exports.TextSystem=l;
@@ -125,12 +125,12 @@ let Text = class Text extends Renderer {
125
125
  });
126
126
  }
127
127
  addTextComponent(changed) {
128
+ var _a;
128
129
  return __awaiter(this, void 0, void 0, function* () {
129
130
  const component = changed.component;
130
- const styleWithoutFont = Object.assign({}, component.style);
131
- const fontFamily = styleWithoutFont.fontFamily;
132
- delete styleWithoutFont.fontFamily;
133
- const text = new Text$3(component.text, styleWithoutFont);
131
+ const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
132
+ const initialText = fontFamily ? '' : component.text;
133
+ const text = new Text$3(initialText, component.style);
134
134
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
135
135
  this.texts[changed.gameObject.id] = {
136
136
  text,
@@ -143,12 +143,12 @@ let Text = class Text extends Renderer {
143
143
  });
144
144
  }
145
145
  addHTMLTextComponent(changed) {
146
+ var _a;
146
147
  return __awaiter(this, void 0, void 0, function* () {
147
148
  const component = changed.component;
148
- const styleWithoutFont = Object.assign({}, component.style);
149
- const fontFamily = styleWithoutFont.fontFamily;
150
- delete styleWithoutFont.fontFamily;
151
- const htmlText = new HTMLText$1(Object.assign({ text: component.text, style: styleWithoutFont }, (component.textureStyle && { textureStyle: component.textureStyle })));
149
+ const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
150
+ const initialText = fontFamily ? '' : component.text;
151
+ const htmlText = new HTMLText$1(Object.assign({ text: initialText, style: component.style }, (component.textureStyle && { textureStyle: component.textureStyle })));
152
152
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(htmlText, 0);
153
153
  this.texts[changed.gameObject.id] = {
154
154
  text: htmlText,
@@ -171,7 +171,8 @@ let Text = class Text extends Renderer {
171
171
  yield resource.getResource(fontName);
172
172
  if (!this.validateAsyncId(changed.gameObject.id, asyncId))
173
173
  return;
174
- text.style.fontFamily = fontFamily;
174
+ const component = this.texts[changed.gameObject.id].component;
175
+ text.text = component.text;
175
176
  this.setSize(changed);
176
177
  }
177
178
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-text",
3
- "version": "2.0.1-beta.20",
3
+ "version": "2.0.1-beta.21",
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.20",
23
- "@eva/renderer-adapter": "2.0.1-beta.20",
24
- "@eva/eva.js": "2.0.1-beta.20",
22
+ "@eva/plugin-renderer": "2.0.1-beta.21",
23
+ "@eva/renderer-adapter": "2.0.1-beta.21",
24
+ "@eva/eva.js": "2.0.1-beta.21",
25
25
  "pixi.js": "^8.8.1"
26
26
  }
27
27
  }