js_lis 1.0.6 → 1.0.7
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/VirtualKeyboard.js +45 -8
- package/layouts.js +42 -42
- package/package.json +1 -1
package/VirtualKeyboard.js
CHANGED
|
@@ -5,17 +5,29 @@ export class VirtualKeyboard {
|
|
|
5
5
|
this.currentLayout = 'en';
|
|
6
6
|
this.isVisible = false;
|
|
7
7
|
this.container = document.getElementById('keyboard-container');
|
|
8
|
-
this.currentInput = null;
|
|
8
|
+
this.currentInput = null;
|
|
9
9
|
this.layouts = layouts;
|
|
10
10
|
this.isDragging = false;
|
|
11
11
|
this.offsetX = 0;
|
|
12
12
|
this.offsetY = 0;
|
|
13
13
|
this.shiftActive = false;
|
|
14
14
|
this.capsLockActive = false;
|
|
15
|
+
|
|
15
16
|
this.render();
|
|
16
17
|
this.initializeInputListeners();
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
|
|
20
|
+
getLayoutName(layout) {
|
|
21
|
+
switch (layout) {
|
|
22
|
+
case 'en': return 'English Keyboard';
|
|
23
|
+
case 'enSc': return 'English scrambled';
|
|
24
|
+
case 'th': return 'Thai keyboard';
|
|
25
|
+
case 'thSc': return 'Thai scrambled';
|
|
26
|
+
case 'numpad': return 'Numpad Keyboard';
|
|
27
|
+
case 'scNum': return 'Scrambled Keyboard';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
19
31
|
initializeInputListeners() {
|
|
20
32
|
// เพิ่ม event listener สำหรับทุก input และ textarea
|
|
21
33
|
document.addEventListener('click', (e) => {
|
|
@@ -49,12 +61,36 @@ export class VirtualKeyboard {
|
|
|
49
61
|
const keyboard = document.createElement('div');
|
|
50
62
|
keyboard.className = 'virtual-keyboard';
|
|
51
63
|
keyboard.style.display = this.isVisible ? 'block' : 'none';
|
|
52
|
-
|
|
64
|
+
|
|
53
65
|
// Add the ID for easy reference in dragging
|
|
54
66
|
keyboard.id = 'keyboard';
|
|
55
|
-
|
|
56
|
-
const layout = this.layouts[this.currentLayout];
|
|
57
67
|
|
|
68
|
+
// New: Add Layout selector at the top inside the keyboard div
|
|
69
|
+
const controlsContainer = document.createElement('div');
|
|
70
|
+
controlsContainer.className = 'controls';
|
|
71
|
+
controlsContainer.style.display = 'flex';
|
|
72
|
+
controlsContainer.style.justifyContent = 'center';
|
|
73
|
+
controlsContainer.style.alignItems = 'center';
|
|
74
|
+
controlsContainer.style.marginBottom = '10px'; // Optional: Add some space below the selector
|
|
75
|
+
|
|
76
|
+
const layoutSelector = document.createElement('select');
|
|
77
|
+
layoutSelector.id = 'layout-selector';
|
|
78
|
+
layoutSelector.onchange = (e) => this.changeLayout(e.target.value);
|
|
79
|
+
|
|
80
|
+
const layouts = ['en', 'enSc', 'th', 'thSc', 'numpad', 'scNum'];
|
|
81
|
+
layouts.forEach(layout => {
|
|
82
|
+
const option = document.createElement('option');
|
|
83
|
+
option.value = layout;
|
|
84
|
+
option.innerText = this.getLayoutName(layout);
|
|
85
|
+
layoutSelector.appendChild(option);
|
|
86
|
+
});
|
|
87
|
+
layoutSelector.value = this.currentLayout;
|
|
88
|
+
controlsContainer.appendChild(layoutSelector);
|
|
89
|
+
|
|
90
|
+
keyboard.appendChild(controlsContainer);
|
|
91
|
+
|
|
92
|
+
const layout = this.layouts[this.currentLayout];
|
|
93
|
+
|
|
58
94
|
layout.forEach(row => {
|
|
59
95
|
const rowElement = document.createElement('div');
|
|
60
96
|
rowElement.className = 'keyboard-row';
|
|
@@ -71,7 +107,7 @@ export class VirtualKeyboard {
|
|
|
71
107
|
if (key === 'Space') {
|
|
72
108
|
keyElement.className += ' space';
|
|
73
109
|
}
|
|
74
|
-
|
|
110
|
+
|
|
75
111
|
if (key === 'backspace') {
|
|
76
112
|
keyElement.className += ' backspacew';
|
|
77
113
|
}
|
|
@@ -85,7 +121,6 @@ export class VirtualKeyboard {
|
|
|
85
121
|
console.error("The key element does not have a valid key value.");
|
|
86
122
|
}
|
|
87
123
|
};
|
|
88
|
-
|
|
89
124
|
|
|
90
125
|
rowElement.appendChild(keyElement);
|
|
91
126
|
});
|
|
@@ -107,11 +142,13 @@ export class VirtualKeyboard {
|
|
|
107
142
|
if (this.currentLayout === "thSc") {
|
|
108
143
|
this.scrambleThaiKeys();
|
|
109
144
|
}
|
|
110
|
-
|
|
145
|
+
|
|
111
146
|
// Add drag functionality to the keyboard
|
|
112
147
|
keyboard.addEventListener('mousedown', (event) => this.startDrag(event));
|
|
113
148
|
}
|
|
114
149
|
|
|
150
|
+
|
|
151
|
+
|
|
115
152
|
handleKeyPress(keyPressed) {
|
|
116
153
|
if (!this.currentInput) return;
|
|
117
154
|
|
package/layouts.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
export const layouts = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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']
|
|
8
|
+
],
|
|
9
|
+
th: [
|
|
10
|
+
['_', 'ๅ', '/', '-', 'ภ', 'ถ', 'ุ', 'ึ', 'ค', 'ต', 'จ', 'ข', 'ช', 'Backspace'],
|
|
11
|
+
['Tab', 'ๆ', 'ไ', 'ำ', 'พ', 'ะ', 'ั', 'ี', 'ร', 'น', 'ย', 'บ', 'ล', 'ฃ'],
|
|
12
|
+
['Caps', 'ฟ', 'ห', 'ก', 'ด', 'เ', '้', '่', 'า', 'ส', 'ว', 'ง', 'Enter'],
|
|
13
|
+
['Shift', 'ผ', 'ป', 'แ', 'อ', 'ิ', 'ื', 'ท', 'ม', 'ใ', 'ฝ', 'Shift'],
|
|
14
|
+
['Space']
|
|
15
|
+
],
|
|
16
|
+
numpad: [
|
|
17
|
+
["+", "-", "*", "/"],
|
|
18
|
+
["1", "2", "3", "%"],
|
|
19
|
+
["4", "5", "6", "."],
|
|
20
|
+
["7", "8", "9", "="],
|
|
21
|
+
["00", "0", "backspace"],
|
|
22
|
+
],
|
|
23
|
+
scNum : [
|
|
24
|
+
["+", "-", "*", "/"],
|
|
25
|
+
["1", "2", "3", "%"],
|
|
26
|
+
["4", "5", "6", "."],
|
|
27
|
+
["7", "8", "9", "="],
|
|
28
|
+
["00", "0", "backspace"],
|
|
29
|
+
],
|
|
30
|
+
thSc : [
|
|
31
|
+
["ก", "ข", "ฃ", "ค", "ฅ", "ฆ", "ง", "จ", "ฉ", "ช", "ซ", "ฌ", "Backspace"],
|
|
32
|
+
["ญ", "ฎ", "ฏ", "ฐ", "ฑ", "ฒ", "ณ", "ด", "ต", "ถ", "ท", "ธ", "น"],
|
|
33
|
+
["บ", "ป", "ผ", "ฝ", "พ", "ฟ", "ภ", "ม", "ย", "ร", "ฤ", "Enter"],
|
|
34
|
+
["ล", "ฦ", "ว", "ศ", "ษ", "ส", "ห", "ฬ", "อ", "ฮ"],
|
|
35
|
+
["Space"],
|
|
36
|
+
],
|
|
37
|
+
enSc: [
|
|
38
|
+
["`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "="],
|
|
39
|
+
["Tab", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "Backspace"],
|
|
40
|
+
["Caps", "a", "s", "d", "f", "g", "h", "j", "k", "l", "Enter"],
|
|
41
|
+
["Shift", "z", "x", "c", "v", "b", "n", "m", "Shift"],
|
|
42
|
+
["Space"],
|
|
43
|
+
],
|
|
44
44
|
};
|