@eva/plugin-a11y 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.
- package/dist/miniprogram.js +631 -0
- package/dist/plugin-a11y.cjs.js +568 -0
- package/dist/plugin-a11y.cjs.prod.js +1 -0
- package/dist/plugin-a11y.esm.js +563 -0
- package/package.json +3 -3
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
import { Component, decorators, System, OBSERVER_TYPE } from '@eva/eva.js';
|
|
2
|
+
import { RendererSystem } from '@eva/plugin-renderer';
|
|
3
|
+
import { type, step } from '@eva/inspector-decorator';
|
|
4
|
+
|
|
5
|
+
/*! *****************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
8
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
9
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
12
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
13
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
14
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
15
|
+
|
|
16
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
17
|
+
and limitations under the License.
|
|
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
|
+
|
|
45
|
+
function __decorate(decorators, target, key, desc) {
|
|
46
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
47
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
48
|
+
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;
|
|
49
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
53
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
54
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
55
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
56
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
57
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
58
|
+
});
|
|
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
|
+
}
|
|
99
|
+
|
|
100
|
+
function uuid(len) {
|
|
101
|
+
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
|
|
102
|
+
var uuid = [];
|
|
103
|
+
var radix = chars.length;
|
|
104
|
+
for (var i = 0; i < len; i++)
|
|
105
|
+
uuid[i] = chars[0 | (Math.random() * radix)];
|
|
106
|
+
return uuid.join('');
|
|
107
|
+
}
|
|
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";
|
|
112
|
+
element.style.position = position;
|
|
113
|
+
element.style.left = "" + left;
|
|
114
|
+
element.style.top = "" + top;
|
|
115
|
+
element.style.zIndex = "" + zIndex;
|
|
116
|
+
element.style.pointerEvents = pointerEvents;
|
|
117
|
+
element.style.background = background;
|
|
118
|
+
element.style.border = 'none';
|
|
119
|
+
element.style.overflow = 'hidden';
|
|
120
|
+
};
|
|
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;
|
|
127
|
+
element.style.transformOrigin = 'left top';
|
|
128
|
+
element.style.webkitTransformOrigin = 'left top';
|
|
129
|
+
};
|
|
130
|
+
|
|
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;
|
|
146
|
+
}
|
|
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;
|
|
167
|
+
|
|
168
|
+
var POSITION = 'absolute';
|
|
169
|
+
var ZINDEX = 3;
|
|
170
|
+
var A11yActivate;
|
|
171
|
+
(function (A11yActivate) {
|
|
172
|
+
A11yActivate[A11yActivate["ENABLE"] = 0] = "ENABLE";
|
|
173
|
+
A11yActivate[A11yActivate["DISABLE"] = 1] = "DISABLE";
|
|
174
|
+
A11yActivate[A11yActivate["CHECK"] = 2] = "CHECK";
|
|
175
|
+
})(A11yActivate || (A11yActivate = {}));
|
|
176
|
+
var PointerEvents;
|
|
177
|
+
(function (PointerEvents) {
|
|
178
|
+
PointerEvents["NONE"] = "none";
|
|
179
|
+
PointerEvents["AUTO"] = "auto";
|
|
180
|
+
})(PointerEvents || (PointerEvents = {}));
|
|
181
|
+
var MaskBackground;
|
|
182
|
+
(function (MaskBackground) {
|
|
183
|
+
MaskBackground["DEBUG"] = "rgba(255,0,0,0.5)";
|
|
184
|
+
MaskBackground["NONE"] = "transparent";
|
|
185
|
+
})(MaskBackground || (MaskBackground = {}));
|
|
186
|
+
var ElementType;
|
|
187
|
+
(function (ElementType) {
|
|
188
|
+
ElementType["BUTTON"] = "button";
|
|
189
|
+
ElementType["DIV"] = "div";
|
|
190
|
+
})(ElementType || (ElementType = {}));
|
|
191
|
+
|
|
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) {
|
|
196
|
+
event.emit(name, {
|
|
197
|
+
stopPropagation: function () { return e.stopPropagation(); },
|
|
198
|
+
data: {
|
|
199
|
+
position: _this.eventPosition,
|
|
200
|
+
},
|
|
201
|
+
gameObject: gameObject,
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
};
|
|
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;
|
|
213
|
+
}
|
|
214
|
+
Object.defineProperty(A11ySystem.prototype, "ratioX", {
|
|
215
|
+
get: function () {
|
|
216
|
+
if (this._ratioX) {
|
|
217
|
+
return this._ratioX;
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
var success = this.setRatio();
|
|
221
|
+
if (success) {
|
|
222
|
+
return this._ratioX;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
enumerable: false,
|
|
230
|
+
configurable: true
|
|
231
|
+
});
|
|
232
|
+
Object.defineProperty(A11ySystem.prototype, "ratioY", {
|
|
233
|
+
get: function () {
|
|
234
|
+
if (this._ratioY) {
|
|
235
|
+
return this._ratioY;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
var success = this.setRatio();
|
|
239
|
+
if (success) {
|
|
240
|
+
return this._ratioY;
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
return 0;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
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:
|
|
280
|
+
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
|
+
});
|
|
300
|
+
});
|
|
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;
|
|
305
|
+
this._ratioX = width / renderWidth;
|
|
306
|
+
this._ratioY = height / renderHeight;
|
|
307
|
+
if (width || height) {
|
|
308
|
+
this.initDiv();
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
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",
|
|
333
|
+
position: POSITION,
|
|
334
|
+
zIndex: this.zIndex,
|
|
335
|
+
pointerEvents: PointerEvents.NONE,
|
|
336
|
+
background: MaskBackground.NONE,
|
|
337
|
+
};
|
|
338
|
+
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 };
|
|
345
|
+
}, 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; }
|
|
380
|
+
}
|
|
381
|
+
return [2];
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
A11ySystem.prototype.change = function (changed) {
|
|
386
|
+
var component = changed.component;
|
|
387
|
+
if (changed.prop.prop[0] === 'hint') {
|
|
388
|
+
var dom = this.cache.get(component.a11yId);
|
|
389
|
+
dom === null || dom === void 0 ? void 0 : dom.setAttribute('aria-label', component.hint);
|
|
390
|
+
dom && this.setPosition(dom, changed.gameObject.transform);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
A11ySystem.prototype.remove = function (changed) {
|
|
394
|
+
var component = changed.component;
|
|
395
|
+
if (!component)
|
|
396
|
+
return;
|
|
397
|
+
var a11yId = component.a11yId;
|
|
398
|
+
var element = this.div.querySelector("#" + a11yId);
|
|
399
|
+
element && this.div.removeChild(element);
|
|
400
|
+
this.cache.delete(a11yId);
|
|
401
|
+
};
|
|
402
|
+
A11ySystem.prototype.add = function (changed) {
|
|
403
|
+
var _this = this;
|
|
404
|
+
if (!this.activate)
|
|
405
|
+
return;
|
|
406
|
+
var component = changed.component;
|
|
407
|
+
var gameObject = changed.gameObject;
|
|
408
|
+
var delay = component.delay, id = component.a11yId;
|
|
409
|
+
var event = component.event;
|
|
410
|
+
if (!gameObject)
|
|
411
|
+
return;
|
|
412
|
+
var transform = gameObject.transform;
|
|
413
|
+
if (!transform)
|
|
414
|
+
return;
|
|
415
|
+
var element = document.createElement('div');
|
|
416
|
+
this.cache.set(id, element);
|
|
417
|
+
if (!event) {
|
|
418
|
+
event = gameObject.getComponent('Event');
|
|
419
|
+
}
|
|
420
|
+
setTimeout(function () {
|
|
421
|
+
_this.setPosition(element, transform);
|
|
422
|
+
_this.setA11yAttr(element, component);
|
|
423
|
+
if (event) {
|
|
424
|
+
_this.addEvent(gameObject);
|
|
425
|
+
}
|
|
426
|
+
if (gameObject.scene) {
|
|
427
|
+
_this.div.appendChild(element);
|
|
428
|
+
}
|
|
429
|
+
}, 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);
|
|
435
|
+
if (!a11yComponent)
|
|
436
|
+
return;
|
|
437
|
+
var a11yId = a11yComponent.a11yId;
|
|
438
|
+
if (!component.inScene) {
|
|
439
|
+
var dom = this.div.querySelector("#" + a11yId);
|
|
440
|
+
dom && this.div.removeChild(dom);
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
if (this.cache.has(a11yId)) {
|
|
444
|
+
var addDom = this.cache.get(a11yId);
|
|
445
|
+
addDom && this.div.appendChild(addDom);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
A11ySystem.prototype.setEvent = function (element, event, gameObject, id) {
|
|
450
|
+
if (!event) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
var func = getEventFunc.bind(this, event, gameObject);
|
|
454
|
+
this.eventCache.set(id, func);
|
|
455
|
+
element.addEventListener('click', func);
|
|
456
|
+
};
|
|
457
|
+
A11ySystem.prototype.addEvent = function (gameObject) {
|
|
458
|
+
var a11y = gameObject.getComponent(A11y$1);
|
|
459
|
+
if (!a11y)
|
|
460
|
+
return;
|
|
461
|
+
var event = gameObject.getComponent('Event');
|
|
462
|
+
if (!event)
|
|
463
|
+
return;
|
|
464
|
+
var element = this.cache.get(a11y.a11yId);
|
|
465
|
+
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);
|
|
470
|
+
if (!a11y)
|
|
471
|
+
return;
|
|
472
|
+
var event = changed.component;
|
|
473
|
+
if (!event)
|
|
474
|
+
return;
|
|
475
|
+
var a11yId = a11y.a11yId;
|
|
476
|
+
var func = this.eventCache.get(a11yId);
|
|
477
|
+
var element = this.cache.get(a11yId);
|
|
478
|
+
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';
|
|
484
|
+
element.setAttribute('role', realRole);
|
|
485
|
+
element.setAttribute('aria-label', hint);
|
|
486
|
+
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
|
+
}
|
|
493
|
+
}
|
|
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
|
+
}
|
|
507
|
+
}
|
|
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);
|
|
512
|
+
}
|
|
513
|
+
finally { if (e_3) throw e_3.error; }
|
|
514
|
+
}
|
|
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 = {
|
|
534
|
+
width: width === 0 ? 1 : width * this.ratioX,
|
|
535
|
+
height: height === 0 ? 1 : height * this.ratioY,
|
|
536
|
+
position: POSITION,
|
|
537
|
+
zIndex: this.zIndex,
|
|
538
|
+
pointerEvents: PointerEvents.AUTO,
|
|
539
|
+
background: this.debug ? MaskBackground.DEBUG : MaskBackground.NONE,
|
|
540
|
+
};
|
|
541
|
+
var transformProps = __assign({}, transform);
|
|
542
|
+
setStyle(element, style);
|
|
543
|
+
setTransform(element, transformProps, this.ratioX, this.ratioY);
|
|
544
|
+
};
|
|
545
|
+
A11ySystem.prototype.onDestroy = function () {
|
|
546
|
+
this.div.parentElement.removeChild(this.div);
|
|
547
|
+
this.cache = null;
|
|
548
|
+
this.eventCache = null;
|
|
549
|
+
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));
|
|
561
|
+
var A11ySystem$1 = A11ySystem;
|
|
562
|
+
|
|
563
|
+
export { A11y$1 as A11y, A11yActivate, A11ySystem$1 as A11ySystem };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-a11y",
|
|
3
|
-
"version": "1.2.2-
|
|
3
|
+
"version": "1.2.2-mini.1",
|
|
4
4
|
"description": "@eva/plugin-a11y",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-a11y.esm.js",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@eva/eva.js": "1.2.2-
|
|
21
|
+
"@eva/eva.js": "1.2.2-mini.1",
|
|
22
22
|
"@eva/inspector-decorator": "^0.0.5",
|
|
23
|
-
"@eva/plugin-renderer": "1.2.2-
|
|
23
|
+
"@eva/plugin-renderer": "1.2.2-mini.1",
|
|
24
24
|
"eventemitter3": "^3.1.2"
|
|
25
25
|
}
|
|
26
26
|
}
|