Skip to content

Commit 91e31c9

Browse files
committed
[RZA-250143]: replace keyCode with key
1 parent c80229a commit 91e31c9

File tree

7 files changed

+55
-54
lines changed

7 files changed

+55
-54
lines changed

src/assets/styles/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,4 @@
146146
padding-left: 6rem;
147147
padding-right: 6rem;
148148
}
149-
}
149+
}

src/assets/styles/menu.css

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,27 @@
66
--header-height: 80px;
77
--sidebar-width: 16ch;
88
--timing: 0.42s;
9-
--ease: linear(0 0%,
10-
0.0036 9.62%,
11-
0.0185 16.66%,
12-
0.0489 23.03%,
13-
0.0962 28.86%,
14-
0.1705 34.93%,
15-
0.269 40.66%,
16-
0.3867 45.89%,
17-
0.5833 52.95%,
18-
0.683 57.05%,
19-
0.7829 62.14%,
20-
0.8621 67.46%,
21-
0.8991 70.68%,
22-
0.9299 74.03%,
23-
0.9545 77.52%,
24-
0.9735 81.21%,
25-
0.9865 85%,
26-
0.9949 89.15%,
27-
1 100%);
9+
--ease: linear(
10+
0 0%,
11+
0.0036 9.62%,
12+
0.0185 16.66%,
13+
0.0489 23.03%,
14+
0.0962 28.86%,
15+
0.1705 34.93%,
16+
0.269 40.66%,
17+
0.3867 45.89%,
18+
0.5833 52.95%,
19+
0.683 57.05%,
20+
0.7829 62.14%,
21+
0.8621 67.46%,
22+
0.8991 70.68%,
23+
0.9299 74.03%,
24+
0.9545 77.52%,
25+
0.9735 81.21%,
26+
0.9865 85%,
27+
0.9949 89.15%,
28+
1 100%
29+
);
2830
--sidebar-collapsed: 4rem;
2931
--sidebar-expanded: 16ch;
3032
--icon-size: 1.5rem;
@@ -529,4 +531,4 @@
529531
[data-theme="system"] [popover] .nav--list__item:hover a {
530532
color: var(--primary);
531533
}
532-
}
534+
}

src/layouts/Base.astro

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import Shortcut from "@/components/Shortcut.astro";
99
1010
const {
1111
meta: { title, description = siteConfig.description, ogImage },
12-
sidebar = true,
13-
meta
12+
sidebar = true
1413
} = Astro.props;
1514
---
1615

@@ -39,7 +38,7 @@ const {
3938
.getRegistrations()
4039
.then((registrations) => {
4140
// Unregister all existing service workers
42-
const unregisterPromises = registrations.map((registration) => {
41+
const unregisterPromises = registrations.map(async (registration) => {
4342
return registration.unregister().then((success) => {
4443
if (success) {
4544
console.log("Successfully unregistered service worker:", registration.scope);

src/pages/alphabets/[alphabet]/playground.astro

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,20 @@ const meta = {
180180
}
181181
} else {
182182
// Default behavior for other alphabets (A-Z, 0-9)
183-
const { key, keyCode } = e;
184-
const isAlphabet = keyCode >= 65 && keyCode <= 90;
185-
const isNumber = keyCode >= 48 && keyCode <= 57;
183+
const { key } = e;
184+
const isAlphabet = /^[A-Za-z]$/.test(key);
185+
console.log({ isAlphabet });
186+
const isNumber = /^[0-9]$/.test(key);
187+
console.log({ isNumber });
186188
if (isAlphabet) {
187189
const keyCapital = key.toUpperCase();
188190
const info = alphabetData.find((item) => item.letter.toUpperCase() === keyCapital || item.letter === key);
189191
if (info) drawInfo(info, random(colorBox));
190-
} else if (isNumber) {
191-
const info = alphabetData.find((item) => item.letter === key);
192-
if (info) drawInfo(info, random(colorBox));
193192
}
193+
//else if (isNumber) {
194+
// const info = alphabetData.find((item) => item.letter === key);
195+
// if (info) drawInfo(info, random(colorBox));
196+
//}
194197
}
195198
},
196199
false

src/pages/panel.astro

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ const meta = {
123123
</BaseLayout>
124124
<script>
125125
enum ArrowKeys {
126-
LEFT = 37,
127-
UP = 38,
128-
RIGHT = 39,
129-
DOWN = 40
126+
LEFT = "ArrowLeft",
127+
UP = "ArrowUp",
128+
RIGHT = "ArrowRight",
129+
DOWN = "ArrowDown"
130130
}
131131

132132
enum ContentType {
@@ -171,8 +171,8 @@ const meta = {
171171

172172
#emitEvent() {
173173
document.addEventListener("keyup", (e: KeyboardEvent) => {
174-
const { charCode, code, keyCode, key } = e;
175-
this.onKeyChange(keyCode);
174+
const { key } = e;
175+
this.onKeyChange(key);
176176
});
177177

178178
this.#orientationPanel.forEach((radio) => {
@@ -328,12 +328,12 @@ const meta = {
328328
this.#panel.style.transform = transformString;
329329
}
330330

331-
onKeyChange(code: number) {
331+
onKeyChange(key: string) {
332332
const VerticalButton = this.#orientationPanel[0] as HTMLInputElement;
333333
const horizontalButton = this.#orientationPanel[1] as HTMLInputElement;
334334
const currentPanelSize = Number(this.#cellRange.value);
335335

336-
switch (code) {
336+
switch (key) {
337337
case ArrowKeys.RIGHT: {
338338
if (this.#orientation === "Y") {
339339
this.#selectedIndex--;
@@ -368,22 +368,23 @@ const meta = {
368368
}
369369
default: {
370370
// Handle character input (alphabets and numbers)
371+
const char = key.toUpperCase();
371372
if (this.#contentType === ContentType.ALPHABET) {
372-
if (code >= 65 && code <= 90) {
373+
if (/^[A-Z]$/.test(key)) {
373374
// A-Z (uppercase)
374-
this.#selectedIndex = (65 - code + currentPanelSize) % currentPanelSize; // Calculate index relative to A
375-
} else if (code >= 97 && code <= 122) {
375+
this.#selectedIndex = (65 - char.charCodeAt(0) + currentPanelSize) % currentPanelSize; // Calculate index relative to A
376+
} else if (/^[a-z]$/.test(key)) {
376377
// a-z (lowercase)
377-
this.#selectedIndex = (97 - code + currentPanelSize) % currentPanelSize; // Calculate index relative to a
378+
this.#selectedIndex = (97 - char.charCodeAt(0) + currentPanelSize) % currentPanelSize; // Calculate index relative to a
378379
} else {
379380
// If not an alphabet, just move forward
380381
this.#selectedIndex++;
381382
}
382383
} else {
383384
// ContentType.NUMBERS
384-
if (code >= 48 && code <= 57) {
385+
if (/^[0-9]$/.test(key)) {
385386
// 0-9
386-
this.#selectedIndex = (48 - code + currentPanelSize) % currentPanelSize; // Calculate index relative to 0
387+
this.#selectedIndex = (48 - char.charCodeAt(0) + currentPanelSize) % currentPanelSize; // Calculate index relative to 0
387388
} else {
388389
// If not a number, just move forward
389390
this.#selectedIndex++;

src/pages/varnmala/listen.astro

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const meta = {
4949

5050
<script>
5151
import { emojiList } from "@/mappers/alphabet";
52-
import { getRandomValue, isAlphabet, isNumber } from "@/utils/index";
52+
import { getRandomValue } from "@/utils/index";
5353

5454
const mainBlock = document.querySelector("#letter") as HTMLElement;
5555
const muteButton = document.querySelector("#mute") as HTMLButtonElement;
@@ -176,15 +176,15 @@ const meta = {
176176
};
177177

178178
document.addEventListener("keydown", (e: KeyboardEvent) => {
179-
const { key, keyCode, which, code } = e;
179+
const { key, code } = e;
180180
if (!mainBlock) return;
181181

182182
if (!isNonPrintingKey(e)) {
183-
if (isAlphabet(which)) {
183+
if (/^[A-Z]$/i.test(key)) {
184184
const emoji = getEmoji(key);
185185
mainBlock.innerHTML = key + emoji;
186186
if (muteButton) attachAudio(code);
187-
} else if (isNumber(keyCode)) {
187+
} else if (/^[0-9]$/.test(key)) {
188188
mainBlock.innerHTML = key;
189189
if (muteButton) attachAudio(code, true);
190190
} else {

src/pages/varnmala/play.astro

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ const meta = {
7575
let lastKey: string | null = null; // Store the last key pressed
7676
let isMuted = false; // Flag to track mute state
7777

78-
function isAlphabet(keyCode: number): boolean {
79-
return keyCode >= 65 && keyCode <= 90;
80-
}
81-
8278
function speak(text: string) {
8379
if (isMuted) return; // Do not speak if muted
8480

@@ -129,9 +125,9 @@ const meta = {
129125
"keydown",
130126
(e) => {
131127
e.preventDefault();
132-
const { key, keyCode } = e;
128+
const { key } = e;
133129

134-
if (isAlphabet(keyCode)) {
130+
if (/^[0-9]$/.test(key)) {
135131
const upperKey = key.toUpperCase();
136132
let isDouble = false;
137133
let doublePress;

0 commit comments

Comments
 (0)