@eva/plugin-renderer-text 2.1.0-beta.13 → 2.1.0-beta.14
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 +25 -10
- package/dist/EVA.plugin.renderer.text.min.js +1 -1
- package/dist/plugin-renderer-text.cjs.js +35 -12
- package/dist/plugin-renderer-text.cjs.prod.js +1 -1
- package/dist/plugin-renderer-text.d.ts +1 -0
- package/dist/plugin-renderer-text.esm.js +36 -13
- package/package.json +4 -4
|
@@ -256,7 +256,9 @@ var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendere
|
|
|
256
256
|
} else {
|
|
257
257
|
this.change(changed);
|
|
258
258
|
const component = changed.component;
|
|
259
|
-
|
|
259
|
+
const propPath = changed.prop.prop;
|
|
260
|
+
const fontFamilyChanged = propPath[0] === 'style' && (propPath.length === 1 || propPath[1] === 'fontFamily');
|
|
261
|
+
if (fontFamilyChanged && component.style && this.hasRegisteredFont(component.style.fontFamily)) {
|
|
260
262
|
const {
|
|
261
263
|
text
|
|
262
264
|
} = this.texts[changed.gameObject.id];
|
|
@@ -271,15 +273,16 @@ var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendere
|
|
|
271
273
|
const component = changed.component;
|
|
272
274
|
const styleWithoutFont = this.processStyle(component.style);
|
|
273
275
|
const fontFamily = styleWithoutFont.fontFamily;
|
|
274
|
-
|
|
275
|
-
|
|
276
|
+
const waitsForFontResource = this.hasRegisteredFont(fontFamily);
|
|
277
|
+
if (waitsForFontResource) delete styleWithoutFont.fontFamily;
|
|
278
|
+
const initialText = waitsForFontResource ? '' : component.text;
|
|
276
279
|
const text = new rendererAdapter.Text(initialText, styleWithoutFont);
|
|
277
280
|
this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
|
|
278
281
|
this.texts[changed.gameObject.id] = {
|
|
279
282
|
text,
|
|
280
283
|
component
|
|
281
284
|
};
|
|
282
|
-
if (
|
|
285
|
+
if (waitsForFontResource) {
|
|
283
286
|
yield this.waitForFontResource(text, changed, fontFamily);
|
|
284
287
|
}
|
|
285
288
|
});
|
|
@@ -289,8 +292,9 @@ var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendere
|
|
|
289
292
|
const component = changed.component;
|
|
290
293
|
const styleWithoutFont = this.processStyle(component.style);
|
|
291
294
|
const fontFamily = styleWithoutFont.fontFamily;
|
|
292
|
-
|
|
293
|
-
|
|
295
|
+
const waitsForFontResource = this.hasRegisteredFont(fontFamily);
|
|
296
|
+
if (waitsForFontResource) delete styleWithoutFont.fontFamily;
|
|
297
|
+
const initialText = waitsForFontResource ? '' : component.text;
|
|
294
298
|
const htmlText = new rendererAdapter.HTMLText(_extends({
|
|
295
299
|
text: initialText,
|
|
296
300
|
style: styleWithoutFont
|
|
@@ -302,7 +306,7 @@ var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendere
|
|
|
302
306
|
text: htmlText,
|
|
303
307
|
component
|
|
304
308
|
};
|
|
305
|
-
if (
|
|
309
|
+
if (waitsForFontResource) {
|
|
306
310
|
yield this.waitForFontResource(htmlText, changed, fontFamily);
|
|
307
311
|
}
|
|
308
312
|
});
|
|
@@ -312,19 +316,26 @@ var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendere
|
|
|
312
316
|
const component = changed.component;
|
|
313
317
|
const styleWithoutFont = this.processStyle(component.style);
|
|
314
318
|
const fontFamily = styleWithoutFont.fontFamily;
|
|
315
|
-
|
|
316
|
-
|
|
319
|
+
const waitsForFontResource = this.hasRegisteredFont(fontFamily);
|
|
320
|
+
if (waitsForFontResource) delete styleWithoutFont.fontFamily;
|
|
321
|
+
const initialText = waitsForFontResource ? '' : component.text;
|
|
317
322
|
const bitmapText = new rendererAdapter.BitmapText(initialText, styleWithoutFont);
|
|
318
323
|
this.containerManager.getContainer(changed.gameObject.id).addChildAt(bitmapText, 0);
|
|
319
324
|
this.texts[changed.gameObject.id] = {
|
|
320
325
|
text: bitmapText,
|
|
321
326
|
component
|
|
322
327
|
};
|
|
323
|
-
if (
|
|
328
|
+
if (waitsForFontResource) {
|
|
324
329
|
yield this.waitForFontResource(bitmapText, changed, fontFamily);
|
|
325
330
|
}
|
|
326
331
|
});
|
|
327
332
|
}
|
|
333
|
+
hasRegisteredFont(fontFamily) {
|
|
334
|
+
var _a;
|
|
335
|
+
if (!fontFamily) return false;
|
|
336
|
+
const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
|
|
337
|
+
return ((_a = eva_js.resource.resourcesMap[fontName]) === null || _a === void 0 ? void 0 : _a.type) === eva_js.RESOURCE_TYPE.FONT;
|
|
338
|
+
}
|
|
328
339
|
waitForFontResource(text, changed, fontFamily) {
|
|
329
340
|
return __awaiter(this, void 0, void 0, function* () {
|
|
330
341
|
if (!fontFamily) {
|
|
@@ -332,6 +343,7 @@ var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendere
|
|
|
332
343
|
}
|
|
333
344
|
try {
|
|
334
345
|
const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
|
|
346
|
+
if (!this.hasRegisteredFont(fontFamily)) return;
|
|
335
347
|
const asyncId = this.increaseAsyncId(changed.gameObject.id);
|
|
336
348
|
yield eva_js.resource.getResource(fontName);
|
|
337
349
|
if (!this.validateAsyncId(changed.gameObject.id, asyncId)) return;
|
|
@@ -413,6 +425,7 @@ var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendere
|
|
|
413
425
|
text.text = component.text;
|
|
414
426
|
} else if (changed.prop.prop[0] === 'style') {
|
|
415
427
|
const processedStyle = this.processStyle(component.style);
|
|
428
|
+
if (this.hasRegisteredFont(processedStyle.fontFamily)) delete processedStyle.fontFamily;
|
|
416
429
|
_extends(text.style, processedStyle);
|
|
417
430
|
} else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
|
|
418
431
|
const htmlComponent = component;
|
|
@@ -440,8 +453,10 @@ var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendere
|
|
|
440
453
|
text
|
|
441
454
|
} = this.texts[changed.gameObject.id];
|
|
442
455
|
const size = text.getSize();
|
|
456
|
+
if (transform.size.width === size.width && transform.size.height === size.height) return;
|
|
443
457
|
transform.size.width = size.width;
|
|
444
458
|
transform.size.height = size.height;
|
|
459
|
+
this.renderSystem.commitIntrinsicSize(changed.gameObject);
|
|
445
460
|
}
|
|
446
461
|
};
|
|
447
462
|
Text.systemName = 'Text';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var i in o)({}).hasOwnProperty.call(o,i)&&(e[i]=o[i])}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,o,i,n){"use strict";function r(e,t,o,i){var n,r=arguments.length,p=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)p=Reflect.decorate(e,t,o,i);else for(var d=e.length-1;d>=0;d--)(n=e[d])&&(p=(r<3?n(p):r>3?n(t,o,p):n(t,o))||p);return r>3&&p&&Object.defineProperty(t,o,p),p}function p(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function d(e,t,o,i){return new(o||(o=Promise))(function(n,r){function p(e){try{s(i.next(e))}catch(e){r(e)}}function d(e){try{s(i.throw(e))}catch(e){r(e)}}function s(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o(function(e){e(t)})).then(p,d)}s((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class s{}r([t.type("string"),p("design:type",Object)],s.prototype,"fontFamily",void 0),r([t.type("number"),p("design:type",Object)],s.prototype,"fontSize",void 0),r([t.Field({type:"color"}),p("design:type",Object)],s.prototype,"fill",void 0),r([t.type("string"),p("design:type",String)],s.prototype,"align",void 0),r([t.type("number"),p("design:type",Number)],s.prototype,"letterSpacing",void 0),r([t.type("number"),p("design:type",Number)],s.prototype,"padding",void 0),r([t.Field({type:"color"}),p("design:type",Object)],s.prototype,"stroke",void 0),r([t.type("number"),p("design:type",Number)],s.prototype,"strokeThickness",void 0),r([t.type("string"),p("design:type",String)],s.prototype,"fontWeight",void 0),r([t.type("string"),p("design:type",String)],s.prototype,"fontStyle",void 0);class y extends t.Component{constructor(){super(...arguments),this.text="",this.style={}}init(e){this.style=_extends({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==e?void 0:e.style),e&&(this.text=e.text)}}y.componentName="BitmapText",r([t.type("string"),p("design:type",String)],y.prototype,"text",void 0),r([t.Field(()=>s),p("design:type",Object)],y.prototype,"style",void 0);class l{}r([t.type("number"),p("design:type",Number)],l.prototype,"alpha",void 0),r([t.Field({type:"color"}),p("design:type",Object)],l.prototype,"color",void 0),r([t.type("string"),p("design:type",String)],l.prototype,"join",void 0),r([t.type("number"),p("design:type",Number)],l.prototype,"miterLimit",void 0),r([t.type("number"),p("design:type",Number)],l.prototype,"width",void 0);class a{}r([t.type("number"),p("design:type",Number)],a.prototype,"alpha",void 0),r([t.type("number"),p("design:type",Number)],a.prototype,"angle",void 0),r([t.type("number"),p("design:type",Number)],a.prototype,"blur",void 0),r([t.Field({type:"color"}),p("design:type",Object)],a.prototype,"color",void 0),r([t.type("number"),p("design:type",Number)],a.prototype,"distance",void 0),r([t.type("boolean"),p("design:type",Boolean)],a.prototype,"enabled",void 0);class g{}r([t.type("string"),p("design:type",String)],g.prototype,"align",void 0),r([t.type("boolean"),p("design:type",Boolean)],g.prototype,"breakWords",void 0),r([t.Field(()=>a),p("design:type",Object)],g.prototype,"dropShadow",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"dropShadowAlpha",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"dropShadowAngle",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"dropShadowBlur",void 0),r([t.Field({type:"color"}),p("design:type",Object)],g.prototype,"dropShadowColor",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"dropShadowDistance",void 0),r([t.Field({type:"color"}),p("design:type",Object)],g.prototype,"fill",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"fillGradientType",void 0),r([t.type("number"),p("design:type",Array)],g.prototype,"fillGradientStops",void 0),r([t.type("string"),p("design:type",Object)],g.prototype,"fontFamily",void 0),r([t.type("number"),p("design:type",Object)],g.prototype,"fontSize",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"fontStyle",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"fontVariant",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"fontWeight",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"leading",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"letterSpacing",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"lineHeight",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"lineJoin",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"miterLimit",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"padding",void 0),r([t.Field(()=>l),p("design:type",Object)],g.prototype,"stroke",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"strokeThickness",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"textBaseline",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"verticalAlign",void 0),r([t.type("boolean"),p("design:type",Boolean)],g.prototype,"trim",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"whiteSpace",void 0),r([t.type("boolean"),p("design:type",Boolean)],g.prototype,"wordWrap",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"wordWrapWidth",void 0);class c extends t.Component{constructor(e){super(e),this.text="",this.style={},this.init(e)}init(e){const t=new o.TextStyle({fontSize:20}),i={};for(const e in t)0===e.indexOf("_")&&(i[e.substring(1)]=t[e]);delete i.styleKey,this.style=i,e&&(this.text=e.text,_extends(this.style,e.style))}}c.componentName="Text",r([t.type("string"),p("design:type",String)],c.prototype,"text",void 0),r([t.Field(()=>g),p("design:type",Object)],c.prototype,"style",void 0);class u{}r([t.type("string"),p("design:type",String)],u.prototype,"scaleMode",void 0),r([t.type("number"),p("design:type",Number)],u.prototype,"resolution",void 0);class m{}r([t.type("string"),p("design:type",Object)],m.prototype,"fontFamily",void 0),r([t.type("number"),p("design:type",Object)],m.prototype,"fontSize",void 0),r([t.type("string"),p("design:type",String)],m.prototype,"fontWeight",void 0),r([t.type("string"),p("design:type",String)],m.prototype,"fontStyle",void 0),r([t.type("string"),p("design:type",String)],m.prototype,"fontVariant",void 0),r([t.type("string"),p("design:type",String)],m.prototype,"align",void 0),r([t.type("string"),p("design:type",String)],m.prototype,"textBaseline",void 0),r([t.Field({type:"color"}),p("design:type",Object)],m.prototype,"fill",void 0),r([t.Field({type:"color"}),p("design:type",Object)],m.prototype,"stroke",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"strokeThickness",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"lineHeight",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"letterSpacing",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"padding",void 0),r([t.type("boolean"),p("design:type",Boolean)],m.prototype,"wordWrap",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"wordWrapWidth",void 0),r([t.type("boolean"),p("design:type",Boolean)],m.prototype,"breakWords",void 0),r([t.type("string"),p("design:type",String)],m.prototype,"whiteSpace",void 0),r([t.type("boolean"),p("design:type",Boolean)],m.prototype,"dropShadow",void 0),r([t.Field({type:"color"}),p("design:type",Object)],m.prototype,"dropShadowColor",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"dropShadowAlpha",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"dropShadowAngle",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"dropShadowBlur",void 0),r([t.type("number"),p("design:type",Number)],m.prototype,"dropShadowDistance",void 0),r([t.type("object"),p("design:type",Array)],m.prototype,"cssOverrides",void 0),r([t.type("object"),p("design:type",Object)],m.prototype,"tagStyles",void 0),r([t.type("boolean"),p("design:type",Boolean)],m.prototype,"trim",void 0);class h extends t.Component{constructor(){super(...arguments),this.text="",this.style={},this.textureStyle={}}init(e){this.style=_extends({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==e?void 0:e.style),this.textureStyle=_extends({scaleMode:"linear",resolution:window.devicePixelRatio||1},null==e?void 0:e.textureStyle),e&&(this.text=e.text)}}h.componentName="HTMLText",r([t.type("string"),p("design:type",String)],h.prototype,"text",void 0),r([t.Field(()=>m),p("design:type",Object)],h.prototype,"style",void 0),r([t.Field(()=>u),p("design:type",Object)],h.prototype,"textureStyle",void 0);let b=class extends i.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){return d(this,void 0,void 0,function*(){const o="Text"===e.componentName,i="HTMLText"===e.componentName,n="BitmapText"===e.componentName;if(o||i||n)if(e.type===t.OBSERVER_TYPE.ADD)o?yield this.addTextComponent(e):i?yield this.addHTMLTextComponent(e):yield this.addBitmapTextComponent(e),this.setSize(e);else if(e.type===t.OBSERVER_TYPE.REMOVE)this.containerManager.getContainer(e.gameObject.id).removeChild(this.texts[e.gameObject.id].text),this.texts[e.gameObject.id].text.destroy({children:!0}),delete this.texts[e.gameObject.id];else{this.change(e);const t=e.component;if("style"===e.prop.prop[0]&&t.style&&t.style.fontFamily){const{text:o}=this.texts[e.gameObject.id];yield this.waitForFontResource(o,e,t.style.fontFamily)}this.setSize(e)}})}addTextComponent(e){return d(this,void 0,void 0,function*(){const t=e.component,o=this.processStyle(t.style),i=o.fontFamily;delete o.fontFamily;const r=i?"":t.text,p=new n.Text(r,o);this.containerManager.getContainer(e.gameObject.id).addChildAt(p,0),this.texts[e.gameObject.id]={text:p,component:t},i&&(yield this.waitForFontResource(p,e,i))})}addHTMLTextComponent(e){return d(this,void 0,void 0,function*(){const t=e.component,o=this.processStyle(t.style),i=o.fontFamily;delete o.fontFamily;const r=i?"":t.text,p=new n.HTMLText(_extends({text:r,style:o},t.textureStyle&&{textureStyle:t.textureStyle}));this.containerManager.getContainer(e.gameObject.id).addChildAt(p,0),this.texts[e.gameObject.id]={text:p,component:t},i&&(yield this.waitForFontResource(p,e,i))})}addBitmapTextComponent(e){return d(this,void 0,void 0,function*(){const t=e.component,o=this.processStyle(t.style),i=o.fontFamily;delete o.fontFamily;const r=i?"":t.text,p=new n.BitmapText(r,o);this.containerManager.getContainer(e.gameObject.id).addChildAt(p,0),this.texts[e.gameObject.id]={text:p,component:t},i&&(yield this.waitForFontResource(p,e,i))})}waitForFontResource(e,o,i){return d(this,void 0,void 0,function*(){if(i)try{const n=Array.isArray(i)?i[0]:i,r=this.increaseAsyncId(o.gameObject.id);if(yield t.resource.getResource(n),!this.validateAsyncId(o.gameObject.id,r))return;const p=this.texts[o.gameObject.id].component;e.style.fontFamily=i,e.text=p.text}catch(e){console.warn(`字体资源 ${i} 加载失败:`,e)}})}processStyle(e){const t=_extends({},e);if(t.strokeThickness){const e=t.stroke;t.stroke={color:e,width:t.strokeThickness},delete t.strokeThickness}const i=null!=t.dropShadowColor||null!=t.dropShadowDistance||null!=t.dropShadowAngle||null!=t.dropShadowAlpha||null!=t.dropShadowBlur;if(t.dropShadow&&i){const e=t.dropShadow&&"object"==typeof t.dropShadow&&!Array.isArray(t.dropShadow)?_extends({},t.dropShadow):{};null!=t.dropShadowColor&&(e.color=t.dropShadowColor),null!=t.dropShadowDistance&&(e.distance=t.dropShadowDistance),null!=t.dropShadowAngle&&(e.angle=t.dropShadowAngle),null!=t.dropShadowAlpha&&(e.alpha=t.dropShadowAlpha),null!=t.dropShadowBlur&&(e.blur=t.dropShadowBlur),t.dropShadow=e}if(delete t.dropShadowColor,delete t.dropShadowDistance,delete t.dropShadowAngle,delete t.dropShadowAlpha,delete t.dropShadowBlur,Array.isArray(t.fill)&&(t.fill=t.fill[0]),Array.isArray(t.fillGradientStops)){let e;e=null==t.fontSize?o.TextStyle.defaultTextStyle.fontSize:"string"==typeof t.fontSize?parseInt(t.fontSize,10):t.fontSize;const i=new o.FillGradient(0,0,0,1.7*e),n=t.fillGradientStops.map(e=>o.Color.shared.setValue(e).toNumber());n.forEach((e,t)=>{const o=t/(n.length-1);i.addColorStop(o,e)}),t.fill={fill:i},delete t.fillGradientStops}return t}change(e){const{text:t,component:o}=this.texts[e.gameObject.id],i="HTMLText"===e.componentName;if("text"===e.prop.prop[0])t.text=o.text;else if("style"===e.prop.prop[0]){const e=this.processStyle(o.style);_extends(t.style,e)}else if("textureStyle"===e.prop.prop[0]&&i){const i=o,r=this.containerManager.getContainer(e.gameObject.id),p=r.getChildIndex(t);r.removeChild(t),t.destroy({children:!0});const d=new n.HTMLText({text:i.text,style:i.style,textureStyle:i.textureStyle});r.addChildAt(d,p),this.texts[e.gameObject.id].text=d}}setSize(e){const{transform:t}=e.gameObject;if(!t)return;const{text:o}=this.texts[e.gameObject.id],i=o.getSize();t.size.width=i.width,t.size.height=i.height}};b.systemName="Text",b=r([t.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}],HTMLText:["text",{prop:["style"],deep:!0},{prop:["textureStyle"],deep:!0}],BitmapText:["text",{prop:["style"],deep:!0}]})],b);var v=b;return e.BitmapText=y,e.HTMLText=h,e.Text=c,e.TextSystem=v,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,PIXI,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 o=arguments[t];for(var i in o)({}).hasOwnProperty.call(o,i)&&(e[i]=o[i])}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,o,i,n){"use strict";function r(e,t,o,i){var n,r=arguments.length,p=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)p=Reflect.decorate(e,t,o,i);else for(var d=e.length-1;d>=0;d--)(n=e[d])&&(p=(r<3?n(p):r>3?n(t,o,p):n(t,o))||p);return r>3&&p&&Object.defineProperty(t,o,p),p}function p(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function d(e,t,o,i){return new(o||(o=Promise))(function(n,r){function p(e){try{s(i.next(e))}catch(e){r(e)}}function d(e){try{s(i.throw(e))}catch(e){r(e)}}function s(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o(function(e){e(t)})).then(p,d)}s((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class s{}r([t.type("string"),p("design:type",Object)],s.prototype,"fontFamily",void 0),r([t.type("number"),p("design:type",Object)],s.prototype,"fontSize",void 0),r([t.Field({type:"color"}),p("design:type",Object)],s.prototype,"fill",void 0),r([t.type("string"),p("design:type",String)],s.prototype,"align",void 0),r([t.type("number"),p("design:type",Number)],s.prototype,"letterSpacing",void 0),r([t.type("number"),p("design:type",Number)],s.prototype,"padding",void 0),r([t.Field({type:"color"}),p("design:type",Object)],s.prototype,"stroke",void 0),r([t.type("number"),p("design:type",Number)],s.prototype,"strokeThickness",void 0),r([t.type("string"),p("design:type",String)],s.prototype,"fontWeight",void 0),r([t.type("string"),p("design:type",String)],s.prototype,"fontStyle",void 0);class y extends t.Component{constructor(){super(...arguments),this.text="",this.style={}}init(e){this.style=_extends({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==e?void 0:e.style),e&&(this.text=e.text)}}y.componentName="BitmapText",r([t.type("string"),p("design:type",String)],y.prototype,"text",void 0),r([t.Field(()=>s),p("design:type",Object)],y.prototype,"style",void 0);class l{}r([t.type("number"),p("design:type",Number)],l.prototype,"alpha",void 0),r([t.Field({type:"color"}),p("design:type",Object)],l.prototype,"color",void 0),r([t.type("string"),p("design:type",String)],l.prototype,"join",void 0),r([t.type("number"),p("design:type",Number)],l.prototype,"miterLimit",void 0),r([t.type("number"),p("design:type",Number)],l.prototype,"width",void 0);class a{}r([t.type("number"),p("design:type",Number)],a.prototype,"alpha",void 0),r([t.type("number"),p("design:type",Number)],a.prototype,"angle",void 0),r([t.type("number"),p("design:type",Number)],a.prototype,"blur",void 0),r([t.Field({type:"color"}),p("design:type",Object)],a.prototype,"color",void 0),r([t.type("number"),p("design:type",Number)],a.prototype,"distance",void 0),r([t.type("boolean"),p("design:type",Boolean)],a.prototype,"enabled",void 0);class g{}r([t.type("string"),p("design:type",String)],g.prototype,"align",void 0),r([t.type("boolean"),p("design:type",Boolean)],g.prototype,"breakWords",void 0),r([t.Field(()=>a),p("design:type",Object)],g.prototype,"dropShadow",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"dropShadowAlpha",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"dropShadowAngle",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"dropShadowBlur",void 0),r([t.Field({type:"color"}),p("design:type",Object)],g.prototype,"dropShadowColor",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"dropShadowDistance",void 0),r([t.Field({type:"color"}),p("design:type",Object)],g.prototype,"fill",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"fillGradientType",void 0),r([t.type("number"),p("design:type",Array)],g.prototype,"fillGradientStops",void 0),r([t.type("string"),p("design:type",Object)],g.prototype,"fontFamily",void 0),r([t.type("number"),p("design:type",Object)],g.prototype,"fontSize",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"fontStyle",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"fontVariant",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"fontWeight",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"leading",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"letterSpacing",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"lineHeight",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"lineJoin",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"miterLimit",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"padding",void 0),r([t.Field(()=>l),p("design:type",Object)],g.prototype,"stroke",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"strokeThickness",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"textBaseline",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"verticalAlign",void 0),r([t.type("boolean"),p("design:type",Boolean)],g.prototype,"trim",void 0),r([t.type("string"),p("design:type",String)],g.prototype,"whiteSpace",void 0),r([t.type("boolean"),p("design:type",Boolean)],g.prototype,"wordWrap",void 0),r([t.type("number"),p("design:type",Number)],g.prototype,"wordWrapWidth",void 0);class c extends t.Component{constructor(e){super(e),this.text="",this.style={},this.init(e)}init(e){const t=new o.TextStyle({fontSize:20}),i={};for(const e in t)0===e.indexOf("_")&&(i[e.substring(1)]=t[e]);delete i.styleKey,this.style=i,e&&(this.text=e.text,_extends(this.style,e.style))}}c.componentName="Text",r([t.type("string"),p("design:type",String)],c.prototype,"text",void 0),r([t.Field(()=>g),p("design:type",Object)],c.prototype,"style",void 0);class h{}r([t.type("string"),p("design:type",String)],h.prototype,"scaleMode",void 0),r([t.type("number"),p("design:type",Number)],h.prototype,"resolution",void 0);class u{}r([t.type("string"),p("design:type",Object)],u.prototype,"fontFamily",void 0),r([t.type("number"),p("design:type",Object)],u.prototype,"fontSize",void 0),r([t.type("string"),p("design:type",String)],u.prototype,"fontWeight",void 0),r([t.type("string"),p("design:type",String)],u.prototype,"fontStyle",void 0),r([t.type("string"),p("design:type",String)],u.prototype,"fontVariant",void 0),r([t.type("string"),p("design:type",String)],u.prototype,"align",void 0),r([t.type("string"),p("design:type",String)],u.prototype,"textBaseline",void 0),r([t.Field({type:"color"}),p("design:type",Object)],u.prototype,"fill",void 0),r([t.Field({type:"color"}),p("design:type",Object)],u.prototype,"stroke",void 0),r([t.type("number"),p("design:type",Number)],u.prototype,"strokeThickness",void 0),r([t.type("number"),p("design:type",Number)],u.prototype,"lineHeight",void 0),r([t.type("number"),p("design:type",Number)],u.prototype,"letterSpacing",void 0),r([t.type("number"),p("design:type",Number)],u.prototype,"padding",void 0),r([t.type("boolean"),p("design:type",Boolean)],u.prototype,"wordWrap",void 0),r([t.type("number"),p("design:type",Number)],u.prototype,"wordWrapWidth",void 0),r([t.type("boolean"),p("design:type",Boolean)],u.prototype,"breakWords",void 0),r([t.type("string"),p("design:type",String)],u.prototype,"whiteSpace",void 0),r([t.type("boolean"),p("design:type",Boolean)],u.prototype,"dropShadow",void 0),r([t.Field({type:"color"}),p("design:type",Object)],u.prototype,"dropShadowColor",void 0),r([t.type("number"),p("design:type",Number)],u.prototype,"dropShadowAlpha",void 0),r([t.type("number"),p("design:type",Number)],u.prototype,"dropShadowAngle",void 0),r([t.type("number"),p("design:type",Number)],u.prototype,"dropShadowBlur",void 0),r([t.type("number"),p("design:type",Number)],u.prototype,"dropShadowDistance",void 0),r([t.type("object"),p("design:type",Array)],u.prototype,"cssOverrides",void 0),r([t.type("object"),p("design:type",Object)],u.prototype,"tagStyles",void 0),r([t.type("boolean"),p("design:type",Boolean)],u.prototype,"trim",void 0);class m extends t.Component{constructor(){super(...arguments),this.text="",this.style={},this.textureStyle={}}init(e){this.style=_extends({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==e?void 0:e.style),this.textureStyle=_extends({scaleMode:"linear",resolution:window.devicePixelRatio||1},null==e?void 0:e.textureStyle),e&&(this.text=e.text)}}m.componentName="HTMLText",r([t.type("string"),p("design:type",String)],m.prototype,"text",void 0),r([t.Field(()=>u),p("design:type",Object)],m.prototype,"style",void 0),r([t.Field(()=>h),p("design:type",Object)],m.prototype,"textureStyle",void 0);let b=class extends i.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={}}init(){this.renderSystem=this.game.getSystem(i.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){return d(this,void 0,void 0,function*(){const o="Text"===e.componentName,i="HTMLText"===e.componentName,n="BitmapText"===e.componentName;if(o||i||n)if(e.type===t.OBSERVER_TYPE.ADD)o?yield this.addTextComponent(e):i?yield this.addHTMLTextComponent(e):yield this.addBitmapTextComponent(e),this.setSize(e);else if(e.type===t.OBSERVER_TYPE.REMOVE)this.containerManager.getContainer(e.gameObject.id).removeChild(this.texts[e.gameObject.id].text),this.texts[e.gameObject.id].text.destroy({children:!0}),delete this.texts[e.gameObject.id];else{this.change(e);const t=e.component,o=e.prop.prop;if("style"===o[0]&&(1===o.length||"fontFamily"===o[1])&&t.style&&this.hasRegisteredFont(t.style.fontFamily)){const{text:o}=this.texts[e.gameObject.id];yield this.waitForFontResource(o,e,t.style.fontFamily)}this.setSize(e)}})}addTextComponent(e){return d(this,void 0,void 0,function*(){const t=e.component,o=this.processStyle(t.style),i=o.fontFamily,r=this.hasRegisteredFont(i);r&&delete o.fontFamily;const p=r?"":t.text,d=new n.Text(p,o);this.containerManager.getContainer(e.gameObject.id).addChildAt(d,0),this.texts[e.gameObject.id]={text:d,component:t},r&&(yield this.waitForFontResource(d,e,i))})}addHTMLTextComponent(e){return d(this,void 0,void 0,function*(){const t=e.component,o=this.processStyle(t.style),i=o.fontFamily,r=this.hasRegisteredFont(i);r&&delete o.fontFamily;const p=r?"":t.text,d=new n.HTMLText(_extends({text:p,style:o},t.textureStyle&&{textureStyle:t.textureStyle}));this.containerManager.getContainer(e.gameObject.id).addChildAt(d,0),this.texts[e.gameObject.id]={text:d,component:t},r&&(yield this.waitForFontResource(d,e,i))})}addBitmapTextComponent(e){return d(this,void 0,void 0,function*(){const t=e.component,o=this.processStyle(t.style),i=o.fontFamily,r=this.hasRegisteredFont(i);r&&delete o.fontFamily;const p=r?"":t.text,d=new n.BitmapText(p,o);this.containerManager.getContainer(e.gameObject.id).addChildAt(d,0),this.texts[e.gameObject.id]={text:d,component:t},r&&(yield this.waitForFontResource(d,e,i))})}hasRegisteredFont(e){var o;if(!e)return!1;const i=Array.isArray(e)?e[0]:e;return(null===(o=t.resource.resourcesMap[i])||void 0===o?void 0:o.type)===t.RESOURCE_TYPE.FONT}waitForFontResource(e,o,i){return d(this,void 0,void 0,function*(){if(i)try{const n=Array.isArray(i)?i[0]:i;if(!this.hasRegisteredFont(i))return;const r=this.increaseAsyncId(o.gameObject.id);if(yield t.resource.getResource(n),!this.validateAsyncId(o.gameObject.id,r))return;const p=this.texts[o.gameObject.id].component;e.style.fontFamily=i,e.text=p.text}catch(e){console.warn(`字体资源 ${i} 加载失败:`,e)}})}processStyle(e){const t=_extends({},e);if(t.strokeThickness){const e=t.stroke;t.stroke={color:e,width:t.strokeThickness},delete t.strokeThickness}const i=null!=t.dropShadowColor||null!=t.dropShadowDistance||null!=t.dropShadowAngle||null!=t.dropShadowAlpha||null!=t.dropShadowBlur;if(t.dropShadow&&i){const e=t.dropShadow&&"object"==typeof t.dropShadow&&!Array.isArray(t.dropShadow)?_extends({},t.dropShadow):{};null!=t.dropShadowColor&&(e.color=t.dropShadowColor),null!=t.dropShadowDistance&&(e.distance=t.dropShadowDistance),null!=t.dropShadowAngle&&(e.angle=t.dropShadowAngle),null!=t.dropShadowAlpha&&(e.alpha=t.dropShadowAlpha),null!=t.dropShadowBlur&&(e.blur=t.dropShadowBlur),t.dropShadow=e}if(delete t.dropShadowColor,delete t.dropShadowDistance,delete t.dropShadowAngle,delete t.dropShadowAlpha,delete t.dropShadowBlur,Array.isArray(t.fill)&&(t.fill=t.fill[0]),Array.isArray(t.fillGradientStops)){let e;e=null==t.fontSize?o.TextStyle.defaultTextStyle.fontSize:"string"==typeof t.fontSize?parseInt(t.fontSize,10):t.fontSize;const i=new o.FillGradient(0,0,0,1.7*e),n=t.fillGradientStops.map(e=>o.Color.shared.setValue(e).toNumber());n.forEach((e,t)=>{const o=t/(n.length-1);i.addColorStop(o,e)}),t.fill={fill:i},delete t.fillGradientStops}return t}change(e){const{text:t,component:o}=this.texts[e.gameObject.id],i="HTMLText"===e.componentName;if("text"===e.prop.prop[0])t.text=o.text;else if("style"===e.prop.prop[0]){const e=this.processStyle(o.style);this.hasRegisteredFont(e.fontFamily)&&delete e.fontFamily,_extends(t.style,e)}else if("textureStyle"===e.prop.prop[0]&&i){const i=o,r=this.containerManager.getContainer(e.gameObject.id),p=r.getChildIndex(t);r.removeChild(t),t.destroy({children:!0});const d=new n.HTMLText({text:i.text,style:i.style,textureStyle:i.textureStyle});r.addChildAt(d,p),this.texts[e.gameObject.id].text=d}}setSize(e){const{transform:t}=e.gameObject;if(!t)return;const{text:o}=this.texts[e.gameObject.id],i=o.getSize();t.size.width===i.width&&t.size.height===i.height||(t.size.width=i.width,t.size.height=i.height,this.renderSystem.commitIntrinsicSize(e.gameObject))}};b.systemName="Text",b=r([t.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}],HTMLText:["text",{prop:["style"],deep:!0},{prop:["textureStyle"],deep:!0}],BitmapText:["text",{prop:["style"],deep:!0}]})],b);var v=b;return e.BitmapText=y,e.HTMLText=m,e.Text=c,e.TextSystem=v,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,PIXI,EVA.plugin.renderer,EVA.rendererAdapter);globalThis.EVA.plugin.renderer.text=globalThis.EVA.plugin.renderer.text||_EVA_IIFE_text;
|
|
@@ -640,9 +640,11 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
640
640
|
}
|
|
641
641
|
else {
|
|
642
642
|
this.change(changed);
|
|
643
|
-
//
|
|
643
|
+
// Only a font-family replacement can introduce a new async font asset.
|
|
644
644
|
const component = changed.component;
|
|
645
|
-
|
|
645
|
+
const propPath = changed.prop.prop;
|
|
646
|
+
const fontFamilyChanged = propPath[0] === 'style' && (propPath.length === 1 || propPath[1] === 'fontFamily');
|
|
647
|
+
if (fontFamilyChanged && component.style && this.hasRegisteredFont(component.style.fontFamily)) {
|
|
646
648
|
const { text } = this.texts[changed.gameObject.id];
|
|
647
649
|
yield this.waitForFontResource(text, changed, component.style.fontFamily);
|
|
648
650
|
}
|
|
@@ -653,11 +655,14 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
653
655
|
addTextComponent(changed) {
|
|
654
656
|
return __awaiter(this, void 0, void 0, function* () {
|
|
655
657
|
const component = changed.component;
|
|
656
|
-
//
|
|
658
|
+
// Registered Eva font assets must load before the first glyph. Ordinary
|
|
659
|
+
// CSS/system families are already valid Pixi styles and render directly.
|
|
657
660
|
const styleWithoutFont = this.processStyle(component.style);
|
|
658
661
|
const fontFamily = styleWithoutFont.fontFamily;
|
|
659
|
-
|
|
660
|
-
|
|
662
|
+
const waitsForFontResource = this.hasRegisteredFont(fontFamily);
|
|
663
|
+
if (waitsForFontResource)
|
|
664
|
+
delete styleWithoutFont.fontFamily;
|
|
665
|
+
const initialText = waitsForFontResource ? '' : component.text;
|
|
661
666
|
const text = new rendererAdapter.Text(initialText, styleWithoutFont);
|
|
662
667
|
this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
|
|
663
668
|
this.texts[changed.gameObject.id] = {
|
|
@@ -665,7 +670,7 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
665
670
|
component,
|
|
666
671
|
};
|
|
667
672
|
// 如果指定了字体资源,等待资源加载完成后设置 fontFamily
|
|
668
|
-
if (
|
|
673
|
+
if (waitsForFontResource) {
|
|
669
674
|
yield this.waitForFontResource(text, changed, fontFamily);
|
|
670
675
|
}
|
|
671
676
|
});
|
|
@@ -676,8 +681,10 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
676
681
|
// 创建样式副本,先不设置 fontFamily
|
|
677
682
|
const styleWithoutFont = this.processStyle(component.style);
|
|
678
683
|
const fontFamily = styleWithoutFont.fontFamily;
|
|
679
|
-
|
|
680
|
-
|
|
684
|
+
const waitsForFontResource = this.hasRegisteredFont(fontFamily);
|
|
685
|
+
if (waitsForFontResource)
|
|
686
|
+
delete styleWithoutFont.fontFamily;
|
|
687
|
+
const initialText = waitsForFontResource ? '' : component.text;
|
|
681
688
|
const htmlText = new rendererAdapter.HTMLText(Object.assign({ text: initialText, style: styleWithoutFont }, (component.textureStyle && { textureStyle: component.textureStyle })));
|
|
682
689
|
this.containerManager.getContainer(changed.gameObject.id).addChildAt(htmlText, 0);
|
|
683
690
|
this.texts[changed.gameObject.id] = {
|
|
@@ -685,7 +692,7 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
685
692
|
component,
|
|
686
693
|
};
|
|
687
694
|
// 如果指定了字体资源,等待资源加载完成后设置 fontFamily
|
|
688
|
-
if (
|
|
695
|
+
if (waitsForFontResource) {
|
|
689
696
|
yield this.waitForFontResource(htmlText, changed, fontFamily);
|
|
690
697
|
}
|
|
691
698
|
});
|
|
@@ -696,8 +703,10 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
696
703
|
// 创建样式副本,先不设置 fontFamily
|
|
697
704
|
const styleWithoutFont = this.processStyle(component.style);
|
|
698
705
|
const fontFamily = styleWithoutFont.fontFamily;
|
|
699
|
-
|
|
700
|
-
|
|
706
|
+
const waitsForFontResource = this.hasRegisteredFont(fontFamily);
|
|
707
|
+
if (waitsForFontResource)
|
|
708
|
+
delete styleWithoutFont.fontFamily;
|
|
709
|
+
const initialText = waitsForFontResource ? '' : component.text;
|
|
701
710
|
const bitmapText = new rendererAdapter.BitmapText(initialText, styleWithoutFont);
|
|
702
711
|
this.containerManager.getContainer(changed.gameObject.id).addChildAt(bitmapText, 0);
|
|
703
712
|
this.texts[changed.gameObject.id] = {
|
|
@@ -705,11 +714,18 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
705
714
|
component,
|
|
706
715
|
};
|
|
707
716
|
// 如果指定了字体资源,等待资源加载完成后设置 fontFamily
|
|
708
|
-
if (
|
|
717
|
+
if (waitsForFontResource) {
|
|
709
718
|
yield this.waitForFontResource(bitmapText, changed, fontFamily);
|
|
710
719
|
}
|
|
711
720
|
});
|
|
712
721
|
}
|
|
722
|
+
hasRegisteredFont(fontFamily) {
|
|
723
|
+
var _a;
|
|
724
|
+
if (!fontFamily)
|
|
725
|
+
return false;
|
|
726
|
+
const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
|
|
727
|
+
return ((_a = eva_js.resource.resourcesMap[fontName]) === null || _a === void 0 ? void 0 : _a.type) === eva_js.RESOURCE_TYPE.FONT;
|
|
728
|
+
}
|
|
713
729
|
/**
|
|
714
730
|
* 等待字体资源加载完成并更新文本
|
|
715
731
|
*/
|
|
@@ -720,6 +736,8 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
720
736
|
}
|
|
721
737
|
try {
|
|
722
738
|
const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
|
|
739
|
+
if (!this.hasRegisteredFont(fontFamily))
|
|
740
|
+
return;
|
|
723
741
|
// 通过 resource 系统获取字体资源
|
|
724
742
|
const asyncId = this.increaseAsyncId(changed.gameObject.id);
|
|
725
743
|
yield eva_js.resource.getResource(fontName);
|
|
@@ -820,6 +838,8 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
820
838
|
}
|
|
821
839
|
else if (changed.prop.prop[0] === 'style') {
|
|
822
840
|
const processedStyle = this.processStyle(component.style);
|
|
841
|
+
if (this.hasRegisteredFont(processedStyle.fontFamily))
|
|
842
|
+
delete processedStyle.fontFamily;
|
|
823
843
|
Object.assign(text.style, processedStyle);
|
|
824
844
|
}
|
|
825
845
|
else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
|
|
@@ -844,8 +864,11 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
844
864
|
return;
|
|
845
865
|
const { text } = this.texts[changed.gameObject.id];
|
|
846
866
|
const size = text.getSize();
|
|
867
|
+
if (transform.size.width === size.width && transform.size.height === size.height)
|
|
868
|
+
return;
|
|
847
869
|
transform.size.width = size.width;
|
|
848
870
|
transform.size.height = size.height;
|
|
871
|
+
this.renderSystem.commitIntrinsicSize(changed.gameObject);
|
|
849
872
|
}
|
|
850
873
|
};
|
|
851
874
|
Text.systemName = 'Text';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("pixi.js"),o=require("@eva/plugin-renderer"),i=require("@eva/renderer-adapter");function r(e,t,o,i){var r,n=arguments.length,p=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)p=Reflect.decorate(e,t,o,i);else for(var d=e.length-1;d>=0;d--)(r=e[d])&&(p=(n<3?r(p):n>3?r(t,o,p):r(t,o))||p);return n>3&&p&&Object.defineProperty(t,o,p),p}function n(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function p(e,t,o,i){return new(o||(o=Promise))(function(r,n){function p(e){try{s(i.next(e))}catch(e){n(e)}}function d(e){try{s(i.throw(e))}catch(e){n(e)}}function s(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o(function(e){e(t)})).then(p,d)}s((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class d{}r([e.type("string"),n("design:type",Object)],d.prototype,"fontFamily",void 0),r([e.type("number"),n("design:type",Object)],d.prototype,"fontSize",void 0),r([e.Field({type:"color"}),n("design:type",Object)],d.prototype,"fill",void 0),r([e.type("string"),n("design:type",String)],d.prototype,"align",void 0),r([e.type("number"),n("design:type",Number)],d.prototype,"letterSpacing",void 0),r([e.type("number"),n("design:type",Number)],d.prototype,"padding",void 0),r([e.Field({type:"color"}),n("design:type",Object)],d.prototype,"stroke",void 0),r([e.type("number"),n("design:type",Number)],d.prototype,"strokeThickness",void 0),r([e.type("string"),n("design:type",String)],d.prototype,"fontWeight",void 0),r([e.type("string"),n("design:type",String)],d.prototype,"fontStyle",void 0);class s extends e.Component{constructor(){super(...arguments),this.text="",this.style={}}init(e){this.style=Object.assign({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==e?void 0:e.style),e&&(this.text=e.text)}}s.componentName="BitmapText",r([e.type("string"),n("design:type",String)],s.prototype,"text",void 0),r([e.Field(()=>d),n("design:type",Object)],s.prototype,"style",void 0);class y{}r([e.type("number"),n("design:type",Number)],y.prototype,"alpha",void 0),r([e.Field({type:"color"}),n("design:type",Object)],y.prototype,"color",void 0),r([e.type("string"),n("design:type",String)],y.prototype,"join",void 0),r([e.type("number"),n("design:type",Number)],y.prototype,"miterLimit",void 0),r([e.type("number"),n("design:type",Number)],y.prototype,"width",void 0);class l{}r([e.type("number"),n("design:type",Number)],l.prototype,"alpha",void 0),r([e.type("number"),n("design:type",Number)],l.prototype,"angle",void 0),r([e.type("number"),n("design:type",Number)],l.prototype,"blur",void 0),r([e.Field({type:"color"}),n("design:type",Object)],l.prototype,"color",void 0),r([e.type("number"),n("design:type",Number)],l.prototype,"distance",void 0),r([e.type("boolean"),n("design:type",Boolean)],l.prototype,"enabled",void 0);class a{}r([e.type("string"),n("design:type",String)],a.prototype,"align",void 0),r([e.type("boolean"),n("design:type",Boolean)],a.prototype,"breakWords",void 0),r([e.Field(()=>l),n("design:type",Object)],a.prototype,"dropShadow",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"dropShadowAlpha",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"dropShadowAngle",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"dropShadowBlur",void 0),r([e.Field({type:"color"}),n("design:type",Object)],a.prototype,"dropShadowColor",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"dropShadowDistance",void 0),r([e.Field({type:"color"}),n("design:type",Object)],a.prototype,"fill",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"fillGradientType",void 0),r([e.type("number"),n("design:type",Array)],a.prototype,"fillGradientStops",void 0),r([e.type("string"),n("design:type",Object)],a.prototype,"fontFamily",void 0),r([e.type("number"),n("design:type",Object)],a.prototype,"fontSize",void 0),r([e.type("string"),n("design:type",String)],a.prototype,"fontStyle",void 0),r([e.type("string"),n("design:type",String)],a.prototype,"fontVariant",void 0),r([e.type("string"),n("design:type",String)],a.prototype,"fontWeight",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"leading",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"letterSpacing",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"lineHeight",void 0),r([e.type("string"),n("design:type",String)],a.prototype,"lineJoin",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"miterLimit",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"padding",void 0),r([e.Field(()=>y),n("design:type",Object)],a.prototype,"stroke",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"strokeThickness",void 0),r([e.type("string"),n("design:type",String)],a.prototype,"textBaseline",void 0),r([e.type("string"),n("design:type",String)],a.prototype,"verticalAlign",void 0),r([e.type("boolean"),n("design:type",Boolean)],a.prototype,"trim",void 0),r([e.type("string"),n("design:type",String)],a.prototype,"whiteSpace",void 0),r([e.type("boolean"),n("design:type",Boolean)],a.prototype,"wordWrap",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"wordWrapWidth",void 0);class c extends e.Component{constructor(e){super(e),this.text="",this.style={},this.init(e)}init(e){const o=new t.TextStyle({fontSize:20}),i={};for(const e in o)0===e.indexOf("_")&&(i[e.substring(1)]=o[e]);delete i.styleKey,this.style=i,e&&(this.text=e.text,Object.assign(this.style,e.style))}}c.componentName="Text",r([e.type("string"),n("design:type",String)],c.prototype,"text",void 0),r([e.Field(()=>a),n("design:type",Object)],c.prototype,"style",void 0);class g{}r([e.type("string"),n("design:type",String)],g.prototype,"scaleMode",void 0),r([e.type("number"),n("design:type",Number)],g.prototype,"resolution",void 0);class m{}r([e.type("string"),n("design:type",Object)],m.prototype,"fontFamily",void 0),r([e.type("number"),n("design:type",Object)],m.prototype,"fontSize",void 0),r([e.type("string"),n("design:type",String)],m.prototype,"fontWeight",void 0),r([e.type("string"),n("design:type",String)],m.prototype,"fontStyle",void 0),r([e.type("string"),n("design:type",String)],m.prototype,"fontVariant",void 0),r([e.type("string"),n("design:type",String)],m.prototype,"align",void 0),r([e.type("string"),n("design:type",String)],m.prototype,"textBaseline",void 0),r([e.Field({type:"color"}),n("design:type",Object)],m.prototype,"fill",void 0),r([e.Field({type:"color"}),n("design:type",Object)],m.prototype,"stroke",void 0),r([e.type("number"),n("design:type",Number)],m.prototype,"strokeThickness",void 0),r([e.type("number"),n("design:type",Number)],m.prototype,"lineHeight",void 0),r([e.type("number"),n("design:type",Number)],m.prototype,"letterSpacing",void 0),r([e.type("number"),n("design:type",Number)],m.prototype,"padding",void 0),r([e.type("boolean"),n("design:type",Boolean)],m.prototype,"wordWrap",void 0),r([e.type("number"),n("design:type",Number)],m.prototype,"wordWrapWidth",void 0),r([e.type("boolean"),n("design:type",Boolean)],m.prototype,"breakWords",void 0),r([e.type("string"),n("design:type",String)],m.prototype,"whiteSpace",void 0),r([e.type("boolean"),n("design:type",Boolean)],m.prototype,"dropShadow",void 0),r([e.Field({type:"color"}),n("design:type",Object)],m.prototype,"dropShadowColor",void 0),r([e.type("number"),n("design:type",Number)],m.prototype,"dropShadowAlpha",void 0),r([e.type("number"),n("design:type",Number)],m.prototype,"dropShadowAngle",void 0),r([e.type("number"),n("design:type",Number)],m.prototype,"dropShadowBlur",void 0),r([e.type("number"),n("design:type",Number)],m.prototype,"dropShadowDistance",void 0),r([e.type("object"),n("design:type",Array)],m.prototype,"cssOverrides",void 0),r([e.type("object"),n("design:type",Object)],m.prototype,"tagStyles",void 0),r([e.type("boolean"),n("design:type",Boolean)],m.prototype,"trim",void 0);class u extends e.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)}}u.componentName="HTMLText",r([e.type("string"),n("design:type",String)],u.prototype,"text",void 0),r([e.Field(()=>m),n("design:type",Object)],u.prototype,"style",void 0),r([e.Field(()=>g),n("design:type",Object)],u.prototype,"textureStyle",void 0);let h=class extends o.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={}}init(){this.renderSystem=this.game.getSystem(o.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(t){return p(this,void 0,void 0,function*(){const o="Text"===t.componentName,i="HTMLText"===t.componentName,r="BitmapText"===t.componentName;if(o||i||r)if(t.type===e.OBSERVER_TYPE.ADD)o?yield this.addTextComponent(t):i?yield this.addHTMLTextComponent(t):yield this.addBitmapTextComponent(t),this.setSize(t);else if(t.type===e.OBSERVER_TYPE.REMOVE)this.containerManager.getContainer(t.gameObject.id).removeChild(this.texts[t.gameObject.id].text),this.texts[t.gameObject.id].text.destroy({children:!0}),delete this.texts[t.gameObject.id];else{this.change(t);const e=t.component;if("style"===t.prop.prop[0]&&e.style&&e.style.fontFamily){const{text:o}=this.texts[t.gameObject.id];yield this.waitForFontResource(o,t,e.style.fontFamily)}this.setSize(t)}})}addTextComponent(e){return p(this,void 0,void 0,function*(){const t=e.component,o=this.processStyle(t.style),r=o.fontFamily;delete o.fontFamily;const n=r?"":t.text,p=new i.Text(n,o);this.containerManager.getContainer(e.gameObject.id).addChildAt(p,0),this.texts[e.gameObject.id]={text:p,component:t},r&&(yield this.waitForFontResource(p,e,r))})}addHTMLTextComponent(e){return p(this,void 0,void 0,function*(){const t=e.component,o=this.processStyle(t.style),r=o.fontFamily;delete o.fontFamily;const n=r?"":t.text,p=new i.HTMLText(Object.assign({text:n,style:o},t.textureStyle&&{textureStyle:t.textureStyle}));this.containerManager.getContainer(e.gameObject.id).addChildAt(p,0),this.texts[e.gameObject.id]={text:p,component:t},r&&(yield this.waitForFontResource(p,e,r))})}addBitmapTextComponent(e){return p(this,void 0,void 0,function*(){const t=e.component,o=this.processStyle(t.style),r=o.fontFamily;delete o.fontFamily;const n=r?"":t.text,p=new i.BitmapText(n,o);this.containerManager.getContainer(e.gameObject.id).addChildAt(p,0),this.texts[e.gameObject.id]={text:p,component:t},r&&(yield this.waitForFontResource(p,e,r))})}waitForFontResource(t,o,i){return p(this,void 0,void 0,function*(){if(i)try{const r=Array.isArray(i)?i[0]:i,n=this.increaseAsyncId(o.gameObject.id);if(yield e.resource.getResource(r),!this.validateAsyncId(o.gameObject.id,n))return;const p=this.texts[o.gameObject.id].component;t.style.fontFamily=i,t.text=p.text}catch(e){console.warn(`字体资源 ${i} 加载失败:`,e)}})}processStyle(e){const o=Object.assign({},e);if(o.strokeThickness){const e=o.stroke;o.stroke={color:e,width:o.strokeThickness},delete o.strokeThickness}const i=null!=o.dropShadowColor||null!=o.dropShadowDistance||null!=o.dropShadowAngle||null!=o.dropShadowAlpha||null!=o.dropShadowBlur;if(o.dropShadow&&i){const e=o.dropShadow&&"object"==typeof o.dropShadow&&!Array.isArray(o.dropShadow)?Object.assign({},o.dropShadow):{};null!=o.dropShadowColor&&(e.color=o.dropShadowColor),null!=o.dropShadowDistance&&(e.distance=o.dropShadowDistance),null!=o.dropShadowAngle&&(e.angle=o.dropShadowAngle),null!=o.dropShadowAlpha&&(e.alpha=o.dropShadowAlpha),null!=o.dropShadowBlur&&(e.blur=o.dropShadowBlur),o.dropShadow=e}if(delete o.dropShadowColor,delete o.dropShadowDistance,delete o.dropShadowAngle,delete o.dropShadowAlpha,delete o.dropShadowBlur,Array.isArray(o.fill)&&(o.fill=o.fill[0]),Array.isArray(o.fillGradientStops)){let e;e=null==o.fontSize?t.TextStyle.defaultTextStyle.fontSize:"string"==typeof o.fontSize?parseInt(o.fontSize,10):o.fontSize;const i=new t.FillGradient(0,0,0,1.7*e),r=o.fillGradientStops.map(e=>t.Color.shared.setValue(e).toNumber());r.forEach((e,t)=>{const o=t/(r.length-1);i.addColorStop(o,e)}),o.fill={fill:i},delete o.fillGradientStops}return o}change(e){const{text:t,component:o}=this.texts[e.gameObject.id],r="HTMLText"===e.componentName;if("text"===e.prop.prop[0])t.text=o.text;else if("style"===e.prop.prop[0]){const e=this.processStyle(o.style);Object.assign(t.style,e)}else if("textureStyle"===e.prop.prop[0]&&r){const r=o,n=this.containerManager.getContainer(e.gameObject.id),p=n.getChildIndex(t);n.removeChild(t),t.destroy({children:!0});const d=new i.HTMLText({text:r.text,style:r.style,textureStyle:r.textureStyle});n.addChildAt(d,p),this.texts[e.gameObject.id].text=d}}setSize(e){const{transform:t}=e.gameObject;if(!t)return;const{text:o}=this.texts[e.gameObject.id],i=o.getSize();t.size.width=i.width,t.size.height=i.height}};h.systemName="Text",h=r([e.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}],HTMLText:["text",{prop:["style"],deep:!0},{prop:["textureStyle"],deep:!0}],BitmapText:["text",{prop:["style"],deep:!0}]})],h);var b=h;exports.BitmapText=s,exports.HTMLText=u,exports.Text=c,exports.TextSystem=b;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("pixi.js"),o=require("@eva/plugin-renderer"),i=require("@eva/renderer-adapter");function r(e,t,o,i){var r,n=arguments.length,p=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,o):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)p=Reflect.decorate(e,t,o,i);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(p=(n<3?r(p):n>3?r(t,o,p):r(t,o))||p);return n>3&&p&&Object.defineProperty(t,o,p),p}function n(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function p(e,t,o,i){return new(o||(o=Promise))(function(r,n){function p(e){try{d(i.next(e))}catch(e){n(e)}}function s(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o(function(e){e(t)})).then(p,s)}d((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;class s{}r([e.type("string"),n("design:type",Object)],s.prototype,"fontFamily",void 0),r([e.type("number"),n("design:type",Object)],s.prototype,"fontSize",void 0),r([e.Field({type:"color"}),n("design:type",Object)],s.prototype,"fill",void 0),r([e.type("string"),n("design:type",String)],s.prototype,"align",void 0),r([e.type("number"),n("design:type",Number)],s.prototype,"letterSpacing",void 0),r([e.type("number"),n("design:type",Number)],s.prototype,"padding",void 0),r([e.Field({type:"color"}),n("design:type",Object)],s.prototype,"stroke",void 0),r([e.type("number"),n("design:type",Number)],s.prototype,"strokeThickness",void 0),r([e.type("string"),n("design:type",String)],s.prototype,"fontWeight",void 0),r([e.type("string"),n("design:type",String)],s.prototype,"fontStyle",void 0);class d extends e.Component{constructor(){super(...arguments),this.text="",this.style={}}init(e){this.style=Object.assign({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==e?void 0:e.style),e&&(this.text=e.text)}}d.componentName="BitmapText",r([e.type("string"),n("design:type",String)],d.prototype,"text",void 0),r([e.Field(()=>s),n("design:type",Object)],d.prototype,"style",void 0);class y{}r([e.type("number"),n("design:type",Number)],y.prototype,"alpha",void 0),r([e.Field({type:"color"}),n("design:type",Object)],y.prototype,"color",void 0),r([e.type("string"),n("design:type",String)],y.prototype,"join",void 0),r([e.type("number"),n("design:type",Number)],y.prototype,"miterLimit",void 0),r([e.type("number"),n("design:type",Number)],y.prototype,"width",void 0);class l{}r([e.type("number"),n("design:type",Number)],l.prototype,"alpha",void 0),r([e.type("number"),n("design:type",Number)],l.prototype,"angle",void 0),r([e.type("number"),n("design:type",Number)],l.prototype,"blur",void 0),r([e.Field({type:"color"}),n("design:type",Object)],l.prototype,"color",void 0),r([e.type("number"),n("design:type",Number)],l.prototype,"distance",void 0),r([e.type("boolean"),n("design:type",Boolean)],l.prototype,"enabled",void 0);class a{}r([e.type("string"),n("design:type",String)],a.prototype,"align",void 0),r([e.type("boolean"),n("design:type",Boolean)],a.prototype,"breakWords",void 0),r([e.Field(()=>l),n("design:type",Object)],a.prototype,"dropShadow",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"dropShadowAlpha",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"dropShadowAngle",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"dropShadowBlur",void 0),r([e.Field({type:"color"}),n("design:type",Object)],a.prototype,"dropShadowColor",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"dropShadowDistance",void 0),r([e.Field({type:"color"}),n("design:type",Object)],a.prototype,"fill",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"fillGradientType",void 0),r([e.type("number"),n("design:type",Array)],a.prototype,"fillGradientStops",void 0),r([e.type("string"),n("design:type",Object)],a.prototype,"fontFamily",void 0),r([e.type("number"),n("design:type",Object)],a.prototype,"fontSize",void 0),r([e.type("string"),n("design:type",String)],a.prototype,"fontStyle",void 0),r([e.type("string"),n("design:type",String)],a.prototype,"fontVariant",void 0),r([e.type("string"),n("design:type",String)],a.prototype,"fontWeight",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"leading",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"letterSpacing",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"lineHeight",void 0),r([e.type("string"),n("design:type",String)],a.prototype,"lineJoin",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"miterLimit",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"padding",void 0),r([e.Field(()=>y),n("design:type",Object)],a.prototype,"stroke",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"strokeThickness",void 0),r([e.type("string"),n("design:type",String)],a.prototype,"textBaseline",void 0),r([e.type("string"),n("design:type",String)],a.prototype,"verticalAlign",void 0),r([e.type("boolean"),n("design:type",Boolean)],a.prototype,"trim",void 0),r([e.type("string"),n("design:type",String)],a.prototype,"whiteSpace",void 0),r([e.type("boolean"),n("design:type",Boolean)],a.prototype,"wordWrap",void 0),r([e.type("number"),n("design:type",Number)],a.prototype,"wordWrapWidth",void 0);class g extends e.Component{constructor(e){super(e),this.text="",this.style={},this.init(e)}init(e){const o=new t.TextStyle({fontSize:20}),i={};for(const e in o)0===e.indexOf("_")&&(i[e.substring(1)]=o[e]);delete i.styleKey,this.style=i,e&&(this.text=e.text,Object.assign(this.style,e.style))}}g.componentName="Text",r([e.type("string"),n("design:type",String)],g.prototype,"text",void 0),r([e.Field(()=>a),n("design:type",Object)],g.prototype,"style",void 0);class c{}r([e.type("string"),n("design:type",String)],c.prototype,"scaleMode",void 0),r([e.type("number"),n("design:type",Number)],c.prototype,"resolution",void 0);class h{}r([e.type("string"),n("design:type",Object)],h.prototype,"fontFamily",void 0),r([e.type("number"),n("design:type",Object)],h.prototype,"fontSize",void 0),r([e.type("string"),n("design:type",String)],h.prototype,"fontWeight",void 0),r([e.type("string"),n("design:type",String)],h.prototype,"fontStyle",void 0),r([e.type("string"),n("design:type",String)],h.prototype,"fontVariant",void 0),r([e.type("string"),n("design:type",String)],h.prototype,"align",void 0),r([e.type("string"),n("design:type",String)],h.prototype,"textBaseline",void 0),r([e.Field({type:"color"}),n("design:type",Object)],h.prototype,"fill",void 0),r([e.Field({type:"color"}),n("design:type",Object)],h.prototype,"stroke",void 0),r([e.type("number"),n("design:type",Number)],h.prototype,"strokeThickness",void 0),r([e.type("number"),n("design:type",Number)],h.prototype,"lineHeight",void 0),r([e.type("number"),n("design:type",Number)],h.prototype,"letterSpacing",void 0),r([e.type("number"),n("design:type",Number)],h.prototype,"padding",void 0),r([e.type("boolean"),n("design:type",Boolean)],h.prototype,"wordWrap",void 0),r([e.type("number"),n("design:type",Number)],h.prototype,"wordWrapWidth",void 0),r([e.type("boolean"),n("design:type",Boolean)],h.prototype,"breakWords",void 0),r([e.type("string"),n("design:type",String)],h.prototype,"whiteSpace",void 0),r([e.type("boolean"),n("design:type",Boolean)],h.prototype,"dropShadow",void 0),r([e.Field({type:"color"}),n("design:type",Object)],h.prototype,"dropShadowColor",void 0),r([e.type("number"),n("design:type",Number)],h.prototype,"dropShadowAlpha",void 0),r([e.type("number"),n("design:type",Number)],h.prototype,"dropShadowAngle",void 0),r([e.type("number"),n("design:type",Number)],h.prototype,"dropShadowBlur",void 0),r([e.type("number"),n("design:type",Number)],h.prototype,"dropShadowDistance",void 0),r([e.type("object"),n("design:type",Array)],h.prototype,"cssOverrides",void 0),r([e.type("object"),n("design:type",Object)],h.prototype,"tagStyles",void 0),r([e.type("boolean"),n("design:type",Boolean)],h.prototype,"trim",void 0);class m extends e.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)}}m.componentName="HTMLText",r([e.type("string"),n("design:type",String)],m.prototype,"text",void 0),r([e.Field(()=>h),n("design:type",Object)],m.prototype,"style",void 0),r([e.Field(()=>c),n("design:type",Object)],m.prototype,"textureStyle",void 0);let u=class extends o.Renderer{constructor(){super(...arguments),this.name="Text",this.texts={}}init(){this.renderSystem=this.game.getSystem(o.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(t){return p(this,void 0,void 0,function*(){const o="Text"===t.componentName,i="HTMLText"===t.componentName,r="BitmapText"===t.componentName;if(o||i||r)if(t.type===e.OBSERVER_TYPE.ADD)o?yield this.addTextComponent(t):i?yield this.addHTMLTextComponent(t):yield this.addBitmapTextComponent(t),this.setSize(t);else if(t.type===e.OBSERVER_TYPE.REMOVE)this.containerManager.getContainer(t.gameObject.id).removeChild(this.texts[t.gameObject.id].text),this.texts[t.gameObject.id].text.destroy({children:!0}),delete this.texts[t.gameObject.id];else{this.change(t);const e=t.component,o=t.prop.prop;if("style"===o[0]&&(1===o.length||"fontFamily"===o[1])&&e.style&&this.hasRegisteredFont(e.style.fontFamily)){const{text:o}=this.texts[t.gameObject.id];yield this.waitForFontResource(o,t,e.style.fontFamily)}this.setSize(t)}})}addTextComponent(e){return p(this,void 0,void 0,function*(){const t=e.component,o=this.processStyle(t.style),r=o.fontFamily,n=this.hasRegisteredFont(r);n&&delete o.fontFamily;const p=n?"":t.text,s=new i.Text(p,o);this.containerManager.getContainer(e.gameObject.id).addChildAt(s,0),this.texts[e.gameObject.id]={text:s,component:t},n&&(yield this.waitForFontResource(s,e,r))})}addHTMLTextComponent(e){return p(this,void 0,void 0,function*(){const t=e.component,o=this.processStyle(t.style),r=o.fontFamily,n=this.hasRegisteredFont(r);n&&delete o.fontFamily;const p=n?"":t.text,s=new i.HTMLText(Object.assign({text:p,style:o},t.textureStyle&&{textureStyle:t.textureStyle}));this.containerManager.getContainer(e.gameObject.id).addChildAt(s,0),this.texts[e.gameObject.id]={text:s,component:t},n&&(yield this.waitForFontResource(s,e,r))})}addBitmapTextComponent(e){return p(this,void 0,void 0,function*(){const t=e.component,o=this.processStyle(t.style),r=o.fontFamily,n=this.hasRegisteredFont(r);n&&delete o.fontFamily;const p=n?"":t.text,s=new i.BitmapText(p,o);this.containerManager.getContainer(e.gameObject.id).addChildAt(s,0),this.texts[e.gameObject.id]={text:s,component:t},n&&(yield this.waitForFontResource(s,e,r))})}hasRegisteredFont(t){var o;if(!t)return!1;const i=Array.isArray(t)?t[0]:t;return(null===(o=e.resource.resourcesMap[i])||void 0===o?void 0:o.type)===e.RESOURCE_TYPE.FONT}waitForFontResource(t,o,i){return p(this,void 0,void 0,function*(){if(i)try{const r=Array.isArray(i)?i[0]:i;if(!this.hasRegisteredFont(i))return;const n=this.increaseAsyncId(o.gameObject.id);if(yield e.resource.getResource(r),!this.validateAsyncId(o.gameObject.id,n))return;const p=this.texts[o.gameObject.id].component;t.style.fontFamily=i,t.text=p.text}catch(e){console.warn(`字体资源 ${i} 加载失败:`,e)}})}processStyle(e){const o=Object.assign({},e);if(o.strokeThickness){const e=o.stroke;o.stroke={color:e,width:o.strokeThickness},delete o.strokeThickness}const i=null!=o.dropShadowColor||null!=o.dropShadowDistance||null!=o.dropShadowAngle||null!=o.dropShadowAlpha||null!=o.dropShadowBlur;if(o.dropShadow&&i){const e=o.dropShadow&&"object"==typeof o.dropShadow&&!Array.isArray(o.dropShadow)?Object.assign({},o.dropShadow):{};null!=o.dropShadowColor&&(e.color=o.dropShadowColor),null!=o.dropShadowDistance&&(e.distance=o.dropShadowDistance),null!=o.dropShadowAngle&&(e.angle=o.dropShadowAngle),null!=o.dropShadowAlpha&&(e.alpha=o.dropShadowAlpha),null!=o.dropShadowBlur&&(e.blur=o.dropShadowBlur),o.dropShadow=e}if(delete o.dropShadowColor,delete o.dropShadowDistance,delete o.dropShadowAngle,delete o.dropShadowAlpha,delete o.dropShadowBlur,Array.isArray(o.fill)&&(o.fill=o.fill[0]),Array.isArray(o.fillGradientStops)){let e;e=null==o.fontSize?t.TextStyle.defaultTextStyle.fontSize:"string"==typeof o.fontSize?parseInt(o.fontSize,10):o.fontSize;const i=new t.FillGradient(0,0,0,1.7*e),r=o.fillGradientStops.map(e=>t.Color.shared.setValue(e).toNumber());r.forEach((e,t)=>{const o=t/(r.length-1);i.addColorStop(o,e)}),o.fill={fill:i},delete o.fillGradientStops}return o}change(e){const{text:t,component:o}=this.texts[e.gameObject.id],r="HTMLText"===e.componentName;if("text"===e.prop.prop[0])t.text=o.text;else if("style"===e.prop.prop[0]){const e=this.processStyle(o.style);this.hasRegisteredFont(e.fontFamily)&&delete e.fontFamily,Object.assign(t.style,e)}else if("textureStyle"===e.prop.prop[0]&&r){const r=o,n=this.containerManager.getContainer(e.gameObject.id),p=n.getChildIndex(t);n.removeChild(t),t.destroy({children:!0});const s=new i.HTMLText({text:r.text,style:r.style,textureStyle:r.textureStyle});n.addChildAt(s,p),this.texts[e.gameObject.id].text=s}}setSize(e){const{transform:t}=e.gameObject;if(!t)return;const{text:o}=this.texts[e.gameObject.id],i=o.getSize();t.size.width===i.width&&t.size.height===i.height||(t.size.width=i.width,t.size.height=i.height,this.renderSystem.commitIntrinsicSize(e.gameObject))}};u.systemName="Text",u=r([e.decorators.componentObserver({Text:["text",{prop:["style"],deep:!0}],HTMLText:["text",{prop:["style"],deep:!0},{prop:["textureStyle"],deep:!0}],BitmapText:["text",{prop:["style"],deep:!0}]})],u);var b=u;exports.BitmapText=d,exports.HTMLText=m,exports.Text=g,exports.TextSystem=b;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component, type, Field, decorators, OBSERVER_TYPE
|
|
1
|
+
import { Component, type, Field, resource, RESOURCE_TYPE, decorators, OBSERVER_TYPE } from '@eva/eva.js';
|
|
2
2
|
import { TextStyle, FillGradient, Color } from 'pixi.js';
|
|
3
3
|
import { Renderer, RendererSystem } from '@eva/plugin-renderer';
|
|
4
4
|
import { HTMLText as HTMLText$1, Text as Text$3, BitmapText as BitmapText$1 } from '@eva/renderer-adapter';
|
|
@@ -636,9 +636,11 @@ let Text = class Text extends Renderer {
|
|
|
636
636
|
}
|
|
637
637
|
else {
|
|
638
638
|
this.change(changed);
|
|
639
|
-
//
|
|
639
|
+
// Only a font-family replacement can introduce a new async font asset.
|
|
640
640
|
const component = changed.component;
|
|
641
|
-
|
|
641
|
+
const propPath = changed.prop.prop;
|
|
642
|
+
const fontFamilyChanged = propPath[0] === 'style' && (propPath.length === 1 || propPath[1] === 'fontFamily');
|
|
643
|
+
if (fontFamilyChanged && component.style && this.hasRegisteredFont(component.style.fontFamily)) {
|
|
642
644
|
const { text } = this.texts[changed.gameObject.id];
|
|
643
645
|
yield this.waitForFontResource(text, changed, component.style.fontFamily);
|
|
644
646
|
}
|
|
@@ -649,11 +651,14 @@ let Text = class Text extends Renderer {
|
|
|
649
651
|
addTextComponent(changed) {
|
|
650
652
|
return __awaiter(this, void 0, void 0, function* () {
|
|
651
653
|
const component = changed.component;
|
|
652
|
-
//
|
|
654
|
+
// Registered Eva font assets must load before the first glyph. Ordinary
|
|
655
|
+
// CSS/system families are already valid Pixi styles and render directly.
|
|
653
656
|
const styleWithoutFont = this.processStyle(component.style);
|
|
654
657
|
const fontFamily = styleWithoutFont.fontFamily;
|
|
655
|
-
|
|
656
|
-
|
|
658
|
+
const waitsForFontResource = this.hasRegisteredFont(fontFamily);
|
|
659
|
+
if (waitsForFontResource)
|
|
660
|
+
delete styleWithoutFont.fontFamily;
|
|
661
|
+
const initialText = waitsForFontResource ? '' : component.text;
|
|
657
662
|
const text = new Text$3(initialText, styleWithoutFont);
|
|
658
663
|
this.containerManager.getContainer(changed.gameObject.id).addChildAt(text, 0);
|
|
659
664
|
this.texts[changed.gameObject.id] = {
|
|
@@ -661,7 +666,7 @@ let Text = class Text extends Renderer {
|
|
|
661
666
|
component,
|
|
662
667
|
};
|
|
663
668
|
// 如果指定了字体资源,等待资源加载完成后设置 fontFamily
|
|
664
|
-
if (
|
|
669
|
+
if (waitsForFontResource) {
|
|
665
670
|
yield this.waitForFontResource(text, changed, fontFamily);
|
|
666
671
|
}
|
|
667
672
|
});
|
|
@@ -672,8 +677,10 @@ let Text = class Text extends Renderer {
|
|
|
672
677
|
// 创建样式副本,先不设置 fontFamily
|
|
673
678
|
const styleWithoutFont = this.processStyle(component.style);
|
|
674
679
|
const fontFamily = styleWithoutFont.fontFamily;
|
|
675
|
-
|
|
676
|
-
|
|
680
|
+
const waitsForFontResource = this.hasRegisteredFont(fontFamily);
|
|
681
|
+
if (waitsForFontResource)
|
|
682
|
+
delete styleWithoutFont.fontFamily;
|
|
683
|
+
const initialText = waitsForFontResource ? '' : component.text;
|
|
677
684
|
const htmlText = new HTMLText$1(Object.assign({ text: initialText, style: styleWithoutFont }, (component.textureStyle && { textureStyle: component.textureStyle })));
|
|
678
685
|
this.containerManager.getContainer(changed.gameObject.id).addChildAt(htmlText, 0);
|
|
679
686
|
this.texts[changed.gameObject.id] = {
|
|
@@ -681,7 +688,7 @@ let Text = class Text extends Renderer {
|
|
|
681
688
|
component,
|
|
682
689
|
};
|
|
683
690
|
// 如果指定了字体资源,等待资源加载完成后设置 fontFamily
|
|
684
|
-
if (
|
|
691
|
+
if (waitsForFontResource) {
|
|
685
692
|
yield this.waitForFontResource(htmlText, changed, fontFamily);
|
|
686
693
|
}
|
|
687
694
|
});
|
|
@@ -692,8 +699,10 @@ let Text = class Text extends Renderer {
|
|
|
692
699
|
// 创建样式副本,先不设置 fontFamily
|
|
693
700
|
const styleWithoutFont = this.processStyle(component.style);
|
|
694
701
|
const fontFamily = styleWithoutFont.fontFamily;
|
|
695
|
-
|
|
696
|
-
|
|
702
|
+
const waitsForFontResource = this.hasRegisteredFont(fontFamily);
|
|
703
|
+
if (waitsForFontResource)
|
|
704
|
+
delete styleWithoutFont.fontFamily;
|
|
705
|
+
const initialText = waitsForFontResource ? '' : component.text;
|
|
697
706
|
const bitmapText = new BitmapText$1(initialText, styleWithoutFont);
|
|
698
707
|
this.containerManager.getContainer(changed.gameObject.id).addChildAt(bitmapText, 0);
|
|
699
708
|
this.texts[changed.gameObject.id] = {
|
|
@@ -701,11 +710,18 @@ let Text = class Text extends Renderer {
|
|
|
701
710
|
component,
|
|
702
711
|
};
|
|
703
712
|
// 如果指定了字体资源,等待资源加载完成后设置 fontFamily
|
|
704
|
-
if (
|
|
713
|
+
if (waitsForFontResource) {
|
|
705
714
|
yield this.waitForFontResource(bitmapText, changed, fontFamily);
|
|
706
715
|
}
|
|
707
716
|
});
|
|
708
717
|
}
|
|
718
|
+
hasRegisteredFont(fontFamily) {
|
|
719
|
+
var _a;
|
|
720
|
+
if (!fontFamily)
|
|
721
|
+
return false;
|
|
722
|
+
const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
|
|
723
|
+
return ((_a = resource.resourcesMap[fontName]) === null || _a === void 0 ? void 0 : _a.type) === RESOURCE_TYPE.FONT;
|
|
724
|
+
}
|
|
709
725
|
/**
|
|
710
726
|
* 等待字体资源加载完成并更新文本
|
|
711
727
|
*/
|
|
@@ -716,6 +732,8 @@ let Text = class Text extends Renderer {
|
|
|
716
732
|
}
|
|
717
733
|
try {
|
|
718
734
|
const fontName = Array.isArray(fontFamily) ? fontFamily[0] : fontFamily;
|
|
735
|
+
if (!this.hasRegisteredFont(fontFamily))
|
|
736
|
+
return;
|
|
719
737
|
// 通过 resource 系统获取字体资源
|
|
720
738
|
const asyncId = this.increaseAsyncId(changed.gameObject.id);
|
|
721
739
|
yield resource.getResource(fontName);
|
|
@@ -816,6 +834,8 @@ let Text = class Text extends Renderer {
|
|
|
816
834
|
}
|
|
817
835
|
else if (changed.prop.prop[0] === 'style') {
|
|
818
836
|
const processedStyle = this.processStyle(component.style);
|
|
837
|
+
if (this.hasRegisteredFont(processedStyle.fontFamily))
|
|
838
|
+
delete processedStyle.fontFamily;
|
|
819
839
|
Object.assign(text.style, processedStyle);
|
|
820
840
|
}
|
|
821
841
|
else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
|
|
@@ -840,8 +860,11 @@ let Text = class Text extends Renderer {
|
|
|
840
860
|
return;
|
|
841
861
|
const { text } = this.texts[changed.gameObject.id];
|
|
842
862
|
const size = text.getSize();
|
|
863
|
+
if (transform.size.width === size.width && transform.size.height === size.height)
|
|
864
|
+
return;
|
|
843
865
|
transform.size.width = size.width;
|
|
844
866
|
transform.size.height = size.height;
|
|
867
|
+
this.renderSystem.commitIntrinsicSize(changed.gameObject);
|
|
845
868
|
}
|
|
846
869
|
};
|
|
847
870
|
Text.systemName = 'Text';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-text",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.14",
|
|
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": "^2.0.0-beta.0",
|
|
22
|
-
"@eva/plugin-renderer": "2.1.0-beta.
|
|
23
|
-
"@eva/renderer-adapter": "2.1.0-beta.
|
|
24
|
-
"@eva/eva.js": "2.1.0-beta.
|
|
22
|
+
"@eva/plugin-renderer": "2.1.0-beta.14",
|
|
23
|
+
"@eva/renderer-adapter": "2.1.0-beta.14",
|
|
24
|
+
"@eva/eva.js": "2.1.0-beta.14",
|
|
25
25
|
"pixi.js": "^8.17.0"
|
|
26
26
|
}
|
|
27
27
|
}
|