@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/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.6
6
+ * Version: v2.8.8
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;
@@ -533,6 +532,7 @@ var RichTextLayout = /*#__PURE__*/ function() {
533
532
  /**
534
533
  * 设置文本框尺寸
535
534
  * - 不包含 fontScale 缩放
535
+ * @deprecated use maxTextWidth / maxTextHeight instead
536
536
  */ _proto.setSize = function setSize(width, height) {
537
537
  this.width = width;
538
538
  this.height = height;
@@ -619,11 +619,12 @@ var RichTextLayout = /*#__PURE__*/ function() {
619
619
  */ var RichWrapDisabledStrategy = /*#__PURE__*/ function() {
620
620
  function RichWrapDisabledStrategy() {}
621
621
  var _proto = RichWrapDisabledStrategy.prototype;
622
- _proto.computeLines = function computeLines(processedOptions, context, style, layout, singleLineHeight, fontScale, letterSpace, scaleFactor) {
622
+ _proto.computeLines = function computeLines(processedOptions, context, style, layout, singleLineHeight, fontScale, letterSpace) {
623
623
  var _this = this;
624
624
  var lines = [];
625
625
  var baselines = [];
626
626
  var gapPx = (layout.lineHeight || 0) * fontScale;
627
+ var scaleFactor = 1 / 10; // 1/10px, 后面 context.font 设置的字号为10px
627
628
  var currentLine = this.createNewLine();
628
629
  var maxLineWidth = 0;
629
630
  var totalHeight = 0;
@@ -736,11 +737,12 @@ var RichTextLayout = /*#__PURE__*/ function() {
736
737
  */ var RichWrapEnabledStrategy = /*#__PURE__*/ function() {
737
738
  function RichWrapEnabledStrategy() {}
738
739
  var _proto = RichWrapEnabledStrategy.prototype;
739
- _proto.computeLines = function computeLines(processedOptions, context, style, layout, singleLineHeight, fontScale, letterSpace, scaleFactor) {
740
+ _proto.computeLines = function computeLines(processedOptions, context, style, layout, singleLineHeight, fontScale, letterSpace) {
740
741
  var _this = this;
741
742
  var lines = [];
742
743
  var baselines = [];
743
744
  var gapPx = (layout.lineHeight || 0) * fontScale;
745
+ var scaleFactor = 1 / 10; // 1/10px, 后面 context.font 设置的字号为10px
744
746
  var currentLine = this.createNewLine();
745
747
  var maxLineWidth = 0;
746
748
  var totalHeight = 0;
@@ -813,7 +815,7 @@ var RichTextLayout = /*#__PURE__*/ function() {
813
815
  var spacing = chunkChars.length > 0 ? letterSpace : 0;
814
816
  var willWidth = currentLine.width + spacing + charWidth;
815
817
  // 自动换行判断
816
- if (willWidth > (layout.maxTextWidth || Infinity)) {
818
+ if (willWidth > (layout.maxTextWidth * fontScale || Infinity)) {
817
819
  flushChunk();
818
820
  finishCurrentLine();
819
821
  }
@@ -1199,7 +1201,7 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1199
1201
  _this.size = null;
1200
1202
  _this.initialized = false;
1201
1203
  _this.canvasSize = null;
1202
- _this.SCALE_FACTOR = 0.1;
1204
+ _this.SCALE_FACTOR = 0.11092565;
1203
1205
  _this.ALPHA_FIX_VALUE = 1 / 255;
1204
1206
  _this.name = "MRichText" + seed++;
1205
1207
  _this.initTextBase(engine);
@@ -1230,7 +1232,7 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1230
1232
  this.textLayout.textVerticalAlign = EFFECTS.spec.TextVerticalAlign.middle;
1231
1233
  }
1232
1234
  this.updateStrategies();
1233
- this.renderText(options);
1235
+ this.updateTexture();
1234
1236
  // 设置默认颜色(math.Color)
1235
1237
  this.material.setColor("_Color", new EFFECTS.math.Color(1, 1, 1, 1));
1236
1238
  };
@@ -1290,13 +1292,6 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1290
1292
  this.updateStrategies();
1291
1293
  this.isDirty = true;
1292
1294
  };
1293
- _proto.renderText = function renderText(options) {
1294
- var size = options.size;
1295
- if (size) {
1296
- this.canvasSize = new EFFECTS.math.Vector2(size[0], size[1]);
1297
- }
1298
- this.updateTexture();
1299
- };
1300
1295
  /**
1301
1296
  * 更新文本
1302
1297
  * @returns
@@ -1322,6 +1317,7 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1322
1317
  if (!this.isDirty || !this.context || !this.canvas || !this.textStyle) {
1323
1318
  return;
1324
1319
  }
1320
+ var legacyScaleFactor = 0.1;
1325
1321
  this.generateTextProgram(this.text);
1326
1322
  var width = 0, height = 0;
1327
1323
  var layout = this.textLayout;
@@ -1368,7 +1364,7 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1368
1364
  charInfo.offsetY = fontSize * textStyle.fontScale * (_this.singleLineHeight - 1) / 2;
1369
1365
  }
1370
1366
  charInfo.offsetX.push(charInfo.width);
1371
- charInfo.width += (textWidth <= 0 ? 0 : textWidth) * fontSize * _this.SCALE_FACTOR * textStyle.fontScale + text.length * letterSpace;
1367
+ charInfo.width += (textWidth <= 0 ? 0 : textWidth) * fontSize * legacyScaleFactor * textStyle.fontScale + text.length * letterSpace;
1372
1368
  charInfo.richOptions.push(options);
1373
1369
  });
1374
1370
  charsInfo.push(charInfo);
@@ -1386,7 +1382,7 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1386
1382
  if (!this.initialized) {
1387
1383
  this.canvasSize = !this.canvasSize ? new EFFECTS.math.Vector2(width, height) : this.canvasSize;
1388
1384
  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);
1385
+ this.item.transform.size.set(x * canvasWidth * legacyScaleFactor * legacyScaleFactor, y * canvasHeight * legacyScaleFactor * legacyScaleFactor);
1390
1386
  this.size = this.item.transform.size.clone();
1391
1387
  this.initialized = true;
1392
1388
  }
@@ -1455,7 +1451,7 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1455
1451
  return;
1456
1452
  }
1457
1453
  // 步骤1: 换行策略计算行信息
1458
- var wrapResult = this.richWrapStrategy.computeLines(this.processedTextOptions, context, this.textStyle, layout, this.singleLineHeight, this.textStyle.fontScale, letterSpace, this.SCALE_FACTOR);
1454
+ var wrapResult = this.richWrapStrategy.computeLines(this.processedTextOptions, context, this.textStyle, layout, this.singleLineHeight, this.textStyle.fontScale, letterSpace);
1459
1455
  if (wrapResult.lines.length === 0 || wrapResult.maxLineWidth === 0 || wrapResult.totalHeight === 0) {
1460
1456
  this.isDirty = false;
1461
1457
  return;
@@ -1596,7 +1592,8 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1596
1592
  this.canvasSize = new EFFECTS.math.Vector2(finalWpx, finalHpx);
1597
1593
  var _this_size1;
1598
1594
  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);
1595
+ // 实际元素渲染尺寸不随着 fontScale 改变
1596
+ this.item.transform.size.set(x1 * finalWpx / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR, y1 * finalHpx / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR);
1600
1597
  this.initialized = true;
1601
1598
  break;
1602
1599
  }
@@ -1617,7 +1614,7 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1617
1614
  layout.height = frameH;
1618
1615
  var _this_size2;
1619
1616
  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);
1617
+ this.item.transform.size.set(x2 * frameWpx1 / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR, y2 * frameHpx1 / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR);
1621
1618
  this.initialized = true;
1622
1619
  break;
1623
1620
  }
@@ -1627,7 +1624,7 @@ exports.RichTextComponent = /*#__PURE__*/ function(MaskableGraphic) {
1627
1624
  var frameWpx2 = frameW * fontScale;
1628
1625
  var frameHpx2 = frameH * fontScale;
1629
1626
  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);
1627
+ this.item.transform.size.set(x * frameWpx2 / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR, y * frameHpx2 / fontScale * this.SCALE_FACTOR * this.SCALE_FACTOR);
1631
1628
  this.initialized = true;
1632
1629
  }
1633
1630
  break;
@@ -1746,7 +1743,7 @@ EFFECTS.applyMixins(exports.RichTextComponent, [
1746
1743
 
1747
1744
  /**
1748
1745
  * 插件版本号
1749
- */ var version = "2.8.6";
1746
+ */ var version = "2.8.8";
1750
1747
  EFFECTS.registerPlugin("rich-text", RichTextLoader);
1751
1748
  EFFECTS.logger.info("Plugin rich text version: " + version + ".");
1752
1749
  if (version !== EFFECTS__namespace.version) {