@galacean/effects-plugin-rich-text 2.8.5 → 2.8.7

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/index.js 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.5
6
+ * Version: v2.8.7
7
7
  */
8
8
 
9
9
  'use strict';
@@ -423,6 +423,7 @@ typeof SuppressedError === "function" ? SuppressedError : function _SuppressedEr
423
423
 
424
424
  var RichTextLayout = /*#__PURE__*/ function() {
425
425
  function RichTextLayout(options) {
426
+ // TODO: width 和 height 新版富文本计算没有地方用到
426
427
  this.width = 0;
427
428
  this.height = 0;
428
429
  var size = options.size, _options_textOverflow = options.textOverflow, textOverflow = _options_textOverflow === void 0 ? EFFECTS.spec.TextOverflow.clip : _options_textOverflow, _options_textVerticalAlign = options.textVerticalAlign, textVerticalAlign = _options_textVerticalAlign === void 0 ? EFFECTS.spec.TextVerticalAlign.middle : _options_textVerticalAlign, _options_textAlign = options.textAlign, textAlign = _options_textAlign === void 0 ? EFFECTS.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 ? EFFECTS.spec.TextSizeMode.autoWidth : _options_sizeMode, _options_useLegacyRichText = options.// @ts-expect-error 兼容旧版
@@ -436,10 +437,8 @@ var RichTextLayout = /*#__PURE__*/ function() {
436
437
  this.width = size ? size[0] : 100;
437
438
  this.height = size ? size[1] : 100;
438
439
  this.wrapEnabled = wrapEnabled;
439
- // TODO: 统一富文本和图层 size 单位,这边先临时做个转换
440
- var scaleFactor = 50;
441
- this.maxTextWidth = maxTextWidth * scaleFactor;
442
- this.maxTextHeight = maxTextHeight * scaleFactor;
440
+ this.maxTextWidth = maxTextWidth;
441
+ this.maxTextHeight = maxTextHeight;
443
442
  this.sizeMode = sizeMode;
444
443
  }
445
444
  var _proto = RichTextLayout.prototype;
@@ -813,7 +812,7 @@ var RichTextLayout = /*#__PURE__*/ function() {
813
812
  var spacing = chunkChars.length > 0 ? letterSpace : 0;
814
813
  var willWidth = currentLine.width + spacing + charWidth;
815
814
  // 自动换行判断
816
- if (willWidth > (layout.maxTextWidth || Infinity)) {
815
+ if (willWidth > (layout.maxTextWidth * fontScale || Infinity)) {
817
816
  flushChunk();
818
817
  finishCurrentLine();
819
818
  }
@@ -1199,7 +1198,7 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1199
1198
  _this.size = null;
1200
1199
  _this.initialized = false;
1201
1200
  _this.canvasSize = null;
1202
- _this.SCALE_FACTOR = 0.1;
1201
+ _this.SCALE_FACTOR = 0.11092565;
1203
1202
  _this.ALPHA_FIX_VALUE = 1 / 255;
1204
1203
  _this.name = "MRichText" + seed++;
1205
1204
  _this.initTextBase(engine);
@@ -1322,6 +1321,7 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1322
1321
  if (!this.isDirty || !this.context || !this.canvas || !this.textStyle) {
1323
1322
  return;
1324
1323
  }
1324
+ var legacyScaleFactor = 0.1;
1325
1325
  this.generateTextProgram(this.text);
1326
1326
  var width = 0, height = 0;
1327
1327
  var layout = this.textLayout;
@@ -1368,7 +1368,7 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1368
1368
  charInfo.offsetY = fontSize * textStyle.fontScale * (_this.singleLineHeight - 1) / 2;
1369
1369
  }
1370
1370
  charInfo.offsetX.push(charInfo.width);
1371
- charInfo.width += (textWidth <= 0 ? 0 : textWidth) * fontSize * _this.SCALE_FACTOR * textStyle.fontScale + text.length * letterSpace;
1371
+ charInfo.width += (textWidth <= 0 ? 0 : textWidth) * fontSize * legacyScaleFactor * textStyle.fontScale + text.length * letterSpace;
1372
1372
  charInfo.richOptions.push(options);
1373
1373
  });
1374
1374
  charsInfo.push(charInfo);
@@ -1386,7 +1386,7 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1386
1386
  if (!this.initialized) {
1387
1387
  this.canvasSize = !this.canvasSize ? new EFFECTS.math.Vector2(width, height) : this.canvasSize;
1388
1388
  var _this_canvasSize = this.canvasSize, canvasWidth = _this_canvasSize.x, canvasHeight = _this_canvasSize.y;
1389
- this.item.transform.size.set(x * canvasWidth * this.SCALE_FACTOR * this.SCALE_FACTOR, y * canvasHeight * this.SCALE_FACTOR * this.SCALE_FACTOR);
1389
+ this.item.transform.size.set(x * canvasWidth * legacyScaleFactor * legacyScaleFactor, y * canvasHeight * legacyScaleFactor * legacyScaleFactor);
1390
1390
  this.size = this.item.transform.size.clone();
1391
1391
  this.initialized = true;
1392
1392
  }
@@ -1596,7 +1596,8 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1596
1596
  this.canvasSize = new EFFECTS.math.Vector2(finalWpx, finalHpx);
1597
1597
  var _this_size1;
1598
1598
  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;
1599
- this.item.transform.size.set(x1 * finalWpx * this.SCALE_FACTOR * this.SCALE_FACTOR, y1 * finalHpx * this.SCALE_FACTOR * this.SCALE_FACTOR);
1599
+ // 实际元素渲染尺寸不随着 fontScale 改变
1600
+ this.item.transform.size.set(x1 * finalWpx / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR, y1 * finalHpx / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR);
1600
1601
  this.initialized = true;
1601
1602
  break;
1602
1603
  }
@@ -1617,7 +1618,7 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1617
1618
  layout.height = frameH;
1618
1619
  var _this_size2;
1619
1620
  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;
1620
- this.item.transform.size.set(x2 * frameWpx1 * this.SCALE_FACTOR * this.SCALE_FACTOR, y2 * frameHpx1 * this.SCALE_FACTOR * this.SCALE_FACTOR);
1621
+ this.item.transform.size.set(x2 * frameWpx1 / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR, y2 * frameHpx1 / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR);
1621
1622
  this.initialized = true;
1622
1623
  break;
1623
1624
  }
@@ -1627,7 +1628,7 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1627
1628
  var frameWpx2 = frameW * fontScale;
1628
1629
  var frameHpx2 = frameH * fontScale;
1629
1630
  this.canvasSize = new EFFECTS.math.Vector2(frameWpx2, frameHpx2);
1630
- this.item.transform.size.set(x * frameWpx2 * this.SCALE_FACTOR * this.SCALE_FACTOR, y * frameHpx2 * this.SCALE_FACTOR * this.SCALE_FACTOR);
1631
+ this.item.transform.size.set(x * frameWpx2 / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR, y * frameHpx2 / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR);
1631
1632
  this.initialized = true;
1632
1633
  }
1633
1634
  break;
@@ -1746,7 +1747,7 @@ EFFECTS.applyMixins(exports.RichTextComponent, [
1746
1747
 
1747
1748
  /**
1748
1749
  * 插件版本号
1749
- */ var version = "2.8.5";
1750
+ */ var version = "2.8.7";
1750
1751
  EFFECTS.registerPlugin("rich-text", RichTextLoader);
1751
1752
  EFFECTS.logger.info("Plugin rich text version: " + version + ".");
1752
1753
  if (version !== EFFECTS__namespace.version) {