@eva/plugin-renderer-lottie 2.0.1-beta.4 → 2.0.1-beta.40

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.
@@ -279,7 +279,7 @@ if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function
279
279
  * @param {*} len a
280
280
  * @return {*}
281
281
  */
282
- function createSizedArray$1(len) {
282
+ function createSizedArray$2(len) {
283
283
  return new Array(len);
284
284
  }
285
285
 
@@ -509,7 +509,7 @@ var BezierFactory = {
509
509
  * @return {*}
510
510
  */
511
511
  function _double(arr) {
512
- return arr.concat(createSizedArray$1(arr.length));
512
+ return arr.concat(createSizedArray$2(arr.length));
513
513
  }
514
514
  var pooling = {
515
515
  double: _double,
@@ -518,7 +518,7 @@ var pooling = {
518
518
  var PoolFactory = function PoolFactory(initialLength, _create, _release) {
519
519
  var _length = 0;
520
520
  var _maxLength = initialLength;
521
- var pool = createSizedArray$1(_maxLength);
521
+ var pool = createSizedArray$2(_maxLength);
522
522
  var ob = {
523
523
  newElement: newElement,
524
524
  release: release,
@@ -798,7 +798,7 @@ function buildBezierData(pt1, pt2, pt3, pt4) {
798
798
  var bezierData = new BezierData(curveSegments);
799
799
  var len = pt3.length;
800
800
  for (var k = 0; k < curveSegments; k += 1) {
801
- point = createSizedArray$1(len);
801
+ point = createSizedArray$2(len);
802
802
  var perc = k / (curveSegments - 1);
803
803
  ptDistance = 0;
804
804
  for (var i = 0; i < len; i += 1) {
@@ -2186,9 +2186,9 @@ var ShapePath = /*#__PURE__*/ (function () {
2186
2186
  this.c = false;
2187
2187
  this._length = 0;
2188
2188
  this._maxLength = 8;
2189
- this.v = createSizedArray$1(this._maxLength);
2190
- this.o = createSizedArray$1(this._maxLength);
2191
- this.i = createSizedArray$1(this._maxLength);
2189
+ this.v = createSizedArray$2(this._maxLength);
2190
+ this.o = createSizedArray$2(this._maxLength);
2191
+ this.i = createSizedArray$2(this._maxLength);
2192
2192
  }
2193
2193
 
2194
2194
  /**
@@ -2232,9 +2232,9 @@ var ShapePath = /*#__PURE__*/ (function () {
2232
2232
  {
2233
2233
  key: 'doubleArrayLength',
2234
2234
  value: function doubleArrayLength() {
2235
- this.v = this.v.concat(createSizedArray$1(this._maxLength));
2236
- this.i = this.i.concat(createSizedArray$1(this._maxLength));
2237
- this.o = this.o.concat(createSizedArray$1(this._maxLength));
2235
+ this.v = this.v.concat(createSizedArray$2(this._maxLength));
2236
+ this.i = this.i.concat(createSizedArray$2(this._maxLength));
2237
+ this.o = this.o.concat(createSizedArray$2(this._maxLength));
2238
2238
  this._maxLength *= 2;
2239
2239
  },
2240
2240
 
@@ -2403,7 +2403,7 @@ var ShapeCollection = /*#__PURE__*/ (function () {
2403
2403
  _classCallCheck(this, ShapeCollection);
2404
2404
  this._length = 0;
2405
2405
  this._maxLength = 4;
2406
- this.shapes = createSizedArray$1(this._maxLength);
2406
+ this.shapes = createSizedArray$2(this._maxLength);
2407
2407
  }
2408
2408
 
2409
2409
  /**
@@ -2415,7 +2415,7 @@ var ShapeCollection = /*#__PURE__*/ (function () {
2415
2415
  key: 'addShape',
2416
2416
  value: function addShape(shapeData) {
2417
2417
  if (this._length === this._maxLength) {
2418
- this.shapes = this.shapes.concat(createSizedArray$1(this._maxLength));
2418
+ this.shapes = this.shapes.concat(createSizedArray$2(this._maxLength));
2419
2419
  this._maxLength *= 2;
2420
2420
  }
2421
2421
  this.shapes[this._length] = shapeData;
@@ -2440,7 +2440,7 @@ var ShapeCollection = /*#__PURE__*/ (function () {
2440
2440
 
2441
2441
  var _length = 0;
2442
2442
  var _maxLength = 4;
2443
- var pool = createSizedArray$1(_maxLength);
2443
+ var pool = createSizedArray$2(_maxLength);
2444
2444
 
2445
2445
  /**
2446
2446
  * a
@@ -3265,7 +3265,7 @@ var MaskFrames = /*#__PURE__*/ (function (_DynamicPropertyConta) {
3265
3265
  _this.propType = 'mask';
3266
3266
  _this.masksProperties = masksProperties || [];
3267
3267
  _this.initDynamicPropertyContainer(elem);
3268
- _this.viewData = createSizedArray$1(_this.masksProperties.length);
3268
+ _this.viewData = createSizedArray$2(_this.masksProperties.length);
3269
3269
  var len = _this.masksProperties.length;
3270
3270
  var hasMasks = false;
3271
3271
  for (var i = 0; i < len; i++) {
@@ -5696,7 +5696,7 @@ var DashProperty = /*#__PURE__*/ (function (_DynamicPropertyConta) {
5696
5696
  _this = _callSuper(this, DashProperty);
5697
5697
  _this.elem = elem;
5698
5698
  _this.frameId = -1;
5699
- _this.dataProps = createSizedArray$1(data.length);
5699
+ _this.dataProps = createSizedArray$2(data.length);
5700
5700
  // this.renderer = renderer;
5701
5701
  _this.k = false;
5702
5702
  // this.dashStr = '';
@@ -7421,7 +7421,7 @@ var TextAnimatorProperty = /*#__PURE__*/ (function (_DynamicPropertyConta) {
7421
7421
  _this._textData = textData;
7422
7422
  _this._renderType = renderType;
7423
7423
  _this.elem = elem;
7424
- _this._animatorsData = createSizedArray$1(_this._textData.a.length);
7424
+ _this._animatorsData = createSizedArray$2(_this._textData.a.length);
7425
7425
  _this._pathData = {};
7426
7426
  _this._moreOptions = {
7427
7427
  alignment: {},
@@ -10216,7 +10216,6 @@ const Tween = {
10216
10216
  };
10217
10217
 
10218
10218
  ({
10219
- UPDATE_PRIORITY: pixi_js.UPDATE_PRIORITY,
10220
10219
  animationTicker: pixi_js.Ticker.shared,
10221
10220
  });
10222
10221
 
@@ -10276,6 +10275,61 @@ class LottieGraphicsMask extends pixi_js.Graphics {
10276
10275
  }
10277
10276
  }
10278
10277
 
10278
+ const updateTransformByHierarchy = (container, transform, parent) => {
10279
+ // const localMatrixA = new Matrix();
10280
+
10281
+ if (transform.p) {
10282
+ container.x = transform.p.v[0];
10283
+ container.y = transform.p.v[1];
10284
+ } else {
10285
+ container.x = transform.px.v;
10286
+ container.y = transform.py.v;
10287
+ }
10288
+
10289
+ container.pivot.x = transform.a.v[0];
10290
+ container.pivot.y = transform.a.v[1];
10291
+
10292
+ container.scale.x = transform.s.v[0];
10293
+ container.scale.y = transform.s.v[1];
10294
+
10295
+ if (transform.r) {
10296
+ container.rotation = transform.r.v + transform.orientation;
10297
+ } else if (transform.rz) {
10298
+ container.rotation = transform.rz.v + transform.or.v[2];
10299
+ }
10300
+
10301
+ // let x = transform.p ? transform.p.v[0] : transform.px.v;
10302
+ // let y = transform.p ? transform.p.v[1] : transform.py.v;
10303
+
10304
+ // const rotation = transform.r
10305
+ // ? transform.r.v + transform.orientation
10306
+ // : transform.rz
10307
+ // ? transform.rz.v + transform.or.v[2]
10308
+ // : 0;
10309
+
10310
+ // localMatrixA.setTransform(
10311
+ // x,
10312
+ // y,
10313
+ // transform.a.v[0],
10314
+ // transform.a.v[1],
10315
+ // transform.s.v[0],
10316
+ // transform.s.v[1],
10317
+ // rotation,
10318
+ // 0,
10319
+ // 0
10320
+ // );
10321
+
10322
+ // if (parent) {
10323
+ // const parentWorldTransform = parent.worldTransform.clone();
10324
+ // container.setFromMatrix(localMatrixA.append(parentWorldTransform));
10325
+ // } else {
10326
+ // container.setFromMatrix(localMatrixA);
10327
+ // }
10328
+
10329
+ const parentAlpha = parent ? parent.alpha : 1;
10330
+ container.alpha = parentAlpha * transform.o.v;
10331
+ };
10332
+
10279
10333
  /**
10280
10334
  * NullElement class
10281
10335
  * @class
@@ -10324,27 +10378,7 @@ class CompElement extends pixi_js.Container {
10324
10378
  }
10325
10379
 
10326
10380
  updateLottieTransform(transform) {
10327
- if (transform.p) {
10328
- this.x = transform.p.v[0];
10329
- this.y = transform.p.v[1];
10330
- } else {
10331
- this.x = transform.px.v;
10332
- this.y = transform.py.v;
10333
- }
10334
-
10335
- this.pivot.x = transform.a.v[0];
10336
- this.pivot.y = transform.a.v[1];
10337
-
10338
- this.scale.x = transform.s.v[0];
10339
- this.scale.y = transform.s.v[1];
10340
-
10341
- if (transform.r) {
10342
- this.rotation = transform.r.v + transform.orientation;
10343
- } else if (transform.rz) {
10344
- this.rotation = transform.rz.v + transform.or.v[2];
10345
- }
10346
-
10347
- this.alpha = transform.o.v;
10381
+ updateTransformByHierarchy(this, transform, this.hierarchy);
10348
10382
  }
10349
10383
 
10350
10384
  /**
@@ -10519,27 +10553,7 @@ class ShapeElement extends pixi_js.Graphics {
10519
10553
  * @param {*} transform
10520
10554
  */
10521
10555
  updateLottieTransform(transform) {
10522
- if (transform.p) {
10523
- this.x = transform.p.v[0];
10524
- this.y = transform.p.v[1];
10525
- } else {
10526
- this.x = transform.px.v;
10527
- this.y = transform.py.v;
10528
- }
10529
-
10530
- this.pivot.x = transform.a.v[0];
10531
- this.pivot.y = transform.a.v[1];
10532
-
10533
- this.scale.x = transform.s.v[0];
10534
- this.scale.y = transform.s.v[1];
10535
-
10536
- if (transform.r) {
10537
- this.rotation = transform.r.v + transform.orientation;
10538
- } else if (transform.rz) {
10539
- this.rotation = transform.rz.v + transform.or.v[2];
10540
- }
10541
-
10542
- this.alpha = transform.o.v;
10556
+ updateTransformByHierarchy(this, transform, this.hierarchy);
10543
10557
  }
10544
10558
 
10545
10559
  /**
@@ -10565,6 +10579,154 @@ function createSizedArray(len) {
10565
10579
  return Array.apply(null, { length: len });
10566
10580
  }
10567
10581
 
10582
+ /**
10583
+ * NullElement class
10584
+ * @class
10585
+ * @private
10586
+ */
10587
+ class TextElement extends pixi_js.Text {
10588
+ /**
10589
+ * ShapeElement constructor
10590
+ */
10591
+ constructor(lottieLayer) {
10592
+ super();
10593
+ this.label = lottieLayer.fullname;
10594
+ this.lottieLayer = lottieLayer;
10595
+ this.lottieLayer.lettersChangedFlag = true;
10596
+ if (this.lottieLayer.masks) {
10597
+ this.mask = new LottieGraphicsMask(this.lottieLayer.session.local, this.lottieLayer);
10598
+ this.addChild(this.mask);
10599
+ }
10600
+
10601
+ this.init();
10602
+ this.buildNewText();
10603
+ this.updateLottie = this.updateLottie.bind(this);
10604
+ this.updateLottie(this.lottieLayer, true);
10605
+ this.lottieLayer.on('updatelayer', this.updateLottie);
10606
+ this.onRender = () => {
10607
+ this.updateLottie(this.lottieLayer, true);
10608
+ };
10609
+ }
10610
+
10611
+ init() {
10612
+ this._textSpans = [];
10613
+ this._yOffset = 0;
10614
+ this._fillColorAnim = false;
10615
+ this._strokeColorAnim = false;
10616
+ this._strokeWidthAnim = false;
10617
+ this._stroke = false;
10618
+ this._fill = false;
10619
+ this._justifyOffset = 0;
10620
+ this._currentRender = null;
10621
+ this._renderType = 'canvas';
10622
+ this._fillStyle = {};
10623
+ this._values = {
10624
+ fill: '#000000',
10625
+ stroke: '#000000',
10626
+ sWidth: 0,
10627
+ fValue: '',
10628
+ };
10629
+ }
10630
+
10631
+ buildNewText() {
10632
+ const documentData = this.lottieLayer.textProperty.currentData;
10633
+ this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
10634
+ let hasFill = false;
10635
+ if (documentData.fc) {
10636
+ hasFill = true;
10637
+ this._values.fill = Tools.rgb2hex(
10638
+ documentData.fc.map(item => {
10639
+ return item > 1 ? item : item * 255;
10640
+ }),
10641
+ documentData.fc,
10642
+ );
10643
+ } else {
10644
+ this._values.fill = '#000000';
10645
+ }
10646
+ this._fill = hasFill;
10647
+ let hasStroke = false;
10648
+ if (documentData.sc) {
10649
+ hasStroke = true;
10650
+ this._values.stroke = this.buildColor(documentData.sc);
10651
+ this._values.sWidth = documentData.sw;
10652
+ }
10653
+ const fontManager = this.lottieLayer.global.fontManager;
10654
+ this._stroke = hasStroke;
10655
+ this._values.fontSize = documentData.finalSize;
10656
+ this._values.fontFamily = fontManager.getFontByName(documentData.f).fFamily;
10657
+ this._values.fontWeight = documentData.fWeight;
10658
+ this._values.fontStyle = documentData.fStyle;
10659
+ this._values.lineHeight = documentData.finalLineHeight;
10660
+ this._text = documentData.t;
10661
+
10662
+ this.renderText();
10663
+ }
10664
+
10665
+ async renderText() {
10666
+ this.text = this._text;
10667
+ if (this.style.fontFamily) {
10668
+ await pixi_js.Assets.get(this.style.fontFamily);
10669
+ }
10670
+ this.style.fontFamily = this._values.fontFamily;
10671
+ this.style.fontSize = this._values.fontSize;
10672
+ this.style.fill = this._values.fill;
10673
+ this.style.fontWeight = this._values.fontWeight;
10674
+ this.style.fontStyle = this._values.fontStyle;
10675
+ this.style.lineHeight = this._values.lineHeight;
10676
+
10677
+ this.anchor.x = 0.5;
10678
+ this.anchor.y = 0.8;
10679
+ }
10680
+
10681
+ /**
10682
+ * update lottie information
10683
+ * @param {*} lottieLayer lottie element object
10684
+ * @param {boolean} forceUpdate forceUpdate
10685
+ */
10686
+ updateLottie(lottieLayer, _forceUpdate = false) {
10687
+ let forceUpdate = true;
10688
+ if (lottieLayer.transform && forceUpdate) {
10689
+ this.updateLottieTransform(lottieLayer.transform);
10690
+ }
10691
+ if (lottieLayer.masks && forceUpdate) {
10692
+ this.updateLottieMasks(lottieLayer.masks);
10693
+ }
10694
+ if (lottieLayer._mdf) {
10695
+ this.renderText();
10696
+ }
10697
+ this.visible = lottieLayer.isInRange;
10698
+ this._onUpdate();
10699
+ }
10700
+
10701
+ /**
10702
+ * a
10703
+ * @param {*} parent a
10704
+ */
10705
+ setTransformHierarchy(parent) {
10706
+ this.hierarchy = parent;
10707
+ }
10708
+
10709
+ /**
10710
+ * a
10711
+ * @param {*} transform
10712
+ */
10713
+ updateLottieTransform(transform) {
10714
+ updateTransformByHierarchy(this, transform, this.hierarchy);
10715
+ }
10716
+
10717
+ /**
10718
+ * a
10719
+ * @param {*} masks a
10720
+ */
10721
+ updateLottieMasks(masks) {
10722
+ this.mask.updateMasks(masks);
10723
+ }
10724
+ }
10725
+
10726
+ function createSizedArray$1(len) {
10727
+ return Array.apply(null, { length: len });
10728
+ }
10729
+
10568
10730
  class MatrixHelper extends pixi_js.Matrix {
10569
10731
  reset() {
10570
10732
  // 重置为单位矩阵
@@ -10638,7 +10800,7 @@ class MatrixHelper extends pixi_js.Matrix {
10638
10800
  * @class
10639
10801
  * @private
10640
10802
  */
10641
- class TextElement extends pixi_js.Graphics {
10803
+ class TextGlyphsElement extends pixi_js.Graphics {
10642
10804
  /**
10643
10805
  * ShapeElement constructor
10644
10806
  */
@@ -10684,15 +10846,14 @@ class TextElement extends pixi_js.Graphics {
10684
10846
 
10685
10847
  buildNewText() {
10686
10848
  const documentData = this.lottieLayer.textProperty.currentData;
10687
- this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
10849
+ this.renderedLetters = createSizedArray$1(documentData.l ? documentData.l.length : 0);
10688
10850
  let hasFill = false;
10689
10851
  if (documentData.fc) {
10690
10852
  hasFill = true;
10691
10853
  this._values.fill = Tools.rgb2hex(
10692
- // documentData.fc.map((item) => {
10693
- // console.log(item)
10694
- // return item > 1 ? item : item * 255
10695
- // }),
10854
+ documentData.fc.map(item => {
10855
+ return item > 1 ? item : item * 255;
10856
+ }),
10696
10857
  documentData.fc,
10697
10858
  );
10698
10859
  } else {
@@ -10749,8 +10910,7 @@ class TextElement extends pixi_js.Graphics {
10749
10910
  shapes = shapeData.shapes ? shapeData.shapes[0].it : [];
10750
10911
  jLen = shapes.length;
10751
10912
  matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
10752
- commands = createSizedArray(jLen - 1);
10753
- window.$commands.push(commands);
10913
+ commands = createSizedArray$1(jLen - 1);
10754
10914
  let commandsCounter = 0;
10755
10915
  for (j = 0; j < jLen; j += 1) {
10756
10916
  if (shapes[j].ty === 'sh') {
@@ -10965,27 +11125,7 @@ class TextElement extends pixi_js.Graphics {
10965
11125
  * @param {*} transform
10966
11126
  */
10967
11127
  updateLottieTransform(transform) {
10968
- if (transform.p) {
10969
- this.x = transform.p.v[0];
10970
- this.y = transform.p.v[1];
10971
- } else {
10972
- this.x = transform.px.v;
10973
- this.y = transform.py.v;
10974
- }
10975
-
10976
- this.pivot.x = transform.a.v[0];
10977
- this.pivot.y = transform.a.v[1];
10978
-
10979
- this.scale.x = transform.s.v[0];
10980
- this.scale.y = transform.s.v[1];
10981
-
10982
- if (transform.r) {
10983
- this.rotation = transform.r.v + transform.orientation;
10984
- } else if (transform.rz) {
10985
- this.rotation = transform.rz.v + transform.or.v[2];
10986
- }
10987
-
10988
- this.alpha = transform.o.v;
11128
+ updateTransformByHierarchy(this, transform, this.hierarchy);
10989
11129
  }
10990
11130
 
10991
11131
  /**
@@ -11051,27 +11191,7 @@ class SolidElement extends pixi_js.Graphics {
11051
11191
  * @param {*} transform
11052
11192
  */
11053
11193
  updateLottieTransform(transform) {
11054
- if (transform.p) {
11055
- this.x = transform.p.v[0];
11056
- this.y = transform.p.v[1];
11057
- } else {
11058
- this.x = transform.px.v;
11059
- this.y = transform.py.v;
11060
- }
11061
-
11062
- this.pivot.x = transform.a.v[0];
11063
- this.pivot.y = transform.a.v[1];
11064
-
11065
- this.scale.x = transform.s.v[0];
11066
- this.scale.y = transform.s.v[1];
11067
-
11068
- if (transform.r) {
11069
- this.rotation = transform.r.v + transform.orientation;
11070
- } else if (transform.rz) {
11071
- this.rotation = transform.rz.v + transform.or.v[2];
11072
- }
11073
-
11074
- this.alpha = transform.o.v;
11194
+ updateTransformByHierarchy(this, transform, this.hierarchy);
11075
11195
  }
11076
11196
 
11077
11197
  /**
@@ -11146,27 +11266,7 @@ class SpriteElement extends pixi_js.Sprite {
11146
11266
  * @param {*} transform
11147
11267
  */
11148
11268
  updateLottieTransform(transform) {
11149
- if (transform.p) {
11150
- this.x = transform.p.v[0];
11151
- this.y = transform.p.v[1];
11152
- } else {
11153
- this.x = transform.px.v;
11154
- this.y = transform.py.v;
11155
- }
11156
-
11157
- this.pivot.x = transform.a.v[0];
11158
- this.pivot.y = transform.a.v[1];
11159
-
11160
- this.scale.x = transform.s.v[0];
11161
- this.scale.y = transform.s.v[1];
11162
-
11163
- if (transform.r) {
11164
- this.rotation = transform.r.v + transform.orientation;
11165
- } else if (transform.rz) {
11166
- this.rotation = transform.rz.v + transform.or.v[2];
11167
- }
11168
-
11169
- this.alpha = transform.o.v;
11269
+ updateTransformByHierarchy(this, transform, this.hierarchy);
11170
11270
  }
11171
11271
 
11172
11272
  /**
@@ -11385,6 +11485,29 @@ function loadJson(path) {
11385
11485
  return new LoadJson(path);
11386
11486
  }
11387
11487
 
11488
+ const getLayerBySubstituteId = (lottieFile, substituteId) => {
11489
+ const { substituteIds } = lottieFile || {};
11490
+ if (!substituteIds || Object.keys(substituteIds).length === 0) return null;
11491
+ let layer;
11492
+ // 在复合图层内部
11493
+ if (substituteId && substituteId.indexOf('_') === -1) {
11494
+ const outerIndex = Number(substituteId);
11495
+ if (!Number.isNaN(outerIndex)) {
11496
+ layer = lottieFile?.layers?.[outerIndex];
11497
+ }
11498
+ } else if (substituteId) {
11499
+ // 在顶层图层
11500
+ const substituteIdArr = substituteId.split('_');
11501
+ const outerIndex = Number(substituteIdArr[0]);
11502
+ const innerIndex = Number(substituteIdArr[1]);
11503
+ if (!Number.isNaN(outerIndex) && !Number.isNaN(innerIndex)) {
11504
+ const asset = lottieFile.assets[outerIndex];
11505
+ layer = asset?.layers?.[innerIndex];
11506
+ }
11507
+ }
11508
+ return layer;
11509
+ };
11510
+
11388
11511
  /**
11389
11512
  * an animation group, store and compute frame information, one lottie animate one AnimationGroup
11390
11513
  * @class
@@ -11413,6 +11536,7 @@ class AnimationGroup extends Eventer {
11413
11536
  * @param {boolean} [options.depthTest=true] enable depth test for 3d layer
11414
11537
  * @param {boolean} [options.maskComp=false] add mask for each comp
11415
11538
  * @param {string} [options.prefix=''] assets url prefix, look like link path
11539
+ * @param {boolean} [options.replaceData=''] assets url prefix, look like link path
11416
11540
  */
11417
11541
  constructor(options) {
11418
11542
  super();
@@ -11643,7 +11767,14 @@ class AnimationGroup extends Eventer {
11643
11767
 
11644
11768
  if (options.keyframes) {
11645
11769
  if (!this._prefix && options.keyframes.prefix) this._prefix = options.keyframes.prefix;
11646
- this._setupDate(options.keyframes);
11770
+ if (!options.replaceData) {
11771
+ this._setupDate(options.keyframes);
11772
+ } else {
11773
+ this._response = options.keyframes;
11774
+ if (this._replaceData) {
11775
+ this._setupReplaceData();
11776
+ }
11777
+ }
11647
11778
  } else if (options.path) {
11648
11779
  let prefix = '';
11649
11780
  if (options.path.lastIndexOf('\\') !== -1) {
@@ -11655,7 +11786,14 @@ class AnimationGroup extends Eventer {
11655
11786
 
11656
11787
  this.jsonLoader = loadJson(options.path);
11657
11788
  this.jsonLoader.once('success', response => {
11658
- this._setupDate(response);
11789
+ if (!options.replaceData) {
11790
+ this._setupDate(response);
11791
+ } else {
11792
+ this._response = response;
11793
+ if (this._replaceData) {
11794
+ this._setupReplaceData();
11795
+ }
11796
+ }
11659
11797
  });
11660
11798
  this.jsonLoader.once('error', error => {
11661
11799
  this.emit('error', error);
@@ -11663,6 +11801,43 @@ class AnimationGroup extends Eventer {
11663
11801
  }
11664
11802
  }
11665
11803
 
11804
+ replaceData(data) {
11805
+ this._replaceData = data;
11806
+ this._setupReplaceData();
11807
+ }
11808
+
11809
+ _setupReplaceData() {
11810
+ if (this._response && this._replaceData) {
11811
+ if (this._response.substituteIds) {
11812
+ const revertSubstituteIds = {};
11813
+ for (const key in this._response.substituteIds) {
11814
+ const value = this._response.substituteIds[key];
11815
+ revertSubstituteIds[value] = key;
11816
+ }
11817
+
11818
+ for (const name in this._replaceData) {
11819
+ const data = this._replaceData[name];
11820
+
11821
+ const layer = getLayerBySubstituteId(this._response, revertSubstituteIds[name]);
11822
+ if (!layer) continue;
11823
+ // 更新图片图层或文本图层的内容
11824
+ const { ty } = layer;
11825
+ if (ty === 2) {
11826
+ const asset = lottieFile.assets.find(item => item.id === layer.refId);
11827
+ if (asset) {
11828
+ asset.p = data;
11829
+ }
11830
+ } else if (ty === 5) {
11831
+ if (layer?.t?.d?.k?.[0]?.s?.t) {
11832
+ layer.t.d.k[0].s.t = data;
11833
+ }
11834
+ }
11835
+ }
11836
+ }
11837
+ this._setupDate(this._response);
11838
+ }
11839
+ }
11840
+
11666
11841
  /**
11667
11842
  * 安装动画数据
11668
11843
  * @private
@@ -11793,8 +11968,20 @@ class AnimationGroup extends Eventer {
11793
11968
  st,
11794
11969
  },
11795
11970
  };
11796
- session.fontManager.addChars(data.chars);
11971
+ session.fontManager.addChars(data.chars || []);
11797
11972
  session.fontManager.addFonts(data.fonts, document.body);
11973
+ if (data.fonts?.list?.length) {
11974
+ const fonts = data.fonts.list
11975
+ .map(item => ({
11976
+ alias: item.fFamily,
11977
+ src: item.fPath,
11978
+ data: { family: item.fFamily },
11979
+ }))
11980
+ .filter(item => item.src);
11981
+ pixi_js.Assets.load(fonts).catch(e => {
11982
+ console.error(e);
11983
+ });
11984
+ }
11798
11985
 
11799
11986
  this._buildElements(session);
11800
11987
 
@@ -12030,7 +12217,10 @@ class AnimationGroup extends Eventer {
12030
12217
  // texture,
12031
12218
  // });
12032
12219
  } else {
12033
- lottieLayer.display = new SpriteElement(lottieLayer, { asset, texture });
12220
+ lottieLayer.display = new SpriteElement(lottieLayer, {
12221
+ asset,
12222
+ texture,
12223
+ });
12034
12224
  }
12035
12225
  return lottieLayer;
12036
12226
  }
@@ -12073,7 +12263,13 @@ class AnimationGroup extends Eventer {
12073
12263
  _extraText(layer, session) {
12074
12264
  layer.global = session;
12075
12265
  const lottieLayer = new TextLottieLayer(layer, session);
12076
- lottieLayer.display = new TextElement(lottieLayer);
12266
+ const usesGlyphs = !!session.fontManager.chars?.length;
12267
+ if (usesGlyphs) {
12268
+ lottieLayer.display = new TextGlyphsElement(lottieLayer);
12269
+ } else {
12270
+ lottieLayer.display = new TextElement(lottieLayer);
12271
+ }
12272
+
12077
12273
  return lottieLayer;
12078
12274
  }
12079
12275
 
@@ -12308,10 +12504,11 @@ class AnimationGroup extends Eventer {
12308
12504
  */
12309
12505
  update(snippetCache, firstFrame = false) {
12310
12506
  if (!this.living || !this.isDisplayLoaded || (this.isPaused && !firstFrame)) return;
12311
-
12312
- const isEnd = this._updateTime(snippetCache);
12313
-
12314
- const correctedFrameNum = this.beginFrame + this.frameNum;
12507
+ let isEnd = this._updateTime(snippetCache);
12508
+ const correctedFrameNum = this.direction === 1 ? this.beginFrame + this.frameNum : this.frameNum;
12509
+ if (this.direction === -1 && correctedFrameNum <= this.beginFrame) {
12510
+ isEnd = true;
12511
+ }
12315
12512
  this.root.updateFrame(correctedFrameNum);
12316
12513
 
12317
12514
  const np = correctedFrameNum >> 0;
@@ -12413,6 +12610,7 @@ class AnimationGroup extends Eventer {
12413
12610
  * @param {boolean} [options.alternate=false] alternate direction every round
12414
12611
  * @param {number} [options.wait=0] need wait how much millisecond to start
12415
12612
  * @param {number} [options.delay=0] need delay how much millisecond to begin, effect every loop round
12613
+ * @param {number} [options.direction=1] need direction
12416
12614
  * @return {this}
12417
12615
  */
12418
12616
  playSegment(name, options = {}) {
@@ -12436,6 +12634,11 @@ class AnimationGroup extends Eventer {
12436
12634
  if (Tools.isBoolean(options.alternate)) this.alternate = options.alternate;
12437
12635
  if (Tools.isNumber(options.wait)) this.wait = options.wait;
12438
12636
  if (Tools.isNumber(options.delay)) this.delay = options.delay;
12637
+ if (Tools.isNumber(options.direction)) {
12638
+ this.direction = options.direction;
12639
+ } else {
12640
+ this.direction = 1;
12641
+ }
12439
12642
 
12440
12643
  this.replay();
12441
12644
  return this;
@@ -12541,9 +12744,15 @@ class AnimationGroup extends Eventer {
12541
12744
  this._repeatsCut = this.repeats;
12542
12745
  this._delayCut = this.delay;
12543
12746
  this.living = true;
12544
- this.frameNum = 0;
12747
+ // 根据播放方向设置初始帧位置
12748
+ if (this.direction === -1) {
12749
+ // 倒着播放从duration开始
12750
+ this.frameNum = this.duration;
12751
+ } else {
12752
+ // 正常播放从0开始
12753
+ this.frameNum = 0;
12754
+ }
12545
12755
  this.duration = Math.floor(this.endFrame - this.beginFrame);
12546
- this.direction = 1;
12547
12756
  return this;
12548
12757
  }
12549
12758
 
@@ -12912,6 +13121,12 @@ let LottieSystem = class LottieSystem extends pluginRenderer.Renderer {
12912
13121
  'update',
12913
13122
  ];
12914
13123
  }
13124
+ /**
13125
+ * System 初始化用,可以配置参数,游戏未开始
13126
+ *
13127
+ * System init, set params, game is not begain
13128
+ * @param param init params
13129
+ */
12915
13130
  init() {
12916
13131
  this.renderSystem = this.game.getSystem('Renderer');
12917
13132
  this.app = this.renderSystem.application;
@@ -12929,16 +13144,17 @@ let LottieSystem = class LottieSystem extends pluginRenderer.Renderer {
12929
13144
  });
12930
13145
  }
12931
13146
  add(changed) {
13147
+ var _a, _b;
12932
13148
  return __awaiter(this, void 0, void 0, function* () {
12933
13149
  this.manager = new AnimationManager(this.app);
12934
13150
  const component = changed.component;
12935
13151
  const container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
12936
13152
  if (!container)
12937
13153
  return;
12938
- const _a = component.options, { resource: rn } = _a, otherOpts = __rest(_a, ["resource"]);
13154
+ const _c = component.options, { resource: rn } = _c, otherOpts = __rest(_c, ["resource"]);
12939
13155
  const res = yield eva_js.resource.getResource(rn);
12940
13156
  const data = res.data;
12941
- const url = res.src.json.url;
13157
+ const url = ((_b = (_a = res.src) === null || _a === void 0 ? void 0 : _a.json) === null || _b === void 0 ? void 0 : _b.url) || '';
12942
13158
  const json = Object.assign({}, (data.json || {}));
12943
13159
  const assets = json.assets || [];
12944
13160
  assets.forEach(item => {
@@ -12947,6 +13163,9 @@ let LottieSystem = class LottieSystem extends pluginRenderer.Renderer {
12947
13163
  });
12948
13164
  const anim = this.manager.parseAnimation(Object.assign({ keyframes: json, prefix: this.getDir(url) }, otherOpts));
12949
13165
  component.anim = anim;
13166
+ if (component._replaceData) {
13167
+ anim.replaceData(component._replaceData);
13168
+ }
12950
13169
  container.addChildAt(anim.group, 0);
12951
13170
  this.managerLife.forEach(eventName => {
12952
13171
  anim.on(eventName, e => component.emit(eventName, e));
@@ -12956,6 +13175,8 @@ let LottieSystem = class LottieSystem extends pluginRenderer.Renderer {
12956
13175
  });
12957
13176
  }
12958
13177
  getDir(url) {
13178
+ if (!url)
13179
+ return url;
12959
13180
  return new URL('./', url).href;
12960
13181
  }
12961
13182
  remove(changed) {
@@ -12976,12 +13197,78 @@ LottieSystem = __decorate([
12976
13197
  ], LottieSystem);
12977
13198
  var LottieSystem$1 = LottieSystem;
12978
13199
 
13200
+ /**
13201
+ * Lottie 动画组件
13202
+ *
13203
+ * Lottie 组件用于播放 Adobe After Effects 导出的 Lottie 动画文件。
13204
+ * Lottie 是一种基于 JSON 的动画格式,可以实现复杂的矢量动画效果,
13205
+ * 文件体积小、性能高,适用于图标动画、loading 动画、复杂 UI 动效等场景。
13206
+ *
13207
+ * 主要功能:
13208
+ * - 播放 Lottie JSON 动画
13209
+ * - 支持动画片段播放和循环
13210
+ * - 支持插槽(slot)动态替换内容
13211
+ * - 支持帧事件监听
13212
+ * - 支持交互热区绑定
13213
+ * - 支持动态替换动画数据
13214
+ *
13215
+ * @example
13216
+ * ```typescript
13217
+ * // 基础用法
13218
+ * const animation = new GameObject('animation');
13219
+ * animation.addComponent(new Lottie({
13220
+ * resource: 'loadingAnimation', // Lottie JSON 资源
13221
+ * autoStart: true
13222
+ * }));
13223
+ *
13224
+ * // 播放指定片段
13225
+ * const lottie = animation.getComponent('Lottie');
13226
+ * lottie.play([0, 60], { repeats: -1 }); // 播放 0-60 帧,无限循环
13227
+ *
13228
+ * // 动态替换插槽内容
13229
+ * lottie.play([0, 120], {
13230
+ * slot: [{
13231
+ * name: 'avatar',
13232
+ * type: 'IMAGE',
13233
+ * value: 'user-avatar.png',
13234
+ * style: { width: 100, height: 100 }
13235
+ * }, {
13236
+ * name: 'username',
13237
+ * type: 'TEXT',
13238
+ * value: '玩家名称',
13239
+ * style: { fontSize: 24 }
13240
+ * }]
13241
+ * });
13242
+ *
13243
+ * // 监听特定帧事件
13244
+ * lottie.on('@30', () => {
13245
+ * console.log('到达第 30 帧');
13246
+ * });
13247
+ *
13248
+ * // 绑定点击热区
13249
+ * lottie.onTap('buttonLayer', () => {
13250
+ * console.log('按钮被点击');
13251
+ * });
13252
+ * ```
13253
+ */
12979
13254
  class Lottie extends eva_js.Component {
13255
+ /**
13256
+ * 构造 Lottie 组件
13257
+ * @param options - Lottie 配置选项
13258
+ * @param options.resource - Lottie JSON 资源名称
13259
+ * @param options.autoStart - 是否自动开始播放
13260
+ */
12980
13261
  constructor(options) {
12981
13262
  super();
13263
+ /** 待替换的数据 */
13264
+ this._replaceData = null;
13265
+ /** 资源加载状态 */
12982
13266
  this.loadStatus = false;
13267
+ /** 首次播放回调 */
12983
13268
  this.firstPlay = null;
13269
+ /** 前一次的插槽内容 */
12984
13270
  this.prevSlot = {};
13271
+ /** 当前的插槽内容 */
12985
13272
  this.currentSlot = {};
12986
13273
  this.options = Object.assign({ autoStart: false }, options);
12987
13274
  this.on('success', () => {
@@ -13032,6 +13319,14 @@ class Lottie extends eva_js.Component {
13032
13319
  });
13033
13320
  this.anim.playSegment(this.playParamsHandle(params), expandOpts);
13034
13321
  }
13322
+ replaceData(data) {
13323
+ if (data) {
13324
+ if (this.anim)
13325
+ this.anim.replaceData(data);
13326
+ else
13327
+ this._replaceData = data;
13328
+ }
13329
+ }
13035
13330
  playParamsHandle(params) {
13036
13331
  let p = [].concat(params);
13037
13332
  const { keyframes } = this.anim;
@@ -13058,6 +13353,7 @@ class Lottie extends eva_js.Component {
13058
13353
  });
13059
13354
  }
13060
13355
  }
13356
+ /** 组件名称 */
13061
13357
  Lottie.componentName = 'Lottie';
13062
13358
 
13063
13359
  eva_js.resource.registerResourceType('LOTTIE');