@pluginjs/keyboard
Advanced tools
Comparing version 0.8.4 to 0.8.5
/*! | ||
* @pluginjs/keyboard v0.8.4 (https://pluginjs.com) | ||
* Copyright 2020 Creation Studio Limited | ||
* @pluginjs/keyboard v0.8.5 (https://pluginjs.com) | ||
* Copyright 2021 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
@@ -8,7 +8,9 @@ */ | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var SimpleEmitter = _interopDefault(require('@pluginjs/simple-emitter')); | ||
var SimpleEmitter = require('@pluginjs/simple-emitter'); | ||
var utils = require('@pluginjs/utils'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var SimpleEmitter__default = /*#__PURE__*/_interopDefaultLegacy(SimpleEmitter); | ||
/* eslint object-property-newline: 'off' */ | ||
@@ -105,3 +107,3 @@ | ||
this.element = element || window.document; | ||
this.emitter = new SimpleEmitter(); | ||
this.emitter = new SimpleEmitter__default['default'](); | ||
this.initialize(); | ||
@@ -108,0 +110,0 @@ this.registerEvent(); |
/*! | ||
* @pluginjs/keyboard v0.8.4 (https://pluginjs.com) | ||
* Copyright 2020 Creation Studio Limited | ||
* @pluginjs/keyboard v0.8.5 (https://pluginjs.com) | ||
* Copyright 2021 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
"use strict";var t,e=(t=require("@pluginjs/simple-emitter"))&&"object"==typeof t&&"default"in t?t.default:t,r=require("@pluginjs/utils"),s={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"caps_lock",27:"esc",32:"space",33:"page_up",34:"page_down",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"command",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"num_lock"},i={};for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(i[s[n]]=Number(n));var a={16:"shift",17:"ctrl",18:"alt",91:"command"};class o{constructor(t){this.element=t||window.document,this.emitter=new e,this.initialize(),this.registerEvent()}initialize(){this.status={},r.each(a,(t,e)=>{this.status[e]=!1,this.emitter.on("".concat(t,"down"),()=>{this.status[e]||(this.status[e]=!0)}),this.emitter.on("".concat(t,"up"),()=>{this.status[e]&&(this.status[e]=!1)})})}registerEvent(){var t=t=>this.handler(t);this.element.addEventListener("keydown",t),this.element.addEventListener("keyup",t)}handler(t){var e=t.keyCode,s="keydown"===t.type?"down":"up",i="";if((93!==e&&224!==e||(e=91),e in a)&&!1===this.emitter.emit(e+s))return!1;r.each(this.status,(t,e)=>{e&&(i+=t)});var n=i+e+s;n in this.emitter.listeners&&(!1===this.emitter.emit(n)&&(t.preventDefault(),t.stopPropagation()))}on(t,e,r){return this.dispatch(!0,t,e,r)}off(t,e,r){return this.dispatch(!1,t,e,r)}dispatch(t,e,r,s){return this.parseKeys(this.processKey(r)).forEach(r=>{var i=r.modifiers,n=r.keyCode,o="";if(null!==i)for(var h=0;h<i.length;h++)o+=a[i[h]];t?this.emitter.on(o+n+e,s):this.emitter.off(o+n+e,s)}),this}parseKeys(t){var e=[];return t.map(t=>{var r={},s=null,i=(t=t.split("+")).length;return i>1&&(s=this.processModifiers(t),t=[t[i-1]]),t=this.getKeyCode(t[0]),r.modifiers=s,r.keyCode=t,e.push(r),t}),e}processKey(t){var e=(t=t.toLowerCase().replace(/\s/g,"")).split(",");return""===e[e.length-1]&&(e[e.length-2]+=","),e}processModifiers(t){for(var e=t.slice(0,t.length-1),r=0;r<e.length;r++)e[r]=i[e[r]];return e.sort(),e}distribute(t,e,r){return null==r?this.off(t,e,r):this.on(t,e,r)}getKeyName(t){return s[t]}getKeyCode(t){return i[t]}up(t,e){return this.distribute("up",t,e)}down(t,e){return this.distribute("down",t,e)}static of(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return new this(...e)}}module.exports=function(){return o.of(...arguments)}; | ||
"use strict";var t=require("@pluginjs/simple-emitter"),e=require("@pluginjs/utils");function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var s=r(t),i={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"caps_lock",27:"esc",32:"space",33:"page_up",34:"page_down",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"command",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"num_lock"},n={};for(var a in i)Object.prototype.hasOwnProperty.call(i,a)&&(n[i[a]]=Number(a));var o={16:"shift",17:"ctrl",18:"alt",91:"command"};class h{constructor(t){this.element=t||window.document,this.emitter=new s.default,this.initialize(),this.registerEvent()}initialize(){this.status={},e.each(o,((t,e)=>{this.status[e]=!1,this.emitter.on("".concat(t,"down"),(()=>{this.status[e]||(this.status[e]=!0)})),this.emitter.on("".concat(t,"up"),(()=>{this.status[e]&&(this.status[e]=!1)}))}))}registerEvent(){var t=t=>this.handler(t);this.element.addEventListener("keydown",t),this.element.addEventListener("keyup",t)}handler(t){var r=t.keyCode,s="keydown"===t.type?"down":"up",i="";if((93!==r&&224!==r||(r=91),r in o)&&!1===this.emitter.emit(r+s))return!1;e.each(this.status,((t,e)=>{e&&(i+=t)}));var n=i+r+s;n in this.emitter.listeners&&(!1===this.emitter.emit(n)&&(t.preventDefault(),t.stopPropagation()))}on(t,e,r){return this.dispatch(!0,t,e,r)}off(t,e,r){return this.dispatch(!1,t,e,r)}dispatch(t,e,r,s){return this.parseKeys(this.processKey(r)).forEach((r=>{var i=r.modifiers,n=r.keyCode,a="";if(null!==i)for(var h=0;h<i.length;h++)a+=o[i[h]];t?this.emitter.on(a+n+e,s):this.emitter.off(a+n+e,s)})),this}parseKeys(t){var e=[];return t.map((t=>{var r={},s=null,i=(t=t.split("+")).length;return i>1&&(s=this.processModifiers(t),t=[t[i-1]]),t=this.getKeyCode(t[0]),r.modifiers=s,r.keyCode=t,e.push(r),t})),e}processKey(t){var e=(t=t.toLowerCase().replace(/\s/g,"")).split(",");return""===e[e.length-1]&&(e[e.length-2]+=","),e}processModifiers(t){for(var e=t.slice(0,t.length-1),r=0;r<e.length;r++)e[r]=n[e[r]];return e.sort(),e}distribute(t,e,r){return null==r?this.off(t,e,r):this.on(t,e,r)}getKeyName(t){return i[t]}getKeyCode(t){return n[t]}up(t,e){return this.distribute("up",t,e)}down(t,e){return this.distribute("down",t,e)}static of(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return new this(...e)}}module.exports=function(){return h.of(...arguments)}; |
/*! | ||
* @pluginjs/keyboard v0.8.4 (https://pluginjs.com) | ||
* Copyright 2020 Creation Studio Limited | ||
* @pluginjs/keyboard v0.8.5 (https://pluginjs.com) | ||
* Copyright 2021 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
@@ -5,0 +5,0 @@ */ |
/*! | ||
* @pluginjs/keyboard v0.8.4 (https://pluginjs.com) | ||
* Copyright 2020 Creation Studio Limited | ||
* @pluginjs/keyboard v0.8.5 (https://pluginjs.com) | ||
* Copyright 2021 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
import t from"@pluginjs/simple-emitter";import{each as e}from"@pluginjs/utils";var r={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"caps_lock",27:"esc",32:"space",33:"page_up",34:"page_down",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"command",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"num_lock"},s={};for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(s[r[i]]=Number(i));var n={16:"shift",17:"ctrl",18:"alt",91:"command"};class o{constructor(e){this.element=e||window.document,this.emitter=new t,this.initialize(),this.registerEvent()}initialize(){this.status={},e(n,(t,e)=>{this.status[e]=!1,this.emitter.on("".concat(t,"down"),()=>{this.status[e]||(this.status[e]=!0)}),this.emitter.on("".concat(t,"up"),()=>{this.status[e]&&(this.status[e]=!1)})})}registerEvent(){var t=t=>this.handler(t);this.element.addEventListener("keydown",t),this.element.addEventListener("keyup",t)}handler(t){var r=t.keyCode,s="keydown"===t.type?"down":"up",i="";if((93!==r&&224!==r||(r=91),r in n)&&!1===this.emitter.emit(r+s))return!1;e(this.status,(t,e)=>{e&&(i+=t)});var o=i+r+s;o in this.emitter.listeners&&(!1===this.emitter.emit(o)&&(t.preventDefault(),t.stopPropagation()))}on(t,e,r){return this.dispatch(!0,t,e,r)}off(t,e,r){return this.dispatch(!1,t,e,r)}dispatch(t,e,r,s){return this.parseKeys(this.processKey(r)).forEach(r=>{var i=r.modifiers,o=r.keyCode,a="";if(null!==i)for(var h=0;h<i.length;h++)a+=n[i[h]];t?this.emitter.on(a+o+e,s):this.emitter.off(a+o+e,s)}),this}parseKeys(t){var e=[];return t.map(t=>{var r={},s=null,i=(t=t.split("+")).length;return i>1&&(s=this.processModifiers(t),t=[t[i-1]]),t=this.getKeyCode(t[0]),r.modifiers=s,r.keyCode=t,e.push(r),t}),e}processKey(t){var e=(t=t.toLowerCase().replace(/\s/g,"")).split(",");return""===e[e.length-1]&&(e[e.length-2]+=","),e}processModifiers(t){for(var e=t.slice(0,t.length-1),r=0;r<e.length;r++)e[r]=s[e[r]];return e.sort(),e}distribute(t,e,r){return null==r?this.off(t,e,r):this.on(t,e,r)}getKeyName(t){return r[t]}getKeyCode(t){return s[t]}up(t,e){return this.distribute("up",t,e)}down(t,e){return this.distribute("down",t,e)}static of(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return new this(...e)}}export default function(){return o.of(...arguments)} | ||
import t from"@pluginjs/simple-emitter";import{each as e}from"@pluginjs/utils";var r={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"caps_lock",27:"esc",32:"space",33:"page_up",34:"page_down",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"command",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"num_lock"},s={};for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(s[r[i]]=Number(i));var n={16:"shift",17:"ctrl",18:"alt",91:"command"};class o{constructor(e){this.element=e||window.document,this.emitter=new t,this.initialize(),this.registerEvent()}initialize(){this.status={},e(n,((t,e)=>{this.status[e]=!1,this.emitter.on("".concat(t,"down"),(()=>{this.status[e]||(this.status[e]=!0)})),this.emitter.on("".concat(t,"up"),(()=>{this.status[e]&&(this.status[e]=!1)}))}))}registerEvent(){var t=t=>this.handler(t);this.element.addEventListener("keydown",t),this.element.addEventListener("keyup",t)}handler(t){var r=t.keyCode,s="keydown"===t.type?"down":"up",i="";if((93!==r&&224!==r||(r=91),r in n)&&!1===this.emitter.emit(r+s))return!1;e(this.status,((t,e)=>{e&&(i+=t)}));var o=i+r+s;o in this.emitter.listeners&&(!1===this.emitter.emit(o)&&(t.preventDefault(),t.stopPropagation()))}on(t,e,r){return this.dispatch(!0,t,e,r)}off(t,e,r){return this.dispatch(!1,t,e,r)}dispatch(t,e,r,s){return this.parseKeys(this.processKey(r)).forEach((r=>{var i=r.modifiers,o=r.keyCode,a="";if(null!==i)for(var h=0;h<i.length;h++)a+=n[i[h]];t?this.emitter.on(a+o+e,s):this.emitter.off(a+o+e,s)})),this}parseKeys(t){var e=[];return t.map((t=>{var r={},s=null,i=(t=t.split("+")).length;return i>1&&(s=this.processModifiers(t),t=[t[i-1]]),t=this.getKeyCode(t[0]),r.modifiers=s,r.keyCode=t,e.push(r),t})),e}processKey(t){var e=(t=t.toLowerCase().replace(/\s/g,"")).split(",");return""===e[e.length-1]&&(e[e.length-2]+=","),e}processModifiers(t){for(var e=t.slice(0,t.length-1),r=0;r<e.length;r++)e[r]=s[e[r]];return e.sort(),e}distribute(t,e,r){return null==r?this.off(t,e,r):this.on(t,e,r)}getKeyName(t){return r[t]}getKeyCode(t){return s[t]}up(t,e){return this.distribute("up",t,e)}down(t,e){return this.distribute("down",t,e)}static of(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return new this(...e)}}export default function(){return o.of(...arguments)} |
/*! | ||
* @pluginjs/keyboard v0.8.4 (https://pluginjs.com) | ||
* Copyright 2020 Creation Studio Limited | ||
* @pluginjs/keyboard v0.8.5 (https://pluginjs.com) | ||
* Copyright 2021 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
@@ -9,7 +9,9 @@ */ | ||
typeof define === 'function' && define.amd ? define(['@pluginjs/simple-emitter', '@pluginjs/utils'], factory) : | ||
(global = global || self, global['@pluginjs/keyboard'] = factory(global['@pluginjs/simple-emitter'], global['@pluginjs/utils'])); | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global['@pluginjs/keyboard'] = factory(global['@pluginjs/simple-emitter'], global['@pluginjs/utils'])); | ||
}(this, (function (SimpleEmitter, utils) { 'use strict'; | ||
SimpleEmitter = SimpleEmitter && Object.prototype.hasOwnProperty.call(SimpleEmitter, 'default') ? SimpleEmitter['default'] : SimpleEmitter; | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var SimpleEmitter__default = /*#__PURE__*/_interopDefaultLegacy(SimpleEmitter); | ||
function _classCallCheck(instance, Constructor) { | ||
@@ -52,3 +54,3 @@ if (!(instance instanceof Constructor)) { | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
@@ -170,3 +172,3 @@ } catch (e) { | ||
this.element = element || window.document; | ||
this.emitter = new SimpleEmitter(); | ||
this.emitter = new SimpleEmitter__default['default'](); | ||
this.initialize(); | ||
@@ -173,0 +175,0 @@ this.registerEvent(); |
/*! | ||
* @pluginjs/keyboard v0.8.4 (https://pluginjs.com) | ||
* Copyright 2020 Creation Studio Limited | ||
* @pluginjs/keyboard v0.8.5 (https://pluginjs.com) | ||
* Copyright 2021 Creation Studio Limited | ||
* Released under the GPL-3.0 License. | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@pluginjs/simple-emitter"),require("@pluginjs/utils")):"function"==typeof define&&define.amd?define(["@pluginjs/simple-emitter","@pluginjs/utils"],t):(e=e||self)["@pluginjs/keyboard"]=t(e["@pluginjs/simple-emitter"],e["@pluginjs/utils"])}(this,(function(e,t){"use strict";function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function r(e,t){return(r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function u(e,t,n){return(u=i()?Reflect.construct:function(e,t,n){var i=[null];i.push.apply(i,t);var u=new(Function.bind.apply(e,i));return n&&r(u,n.prototype),u}).apply(null,arguments)}e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;var o={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"caps_lock",27:"esc",32:"space",33:"page_up",34:"page_down",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"command",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"num_lock"},s={};for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&(s[o[a]]=Number(a));var f={16:"shift",17:"ctrl",18:"alt",91:"command"},c=function(){function r(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),this.element=t||window.document,this.emitter=new e,this.initialize(),this.registerEvent()}var i,a,c;return i=r,c=[{key:"of",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return u(this,t)}}],(a=[{key:"initialize",value:function(){var e=this;this.status={},t.each(f,(function(t,n){e.status[n]=!1,e.emitter.on("".concat(t,"down"),(function(){e.status[n]||(e.status[n]=!0)})),e.emitter.on("".concat(t,"up"),(function(){e.status[n]&&(e.status[n]=!1)}))}))}},{key:"registerEvent",value:function(){var e=this,t=function(t){return e.handler(t)};this.element.addEventListener("keydown",t),this.element.addEventListener("keyup",t)}},{key:"handler",value:function(e){var n=e.keyCode,r="keydown"===e.type?"down":"up",i="";if(93!==n&&224!==n||(n=91),n in f&&!1===this.emitter.emit(n+r))return!1;t.each(this.status,(function(e,t){t&&(i+=e)}));var u=i+n+r;u in this.emitter.listeners&&!1===this.emitter.emit(u)&&(e.preventDefault(),e.stopPropagation())}},{key:"on",value:function(e,t,n){return this.dispatch(!0,e,t,n)}},{key:"off",value:function(e,t,n){return this.dispatch(!1,e,t,n)}},{key:"dispatch",value:function(e,t,n,r){var i=this;return this.parseKeys(this.processKey(n)).forEach((function(n){var u=n.modifiers,o=n.keyCode,s="";if(null!==u)for(var a=0;a<u.length;a++)s+=f[u[a]];e?i.emitter.on(s+o+t,r):i.emitter.off(s+o+t,r)})),this}},{key:"parseKeys",value:function(e){var t=this,n=[];return e.map((function(e){var r={},i=null,u=(e=e.split("+")).length;return u>1&&(i=t.processModifiers(e),e=[e[u-1]]),e=t.getKeyCode(e[0]),r.modifiers=i,r.keyCode=e,n.push(r),e})),n}},{key:"processKey",value:function(e){var t=(e=e.toLowerCase().replace(/\s/g,"")).split(",");return""===t[t.length-1]&&(t[t.length-2]+=","),t}},{key:"processModifiers",value:function(e){for(var t=e.slice(0,e.length-1),n=0;n<t.length;n++)t[n]=s[t[n]];return t.sort(),t}},{key:"distribute",value:function(e,t,n){return null==n?this.off(e,t,n):this.on(e,t,n)}},{key:"getKeyName",value:function(e){return o[e]}},{key:"getKeyCode",value:function(e){return s[e]}},{key:"up",value:function(e,t){return this.distribute("up",e,t)}},{key:"down",value:function(e,t){return this.distribute("down",e,t)}}])&&n(i.prototype,a),c&&n(i,c),r}();return function(){return c.of.apply(c,arguments)}})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@pluginjs/simple-emitter"),require("@pluginjs/utils")):"function"==typeof define&&define.amd?define(["@pluginjs/simple-emitter","@pluginjs/utils"],t):(e="undefined"!=typeof globalThis?globalThis:e||self)["@pluginjs/keyboard"]=t(e["@pluginjs/simple-emitter"],e["@pluginjs/utils"])}(this,(function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(e);function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function o(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function s(e,t,n){return(s=o()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&u(i,n.prototype),i}).apply(null,arguments)}var a={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"caps_lock",27:"esc",32:"space",33:"page_up",34:"page_down",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"command",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"num_lock"},f={};for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(f[a[l]]=Number(l));var c={16:"shift",17:"ctrl",18:"alt",91:"command"},p=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.element=t||window.document,this.emitter=new r.default,this.initialize(),this.registerEvent()}var n,u,o;return n=e,o=[{key:"of",value:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return s(this,t)}}],(u=[{key:"initialize",value:function(){var e=this;this.status={},t.each(c,(function(t,n){e.status[n]=!1,e.emitter.on("".concat(t,"down"),(function(){e.status[n]||(e.status[n]=!0)})),e.emitter.on("".concat(t,"up"),(function(){e.status[n]&&(e.status[n]=!1)}))}))}},{key:"registerEvent",value:function(){var e=this,t=function(t){return e.handler(t)};this.element.addEventListener("keydown",t),this.element.addEventListener("keyup",t)}},{key:"handler",value:function(e){var n=e.keyCode,r="keydown"===e.type?"down":"up",i="";if(93!==n&&224!==n||(n=91),n in c&&!1===this.emitter.emit(n+r))return!1;t.each(this.status,(function(e,t){t&&(i+=e)}));var u=i+n+r;u in this.emitter.listeners&&!1===this.emitter.emit(u)&&(e.preventDefault(),e.stopPropagation())}},{key:"on",value:function(e,t,n){return this.dispatch(!0,e,t,n)}},{key:"off",value:function(e,t,n){return this.dispatch(!1,e,t,n)}},{key:"dispatch",value:function(e,t,n,r){var i=this;return this.parseKeys(this.processKey(n)).forEach((function(n){var u=n.modifiers,o=n.keyCode,s="";if(null!==u)for(var a=0;a<u.length;a++)s+=c[u[a]];e?i.emitter.on(s+o+t,r):i.emitter.off(s+o+t,r)})),this}},{key:"parseKeys",value:function(e){var t=this,n=[];return e.map((function(e){var r={},i=null,u=(e=e.split("+")).length;return u>1&&(i=t.processModifiers(e),e=[e[u-1]]),e=t.getKeyCode(e[0]),r.modifiers=i,r.keyCode=e,n.push(r),e})),n}},{key:"processKey",value:function(e){var t=(e=e.toLowerCase().replace(/\s/g,"")).split(",");return""===t[t.length-1]&&(t[t.length-2]+=","),t}},{key:"processModifiers",value:function(e){for(var t=e.slice(0,e.length-1),n=0;n<t.length;n++)t[n]=f[t[n]];return t.sort(),t}},{key:"distribute",value:function(e,t,n){return null==n?this.off(e,t,n):this.on(e,t,n)}},{key:"getKeyName",value:function(e){return a[e]}},{key:"getKeyCode",value:function(e){return f[e]}},{key:"up",value:function(e,t){return this.distribute("up",e,t)}},{key:"down",value:function(e,t){return this.distribute("down",e,t)}}])&&i(n.prototype,u),o&&i(n,o),e}();return function(){return p.of.apply(p,arguments)}})); |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "0.8.4", | ||
"version": "0.8.5", | ||
"category": "core", | ||
@@ -37,12 +37,12 @@ "main": "dist/keyboard.common.js", | ||
"dependencies": { | ||
"@pluginjs/dom": "^0.8.4", | ||
"@pluginjs/simple-emitter": "^0.8.4", | ||
"@pluginjs/utils": "^0.8.4" | ||
"@pluginjs/dom": "^0.8.5", | ||
"@pluginjs/simple-emitter": "^0.8.5", | ||
"@pluginjs/utils": "^0.8.5" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.10.2", | ||
"@pluginjs/browserslist-config": "^1.3.1", | ||
"@pluginjs/cli": "^0.8.1", | ||
"@rollup/plugin-commonjs": "^12.0.0", | ||
"@rollup/plugin-node-resolve": "^8.0.0", | ||
"@babel/core": "^7.12.10", | ||
"@pluginjs/browserslist-config": "^1.3.2", | ||
"@pluginjs/cli": "^0.8.2", | ||
"@rollup/plugin-commonjs": "^17.1.0", | ||
"@rollup/plugin-node-resolve": "^11.1.0", | ||
"babel-jest": "*", | ||
@@ -52,3 +52,3 @@ "jest": "*", | ||
"rename": "^1.0.4", | ||
"rollup": "^2.12.0", | ||
"rollup": "^2.38.1", | ||
"rollup-plugin-babel": "*", | ||
@@ -72,4 +72,4 @@ "rollup-plugin-terser": "*" | ||
], | ||
"gitHead": "c7a30bcc922362e40dbc35af4290a259c9b29566", | ||
"gitHead": "e0247ab4b5e2026b77a390619f2b96bac30609c6", | ||
"title": "Plugin" | ||
} |
42307
1095
Updated@pluginjs/dom@^0.8.5
Updated@pluginjs/utils@^0.8.5