Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

keycon

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keycon - npm Package Compare versions

Comparing version 1.3.1 to 1.3.2

2

declaration/KeyController.d.ts

@@ -29,3 +29,3 @@ import EventEmitter, { EmitterParam } from "@scena/event-emitter";

}> {
private container;
container: Window | Document | HTMLElement;
static get global(): KeyController;

@@ -32,0 +32,0 @@ static setGlobal(): KeyController;

import { ReactiveAdapter, Ref, ReactiveObject, Observer } from "@cfcs/core";
import KeyController, { KeyconEvents } from "./KeyController";
export interface ReactiveKeyConData {
ref?: Ref<HTMLElement>;
ref?: Ref<HTMLElement | null | undefined>;
keys: string | string[];

@@ -6,0 +6,0 @@ }

@@ -7,3 +7,3 @@ /*

repository: git+https://github.com/daybrush/keycon.git
version: 1.3.1
version: 1.3.2
*/

@@ -29,4 +29,4 @@ 'use strict';

***************************************************************************** */
/* global Reflect, Promise */
/* global Reflect, Promise */
var extendStatics = function (d, b) {

@@ -40,14 +40,10 @@ extendStatics = Object.setPrototypeOf || {

};
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());

@@ -259,10 +255,7 @@ }

*/
function getKey(keyCode, keyName) {
var key = (keycode_4[keyCode] || keyName || "").toLowerCase();
for (var name in codeData) {
key = key.replace(name, codeData[name]);
}
return key.replace(/\s/g, "");

@@ -273,3 +266,2 @@ }

*/
function getCombi(e, key) {

@@ -279,3 +271,2 @@ if (key === void 0) {

}
var keys = getModifierCombi(e);

@@ -288,3 +279,2 @@ keys.indexOf(key) === -1 && keys.push(key);

*/
function getModifierCombi(e) {

@@ -294,3 +284,2 @@ var keys = [e.shiftKey && "shift", e.ctrlKey && "ctrl", e.altKey && "alt", e.metaKey && "meta"];

}
function getArrangeCombi(keys) {

@@ -305,10 +294,6 @@ var arrangeKeys = keys.slice();

}
var globalKeyController;
/**
*/
var KeyController =
/*#__PURE__*/
function (_super) {
var KeyController = /*#__PURE__*/function (_super) {
__extends(KeyController, _super);

@@ -318,4 +303,2 @@ /**

*/
function KeyController(container) {

@@ -325,13 +308,9 @@ if (container === void 0) {

}
var _this = _super.call(this) || this;
_this.container = container;
/**
*/
_this.ctrlKey = false;
/**
*/
_this.altKey = false;

@@ -341,3 +320,2 @@ /**

*/
_this.shiftKey = false;

@@ -347,5 +325,3 @@ /**

*/
_this.metaKey = false;
_this.clear = function () {

@@ -358,17 +334,12 @@ _this.ctrlKey = false;

};
_this.keydownEvent = function (e) {
_this.triggerEvent("keydown", e);
};
_this.keyupEvent = function (e) {
_this.triggerEvent("keyup", e);
};
_this.blur = function () {
_this.clear();
_this.trigger("blur");
};
utils.addEvent(container, "blur", _this.blur);

@@ -379,3 +350,2 @@ utils.addEvent(container, "keydown", _this.keydownEvent);

}
var __proto = KeyController.prototype;

@@ -391,3 +361,2 @@ Object.defineProperty(KeyController, "global", {

});
KeyController.setGlobal = function () {

@@ -399,4 +368,2 @@ return this.global;

*/
__proto.destroy = function () {

@@ -413,4 +380,2 @@ var container = this.container;

*/
__proto.keydown = function (comb, callback) {

@@ -422,4 +387,2 @@ return this.addEvent("keydown", comb, callback);

*/
__proto.offKeydown = function (comb, callback) {

@@ -431,4 +394,2 @@ return this.removeEvent("keydown", comb, callback);

*/
__proto.offKeyup = function (comb, callback) {

@@ -440,8 +401,5 @@ return this.removeEvent("keyup", comb, callback);

*/
__proto.keyup = function (comb, callback) {
return this.addEvent("keyup", comb, callback);
};
__proto.addEvent = function (type, comb, callback) {

@@ -455,6 +413,4 @@ if (utils.isArray(comb)) {

}
return this;
};
__proto.removeEvent = function (type, comb, callback) {

@@ -468,6 +424,4 @@ if (utils.isArray(comb)) {

}
return this;
};
__proto.triggerEvent = function (type, e) {

@@ -495,3 +449,2 @@ this.ctrlKey = e.ctrlKey;

};
return KeyController;

@@ -1121,2 +1074,3 @@ }(EventEmitter);

var instanceMap;
var REACTIVE = {

@@ -1129,5 +1083,17 @@ events: ["keydown", "keyup", "blur"],

var _a, _b;
if (!instanceMap) {
instanceMap = new Map();
}
var element = (_b = (_a = data.ref) === null || _a === void 0 ? void 0 : _a.current) !== null && _b !== void 0 ? _b : window;
var info = instanceMap.get(element);
if (!info) {
info = {
inst: new KeyController(element),
count: 0
};
instanceMap.set(element, info);
}
++info.count;
var keycon = info.inst;
var keys = data.keys;
var keycon = new KeyController(((_a = data.ref) === null || _a === void 0 ? void 0 : _a.current) || ((_b = data.ref) === null || _b === void 0 ? void 0 : _b.value) || window);
var isKeydown = observe(false);

@@ -1152,8 +1118,14 @@ keycon.keydown(keys, function () {

},
destroy: function (inst) {
inst.destroy();
destroy: function (_a) {
var inst = _a.inst;
var element = inst.container;
var info = instanceMap.get(element);
--info.count;
if (!info.count) {
inst.destroy();
instanceMap.delete(element);
}
},
on: function (inst, name, callback) {
var keycon = inst.inst;
if (name === "keydown") {

@@ -1169,3 +1141,2 @@ keycon.keydown(inst.keys, callback);

var keycon = inst.inst;
if (name === "keydown") {

@@ -1195,3 +1166,2 @@ keycon.offKeydown(inst.keys, callback);

}
module.exports = KeyController;

@@ -1198,0 +1168,0 @@

@@ -7,3 +7,3 @@ /*

repository: git+https://github.com/daybrush/keycon.git
version: 1.3.1
version: 1.3.2
*/

@@ -27,4 +27,4 @@ import EventEmitter from '@scena/event-emitter';

***************************************************************************** */
/* global Reflect, Promise */
/* global Reflect, Promise */
var extendStatics = function (d, b) {

@@ -38,14 +38,10 @@ extendStatics = Object.setPrototypeOf || {

};
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());

@@ -257,10 +253,7 @@ }

*/
function getKey(keyCode, keyName) {
var key = (keycode_4[keyCode] || keyName || "").toLowerCase();
for (var name in codeData) {
key = key.replace(name, codeData[name]);
}
return key.replace(/\s/g, "");

@@ -271,3 +264,2 @@ }

*/
function getCombi(e, key) {

@@ -277,3 +269,2 @@ if (key === void 0) {

}
var keys = getModifierCombi(e);

@@ -286,3 +277,2 @@ keys.indexOf(key) === -1 && keys.push(key);

*/
function getModifierCombi(e) {

@@ -292,3 +282,2 @@ var keys = [e.shiftKey && "shift", e.ctrlKey && "ctrl", e.altKey && "alt", e.metaKey && "meta"];

}
function getArrangeCombi(keys) {

@@ -303,10 +292,6 @@ var arrangeKeys = keys.slice();

}
var globalKeyController;
/**
*/
var KeyController =
/*#__PURE__*/
function (_super) {
var KeyController = /*#__PURE__*/function (_super) {
__extends(KeyController, _super);

@@ -316,4 +301,2 @@ /**

*/
function KeyController(container) {

@@ -323,13 +306,9 @@ if (container === void 0) {

}
var _this = _super.call(this) || this;
_this.container = container;
/**
*/
_this.ctrlKey = false;
/**
*/
_this.altKey = false;

@@ -339,3 +318,2 @@ /**

*/
_this.shiftKey = false;

@@ -345,5 +323,3 @@ /**

*/
_this.metaKey = false;
_this.clear = function () {

@@ -356,17 +332,12 @@ _this.ctrlKey = false;

};
_this.keydownEvent = function (e) {
_this.triggerEvent("keydown", e);
};
_this.keyupEvent = function (e) {
_this.triggerEvent("keyup", e);
};
_this.blur = function () {
_this.clear();
_this.trigger("blur");
};
addEvent(container, "blur", _this.blur);

@@ -377,3 +348,2 @@ addEvent(container, "keydown", _this.keydownEvent);

}
var __proto = KeyController.prototype;

@@ -389,3 +359,2 @@ Object.defineProperty(KeyController, "global", {

});
KeyController.setGlobal = function () {

@@ -397,4 +366,2 @@ return this.global;

*/
__proto.destroy = function () {

@@ -411,4 +378,2 @@ var container = this.container;

*/
__proto.keydown = function (comb, callback) {

@@ -420,4 +385,2 @@ return this.addEvent("keydown", comb, callback);

*/
__proto.offKeydown = function (comb, callback) {

@@ -429,4 +392,2 @@ return this.removeEvent("keydown", comb, callback);

*/
__proto.offKeyup = function (comb, callback) {

@@ -438,8 +399,5 @@ return this.removeEvent("keyup", comb, callback);

*/
__proto.keyup = function (comb, callback) {
return this.addEvent("keyup", comb, callback);
};
__proto.addEvent = function (type, comb, callback) {

@@ -453,6 +411,4 @@ if (isArray(comb)) {

}
return this;
};
__proto.removeEvent = function (type, comb, callback) {

@@ -466,6 +422,4 @@ if (isArray(comb)) {

}
return this;
};
__proto.triggerEvent = function (type, e) {

@@ -493,3 +447,2 @@ this.ctrlKey = e.ctrlKey;

};
return KeyController;

@@ -1119,2 +1072,3 @@ }(EventEmitter);

var instanceMap;
var REACTIVE = {

@@ -1127,5 +1081,17 @@ events: ["keydown", "keyup", "blur"],

var _a, _b;
if (!instanceMap) {
instanceMap = new Map();
}
var element = (_b = (_a = data.ref) === null || _a === void 0 ? void 0 : _a.current) !== null && _b !== void 0 ? _b : window;
var info = instanceMap.get(element);
if (!info) {
info = {
inst: new KeyController(element),
count: 0
};
instanceMap.set(element, info);
}
++info.count;
var keycon = info.inst;
var keys = data.keys;
var keycon = new KeyController(((_a = data.ref) === null || _a === void 0 ? void 0 : _a.current) || ((_b = data.ref) === null || _b === void 0 ? void 0 : _b.value) || window);
var isKeydown = observe(false);

@@ -1150,8 +1116,14 @@ keycon.keydown(keys, function () {

},
destroy: function (inst) {
inst.destroy();
destroy: function (_a) {
var inst = _a.inst;
var element = inst.container;
var info = instanceMap.get(element);
--info.count;
if (!info.count) {
inst.destroy();
instanceMap.delete(element);
}
},
on: function (inst, name, callback) {
var keycon = inst.inst;
if (name === "keydown") {

@@ -1167,3 +1139,2 @@ keycon.keydown(inst.keys, callback);

var keycon = inst.inst;
if (name === "keydown") {

@@ -1170,0 +1141,0 @@ keycon.offKeydown(inst.keys, callback);

@@ -7,3 +7,3 @@ /*

repository: git+https://github.com/daybrush/keycon.git
version: 1.3.1
version: 1.3.2
*/

@@ -30,4 +30,4 @@ (function (global, factory) {

***************************************************************************** */
/* global Reflect, Promise */
/* global Reflect, Promise */
var extendStatics = function (d, b) {

@@ -41,14 +41,10 @@ extendStatics = Object.setPrototypeOf || {

};
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());

@@ -63,3 +59,3 @@ }

repository: https://github.com/daybrush/utils
@version 1.7.1
@version 1.10.0
*/

@@ -687,10 +683,7 @@ /**

*/
function getKey(keyCode, keyName) {
var key = (keycode_4[keyCode] || keyName || "").toLowerCase();
for (var name in codeData) {
key = key.replace(name, codeData[name]);
}
return key.replace(/\s/g, "");

@@ -701,3 +694,2 @@ }

*/
function getCombi(e, key) {

@@ -707,3 +699,2 @@ if (key === void 0) {

}
var keys = getModifierCombi(e);

@@ -716,3 +707,2 @@ keys.indexOf(key) === -1 && keys.push(key);

*/
function getModifierCombi(e) {

@@ -722,3 +712,2 @@ var keys = [e.shiftKey && "shift", e.ctrlKey && "ctrl", e.altKey && "alt", e.metaKey && "meta"];

}
function getArrangeCombi(keys) {

@@ -733,10 +722,6 @@ var arrangeKeys = keys.slice();

}
var globalKeyController;
/**
*/
var KeyController =
/*#__PURE__*/
function (_super) {
var KeyController = /*#__PURE__*/function (_super) {
__extends(KeyController, _super);

@@ -746,4 +731,2 @@ /**

*/
function KeyController(container) {

@@ -753,13 +736,9 @@ if (container === void 0) {

}
var _this = _super.call(this) || this;
_this.container = container;
/**
*/
_this.ctrlKey = false;
/**
*/
_this.altKey = false;

@@ -769,3 +748,2 @@ /**

*/
_this.shiftKey = false;

@@ -775,5 +753,3 @@ /**

*/
_this.metaKey = false;
_this.clear = function () {

@@ -786,17 +762,12 @@ _this.ctrlKey = false;

};
_this.keydownEvent = function (e) {
_this.triggerEvent("keydown", e);
};
_this.keyupEvent = function (e) {
_this.triggerEvent("keyup", e);
};
_this.blur = function () {
_this.clear();
_this.trigger("blur");
};
addEvent(container, "blur", _this.blur);

@@ -807,3 +778,2 @@ addEvent(container, "keydown", _this.keydownEvent);

}
var __proto = KeyController.prototype;

@@ -819,3 +789,2 @@ Object.defineProperty(KeyController, "global", {

});
KeyController.setGlobal = function () {

@@ -827,4 +796,2 @@ return this.global;

*/
__proto.destroy = function () {

@@ -841,4 +808,2 @@ var container = this.container;

*/
__proto.keydown = function (comb, callback) {

@@ -850,4 +815,2 @@ return this.addEvent("keydown", comb, callback);

*/
__proto.offKeydown = function (comb, callback) {

@@ -859,4 +822,2 @@ return this.removeEvent("keydown", comb, callback);

*/
__proto.offKeyup = function (comb, callback) {

@@ -868,8 +829,5 @@ return this.removeEvent("keyup", comb, callback);

*/
__proto.keyup = function (comb, callback) {
return this.addEvent("keyup", comb, callback);
};
__proto.addEvent = function (type, comb, callback) {

@@ -883,6 +841,4 @@ if (isArray(comb)) {

}
return this;
};
__proto.removeEvent = function (type, comb, callback) {

@@ -896,6 +852,4 @@ if (isArray(comb)) {

}
return this;
};
__proto.triggerEvent = function (type, e) {

@@ -923,3 +877,2 @@ this.ctrlKey = e.ctrlKey;

};
return KeyController;

@@ -1549,2 +1502,3 @@ }(EventEmitter);

var instanceMap;
var REACTIVE = {

@@ -1557,5 +1511,17 @@ events: ["keydown", "keyup", "blur"],

var _a, _b;
if (!instanceMap) {
instanceMap = new Map();
}
var element = (_b = (_a = data.ref) === null || _a === void 0 ? void 0 : _a.current) !== null && _b !== void 0 ? _b : window;
var info = instanceMap.get(element);
if (!info) {
info = {
inst: new KeyController(element),
count: 0
};
instanceMap.set(element, info);
}
++info.count;
var keycon = info.inst;
var keys = data.keys;
var keycon = new KeyController(((_a = data.ref) === null || _a === void 0 ? void 0 : _a.current) || ((_b = data.ref) === null || _b === void 0 ? void 0 : _b.value) || window);
var isKeydown = observe(false);

@@ -1580,8 +1546,14 @@ keycon.keydown(keys, function () {

},
destroy: function (inst) {
inst.destroy();
destroy: function (_a) {
var inst = _a.inst;
var element = inst.container;
var info = instanceMap.get(element);
--info.count;
if (!info.count) {
inst.destroy();
instanceMap.delete(element);
}
},
on: function (inst, name, callback) {
var keycon = inst.inst;
if (name === "keydown") {

@@ -1597,3 +1569,2 @@ keycon.keydown(inst.keys, callback);

var keycon = inst.inst;
if (name === "keydown") {

@@ -1600,0 +1571,0 @@ keycon.offKeydown(inst.keys, callback);

@@ -7,5 +7,5 @@ /*

repository: git+https://github.com/daybrush/keycon.git
version: 1.3.1
version: 1.3.2
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).keycon=e()}(this,function(){"use strict";var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};function u(t){return t&&"object"==typeof t}function c(t){return Array.isArray(t)}function f(t){return"string"==typeof t}function a(t,e,n,r){t.addEventListener(e,n,r)}function s(t,e,n,r){t.removeEventListener(e,n,r)}var o=function(){return(o=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};var t=function(){function t(){this._events={}}var e=t.prototype;return e.on=function(t,e){if(u(t))for(var n in t)this.on(n,t[n]);else this._addEvent(t,e,{});return this},e.off=function(t,e){if(t)if(u(t))for(var n in t)this.off(n);else{var r,o;e?(r=this._events[t])&&-1<(o=function(t,e,n){void 0===n&&(n=-1);for(var r=t.length,o=0;o<r;++o)if(e(t[o],o,t))return o;return n}(r,function(t){return t.listener===e}))&&r.splice(o,1):this._events[t]=[]}else this._events={};return this},e.once=function(e,t){var n=this;return t&&this._addEvent(e,t,{once:!0}),new Promise(function(t){n._addEvent(e,t,{once:!0})})},e.emit=function(e,n){var r=this,t=(void 0===n&&(n={}),this._events[e]);if(!e||!t)return!0;var o=!1;return n.eventType=e,n.stop=function(){o=!0},n.currentTarget=this,function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;for(var r=Array(t),o=0,e=0;e<n;e++)for(var i=arguments[e],u=0,c=i.length;u<c;u++,o++)r[o]=i[u];return r}(t).forEach(function(t){t.listener(n),t.once&&r.off(e,t.listener)}),!o},e.trigger=function(t,e){return this.emit(t,e=void 0===e?{}:e)},e._addEvent=function(t,e,n){var r=this._events;r[t]=r[t]||[],r[t].push(o({listener:e},n))},t}();(function(t,e){function n(t){if(!t||"object"!=typeof t||(e=t.which||t.keyCode||t.charCode)&&(t=e),"number"==typeof t)return c[t];var e=String(t),t=r[e.toLowerCase()];return t||((t=o[e.toLowerCase()])?t:1===e.length?e.charCodeAt(0):void 0)}n.isEventKey=function(t,e){if(t&&"object"==typeof t){t=t.which||t.keyCode||t.charCode;if(null!=t)if("string"==typeof e){var n=r[e.toLowerCase()];if(n)return n===t;if(n=o[e.toLowerCase()])return n===t}else if("number"==typeof e)return e===t;return!1}};for(var r=(e=t.exports=n).code=e.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},o=e.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},i=97;i<123;i++)r[String.fromCharCode(i)]=i-32;for(var i=48;i<58;i++)r[i-48]=i;for(i=1;i<13;i++)r["f"+i]=i+111;for(i=0;i<10;i++)r["numpad "+i]=i+96;var u,c=e.names=e.title={};for(i in r)c[r[i]]=i;for(u in o)r[u]=o[u]})(e={exports:{}},e.exports);var l,e=e.exports,y=(e.code,e.codes,e.aliases,e.names),h=(e.title,{"+":"plus","left command":"meta","right command":"meta"}),n={shift:1,ctrl:2,alt:3,meta:4};function d(t,e){var n,r=(y[t]||e||"").toLowerCase();for(n in h)r=r.replace(n,h[n]);return r.replace(/\s/g,"")}function v(t,e){void 0===e&&(e=d(t.keyCode,t.key));t=r(t);return-1===t.indexOf(e)&&t.push(e),t.filter(Boolean)}function r(t){return[t.shiftKey&&"shift",t.ctrlKey&&"ctrl",t.altKey&&"alt",t.metaKey&&"meta"].filter(Boolean)}function p(t){t=t.slice();return t.sort(function(t,e){return(n[t]||5)-(n[e]||5)}),t}var b=function(n){var t=o,e=n;if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}function o(t){void 0===t&&(t=window);var e=n.call(this)||this;return e.container=t,e.ctrlKey=!1,e.altKey=!1,e.shiftKey=!1,e.metaKey=!1,e.clear=function(){return e.ctrlKey=!1,e.altKey=!1,e.shiftKey=!1,e.metaKey=!1,e},e.keydownEvent=function(t){e.triggerEvent("keydown",t)},e.keyupEvent=function(t){e.triggerEvent("keyup",t)},e.blur=function(){e.clear(),e.trigger("blur")},a(t,"blur",e.blur),a(t,"keydown",e.keydownEvent),a(t,"keyup",e.keyupEvent),e}i(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r);e=o.prototype;return Object.defineProperty(o,"global",{get:function(){return l=l||new o},enumerable:!1,configurable:!0}),o.setGlobal=function(){return this.global},e.destroy=function(){var t=this.container;this.clear(),this.off(),s(t,"blur",this.blur),s(t,"keydown",this.keydownEvent),s(t,"keyup",this.keyupEvent)},e.keydown=function(t,e){return this.addEvent("keydown",t,e)},e.offKeydown=function(t,e){return this.removeEvent("keydown",t,e)},e.offKeyup=function(t,e){return this.removeEvent("keyup",t,e)},e.keyup=function(t,e){return this.addEvent("keyup",t,e)},e.addEvent=function(t,e,n){return c(e)?this.on("".concat(t,".").concat(p(e).join(".")),n):f(e)?this.on("".concat(t,".").concat(e),n):this.on(t,e),this},e.removeEvent=function(t,e,n){return c(e)?this.off("".concat(t,".").concat(p(e).join(".")),n):f(e)?this.off("".concat(t,".").concat(e),n):this.off(t,e),this},e.triggerEvent=function(t,e){this.ctrlKey=e.ctrlKey,this.shiftKey=e.shiftKey,this.altKey=e.altKey,this.metaKey=e.metaKey;var n=d(e.keyCode,e.key),r={key:n,isToggle:"ctrl"===n||"shift"===n||"meta"===n||"alt"===n,inputEvent:e,keyCode:e.keyCode,ctrlKey:e.ctrlKey,altKey:e.altKey,shiftKey:e.shiftKey,metaKey:e.metaKey},e=(this.trigger(t,r),this.trigger("".concat(t,".").concat(n),r),v(e,n));1<e.length&&this.trigger("".concat(t,".").concat(e.join(".")),r)},o}(t);function g(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return{value:(t=t&&r>=t.length?void 0:t)&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function m(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||0<e--)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u}(arguments[e]));return t}function k(t){return void 0===t}var w=function(){function t(t,e){var n,r;if(this._canceled=!1,e)try{for(var o=g(Object.keys(e)),i=o.next();!i.done;i=o.next()){var u=i.value;this[u]=e[u]}}catch(t){n={error:t}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}this.eventType=t}var e=t.prototype;return e.stop=function(){this._canceled=!0},e.isCanceled=function(){return this._canceled},t}(),_=function(){function t(){this._eventHandler={}}var e=t.prototype;return e.trigger=function(e){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];var r=e instanceof w?e.eventType:e,r=m(this._eventHandler[r]||[]);return r.length<=0||(e instanceof w?(e.currentTarget=this,r.forEach(function(t){t(e)})):r.forEach(function(t){t.apply(void 0,m(n))})),this},e.once=function(n,r){var o,i=this;if("object"==typeof n&&k(r)){var t,e=n;for(t in e)this.once(t,e[t])}else"string"==typeof n&&"function"==typeof r&&(o=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];r.apply(void 0,m(t)),i.off(n,o)},this.on(n,o));return this},e.hasOn=function(t){return!!this._eventHandler[t]},e.on=function(t,e){if("object"==typeof t&&k(e)){var n,r=t;for(n in r)this.on(n,r[n])}else{var o;"string"==typeof t&&"function"==typeof e&&(o=this._eventHandler[t],k(o)&&(this._eventHandler[t]=[],o=this._eventHandler[t]),o.push(e))}return this},e.off=function(t,e){var n,r;if(k(t))return this._eventHandler={},this;if(k(e)){if("string"==typeof t)return delete this._eventHandler[t],this;var o,i=t;for(o in i)this.off(o,i[o])}else{var u=this._eventHandler[t];if(u){var c=0;try{for(var f=g(u),a=f.next();!a.done;a=f.next()){if(a.value===e){u.splice(c,1),u.length<=0&&delete this._eventHandler[t];break}c++}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=f.return)&&r.call(f)}finally{if(n)throw n.error}}}}return this},t.VERSION="3.0.2",t}();function K(t){return Object.keys(t)}var E="__observers__",j=function(){function t(t){this._emitter=new _,this._current=t}var e=t.prototype;return Object.defineProperty(e,"current",{get:function(){return this._current},set:function(t){var e=t!==this._current;this._current=t,e&&this._emitter.trigger("update",t)},enumerable:!1,configurable:!0}),e.subscribe=function(t){this._emitter.on("update",t)},e.unsubscribe=function(t){this._emitter.off("update",t)},t}();function C(t){return new j(t)}function O(t){var e={};Object.defineProperty(t,E,{get:function(){return e}})}function x(t){return t[E]||O(t),t[E]}function H(t,e,n){t=x(t);return t[e]||(t[e]=C(n)),t[e]}function P(t){var i="function"==typeof t?t():t,u={};return O(u),K(i).forEach(function(t){var e,n,r,o=i[t];(r=o)&&"object"==typeof r&&"current"in r&&"subscribe"in r&&"unsubscribe"in r?(r=t,n=o,x(u)[r]=n,r=u,e=(n=t)||n,Object.defineProperty(r,n,{get:function(){return H(this,e).current},set:function(t){H(this,e,t).current=t}}),e!==n&&Object.defineProperty(r,e,{get:function(){return H(this,e).current}})):u[t]=o}),(t=u).subscribe=function(t,e){H(this,t).subscribe(e)},t.unsubscribe=function(t,e){var n=this;t?t in this&&H(this,t).unsubscribe(e):K(x(this)).forEach(function(t){n.unsubscribe(t)})},u}var S,T={__proto__:null,default:b,getKey:d,getCombi:v,getModifierCombi:r,REACTIVE:{events:["keydown","keyup","blur"],state:{isKeydown:!1},mounted:function(t){var e,n=t.keys,r=new b((null==(e=t.ref)?void 0:e.current)||(null==(e=t.ref)?void 0:e.value)||window),o=C(!1);return r.keydown(n,function(){o.current=!0}),r.keyup(n,function(){o.current=!1}),r.on("blur",function(){o.current=!1}),P({inst:r,keys:n,destroy:function(){return r.destroy()},isKeydown:o})},destroy:function(t){t.destroy()},on:function(t,e,n){var r=t.inst;"keydown"===e?r.keydown(t.keys,n):"keyup"===e?r.keyup(t.keys,n):r.on(e,n)},off:function(t,e,n){var r=t.inst;"keydown"===e?r.offKeydown(t.keys,n):"keyup"===e?r.offKeyup(t.keys,n):r.off(e,n)}}};for(S in T)b[S]=T[S];return b});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).keycon=e()}(this,function(){"use strict";var i=function(t,e){return(i=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,e){t.__proto__=e}:function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}))(t,e)};function u(t){return t&&"object"==typeof t}function c(t){return Array.isArray(t)}function f(t){return"string"==typeof t}function s(t,e,n,r){t.addEventListener(e,n,r)}function a(t,e,n,r){t.removeEventListener(e,n,r)}var o=function(){return(o=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};var t=function(){function t(){this._events={}}var e=t.prototype;return e.on=function(t,e){if(u(t))for(var n in t)this.on(n,t[n]);else this._addEvent(t,e,{});return this},e.off=function(t,e){if(t)if(u(t))for(var n in t)this.off(n);else{var r,o;e?(r=this._events[t])&&-1<(o=function(t,e,n){void 0===n&&(n=-1);for(var r=t.length,o=0;o<r;++o)if(e(t[o],o,t))return o;return n}(r,function(t){return t.listener===e}))&&r.splice(o,1):this._events[t]=[]}else this._events={};return this},e.once=function(e,t){var n=this;return t&&this._addEvent(e,t,{once:!0}),new Promise(function(t){n._addEvent(e,t,{once:!0})})},e.emit=function(e,n){var t,r=this,o=(void 0===n&&(n={}),this._events[e]);return!e||!o||(t=!1,n.eventType=e,n.stop=function(){t=!0},n.currentTarget=this,function(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;for(var r=Array(t),o=0,e=0;e<n;e++)for(var i=arguments[e],u=0,c=i.length;u<c;u++,o++)r[o]=i[u];return r}(o).forEach(function(t){t.listener(n),t.once&&r.off(e,t.listener)}),!t)},e.trigger=function(t,e){return this.emit(t,e=void 0===e?{}:e)},e._addEvent=function(t,e,n){var r=this._events;r[t]=r[t]||[],r[t].push(o({listener:e},n))},t}();(function(t,e){function n(t){var e;return"number"==typeof(t=t&&"object"==typeof t&&(e=t.which||t.keyCode||t.charCode)?e:t)?c[t]:(e=String(t),r[e.toLowerCase()]||o[e.toLowerCase()]||(1===e.length?e.charCodeAt(0):void 0))}n.isEventKey=function(t,e){if(t&&"object"==typeof t){t=t.which||t.keyCode||t.charCode;if(null!=t)if("string"==typeof e){var n=r[e.toLowerCase()];if(n)return n===t;if(n=o[e.toLowerCase()])return n===t}else if("number"==typeof e)return e===t;return!1}};for(var r=(e=t.exports=n).code=e.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},o=e.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},i=97;i<123;i++)r[String.fromCharCode(i)]=i-32;for(var i=48;i<58;i++)r[i-48]=i;for(i=1;i<13;i++)r["f"+i]=i+111;for(i=0;i<10;i++)r["numpad "+i]=i+96;var u,c=e.names=e.title={};for(i in r)c[r[i]]=i;for(u in o)r[u]=o[u]})(e={exports:{}},e.exports);var l,e=e.exports,y=(e.code,e.codes,e.aliases,e.names),h=(e.title,{"+":"plus","left command":"meta","right command":"meta"}),n={shift:1,ctrl:2,alt:3,meta:4};function d(t,e){var n,r=(y[t]||e||"").toLowerCase();for(n in h)r=r.replace(n,h[n]);return r.replace(/\s/g,"")}function v(t,e){void 0===e&&(e=d(t.keyCode,t.key));t=r(t);return-1===t.indexOf(e)&&t.push(e),t.filter(Boolean)}function r(t){return[t.shiftKey&&"shift",t.ctrlKey&&"ctrl",t.altKey&&"alt",t.metaKey&&"meta"].filter(Boolean)}function p(t){t=t.slice();return t.sort(function(t,e){return(n[t]||5)-(n[e]||5)}),t}var b=function(n){var t=o,e=n;if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}function o(t){void 0===t&&(t=window);var e=n.call(this)||this;return e.container=t,e.ctrlKey=!1,e.altKey=!1,e.shiftKey=!1,e.metaKey=!1,e.clear=function(){return e.ctrlKey=!1,e.altKey=!1,e.shiftKey=!1,e.metaKey=!1,e},e.keydownEvent=function(t){e.triggerEvent("keydown",t)},e.keyupEvent=function(t){e.triggerEvent("keyup",t)},e.blur=function(){e.clear(),e.trigger("blur")},s(t,"blur",e.blur),s(t,"keydown",e.keydownEvent),s(t,"keyup",e.keyupEvent),e}i(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r);e=o.prototype;return Object.defineProperty(o,"global",{get:function(){return l=l||new o},enumerable:!1,configurable:!0}),o.setGlobal=function(){return this.global},e.destroy=function(){var t=this.container;this.clear(),this.off(),a(t,"blur",this.blur),a(t,"keydown",this.keydownEvent),a(t,"keyup",this.keyupEvent)},e.keydown=function(t,e){return this.addEvent("keydown",t,e)},e.offKeydown=function(t,e){return this.removeEvent("keydown",t,e)},e.offKeyup=function(t,e){return this.removeEvent("keyup",t,e)},e.keyup=function(t,e){return this.addEvent("keyup",t,e)},e.addEvent=function(t,e,n){return c(e)?this.on("".concat(t,".").concat(p(e).join(".")),n):f(e)?this.on("".concat(t,".").concat(e),n):this.on(t,e),this},e.removeEvent=function(t,e,n){return c(e)?this.off("".concat(t,".").concat(p(e).join(".")),n):f(e)?this.off("".concat(t,".").concat(e),n):this.off(t,e),this},e.triggerEvent=function(t,e){this.ctrlKey=e.ctrlKey,this.shiftKey=e.shiftKey,this.altKey=e.altKey,this.metaKey=e.metaKey;var n=d(e.keyCode,e.key),r={key:n,isToggle:"ctrl"===n||"shift"===n||"meta"===n||"alt"===n,inputEvent:e,keyCode:e.keyCode,ctrlKey:e.ctrlKey,altKey:e.altKey,shiftKey:e.shiftKey,metaKey:e.metaKey},e=(this.trigger(t,r),this.trigger("".concat(t,".").concat(n),r),v(e,n));1<e.length&&this.trigger("".concat(t,".").concat(e.join(".")),r)},o}(t);function g(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return{value:(t=t&&r>=t.length?void 0:t)&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function m(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||0<e--)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u}(arguments[e]));return t}function k(t){return void 0===t}var w=function(){function t(t,e){var n,r;if(this._canceled=!1,e)try{for(var o=g(Object.keys(e)),i=o.next();!i.done;i=o.next()){var u=i.value;this[u]=e[u]}}catch(t){n={error:t}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}this.eventType=t}var e=t.prototype;return e.stop=function(){this._canceled=!0},e.isCanceled=function(){return this._canceled},t}(),_=function(){function t(){this._eventHandler={}}var e=t.prototype;return e.trigger=function(e){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];var r=e instanceof w?e.eventType:e,r=m(this._eventHandler[r]||[]);return r.length<=0||(e instanceof w?(e.currentTarget=this,r.forEach(function(t){t(e)})):r.forEach(function(t){t.apply(void 0,m(n))})),this},e.once=function(n,r){var o,i=this;if("object"==typeof n&&k(r)){var t,e=n;for(t in e)this.once(t,e[t])}else"string"==typeof n&&"function"==typeof r&&(o=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];r.apply(void 0,m(t)),i.off(n,o)},this.on(n,o));return this},e.hasOn=function(t){return!!this._eventHandler[t]},e.on=function(t,e){if("object"==typeof t&&k(e)){var n,r=t;for(n in r)this.on(n,r[n])}else{var o;"string"==typeof t&&"function"==typeof e&&(o=this._eventHandler[t],k(o)&&(this._eventHandler[t]=[],o=this._eventHandler[t]),o.push(e))}return this},e.off=function(t,e){var n,r;if(k(t))this._eventHandler={};else if(k(e))if("string"==typeof t)delete this._eventHandler[t];else{var o,i=t;for(o in i)this.off(o,i[o])}else{var u=this._eventHandler[t];if(u){var c=0;try{for(var f=g(u),s=f.next();!s.done;s=f.next()){if(s.value===e){u.splice(c,1),u.length<=0&&delete this._eventHandler[t];break}c++}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=f.return)&&r.call(f)}finally{if(n)throw n.error}}}}return this},t.VERSION="3.0.2",t}();function K(t){return Object.keys(t)}var E,j="__observers__",C=function(){function t(t){this._emitter=new _,this._current=t}var e=t.prototype;return Object.defineProperty(e,"current",{get:function(){return this._current},set:function(t){var e=t!==this._current;this._current=t,e&&this._emitter.trigger("update",t)},enumerable:!1,configurable:!0}),e.subscribe=function(t){this._emitter.on("update",t)},e.unsubscribe=function(t){this._emitter.off("update",t)},t}();function O(t){return new C(t)}function x(t){var e={};Object.defineProperty(t,j,{get:function(){return e}})}function H(t){return t[j]||x(t),t[j]}function P(t,e,n){t=H(t);return t[e]||(t[e]=O(n)),t[e]}function S(t){var i="function"==typeof t?t():t,u={};return x(u),K(i).forEach(function(t){var e,n,r,o=i[t];(r=o)&&"object"==typeof r&&"current"in r&&"subscribe"in r&&"unsubscribe"in r?(r=t,n=o,H(u)[r]=n,r=u,e=(n=t)||n,Object.defineProperty(r,n,{get:function(){return P(this,e).current},set:function(t){P(this,e,t).current=t}}),e!==n&&Object.defineProperty(r,e,{get:function(){return P(this,e).current}})):u[t]=o}),(t=u).subscribe=function(t,e){P(this,t).subscribe(e)},t.unsubscribe=function(t,e){var n=this;t?t in this&&P(this,t).unsubscribe(e):K(H(this)).forEach(function(t){n.unsubscribe(t)})},u}var T,L={__proto__:null,default:b,getKey:d,getCombi:v,getModifierCombi:r,REACTIVE:{events:["keydown","keyup","blur"],state:{isKeydown:!1},mounted:function(t){E=E||new Map;var e=null!=(e=null==(e=t.ref)?void 0:e.current)?e:window,n=E.get(e),r=(n||(n={inst:new b(e),count:0},E.set(e,n)),++n.count,n.inst),e=t.keys,o=O(!1);return r.keydown(e,function(){o.current=!0}),r.keyup(e,function(){o.current=!1}),r.on("blur",function(){o.current=!1}),S({inst:r,keys:e,destroy:function(){return r.destroy()},isKeydown:o})},destroy:function(t){var t=t.inst,e=t.container,n=E.get(e);--n.count,n.count||(t.destroy(),E.delete(e))},on:function(t,e,n){var r=t.inst;"keydown"===e?r.keydown(t.keys,n):"keyup"===e?r.keyup(t.keys,n):r.on(e,n)},off:function(t,e,n){var r=t.inst;"keydown"===e?r.offKeydown(t.keys,n):"keyup"===e?r.offKeyup(t.keys,n):r.off(e,n)}}};for(T in L)b[T]=L[T];return b});
//# sourceMappingURL=keycon.min.js.map
{
"name": "keycon",
"version": "1.3.1",
"version": "1.3.2",
"description": "Keyboard Controller",

@@ -5,0 +5,0 @@ "main": "./dist/keycon.cjs.js",

@@ -117,3 +117,3 @@ import EventEmitter, { EmitterParam, TargetParam } from "@scena/event-emitter";

*/
constructor(private container: Window | Document | HTMLElement = window) {
constructor(public container: Window | Document | HTMLElement = window) {
super();

@@ -120,0 +120,0 @@

@@ -5,3 +5,3 @@ import { ReactiveAdapter, reactive, Ref, observe, ReactiveObject, Observer } from "@cfcs/core";

export interface ReactiveKeyConData {
ref?: Ref<HTMLElement>;
ref?: Ref<HTMLElement | null | undefined>;
keys: string | string[];

@@ -16,2 +16,8 @@ }

let instanceMap!: Map<HTMLElement | Window | Document, {
inst: KeyController;
count: number;
}>;
export const REACTIVE: ReactiveAdapter<

@@ -27,4 +33,21 @@ ReactiveKeyCon,

mounted(data) {
if (!instanceMap) {
instanceMap = new Map();
}
const element = data.ref?.current ?? window;
let info = instanceMap.get(element);
if (!info) {
info = {
inst: new KeyController(element),
count: 0,
};
instanceMap.set(element, info);
}
++info.count;
const keycon = info.inst;
const keys = data.keys;
const keycon = new KeyController((data.ref?.current || data.ref?.value) || window);
const isKeydown = observe(false);

@@ -49,4 +72,11 @@

},
destroy(inst) {
inst.destroy();
destroy({ inst }) {
const element = inst.container;
const info = instanceMap.get(element);
--info.count;
if (!info.count) {
inst.destroy();
instanceMap.delete(element);
}
},

@@ -53,0 +83,0 @@ on(inst, name, callback) {

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc