js_lis 1.0.17 → 1.0.18

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.
@@ -262,88 +262,138 @@ export class VirtualKeyboard {
262
262
  this.currentInput.value = this.currentInput.value.slice(0, start) + decodedText + this.currentInput.value.slice(end);
263
263
  this.currentInput.selectionStart = this.currentInput.selectionEnd = start + decodedText.length;
264
264
  }
265
-
265
+
266
266
  toggleCapsLock() {
267
267
  this.capsLockActive = !this.capsLockActive;
268
- const capsKey = document.querySelector('.key[data-key="Caps"]');
269
- capsKey.classList.toggle("active", this.capsLockActive);
270
- capsKey.classList.toggle("bg-gray-400", this.capsLockActive);
268
+ document.querySelectorAll('.key[data-key="Caps"]').forEach((key) => {
269
+ key.classList.toggle("active", this.capsLockActive);
270
+ key.classList.toggle("bg-gray-400", this.capsLockActive);
271
+ });
271
272
 
272
273
  document.querySelectorAll(".key").forEach((key) => {
273
- if (key.dataset.key.length === 1 && /[a-zA-Zก-๙]/.test(key.dataset.key)) {
274
- key.textContent = this.capsLockActive
275
- ? key.dataset.key.toUpperCase()
276
- : key.dataset.key.toLowerCase();
277
- }
274
+ if (key.dataset.key.length === 1 && /[a-zA-Zก-๙]/.test(key.dataset.key)) {
275
+ key.textContent = this.capsLockActive
276
+ ? key.dataset.key.toUpperCase()
277
+ : key.dataset.key.toLowerCase();
278
+ }
278
279
  });
279
280
 
280
- const keyboardKeys = document.querySelectorAll(".key:not([data-key='Shift'])");
281
+ const keyboardKeys = document.querySelectorAll(
282
+ ".key:not([data-key='Shift'])"
283
+ );
281
284
  keyboardKeys.forEach((key) => {
282
- const currentChar = key.textContent.trim();
283
- if (
284
- this.capsLockActive &&
285
- this.currentLayout === "th" &&
286
- this.ThaiAlphabetShift[currentChar]
287
- ) {
288
- key.textContent = this.ThaiAlphabetShift[currentChar];
289
- key.dataset.key = this.ThaiAlphabetShift[currentChar];
290
- } else if (
291
- !this.capsLockActive &&
292
- this.currentLayout === "th" &&
293
- Object.values(this.ThaiAlphabetShift).includes(currentChar)
294
- ) {
295
- const originalKey = Object.keys(this.ThaiAlphabetShift).find(
296
- (key) => this.ThaiAlphabetShift[key] === currentChar
297
- );
298
- if (originalKey) {
299
- key.textContent = originalKey;
300
- key.dataset.key = originalKey;
301
- }
285
+ const currentChar = key.textContent.trim();
286
+ if (
287
+ this.capsLockActive &&
288
+ this.currentLayout === "th" &&
289
+ this.ThaiAlphabetShift[currentChar]
290
+ ) {
291
+ key.textContent = this.ThaiAlphabetShift[currentChar];
292
+ key.dataset.key = this.ThaiAlphabetShift[currentChar];
293
+ } else if (
294
+ !this.capsLockActive &&
295
+ this.currentLayout === "th" &&
296
+ Object.values(this.ThaiAlphabetShift).includes(currentChar)
297
+ ) {
298
+ // เปลี่ยนกลับเมื่อปิด Shift
299
+ const originalKey = Object.keys(ThaiAlphabetShift).find(
300
+ (key) => this.ThaiAlphabetShift[key] === currentChar
301
+ );
302
+ if (originalKey) {
303
+ key.textContent = originalKey;
304
+ key.dataset.key = originalKey;
305
+ }
306
+ }
307
+
308
+ // Shift state for English layout
309
+ if (this.capsLockActive && this.currentLayout === "en") {
310
+ if (EngAlphabetShift[key.dataset.key]) {
311
+ key.textContent = this.EngAlphabetShift[key.dataset.key];
312
+ key.dataset.key = this.EngAlphabetShift[key.dataset.key];
302
313
  }
314
+ } else if (!this.capsLockActive && this.currentLayout === "en") {
315
+ // Revert when shift is off
316
+ if (Object.values(EngAlphabetShift).includes(currentChar)) {
317
+ const originalKey = Object.keys(EngAlphabetShift).find(
318
+ (key) => EngAlphabetShift[key] === currentChar
319
+ );
320
+ if (originalKey) {
321
+ key.textContent = originalKey;
322
+ key.dataset.key = originalKey;
323
+ }
324
+ }
325
+ }
303
326
  });
304
327
  }
305
-
328
+
306
329
  toggleShift() {
307
330
  this.shiftActive = !this.shiftActive;
308
- const shiftKey = document.querySelector('.key[data-key="Shift"]');
309
- shiftKey.classList.toggle("active", this.shiftActive);
310
- shiftKey.classList.toggle("bg-gray-400", this.shiftActive);
331
+ document.querySelectorAll('.key[data-key="Shift"]').forEach((key) => {
332
+ key.classList.toggle("active", this.shiftActive);
333
+ key.classList.toggle("bg-gray-400", this.shiftActive);
334
+ });
311
335
 
312
336
  document.querySelectorAll(".key").forEach((key) => {
313
- if (key.dataset.key.length === 1 && /[a-zA-Zก-๙]/.test(key.dataset.key)) {
314
- // แสดงผลตัวพิมพ์ใหญ่หรือเล็กตามค่า Shift
315
- key.textContent = this.shiftActive
316
- ? key.dataset.key.toUpperCase()
317
- : key.dataset.key.toLowerCase();
318
- }
337
+ if (key.dataset.key.length === 1 && /[a-zA-Zก-๙]/.test(key.dataset.key)) {
338
+ key.textContent = this.shiftActive
339
+ ? key.dataset.key.toUpperCase()
340
+ : key.dataset.key.toLowerCase();
341
+ }
319
342
  });
320
343
 
321
- const keyboardKeys = document.querySelectorAll(".key:not([data-key='Shift'])");
344
+ const keyboardKeys = document.querySelectorAll(
345
+ ".key:not([data-key='Shift'])"
346
+ );
322
347
  keyboardKeys.forEach((key) => {
323
- const currentChar = key.textContent.trim();
324
- if (
325
- this.shiftActive &&
326
- this.currentLayout === "th" && // ตรวจสอบว่ากำลังใช้เลย์เอาต์ภาษาไทย
327
- this.ThaiAlphabetShift[currentChar]
328
- ) {
329
- key.textContent = this.ThaiAlphabetShift[currentChar]; // แสดงอักษรจาก shift
330
- key.dataset.key = this.ThaiAlphabetShift[currentChar]; // อัปเดต dataset.key
331
- } else if (
332
- !this.shiftActive &&
333
- this.currentLayout === "th" &&
334
- Object.values(this.ThaiAlphabetShift).includes(currentChar)
335
- ) {
336
- const originalKey = Object.keys(this.ThaiAlphabetShift).find(
337
- (key) => this.ThaiAlphabetShift[key] === currentChar
338
- );
339
- if (originalKey) {
340
- key.textContent = originalKey;
341
- key.dataset.key = originalKey;
342
- }
348
+ const currentChar = key.textContent.trim();
349
+ if (
350
+ this.shiftActive &&
351
+ this.currentLayout === "th" &&
352
+ this.ThaiAlphabetShift[currentChar]
353
+ ) {
354
+ key.textContent = this.ThaiAlphabetShift[currentChar];
355
+ key.dataset.key = this.ThaiAlphabetShift[currentChar];
356
+ } else if (
357
+ !this.shiftActive &&
358
+ this.currentLayout === "th" &&
359
+ Object.values(this.ThaiAlphabetShift).includes(currentChar)
360
+ ) {
361
+ // เปลี่ยนกลับเมื่อปิด Shift
362
+ const originalKey = Object.keys(ThaiAlphabetShift).find(
363
+ (key) => this.ThaiAlphabetShift[key] === currentChar
364
+ );
365
+ if (originalKey) {
366
+ key.textContent = originalKey;
367
+ key.dataset.key = originalKey;
343
368
  }
369
+ }
370
+
371
+ // Shift state for English layout
372
+ if (this.shiftActive && this.currentLayout === "en") {
373
+ if (EngAlphabetShift[key.dataset.key]) {
374
+ key.textContent = this.EngAlphabetShift[key.dataset.key];
375
+ key.dataset.key = this.EngAlphabetShift[key.dataset.key];
376
+ }
377
+ } else if (!this.shiftActive && this.currentLayout === "en") {
378
+ // Revert when shift is off
379
+ if (Object.values(EngAlphabetShift).includes(currentChar)) {
380
+ const originalKey = Object.keys(EngAlphabetShift).find(
381
+ (key) => EngAlphabetShift[key] === currentChar
382
+ );
383
+ if (originalKey) {
384
+ key.textContent = originalKey;
385
+ key.dataset.key = originalKey;
386
+ }
387
+ }
388
+ }
344
389
  });
345
390
  }
346
391
 
392
+ EngAlphabetShift = {
393
+ "`": "~", 1: "!", 2: "@", 3: "#", 4: "$", 5: "%", 6: "^", 7: "&", 8: "*", 9: "(", 0: ")", "-": "_", "=": "+",
394
+ "[": "{", "]": "}", "\\": "|", ";": ":", "'": '"', ",": "<", ".": ">", "/": "?"
395
+ };
396
+
347
397
  ThaiAlphabetShift = {
348
398
  _: "%",
349
399
  ๅ: "+",
package/layouts.js CHANGED
@@ -1,17 +1,17 @@
1
1
  export const layouts = {
2
2
  en: [
3
- ['`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 'Backspace'],
4
- ['Tab', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\'],
5
- ['Caps', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', 'Enter'],
6
- ['Shift', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 'Shift'],
7
- ['Space']
3
+ ["`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "Backspace"],
4
+ ["Tab", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", "\\"],
5
+ ["Caps", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "Enter"],
6
+ ["Shift", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "Shift"],
7
+ ["Space"],
8
8
  ],
9
9
  th: [
10
- ['_', '', '/', '-', '', '', '', '', '', '', '', '', '', 'Backspace'],
11
- ['Tab', '', '', '', '', '', '', '', '', '', '', '', '', ''],
12
- ['Caps', '', '', '', '', '', '', '', '', '', '', '', 'Enter'],
13
- ['Shift', '', '', '', '', '', '', '', '', '', '', 'Shift'],
14
- ['Space']
10
+ ["_", "", "/", "-", "", "", "", "", "", "", "", "", "", "Backspace"],
11
+ ["Tab", "", "", "", "", "", "", "", "", "", "", "", "", ""],
12
+ ["Caps", "", "", "", "", "", "", "", "", "", "", "", "Enter"],
13
+ ["Shift", "", "", "", "", "", "", "", "", "", "", "Shift"],
14
+ ["Space"],
15
15
  ],
16
16
  numpad: [
17
17
  ["+", "-", "*", "/"],
@@ -20,14 +20,14 @@ export const layouts = {
20
20
  ["7", "8", "9", "="],
21
21
  ["00", "0", "backspace"],
22
22
  ],
23
- scNum : [
23
+ scNum: [
24
24
  ["+", "-", "*", "/"],
25
25
  ["1", "2", "3", "%"],
26
26
  ["4", "5", "6", "."],
27
27
  ["7", "8", "9", "="],
28
28
  ["00", "0", "backspace"],
29
29
  ],
30
- thSc : [
30
+ thSc: [
31
31
  ["ก", "ข", "ฃ", "ค", "ฅ", "ฆ", "ง", "จ", "ฉ", "ช", "ซ", "ฌ", "Backspace"],
32
32
  ["ญ", "ฎ", "ฏ", "ฐ", "ฑ", "ฒ", "ณ", "ด", "ต", "ถ", "ท", "ธ", "น"],
33
33
  ["บ", "ป", "ผ", "ฝ", "พ", "ฟ", "ภ", "ม", "ย", "ร", "ฤ", "Enter"],
@@ -41,4 +41,4 @@ export const layouts = {
41
41
  ["Shift", "z", "x", "c", "v", "b", "n", "m", "Shift"],
42
42
  ["Space"],
43
43
  ],
44
- };
44
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js_lis",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"