@ramstack/alpinegear-hotkey 1.4.4 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/alpinegear-hotkey.esm.js +30 -27
- package/alpinegear-hotkey.esm.min.js +1 -1
- package/alpinegear-hotkey.js +30 -27
- package/alpinegear-hotkey.min.js +1 -1
- package/package.json +1 -1
package/alpinegear-hotkey.esm.js
CHANGED
|
@@ -16,17 +16,15 @@ const aliases = {
|
|
|
16
16
|
"windows": "meta",
|
|
17
17
|
"cmd": "meta",
|
|
18
18
|
"command": "meta",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"equal": "=",
|
|
29
|
-
"slash": "/"
|
|
19
|
+
",": "comma",
|
|
20
|
+
".": "period",
|
|
21
|
+
"/": "slash",
|
|
22
|
+
"\\": "backslash",
|
|
23
|
+
";": "semicolon",
|
|
24
|
+
"=": "equal",
|
|
25
|
+
"`": "backquote",
|
|
26
|
+
"]": "bracketright",
|
|
27
|
+
"[": "bracketleft",
|
|
30
28
|
};
|
|
31
29
|
const control_keys = [
|
|
32
30
|
"ctrlKey",
|
|
@@ -39,34 +37,39 @@ function registerHotkey(target, hotkey, handler, eventName = "keydown", options)
|
|
|
39
37
|
if (typeof target === "string") {
|
|
40
38
|
target = document.querySelector(target) ?? error(`No element found for selector '${target}'`);
|
|
41
39
|
}
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
const require_trusted = options?.trusted;
|
|
41
|
+
const once = options?.once;
|
|
42
|
+
const native_options = options && typeof options === "object"
|
|
43
|
+
? { capture: options.capture, passive: options.passive }
|
|
44
|
+
: options;
|
|
45
|
+
const unregister = listen(target, eventName, function (e) {
|
|
46
|
+
if (!require_trusted || e.isTrusted) {
|
|
44
47
|
if (!e.target?.closest("[data-hotkey-ignore]")) {
|
|
45
48
|
if (info.code === e.code.toUpperCase()) {
|
|
46
49
|
if (control_keys.every(n => info[n] === e[n])) {
|
|
50
|
+
once && unregister();
|
|
47
51
|
handler.call(this, e);
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
|
-
},
|
|
56
|
+
}, native_options);
|
|
57
|
+
return unregister;
|
|
53
58
|
}
|
|
54
59
|
function describe(hotkey) {
|
|
55
60
|
const keys = hotkey.replace(/\s+/g, "").toLowerCase().split("+");
|
|
56
61
|
const info = keys.reduce((data, k) => {
|
|
57
62
|
k = aliases[k] ?? k;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
k
|
|
67
|
-
|
|
68
|
-
data.code = k.length === 1 && k >= 'A' && k <= 'Z' ? `KEY${k}` : k;
|
|
69
|
-
break;
|
|
63
|
+
if (/^(ctrl|alt|shift|meta)$/.test(k)) {
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
data[`${k}Key`] = true;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
k.length || error_invalid_key(hotkey);
|
|
69
|
+
k = k.toUpperCase();
|
|
70
|
+
data.code = /^[A-Z]$/.test(k) ? `KEY${k}`
|
|
71
|
+
: /^[0-9]$/.test(k) ? `DIGIT${k}`
|
|
72
|
+
: k;
|
|
70
73
|
}
|
|
71
74
|
return data;
|
|
72
75
|
}, {
|
|
@@ -123,7 +126,7 @@ function plugin({ directive }) {
|
|
|
123
126
|
hotkey,
|
|
124
127
|
e => {
|
|
125
128
|
has_modifier(modifiers, "prevent") && e.preventDefault();
|
|
126
|
-
has_modifier(modifiers, "stop") && e.
|
|
129
|
+
has_modifier(modifiers, "stop") && e.stopPropagation();
|
|
127
130
|
|
|
128
131
|
e.hotkey = hotkey;
|
|
129
132
|
listener(e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e={esc:"escape",ins:"insert",del:"delete",up:"arrowup",down:"arrowdown",right:"arrowright",left:"arrowleft",pgup:"pageup",pgdn:"pagedown",break:"pause",scroll:"scrolllock",scrlk:"scrolllock",prtscr:"printscreen",win:"meta",windows:"meta",cmd:"meta",command:"meta",
|
|
1
|
+
const e={esc:"escape",ins:"insert",del:"delete",up:"arrowup",down:"arrowdown",right:"arrowright",left:"arrowleft",pgup:"pageup",pgdn:"pagedown",break:"pause",scroll:"scrolllock",scrlk:"scrolllock",prtscr:"printscreen",win:"meta",windows:"meta",cmd:"meta",command:"meta",",":"comma",".":"period","/":"slash","\\":"backslash",";":"semicolon","=":"equal","`":"backquote","]":"bracketright","[":"bracketleft"},t=["ctrlKey","altKey","shiftKey","metaKey"];function o(e){r(`Invalid hotkey: '${e}'`)}function r(e){throw new Error(e)}const s=(e,t)=>e.includes(t),n=["capture","passive","once","prevent","stop","trusted","window","document"];function c({directive:c}){c("hotkey",(c,{expression:a,value:i,modifiers:p},{evaluateLater:l,cleanup:u})=>{const d=a?l(a):()=>{},f=s(p,"window")?window:s(p,"document")?document:c;u(((...e)=>(...t)=>{for(const o of e)o&&o(...t)})(...p.filter(e=>!n.includes(e)).flatMap(e=>e.split(",")).map(n=>function(s,n,c,a="keydown",i){const p=function(t){const r=t.replace(/\s+/g,"").toLowerCase().split("+").reduce((r,s)=>(/^(ctrl|alt|shift|meta)$/.test(s=e[s]??s)?r[`${s}Key`]=!0:(s.length||o(t),s=s.toUpperCase(),r.code=/^[A-Z]$/.test(s)?`KEY${s}`:/^[0-9]$/.test(s)?`DIGIT${s}`:s),r),{code:"",ctrlKey:!1,altKey:!1,shiftKey:!1,metaKey:!1});return r.code||o(t),r}(n);"string"==typeof s&&(s=document.querySelector(s)??r(`No element found for selector '${s}'`));const l=i?.trusted,u=i?.once,d=function(e,t,o,r){return e.addEventListener(t,o,r),()=>e.removeEventListener(t,o,r)}(s,a,function(e){l&&!e.isTrusted||e.target?.closest("[data-hotkey-ignore]")||p.code===e.code.toUpperCase()&&t.every(t=>p[t]===e[t])&&(u&&d(),c.call(this,e))},i&&"object"==typeof i?{capture:i.capture,passive:i.passive}:i);return d}(f,n,e=>{s(p,"prevent")&&e.preventDefault(),s(p,"stop")&&e.stopPropagation(),e.hotkey=n,(e=>{d(()=>{},{scope:{$event:e},params:[e]})})(e)},i||"keydown",{capture:s(p,"capture"),passive:s(p,"passive"),once:s(p,"once"),trusted:s(p,"trusted")}))))})}export{c as default,c as hotkey};
|
package/alpinegear-hotkey.js
CHANGED
|
@@ -32,17 +32,15 @@
|
|
|
32
32
|
"windows": "meta",
|
|
33
33
|
"cmd": "meta",
|
|
34
34
|
"command": "meta",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"equal": "=",
|
|
45
|
-
"slash": "/"
|
|
35
|
+
",": "comma",
|
|
36
|
+
".": "period",
|
|
37
|
+
"/": "slash",
|
|
38
|
+
"\\": "backslash",
|
|
39
|
+
";": "semicolon",
|
|
40
|
+
"=": "equal",
|
|
41
|
+
"`": "backquote",
|
|
42
|
+
"]": "bracketright",
|
|
43
|
+
"[": "bracketleft",
|
|
46
44
|
};
|
|
47
45
|
const control_keys = [
|
|
48
46
|
"ctrlKey",
|
|
@@ -55,34 +53,39 @@
|
|
|
55
53
|
if (typeof target === "string") {
|
|
56
54
|
target = document.querySelector(target) ?? error(`No element found for selector '${target}'`);
|
|
57
55
|
}
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
const require_trusted = options?.trusted;
|
|
57
|
+
const once = options?.once;
|
|
58
|
+
const native_options = options && typeof options === "object"
|
|
59
|
+
? { capture: options.capture, passive: options.passive }
|
|
60
|
+
: options;
|
|
61
|
+
const unregister = listen(target, eventName, function (e) {
|
|
62
|
+
if (!require_trusted || e.isTrusted) {
|
|
60
63
|
if (!e.target?.closest("[data-hotkey-ignore]")) {
|
|
61
64
|
if (info.code === e.code.toUpperCase()) {
|
|
62
65
|
if (control_keys.every(n => info[n] === e[n])) {
|
|
66
|
+
once && unregister();
|
|
63
67
|
handler.call(this, e);
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
|
-
},
|
|
72
|
+
}, native_options);
|
|
73
|
+
return unregister;
|
|
69
74
|
}
|
|
70
75
|
function describe(hotkey) {
|
|
71
76
|
const keys = hotkey.replace(/\s+/g, "").toLowerCase().split("+");
|
|
72
77
|
const info = keys.reduce((data, k) => {
|
|
73
78
|
k = aliases[k] ?? k;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
k
|
|
83
|
-
|
|
84
|
-
data.code = k.length === 1 && k >= 'A' && k <= 'Z' ? `KEY${k}` : k;
|
|
85
|
-
break;
|
|
79
|
+
if (/^(ctrl|alt|shift|meta)$/.test(k)) {
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
data[`${k}Key`] = true;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
k.length || error_invalid_key(hotkey);
|
|
85
|
+
k = k.toUpperCase();
|
|
86
|
+
data.code = /^[A-Z]$/.test(k) ? `KEY${k}`
|
|
87
|
+
: /^[0-9]$/.test(k) ? `DIGIT${k}`
|
|
88
|
+
: k;
|
|
86
89
|
}
|
|
87
90
|
return data;
|
|
88
91
|
}, {
|
|
@@ -131,7 +134,7 @@
|
|
|
131
134
|
hotkey,
|
|
132
135
|
e => {
|
|
133
136
|
has_modifier(modifiers, "prevent") && e.preventDefault();
|
|
134
|
-
has_modifier(modifiers, "stop") && e.
|
|
137
|
+
has_modifier(modifiers, "stop") && e.stopPropagation();
|
|
135
138
|
|
|
136
139
|
e.hotkey = hotkey;
|
|
137
140
|
listener(e);
|
package/alpinegear-hotkey.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";const e=(e,t)=>e.includes(t),t={esc:"escape",ins:"insert",del:"delete",up:"arrowup",down:"arrowdown",right:"arrowright",left:"arrowleft",pgup:"pageup",pgdn:"pagedown",break:"pause",scroll:"scrolllock",scrlk:"scrolllock",prtscr:"printscreen",win:"meta",windows:"meta",cmd:"meta",command:"meta",
|
|
1
|
+
!function(){"use strict";const e=(e,t)=>e.includes(t),t={esc:"escape",ins:"insert",del:"delete",up:"arrowup",down:"arrowdown",right:"arrowright",left:"arrowleft",pgup:"pageup",pgdn:"pagedown",break:"pause",scroll:"scrolllock",scrlk:"scrolllock",prtscr:"printscreen",win:"meta",windows:"meta",cmd:"meta",command:"meta",",":"comma",".":"period","/":"slash","\\":"backslash",";":"semicolon","=":"equal","`":"backquote","]":"bracketright","[":"bracketleft"},o=["ctrlKey","altKey","shiftKey","metaKey"];function n(e){r(`Invalid hotkey: '${e}'`)}function r(e){throw new Error(e)}const s=["capture","passive","once","prevent","stop","trusted","window","document"];function c({directive:c}){c("hotkey",(c,{expression:a,value:i,modifiers:p},{evaluateLater:l,cleanup:u})=>{const d=a?l(a):()=>{},f=e(p,"window")?window:e(p,"document")?document:c;u(((...e)=>(...t)=>{for(const o of e)o&&o(...t)})(...p.filter(e=>!s.includes(e)).flatMap(e=>e.split(",")).map(s=>function(e,s,c,a="keydown",i){const p=function(e){const o=e.replace(/\s+/g,"").toLowerCase().split("+").reduce((o,r)=>(/^(ctrl|alt|shift|meta)$/.test(r=t[r]??r)?o[`${r}Key`]=!0:(r.length||n(e),r=r.toUpperCase(),o.code=/^[A-Z]$/.test(r)?`KEY${r}`:/^[0-9]$/.test(r)?`DIGIT${r}`:r),o),{code:"",ctrlKey:!1,altKey:!1,shiftKey:!1,metaKey:!1});return o.code||n(e),o}(s);"string"==typeof e&&(e=document.querySelector(e)??r(`No element found for selector '${e}'`));const l=i?.trusted,u=i?.once,d=function(e,t,o,n){return e.addEventListener(t,o,n),()=>e.removeEventListener(t,o,n)}(e,a,function(e){l&&!e.isTrusted||e.target?.closest("[data-hotkey-ignore]")||p.code===e.code.toUpperCase()&&o.every(t=>p[t]===e[t])&&(u&&d(),c.call(this,e))},i&&"object"==typeof i?{capture:i.capture,passive:i.passive}:i);return d}(f,s,t=>{e(p,"prevent")&&t.preventDefault(),e(p,"stop")&&t.stopPropagation(),t.hotkey=s,(e=>{d(()=>{},{scope:{$event:e},params:[e]})})(t)},i||"keydown",{capture:e(p,"capture"),passive:e(p,"passive"),once:e(p,"once"),trusted:e(p,"trusted")}))))})}document.addEventListener("alpine:init",()=>Alpine.plugin(c),void 0)}();
|
package/package.json
CHANGED