@leonabcd123/modern-caps-lock 3.1.1 → 3.1.3

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.
Files changed (3) hide show
  1. package/README.md +11 -3
  2. package/lib/index.js +11 -6
  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. [Supported Platforms](#supported-platforms)
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
- ### Supported Platforms
80
+ ### Support
81
+
82
+ ##### Supported Platforms
79
83
 
80
84
  - Windows
81
85
  - Mac
82
86
  - Linux
83
87
  - iPad
84
- - Android
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,16 +1,18 @@
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
- let onCapsChangeCallback;
6
+ let onCapsChangeCallbacks = [];
6
7
  const mouseEventsToUpdateOn = ["mousedown", "mousemove", "wheel"];
7
- const isiPad = os === "Mac" && navigator.maxTouchPoints > 1;
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;
11
13
  previousCapsState = capsState;
12
14
  if (callCallback) {
13
- onCapsChangeCallback === null || onCapsChangeCallback === void 0 ? void 0 : onCapsChangeCallback(capsState);
15
+ onCapsChangeCallbacks.forEach((callback) => callback(capsState));
14
16
  }
15
17
  }
16
18
  function getCapsLockModifierState(event) {
@@ -20,8 +22,11 @@ function getCapsLockModifierState(event) {
20
22
  mouseEventsToUpdateOn.forEach((eventType) => {
21
23
  document.addEventListener(eventType, (event) => {
22
24
  if (!isiPad) {
23
- capsState = getCapsLockModifierState(event);
24
- callCallbackIfNeeded();
25
+ const currentCapsState = getCapsLockModifierState(event);
26
+ if (!isMobile || !currentCapsState) {
27
+ capsState = currentCapsState;
28
+ callCallbackIfNeeded();
29
+ }
25
30
  }
26
31
  });
27
32
  });
@@ -63,5 +68,5 @@ export function isCapsLockOn() {
63
68
  return capsState;
64
69
  }
65
70
  export function onCapsLockChange(callback) {
66
- onCapsChangeCallback = callback;
71
+ onCapsChangeCallbacks.push(callback);
67
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leonabcd123/modern-caps-lock",
3
- "version": "3.1.1",
3
+ "version": "3.1.3",
4
4
  "description": "A package that allows you to check whether caps lock is active or not",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",