@galacean/effects-core 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 runtime core for the web
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';
@@ -2444,11 +2444,8 @@ function parsePercent$1(c) {
2444
2444
  }
2445
2445
 
2446
2446
  function getPixelRatio() {
2447
- if (typeof screen === "object" && typeof document === "object") {
2448
- var viewportWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
2449
- var screenWidth = screen.width;
2450
- var viewportScale = screenWidth / viewportWidth;
2451
- return Math.min(2 * viewportScale, 2);
2447
+ if (typeof window === "object") {
2448
+ return Math.min(2, window.devicePixelRatio || 1);
2452
2449
  }
2453
2450
  return 1;
2454
2451
  }
@@ -17194,22 +17191,6 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
17194
17191
  this.transform.scaleBy(x, y, z);
17195
17192
  };
17196
17193
  /**
17197
- * 设置元素在画布上的像素位置
17198
- * Tips:
17199
- * - 坐标原点在 canvas 左上角,x 正方向水平向右, y 正方向垂直向下
17200
- * - 设置后会覆盖原有的位置信息
17201
- * @param x - x 坐标
17202
- * @param y - y 坐标
17203
- */ _proto.setPositionByPixel = function setPositionByPixel(x, y) {
17204
- if (this.composition) {
17205
- var z = this.transform.getWorldPosition().z;
17206
- var _this_composition_camera_getInverseVPRatio = this.composition.camera.getInverseVPRatio(z), rx = _this_composition_camera_getInverseVPRatio.x, ry = _this_composition_camera_getInverseVPRatio.y;
17207
- var width = this.composition.renderer.getWidth() / 2;
17208
- var height = this.composition.renderer.getHeight() / 2;
17209
- this.transform.setPosition((2 * x / width - 1) * rx, (1 - 2 * y / height) * ry, z);
17210
- }
17211
- };
17212
- /**
17213
17194
  * 设置本地坐标位置
17214
17195
  */ _proto.setPosition = function setPosition(x, y, z) {
17215
17196
  this.transform.setPosition(x, y, z);
@@ -17233,6 +17214,29 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
17233
17214
  this.transform.setWorldPosition(x, y, z);
17234
17215
  };
17235
17216
  /**
17217
+ * 设置元素在画布上的像素位置
17218
+ * Tips:
17219
+ * - 坐标原点在 canvas 左上角,x 正方向水平向右, y 正方向垂直向下
17220
+ * - 设置后会覆盖原有的位置信息
17221
+ * @param x - x 坐标
17222
+ * @param y - y 坐标
17223
+ */ _proto.setPositionByPixel = function setPositionByPixel(x, y) {
17224
+ if (this.composition) {
17225
+ var z = this.transform.getWorldPosition().z;
17226
+ var _this_composition_camera_getInverseVPRatio = this.composition.camera.getInverseVPRatio(z), rx = _this_composition_camera_getInverseVPRatio.x, ry = _this_composition_camera_getInverseVPRatio.y;
17227
+ var _this_composition_getEngine_canvas_getBoundingClientRect = this.composition.getEngine().canvas.getBoundingClientRect(), width = _this_composition_getEngine_canvas_getBoundingClientRect.width, height = _this_composition_getEngine_canvas_getBoundingClientRect.height;
17228
+ this.transform.setPosition((2 * x / width - 1) * rx, (1 - 2 * y / height) * ry, z);
17229
+ }
17230
+ };
17231
+ _proto.translateByPixel = function translateByPixel(x, y) {
17232
+ if (this.composition) {
17233
+ var _this_composition_getEngine_canvas_getBoundingClientRect = this.composition.getEngine().canvas.getBoundingClientRect(), width = _this_composition_getEngine_canvas_getBoundingClientRect.width, height = _this_composition_getEngine_canvas_getBoundingClientRect.height;
17234
+ var z = this.transform.getWorldPosition().z;
17235
+ var _this_composition_camera_getInverseVPRatio = this.composition.camera.getInverseVPRatio(z), rx = _this_composition_camera_getInverseVPRatio.x, ry = _this_composition_camera_getInverseVPRatio.y;
17236
+ this.transform.translate(2 * x * rx / width, -2 * y * ry / height, 0);
17237
+ }
17238
+ };
17239
+ /**
17236
17240
  * 获取元素包围盒
17237
17241
  * @override
17238
17242
  */ _proto.getBoundingBox = function getBoundingBox() {
@@ -17420,14 +17424,6 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
17420
17424
  }
17421
17425
  this.defination.content = {};
17422
17426
  };
17423
- _proto.translateByPixel = function translateByPixel(x, y) {
17424
- if (this.composition) {
17425
- var _this_composition_getEngine_canvas_getBoundingClientRect = this.composition.getEngine().canvas.getBoundingClientRect(), width = _this_composition_getEngine_canvas_getBoundingClientRect.width, height = _this_composition_getEngine_canvas_getBoundingClientRect.height;
17426
- var z = this.transform.getWorldPosition().z;
17427
- var _this_composition_camera_getInverseVPRatio = this.composition.camera.getInverseVPRatio(z), rx = _this_composition_camera_getInverseVPRatio.x, ry = _this_composition_camera_getInverseVPRatio.y;
17428
- this.transform.translate(2 * x * rx / width, -2 * y * ry / height, 0);
17429
- }
17430
- };
17431
17427
  /**
17432
17428
  * 销毁元素
17433
17429
  */ _proto.dispose = function dispose() {
@@ -28868,7 +28864,6 @@ var TextComponentBase = /*#__PURE__*/ function() {
28868
28864
  this.lineCount = 0;
28869
28865
  this.maxLineWidth = 0;
28870
28866
  // 常量
28871
- this.SCALE_FACTOR = 0.1;
28872
28867
  this.ALPHA_FIX_VALUE = 1 / 255;
28873
28868
  }
28874
28869
  var _proto = TextComponentBase.prototype;
@@ -28990,8 +28985,8 @@ var TextComponentBase = /*#__PURE__*/ function() {
28990
28985
  };
28991
28986
  _proto.setupShadow = function setupShadow() {
28992
28987
  var context = this.context;
28993
- var _this_textStyle = this.textStyle, outlineColor = _this_textStyle.outlineColor, shadowBlur = _this_textStyle.shadowBlur, shadowOffsetX = _this_textStyle.shadowOffsetX, shadowOffsetY = _this_textStyle.shadowOffsetY;
28994
- var r = outlineColor[0], g = outlineColor[1], b = outlineColor[2], a = outlineColor[3];
28988
+ var _this_textStyle = this.textStyle, shadowColor = _this_textStyle.shadowColor, shadowBlur = _this_textStyle.shadowBlur, shadowOffsetX = _this_textStyle.shadowOffsetX, shadowOffsetY = _this_textStyle.shadowOffsetY;
28989
+ var r = shadowColor[0], g = shadowColor[1], b = shadowColor[2], a = shadowColor[3];
28995
28990
  if (context) {
28996
28991
  context.shadowColor = "rgba(" + r * 255 + ", " + g * 255 + ", " + b * 255 + ", " + a + ")";
28997
28992
  context.shadowBlur = shadowBlur;
@@ -29216,11 +29211,11 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29216
29211
  _proto.getLineCount = function getLineCount(text) {
29217
29212
  var context = this.context;
29218
29213
  var _this_textLayout = this.textLayout, letterSpace = _this_textLayout.letterSpace, overflow = _this_textLayout.overflow;
29219
- // const fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
29220
29214
  this.maxLineWidth = 0;
29221
29215
  var width = this.textLayout.width + this.textStyle.fontOffset;
29222
29216
  var lineCount = 1;
29223
29217
  var x = 0;
29218
+ var charCountInLine = 0; // 跟踪当前行的字符数
29224
29219
  // 设置 context.font 的字号,确保 measureText 能正确计算字宽
29225
29220
  if (context) {
29226
29221
  context.font = this.getFontDesc(this.textStyle.fontSize);
@@ -29231,14 +29226,19 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29231
29226
  var _context_measureText_width;
29232
29227
  var textMetrics = (_context_measureText_width = context == null ? void 0 : (_context_measureText = context.measureText(str)) == null ? void 0 : _context_measureText.width) != null ? _context_measureText_width : 0;
29233
29228
  // 和浏览器行为保持一致
29234
- x += letterSpace;
29229
+ // 字符间距只应用在字符之间,每行第一个字符不加间距
29230
+ if (charCountInLine > 0) {
29231
+ x += letterSpace;
29232
+ }
29235
29233
  // 处理文本结束行为
29236
29234
  if (overflow === TextOverflow.display) {
29237
29235
  if (str === "\n") {
29238
29236
  lineCount++;
29239
29237
  x = 0;
29238
+ charCountInLine = 0; // 重置行字符计数
29240
29239
  } else {
29241
29240
  x += textMetrics;
29241
+ charCountInLine++;
29242
29242
  this.maxLineWidth = Math.max(this.maxLineWidth, x);
29243
29243
  }
29244
29244
  } else {
@@ -29246,9 +29246,11 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29246
29246
  lineCount++;
29247
29247
  this.maxLineWidth = Math.max(this.maxLineWidth, x);
29248
29248
  x = 0;
29249
+ charCountInLine = 0; // 重置行字符计数
29249
29250
  }
29250
29251
  if (str !== "\n") {
29251
29252
  x += textMetrics;
29253
+ charCountInLine++;
29252
29254
  }
29253
29255
  }
29254
29256
  }
@@ -29395,7 +29397,10 @@ exports.TextComponent = /*#__PURE__*/ function(MaskableGraphic) {
29395
29397
  var str = char[i];
29396
29398
  var textMetrics = context.measureText(str);
29397
29399
  // 和浏览器行为保持一致
29398
- x += layout.letterSpace * fontScale;
29400
+ // 字符间距只应用在字符之间,每行第一个字符不加间距
29401
+ if (charsArray.length > 0) {
29402
+ x += layout.letterSpace * fontScale;
29403
+ }
29399
29404
  if (x + textMetrics.width > baseWidth && i > 0 || str === "\n") {
29400
29405
  charsInfo.push({
29401
29406
  y: y,
@@ -31625,7 +31630,7 @@ function getStandardSpriteContent(sprite, transform) {
31625
31630
  return ret;
31626
31631
  }
31627
31632
 
31628
- var version$1 = "2.8.6";
31633
+ var version$1 = "2.8.8";
31629
31634
  var v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
31630
31635
  var standardVersion = /^(\d+)\.(\d+)$/;
31631
31636
  var reverseParticle = false;
@@ -35325,7 +35330,7 @@ registerPlugin("text", TextLoader);
35325
35330
  registerPlugin("sprite", SpriteLoader);
35326
35331
  registerPlugin("particle", ParticleLoader);
35327
35332
  registerPlugin("interact", InteractLoader);
35328
- var version = "2.8.6";
35333
+ var version = "2.8.8";
35329
35334
  logger.info("Core version: " + version + ".");
35330
35335
 
35331
35336
  exports.ActivationMixerPlayable = ActivationMixerPlayable;