@eva/plugin-a11y 1.2.0-alpha.5 → 1.2.0

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.
@@ -212,6 +212,7 @@ var A11ySystem = (function (_super) {
212
212
  var _this = _super.call(this, opt) || this;
213
213
  _this.cache = new Map();
214
214
  _this.eventCache = new Map();
215
+ _this.zIndex = ZINDEX;
215
216
  return _this;
216
217
  }
217
218
  Object.defineProperty(A11ySystem.prototype, "ratioX", {
@@ -253,12 +254,13 @@ var A11ySystem = (function (_super) {
253
254
  A11ySystem.prototype.init = function (opt) {
254
255
  if (opt === void 0) { opt = {}; }
255
256
  return __awaiter(this, void 0, void 0, function () {
256
- var _a, activate, _b, delay, _c, checkA11yOpen, _d, _e, div;
257
+ var _a, activate, _b, delay, _c, checkA11yOpen, zIndex, _d, _e, div;
257
258
  return __generator(this, function (_f) {
258
259
  switch (_f.label) {
259
260
  case 0:
260
- _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;
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;
261
262
  this.delay = delay;
263
+ this.zIndex = zIndex || this.zIndex;
262
264
  _d = activate;
263
265
  switch (_d) {
264
266
  case exports.A11yActivate.CHECK: return [3, 1];
@@ -294,7 +296,7 @@ var A11ySystem = (function (_super) {
294
296
  div = document.createElement('div');
295
297
  this.div = div;
296
298
  if (this.game.canvas.parentNode) {
297
- this.game.canvas.parentNode.appendChild(this.div);
299
+ this.game.canvas.parentNode.insertBefore(this.div, this.game.canvas);
298
300
  }
299
301
  return [2];
300
302
  }
@@ -333,7 +335,7 @@ var A11ySystem = (function (_super) {
333
335
  left: left + pageXOffset + "px",
334
336
  top: top + pageYOffset + "px",
335
337
  position: POSITION,
336
- zIndex: ZINDEX,
338
+ zIndex: this.zIndex,
337
339
  pointerEvents: PointerEvents.NONE,
338
340
  background: MaskBackground.NONE,
339
341
  };
@@ -536,7 +538,7 @@ var A11ySystem = (function (_super) {
536
538
  width: width === 0 ? 1 : width * this.ratioX,
537
539
  height: height === 0 ? 1 : height * this.ratioY,
538
540
  position: POSITION,
539
- zIndex: ZINDEX,
541
+ zIndex: this.zIndex,
540
542
  pointerEvents: PointerEvents.AUTO,
541
543
  background: this.debug ? MaskBackground.DEBUG : MaskBackground.NONE,
542
544
  };
@@ -548,6 +550,7 @@ var A11ySystem = (function (_super) {
548
550
  this.div.parentElement.removeChild(this.div);
549
551
  this.cache = null;
550
552
  this.eventCache = null;
553
+ this.div = null;
551
554
  };
552
555
  A11ySystem.systemName = 'A11ySystem';
553
556
  A11ySystem = __decorate([
@@ -1 +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 o(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function a(t,e,n,r){var o,i=arguments.length,a=i<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--)(o=t[s])&&(a=(i<3?o(a):i>3?o(e,n,a):o(e,n))||a);return i>3&&a&&Object.defineProperty(e,n,a),a}function s(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){t.done?o(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,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,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,l,v,d=function(t,e){var n=e.width,r=e.height,o=e.position,i=e.left,a=void 0===i?0:i,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=o,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,o=void 0===r?"":r,i=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,l=e.props,v=void 0===l?{}:l,d=e.state,f=void 0===d?{}:d;return n.hint=o,n.event=i,n.delay=s,n.attr=h,n.role=u,n.props=v,n.state=f,n.a11yId="_"+function(t){for(var e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),n=[],r=e.length,o=0;o<t;o++)n[o]=e[0|Math.random()*r];return n.join("")}(6),n}return o(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"}(l||(l={})),function(t){t.BUTTON="button",t.DIV="div"}(v||(v={}));var y=["hint","event","delay","attr","role","props","state","a11yId","name"],g=function(t,e,n){var r=this;["touchstart","touchend","tap"].forEach((function(o){t.emit(o,{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}return o(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,o,i,a,s,h;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,o=void 0===r?100:r,i=t.checkA11yOpen,a=void 0===i?function(){return Promise.resolve(!1)}:i,this.delay=o,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]),s=this,[4,a()];case 2:return s.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?(h=document.createElement("div"),this.div=h,this.game.canvas.parentNode&&this.game.canvas.parentNode.appendChild(this.div),[2]):[2]}}))}))},r.prototype.setRatio=function(){var t=this.getCanvasBoundingClientRect(),e=t.width,n=t.height,r=this.getRenderRect(),o=r.renderWidth,i=r.renderHeight;return this._ratioX=e/o,this._ratioY=n/i,!(!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(),o={width:r.width,height:r.height,left:r.left+e+"px",top:r.top+n+"px",position:"absolute",zIndex:3,pointerEvents:u.NONE,background:l.NONE};d(this.div,o),this.div.addEventListener("click",(function(e){var n=e.currentTarget.getBoundingClientRect(),r=n.left,o=n.top,i=(e.pageX-r)/t.ratioX,a=(e.pageY-o)/t.ratioY;t.eventPosition={x:i,y:a}}),!0)},r.prototype.update=function(){return s(this,void 0,void 0,(function(){var e,n,r,o,i,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((o=r.value).type){case t.OBSERVER_TYPE.ADD:"Event"===o.componentName&&this.addEvent(o.gameObject),"A11y"===o.componentName&&this.add(o);break;case t.OBSERVER_TYPE.CHANGE:"Transform"===o.componentName&&this.transformChange(o),"A11y"===o.componentName&&this.change(o);break;case t.OBSERVER_TYPE.REMOVE:"Event"===o.componentName&&this.removeEvent(o),"A11y"===o.componentName&&this.remove(o)}}catch(t){i={error:t}}finally{try{r&&!r.done&&(a=n.return)&&a.call(n)}finally{if(i)throw i.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,o=n.delay,i=n.a11yId,a=n.event;if(r){var s=r.transform;if(s){var c=document.createElement("div");this.cache.set(i,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)}),o||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 o=this.cache.get(r);o&&this.div.appendChild(o)}}else{var i=this.div.querySelector("#"+r);i&&this.div.removeChild(i)}}},r.prototype.setEvent=function(t,e,n,r){if(e){var o=g.bind(this,e,n);this.eventCache.set(r,o),t.addEventListener("click",o)}},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),o=this.cache.get(n);o&&o.removeEventListener("click",r)}},r.prototype.setA11yAttr=function(t,e){var n,r,o,i,a,s,c=e.hint,p=e.props,u=void 0===p?{}:p,l=e.state,v=void 0===l?{}:l,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 A=E.value;t.setAttribute(A,u[A])}}catch(t){n={error:t}}finally{try{E&&!E.done&&(r=b.return)&&r.call(b)}finally{if(n)throw n.error}}var O=Object.keys(v);try{for(var w=h(O),x=w.next();!x.done;x=w.next()){A=x.value;t.setAttribute(A,v[A])}}catch(t){o={error:t}}finally{try{x&&!x.done&&(i=w.return)&&i.call(w)}finally{if(o)throw o.error}}try{for(var C=h(Object.keys(e)),N=C.next();!N.done;N=C.next()){"string"==typeof e[A=N.value]&&-1===y.indexOf(A)&&1!==A.indexOf("_")&&t.setAttribute(A,e[A])}}catch(t){a={error:t}}finally{try{N&&!N.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,o=n.height,a={width:0===r?1:r*this.ratioX,height:0===o?1:o*this.ratioY,position:"absolute",zIndex:3,pointerEvents:u.AUTO,background:this.debug?l.DEBUG:l.NONE},s=i({},e);d(t,a),function(t,e,n,r){var o=e.worldTransform,i="matrix("+o.a+", "+o.b+", "+o.c+", "+o.d+", "+o.tx*n+", "+o.ty*r+")";t.style.transform=""+i,t.style.webkitTransform=""+i,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},r.systemName="A11ySystem",r=a([t.decorators.componentObserver({A11y:["hint"],Transform:["inScene"],Event:[]})],r)}(t.System);exports.A11y=f,exports.A11ySystem=m;
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;
@@ -48,6 +48,7 @@ export declare class A11ySystem extends System {
48
48
  delay: number;
49
49
  cache: Map<string, HTMLElement>;
50
50
  eventCache: Map<string, (e: MouseEvent) => void>;
51
+ zIndex: number;
51
52
  constructor(opt?: SystemParam);
52
53
  get ratioX(): number;
53
54
  get ratioY(): number;
@@ -86,6 +87,7 @@ declare interface SystemParam {
86
87
  debug?: boolean;
87
88
  activate?: A11yActivate;
88
89
  delay?: number;
90
+ zIndex?: number;
89
91
  checkA11yOpen?: () => Promise<boolean>;
90
92
  }
91
93
 
@@ -208,6 +208,7 @@ var A11ySystem = (function (_super) {
208
208
  var _this = _super.call(this, opt) || this;
209
209
  _this.cache = new Map();
210
210
  _this.eventCache = new Map();
211
+ _this.zIndex = ZINDEX;
211
212
  return _this;
212
213
  }
213
214
  Object.defineProperty(A11ySystem.prototype, "ratioX", {
@@ -249,12 +250,13 @@ var A11ySystem = (function (_super) {
249
250
  A11ySystem.prototype.init = function (opt) {
250
251
  if (opt === void 0) { opt = {}; }
251
252
  return __awaiter(this, void 0, void 0, function () {
252
- var _a, activate, _b, delay, _c, checkA11yOpen, _d, _e, div;
253
+ var _a, activate, _b, delay, _c, checkA11yOpen, zIndex, _d, _e, div;
253
254
  return __generator(this, function (_f) {
254
255
  switch (_f.label) {
255
256
  case 0:
256
- _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;
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;
257
258
  this.delay = delay;
259
+ this.zIndex = zIndex || this.zIndex;
258
260
  _d = activate;
259
261
  switch (_d) {
260
262
  case A11yActivate.CHECK: return [3, 1];
@@ -290,7 +292,7 @@ var A11ySystem = (function (_super) {
290
292
  div = document.createElement('div');
291
293
  this.div = div;
292
294
  if (this.game.canvas.parentNode) {
293
- this.game.canvas.parentNode.appendChild(this.div);
295
+ this.game.canvas.parentNode.insertBefore(this.div, this.game.canvas);
294
296
  }
295
297
  return [2];
296
298
  }
@@ -329,7 +331,7 @@ var A11ySystem = (function (_super) {
329
331
  left: left + pageXOffset + "px",
330
332
  top: top + pageYOffset + "px",
331
333
  position: POSITION,
332
- zIndex: ZINDEX,
334
+ zIndex: this.zIndex,
333
335
  pointerEvents: PointerEvents.NONE,
334
336
  background: MaskBackground.NONE,
335
337
  };
@@ -532,7 +534,7 @@ var A11ySystem = (function (_super) {
532
534
  width: width === 0 ? 1 : width * this.ratioX,
533
535
  height: height === 0 ? 1 : height * this.ratioY,
534
536
  position: POSITION,
535
- zIndex: ZINDEX,
537
+ zIndex: this.zIndex,
536
538
  pointerEvents: PointerEvents.AUTO,
537
539
  background: this.debug ? MaskBackground.DEBUG : MaskBackground.NONE,
538
540
  };
@@ -544,6 +546,7 @@ var A11ySystem = (function (_super) {
544
546
  this.div.parentElement.removeChild(this.div);
545
547
  this.cache = null;
546
548
  this.eventCache = null;
549
+ this.div = null;
547
550
  };
548
551
  A11ySystem.systemName = 'A11ySystem';
549
552
  A11ySystem = __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-a11y",
3
- "version": "1.2.0-alpha.5",
3
+ "version": "1.2.0",
4
4
  "description": "@eva/plugin-a11y",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-a11y.esm.js",
@@ -18,8 +18,9 @@
18
18
  "license": "MIT",
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
- "@eva/eva.js": "1.2.0-alpha.5",
21
+ "@eva/eva.js": "1.2.0",
22
22
  "@eva/inspector-decorator": "^0.0.5",
23
+ "@eva/plugin-renderer": "1.2.0",
23
24
  "eventemitter3": "^3.1.2"
24
25
  }
25
26
  }
@@ -1,872 +0,0 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- this.EVA = this.EVA || {};
4
- this.EVA.plugin = this.EVA.plugin || {};
5
-
6
- this.EVA.plugin.a11y = function (exports, eva_js, pluginRenderer) {
7
- 'use strict';
8
-
9
- var _extendStatics = function extendStatics(d, b) {
10
- _extendStatics = Object.setPrototypeOf || {
11
- __proto__: []
12
- } instanceof Array && function (d, b) {
13
- d.__proto__ = b;
14
- } || function (d, b) {
15
- for (var p in b) {
16
- if (b.hasOwnProperty(p)) d[p] = b[p];
17
- }
18
- };
19
-
20
- return _extendStatics(d, b);
21
- };
22
-
23
- function __extends(d, b) {
24
- _extendStatics(d, b);
25
-
26
- function __() {
27
- this.constructor = d;
28
- }
29
-
30
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
31
- }
32
-
33
- var _assign = function __assign() {
34
- _assign = Object.assign || function __assign(t) {
35
- for (var s, i = 1, n = arguments.length; i < n; i++) {
36
- s = arguments[i];
37
-
38
- for (var p in s) {
39
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
40
- }
41
- }
42
-
43
- return t;
44
- };
45
-
46
- return _assign.apply(this, arguments);
47
- };
48
-
49
- function __decorate(decorators, target, key, desc) {
50
- var c = arguments.length,
51
- r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
52
- d;
53
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
54
- if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
55
- }
56
- return c > 3 && r && Object.defineProperty(target, key, r), r;
57
- }
58
-
59
- function __awaiter(thisArg, _arguments, P, generator) {
60
- function adopt(value) {
61
- return value instanceof P ? value : new P(function (resolve) {
62
- resolve(value);
63
- });
64
- }
65
-
66
- return new (P || (P = Promise))(function (resolve, reject) {
67
- function fulfilled(value) {
68
- try {
69
- step(generator.next(value));
70
- } catch (e) {
71
- reject(e);
72
- }
73
- }
74
-
75
- function rejected(value) {
76
- try {
77
- step(generator["throw"](value));
78
- } catch (e) {
79
- reject(e);
80
- }
81
- }
82
-
83
- function step(result) {
84
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
85
- }
86
-
87
- step((generator = generator.apply(thisArg, _arguments || [])).next());
88
- });
89
- }
90
-
91
- function __generator(thisArg, body) {
92
- var _ = {
93
- label: 0,
94
- sent: function sent() {
95
- if (t[0] & 1) throw t[1];
96
- return t[1];
97
- },
98
- trys: [],
99
- ops: []
100
- },
101
- f,
102
- y,
103
- t,
104
- g;
105
- return g = {
106
- next: verb(0),
107
- "throw": verb(1),
108
- "return": verb(2)
109
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
110
- return this;
111
- }), g;
112
-
113
- function verb(n) {
114
- return function (v) {
115
- return step([n, v]);
116
- };
117
- }
118
-
119
- function step(op) {
120
- if (f) throw new TypeError("Generator is already executing.");
121
-
122
- while (_) {
123
- try {
124
- 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;
125
- if (y = 0, t) op = [op[0] & 2, t.value];
126
-
127
- switch (op[0]) {
128
- case 0:
129
- case 1:
130
- t = op;
131
- break;
132
-
133
- case 4:
134
- _.label++;
135
- return {
136
- value: op[1],
137
- done: false
138
- };
139
-
140
- case 5:
141
- _.label++;
142
- y = op[1];
143
- op = [0];
144
- continue;
145
-
146
- case 7:
147
- op = _.ops.pop();
148
-
149
- _.trys.pop();
150
-
151
- continue;
152
-
153
- default:
154
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
155
- _ = 0;
156
- continue;
157
- }
158
-
159
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
160
- _.label = op[1];
161
- break;
162
- }
163
-
164
- if (op[0] === 6 && _.label < t[1]) {
165
- _.label = t[1];
166
- t = op;
167
- break;
168
- }
169
-
170
- if (t && _.label < t[2]) {
171
- _.label = t[2];
172
-
173
- _.ops.push(op);
174
-
175
- break;
176
- }
177
-
178
- if (t[2]) _.ops.pop();
179
-
180
- _.trys.pop();
181
-
182
- continue;
183
- }
184
-
185
- op = body.call(thisArg, _);
186
- } catch (e) {
187
- op = [6, e];
188
- y = 0;
189
- } finally {
190
- f = t = 0;
191
- }
192
- }
193
-
194
- if (op[0] & 5) throw op[1];
195
- return {
196
- value: op[0] ? op[1] : void 0,
197
- done: true
198
- };
199
- }
200
- }
201
-
202
- function __values(o) {
203
- var s = typeof Symbol === "function" && Symbol.iterator,
204
- m = s && o[s],
205
- i = 0;
206
- if (m) return m.call(o);
207
- if (o && typeof o.length === "number") return {
208
- next: function next() {
209
- if (o && i >= o.length) o = void 0;
210
- return {
211
- value: o && o[i++],
212
- done: !o
213
- };
214
- }
215
- };
216
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
217
- }
218
-
219
- function getIDEPropsPropertyObj(target, propertyKey) {
220
- if (!target.constructor.IDEProps) {
221
- target.constructor.IDEProps = {};
222
- }
223
-
224
- if (!target.constructor.IDEProps[propertyKey]) {
225
- target.constructor.IDEProps[propertyKey] = {};
226
- }
227
-
228
- var propertyObj = target.constructor.IDEProps[propertyKey];
229
- return propertyObj;
230
- }
231
-
232
- function type(type) {
233
- return function (target, propertyKey) {
234
- var prop = getIDEPropsPropertyObj(target, propertyKey);
235
- prop.key = propertyKey;
236
- prop.type = type;
237
- };
238
- }
239
-
240
- function step(step) {
241
- return function (target, propertyKey) {
242
- var prop = getIDEPropsPropertyObj(target, propertyKey);
243
- prop.step = step;
244
- };
245
- }
246
-
247
- function uuid(len) {
248
- var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
249
- var uuid = [];
250
- var radix = chars.length;
251
-
252
- for (var i = 0; i < len; i++) {
253
- uuid[i] = chars[0 | Math.random() * radix];
254
- }
255
-
256
- return uuid.join('');
257
- }
258
-
259
- var setStyle = function setStyle(element, style) {
260
- var width = style.width,
261
- height = style.height,
262
- position = style.position,
263
- _a = style.left,
264
- left = _a === void 0 ? 0 : _a,
265
- _b = style.top,
266
- top = _b === void 0 ? 0 : _b,
267
- zIndex = style.zIndex,
268
- pointerEvents = style.pointerEvents,
269
- background = style.background;
270
- element.style.width = width + "px";
271
- element.style.height = height + "px";
272
- element.style.position = position;
273
- element.style.left = "" + left;
274
- element.style.top = "" + top;
275
- element.style.zIndex = "" + zIndex;
276
- element.style.pointerEvents = pointerEvents;
277
- element.style.background = background;
278
- element.style.border = 'none';
279
- element.style.overflow = 'hidden';
280
- };
281
-
282
- var setTransform = function setTransform(element, transform, ratioX, ratioY) {
283
- var worldTransform = transform.worldTransform;
284
- var a = worldTransform.a,
285
- b = worldTransform.b,
286
- c = worldTransform.c,
287
- d = worldTransform.d,
288
- tx = worldTransform.tx,
289
- ty = worldTransform.ty;
290
- var matrix = "matrix(" + a + ", " + b + ", " + c + ", " + d + ", " + tx * ratioX + ", " + ty * ratioY + ")";
291
- element.style.transform = "" + matrix;
292
- element.style.webkitTransform = "" + matrix;
293
- element.style.transformOrigin = 'left top';
294
- element.style.webkitTransformOrigin = 'left top';
295
- };
296
-
297
- var A11y = function (_super) {
298
- __extends(A11y, _super);
299
-
300
- function A11y(param) {
301
- var _this = _super.call(this) || this;
302
-
303
- _extends(_this, param);
304
-
305
- var _a = param.hint,
306
- hint = _a === void 0 ? '' : _a,
307
- event = param.event,
308
- _b = param.delay,
309
- delay = _b === void 0 ? 0 : _b,
310
- _c = param.attr,
311
- attr = _c === void 0 ? {} : _c,
312
- _d = param.role,
313
- role = _d === void 0 ? '' : _d,
314
- _e = param.props,
315
- props = _e === void 0 ? {} : _e,
316
- _f = param.state,
317
- state = _f === void 0 ? {} : _f;
318
- _this.hint = hint;
319
- _this.event = event;
320
- _this.delay = delay;
321
- _this.attr = attr;
322
- _this.role = role;
323
- _this.props = props;
324
- _this.state = state;
325
- _this.a11yId = "_" + uuid(6);
326
- return _this;
327
- }
328
-
329
- A11y.componentName = 'A11y';
330
-
331
- __decorate([type('boolean')], A11y.prototype, "interactive", void 0);
332
-
333
- __decorate([type('string')], A11y.prototype, "hint", void 0);
334
-
335
- __decorate([type('number'), step(1)], A11y.prototype, "delay", void 0);
336
-
337
- __decorate([type('string')], A11y.prototype, "role", void 0);
338
-
339
- __decorate([type('string')], A11y.prototype, "a11yId", void 0);
340
-
341
- return A11y;
342
- }(eva_js.Component);
343
-
344
- var A11y$1 = A11y;
345
- var POSITION = 'absolute';
346
- var ZINDEX = 3;
347
- exports.A11yActivate = void 0;
348
-
349
- (function (A11yActivate) {
350
- A11yActivate[A11yActivate["ENABLE"] = 0] = "ENABLE";
351
- A11yActivate[A11yActivate["DISABLE"] = 1] = "DISABLE";
352
- A11yActivate[A11yActivate["CHECK"] = 2] = "CHECK";
353
- })(exports.A11yActivate || (exports.A11yActivate = {}));
354
-
355
- var PointerEvents;
356
-
357
- (function (PointerEvents) {
358
- PointerEvents["NONE"] = "none";
359
- PointerEvents["AUTO"] = "auto";
360
- })(PointerEvents || (PointerEvents = {}));
361
-
362
- var MaskBackground;
363
-
364
- (function (MaskBackground) {
365
- MaskBackground["DEBUG"] = "rgba(255,0,0,0.5)";
366
- MaskBackground["NONE"] = "transparent";
367
- })(MaskBackground || (MaskBackground = {}));
368
-
369
- var ElementType;
370
-
371
- (function (ElementType) {
372
- ElementType["BUTTON"] = "button";
373
- ElementType["DIV"] = "div";
374
- })(ElementType || (ElementType = {}));
375
-
376
- var notAttr = ['hint', 'event', 'delay', 'attr', 'role', 'props', 'state', 'a11yId', 'name'];
377
-
378
- var getEventFunc = function getEventFunc(event, gameObject, e) {
379
- var _this = this;
380
-
381
- ['touchstart', 'touchend', 'tap'].forEach(function (name) {
382
- event.emit(name, {
383
- stopPropagation: function stopPropagation() {
384
- return e.stopPropagation();
385
- },
386
- data: {
387
- position: _this.eventPosition
388
- },
389
- gameObject: gameObject
390
- });
391
- });
392
- };
393
-
394
- var A11ySystem = function (_super) {
395
- __extends(A11ySystem, _super);
396
-
397
- function A11ySystem(opt) {
398
- var _this = _super.call(this, opt) || this;
399
-
400
- _this.cache = new Map();
401
- _this.eventCache = new Map();
402
- return _this;
403
- }
404
-
405
- Object.defineProperty(A11ySystem.prototype, "ratioX", {
406
- get: function get() {
407
- if (this._ratioX) {
408
- return this._ratioX;
409
- } else {
410
- var success = this.setRatio();
411
-
412
- if (success) {
413
- return this._ratioX;
414
- } else {
415
- return 0;
416
- }
417
- }
418
- },
419
- enumerable: false,
420
- configurable: true
421
- });
422
- Object.defineProperty(A11ySystem.prototype, "ratioY", {
423
- get: function get() {
424
- if (this._ratioY) {
425
- return this._ratioY;
426
- } else {
427
- var success = this.setRatio();
428
-
429
- if (success) {
430
- return this._ratioY;
431
- } else {
432
- return 0;
433
- }
434
- }
435
- },
436
- enumerable: false,
437
- configurable: true
438
- });
439
-
440
- A11ySystem.prototype.init = function (opt) {
441
- if (opt === void 0) {
442
- opt = {};
443
- }
444
-
445
- return __awaiter(this, void 0, void 0, function () {
446
- var _a, activate, _b, delay, _c, checkA11yOpen, _d, _e, div;
447
-
448
- return __generator(this, function (_f) {
449
- switch (_f.label) {
450
- case 0:
451
- _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 () {
452
- return Promise.resolve(false);
453
- } : _c;
454
- this.delay = delay;
455
- _d = activate;
456
-
457
- switch (_d) {
458
- case exports.A11yActivate.CHECK:
459
- return [3, 1];
460
-
461
- case exports.A11yActivate.DISABLE:
462
- return [3, 5];
463
-
464
- case exports.A11yActivate.ENABLE:
465
- return [3, 6];
466
- }
467
-
468
- return [3, 7];
469
-
470
- case 1:
471
- _f.trys.push([1, 3,, 4]);
472
-
473
- _e = this;
474
- return [4, checkA11yOpen()];
475
-
476
- case 2:
477
- _e.activate = _f.sent();
478
- return [3, 4];
479
-
480
- case 3:
481
- _f.sent();
482
-
483
- this.activate = false;
484
- return [3, 4];
485
-
486
- case 4:
487
- return [3, 7];
488
-
489
- case 5:
490
- this.activate = false;
491
- return [3, 7];
492
-
493
- case 6:
494
- this.activate = true;
495
- return [3, 7];
496
-
497
- case 7:
498
- this.debug = opt.debug || false;
499
-
500
- if (this.debug) {
501
- this.activate = true;
502
- }
503
-
504
- if (!this.activate) return [2];
505
- div = document.createElement('div');
506
- this.div = div;
507
-
508
- if (this.game.canvas.parentNode) {
509
- this.game.canvas.parentNode.appendChild(this.div);
510
- }
511
-
512
- return [2];
513
- }
514
- });
515
- });
516
- };
517
-
518
- A11ySystem.prototype.setRatio = function () {
519
- var _a = this.getCanvasBoundingClientRect(),
520
- width = _a.width,
521
- height = _a.height;
522
-
523
- var _b = this.getRenderRect(),
524
- renderWidth = _b.renderWidth,
525
- renderHeight = _b.renderHeight;
526
-
527
- this._ratioX = width / renderWidth;
528
- this._ratioY = height / renderHeight;
529
-
530
- if (width || height) {
531
- this.initDiv();
532
- return true;
533
- } else {
534
- return false;
535
- }
536
- };
537
-
538
- A11ySystem.prototype.getRenderRect = function () {
539
- var _a = this.game.getSystem(pluginRenderer.RendererSystem).params,
540
- params = _a === void 0 ? {
541
- width: 300,
542
- height: 300
543
- } : _a;
544
- var renderHeight = params.height,
545
- renderWidth = params.width;
546
- return {
547
- renderWidth: renderWidth,
548
- renderHeight: renderHeight
549
- };
550
- };
551
-
552
- A11ySystem.prototype.getCanvasBoundingClientRect = function () {
553
- var _a = this.game.canvas.getBoundingClientRect(),
554
- width = _a.width,
555
- height = _a.height,
556
- left = _a.left,
557
- top = _a.top;
558
-
559
- return {
560
- width: width,
561
- height: height,
562
- left: left,
563
- top: top
564
- };
565
- };
566
-
567
- A11ySystem.prototype.initDiv = function () {
568
- var _this = this;
569
-
570
- var pageXOffset = window.pageXOffset,
571
- pageYOffset = window.pageYOffset;
572
-
573
- var _a = this.getCanvasBoundingClientRect(),
574
- width = _a.width,
575
- height = _a.height,
576
- left = _a.left,
577
- top = _a.top;
578
-
579
- var style = {
580
- width: width,
581
- height: height,
582
- left: left + pageXOffset + "px",
583
- top: top + pageYOffset + "px",
584
- position: POSITION,
585
- zIndex: ZINDEX,
586
- pointerEvents: PointerEvents.NONE,
587
- background: MaskBackground.NONE
588
- };
589
- setStyle(this.div, style);
590
- this.div.addEventListener('click', function (e) {
591
- var currentTarget = e.currentTarget;
592
-
593
- var _a = currentTarget.getBoundingClientRect(),
594
- left = _a.left,
595
- top = _a.top;
596
-
597
- var x = (e.pageX - left) / _this.ratioX;
598
- var y = (e.pageY - top) / _this.ratioY;
599
- _this.eventPosition = {
600
- x: x,
601
- y: y
602
- };
603
- }, true);
604
- };
605
-
606
- A11ySystem.prototype.update = function () {
607
- return __awaiter(this, void 0, void 0, function () {
608
- var changes, changes_1, changes_1_1, changed;
609
-
610
- var e_1, _a;
611
-
612
- return __generator(this, function (_b) {
613
- changes = this.componentObserver.clear();
614
-
615
- if (!this.activate) {
616
- return [2];
617
- }
618
-
619
- try {
620
- for (changes_1 = __values(changes), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
621
- changed = changes_1_1.value;
622
-
623
- switch (changed.type) {
624
- case eva_js.OBSERVER_TYPE.ADD:
625
- changed.componentName === 'Event' && this.addEvent(changed.gameObject);
626
- changed.componentName === 'A11y' && this.add(changed);
627
- break;
628
-
629
- case eva_js.OBSERVER_TYPE.CHANGE:
630
- changed.componentName === 'Transform' && this.transformChange(changed);
631
- changed.componentName === 'A11y' && this.change(changed);
632
- break;
633
-
634
- case eva_js.OBSERVER_TYPE.REMOVE:
635
- changed.componentName === 'Event' && this.removeEvent(changed);
636
- changed.componentName === 'A11y' && this.remove(changed);
637
- }
638
- }
639
- } catch (e_1_1) {
640
- e_1 = {
641
- error: e_1_1
642
- };
643
- } finally {
644
- try {
645
- if (changes_1_1 && !changes_1_1.done && (_a = changes_1.return)) _a.call(changes_1);
646
- } finally {
647
- if (e_1) throw e_1.error;
648
- }
649
- }
650
-
651
- return [2];
652
- });
653
- });
654
- };
655
-
656
- A11ySystem.prototype.change = function (changed) {
657
- var component = changed.component;
658
-
659
- if (changed.prop.prop[0] === 'hint') {
660
- var dom = this.cache.get(component.a11yId);
661
- dom === null || dom === void 0 ? void 0 : dom.setAttribute('aria-label', component.hint);
662
- dom && this.setPosition(dom, changed.gameObject.transform);
663
- }
664
- };
665
-
666
- A11ySystem.prototype.remove = function (changed) {
667
- var component = changed.component;
668
- if (!component) return;
669
- var a11yId = component.a11yId;
670
- var element = this.div.querySelector("#" + a11yId);
671
- element && this.div.removeChild(element);
672
- this.cache.delete(a11yId);
673
- };
674
-
675
- A11ySystem.prototype.add = function (changed) {
676
- var _this = this;
677
-
678
- if (!this.activate) return;
679
- var component = changed.component;
680
- var gameObject = changed.gameObject;
681
- var delay = component.delay,
682
- id = component.a11yId;
683
- var event = component.event;
684
- if (!gameObject) return;
685
- var transform = gameObject.transform;
686
- if (!transform) return;
687
- var element = document.createElement('div');
688
- this.cache.set(id, element);
689
-
690
- if (!event) {
691
- event = gameObject.getComponent('Event');
692
- }
693
-
694
- setTimeout(function () {
695
- _this.setPosition(element, transform);
696
-
697
- _this.setA11yAttr(element, component);
698
-
699
- if (event) {
700
- _this.addEvent(gameObject);
701
- }
702
-
703
- if (gameObject.scene) {
704
- _this.div.appendChild(element);
705
- }
706
- }, delay || this.delay);
707
- };
708
-
709
- A11ySystem.prototype.transformChange = function (changed) {
710
- var component = changed.component;
711
- var gameObject = changed.gameObject;
712
- var a11yComponent = gameObject.getComponent(A11y$1);
713
- if (!a11yComponent) return;
714
- var a11yId = a11yComponent.a11yId;
715
-
716
- if (!component.inScene) {
717
- var dom = this.div.querySelector("#" + a11yId);
718
- dom && this.div.removeChild(dom);
719
- } else {
720
- if (this.cache.has(a11yId)) {
721
- var addDom = this.cache.get(a11yId);
722
- addDom && this.div.appendChild(addDom);
723
- }
724
- }
725
- };
726
-
727
- A11ySystem.prototype.setEvent = function (element, event, gameObject, id) {
728
- if (!event) {
729
- return;
730
- }
731
-
732
- var func = getEventFunc.bind(this, event, gameObject);
733
- this.eventCache.set(id, func);
734
- element.addEventListener('click', func);
735
- };
736
-
737
- A11ySystem.prototype.addEvent = function (gameObject) {
738
- var a11y = gameObject.getComponent(A11y$1);
739
- if (!a11y) return;
740
- var event = gameObject.getComponent('Event');
741
- if (!event) return;
742
- var element = this.cache.get(a11y.a11yId);
743
- element && this.setEvent(element, event, gameObject, a11y.a11yId);
744
- };
745
-
746
- A11ySystem.prototype.removeEvent = function (changed) {
747
- var gameObject = changed.gameObject;
748
- var a11y = gameObject.getComponent(A11y$1);
749
- if (!a11y) return;
750
- var event = changed.component;
751
- if (!event) return;
752
- var a11yId = a11y.a11yId;
753
- var func = this.eventCache.get(a11yId);
754
- var element = this.cache.get(a11yId);
755
- element && element.removeEventListener('click', func);
756
- };
757
-
758
- A11ySystem.prototype.setA11yAttr = function (element, component) {
759
- var e_2, _a, e_3, _b, e_4, _c;
760
-
761
- var hint = component.hint,
762
- _d = component.props,
763
- props = _d === void 0 ? {} : _d,
764
- _e = component.state,
765
- state = _e === void 0 ? {} : _e,
766
- role = component.role,
767
- id = component.a11yId;
768
- var realRole = role || 'text';
769
- element.setAttribute('role', realRole);
770
- element.setAttribute('aria-label', hint);
771
- element.id = id;
772
- var ariaProps = Object.keys(props);
773
-
774
- try {
775
- for (var ariaProps_1 = __values(ariaProps), ariaProps_1_1 = ariaProps_1.next(); !ariaProps_1_1.done; ariaProps_1_1 = ariaProps_1.next()) {
776
- var key = ariaProps_1_1.value;
777
- element.setAttribute(key, props[key]);
778
- }
779
- } catch (e_2_1) {
780
- e_2 = {
781
- error: e_2_1
782
- };
783
- } finally {
784
- try {
785
- if (ariaProps_1_1 && !ariaProps_1_1.done && (_a = ariaProps_1.return)) _a.call(ariaProps_1);
786
- } finally {
787
- if (e_2) throw e_2.error;
788
- }
789
- }
790
-
791
- var ariaState = Object.keys(state);
792
-
793
- try {
794
- for (var ariaState_1 = __values(ariaState), ariaState_1_1 = ariaState_1.next(); !ariaState_1_1.done; ariaState_1_1 = ariaState_1.next()) {
795
- var key = ariaState_1_1.value;
796
- element.setAttribute(key, state[key]);
797
- }
798
- } catch (e_3_1) {
799
- e_3 = {
800
- error: e_3_1
801
- };
802
- } finally {
803
- try {
804
- if (ariaState_1_1 && !ariaState_1_1.done && (_b = ariaState_1.return)) _b.call(ariaState_1);
805
- } finally {
806
- if (e_3) throw e_3.error;
807
- }
808
- }
809
-
810
- try {
811
- for (var _f = __values(Object.keys(component)), _g = _f.next(); !_g.done; _g = _f.next()) {
812
- var key = _g.value;
813
-
814
- if (typeof component[key] === 'string' && notAttr.indexOf(key) === -1 && key.indexOf('_') !== 1) {
815
- element.setAttribute(key, component[key]);
816
- }
817
- }
818
- } catch (e_4_1) {
819
- e_4 = {
820
- error: e_4_1
821
- };
822
- } finally {
823
- try {
824
- if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
825
- } finally {
826
- if (e_4) throw e_4.error;
827
- }
828
- }
829
- };
830
-
831
- A11ySystem.prototype.setPosition = function (element, transform) {
832
- var _a = transform.size,
833
- width = _a.width,
834
- height = _a.height;
835
- var style = {
836
- width: width === 0 ? 1 : width * this.ratioX,
837
- height: height === 0 ? 1 : height * this.ratioY,
838
- position: POSITION,
839
- zIndex: ZINDEX,
840
- pointerEvents: PointerEvents.AUTO,
841
- background: this.debug ? MaskBackground.DEBUG : MaskBackground.NONE
842
- };
843
-
844
- var transformProps = _assign({}, transform);
845
-
846
- setStyle(element, style);
847
- setTransform(element, transformProps, this.ratioX, this.ratioY);
848
- };
849
-
850
- A11ySystem.prototype.onDestroy = function () {
851
- this.div.parentElement.removeChild(this.div);
852
- this.cache = null;
853
- this.eventCache = null;
854
- };
855
-
856
- A11ySystem.systemName = 'A11ySystem';
857
- A11ySystem = __decorate([eva_js.decorators.componentObserver({
858
- A11y: ['hint'],
859
- Transform: ['inScene'],
860
- Event: []
861
- })], A11ySystem);
862
- return A11ySystem;
863
- }(eva_js.System);
864
-
865
- var A11ySystem$1 = A11ySystem;
866
- exports.A11y = A11y$1;
867
- exports.A11ySystem = A11ySystem$1;
868
- Object.defineProperty(exports, '__esModule', {
869
- value: true
870
- });
871
- return exports;
872
- }({}, EVA, EVA.plugin.renderer);
@@ -1 +0,0 @@
1
- function _extends(){return(_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}this.EVA=this.EVA||{},this.EVA.plugin=this.EVA.plugin||{},this.EVA.plugin.a11y=function(t,e,n){"use strict";var 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 o(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function a(t,e,n,r){var o,i=arguments.length,a=i<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 c=t.length-1;c>=0;c--)(o=t[c])&&(a=(i<3?o(a):i>3?o(e,n,a):o(e,n))||a);return i>3&&a&&Object.defineProperty(e,n,a),a}function c(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function c(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,c)}s((r=r.apply(t,e||[])).next())}))}function s(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function u(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function h(t,e){return t.constructor.IDEProps||(t.constructor.IDEProps={}),t.constructor.IDEProps[e]||(t.constructor.IDEProps[e]={}),t.constructor.IDEProps[e]}function p(t){return function(e,n){var r=h(e,n);r.key=n,r.type=t}}function l(t){return function(e,n){h(e,n).step=t}}var v,d,f,y,g=function(t,e){var n=e.width,r=e.height,o=e.position,i=e.left,a=void 0===i?0:i,c=e.top,s=void 0===c?0:c,u=e.zIndex,h=e.pointerEvents,p=e.background;t.style.width=n+"px",t.style.height=r+"px",t.style.position=o,t.style.left=""+a,t.style.top=""+s,t.style.zIndex=""+u,t.style.pointerEvents=h,t.style.background=p,t.style.border="none",t.style.overflow="hidden"},m=function(t){function e(e){var n=t.call(this)||this;_extends(n,e);var r=e.hint,o=void 0===r?"":r,i=e.event,a=e.delay,c=void 0===a?0:a,s=e.attr,u=void 0===s?{}:s,h=e.role,p=void 0===h?"":h,l=e.props,v=void 0===l?{}:l,d=e.state,f=void 0===d?{}:d;return n.hint=o,n.event=i,n.delay=c,n.attr=u,n.role=p,n.props=v,n.state=f,n.a11yId="_"+function(t){for(var e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),n=[],r=e.length,o=0;o<t;o++)n[o]=e[0|Math.random()*r];return n.join("")}(6),n}return o(e,t),e.componentName="A11y",a([p("boolean")],e.prototype,"interactive",void 0),a([p("string")],e.prototype,"hint",void 0),a([p("number"),l(1)],e.prototype,"delay",void 0),a([p("string")],e.prototype,"role",void 0),a([p("string")],e.prototype,"a11yId",void 0),e}(e.Component),b="absolute";t.A11yActivate=void 0,(v=t.A11yActivate||(t.A11yActivate={}))[v.ENABLE=0]="ENABLE",v[v.DISABLE=1]="DISABLE",v[v.CHECK=2]="CHECK",function(t){t.NONE="none",t.AUTO="auto"}(d||(d={})),function(t){t.DEBUG="rgba(255,0,0,0.5)",t.NONE="transparent"}(f||(f={})),function(t){t.BUTTON="button",t.DIV="div"}(y||(y={}));var E=["hint","event","delay","attr","role","props","state","a11yId","name"],A=function(t,e,n){var r=this;["touchstart","touchend","tap"].forEach((function(o){t.emit(o,{stopPropagation:function(){return n.stopPropagation()},data:{position:r.eventPosition},gameObject:e})}))},O=function(r){function h(t){var e=r.call(this,t)||this;return e.cache=new Map,e.eventCache=new Map,e}return o(h,r),Object.defineProperty(h.prototype,"ratioX",{get:function(){return this._ratioX||this.setRatio()?this._ratioX:0},enumerable:!1,configurable:!0}),Object.defineProperty(h.prototype,"ratioY",{get:function(){return this._ratioY||this.setRatio()?this._ratioY:0},enumerable:!1,configurable:!0}),h.prototype.init=function(e){return void 0===e&&(e={}),c(this,void 0,void 0,(function(){var n,r,o,i,a,c,u,h;return s(this,(function(s){switch(s.label){case 0:switch(n=e.activate,r=void 0===n?t.A11yActivate.CHECK:n,o=e.delay,i=void 0===o?100:o,a=e.checkA11yOpen,c=void 0===a?function(){return Promise.resolve(!1)}:a,this.delay=i,r){case t.A11yActivate.CHECK:return[3,1];case t.A11yActivate.DISABLE:return[3,5];case t.A11yActivate.ENABLE:return[3,6]}return[3,7];case 1:return s.trys.push([1,3,,4]),u=this,[4,c()];case 2:return u.activate=s.sent(),[3,4];case 3:return s.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=e.debug||!1,this.debug&&(this.activate=!0),this.activate?(h=document.createElement("div"),this.div=h,this.game.canvas.parentNode&&this.game.canvas.parentNode.appendChild(this.div),[2]):[2]}}))}))},h.prototype.setRatio=function(){var t=this.getCanvasBoundingClientRect(),e=t.width,n=t.height,r=this.getRenderRect(),o=r.renderWidth,i=r.renderHeight;return this._ratioX=e/o,this._ratioY=n/i,!(!e&&!n)&&(this.initDiv(),!0)},h.prototype.getRenderRect=function(){var t=this.game.getSystem(n.RendererSystem).params,e=void 0===t?{width:300,height:300}:t,r=e.height;return{renderWidth:e.width,renderHeight:r}},h.prototype.getCanvasBoundingClientRect=function(){var t=this.game.canvas.getBoundingClientRect();return{width:t.width,height:t.height,left:t.left,top:t.top}},h.prototype.initDiv=function(){var t=this,e=window.pageXOffset,n=window.pageYOffset,r=this.getCanvasBoundingClientRect(),o={width:r.width,height:r.height,left:r.left+e+"px",top:r.top+n+"px",position:b,zIndex:3,pointerEvents:d.NONE,background:f.NONE};g(this.div,o),this.div.addEventListener("click",(function(e){var n=e.currentTarget.getBoundingClientRect(),r=n.left,o=n.top,i=(e.pageX-r)/t.ratioX,a=(e.pageY-o)/t.ratioY;t.eventPosition={x:i,y:a}}),!0)},h.prototype.update=function(){return c(this,void 0,void 0,(function(){var t,n,r,o,i,a;return s(this,(function(c){if(t=this.componentObserver.clear(),!this.activate)return[2];try{for(n=u(t),r=n.next();!r.done;r=n.next())switch((o=r.value).type){case e.OBSERVER_TYPE.ADD:"Event"===o.componentName&&this.addEvent(o.gameObject),"A11y"===o.componentName&&this.add(o);break;case e.OBSERVER_TYPE.CHANGE:"Transform"===o.componentName&&this.transformChange(o),"A11y"===o.componentName&&this.change(o);break;case e.OBSERVER_TYPE.REMOVE:"Event"===o.componentName&&this.removeEvent(o),"A11y"===o.componentName&&this.remove(o)}}catch(t){i={error:t}}finally{try{r&&!r.done&&(a=n.return)&&a.call(n)}finally{if(i)throw i.error}}return[2]}))}))},h.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)}},h.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)}},h.prototype.add=function(t){var e=this;if(this.activate){var n=t.component,r=t.gameObject,o=n.delay,i=n.a11yId,a=n.event;if(r){var c=r.transform;if(c){var s=document.createElement("div");this.cache.set(i,s),a||(a=r.getComponent("Event")),setTimeout((function(){e.setPosition(s,c),e.setA11yAttr(s,n),a&&e.addEvent(r),r.scene&&e.div.appendChild(s)}),o||this.delay)}}}},h.prototype.transformChange=function(t){var e=t.component,n=t.gameObject.getComponent(m);if(n){var r=n.a11yId;if(e.inScene){if(this.cache.has(r)){var o=this.cache.get(r);o&&this.div.appendChild(o)}}else{var i=this.div.querySelector("#"+r);i&&this.div.removeChild(i)}}},h.prototype.setEvent=function(t,e,n,r){if(e){var o=A.bind(this,e,n);this.eventCache.set(r,o),t.addEventListener("click",o)}},h.prototype.addEvent=function(t){var e=t.getComponent(m);if(e){var n=t.getComponent("Event");if(n){var r=this.cache.get(e.a11yId);r&&this.setEvent(r,n,t,e.a11yId)}}},h.prototype.removeEvent=function(t){var e=t.gameObject.getComponent(m);if(e&&t.component){var n=e.a11yId,r=this.eventCache.get(n),o=this.cache.get(n);o&&o.removeEventListener("click",r)}},h.prototype.setA11yAttr=function(t,e){var n,r,o,i,a,c,s=e.hint,h=e.props,p=void 0===h?{}:h,l=e.state,v=void 0===l?{}:l,d=e.role,f=e.a11yId,y=d||"text";t.setAttribute("role",y),t.setAttribute("aria-label",s),t.id=f;var g=Object.keys(p);try{for(var m=u(g),b=m.next();!b.done;b=m.next()){var A=b.value;t.setAttribute(A,p[A])}}catch(t){n={error:t}}finally{try{b&&!b.done&&(r=m.return)&&r.call(m)}finally{if(n)throw n.error}}var O=Object.keys(v);try{for(var w=u(O),C=w.next();!C.done;C=w.next()){A=C.value;t.setAttribute(A,v[A])}}catch(t){o={error:t}}finally{try{C&&!C.done&&(i=w.return)&&i.call(w)}finally{if(o)throw o.error}}try{for(var x=u(Object.keys(e)),P=x.next();!P.done;P=x.next()){"string"==typeof e[A=P.value]&&-1===E.indexOf(A)&&1!==A.indexOf("_")&&t.setAttribute(A,e[A])}}catch(t){a={error:t}}finally{try{P&&!P.done&&(c=x.return)&&c.call(x)}finally{if(a)throw a.error}}},h.prototype.setPosition=function(t,e){var n=e.size,r=n.width,o=n.height,a={width:0===r?1:r*this.ratioX,height:0===o?1:o*this.ratioY,position:b,zIndex:3,pointerEvents:d.AUTO,background:this.debug?f.DEBUG:f.NONE},c=i({},e);g(t,a),function(t,e,n,r){var o=e.worldTransform,i="matrix("+o.a+", "+o.b+", "+o.c+", "+o.d+", "+o.tx*n+", "+o.ty*r+")";t.style.transform=""+i,t.style.webkitTransform=""+i,t.style.transformOrigin="left top",t.style.webkitTransformOrigin="left top"}(t,c,this.ratioX,this.ratioY)},h.prototype.onDestroy=function(){this.div.parentElement.removeChild(this.div),this.cache=null,this.eventCache=null},h.systemName="A11ySystem",h=a([e.decorators.componentObserver({A11y:["hint"],Transform:["inScene"],Event:[]})],h)}(e.System);return t.A11y=m,t.A11ySystem=O,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,EVA.plugin.renderer);