@eva/plugin-a11y 1.2.2-alpha.1 → 1.2.2-alpha.5

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