@eva/plugin-renderer-lottie 2.0.1-beta.3 → 2.0.1-beta.30
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/EVA.plugin.renderer.lottie.js +311 -177
- package/dist/EVA.plugin.renderer.lottie.min.js +1 -1
- package/dist/plugin-renderer-lottie.cjs.js +464 -196
- package/dist/plugin-renderer-lottie.cjs.prod.js +1 -1
- package/dist/plugin-renderer-lottie.d.ts +80 -0
- package/dist/plugin-renderer-lottie.esm.js +469 -201
- package/package.json +3 -3
|
@@ -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 {
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
2182
|
-
this.o = createSizedArray$
|
|
2183
|
-
this.i = createSizedArray$
|
|
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$
|
|
2228
|
-
this.i = this.i.concat(createSizedArray$
|
|
2229
|
-
this.o = this.o.concat(createSizedArray$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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$
|
|
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
|
-
|
|
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
|
-
|
|
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,7 +10571,153 @@ function createSizedArray(len) {
|
|
|
10557
10571
|
return Array.apply(null, { length: len });
|
|
10558
10572
|
}
|
|
10559
10573
|
|
|
10560
|
-
|
|
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
|
+
}
|
|
10561
10721
|
|
|
10562
10722
|
class MatrixHelper extends Matrix$1 {
|
|
10563
10723
|
reset() {
|
|
@@ -10632,7 +10792,7 @@ class MatrixHelper extends Matrix$1 {
|
|
|
10632
10792
|
* @class
|
|
10633
10793
|
* @private
|
|
10634
10794
|
*/
|
|
10635
|
-
class
|
|
10795
|
+
class TextGlyphsElement extends Graphics {
|
|
10636
10796
|
/**
|
|
10637
10797
|
* ShapeElement constructor
|
|
10638
10798
|
*/
|
|
@@ -10678,15 +10838,14 @@ class TextElement extends Graphics {
|
|
|
10678
10838
|
|
|
10679
10839
|
buildNewText() {
|
|
10680
10840
|
const documentData = this.lottieLayer.textProperty.currentData;
|
|
10681
|
-
this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0);
|
|
10841
|
+
this.renderedLetters = createSizedArray$1(documentData.l ? documentData.l.length : 0);
|
|
10682
10842
|
let hasFill = false;
|
|
10683
10843
|
if (documentData.fc) {
|
|
10684
10844
|
hasFill = true;
|
|
10685
10845
|
this._values.fill = Tools.rgb2hex(
|
|
10686
|
-
|
|
10687
|
-
|
|
10688
|
-
|
|
10689
|
-
// }),
|
|
10846
|
+
documentData.fc.map(item => {
|
|
10847
|
+
return item > 1 ? item : item * 255;
|
|
10848
|
+
}),
|
|
10690
10849
|
documentData.fc,
|
|
10691
10850
|
);
|
|
10692
10851
|
} else {
|
|
@@ -10743,8 +10902,7 @@ class TextElement extends Graphics {
|
|
|
10743
10902
|
shapes = shapeData.shapes ? shapeData.shapes[0].it : [];
|
|
10744
10903
|
jLen = shapes.length;
|
|
10745
10904
|
matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100);
|
|
10746
|
-
commands = createSizedArray(jLen - 1);
|
|
10747
|
-
window.$commands.push(commands);
|
|
10905
|
+
commands = createSizedArray$1(jLen - 1);
|
|
10748
10906
|
let commandsCounter = 0;
|
|
10749
10907
|
for (j = 0; j < jLen; j += 1) {
|
|
10750
10908
|
if (shapes[j].ty === 'sh') {
|
|
@@ -10959,27 +11117,7 @@ class TextElement extends Graphics {
|
|
|
10959
11117
|
* @param {*} transform
|
|
10960
11118
|
*/
|
|
10961
11119
|
updateLottieTransform(transform) {
|
|
10962
|
-
|
|
10963
|
-
this.x = transform.p.v[0];
|
|
10964
|
-
this.y = transform.p.v[1];
|
|
10965
|
-
} else {
|
|
10966
|
-
this.x = transform.px.v;
|
|
10967
|
-
this.y = transform.py.v;
|
|
10968
|
-
}
|
|
10969
|
-
|
|
10970
|
-
this.pivot.x = transform.a.v[0];
|
|
10971
|
-
this.pivot.y = transform.a.v[1];
|
|
10972
|
-
|
|
10973
|
-
this.scale.x = transform.s.v[0];
|
|
10974
|
-
this.scale.y = transform.s.v[1];
|
|
10975
|
-
|
|
10976
|
-
if (transform.r) {
|
|
10977
|
-
this.rotation = transform.r.v + transform.orientation;
|
|
10978
|
-
} else if (transform.rz) {
|
|
10979
|
-
this.rotation = transform.rz.v + transform.or.v[2];
|
|
10980
|
-
}
|
|
10981
|
-
|
|
10982
|
-
this.alpha = transform.o.v;
|
|
11120
|
+
updateTransformByHierarchy(this, transform, this.hierarchy);
|
|
10983
11121
|
}
|
|
10984
11122
|
|
|
10985
11123
|
/**
|
|
@@ -11045,27 +11183,7 @@ class SolidElement extends Graphics {
|
|
|
11045
11183
|
* @param {*} transform
|
|
11046
11184
|
*/
|
|
11047
11185
|
updateLottieTransform(transform) {
|
|
11048
|
-
|
|
11049
|
-
this.x = transform.p.v[0];
|
|
11050
|
-
this.y = transform.p.v[1];
|
|
11051
|
-
} else {
|
|
11052
|
-
this.x = transform.px.v;
|
|
11053
|
-
this.y = transform.py.v;
|
|
11054
|
-
}
|
|
11055
|
-
|
|
11056
|
-
this.pivot.x = transform.a.v[0];
|
|
11057
|
-
this.pivot.y = transform.a.v[1];
|
|
11058
|
-
|
|
11059
|
-
this.scale.x = transform.s.v[0];
|
|
11060
|
-
this.scale.y = transform.s.v[1];
|
|
11061
|
-
|
|
11062
|
-
if (transform.r) {
|
|
11063
|
-
this.rotation = transform.r.v + transform.orientation;
|
|
11064
|
-
} else if (transform.rz) {
|
|
11065
|
-
this.rotation = transform.rz.v + transform.or.v[2];
|
|
11066
|
-
}
|
|
11067
|
-
|
|
11068
|
-
this.alpha = transform.o.v;
|
|
11186
|
+
updateTransformByHierarchy(this, transform, this.hierarchy);
|
|
11069
11187
|
}
|
|
11070
11188
|
|
|
11071
11189
|
/**
|
|
@@ -11089,18 +11207,17 @@ class SpriteElement extends Sprite {
|
|
|
11089
11207
|
* @param {object} config layer data information
|
|
11090
11208
|
*/
|
|
11091
11209
|
constructor(lottieLayer, imageInfo) {
|
|
11092
|
-
const {
|
|
11093
|
-
super(
|
|
11210
|
+
const { texture: texturePromise } = imageInfo;
|
|
11211
|
+
super();
|
|
11094
11212
|
this.label = lottieLayer.fullname;
|
|
11095
11213
|
|
|
11096
|
-
|
|
11097
|
-
|
|
11098
|
-
|
|
11099
|
-
|
|
11100
|
-
|
|
11101
|
-
|
|
11214
|
+
texturePromise
|
|
11215
|
+
.then(texture => {
|
|
11216
|
+
this.texture = texture;
|
|
11217
|
+
})
|
|
11218
|
+
.catch(e => {
|
|
11219
|
+
console.error(e);
|
|
11102
11220
|
});
|
|
11103
|
-
}
|
|
11104
11221
|
|
|
11105
11222
|
this.lottieLayer = lottieLayer;
|
|
11106
11223
|
|
|
@@ -11141,27 +11258,7 @@ class SpriteElement extends Sprite {
|
|
|
11141
11258
|
* @param {*} transform
|
|
11142
11259
|
*/
|
|
11143
11260
|
updateLottieTransform(transform) {
|
|
11144
|
-
|
|
11145
|
-
this.x = transform.p.v[0];
|
|
11146
|
-
this.y = transform.p.v[1];
|
|
11147
|
-
} else {
|
|
11148
|
-
this.x = transform.px.v;
|
|
11149
|
-
this.y = transform.py.v;
|
|
11150
|
-
}
|
|
11151
|
-
|
|
11152
|
-
this.pivot.x = transform.a.v[0];
|
|
11153
|
-
this.pivot.y = transform.a.v[1];
|
|
11154
|
-
|
|
11155
|
-
this.scale.x = transform.s.v[0];
|
|
11156
|
-
this.scale.y = transform.s.v[1];
|
|
11157
|
-
|
|
11158
|
-
if (transform.r) {
|
|
11159
|
-
this.rotation = transform.r.v + transform.orientation;
|
|
11160
|
-
} else if (transform.rz) {
|
|
11161
|
-
this.rotation = transform.rz.v + transform.or.v[2];
|
|
11162
|
-
}
|
|
11163
|
-
|
|
11164
|
-
this.alpha = transform.o.v;
|
|
11261
|
+
updateTransformByHierarchy(this, transform, this.hierarchy);
|
|
11165
11262
|
}
|
|
11166
11263
|
|
|
11167
11264
|
/**
|
|
@@ -11173,32 +11270,6 @@ class SpriteElement extends Sprite {
|
|
|
11173
11270
|
}
|
|
11174
11271
|
}
|
|
11175
11272
|
|
|
11176
|
-
class BaseTexture extends EventEmitter {
|
|
11177
|
-
constructor(url) {
|
|
11178
|
-
super();
|
|
11179
|
-
this.texture = Texture$1.EMPTY;
|
|
11180
|
-
this.img = new Image();
|
|
11181
|
-
this.img.src = url;
|
|
11182
|
-
this.img.onload = () => {
|
|
11183
|
-
this.texture = Texture$1.from(this.img);
|
|
11184
|
-
this.emit('loaded');
|
|
11185
|
-
};
|
|
11186
|
-
this.img.onerror = () => {
|
|
11187
|
-
this.emit('error');
|
|
11188
|
-
};
|
|
11189
|
-
}
|
|
11190
|
-
}
|
|
11191
|
-
|
|
11192
|
-
class Texture {
|
|
11193
|
-
constructor(url) {
|
|
11194
|
-
this.baseTexture = new BaseTexture(url);
|
|
11195
|
-
}
|
|
11196
|
-
|
|
11197
|
-
static from(url) {
|
|
11198
|
-
return new Texture(url);
|
|
11199
|
-
}
|
|
11200
|
-
}
|
|
11201
|
-
|
|
11202
11273
|
const regHttp = /^(https?:)?\/\//;
|
|
11203
11274
|
|
|
11204
11275
|
/**
|
|
@@ -11254,25 +11325,20 @@ class LoadTexture extends Eventer {
|
|
|
11254
11325
|
this.assets.forEach(asset => {
|
|
11255
11326
|
const id = asset.id;
|
|
11256
11327
|
const url = createUrl(asset, this.prefix);
|
|
11257
|
-
const
|
|
11258
|
-
this.textures[id] =
|
|
11328
|
+
const texturePromise = Assets.load(url);
|
|
11329
|
+
this.textures[id] = texturePromise;
|
|
11259
11330
|
this._total++;
|
|
11260
|
-
|
|
11261
|
-
|
|
11262
|
-
this.emit('update');
|
|
11263
|
-
if (this._received + this._failed >= this._total) this._onComplete();
|
|
11264
|
-
} else {
|
|
11265
|
-
texture.baseTexture.once('loaded', () => {
|
|
11331
|
+
texturePromise
|
|
11332
|
+
.then(() => {
|
|
11266
11333
|
this._received++;
|
|
11267
11334
|
this.emit('update');
|
|
11268
11335
|
if (this._received + this._failed >= this._total) this._onComplete();
|
|
11269
|
-
})
|
|
11270
|
-
|
|
11336
|
+
})
|
|
11337
|
+
.catch(e => {
|
|
11271
11338
|
this._failed++;
|
|
11272
11339
|
this.emit('update');
|
|
11273
11340
|
if (this._received + this._failed >= this._total) this._onComplete();
|
|
11274
11341
|
});
|
|
11275
|
-
}
|
|
11276
11342
|
});
|
|
11277
11343
|
}
|
|
11278
11344
|
|
|
@@ -11411,6 +11477,29 @@ function loadJson(path) {
|
|
|
11411
11477
|
return new LoadJson(path);
|
|
11412
11478
|
}
|
|
11413
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
|
+
|
|
11414
11503
|
/**
|
|
11415
11504
|
* an animation group, store and compute frame information, one lottie animate one AnimationGroup
|
|
11416
11505
|
* @class
|
|
@@ -11439,6 +11528,7 @@ class AnimationGroup extends Eventer {
|
|
|
11439
11528
|
* @param {boolean} [options.depthTest=true] enable depth test for 3d layer
|
|
11440
11529
|
* @param {boolean} [options.maskComp=false] add mask for each comp
|
|
11441
11530
|
* @param {string} [options.prefix=''] assets url prefix, look like link path
|
|
11531
|
+
* @param {boolean} [options.replaceData=''] assets url prefix, look like link path
|
|
11442
11532
|
*/
|
|
11443
11533
|
constructor(options) {
|
|
11444
11534
|
super();
|
|
@@ -11669,7 +11759,14 @@ class AnimationGroup extends Eventer {
|
|
|
11669
11759
|
|
|
11670
11760
|
if (options.keyframes) {
|
|
11671
11761
|
if (!this._prefix && options.keyframes.prefix) this._prefix = options.keyframes.prefix;
|
|
11672
|
-
|
|
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
|
+
}
|
|
11673
11770
|
} else if (options.path) {
|
|
11674
11771
|
let prefix = '';
|
|
11675
11772
|
if (options.path.lastIndexOf('\\') !== -1) {
|
|
@@ -11681,7 +11778,14 @@ class AnimationGroup extends Eventer {
|
|
|
11681
11778
|
|
|
11682
11779
|
this.jsonLoader = loadJson(options.path);
|
|
11683
11780
|
this.jsonLoader.once('success', response => {
|
|
11684
|
-
|
|
11781
|
+
if (!options.replaceData) {
|
|
11782
|
+
this._setupDate(response);
|
|
11783
|
+
} else {
|
|
11784
|
+
this._response = response;
|
|
11785
|
+
if (this._replaceData) {
|
|
11786
|
+
this._setupReplaceData();
|
|
11787
|
+
}
|
|
11788
|
+
}
|
|
11685
11789
|
});
|
|
11686
11790
|
this.jsonLoader.once('error', error => {
|
|
11687
11791
|
this.emit('error', error);
|
|
@@ -11689,6 +11793,43 @@ class AnimationGroup extends Eventer {
|
|
|
11689
11793
|
}
|
|
11690
11794
|
}
|
|
11691
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
|
+
|
|
11692
11833
|
/**
|
|
11693
11834
|
* 安装动画数据
|
|
11694
11835
|
* @private
|
|
@@ -11819,8 +11960,20 @@ class AnimationGroup extends Eventer {
|
|
|
11819
11960
|
st,
|
|
11820
11961
|
},
|
|
11821
11962
|
};
|
|
11822
|
-
session.fontManager.addChars(data.chars);
|
|
11963
|
+
session.fontManager.addChars(data.chars || []);
|
|
11823
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
|
+
}
|
|
11824
11977
|
|
|
11825
11978
|
this._buildElements(session);
|
|
11826
11979
|
|
|
@@ -12056,7 +12209,10 @@ class AnimationGroup extends Eventer {
|
|
|
12056
12209
|
// texture,
|
|
12057
12210
|
// });
|
|
12058
12211
|
} else {
|
|
12059
|
-
lottieLayer.display = new SpriteElement(lottieLayer, {
|
|
12212
|
+
lottieLayer.display = new SpriteElement(lottieLayer, {
|
|
12213
|
+
asset,
|
|
12214
|
+
texture,
|
|
12215
|
+
});
|
|
12060
12216
|
}
|
|
12061
12217
|
return lottieLayer;
|
|
12062
12218
|
}
|
|
@@ -12099,7 +12255,13 @@ class AnimationGroup extends Eventer {
|
|
|
12099
12255
|
_extraText(layer, session) {
|
|
12100
12256
|
layer.global = session;
|
|
12101
12257
|
const lottieLayer = new TextLottieLayer(layer, session);
|
|
12102
|
-
|
|
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
|
+
|
|
12103
12265
|
return lottieLayer;
|
|
12104
12266
|
}
|
|
12105
12267
|
|
|
@@ -12284,11 +12446,11 @@ class AnimationGroup extends Eventer {
|
|
|
12284
12446
|
* @param {*} image url | texture
|
|
12285
12447
|
* @return {this}
|
|
12286
12448
|
*/
|
|
12287
|
-
replaceImageByQuerySelector(selector, image = Texture
|
|
12449
|
+
replaceImageByQuerySelector(selector, image = Texture.EMPTY) {
|
|
12288
12450
|
const layerDisplay = this.getDisplayByQuerySelector(selector);
|
|
12289
12451
|
if (layerDisplay && layerDisplay.isSprite) {
|
|
12290
12452
|
const texture =
|
|
12291
|
-
typeof image === 'string' ? Texture
|
|
12453
|
+
typeof image === 'string' ? Texture.from(image, { resourceOptions: { crossorigin: '*' } }) : image;
|
|
12292
12454
|
layerDisplay.texture = texture;
|
|
12293
12455
|
}
|
|
12294
12456
|
return this;
|
|
@@ -12301,7 +12463,7 @@ class AnimationGroup extends Eventer {
|
|
|
12301
12463
|
* @param {*} image url | texture or array[url | texture]
|
|
12302
12464
|
* @return {this}
|
|
12303
12465
|
*/
|
|
12304
|
-
replaceImageByQuerySelectorAll(selector, image = [Texture
|
|
12466
|
+
replaceImageByQuerySelectorAll(selector, image = [Texture.EMPTY]) {
|
|
12305
12467
|
const layers = this.querySelectorAll(selector);
|
|
12306
12468
|
const isArrImage = Tools.isArray(image);
|
|
12307
12469
|
layers.forEach((layer, idx) => {
|
|
@@ -12310,7 +12472,7 @@ class AnimationGroup extends Eventer {
|
|
|
12310
12472
|
const imageItem = isArrImage ? image[idx] : image;
|
|
12311
12473
|
const texture =
|
|
12312
12474
|
typeof imageItem === 'string'
|
|
12313
|
-
? Texture
|
|
12475
|
+
? Texture.from(imageItem, { resourceOptions: { crossorigin: '*' } })
|
|
12314
12476
|
: imageItem;
|
|
12315
12477
|
layerDisplay.texture = texture;
|
|
12316
12478
|
}
|
|
@@ -12334,10 +12496,11 @@ class AnimationGroup extends Eventer {
|
|
|
12334
12496
|
*/
|
|
12335
12497
|
update(snippetCache, firstFrame = false) {
|
|
12336
12498
|
if (!this.living || !this.isDisplayLoaded || (this.isPaused && !firstFrame)) return;
|
|
12337
|
-
|
|
12338
|
-
const
|
|
12339
|
-
|
|
12340
|
-
|
|
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
|
+
}
|
|
12341
12504
|
this.root.updateFrame(correctedFrameNum);
|
|
12342
12505
|
|
|
12343
12506
|
const np = correctedFrameNum >> 0;
|
|
@@ -12439,6 +12602,7 @@ class AnimationGroup extends Eventer {
|
|
|
12439
12602
|
* @param {boolean} [options.alternate=false] alternate direction every round
|
|
12440
12603
|
* @param {number} [options.wait=0] need wait how much millisecond to start
|
|
12441
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
|
|
12442
12606
|
* @return {this}
|
|
12443
12607
|
*/
|
|
12444
12608
|
playSegment(name, options = {}) {
|
|
@@ -12462,6 +12626,11 @@ class AnimationGroup extends Eventer {
|
|
|
12462
12626
|
if (Tools.isBoolean(options.alternate)) this.alternate = options.alternate;
|
|
12463
12627
|
if (Tools.isNumber(options.wait)) this.wait = options.wait;
|
|
12464
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
|
+
}
|
|
12465
12634
|
|
|
12466
12635
|
this.replay();
|
|
12467
12636
|
return this;
|
|
@@ -12567,9 +12736,15 @@ class AnimationGroup extends Eventer {
|
|
|
12567
12736
|
this._repeatsCut = this.repeats;
|
|
12568
12737
|
this._delayCut = this.delay;
|
|
12569
12738
|
this.living = true;
|
|
12570
|
-
|
|
12739
|
+
// 根据播放方向设置初始帧位置
|
|
12740
|
+
if (this.direction === -1) {
|
|
12741
|
+
// 倒着播放从duration开始
|
|
12742
|
+
this.frameNum = this.duration;
|
|
12743
|
+
} else {
|
|
12744
|
+
// 正常播放从0开始
|
|
12745
|
+
this.frameNum = 0;
|
|
12746
|
+
}
|
|
12571
12747
|
this.duration = Math.floor(this.endFrame - this.beginFrame);
|
|
12572
|
-
this.direction = 1;
|
|
12573
12748
|
return this;
|
|
12574
12749
|
}
|
|
12575
12750
|
|
|
@@ -12876,7 +13051,7 @@ class AnimationManager extends Eventer {
|
|
|
12876
13051
|
}
|
|
12877
13052
|
}
|
|
12878
13053
|
|
|
12879
|
-
const { major } = iOSVersion(
|
|
13054
|
+
const { major } = iOSVersion(globalThis.navigator.userAgent) || {};
|
|
12880
13055
|
|
|
12881
13056
|
/**
|
|
12882
13057
|
* dataURL 转成 blob
|
|
@@ -12938,6 +13113,12 @@ let LottieSystem = class LottieSystem extends Renderer {
|
|
|
12938
13113
|
'update',
|
|
12939
13114
|
];
|
|
12940
13115
|
}
|
|
13116
|
+
/**
|
|
13117
|
+
* System 初始化用,可以配置参数,游戏未开始
|
|
13118
|
+
*
|
|
13119
|
+
* System init, set params, game is not begain
|
|
13120
|
+
* @param param init params
|
|
13121
|
+
*/
|
|
12941
13122
|
init() {
|
|
12942
13123
|
this.renderSystem = this.game.getSystem('Renderer');
|
|
12943
13124
|
this.app = this.renderSystem.application;
|
|
@@ -12955,22 +13136,28 @@ let LottieSystem = class LottieSystem extends Renderer {
|
|
|
12955
13136
|
});
|
|
12956
13137
|
}
|
|
12957
13138
|
add(changed) {
|
|
13139
|
+
var _a, _b;
|
|
12958
13140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
12959
13141
|
this.manager = new AnimationManager(this.app);
|
|
12960
13142
|
const component = changed.component;
|
|
12961
13143
|
const container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
|
|
12962
13144
|
if (!container)
|
|
12963
13145
|
return;
|
|
12964
|
-
const
|
|
12965
|
-
const
|
|
13146
|
+
const _c = component.options, { resource: rn } = _c, otherOpts = __rest(_c, ["resource"]);
|
|
13147
|
+
const res = yield resource.getResource(rn);
|
|
13148
|
+
const data = res.data;
|
|
13149
|
+
const url = ((_b = (_a = res.src) === null || _a === void 0 ? void 0 : _a.json) === null || _b === void 0 ? void 0 : _b.url) || '';
|
|
12966
13150
|
const json = Object.assign({}, (data.json || {}));
|
|
12967
13151
|
const assets = json.assets || [];
|
|
12968
13152
|
assets.forEach(item => {
|
|
12969
13153
|
if (item.p)
|
|
12970
13154
|
item.p = imageHandle(item.p);
|
|
12971
13155
|
});
|
|
12972
|
-
const anim = this.manager.parseAnimation(Object.assign({ keyframes: json }, otherOpts));
|
|
13156
|
+
const anim = this.manager.parseAnimation(Object.assign({ keyframes: json, prefix: this.getDir(url) }, otherOpts));
|
|
12973
13157
|
component.anim = anim;
|
|
13158
|
+
if (component._replaceData) {
|
|
13159
|
+
anim.replaceData(component._replaceData);
|
|
13160
|
+
}
|
|
12974
13161
|
container.addChildAt(anim.group, 0);
|
|
12975
13162
|
this.managerLife.forEach(eventName => {
|
|
12976
13163
|
anim.on(eventName, e => component.emit(eventName, e));
|
|
@@ -12979,6 +13166,11 @@ let LottieSystem = class LottieSystem extends Renderer {
|
|
|
12979
13166
|
component.emit('success', {});
|
|
12980
13167
|
});
|
|
12981
13168
|
}
|
|
13169
|
+
getDir(url) {
|
|
13170
|
+
if (!url)
|
|
13171
|
+
return url;
|
|
13172
|
+
return new URL('./', url).href;
|
|
13173
|
+
}
|
|
12982
13174
|
remove(changed) {
|
|
12983
13175
|
const component = changed.component;
|
|
12984
13176
|
const container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
|
|
@@ -12997,12 +13189,78 @@ LottieSystem = __decorate([
|
|
|
12997
13189
|
], LottieSystem);
|
|
12998
13190
|
var LottieSystem$1 = LottieSystem;
|
|
12999
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
|
+
*/
|
|
13000
13246
|
class Lottie extends Component {
|
|
13247
|
+
/**
|
|
13248
|
+
* 构造 Lottie 组件
|
|
13249
|
+
* @param options - Lottie 配置选项
|
|
13250
|
+
* @param options.resource - Lottie JSON 资源名称
|
|
13251
|
+
* @param options.autoStart - 是否自动开始播放
|
|
13252
|
+
*/
|
|
13001
13253
|
constructor(options) {
|
|
13002
13254
|
super();
|
|
13255
|
+
/** 待替换的数据 */
|
|
13256
|
+
this._replaceData = null;
|
|
13257
|
+
/** 资源加载状态 */
|
|
13003
13258
|
this.loadStatus = false;
|
|
13259
|
+
/** 首次播放回调 */
|
|
13004
13260
|
this.firstPlay = null;
|
|
13261
|
+
/** 前一次的插槽内容 */
|
|
13005
13262
|
this.prevSlot = {};
|
|
13263
|
+
/** 当前的插槽内容 */
|
|
13006
13264
|
this.currentSlot = {};
|
|
13007
13265
|
this.options = Object.assign({ autoStart: false }, options);
|
|
13008
13266
|
this.on('success', () => {
|
|
@@ -13031,7 +13289,10 @@ class Lottie extends Component {
|
|
|
13031
13289
|
this.currentSlot[name] = Sprite.from(value);
|
|
13032
13290
|
}
|
|
13033
13291
|
else if (type === 'TEXT') {
|
|
13034
|
-
this.currentSlot[name] = new Text(
|
|
13292
|
+
this.currentSlot[name] = new Text({
|
|
13293
|
+
text: value,
|
|
13294
|
+
style: new TextStyle(style),
|
|
13295
|
+
});
|
|
13035
13296
|
}
|
|
13036
13297
|
if (x)
|
|
13037
13298
|
this.currentSlot[name].x = x;
|
|
@@ -13050,6 +13311,14 @@ class Lottie extends Component {
|
|
|
13050
13311
|
});
|
|
13051
13312
|
this.anim.playSegment(this.playParamsHandle(params), expandOpts);
|
|
13052
13313
|
}
|
|
13314
|
+
replaceData(data) {
|
|
13315
|
+
if (data) {
|
|
13316
|
+
if (this.anim)
|
|
13317
|
+
this.anim.replaceData(data);
|
|
13318
|
+
else
|
|
13319
|
+
this._replaceData = data;
|
|
13320
|
+
}
|
|
13321
|
+
}
|
|
13053
13322
|
playParamsHandle(params) {
|
|
13054
13323
|
let p = [].concat(params);
|
|
13055
13324
|
const { keyframes } = this.anim;
|
|
@@ -13066,9 +13335,7 @@ class Lottie extends Component {
|
|
|
13066
13335
|
this.on('success', () => {
|
|
13067
13336
|
const ele = this.anim.querySelector(name);
|
|
13068
13337
|
const display = ele.display;
|
|
13069
|
-
g.
|
|
13070
|
-
g.drawRect(0, 0, 100, 100);
|
|
13071
|
-
g.endFill();
|
|
13338
|
+
g.rect(0, 0, 100, 100).fill(0xffffff);
|
|
13072
13339
|
g.alpha = 0;
|
|
13073
13340
|
display.addChild(g);
|
|
13074
13341
|
ele.display.interactive = true;
|
|
@@ -13078,6 +13345,7 @@ class Lottie extends Component {
|
|
|
13078
13345
|
});
|
|
13079
13346
|
}
|
|
13080
13347
|
}
|
|
13348
|
+
/** 组件名称 */
|
|
13081
13349
|
Lottie.componentName = 'Lottie';
|
|
13082
13350
|
|
|
13083
13351
|
resource.registerResourceType('LOTTIE');
|