@eva/plugin-renderer-event 1.2.2-alpha.1 → 1.2.2-mini.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.
Files changed (2) hide show
  1. package/dist/miniprogram.js +279 -0
  2. package/package.json +3 -3
@@ -0,0 +1,279 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import { __extends, __values, __spread, __decorate } from 'tslib';
4
+ import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
5
+ import { OBSERVER_TYPE, decorators, Component } from '@eva/eva.js/dist/miniprogram';
6
+ import { Circle, Ellipse, Polygon, Rectangle, RoundedRectangle } from '@eva/miniprogram-pixi';
7
+ var hitAreaFunc = {
8
+ Circle: Circle,
9
+ Ellipse: Ellipse,
10
+ Polygon: Polygon,
11
+ Rect: Rectangle,
12
+ RoundedRect: RoundedRectangle
13
+ };
14
+ var propertyForHitArea = {
15
+ Circle: ['x', 'y', 'radius'],
16
+ Ellipse: ['x', 'y', 'width', 'height'],
17
+ Rect: ['x', 'y', 'width', 'height'],
18
+ RoundedRect: ['x', 'y', 'width', 'height', 'radius'],
19
+ Polygon: ['paths']
20
+ };
21
+
22
+ var Event$2 = function (_super) {
23
+ __extends(Event, _super);
24
+
25
+ function Event() {
26
+ var _this = _super !== null && _super.apply(this, arguments) || this;
27
+
28
+ _this.name = 'Event';
29
+ return _this;
30
+ }
31
+
32
+ Event.prototype.init = function (_a) {
33
+ var _b = (_a === void 0 ? {} : _a).moveWhenInside,
34
+ moveWhenInside = _b === void 0 ? false : _b;
35
+ this.renderSystem = this.game.getSystem(RendererSystem);
36
+ this.renderSystem.rendererManager.register(this);
37
+
38
+ try {
39
+ this.renderSystem.application.renderer.plugins.interaction.moveWhenInside = moveWhenInside;
40
+ } catch (e) {
41
+ console.error('Setting moveWhenInside error.', e);
42
+ }
43
+ };
44
+
45
+ Event.prototype.componentChanged = function (changed) {
46
+ switch (changed.type) {
47
+ case OBSERVER_TYPE.ADD:
48
+ this.add(changed);
49
+ break;
50
+
51
+ case OBSERVER_TYPE.REMOVE:
52
+ this.remove(changed);
53
+ break;
54
+
55
+ case OBSERVER_TYPE.CHANGE:
56
+ this.change(changed);
57
+ break;
58
+ }
59
+ };
60
+
61
+ Event.prototype.add = function (changed) {
62
+ var container = this.containerManager.getContainer(changed.gameObject.id);
63
+ container.interactive = true;
64
+ container.interactiveChildren = true;
65
+ var component = changed.component;
66
+
67
+ if (component.hitArea) {
68
+ this.addHitArea(changed, container, component.hitArea);
69
+ }
70
+
71
+ container.on('pointertap', function (e) {
72
+ component.emit('tap', {
73
+ stopPropagation: function stopPropagation() {
74
+ return e.stopPropagation();
75
+ },
76
+ data: {
77
+ pointerId: e.data.pointerId,
78
+ position: {
79
+ x: e.data.global.x,
80
+ y: e.data.global.y
81
+ }
82
+ },
83
+ gameObject: component.gameObject
84
+ });
85
+ });
86
+ container.on('pointerdown', function (e) {
87
+ component.emit('touchstart', {
88
+ stopPropagation: function stopPropagation() {
89
+ return e.stopPropagation();
90
+ },
91
+ data: {
92
+ pointerId: e.data.pointerId,
93
+ position: {
94
+ x: e.data.global.x,
95
+ y: e.data.global.y
96
+ }
97
+ },
98
+ gameObject: component.gameObject
99
+ });
100
+ });
101
+ container.on('pointermove', function (e) {
102
+ component.emit('touchmove', {
103
+ stopPropagation: function stopPropagation() {
104
+ return e.stopPropagation();
105
+ },
106
+ data: {
107
+ pointerId: e.data.pointerId,
108
+ position: {
109
+ x: e.data.global.x,
110
+ y: e.data.global.y
111
+ }
112
+ },
113
+ gameObject: component.gameObject
114
+ });
115
+ });
116
+ container.on('pointerup', function (e) {
117
+ component.emit('touchend', {
118
+ stopPropagation: function stopPropagation() {
119
+ return e.stopPropagation();
120
+ },
121
+ data: {
122
+ pointerId: e.data.pointerId,
123
+ position: {
124
+ x: e.data.global.x,
125
+ y: e.data.global.y
126
+ }
127
+ },
128
+ gameObject: component.gameObject
129
+ });
130
+ });
131
+ container.on('pointerupoutside', function (e) {
132
+ component.emit('touchendoutside', {
133
+ stopPropagation: function stopPropagation() {
134
+ return e.stopPropagation();
135
+ },
136
+ data: {
137
+ pointerId: e.data.pointerId,
138
+ position: {
139
+ x: e.data.global.x,
140
+ y: e.data.global.y
141
+ }
142
+ },
143
+ gameObject: component.gameObject
144
+ });
145
+ });
146
+ container.on('pointercancel', function (e) {
147
+ component.emit('touchcancel', {
148
+ stopPropagation: function stopPropagation() {
149
+ return e.stopPropagation();
150
+ },
151
+ data: {
152
+ pointerId: e.data.pointerId,
153
+ position: {
154
+ x: e.data.global.x,
155
+ y: e.data.global.y
156
+ }
157
+ },
158
+ gameObject: component.gameObject
159
+ });
160
+ });
161
+ };
162
+
163
+ Event.prototype.remove = function (changed) {
164
+ var container = this.containerManager.getContainer(changed.gameObject.id);
165
+ container.interactive = false;
166
+ container.off('tap');
167
+ container.off('pointerdown');
168
+ container.off('pointermove');
169
+ container.off('pointerup');
170
+ container.off('pointerupoutside');
171
+ container.off('pointercancel');
172
+ changed.component.removeAllListeners();
173
+ };
174
+
175
+ Event.prototype.change = function (changed) {
176
+ var container = this.containerManager.getContainer(changed.gameObject.id);
177
+ container.interactive = true;
178
+ var component = changed.component;
179
+
180
+ if (component.hitArea) {
181
+ this.addHitArea(changed, container, component.hitArea);
182
+ } else {
183
+ component.hitArea = null;
184
+ }
185
+ };
186
+
187
+ Event.prototype.addHitArea = function (changed, container, hitArea) {
188
+ var e_1, _a, _b;
189
+
190
+ var type = hitArea.type,
191
+ style = hitArea.style;
192
+
193
+ if (!hitAreaFunc[type]) {
194
+ console.error(changed.gameObject.name + "'s hitArea type is not defined");
195
+ return;
196
+ }
197
+
198
+ var params = [];
199
+
200
+ try {
201
+ for (var _c = __values(propertyForHitArea[type]), _d = _c.next(); !_d.done; _d = _c.next()) {
202
+ var key = _d.value;
203
+ params.push(style[key]);
204
+ }
205
+ } catch (e_1_1) {
206
+ e_1 = {
207
+ error: e_1_1
208
+ };
209
+ } finally {
210
+ try {
211
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
212
+ } finally {
213
+ if (e_1) throw e_1.error;
214
+ }
215
+ }
216
+
217
+ var hitAreaShape = new ((_b = hitAreaFunc[type]).bind.apply(_b, __spread([void 0], params)))();
218
+ container.hitArea = hitAreaShape;
219
+ };
220
+
221
+ Event.systemName = 'Event';
222
+ Event = __decorate([decorators.componentObserver({
223
+ Event: [{
224
+ prop: ['hitArea'],
225
+ deep: true
226
+ }]
227
+ })], Event);
228
+ return Event;
229
+ }(Renderer);
230
+
231
+ var Event$3 = Event$2;
232
+ var HIT_AREA_TYPE;
233
+
234
+ (function (HIT_AREA_TYPE) {
235
+ HIT_AREA_TYPE["Circle"] = "Circle";
236
+ HIT_AREA_TYPE["Ellipse"] = "Ellipse";
237
+ HIT_AREA_TYPE["Polygon"] = "Polygon";
238
+ HIT_AREA_TYPE["Rect"] = "Rect";
239
+ HIT_AREA_TYPE["RoundedRect"] = "RoundedRect";
240
+ })(HIT_AREA_TYPE || (HIT_AREA_TYPE = {}));
241
+
242
+ var Event = function (_super) {
243
+ __extends(Event, _super);
244
+
245
+ function Event() {
246
+ var _this = _super !== null && _super.apply(this, arguments) || this;
247
+
248
+ _this.hitArea = undefined;
249
+ return _this;
250
+ }
251
+
252
+ Event.prototype.init = function (params) {
253
+ params && _extends(this, params);
254
+ };
255
+
256
+ Event.prototype.emit = function (en) {
257
+ var args = [];
258
+
259
+ for (var _i = 1; _i < arguments.length; _i++) {
260
+ args[_i - 1] = arguments[_i];
261
+ }
262
+
263
+ return _super.prototype.emit.apply(this, __spread([en], args));
264
+ };
265
+
266
+ Event.prototype.once = function (en, fn, context) {
267
+ return _super.prototype.once.call(this, en, fn, context);
268
+ };
269
+
270
+ Event.prototype.on = function (en, fn, context) {
271
+ return _super.prototype.on.call(this, en, fn, context);
272
+ };
273
+
274
+ Event.componentName = 'Event';
275
+ return Event;
276
+ }(Component);
277
+
278
+ var Event$1 = Event;
279
+ export { Event$1 as Event, Event$3 as EventSystem, HIT_AREA_TYPE };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-event",
3
- "version": "1.2.2-alpha.1",
3
+ "version": "1.2.2-mini.1",
4
4
  "description": "@eva/plugin-renderer-event",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-event.esm.js",
@@ -18,8 +18,8 @@
18
18
  "license": "MIT",
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
- "@eva/plugin-renderer": "1.2.2-alpha.1",
22
- "@eva/eva.js": "1.2.2-alpha.1",
21
+ "@eva/plugin-renderer": "1.2.2-mini.1",
22
+ "@eva/eva.js": "1.2.2-mini.1",
23
23
  "pixi.js": "^4.8.7"
24
24
  }
25
25
  }