Comparing version 1.1.0 to 1.1.1
@@ -1,6 +0,6 @@ | ||
import Component from "@egjs/component"; | ||
import EventEmitter, { EmitterParam } from "@scena/event-emitter"; | ||
export declare function getKey(keyCode: number): string; | ||
export declare function getCombi(e: KeyboardEvent, key?: string): string[]; | ||
export declare function getModifierCombi(e: KeyboardEvent): string[]; | ||
export interface KeyControllerEvent { | ||
export interface KeyControllerEvent extends EmitterParam { | ||
inputEvent: KeyboardEvent; | ||
@@ -15,3 +15,6 @@ isToggle: boolean; | ||
} | ||
declare class KeyController extends Component { | ||
declare class KeyController extends EventEmitter<{ | ||
blur: {}; | ||
[key: string]: object; | ||
}> { | ||
private container; | ||
@@ -18,0 +21,0 @@ static get global(): KeyController; |
@@ -7,6 +7,4 @@ /* | ||
repository: git+https://github.com/daybrush/keycon.git | ||
version: 1.1.0 | ||
version: 1.1.1 | ||
*/ | ||
import Component from '@egjs/component'; | ||
/*! ***************************************************************************** | ||
@@ -50,2 +48,427 @@ Copyright (c) Microsoft Corporation. | ||
/* | ||
Copyright (c) 2018 Daybrush | ||
@name: @daybrush/utils | ||
license: MIT | ||
author: Daybrush | ||
repository: https://github.com/daybrush/utils | ||
@version 1.0.0 | ||
*/ | ||
/** | ||
* get string "object" | ||
* @memberof Consts | ||
* @example | ||
import {OBJECT} from "@daybrush/utils"; | ||
console.log(OBJECT); // "object" | ||
*/ | ||
var OBJECT = "object"; | ||
/** | ||
* get string "string" | ||
* @memberof Consts | ||
* @example | ||
import {STRING} from "@daybrush/utils"; | ||
console.log(STRING); // "string" | ||
*/ | ||
var STRING = "string"; | ||
/** | ||
* Check the type that the value is object. | ||
* @memberof Utils | ||
* @param {string} value - Value to check the type | ||
* @return {} true if the type is correct, false otherwise | ||
* @example | ||
import {isObject} from "@daybrush/utils"; | ||
console.log(isObject({})); // true | ||
console.log(isObject(undefined)); // false | ||
console.log(isObject("")); // false | ||
console.log(isObject(null)); // false | ||
*/ | ||
function isObject(value) { | ||
return value && typeof value === OBJECT; | ||
} | ||
/** | ||
* Check the type that the value is isArray. | ||
* @memberof Utils | ||
* @param {string} value - Value to check the type | ||
* @return {} true if the type is correct, false otherwise | ||
* @example | ||
import {isArray} from "@daybrush/utils"; | ||
console.log(isArray([])); // true | ||
console.log(isArray({})); // false | ||
console.log(isArray(undefined)); // false | ||
console.log(isArray(null)); // false | ||
*/ | ||
function isArray(value) { | ||
return Array.isArray(value); | ||
} | ||
/** | ||
* Check the type that the value is string. | ||
* @memberof Utils | ||
* @param {string} value - Value to check the type | ||
* @return {} true if the type is correct, false otherwise | ||
* @example | ||
import {isString} from "@daybrush/utils"; | ||
console.log(isString("1234")); // true | ||
console.log(isString(undefined)); // false | ||
console.log(isString(1)); // false | ||
console.log(isString(null)); // false | ||
*/ | ||
function isString(value) { | ||
return typeof value === STRING; | ||
} | ||
/** | ||
* Returns the index of the first element in the array that satisfies the provided testing function. | ||
* @function | ||
* @memberof CrossBrowser | ||
* @param - The array `findIndex` was called upon. | ||
* @param - A function to execute on each value in the array until the function returns true, indicating that the satisfying element was found. | ||
* @param - Returns defaultIndex if not found by the function. | ||
* @example | ||
import { findIndex } from "@daybrush/utils"; | ||
findIndex([{a: 1}, {a: 2}, {a: 3}, {a: 4}], ({ a }) => a === 2); // 1 | ||
*/ | ||
function findIndex(arr, callback, defaultIndex) { | ||
if (defaultIndex === void 0) { | ||
defaultIndex = -1; | ||
} | ||
var length = arr.length; | ||
for (var i = 0; i < length; ++i) { | ||
if (callback(arr[i], i, arr)) { | ||
return i; | ||
} | ||
} | ||
return defaultIndex; | ||
} | ||
/** | ||
* Sets up a function that will be called whenever the specified event is delivered to the target | ||
* @memberof DOM | ||
* @param - event target | ||
* @param - A case-sensitive string representing the event type to listen for. | ||
* @param - The object which receives a notification (an object that implements the Event interface) when an event of the specified type occurs | ||
* @param - An options object that specifies characteristics about the event listener. The available options are: | ||
* @example | ||
import {addEvent} from "@daybrush/utils"; | ||
addEvent(el, "click", e => { | ||
console.log(e); | ||
}); | ||
*/ | ||
function addEvent(el, type, listener, options) { | ||
el.addEventListener(type, listener, options); | ||
} | ||
/** | ||
* removes from the EventTarget an event listener previously registered with EventTarget.addEventListener() | ||
* @memberof DOM | ||
* @param - event target | ||
* @param - A case-sensitive string representing the event type to listen for. | ||
* @param - The EventListener function of the event handler to remove from the event target. | ||
* @example | ||
import {addEvent, removeEvent} from "@daybrush/utils"; | ||
const listener = e => { | ||
console.log(e); | ||
}; | ||
addEvent(el, "click", listener); | ||
removeEvent(el, "click", listener); | ||
*/ | ||
function removeEvent(el, type, listener) { | ||
el.removeEventListener(type, listener); | ||
} | ||
/* | ||
Copyright (c) 2019 Daybrush | ||
name: @scena/event-emitter | ||
license: MIT | ||
author: Daybrush | ||
repository: git+https://github.com/daybrush/gesture.git | ||
version: 1.0.0 | ||
*/ | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
var __assign = function () { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __spreadArrays() { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; | ||
return r; | ||
} | ||
/** | ||
* Implement EventEmitter on object or component. | ||
*/ | ||
var EventEmitter = | ||
/*#__PURE__*/ | ||
function () { | ||
function EventEmitter() { | ||
this._events = {}; | ||
} | ||
/** | ||
* Add a listener to the registered event. | ||
* @param - Name of the event to be added | ||
* @param - listener function of the event to be added | ||
* @example | ||
* import EventEmitter from "@scena/event-emitter"; | ||
* cosnt emitter = new EventEmitter(); | ||
* | ||
* // Add listener in "a" event | ||
* emitter.on("a", () => { | ||
* }); | ||
* // Add listeners | ||
* emitter.on({ | ||
* a: () => {}, | ||
* b: () => {}, | ||
* }); | ||
*/ | ||
var __proto = EventEmitter.prototype; | ||
__proto.on = function (eventName, listener) { | ||
if (isObject(eventName)) { | ||
for (var name in eventName) { | ||
this.on(name, eventName[name]); | ||
} | ||
} else { | ||
this._addEvent(eventName, listener, {}); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Remove listeners registered in the event target. | ||
* @param - Name of the event to be removed | ||
* @param - listener function of the event to be removed | ||
* @example | ||
* import EventEmitter from "@scena/event-emitter"; | ||
* cosnt emitter = new EventEmitter(); | ||
* | ||
* // Remove all listeners. | ||
* emitter.off(); | ||
* | ||
* // Remove all listeners in "A" event. | ||
* emitter.off("a"); | ||
* | ||
* | ||
* // Remove "listener" listener in "a" event. | ||
* emitter.off("a", listener); | ||
*/ | ||
__proto.off = function (eventName, listener) { | ||
if (!eventName) { | ||
this._events = {}; | ||
} else if (isObject(eventName)) { | ||
for (var name in eventName) { | ||
this.off(name); | ||
} | ||
} else if (!listener) { | ||
this._events[eventName] = []; | ||
} else { | ||
var events = this._events[eventName]; | ||
if (events) { | ||
var index = findIndex(events, function (e) { | ||
return e.listener === listener; | ||
}); | ||
if (index > -1) { | ||
events.splice(index, 1); | ||
} | ||
} | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Add a disposable listener and Use promise to the registered event. | ||
* @param - Name of the event to be added | ||
* @param - disposable listener function of the event to be added | ||
* @example | ||
* import EventEmitter from "@scena/event-emitter"; | ||
* cosnt emitter = new EventEmitter(); | ||
* | ||
* // Add a disposable listener in "a" event | ||
* emitter.once("a", () => { | ||
* }); | ||
* | ||
* // Use Promise | ||
* emitter.once("a").then(e => { | ||
* }); | ||
*/ | ||
__proto.once = function (eventName, listener) { | ||
var _this = this; | ||
if (listener) { | ||
this._addEvent(eventName, listener, { | ||
once: true | ||
}); | ||
} | ||
return new Promise(function (resolve) { | ||
_this._addEvent(eventName, resolve, { | ||
once: true | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Fires an event to call listeners. | ||
* @param - Event name | ||
* @param - Event parameter | ||
* @return If false, stop the event. | ||
* @example | ||
* | ||
* import EventEmitter from "@scena/event-emitter"; | ||
* | ||
* | ||
* const emitter = new EventEmitter(); | ||
* | ||
* emitter.on("a", e => { | ||
* }); | ||
* | ||
* | ||
* emitter.emit("a", { | ||
* a: 1, | ||
* }); | ||
*/ | ||
__proto.emit = function (eventName, param) { | ||
var _this = this; | ||
if (param === void 0) { | ||
param = {}; | ||
} | ||
var events = this._events[eventName]; | ||
if (!eventName || !events) { | ||
return true; | ||
} | ||
var isStop = false; | ||
param.eventType = eventName; | ||
param.stop = function () { | ||
isStop = true; | ||
}; | ||
param.currentTarget = this; | ||
__spreadArrays(events).forEach(function (info) { | ||
info.listener(param); | ||
if (info.once) { | ||
_this.off(eventName, info.listener); | ||
} | ||
}); | ||
return isStop; | ||
}; | ||
/** | ||
* Fires an event to call listeners. | ||
* @param - Event name | ||
* @param - Event parameter | ||
* @return If false, stop the event. | ||
* @example | ||
* | ||
* import EventEmitter from "@scena/event-emitter"; | ||
* | ||
* | ||
* const emitter = new EventEmitter(); | ||
* | ||
* emitter.on("a", e => { | ||
* }); | ||
* | ||
* | ||
* emitter.emit("a", { | ||
* a: 1, | ||
* }); | ||
*/ | ||
/** | ||
* Fires an event to call listeners. | ||
* @param - Event name | ||
* @param - Event parameter | ||
* @return If false, stop the event. | ||
* @example | ||
* | ||
* import EventEmitter from "@scena/event-emitter"; | ||
* | ||
* | ||
* const emitter = new EventEmitter(); | ||
* | ||
* emitter.on("a", e => { | ||
* }); | ||
* | ||
* // emit | ||
* emitter.trigger("a", { | ||
* a: 1, | ||
* }); | ||
*/ | ||
__proto.trigger = function (eventName, param) { | ||
if (param === void 0) { | ||
param = {}; | ||
} | ||
return this.emit(eventName, param); | ||
}; | ||
__proto._addEvent = function (eventName, listener, options) { | ||
var events = this._events; | ||
events[eventName] = events[eventName] || []; | ||
var listeners = events[eventName]; | ||
listeners.push(__assign({ | ||
listener: listener | ||
}, options)); | ||
}; | ||
return EventEmitter; | ||
}(); | ||
function createCommonjsModule(fn, module) { | ||
@@ -240,91 +663,2 @@ return module = { | ||
/* | ||
Copyright (c) 2018 Daybrush | ||
@name: @daybrush/utils | ||
license: MIT | ||
author: Daybrush | ||
repository: https://github.com/daybrush/utils | ||
@version 1.0.0 | ||
*/ | ||
/** | ||
* get string "string" | ||
* @memberof Consts | ||
* @example | ||
import {STRING} from "@daybrush/utils"; | ||
console.log(STRING); // "string" | ||
*/ | ||
var STRING = "string"; | ||
/** | ||
* Check the type that the value is isArray. | ||
* @memberof Utils | ||
* @param {string} value - Value to check the type | ||
* @return {} true if the type is correct, false otherwise | ||
* @example | ||
import {isArray} from "@daybrush/utils"; | ||
console.log(isArray([])); // true | ||
console.log(isArray({})); // false | ||
console.log(isArray(undefined)); // false | ||
console.log(isArray(null)); // false | ||
*/ | ||
function isArray(value) { | ||
return Array.isArray(value); | ||
} | ||
/** | ||
* Check the type that the value is string. | ||
* @memberof Utils | ||
* @param {string} value - Value to check the type | ||
* @return {} true if the type is correct, false otherwise | ||
* @example | ||
import {isString} from "@daybrush/utils"; | ||
console.log(isString("1234")); // true | ||
console.log(isString(undefined)); // false | ||
console.log(isString(1)); // false | ||
console.log(isString(null)); // false | ||
*/ | ||
function isString(value) { | ||
return typeof value === STRING; | ||
} | ||
/** | ||
* Sets up a function that will be called whenever the specified event is delivered to the target | ||
* @memberof DOM | ||
* @param - event target | ||
* @param - A case-sensitive string representing the event type to listen for. | ||
* @param - The object which receives a notification (an object that implements the Event interface) when an event of the specified type occurs | ||
* @param - An options object that specifies characteristics about the event listener. The available options are: | ||
* @example | ||
import {addEvent} from "@daybrush/utils"; | ||
addEvent(el, "click", e => { | ||
console.log(e); | ||
}); | ||
*/ | ||
function addEvent(el, type, listener, options) { | ||
el.addEventListener(type, listener, options); | ||
} | ||
/** | ||
* removes from the EventTarget an event listener previously registered with EventTarget.addEventListener() | ||
* @memberof DOM | ||
* @param - event target | ||
* @param - A case-sensitive string representing the event type to listen for. | ||
* @param - The EventListener function of the event handler to remove from the event target. | ||
* @example | ||
import {addEvent, removeEvent} from "@daybrush/utils"; | ||
const listener = e => { | ||
console.log(e); | ||
}; | ||
addEvent(el, "click", listener); | ||
removeEvent(el, "click", listener); | ||
*/ | ||
function removeEvent(el, type, listener) { | ||
el.removeEventListener(type, listener); | ||
} | ||
var codeData = { | ||
@@ -562,3 +896,3 @@ "+": "plus", | ||
return KeyController; | ||
}(Component); | ||
}(EventEmitter); | ||
@@ -565,0 +899,0 @@ export default KeyController; |
@@ -7,5 +7,5 @@ /* | ||
repository: git+https://github.com/daybrush/keycon.git | ||
version: 1.1.0 | ||
version: 1.1.1 | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@egjs/component"),require("@daybrush/utils")):"function"==typeof define&&define.amd?define(["@egjs/component","@daybrush/utils"],t):(e=e||self).keycon=t(e.eg.Component,e.utils)}(this,function(e,a){"use strict";var u=function(e,t){return(u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};var t,s,n=(function(e,t){function n(e){var t;if(!e||"object"!=typeof e||(t=e.which||e.keyCode||e.charCode)&&(e=t),"number"==typeof e)return a[e];var n=String(e),r=o[n.toLowerCase()];return r||((r=i[n.toLowerCase()])?r:1===n.length?n.charCodeAt(0):void 0)}n.isEventKey=function(e,t){if(e&&"object"==typeof e){var n=e.which||e.keyCode||e.charCode;if(null==n)return!1;if("string"==typeof t){var r=o[t.toLowerCase()];if(r)return r===n;if(r=i[t.toLowerCase()])return r===n}else if("number"==typeof t)return t===n;return!1}};for(var o=(t=e.exports=n).code=t.codes={backspace:8,tab:9,enter:13,shift:16,ctrl:17,alt:18,"pause/break":19,"caps lock":20,esc:27,space:32,"page up":33,"page down":34,end:35,home:36,left:37,up:38,right:39,down:40,insert:45,delete:46,command:91,"left command":91,"right command":93,"numpad *":106,"numpad +":107,"numpad -":109,"numpad .":110,"numpad /":111,"num lock":144,"scroll lock":145,"my computer":182,"my calculator":183,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222},i=t.aliases={windows:91,"⇧":16,"⌥":18,"⌃":17,"⌘":91,ctl:17,control:17,option:18,pause:19,break:19,caps:20,return:13,escape:27,spc:32,spacebar:32,pgup:33,pgdn:34,ins:45,del:46,cmd:91},r=97;r<123;r++)o[String.fromCharCode(r)]=r-32;for(var r=48;r<58;r++)o[r-48]=r;for(r=1;r<13;r++)o["f"+r]=r+111;for(r=0;r<10;r++)o["numpad "+r]=r+96;var a=t.names=t.title={};for(r in o)a[o[r]]=r;for(var u in i)o[u]=i[u]}(t={exports:{}},t.exports),t.exports),r=(n.code,n.codes,n.aliases,n.names),o=(n.title,{"+":"plus","left command":"meta","right command":"meta"}),i={shift:1,ctrl:2,alt:3,meta:4};function c(e){var t=r[e]||"";for(var n in o)t=t.replace(n,o[n]);return t.replace(/\s/g,"")}function f(e,t){void 0===t&&(t=c(e.keyCode));var n,r=[(n=e).shiftKey&&"shift",n.ctrlKey&&"ctrl",n.altKey&&"alt",n.metaKey&&"meta"].filter(Boolean);return-1===r.indexOf(t)&&r.push(t),r.filter(Boolean)}function l(e){var t=e.slice();return t.sort(function(e,t){return(i[e]||5)-(i[t]||5)}),t}var y=function(n){function e(){this.constructor=t}var t,r;function o(e){void 0===e&&(e=window);var t=n.call(this)||this;return t.container=e,t.ctrlKey=!1,t.altKey=!1,t.shiftKey=!1,t.metaKey=!1,t.clear=function(){return t.ctrlKey=!1,t.altKey=!1,t.shiftKey=!1,t.metaKey=!1,t},t.keydownEvent=function(e){t.triggerEvent("keydown",e)},t.keyupEvent=function(e){t.triggerEvent("keyup",e)},t.blur=function(){t.clear(),t.trigger("blur")},a.addEvent(e,"blur",t.blur),a.addEvent(e,"keydown",t.keydownEvent),a.addEvent(e,"keyup",t.keyupEvent),t}u(t=o,r=n),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e);var i=o.prototype;return Object.defineProperty(o,"global",{get:function(){return s=s||new o},enumerable:!1,configurable:!0}),o.setGlobal=function(){return this.global},i.destroy=function(){var e=this.container;this.clear(),this.off(),a.removeEvent(e,"blur",this.blur),a.removeEvent(e,"keydown",this.keydownEvent),a.removeEvent(e,"keyup",this.keyupEvent)},i.keydown=function(e,t){return this.addEvent("keydown",e,t)},i.offKeydown=function(e,t){return this.removeEvent("keydown",e,t)},i.offKeyup=function(e,t){return this.removeEvent("keyup",e,t)},i.keyup=function(e,t){return this.addEvent("keyup",e,t)},i.addEvent=function(e,t,n){return a.isArray(t)?this.on(e+"."+l(t).join("."),n):a.isString(t)?this.on(e+"."+t,n):this.on(e,t),this},i.removeEvent=function(e,t,n){return a.isArray(t)?this.off(e+"."+l(t).join("."),n):a.isString(t)?this.off(e+"."+t,n):this.off(e,t),this},i.triggerEvent=function(e,t){this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey;var n=c(t.keyCode),r={key:n,isToggle:"ctrl"===n||"shift"===n||"meta"===n||"alt"===n,inputEvent:t,keyCode:t.keyCode,ctrlKey:t.ctrlKey,altKey:t.altKey,shiftKey:t.shiftKey,metaKey:t.metaKey};this.trigger(e,r),this.trigger(e+"."+n,r);var o=f(t,n);1<o.length&&this.trigger(e+"."+o.join("."),r)},o}(e);return y.getKey=c,y.getCombi=f,y}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@daybrush/utils")):"function"==typeof define&&define.amd?define(["@daybrush/utils"],t):(e=e||self).keycon=t(e.utils)}(this,function(a){"use strict";var s=function(e,t){return(s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};var o=function(){return(o=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};var e=function(){function e(){this._events={}}var t=e.prototype;return t.on=function(e,t){if(a.isObject(e))for(var n in e)this.on(n,e[n]);else this._addEvent(e,t,{});return this},t.off=function(e,t){if(e)if(a.isObject(e))for(var n in e)this.off(n);else{var r,o;t?!(r=this._events[e])||-1<(o=a.findIndex(r,function(e){return e.listener===t}))&&r.splice(o,1):this._events[e]=[]}else this._events={};return this},t.once=function(t,e){var n=this;return e&&this._addEvent(t,e,{once:!0}),new Promise(function(e){n._addEvent(t,e,{once:!0})})},t.emit=function(t,n){var r=this;void 0===n&&(n={});var e=this._events[t];if(!t||!e)return!0;var o=!1;return n.eventType=t,n.stop=function(){o=!0},n.currentTarget=this,function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var r=Array(e),o=0,t=0;t<n;t++)for(var i=arguments[t],a=0,s=i.length;a<s;a++,o++)r[o]=i[a];return r}(e).forEach(function(e){e.listener(n),e.once&&r.off(t,e.listener)}),o},t.trigger=function(e,t){return void 0===t&&(t={}),this.emit(e,t)},t._addEvent=function(e,t,n){var r=this._events;r[e]=r[e]||[],r[e].push(o({listener:t},n))},e}();var t,u,n=(function(e,t){function n(e){var t;if(!e||"object"!=typeof e||(t=e.which||e.keyCode||e.charCode)&&(e=t),"number"==typeof e)return a[e];var n=String(e),r=o[n.toLowerCase()];return r||((r=i[n.toLowerCase()])?r:1===n.length?n.charCodeAt(0):void 0)}n.isEventKey=function(e,t){if(e&&"object"==typeof e){var n=e.which||e.keyCode||e.charCode;if(null==n)return!1;if("string"==typeof t){var r=o[t.toLowerCase()];if(r)return r===n;if(r=i[t.toLowerCase()])return r===n}else if("number"==typeof t)return t===n;return!1}};for(var o=(t=e.exports=n).code=t.codes={backspace:8,tab:9,enter:13,shift:16,ctrl:17,alt:18,"pause/break":19,"caps lock":20,esc:27,space:32,"page up":33,"page down":34,end:35,home:36,left:37,up:38,right:39,down:40,insert:45,delete:46,command:91,"left command":91,"right command":93,"numpad *":106,"numpad +":107,"numpad -":109,"numpad .":110,"numpad /":111,"num lock":144,"scroll lock":145,"my computer":182,"my calculator":183,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222},i=t.aliases={windows:91,"⇧":16,"⌥":18,"⌃":17,"⌘":91,ctl:17,control:17,option:18,pause:19,break:19,caps:20,return:13,escape:27,spc:32,spacebar:32,pgup:33,pgdn:34,ins:45,del:46,cmd:91},r=97;r<123;r++)o[String.fromCharCode(r)]=r-32;for(var r=48;r<58;r++)o[r-48]=r;for(r=1;r<13;r++)o["f"+r]=r+111;for(r=0;r<10;r++)o["numpad "+r]=r+96;var a=t.names=t.title={};for(r in o)a[o[r]]=r;for(var s in i)o[s]=i[s]}(t={exports:{}},t.exports),t.exports),r=(n.code,n.codes,n.aliases,n.names),i=(n.title,{"+":"plus","left command":"meta","right command":"meta"}),f={shift:1,ctrl:2,alt:3,meta:4};function c(e){var t=r[e]||"";for(var n in i)t=t.replace(n,i[n]);return t.replace(/\s/g,"")}function l(e,t){void 0===t&&(t=c(e.keyCode));var n,r=[(n=e).shiftKey&&"shift",n.ctrlKey&&"ctrl",n.altKey&&"alt",n.metaKey&&"meta"].filter(Boolean);return-1===r.indexOf(t)&&r.push(t),r.filter(Boolean)}function y(e){var t=e.slice();return t.sort(function(e,t){return(f[e]||5)-(f[t]||5)}),t}var d=function(n){function e(){this.constructor=t}var t,r;function o(e){void 0===e&&(e=window);var t=n.call(this)||this;return t.container=e,t.ctrlKey=!1,t.altKey=!1,t.shiftKey=!1,t.metaKey=!1,t.clear=function(){return t.ctrlKey=!1,t.altKey=!1,t.shiftKey=!1,t.metaKey=!1,t},t.keydownEvent=function(e){t.triggerEvent("keydown",e)},t.keyupEvent=function(e){t.triggerEvent("keyup",e)},t.blur=function(){t.clear(),t.trigger("blur")},a.addEvent(e,"blur",t.blur),a.addEvent(e,"keydown",t.keydownEvent),a.addEvent(e,"keyup",t.keyupEvent),t}s(t=o,r=n),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e);var i=o.prototype;return Object.defineProperty(o,"global",{get:function(){return u=u||new o},enumerable:!1,configurable:!0}),o.setGlobal=function(){return this.global},i.destroy=function(){var e=this.container;this.clear(),this.off(),a.removeEvent(e,"blur",this.blur),a.removeEvent(e,"keydown",this.keydownEvent),a.removeEvent(e,"keyup",this.keyupEvent)},i.keydown=function(e,t){return this.addEvent("keydown",e,t)},i.offKeydown=function(e,t){return this.removeEvent("keydown",e,t)},i.offKeyup=function(e,t){return this.removeEvent("keyup",e,t)},i.keyup=function(e,t){return this.addEvent("keyup",e,t)},i.addEvent=function(e,t,n){return a.isArray(t)?this.on(e+"."+y(t).join("."),n):a.isString(t)?this.on(e+"."+t,n):this.on(e,t),this},i.removeEvent=function(e,t,n){return a.isArray(t)?this.off(e+"."+y(t).join("."),n):a.isString(t)?this.off(e+"."+t,n):this.off(e,t),this},i.triggerEvent=function(e,t){this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey;var n=c(t.keyCode),r={key:n,isToggle:"ctrl"===n||"shift"===n||"meta"===n||"alt"===n,inputEvent:t,keyCode:t.keyCode,ctrlKey:t.ctrlKey,altKey:t.altKey,shiftKey:t.shiftKey,metaKey:t.metaKey};this.trigger(e,r),this.trigger(e+"."+n,r);var o=l(t,n);1<o.length&&this.trigger(e+"."+o.join("."),r)},o}(e);return d.getKey=c,d.getCombi=l,d}); | ||
//# sourceMappingURL=keycon.js.map |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/keycon.git | ||
version: 1.1.0 | ||
version: 1.1.1 | ||
*/ | ||
@@ -55,289 +55,424 @@ (function (global, factory) { | ||
/* | ||
Copyright (c) 2017 NAVER Corp. | ||
@egjs/component project is licensed under the MIT license | ||
Copyright (c) 2018 Daybrush | ||
@name: @daybrush/utils | ||
license: MIT | ||
author: Daybrush | ||
repository: https://github.com/daybrush/utils | ||
@version 1.0.0 | ||
*/ | ||
/** | ||
* get string "object" | ||
* @memberof Consts | ||
* @example | ||
import {OBJECT} from "@daybrush/utils"; | ||
@egjs/component JavaScript library | ||
https://naver.github.io/egjs-component | ||
console.log(OBJECT); // "object" | ||
*/ | ||
@version 2.1.2 | ||
var OBJECT = "object"; | ||
/** | ||
* get string "string" | ||
* @memberof Consts | ||
* @example | ||
import {STRING} from "@daybrush/utils"; | ||
console.log(STRING); // "string" | ||
*/ | ||
var STRING = "string"; | ||
/** | ||
* Copyright (c) 2015 NAVER Corp. | ||
* egjs projects are licensed under the MIT license | ||
*/ | ||
function isUndefined(value) { | ||
return typeof value === "undefined"; | ||
* Check the type that the value is object. | ||
* @memberof Utils | ||
* @param {string} value - Value to check the type | ||
* @return {} true if the type is correct, false otherwise | ||
* @example | ||
import {isObject} from "@daybrush/utils"; | ||
console.log(isObject({})); // true | ||
console.log(isObject(undefined)); // false | ||
console.log(isObject("")); // false | ||
console.log(isObject(null)); // false | ||
*/ | ||
function isObject(value) { | ||
return value && typeof value === OBJECT; | ||
} | ||
/** | ||
* A class used to manage events in a component | ||
* @ko 컴포넌트의 이벤트을 관리할 수 있게 하는 클래스 | ||
* @alias eg.Component | ||
*/ | ||
* Check the type that the value is isArray. | ||
* @memberof Utils | ||
* @param {string} value - Value to check the type | ||
* @return {} true if the type is correct, false otherwise | ||
* @example | ||
import {isArray} from "@daybrush/utils"; | ||
console.log(isArray([])); // true | ||
console.log(isArray({})); // false | ||
console.log(isArray(undefined)); // false | ||
console.log(isArray(null)); // false | ||
*/ | ||
var Component = | ||
/*#__PURE__*/ | ||
function () { | ||
var Component = | ||
/*#__PURE__*/ | ||
function () { | ||
/** | ||
* Version info string | ||
* @ko 버전정보 문자열 | ||
* @name VERSION | ||
* @static | ||
* @type {String} | ||
* @example | ||
* eg.Component.VERSION; // ex) 2.0.0 | ||
* @memberof eg.Component | ||
*/ | ||
function isArray(value) { | ||
return Array.isArray(value); | ||
} | ||
/** | ||
* Check the type that the value is string. | ||
* @memberof Utils | ||
* @param {string} value - Value to check the type | ||
* @return {} true if the type is correct, false otherwise | ||
* @example | ||
import {isString} from "@daybrush/utils"; | ||
/** | ||
* @support {"ie": "7+", "ch" : "latest", "ff" : "latest", "sf" : "latest", "edge" : "latest", "ios" : "7+", "an" : "2.1+ (except 3.x)"} | ||
*/ | ||
function Component() { | ||
this._eventHandler = {}; | ||
this.options = {}; | ||
} | ||
/** | ||
* Triggers a custom event. | ||
* @ko 커스텀 이벤트를 발생시킨다 | ||
* @param {String} eventName The name of the custom event to be triggered <ko>발생할 커스텀 이벤트의 이름</ko> | ||
* @param {Object} customEvent Event data to be sent when triggering a custom event <ko>커스텀 이벤트가 발생할 때 전달할 데이터</ko> | ||
* @return {Boolean} Indicates whether the event has occurred. If the stop() method is called by a custom event handler, it will return false and prevent the event from occurring. <a href="https://github.com/naver/egjs-component/wiki/How-to-make-Component-event-design%3F">Ref</a> <ko>이벤트 발생 여부. 커스텀 이벤트 핸들러에서 stop() 메서드를 호출하면 'false'를 반환하고 이벤트 발생을 중단한다. <a href="https://github.com/naver/egjs-component/wiki/How-to-make-Component-event-design%3F">참고</a></ko> | ||
* @example | ||
class Some extends eg.Component { | ||
some(){ | ||
if(this.trigger("beforeHi")){ // When event call to stop return false. | ||
this.trigger("hi");// fire hi event. | ||
} | ||
} | ||
} | ||
const some = new Some(); | ||
some.on("beforeHi", (e) => { | ||
if(condition){ | ||
e.stop(); // When event call to stop, `hi` event not call. | ||
} | ||
}); | ||
some.on("hi", (e) => { | ||
// `currentTarget` is component instance. | ||
console.log(some === e.currentTarget); // true | ||
}); | ||
// If you want to more know event design. You can see article. | ||
// https://github.com/naver/egjs-component/wiki/How-to-make-Component-event-design%3F | ||
*/ | ||
console.log(isString("1234")); // true | ||
console.log(isString(undefined)); // false | ||
console.log(isString(1)); // false | ||
console.log(isString(null)); // false | ||
*/ | ||
function isString(value) { | ||
return typeof value === STRING; | ||
} | ||
/** | ||
* Returns the index of the first element in the array that satisfies the provided testing function. | ||
* @function | ||
* @memberof CrossBrowser | ||
* @param - The array `findIndex` was called upon. | ||
* @param - A function to execute on each value in the array until the function returns true, indicating that the satisfying element was found. | ||
* @param - Returns defaultIndex if not found by the function. | ||
* @example | ||
import { findIndex } from "@daybrush/utils"; | ||
var _proto = Component.prototype; | ||
findIndex([{a: 1}, {a: 2}, {a: 3}, {a: 4}], ({ a }) => a === 2); // 1 | ||
*/ | ||
_proto.trigger = function trigger(eventName, customEvent) { | ||
if (customEvent === void 0) { | ||
customEvent = {}; | ||
} | ||
function findIndex(arr, callback, defaultIndex) { | ||
if (defaultIndex === void 0) { | ||
defaultIndex = -1; | ||
} | ||
var handlerList = this._eventHandler[eventName] || []; | ||
var hasHandlerList = handlerList.length > 0; | ||
var length = arr.length; | ||
if (!hasHandlerList) { | ||
return true; | ||
} // If detach method call in handler in first time then handler list calls. | ||
for (var i = 0; i < length; ++i) { | ||
if (callback(arr[i], i, arr)) { | ||
return i; | ||
} | ||
} | ||
return defaultIndex; | ||
} | ||
/** | ||
* Sets up a function that will be called whenever the specified event is delivered to the target | ||
* @memberof DOM | ||
* @param - event target | ||
* @param - A case-sensitive string representing the event type to listen for. | ||
* @param - The object which receives a notification (an object that implements the Event interface) when an event of the specified type occurs | ||
* @param - An options object that specifies characteristics about the event listener. The available options are: | ||
* @example | ||
import {addEvent} from "@daybrush/utils"; | ||
handlerList = handlerList.concat(); | ||
customEvent.eventType = eventName; | ||
var isCanceled = false; | ||
var arg = [customEvent]; | ||
var i = 0; | ||
addEvent(el, "click", e => { | ||
console.log(e); | ||
}); | ||
*/ | ||
customEvent.stop = function () { | ||
isCanceled = true; | ||
}; | ||
function addEvent(el, type, listener, options) { | ||
el.addEventListener(type, listener, options); | ||
} | ||
/** | ||
* removes from the EventTarget an event listener previously registered with EventTarget.addEventListener() | ||
* @memberof DOM | ||
* @param - event target | ||
* @param - A case-sensitive string representing the event type to listen for. | ||
* @param - The EventListener function of the event handler to remove from the event target. | ||
* @example | ||
import {addEvent, removeEvent} from "@daybrush/utils"; | ||
const listener = e => { | ||
console.log(e); | ||
}; | ||
addEvent(el, "click", listener); | ||
removeEvent(el, "click", listener); | ||
*/ | ||
customEvent.currentTarget = this; | ||
function removeEvent(el, type, listener) { | ||
el.removeEventListener(type, listener); | ||
} | ||
for (var _len = arguments.length, restParam = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
restParam[_key - 2] = arguments[_key]; | ||
} | ||
/* | ||
Copyright (c) 2019 Daybrush | ||
name: @scena/event-emitter | ||
license: MIT | ||
author: Daybrush | ||
repository: git+https://github.com/daybrush/gesture.git | ||
version: 1.0.0 | ||
*/ | ||
if (restParam.length >= 1) { | ||
arg = arg.concat(restParam); | ||
} | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
for (i = 0; handlerList[i]; i++) { | ||
handlerList[i].apply(this, arg); | ||
} | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
return !isCanceled; | ||
}; | ||
/** | ||
* Executed event just one time. | ||
* @ko 이벤트가 한번만 실행된다. | ||
* @param {eventName} eventName The name of the event to be attached <ko>등록할 이벤트의 이름</ko> | ||
* @param {Function} handlerToAttach The handler function of the event to be attached <ko>등록할 이벤트의 핸들러 함수</ko> | ||
* @return {eg.Component} An instance of a component itself<ko>컴포넌트 자신의 인스턴스</ko> | ||
* @example | ||
class Some extends eg.Component { | ||
hi() { | ||
alert("hi"); | ||
} | ||
thing() { | ||
this.once("hi", this.hi); | ||
} | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
var __assign = function () { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
var some = new Some(); | ||
some.thing(); | ||
some.trigger("hi"); | ||
// fire alert("hi"); | ||
some.trigger("hi"); | ||
// Nothing happens | ||
*/ | ||
return t; | ||
}; | ||
_proto.once = function once(eventName, handlerToAttach) { | ||
if (typeof eventName === "object" && isUndefined(handlerToAttach)) { | ||
var eventHash = eventName; | ||
var i; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __spreadArrays() { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (i in eventHash) { | ||
this.once(i, eventHash[i]); | ||
} | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; | ||
return this; | ||
} else if (typeof eventName === "string" && typeof handlerToAttach === "function") { | ||
var self = this; | ||
this.on(eventName, function listener() { | ||
for (var _len2 = arguments.length, arg = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
arg[_key2] = arguments[_key2]; | ||
} | ||
return r; | ||
} | ||
handlerToAttach.apply(self, arg); | ||
self.off(eventName, listener); | ||
}); | ||
} | ||
/** | ||
* Implement EventEmitter on object or component. | ||
*/ | ||
return this; | ||
}; | ||
/** | ||
* Checks whether an event has been attached to a component. | ||
* @ko 컴포넌트에 이벤트가 등록됐는지 확인한다. | ||
* @param {String} eventName The name of the event to be attached <ko>등록 여부를 확인할 이벤트의 이름</ko> | ||
* @return {Boolean} Indicates whether the event is attached. <ko>이벤트 등록 여부</ko> | ||
* @example | ||
class Some extends eg.Component { | ||
some() { | ||
this.hasOn("hi");// check hi event. | ||
} | ||
} | ||
*/ | ||
var EventEmitter = | ||
/*#__PURE__*/ | ||
function () { | ||
function EventEmitter() { | ||
this._events = {}; | ||
} | ||
/** | ||
* Add a listener to the registered event. | ||
* @param - Name of the event to be added | ||
* @param - listener function of the event to be added | ||
* @example | ||
* import EventEmitter from "@scena/event-emitter"; | ||
* cosnt emitter = new EventEmitter(); | ||
* | ||
* // Add listener in "a" event | ||
* emitter.on("a", () => { | ||
* }); | ||
* // Add listeners | ||
* emitter.on({ | ||
* a: () => {}, | ||
* b: () => {}, | ||
* }); | ||
*/ | ||
_proto.hasOn = function hasOn(eventName) { | ||
return !!this._eventHandler[eventName]; | ||
}; | ||
/** | ||
* Attaches an event to a component. | ||
* @ko 컴포넌트에 이벤트를 등록한다. | ||
* @param {eventName} eventName The name of the event to be attached <ko>등록할 이벤트의 이름</ko> | ||
* @param {Function} handlerToAttach The handler function of the event to be attached <ko>등록할 이벤트의 핸들러 함수</ko> | ||
* @return {eg.Component} An instance of a component itself<ko>컴포넌트 자신의 인스턴스</ko> | ||
* @example | ||
class Some extends eg.Component { | ||
hi() { | ||
console.log("hi"); | ||
} | ||
some() { | ||
this.on("hi",this.hi); //attach event | ||
} | ||
var __proto = EventEmitter.prototype; | ||
__proto.on = function (eventName, listener) { | ||
if (isObject(eventName)) { | ||
for (var name in eventName) { | ||
this.on(name, eventName[name]); | ||
} | ||
} else { | ||
this._addEvent(eventName, listener, {}); | ||
} | ||
*/ | ||
return this; | ||
}; | ||
/** | ||
* Remove listeners registered in the event target. | ||
* @param - Name of the event to be removed | ||
* @param - listener function of the event to be removed | ||
* @example | ||
* import EventEmitter from "@scena/event-emitter"; | ||
* cosnt emitter = new EventEmitter(); | ||
* | ||
* // Remove all listeners. | ||
* emitter.off(); | ||
* | ||
* // Remove all listeners in "A" event. | ||
* emitter.off("a"); | ||
* | ||
* | ||
* // Remove "listener" listener in "a" event. | ||
* emitter.off("a", listener); | ||
*/ | ||
_proto.on = function on(eventName, handlerToAttach) { | ||
if (typeof eventName === "object" && isUndefined(handlerToAttach)) { | ||
var eventHash = eventName; | ||
var name; | ||
for (name in eventHash) { | ||
this.on(name, eventHash[name]); | ||
} | ||
__proto.off = function (eventName, listener) { | ||
if (!eventName) { | ||
this._events = {}; | ||
} else if (isObject(eventName)) { | ||
for (var name in eventName) { | ||
this.off(name); | ||
} | ||
} else if (!listener) { | ||
this._events[eventName] = []; | ||
} else { | ||
var events = this._events[eventName]; | ||
return this; | ||
} else if (typeof eventName === "string" && typeof handlerToAttach === "function") { | ||
var handlerList = this._eventHandler[eventName]; | ||
if (events) { | ||
var index = findIndex(events, function (e) { | ||
return e.listener === listener; | ||
}); | ||
if (isUndefined(handlerList)) { | ||
this._eventHandler[eventName] = []; | ||
handlerList = this._eventHandler[eventName]; | ||
if (index > -1) { | ||
events.splice(index, 1); | ||
} | ||
handlerList.push(handlerToAttach); | ||
} | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Detaches an event from the component. | ||
* @ko 컴포넌트에 등록된 이벤트를 해제한다 | ||
* @param {eventName} eventName The name of the event to be detached <ko>해제할 이벤트의 이름</ko> | ||
* @param {Function} handlerToDetach The handler function of the event to be detached <ko>해제할 이벤트의 핸들러 함수</ko> | ||
* @return {eg.Component} An instance of a component itself <ko>컴포넌트 자신의 인스턴스</ko> | ||
* @example | ||
class Some extends eg.Component { | ||
hi() { | ||
console.log("hi"); | ||
} | ||
some() { | ||
this.off("hi",this.hi); //detach event | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Add a disposable listener and Use promise to the registered event. | ||
* @param - Name of the event to be added | ||
* @param - disposable listener function of the event to be added | ||
* @example | ||
* import EventEmitter from "@scena/event-emitter"; | ||
* cosnt emitter = new EventEmitter(); | ||
* | ||
* // Add a disposable listener in "a" event | ||
* emitter.once("a", () => { | ||
* }); | ||
* | ||
* // Use Promise | ||
* emitter.once("a").then(e => { | ||
* }); | ||
*/ | ||
__proto.once = function (eventName, listener) { | ||
var _this = this; | ||
if (listener) { | ||
this._addEvent(eventName, listener, { | ||
once: true | ||
}); | ||
} | ||
*/ | ||
return new Promise(function (resolve) { | ||
_this._addEvent(eventName, resolve, { | ||
once: true | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Fires an event to call listeners. | ||
* @param - Event name | ||
* @param - Event parameter | ||
* @return If false, stop the event. | ||
* @example | ||
* | ||
* import EventEmitter from "@scena/event-emitter"; | ||
* | ||
* | ||
* const emitter = new EventEmitter(); | ||
* | ||
* emitter.on("a", e => { | ||
* }); | ||
* | ||
* | ||
* emitter.emit("a", { | ||
* a: 1, | ||
* }); | ||
*/ | ||
_proto.off = function off(eventName, handlerToDetach) { | ||
// All event detach. | ||
if (isUndefined(eventName)) { | ||
this._eventHandler = {}; | ||
return this; | ||
} // All handler of specific event detach. | ||
__proto.emit = function (eventName, param) { | ||
var _this = this; | ||
if (isUndefined(handlerToDetach)) { | ||
if (typeof eventName === "string") { | ||
this._eventHandler[eventName] = undefined; | ||
return this; | ||
} else { | ||
var eventHash = eventName; | ||
var name; | ||
if (param === void 0) { | ||
param = {}; | ||
} | ||
for (name in eventHash) { | ||
this.off(name, eventHash[name]); | ||
} | ||
var events = this._events[eventName]; | ||
return this; | ||
} | ||
} // The handler of specific event detach. | ||
if (!eventName || !events) { | ||
return true; | ||
} | ||
var isStop = false; | ||
param.eventType = eventName; | ||
var handlerList = this._eventHandler[eventName]; | ||
param.stop = function () { | ||
isStop = true; | ||
}; | ||
if (handlerList) { | ||
var k; | ||
var handlerFunction; | ||
param.currentTarget = this; | ||
for (k = 0; (handlerFunction = handlerList[k]) !== undefined; k++) { | ||
if (handlerFunction === handlerToDetach) { | ||
handlerList = handlerList.splice(k, 1); | ||
break; | ||
} | ||
} | ||
__spreadArrays(events).forEach(function (info) { | ||
info.listener(param); | ||
if (info.once) { | ||
_this.off(eventName, info.listener); | ||
} | ||
}); | ||
return this; | ||
}; | ||
return isStop; | ||
}; | ||
/** | ||
* Fires an event to call listeners. | ||
* @param - Event name | ||
* @param - Event parameter | ||
* @return If false, stop the event. | ||
* @example | ||
* | ||
* import EventEmitter from "@scena/event-emitter"; | ||
* | ||
* | ||
* const emitter = new EventEmitter(); | ||
* | ||
* emitter.on("a", e => { | ||
* }); | ||
* | ||
* | ||
* emitter.emit("a", { | ||
* a: 1, | ||
* }); | ||
*/ | ||
return Component; | ||
}(); | ||
/** | ||
* Fires an event to call listeners. | ||
* @param - Event name | ||
* @param - Event parameter | ||
* @return If false, stop the event. | ||
* @example | ||
* | ||
* import EventEmitter from "@scena/event-emitter"; | ||
* | ||
* | ||
* const emitter = new EventEmitter(); | ||
* | ||
* emitter.on("a", e => { | ||
* }); | ||
* | ||
* // emit | ||
* emitter.trigger("a", { | ||
* a: 1, | ||
* }); | ||
*/ | ||
Component.VERSION = "2.1.2"; | ||
return Component; | ||
__proto.trigger = function (eventName, param) { | ||
if (param === void 0) { | ||
param = {}; | ||
} | ||
return this.emit(eventName, param); | ||
}; | ||
__proto._addEvent = function (eventName, listener, options) { | ||
var events = this._events; | ||
events[eventName] = events[eventName] || []; | ||
var listeners = events[eventName]; | ||
listeners.push(__assign({ | ||
listener: listener | ||
}, options)); | ||
}; | ||
return EventEmitter; | ||
}(); | ||
@@ -534,91 +669,2 @@ | ||
/* | ||
Copyright (c) 2018 Daybrush | ||
@name: @daybrush/utils | ||
license: MIT | ||
author: Daybrush | ||
repository: https://github.com/daybrush/utils | ||
@version 1.0.0 | ||
*/ | ||
/** | ||
* get string "string" | ||
* @memberof Consts | ||
* @example | ||
import {STRING} from "@daybrush/utils"; | ||
console.log(STRING); // "string" | ||
*/ | ||
var STRING = "string"; | ||
/** | ||
* Check the type that the value is isArray. | ||
* @memberof Utils | ||
* @param {string} value - Value to check the type | ||
* @return {} true if the type is correct, false otherwise | ||
* @example | ||
import {isArray} from "@daybrush/utils"; | ||
console.log(isArray([])); // true | ||
console.log(isArray({})); // false | ||
console.log(isArray(undefined)); // false | ||
console.log(isArray(null)); // false | ||
*/ | ||
function isArray(value) { | ||
return Array.isArray(value); | ||
} | ||
/** | ||
* Check the type that the value is string. | ||
* @memberof Utils | ||
* @param {string} value - Value to check the type | ||
* @return {} true if the type is correct, false otherwise | ||
* @example | ||
import {isString} from "@daybrush/utils"; | ||
console.log(isString("1234")); // true | ||
console.log(isString(undefined)); // false | ||
console.log(isString(1)); // false | ||
console.log(isString(null)); // false | ||
*/ | ||
function isString(value) { | ||
return typeof value === STRING; | ||
} | ||
/** | ||
* Sets up a function that will be called whenever the specified event is delivered to the target | ||
* @memberof DOM | ||
* @param - event target | ||
* @param - A case-sensitive string representing the event type to listen for. | ||
* @param - The object which receives a notification (an object that implements the Event interface) when an event of the specified type occurs | ||
* @param - An options object that specifies characteristics about the event listener. The available options are: | ||
* @example | ||
import {addEvent} from "@daybrush/utils"; | ||
addEvent(el, "click", e => { | ||
console.log(e); | ||
}); | ||
*/ | ||
function addEvent(el, type, listener, options) { | ||
el.addEventListener(type, listener, options); | ||
} | ||
/** | ||
* removes from the EventTarget an event listener previously registered with EventTarget.addEventListener() | ||
* @memberof DOM | ||
* @param - event target | ||
* @param - A case-sensitive string representing the event type to listen for. | ||
* @param - The EventListener function of the event handler to remove from the event target. | ||
* @example | ||
import {addEvent, removeEvent} from "@daybrush/utils"; | ||
const listener = e => { | ||
console.log(e); | ||
}; | ||
addEvent(el, "click", listener); | ||
removeEvent(el, "click", listener); | ||
*/ | ||
function removeEvent(el, type, listener) { | ||
el.removeEventListener(type, listener); | ||
} | ||
var codeData = { | ||
@@ -856,3 +902,3 @@ "+": "plus", | ||
return KeyController; | ||
}(Component); | ||
}(EventEmitter); | ||
@@ -859,0 +905,0 @@ KeyController.getKey = getKey; |
@@ -7,5 +7,5 @@ /* | ||
repository: git+https://github.com/daybrush/keycon.git | ||
version: 1.1.0 | ||
version: 1.1.1 | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).keycon=t()}(this,function(){"use strict";var a=function(e,t){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function f(e){return void 0===e}var e=function(){var e=function(){function e(){this._eventHandler={},this.options={}}var t=e.prototype;return t.trigger=function(e,t){void 0===t&&(t={});var n=this._eventHandler[e]||[];if(!(0<n.length))return!0;n=n.concat(),t.eventType=e;var r=!1,o=[t],i=0;t.stop=function(){r=!0},t.currentTarget=this;for(var a=arguments.length,f=new Array(2<a?a-2:0),u=2;u<a;u++)f[u-2]=arguments[u];for(1<=f.length&&(o=o.concat(f)),i=0;n[i];i++)n[i].apply(this,o);return!r},t.once=function(o,i){if("object"==typeof o&&f(i)){var e,t=o;for(e in t)this.once(e,t[e]);return this}var a;return"string"==typeof o&&"function"==typeof i&&(a=this).on(o,function e(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];i.apply(a,n),a.off(o,e)}),this},t.hasOn=function(e){return!!this._eventHandler[e]},t.on=function(e,t){if("object"==typeof e&&f(t)){var n,r=e;for(n in r)this.on(n,r[n]);return this}var o;return"string"==typeof e&&"function"==typeof t&&(f(o=this._eventHandler[e])&&(this._eventHandler[e]=[],o=this._eventHandler[e]),o.push(t)),this},t.off=function(e,t){if(f(e))return this._eventHandler={},this;if(f(t)){if("string"==typeof e)return this._eventHandler[e]=void 0,this;var n,r=e;for(n in r)this.off(n,r[n]);return this}var o=this._eventHandler[e];if(o)for(var i,a=0;void 0!==(i=o[a]);a++)if(i===t){o=o.splice(a,1);break}return this},e}();return e.VERSION="2.1.2",e}();var t,n=(function(e,t){function n(e){var t;if(!e||"object"!=typeof e||(t=e.which||e.keyCode||e.charCode)&&(e=t),"number"==typeof e)return a[e];var n=String(e),r=o[n.toLowerCase()];return r||((r=i[n.toLowerCase()])?r:1===n.length?n.charCodeAt(0):void 0)}n.isEventKey=function(e,t){if(e&&"object"==typeof e){var n=e.which||e.keyCode||e.charCode;if(null==n)return!1;if("string"==typeof t){var r=o[t.toLowerCase()];if(r)return r===n;if(r=i[t.toLowerCase()])return r===n}else if("number"==typeof t)return t===n;return!1}};for(var o=(t=e.exports=n).code=t.codes={backspace:8,tab:9,enter:13,shift:16,ctrl:17,alt:18,"pause/break":19,"caps lock":20,esc:27,space:32,"page up":33,"page down":34,end:35,home:36,left:37,up:38,right:39,down:40,insert:45,delete:46,command:91,"left command":91,"right command":93,"numpad *":106,"numpad +":107,"numpad -":109,"numpad .":110,"numpad /":111,"num lock":144,"scroll lock":145,"my computer":182,"my calculator":183,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222},i=t.aliases={windows:91,"⇧":16,"⌥":18,"⌃":17,"⌘":91,ctl:17,control:17,option:18,pause:19,break:19,caps:20,return:13,escape:27,spc:32,spacebar:32,pgup:33,pgdn:34,ins:45,del:46,cmd:91},r=97;r<123;r++)o[String.fromCharCode(r)]=r-32;for(var r=48;r<58;r++)o[r-48]=r;for(r=1;r<13;r++)o["f"+r]=r+111;for(r=0;r<10;r++)o["numpad "+r]=r+96;var a=t.names=t.title={};for(r in o)a[o[r]]=r;for(var f in i)o[f]=i[f]}(t={exports:{}},t.exports),t.exports),r=(n.code,n.codes,n.aliases,n.names);n.title;function u(e){return Array.isArray(e)}function s(e){return"string"==typeof e}function c(e,t,n,r){e.addEventListener(t,n,r)}function l(e,t,n){e.removeEventListener(t,n)}var y,o={"+":"plus","left command":"meta","right command":"meta"},i={shift:1,ctrl:2,alt:3,meta:4};function h(e){var t=r[e]||"";for(var n in o)t=t.replace(n,o[n]);return t.replace(/\s/g,"")}function p(e,t){void 0===t&&(t=h(e.keyCode));var n,r=[(n=e).shiftKey&&"shift",n.ctrlKey&&"ctrl",n.altKey&&"alt",n.metaKey&&"meta"].filter(Boolean);return-1===r.indexOf(t)&&r.push(t),r.filter(Boolean)}function d(e){var t=e.slice();return t.sort(function(e,t){return(i[e]||5)-(i[t]||5)}),t}var v=function(n){function e(){this.constructor=t}var t,r;function o(e){void 0===e&&(e=window);var t=n.call(this)||this;return t.container=e,t.ctrlKey=!1,t.altKey=!1,t.shiftKey=!1,t.metaKey=!1,t.clear=function(){return t.ctrlKey=!1,t.altKey=!1,t.shiftKey=!1,t.metaKey=!1,t},t.keydownEvent=function(e){t.triggerEvent("keydown",e)},t.keyupEvent=function(e){t.triggerEvent("keyup",e)},t.blur=function(){t.clear(),t.trigger("blur")},c(e,"blur",t.blur),c(e,"keydown",t.keydownEvent),c(e,"keyup",t.keyupEvent),t}a(t=o,r=n),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e);var i=o.prototype;return Object.defineProperty(o,"global",{get:function(){return y=y||new o},enumerable:!1,configurable:!0}),o.setGlobal=function(){return this.global},i.destroy=function(){var e=this.container;this.clear(),this.off(),l(e,"blur",this.blur),l(e,"keydown",this.keydownEvent),l(e,"keyup",this.keyupEvent)},i.keydown=function(e,t){return this.addEvent("keydown",e,t)},i.offKeydown=function(e,t){return this.removeEvent("keydown",e,t)},i.offKeyup=function(e,t){return this.removeEvent("keyup",e,t)},i.keyup=function(e,t){return this.addEvent("keyup",e,t)},i.addEvent=function(e,t,n){return u(t)?this.on(e+"."+d(t).join("."),n):s(t)?this.on(e+"."+t,n):this.on(e,t),this},i.removeEvent=function(e,t,n){return u(t)?this.off(e+"."+d(t).join("."),n):s(t)?this.off(e+"."+t,n):this.off(e,t),this},i.triggerEvent=function(e,t){this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey;var n=h(t.keyCode),r={key:n,isToggle:"ctrl"===n||"shift"===n||"meta"===n||"alt"===n,inputEvent:t,keyCode:t.keyCode,ctrlKey:t.ctrlKey,altKey:t.altKey,shiftKey:t.shiftKey,metaKey:t.metaKey};this.trigger(e,r),this.trigger(e+"."+n,r);var o=p(t,n);1<o.length&&this.trigger(e+"."+o.join("."),r)},o}(e);return v.getKey=h,v.getCombi=p,v}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).keycon=t()}(this,function(){"use strict";var a=function(e,t){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function i(e){return e&&"object"==typeof e}function u(e){return Array.isArray(e)}function f(e){return"string"==typeof e}function s(e,t,n,r){e.addEventListener(t,n,r)}function c(e,t,n){e.removeEventListener(t,n)}var o=function(){return(o=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};var e=function(){function e(){this._events={}}var t=e.prototype;return t.on=function(e,t){if(i(e))for(var n in e)this.on(n,e[n]);else this._addEvent(e,t,{});return this},t.off=function(e,t){if(e)if(i(e))for(var n in e)this.off(n);else{var r,o;t?!(r=this._events[e])||-1<(o=function(e,t,n){void 0===n&&(n=-1);for(var r=e.length,o=0;o<r;++o)if(t(e[o],o,e))return o;return n}(r,function(e){return e.listener===t}))&&r.splice(o,1):this._events[e]=[]}else this._events={};return this},t.once=function(t,e){var n=this;return e&&this._addEvent(t,e,{once:!0}),new Promise(function(e){n._addEvent(t,e,{once:!0})})},t.emit=function(t,n){var r=this;void 0===n&&(n={});var e=this._events[t];if(!t||!e)return!0;var o=!1;return n.eventType=t,n.stop=function(){o=!0},n.currentTarget=this,function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var r=Array(e),o=0,t=0;t<n;t++)for(var i=arguments[t],a=0,u=i.length;a<u;a++,o++)r[o]=i[a];return r}(e).forEach(function(e){e.listener(n),e.once&&r.off(t,e.listener)}),o},t.trigger=function(e,t){return void 0===t&&(t={}),this.emit(e,t)},t._addEvent=function(e,t,n){var r=this._events;r[e]=r[e]||[],r[e].push(o({listener:t},n))},e}();var t,l,n=(function(e,t){function n(e){var t;if(!e||"object"!=typeof e||(t=e.which||e.keyCode||e.charCode)&&(e=t),"number"==typeof e)return a[e];var n=String(e),r=o[n.toLowerCase()];return r||((r=i[n.toLowerCase()])?r:1===n.length?n.charCodeAt(0):void 0)}n.isEventKey=function(e,t){if(e&&"object"==typeof e){var n=e.which||e.keyCode||e.charCode;if(null==n)return!1;if("string"==typeof t){var r=o[t.toLowerCase()];if(r)return r===n;if(r=i[t.toLowerCase()])return r===n}else if("number"==typeof t)return t===n;return!1}};for(var o=(t=e.exports=n).code=t.codes={backspace:8,tab:9,enter:13,shift:16,ctrl:17,alt:18,"pause/break":19,"caps lock":20,esc:27,space:32,"page up":33,"page down":34,end:35,home:36,left:37,up:38,right:39,down:40,insert:45,delete:46,command:91,"left command":91,"right command":93,"numpad *":106,"numpad +":107,"numpad -":109,"numpad .":110,"numpad /":111,"num lock":144,"scroll lock":145,"my computer":182,"my calculator":183,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222},i=t.aliases={windows:91,"⇧":16,"⌥":18,"⌃":17,"⌘":91,ctl:17,control:17,option:18,pause:19,break:19,caps:20,return:13,escape:27,spc:32,spacebar:32,pgup:33,pgdn:34,ins:45,del:46,cmd:91},r=97;r<123;r++)o[String.fromCharCode(r)]=r-32;for(var r=48;r<58;r++)o[r-48]=r;for(r=1;r<13;r++)o["f"+r]=r+111;for(r=0;r<10;r++)o["numpad "+r]=r+96;var a=t.names=t.title={};for(r in o)a[o[r]]=r;for(var u in i)o[u]=i[u]}(t={exports:{}},t.exports),t.exports),r=(n.code,n.codes,n.aliases,n.names),y=(n.title,{"+":"plus","left command":"meta","right command":"meta"}),h={shift:1,ctrl:2,alt:3,meta:4};function p(e){var t=r[e]||"";for(var n in y)t=t.replace(n,y[n]);return t.replace(/\s/g,"")}function v(e,t){void 0===t&&(t=p(e.keyCode));var n,r=[(n=e).shiftKey&&"shift",n.ctrlKey&&"ctrl",n.altKey&&"alt",n.metaKey&&"meta"].filter(Boolean);return-1===r.indexOf(t)&&r.push(t),r.filter(Boolean)}function d(e){var t=e.slice();return t.sort(function(e,t){return(h[e]||5)-(h[t]||5)}),t}var m=function(n){function e(){this.constructor=t}var t,r;function o(e){void 0===e&&(e=window);var t=n.call(this)||this;return t.container=e,t.ctrlKey=!1,t.altKey=!1,t.shiftKey=!1,t.metaKey=!1,t.clear=function(){return t.ctrlKey=!1,t.altKey=!1,t.shiftKey=!1,t.metaKey=!1,t},t.keydownEvent=function(e){t.triggerEvent("keydown",e)},t.keyupEvent=function(e){t.triggerEvent("keyup",e)},t.blur=function(){t.clear(),t.trigger("blur")},s(e,"blur",t.blur),s(e,"keydown",t.keydownEvent),s(e,"keyup",t.keyupEvent),t}a(t=o,r=n),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e);var i=o.prototype;return Object.defineProperty(o,"global",{get:function(){return l=l||new o},enumerable:!1,configurable:!0}),o.setGlobal=function(){return this.global},i.destroy=function(){var e=this.container;this.clear(),this.off(),c(e,"blur",this.blur),c(e,"keydown",this.keydownEvent),c(e,"keyup",this.keyupEvent)},i.keydown=function(e,t){return this.addEvent("keydown",e,t)},i.offKeydown=function(e,t){return this.removeEvent("keydown",e,t)},i.offKeyup=function(e,t){return this.removeEvent("keyup",e,t)},i.keyup=function(e,t){return this.addEvent("keyup",e,t)},i.addEvent=function(e,t,n){return u(t)?this.on(e+"."+d(t).join("."),n):f(t)?this.on(e+"."+t,n):this.on(e,t),this},i.removeEvent=function(e,t,n){return u(t)?this.off(e+"."+d(t).join("."),n):f(t)?this.off(e+"."+t,n):this.off(e,t),this},i.triggerEvent=function(e,t){this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey;var n=p(t.keyCode),r={key:n,isToggle:"ctrl"===n||"shift"===n||"meta"===n||"alt"===n,inputEvent:t,keyCode:t.keyCode,ctrlKey:t.ctrlKey,altKey:t.altKey,shiftKey:t.shiftKey,metaKey:t.metaKey};this.trigger(e,r),this.trigger(e+"."+n,r);var o=v(t,n);1<o.length&&this.trigger(e+"."+o.join("."),r)},o}(e);return m.getKey=p,m.getCombi=v,m}); | ||
//# sourceMappingURL=keycon.pkgd.min.js.map |
{ | ||
"name": "keycon", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Keyboard Controller", | ||
@@ -36,3 +36,3 @@ "main": "./dist/keycon.js", | ||
"@daybrush/utils": "^1.0.0", | ||
"@egjs/component": "^2.1.2", | ||
"@scena/event-emitter": "^1.0.0", | ||
"keycode": "^2.2.0" | ||
@@ -39,0 +39,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
import Component from "@egjs/component"; | ||
import EventEmitter, { EmitterParam, TargetParam } from "@scena/event-emitter"; | ||
import { names } from "keycode"; | ||
@@ -62,3 +62,3 @@ import { isString, isArray, addEvent, removeEvent } from "@daybrush/utils"; | ||
*/ | ||
export interface KeyControllerEvent { | ||
export interface KeyControllerEvent extends EmitterParam { | ||
inputEvent: KeyboardEvent; | ||
@@ -77,3 +77,6 @@ isToggle: boolean; | ||
*/ | ||
class KeyController extends Component { | ||
class KeyController extends EventEmitter<{ | ||
blur: {}, | ||
[key: string]: object, | ||
}> { | ||
/** | ||
@@ -213,3 +216,3 @@ */ | ||
|| key === "alt"; | ||
const param: KeyControllerEvent = { | ||
const param: TargetParam<KeyControllerEvent> = { | ||
key, | ||
@@ -216,0 +219,0 @@ isToggle, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118811
2037
+ Added@scena/event-emitter@^1.0.0
+ Added@scena/event-emitter@1.0.5(transitive)
- Removed@egjs/component@^2.1.2
- Removed@egjs/component@2.2.2(transitive)