@eva/plugin-renderer-text 2.0.1-beta.25 → 2.0.1-beta.27

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.
@@ -60,6 +60,7 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
60
60
  super(...arguments);
61
61
  this.text = '';
62
62
  this.style = {};
63
+ this.resolution = 1;
63
64
  }
64
65
  init(obj) {
65
66
  const style = new pixi_js.TextStyle({
@@ -76,11 +77,15 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
76
77
  if (obj) {
77
78
  this.text = obj.text;
78
79
  _extends(this.style, obj.style);
80
+ if (obj.resolution !== undefined) {
81
+ this.resolution = obj.resolution;
82
+ }
79
83
  }
80
84
  }
81
85
  }
82
86
  Text$2.componentName = 'Text';
83
87
  __decorate([type('string')], Text$2.prototype, "text", void 0);
88
+ __decorate([type('number')], Text$2.prototype, "resolution", void 0);
84
89
  class HTMLText extends eva_js.Component {
85
90
  constructor() {
86
91
  super(...arguments);
@@ -154,6 +159,9 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
154
159
  delete styleWithoutFont.fontFamily;
155
160
  const initialText = fontFamily ? '' : component.text;
156
161
  const text = new rendererAdapter.Text(initialText, styleWithoutFont);
162
+ if (component.resolution !== undefined && component.resolution > 0) {
163
+ text.resolution = component.resolution;
164
+ }
157
165
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
158
166
  this.texts[changed.gameObject.id] = {
159
167
  text,
@@ -215,6 +223,11 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
215
223
  text.text = component.text;
216
224
  } else if (changed.prop.prop[0] === 'style') {
217
225
  _extends(text.style, component.style);
226
+ } else if (changed.prop.prop[0] === 'resolution' && !isHTMLText) {
227
+ const textComponent = component;
228
+ if (textComponent.resolution !== undefined && textComponent.resolution > 0) {
229
+ text.resolution = textComponent.resolution;
230
+ }
218
231
  } else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
219
232
  const htmlComponent = component;
220
233
  const container = this.containerManager.getContainer(changed.gameObject.id);
@@ -250,7 +263,7 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
250
263
  Text: ['text', {
251
264
  prop: ['style'],
252
265
  deep: true
253
- }],
266
+ }, 'resolution'],
254
267
  HTMLText: ['text', {
255
268
  prop: ['style'],
256
269
  deep: true
@@ -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),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;
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 o in n)({}).hasOwnProperty.call(n,o)&&(t[o]=n[o])}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,o,i){"use strict";function s(t,e,n,o){var i,s=arguments.length,r=s<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,o);else for(var l=t.length-1;l>=0;l--)(i=t[l])&&(r=(s<3?i(r):s>3?i(e,n,r):i(e,n))||r);return s>3&&r&&Object.defineProperty(e,n,r),r}function r(t,e,n,o){return new(n||(n=Promise))((function(i,s){function r(t){try{c(o.next(t))}catch(t){s(t)}}function l(t){try{c(o.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(r,l)}c((o=o.apply(t,e||[])).next())}))}function l(t){return function(e,n){var o=function(t,e){return t.constructor.IDEProps||(t.constructor.IDEProps={}),t.constructor.IDEProps[e]||(t.constructor.IDEProps[e]={}),t.constructor.IDEProps[e]}(e,n);o.key=n,o.type=t}}class c extends n.Component{constructor(){super(...arguments),this.text="",this.style={},this.resolution=1}init(t){const n=new e.TextStyle({fontSize:20}),o={};for(const t in n)0===t.indexOf("_")&&(o[t.substring(1)]=n[t]);delete o.styleKey,this.style=o,t&&(this.text=t.text,_extends(this.style,t.style),void 0!==t.resolution&&(this.resolution=t.resolution))}}c.componentName="Text",s([l("string")],c.prototype,"text",void 0),s([l("number")],c.prototype,"resolution",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([l("string")],a.prototype,"text",void 0);let d=class extends o.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={}}init(){this.renderSystem=this.game.getSystem(o.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(t){return r(this,void 0,void 0,(function*(){const e="Text"===t.componentName,o="HTMLText"===t.componentName;if(e||o)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),o=n.fontFamily;delete n.fontFamily;const s=o?"":e.text,r=new i.Text(s,n);void 0!==e.resolution&&e.resolution>0&&(r.resolution=e.resolution),this.containerManager.getContainer(t.gameObject.id).addChildAt(r,0),this.texts[t.gameObject.id]={text:r,component:e},o&&(yield this.waitForFontResource(r,t,o))}))}addHTMLTextComponent(t){return r(this,void 0,void 0,(function*(){const e=t.component,n=_extends({},e.style),o=n.fontFamily;delete n.fontFamily;const s=o?"":e.text,r=new i.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},o&&(yield this.waitForFontResource(r,t,o))}))}waitForFontResource(t,e,o){return r(this,void 0,void 0,(function*(){if(o)try{const i=Array.isArray(o)?o[0]:o,s=this.increaseAsyncId(e.gameObject.id);if(yield n.resource.getResource(i),!this.validateAsyncId(e.gameObject.id,s))return;const r=this.texts[e.gameObject.id].component;t.style.fontFamily=o,t.text=r.text}catch(t){console.warn(`字体资源 ${o} 加载失败:`,t)}}))}change(t){const{text:e,component:n}=this.texts[t.gameObject.id],o="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("resolution"!==t.prop.prop[0]||o){if("textureStyle"===t.prop.prop[0]&&o){const o=n,s=this.containerManager.getContainer(t.gameObject.id),r=s.getChildIndex(e);s.removeChild(e),e.destroy({children:!0});const l=new i.HTMLText({text:o.text,style:o.style,textureStyle:o.textureStyle});s.addChildAt(l,r),this.texts[t.gameObject.id].text=l}}else{const t=n;void 0!==t.resolution&&t.resolution>0&&(e.resolution=t.resolution)}}setSize(t){const{transform:e}=t.gameObject;if(!e)return;const{text:n}=this.texts[t.gameObject.id],o=n.getSize();e.size.width=o.width,e.size.height=o.height}};d.systemName="Text",d=s([n.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0},"resolution"],HTMLText:["text",{prop:["style"],deep:!0},{prop:["textureStyle"],deep:!0}]})],d);var u=d;return t.HTMLText=a,t.Text=c,t.TextSystem=u,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;
@@ -44,6 +44,7 @@ class Text$2 extends eva_js.Component {
44
44
  super(...arguments);
45
45
  this.text = '';
46
46
  this.style = {};
47
+ this.resolution = 1;
47
48
  }
48
49
  init(obj) {
49
50
  const style = new pixi_js.TextStyle({
@@ -60,13 +61,19 @@ class Text$2 extends eva_js.Component {
60
61
  if (obj) {
61
62
  this.text = obj.text;
62
63
  Object.assign(this.style, obj.style);
64
+ if (obj.resolution !== undefined) {
65
+ this.resolution = obj.resolution;
66
+ }
63
67
  }
64
68
  }
65
69
  }
66
70
  Text$2.componentName = 'Text';
67
71
  __decorate([
68
72
  inspectorDecorator.type('string')
69
- ], Text$2.prototype, "text", void 0);
73
+ ], Text$2.prototype, "text", void 0);
74
+ __decorate([
75
+ inspectorDecorator.type('number')
76
+ ], Text$2.prototype, "resolution", void 0);
70
77
 
71
78
  class HTMLText extends eva_js.Component {
72
79
  constructor() {
@@ -137,6 +144,9 @@ let Text = class Text extends pluginRenderer.Renderer {
137
144
  delete styleWithoutFont.fontFamily;
138
145
  const initialText = fontFamily ? '' : component.text;
139
146
  const text = new rendererAdapter.Text(initialText, styleWithoutFont);
147
+ if (component.resolution !== undefined && component.resolution > 0) {
148
+ text.resolution = component.resolution;
149
+ }
140
150
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
141
151
  this.texts[changed.gameObject.id] = {
142
152
  text,
@@ -194,6 +204,12 @@ let Text = class Text extends pluginRenderer.Renderer {
194
204
  else if (changed.prop.prop[0] === 'style') {
195
205
  Object.assign(text.style, component.style);
196
206
  }
207
+ else if (changed.prop.prop[0] === 'resolution' && !isHTMLText) {
208
+ const textComponent = component;
209
+ if (textComponent.resolution !== undefined && textComponent.resolution > 0) {
210
+ text.resolution = textComponent.resolution;
211
+ }
212
+ }
197
213
  else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
198
214
  const htmlComponent = component;
199
215
  const container = this.containerManager.getContainer(changed.gameObject.id);
@@ -222,7 +238,7 @@ let Text = class Text extends pluginRenderer.Renderer {
222
238
  Text.systemName = 'Text';
223
239
  Text = __decorate([
224
240
  eva_js.decorators.componentObserver({
225
- Text: ['text', { prop: ['style'], deep: true }],
241
+ Text: ['text', { prop: ['style'], deep: true }, 'resolution'],
226
242
  HTMLText: ['text', { prop: ['style'], deep: true }, { prop: ['textureStyle'], deep: true }],
227
243
  })
228
244
  ], Text);
@@ -1,4 +1,4 @@
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");
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("pixi.js"),t=require("@eva/eva.js"),i=require("@eva/inspector-decorator"),o=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 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;
16
+ function s(e,t,i,o){var n,s=arguments.length,r=s<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,o);else for(var c=e.length-1;c>=0;c--)(n=e[c])&&(r=(s<3?n(r):s>3?n(t,i,r):n(t,i))||r);return s>3&&r&&Object.defineProperty(t,i,r),r}function r(e,t,i,o){return new(i||(i=Promise))((function(n,s){function r(e){try{l(o.next(e))}catch(e){s(e)}}function c(e){try{l(o.throw(e))}catch(e){s(e)}}function l(e){e.done?n(e.value):new i((function(t){t(e.value)})).then(r,c)}l((o=o.apply(e,t||[])).next())}))}class c extends t.Component{constructor(){super(...arguments),this.text="",this.style={},this.resolution=1}init(t){const i=new e.TextStyle({fontSize:20}),o={};for(const e in i)0===e.indexOf("_")&&(o[e.substring(1)]=i[e]);delete o.styleKey,this.style=o,t&&(this.text=t.text,Object.assign(this.style,t.style),void 0!==t.resolution&&(this.resolution=t.resolution))}}c.componentName="Text",s([i.type("string")],c.prototype,"text",void 0),s([i.type("number")],c.prototype,"resolution",void 0);class l 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)}}l.componentName="HTMLText",s([i.type("string")],l.prototype,"text",void 0);let a=class extends o.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={}}init(){this.renderSystem=this.game.getSystem(o.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){return r(this,void 0,void 0,(function*(){const i="Text"===e.componentName,o="HTMLText"===e.componentName;if(i||o)if(e.type===t.OBSERVER_TYPE.ADD)i?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:i}=this.texts[e.gameObject.id];yield this.waitForFontResource(i,e,t.style.fontFamily)}this.setSize(e)}}))}addTextComponent(e){return r(this,void 0,void 0,(function*(){const t=e.component,i=Object.assign({},t.style),o=i.fontFamily;delete i.fontFamily;const s=o?"":t.text,r=new n.Text(s,i);void 0!==t.resolution&&t.resolution>0&&(r.resolution=t.resolution),this.containerManager.getContainer(e.gameObject.id).addChildAt(r,0),this.texts[e.gameObject.id]={text:r,component:t},o&&(yield this.waitForFontResource(r,e,o))}))}addHTMLTextComponent(e){return r(this,void 0,void 0,(function*(){const t=e.component,i=Object.assign({},t.style),o=i.fontFamily;delete i.fontFamily;const s=o?"":t.text,r=new n.HTMLText(Object.assign({text:s,style:i},t.textureStyle&&{textureStyle:t.textureStyle}));this.containerManager.getContainer(e.gameObject.id).addChildAt(r,0),this.texts[e.gameObject.id]={text:r,component:t},o&&(yield this.waitForFontResource(r,e,o))}))}waitForFontResource(e,i,o){return r(this,void 0,void 0,(function*(){if(o)try{const n=Array.isArray(o)?o[0]:o,s=this.increaseAsyncId(i.gameObject.id);if(yield t.resource.getResource(n),!this.validateAsyncId(i.gameObject.id,s))return;const r=this.texts[i.gameObject.id].component;e.style.fontFamily=o,e.text=r.text}catch(e){console.warn(`字体资源 ${o} 加载失败:`,e)}}))}change(e){const{text:t,component:i}=this.texts[e.gameObject.id],o="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("resolution"!==e.prop.prop[0]||o){if("textureStyle"===e.prop.prop[0]&&o){const o=i,s=this.containerManager.getContainer(e.gameObject.id),r=s.getChildIndex(t);s.removeChild(t),t.destroy({children:!0});const c=new n.HTMLText({text:o.text,style:o.style,textureStyle:o.textureStyle});s.addChildAt(c,r),this.texts[e.gameObject.id].text=c}}else{const e=i;void 0!==e.resolution&&e.resolution>0&&(t.resolution=e.resolution)}}setSize(e){const{transform:t}=e.gameObject;if(!t)return;const{text:i}=this.texts[e.gameObject.id],o=i.getSize();t.size.width=o.width,t.size.height=o.height}};a.systemName="Text",a=s([t.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0},"resolution"],HTMLText:["text",{prop:["style"],deep:!0},{prop:["textureStyle"],deep:!0}]})],a);var d=a;exports.HTMLText=l,exports.Text=c,exports.TextSystem=d;
@@ -64,6 +64,7 @@ declare class Text_2 extends Component<TextParams> {
64
64
  static componentName: string;
65
65
  text: string;
66
66
  style: TextParams['style'];
67
+ resolution: number;
67
68
  init(obj?: TextParams): void;
68
69
  }
69
70
  export { Text_2 as Text }
@@ -101,6 +102,7 @@ export declare interface TextParams {
101
102
  wordWrapWidth?: number;
102
103
  leading?: number;
103
104
  };
105
+ resolution?: number;
104
106
  }
105
107
 
106
108
  export declare class TextSystem extends Renderer {
@@ -40,6 +40,7 @@ class Text$2 extends Component {
40
40
  super(...arguments);
41
41
  this.text = '';
42
42
  this.style = {};
43
+ this.resolution = 1;
43
44
  }
44
45
  init(obj) {
45
46
  const style = new TextStyle({
@@ -56,13 +57,19 @@ class Text$2 extends Component {
56
57
  if (obj) {
57
58
  this.text = obj.text;
58
59
  Object.assign(this.style, obj.style);
60
+ if (obj.resolution !== undefined) {
61
+ this.resolution = obj.resolution;
62
+ }
59
63
  }
60
64
  }
61
65
  }
62
66
  Text$2.componentName = 'Text';
63
67
  __decorate([
64
68
  type('string')
65
- ], Text$2.prototype, "text", void 0);
69
+ ], Text$2.prototype, "text", void 0);
70
+ __decorate([
71
+ type('number')
72
+ ], Text$2.prototype, "resolution", void 0);
66
73
 
67
74
  class HTMLText extends Component {
68
75
  constructor() {
@@ -133,6 +140,9 @@ let Text = class Text extends Renderer {
133
140
  delete styleWithoutFont.fontFamily;
134
141
  const initialText = fontFamily ? '' : component.text;
135
142
  const text = new Text$3(initialText, styleWithoutFont);
143
+ if (component.resolution !== undefined && component.resolution > 0) {
144
+ text.resolution = component.resolution;
145
+ }
136
146
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
137
147
  this.texts[changed.gameObject.id] = {
138
148
  text,
@@ -190,6 +200,12 @@ let Text = class Text extends Renderer {
190
200
  else if (changed.prop.prop[0] === 'style') {
191
201
  Object.assign(text.style, component.style);
192
202
  }
203
+ else if (changed.prop.prop[0] === 'resolution' && !isHTMLText) {
204
+ const textComponent = component;
205
+ if (textComponent.resolution !== undefined && textComponent.resolution > 0) {
206
+ text.resolution = textComponent.resolution;
207
+ }
208
+ }
193
209
  else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
194
210
  const htmlComponent = component;
195
211
  const container = this.containerManager.getContainer(changed.gameObject.id);
@@ -218,7 +234,7 @@ let Text = class Text extends Renderer {
218
234
  Text.systemName = 'Text';
219
235
  Text = __decorate([
220
236
  decorators.componentObserver({
221
- Text: ['text', { prop: ['style'], deep: true }],
237
+ Text: ['text', { prop: ['style'], deep: true }, 'resolution'],
222
238
  HTMLText: ['text', { prop: ['style'], deep: true }, { prop: ['textureStyle'], deep: true }],
223
239
  })
224
240
  ], Text);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-text",
3
- "version": "2.0.1-beta.25",
3
+ "version": "2.0.1-beta.27",
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.25",
23
- "@eva/renderer-adapter": "2.0.1-beta.25",
24
- "@eva/eva.js": "2.0.1-beta.25",
22
+ "@eva/plugin-renderer": "2.0.1-beta.27",
23
+ "@eva/renderer-adapter": "2.0.1-beta.27",
24
+ "@eva/eva.js": "2.0.1-beta.27",
25
25
  "pixi.js": "^8.8.1"
26
26
  }
27
27
  }