@galacean/effects-plugin-rich-text 2.8.6 → 2.8.8
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/alipay.js +1 -1
- package/dist/alipay.js.map +1 -1
- package/dist/alipay.mjs +1 -1
- package/dist/alipay.mjs.map +1 -1
- package/dist/douyin.js +1 -1
- package/dist/douyin.js.map +1 -1
- package/dist/douyin.mjs +1 -1
- package/dist/douyin.mjs.map +1 -1
- package/dist/index.js +21 -24
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +21 -24
- package/dist/index.mjs.map +1 -1
- package/dist/rich-text-component.d.ts +1 -2
- package/dist/rich-text-layout.d.ts +1 -0
- package/dist/strategies/rich-text-interfaces.d.ts +1 -1
- package/dist/strategies/wrap/rich-wrap-disabled.d.ts +1 -1
- package/dist/strategies/wrap/rich-wrap-enabled.d.ts +1 -1
- package/dist/weapp.js +1 -1
- package/dist/weapp.js.map +1 -1
- package/dist/weapp.mjs +1 -1
- package/dist/weapp.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Description: Galacean Effects player rich text plugin
|
|
4
4
|
* Author: Ant Group CO., Ltd.
|
|
5
5
|
* Contributors: 云垣
|
|
6
|
-
* Version: v2.8.
|
|
6
|
+
* Version: v2.8.8
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import * as EFFECTS from '@galacean/effects';
|
|
@@ -400,6 +400,7 @@ typeof SuppressedError === "function" ? SuppressedError : function _SuppressedEr
|
|
|
400
400
|
|
|
401
401
|
var RichTextLayout = /*#__PURE__*/ function() {
|
|
402
402
|
function RichTextLayout(options) {
|
|
403
|
+
// TODO: width 和 height 新版富文本计算没有地方用到
|
|
403
404
|
this.width = 0;
|
|
404
405
|
this.height = 0;
|
|
405
406
|
var size = options.size, _options_textOverflow = options.textOverflow, textOverflow = _options_textOverflow === void 0 ? spec.TextOverflow.clip : _options_textOverflow, _options_textVerticalAlign = options.textVerticalAlign, textVerticalAlign = _options_textVerticalAlign === void 0 ? spec.TextVerticalAlign.middle : _options_textVerticalAlign, _options_textAlign = options.textAlign, textAlign = _options_textAlign === void 0 ? spec.TextAlignment.left : _options_textAlign, _options_letterSpace = options.letterSpace, letterSpace = _options_letterSpace === void 0 ? 0 : _options_letterSpace, _options_lineHeight = options.lineHeight, lineHeight = _options_lineHeight === void 0 ? 0.571 : _options_lineHeight, _options_wrapEnabled = options.wrapEnabled, wrapEnabled = _options_wrapEnabled === void 0 ? false : _options_wrapEnabled, _options_maxTextWidth = options.maxTextWidth, maxTextWidth = _options_maxTextWidth === void 0 ? 350 : _options_maxTextWidth, _options_maxTextHeight = options.maxTextHeight, maxTextHeight = _options_maxTextHeight === void 0 ? 1000 : _options_maxTextHeight, _options_sizeMode = options.sizeMode, sizeMode = _options_sizeMode === void 0 ? spec.TextSizeMode.autoWidth : _options_sizeMode, _options_useLegacyRichText = options.// @ts-expect-error 兼容旧版
|
|
@@ -413,10 +414,8 @@ var RichTextLayout = /*#__PURE__*/ function() {
|
|
|
413
414
|
this.width = size ? size[0] : 100;
|
|
414
415
|
this.height = size ? size[1] : 100;
|
|
415
416
|
this.wrapEnabled = wrapEnabled;
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
this.maxTextWidth = maxTextWidth * scaleFactor;
|
|
419
|
-
this.maxTextHeight = maxTextHeight * scaleFactor;
|
|
417
|
+
this.maxTextWidth = maxTextWidth;
|
|
418
|
+
this.maxTextHeight = maxTextHeight;
|
|
420
419
|
this.sizeMode = sizeMode;
|
|
421
420
|
}
|
|
422
421
|
var _proto = RichTextLayout.prototype;
|
|
@@ -510,6 +509,7 @@ var RichTextLayout = /*#__PURE__*/ function() {
|
|
|
510
509
|
/**
|
|
511
510
|
* 设置文本框尺寸
|
|
512
511
|
* - 不包含 fontScale 缩放
|
|
512
|
+
* @deprecated use maxTextWidth / maxTextHeight instead
|
|
513
513
|
*/ _proto.setSize = function setSize(width, height) {
|
|
514
514
|
this.width = width;
|
|
515
515
|
this.height = height;
|
|
@@ -596,11 +596,12 @@ var RichTextLayout = /*#__PURE__*/ function() {
|
|
|
596
596
|
*/ var RichWrapDisabledStrategy = /*#__PURE__*/ function() {
|
|
597
597
|
function RichWrapDisabledStrategy() {}
|
|
598
598
|
var _proto = RichWrapDisabledStrategy.prototype;
|
|
599
|
-
_proto.computeLines = function computeLines(processedOptions, context, style, layout, singleLineHeight, fontScale, letterSpace
|
|
599
|
+
_proto.computeLines = function computeLines(processedOptions, context, style, layout, singleLineHeight, fontScale, letterSpace) {
|
|
600
600
|
var _this = this;
|
|
601
601
|
var lines = [];
|
|
602
602
|
var baselines = [];
|
|
603
603
|
var gapPx = (layout.lineHeight || 0) * fontScale;
|
|
604
|
+
var scaleFactor = 1 / 10; // 1/10px, 后面 context.font 设置的字号为10px
|
|
604
605
|
var currentLine = this.createNewLine();
|
|
605
606
|
var maxLineWidth = 0;
|
|
606
607
|
var totalHeight = 0;
|
|
@@ -713,11 +714,12 @@ var RichTextLayout = /*#__PURE__*/ function() {
|
|
|
713
714
|
*/ var RichWrapEnabledStrategy = /*#__PURE__*/ function() {
|
|
714
715
|
function RichWrapEnabledStrategy() {}
|
|
715
716
|
var _proto = RichWrapEnabledStrategy.prototype;
|
|
716
|
-
_proto.computeLines = function computeLines(processedOptions, context, style, layout, singleLineHeight, fontScale, letterSpace
|
|
717
|
+
_proto.computeLines = function computeLines(processedOptions, context, style, layout, singleLineHeight, fontScale, letterSpace) {
|
|
717
718
|
var _this = this;
|
|
718
719
|
var lines = [];
|
|
719
720
|
var baselines = [];
|
|
720
721
|
var gapPx = (layout.lineHeight || 0) * fontScale;
|
|
722
|
+
var scaleFactor = 1 / 10; // 1/10px, 后面 context.font 设置的字号为10px
|
|
721
723
|
var currentLine = this.createNewLine();
|
|
722
724
|
var maxLineWidth = 0;
|
|
723
725
|
var totalHeight = 0;
|
|
@@ -790,7 +792,7 @@ var RichTextLayout = /*#__PURE__*/ function() {
|
|
|
790
792
|
var spacing = chunkChars.length > 0 ? letterSpace : 0;
|
|
791
793
|
var willWidth = currentLine.width + spacing + charWidth;
|
|
792
794
|
// 自动换行判断
|
|
793
|
-
if (willWidth > (layout.maxTextWidth || Infinity)) {
|
|
795
|
+
if (willWidth > (layout.maxTextWidth * fontScale || Infinity)) {
|
|
794
796
|
flushChunk();
|
|
795
797
|
finishCurrentLine();
|
|
796
798
|
}
|
|
@@ -1176,7 +1178,7 @@ var RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
1176
1178
|
_this.size = null;
|
|
1177
1179
|
_this.initialized = false;
|
|
1178
1180
|
_this.canvasSize = null;
|
|
1179
|
-
_this.SCALE_FACTOR = 0.
|
|
1181
|
+
_this.SCALE_FACTOR = 0.11092565;
|
|
1180
1182
|
_this.ALPHA_FIX_VALUE = 1 / 255;
|
|
1181
1183
|
_this.name = "MRichText" + seed++;
|
|
1182
1184
|
_this.initTextBase(engine);
|
|
@@ -1207,7 +1209,7 @@ var RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
1207
1209
|
this.textLayout.textVerticalAlign = spec.TextVerticalAlign.middle;
|
|
1208
1210
|
}
|
|
1209
1211
|
this.updateStrategies();
|
|
1210
|
-
this.
|
|
1212
|
+
this.updateTexture();
|
|
1211
1213
|
// 设置默认颜色(math.Color)
|
|
1212
1214
|
this.material.setColor("_Color", new math.Color(1, 1, 1, 1));
|
|
1213
1215
|
};
|
|
@@ -1267,13 +1269,6 @@ var RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
1267
1269
|
this.updateStrategies();
|
|
1268
1270
|
this.isDirty = true;
|
|
1269
1271
|
};
|
|
1270
|
-
_proto.renderText = function renderText(options) {
|
|
1271
|
-
var size = options.size;
|
|
1272
|
-
if (size) {
|
|
1273
|
-
this.canvasSize = new math.Vector2(size[0], size[1]);
|
|
1274
|
-
}
|
|
1275
|
-
this.updateTexture();
|
|
1276
|
-
};
|
|
1277
1272
|
/**
|
|
1278
1273
|
* 更新文本
|
|
1279
1274
|
* @returns
|
|
@@ -1299,6 +1294,7 @@ var RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
1299
1294
|
if (!this.isDirty || !this.context || !this.canvas || !this.textStyle) {
|
|
1300
1295
|
return;
|
|
1301
1296
|
}
|
|
1297
|
+
var legacyScaleFactor = 0.1;
|
|
1302
1298
|
this.generateTextProgram(this.text);
|
|
1303
1299
|
var width = 0, height = 0;
|
|
1304
1300
|
var layout = this.textLayout;
|
|
@@ -1345,7 +1341,7 @@ var RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
1345
1341
|
charInfo.offsetY = fontSize * textStyle.fontScale * (_this.singleLineHeight - 1) / 2;
|
|
1346
1342
|
}
|
|
1347
1343
|
charInfo.offsetX.push(charInfo.width);
|
|
1348
|
-
charInfo.width += (textWidth <= 0 ? 0 : textWidth) * fontSize *
|
|
1344
|
+
charInfo.width += (textWidth <= 0 ? 0 : textWidth) * fontSize * legacyScaleFactor * textStyle.fontScale + text.length * letterSpace;
|
|
1349
1345
|
charInfo.richOptions.push(options);
|
|
1350
1346
|
});
|
|
1351
1347
|
charsInfo.push(charInfo);
|
|
@@ -1363,7 +1359,7 @@ var RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
1363
1359
|
if (!this.initialized) {
|
|
1364
1360
|
this.canvasSize = !this.canvasSize ? new math.Vector2(width, height) : this.canvasSize;
|
|
1365
1361
|
var _this_canvasSize = this.canvasSize, canvasWidth = _this_canvasSize.x, canvasHeight = _this_canvasSize.y;
|
|
1366
|
-
this.item.transform.size.set(x * canvasWidth *
|
|
1362
|
+
this.item.transform.size.set(x * canvasWidth * legacyScaleFactor * legacyScaleFactor, y * canvasHeight * legacyScaleFactor * legacyScaleFactor);
|
|
1367
1363
|
this.size = this.item.transform.size.clone();
|
|
1368
1364
|
this.initialized = true;
|
|
1369
1365
|
}
|
|
@@ -1432,7 +1428,7 @@ var RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
1432
1428
|
return;
|
|
1433
1429
|
}
|
|
1434
1430
|
// 步骤1: 换行策略计算行信息
|
|
1435
|
-
var wrapResult = this.richWrapStrategy.computeLines(this.processedTextOptions, context, this.textStyle, layout, this.singleLineHeight, this.textStyle.fontScale, letterSpace
|
|
1431
|
+
var wrapResult = this.richWrapStrategy.computeLines(this.processedTextOptions, context, this.textStyle, layout, this.singleLineHeight, this.textStyle.fontScale, letterSpace);
|
|
1436
1432
|
if (wrapResult.lines.length === 0 || wrapResult.maxLineWidth === 0 || wrapResult.totalHeight === 0) {
|
|
1437
1433
|
this.isDirty = false;
|
|
1438
1434
|
return;
|
|
@@ -1573,7 +1569,8 @@ var RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
1573
1569
|
this.canvasSize = new math.Vector2(finalWpx, finalHpx);
|
|
1574
1570
|
var _this_size1;
|
|
1575
1571
|
var _ref = (_this_size1 = this.size) != null ? _this_size1 : this.item.transform.size, _ref_x = _ref.x, x1 = _ref_x === void 0 ? 1 : _ref_x, _ref_y = _ref.y, y1 = _ref_y === void 0 ? 1 : _ref_y;
|
|
1576
|
-
|
|
1572
|
+
// 实际元素渲染尺寸不随着 fontScale 改变
|
|
1573
|
+
this.item.transform.size.set(x1 * finalWpx / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR, y1 * finalHpx / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR);
|
|
1577
1574
|
this.initialized = true;
|
|
1578
1575
|
break;
|
|
1579
1576
|
}
|
|
@@ -1594,7 +1591,7 @@ var RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
1594
1591
|
layout.height = frameH;
|
|
1595
1592
|
var _this_size2;
|
|
1596
1593
|
var _ref1 = (_this_size2 = this.size) != null ? _this_size2 : this.item.transform.size, _ref_x1 = _ref1.x, x2 = _ref_x1 === void 0 ? 1 : _ref_x1, _ref_y1 = _ref1.y, y2 = _ref_y1 === void 0 ? 1 : _ref_y1;
|
|
1597
|
-
this.item.transform.size.set(x2 * frameWpx1 * this.SCALE_FACTOR * this.SCALE_FACTOR, y2 * frameHpx1 * this.SCALE_FACTOR * this.SCALE_FACTOR);
|
|
1594
|
+
this.item.transform.size.set(x2 * frameWpx1 / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR, y2 * frameHpx1 / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR);
|
|
1598
1595
|
this.initialized = true;
|
|
1599
1596
|
break;
|
|
1600
1597
|
}
|
|
@@ -1604,7 +1601,7 @@ var RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
|
|
|
1604
1601
|
var frameWpx2 = frameW * fontScale;
|
|
1605
1602
|
var frameHpx2 = frameH * fontScale;
|
|
1606
1603
|
this.canvasSize = new math.Vector2(frameWpx2, frameHpx2);
|
|
1607
|
-
this.item.transform.size.set(x * frameWpx2 * this.SCALE_FACTOR * this.SCALE_FACTOR, y * frameHpx2 * this.SCALE_FACTOR * this.SCALE_FACTOR);
|
|
1604
|
+
this.item.transform.size.set(x * frameWpx2 / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR, y * frameHpx2 / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR);
|
|
1608
1605
|
this.initialized = true;
|
|
1609
1606
|
}
|
|
1610
1607
|
break;
|
|
@@ -1723,7 +1720,7 @@ applyMixins(RichTextComponent, [
|
|
|
1723
1720
|
|
|
1724
1721
|
/**
|
|
1725
1722
|
* 插件版本号
|
|
1726
|
-
*/ var version = "2.8.
|
|
1723
|
+
*/ var version = "2.8.8";
|
|
1727
1724
|
registerPlugin("rich-text", RichTextLoader);
|
|
1728
1725
|
logger.info("Plugin rich text version: " + version + ".");
|
|
1729
1726
|
if (version !== EFFECTS.version) {
|