@eva/plugin-renderer-text 2.0.1-beta.35 → 2.0.1-beta.36
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 +14 -1
- package/dist/EVA.plugin.renderer.text.min.js +1 -1
- package/dist/plugin-renderer-text.cjs.js +17 -1
- package/dist/plugin-renderer-text.cjs.prod.js +2 -2
- package/dist/plugin-renderer-text.d.ts +4 -0
- package/dist/plugin-renderer-text.esm.js +17 -1
- package/package.json +4 -4
|
@@ -245,6 +245,18 @@ var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendere
|
|
|
245
245
|
}
|
|
246
246
|
});
|
|
247
247
|
}
|
|
248
|
+
processStrokeStyle(style) {
|
|
249
|
+
const processed = _extends({}, style);
|
|
250
|
+
if (processed.strokeThickness) {
|
|
251
|
+
const color = processed.stroke;
|
|
252
|
+
processed.stroke = {
|
|
253
|
+
color,
|
|
254
|
+
width: processed.strokeThickness
|
|
255
|
+
};
|
|
256
|
+
delete processed.strokeThickness;
|
|
257
|
+
}
|
|
258
|
+
return processed;
|
|
259
|
+
}
|
|
248
260
|
change(changed) {
|
|
249
261
|
const {
|
|
250
262
|
text,
|
|
@@ -254,7 +266,8 @@ var _EVA_IIFE_text = function (exports, eva_js, pixi_js, pluginRenderer, rendere
|
|
|
254
266
|
if (changed.prop.prop[0] === 'text') {
|
|
255
267
|
text.text = component.text;
|
|
256
268
|
} else if (changed.prop.prop[0] === 'style') {
|
|
257
|
-
|
|
269
|
+
const processedStyle = this.processStrokeStyle(component.style);
|
|
270
|
+
_extends(text.style, processedStyle);
|
|
258
271
|
} else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
|
|
259
272
|
const htmlComponent = component;
|
|
260
273
|
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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 o in n)({}).hasOwnProperty.call(n,o)&&(t[o]=n[o])}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,o,i){"use strict";function s(t,e,n,o){var i,s=arguments.length,r=s<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,o);else for(var c=t.length-1;c>=0;c--)(i=t[c])&&(r=(s<3?i(r):s>3?i(e,n,r):i(e,n))||r);return s>3&&r&&Object.defineProperty(e,n,r),r}function r(t,e,n,o){return new(n||(n=Promise))((function(i,s){function r(t){try{l(o.next(t))}catch(t){s(t)}}function c(t){try{l(o.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(r,c)}l((o=o.apply(t,e||[])).next())}))}function c(t){return function(e,n){var o=function(t,e){return t.constructor.IDEProps||(t.constructor.IDEProps={}),t.constructor.IDEProps[e]||(t.constructor.IDEProps[e]={}),t.constructor.IDEProps[e]}(e,n);o.key=n,o.type=t}}class l extends e.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){this.style=_extends({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==t?void 0:t.style),t&&(this.text=t.text)}}l.componentName="BitmapText",s([c("string")],l.prototype,"text",void 0);class a extends e.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){const e=new n.TextStyle({fontSize:20}),o={};for(const t in e)0===t.indexOf("_")&&(o[t.substring(1)]=e[t]);delete o.styleKey,this.style=o,t&&(this.text=t.text,_extends(this.style,t.style))}}a.componentName="Text",s([c("string")],a.prototype,"text",void 0);class d extends e.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)}}d.componentName="HTMLText",s([c("string")],d.prototype,"text",void 0);let x=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 r(this,void 0,void 0,(function*(){const n="Text"===t.componentName,o="HTMLText"===t.componentName,i="BitmapText"===t.componentName;if(n||o||i)if(t.type===e.OBSERVER_TYPE.ADD)n?yield this.addTextComponent(t):o?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:n}=this.texts[t.gameObject.id];yield this.waitForFontResource(n,t,e.style.fontFamily)}this.setSize(t)}}))}addTextComponent(t){return r(this,void 0,void 0,(function*(){const e=t.component,n=_extends({},e.style),o=n.fontFamily;delete n.fontFamily;const s=o?"":e.text,r=new i.Text(s,n);this.containerManager.getContainer(t.gameObject.id).addChildAt(r,0),this.texts[t.gameObject.id]={text:r,component:e},o&&(yield this.waitForFontResource(r,t,o))}))}addHTMLTextComponent(t){return r(this,void 0,void 0,(function*(){const e=t.component,n=_extends({},e.style),o=n.fontFamily;delete n.fontFamily;const s=o?"":e.text,r=new i.HTMLText(_extends({text:s,style:n},e.textureStyle&&{textureStyle:e.textureStyle}));this.containerManager.getContainer(t.gameObject.id).addChildAt(r,0),this.texts[t.gameObject.id]={text:r,component:e},o&&(yield this.waitForFontResource(r,t,o))}))}addBitmapTextComponent(t){return r(this,void 0,void 0,(function*(){const e=t.component,n=_extends({},e.style),o=n.fontFamily;delete n.fontFamily;const s=o?"":e.text,r=new i.BitmapText(s,n);this.containerManager.getContainer(t.gameObject.id).addChildAt(r,0),this.texts[t.gameObject.id]={text:r,component:e},o&&(yield this.waitForFontResource(r,t,o))}))}waitForFontResource(t,n,o){return r(this,void 0,void 0,(function*(){if(o)try{const i=Array.isArray(o)?o[0]:o,s=this.increaseAsyncId(n.gameObject.id);if(yield e.resource.getResource(i),!this.validateAsyncId(n.gameObject.id,s))return;const r=this.texts[n.gameObject.id].component;t.style.fontFamily=o,t.text=r.text}catch(t){console.warn(`字体资源 ${o} 加载失败:`,t)}}))}processStrokeStyle(t){const e=_extends({},t);if(e.strokeThickness){const t=e.stroke;e.stroke={color:t,width:e.strokeThickness},delete e.strokeThickness}return e}change(t){const{text:e,component:n}=this.texts[t.gameObject.id],o="HTMLText"===t.componentName;if("text"===t.prop.prop[0])e.text=n.text;else if("style"===t.prop.prop[0]){const t=this.processStrokeStyle(n.style);_extends(e.style,t)}else if("textureStyle"===t.prop.prop[0]&&o){const o=n,s=this.containerManager.getContainer(t.gameObject.id),r=s.getChildIndex(e);s.removeChild(e),e.destroy({children:!0});const c=new i.HTMLText({text:o.text,style:o.style,textureStyle:o.textureStyle});s.addChildAt(c,r),this.texts[t.gameObject.id].text=c}}setSize(t){const{transform:e}=t.gameObject;if(!e)return;const{text:n}=this.texts[t.gameObject.id],o=n.getSize();e.size.width=o.width,e.size.height=o.height}};x.systemName="Text",x=s([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}]})],x);var p=x;return t.BitmapText=l,t.HTMLText=d,t.Text=a,t.TextSystem=p,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,PIXI,EVA.plugin.renderer,EVA.rendererAdapter);globalThis.EVA.plugin.renderer.text=globalThis.EVA.plugin.renderer.text||_EVA_IIFE_text;
|
|
@@ -386,6 +386,21 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
386
386
|
}
|
|
387
387
|
});
|
|
388
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* 将 Eva.js 的 stroke/strokeThickness 格式转换为 PixiJS v8 格式
|
|
391
|
+
*/
|
|
392
|
+
processStrokeStyle(style) {
|
|
393
|
+
const processed = Object.assign({}, style);
|
|
394
|
+
if (processed.strokeThickness) {
|
|
395
|
+
const color = processed.stroke;
|
|
396
|
+
processed.stroke = {
|
|
397
|
+
color,
|
|
398
|
+
width: processed.strokeThickness,
|
|
399
|
+
};
|
|
400
|
+
delete processed.strokeThickness;
|
|
401
|
+
}
|
|
402
|
+
return processed;
|
|
403
|
+
}
|
|
389
404
|
change(changed) {
|
|
390
405
|
const { text, component } = this.texts[changed.gameObject.id];
|
|
391
406
|
const isHTMLText = changed.componentName === 'HTMLText';
|
|
@@ -393,7 +408,8 @@ let Text = class Text extends pluginRenderer.Renderer {
|
|
|
393
408
|
text.text = component.text;
|
|
394
409
|
}
|
|
395
410
|
else if (changed.prop.prop[0] === 'style') {
|
|
396
|
-
|
|
411
|
+
const processedStyle = this.processStrokeStyle(component.style);
|
|
412
|
+
Object.assign(text.style, processedStyle);
|
|
397
413
|
}
|
|
398
414
|
else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
|
|
399
415
|
// HTMLText 纹理样式变化需要重新创建
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@eva/eva.js"),e=require("@eva/inspector-decorator"),i=require("pixi.js"),n=require("@eva/plugin-renderer"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@eva/eva.js"),e=require("@eva/inspector-decorator"),i=require("pixi.js"),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(t,e,i,n){var s,o=arguments.length,r=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,n);else for(var c=t.length-1;c>=0;c--)(s=t[c])&&(r=(o<3?s(r):o>3?s(e,i,r):s(e,i))||r);return o>3&&r&&Object.defineProperty(e,i,r),r}function r(t,e,i,n){return new(i||(i=Promise))((function(s,o){function r(t){try{a(n.next(t))}catch(t){o(t)}}function c(t){try{a(n.throw(t))}catch(t){o(t)}}function a(t){t.done?s(t.value):new i((function(e){e(t.value)})).then(r,c)}a((n=n.apply(t,e||[])).next())}))}class c extends t.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){this.style=Object.assign({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==t?void 0:t.style),t&&(this.text=t.text)}}c.componentName="BitmapText",o([e.type("string")],c.prototype,"text",void 0);class a extends t.Component{constructor(){super(...arguments),this.text="",this.style={}}init(t){const e=new i.TextStyle({fontSize:20}),n={};for(const t in e)0===t.indexOf("_")&&(n[t.substring(1)]=e[t]);delete n.styleKey,this.style=n,t&&(this.text=t.text,Object.assign(this.style,t.style))}}a.componentName="Text",o([e.type("string")],a.prototype,"text",void 0);class l extends t.Component{constructor(){super(...arguments),this.text="",this.style={},this.textureStyle={}}init(t){this.style=Object.assign({fontSize:24,fill:"#000000",fontFamily:"Arial"},null==t?void 0:t.style),this.textureStyle=Object.assign({scaleMode:"linear",resolution:window.devicePixelRatio||1},null==t?void 0:t.textureStyle),t&&(this.text=t.text)}}l.componentName="HTMLText",o([e.type("string")],l.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,s="BitmapText"===e.componentName;if(i||n||s)if(e.type===t.OBSERVER_TYPE.ADD)i?yield this.addTextComponent(e):n?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:i}=this.texts[e.gameObject.id];yield this.waitForFontResource(i,e,t.style.fontFamily)}this.setSize(e)}}))}addTextComponent(t){return r(this,void 0,void 0,(function*(){const e=t.component,i=Object.assign({},e.style),n=i.fontFamily;delete i.fontFamily;const o=n?"":e.text,r=new s.Text(o,i);this.containerManager.getContainer(t.gameObject.id).addChildAt(r,0),this.texts[t.gameObject.id]={text:r,component:e},n&&(yield this.waitForFontResource(r,t,n))}))}addHTMLTextComponent(t){return r(this,void 0,void 0,(function*(){const e=t.component,i=Object.assign({},e.style),n=i.fontFamily;delete i.fontFamily;const o=n?"":e.text,r=new s.HTMLText(Object.assign({text:o,style:i},e.textureStyle&&{textureStyle:e.textureStyle}));this.containerManager.getContainer(t.gameObject.id).addChildAt(r,0),this.texts[t.gameObject.id]={text:r,component:e},n&&(yield this.waitForFontResource(r,t,n))}))}addBitmapTextComponent(t){return r(this,void 0,void 0,(function*(){const e=t.component,i=Object.assign({},e.style),n=i.fontFamily;delete i.fontFamily;const o=n?"":e.text,r=new s.BitmapText(o,i);this.containerManager.getContainer(t.gameObject.id).addChildAt(r,0),this.texts[t.gameObject.id]={text:r,component:e},n&&(yield this.waitForFontResource(r,t,n))}))}waitForFontResource(e,i,n){return r(this,void 0,void 0,(function*(){if(n)try{const s=Array.isArray(n)?n[0]:n,o=this.increaseAsyncId(i.gameObject.id);if(yield t.resource.getResource(s),!this.validateAsyncId(i.gameObject.id,o))return;const r=this.texts[i.gameObject.id].component;e.style.fontFamily=n,e.text=r.text}catch(t){console.warn(`字体资源 ${n} 加载失败:`,t)}}))}processStrokeStyle(t){const e=Object.assign({},t);if(e.strokeThickness){const t=e.stroke;e.stroke={color:t,width:e.strokeThickness},delete e.strokeThickness}return e}change(t){const{text:e,component:i}=this.texts[t.gameObject.id],n="HTMLText"===t.componentName;if("text"===t.prop.prop[0])e.text=i.text;else if("style"===t.prop.prop[0]){const t=this.processStrokeStyle(i.style);Object.assign(e.style,t)}else if("textureStyle"===t.prop.prop[0]&&n){const n=i,o=this.containerManager.getContainer(t.gameObject.id),r=o.getChildIndex(e);o.removeChild(e),e.destroy({children:!0});const c=new s.HTMLText({text:n.text,style:n.style,textureStyle:n.textureStyle});o.addChildAt(c,r),this.texts[t.gameObject.id].text=c}}setSize(t){const{transform:e}=t.gameObject;if(!e)return;const{text:i}=this.texts[t.gameObject.id],n=i.getSize();e.size.width=n.width,e.size.height=n.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}],BitmapText:["text",{prop:["style"],deep:!0}]})],d);var x=d;exports.BitmapText=c,exports.HTMLText=l,exports.Text=a,exports.TextSystem=x;
|
|
@@ -296,6 +296,10 @@ export declare class TextSystem extends Renderer {
|
|
|
296
296
|
* 等待字体资源加载完成并更新文本
|
|
297
297
|
*/
|
|
298
298
|
private waitForFontResource;
|
|
299
|
+
/**
|
|
300
|
+
* 将 Eva.js 的 stroke/strokeThickness 格式转换为 PixiJS v8 格式
|
|
301
|
+
*/
|
|
302
|
+
private processStrokeStyle;
|
|
299
303
|
change(changed: ComponentChanged): void;
|
|
300
304
|
setSize(changed: ComponentChanged): void;
|
|
301
305
|
}
|
|
@@ -382,6 +382,21 @@ let Text = class Text extends Renderer {
|
|
|
382
382
|
}
|
|
383
383
|
});
|
|
384
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* 将 Eva.js 的 stroke/strokeThickness 格式转换为 PixiJS v8 格式
|
|
387
|
+
*/
|
|
388
|
+
processStrokeStyle(style) {
|
|
389
|
+
const processed = Object.assign({}, style);
|
|
390
|
+
if (processed.strokeThickness) {
|
|
391
|
+
const color = processed.stroke;
|
|
392
|
+
processed.stroke = {
|
|
393
|
+
color,
|
|
394
|
+
width: processed.strokeThickness,
|
|
395
|
+
};
|
|
396
|
+
delete processed.strokeThickness;
|
|
397
|
+
}
|
|
398
|
+
return processed;
|
|
399
|
+
}
|
|
385
400
|
change(changed) {
|
|
386
401
|
const { text, component } = this.texts[changed.gameObject.id];
|
|
387
402
|
const isHTMLText = changed.componentName === 'HTMLText';
|
|
@@ -389,7 +404,8 @@ let Text = class Text extends Renderer {
|
|
|
389
404
|
text.text = component.text;
|
|
390
405
|
}
|
|
391
406
|
else if (changed.prop.prop[0] === 'style') {
|
|
392
|
-
|
|
407
|
+
const processedStyle = this.processStrokeStyle(component.style);
|
|
408
|
+
Object.assign(text.style, processedStyle);
|
|
393
409
|
}
|
|
394
410
|
else if (changed.prop.prop[0] === 'textureStyle' && isHTMLText) {
|
|
395
411
|
// HTMLText 纹理样式变化需要重新创建
|
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.36",
|
|
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.36",
|
|
23
|
+
"@eva/renderer-adapter": "2.0.1-beta.36",
|
|
24
|
+
"@eva/eva.js": "2.0.1-beta.36",
|
|
25
25
|
"pixi.js": "^8.17.0"
|
|
26
26
|
}
|
|
27
27
|
}
|