@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.
@@ -1,6 +1,6 @@
1
1
  import { decorators, OBSERVER_TYPE, resource, Component } from '@eva/eva.js';
2
2
  import { Renderer } from '@eva/plugin-renderer';
3
- import { UPDATE_PRIORITY, Ticker, Container, Texture, Graphics, Matrix as Matrix$1, Sprite, Assets, Text, TextStyle } from 'pixi.js';
3
+ import { Ticker, Container, Assets, Texture, Graphics, Text, Matrix as Matrix$1, Sprite, TextStyle } from 'pixi.js';
4
4
  import iOSVersion from 'ios-version';
5
5
 
6
6
  /*! *****************************************************************************
@@ -271,7 +271,7 @@ if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function
271
271
  * @param {*} len a
272
272
  * @return {*}
273
273
  */
274
- function createSizedArray$1(len) {
274
+ function createSizedArray$2(len) {
275
275
  return new Array(len);
276
276
  }
277
277
 
@@ -501,7 +501,7 @@ var BezierFactory = {
501
501
  * @return {*}
502
502
  */
503
503
  function _double(arr) {
504
- return arr.concat(createSizedArray$1(arr.length));
504
+ return arr.concat(createSizedArray$2(arr.length));
505
505
  }
506
506
  var pooling = {
507
507
  double: _double,
@@ -510,7 +510,7 @@ var pooling = {
510
510
  var PoolFactory = function PoolFactory(initialLength, _create, _release) {
511
511
  var _length = 0;
512
512
  var _maxLength = initialLength;
513
- var pool = createSizedArray$1(_maxLength);
513
+ var pool = createSizedArray$2(_maxLength);
514
514
  var ob = {
515
515
  newElement: newElement,
516
516
  release: release,
@@ -790,7 +790,7 @@ function buildBezierData(pt1, pt2, pt3, pt4) {
790
790
  var bezierData = new BezierData(curveSegments);
791
791
  var len = pt3.length;
792
792
  for (var k = 0; k < curveSegments; k += 1) {
793
- point = createSizedArray$1(len);
793
+ point = createSizedArray$2(len);
794
794
  var perc = k / (curveSegments - 1);
795
795
  ptDistance = 0;
796
796
  for (var i = 0; i < len; i += 1) {
@@ -2178,9 +2178,9 @@ var ShapePath = /*#__PURE__*/ (function () {
2178
2178
  this.c = false;
2179
2179
  this._length = 0;
2180
2180
  this._maxLength = 8;
2181
- this.v = createSizedArray$1(this._maxLength);
2182
- this.o = createSizedArray$1(this._maxLength);
2183
- this.i = createSizedArray$1(this._maxLength);
2181
+ this.v = createSizedArray$2(this._maxLength);
2182
+ this.o = createSizedArray$2(this._maxLength);
2183
+ this.i = createSizedArray$2(this._maxLength);
2184
2184
  }
2185
2185
 
2186
2186
  /**
@@ -2224,9 +2224,9 @@ var ShapePath = /*#__PURE__*/ (function () {
2224
2224
  {
2225
2225
  key: 'doubleArrayLength',
2226
2226
  value: function doubleArrayLength() {
2227
- this.v = this.v.concat(createSizedArray$1(this._maxLength));
2228
- this.i = this.i.concat(createSizedArray$1(this._maxLength));
2229
- this.o = this.o.concat(createSizedArray$1(this._maxLength));
2227
+ this.v = this.v.concat(createSizedArray$2(this._maxLength));
2228
+ this.i = this.i.concat(createSizedArray$2(this._maxLength));
2229
+ this.o = this.o.concat(createSizedArray$2(this._maxLength));
2230
2230
  this._maxLength *= 2;
2231
2231
  },
2232
2232
 
@@ -2395,7 +2395,7 @@ var ShapeCollection = /*#__PURE__*/ (function () {
2395
2395
  _classCallCheck(this, ShapeCollection);
2396
2396
  this._length = 0;
2397
2397
  this._maxLength = 4;
2398
- this.shapes = createSizedArray$1(this._maxLength);
2398
+ this.shapes = createSizedArray$2(this._maxLength);
2399
2399
  }
2400
2400
 
2401
2401
  /**
@@ -2407,7 +2407,7 @@ var ShapeCollection = /*#__PURE__*/ (function () {
2407
2407
  key: 'addShape',
2408
2408
  value: function addShape(shapeData) {
2409
2409
  if (this._length === this._maxLength) {
2410
- this.shapes = this.shapes.concat(createSizedArray$1(this._maxLength));
2410
+ this.shapes = this.shapes.concat(createSizedArray$2(this._maxLength));
2411
2411
  this._maxLength *= 2;
2412
2412
  }
2413
2413
  this.shapes[this._length] = shapeData;
@@ -2432,7 +2432,7 @@ var ShapeCollection = /*#__PURE__*/ (function () {
2432
2432
 
2433
2433
  var _length = 0;
2434
2434
  var _maxLength = 4;
2435
- var pool = createSizedArray$1(_maxLength);
2435
+ var pool = createSizedArray$2(_maxLength);
2436
2436
 
2437
2437
  /**
2438
2438
  * a
@@ -3257,7 +3257,7 @@ var MaskFrames = /*#__PURE__*/ (function (_DynamicPropertyConta) {
3257
3257
  _this.propType = 'mask';
3258
3258
  _this.masksProperties = masksProperties || [];
3259
3259
  _this.initDynamicPropertyContainer(elem);
3260
- _this.viewData = createSizedArray$1(_this.masksProperties.length);
3260
+ _this.viewData = createSizedArray$2(_this.masksProperties.length);
3261
3261
  var len = _this.masksProperties.length;
3262
3262
  var hasMasks = false;
3263
3263
  for (var i = 0; i < len; i++) {
@@ -5688,7 +5688,7 @@ var DashProperty = /*#__PURE__*/ (function (_DynamicPropertyConta) {
5688
5688
  _this = _callSuper(this, DashProperty);
5689
5689
  _this.elem = elem;
5690
5690
  _this.frameId = -1;
5691
- _this.dataProps = createSizedArray$1(data.length);
5691
+ _this.dataProps = createSizedArray$2(data.length);
5692
5692
  // this.renderer = renderer;
5693
5693
  _this.k = false;
5694
5694
  // this.dashStr = '';
@@ -7413,7 +7413,7 @@ var TextAnimatorProperty = /*#__PURE__*/ (function (_DynamicPropertyConta) {
7413
7413
  _this._textData = textData;
7414
7414
  _this._renderType = renderType;
7415
7415
  _this.elem = elem;
7416
- _this._animatorsData = createSizedArray$1(_this._textData.a.length);
7416
+ _this._animatorsData = createSizedArray$2(_this._textData.a.length);
7417
7417
  _this._pathData = {};
7418
7418
  _this._moreOptions = {
7419
7419
  alignment: {},
@@ -10208,7 +10208,6 @@ const Tween = {
10208
10208
  };
10209
10209
 
10210
10210
  ({
10211
- UPDATE_PRIORITY,
10212
10211
  animationTicker: Ticker.shared,
10213
10212
  });
10214
10213
 
@@ -10268,6 +10267,61 @@ class LottieGraphicsMask extends Graphics {
10268
10267
  }
10269
10268
  }
10270
10269
 
10270
+ const updateTransformByHierarchy = (container, transform, parent) => {
10271
+ // const localMatrixA = new Matrix();
10272
+
10273
+ if (transform.p) {
10274
+ container.x = transform.p.v[0];
10275
+ container.y = transform.p.v[1];
10276
+ } else {
10277
+ container.x = transform.px.v;
10278
+ container.y = transform.py.v;
10279
+ }
10280
+
10281
+ container.pivot.x = transform.a.v[0];
10282
+ container.pivot.y = transform.a.v[1];
10283
+
10284
+ container.scale.x = transform.s.v[0];
10285
+ container.scale.y = transform.s.v[1];
10286
+
10287
+ if (transform.r) {
10288
+ container.rotation = transform.r.v + transform.orientation;
10289
+ } else if (transform.rz) {
10290
+ container.rotation = transform.rz.v + transform.or.v[2];
10291
+ }
10292
+
10293
+ // let x = transform.p ? transform.p.v[0] : transform.px.v;
10294
+ // let y = transform.p ? transform.p.v[1] : transform.py.v;
10295
+
10296
+ // const rotation = transform.r
10297
+ // ? transform.r.v + transform.orientation
10298
+ // : transform.rz
10299
+ // ? transform.rz.v + transform.or.v[2]
10300
+ // : 0;
10301
+
10302
+ // localMatrixA.setTransform(
10303
+ // x,
10304
+ // y,
10305
+ // transform.a.v[0],
10306
+ // transform.a.v[1],
10307
+ // transform.s.v[0],
10308
+ // transform.s.v[1],
10309
+ // rotation,
10310
+ // 0,
10311
+ // 0
10312
+ // );
10313
+
10314
+ // if (parent) {
10315
+ // const parentWorldTransform = parent.worldTransform.clone();
10316
+ // container.setFromMatrix(localMatrixA.append(parentWorldTransform));
10317
+ // } else {
10318
+ // container.setFromMatrix(localMatrixA);
10319
+ // }
10320
+
10321
+ const parentAlpha = parent ? parent.alpha : 1;
10322
+ container.alpha = parentAlpha * transform.o.v;
10323
+ };
10324
+
10271
10325
  /**
10272
10326
  * NullElement class
10273
10327
  * @class
@@ -10316,27 +10370,7 @@ class CompElement extends Container {
10316
10370
  }
10317
10371
 
10318
10372
  updateLottieTransform(transform) {
10319
- if (transform.p) {
10320
- this.x = transform.p.v[0];
10321
- this.y = transform.p.v[1];
10322
- } else {
10323
- this.x = transform.px.v;
10324
- this.y = transform.py.v;
10325
- }
10326
-
10327
- this.pivot.x = transform.a.v[0];
10328
- this.pivot.y = transform.a.v[1];
10329
-
10330
- this.scale.x = transform.s.v[0];
10331
- this.scale.y = transform.s.v[1];
10332
-
10333
- if (transform.r) {
10334
- this.rotation = transform.r.v + transform.orientation;
10335
- } else if (transform.rz) {
10336
- this.rotation = transform.rz.v + transform.or.v[2];
10337
- }
10338
-
10339
- this.alpha = transform.o.v;
10373
+ updateTransformByHierarchy(this, transform, this.hierarchy);
10340
10374
  }
10341
10375
 
10342
10376
  /**
@@ -10511,27 +10545,7 @@ class ShapeElement extends Graphics {
10511
10545
  * @param {*} transform
10512
10546
  */
10513
10547
  updateLottieTransform(transform) {
10514
- if (transform.p) {
10515
- this.x = transform.p.v[0];
10516
- this.y = transform.p.v[1];
10517
- } else {
10518
- this.x = transform.px.v;
10519
- this.y = transform.py.v;
10520
- }
10521
-
10522
- this.pivot.x = transform.a.v[0];
10523
- this.pivot.y = transform.a.v[1];
10524
-
10525
- this.scale.x = transform.s.v[0];
10526
- this.scale.y = transform.s.v[1];
10527
-
10528
- if (transform.r) {
10529
- this.rotation = transform.r.v + transform.orientation;
10530
- } else if (transform.rz) {
10531
- this.rotation = transform.rz.v + transform.or.v[2];
10532
- }
10533
-
10534
- this.alpha = transform.o.v;
10548
+ updateTransformByHierarchy(this, transform, this.hierarchy);
10535
10549
  }
10536
10550
 
10537
10551
  /**
@@ -10557,6 +10571,154 @@ function createSizedArray(len) {
10557
10571
  return Array.apply(null, { length: len });
10558
10572
  }
10559
10573
 
10574
+ /**
10575
+ * NullElement class
10576
+ * @class
10577
+ * @private
10578
+ */
10579
+ class TextElement extends Text {
10580
+ /**
10581
+ * ShapeElement constructor
10582
+ */
10583
+ constructor(lottieLayer) {
10584
+ super();
10585
+ this.label = lottieLayer.fullname;
10586
+ this.lottieLayer = lottieLayer;
10587
+ this.lottieLayer.lettersChangedFlag = true;
10588
+ if (this.lottieLayer.masks) {
10589
+ this.mask = new LottieGraphicsMask(this.lottieLayer.session.local, this.lottieLayer);
10590
+ this.addChild(this.mask);
10591
+ }
10592
+
10593
+ this.init();
10594
+ this.buildNewText();
10595
+ this.updateLottie = this.updateLottie.bind(this);
10596
+ this.updateLottie(this.lottieLayer, true);
10597
+ this.lottieLayer.on('updatelayer', this.updateLottie);
10598
+ this.onRender = () => {
10599
+ this.updateLottie(this.lottieLayer, true);
10600
+ };
10601
+ }
10602
+
10603
+ init() {
10604
+ this._textSpans = [];
10605
+ this._yOffset = 0;
10606
+ this._fillColorAnim = false;
10607
+ this._strokeColorAnim = false;
10608
+ this._strokeWidthAnim = false;
10609
+ this._stroke = false;
10610
+ this._fill = false;
10611
+ this._justifyOffset = 0;
10612
+ this._currentRender = null;
10613
+ this._renderType = 'canvas';
10614
+ this._fillStyle = {};
10615
+ this._values = {
10616
+ fill: '#000000',
10617
+ stroke: '#000000',
10618
+ sWidth: 0,
10619
+ fValue: '',
10620
+ };
10621
+ }
10622
+
10623
+ buildNewText() {
10624
+ const documentData = this.lottieLayer.textProperty.currentData;
10625
+ this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
10626
+ let hasFill = false;
10627
+ if (documentData.fc) {
10628
+ hasFill = true;
10629
+ this._values.fill = Tools.rgb2hex(
10630
+ documentData.fc.map(item => {
10631
+ return item > 1 ? item : item * 255;
10632
+ }),
10633
+ documentData.fc,
10634
+ );
10635
+ } else {
10636
+ this._values.fill = '#000000';
10637
+ }
10638
+ this._fill = hasFill;
10639
+ let hasStroke = false;
10640
+ if (documentData.sc) {
10641
+ hasStroke = true;
10642
+ this._values.stroke = this.buildColor(documentData.sc);
10643
+ this._values.sWidth = documentData.sw;
10644
+ }
10645
+ const fontManager = this.lottieLayer.global.fontManager;
10646
+ this._stroke = hasStroke;
10647
+ this._values.fontSize = documentData.finalSize;
10648
+ this._values.fontFamily = fontManager.getFontByName(documentData.f).fFamily;
10649
+ this._values.fontWeight = documentData.fWeight;
10650
+ this._values.fontStyle = documentData.fStyle;
10651
+ this._values.lineHeight = documentData.finalLineHeight;
10652
+ this._text = documentData.t;
10653
+
10654
+ this.renderText();
10655
+ }
10656
+
10657
+ async renderText() {
10658
+ this.text = this._text;
10659
+ if (this.style.fontFamily) {
10660
+ await Assets.get(this.style.fontFamily);
10661
+ }
10662
+ this.style.fontFamily = this._values.fontFamily;
10663
+ this.style.fontSize = this._values.fontSize;
10664
+ this.style.fill = this._values.fill;
10665
+ this.style.fontWeight = this._values.fontWeight;
10666
+ this.style.fontStyle = this._values.fontStyle;
10667
+ this.style.lineHeight = this._values.lineHeight;
10668
+
10669
+ this.anchor.x = 0.5;
10670
+ this.anchor.y = 0.8;
10671
+ }
10672
+
10673
+ /**
10674
+ * update lottie information
10675
+ * @param {*} lottieLayer lottie element object
10676
+ * @param {boolean} forceUpdate forceUpdate
10677
+ */
10678
+ updateLottie(lottieLayer, _forceUpdate = false) {
10679
+ let forceUpdate = true;
10680
+ if (lottieLayer.transform && forceUpdate) {
10681
+ this.updateLottieTransform(lottieLayer.transform);
10682
+ }
10683
+ if (lottieLayer.masks && forceUpdate) {
10684
+ this.updateLottieMasks(lottieLayer.masks);
10685
+ }
10686
+ if (lottieLayer._mdf) {
10687
+ this.renderText();
10688
+ }
10689
+ this.visible = lottieLayer.isInRange;
10690
+ this._onUpdate();
10691
+ }
10692
+
10693
+ /**
10694
+ * a
10695
+ * @param {*} parent a
10696
+ */
10697
+ setTransformHierarchy(parent) {
10698
+ this.hierarchy = parent;
10699
+ }
10700
+
10701
+ /**
10702
+ * a
10703
+ * @param {*} transform
10704
+ */
10705
+ updateLottieTransform(transform) {
10706
+ updateTransformByHierarchy(this, transform, this.hierarchy);
10707
+ }
10708
+
10709
+ /**
10710
+ * a
10711
+ * @param {*} masks a
10712
+ */
10713
+ updateLottieMasks(masks) {
10714
+ this.mask.updateMasks(masks);
10715
+ }
10716
+ }
10717
+
10718
+ function createSizedArray$1(len) {
10719
+ return Array.apply(null, { length: len });
10720
+ }
10721
+
10560
10722
  class MatrixHelper extends Matrix$1 {
10561
10723
  reset() {
10562
10724
  // 重置为单位矩阵
@@ -10630,7 +10792,7 @@ class MatrixHelper extends Matrix$1 {
10630
10792
  * @class
10631
10793
  * @private
10632
10794
  */
10633
- class TextElement extends Graphics {
10795
+ class TextGlyphsElement extends Graphics {
10634
10796
  /**
10635
10797
  * ShapeElement constructor
10636
10798
  */
@@ -10676,15 +10838,14 @@ class TextElement extends Graphics {
10676
10838
 
10677
10839
  buildNewText() {
10678
10840
  const documentData = this.lottieLayer.textProperty.currentData;
10679
- this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
10841
+ this.renderedLetters = createSizedArray$1(documentData.l ? documentData.l.length : 0);
10680
10842
  let hasFill = false;
10681
10843
  if (documentData.fc) {
10682
10844
  hasFill = true;
10683
10845
  this._values.fill = Tools.rgb2hex(
10684
- // documentData.fc.map((item) => {
10685
- // console.log(item)
10686
- // return item > 1 ? item : item * 255
10687
- // }),
10846
+ documentData.fc.map(item => {
10847
+ return item > 1 ? item : item * 255;
10848
+ }),
10688
10849
  documentData.fc,
10689
10850
  );
10690
10851
  } else {
@@ -10741,8 +10902,7 @@ class TextElement extends Graphics {
10741
10902
  shapes = shapeData.shapes ? shapeData.shapes[0].it : [];
10742
10903
  jLen = shapes.length;
10743
10904
  matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
10744
- commands = createSizedArray(jLen - 1);
10745
- window.$commands.push(commands);
10905
+ commands = createSizedArray$1(jLen - 1);
10746
10906
  let commandsCounter = 0;
10747
10907
  for (j = 0; j < jLen; j += 1) {
10748
10908
  if (shapes[j].ty === 'sh') {
@@ -10957,27 +11117,7 @@ class TextElement extends Graphics {
10957
11117
  * @param {*} transform
10958
11118
  */
10959
11119
  updateLottieTransform(transform) {
10960
- if (transform.p) {
10961
- this.x = transform.p.v[0];
10962
- this.y = transform.p.v[1];
10963
- } else {
10964
- this.x = transform.px.v;
10965
- this.y = transform.py.v;
10966
- }
10967
-
10968
- this.pivot.x = transform.a.v[0];
10969
- this.pivot.y = transform.a.v[1];
10970
-
10971
- this.scale.x = transform.s.v[0];
10972
- this.scale.y = transform.s.v[1];
10973
-
10974
- if (transform.r) {
10975
- this.rotation = transform.r.v + transform.orientation;
10976
- } else if (transform.rz) {
10977
- this.rotation = transform.rz.v + transform.or.v[2];
10978
- }
10979
-
10980
- this.alpha = transform.o.v;
11120
+ updateTransformByHierarchy(this, transform, this.hierarchy);
10981
11121
  }
10982
11122
 
10983
11123
  /**
@@ -11043,27 +11183,7 @@ class SolidElement extends Graphics {
11043
11183
  * @param {*} transform
11044
11184
  */
11045
11185
  updateLottieTransform(transform) {
11046
- if (transform.p) {
11047
- this.x = transform.p.v[0];
11048
- this.y = transform.p.v[1];
11049
- } else {
11050
- this.x = transform.px.v;
11051
- this.y = transform.py.v;
11052
- }
11053
-
11054
- this.pivot.x = transform.a.v[0];
11055
- this.pivot.y = transform.a.v[1];
11056
-
11057
- this.scale.x = transform.s.v[0];
11058
- this.scale.y = transform.s.v[1];
11059
-
11060
- if (transform.r) {
11061
- this.rotation = transform.r.v + transform.orientation;
11062
- } else if (transform.rz) {
11063
- this.rotation = transform.rz.v + transform.or.v[2];
11064
- }
11065
-
11066
- this.alpha = transform.o.v;
11186
+ updateTransformByHierarchy(this, transform, this.hierarchy);
11067
11187
  }
11068
11188
 
11069
11189
  /**
@@ -11138,27 +11258,7 @@ class SpriteElement extends Sprite {
11138
11258
  * @param {*} transform
11139
11259
  */
11140
11260
  updateLottieTransform(transform) {
11141
- if (transform.p) {
11142
- this.x = transform.p.v[0];
11143
- this.y = transform.p.v[1];
11144
- } else {
11145
- this.x = transform.px.v;
11146
- this.y = transform.py.v;
11147
- }
11148
-
11149
- this.pivot.x = transform.a.v[0];
11150
- this.pivot.y = transform.a.v[1];
11151
-
11152
- this.scale.x = transform.s.v[0];
11153
- this.scale.y = transform.s.v[1];
11154
-
11155
- if (transform.r) {
11156
- this.rotation = transform.r.v + transform.orientation;
11157
- } else if (transform.rz) {
11158
- this.rotation = transform.rz.v + transform.or.v[2];
11159
- }
11160
-
11161
- this.alpha = transform.o.v;
11261
+ updateTransformByHierarchy(this, transform, this.hierarchy);
11162
11262
  }
11163
11263
 
11164
11264
  /**
@@ -11377,6 +11477,29 @@ function loadJson(path) {
11377
11477
  return new LoadJson(path);
11378
11478
  }
11379
11479
 
11480
+ const getLayerBySubstituteId = (lottieFile, substituteId) => {
11481
+ const { substituteIds } = lottieFile || {};
11482
+ if (!substituteIds || Object.keys(substituteIds).length === 0) return null;
11483
+ let layer;
11484
+ // 在复合图层内部
11485
+ if (substituteId && substituteId.indexOf('_') === -1) {
11486
+ const outerIndex = Number(substituteId);
11487
+ if (!Number.isNaN(outerIndex)) {
11488
+ layer = lottieFile?.layers?.[outerIndex];
11489
+ }
11490
+ } else if (substituteId) {
11491
+ // 在顶层图层
11492
+ const substituteIdArr = substituteId.split('_');
11493
+ const outerIndex = Number(substituteIdArr[0]);
11494
+ const innerIndex = Number(substituteIdArr[1]);
11495
+ if (!Number.isNaN(outerIndex) && !Number.isNaN(innerIndex)) {
11496
+ const asset = lottieFile.assets[outerIndex];
11497
+ layer = asset?.layers?.[innerIndex];
11498
+ }
11499
+ }
11500
+ return layer;
11501
+ };
11502
+
11380
11503
  /**
11381
11504
  * an animation group, store and compute frame information, one lottie animate one AnimationGroup
11382
11505
  * @class
@@ -11405,6 +11528,7 @@ class AnimationGroup extends Eventer {
11405
11528
  * @param {boolean} [options.depthTest=true] enable depth test for 3d layer
11406
11529
  * @param {boolean} [options.maskComp=false] add mask for each comp
11407
11530
  * @param {string} [options.prefix=''] assets url prefix, look like link path
11531
+ * @param {boolean} [options.replaceData=''] assets url prefix, look like link path
11408
11532
  */
11409
11533
  constructor(options) {
11410
11534
  super();
@@ -11635,7 +11759,14 @@ class AnimationGroup extends Eventer {
11635
11759
 
11636
11760
  if (options.keyframes) {
11637
11761
  if (!this._prefix && options.keyframes.prefix) this._prefix = options.keyframes.prefix;
11638
- this._setupDate(options.keyframes);
11762
+ if (!options.replaceData) {
11763
+ this._setupDate(options.keyframes);
11764
+ } else {
11765
+ this._response = options.keyframes;
11766
+ if (this._replaceData) {
11767
+ this._setupReplaceData();
11768
+ }
11769
+ }
11639
11770
  } else if (options.path) {
11640
11771
  let prefix = '';
11641
11772
  if (options.path.lastIndexOf('\\') !== -1) {
@@ -11647,7 +11778,14 @@ class AnimationGroup extends Eventer {
11647
11778
 
11648
11779
  this.jsonLoader = loadJson(options.path);
11649
11780
  this.jsonLoader.once('success', response => {
11650
- this._setupDate(response);
11781
+ if (!options.replaceData) {
11782
+ this._setupDate(response);
11783
+ } else {
11784
+ this._response = response;
11785
+ if (this._replaceData) {
11786
+ this._setupReplaceData();
11787
+ }
11788
+ }
11651
11789
  });
11652
11790
  this.jsonLoader.once('error', error => {
11653
11791
  this.emit('error', error);
@@ -11655,6 +11793,43 @@ class AnimationGroup extends Eventer {
11655
11793
  }
11656
11794
  }
11657
11795
 
11796
+ replaceData(data) {
11797
+ this._replaceData = data;
11798
+ this._setupReplaceData();
11799
+ }
11800
+
11801
+ _setupReplaceData() {
11802
+ if (this._response && this._replaceData) {
11803
+ if (this._response.substituteIds) {
11804
+ const revertSubstituteIds = {};
11805
+ for (const key in this._response.substituteIds) {
11806
+ const value = this._response.substituteIds[key];
11807
+ revertSubstituteIds[value] = key;
11808
+ }
11809
+
11810
+ for (const name in this._replaceData) {
11811
+ const data = this._replaceData[name];
11812
+
11813
+ const layer = getLayerBySubstituteId(this._response, revertSubstituteIds[name]);
11814
+ if (!layer) continue;
11815
+ // 更新图片图层或文本图层的内容
11816
+ const { ty } = layer;
11817
+ if (ty === 2) {
11818
+ const asset = lottieFile.assets.find(item => item.id === layer.refId);
11819
+ if (asset) {
11820
+ asset.p = data;
11821
+ }
11822
+ } else if (ty === 5) {
11823
+ if (layer?.t?.d?.k?.[0]?.s?.t) {
11824
+ layer.t.d.k[0].s.t = data;
11825
+ }
11826
+ }
11827
+ }
11828
+ }
11829
+ this._setupDate(this._response);
11830
+ }
11831
+ }
11832
+
11658
11833
  /**
11659
11834
  * 安装动画数据
11660
11835
  * @private
@@ -11785,8 +11960,20 @@ class AnimationGroup extends Eventer {
11785
11960
  st,
11786
11961
  },
11787
11962
  };
11788
- session.fontManager.addChars(data.chars);
11963
+ session.fontManager.addChars(data.chars || []);
11789
11964
  session.fontManager.addFonts(data.fonts, document.body);
11965
+ if (data.fonts?.list?.length) {
11966
+ const fonts = data.fonts.list
11967
+ .map(item => ({
11968
+ alias: item.fFamily,
11969
+ src: item.fPath,
11970
+ data: { family: item.fFamily },
11971
+ }))
11972
+ .filter(item => item.src);
11973
+ Assets.load(fonts).catch(e => {
11974
+ console.error(e);
11975
+ });
11976
+ }
11790
11977
 
11791
11978
  this._buildElements(session);
11792
11979
 
@@ -12022,7 +12209,10 @@ class AnimationGroup extends Eventer {
12022
12209
  // texture,
12023
12210
  // });
12024
12211
  } else {
12025
- lottieLayer.display = new SpriteElement(lottieLayer, { asset, texture });
12212
+ lottieLayer.display = new SpriteElement(lottieLayer, {
12213
+ asset,
12214
+ texture,
12215
+ });
12026
12216
  }
12027
12217
  return lottieLayer;
12028
12218
  }
@@ -12065,7 +12255,13 @@ class AnimationGroup extends Eventer {
12065
12255
  _extraText(layer, session) {
12066
12256
  layer.global = session;
12067
12257
  const lottieLayer = new TextLottieLayer(layer, session);
12068
- lottieLayer.display = new TextElement(lottieLayer);
12258
+ const usesGlyphs = !!session.fontManager.chars?.length;
12259
+ if (usesGlyphs) {
12260
+ lottieLayer.display = new TextGlyphsElement(lottieLayer);
12261
+ } else {
12262
+ lottieLayer.display = new TextElement(lottieLayer);
12263
+ }
12264
+
12069
12265
  return lottieLayer;
12070
12266
  }
12071
12267
 
@@ -12300,10 +12496,11 @@ class AnimationGroup extends Eventer {
12300
12496
  */
12301
12497
  update(snippetCache, firstFrame = false) {
12302
12498
  if (!this.living || !this.isDisplayLoaded || (this.isPaused && !firstFrame)) return;
12303
-
12304
- const isEnd = this._updateTime(snippetCache);
12305
-
12306
- const correctedFrameNum = this.beginFrame + this.frameNum;
12499
+ let isEnd = this._updateTime(snippetCache);
12500
+ const correctedFrameNum = this.direction === 1 ? this.beginFrame + this.frameNum : this.frameNum;
12501
+ if (this.direction === -1 && correctedFrameNum <= this.beginFrame) {
12502
+ isEnd = true;
12503
+ }
12307
12504
  this.root.updateFrame(correctedFrameNum);
12308
12505
 
12309
12506
  const np = correctedFrameNum >> 0;
@@ -12405,6 +12602,7 @@ class AnimationGroup extends Eventer {
12405
12602
  * @param {boolean} [options.alternate=false] alternate direction every round
12406
12603
  * @param {number} [options.wait=0] need wait how much millisecond to start
12407
12604
  * @param {number} [options.delay=0] need delay how much millisecond to begin, effect every loop round
12605
+ * @param {number} [options.direction=1] need direction
12408
12606
  * @return {this}
12409
12607
  */
12410
12608
  playSegment(name, options = {}) {
@@ -12428,6 +12626,11 @@ class AnimationGroup extends Eventer {
12428
12626
  if (Tools.isBoolean(options.alternate)) this.alternate = options.alternate;
12429
12627
  if (Tools.isNumber(options.wait)) this.wait = options.wait;
12430
12628
  if (Tools.isNumber(options.delay)) this.delay = options.delay;
12629
+ if (Tools.isNumber(options.direction)) {
12630
+ this.direction = options.direction;
12631
+ } else {
12632
+ this.direction = 1;
12633
+ }
12431
12634
 
12432
12635
  this.replay();
12433
12636
  return this;
@@ -12533,9 +12736,15 @@ class AnimationGroup extends Eventer {
12533
12736
  this._repeatsCut = this.repeats;
12534
12737
  this._delayCut = this.delay;
12535
12738
  this.living = true;
12536
- this.frameNum = 0;
12739
+ // 根据播放方向设置初始帧位置
12740
+ if (this.direction === -1) {
12741
+ // 倒着播放从duration开始
12742
+ this.frameNum = this.duration;
12743
+ } else {
12744
+ // 正常播放从0开始
12745
+ this.frameNum = 0;
12746
+ }
12537
12747
  this.duration = Math.floor(this.endFrame - this.beginFrame);
12538
- this.direction = 1;
12539
12748
  return this;
12540
12749
  }
12541
12750
 
@@ -12904,6 +13113,12 @@ let LottieSystem = class LottieSystem extends Renderer {
12904
13113
  'update',
12905
13114
  ];
12906
13115
  }
13116
+ /**
13117
+ * System 初始化用,可以配置参数,游戏未开始
13118
+ *
13119
+ * System init, set params, game is not begain
13120
+ * @param param init params
13121
+ */
12907
13122
  init() {
12908
13123
  this.renderSystem = this.game.getSystem('Renderer');
12909
13124
  this.app = this.renderSystem.application;
@@ -12921,16 +13136,17 @@ let LottieSystem = class LottieSystem extends Renderer {
12921
13136
  });
12922
13137
  }
12923
13138
  add(changed) {
13139
+ var _a, _b;
12924
13140
  return __awaiter(this, void 0, void 0, function* () {
12925
13141
  this.manager = new AnimationManager(this.app);
12926
13142
  const component = changed.component;
12927
13143
  const container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
12928
13144
  if (!container)
12929
13145
  return;
12930
- const _a = component.options, { resource: rn } = _a, otherOpts = __rest(_a, ["resource"]);
13146
+ const _c = component.options, { resource: rn } = _c, otherOpts = __rest(_c, ["resource"]);
12931
13147
  const res = yield resource.getResource(rn);
12932
13148
  const data = res.data;
12933
- const url = res.src.json.url;
13149
+ const url = ((_b = (_a = res.src) === null || _a === void 0 ? void 0 : _a.json) === null || _b === void 0 ? void 0 : _b.url) || '';
12934
13150
  const json = Object.assign({}, (data.json || {}));
12935
13151
  const assets = json.assets || [];
12936
13152
  assets.forEach(item => {
@@ -12939,6 +13155,9 @@ let LottieSystem = class LottieSystem extends Renderer {
12939
13155
  });
12940
13156
  const anim = this.manager.parseAnimation(Object.assign({ keyframes: json, prefix: this.getDir(url) }, otherOpts));
12941
13157
  component.anim = anim;
13158
+ if (component._replaceData) {
13159
+ anim.replaceData(component._replaceData);
13160
+ }
12942
13161
  container.addChildAt(anim.group, 0);
12943
13162
  this.managerLife.forEach(eventName => {
12944
13163
  anim.on(eventName, e => component.emit(eventName, e));
@@ -12948,6 +13167,8 @@ let LottieSystem = class LottieSystem extends Renderer {
12948
13167
  });
12949
13168
  }
12950
13169
  getDir(url) {
13170
+ if (!url)
13171
+ return url;
12951
13172
  return new URL('./', url).href;
12952
13173
  }
12953
13174
  remove(changed) {
@@ -12968,12 +13189,78 @@ LottieSystem = __decorate([
12968
13189
  ], LottieSystem);
12969
13190
  var LottieSystem$1 = LottieSystem;
12970
13191
 
13192
+ /**
13193
+ * Lottie 动画组件
13194
+ *
13195
+ * Lottie 组件用于播放 Adobe After Effects 导出的 Lottie 动画文件。
13196
+ * Lottie 是一种基于 JSON 的动画格式,可以实现复杂的矢量动画效果,
13197
+ * 文件体积小、性能高,适用于图标动画、loading 动画、复杂 UI 动效等场景。
13198
+ *
13199
+ * 主要功能:
13200
+ * - 播放 Lottie JSON 动画
13201
+ * - 支持动画片段播放和循环
13202
+ * - 支持插槽(slot)动态替换内容
13203
+ * - 支持帧事件监听
13204
+ * - 支持交互热区绑定
13205
+ * - 支持动态替换动画数据
13206
+ *
13207
+ * @example
13208
+ * ```typescript
13209
+ * // 基础用法
13210
+ * const animation = new GameObject('animation');
13211
+ * animation.addComponent(new Lottie({
13212
+ * resource: 'loadingAnimation', // Lottie JSON 资源
13213
+ * autoStart: true
13214
+ * }));
13215
+ *
13216
+ * // 播放指定片段
13217
+ * const lottie = animation.getComponent('Lottie');
13218
+ * lottie.play([0, 60], { repeats: -1 }); // 播放 0-60 帧,无限循环
13219
+ *
13220
+ * // 动态替换插槽内容
13221
+ * lottie.play([0, 120], {
13222
+ * slot: [{
13223
+ * name: 'avatar',
13224
+ * type: 'IMAGE',
13225
+ * value: 'user-avatar.png',
13226
+ * style: { width: 100, height: 100 }
13227
+ * }, {
13228
+ * name: 'username',
13229
+ * type: 'TEXT',
13230
+ * value: '玩家名称',
13231
+ * style: { fontSize: 24 }
13232
+ * }]
13233
+ * });
13234
+ *
13235
+ * // 监听特定帧事件
13236
+ * lottie.on('@30', () => {
13237
+ * console.log('到达第 30 帧');
13238
+ * });
13239
+ *
13240
+ * // 绑定点击热区
13241
+ * lottie.onTap('buttonLayer', () => {
13242
+ * console.log('按钮被点击');
13243
+ * });
13244
+ * ```
13245
+ */
12971
13246
  class Lottie extends Component {
13247
+ /**
13248
+ * 构造 Lottie 组件
13249
+ * @param options - Lottie 配置选项
13250
+ * @param options.resource - Lottie JSON 资源名称
13251
+ * @param options.autoStart - 是否自动开始播放
13252
+ */
12972
13253
  constructor(options) {
12973
13254
  super();
13255
+ /** 待替换的数据 */
13256
+ this._replaceData = null;
13257
+ /** 资源加载状态 */
12974
13258
  this.loadStatus = false;
13259
+ /** 首次播放回调 */
12975
13260
  this.firstPlay = null;
13261
+ /** 前一次的插槽内容 */
12976
13262
  this.prevSlot = {};
13263
+ /** 当前的插槽内容 */
12977
13264
  this.currentSlot = {};
12978
13265
  this.options = Object.assign({ autoStart: false }, options);
12979
13266
  this.on('success', () => {
@@ -13024,6 +13311,14 @@ class Lottie extends Component {
13024
13311
  });
13025
13312
  this.anim.playSegment(this.playParamsHandle(params), expandOpts);
13026
13313
  }
13314
+ replaceData(data) {
13315
+ if (data) {
13316
+ if (this.anim)
13317
+ this.anim.replaceData(data);
13318
+ else
13319
+ this._replaceData = data;
13320
+ }
13321
+ }
13027
13322
  playParamsHandle(params) {
13028
13323
  let p = [].concat(params);
13029
13324
  const { keyframes } = this.anim;
@@ -13050,6 +13345,7 @@ class Lottie extends Component {
13050
13345
  });
13051
13346
  }
13052
13347
  }
13348
+ /** 组件名称 */
13053
13349
  Lottie.componentName = 'Lottie';
13054
13350
 
13055
13351
  resource.registerResourceType('LOTTIE');