@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.
- package/dist/EVA.plugin.a11y.js +314 -516
- package/dist/EVA.plugin.a11y.min.js +1 -1
- package/dist/plugin-a11y.cjs.js +239 -385
- package/dist/plugin-a11y.cjs.prod.js +16 -1
- package/dist/plugin-a11y.esm.js +240 -386
- package/package.json +3 -3
package/dist/plugin-a11y.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component,
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
for (
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
element.style.width = width
|
|
111
|
-
element.style.height = height
|
|
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 =
|
|
114
|
-
element.style.top =
|
|
115
|
-
element.style.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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
element.style.transform =
|
|
126
|
-
element.style.webkitTransform =
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
169
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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:
|
|
128
|
+
stopPropagation: () => e.stopPropagation(),
|
|
198
129
|
data: {
|
|
199
|
-
position:
|
|
130
|
+
position: this.eventPosition,
|
|
200
131
|
},
|
|
201
|
-
gameObject
|
|
132
|
+
gameObject,
|
|
202
133
|
});
|
|
203
134
|
});
|
|
204
135
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
221
|
-
if (success) {
|
|
222
|
-
return this._ratioX;
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
return 0;
|
|
226
|
-
}
|
|
153
|
+
return 0;
|
|
227
154
|
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
-
|
|
239
|
-
if (success) {
|
|
240
|
-
return this._ratioY;
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
return 0;
|
|
244
|
-
}
|
|
167
|
+
return 0;
|
|
245
168
|
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
return { renderWidth
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
return { width
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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',
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
-
|
|
348
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
-
|
|
382
|
-
});
|
|
269
|
+
}
|
|
383
270
|
});
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
|
|
271
|
+
}
|
|
272
|
+
change(changed) {
|
|
273
|
+
const component = changed.component;
|
|
387
274
|
if (changed.prop.prop[0] === 'hint') {
|
|
388
|
-
|
|
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
|
-
|
|
394
|
-
|
|
279
|
+
}
|
|
280
|
+
remove(changed) {
|
|
281
|
+
const component = changed.component;
|
|
395
282
|
if (!component)
|
|
396
283
|
return;
|
|
397
|
-
|
|
398
|
-
|
|
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
|
-
|
|
403
|
-
var _this = this;
|
|
288
|
+
}
|
|
289
|
+
add(changed) {
|
|
404
290
|
if (!this.activate)
|
|
405
291
|
return;
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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
|
-
|
|
298
|
+
const { transform } = gameObject;
|
|
413
299
|
if (!transform)
|
|
414
300
|
return;
|
|
415
|
-
|
|
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(
|
|
421
|
-
|
|
422
|
-
|
|
306
|
+
setTimeout(() => {
|
|
307
|
+
this.setPosition(element, transform);
|
|
308
|
+
this.setA11yAttr(element, component);
|
|
423
309
|
if (event) {
|
|
424
|
-
|
|
310
|
+
this.addEvent(gameObject);
|
|
425
311
|
}
|
|
426
312
|
if (gameObject.scene) {
|
|
427
|
-
|
|
313
|
+
this.div.appendChild(element);
|
|
428
314
|
}
|
|
429
315
|
}, delay || this.delay);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
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
|
-
|
|
323
|
+
const { a11yId } = a11yComponent;
|
|
438
324
|
if (!component.inScene) {
|
|
439
|
-
|
|
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
|
-
|
|
330
|
+
const addDom = this.cache.get(a11yId);
|
|
445
331
|
addDom && this.div.appendChild(addDom);
|
|
446
332
|
}
|
|
447
333
|
}
|
|
448
|
-
}
|
|
449
|
-
|
|
334
|
+
}
|
|
335
|
+
setEvent(element, event, gameObject, id) {
|
|
450
336
|
if (!event) {
|
|
451
337
|
return;
|
|
452
338
|
}
|
|
453
|
-
|
|
339
|
+
const func = getEventFunc.bind(this, event, gameObject);
|
|
454
340
|
this.eventCache.set(id, func);
|
|
455
341
|
element.addEventListener('click', func);
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
|
|
342
|
+
}
|
|
343
|
+
addEvent(gameObject) {
|
|
344
|
+
const a11y = gameObject.getComponent(A11y);
|
|
459
345
|
if (!a11y)
|
|
460
346
|
return;
|
|
461
|
-
|
|
347
|
+
const event = gameObject.getComponent('Event');
|
|
462
348
|
if (!event)
|
|
463
349
|
return;
|
|
464
|
-
|
|
350
|
+
const element = this.cache.get(a11y.a11yId);
|
|
465
351
|
element && this.setEvent(element, event, gameObject, a11y.a11yId);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
352
|
+
}
|
|
353
|
+
removeEvent(changed) {
|
|
354
|
+
const { gameObject } = changed;
|
|
355
|
+
const a11y = gameObject.getComponent(A11y);
|
|
470
356
|
if (!a11y)
|
|
471
357
|
return;
|
|
472
|
-
|
|
358
|
+
const event = changed.component;
|
|
473
359
|
if (!event)
|
|
474
360
|
return;
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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
|
-
|
|
481
|
-
|
|
482
|
-
|
|
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
|
-
|
|
488
|
-
|
|
489
|
-
|
|
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
|
-
|
|
495
|
-
|
|
496
|
-
|
|
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
|
-
|
|
509
|
-
|
|
510
|
-
|
|
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
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
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
|
-
|
|
396
|
+
const transformProps = Object.assign({}, transform);
|
|
542
397
|
setStyle(element, style);
|
|
543
398
|
setTransform(element, transformProps, this.ratioX, this.ratioY);
|
|
544
|
-
}
|
|
545
|
-
|
|
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
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
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
|
|
417
|
+
export { A11y, A11yActivate, A11ySystem$1 as A11ySystem };
|