js_lis 1.0.18 → 1.0.19

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 (2) hide show
  1. package/VirtualKeyboard.js +79 -73
  2. package/package.json +1 -1
@@ -264,15 +264,81 @@ export class VirtualKeyboard {
264
264
  }
265
265
 
266
266
  toggleCapsLock() {
267
- this.capsLockActive = !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);
267
+ this.capsLockActive = !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
+ });
272
+
273
+ document.querySelectorAll(".key").forEach((key) => {
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
+ }
279
+ });
280
+
281
+ const keyboardKeys = document.querySelectorAll(
282
+ ".key:not([data-key='Caps'])"
283
+ );
284
+ keyboardKeys.forEach((key) => {
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
+ if (
309
+ this.capsLockActive &&
310
+ this.currentLayout === "th" &&
311
+ this.EngAlphabetShift[currentChar]
312
+ ) {
313
+ key.textContent = this.EngAlphabetShift[currentChar];
314
+ key.dataset.key = this.EngAlphabetShift[currentChar];
315
+ } else if (
316
+ !this.capsLockActive &&
317
+ this.currentLayout === "th" &&
318
+ Object.values(this.EngAlphabetShift).includes(currentChar)
319
+ ) {
320
+ // เปลี่ยนกลับเมื่อปิด Shift
321
+ const originalKey = Object.keys(EngAlphabetShift).find(
322
+ (key) => this.EngAlphabetShift[key] === currentChar
323
+ );
324
+ if (originalKey) {
325
+ key.textContent = originalKey;
326
+ key.dataset.key = originalKey;
327
+ }
328
+ }
329
+ });
330
+ }
331
+
332
+ toggleShift() {
333
+ this.shiftActive = !this.shiftActive;
334
+ document.querySelectorAll('.key[data-key="Shift"]').forEach((key) => {
335
+ key.classList.toggle("active", this.shiftActive);
336
+ key.classList.toggle("bg-gray-400", this.shiftActive);
271
337
  });
272
338
 
273
339
  document.querySelectorAll(".key").forEach((key) => {
274
340
  if (key.dataset.key.length === 1 && /[a-zA-Zก-๙]/.test(key.dataset.key)) {
275
- key.textContent = this.capsLockActive
341
+ key.textContent = this.shiftActive
276
342
  ? key.dataset.key.toUpperCase()
277
343
  : key.dataset.key.toLowerCase();
278
344
  }
@@ -284,14 +350,14 @@ export class VirtualKeyboard {
284
350
  keyboardKeys.forEach((key) => {
285
351
  const currentChar = key.textContent.trim();
286
352
  if (
287
- this.capsLockActive &&
353
+ this.shiftActive &&
288
354
  this.currentLayout === "th" &&
289
355
  this.ThaiAlphabetShift[currentChar]
290
356
  ) {
291
357
  key.textContent = this.ThaiAlphabetShift[currentChar];
292
358
  key.dataset.key = this.ThaiAlphabetShift[currentChar];
293
359
  } else if (
294
- !this.capsLockActive &&
360
+ !this.shiftActive &&
295
361
  this.currentLayout === "th" &&
296
362
  Object.values(this.ThaiAlphabetShift).includes(currentChar)
297
363
  ) {
@@ -304,88 +370,28 @@ export class VirtualKeyboard {
304
370
  key.dataset.key = originalKey;
305
371
  }
306
372
  }
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];
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
- }
326
- });
327
- }
328
373
 
329
- toggleShift() {
330
- this.shiftActive = !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
- });
335
-
336
- document.querySelectorAll(".key").forEach((key) => {
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
- }
342
- });
343
-
344
- const keyboardKeys = document.querySelectorAll(
345
- ".key:not([data-key='Shift'])"
346
- );
347
- keyboardKeys.forEach((key) => {
348
- const currentChar = key.textContent.trim();
349
374
  if (
350
375
  this.shiftActive &&
351
376
  this.currentLayout === "th" &&
352
- this.ThaiAlphabetShift[currentChar]
377
+ this.EngAlphabetShift[currentChar]
353
378
  ) {
354
- key.textContent = this.ThaiAlphabetShift[currentChar];
355
- key.dataset.key = this.ThaiAlphabetShift[currentChar];
379
+ key.textContent = this.EngAlphabetShift[currentChar];
380
+ key.dataset.key = this.EngAlphabetShift[currentChar];
356
381
  } else if (
357
382
  !this.shiftActive &&
358
383
  this.currentLayout === "th" &&
359
- Object.values(this.ThaiAlphabetShift).includes(currentChar)
384
+ Object.values(this.EngAlphabetShift).includes(currentChar)
360
385
  ) {
361
386
  // เปลี่ยนกลับเมื่อปิด Shift
362
- const originalKey = Object.keys(ThaiAlphabetShift).find(
363
- (key) => this.ThaiAlphabetShift[key] === currentChar
387
+ const originalKey = Object.keys(EngAlphabetShift).find(
388
+ (key) => this.EngAlphabetShift[key] === currentChar
364
389
  );
365
390
  if (originalKey) {
366
391
  key.textContent = originalKey;
367
392
  key.dataset.key = originalKey;
368
393
  }
369
394
  }
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
- }
389
395
  });
390
396
  }
391
397
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js_lis",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"