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.2 to 1.4.0

declaration/utils.d.ts

14

CHANGELOG.md

@@ -6,2 +6,16 @@ # Change Log

## [1.3.2](https://github.com/daybrush/keycon/compare/keycon@1.3.0...keycon@1.3.2) (2022-10-19)
### :rocket: New Features
* add svelte-keycon ([066a257](https://github.com/daybrush/keycon/commit/066a257e86e8d2ce22a42905c852d04f4f26d498))
### :mega: Other
* update packages versions ([07f0b13](https://github.com/daybrush/keycon/commit/07f0b138200de547b2634c4b7542a9f008174dc9))
## [1.3.0](https://github.com/daybrush/keycon/compare/keycon@1.2.2...keycon@1.3.0) (2022-09-24)

@@ -8,0 +22,0 @@

1

declaration/index.d.ts
import keycon from "./KeyController";
export * from "./utils";
export * from "./KeyController";
export * from "./reactive";
export default keycon;

4

declaration/KeyController.d.ts
import EventEmitter, { EmitterParam } from "@scena/event-emitter";
export declare function getKey(keyCode: number, keyName?: string): string;
export declare function getCombi(e: KeyboardEvent, key?: string): string[];
export declare function getModifierCombi(e: KeyboardEvent): string[];
export interface KeyControllerEvent extends EmitterParam {

@@ -26,2 +23,3 @@ inputEvent: KeyboardEvent;

}
export declare type KeyControllerEvents = KeyconEvents;
declare class KeyController extends EventEmitter<KeyconEvents & {

@@ -28,0 +26,0 @@ [text: string]: any;

import { ReactiveAdapter, Ref, ReactiveObject, Observer } from "@cfcs/core";
import KeyController, { KeyconEvents } from "./KeyController";
export interface ReactiveKeyConData {
import KeyController, { KeyControllerEvents, KeyControllerEvent } from "./KeyController";
export interface ReactiveKeyControllerData {
ref?: Ref<HTMLElement | null | undefined>;
checker?: (e: KeyControllerEvent) => boolean;
keys: string | string[];
}
export declare type ReactiveKeyCon = ReactiveObject<{
export declare type ReactiveKeyController = ReactiveObject<{
inst: KeyController;

@@ -13,4 +14,4 @@ keys: string | string[];

}>;
export declare const REACTIVE: ReactiveAdapter<ReactiveKeyCon, {
export declare const REACTIVE: ReactiveAdapter<ReactiveKeyController, {
isKeydown: boolean;
}, never, ReactiveKeyConData, KeyconEvents>;
}, never, ReactiveKeyControllerData, KeyControllerEvents>;

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

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

@@ -278,2 +278,5 @@ 'use strict';

}
/**
* @memberof KeyController
*/
function getArrangeCombi(keys) {

@@ -288,2 +291,3 @@ var arrangeKeys = keys.slice();

}
var globalKeyController;

@@ -1077,4 +1081,7 @@ /**

var isKeydown = observe(false);
keycon.keydown(keys, function () {
isKeydown.current = true;
var checker = data.checker;
keycon.keydown(keys, function (e) {
if (!checker || checker(e)) {
isKeydown.current = true;
}
});

@@ -1136,2 +1143,3 @@ keycon.keyup(keys, function () {

getModifierCombi: getModifierCombi,
getArrangeCombi: getArrangeCombi,
REACTIVE: REACTIVE

@@ -1147,2 +1155,3 @@ };

exports.default = KeyController;
exports.getArrangeCombi = getArrangeCombi;
exports.getCombi = getCombi;

@@ -1149,0 +1158,0 @@ exports.getKey = getKey;

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

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

@@ -276,2 +276,5 @@ import EventEmitter from '@scena/event-emitter';

}
/**
* @memberof KeyController
*/
function getArrangeCombi(keys) {

@@ -286,2 +289,3 @@ var arrangeKeys = keys.slice();

}
var globalKeyController;

@@ -1075,4 +1079,7 @@ /**

var isKeydown = observe(false);
keycon.keydown(keys, function () {
isKeydown.current = true;
var checker = data.checker;
keycon.keydown(keys, function (e) {
if (!checker || checker(e)) {
isKeydown.current = true;
}
});

@@ -1127,3 +1134,3 @@ keycon.keyup(keys, function () {

export default KeyController;
export { REACTIVE, getCombi, getKey, getModifierCombi };
export { REACTIVE, getArrangeCombi, getCombi, getKey, getModifierCombi };
//# sourceMappingURL=keycon.esm.js.map

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

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

@@ -705,2 +705,5 @@ (function (global, factory) {

}
/**
* @memberof KeyController
*/
function getArrangeCombi(keys) {

@@ -715,2 +718,3 @@ var arrangeKeys = keys.slice();

}
var globalKeyController;

@@ -1504,4 +1508,7 @@ /**

var isKeydown = observe(false);
keycon.keydown(keys, function () {
isKeydown.current = true;
var checker = data.checker;
keycon.keydown(keys, function (e) {
if (!checker || checker(e)) {
isKeydown.current = true;
}
});

@@ -1563,2 +1570,3 @@ keycon.keyup(keys, function () {

getModifierCombi: getModifierCombi,
getArrangeCombi: getArrangeCombi,
REACTIVE: REACTIVE

@@ -1565,0 +1573,0 @@ };

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

repository: git+https://github.com/daybrush/keycon.git
version: 1.3.2
version: 1.4.0
*/
!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});
!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,A={__proto__:null,default:b,getKey:d,getCombi:v,getModifierCombi:r,getArrangeCombi:p,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),i=t.checker;return r.keydown(e,function(t){i&&!i(t)||(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 A)b[T]=A[T];return b});
//# sourceMappingURL=keycon.min.js.map
{
"name": "keycon",
"version": "1.3.2",
"version": "1.4.0",
"description": "Keyboard Controller",

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

import keycon from "./KeyController";
export * from "./utils";
export * from "./KeyController";
export * from "./reactive";
export default keycon;
import EventEmitter, { EmitterParam, TargetParam } from "@scena/event-emitter";
import { names } from "keycode";
import { isString, isArray, addEvent, removeEvent } from "@daybrush/utils";
import { getArrangeCombi, getKey, getCombi } from "./utils";
const codeData = {
"+": "plus",
"left command": "meta",
"right command": "meta",
};
const keysSort = {
shift: 1,
ctrl: 2,
alt: 3,
meta: 4,
};
/**
* @memberof KeyController
*/
export function getKey(keyCode: number, keyName?: string): string {
let key = (names[keyCode] || keyName || "").toLowerCase();
for (const name in codeData) {
key = key.replace(name, codeData[name]);
}
return key.replace(/\s/g, "");
}
/**
* @memberof KeyController
*/
export function getCombi(e: KeyboardEvent, key: string = getKey(e.keyCode, e.key)): string[] {
const keys = getModifierCombi(e);
keys.indexOf(key) === -1 && keys.push(key);
return keys.filter(Boolean);
}
/**
* @memberof KeyController
*/
export function getModifierCombi(e: KeyboardEvent): string[] {
const keys = [e.shiftKey && "shift", e.ctrlKey && "ctrl", e.altKey && "alt", e.metaKey && "meta"];
return keys.filter(Boolean);
}
function getArrangeCombi(keys: string[]) {
const arrangeKeys = keys.slice();
arrangeKeys.sort((prev, next) => {
const prevScore = keysSort[prev] || 5;
const nextScore = keysSort[next] || 5;
return prevScore - nextScore;
});
return arrangeKeys;
}
/**
* @typedef

@@ -87,2 +35,4 @@ * @memberof KeyController

}
export type KeyControllerEvents = KeyconEvents;
let globalKeyController!: KeyController;

@@ -89,0 +39,0 @@

import { ReactiveAdapter, reactive, Ref, observe, ReactiveObject, Observer } from "@cfcs/core";
import KeyController, { KeyconEvents } from "./KeyController";
import KeyController, { KeyControllerEvents, KeyControllerEvent } from "./KeyController";
export interface ReactiveKeyConData {
export interface ReactiveKeyControllerData {
ref?: Ref<HTMLElement | null | undefined>;
checker?: (e: KeyControllerEvent) => boolean;
keys: string | string[];
}
export type ReactiveKeyCon = ReactiveObject<{
export type ReactiveKeyController = ReactiveObject<{
inst: KeyController;

@@ -15,3 +17,2 @@ keys: string | string[];

let instanceMap!: Map<HTMLElement | Window | Document, {

@@ -23,10 +24,10 @@ inst: KeyController;

export const REACTIVE: ReactiveAdapter<
ReactiveKeyCon,
ReactiveKeyController,
{ isKeydown: boolean },
never,
ReactiveKeyConData,
KeyconEvents
ReactiveKeyControllerData,
KeyControllerEvents
> = {
events: ["keydown", "keyup", "blur"],
state: { isKeydown : false },
state: { isKeydown: false },
mounted(data) {

@@ -53,5 +54,8 @@ if (!instanceMap) {

const isKeydown = observe(false);
const checker = data.checker;
keycon.keydown(keys, () => {
isKeydown.current = true;
keycon.keydown(keys, (e: KeyControllerEvent) => {
if (!checker || checker(e)) {
isKeydown.current = true;
}
});

@@ -58,0 +62,0 @@ keycon.keyup(keys, () => {

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