@galacean/effects 1.6.0-beta.1 → 1.6.0

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.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime player for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v1.6.0-beta.1
6
+ * Version: v1.6.0
7
7
  */
8
8
 
9
9
  /******************************************************************************
@@ -20280,32 +20280,37 @@ var TextLayout = /** @class */ (function () {
20280
20280
  this.textAlign = textAlign;
20281
20281
  this.lineHeight = lineHeight;
20282
20282
  }
20283
- TextLayout.prototype.getOffsetY = function (style) {
20284
- var offsetY = 0;
20285
- var offset = (style.fontSize + style.outlineWidth) * style.fontScale;
20283
+ TextLayout.prototype.getOffsetY = function (style, lineCount, lineHeight) {
20284
+ var offsetResult = 0;
20285
+ var fontSize = style.fontSize, outlineWidth = style.outlineWidth, fontScale = style.fontScale;
20286
+ // 计算基础偏移量
20287
+ var baseOffset = (fontSize + outlineWidth) * fontScale;
20288
+ // /3 计算Y轴偏移量,以匹配编辑器行为
20289
+ var offsetY = (lineHeight - fontSize) / 3;
20290
+ var commonCalculation = lineHeight * (lineCount - 1);
20286
20291
  switch (this.textBaseline) {
20287
- case 0:
20288
- offsetY = offset;
20292
+ case TextBaseline$1.top:
20293
+ offsetResult = baseOffset + offsetY;
20289
20294
  break;
20290
- case 1:
20291
- offsetY = (this.height + offset) / 2; // fonSize;
20295
+ case TextBaseline$1.middle:
20296
+ offsetResult = (this.height * fontScale - commonCalculation + baseOffset) / 2;
20292
20297
  break;
20293
- case 2:
20294
- offsetY = this.height - offset / 2;
20298
+ case TextBaseline$1.bottom:
20299
+ offsetResult = (this.height * fontScale - commonCalculation) - offsetY;
20295
20300
  break;
20296
20301
  }
20297
- return offsetY;
20302
+ return offsetResult;
20298
20303
  };
20299
20304
  TextLayout.prototype.getOffsetX = function (style, maxWidth) {
20300
20305
  var offsetX = 0;
20301
20306
  switch (this.textAlign) {
20302
- case 0:
20307
+ case TextAlignment$1.left:
20303
20308
  offsetX = style.outlineWidth * style.fontScale;
20304
20309
  break;
20305
- case 1:
20310
+ case TextAlignment$1.middle:
20306
20311
  offsetX = (this.width * style.fontScale - maxWidth) / 2;
20307
20312
  break;
20308
- case 2:
20313
+ case TextAlignment$1.right:
20309
20314
  offsetX = (this.width * style.fontScale - maxWidth);
20310
20315
  break;
20311
20316
  }
@@ -20328,6 +20333,10 @@ var TextItem = /** @class */ (function (_super) {
20328
20333
  function TextItem(props, opts, vfxItem) {
20329
20334
  var _this = _super.call(this, props, opts, vfxItem) || this;
20330
20335
  _this.isDirty = true;
20336
+ /**
20337
+ * 文本行数
20338
+ */
20339
+ _this.lineCount = 0;
20331
20340
  var options = props.options;
20332
20341
  _this.canvas = canvasPool.getCanvas();
20333
20342
  canvasPool.saveCanvas(_this.canvas);
@@ -20336,10 +20345,34 @@ var TextItem = /** @class */ (function (_super) {
20336
20345
  _this.textStyle = new TextStyle(options);
20337
20346
  _this.textLayout = new TextLayout(options);
20338
20347
  _this.text = options.text;
20348
+ _this.lineCount = _this.getLineCount(options.text, true);
20339
20349
  // Text
20340
20350
  _this.mesh = new TextMesh(_this.engine, _this.renderInfo, vfxItem.composition);
20341
20351
  return _this;
20342
20352
  }
20353
+ TextItem.prototype.getLineCount = function (text, init) {
20354
+ var _a, _b;
20355
+ var context = this.context;
20356
+ var letterSpace = this.textLayout.letterSpace;
20357
+ var fontScale = init ? this.textStyle.fontSize / 10 : 1 / this.textStyle.fontScale;
20358
+ var width = (this.textLayout.width + this.textStyle.fontOffset);
20359
+ var lineCount = 1;
20360
+ var x = 0;
20361
+ for (var i = 0; i < text.length; i++) {
20362
+ var str = text[i];
20363
+ var textMetrics = ((_b = (_a = context === null || context === void 0 ? void 0 : context.measureText(str)) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 0) * fontScale;
20364
+ // 和浏览器行为保持一致
20365
+ x += letterSpace;
20366
+ if (((x + textMetrics) > width && i > 0) || str === '\n') {
20367
+ lineCount++;
20368
+ x = 0;
20369
+ }
20370
+ if (str !== '\n') {
20371
+ x += textMetrics;
20372
+ }
20373
+ }
20374
+ return lineCount;
20375
+ };
20343
20376
  /**
20344
20377
  * 设置字号大小
20345
20378
  * @param value - 字号
@@ -20389,6 +20422,7 @@ var TextItem = /** @class */ (function (_super) {
20389
20422
  return;
20390
20423
  }
20391
20424
  this.text = value;
20425
+ this.lineCount = this.getLineCount(value, false);
20392
20426
  this.isDirty = true;
20393
20427
  };
20394
20428
  /**
@@ -20539,7 +20573,7 @@ var TextItem = /** @class */ (function (_super) {
20539
20573
  var fontScale = style.fontScale;
20540
20574
  var width = (layout.width + style.fontOffset) * fontScale;
20541
20575
  var height = layout.height * fontScale;
20542
- var fontSize = style.fontSize * fontScale;
20576
+ style.fontSize * fontScale;
20543
20577
  var lineHeight = layout.lineHeight * fontScale;
20544
20578
  this.char = (this.text || '').split('');
20545
20579
  this.canvas.width = width;
@@ -20559,10 +20593,8 @@ var TextItem = /** @class */ (function (_super) {
20559
20593
  // 文本颜色
20560
20594
  context.fillStyle = "rgba(".concat(style.textColor[0], ", ").concat(style.textColor[1], ", ").concat(style.textColor[2], ", ").concat(style.textColor[3], ")");
20561
20595
  var charsInfo = [];
20562
- // /3 为了和编辑器行为保持一致
20563
- var offsetY = (lineHeight - fontSize) / 3;
20564
20596
  var x = 0;
20565
- var y = layout.getOffsetY(style) + offsetY;
20597
+ var y = layout.getOffsetY(style, this.lineCount, lineHeight);
20566
20598
  var charsArray = [];
20567
20599
  var charOffsetX = [];
20568
20600
  for (var i = 0; i < this.char.length; i++) {
@@ -30994,7 +31026,7 @@ Renderer.create = function (canvas, framework, renderOptions) {
30994
31026
  Engine.create = function (gl) {
30995
31027
  return new GLEngine(gl);
30996
31028
  };
30997
- var version = "1.6.0-beta.1";
31029
+ var version = "1.6.0";
30998
31030
  logger.info('player version: ' + version);
30999
31031
 
31000
31032
  export { AbstractPlugin, AssetManager, BYTES_TYPE_MAP, BezierCurve, BezierCurvePath, COMPRESSED_TEXTURE, COPY_FRAGMENT_SHADER, COPY_MESH_SHADER_ID, COPY_VERTEX_SHADER, CalculateItem, CalculateLoader, CalculateVFXItem, Camera, CameraController, CameraVFXItem, CameraVFXItemLoader, Composition, CompositionSourceManager, DEFAULT_FONTS, DestroyOptions, Downloader, EFFECTS_COPY_MESH_NAME, EVENT_TYPE_CLICK, EVENT_TYPE_TOUCH_END, EVENT_TYPE_TOUCH_MOVE, EVENT_TYPE_TOUCH_START, Engine, EventSystem, FILTER_NAME_NONE, FilterMode, FilterSpriteVFXItem, Float16ArrayWrapper, FrameBuffer, GLEngine, GLGeometry, GLRenderer, GLSLVersion, GPUCapability, Geometry, GlobalUniforms, GradientValue, HELP_LINK$1 as HELP_LINK, HitTestType, InteractBehavior$1 as InteractBehavior, InteractItem, InteractLoader, InteractMesh, InteractVFXItem, Item, KTXTexture, LineSegments, LinearValue, Material, MaterialDataBlock, MaterialRenderType, Mesh, OrderType, PLAYER_OPTIONS_ENV_EDITOR, POST_PROCESS_SETTINGS, ParticleLoader, ParticleMesh, ParticleSystem, ParticleVFXItem, PassTextureCache, Player, PluginSystem, QCanvasViewer, QText, QTextWrapMode, RENDER_PASS_NAME_PREFIX, RENDER_PREFER_LOOKUP_TEXTURE, RUNTIME_ENV, RandomSetValue, RandomValue, RandomVectorValue, RenderBuffer, RenderFrame, RenderPass, RenderPassAttachmentStorageType, RenderPassDestroyAttachmentType, RenderPassPriorityNormal, RenderPassPriorityPostprocess, RenderPassPriorityPrepare, RenderTargetHandle, RenderTextureFormat, Renderer, SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_0, SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_SIZE_0, SEMANTIC_PRE_COLOR_ATTACHMENT_0, SEMANTIC_PRE_COLOR_ATTACHMENT_SIZE_0, SPRITE_VERTEX_STRIDE, SemanticMap, Shader, ShaderCompileResultStatus, ShaderType, SpriteItem, SpriteLoader, SpriteMesh, SpriteVFXItem, StaticValue, TEMPLATE_USE_OFFSCREEN_CANVAS, TextItem, TextLoader, TextMesh, TextVFXItem, Texture, TextureFactory, TextureLoadAction, TextureSourceType, TextureStoreAction, Ticker, TimelineComponent, Transform, VFXItem, ValueGetter, addByOrder, addItem, addItemWithOrder, alphaFrameFrag, alphaMaskFrag, assertExist, asserts, blend, bloomMixVert, bloomThresholdVert, calculateTranslation, cameraMove_frag as cameraMoveFrag, cameraMoveVert, canvasPool, colorGradingFrag, colorStopsFromGradient, colorToArr$1 as colorToArr, combineImageTemplate, combineImageTemplate1, combineImageTemplate1Async, combineImageTemplate2, combineImageTemplate2Async, combineImageTemplateAsync, compatible_frag as compatibleFrag, compatible_vert as compatibleVert, convertAnchor, copyFrag, createCopyShader, createFilter, createFilterShaders, createGLContext, createKeyFrameMeta, createShaderWithMarcos, createShape, createVFXItem, createValueGetter, decimalEqual, deepClone, defaultGlobalVolume, defaultPlugins, delayFrag, deserializeMipmapTexture, disableAllPlayer, distortionFrag, distortionVert, earcut, enlargeBuffer, ensureVec3, filters, findPreviousRenderPass, gaussianDown_frag as gaussianDownFrag, gaussianDownHFrag, gaussianDownVFrag, gaussianUpFrag, generateEmptyTypedArray, generateHalfFloatTexture, getActivePlayers, getBackgroundImage, getColorFromGradientStops, getConfig, getDefaultTemplateCanvasPool, getDefaultTextureFactory, getGeometryByShape, getGeometryTriangles, getImageItemRenderInfo, getKTXTextureOptions, getKeyFrameMetaByRawValue, getParticleMeshShader, getPixelRatio, getPlayerByCanvas, getPreMultiAlpha, getStandardComposition, getStandardImage, getStandardItem, getStandardJSON, getTextureSize, glContext, gpuTimer, imageDataFromColor, imageDataFromGradient, initErrors, initGLContext, integrate, interpolateColor, isAlipayMiniApp, isAndroid, isArray, isCanvasUsedByPlayer, isFunction, isIOS, isObject, isScene, isSceneWithOptions, isSimulatorCellPhone, isString, isUniformStruct, isUniformStructArray, isValidFontFamily, isWebGL2, itemFrag, itemFrameFrag, itemVert, loadBinary, loadBlob, loadImage, loadMedia, loadVideo, loadWebPOptional, logger, index as math, maxSpriteMeshItemCount, maxSpriteTextureCount, modifyMaxKeyframeShader, nearestPowerOfTwo, noop, numberToFix, parsePercent$1 as parsePercent, particleFrag, particleOriginTranslateMap, particleUniformTypeMap, particleVert, pluginLoaderMap, pointOnLine, random, registerFilter, registerFilters, registerPlugin, removeItem, requestAsync, rotateVec2, screenMeshVert, setBlendMode, setConfig, setDefaultTextureFactory, setMaskMode, setMaxSpriteMeshItemCount, setRayFromCamera, setSideMode, setSpriteMeshMaxFragmentTextures, setSpriteMeshMaxItemCountByGPU, sortByOrder, index$1 as spec, spriteMeshShaderFromFilter, spriteMeshShaderFromRenderInfo, spriteMeshShaderIdFromRenderInfo, thresholdFrag, throwDestroyedError$1 as throwDestroyedError, trailVert, translatePoint, trianglesFromRect, unregisterPlugin, valIfUndefined, value, valueDefine, vecAssign, vecFill, vecMulCombine, vecNormalize, version };