@eva/plugin-renderer-text 2.0.1-beta.5 → 2.0.1-beta.7

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.
@@ -96,6 +96,8 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
96
96
  if (changed.componentName !== 'Text') return;
97
97
  if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
98
98
  const component = changed.component;
99
+ const fontFamily = component.style.fontFamily;
100
+ component.style.fontFamily = '';
99
101
  const text = new rendererAdapter.Text(component.text, component.style);
100
102
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
101
103
  this.texts[changed.gameObject.id] = {
@@ -103,6 +105,7 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
103
105
  component: changed.component
104
106
  };
105
107
  this.setSize(changed);
108
+ this.asyncUpdateFontFamily(text, fontFamily);
106
109
  } else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
107
110
  this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
108
111
  this.texts[changed.gameObject.id].text.destroy({
@@ -123,7 +126,28 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
123
126
  if (changed.prop.prop[0] === 'text') {
124
127
  text.text = component.text;
125
128
  } else if (changed.prop.prop[0] === 'style') {
126
- _extends(text.style, changed.component.style);
129
+ this.asyncChangeTextStyle(text, changed.component.style);
130
+ }
131
+ }
132
+ asyncChangeTextStyle(text, textStyle) {
133
+ if (textStyle.fontFamily) {
134
+ const fontFamily = textStyle.fontFamily;
135
+ textStyle.fontFamily = '';
136
+ this.asyncUpdateFontFamily(text, fontFamily);
137
+ }
138
+ _extends(text.style, textStyle);
139
+ }
140
+ asyncUpdateFontFamily(text, fontFamily) {
141
+ if (fontFamily) {
142
+ if (Array.isArray(fontFamily)) {
143
+ Promise.all(fontFamily.map(font => eva_js.resource.getResource(font))).finally(() => {
144
+ text.style.fontFamily = fontFamily;
145
+ });
146
+ } else {
147
+ eva_js.resource.getResource(fontFamily).finally(() => {
148
+ text.style.fontFamily = fontFamily;
149
+ });
150
+ }
127
151
  }
128
152
  }
129
153
  setSize(changed) {
@@ -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 o(e,t,n,r){var s,o=arguments.length,i=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,n,r);else for(var c=e.length-1;c>=0;c--)(s=e[c])&&(i=(o<3?s(i):o>3?s(t,n,i):s(t,n))||i);return o>3&&i&&Object.defineProperty(t,n,i),i}function i(e,t,n,r){return new(n||(n=Promise))((function(s,o){function i(e){try{a(r.next(e))}catch(e){o(e)}}function c(e){try{a(r.throw(e))}catch(e){o(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(i,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",o([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 i(this,void 0,void 0,(function*(){if("Text"===e.componentName)if(e.type===n.OBSERVER_TYPE.ADD){const t=e.component,n=new s.Text(t.text,t.style);this.containerManager.getContainer(e.gameObject.id).addChildAt(n,0),this.texts[e.gameObject.id]={text:n,component:e.component},this.setSize(e)}else 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]):(this.change(e),this.setSize(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=o([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(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 a=e.length-1;a>=0;a--)(s=e[a])&&(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{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}c((r=r.apply(e,t||[])).next())}))}class a 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))}}a.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")],a.prototype,"text",void 0);let c=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=t.style.fontFamily;t.style.fontFamily="";const r=new s.Text(t.text,t.style);this.containerManager.getContainer(e.gameObject.id).addChildAt(r,0),this.texts[e.gameObject.id]={text:r,component:e.component},this.setSize(e),this.asyncUpdateFontFamily(r,n)}else 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]):(this.change(e),this.setSize(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]&&this.asyncChangeTextStyle(t,e.component.style)}asyncChangeTextStyle(e,t){if(t.fontFamily){const n=t.fontFamily;t.fontFamily="",this.asyncUpdateFontFamily(e,n)}_extends(e.style,t)}asyncUpdateFontFamily(e,t){t&&(Array.isArray(t)?Promise.all(t.map((e=>n.resource.getResource(e)))).finally((()=>{e.style.fontFamily=t})):n.resource.getResource(t).finally((()=>{e.style.fontFamily=t})))}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)}};c.systemName="Text",c=i([n.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}]})],c);var l=c;return e.Text=a,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;
@@ -84,6 +84,8 @@ let Text = class Text extends pluginRenderer.Renderer {
84
84
  return;
85
85
  if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
86
86
  const component = changed.component;
87
+ const fontFamily = component.style.fontFamily;
88
+ component.style.fontFamily = '';
87
89
  const text = new rendererAdapter.Text(component.text, component.style);
88
90
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
89
91
  this.texts[changed.gameObject.id] = {
@@ -91,6 +93,7 @@ let Text = class Text extends pluginRenderer.Renderer {
91
93
  component: changed.component,
92
94
  };
93
95
  this.setSize(changed);
96
+ this.asyncUpdateFontFamily(text, fontFamily);
94
97
  }
95
98
  else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
96
99
  this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
@@ -109,7 +112,29 @@ let Text = class Text extends pluginRenderer.Renderer {
109
112
  text.text = component.text;
110
113
  }
111
114
  else if (changed.prop.prop[0] === 'style') {
112
- Object.assign(text.style, changed.component.style);
115
+ this.asyncChangeTextStyle(text, changed.component.style);
116
+ }
117
+ }
118
+ asyncChangeTextStyle(text, textStyle) {
119
+ if (textStyle.fontFamily) {
120
+ const fontFamily = textStyle.fontFamily;
121
+ textStyle.fontFamily = '';
122
+ this.asyncUpdateFontFamily(text, fontFamily);
123
+ }
124
+ Object.assign(text.style, textStyle);
125
+ }
126
+ asyncUpdateFontFamily(text, fontFamily) {
127
+ if (fontFamily) {
128
+ if (Array.isArray(fontFamily)) {
129
+ Promise.all(fontFamily.map(font => eva_js.resource.getResource(font))).finally(() => {
130
+ text.style.fontFamily = fontFamily;
131
+ });
132
+ }
133
+ else {
134
+ eva_js.resource.getResource(fontFamily).finally(() => {
135
+ text.style.fontFamily = fontFamily;
136
+ });
137
+ }
113
138
  }
114
139
  }
115
140
  setSize(changed) {
@@ -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"),s=require("@eva/plugin-renderer"),r=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"),s=require("@eva/plugin-renderer"),i=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 i(e,t,n,s){var r,i=arguments.length,o=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,n):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,s);else for(var c=e.length-1;c>=0;c--)(r=e[c])&&(o=(i<3?r(o):i>3?r(t,n,o):r(t,n))||o);return i>3&&o&&Object.defineProperty(t,n,o),o}class o extends t.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){const n=new e.TextStyle({fontSize:20}),s={};for(const e in n)0===e.indexOf("_")&&(s[e.substring(1)]=n[e]);delete s.styleKey,this.style=s,t&&(this.text=t.text,Object.assign(this.style,t.style))}}o.componentName="Text",i([n.type("string")],o.prototype,"text",void 0);let c=class extends s.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={}}init(){this.renderSystem=this.game.getSystem(s.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){return n=this,s=void 0,o=function*(){if("Text"===e.componentName)if(e.type===t.OBSERVER_TYPE.ADD){const t=e.component,n=new r.Text(t.text,t.style);this.containerManager.getContainer(e.gameObject.id).addChildAt(n,0),this.texts[e.gameObject.id]={text:n,component:e.component},this.setSize(e)}else e.type===t.OBSERVER_TYPE.REMOVE?(this.containerManager.getContainer(e.gameObject.id).removeChild(this.texts[e.gameObject.id].text),this.texts[e.gameObject.id].text.destroy({children:!0}),delete this.texts[e.gameObject.id]):(this.change(e),this.setSize(e))},new((i=void 0)||(i=Promise))((function(e,t){function r(e){try{a(o.next(e))}catch(e){t(e)}}function c(e){try{a(o.throw(e))}catch(e){t(e)}}function a(t){t.done?e(t.value):new i((function(e){e(t.value)})).then(r,c)}a((o=o.apply(n,s||[])).next())}));var n,s,i,o}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]&&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)}};c.systemName="Text",c=i([t.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}]})],c);var a=c;exports.Text=o,exports.TextSystem=a;
16
+ function r(e,t,n,s){var i,r=arguments.length,o=r<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,n):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,s);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(o=(r<3?i(o):r>3?i(t,n,o):i(t,n))||o);return r>3&&o&&Object.defineProperty(t,n,o),o}class o extends t.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){const n=new e.TextStyle({fontSize:20}),s={};for(const e in n)0===e.indexOf("_")&&(s[e.substring(1)]=n[e]);delete s.styleKey,this.style=s,t&&(this.text=t.text,Object.assign(this.style,t.style))}}o.componentName="Text",r([n.type("string")],o.prototype,"text",void 0);let a=class extends s.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={}}init(){this.renderSystem=this.game.getSystem(s.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){return n=this,s=void 0,o=function*(){if("Text"===e.componentName)if(e.type===t.OBSERVER_TYPE.ADD){const t=e.component,n=t.style.fontFamily;t.style.fontFamily="";const s=new i.Text(t.text,t.style);this.containerManager.getContainer(e.gameObject.id).addChildAt(s,0),this.texts[e.gameObject.id]={text:s,component:e.component},this.setSize(e),this.asyncUpdateFontFamily(s,n)}else e.type===t.OBSERVER_TYPE.REMOVE?(this.containerManager.getContainer(e.gameObject.id).removeChild(this.texts[e.gameObject.id].text),this.texts[e.gameObject.id].text.destroy({children:!0}),delete this.texts[e.gameObject.id]):(this.change(e),this.setSize(e))},new((r=void 0)||(r=Promise))((function(e,t){function i(e){try{c(o.next(e))}catch(e){t(e)}}function a(e){try{c(o.throw(e))}catch(e){t(e)}}function c(t){t.done?e(t.value):new r((function(e){e(t.value)})).then(i,a)}c((o=o.apply(n,s||[])).next())}));var n,s,r,o}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]&&this.asyncChangeTextStyle(t,e.component.style)}asyncChangeTextStyle(e,t){if(t.fontFamily){const n=t.fontFamily;t.fontFamily="",this.asyncUpdateFontFamily(e,n)}Object.assign(e.style,t)}asyncUpdateFontFamily(e,n){n&&(Array.isArray(n)?Promise.all(n.map((e=>t.resource.getResource(e)))).finally((()=>{e.style.fontFamily=n})):t.resource.getResource(n).finally((()=>{e.style.fontFamily=n})))}setSize(e){const{transform:t}=e.gameObject;t&&(t.size.width=this.texts[e.gameObject.id].text.width,t.size.height=this.texts[e.gameObject.id].text.height)}};a.systemName="Text",a=r([t.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}]})],a);var c=a;exports.Text=o,exports.TextSystem=c;
@@ -70,6 +70,8 @@ export declare class TextSystem extends Renderer {
70
70
  init(): void;
71
71
  componentChanged(changed: ComponentChanged): Promise<void>;
72
72
  change(changed: ComponentChanged): void;
73
+ asyncChangeTextStyle(text: Text_3, textStyle: TextParams['style']): void;
74
+ asyncUpdateFontFamily(text: Text_3, fontFamily: string | string[] | undefined): void;
73
75
  setSize(changed: ComponentChanged): void;
74
76
  }
75
77
 
@@ -1,5 +1,5 @@
1
1
  import { TextStyle } from 'pixi.js';
2
- import { Component, decorators, OBSERVER_TYPE } from '@eva/eva.js';
2
+ import { Component, resource, decorators, OBSERVER_TYPE } from '@eva/eva.js';
3
3
  import { type } from '@eva/inspector-decorator';
4
4
  import { Renderer, RendererSystem } from '@eva/plugin-renderer';
5
5
  import { Text as Text$3 } from '@eva/renderer-adapter';
@@ -80,6 +80,8 @@ let Text = class Text extends Renderer {
80
80
  return;
81
81
  if (changed.type === OBSERVER_TYPE.ADD) {
82
82
  const component = changed.component;
83
+ const fontFamily = component.style.fontFamily;
84
+ component.style.fontFamily = '';
83
85
  const text = new Text$3(component.text, component.style);
84
86
  this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
85
87
  this.texts[changed.gameObject.id] = {
@@ -87,6 +89,7 @@ let Text = class Text extends Renderer {
87
89
  component: changed.component,
88
90
  };
89
91
  this.setSize(changed);
92
+ this.asyncUpdateFontFamily(text, fontFamily);
90
93
  }
91
94
  else if (changed.type === OBSERVER_TYPE.REMOVE) {
92
95
  this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
@@ -105,7 +108,29 @@ let Text = class Text extends Renderer {
105
108
  text.text = component.text;
106
109
  }
107
110
  else if (changed.prop.prop[0] === 'style') {
108
- Object.assign(text.style, changed.component.style);
111
+ this.asyncChangeTextStyle(text, changed.component.style);
112
+ }
113
+ }
114
+ asyncChangeTextStyle(text, textStyle) {
115
+ if (textStyle.fontFamily) {
116
+ const fontFamily = textStyle.fontFamily;
117
+ textStyle.fontFamily = '';
118
+ this.asyncUpdateFontFamily(text, fontFamily);
119
+ }
120
+ Object.assign(text.style, textStyle);
121
+ }
122
+ asyncUpdateFontFamily(text, fontFamily) {
123
+ if (fontFamily) {
124
+ if (Array.isArray(fontFamily)) {
125
+ Promise.all(fontFamily.map(font => resource.getResource(font))).finally(() => {
126
+ text.style.fontFamily = fontFamily;
127
+ });
128
+ }
129
+ else {
130
+ resource.getResource(fontFamily).finally(() => {
131
+ text.style.fontFamily = fontFamily;
132
+ });
133
+ }
109
134
  }
110
135
  }
111
136
  setSize(changed) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-text",
3
- "version": "2.0.1-beta.5",
3
+ "version": "2.0.1-beta.7",
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.5",
23
- "@eva/renderer-adapter": "2.0.1-beta.5",
24
- "@eva/eva.js": "2.0.1-beta.5",
22
+ "@eva/plugin-renderer": "2.0.1-beta.7",
23
+ "@eva/renderer-adapter": "2.0.1-beta.7",
24
+ "@eva/eva.js": "2.0.1-beta.7",
25
25
  "pixi.js": "^8.8.1"
26
26
  }
27
27
  }