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

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.
@@ -13065,52 +13065,36 @@ class AnimationManager extends Eventer {
13065
13065
  }
13066
13066
  }
13067
13067
 
13068
- const { major } = iOSVersion__default(globalThis.navigator.userAgent) || {};
13069
-
13070
- /**
13071
- * dataURL 转成 blob
13072
- * @param dataURL
13073
- * @return blob
13074
- */
13075
- function dataURL2blob(dataURL) {
13076
- let binaryString = atob(dataURL.split(',')[1]);
13077
- let arrayBuffer = new ArrayBuffer(binaryString.length);
13078
- let intArray = new Uint8Array(arrayBuffer);
13079
- let mime = dataURL.split(',')[0].match(/:(.*?);/)[1];
13080
- for (let i = 0, j = binaryString.length; i < j; i++) {
13081
- intArray[i] = binaryString.charCodeAt(i);
13082
- }
13083
- let data = [intArray];
13084
- let result;
13085
- try {
13086
- result = new Blob(data, { type: mime });
13087
- } catch (error) {
13088
- console.log(error);
13089
- }
13090
- return result;
13091
- }
13092
-
13093
- /**
13094
- * 创建新的URL 对象表示指定的 File 对象或 Blob 对象。
13095
- * @param {string} dataURL base64
13096
- */
13097
- function dataURL2ObjUrl(dataURL) {
13098
- window.URL = window.URL || window.webkitURL;
13099
- if (window.URL && URL.createObjectURL) {
13100
- // dataURL2blob 此方法需额外定义
13101
- const blob = dataURL2blob(dataURL);
13102
- return URL.createObjectURL(blob);
13103
- }
13104
- return dataURL;
13105
- }
13106
-
13107
- function imageHandle(source) {
13108
- const isBase64Reg = /^data:image\/png;base64/;
13109
- if (major <= 8 && isBase64Reg.test(source)) {
13110
- return dataURL2ObjUrl(source);
13111
- }
13112
-
13113
- return source;
13068
+ const getIOSMajor = () => {
13069
+ var _a, _b;
13070
+ const userAgent = ((_a = globalThis.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) || '';
13071
+ return (_b = iOSVersion__default(userAgent)) === null || _b === void 0 ? void 0 : _b.major;
13072
+ };
13073
+ const dataURL2blob = (dataURL) => {
13074
+ var _a;
13075
+ const binaryString = atob(dataURL.split(',')[1]);
13076
+ const arrayBuffer = new ArrayBuffer(binaryString.length);
13077
+ const intArray = new Uint8Array(arrayBuffer);
13078
+ const mime = ((_a = dataURL.split(',')[0].match(/:(.*?);/)) === null || _a === void 0 ? void 0 : _a[1]) || 'image/png';
13079
+ for (let i = 0, j = binaryString.length; i < j; i++) {
13080
+ intArray[i] = binaryString.charCodeAt(i);
13081
+ }
13082
+ return new Blob([intArray], { type: mime });
13083
+ };
13084
+ const dataURL2ObjUrl = (dataURL) => {
13085
+ const urlFactory = globalThis.URL || window.webkitURL;
13086
+ if (urlFactory === null || urlFactory === void 0 ? void 0 : urlFactory.createObjectURL) {
13087
+ return urlFactory.createObjectURL(dataURL2blob(dataURL));
13088
+ }
13089
+ return dataURL;
13090
+ };
13091
+ function imageHandle(source) {
13092
+ const isBase64Reg = /^data:image\/png;base64/;
13093
+ const major = getIOSMajor();
13094
+ if (major && major <= 8 && isBase64Reg.test(source)) {
13095
+ return dataURL2ObjUrl(source);
13096
+ }
13097
+ return source;
13114
13098
  }
13115
13099
 
13116
13100
  let LottieSystem = class LottieSystem extends pluginRenderer.Renderer {
@@ -13265,9 +13249,15 @@ class Lottie extends eva_js.Component {
13265
13249
  * @param options.autoStart - 是否自动开始播放
13266
13250
  */
13267
13251
  constructor(options) {
13252
+ var _a, _b, _c, _d;
13268
13253
  super();
13269
13254
  /** 待替换的数据 */
13270
13255
  this._replaceData = null;
13256
+ /** 是否资源就绪后自动播放 */
13257
+ this.autoplay = false;
13258
+ /** 是否循环播放 */
13259
+ this.loop = false;
13260
+ this._speed = 1;
13271
13261
  /** 资源加载状态 */
13272
13262
  this.loadStatus = false;
13273
13263
  /** 首次播放回调 */
@@ -13276,27 +13266,50 @@ class Lottie extends eva_js.Component {
13276
13266
  this.prevSlot = {};
13277
13267
  /** 当前的插槽内容 */
13278
13268
  this.currentSlot = {};
13279
- this.options = Object.assign({ autoStart: false }, options);
13269
+ const autoStart = (_b = (_a = options.autoStart) !== null && _a !== void 0 ? _a : options.autoplay) !== null && _b !== void 0 ? _b : false;
13270
+ this.options = Object.assign(Object.assign({}, options), { autoStart });
13271
+ this.autoplay = autoStart;
13272
+ this.loop = (_c = options.loop) !== null && _c !== void 0 ? _c : false;
13273
+ this._speed = (_d = options.speed) !== null && _d !== void 0 ? _d : 1;
13274
+ this.onComplete = options.onComplete;
13275
+ this.onLoopComplete = options.onLoopComplete;
13276
+ if (this.onComplete)
13277
+ this.on('complete', this.onComplete);
13278
+ if (this.onLoopComplete)
13279
+ this.on('loopComplete', this.onLoopComplete);
13280
13280
  this.on('success', () => {
13281
13281
  this.loadStatus = true;
13282
+ this.applySpeed();
13282
13283
  const { ip, op } = this.anim.keyframes;
13283
13284
  for (let i = ip; i <= op; i++) {
13284
13285
  const event = `@${i}`;
13285
13286
  this.anim.on(event, e => this.emit(event, e));
13286
13287
  }
13288
+ if (this.options.autoStart)
13289
+ this.play();
13287
13290
  this.firstPlay && this.firstPlay();
13288
13291
  });
13289
13292
  }
13293
+ get speed() {
13294
+ return this._speed;
13295
+ }
13296
+ set speed(value) {
13297
+ this._speed = value;
13298
+ this.options.speed = value;
13299
+ this.applySpeed();
13300
+ }
13290
13301
  play(params = [], expandOpts = {
13291
13302
  repeats: 0,
13292
13303
  }) {
13304
+ var _a;
13293
13305
  if (!this.loadStatus) {
13294
13306
  this.firstPlay = () => {
13295
13307
  this.play(params, expandOpts);
13296
13308
  };
13297
13309
  return;
13298
13310
  }
13299
- const { slot = [] } = expandOpts;
13311
+ const playOptions = Object.assign(Object.assign({}, expandOpts), { repeats: (_a = expandOpts.repeats) !== null && _a !== void 0 ? _a : (this.loop ? -1 : 0) });
13312
+ const { slot = [] } = playOptions;
13300
13313
  slot.forEach(({ name, type, value, style = {} }) => {
13301
13314
  const { x, y, anchor = { x: 0, y: 0 }, pivot = { x: 0, y: 0 }, width, height } = style;
13302
13315
  if (type === 'IMAGE') {
@@ -13323,7 +13336,30 @@ class Lottie extends eva_js.Component {
13323
13336
  this.anim.bindSlot(name, this.currentSlot[name]);
13324
13337
  this.prevSlot[name] = this.currentSlot[name];
13325
13338
  });
13326
- this.anim.playSegment(this.playParamsHandle(params), expandOpts);
13339
+ this.anim.playSegment(this.playParamsHandle(params), playOptions);
13340
+ }
13341
+ pause() {
13342
+ var _a;
13343
+ if ((_a = this.anim) === null || _a === void 0 ? void 0 : _a.pause)
13344
+ this.anim.pause();
13345
+ }
13346
+ stop() {
13347
+ var _a, _b;
13348
+ if ((_a = this.anim) === null || _a === void 0 ? void 0 : _a.stop)
13349
+ this.anim.stop();
13350
+ else if ((_b = this.anim) === null || _b === void 0 ? void 0 : _b.goToAndStop)
13351
+ this.anim.goToAndStop(0, true);
13352
+ }
13353
+ goToFrame(frame) {
13354
+ var _a;
13355
+ if ((_a = this.anim) === null || _a === void 0 ? void 0 : _a.goToAndStop)
13356
+ this.anim.goToAndStop(frame, true);
13357
+ }
13358
+ load() {
13359
+ var _a;
13360
+ if (this.loadStatus || this.anim)
13361
+ return;
13362
+ this.firstPlay = (_a = this.firstPlay) !== null && _a !== void 0 ? _a : (() => { });
13327
13363
  }
13328
13364
  replaceData(data) {
13329
13365
  if (data) {
@@ -13358,6 +13394,30 @@ class Lottie extends eva_js.Component {
13358
13394
  });
13359
13395
  });
13360
13396
  }
13397
+ destroy() {
13398
+ var _a;
13399
+ Object.keys(this.prevSlot).forEach(name => {
13400
+ var _a;
13401
+ const slot = this.prevSlot[name];
13402
+ if (((_a = this.anim) === null || _a === void 0 ? void 0 : _a.unbindSlot) && slot)
13403
+ this.anim.unbindSlot(name, slot);
13404
+ if (slot === null || slot === void 0 ? void 0 : slot.destroy)
13405
+ slot.destroy();
13406
+ });
13407
+ this.prevSlot = {};
13408
+ this.currentSlot = {};
13409
+ if ((_a = this.anim) === null || _a === void 0 ? void 0 : _a.destroy)
13410
+ this.anim.destroy();
13411
+ this.anim = null;
13412
+ this.loadStatus = false;
13413
+ }
13414
+ applySpeed() {
13415
+ var _a;
13416
+ if ((_a = this.anim) === null || _a === void 0 ? void 0 : _a.setSpeed)
13417
+ this.anim.setSpeed(this._speed);
13418
+ else if (this.anim)
13419
+ this.anim.timeScale = this._speed;
13420
+ }
13361
13421
  }
13362
13422
  /** 组件名称 */
13363
13423
  Lottie.componentName = 'Lottie';