@pluginjs/keyboard
Advanced tools
Comparing version 0.2.17 to 0.2.18
@@ -155,2 +155,11 @@ let Emitter = class Emitter { | ||
const curry = (fn, args = []) => (...subArgs) => { | ||
const currylen = fn.currylen || fn.length; | ||
const collect = args.concat(subArgs); | ||
if (collect.length >= currylen) { | ||
return fn(...collect); | ||
} | ||
return curry(fn, collect); | ||
}; | ||
/*eslint-disable */ | ||
@@ -314,2 +323,42 @@ /* Credit to http://is.js.org MIT */ | ||
// == animation == // | ||
const fade = curry((type, { duration, callback }, element) => { | ||
const isIn = type === 'in'; | ||
let opacity = isIn ? 0 : 1; | ||
let start = null; | ||
if (isIn) { | ||
if (element.style.display === 'none') { | ||
element.style.display = 'inline'; | ||
} | ||
element.style.opacity = opacity; | ||
} | ||
function step(timestamp) { | ||
if (!start) { | ||
start = timestamp; | ||
} | ||
const progress = timestamp - start; | ||
const percent = progress / duration; | ||
opacity = isIn ? opacity + percent : opacity - percent; | ||
element.style.opacity = opacity; | ||
if (opacity <= 0) { | ||
element.style.display = 'none'; | ||
} | ||
if (progress < duration) { | ||
window.requestAnimationFrame(step); | ||
} else if (callback) { | ||
callback(); | ||
} | ||
} | ||
window.requestAnimationFrame(step); | ||
}); | ||
const fadeOut = fade('out'); | ||
const fadeIn = fade('in'); | ||
/* eslint object-property-newline: 'off' */ | ||
@@ -316,0 +365,0 @@ const MAP_BY_CODE = { |
@@ -75,2 +75,12 @@ (function (global, factory) { | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
var Emitter = function () { | ||
@@ -264,2 +274,18 @@ function Emitter() { | ||
var curry = function curry(fn) { | ||
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
return function () { | ||
for (var _len5 = arguments.length, subArgs = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { | ||
subArgs[_key5] = arguments[_key5]; | ||
} | ||
var currylen = fn.currylen || fn.length; | ||
var collect = args.concat(subArgs); | ||
if (collect.length >= currylen) { | ||
return fn.apply(undefined, toConsumableArray(collect)); | ||
} | ||
return curry(fn, collect); | ||
}; | ||
}; | ||
/*eslint-disable */ | ||
@@ -429,2 +455,45 @@ /* Credit to http://is.js.org MIT */ | ||
// == animation == // | ||
var fade = curry(function (type, _ref9, element) { | ||
var duration = _ref9.duration, | ||
callback = _ref9.callback; | ||
var isIn = type === 'in'; | ||
var opacity = isIn ? 0 : 1; | ||
var start = null; | ||
if (isIn) { | ||
if (element.style.display === 'none') { | ||
element.style.display = 'inline'; | ||
} | ||
element.style.opacity = opacity; | ||
} | ||
function step(timestamp) { | ||
if (!start) { | ||
start = timestamp; | ||
} | ||
var progress = timestamp - start; | ||
var percent = progress / duration; | ||
opacity = isIn ? opacity + percent : opacity - percent; | ||
element.style.opacity = opacity; | ||
if (opacity <= 0) { | ||
element.style.display = 'none'; | ||
} | ||
if (progress < duration) { | ||
window.requestAnimationFrame(step); | ||
} else if (callback) { | ||
callback(); | ||
} | ||
} | ||
window.requestAnimationFrame(step); | ||
}); | ||
var fadeOut = fade('out'); | ||
var fadeIn = fade('in'); | ||
/* eslint object-property-newline: 'off' */ | ||
@@ -431,0 +500,0 @@ var MAP_BY_CODE = { |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e["@pluginjs/keyboard"]={})}(this,function(e){"use strict";var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},r=function(){function e(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)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,i=!1,s=void 0;try{for(var o,u=e[Symbol.iterator]();!(r=(o=u.next()).done)&&(n.push(o.value),!t||n.length!==t);r=!0);}catch(e){i=!0,s=e}finally{try{!r&&u.return&&u.return()}finally{if(i)throw s}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),s=function(){function e(){n(this,e),this.listeners={},this.sortedListeners={}}return r(e,[{key:"emit",value:function(e){for(var t=this.getListeners(e),n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];for(var s=0;s<t.length;s++){var o=null;if(o=null!==t[s].context?t[s].context:{type:e},!1===t[s].listener.apply(o,r))return!1}return!0}},{key:"on",value:function(e,t,n,r){return this.addListener(e,t,n,r)}},{key:"once",value:function(e,t,n,r){return this.addOneTimeListener(e,t,n,r)}},{key:"off",value:function(e,t){return void 0===t?this.removeAllListeners(e):this.removeListener(e,t)}},{key:"addListener",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10;return this.ensureListener(t),this.listeners[e]||(this.listeners[e]={}),this.listeners[e][r]||(this.listeners[e][r]=[]),this.listeners[e][r].push({context:n,listener:t}),this.clearSortedListeners(e),this}},{key:"addOneTimeListener",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10,i=this;return this.addListener(e,function n(){return i.removeListener(e,n),t.apply(void 0,arguments)},n,r),this}},{key:"removeListener",value:function(e,t){this.clearSortedListeners(e);var n=this.hasListeners(e)?this.listeners[e]:[];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(n[r]=n[r].filter(function(e){return e.listener!==t}),0===n[r].length&&delete n[r]);return this.listeners[e]=n,this}},{key:"removeAllListeners",value:function(e){return this.clearSortedListeners(e),this.hasListeners(e)&&delete this.listeners[e],this}},{key:"ensureListener",value:function(e){var n=void 0===e?"undefined":t(e);if("function"===n)return e;throw new TypeError("Listeners should be function or closure. Received type: "+n)}},{key:"hasListeners",value:function(e){return!(!this.listeners[e]||0===Object.keys(this.listeners[e]).length)}},{key:"getListeners",value:function(e){return this.sortedListeners.hasOwnProperty(e)||(this.sortedListeners[e]=this.getSortedListeners(e)),this.sortedListeners[e]}},{key:"getSortedListeners",value:function(e){if(!this.hasListeners(e))return[];var t=this.listeners[e],n=Object.keys(t);n.sort(function(e,t){return e-t});for(var r=[],i=0;i<n.length;i++)r=r.concat(t[n[i]]);return r}},{key:"clearSortedListeners",value:function(e){delete this.sortedListeners[e]}}]),e}(),o=Object.prototype.toString,u=function(e){return Array.isArray?Array.isArray(e):"[object Array]"===o.call(e)},a=function(e,t){var n=0,r=void 0;if(u(e))for(r=e.length;n<r;n++)t(e[n],n);else Object.entries(e).map(function(e){var n=i(e,2),r=n[0],s=n[1];return t(r,s)});return e},l={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 c in l)Object.prototype.hasOwnProperty.call(l,c)&&(f[l[c]]=Number(c));var h={16:"shift",17:"ctrl",18:"alt",91:"command"},y=function(){function e(t){n(this,e),this.element=t||window.document,this.emitter=new s,this.initialize(),this.registerEvent()}return r(e,[{key:"initialize",value:function(){var e=this;this.status={},a(h,function(t,n){e.status[n]=!1,e.emitter.on(t+"down",function(){e.status[n]||(e.status[n]=!0)}),e.emitter.on(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 t=e.keyCode,n="keydown"===e.type?"down":"up",r="";if((93!==t&&224!==t||(t=91),t in h)&&!1===this.emitter.emit(t+n))return!1;a(this.status,function(e,t){t&&(r+=e)});var i=r+t+n;if(i in this.emitter.listeners)return this.emitter.emit(i)}},{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 s=n.modifiers,o=n.keyCode,u="";if(null!==s)for(var a=0;a<s.length;a++)u+=h[s[a]];e?i.emitter.on(u+o+t,r):i.emitter.off(u+o+t,r)}),this}},{key:"parseKeys",value:function(e){var t=this,n=[];return e.map(function(e){var r={},i=null,s=(e=e.split("+")).length;return s>1&&(i=t.processModifiers(e),e=[e[s-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||void 0===n?this.off(e,t,n):this.on(e,t,n)}},{key:"getKeyName",value:function(e){return l[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)}}]),e}(),d={init:function(e){return new y(e)}};e.default=d,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e["@pluginjs/keyboard"]={})}(this,function(e){"use strict";var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},r=function(){function e(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)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],r=!0,i=!1,s=void 0;try{for(var o,u=e[Symbol.iterator]();!(r=(o=u.next()).done)&&(n.push(o.value),!t||n.length!==t);r=!0);}catch(e){i=!0,s=e}finally{try{!r&&u.return&&u.return()}finally{if(i)throw s}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),s=function(){function e(){n(this,e),this.listeners={},this.sortedListeners={}}return r(e,[{key:"emit",value:function(e){for(var t=this.getListeners(e),n=arguments.length,r=Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];for(var s=0;s<t.length;s++){var o=null;if(o=null!==t[s].context?t[s].context:{type:e},!1===t[s].listener.apply(o,r))return!1}return!0}},{key:"on",value:function(e,t,n,r){return this.addListener(e,t,n,r)}},{key:"once",value:function(e,t,n,r){return this.addOneTimeListener(e,t,n,r)}},{key:"off",value:function(e,t){return void 0===t?this.removeAllListeners(e):this.removeListener(e,t)}},{key:"addListener",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10;return this.ensureListener(t),this.listeners[e]||(this.listeners[e]={}),this.listeners[e][r]||(this.listeners[e][r]=[]),this.listeners[e][r].push({context:n,listener:t}),this.clearSortedListeners(e),this}},{key:"addOneTimeListener",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10,i=this;return this.addListener(e,function n(){return i.removeListener(e,n),t.apply(void 0,arguments)},n,r),this}},{key:"removeListener",value:function(e,t){this.clearSortedListeners(e);var n=this.hasListeners(e)?this.listeners[e]:[];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(n[r]=n[r].filter(function(e){return e.listener!==t}),0===n[r].length&&delete n[r]);return this.listeners[e]=n,this}},{key:"removeAllListeners",value:function(e){return this.clearSortedListeners(e),this.hasListeners(e)&&delete this.listeners[e],this}},{key:"ensureListener",value:function(e){var n=void 0===e?"undefined":t(e);if("function"===n)return e;throw new TypeError("Listeners should be function or closure. Received type: "+n)}},{key:"hasListeners",value:function(e){return!(!this.listeners[e]||0===Object.keys(this.listeners[e]).length)}},{key:"getListeners",value:function(e){return this.sortedListeners.hasOwnProperty(e)||(this.sortedListeners[e]=this.getSortedListeners(e)),this.sortedListeners[e]}},{key:"getSortedListeners",value:function(e){if(!this.hasListeners(e))return[];var t=this.listeners[e],n=Object.keys(t);n.sort(function(e,t){return e-t});for(var r=[],i=0;i<n.length;i++)r=r.concat(t[n[i]]);return r}},{key:"clearSortedListeners",value:function(e){delete this.sortedListeners[e]}}]),e}(),o=Object.prototype.toString,u=function(e){return Array.isArray?Array.isArray(e):"[object Array]"===o.call(e)},a=function(e,t){var n=0,r=void 0;if(u(e))for(r=e.length;n<r;n++)t(e[n],n);else Object.entries(e).map(function(e){var n=i(e,2),r=n[0],s=n[1];return t(r,s)});return e},l=function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return function(){for(var r=arguments.length,i=Array(r),s=0;s<r;s++)i[s]=arguments[s];var o=t.currylen||t.length,u=n.concat(i);return u.length>=o?t.apply(void 0,function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}(u)):e(t,u)}}(function(e,t,n){var r=t.duration,i=t.callback,s="in"===e,o=s?0:1,u=null;s&&("none"===n.style.display&&(n.style.display="inline"),n.style.opacity=o),window.requestAnimationFrame(function e(t){u||(u=t);var a=t-u,l=a/r;o=s?o+l:o-l,n.style.opacity=o,o<=0&&(n.style.display="none"),a<r?window.requestAnimationFrame(e):i&&i()})}),f=(l("out"),l("in"),{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"}),c={};for(var h in f)Object.prototype.hasOwnProperty.call(f,h)&&(c[f[h]]=Number(h));var y={16:"shift",17:"ctrl",18:"alt",91:"command"},d=function(){function e(t){n(this,e),this.element=t||window.document,this.emitter=new s,this.initialize(),this.registerEvent()}return r(e,[{key:"initialize",value:function(){var e=this;this.status={},a(y,function(t,n){e.status[n]=!1,e.emitter.on(t+"down",function(){e.status[n]||(e.status[n]=!0)}),e.emitter.on(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 t=e.keyCode,n="keydown"===e.type?"down":"up",r="";if((93!==t&&224!==t||(t=91),t in y)&&!1===this.emitter.emit(t+n))return!1;a(this.status,function(e,t){t&&(r+=e)});var i=r+t+n;if(i in this.emitter.listeners)return this.emitter.emit(i)}},{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 s=n.modifiers,o=n.keyCode,u="";if(null!==s)for(var a=0;a<s.length;a++)u+=y[s[a]];e?i.emitter.on(u+o+t,r):i.emitter.off(u+o+t,r)}),this}},{key:"parseKeys",value:function(e){var t=this,n=[];return e.map(function(e){var r={},i=null,s=(e=e.split("+")).length;return s>1&&(i=t.processModifiers(e),e=[e[s-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]=c[t[n]];return t.sort(),t}},{key:"distribute",value:function(e,t,n){return null===n||void 0===n?this.off(e,t,n):this.on(e,t,n)}},{key:"getKeyName",value:function(e){return f[e]}},{key:"getKeyCode",value:function(e){return c[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)}}]),e}(),v={init:function(e){return new d(e)}};e.default=v,Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -75,2 +75,12 @@ (function (global, factory) { | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
var Emitter = function () { | ||
@@ -264,2 +274,18 @@ function Emitter() { | ||
var curry = function curry(fn) { | ||
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
return function () { | ||
for (var _len5 = arguments.length, subArgs = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { | ||
subArgs[_key5] = arguments[_key5]; | ||
} | ||
var currylen = fn.currylen || fn.length; | ||
var collect = args.concat(subArgs); | ||
if (collect.length >= currylen) { | ||
return fn.apply(undefined, toConsumableArray(collect)); | ||
} | ||
return curry(fn, collect); | ||
}; | ||
}; | ||
/*eslint-disable */ | ||
@@ -429,2 +455,45 @@ /* Credit to http://is.js.org MIT */ | ||
// == animation == // | ||
var fade = curry(function (type, _ref9, element) { | ||
var duration = _ref9.duration, | ||
callback = _ref9.callback; | ||
var isIn = type === 'in'; | ||
var opacity = isIn ? 0 : 1; | ||
var start = null; | ||
if (isIn) { | ||
if (element.style.display === 'none') { | ||
element.style.display = 'inline'; | ||
} | ||
element.style.opacity = opacity; | ||
} | ||
function step(timestamp) { | ||
if (!start) { | ||
start = timestamp; | ||
} | ||
var progress = timestamp - start; | ||
var percent = progress / duration; | ||
opacity = isIn ? opacity + percent : opacity - percent; | ||
element.style.opacity = opacity; | ||
if (opacity <= 0) { | ||
element.style.display = 'none'; | ||
} | ||
if (progress < duration) { | ||
window.requestAnimationFrame(step); | ||
} else if (callback) { | ||
callback(); | ||
} | ||
} | ||
window.requestAnimationFrame(step); | ||
}); | ||
var fadeOut = fade('out'); | ||
var fadeIn = fade('in'); | ||
/* eslint object-property-newline: 'off' */ | ||
@@ -431,0 +500,0 @@ var MAP_BY_CODE = { |
{ | ||
"name": "@pluginjs/keyboard", | ||
"title": "Plugin", | ||
"version": "0.2.17", | ||
"version": "0.2.18", | ||
"description": "A workflow for modern frontend development.", | ||
@@ -6,0 +6,0 @@ "author": "Creation Studio Limited", |
import Emitter from '@pluginjs/emitter' | ||
import { Each } from '@pluginjs/dom/html' | ||
import { Each } from '@pluginjs/dom' | ||
@@ -4,0 +4,0 @@ /* eslint object-property-newline: 'off' */ |
68140
2116