@leonabcd123/modern-caps-lock 3.0.4 → 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,23 @@
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
+
5
+ 1. [Installation](#installation)
6
+ 2. [API](#api)
7
+ 1. [`onCapsLockChange`](#oncapslockchange)
8
+ 1. [Arguments](#arguments)
9
+ 2. [Return value](#return-value)
10
+ 2. [`isCapsLockOn`](#iscapslockon)
11
+ 1. [Arguments](#arguments-1)
12
+ 2. [Return value](#return-value-1)
13
+ 3. [Examples](#examples)
14
+ 1. [Print Caps Lock state after every change](#print-caps-lock-state-after-every-change)
15
+ 2. [Get current Caps Lock state](#get-current-caps-lock-state)
16
+ 4. [Support](#support)
17
+ 1. [Supported Platforms](#supported-platforms)
18
+ 2. [Unsupported Platforms](#unsupported-platforms)
19
+ 5. [Limitations](#limitations)
20
+ 6. [Credits](#credits)
4
21
 
5
22
  ### Installation
6
23
 
@@ -12,9 +29,9 @@ npm install @leonabcd123/modern-caps-lock
12
29
 
13
30
  ### API
14
31
 
15
- #### onCapsLockChange()
32
+ #### onCapsLockChange
16
33
 
17
- Runs the provided callback function whenever Caps Lock state is changed.
34
+ Runs the provided callback function whenever the Caps Lock state changes.
18
35
 
19
36
  ##### Arguments
20
37
 
@@ -24,7 +41,7 @@ Runs the provided callback function whenever Caps Lock state is changed.
24
41
 
25
42
  `void`.
26
43
 
27
- #### isCapsLockOn()
44
+ #### isCapsLockOn
28
45
 
29
46
  Returns the current Caps Lock state.
30
47
 
@@ -34,7 +51,7 @@ None.
34
51
 
35
52
  ##### Return value
36
53
 
37
- `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.
38
55
 
39
56
 
40
57
  ### Examples
@@ -62,21 +79,21 @@ if (isCapsLockOn()) {
62
79
 
63
80
  ### Support
64
81
 
65
- ##### Supported Platforms:
82
+ ##### Supported Platforms
66
83
 
67
84
  - Windows
68
85
  - Mac
69
86
  - Linux
70
87
  - iPad
71
88
 
72
- ##### Unsupported Platforms:
89
+ ##### Unsupported Platforms
73
90
 
74
91
  - Platforms using [GBoard](https://en.wikipedia.org/wiki/Gboard)
75
92
 
76
93
  ### Limitations
77
94
 
78
95
  Because of browser limitations, we can only detect the Caps Lock state after a KeyboardEvent
79
- 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:
80
97
 
81
98
  - keydown
82
99
  - keyup
@@ -84,7 +101,7 @@ or a MouseEvent. We currently detect updates to the Caps Lock state when the fol
84
101
  - mousemove
85
102
  - wheel
86
103
 
87
- 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`.
88
105
 
89
106
  ### Credits
90
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
- isSendingCapsLockStateOniPad || (isSendingCapsLockStateOniPad = currentCapsState);
53
- if (isSendingCapsLockStateOniPad) {
35
+ if (isSendingCapsLockState || currentCapsState) {
54
36
  capsState = currentCapsState;
37
+ isSendingCapsLockState = true;
55
38
  }
56
39
  }
57
40
  }
@@ -82,4 +65,3 @@ export function isCapsLockOn() {
82
65
  export function onCapsLockChange(callback) {
83
66
  onCapsChangeCallback = callback;
84
67
  }
85
- //# sourceMappingURL=index.js.map
@@ -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.4",
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
  },
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,SAAS,UAAU,CAAC,MAAc;;IAIhC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAA,MAAA,SAAS,CAAC,aAAa,0CAAE,QAAQ,mCAAI,CAAC,SAAS,CAAC,KAAK,IAAI,SAAS,CAAC,SAAS,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1H,CAAC;AAOD,SAAS,YAAY;IACnB,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAC9B,IAAI,SAAS,GAAG,KAAK,CAAC;AACtB,MAAM,EAAE,GAAG,YAAY,EAAE,CAAC;AAE1B,IAAI,oBAA0C,CAA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