@leonabcd123/modern-caps-lock 3.0.5 → 3.0.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Modern Caps Lock
2
2
 
3
- Modern Caps Lock provides an easy way to check whether Caps Lock is active or not, and it allows you to run your code whenever Caps Lock state changes.
3
+ Modern Caps Lock provides an easy way to check whether Caps Lock is active, and it allows you to run your code whenever the Caps Lock state changes.
4
4
 
5
5
  1. [Installation](#installation)
6
6
  2. [API](#api)
@@ -13,11 +13,11 @@ Modern Caps Lock provides an easy way to check whether Caps Lock is active or no
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
- 5. [Support](#support)
16
+ 4. [Support](#support)
17
17
  1. [Supported Platforms](#supported-platforms)
18
18
  2. [Unsupported Platforms](#unsupported-platforms)
19
- 6. [Limitations](#limitations)
20
- 7. [Credits](#credits)
19
+ 5. [Limitations](#limitations)
20
+ 6. [Credits](#credits)
21
21
 
22
22
  ### Installation
23
23
 
@@ -31,7 +31,7 @@ npm install @leonabcd123/modern-caps-lock
31
31
 
32
32
  #### onCapsLockChange
33
33
 
34
- Runs the provided callback function whenever Caps Lock state is changed.
34
+ Runs the provided callback function whenever the Caps Lock state changes.
35
35
 
36
36
  ##### Arguments
37
37
 
@@ -51,7 +51,7 @@ None.
51
51
 
52
52
  ##### Return value
53
53
 
54
- `capsState: boolean`: a boolean representing the current Caps Lock state. If `true`, Caps Lock is on; if `false`, Caps Lock is off.
54
+ `capsState: boolean`: a boolean indicating whether Caps Lock is on. If `true`, Caps Lock is on; if `false`, Caps Lock is off.
55
55
 
56
56
 
57
57
  ### Examples
@@ -93,7 +93,7 @@ if (isCapsLockOn()) {
93
93
  ### Limitations
94
94
 
95
95
  Because of browser limitations, we can only detect the Caps Lock state after a KeyboardEvent
96
- or a MouseEvent. We currently detect updates to the Caps Lock state when the following events are fired:
96
+ or MouseEvent occurs. We currently detect updates to the Caps Lock state when the following events are fired:
97
97
 
98
98
  - keydown
99
99
  - keyup
@@ -101,7 +101,7 @@ or a MouseEvent. We currently detect updates to the Caps Lock state when the fol
101
101
  - mousemove
102
102
  - wheel
103
103
 
104
- Before any of these events are fired, Caps Lock state is off.
104
+ Until one of these events is fired, the Caps Lock state defaults to `false`.
105
105
 
106
106
  ### Credits
107
107
 
package/lib/index.js CHANGED
@@ -1,26 +1,11 @@
1
- function isPlatform(osName) {
2
- var _a, _b;
3
- return osName.test((_b = (_a = navigator.userAgentData) === null || _a === void 0 ? void 0 : _a.platform) !== null && _b !== void 0 ? _b : (navigator.oscpu || navigator.userAgent || navigator.platform));
4
- }
5
- function getCurrentOs() {
6
- if (isPlatform(/Mac/i)) {
7
- return "Mac";
8
- }
9
- if (isPlatform(/Linux/i)) {
10
- return "Linux";
11
- }
12
- if (isPlatform(/Win/i)) {
13
- return "Windows";
14
- }
15
- return "Unknown";
16
- }
1
+ import { getCurrentOs } from "./os-detection";
17
2
  let previousCapsState = false;
18
3
  let capsState = false;
19
4
  const os = getCurrentOs();
20
5
  let onCapsChangeCallback;
21
6
  const mouseEventsToUpdateOn = ["mousedown", "mousemove", "wheel"];
22
7
  const isiPad = os === "Mac" && navigator.maxTouchPoints > 1;
23
- let isSendingCapsLockStateOniPad = !isiPad;
8
+ let isSendingCapsLockState = !isiPad;
24
9
  function callCallbackIfNeeded() {
25
10
  const callCallback = previousCapsState !== capsState;
26
11
  previousCapsState = capsState;
@@ -34,11 +19,9 @@ function getCapsLockModifierState(event) {
34
19
  }
35
20
  mouseEventsToUpdateOn.forEach((eventType) => {
36
21
  document.addEventListener(eventType, (event) => {
37
- if (event instanceof MouseEvent) {
38
- if (!isiPad) {
39
- capsState = getCapsLockModifierState(event);
40
- callCallbackIfNeeded();
41
- }
22
+ if (!isiPad) {
23
+ capsState = getCapsLockModifierState(event);
24
+ callCallbackIfNeeded();
42
25
  }
43
26
  });
44
27
  });
@@ -49,9 +32,9 @@ document.addEventListener("keyup", (event) => {
49
32
  }
50
33
  else {
51
34
  const currentCapsState = getCapsLockModifierState(event);
52
- if (isSendingCapsLockStateOniPad || currentCapsState) {
35
+ if (isSendingCapsLockState || currentCapsState) {
53
36
  capsState = currentCapsState;
54
- isSendingCapsLockStateOniPad = true;
37
+ isSendingCapsLockState = true;
55
38
  }
56
39
  }
57
40
  }
@@ -0,0 +1 @@
1
+ export declare function getCurrentOs(): "Mac" | "Linux" | "Windows" | "Unknown";
@@ -0,0 +1,16 @@
1
+ function isPlatform(osName) {
2
+ var _a, _b, _c;
3
+ return osName.test((_b = (_a = navigator.userAgentData) === null || _a === void 0 ? void 0 : _a.platform) !== null && _b !== void 0 ? _b : ((_c = navigator.oscpu) !== null && _c !== void 0 ? _c : "") + navigator.userAgent + navigator.platform);
4
+ }
5
+ export function getCurrentOs() {
6
+ if (isPlatform(/Mac/i)) {
7
+ return "Mac";
8
+ }
9
+ if (isPlatform(/Linux/i)) {
10
+ return "Linux";
11
+ }
12
+ if (isPlatform(/Win/i)) {
13
+ return "Windows";
14
+ }
15
+ return "Unknown";
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leonabcd123/modern-caps-lock",
3
- "version": "3.0.5",
3
+ "version": "3.0.6",
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",
@@ -29,7 +29,7 @@
29
29
  "contributors": [
30
30
  "fehmer"
31
31
  ],
32
- "license": "GPL-3.0-only",
32
+ "license": "GPL-3.0-or-later",
33
33
  "bugs": {
34
34
  "url": "https://github.com/Leonabcd123/modern-caps-lock/issues"
35
35
  },