@eva/plugin-a11y 1.2.7-editor.4 → 1.2.7-editor.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/EVA.plugin.a11y.js
CHANGED
|
@@ -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},_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 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){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(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){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}c((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: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 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,s=function(t){return t===String?"string":t===Number?"number":t===Boolean?"boolean":"unknown"}(o);if("unknown"!==s&&(o=s),r){var c=r();Array.isArray(c)?(a=!0,o=c[0]):o=c}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,s=e.top,c=void 0===s?0:s,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=""+c,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,s=void 0===a?0:a,c=e.attr,u=void 0===c?{}:c,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=s,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(),s("design:type",Boolean)],e.prototype,"interactive",void 0),a([f(),s("design:type",String)],e.prototype,"hint",void 0),a([f({step:1}),s("design:type",Number)],e.prototype,"delay",void 0),a([f(),s("design:type",String)],e.prototype,"role",void 0),a([f(),s("design:type",String)],e.prototype,"a11yId",void 0),e}(e.Component),w=E,A="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 O=["hint","event","delay","attr","role","props","state","a11yId","name"],x=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})}))},C=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={}),c(this,void 0,void 0,(function(){var n,r,o,i,a,s,c,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,s=void 0===a?function(){return Promise.resolve(!1)}:a,c=e.zIndex,this.delay=i,this.zIndex=c||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,s()];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:A,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 c(this,void 0,void 0,(function(){var t,n,r,o,i,a;return u(this,(function(s){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 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)}}}},l.prototype.transformChange=function(t){var e=t.component,n=t.gameObject.getComponent(w);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=x.bind(this,e,n);this.eventCache.set(r,o),t.addEventListener("click",o)}},l.prototype.addEvent=function(t){var e=t.getComponent(w);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(w);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,s,c=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",c),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 A=p(w),x=A.next();!x.done;x=A.next()){E=x.value;t.setAttribute(E,d[E])}}catch(t){o={error:t}}finally{try{x&&!x.done&&(i=A.return)&&i.call(A)}finally{if(o)throw o.error}}try{for(var C=p(Object.keys(e)),_=C.next();!_.done;_=C.next()){"string"==typeof e[E=_.value]&&-1===O.indexOf(E)&&1!==E.indexOf("_")&&t.setAttribute(E,e[E])}}catch(t){a={error:t}}finally{try{_&&!_.done&&(s=C.return)&&s.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:A,zIndex:this.zIndex,pointerEvents:y.AUTO,background:this.debug?g.DEBUG:g.NONE},s=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,s,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:[]}),s("design:paramtypes",[Object])],l)}(e.System);return t.A11y=w,t.A11ySystem=C,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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-a11y",
|
|
3
|
-
"version": "1.2.7-editor.
|
|
3
|
+
"version": "1.2.7-editor.7",
|
|
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.
|
|
22
|
-
"@eva/inspector-decorator": "0.1.0-alpha.
|
|
23
|
-
"@eva/plugin-renderer": "1.2.7-editor.
|
|
21
|
+
"@eva/eva.js": "1.2.7-editor.7",
|
|
22
|
+
"@eva/inspector-decorator": "0.1.0-alpha.2",
|
|
23
|
+
"@eva/plugin-renderer": "1.2.7-editor.7",
|
|
24
24
|
"eventemitter3": "^3.1.2"
|
|
25
25
|
}
|
|
26
26
|
}
|