@eva/plugin-a11y 1.2.7-editor.1 → 1.2.7-editor.12

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