@eva/plugin-a11y 2.0.0-beta.1 → 2.0.0-beta.3

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.
@@ -1,4 +1,4 @@
1
- import { Component, decorators, System, OBSERVER_TYPE } from '@eva/eva.js';
1
+ import { Component, System, decorators, OBSERVER_TYPE } from '@eva/eva.js';
2
2
  import { RendererSystem } from '@eva/plugin-renderer';
3
3
  import { type, step } from '@eva/inspector-decorator';
4
4
 
@@ -16,31 +16,6 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
16
16
  See the Apache Version 2.0 License for specific language governing permissions
17
17
  and limitations under the License.
18
18
  ***************************************************************************** */
19
- /* global Reflect, Promise */
20
-
21
- var extendStatics = function(d, b) {
22
- extendStatics = Object.setPrototypeOf ||
23
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
24
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
25
- return extendStatics(d, b);
26
- };
27
-
28
- function __extends(d, b) {
29
- extendStatics(d, b);
30
- function __() { this.constructor = d; }
31
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
32
- }
33
-
34
- var __assign = function() {
35
- __assign = Object.assign || function __assign(t) {
36
- for (var s, i = 1, n = arguments.length; i < n; i++) {
37
- s = arguments[i];
38
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
39
- }
40
- return t;
41
- };
42
- return __assign.apply(this, arguments);
43
- };
44
19
 
45
20
  function __decorate(decorators, target, key, desc) {
46
21
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -56,117 +31,74 @@ function __awaiter(thisArg, _arguments, P, generator) {
56
31
  function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
57
32
  step((generator = generator.apply(thisArg, _arguments || [])).next());
58
33
  });
59
- }
60
-
61
- function __generator(thisArg, body) {
62
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
63
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
64
- function verb(n) { return function (v) { return step([n, v]); }; }
65
- function step(op) {
66
- if (f) throw new TypeError("Generator is already executing.");
67
- while (_) try {
68
- 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;
69
- if (y = 0, t) op = [op[0] & 2, t.value];
70
- switch (op[0]) {
71
- case 0: case 1: t = op; break;
72
- case 4: _.label++; return { value: op[1], done: false };
73
- case 5: _.label++; y = op[1]; op = [0]; continue;
74
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
75
- default:
76
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
77
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
78
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
79
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
80
- if (t[2]) _.ops.pop();
81
- _.trys.pop(); continue;
82
- }
83
- op = body.call(thisArg, _);
84
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
85
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
86
- }
87
- }
88
-
89
- function __values(o) {
90
- var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
91
- if (m) return m.call(o);
92
- return {
93
- next: function () {
94
- if (o && i >= o.length) o = void 0;
95
- return { value: o && o[i++], done: !o };
96
- }
97
- };
98
34
  }
99
35
 
100
36
  function uuid(len) {
101
- var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
102
- var uuid = [];
103
- var radix = chars.length;
104
- for (var i = 0; i < len; i++)
37
+ let chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
38
+ let uuid = [];
39
+ let radix = chars.length;
40
+ for (let i = 0; i < len; i++)
105
41
  uuid[i] = chars[0 | (Math.random() * radix)];
106
42
  return uuid.join('');
107
43
  }
108
- var setStyle = function (element, style) {
109
- var width = style.width, height = style.height, position = style.position, _a = style.left, left = _a === void 0 ? 0 : _a, _b = style.top, top = _b === void 0 ? 0 : _b, zIndex = style.zIndex, pointerEvents = style.pointerEvents, background = style.background;
110
- element.style.width = width + "px";
111
- element.style.height = height + "px";
44
+ const setStyle = (element, style) => {
45
+ const { width, height, position, left = 0, top = 0, zIndex, pointerEvents, background } = style;
46
+ element.style.width = `${width}px`;
47
+ element.style.height = `${height}px`;
112
48
  element.style.position = position;
113
- element.style.left = "" + left;
114
- element.style.top = "" + top;
115
- element.style.zIndex = "" + zIndex;
49
+ element.style.left = `${left}`;
50
+ element.style.top = `${top}`;
51
+ element.style.zIndex = `${zIndex}`;
116
52
  element.style.pointerEvents = pointerEvents;
117
53
  element.style.background = background;
118
54
  element.style.border = 'none';
119
55
  element.style.overflow = 'hidden';
120
56
  };
121
- var setTransform = function (element, transform, ratioX, ratioY) {
122
- var worldTransform = transform.worldTransform;
123
- var a = worldTransform.a, b = worldTransform.b, c = worldTransform.c, d = worldTransform.d, tx = worldTransform.tx, ty = worldTransform.ty;
124
- var matrix = "matrix(" + a + ", " + b + ", " + c + ", " + d + ", " + tx * ratioX + ", " + ty * ratioY + ")";
125
- element.style.transform = "" + matrix;
126
- element.style.webkitTransform = "" + matrix;
57
+ const setTransform = (element, transform, ratioX, ratioY) => {
58
+ const { worldTransform } = transform;
59
+ const { a, b, c, d, tx, ty } = worldTransform;
60
+ const matrix = `matrix(${a}, ${b}, ${c}, ${d}, ${tx * ratioX}, ${ty * ratioY})`;
61
+ element.style.transform = `${matrix}`;
62
+ element.style.webkitTransform = `${matrix}`;
127
63
  element.style.transformOrigin = 'left top';
128
64
  element.style.webkitTransformOrigin = 'left top';
129
65
  };
130
66
 
131
- var A11y = (function (_super) {
132
- __extends(A11y, _super);
133
- function A11y(param) {
134
- var _this = _super.call(this) || this;
135
- Object.assign(_this, param);
136
- var _a = param.hint, hint = _a === void 0 ? '' : _a, event = param.event, _b = param.delay, delay = _b === void 0 ? 0 : _b, _c = param.attr, attr = _c === void 0 ? {} : _c, _d = param.role, role = _d === void 0 ? '' : _d, _e = param.props, props = _e === void 0 ? {} : _e, _f = param.state, state = _f === void 0 ? {} : _f;
137
- _this.hint = hint;
138
- _this.event = event;
139
- _this.delay = delay;
140
- _this.attr = attr;
141
- _this.role = role;
142
- _this.props = props;
143
- _this.state = state;
144
- _this.a11yId = "_" + uuid(6);
145
- return _this;
67
+ class A11y extends Component {
68
+ constructor(param) {
69
+ super();
70
+ Object.assign(this, param);
71
+ const { hint = '', event, delay = 0, attr = {}, role = '', props = {}, state = {} } = param;
72
+ this.hint = hint;
73
+ this.event = event;
74
+ this.delay = delay;
75
+ this.attr = attr;
76
+ this.role = role;
77
+ this.props = props;
78
+ this.state = state;
79
+ this.a11yId = `_${uuid(6)}`;
146
80
  }
147
- A11y.componentName = 'A11y';
148
- __decorate([
149
- type('boolean')
150
- ], A11y.prototype, "interactive", void 0);
151
- __decorate([
152
- type('string')
153
- ], A11y.prototype, "hint", void 0);
154
- __decorate([
155
- type('number'),
156
- step(1)
157
- ], A11y.prototype, "delay", void 0);
158
- __decorate([
159
- type('string')
160
- ], A11y.prototype, "role", void 0);
161
- __decorate([
162
- type('string')
163
- ], A11y.prototype, "a11yId", void 0);
164
- return A11y;
165
- }(Component));
166
- var A11y$1 = A11y;
81
+ }
82
+ A11y.componentName = 'A11y';
83
+ __decorate([
84
+ type('boolean')
85
+ ], A11y.prototype, "interactive", void 0);
86
+ __decorate([
87
+ type('string')
88
+ ], A11y.prototype, "hint", void 0);
89
+ __decorate([
90
+ type('number'),
91
+ step(1)
92
+ ], A11y.prototype, "delay", void 0);
93
+ __decorate([
94
+ type('string')
95
+ ], A11y.prototype, "role", void 0);
96
+ __decorate([
97
+ type('string')
98
+ ], A11y.prototype, "a11yId", void 0);
167
99
 
168
- var POSITION = 'absolute';
169
- var ZINDEX = 3;
100
+ const POSITION = 'absolute';
101
+ const ZINDEX = 3;
170
102
  var A11yActivate;
171
103
  (function (A11yActivate) {
172
104
  A11yActivate[A11yActivate["ENABLE"] = 0] = "ENABLE";
@@ -189,119 +121,90 @@ var ElementType;
189
121
  ElementType["DIV"] = "div";
190
122
  })(ElementType || (ElementType = {}));
191
123
 
192
- var notAttr = ['hint', 'event', 'delay', 'attr', 'role', 'props', 'state', 'a11yId', 'name'];
193
- var getEventFunc = function (event, gameObject, e) {
194
- var _this = this;
195
- ['touchstart', 'touchend', 'tap'].forEach(function (name) {
124
+ const notAttr = ['hint', 'event', 'delay', 'attr', 'role', 'props', 'state', 'a11yId', 'name'];
125
+ const getEventFunc = function (event, gameObject, e) {
126
+ ['touchstart', 'touchend', 'tap'].forEach(name => {
196
127
  event.emit(name, {
197
- stopPropagation: function () { return e.stopPropagation(); },
128
+ stopPropagation: () => e.stopPropagation(),
198
129
  data: {
199
- position: _this.eventPosition,
130
+ position: this.eventPosition,
200
131
  },
201
- gameObject: gameObject,
132
+ gameObject,
202
133
  });
203
134
  });
204
135
  };
205
- var A11ySystem = (function (_super) {
206
- __extends(A11ySystem, _super);
207
- function A11ySystem(opt) {
208
- var _this = _super.call(this, opt) || this;
209
- _this.cache = new Map();
210
- _this.eventCache = new Map();
211
- _this.zIndex = ZINDEX;
212
- return _this;
136
+ let A11ySystem = class A11ySystem extends System {
137
+ constructor(opt) {
138
+ super(opt);
139
+ this.cache = new Map();
140
+ this.eventCache = new Map();
141
+ this.zIndex = ZINDEX;
213
142
  }
214
- Object.defineProperty(A11ySystem.prototype, "ratioX", {
215
- get: function () {
216
- if (this._ratioX) {
143
+ get ratioX() {
144
+ if (this._ratioX) {
145
+ return this._ratioX;
146
+ }
147
+ else {
148
+ const success = this.setRatio();
149
+ if (success) {
217
150
  return this._ratioX;
218
151
  }
219
152
  else {
220
- var success = this.setRatio();
221
- if (success) {
222
- return this._ratioX;
223
- }
224
- else {
225
- return 0;
226
- }
153
+ return 0;
227
154
  }
228
- },
229
- enumerable: false,
230
- configurable: true
231
- });
232
- Object.defineProperty(A11ySystem.prototype, "ratioY", {
233
- get: function () {
234
- if (this._ratioY) {
155
+ }
156
+ }
157
+ get ratioY() {
158
+ if (this._ratioY) {
159
+ return this._ratioY;
160
+ }
161
+ else {
162
+ const success = this.setRatio();
163
+ if (success) {
235
164
  return this._ratioY;
236
165
  }
237
166
  else {
238
- var success = this.setRatio();
239
- if (success) {
240
- return this._ratioY;
241
- }
242
- else {
243
- return 0;
244
- }
167
+ return 0;
245
168
  }
246
- },
247
- enumerable: false,
248
- configurable: true
249
- });
250
- A11ySystem.prototype.init = function (opt) {
251
- if (opt === void 0) { opt = {}; }
252
- return __awaiter(this, void 0, void 0, function () {
253
- var _a, activate, _b, delay, _c, checkA11yOpen, zIndex, _d, _e, div;
254
- return __generator(this, function (_f) {
255
- switch (_f.label) {
256
- case 0:
257
- _a = opt.activate, activate = _a === void 0 ? A11yActivate.CHECK : _a, _b = opt.delay, delay = _b === void 0 ? 100 : _b, _c = opt.checkA11yOpen, checkA11yOpen = _c === void 0 ? function () { return Promise.resolve(false); } : _c, zIndex = opt.zIndex;
258
- this.delay = delay;
259
- this.zIndex = zIndex || this.zIndex;
260
- _d = activate;
261
- switch (_d) {
262
- case A11yActivate.CHECK: return [3, 1];
263
- case A11yActivate.DISABLE: return [3, 5];
264
- case A11yActivate.ENABLE: return [3, 6];
265
- }
266
- return [3, 7];
267
- case 1:
268
- _f.trys.push([1, 3, , 4]);
269
- _e = this;
270
- return [4, checkA11yOpen()];
271
- case 2:
272
- _e.activate = _f.sent();
273
- return [3, 4];
274
- case 3:
275
- _f.sent();
276
- this.activate = false;
277
- return [3, 4];
278
- case 4: return [3, 7];
279
- case 5:
169
+ }
170
+ }
171
+ init(opt = {}) {
172
+ return __awaiter(this, void 0, void 0, function* () {
173
+ const { activate = A11yActivate.CHECK, delay = 100, checkA11yOpen = () => Promise.resolve(false), zIndex } = opt;
174
+ this.delay = delay;
175
+ this.zIndex = zIndex || this.zIndex;
176
+ switch (activate) {
177
+ case A11yActivate.CHECK:
178
+ try {
179
+ this.activate = yield checkA11yOpen();
180
+ }
181
+ catch (error) {
280
182
  this.activate = false;
281
- return [3, 7];
282
- case 6:
283
- this.activate = true;
284
- return [3, 7];
285
- case 7:
286
- this.debug = opt.debug || false;
287
- if (this.debug) {
288
- this.activate = true;
289
- }
290
- if (!this.activate)
291
- return [2];
292
- div = document.createElement('div');
293
- this.div = div;
294
- if (this.game.canvas.parentNode) {
295
- this.game.canvas.parentNode.insertBefore(this.div, this.game.canvas);
296
- }
297
- return [2];
298
- }
299
- });
183
+ }
184
+ break;
185
+ case A11yActivate.DISABLE:
186
+ this.activate = false;
187
+ break;
188
+ case A11yActivate.ENABLE:
189
+ this.activate = true;
190
+ break;
191
+ }
192
+ this.debug = opt.debug || false;
193
+ if (this.debug) {
194
+ this.activate = true;
195
+ }
196
+ if (!this.activate)
197
+ return;
198
+ const div = document.createElement('div');
199
+ this.div = div;
200
+ if (this.game.canvas.parentNode) {
201
+ this.game.canvas.parentNode.insertBefore(this.div, this.game.canvas);
202
+ }
300
203
  });
301
- };
302
- A11ySystem.prototype.setRatio = function () {
303
- var _a = this.getCanvasBoundingClientRect(), width = _a.width, height = _a.height;
304
- var _b = this.getRenderRect(), renderWidth = _b.renderWidth, renderHeight = _b.renderHeight;
204
+ }
205
+ setRatio() {
206
+ const { width, height } = this.getCanvasBoundingClientRect();
207
+ const { renderWidth, renderHeight } = this.getRenderRect();
305
208
  this._ratioX = width / renderWidth;
306
209
  this._ratioY = height / renderHeight;
307
210
  if (width || height) {
@@ -311,226 +214,178 @@ var A11ySystem = (function (_super) {
311
214
  else {
312
215
  return false;
313
216
  }
314
- };
315
- A11ySystem.prototype.getRenderRect = function () {
316
- var _a = this.game.getSystem(RendererSystem).params, params = _a === void 0 ? { width: 300, height: 300 } : _a;
317
- var renderHeight = params.height, renderWidth = params.width;
318
- return { renderWidth: renderWidth, renderHeight: renderHeight };
319
- };
320
- A11ySystem.prototype.getCanvasBoundingClientRect = function () {
321
- var _a = this.game.canvas.getBoundingClientRect(), width = _a.width, height = _a.height, left = _a.left, top = _a.top;
322
- return { width: width, height: height, left: left, top: top };
323
- };
324
- A11ySystem.prototype.initDiv = function () {
325
- var _this = this;
326
- var pageXOffset = window.pageXOffset, pageYOffset = window.pageYOffset;
327
- var _a = this.getCanvasBoundingClientRect(), width = _a.width, height = _a.height, left = _a.left, top = _a.top;
328
- var style = {
329
- width: width,
330
- height: height,
331
- left: left + pageXOffset + "px",
332
- top: top + pageYOffset + "px",
217
+ }
218
+ getRenderRect() {
219
+ const { params = { width: 300, height: 300 } } = this.game.getSystem(RendererSystem);
220
+ const { height: renderHeight, width: renderWidth } = params;
221
+ return { renderWidth, renderHeight };
222
+ }
223
+ getCanvasBoundingClientRect() {
224
+ const { width, height, left, top } = this.game.canvas.getBoundingClientRect();
225
+ return { width, height, left, top };
226
+ }
227
+ initDiv() {
228
+ const { pageXOffset, pageYOffset } = window;
229
+ const { width, height, left, top } = this.getCanvasBoundingClientRect();
230
+ const style = {
231
+ width,
232
+ height,
233
+ left: `${left + pageXOffset}px`,
234
+ top: `${top + pageYOffset}px`,
333
235
  position: POSITION,
334
236
  zIndex: this.zIndex,
335
237
  pointerEvents: PointerEvents.NONE,
336
238
  background: MaskBackground.NONE,
337
239
  };
338
240
  setStyle(this.div, style);
339
- this.div.addEventListener('click', function (e) {
340
- var currentTarget = e.currentTarget;
341
- var _a = currentTarget.getBoundingClientRect(), left = _a.left, top = _a.top;
342
- var x = (e.pageX - left) / _this.ratioX;
343
- var y = (e.pageY - top) / _this.ratioY;
344
- _this.eventPosition = { x: x, y: y };
241
+ this.div.addEventListener('click', e => {
242
+ const currentTarget = e.currentTarget;
243
+ const { left, top } = currentTarget.getBoundingClientRect();
244
+ const x = (e.pageX - left) / this.ratioX;
245
+ const y = (e.pageY - top) / this.ratioY;
246
+ this.eventPosition = { x, y };
345
247
  }, true);
346
- };
347
- A11ySystem.prototype.update = function () {
348
- return __awaiter(this, void 0, void 0, function () {
349
- var changes, changes_1, changes_1_1, changed;
350
- var e_1, _a;
351
- return __generator(this, function (_b) {
352
- changes = this.componentObserver.clear();
353
- if (!this.activate) {
354
- return [2];
355
- }
356
- try {
357
- for (changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
358
- changed = changes_1_1.value;
359
- switch (changed.type) {
360
- case OBSERVER_TYPE.ADD:
361
- changed.componentName === 'Event' && this.addEvent(changed.gameObject);
362
- changed.componentName === 'A11y' && this.add(changed);
363
- break;
364
- case OBSERVER_TYPE.CHANGE:
365
- changed.componentName === 'Transform' && this.transformChange(changed);
366
- changed.componentName === 'A11y' && this.change(changed);
367
- break;
368
- case OBSERVER_TYPE.REMOVE:
369
- changed.componentName === 'Event' && this.removeEvent(changed);
370
- changed.componentName === 'A11y' && this.remove(changed);
371
- }
372
- }
373
- }
374
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
375
- finally {
376
- try {
377
- if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
378
- }
379
- finally { if (e_1) throw e_1.error; }
248
+ }
249
+ update() {
250
+ return __awaiter(this, void 0, void 0, function* () {
251
+ const changes = this.componentObserver.clear();
252
+ if (!this.activate) {
253
+ return;
254
+ }
255
+ for (const changed of changes) {
256
+ switch (changed.type) {
257
+ case OBSERVER_TYPE.ADD:
258
+ changed.componentName === 'Event' && this.addEvent(changed.gameObject);
259
+ changed.componentName === 'A11y' && this.add(changed);
260
+ break;
261
+ case OBSERVER_TYPE.CHANGE:
262
+ changed.componentName === 'Transform' && this.transformChange(changed);
263
+ changed.componentName === 'A11y' && this.change(changed);
264
+ break;
265
+ case OBSERVER_TYPE.REMOVE:
266
+ changed.componentName === 'Event' && this.removeEvent(changed);
267
+ changed.componentName === 'A11y' && this.remove(changed);
380
268
  }
381
- return [2];
382
- });
269
+ }
383
270
  });
384
- };
385
- A11ySystem.prototype.change = function (changed) {
386
- var component = changed.component;
271
+ }
272
+ change(changed) {
273
+ const component = changed.component;
387
274
  if (changed.prop.prop[0] === 'hint') {
388
- var dom = this.cache.get(component.a11yId);
275
+ const dom = this.cache.get(component.a11yId);
389
276
  dom === null || dom === void 0 ? void 0 : dom.setAttribute('aria-label', component.hint);
390
277
  dom && this.setPosition(dom, changed.gameObject.transform);
391
278
  }
392
- };
393
- A11ySystem.prototype.remove = function (changed) {
394
- var component = changed.component;
279
+ }
280
+ remove(changed) {
281
+ const component = changed.component;
395
282
  if (!component)
396
283
  return;
397
- var a11yId = component.a11yId;
398
- var element = this.div.querySelector("#" + a11yId);
284
+ const { a11yId } = component;
285
+ const element = this.div.querySelector(`#${a11yId}`);
399
286
  element && this.div.removeChild(element);
400
287
  this.cache.delete(a11yId);
401
- };
402
- A11ySystem.prototype.add = function (changed) {
403
- var _this = this;
288
+ }
289
+ add(changed) {
404
290
  if (!this.activate)
405
291
  return;
406
- var component = changed.component;
407
- var gameObject = changed.gameObject;
408
- var delay = component.delay, id = component.a11yId;
409
- var event = component.event;
292
+ const component = changed.component;
293
+ const { gameObject } = changed;
294
+ const { delay, a11yId: id } = component;
295
+ let { event } = component;
410
296
  if (!gameObject)
411
297
  return;
412
- var transform = gameObject.transform;
298
+ const { transform } = gameObject;
413
299
  if (!transform)
414
300
  return;
415
- var element = document.createElement('div');
301
+ const element = document.createElement('div');
416
302
  this.cache.set(id, element);
417
303
  if (!event) {
418
304
  event = gameObject.getComponent('Event');
419
305
  }
420
- setTimeout(function () {
421
- _this.setPosition(element, transform);
422
- _this.setA11yAttr(element, component);
306
+ setTimeout(() => {
307
+ this.setPosition(element, transform);
308
+ this.setA11yAttr(element, component);
423
309
  if (event) {
424
- _this.addEvent(gameObject);
310
+ this.addEvent(gameObject);
425
311
  }
426
312
  if (gameObject.scene) {
427
- _this.div.appendChild(element);
313
+ this.div.appendChild(element);
428
314
  }
429
315
  }, delay || this.delay);
430
- };
431
- A11ySystem.prototype.transformChange = function (changed) {
432
- var component = changed.component;
433
- var gameObject = changed.gameObject;
434
- var a11yComponent = gameObject.getComponent(A11y$1);
316
+ }
317
+ transformChange(changed) {
318
+ const component = changed.component;
319
+ const { gameObject } = changed;
320
+ const a11yComponent = gameObject.getComponent(A11y);
435
321
  if (!a11yComponent)
436
322
  return;
437
- var a11yId = a11yComponent.a11yId;
323
+ const { a11yId } = a11yComponent;
438
324
  if (!component.inScene) {
439
- var dom = this.div.querySelector("#" + a11yId);
325
+ const dom = this.div.querySelector(`#${a11yId}`);
440
326
  dom && this.div.removeChild(dom);
441
327
  }
442
328
  else {
443
329
  if (this.cache.has(a11yId)) {
444
- var addDom = this.cache.get(a11yId);
330
+ const addDom = this.cache.get(a11yId);
445
331
  addDom && this.div.appendChild(addDom);
446
332
  }
447
333
  }
448
- };
449
- A11ySystem.prototype.setEvent = function (element, event, gameObject, id) {
334
+ }
335
+ setEvent(element, event, gameObject, id) {
450
336
  if (!event) {
451
337
  return;
452
338
  }
453
- var func = getEventFunc.bind(this, event, gameObject);
339
+ const func = getEventFunc.bind(this, event, gameObject);
454
340
  this.eventCache.set(id, func);
455
341
  element.addEventListener('click', func);
456
- };
457
- A11ySystem.prototype.addEvent = function (gameObject) {
458
- var a11y = gameObject.getComponent(A11y$1);
342
+ }
343
+ addEvent(gameObject) {
344
+ const a11y = gameObject.getComponent(A11y);
459
345
  if (!a11y)
460
346
  return;
461
- var event = gameObject.getComponent('Event');
347
+ const event = gameObject.getComponent('Event');
462
348
  if (!event)
463
349
  return;
464
- var element = this.cache.get(a11y.a11yId);
350
+ const element = this.cache.get(a11y.a11yId);
465
351
  element && this.setEvent(element, event, gameObject, a11y.a11yId);
466
- };
467
- A11ySystem.prototype.removeEvent = function (changed) {
468
- var gameObject = changed.gameObject;
469
- var a11y = gameObject.getComponent(A11y$1);
352
+ }
353
+ removeEvent(changed) {
354
+ const { gameObject } = changed;
355
+ const a11y = gameObject.getComponent(A11y);
470
356
  if (!a11y)
471
357
  return;
472
- var event = changed.component;
358
+ const event = changed.component;
473
359
  if (!event)
474
360
  return;
475
- var a11yId = a11y.a11yId;
476
- var func = this.eventCache.get(a11yId);
477
- var element = this.cache.get(a11yId);
361
+ const { a11yId } = a11y;
362
+ const func = this.eventCache.get(a11yId);
363
+ const element = this.cache.get(a11yId);
478
364
  element && element.removeEventListener('click', func);
479
- };
480
- A11ySystem.prototype.setA11yAttr = function (element, component) {
481
- var e_2, _a, e_3, _b, e_4, _c;
482
- var hint = component.hint, _d = component.props, props = _d === void 0 ? {} : _d, _e = component.state, state = _e === void 0 ? {} : _e, role = component.role, id = component.a11yId;
483
- var realRole = role || 'text';
365
+ }
366
+ setA11yAttr(element, component) {
367
+ const { hint, props = {}, state = {}, role, a11yId: id } = component;
368
+ const realRole = role || 'text';
484
369
  element.setAttribute('role', realRole);
485
370
  element.setAttribute('aria-label', hint);
486
371
  element.id = id;
487
- var ariaProps = Object.keys(props);
488
- try {
489
- for (var ariaProps_1 = __values(ariaProps), ariaProps_1_1 = ariaProps_1.next(); !ariaProps_1_1.done; ariaProps_1_1 = ariaProps_1.next()) {
490
- var key = ariaProps_1_1.value;
491
- element.setAttribute(key, props[key]);
492
- }
372
+ const ariaProps = Object.keys(props);
373
+ for (const key of ariaProps) {
374
+ element.setAttribute(key, props[key]);
493
375
  }
494
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
495
- finally {
496
- try {
497
- if (ariaProps_1_1 && !ariaProps_1_1.done && (_a = ariaProps_1.return)) _a.call(ariaProps_1);
498
- }
499
- finally { if (e_2) throw e_2.error; }
500
- }
501
- var ariaState = Object.keys(state);
502
- try {
503
- for (var ariaState_1 = __values(ariaState), ariaState_1_1 = ariaState_1.next(); !ariaState_1_1.done; ariaState_1_1 = ariaState_1.next()) {
504
- var key = ariaState_1_1.value;
505
- element.setAttribute(key, state[key]);
506
- }
376
+ const ariaState = Object.keys(state);
377
+ for (const key of ariaState) {
378
+ element.setAttribute(key, state[key]);
507
379
  }
508
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
509
- finally {
510
- try {
511
- if (ariaState_1_1 && !ariaState_1_1.done && (_b = ariaState_1.return)) _b.call(ariaState_1);
380
+ for (const key of Object.keys(component)) {
381
+ if (typeof component[key] === 'string' && notAttr.indexOf(key) === -1 && key.indexOf('_') !== 1) {
382
+ element.setAttribute(key, component[key]);
512
383
  }
513
- finally { if (e_3) throw e_3.error; }
514
384
  }
515
- try {
516
- for (var _f = __values(Object.keys(component)), _g = _f.next(); !_g.done; _g = _f.next()) {
517
- var key = _g.value;
518
- if (typeof component[key] === 'string' && notAttr.indexOf(key) === -1 && key.indexOf('_') !== 1) {
519
- element.setAttribute(key, component[key]);
520
- }
521
- }
522
- }
523
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
524
- finally {
525
- try {
526
- if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
527
- }
528
- finally { if (e_4) throw e_4.error; }
529
- }
530
- };
531
- A11ySystem.prototype.setPosition = function (element, transform) {
532
- var _a = transform.size, width = _a.width, height = _a.height;
533
- var style = {
385
+ }
386
+ setPosition(element, transform) {
387
+ const { width, height } = transform.size;
388
+ const style = {
534
389
  width: width === 0 ? 1 : width * this.ratioX,
535
390
  height: height === 0 ? 1 : height * this.ratioY,
536
391
  position: POSITION,
@@ -538,26 +393,25 @@ var A11ySystem = (function (_super) {
538
393
  pointerEvents: PointerEvents.AUTO,
539
394
  background: this.debug ? MaskBackground.DEBUG : MaskBackground.NONE,
540
395
  };
541
- var transformProps = __assign({}, transform);
396
+ const transformProps = Object.assign({}, transform);
542
397
  setStyle(element, style);
543
398
  setTransform(element, transformProps, this.ratioX, this.ratioY);
544
- };
545
- A11ySystem.prototype.onDestroy = function () {
399
+ }
400
+ onDestroy() {
546
401
  this.div.parentElement.removeChild(this.div);
547
402
  this.cache = null;
548
403
  this.eventCache = null;
549
404
  this.div = null;
550
- };
551
- A11ySystem.systemName = 'A11ySystem';
552
- A11ySystem = __decorate([
553
- decorators.componentObserver({
554
- A11y: ['hint'],
555
- Transform: ['inScene'],
556
- Event: [],
557
- })
558
- ], A11ySystem);
559
- return A11ySystem;
560
- }(System));
405
+ }
406
+ };
407
+ A11ySystem.systemName = 'A11ySystem';
408
+ A11ySystem = __decorate([
409
+ decorators.componentObserver({
410
+ A11y: ['hint'],
411
+ Transform: ['inScene'],
412
+ Event: [],
413
+ })
414
+ ], A11ySystem);
561
415
  var A11ySystem$1 = A11ySystem;
562
416
 
563
- export { A11y$1 as A11y, A11yActivate, A11ySystem$1 as A11ySystem };
417
+ export { A11y, A11yActivate, A11ySystem$1 as A11ySystem };