@eva/plugin-renderer-lottie 2.0.0-beta.1 → 2.0.0-beta.10

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.
@@ -25,31 +25,6 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
25
25
  See the Apache Version 2.0 License for specific language governing permissions
26
26
  and limitations under the License.
27
27
  ***************************************************************************** */
28
- /* global Reflect, Promise */
29
-
30
- var extendStatics = function(d, b) {
31
- extendStatics = Object.setPrototypeOf ||
32
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
33
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
34
- return extendStatics(d, b);
35
- };
36
-
37
- function __extends(d, b) {
38
- extendStatics(d, b);
39
- function __() { this.constructor = d; }
40
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
41
- }
42
-
43
- var __assign = function() {
44
- __assign = Object.assign || function __assign(t) {
45
- for (var s, i = 1, n = arguments.length; i < n; i++) {
46
- s = arguments[i];
47
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
48
- }
49
- return t;
50
- };
51
- return __assign.apply(this, arguments);
52
- };
53
28
 
54
29
  function __rest(s, e) {
55
30
  var t = {};
@@ -77,34 +52,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
77
52
  function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
78
53
  step((generator = generator.apply(thisArg, _arguments || [])).next());
79
54
  });
80
- }
81
-
82
- function __generator(thisArg, body) {
83
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
84
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
85
- function verb(n) { return function (v) { return step([n, v]); }; }
86
- function step(op) {
87
- if (f) throw new TypeError("Generator is already executing.");
88
- while (_) try {
89
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
90
- if (y = 0, t) op = [op[0] & 2, t.value];
91
- switch (op[0]) {
92
- case 0: case 1: t = op; break;
93
- case 4: _.label++; return { value: op[1], done: false };
94
- case 5: _.label++; y = op[1]; op = [0]; continue;
95
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
96
- default:
97
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
98
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
99
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
100
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
101
- if (t[2]) _.ops.pop();
102
- _.trys.pop(); continue;
103
- }
104
- op = body.call(thisArg, _);
105
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
106
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
107
- }
108
55
  }
109
56
 
110
57
  function t(t) {
@@ -5060,11 +5007,10 @@ wt.registerDisplayByType(wt.Type.Solid, G);
5060
5007
  wt.registerDisplayByType(wt.Type.Sprite, R);
5061
5008
  wt.registerDisplayByType(wt.Type.Component, k);
5062
5009
  wt.registerDisplayByType(wt.Type.Container, pixi_js.Container);
5063
- var LottieSystem = (function (_super) {
5064
- __extends(LottieSystem, _super);
5065
- function LottieSystem() {
5066
- var _this = _super !== null && _super.apply(this, arguments) || this;
5067
- _this.managerLife = [
5010
+ let LottieSystem = class LottieSystem extends pluginRenderer.Renderer {
5011
+ constructor() {
5012
+ super(...arguments);
5013
+ this.managerLife = [
5068
5014
  'DisplayReady',
5069
5015
  'ImageReady',
5070
5016
  'success',
@@ -5074,145 +5020,122 @@ var LottieSystem = (function (_super) {
5074
5020
  'enterFrame',
5075
5021
  'update',
5076
5022
  ];
5077
- return _this;
5078
5023
  }
5079
- LottieSystem.prototype.init = function () {
5024
+ init() {
5080
5025
  this.renderSystem = this.game.getSystem('Renderer');
5081
5026
  this.app = this.renderSystem.application;
5082
- };
5083
- LottieSystem.prototype.componentChanged = function (changed) {
5084
- return __awaiter(this, void 0, void 0, function () {
5085
- return __generator(this, function (_a) {
5086
- if (changed.componentName === 'Lottie') {
5087
- if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
5088
- this.add(changed);
5089
- }
5090
- else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
5091
- this.remove(changed);
5092
- }
5027
+ }
5028
+ componentChanged(changed) {
5029
+ return __awaiter(this, void 0, void 0, function* () {
5030
+ if (changed.componentName === 'Lottie') {
5031
+ if (changed.type === eva_js.OBSERVER_TYPE.ADD) {
5032
+ this.add(changed);
5093
5033
  }
5094
- return [2];
5095
- });
5096
- });
5097
- };
5098
- LottieSystem.prototype.add = function (changed) {
5099
- return __awaiter(this, void 0, void 0, function () {
5100
- var component, container, _a, rn, otherOpts, data, json, assets, anim;
5101
- return __generator(this, function (_b) {
5102
- switch (_b.label) {
5103
- case 0:
5104
- this.manager = new Gt(this.app);
5105
- component = changed.component;
5106
- container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
5107
- if (!container)
5108
- return [2];
5109
- _a = component.options, rn = _a.resource, otherOpts = __rest(_a, ["resource"]);
5110
- return [4, eva_js.resource.getResource(rn)];
5111
- case 1:
5112
- data = (_b.sent()).data;
5113
- json = __assign({}, (data.json || {}));
5114
- assets = json.assets || [];
5115
- assets.forEach(function (item) {
5116
- if (item.p)
5117
- item.p = imageHandle(item.p);
5118
- });
5119
- anim = this.manager.parseAnimation(__assign({ keyframes: json }, otherOpts));
5120
- component.anim = anim;
5121
- container.addChildAt(anim.group, 0);
5122
- this.managerLife.forEach(function (eventName) {
5123
- anim.on(eventName, function (e) { return component.emit(eventName, e); });
5124
- });
5125
- if (anim.isImagesLoaded)
5126
- component.emit('success', {});
5127
- return [2];
5034
+ else if (changed.type === eva_js.OBSERVER_TYPE.REMOVE) {
5035
+ this.remove(changed);
5128
5036
  }
5037
+ }
5038
+ });
5039
+ }
5040
+ add(changed) {
5041
+ return __awaiter(this, void 0, void 0, function* () {
5042
+ this.manager = new Gt(this.app);
5043
+ const component = changed.component;
5044
+ const container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
5045
+ if (!container)
5046
+ return;
5047
+ const _a = component.options, { resource: rn } = _a, otherOpts = __rest(_a, ["resource"]);
5048
+ const { data } = yield eva_js.resource.getResource(rn);
5049
+ const json = Object.assign({}, (data.json || {}));
5050
+ const assets = json.assets || [];
5051
+ assets.forEach(item => {
5052
+ if (item.p)
5053
+ item.p = imageHandle(item.p);
5129
5054
  });
5055
+ const anim = this.manager.parseAnimation(Object.assign({ keyframes: json }, otherOpts));
5056
+ component.anim = anim;
5057
+ container.addChildAt(anim.group, 0);
5058
+ this.managerLife.forEach(eventName => {
5059
+ anim.on(eventName, e => component.emit(eventName, e));
5060
+ });
5061
+ if (anim.isImagesLoaded)
5062
+ component.emit('success', {});
5130
5063
  });
5131
- };
5132
- LottieSystem.prototype.remove = function (changed) {
5133
- var component = changed.component;
5134
- var container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
5064
+ }
5065
+ remove(changed) {
5066
+ const component = changed.component;
5067
+ const container = this.renderSystem.containerManager.getContainer(changed.gameObject.id);
5135
5068
  if (container) {
5136
5069
  container.removeChild(component.anim.group);
5137
5070
  component.anim.destroy();
5138
5071
  }
5139
5072
  component.anim = null;
5140
- };
5141
- LottieSystem.systemName = 'LottieSystem';
5142
- LottieSystem = __decorate([
5143
- eva_js.decorators.componentObserver({
5144
- Lottie: [],
5145
- })
5146
- ], LottieSystem);
5147
- return LottieSystem;
5148
- }(pluginRenderer.Renderer));
5073
+ }
5074
+ };
5075
+ LottieSystem.systemName = 'LottieSystem';
5076
+ LottieSystem = __decorate([
5077
+ eva_js.decorators.componentObserver({
5078
+ Lottie: [],
5079
+ })
5080
+ ], LottieSystem);
5149
5081
  var LottieSystem$1 = LottieSystem;
5150
5082
 
5151
- var Lottie = (function (_super) {
5152
- __extends(Lottie, _super);
5153
- function Lottie(options) {
5154
- var _this = _super.call(this) || this;
5155
- _this.loadStatus = false;
5156
- _this.firstPlay = null;
5157
- _this.prevSlot = {};
5158
- _this.currentSlot = {};
5159
- _this.options = __assign({ autoStart: false }, options);
5160
- _this.on('success', function () {
5161
- _this.loadStatus = true;
5162
- var _a = _this.anim.keyframes, ip = _a.ip, op = _a.op;
5163
- var _loop_1 = function (i) {
5164
- var event_1 = "@" + i;
5165
- _this.anim.on(event_1, function (e) { return _this.emit(event_1, e); });
5166
- };
5167
- for (var i = ip; i <= op; i++) {
5168
- _loop_1(i);
5083
+ class Lottie extends eva_js.Component {
5084
+ constructor(options) {
5085
+ super();
5086
+ this.loadStatus = false;
5087
+ this.firstPlay = null;
5088
+ this.prevSlot = {};
5089
+ this.currentSlot = {};
5090
+ this.options = Object.assign({ autoStart: false }, options);
5091
+ this.on('success', () => {
5092
+ this.loadStatus = true;
5093
+ const { ip, op } = this.anim.keyframes;
5094
+ for (let i = ip; i <= op; i++) {
5095
+ const event = `@${i}`;
5096
+ this.anim.on(event, e => this.emit(event, e));
5169
5097
  }
5170
- _this.firstPlay && _this.firstPlay();
5098
+ this.firstPlay && this.firstPlay();
5171
5099
  });
5172
- return _this;
5173
5100
  }
5174
- Lottie.prototype.play = function (params, expandOpts) {
5175
- var _this = this;
5176
- if (params === void 0) { params = []; }
5177
- if (expandOpts === void 0) { expandOpts = {
5178
- repeats: 0,
5179
- }; }
5101
+ play(params = [], expandOpts = {
5102
+ repeats: 0,
5103
+ }) {
5180
5104
  if (!this.loadStatus) {
5181
- this.firstPlay = function () {
5182
- _this.play(params, expandOpts);
5105
+ this.firstPlay = () => {
5106
+ this.play(params, expandOpts);
5183
5107
  };
5184
5108
  return;
5185
5109
  }
5186
- var _a = expandOpts.slot, slot = _a === void 0 ? [] : _a;
5187
- slot.forEach(function (_a) {
5188
- var name = _a.name, type = _a.type, value = _a.value, _b = _a.style, style = _b === void 0 ? {} : _b;
5189
- var x = style.x, y = style.y, _c = style.anchor, anchor = _c === void 0 ? { x: 0, y: 0 } : _c, _d = style.pivot, pivot = _d === void 0 ? { x: 0, y: 0 } : _d, width = style.width, height = style.height;
5110
+ const { slot = [] } = expandOpts;
5111
+ slot.forEach(({ name, type, value, style = {} }) => {
5112
+ const { x, y, anchor = { x: 0, y: 0 }, pivot = { x: 0, y: 0 }, width, height } = style;
5190
5113
  if (type === 'IMAGE') {
5191
- _this.currentSlot[name] = pixi_js.Sprite.from(value);
5114
+ this.currentSlot[name] = pixi_js.Sprite.from(value);
5192
5115
  }
5193
5116
  else if (type === 'TEXT') {
5194
- _this.currentSlot[name] = new pixi_js.Text(value, new pixi_js.TextStyle(style));
5117
+ this.currentSlot[name] = new pixi_js.Text(value, new pixi_js.TextStyle(style));
5195
5118
  }
5196
5119
  if (x)
5197
- _this.currentSlot[name].x = x;
5120
+ this.currentSlot[name].x = x;
5198
5121
  if (y)
5199
- _this.currentSlot[name].y = y;
5122
+ this.currentSlot[name].y = y;
5200
5123
  if (width)
5201
- _this.currentSlot[name].width = width;
5124
+ this.currentSlot[name].width = width;
5202
5125
  if (height)
5203
- _this.currentSlot[name].height = height;
5204
- _this.currentSlot[name].anchor.set(anchor.x || 0, anchor.y || 0);
5205
- _this.currentSlot[name].pivot.set(_this.currentSlot[name].width * (pivot.x || 0), _this.currentSlot[name].height * (pivot.y || 0));
5206
- if (_this.prevSlot[name])
5207
- _this.anim.unbindSlot(name, _this.prevSlot[name]);
5208
- _this.anim.bindSlot(name, _this.currentSlot[name]);
5209
- _this.prevSlot[name] = _this.currentSlot[name];
5126
+ this.currentSlot[name].height = height;
5127
+ this.currentSlot[name].anchor.set(anchor.x || 0, anchor.y || 0);
5128
+ this.currentSlot[name].pivot.set(this.currentSlot[name].width * (pivot.x || 0), this.currentSlot[name].height * (pivot.y || 0));
5129
+ if (this.prevSlot[name])
5130
+ this.anim.unbindSlot(name, this.prevSlot[name]);
5131
+ this.anim.bindSlot(name, this.currentSlot[name]);
5132
+ this.prevSlot[name] = this.currentSlot[name];
5210
5133
  });
5211
5134
  this.anim.playSegment(this.playParamsHandle(params), expandOpts);
5212
- };
5213
- Lottie.prototype.playParamsHandle = function (params) {
5214
- var p = [].concat(params);
5215
- var keyframes = this.anim.keyframes;
5135
+ }
5136
+ playParamsHandle(params) {
5137
+ let p = [].concat(params);
5138
+ const { keyframes } = this.anim;
5216
5139
  if (!p.length || p.length > 2) {
5217
5140
  p = [keyframes.ip, keyframes.op];
5218
5141
  }
@@ -5220,30 +5143,27 @@ var Lottie = (function (_super) {
5220
5143
  p = [p[0] % keyframes.op, keyframes.op];
5221
5144
  }
5222
5145
  return p;
5223
- };
5224
- Lottie.prototype.onTap = function (name, callback) {
5225
- var _this = this;
5226
- var g = new pixi_js.Graphics();
5227
- this.on('success', function () {
5228
- var ele = _this.anim.querySelector(name);
5229
- var display = ele.display;
5146
+ }
5147
+ onTap(name, callback) {
5148
+ const g = new pixi_js.Graphics();
5149
+ this.on('success', () => {
5150
+ const ele = this.anim.querySelector(name);
5151
+ const display = ele.display;
5230
5152
  g.beginFill(0xffffff);
5231
5153
  g.drawRect(0, 0, 100, 100);
5232
5154
  g.endFill();
5233
5155
  g.alpha = 0;
5234
5156
  display.addChild(g);
5235
5157
  ele.display.interactive = true;
5236
- ele.display.on('pointertap', function () {
5158
+ ele.display.on('pointertap', () => {
5237
5159
  callback();
5238
5160
  });
5239
5161
  });
5240
- };
5241
- Lottie.componentName = 'Lottie';
5242
- return Lottie;
5243
- }(eva_js.Component));
5244
- var Lottie$1 = Lottie;
5162
+ }
5163
+ }
5164
+ Lottie.componentName = 'Lottie';
5245
5165
 
5246
5166
  eva_js.resource.registerResourceType('LOTTIE');
5247
5167
 
5248
- exports.Lottie = Lottie$1;
5168
+ exports.Lottie = Lottie;
5249
5169
  exports.LottieSystem = LottieSystem$1;