@leonabcd123/modern-caps-lock 3.1.1 → 3.1.2
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/README.md +11 -3
- package/lib/index.js +8 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,9 @@ Modern Caps Lock provides an easy way to check whether Caps Lock is active, and
|
|
|
13
13
|
3. [Examples](#examples)
|
|
14
14
|
1. [Print Caps Lock state after every change](#print-caps-lock-state-after-every-change)
|
|
15
15
|
2. [Get current Caps Lock state](#get-current-caps-lock-state)
|
|
16
|
-
4. [
|
|
16
|
+
4. [Support](#support)
|
|
17
|
+
1. [Supported Platforms](#supported-platforms)
|
|
18
|
+
2. [Unsupported Platforms](#unsupported-platforms)
|
|
17
19
|
5. [Limitations](#limitations)
|
|
18
20
|
6. [Credits](#credits)
|
|
19
21
|
|
|
@@ -75,13 +77,19 @@ if (isCapsLockOn()) {
|
|
|
75
77
|
}
|
|
76
78
|
```
|
|
77
79
|
|
|
78
|
-
###
|
|
80
|
+
### Support
|
|
81
|
+
|
|
82
|
+
##### Supported Platforms
|
|
79
83
|
|
|
80
84
|
- Windows
|
|
81
85
|
- Mac
|
|
82
86
|
- Linux
|
|
83
87
|
- iPad
|
|
84
|
-
-
|
|
88
|
+
- Platforms using GBoard
|
|
89
|
+
|
|
90
|
+
##### Unsupported Platforms
|
|
91
|
+
|
|
92
|
+
- Platforms using Samsung keyboard
|
|
85
93
|
|
|
86
94
|
### Limitations
|
|
87
95
|
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
var _a, _b;
|
|
1
2
|
import { getCurrentOs } from "./os-detection.js";
|
|
2
3
|
let previousCapsState = false;
|
|
3
4
|
let capsState = false;
|
|
4
5
|
const os = getCurrentOs();
|
|
5
6
|
let onCapsChangeCallback;
|
|
6
7
|
const mouseEventsToUpdateOn = ["mousedown", "mousemove", "wheel"];
|
|
7
|
-
const
|
|
8
|
+
const isMobile = (_b = (_a = navigator.userAgentData) === null || _a === void 0 ? void 0 : _a.mobile) !== null && _b !== void 0 ? _b : navigator.maxTouchPoints > 1;
|
|
9
|
+
const isiPad = os === "Mac" && isMobile;
|
|
8
10
|
let isSendingCapsLockState = !isiPad;
|
|
9
11
|
function callCallbackIfNeeded() {
|
|
10
12
|
const callCallback = previousCapsState !== capsState;
|
|
@@ -20,8 +22,11 @@ function getCapsLockModifierState(event) {
|
|
|
20
22
|
mouseEventsToUpdateOn.forEach((eventType) => {
|
|
21
23
|
document.addEventListener(eventType, (event) => {
|
|
22
24
|
if (!isiPad) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
const currentCapsState = getCapsLockModifierState(event);
|
|
26
|
+
if (!isMobile || !currentCapsState) {
|
|
27
|
+
capsState = currentCapsState;
|
|
28
|
+
callCallbackIfNeeded();
|
|
29
|
+
}
|
|
25
30
|
}
|
|
26
31
|
});
|
|
27
32
|
});
|