@eva/plugin-renderer-text 2.0.1-beta.2 → 2.0.1-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EVA.plugin.renderer.text.js +123 -10
- package/dist/EVA.plugin.renderer.text.min.js +1 -1
- package/dist/plugin-renderer-text.cjs.js +108 -10
- package/dist/plugin-renderer-text.cjs.prod.js +2 -2
- package/dist/plugin-renderer-text.d.ts +53 -2
- package/dist/plugin-renderer-text.esm.js +110 -13
- package/package.json +4 -4
|
@@ -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,16 +117,15 @@ 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
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
component: changed.component
|
|
104
|
-
};
|
|
105
|
-
this.setSize(changed);
|
|
124
|
+
if (isText) {
|
|
125
|
+
yield this.addTextComponent(changed);
|
|
126
|
+
} else {
|
|
127
|
+
yield this.addHTMLTextComponent(changed);
|
|
128
|
+
}
|
|
106
129
|
} else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
107
130
|
this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
|
|
108
131
|
this.texts[changed.gameObject.id].text.destroy({
|
|
@@ -112,6 +135,72 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
|
|
|
112
135
|
} else {
|
|
113
136
|
this.change(changed);
|
|
114
137
|
this.setSize(changed);
|
|
138
|
+
const component = changed.component;
|
|
139
|
+
if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
|
|
140
|
+
const {
|
|
141
|
+
text
|
|
142
|
+
} = this.texts[changed.gameObject.id];
|
|
143
|
+
yield this.waitForFontResource(text, changed, component.style.fontFamily);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
addTextComponent(changed) {
|
|
149
|
+
var _a;
|
|
150
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
const component = changed.component;
|
|
152
|
+
const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
|
|
153
|
+
const initialText = fontFamily ? '' : component.text;
|
|
154
|
+
const text = new rendererAdapter.Text(initialText, component.style);
|
|
155
|
+
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
|
+
var _a;
|
|
168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
const component = changed.component;
|
|
170
|
+
const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
|
|
171
|
+
const initialText = fontFamily ? '' : component.text;
|
|
172
|
+
const htmlText = new rendererAdapter.HTMLText(_extends({
|
|
173
|
+
text: initialText,
|
|
174
|
+
style: component.style
|
|
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
|
+
}
|
|
189
|
+
waitForFontResource(text, changed, fontFamily) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
if (!fontFamily) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
|
|
196
|
+
const asyncId = this.increaseAsyncId(changed.gameObject.id);
|
|
197
|
+
yield eva_js.resource.getResource(fontName);
|
|
198
|
+
if (!this.validateAsyncId(changed.gameObject.id, asyncId)) return;
|
|
199
|
+
const component = this.texts[changed.gameObject.id].component;
|
|
200
|
+
text.text = component.text;
|
|
201
|
+
this.setSize(changed);
|
|
202
|
+
} catch (error) {
|
|
203
|
+
console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
|
|
115
204
|
}
|
|
116
205
|
});
|
|
117
206
|
}
|
|
@@ -120,10 +209,26 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
|
|
|
120
209
|
text,
|
|
121
210
|
component
|
|
122
211
|
} = this.texts[changed.gameObject.id];
|
|
212
|
+
const isHTMLText = changed.componentName === 'HTMLText';
|
|
123
213
|
if (changed.prop.prop[0] === 'text') {
|
|
124
214
|
text.text = component.text;
|
|
125
215
|
} else if (changed.prop.prop[0] === 'style') {
|
|
126
|
-
_extends(text.style,
|
|
216
|
+
_extends(text.style, component.style);
|
|
217
|
+
} else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
|
|
218
|
+
const htmlComponent = component;
|
|
219
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
220
|
+
const index = container.getChildIndex(text);
|
|
221
|
+
container.removeChild(text);
|
|
222
|
+
text.destroy({
|
|
223
|
+
children: true
|
|
224
|
+
});
|
|
225
|
+
const newText = new rendererAdapter.HTMLText({
|
|
226
|
+
text: htmlComponent.text,
|
|
227
|
+
style: htmlComponent.style,
|
|
228
|
+
textureStyle: htmlComponent.textureStyle
|
|
229
|
+
});
|
|
230
|
+
container.addChildAt(newText, index);
|
|
231
|
+
this.texts[changed.gameObject.id].text = newText;
|
|
127
232
|
}
|
|
128
233
|
}
|
|
129
234
|
setSize(changed) {
|
|
@@ -140,9 +245,17 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
|
|
|
140
245
|
Text: ['text', {
|
|
141
246
|
prop: ['style'],
|
|
142
247
|
deep: true
|
|
248
|
+
}],
|
|
249
|
+
HTMLText: ['text', {
|
|
250
|
+
prop: ['style'],
|
|
251
|
+
deep: true
|
|
252
|
+
}, {
|
|
253
|
+
prop: ['textureStyle'],
|
|
254
|
+
deep: true
|
|
143
255
|
}]
|
|
144
256
|
})], Text);
|
|
145
257
|
var Text$1 = Text;
|
|
258
|
+
exports.HTMLText = HTMLText;
|
|
146
259
|
exports.Text = Text$2;
|
|
147
260
|
exports.TextSystem = Text$1;
|
|
148
261
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return _extends=Object.assign?Object.assign.bind():function(
|
|
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;
|
|
@@ -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,17 +100,17 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
80
100
|
}
|
|
81
101
|
componentChanged(changed) {
|
|
82
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
93
|
-
this.setSize(changed);
|
|
108
|
+
if (isText) {
|
|
109
|
+
yield this.addTextComponent(changed);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
yield this.addHTMLTextComponent(changed);
|
|
113
|
+
}
|
|
94
114
|
}
|
|
95
115
|
else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
|
|
96
116
|
this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
|
|
@@ -100,16 +120,92 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
100
120
|
else {
|
|
101
121
|
this.change(changed);
|
|
102
122
|
this.setSize(changed);
|
|
123
|
+
const component = changed.component;
|
|
124
|
+
if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
|
|
125
|
+
const { text } = this.texts[changed.gameObject.id];
|
|
126
|
+
yield this.waitForFontResource(text, changed, component.style.fontFamily);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
addTextComponent(changed) {
|
|
132
|
+
var _a;
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
const component = changed.component;
|
|
135
|
+
const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
|
|
136
|
+
const initialText = fontFamily ? '' : component.text;
|
|
137
|
+
const text = new rendererAdapter.Text(initialText, component.style);
|
|
138
|
+
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
|
+
var _a;
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
const component = changed.component;
|
|
153
|
+
const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
|
|
154
|
+
const initialText = fontFamily ? '' : component.text;
|
|
155
|
+
const htmlText = new rendererAdapter.HTMLText(Object.assign({ text: initialText, style: component.style }, (component.textureStyle && { textureStyle: component.textureStyle })));
|
|
156
|
+
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
|
+
}
|
|
167
|
+
waitForFontResource(text, changed, fontFamily) {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
if (!fontFamily) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
|
|
174
|
+
const asyncId = this.increaseAsyncId(changed.gameObject.id);
|
|
175
|
+
yield eva_js.resource.getResource(fontName);
|
|
176
|
+
if (!this.validateAsyncId(changed.gameObject.id, asyncId))
|
|
177
|
+
return;
|
|
178
|
+
const component = this.texts[changed.gameObject.id].component;
|
|
179
|
+
text.text = component.text;
|
|
180
|
+
this.setSize(changed);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
|
|
103
184
|
}
|
|
104
185
|
});
|
|
105
186
|
}
|
|
106
187
|
change(changed) {
|
|
107
188
|
const { text, component } = this.texts[changed.gameObject.id];
|
|
189
|
+
const isHTMLText = changed.componentName === 'HTMLText';
|
|
108
190
|
if (changed.prop.prop[0] === 'text') {
|
|
109
191
|
text.text = component.text;
|
|
110
192
|
}
|
|
111
193
|
else if (changed.prop.prop[0] === 'style') {
|
|
112
|
-
Object.assign(text.style,
|
|
194
|
+
Object.assign(text.style, component.style);
|
|
195
|
+
}
|
|
196
|
+
else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
|
|
197
|
+
const htmlComponent = component;
|
|
198
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
199
|
+
const index = container.getChildIndex(text);
|
|
200
|
+
container.removeChild(text);
|
|
201
|
+
text.destroy({ children: true });
|
|
202
|
+
const newText = new rendererAdapter.HTMLText({
|
|
203
|
+
text: htmlComponent.text,
|
|
204
|
+
style: htmlComponent.style,
|
|
205
|
+
textureStyle: htmlComponent.textureStyle
|
|
206
|
+
});
|
|
207
|
+
container.addChildAt(newText, index);
|
|
208
|
+
this.texts[changed.gameObject.id].text = newText;
|
|
113
209
|
}
|
|
114
210
|
}
|
|
115
211
|
setSize(changed) {
|
|
@@ -124,9 +220,11 @@ Text.systemName = 'Text';
|
|
|
124
220
|
Text = __decorate([
|
|
125
221
|
eva_js.decorators.componentObserver({
|
|
126
222
|
Text: ['text', { prop: ['style'], deep: true }],
|
|
223
|
+
HTMLText: ['text', { prop: ['style'], deep: true }, { prop: ['textureStyle'], deep: true }],
|
|
127
224
|
})
|
|
128
225
|
], Text);
|
|
129
226
|
var Text$1 = Text;
|
|
130
227
|
|
|
228
|
+
exports.HTMLText = HTMLText;
|
|
131
229
|
exports.Text = Text$2;
|
|
132
230
|
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"),
|
|
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
|
|
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;
|
|
@@ -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,9 @@ 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;
|
|
122
|
+
private waitForFontResource;
|
|
72
123
|
change(changed: ComponentChanged): void;
|
|
73
124
|
setSize(changed: ComponentChanged): void;
|
|
74
125
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TextStyle } from 'pixi.js';
|
|
2
|
-
import { Component, decorators, OBSERVER_TYPE } from '@eva/eva.js';
|
|
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,17 +96,17 @@ let Text = class Text extends Renderer {
|
|
|
76
96
|
}
|
|
77
97
|
componentChanged(changed) {
|
|
78
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
};
|
|
89
|
-
this.setSize(changed);
|
|
104
|
+
if (isText) {
|
|
105
|
+
yield this.addTextComponent(changed);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
yield this.addHTMLTextComponent(changed);
|
|
109
|
+
}
|
|
90
110
|
}
|
|
91
111
|
else if (changed.type === OBSERVER_TYPE.REMOVE) {
|
|
92
112
|
this.containerManager.getContainer(changed.gameObject.id).removeChild(this.texts[changed.gameObject.id].text);
|
|
@@ -96,16 +116,92 @@ let Text = class Text extends Renderer {
|
|
|
96
116
|
else {
|
|
97
117
|
this.change(changed);
|
|
98
118
|
this.setSize(changed);
|
|
119
|
+
const component = changed.component;
|
|
120
|
+
if (changed.prop.prop[0] === 'style' && component.style && component.style.fontFamily) {
|
|
121
|
+
const { text } = this.texts[changed.gameObject.id];
|
|
122
|
+
yield this.waitForFontResource(text, changed, component.style.fontFamily);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
addTextComponent(changed) {
|
|
128
|
+
var _a;
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
const component = changed.component;
|
|
131
|
+
const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
|
|
132
|
+
const initialText = fontFamily ? '' : component.text;
|
|
133
|
+
const text = new Text$3(initialText, component.style);
|
|
134
|
+
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
|
+
var _a;
|
|
147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
const component = changed.component;
|
|
149
|
+
const fontFamily = (_a = component.style) === null || _a === void 0 ? void 0 : _a.fontFamily;
|
|
150
|
+
const initialText = fontFamily ? '' : component.text;
|
|
151
|
+
const htmlText = new HTMLText$1(Object.assign({ text: initialText, style: component.style }, (component.textureStyle && { textureStyle: component.textureStyle })));
|
|
152
|
+
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
|
+
}
|
|
163
|
+
waitForFontResource(text, changed, fontFamily) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
if (!fontFamily) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
|
|
170
|
+
const asyncId = this.increaseAsyncId(changed.gameObject.id);
|
|
171
|
+
yield resource.getResource(fontName);
|
|
172
|
+
if (!this.validateAsyncId(changed.gameObject.id, asyncId))
|
|
173
|
+
return;
|
|
174
|
+
const component = this.texts[changed.gameObject.id].component;
|
|
175
|
+
text.text = component.text;
|
|
176
|
+
this.setSize(changed);
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
|
|
99
180
|
}
|
|
100
181
|
});
|
|
101
182
|
}
|
|
102
183
|
change(changed) {
|
|
103
184
|
const { text, component } = this.texts[changed.gameObject.id];
|
|
185
|
+
const isHTMLText = changed.componentName === 'HTMLText';
|
|
104
186
|
if (changed.prop.prop[0] === 'text') {
|
|
105
187
|
text.text = component.text;
|
|
106
188
|
}
|
|
107
189
|
else if (changed.prop.prop[0] === 'style') {
|
|
108
|
-
Object.assign(text.style,
|
|
190
|
+
Object.assign(text.style, component.style);
|
|
191
|
+
}
|
|
192
|
+
else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
|
|
193
|
+
const htmlComponent = component;
|
|
194
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
195
|
+
const index = container.getChildIndex(text);
|
|
196
|
+
container.removeChild(text);
|
|
197
|
+
text.destroy({ children: true });
|
|
198
|
+
const newText = new HTMLText$1({
|
|
199
|
+
text: htmlComponent.text,
|
|
200
|
+
style: htmlComponent.style,
|
|
201
|
+
textureStyle: htmlComponent.textureStyle
|
|
202
|
+
});
|
|
203
|
+
container.addChildAt(newText, index);
|
|
204
|
+
this.texts[changed.gameObject.id].text = newText;
|
|
109
205
|
}
|
|
110
206
|
}
|
|
111
207
|
setSize(changed) {
|
|
@@ -120,8 +216,9 @@ Text.systemName = 'Text';
|
|
|
120
216
|
Text = __decorate([
|
|
121
217
|
decorators.componentObserver({
|
|
122
218
|
Text: ['text', { prop: ['style'], deep: true }],
|
|
219
|
+
HTMLText: ['text', { prop: ['style'], deep: true }, { prop: ['textureStyle'], deep: true }],
|
|
123
220
|
})
|
|
124
221
|
], Text);
|
|
125
222
|
var Text$1 = Text;
|
|
126
223
|
|
|
127
|
-
export { Text$2 as Text, Text$1 as TextSystem };
|
|
224
|
+
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.
|
|
3
|
+
"version": "2.0.1-beta.21",
|
|
4
4
|
"description": "@eva/plugin-renderer-text",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-renderer-text.esm.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@eva/inspector-decorator": "^0.0.5",
|
|
22
|
-
"@eva/plugin-renderer": "2.0.1-beta.
|
|
23
|
-
"@eva/renderer-adapter": "2.0.1-beta.
|
|
24
|
-
"@eva/eva.js": "2.0.1-beta.
|
|
22
|
+
"@eva/plugin-renderer": "2.0.1-beta.21",
|
|
23
|
+
"@eva/renderer-adapter": "2.0.1-beta.21",
|
|
24
|
+
"@eva/eva.js": "2.0.1-beta.21",
|
|
25
25
|
"pixi.js": "^8.8.1"
|
|
26
26
|
}
|
|
27
27
|
}
|