js_lis 1.0.6 → 1.0.8
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 +51 -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) => {
|
|
@@ -32,6 +44,11 @@ export class VirtualKeyboard {
|
|
|
32
44
|
this.setCurrentInput(target);
|
|
33
45
|
}
|
|
34
46
|
}, true);
|
|
47
|
+
|
|
48
|
+
document.addEventListener('click', (e) => {
|
|
49
|
+
const target = document.getElementById("toggle");
|
|
50
|
+
target.addEventListener('click', this.toggle.bind(this), { once: true });
|
|
51
|
+
});
|
|
35
52
|
}
|
|
36
53
|
|
|
37
54
|
setCurrentInput(inputElement) {
|
|
@@ -49,12 +66,36 @@ export class VirtualKeyboard {
|
|
|
49
66
|
const keyboard = document.createElement('div');
|
|
50
67
|
keyboard.className = 'virtual-keyboard';
|
|
51
68
|
keyboard.style.display = this.isVisible ? 'block' : 'none';
|
|
52
|
-
|
|
69
|
+
|
|
53
70
|
// Add the ID for easy reference in dragging
|
|
54
71
|
keyboard.id = 'keyboard';
|
|
55
|
-
|
|
56
|
-
const layout = this.layouts[this.currentLayout];
|
|
57
72
|
|
|
73
|
+
// New: Add Layout selector at the top inside the keyboard div
|
|
74
|
+
const controlsContainer = document.createElement('div');
|
|
75
|
+
controlsContainer.className = 'controls';
|
|
76
|
+
controlsContainer.style.display = 'flex';
|
|
77
|
+
controlsContainer.style.justifyContent = 'center';
|
|
78
|
+
controlsContainer.style.alignItems = 'center';
|
|
79
|
+
controlsContainer.style.marginBottom = '10px'; // Optional: Add some space below the selector
|
|
80
|
+
|
|
81
|
+
const layoutSelector = document.createElement('select');
|
|
82
|
+
layoutSelector.id = 'layout-selector';
|
|
83
|
+
layoutSelector.onchange = (e) => this.changeLayout(e.target.value);
|
|
84
|
+
|
|
85
|
+
const layouts = ['en', 'enSc', 'th', 'thSc', 'numpad', 'scNum'];
|
|
86
|
+
layouts.forEach(layout => {
|
|
87
|
+
const option = document.createElement('option');
|
|
88
|
+
option.value = layout;
|
|
89
|
+
option.innerText = this.getLayoutName(layout);
|
|
90
|
+
layoutSelector.appendChild(option);
|
|
91
|
+
});
|
|
92
|
+
layoutSelector.value = this.currentLayout;
|
|
93
|
+
controlsContainer.appendChild(layoutSelector);
|
|
94
|
+
|
|
95
|
+
keyboard.appendChild(controlsContainer);
|
|
96
|
+
|
|
97
|
+
const layout = this.layouts[this.currentLayout];
|
|
98
|
+
|
|
58
99
|
layout.forEach(row => {
|
|
59
100
|
const rowElement = document.createElement('div');
|
|
60
101
|
rowElement.className = 'keyboard-row';
|
|
@@ -71,7 +112,7 @@ export class VirtualKeyboard {
|
|
|
71
112
|
if (key === 'Space') {
|
|
72
113
|
keyElement.className += ' space';
|
|
73
114
|
}
|
|
74
|
-
|
|
115
|
+
|
|
75
116
|
if (key === 'backspace') {
|
|
76
117
|
keyElement.className += ' backspacew';
|
|
77
118
|
}
|
|
@@ -85,7 +126,6 @@ export class VirtualKeyboard {
|
|
|
85
126
|
console.error("The key element does not have a valid key value.");
|
|
86
127
|
}
|
|
87
128
|
};
|
|
88
|
-
|
|
89
129
|
|
|
90
130
|
rowElement.appendChild(keyElement);
|
|
91
131
|
});
|
|
@@ -107,11 +147,13 @@ export class VirtualKeyboard {
|
|
|
107
147
|
if (this.currentLayout === "thSc") {
|
|
108
148
|
this.scrambleThaiKeys();
|
|
109
149
|
}
|
|
110
|
-
|
|
150
|
+
|
|
111
151
|
// Add drag functionality to the keyboard
|
|
112
152
|
keyboard.addEventListener('mousedown', (event) => this.startDrag(event));
|
|
113
153
|
}
|
|
114
154
|
|
|
155
|
+
|
|
156
|
+
|
|
115
157
|
handleKeyPress(keyPressed) {
|
|
116
158
|
if (!this.currentInput) return;
|
|
117
159
|
|
|
@@ -397,4 +439,5 @@ export class VirtualKeyboard {
|
|
|
397
439
|
keyboard.style.top = `${event.clientY - this.offsetY}px`;
|
|
398
440
|
}
|
|
399
441
|
}
|
|
442
|
+
|
|
400
443
|
}
|
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
|
};
|