@eva/plugin-renderer-lottie 2.0.2 → 2.1.0-beta.2

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.
@@ -30,6 +30,12 @@ declare interface IOptions {
30
30
  width?: number;
31
31
  height?: number;
32
32
  replaceData?: boolean;
33
+ autoStart?: boolean;
34
+ autoplay?: boolean;
35
+ loop?: boolean;
36
+ speed?: number;
37
+ onComplete?: () => void;
38
+ onLoopComplete?: () => void;
33
39
  }
34
40
 
35
41
  /**
@@ -99,6 +105,15 @@ export declare class Lottie extends Component {
99
105
  anim: any;
100
106
  /** Lottie 配置选项 */
101
107
  options: ExtendOptions;
108
+ /** 是否资源就绪后自动播放 */
109
+ autoplay: boolean;
110
+ /** 是否循环播放 */
111
+ loop: boolean;
112
+ /** 完成事件回调 */
113
+ onComplete?: () => void;
114
+ /** 循环完成事件回调 */
115
+ onLoopComplete?: () => void;
116
+ private _speed;
102
117
  /** 资源加载状态 */
103
118
  loadStatus: boolean;
104
119
  /** 首次播放回调 */
@@ -118,10 +133,18 @@ export declare class Lottie extends Component {
118
133
  * @param options.autoStart - 是否自动开始播放
119
134
  */
120
135
  constructor(options: IOptions);
136
+ get speed(): number;
137
+ set speed(value: number);
121
138
  play(params?: number[], expandOpts?: IExpandOpts): void;
139
+ pause(): void;
140
+ stop(): void;
141
+ goToFrame(frame: number): void;
142
+ load(): void;
122
143
  replaceData(data: Record<string, string>): void;
123
144
  playParamsHandle(params: any): any[];
124
145
  onTap(name: any, callback: any): void;
146
+ destroy(): void;
147
+ private applySpeed;
125
148
  }
126
149
 
127
150
  export declare class LottieSystem extends Renderer {
@@ -13057,52 +13057,36 @@ class AnimationManager extends Eventer {
13057
13057
  }
13058
13058
  }
13059
13059
 
13060
- const { major } = iOSVersion(globalThis.navigator.userAgent) || {};
13061
-
13062
- /**
13063
- * dataURL 转成 blob
13064
- * @param dataURL
13065
- * @return blob
13066
- */
13067
- function dataURL2blob(dataURL) {
13068
- let binaryString = atob(dataURL.split(',')[1]);
13069
- let arrayBuffer = new ArrayBuffer(binaryString.length);
13070
- let intArray = new Uint8Array(arrayBuffer);
13071
- let mime = dataURL.split(',')[0].match(/:(.*?);/)[1];
13072
- for (let i = 0, j = binaryString.length; i < j; i++) {
13073
- intArray[i] = binaryString.charCodeAt(i);
13074
- }
13075
- let data = [intArray];
13076
- let result;
13077
- try {
13078
- result = new Blob(data, { type: mime });
13079
- } catch (error) {
13080
- console.log(error);
13081
- }
13082
- return result;
13083
- }
13084
-
13085
- /**
13086
- * 创建新的URL 对象表示指定的 File 对象或 Blob 对象。
13087
- * @param {string} dataURL base64
13088
- */
13089
- function dataURL2ObjUrl(dataURL) {
13090
- window.URL = window.URL || window.webkitURL;
13091
- if (window.URL && URL.createObjectURL) {
13092
- // dataURL2blob 此方法需额外定义
13093
- const blob = dataURL2blob(dataURL);
13094
- return URL.createObjectURL(blob);
13095
- }
13096
- return dataURL;
13097
- }
13098
-
13099
- function imageHandle(source) {
13100
- const isBase64Reg = /^data:image\/png;base64/;
13101
- if (major <= 8 && isBase64Reg.test(source)) {
13102
- return dataURL2ObjUrl(source);
13103
- }
13104
-
13105
- return source;
13060
+ const getIOSMajor = () => {
13061
+ var _a, _b;
13062
+ const userAgent = ((_a = globalThis.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) || '';
13063
+ return (_b = iOSVersion(userAgent)) === null || _b === void 0 ? void 0 : _b.major;
13064
+ };
13065
+ const dataURL2blob = (dataURL) => {
13066
+ var _a;
13067
+ const binaryString = atob(dataURL.split(',')[1]);
13068
+ const arrayBuffer = new ArrayBuffer(binaryString.length);
13069
+ const intArray = new Uint8Array(arrayBuffer);
13070
+ const mime = ((_a = dataURL.split(',')[0].match(/:(.*?);/)) === null || _a === void 0 ? void 0 : _a[1]) || 'image/png';
13071
+ for (let i = 0, j = binaryString.length; i < j; i++) {
13072
+ intArray[i] = binaryString.charCodeAt(i);
13073
+ }
13074
+ return new Blob([intArray], { type: mime });
13075
+ };
13076
+ const dataURL2ObjUrl = (dataURL) => {
13077
+ const urlFactory = globalThis.URL || window.webkitURL;
13078
+ if (urlFactory === null || urlFactory === void 0 ? void 0 : urlFactory.createObjectURL) {
13079
+ return urlFactory.createObjectURL(dataURL2blob(dataURL));
13080
+ }
13081
+ return dataURL;
13082
+ };
13083
+ function imageHandle(source) {
13084
+ const isBase64Reg = /^data:image\/png;base64/;
13085
+ const major = getIOSMajor();
13086
+ if (major && major <= 8 && isBase64Reg.test(source)) {
13087
+ return dataURL2ObjUrl(source);
13088
+ }
13089
+ return source;
13106
13090
  }
13107
13091
 
13108
13092
  let LottieSystem = class LottieSystem extends Renderer {
@@ -13257,9 +13241,15 @@ class Lottie extends Component {
13257
13241
  * @param options.autoStart - 是否自动开始播放
13258
13242
  */
13259
13243
  constructor(options) {
13244
+ var _a, _b, _c, _d;
13260
13245
  super();
13261
13246
  /** 待替换的数据 */
13262
13247
  this._replaceData = null;
13248
+ /** 是否资源就绪后自动播放 */
13249
+ this.autoplay = false;
13250
+ /** 是否循环播放 */
13251
+ this.loop = false;
13252
+ this._speed = 1;
13263
13253
  /** 资源加载状态 */
13264
13254
  this.loadStatus = false;
13265
13255
  /** 首次播放回调 */
@@ -13268,27 +13258,50 @@ class Lottie extends Component {
13268
13258
  this.prevSlot = {};
13269
13259
  /** 当前的插槽内容 */
13270
13260
  this.currentSlot = {};
13271
- this.options = Object.assign({ autoStart: false }, options);
13261
+ const autoStart = (_b = (_a = options.autoStart) !== null && _a !== void 0 ? _a : options.autoplay) !== null && _b !== void 0 ? _b : false;
13262
+ this.options = Object.assign(Object.assign({}, options), { autoStart });
13263
+ this.autoplay = autoStart;
13264
+ this.loop = (_c = options.loop) !== null && _c !== void 0 ? _c : false;
13265
+ this._speed = (_d = options.speed) !== null && _d !== void 0 ? _d : 1;
13266
+ this.onComplete = options.onComplete;
13267
+ this.onLoopComplete = options.onLoopComplete;
13268
+ if (this.onComplete)
13269
+ this.on('complete', this.onComplete);
13270
+ if (this.onLoopComplete)
13271
+ this.on('loopComplete', this.onLoopComplete);
13272
13272
  this.on('success', () => {
13273
13273
  this.loadStatus = true;
13274
+ this.applySpeed();
13274
13275
  const { ip, op } = this.anim.keyframes;
13275
13276
  for (let i = ip; i <= op; i++) {
13276
13277
  const event = `@${i}`;
13277
13278
  this.anim.on(event, e => this.emit(event, e));
13278
13279
  }
13280
+ if (this.options.autoStart)
13281
+ this.play();
13279
13282
  this.firstPlay && this.firstPlay();
13280
13283
  });
13281
13284
  }
13285
+ get speed() {
13286
+ return this._speed;
13287
+ }
13288
+ set speed(value) {
13289
+ this._speed = value;
13290
+ this.options.speed = value;
13291
+ this.applySpeed();
13292
+ }
13282
13293
  play(params = [], expandOpts = {
13283
13294
  repeats: 0,
13284
13295
  }) {
13296
+ var _a;
13285
13297
  if (!this.loadStatus) {
13286
13298
  this.firstPlay = () => {
13287
13299
  this.play(params, expandOpts);
13288
13300
  };
13289
13301
  return;
13290
13302
  }
13291
- const { slot = [] } = expandOpts;
13303
+ const playOptions = Object.assign(Object.assign({}, expandOpts), { repeats: (_a = expandOpts.repeats) !== null && _a !== void 0 ? _a : (this.loop ? -1 : 0) });
13304
+ const { slot = [] } = playOptions;
13292
13305
  slot.forEach(({ name, type, value, style = {} }) => {
13293
13306
  const { x, y, anchor = { x: 0, y: 0 }, pivot = { x: 0, y: 0 }, width, height } = style;
13294
13307
  if (type === 'IMAGE') {
@@ -13315,7 +13328,30 @@ class Lottie extends Component {
13315
13328
  this.anim.bindSlot(name, this.currentSlot[name]);
13316
13329
  this.prevSlot[name] = this.currentSlot[name];
13317
13330
  });
13318
- this.anim.playSegment(this.playParamsHandle(params), expandOpts);
13331
+ this.anim.playSegment(this.playParamsHandle(params), playOptions);
13332
+ }
13333
+ pause() {
13334
+ var _a;
13335
+ if ((_a = this.anim) === null || _a === void 0 ? void 0 : _a.pause)
13336
+ this.anim.pause();
13337
+ }
13338
+ stop() {
13339
+ var _a, _b;
13340
+ if ((_a = this.anim) === null || _a === void 0 ? void 0 : _a.stop)
13341
+ this.anim.stop();
13342
+ else if ((_b = this.anim) === null || _b === void 0 ? void 0 : _b.goToAndStop)
13343
+ this.anim.goToAndStop(0, true);
13344
+ }
13345
+ goToFrame(frame) {
13346
+ var _a;
13347
+ if ((_a = this.anim) === null || _a === void 0 ? void 0 : _a.goToAndStop)
13348
+ this.anim.goToAndStop(frame, true);
13349
+ }
13350
+ load() {
13351
+ var _a;
13352
+ if (this.loadStatus || this.anim)
13353
+ return;
13354
+ this.firstPlay = (_a = this.firstPlay) !== null && _a !== void 0 ? _a : (() => { });
13319
13355
  }
13320
13356
  replaceData(data) {
13321
13357
  if (data) {
@@ -13350,6 +13386,30 @@ class Lottie extends Component {
13350
13386
  });
13351
13387
  });
13352
13388
  }
13389
+ destroy() {
13390
+ var _a;
13391
+ Object.keys(this.prevSlot).forEach(name => {
13392
+ var _a;
13393
+ const slot = this.prevSlot[name];
13394
+ if (((_a = this.anim) === null || _a === void 0 ? void 0 : _a.unbindSlot) && slot)
13395
+ this.anim.unbindSlot(name, slot);
13396
+ if (slot === null || slot === void 0 ? void 0 : slot.destroy)
13397
+ slot.destroy();
13398
+ });
13399
+ this.prevSlot = {};
13400
+ this.currentSlot = {};
13401
+ if ((_a = this.anim) === null || _a === void 0 ? void 0 : _a.destroy)
13402
+ this.anim.destroy();
13403
+ this.anim = null;
13404
+ this.loadStatus = false;
13405
+ }
13406
+ applySpeed() {
13407
+ var _a;
13408
+ if ((_a = this.anim) === null || _a === void 0 ? void 0 : _a.setSpeed)
13409
+ this.anim.setSpeed(this._speed);
13410
+ else if (this.anim)
13411
+ this.anim.timeScale = this._speed;
13412
+ }
13353
13413
  }
13354
13414
  /** 组件名称 */
13355
13415
  Lottie.componentName = 'Lottie';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-lottie",
3
- "version": "2.0.2",
3
+ "version": "2.1.0-beta.2",
4
4
  "description": "@eva/plugin-renderer-lottie",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-lottie.esm.js",
@@ -18,8 +18,8 @@
18
18
  "license": "MIT",
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
- "@eva/eva.js": "2.0.2",
22
- "@eva/plugin-renderer": "2.0.2",
21
+ "@eva/eva.js": "2.1.0-beta.2",
22
+ "@eva/plugin-renderer": "2.1.0-beta.2",
23
23
  "ios-version": "^1.0.1",
24
24
  "pixi.js": "^8.17.0"
25
25
  }