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

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.
@@ -126,6 +126,7 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
126
126
  } else {
127
127
  yield this.addHTMLTextComponent(changed);
128
128
  }
129
+ this.setSize(changed);
129
130
  } else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
130
131
  this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
131
132
  this.texts[changed.gameObject.id].text.destroy({
@@ -134,7 +135,6 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
134
135
  delete this.texts[changed.gameObject.id];
135
136
  } else {
136
137
  this.change(changed);
137
- this.setSize(changed);
138
138
  const component = changed.component;
139
139
  if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
140
140
  const {
@@ -142,36 +142,38 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
142
142
  } = this.texts[changed.gameObject.id];
143
143
  yield this.waitForFontResource(text, changed, component.style.fontFamily);
144
144
  }
145
+ this.setSize(changed);
145
146
  }
146
147
  });
147
148
  }
148
149
  addTextComponent(changed) {
149
- var _a;
150
150
  return __awaiter(this, void 0, void 0, function* () {
151
151
  const component = changed.component;
152
- const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
152
+ const styleWithoutFont = _extends({}, component.style);
153
+ const fontFamily = styleWithoutFont.fontFamily;
154
+ delete styleWithoutFont.fontFamily;
153
155
  const initialText = fontFamily ? '' : component.text;
154
- const text = new rendererAdapter.Text(initialText, component.style);
156
+ const text = new rendererAdapter.Text(initialText, styleWithoutFont);
155
157
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
156
158
  this.texts[changed.gameObject.id] = {
157
159
  text,
158
160
  component
159
161
  };
160
- this.setSize(changed);
161
162
  if (fontFamily) {
162
163
  yield this.waitForFontResource(text, changed, fontFamily);
163
164
  }
164
165
  });
165
166
  }
166
167
  addHTMLTextComponent(changed) {
167
- var _a;
168
168
  return __awaiter(this, void 0, void 0, function* () {
169
169
  const component = changed.component;
170
- const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
170
+ const styleWithoutFont = _extends({}, component.style);
171
+ const fontFamily = styleWithoutFont.fontFamily;
172
+ delete styleWithoutFont.fontFamily;
171
173
  const initialText = fontFamily ? '' : component.text;
172
174
  const htmlText = new rendererAdapter.HTMLText(_extends({
173
175
  text: initialText,
174
- style: component.style
176
+ style: styleWithoutFont
175
177
  }, component.textureStyle && {
176
178
  textureStyle: component.textureStyle
177
179
  }));
@@ -180,7 +182,6 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
180
182
  text: htmlText,
181
183
  component
182
184
  };
183
- this.setSize(changed);
184
185
  if (fontFamily) {
185
186
  yield this.waitForFontResource(htmlText, changed, fontFamily);
186
187
  }
@@ -197,8 +198,8 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
197
198
  yield eva_js.resource.getResource(fontName);
198
199
  if (!this.validateAsyncId(changed.gameObject.id, asyncId)) return;
199
200
  const component = this.texts[changed.gameObject.id].component;
201
+ text.style.fontFamily = fontFamily;
200
202
  text.text = component.text;
201
- this.setSize(changed);
202
203
  } catch (error) {
203
204
  console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
204
205
  }
@@ -236,8 +237,12 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
236
237
  transform
237
238
  } = changed.gameObject;
238
239
  if (!transform) return;
239
- transform.size.width = this.texts[changed.gameObject.id].text.width;
240
- transform.size.height = this.texts[changed.gameObject.id].text.height;
240
+ const {
241
+ text
242
+ } = this.texts[changed.gameObject.id];
243
+ const size = text.getSize();
244
+ transform.size.width = size.width;
245
+ transform.size.height = size.height;
241
246
  }
242
247
  };
243
248
  Text.systemName = 'Text';
@@ -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){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;
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),this.setSize(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);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)}this.setSize(t)}}))}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=i?"":e.text,r=new o.Text(s,n);this.containerManager.getContainer(t.gameObject.id).addChildAt(r,0),this.texts[t.gameObject.id]={text:r,component:e},i&&(yield this.waitForFontResource(r,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=i?"":e.text,r=new o.HTMLText(_extends({text:s,style:n},e.textureStyle&&{textureStyle:e.textureStyle}));this.containerManager.getContainer(t.gameObject.id).addChildAt(r,0),this.texts[t.gameObject.id]={text:r,component:e},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.style.fontFamily=i,t.text=r.text}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;if(!e)return;const{text:n}=this.texts[t.gameObject.id],i=n.getSize();e.size.width=i.width,e.size.height=i.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;
@@ -111,6 +111,7 @@ let Text = class Text extends pluginRenderer.Renderer {
111
111
  else {
112
112
  yield this.addHTMLTextComponent(changed);
113
113
  }
114
+ this.setSize(changed);
114
115
  }
115
116
  else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
116
117
  this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
@@ -119,46 +120,46 @@ let Text = class Text extends pluginRenderer.Renderer {
119
120
  }
120
121
  else {
121
122
  this.change(changed);
122
- this.setSize(changed);
123
123
  const component = changed.component;
124
124
  if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
125
125
  const { text } = this.texts[changed.gameObject.id];
126
126
  yield this.waitForFontResource(text, changed, component.style.fontFamily);
127
127
  }
128
+ this.setSize(changed);
128
129
  }
129
130
  });
130
131
  }
131
132
  addTextComponent(changed) {
132
- var _a;
133
133
  return __awaiter(this, void 0, void 0, function* () {
134
134
  const component = changed.component;
135
- const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
135
+ const styleWithoutFont = Object.assign({}, component.style);
136
+ const fontFamily = styleWithoutFont.fontFamily;
137
+ delete styleWithoutFont.fontFamily;
136
138
  const initialText = fontFamily ? '' : component.text;
137
- const text = new rendererAdapter.Text(initialText, component.style);
139
+ const text = new rendererAdapter.Text(initialText, styleWithoutFont);
138
140
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
139
141
  this.texts[changed.gameObject.id] = {
140
142
  text,
141
143
  component,
142
144
  };
143
- this.setSize(changed);
144
145
  if (fontFamily) {
145
146
  yield this.waitForFontResource(text, changed, fontFamily);
146
147
  }
147
148
  });
148
149
  }
149
150
  addHTMLTextComponent(changed) {
150
- var _a;
151
151
  return __awaiter(this, void 0, void 0, function* () {
152
152
  const component = changed.component;
153
- const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
153
+ const styleWithoutFont = Object.assign({}, component.style);
154
+ const fontFamily = styleWithoutFont.fontFamily;
155
+ delete styleWithoutFont.fontFamily;
154
156
  const initialText = fontFamily ? '' : component.text;
155
- const htmlText = new rendererAdapter.HTMLText(Object.assign({ text: initialText, style: component.style }, (component.textureStyle && { textureStyle: component.textureStyle })));
157
+ const htmlText = new rendererAdapter.HTMLText(Object.assign({ text: initialText, style: styleWithoutFont }, (component.textureStyle && { textureStyle: component.textureStyle })));
156
158
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(htmlText, 0);
157
159
  this.texts[changed.gameObject.id] = {
158
160
  text: htmlText,
159
161
  component,
160
162
  };
161
- this.setSize(changed);
162
163
  if (fontFamily) {
163
164
  yield this.waitForFontResource(htmlText, changed, fontFamily);
164
165
  }
@@ -176,8 +177,8 @@ let Text = class Text extends pluginRenderer.Renderer {
176
177
  if (!this.validateAsyncId(changed.gameObject.id, asyncId))
177
178
  return;
178
179
  const component = this.texts[changed.gameObject.id].component;
180
+ text.style.fontFamily = fontFamily;
179
181
  text.text = component.text;
180
- this.setSize(changed);
181
182
  }
182
183
  catch (error) {
183
184
  console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
@@ -212,8 +213,10 @@ let Text = class Text extends pluginRenderer.Renderer {
212
213
  const { transform } = changed.gameObject;
213
214
  if (!transform)
214
215
  return;
215
- transform.size.width = this.texts[changed.gameObject.id].text.width;
216
- transform.size.height = this.texts[changed.gameObject.id].text.height;
216
+ const { text } = this.texts[changed.gameObject.id];
217
+ const size = text.getSize();
218
+ transform.size.width = size.width;
219
+ transform.size.height = size.height;
217
220
  }
218
221
  };
219
222
  Text.systemName = 'Text';
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("pixi.js"),t=require("@eva/eva.js"),i=require("@eva/inspector-decorator"),n=require("@eva/plugin-renderer"),s=require("@eva/renderer-adapter");
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("pixi.js"),t=require("@eva/eva.js"),n=require("@eva/inspector-decorator"),i=require("@eva/plugin-renderer"),s=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 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;
16
+ function o(e,t,n,i){var s,o=arguments.length,r=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,i);else for(var c=e.length-1;c>=0;c--)(s=e[c])&&(r=(o<3?s(r):o>3?s(t,n,r):s(t,n))||r);return o>3&&r&&Object.defineProperty(t,n,r),r}function r(e,t,n,i){return new(n||(n=Promise))((function(s,o){function r(e){try{a(i.next(e))}catch(e){o(e)}}function c(e){try{a(i.throw(e))}catch(e){o(e)}}function a(e){e.done?s(e.value):new n((function(t){t(e.value)})).then(r,c)}a((i=i.apply(e,t||[])).next())}))}class c extends t.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){const n=new e.TextStyle({fontSize:20}),i={};for(const e in n)0===e.indexOf("_")&&(i[e.substring(1)]=n[e]);delete i.styleKey,this.style=i,t&&(this.text=t.text,Object.assign(this.style,t.style))}}c.componentName="Text",o([n.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([n.type("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(e){return r(this,void 0,void 0,(function*(){const n="Text"===e.componentName,i="HTMLText"===e.componentName;if(n||i)if(e.type===t.OBSERVER_TYPE.ADD)n?yield this.addTextComponent(e):yield this.addHTMLTextComponent(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:n}=this.texts[e.gameObject.id];yield this.waitForFontResource(n,e,t.style.fontFamily)}this.setSize(e)}}))}addTextComponent(e){return r(this,void 0,void 0,(function*(){const t=e.component,n=Object.assign({},t.style),i=n.fontFamily;delete n.fontFamily;const o=i?"":t.text,r=new s.Text(o,n);this.containerManager.getContainer(e.gameObject.id).addChildAt(r,0),this.texts[e.gameObject.id]={text:r,component:t},i&&(yield this.waitForFontResource(r,e,i))}))}addHTMLTextComponent(e){return r(this,void 0,void 0,(function*(){const t=e.component,n=Object.assign({},t.style),i=n.fontFamily;delete n.fontFamily;const o=i?"":t.text,r=new s.HTMLText(Object.assign({text:o,style:n},t.textureStyle&&{textureStyle:t.textureStyle}));this.containerManager.getContainer(e.gameObject.id).addChildAt(r,0),this.texts[e.gameObject.id]={text:r,component:t},i&&(yield this.waitForFontResource(r,e,i))}))}waitForFontResource(e,n,i){return r(this,void 0,void 0,(function*(){if(i)try{const s=Array.isArray(i)?i[0]:i,o=this.increaseAsyncId(n.gameObject.id);if(yield t.resource.getResource(s),!this.validateAsyncId(n.gameObject.id,o))return;const r=this.texts[n.gameObject.id].component;e.style.fontFamily=i,e.text=r.text}catch(e){console.warn(`字体资源 ${i} 加载失败:`,e)}}))}change(e){const{text:t,component:n}=this.texts[e.gameObject.id],i="HTMLText"===e.componentName;if("text"===e.prop.prop[0])t.text=n.text;else if("style"===e.prop.prop[0])Object.assign(t.style,n.style);else if("textureStyle"===e.prop.prop[0]&&i){const i=n,o=this.containerManager.getContainer(e.gameObject.id),r=o.getChildIndex(t);o.removeChild(t),t.destroy({children:!0});const c=new s.HTMLText({text:i.text,style:i.style,textureStyle:i.textureStyle});o.addChildAt(c,r),this.texts[e.gameObject.id].text=c}}setSize(e){const{transform:t}=e.gameObject;if(!t)return;const{text:n}=this.texts[e.gameObject.id],i=n.getSize();t.size.width=i.width,t.size.height=i.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;
@@ -107,6 +107,7 @@ let Text = class Text extends Renderer {
107
107
  else {
108
108
  yield this.addHTMLTextComponent(changed);
109
109
  }
110
+ this.setSize(changed);
110
111
  }
111
112
  else if (changed.type === OBSERVER_TYPE.REMOVE) {
112
113
  this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
@@ -115,46 +116,46 @@ let Text = class Text extends Renderer {
115
116
  }
116
117
  else {
117
118
  this.change(changed);
118
- this.setSize(changed);
119
119
  const component = changed.component;
120
120
  if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
121
121
  const { text } = this.texts[changed.gameObject.id];
122
122
  yield this.waitForFontResource(text, changed, component.style.fontFamily);
123
123
  }
124
+ this.setSize(changed);
124
125
  }
125
126
  });
126
127
  }
127
128
  addTextComponent(changed) {
128
- var _a;
129
129
  return __awaiter(this, void 0, void 0, function* () {
130
130
  const component = changed.component;
131
- const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
131
+ const styleWithoutFont = Object.assign({}, component.style);
132
+ const fontFamily = styleWithoutFont.fontFamily;
133
+ delete styleWithoutFont.fontFamily;
132
134
  const initialText = fontFamily ? '' : component.text;
133
- const text = new Text$3(initialText, component.style);
135
+ const text = new Text$3(initialText, styleWithoutFont);
134
136
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
135
137
  this.texts[changed.gameObject.id] = {
136
138
  text,
137
139
  component,
138
140
  };
139
- this.setSize(changed);
140
141
  if (fontFamily) {
141
142
  yield this.waitForFontResource(text, changed, fontFamily);
142
143
  }
143
144
  });
144
145
  }
145
146
  addHTMLTextComponent(changed) {
146
- var _a;
147
147
  return __awaiter(this, void 0, void 0, function* () {
148
148
  const component = changed.component;
149
- const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
149
+ const styleWithoutFont = Object.assign({}, component.style);
150
+ const fontFamily = styleWithoutFont.fontFamily;
151
+ delete styleWithoutFont.fontFamily;
150
152
  const initialText = fontFamily ? '' : component.text;
151
- const htmlText = new HTMLText$1(Object.assign({ text: initialText, style: component.style }, (component.textureStyle && { textureStyle: component.textureStyle })));
153
+ const htmlText = new HTMLText$1(Object.assign({ text: initialText, style: styleWithoutFont }, (component.textureStyle && { textureStyle: component.textureStyle })));
152
154
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(htmlText, 0);
153
155
  this.texts[changed.gameObject.id] = {
154
156
  text: htmlText,
155
157
  component,
156
158
  };
157
- this.setSize(changed);
158
159
  if (fontFamily) {
159
160
  yield this.waitForFontResource(htmlText, changed, fontFamily);
160
161
  }
@@ -172,8 +173,8 @@ let Text = class Text extends Renderer {
172
173
  if (!this.validateAsyncId(changed.gameObject.id, asyncId))
173
174
  return;
174
175
  const component = this.texts[changed.gameObject.id].component;
176
+ text.style.fontFamily = fontFamily;
175
177
  text.text = component.text;
176
- this.setSize(changed);
177
178
  }
178
179
  catch (error) {
179
180
  console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
@@ -208,8 +209,10 @@ let Text = class Text extends Renderer {
208
209
  const { transform } = changed.gameObject;
209
210
  if (!transform)
210
211
  return;
211
- transform.size.width = this.texts[changed.gameObject.id].text.width;
212
- transform.size.height = this.texts[changed.gameObject.id].text.height;
212
+ const { text } = this.texts[changed.gameObject.id];
213
+ const size = text.getSize();
214
+ transform.size.width = size.width;
215
+ transform.size.height = size.height;
213
216
  }
214
217
  };
215
218
  Text.systemName = 'Text';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-text",
3
- "version": "2.0.1-beta.21",
3
+ "version": "2.0.1-beta.23",
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.21",
23
- "@eva/renderer-adapter": "2.0.1-beta.21",
24
- "@eva/eva.js": "2.0.1-beta.21",
22
+ "@eva/plugin-renderer": "2.0.1-beta.23",
23
+ "@eva/renderer-adapter": "2.0.1-beta.23",
24
+ "@eva/eva.js": "2.0.1-beta.23",
25
25
  "pixi.js": "^8.8.1"
26
26
  }
27
27
  }