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

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.
@@ -81,6 +81,30 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
81
81
  }
82
82
  Text$2.componentName = 'Text';
83
83
  __decorate([type('string')], Text$2.prototype, "text", void 0);
84
+ class HTMLText extends eva_js.Component {
85
+ constructor() {
86
+ super(...arguments);
87
+ this.text = '';
88
+ this.style = {};
89
+ this.textureStyle = {};
90
+ }
91
+ init(obj) {
92
+ this.style = _extends({
93
+ fontSize: 24,
94
+ fill: '#000000',
95
+ fontFamily: 'Arial'
96
+ }, obj === null || obj === void 0 ? void 0 : obj.style);
97
+ this.textureStyle = _extends({
98
+ scaleMode: 'linear',
99
+ resolution: window.devicePixelRatio || 1
100
+ }, obj === null || obj === void 0 ? void 0 : obj.textureStyle);
101
+ if (obj) {
102
+ this.text = obj.text;
103
+ }
104
+ }
105
+ }
106
+ HTMLText.componentName = 'HTMLText';
107
+ __decorate([type('string')], HTMLText.prototype, "text", void 0);
84
108
  let Text = class Text extends pluginRenderer.Renderer {
85
109
  constructor() {
86
110
  super(...arguments);
@@ -93,21 +117,14 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
93
117
  }
94
118
  componentChanged(changed) {
95
119
  return __awaiter(this, void 0, void 0, function* () {
96
- if (changed.componentName !== 'Text') return;
120
+ const isText = changed.componentName === 'Text';
121
+ const isHTMLText = changed.componentName === 'HTMLText';
122
+ if (!isText && !isHTMLText) return;
97
123
  if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
98
- const component = changed.component;
99
- const styleWithoutFont = _extends({}, component.style);
100
- const fontFamily = styleWithoutFont.fontFamily;
101
- delete styleWithoutFont.fontFamily;
102
- const text = new rendererAdapter.Text(component.text, styleWithoutFont);
103
- this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
104
- this.texts[changed.gameObject.id] = {
105
- text,
106
- component: changed.component
107
- };
108
- this.setSize(changed);
109
- if (fontFamily) {
110
- yield this.waitForFontResource(text, changed, fontFamily);
124
+ if (isText) {
125
+ yield this.addTextComponent(changed);
126
+ } else {
127
+ yield this.addHTMLTextComponent(changed);
111
128
  }
112
129
  } else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
113
130
  this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
@@ -128,6 +145,47 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
128
145
  }
129
146
  });
130
147
  }
148
+ addTextComponent(changed) {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ 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);
155
+ this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
156
+ this.texts[changed.gameObject.id] = {
157
+ text,
158
+ component
159
+ };
160
+ this.setSize(changed);
161
+ if (fontFamily) {
162
+ yield this.waitForFontResource(text, changed, fontFamily);
163
+ }
164
+ });
165
+ }
166
+ addHTMLTextComponent(changed) {
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ const component = changed.component;
169
+ const styleWithoutFont = _extends({}, component.style);
170
+ const fontFamily = styleWithoutFont.fontFamily;
171
+ delete styleWithoutFont.fontFamily;
172
+ const htmlText = new rendererAdapter.HTMLText(_extends({
173
+ text: component.text,
174
+ style: styleWithoutFont
175
+ }, component.textureStyle && {
176
+ textureStyle: component.textureStyle
177
+ }));
178
+ this.containerManager.getContainer(changed.gameObject.id).addChildAt(htmlText, 0);
179
+ this.texts[changed.gameObject.id] = {
180
+ text: htmlText,
181
+ component
182
+ };
183
+ this.setSize(changed);
184
+ if (fontFamily) {
185
+ yield this.waitForFontResource(htmlText, changed, fontFamily);
186
+ }
187
+ });
188
+ }
131
189
  waitForFontResource(text, changed, fontFamily) {
132
190
  return __awaiter(this, void 0, void 0, function* () {
133
191
  if (!fontFamily) {
@@ -150,10 +208,26 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
150
208
  text,
151
209
  component
152
210
  } = this.texts[changed.gameObject.id];
211
+ const isHTMLText = changed.componentName === 'HTMLText';
153
212
  if (changed.prop.prop[0] === 'text') {
154
213
  text.text = component.text;
155
214
  } else if (changed.prop.prop[0] === 'style') {
156
- _extends(text.style, changed.component.style);
215
+ _extends(text.style, component.style);
216
+ } else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
217
+ const htmlComponent = component;
218
+ const container = this.containerManager.getContainer(changed.gameObject.id);
219
+ const index = container.getChildIndex(text);
220
+ container.removeChild(text);
221
+ text.destroy({
222
+ children: true
223
+ });
224
+ const newText = new rendererAdapter.HTMLText({
225
+ text: htmlComponent.text,
226
+ style: htmlComponent.style,
227
+ textureStyle: htmlComponent.textureStyle
228
+ });
229
+ container.addChildAt(newText, index);
230
+ this.texts[changed.gameObject.id].text = newText;
157
231
  }
158
232
  }
159
233
  setSize(changed) {
@@ -170,9 +244,17 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
170
244
  Text: ['text', {
171
245
  prop: ['style'],
172
246
  deep: true
247
+ }],
248
+ HTMLText: ['text', {
249
+ prop: ['style'],
250
+ deep: true
251
+ }, {
252
+ prop: ['textureStyle'],
253
+ deep: true
173
254
  }]
174
255
  })], Text);
175
256
  var Text$1 = Text;
257
+ exports.HTMLText = HTMLText;
176
258
  exports.Text = Text$2;
177
259
  exports.TextSystem = Text$1;
178
260
  Object.defineProperty(exports, '__esModule', {
@@ -1 +1 @@
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;
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;
@@ -68,6 +68,26 @@ __decorate([
68
68
  inspectorDecorator.type('string')
69
69
  ], Text$2.prototype, "text", void 0);
70
70
 
71
+ class HTMLText extends eva_js.Component {
72
+ constructor() {
73
+ super(...arguments);
74
+ this.text = '';
75
+ this.style = {};
76
+ this.textureStyle = {};
77
+ }
78
+ init(obj) {
79
+ this.style = Object.assign({ fontSize: 24, fill: '#000000', fontFamily: 'Arial' }, obj === null || obj === void 0 ? void 0 : obj.style);
80
+ this.textureStyle = Object.assign({ scaleMode: 'linear', resolution: window.devicePixelRatio || 1 }, obj === null || obj === void 0 ? void 0 : obj.textureStyle);
81
+ if (obj) {
82
+ this.text = obj.text;
83
+ }
84
+ }
85
+ }
86
+ HTMLText.componentName = 'HTMLText';
87
+ __decorate([
88
+ inspectorDecorator.type('string')
89
+ ], HTMLText.prototype, "text", void 0);
90
+
71
91
  let Text = class Text extends pluginRenderer.Renderer {
72
92
  constructor() {
73
93
  super(...arguments);
@@ -80,22 +100,16 @@ let Text = class Text extends pluginRenderer.Renderer {
80
100
  }
81
101
  componentChanged(changed) {
82
102
  return __awaiter(this, void 0, void 0, function* () {
83
- if (changed.componentName !== 'Text')
103
+ const isText = changed.componentName === 'Text';
104
+ const isHTMLText = changed.componentName === 'HTMLText';
105
+ if (!isText && !isHTMLText)
84
106
  return;
85
107
  if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
86
- const component = changed.component;
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);
91
- this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
92
- this.texts[changed.gameObject.id] = {
93
- text,
94
- component: changed.component,
95
- };
96
- this.setSize(changed);
97
- if (fontFamily) {
98
- yield this.waitForFontResource(text, changed, fontFamily);
108
+ if (isText) {
109
+ yield this.addTextComponent(changed);
110
+ }
111
+ else {
112
+ yield this.addHTMLTextComponent(changed);
99
113
  }
100
114
  }
101
115
  else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
@@ -114,6 +128,42 @@ let Text = class Text extends pluginRenderer.Renderer {
114
128
  }
115
129
  });
116
130
  }
131
+ addTextComponent(changed) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ 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);
138
+ this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
139
+ this.texts[changed.gameObject.id] = {
140
+ text,
141
+ component,
142
+ };
143
+ this.setSize(changed);
144
+ if (fontFamily) {
145
+ yield this.waitForFontResource(text, changed, fontFamily);
146
+ }
147
+ });
148
+ }
149
+ addHTMLTextComponent(changed) {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ 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 })));
156
+ this.containerManager.getContainer(changed.gameObject.id).addChildAt(htmlText, 0);
157
+ this.texts[changed.gameObject.id] = {
158
+ text: htmlText,
159
+ component,
160
+ };
161
+ this.setSize(changed);
162
+ if (fontFamily) {
163
+ yield this.waitForFontResource(htmlText, changed, fontFamily);
164
+ }
165
+ });
166
+ }
117
167
  waitForFontResource(text, changed, fontFamily) {
118
168
  return __awaiter(this, void 0, void 0, function* () {
119
169
  if (!fontFamily) {
@@ -135,11 +185,26 @@ let Text = class Text extends pluginRenderer.Renderer {
135
185
  }
136
186
  change(changed) {
137
187
  const { text, component } = this.texts[changed.gameObject.id];
188
+ const isHTMLText = changed.componentName === 'HTMLText';
138
189
  if (changed.prop.prop[0] === 'text') {
139
190
  text.text = component.text;
140
191
  }
141
192
  else if (changed.prop.prop[0] === 'style') {
142
- Object.assign(text.style, changed.component.style);
193
+ Object.assign(text.style, component.style);
194
+ }
195
+ else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
196
+ const htmlComponent = component;
197
+ const container = this.containerManager.getContainer(changed.gameObject.id);
198
+ const index = container.getChildIndex(text);
199
+ container.removeChild(text);
200
+ text.destroy({ children: true });
201
+ const newText = new rendererAdapter.HTMLText({
202
+ text: htmlComponent.text,
203
+ style: htmlComponent.style,
204
+ textureStyle: htmlComponent.textureStyle
205
+ });
206
+ container.addChildAt(newText, index);
207
+ this.texts[changed.gameObject.id].text = newText;
143
208
  }
144
209
  }
145
210
  setSize(changed) {
@@ -154,9 +219,11 @@ Text.systemName = 'Text';
154
219
  Text = __decorate([
155
220
  eva_js.decorators.componentObserver({
156
221
  Text: ['text', { prop: ['style'], deep: true }],
222
+ HTMLText: ['text', { prop: ['style'], deep: true }, { prop: ['textureStyle'], deep: true }],
157
223
  })
158
224
  ], Text);
159
225
  var Text$1 = Text;
160
226
 
227
+ exports.HTMLText = HTMLText;
161
228
  exports.Text = Text$2;
162
229
  exports.TextSystem = Text$1;
@@ -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"),i=require("@eva/plugin-renderer"),n=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"),n=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 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;
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;
@@ -1,6 +1,7 @@
1
1
  import { Component } from '@eva/eva.js';
2
2
  import { ComponentChanged } from '@eva/eva.js';
3
3
  import { ContainerManager } from '@eva/plugin-renderer';
4
+ import { HTMLText as HTMLText_2 } from '@eva/renderer-adapter';
4
5
  import { Renderer } from '@eva/plugin-renderer';
5
6
  import { RendererManager } from '@eva/plugin-renderer';
6
7
  import { RendererSystem } from '@eva/plugin-renderer';
@@ -12,6 +13,53 @@ import { TextStyleFontWeight } from 'pixi.js';
12
13
  import { TextStyleTextBaseline } from 'pixi.js';
13
14
  import { TextStyleWhiteSpace } from 'pixi.js';
14
15
 
16
+ export declare class HTMLText extends Component<HTMLTextParams> {
17
+ static componentName: string;
18
+ text: string;
19
+ style: HTMLTextParams['style'];
20
+ textureStyle: HTMLTextParams['textureStyle'];
21
+ init(obj?: HTMLTextParams): void;
22
+ }
23
+
24
+ export declare interface HTMLTextParams {
25
+ text: string;
26
+ style?: HTMLTextStyleOptions & {
27
+ cssOverrides?: string[];
28
+ wordWrap?: boolean;
29
+ wordWrapWidth?: number;
30
+ tagStyles?: Record<string, HTMLTextStyleOptions>;
31
+ };
32
+ textureStyle?: {
33
+ scaleMode?: 'linear' | 'nearest';
34
+ resolution?: number;
35
+ };
36
+ }
37
+
38
+ declare interface HTMLTextStyleOptions {
39
+ fontFamily?: string | string[];
40
+ fontSize?: number | string;
41
+ fill?: string | number;
42
+ align?: 'left' | 'center' | 'right' | 'justify';
43
+ breakWords?: boolean;
44
+ letterSpacing?: number;
45
+ lineHeight?: number;
46
+ padding?: number;
47
+ stroke?: string | number;
48
+ strokeThickness?: number;
49
+ dropShadow?: boolean;
50
+ dropShadowAlpha?: number;
51
+ dropShadowAngle?: number;
52
+ dropShadowBlur?: number;
53
+ dropShadowColor?: string | number;
54
+ dropShadowDistance?: number;
55
+ trim?: boolean;
56
+ fontWeight?: string;
57
+ fontStyle?: string;
58
+ fontVariant?: string;
59
+ textBaseline?: string;
60
+ whiteSpace?: string;
61
+ }
62
+
15
63
  declare class Text_2 extends Component<TextParams> {
16
64
  static componentName: string;
17
65
  text: string;
@@ -60,8 +108,8 @@ export declare class TextSystem extends Renderer {
60
108
  name: string;
61
109
  texts: {
62
110
  [propName: number]: {
63
- text: Text_3;
64
- component: Text_2;
111
+ text: Text_3 | HTMLText_2;
112
+ component: Text_2 | HTMLText;
65
113
  };
66
114
  };
67
115
  renderSystem: RendererSystem;
@@ -69,6 +117,8 @@ export declare class TextSystem extends Renderer {
69
117
  containerManager: ContainerManager;
70
118
  init(): void;
71
119
  componentChanged(changed: ComponentChanged): Promise<void>;
120
+ private addTextComponent;
121
+ private addHTMLTextComponent;
72
122
  private waitForFontResource;
73
123
  change(changed: ComponentChanged): void;
74
124
  setSize(changed: ComponentChanged): void;
@@ -2,7 +2,7 @@ import { TextStyle } from 'pixi.js';
2
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
- import { Text as Text$3 } from '@eva/renderer-adapter';
5
+ import { HTMLText as HTMLText$1, Text as Text$3 } from '@eva/renderer-adapter';
6
6
 
7
7
  /*! *****************************************************************************
8
8
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -64,6 +64,26 @@ __decorate([
64
64
  type('string')
65
65
  ], Text$2.prototype, "text", void 0);
66
66
 
67
+ class HTMLText extends Component {
68
+ constructor() {
69
+ super(...arguments);
70
+ this.text = '';
71
+ this.style = {};
72
+ this.textureStyle = {};
73
+ }
74
+ init(obj) {
75
+ this.style = Object.assign({ fontSize: 24, fill: '#000000', fontFamily: 'Arial' }, obj === null || obj === void 0 ? void 0 : obj.style);
76
+ this.textureStyle = Object.assign({ scaleMode: 'linear', resolution: window.devicePixelRatio || 1 }, obj === null || obj === void 0 ? void 0 : obj.textureStyle);
77
+ if (obj) {
78
+ this.text = obj.text;
79
+ }
80
+ }
81
+ }
82
+ HTMLText.componentName = 'HTMLText';
83
+ __decorate([
84
+ type('string')
85
+ ], HTMLText.prototype, "text", void 0);
86
+
67
87
  let Text = class Text extends Renderer {
68
88
  constructor() {
69
89
  super(...arguments);
@@ -76,22 +96,16 @@ let Text = class Text extends Renderer {
76
96
  }
77
97
  componentChanged(changed) {
78
98
  return __awaiter(this, void 0, void 0, function* () {
79
- if (changed.componentName !== 'Text')
99
+ const isText = changed.componentName === 'Text';
100
+ const isHTMLText = changed.componentName === 'HTMLText';
101
+ if (!isText && !isHTMLText)
80
102
  return;
81
103
  if (changed.type === OBSERVER_TYPE.ADD) {
82
- const component = changed.component;
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);
87
- this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
88
- this.texts[changed.gameObject.id] = {
89
- text,
90
- component: changed.component,
91
- };
92
- this.setSize(changed);
93
- if (fontFamily) {
94
- yield this.waitForFontResource(text, changed, fontFamily);
104
+ if (isText) {
105
+ yield this.addTextComponent(changed);
106
+ }
107
+ else {
108
+ yield this.addHTMLTextComponent(changed);
95
109
  }
96
110
  }
97
111
  else if (changed.type === OBSERVER_TYPE.REMOVE) {
@@ -110,6 +124,42 @@ let Text = class Text extends Renderer {
110
124
  }
111
125
  });
112
126
  }
127
+ addTextComponent(changed) {
128
+ return __awaiter(this, void 0, void 0, function* () {
129
+ 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);
134
+ this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
135
+ this.texts[changed.gameObject.id] = {
136
+ text,
137
+ component,
138
+ };
139
+ this.setSize(changed);
140
+ if (fontFamily) {
141
+ yield this.waitForFontResource(text, changed, fontFamily);
142
+ }
143
+ });
144
+ }
145
+ addHTMLTextComponent(changed) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ 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 })));
152
+ this.containerManager.getContainer(changed.gameObject.id).addChildAt(htmlText, 0);
153
+ this.texts[changed.gameObject.id] = {
154
+ text: htmlText,
155
+ component,
156
+ };
157
+ this.setSize(changed);
158
+ if (fontFamily) {
159
+ yield this.waitForFontResource(htmlText, changed, fontFamily);
160
+ }
161
+ });
162
+ }
113
163
  waitForFontResource(text, changed, fontFamily) {
114
164
  return __awaiter(this, void 0, void 0, function* () {
115
165
  if (!fontFamily) {
@@ -131,11 +181,26 @@ let Text = class Text extends Renderer {
131
181
  }
132
182
  change(changed) {
133
183
  const { text, component } = this.texts[changed.gameObject.id];
184
+ const isHTMLText = changed.componentName === 'HTMLText';
134
185
  if (changed.prop.prop[0] === 'text') {
135
186
  text.text = component.text;
136
187
  }
137
188
  else if (changed.prop.prop[0] === 'style') {
138
- Object.assign(text.style, changed.component.style);
189
+ Object.assign(text.style, component.style);
190
+ }
191
+ else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
192
+ const htmlComponent = component;
193
+ const container = this.containerManager.getContainer(changed.gameObject.id);
194
+ const index = container.getChildIndex(text);
195
+ container.removeChild(text);
196
+ text.destroy({ children: true });
197
+ const newText = new HTMLText$1({
198
+ text: htmlComponent.text,
199
+ style: htmlComponent.style,
200
+ textureStyle: htmlComponent.textureStyle
201
+ });
202
+ container.addChildAt(newText, index);
203
+ this.texts[changed.gameObject.id].text = newText;
139
204
  }
140
205
  }
141
206
  setSize(changed) {
@@ -150,8 +215,9 @@ Text.systemName = 'Text';
150
215
  Text = __decorate([
151
216
  decorators.componentObserver({
152
217
  Text: ['text', { prop: ['style'], deep: true }],
218
+ HTMLText: ['text', { prop: ['style'], deep: true }, { prop: ['textureStyle'], deep: true }],
153
219
  })
154
220
  ], Text);
155
221
  var Text$1 = Text;
156
222
 
157
- export { Text$2 as Text, Text$1 as TextSystem };
223
+ export { HTMLText, Text$2 as Text, Text$1 as TextSystem };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-text",
3
- "version": "2.0.1-beta.19",
3
+ "version": "2.0.1-beta.20",
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.19",
23
- "@eva/renderer-adapter": "2.0.1-beta.19",
24
- "@eva/eva.js": "2.0.1-beta.19",
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",
25
25
  "pixi.js": "^8.8.1"
26
26
  }
27
27
  }