@eva/plugin-renderer-text 2.0.1-beta.2 → 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.
- package/dist/EVA.plugin.renderer.text.js +122 -10
- package/dist/EVA.plugin.renderer.text.min.js +1 -1
- package/dist/plugin-renderer-text.cjs.js +107 -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 +109 -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,71 @@ 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
|
+
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
|
+
}
|
|
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
|
+
text.style.fontFamily = fontFamily;
|
|
200
|
+
this.setSize(changed);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
|
|
115
203
|
}
|
|
116
204
|
});
|
|
117
205
|
}
|
|
@@ -120,10 +208,26 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
|
|
|
120
208
|
text,
|
|
121
209
|
component
|
|
122
210
|
} = this.texts[changed.gameObject.id];
|
|
211
|
+
const isHTMLText = changed.componentName === 'HTMLText';
|
|
123
212
|
if (changed.prop.prop[0] === 'text') {
|
|
124
213
|
text.text = component.text;
|
|
125
214
|
} else if (changed.prop.prop[0] === 'style') {
|
|
126
|
-
_extends(text.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;
|
|
127
231
|
}
|
|
128
232
|
}
|
|
129
233
|
setSize(changed) {
|
|
@@ -140,9 +244,17 @@ var _EVA_IIFE_text = function (exports, pixi_js, eva_js, pluginRenderer, rendere
|
|
|
140
244
|
Text: ['text', {
|
|
141
245
|
prop: ['style'],
|
|
142
246
|
deep: true
|
|
247
|
+
}],
|
|
248
|
+
HTMLText: ['text', {
|
|
249
|
+
prop: ['style'],
|
|
250
|
+
deep: true
|
|
251
|
+
}, {
|
|
252
|
+
prop: ['textureStyle'],
|
|
253
|
+
deep: true
|
|
143
254
|
}]
|
|
144
255
|
})], Text);
|
|
145
256
|
var Text$1 = Text;
|
|
257
|
+
exports.HTMLText = HTMLText;
|
|
146
258
|
exports.Text = Text$2;
|
|
147
259
|
exports.TextSystem = Text$1;
|
|
148
260
|
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){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,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,91 @@ 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
|
+
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
|
+
}
|
|
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
|
+
text.style.fontFamily = fontFamily;
|
|
179
|
+
this.setSize(changed);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
|
|
103
183
|
}
|
|
104
184
|
});
|
|
105
185
|
}
|
|
106
186
|
change(changed) {
|
|
107
187
|
const { text, component } = this.texts[changed.gameObject.id];
|
|
188
|
+
const isHTMLText = changed.componentName === 'HTMLText';
|
|
108
189
|
if (changed.prop.prop[0] === 'text') {
|
|
109
190
|
text.text = component.text;
|
|
110
191
|
}
|
|
111
192
|
else if (changed.prop.prop[0] === 'style') {
|
|
112
|
-
Object.assign(text.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;
|
|
113
208
|
}
|
|
114
209
|
}
|
|
115
210
|
setSize(changed) {
|
|
@@ -124,9 +219,11 @@ Text.systemName = 'Text';
|
|
|
124
219
|
Text = __decorate([
|
|
125
220
|
eva_js.decorators.componentObserver({
|
|
126
221
|
Text: ['text', { prop: ['style'], deep: true }],
|
|
222
|
+
HTMLText: ['text', { prop: ['style'], deep: true }, { prop: ['textureStyle'], deep: true }],
|
|
127
223
|
})
|
|
128
224
|
], Text);
|
|
129
225
|
var Text$1 = Text;
|
|
130
226
|
|
|
227
|
+
exports.HTMLText = HTMLText;
|
|
131
228
|
exports.Text = Text$2;
|
|
132
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"),
|
|
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){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,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,91 @@ 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
|
+
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
|
+
}
|
|
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
|
+
text.style.fontFamily = fontFamily;
|
|
175
|
+
this.setSize(changed);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
console.warn(`字体资源 ${fontFamily} 加载失败:`, error);
|
|
99
179
|
}
|
|
100
180
|
});
|
|
101
181
|
}
|
|
102
182
|
change(changed) {
|
|
103
183
|
const { text, component } = this.texts[changed.gameObject.id];
|
|
184
|
+
const isHTMLText = changed.componentName === 'HTMLText';
|
|
104
185
|
if (changed.prop.prop[0] === 'text') {
|
|
105
186
|
text.text = component.text;
|
|
106
187
|
}
|
|
107
188
|
else if (changed.prop.prop[0] === 'style') {
|
|
108
|
-
Object.assign(text.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;
|
|
109
204
|
}
|
|
110
205
|
}
|
|
111
206
|
setSize(changed) {
|
|
@@ -120,8 +215,9 @@ Text.systemName = 'Text';
|
|
|
120
215
|
Text = __decorate([
|
|
121
216
|
decorators.componentObserver({
|
|
122
217
|
Text: ['text', { prop: ['style'], deep: true }],
|
|
218
|
+
HTMLText: ['text', { prop: ['style'], deep: true }, { prop: ['textureStyle'], deep: true }],
|
|
123
219
|
})
|
|
124
220
|
], Text);
|
|
125
221
|
var Text$1 = Text;
|
|
126
222
|
|
|
127
|
-
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.
|
|
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.
|
|
23
|
-
"@eva/renderer-adapter": "2.0.1-beta.
|
|
24
|
-
"@eva/eva.js": "2.0.1-beta.
|
|
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
|
}
|