@galacean/effects-core 2.8.2 → 2.8.4
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/components/base-render-component.d.ts +1 -0
- package/dist/index.js +110 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +110 -32
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/text/text-item.d.ts +20 -0
- package/dist/plugins/text/text-layout.d.ts +6 -0
- package/package.json +1 -1
|
@@ -85,6 +85,7 @@ export declare class MaskableGraphic extends RendererComponent implements Maskab
|
|
|
85
85
|
* @since 2.3.0
|
|
86
86
|
*/
|
|
87
87
|
setTexture(input: string): Promise<void>;
|
|
88
|
+
onUpdate(dt: number): void;
|
|
88
89
|
render(renderer: Renderer): void;
|
|
89
90
|
onStart(): void;
|
|
90
91
|
getHitTestParams: (force?: boolean) => HitTestTriangleParams | undefined;
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Description: Galacean Effects runtime core for the web
|
|
4
4
|
* Author: Ant Group CO., Ltd.
|
|
5
5
|
* Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
|
|
6
|
-
* Version: v2.8.
|
|
6
|
+
* Version: v2.8.4
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -2665,6 +2665,11 @@ function asserts(condition, msg) {
|
|
|
2665
2665
|
* @returns
|
|
2666
2666
|
*/ function isValidFontFamily(fontFamily) {
|
|
2667
2667
|
// iOS 11/12 不支持自定义字体开头为数字的名称,特殊字符也有风险
|
|
2668
|
+
return isSafeFontFamily(fontFamily) || !isSimulatorCellPhone();
|
|
2669
|
+
}
|
|
2670
|
+
/**
|
|
2671
|
+
* @internal
|
|
2672
|
+
*/ function isSafeFontFamily(fontFamily) {
|
|
2668
2673
|
return /^[^\d.][\w-]*$/.test(fontFamily);
|
|
2669
2674
|
}
|
|
2670
2675
|
|
|
@@ -18370,6 +18375,15 @@ exports.PostProcessVolume = __decorate([
|
|
|
18370
18375
|
});
|
|
18371
18376
|
})();
|
|
18372
18377
|
};
|
|
18378
|
+
_proto.onUpdate = function onUpdate(dt) {
|
|
18379
|
+
for(var i = 0; i < this.materials.length; i++){
|
|
18380
|
+
var material = this.materials[i];
|
|
18381
|
+
material.setVector2("_Size", this.transform.size);
|
|
18382
|
+
if (this.renderer.renderMode === RenderMode.BILLBOARD || this.renderer.renderMode === RenderMode.VERTICAL_BILLBOARD || this.renderer.renderMode === RenderMode.HORIZONTAL_BILLBOARD) {
|
|
18383
|
+
material.setVector3("_Scale", this.transform.scale);
|
|
18384
|
+
}
|
|
18385
|
+
}
|
|
18386
|
+
};
|
|
18373
18387
|
_proto.render = function render(renderer) {
|
|
18374
18388
|
if (!this.getVisible()) {
|
|
18375
18389
|
return;
|
|
@@ -18431,12 +18445,7 @@ exports.PostProcessVolume = __decorate([
|
|
|
18431
18445
|
};
|
|
18432
18446
|
_proto.draw = function draw(renderer) {
|
|
18433
18447
|
for(var i = 0; i < this.materials.length; i++){
|
|
18434
|
-
|
|
18435
|
-
material.setVector2("_Size", this.transform.size);
|
|
18436
|
-
if (this.renderer.renderMode === RenderMode.BILLBOARD || this.renderer.renderMode === RenderMode.VERTICAL_BILLBOARD || this.renderer.renderMode === RenderMode.HORIZONTAL_BILLBOARD) {
|
|
18437
|
-
material.setVector3("_Scale", this.transform.scale);
|
|
18438
|
-
}
|
|
18439
|
-
renderer.drawGeometry(this.geometry, this.transform.getWorldMatrix(), material, i);
|
|
18448
|
+
renderer.drawGeometry(this.geometry, this.transform.getWorldMatrix(), this.materials[i], i);
|
|
18440
18449
|
}
|
|
18441
18450
|
};
|
|
18442
18451
|
_proto.fromData = function fromData(data) {
|
|
@@ -25694,6 +25703,7 @@ exports.SpriteComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
25694
25703
|
var _proto = SpriteComponent.prototype;
|
|
25695
25704
|
_proto.onUpdate = function onUpdate(dt) {
|
|
25696
25705
|
var _this = this;
|
|
25706
|
+
MaskableGraphic.prototype.onUpdate.call(this, dt);
|
|
25697
25707
|
var time = this.time;
|
|
25698
25708
|
var duration = this.duration;
|
|
25699
25709
|
var textureAnimation = this.textureSheetAnimation;
|
|
@@ -28687,11 +28697,11 @@ var TextLayout = /*#__PURE__*/ function() {
|
|
|
28687
28697
|
* @param totalLineHeight - 可选的实际总行高,用于替代默认计算
|
|
28688
28698
|
* @returns - 行高偏移值
|
|
28689
28699
|
*/ _proto.getOffsetY = function getOffsetY(style, lineCount, lineHeight, fontSize, totalLineHeight) {
|
|
28690
|
-
var
|
|
28700
|
+
var fontScale = style.fontScale;
|
|
28691
28701
|
// /3 计算Y轴偏移量,以匹配编辑器行为
|
|
28692
28702
|
var offsetY = (lineHeight - fontSize) / 3;
|
|
28693
28703
|
// 计算基础偏移量
|
|
28694
|
-
var baseOffset = fontSize
|
|
28704
|
+
var baseOffset = fontSize;
|
|
28695
28705
|
var commonCalculation = totalLineHeight !== undefined ? totalLineHeight : lineHeight * (lineCount - 1);
|
|
28696
28706
|
var offsetResult = 0;
|
|
28697
28707
|
switch(this.textVerticalAlign){
|
|
@@ -28707,11 +28717,16 @@ var TextLayout = /*#__PURE__*/ function() {
|
|
|
28707
28717
|
}
|
|
28708
28718
|
return offsetResult;
|
|
28709
28719
|
};
|
|
28710
|
-
|
|
28720
|
+
/**
|
|
28721
|
+
* 获取初始的水平偏移值
|
|
28722
|
+
* @param style - 字体基础数据
|
|
28723
|
+
* @param maxWidth - 最大行宽
|
|
28724
|
+
* @returns - 水平偏移值
|
|
28725
|
+
*/ _proto.getOffsetX = function getOffsetX(style, maxWidth) {
|
|
28711
28726
|
var offsetX = 0;
|
|
28712
28727
|
switch(this.textAlign){
|
|
28713
28728
|
case TextAlignment.left:
|
|
28714
|
-
offsetX =
|
|
28729
|
+
offsetX = 0;
|
|
28715
28730
|
break;
|
|
28716
28731
|
case TextAlignment.middle:
|
|
28717
28732
|
offsetX = (this.width * style.fontScale - maxWidth) / 2;
|
|
@@ -28787,7 +28802,8 @@ var TextStyle = /*#__PURE__*/ function() {
|
|
|
28787
28802
|
1
|
|
28788
28803
|
];
|
|
28789
28804
|
this.outlineWidth = 0;
|
|
28790
|
-
|
|
28805
|
+
var _outline_outlineWidth;
|
|
28806
|
+
if (outline && ((_outline_outlineWidth = outline.outlineWidth) != null ? _outline_outlineWidth : 0) > 0) {
|
|
28791
28807
|
this.isOutlined = true;
|
|
28792
28808
|
var _outline_outlineColor;
|
|
28793
28809
|
this.outlineColor = [].concat((_outline_outlineColor = outline.outlineColor) != null ? _outline_outlineColor : [
|
|
@@ -28796,8 +28812,8 @@ var TextStyle = /*#__PURE__*/ function() {
|
|
|
28796
28812
|
1,
|
|
28797
28813
|
1
|
|
28798
28814
|
]);
|
|
28799
|
-
var
|
|
28800
|
-
this.outlineWidth = (
|
|
28815
|
+
var _outline_outlineWidth1;
|
|
28816
|
+
this.outlineWidth = (_outline_outlineWidth1 = outline.outlineWidth) != null ? _outline_outlineWidth1 : 0;
|
|
28801
28817
|
}
|
|
28802
28818
|
// 重置阴影状态
|
|
28803
28819
|
this.hasShadow = false;
|
|
@@ -29058,6 +29074,10 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
29058
29074
|
* 文本行数
|
|
29059
29075
|
*/ _this.lineCount = 0;
|
|
29060
29076
|
/**
|
|
29077
|
+
* 描边/阴影等特效导致的纹理扩容比例 X/Y
|
|
29078
|
+
*/ _this.effectScaleX = 1;
|
|
29079
|
+
_this.effectScaleY = 1;
|
|
29080
|
+
/**
|
|
29061
29081
|
* 每一行文本的最大宽度
|
|
29062
29082
|
*/ _this.maxLineWidth = 0;
|
|
29063
29083
|
/**
|
|
@@ -29119,6 +29139,16 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
29119
29139
|
_proto.onUpdate = function onUpdate(dt) {
|
|
29120
29140
|
MaskableGraphic.prototype.onUpdate.call(this, dt);
|
|
29121
29141
|
this.updateTexture();
|
|
29142
|
+
// 覆盖基类每帧更新 size 行为,应用扩容比例
|
|
29143
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(this.materials), _step; !(_step = _iterator()).done;){
|
|
29144
|
+
var material = _step.value;
|
|
29145
|
+
var sizeX = this.transform.size.x;
|
|
29146
|
+
var sizeY = this.transform.size.y;
|
|
29147
|
+
var _this_getTextureExpandScale = this.getTextureExpandScale(), scalex = _this_getTextureExpandScale[0], scaley = _this_getTextureExpandScale[1];
|
|
29148
|
+
sizeX *= scalex;
|
|
29149
|
+
sizeY *= scaley;
|
|
29150
|
+
material.setVector2("_Size", new Vector2(sizeX, sizeY));
|
|
29151
|
+
}
|
|
29122
29152
|
};
|
|
29123
29153
|
_proto.onDestroy = function onDestroy() {
|
|
29124
29154
|
MaskableGraphic.prototype.onDestroy.call(this);
|
|
@@ -29308,23 +29338,32 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
29308
29338
|
var style = this.textStyle;
|
|
29309
29339
|
var layout = this.textLayout;
|
|
29310
29340
|
var fontScale = style.fontScale;
|
|
29311
|
-
var
|
|
29341
|
+
var baseWidth = (layout.width + style.fontOffset) * fontScale;
|
|
29312
29342
|
var finalHeight = layout.lineHeight * this.lineCount;
|
|
29313
29343
|
var fontSize = style.fontSize * fontScale;
|
|
29314
29344
|
var lineHeight = layout.lineHeight * fontScale;
|
|
29315
29345
|
style.fontDesc = this.getFontDesc(fontSize);
|
|
29316
29346
|
var char = (this.text || "").split("");
|
|
29347
|
+
var baseHeight = 0;
|
|
29317
29348
|
if (layout.autoWidth) {
|
|
29318
|
-
|
|
29349
|
+
baseHeight = finalHeight * fontScale;
|
|
29319
29350
|
this.item.transform.size.set(1, finalHeight / layout.height);
|
|
29320
29351
|
} else {
|
|
29321
|
-
|
|
29322
|
-
}
|
|
29323
|
-
var
|
|
29324
|
-
|
|
29352
|
+
baseHeight = layout.height * fontScale;
|
|
29353
|
+
}
|
|
29354
|
+
var _this_getEffectPadding = this.getEffectPadding(), padL = _this_getEffectPadding.padL, padR = _this_getEffectPadding.padR, padT = _this_getEffectPadding.padT, padB = _this_getEffectPadding.padB;
|
|
29355
|
+
var hasEffect = (padL | padR | padT | padB) !== 0;
|
|
29356
|
+
var texWidth = hasEffect ? Math.ceil(baseWidth + padL + padR) : baseWidth;
|
|
29357
|
+
var texHeight = hasEffect ? Math.ceil(baseHeight + padT + padB) : baseHeight;
|
|
29358
|
+
var shiftX = hasEffect ? padL : 0;
|
|
29359
|
+
var shiftY = hasEffect ? flipY ? padT : padB : 0;
|
|
29360
|
+
// 给渲染层用:扩容比例
|
|
29361
|
+
this.effectScaleX = baseWidth > 0 ? texWidth / baseWidth : 1;
|
|
29362
|
+
this.effectScaleY = baseHeight > 0 ? texHeight / baseHeight : 1;
|
|
29363
|
+
this.renderToTexture(texWidth, texHeight, flipY, function(context) {
|
|
29325
29364
|
// canvas size 变化后重新刷新 context
|
|
29326
|
-
if (_this.maxLineWidth >
|
|
29327
|
-
context.font = _this.getFontDesc(fontSize *
|
|
29365
|
+
if (_this.maxLineWidth > baseWidth && layout.overflow === TextOverflow.display) {
|
|
29366
|
+
context.font = _this.getFontDesc(fontSize * baseWidth / _this.maxLineWidth);
|
|
29328
29367
|
} else {
|
|
29329
29368
|
context.font = style.fontDesc;
|
|
29330
29369
|
}
|
|
@@ -29347,7 +29386,7 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
29347
29386
|
var textMetrics = context.measureText(str);
|
|
29348
29387
|
// 和浏览器行为保持一致
|
|
29349
29388
|
x += layout.letterSpace * fontScale;
|
|
29350
|
-
if (x + textMetrics.width >
|
|
29389
|
+
if (x + textMetrics.width > baseWidth && i > 0 || str === "\n") {
|
|
29351
29390
|
charsInfo.push({
|
|
29352
29391
|
y: y,
|
|
29353
29392
|
width: x,
|
|
@@ -29371,14 +29410,27 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
29371
29410
|
chars: charsArray,
|
|
29372
29411
|
charOffsetX: charOffsetX
|
|
29373
29412
|
});
|
|
29374
|
-
|
|
29375
|
-
|
|
29376
|
-
|
|
29377
|
-
|
|
29378
|
-
|
|
29413
|
+
// 先描边
|
|
29414
|
+
if (style.isOutlined && style.outlineWidth > 0) {
|
|
29415
|
+
charsInfo.forEach(function(charInfo) {
|
|
29416
|
+
var ox = layout.getOffsetX(style, charInfo.width);
|
|
29417
|
+
for(var i = 0; i < charInfo.chars.length; i++){
|
|
29418
|
+
var str = charInfo.chars[i];
|
|
29419
|
+
var drawX = shiftX + ox + charInfo.charOffsetX[i];
|
|
29420
|
+
var drawY = shiftY + charInfo.y;
|
|
29421
|
+
context.strokeText(str, drawX, drawY);
|
|
29379
29422
|
}
|
|
29380
|
-
context.fillText(str, x + charInfo.charOffsetX[i], charInfo.y);
|
|
29381
29423
|
});
|
|
29424
|
+
}
|
|
29425
|
+
// 再填充
|
|
29426
|
+
charsInfo.forEach(function(charInfo) {
|
|
29427
|
+
var ox = layout.getOffsetX(style, charInfo.width);
|
|
29428
|
+
for(var i = 0; i < charInfo.chars.length; i++){
|
|
29429
|
+
var str = charInfo.chars[i];
|
|
29430
|
+
var drawX = shiftX + ox + charInfo.charOffsetX[i];
|
|
29431
|
+
var drawY = shiftY + charInfo.y;
|
|
29432
|
+
context.fillText(str, drawX, drawY);
|
|
29433
|
+
}
|
|
29382
29434
|
});
|
|
29383
29435
|
if (style.hasShadow) {
|
|
29384
29436
|
context.shadowColor = "transparent";
|
|
@@ -29389,6 +29441,32 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
29389
29441
|
_proto.renderText = function renderText(options) {
|
|
29390
29442
|
this.updateTexture();
|
|
29391
29443
|
};
|
|
29444
|
+
/**
|
|
29445
|
+
* 给渲染层用:获取特效扩容比例(描边/阴影导致的纹理扩容)
|
|
29446
|
+
* @returns
|
|
29447
|
+
*/ _proto.getTextureExpandScale = function getTextureExpandScale() {
|
|
29448
|
+
return [
|
|
29449
|
+
this.effectScaleX,
|
|
29450
|
+
this.effectScaleY
|
|
29451
|
+
];
|
|
29452
|
+
};
|
|
29453
|
+
/**
|
|
29454
|
+
* 获取描边和阴影的 padding 值(单位:px)
|
|
29455
|
+
* @returns
|
|
29456
|
+
*/ _proto.getEffectPadding = function getEffectPadding() {
|
|
29457
|
+
var style = this.textStyle;
|
|
29458
|
+
var hasDrawOutline = style.isOutlined && style.outlineWidth > 0;
|
|
29459
|
+
var outlinePad = hasDrawOutline ? Math.ceil(style.outlineWidth * 2 * style.fontScale) : 0;
|
|
29460
|
+
var hasShadow = style.hasShadow && (style.shadowBlur > 0 || style.shadowOffsetX !== 0 || style.shadowOffsetY !== 0);
|
|
29461
|
+
var shadowPad = hasShadow ? Math.ceil((Math.abs(style.shadowOffsetX) + Math.abs(style.shadowOffsetY) + style.shadowBlur) * style.fontScale) : 0;
|
|
29462
|
+
var pad = outlinePad + shadowPad;
|
|
29463
|
+
return {
|
|
29464
|
+
padL: pad,
|
|
29465
|
+
padR: pad,
|
|
29466
|
+
padT: pad,
|
|
29467
|
+
padB: pad
|
|
29468
|
+
};
|
|
29469
|
+
};
|
|
29392
29470
|
_proto.setAutoWidth = function setAutoWidth(value) {
|
|
29393
29471
|
var layout = this.textLayout;
|
|
29394
29472
|
var normalizedValue = !!value;
|
|
@@ -31537,7 +31615,7 @@ function getStandardSpriteContent(sprite, transform) {
|
|
|
31537
31615
|
return ret;
|
|
31538
31616
|
}
|
|
31539
31617
|
|
|
31540
|
-
var version$1 = "2.8.
|
|
31618
|
+
var version$1 = "2.8.4";
|
|
31541
31619
|
var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
|
|
31542
31620
|
var standardVersion = /^(\d+)\.(\d+)$/;
|
|
31543
31621
|
var reverseParticle = false;
|
|
@@ -35237,7 +35315,7 @@ registerPlugin("text", TextLoader);
|
|
|
35237
35315
|
registerPlugin("sprite", SpriteLoader);
|
|
35238
35316
|
registerPlugin("particle", ParticleLoader);
|
|
35239
35317
|
registerPlugin("interact", InteractLoader);
|
|
35240
|
-
var version = "2.8.
|
|
35318
|
+
var version = "2.8.4";
|
|
35241
35319
|
logger.info("Core version: " + version + ".");
|
|
35242
35320
|
|
|
35243
35321
|
exports.ActivationMixerPlayable = ActivationMixerPlayable;
|
|
@@ -35482,6 +35560,7 @@ exports.isObject = isObject;
|
|
|
35482
35560
|
exports.isOpenHarmony = isOpenHarmony;
|
|
35483
35561
|
exports.isPlainObject = isPlainObject;
|
|
35484
35562
|
exports.isPowerOfTwo = isPowerOfTwo;
|
|
35563
|
+
exports.isSafeFontFamily = isSafeFontFamily;
|
|
35485
35564
|
exports.isSimulatorCellPhone = isSimulatorCellPhone;
|
|
35486
35565
|
exports.isString = isString;
|
|
35487
35566
|
exports.isUniformStruct = isUniformStruct;
|