@leonabcd123/modern-caps-lock 1.0.0
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/lib/index.d.ts +2 -0
- package/lib/index.js +70 -0
- package/package.json +23 -0
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCapsLockOn = isCapsLockOn;
|
|
4
|
+
exports.onCapsLockChange = onCapsLockChange;
|
|
5
|
+
function isPlatform(searchTerm) {
|
|
6
|
+
var platform = navigator.platform;
|
|
7
|
+
if (typeof searchTerm === "string") {
|
|
8
|
+
return platform.includes(searchTerm);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return searchTerm.test(platform);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function getCurrentOs() {
|
|
15
|
+
if (isPlatform("Mac")) {
|
|
16
|
+
return "Mac";
|
|
17
|
+
}
|
|
18
|
+
if (isPlatform("Linux")) {
|
|
19
|
+
return "Linux";
|
|
20
|
+
}
|
|
21
|
+
if (isPlatform("Windows")) {
|
|
22
|
+
return "Windows";
|
|
23
|
+
}
|
|
24
|
+
return "Unknown";
|
|
25
|
+
}
|
|
26
|
+
var capsState = false;
|
|
27
|
+
var os = getCurrentOs();
|
|
28
|
+
var onCapsChangeHandler;
|
|
29
|
+
function getCapsLockModifierState(event) {
|
|
30
|
+
return event.getModifierState("CapsLock");
|
|
31
|
+
}
|
|
32
|
+
document.addEventListener("keyup", function (event) {
|
|
33
|
+
if (os === "Mac") {
|
|
34
|
+
if (event.key === "CapsLock") {
|
|
35
|
+
capsState = false;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (navigator.maxTouchPoints <= 1) {
|
|
39
|
+
capsState = getCapsLockModifierState(event);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (os === "Windows") {
|
|
44
|
+
capsState = getCapsLockModifierState(event);
|
|
45
|
+
}
|
|
46
|
+
else if (event.key !== "CapsLock") {
|
|
47
|
+
capsState = getCapsLockModifierState(event);
|
|
48
|
+
}
|
|
49
|
+
onCapsChangeHandler(capsState);
|
|
50
|
+
});
|
|
51
|
+
document.addEventListener("keydown", function (event) {
|
|
52
|
+
if (os === "Mac") {
|
|
53
|
+
if (event.key === "CapsLock") {
|
|
54
|
+
capsState = true;
|
|
55
|
+
onCapsChangeHandler(capsState);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if (os === "Linux") {
|
|
59
|
+
if (event.key === "CapsLock") {
|
|
60
|
+
capsState = !getCapsLockModifierState(event);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
function isCapsLockOn() {
|
|
65
|
+
return capsState;
|
|
66
|
+
}
|
|
67
|
+
function onCapsLockChange(handler) {
|
|
68
|
+
onCapsChangeHandler = handler;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leonabcd123/modern-caps-lock",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A package that allows you to know whether caps lock is active or not",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"typescript": "next"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/Leonabcd123/modern-caps-lock.git"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"caps-lock"
|
|
16
|
+
],
|
|
17
|
+
"author": "Leonabcd123",
|
|
18
|
+
"license": "GPL-3.0",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/Leonabcd123/modern-caps-lock/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/Leonabcd123/modern-caps-lock#readme"
|
|
23
|
+
}
|