@uiwwsw/virtual-keyboard 0.3.0 → 0.3.2
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/README.md +31 -29
- package/dist/index.js +1259 -0
- package/package.json +9 -2
- package/dist/assets/index-D9g-NLqn.js +0 -94
- package/dist/index.html +0 -13
- package/dist/vite.svg +0 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,1259 @@
|
|
|
1
|
+
// src/components/Input.tsx
|
|
2
|
+
import {
|
|
3
|
+
useState as useState2,
|
|
4
|
+
useMemo,
|
|
5
|
+
useCallback,
|
|
6
|
+
useId,
|
|
7
|
+
useImperativeHandle,
|
|
8
|
+
useEffect as useEffect2,
|
|
9
|
+
useRef
|
|
10
|
+
} from "react";
|
|
11
|
+
|
|
12
|
+
// node_modules/es-hangul/dist/index.mjs
|
|
13
|
+
function excludeLastElement(array) {
|
|
14
|
+
const lastElement = array[array.length - 1];
|
|
15
|
+
return [array.slice(0, -1), lastElement != null ? lastElement : ""];
|
|
16
|
+
}
|
|
17
|
+
function joinString(...args) {
|
|
18
|
+
return args.join("");
|
|
19
|
+
}
|
|
20
|
+
function isBlank(character) {
|
|
21
|
+
return /^\s$/.test(character);
|
|
22
|
+
}
|
|
23
|
+
function assert(condition, errorMessage) {
|
|
24
|
+
if (condition === false) {
|
|
25
|
+
throw new Error(errorMessage != null ? errorMessage : "Invalid condition");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function hasValueInReadOnlyStringList(list, value) {
|
|
29
|
+
return list.some((item) => item === value);
|
|
30
|
+
}
|
|
31
|
+
function hasProperty(obj, key) {
|
|
32
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
33
|
+
}
|
|
34
|
+
var _JASO_HANGUL_NFD = [..."각힣".normalize("NFD")].map((char) => char.charCodeAt(0));
|
|
35
|
+
var COMPLETE_HANGUL_START_CHARCODE = "가".charCodeAt(0);
|
|
36
|
+
var COMPLETE_HANGUL_END_CHARCODE = "힣".charCodeAt(0);
|
|
37
|
+
var NUMBER_OF_JONGSEONG = 28;
|
|
38
|
+
var NUMBER_OF_JUNGSEONG = 21;
|
|
39
|
+
var DISASSEMBLED_CONSONANTS_BY_CONSONANT = {
|
|
40
|
+
"": "",
|
|
41
|
+
ㄱ: "ㄱ",
|
|
42
|
+
ㄲ: "ㄲ",
|
|
43
|
+
ㄳ: "ㄱㅅ",
|
|
44
|
+
ㄴ: "ㄴ",
|
|
45
|
+
ㄵ: "ㄴㅈ",
|
|
46
|
+
ㄶ: "ㄴㅎ",
|
|
47
|
+
ㄷ: "ㄷ",
|
|
48
|
+
ㄸ: "ㄸ",
|
|
49
|
+
ㄹ: "ㄹ",
|
|
50
|
+
ㄺ: "ㄹㄱ",
|
|
51
|
+
ㄻ: "ㄹㅁ",
|
|
52
|
+
ㄼ: "ㄹㅂ",
|
|
53
|
+
ㄽ: "ㄹㅅ",
|
|
54
|
+
ㄾ: "ㄹㅌ",
|
|
55
|
+
ㄿ: "ㄹㅍ",
|
|
56
|
+
ㅀ: "ㄹㅎ",
|
|
57
|
+
ㅁ: "ㅁ",
|
|
58
|
+
ㅂ: "ㅂ",
|
|
59
|
+
ㅃ: "ㅃ",
|
|
60
|
+
ㅄ: "ㅂㅅ",
|
|
61
|
+
ㅅ: "ㅅ",
|
|
62
|
+
ㅆ: "ㅆ",
|
|
63
|
+
ㅇ: "ㅇ",
|
|
64
|
+
ㅈ: "ㅈ",
|
|
65
|
+
ㅉ: "ㅉ",
|
|
66
|
+
ㅊ: "ㅊ",
|
|
67
|
+
ㅋ: "ㅋ",
|
|
68
|
+
ㅌ: "ㅌ",
|
|
69
|
+
ㅍ: "ㅍ",
|
|
70
|
+
ㅎ: "ㅎ"
|
|
71
|
+
};
|
|
72
|
+
var DISASSEMBLED_VOWELS_BY_VOWEL = {
|
|
73
|
+
ㅏ: "ㅏ",
|
|
74
|
+
ㅐ: "ㅐ",
|
|
75
|
+
ㅑ: "ㅑ",
|
|
76
|
+
ㅒ: "ㅒ",
|
|
77
|
+
ㅓ: "ㅓ",
|
|
78
|
+
ㅔ: "ㅔ",
|
|
79
|
+
ㅕ: "ㅕ",
|
|
80
|
+
ㅖ: "ㅖ",
|
|
81
|
+
ㅗ: "ㅗ",
|
|
82
|
+
ㅘ: "ㅗㅏ",
|
|
83
|
+
ㅙ: "ㅗㅐ",
|
|
84
|
+
ㅚ: "ㅗㅣ",
|
|
85
|
+
ㅛ: "ㅛ",
|
|
86
|
+
ㅜ: "ㅜ",
|
|
87
|
+
ㅝ: "ㅜㅓ",
|
|
88
|
+
ㅞ: "ㅜㅔ",
|
|
89
|
+
ㅟ: "ㅜㅣ",
|
|
90
|
+
ㅠ: "ㅠ",
|
|
91
|
+
ㅡ: "ㅡ",
|
|
92
|
+
ㅢ: "ㅡㅣ",
|
|
93
|
+
ㅣ: "ㅣ"
|
|
94
|
+
};
|
|
95
|
+
var CHOSEONGS = [
|
|
96
|
+
"ㄱ",
|
|
97
|
+
"ㄲ",
|
|
98
|
+
"ㄴ",
|
|
99
|
+
"ㄷ",
|
|
100
|
+
"ㄸ",
|
|
101
|
+
"ㄹ",
|
|
102
|
+
"ㅁ",
|
|
103
|
+
"ㅂ",
|
|
104
|
+
"ㅃ",
|
|
105
|
+
"ㅅ",
|
|
106
|
+
"ㅆ",
|
|
107
|
+
"ㅇ",
|
|
108
|
+
"ㅈ",
|
|
109
|
+
"ㅉ",
|
|
110
|
+
"ㅊ",
|
|
111
|
+
"ㅋ",
|
|
112
|
+
"ㅌ",
|
|
113
|
+
"ㅍ",
|
|
114
|
+
"ㅎ"
|
|
115
|
+
];
|
|
116
|
+
var JUNSEONGS = Object.values(DISASSEMBLED_VOWELS_BY_VOWEL);
|
|
117
|
+
var JONGSEONGS = [
|
|
118
|
+
"",
|
|
119
|
+
"ㄱ",
|
|
120
|
+
"ㄲ",
|
|
121
|
+
"ㄳ",
|
|
122
|
+
"ㄴ",
|
|
123
|
+
"ㄵ",
|
|
124
|
+
"ㄶ",
|
|
125
|
+
"ㄷ",
|
|
126
|
+
"ㄹ",
|
|
127
|
+
"ㄺ",
|
|
128
|
+
"ㄻ",
|
|
129
|
+
"ㄼ",
|
|
130
|
+
"ㄽ",
|
|
131
|
+
"ㄾ",
|
|
132
|
+
"ㄿ",
|
|
133
|
+
"ㅀ",
|
|
134
|
+
"ㅁ",
|
|
135
|
+
"ㅂ",
|
|
136
|
+
"ㅄ",
|
|
137
|
+
"ㅅ",
|
|
138
|
+
"ㅆ",
|
|
139
|
+
"ㅇ",
|
|
140
|
+
"ㅈ",
|
|
141
|
+
"ㅊ",
|
|
142
|
+
"ㅋ",
|
|
143
|
+
"ㅌ",
|
|
144
|
+
"ㅍ",
|
|
145
|
+
"ㅎ"
|
|
146
|
+
].map((consonant) => DISASSEMBLED_CONSONANTS_BY_CONSONANT[consonant]);
|
|
147
|
+
var HANGUL_DIGITS = [
|
|
148
|
+
"",
|
|
149
|
+
"만",
|
|
150
|
+
"억",
|
|
151
|
+
"조",
|
|
152
|
+
"경",
|
|
153
|
+
"해",
|
|
154
|
+
"자",
|
|
155
|
+
"양",
|
|
156
|
+
"구",
|
|
157
|
+
"간",
|
|
158
|
+
"정",
|
|
159
|
+
"재",
|
|
160
|
+
"극",
|
|
161
|
+
"항하사",
|
|
162
|
+
"아승기",
|
|
163
|
+
"나유타",
|
|
164
|
+
"불가사의",
|
|
165
|
+
"무량대수",
|
|
166
|
+
"겁",
|
|
167
|
+
"업"
|
|
168
|
+
];
|
|
169
|
+
var HANGUL_DIGITS_MAX = HANGUL_DIGITS.length * 4;
|
|
170
|
+
function disassembleCompleteCharacter(letter) {
|
|
171
|
+
const charCode = letter.charCodeAt(0);
|
|
172
|
+
const isCompleteHangul = COMPLETE_HANGUL_START_CHARCODE <= charCode && charCode <= COMPLETE_HANGUL_END_CHARCODE;
|
|
173
|
+
if (!isCompleteHangul) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const hangulCode = charCode - COMPLETE_HANGUL_START_CHARCODE;
|
|
177
|
+
const jongseongIndex = hangulCode % NUMBER_OF_JONGSEONG;
|
|
178
|
+
const jungseongIndex = (hangulCode - jongseongIndex) / NUMBER_OF_JONGSEONG % NUMBER_OF_JUNGSEONG;
|
|
179
|
+
const choseongIndex = Math.floor((hangulCode - jongseongIndex) / NUMBER_OF_JONGSEONG / NUMBER_OF_JUNGSEONG);
|
|
180
|
+
return {
|
|
181
|
+
choseong: CHOSEONGS[choseongIndex],
|
|
182
|
+
jungseong: JUNSEONGS[jungseongIndex],
|
|
183
|
+
jongseong: JONGSEONGS[jongseongIndex]
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function disassembleToGroups(str) {
|
|
187
|
+
const result = [];
|
|
188
|
+
for (const letter of str) {
|
|
189
|
+
const disassembledComplete = disassembleCompleteCharacter(letter);
|
|
190
|
+
if (disassembledComplete != null) {
|
|
191
|
+
result.push([
|
|
192
|
+
...disassembledComplete.choseong,
|
|
193
|
+
...disassembledComplete.jungseong,
|
|
194
|
+
...disassembledComplete.jongseong
|
|
195
|
+
]);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (hasProperty(DISASSEMBLED_CONSONANTS_BY_CONSONANT, letter)) {
|
|
199
|
+
const disassembledConsonant = DISASSEMBLED_CONSONANTS_BY_CONSONANT[letter];
|
|
200
|
+
result.push([...disassembledConsonant]);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (hasProperty(DISASSEMBLED_VOWELS_BY_VOWEL, letter)) {
|
|
204
|
+
const disassembledVowel = DISASSEMBLED_VOWELS_BY_VOWEL[letter];
|
|
205
|
+
result.push([...disassembledVowel]);
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
result.push([letter]);
|
|
209
|
+
}
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
function disassemble(str) {
|
|
213
|
+
return disassembleToGroups(str).reduce((hanguls, disassembleds) => `${hanguls}${disassembleds.join("")}`, "");
|
|
214
|
+
}
|
|
215
|
+
function canBeChoseong(character) {
|
|
216
|
+
return hasValueInReadOnlyStringList(CHOSEONGS, character);
|
|
217
|
+
}
|
|
218
|
+
function canBeJongseong(character) {
|
|
219
|
+
return hasValueInReadOnlyStringList(JONGSEONGS, character);
|
|
220
|
+
}
|
|
221
|
+
function canBeJungseong(character) {
|
|
222
|
+
if (!character) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
if (character in DISASSEMBLED_VOWELS_BY_VOWEL) {
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
return hasValueInReadOnlyStringList(JUNSEONGS, character);
|
|
229
|
+
}
|
|
230
|
+
function combineVowels(vowel1, vowel2) {
|
|
231
|
+
var _a, _b;
|
|
232
|
+
return (_b = (_a = Object.entries(DISASSEMBLED_VOWELS_BY_VOWEL).find(([, value]) => value === `${vowel1}${vowel2}`)) == null ? undefined : _a[0]) != null ? _b : `${vowel1}${vowel2}`;
|
|
233
|
+
}
|
|
234
|
+
function combineCharacter(choseong, jungseong, jongseong = "") {
|
|
235
|
+
if (canBeChoseong(choseong) === false || canBeJungseong(jungseong) === false || canBeJongseong(jongseong) === false) {
|
|
236
|
+
throw new Error(`Invalid hangul Characters: ${choseong}, ${jungseong}, ${jongseong}`);
|
|
237
|
+
}
|
|
238
|
+
const numOfJungseongs = JUNSEONGS.length;
|
|
239
|
+
const numOfJongseongs = JONGSEONGS.length;
|
|
240
|
+
const choseongIndex = CHOSEONGS.indexOf(choseong);
|
|
241
|
+
const jungseongIndex = JUNSEONGS.indexOf(jungseong);
|
|
242
|
+
const jongseongIndex = JONGSEONGS.indexOf(jongseong);
|
|
243
|
+
const choseongOfTargetConsonant = choseongIndex * numOfJungseongs * numOfJongseongs;
|
|
244
|
+
const choseongOfTargetVowel = jungseongIndex * numOfJongseongs;
|
|
245
|
+
const unicode = COMPLETE_HANGUL_START_CHARCODE + choseongOfTargetConsonant + choseongOfTargetVowel + jongseongIndex;
|
|
246
|
+
return String.fromCharCode(unicode);
|
|
247
|
+
}
|
|
248
|
+
function hasBatchim(str, options) {
|
|
249
|
+
const lastChar = str[str.length - 1];
|
|
250
|
+
if (lastChar == null) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
const charCode = lastChar.charCodeAt(0);
|
|
254
|
+
const isNotCompleteHangul = charCode < COMPLETE_HANGUL_START_CHARCODE || charCode > COMPLETE_HANGUL_END_CHARCODE;
|
|
255
|
+
if (isNotCompleteHangul) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
const batchimCode = (charCode - COMPLETE_HANGUL_START_CHARCODE) % NUMBER_OF_JONGSEONG;
|
|
259
|
+
const batchimLength = JONGSEONGS[batchimCode].length;
|
|
260
|
+
switch (options == null ? undefined : options.only) {
|
|
261
|
+
case "single": {
|
|
262
|
+
return batchimLength === 1;
|
|
263
|
+
}
|
|
264
|
+
case "double": {
|
|
265
|
+
return batchimLength === 2;
|
|
266
|
+
}
|
|
267
|
+
default: {
|
|
268
|
+
return batchimCode > 0;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function removeLastCharacter(words) {
|
|
273
|
+
const lastCharacter = words[words.length - 1];
|
|
274
|
+
if (lastCharacter == null) {
|
|
275
|
+
return "";
|
|
276
|
+
}
|
|
277
|
+
const result = (() => {
|
|
278
|
+
const disassembleLastCharacter = disassembleToGroups(lastCharacter);
|
|
279
|
+
const [lastCharacterWithoutLastAlphabet] = excludeLastElement(disassembleLastCharacter[0]);
|
|
280
|
+
if (lastCharacterWithoutLastAlphabet.length <= 3) {
|
|
281
|
+
const [first, middle, last] = lastCharacterWithoutLastAlphabet;
|
|
282
|
+
if (middle != null) {
|
|
283
|
+
return canBeJungseong(last) ? combineCharacter(first, `${middle}${last}`) : combineCharacter(first, middle, last);
|
|
284
|
+
}
|
|
285
|
+
return first;
|
|
286
|
+
} else {
|
|
287
|
+
const [first, firstJungseong, secondJungseong, firstJongseong] = lastCharacterWithoutLastAlphabet;
|
|
288
|
+
return combineCharacter(first, `${firstJungseong}${secondJungseong}`, firstJongseong);
|
|
289
|
+
}
|
|
290
|
+
})();
|
|
291
|
+
return [words.substring(0, words.length - 1), result].join("");
|
|
292
|
+
}
|
|
293
|
+
function isHangulCharacter(character) {
|
|
294
|
+
return /^[가-힣]$/.test(character);
|
|
295
|
+
}
|
|
296
|
+
function isHangulAlphabet(character) {
|
|
297
|
+
return /^[ㄱ-ㅣ]$/.test(character);
|
|
298
|
+
}
|
|
299
|
+
function binaryAssembleAlphabets(source, nextCharacter) {
|
|
300
|
+
if (canBeJungseong(`${source}${nextCharacter}`)) {
|
|
301
|
+
return combineVowels(source, nextCharacter);
|
|
302
|
+
}
|
|
303
|
+
const isConsonantSource = canBeJungseong(source) === false;
|
|
304
|
+
if (isConsonantSource && canBeJungseong(nextCharacter)) {
|
|
305
|
+
return combineCharacter(source, nextCharacter);
|
|
306
|
+
}
|
|
307
|
+
return joinString(source, nextCharacter);
|
|
308
|
+
}
|
|
309
|
+
function linkHangulCharacters(source, nextCharacter) {
|
|
310
|
+
const sourceJamo = disassembleToGroups(source)[0];
|
|
311
|
+
const [, lastJamo] = excludeLastElement(sourceJamo);
|
|
312
|
+
return joinString(removeLastCharacter(source), combineCharacter(lastJamo, nextCharacter));
|
|
313
|
+
}
|
|
314
|
+
function binaryAssembleCharacters(source, nextCharacter) {
|
|
315
|
+
assert(isHangulCharacter(source) || isHangulAlphabet(source), `Invalid source character: ${source}. Source must be one character.`);
|
|
316
|
+
assert(isHangulAlphabet(nextCharacter), `Invalid next character: ${nextCharacter}. Next character must be one of the choseong, jungseong, or jongseong.`);
|
|
317
|
+
const sourceJamos = disassembleToGroups(source)[0];
|
|
318
|
+
const isSingleCharacter = sourceJamos.length === 1;
|
|
319
|
+
if (isSingleCharacter) {
|
|
320
|
+
const sourceCharacter = sourceJamos[0];
|
|
321
|
+
return binaryAssembleAlphabets(sourceCharacter, nextCharacter);
|
|
322
|
+
}
|
|
323
|
+
const [restJamos, lastJamo] = excludeLastElement(sourceJamos);
|
|
324
|
+
const secondaryLastJamo = excludeLastElement(restJamos)[1];
|
|
325
|
+
const needLinking = canBeChoseong(lastJamo) && canBeJungseong(nextCharacter);
|
|
326
|
+
if (needLinking) {
|
|
327
|
+
return linkHangulCharacters(source, nextCharacter);
|
|
328
|
+
}
|
|
329
|
+
const fixConsonant = curriedCombineCharacter;
|
|
330
|
+
const combineJungseong = fixConsonant(restJamos[0]);
|
|
331
|
+
if (canBeJungseong(`${lastJamo}${nextCharacter}`)) {
|
|
332
|
+
return combineJungseong(`${lastJamo}${nextCharacter}`)();
|
|
333
|
+
}
|
|
334
|
+
if (canBeJungseong(`${secondaryLastJamo}${lastJamo}`) && canBeJongseong(nextCharacter)) {
|
|
335
|
+
return combineJungseong(`${secondaryLastJamo}${lastJamo}`)(nextCharacter);
|
|
336
|
+
}
|
|
337
|
+
if (canBeJungseong(lastJamo) && canBeJongseong(nextCharacter)) {
|
|
338
|
+
return combineJungseong(lastJamo)(nextCharacter);
|
|
339
|
+
}
|
|
340
|
+
const fixVowel = combineJungseong;
|
|
341
|
+
const combineJongseong = fixVowel(canBeJungseong(`${restJamos[1]}${restJamos[2]}`) ? `${restJamos[1]}${restJamos[2]}` : restJamos[1]);
|
|
342
|
+
const lastConsonant = lastJamo;
|
|
343
|
+
if (hasBatchim(source, {
|
|
344
|
+
only: "single"
|
|
345
|
+
}) && canBeJongseong(`${lastConsonant}${nextCharacter}`)) {
|
|
346
|
+
return combineJongseong(`${lastConsonant}${nextCharacter}`);
|
|
347
|
+
}
|
|
348
|
+
return joinString(source, nextCharacter);
|
|
349
|
+
}
|
|
350
|
+
function binaryAssemble(source, nextCharacter) {
|
|
351
|
+
const [rest, lastCharacter] = excludeLastElement(source.split(""));
|
|
352
|
+
const needJoinString = isBlank(lastCharacter) || isBlank(nextCharacter);
|
|
353
|
+
return joinString(...rest, needJoinString ? joinString(lastCharacter, nextCharacter) : binaryAssembleCharacters(lastCharacter, nextCharacter));
|
|
354
|
+
}
|
|
355
|
+
var curriedCombineCharacter = (choseong) => (jungseong) => (jongseong = "") => combineCharacter(choseong, jungseong, jongseong);
|
|
356
|
+
function assemble(fragments) {
|
|
357
|
+
const disassembled = disassemble(fragments.join("")).split("");
|
|
358
|
+
return disassembled.reduce(binaryAssemble);
|
|
359
|
+
}
|
|
360
|
+
var JASO_HANGUL_NFD = {
|
|
361
|
+
START_CHOSEONG: _JASO_HANGUL_NFD[0],
|
|
362
|
+
START_JUNGSEONG: _JASO_HANGUL_NFD[1],
|
|
363
|
+
START_JONGSEONG: _JASO_HANGUL_NFD[2],
|
|
364
|
+
END_CHOSEONG: _JASO_HANGUL_NFD[3],
|
|
365
|
+
END_JUNGSEONG: _JASO_HANGUL_NFD[4],
|
|
366
|
+
END_JONGSEONG: _JASO_HANGUL_NFD[5]
|
|
367
|
+
};
|
|
368
|
+
var EXTRACT_CHOSEONG_REGEX = new RegExp(`[^\\u${JASO_HANGUL_NFD.START_CHOSEONG.toString(16)}-\\u${JASO_HANGUL_NFD.END_CHOSEONG.toString(16)}ㄱ-ㅎ\\s]+`, "ug");
|
|
369
|
+
var CHOOSE_NFD_CHOSEONG_REGEX = new RegExp(`[\\u${JASO_HANGUL_NFD.START_CHOSEONG.toString(16)}-\\u${JASO_HANGUL_NFD.END_CHOSEONG.toString(16)}]`, "g");
|
|
370
|
+
var 로__ = ["으로/로", "으로서/로서", "으로써/로써", "으로부터/로부터"];
|
|
371
|
+
function josa(word, josa2) {
|
|
372
|
+
if (word.length === 0) {
|
|
373
|
+
return word;
|
|
374
|
+
}
|
|
375
|
+
return word + josaPicker(word, josa2);
|
|
376
|
+
}
|
|
377
|
+
josa.pick = josaPicker;
|
|
378
|
+
function josaPicker(word, josa2) {
|
|
379
|
+
var _a;
|
|
380
|
+
if (word.length === 0) {
|
|
381
|
+
return josa2.split("/")[0];
|
|
382
|
+
}
|
|
383
|
+
const has_ = hasBatchim(word);
|
|
384
|
+
let index = has_ ? 0 : 1;
|
|
385
|
+
const is_ = has_ && ((_a = disassembleCompleteCharacter(word[word.length - 1])) == null ? undefined : _a.jongseong) === "ㄹ";
|
|
386
|
+
const isCaseOf_ = has_ && is_ && 로__.includes(josa2);
|
|
387
|
+
if (josa2 === "와/과" || isCaseOf_) {
|
|
388
|
+
index = index === 0 ? 1 : 0;
|
|
389
|
+
}
|
|
390
|
+
const isEndsWith_ = word[word.length - 1] === "이";
|
|
391
|
+
if (josa2 === "이에요/예요" && isEndsWith_) {
|
|
392
|
+
index = 1;
|
|
393
|
+
}
|
|
394
|
+
return josa2.split("/")[index];
|
|
395
|
+
}
|
|
396
|
+
var QWERTY_KEYBOARD_MAP = {
|
|
397
|
+
q: "ㅂ",
|
|
398
|
+
Q: "ㅃ",
|
|
399
|
+
w: "ㅈ",
|
|
400
|
+
W: "ㅉ",
|
|
401
|
+
e: "ㄷ",
|
|
402
|
+
E: "ㄸ",
|
|
403
|
+
r: "ㄱ",
|
|
404
|
+
R: "ㄲ",
|
|
405
|
+
t: "ㅅ",
|
|
406
|
+
T: "ㅆ",
|
|
407
|
+
y: "ㅛ",
|
|
408
|
+
Y: "ㅛ",
|
|
409
|
+
u: "ㅕ",
|
|
410
|
+
U: "ㅕ",
|
|
411
|
+
i: "ㅑ",
|
|
412
|
+
I: "ㅑ",
|
|
413
|
+
o: "ㅐ",
|
|
414
|
+
O: "ㅒ",
|
|
415
|
+
p: "ㅔ",
|
|
416
|
+
P: "ㅖ",
|
|
417
|
+
a: "ㅁ",
|
|
418
|
+
A: "ㅁ",
|
|
419
|
+
s: "ㄴ",
|
|
420
|
+
S: "ㄴ",
|
|
421
|
+
d: "ㅇ",
|
|
422
|
+
D: "ㅇ",
|
|
423
|
+
f: "ㄹ",
|
|
424
|
+
F: "ㄹ",
|
|
425
|
+
g: "ㅎ",
|
|
426
|
+
G: "ㅎ",
|
|
427
|
+
h: "ㅗ",
|
|
428
|
+
H: "ㅗ",
|
|
429
|
+
j: "ㅓ",
|
|
430
|
+
J: "ㅓ",
|
|
431
|
+
k: "ㅏ",
|
|
432
|
+
K: "ㅏ",
|
|
433
|
+
l: "ㅣ",
|
|
434
|
+
L: "ㅣ",
|
|
435
|
+
z: "ㅋ",
|
|
436
|
+
Z: "ㅋ",
|
|
437
|
+
x: "ㅌ",
|
|
438
|
+
X: "ㅌ",
|
|
439
|
+
c: "ㅊ",
|
|
440
|
+
C: "ㅊ",
|
|
441
|
+
v: "ㅍ",
|
|
442
|
+
V: "ㅍ",
|
|
443
|
+
b: "ㅠ",
|
|
444
|
+
B: "ㅠ",
|
|
445
|
+
n: "ㅜ",
|
|
446
|
+
N: "ㅜ",
|
|
447
|
+
m: "ㅡ",
|
|
448
|
+
M: "ㅡ"
|
|
449
|
+
};
|
|
450
|
+
function convertQwertyToAlphabet(word) {
|
|
451
|
+
return word.split("").map((inputText) => hasProperty(QWERTY_KEYBOARD_MAP, inputText) ? QWERTY_KEYBOARD_MAP[inputText] : inputText).join("");
|
|
452
|
+
}
|
|
453
|
+
function convertQwertyToHangul(word) {
|
|
454
|
+
if (!word) {
|
|
455
|
+
return "";
|
|
456
|
+
}
|
|
457
|
+
return assemble([...convertQwertyToAlphabet(word)]);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// src/utils/isHangul.ts
|
|
461
|
+
function isHangul(char) {
|
|
462
|
+
return /^[\u1100-\u11FF\u3130-\u318F\uAC00-\uD7AF]$/.test(char);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// src/components/ShadowWrapper.tsx
|
|
466
|
+
import { useEffect, useState, memo } from "react";
|
|
467
|
+
import ReactDOM from "react-dom";
|
|
468
|
+
import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
|
|
469
|
+
var ShadowWrapper = memo(({
|
|
470
|
+
children,
|
|
471
|
+
css,
|
|
472
|
+
tagName
|
|
473
|
+
}) => {
|
|
474
|
+
const [host, setHost] = useState(null);
|
|
475
|
+
const [shadowRoot, setShadowRoot] = useState(null);
|
|
476
|
+
const Component = tagName;
|
|
477
|
+
useEffect(() => {
|
|
478
|
+
if (host && !shadowRoot) {
|
|
479
|
+
const shadow = host.attachShadow({ mode: "closed" });
|
|
480
|
+
setShadowRoot(shadow);
|
|
481
|
+
}
|
|
482
|
+
}, [host, shadowRoot]);
|
|
483
|
+
return /* @__PURE__ */ jsxDEV(Component, {
|
|
484
|
+
ref: setHost,
|
|
485
|
+
children: shadowRoot && ReactDOM.createPortal(/* @__PURE__ */ jsxDEV(Fragment, {
|
|
486
|
+
children: [
|
|
487
|
+
css && /* @__PURE__ */ jsxDEV("style", {
|
|
488
|
+
children: css
|
|
489
|
+
}, undefined, false, undefined, this),
|
|
490
|
+
children
|
|
491
|
+
]
|
|
492
|
+
}, undefined, true, undefined, this), shadowRoot)
|
|
493
|
+
}, undefined, false, undefined, this);
|
|
494
|
+
});
|
|
495
|
+
ShadowWrapper.displayName = "ShadowWrapper";
|
|
496
|
+
|
|
497
|
+
// src/components/BlinkingCaret.tsx
|
|
498
|
+
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
499
|
+
function BlinkingCaret() {
|
|
500
|
+
return /* @__PURE__ */ jsxDEV2("span", {
|
|
501
|
+
className: "blink",
|
|
502
|
+
style: {
|
|
503
|
+
margin: "0 -0.12em",
|
|
504
|
+
position: "absolute"
|
|
505
|
+
},
|
|
506
|
+
children: "|"
|
|
507
|
+
}, undefined, false, undefined, this);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// src/components/Context.tsx
|
|
511
|
+
import {
|
|
512
|
+
createContext,
|
|
513
|
+
useContext
|
|
514
|
+
} from "react";
|
|
515
|
+
var VirtualInputContext = createContext(null);
|
|
516
|
+
function useVirtualInputContext() {
|
|
517
|
+
const context = useContext(VirtualInputContext);
|
|
518
|
+
if (!context) {
|
|
519
|
+
throw new Error("Input must be used within an <VirtualInputProvider>. Wrap your app with <VirtualInputProvider>.");
|
|
520
|
+
}
|
|
521
|
+
return context;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// src/utils/parseKeyInput.ts
|
|
525
|
+
function parseKeyInput(e, hangulMode) {
|
|
526
|
+
const isMac = navigator.userAgent.includes("Mac");
|
|
527
|
+
if (!isMac && e.key === "HangulMode") {
|
|
528
|
+
return { handled: true, toggleHangulMode: true };
|
|
529
|
+
}
|
|
530
|
+
const ignoredKeys = new Set([
|
|
531
|
+
"Shift",
|
|
532
|
+
"Control",
|
|
533
|
+
"Alt",
|
|
534
|
+
"Meta",
|
|
535
|
+
"CapsLock",
|
|
536
|
+
"Enter",
|
|
537
|
+
"Tab",
|
|
538
|
+
"ArrowUp",
|
|
539
|
+
"ArrowDown",
|
|
540
|
+
"ArrowLeft",
|
|
541
|
+
"ArrowRight",
|
|
542
|
+
"Backspace",
|
|
543
|
+
"Delete",
|
|
544
|
+
"Unidentified"
|
|
545
|
+
]);
|
|
546
|
+
if (ignoredKeys.has(e.key)) {
|
|
547
|
+
return { handled: false };
|
|
548
|
+
}
|
|
549
|
+
if (isMac) {
|
|
550
|
+
if (isHangul(e.key)) {
|
|
551
|
+
return {
|
|
552
|
+
handled: true,
|
|
553
|
+
text: e.key,
|
|
554
|
+
composing: true
|
|
555
|
+
};
|
|
556
|
+
} else {
|
|
557
|
+
return {
|
|
558
|
+
handled: true,
|
|
559
|
+
text: e.key,
|
|
560
|
+
composing: false
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (hangulMode) {
|
|
565
|
+
return {
|
|
566
|
+
handled: true,
|
|
567
|
+
text: isHangul(e.key) ? e.key : convertQwertyToHangul(e.key),
|
|
568
|
+
composing: true
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
return {
|
|
572
|
+
handled: true,
|
|
573
|
+
text: e.key,
|
|
574
|
+
composing: false
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// src/components/Input.tsx
|
|
579
|
+
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
580
|
+
function VirtualInput({
|
|
581
|
+
value: controlledValue,
|
|
582
|
+
defaultValue,
|
|
583
|
+
onChange,
|
|
584
|
+
...props
|
|
585
|
+
}) {
|
|
586
|
+
const id = useId();
|
|
587
|
+
const [internalValue, setInternalValue] = useState2(controlledValue ?? defaultValue ?? "");
|
|
588
|
+
const [caretIndex, setCaretIndex] = useState2(() => (controlledValue ?? defaultValue ?? "").length);
|
|
589
|
+
const [selection, setSelection] = useState2({ start: null, end: null });
|
|
590
|
+
const divRef = useRef(null);
|
|
591
|
+
const letters = useMemo(() => internalValue.split(""), [internalValue]);
|
|
592
|
+
const updateValue = useCallback((newValue, newCaretIndex) => {
|
|
593
|
+
if (controlledValue === undefined) {
|
|
594
|
+
setInternalValue(newValue);
|
|
595
|
+
}
|
|
596
|
+
const fakeInput = { value: newValue };
|
|
597
|
+
const changeEvent = {
|
|
598
|
+
target: fakeInput,
|
|
599
|
+
currentTarget: fakeInput
|
|
600
|
+
};
|
|
601
|
+
onChange?.(changeEvent);
|
|
602
|
+
setCaretIndex(newCaretIndex);
|
|
603
|
+
}, [controlledValue, onChange]);
|
|
604
|
+
useEffect2(() => {
|
|
605
|
+
if (controlledValue !== undefined && controlledValue !== internalValue) {
|
|
606
|
+
setInternalValue(controlledValue);
|
|
607
|
+
}
|
|
608
|
+
}, [controlledValue, internalValue]);
|
|
609
|
+
const {
|
|
610
|
+
focusId,
|
|
611
|
+
onFocus,
|
|
612
|
+
onBlur,
|
|
613
|
+
hangulMode,
|
|
614
|
+
setHangulMode,
|
|
615
|
+
isCompositionRef,
|
|
616
|
+
inputRef,
|
|
617
|
+
shift
|
|
618
|
+
} = useVirtualInputContext();
|
|
619
|
+
const isFocused = focusId === id;
|
|
620
|
+
const selectionStart = selection.start;
|
|
621
|
+
const selectionEnd = selection.end;
|
|
622
|
+
const hasSelection = useMemo(() => selectionStart !== null && selectionEnd !== null && selectionStart !== selectionEnd, [selectionStart, selectionEnd]);
|
|
623
|
+
const clearSelection = useCallback(() => {
|
|
624
|
+
setSelection({ start: null, end: null });
|
|
625
|
+
}, []);
|
|
626
|
+
const deleteSelectedText = useCallback(() => {
|
|
627
|
+
if (!hasSelection || selectionStart === null || selectionEnd === null) {
|
|
628
|
+
return { newString: internalValue, finalCaretIndex: caretIndex };
|
|
629
|
+
}
|
|
630
|
+
const [start, end] = [selectionStart, selectionEnd].sort((a, b) => a - b);
|
|
631
|
+
const newString = internalValue.slice(0, start) + internalValue.slice(end);
|
|
632
|
+
clearSelection();
|
|
633
|
+
return { newString, finalCaretIndex: start };
|
|
634
|
+
}, [
|
|
635
|
+
internalValue,
|
|
636
|
+
caretIndex,
|
|
637
|
+
hasSelection,
|
|
638
|
+
selectionStart,
|
|
639
|
+
selectionEnd,
|
|
640
|
+
clearSelection
|
|
641
|
+
]);
|
|
642
|
+
const handlePaste = useCallback((e) => {
|
|
643
|
+
e.preventDefault();
|
|
644
|
+
const pastedText = e.clipboardData.getData("text/plain");
|
|
645
|
+
if (!pastedText)
|
|
646
|
+
return;
|
|
647
|
+
const { newString, finalCaretIndex } = hasSelection ? deleteSelectedText() : { newString: internalValue, finalCaretIndex: caretIndex };
|
|
648
|
+
const finalString = newString.slice(0, finalCaretIndex) + pastedText + newString.slice(finalCaretIndex);
|
|
649
|
+
const newCaretPosition = finalCaretIndex + pastedText.length;
|
|
650
|
+
updateValue(finalString, newCaretPosition);
|
|
651
|
+
clearSelection();
|
|
652
|
+
}, [
|
|
653
|
+
internalValue,
|
|
654
|
+
caretIndex,
|
|
655
|
+
hasSelection,
|
|
656
|
+
clearSelection,
|
|
657
|
+
deleteSelectedText,
|
|
658
|
+
updateValue
|
|
659
|
+
]);
|
|
660
|
+
const handleKeyDown = useCallback((e) => {
|
|
661
|
+
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "a") {
|
|
662
|
+
e.preventDefault();
|
|
663
|
+
setSelection({ start: 0, end: letters.length });
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
if (e.key === "HangulMode") {
|
|
667
|
+
setHangulMode(!hangulMode);
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "c") {
|
|
671
|
+
if (hasSelection && selectionStart !== null && selectionEnd !== null) {
|
|
672
|
+
e.preventDefault();
|
|
673
|
+
const [start, end] = [selectionStart, selectionEnd].sort((a, b) => a - b);
|
|
674
|
+
const textToCopy = letters.slice(start, end).join("");
|
|
675
|
+
navigator.clipboard.writeText(textToCopy).catch((err) => {
|
|
676
|
+
console.error("Failed to copy text: ", err);
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
if ((e.ctrlKey || e.metaKey) && (e.key.toLowerCase() === "c" || e.key.toLowerCase() === "v"))
|
|
682
|
+
return;
|
|
683
|
+
switch (e.key) {
|
|
684
|
+
case "Backspace": {
|
|
685
|
+
isCompositionRef.current = false;
|
|
686
|
+
if (hasSelection) {
|
|
687
|
+
const { newString, finalCaretIndex } = deleteSelectedText();
|
|
688
|
+
updateValue(newString, finalCaretIndex);
|
|
689
|
+
} else if (caretIndex > 0) {
|
|
690
|
+
const newString = internalValue.slice(0, caretIndex - 1) + internalValue.slice(caretIndex);
|
|
691
|
+
updateValue(newString, caretIndex - 1);
|
|
692
|
+
}
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
case "Delete": {
|
|
696
|
+
isCompositionRef.current = false;
|
|
697
|
+
if (hasSelection) {
|
|
698
|
+
const { newString, finalCaretIndex } = deleteSelectedText();
|
|
699
|
+
updateValue(newString, finalCaretIndex);
|
|
700
|
+
} else if (caretIndex < letters.length) {
|
|
701
|
+
const newString = internalValue.slice(0, caretIndex) + internalValue.slice(caretIndex + 1);
|
|
702
|
+
updateValue(newString, caretIndex);
|
|
703
|
+
}
|
|
704
|
+
break;
|
|
705
|
+
}
|
|
706
|
+
case "ArrowLeft": {
|
|
707
|
+
isCompositionRef.current = false;
|
|
708
|
+
const newCaretIndex = Math.max(0, caretIndex - 1);
|
|
709
|
+
if (e.shiftKey) {
|
|
710
|
+
setSelection((prev) => ({
|
|
711
|
+
start: prev.start ?? caretIndex,
|
|
712
|
+
end: newCaretIndex
|
|
713
|
+
}));
|
|
714
|
+
} else {
|
|
715
|
+
clearSelection();
|
|
716
|
+
}
|
|
717
|
+
setCaretIndex(newCaretIndex);
|
|
718
|
+
break;
|
|
719
|
+
}
|
|
720
|
+
case "ArrowRight": {
|
|
721
|
+
isCompositionRef.current = false;
|
|
722
|
+
const newCaretIndex = Math.min(letters.length, caretIndex + 1);
|
|
723
|
+
if (e.shiftKey) {
|
|
724
|
+
setSelection((prev) => ({
|
|
725
|
+
start: prev.start ?? caretIndex,
|
|
726
|
+
end: newCaretIndex
|
|
727
|
+
}));
|
|
728
|
+
} else {
|
|
729
|
+
clearSelection();
|
|
730
|
+
}
|
|
731
|
+
setCaretIndex(newCaretIndex);
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
case "Unidentified":
|
|
735
|
+
case "Shift":
|
|
736
|
+
case "Control":
|
|
737
|
+
case "Alt":
|
|
738
|
+
case "Meta":
|
|
739
|
+
case "CapsLock":
|
|
740
|
+
case "Enter":
|
|
741
|
+
case "Tab":
|
|
742
|
+
case "ArrowUp":
|
|
743
|
+
case "ArrowDown":
|
|
744
|
+
e.stopPropagation();
|
|
745
|
+
break;
|
|
746
|
+
case "End": {
|
|
747
|
+
const newCaretIndex = letters.length;
|
|
748
|
+
if (e.shiftKey) {
|
|
749
|
+
setSelection((prev) => ({
|
|
750
|
+
...prev,
|
|
751
|
+
end: newCaretIndex
|
|
752
|
+
}));
|
|
753
|
+
}
|
|
754
|
+
setCaretIndex(newCaretIndex);
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
default: {
|
|
758
|
+
const result = parseKeyInput(e, hangulMode);
|
|
759
|
+
if (result.toggleHangulMode) {
|
|
760
|
+
setHangulMode(!hangulMode);
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
if (!result.handled || !result.text)
|
|
764
|
+
return;
|
|
765
|
+
let { text, composing } = result;
|
|
766
|
+
if (shift && text.length === 1 && text.match(/[a-z]/i)) {
|
|
767
|
+
text = text.toUpperCase();
|
|
768
|
+
}
|
|
769
|
+
const { newString, finalCaretIndex } = hasSelection ? deleteSelectedText() : { newString: internalValue, finalCaretIndex: caretIndex };
|
|
770
|
+
const prevChar = newString[finalCaretIndex - 1];
|
|
771
|
+
if (composing && isHangul(prevChar) && isCompositionRef.current) {
|
|
772
|
+
const combined = assemble([prevChar, text]);
|
|
773
|
+
const finalString = newString.slice(0, finalCaretIndex - 1) + combined + newString.slice(finalCaretIndex);
|
|
774
|
+
updateValue(finalString, finalCaretIndex - 1 + combined.length);
|
|
775
|
+
} else {
|
|
776
|
+
const finalString = newString.slice(0, finalCaretIndex) + text + newString.slice(finalCaretIndex);
|
|
777
|
+
updateValue(finalString, finalCaretIndex + text.length);
|
|
778
|
+
}
|
|
779
|
+
isCompositionRef.current = composing;
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}, [
|
|
784
|
+
letters,
|
|
785
|
+
caretIndex,
|
|
786
|
+
hasSelection,
|
|
787
|
+
selectionStart,
|
|
788
|
+
selectionEnd,
|
|
789
|
+
clearSelection,
|
|
790
|
+
deleteSelectedText,
|
|
791
|
+
hangulMode,
|
|
792
|
+
setHangulMode,
|
|
793
|
+
isCompositionRef,
|
|
794
|
+
shift,
|
|
795
|
+
updateValue,
|
|
796
|
+
internalValue
|
|
797
|
+
]);
|
|
798
|
+
const handleFocus = useCallback(() => {
|
|
799
|
+
onFocus(id);
|
|
800
|
+
}, [onFocus, id]);
|
|
801
|
+
const handleBlur = useCallback(() => {
|
|
802
|
+
onBlur();
|
|
803
|
+
}, [onBlur]);
|
|
804
|
+
const handleClickWrap = useCallback(() => {
|
|
805
|
+
clearSelection();
|
|
806
|
+
setCaretIndex(letters.length);
|
|
807
|
+
}, [clearSelection, letters.length]);
|
|
808
|
+
const handleClickLetter = useCallback((index) => {
|
|
809
|
+
clearSelection();
|
|
810
|
+
setCaretIndex(index);
|
|
811
|
+
}, [clearSelection]);
|
|
812
|
+
const isSelected = useCallback((index) => {
|
|
813
|
+
if (!hasSelection || selectionStart === null || selectionEnd === null)
|
|
814
|
+
return false;
|
|
815
|
+
const [start, end] = [selectionStart, selectionEnd].sort((a, b) => a - b);
|
|
816
|
+
return index >= start && index < end;
|
|
817
|
+
}, [hasSelection, selectionStart, selectionEnd]);
|
|
818
|
+
const handleClickLetterEvent = (e) => {
|
|
819
|
+
e.stopPropagation();
|
|
820
|
+
handleClickLetter(Number(e.currentTarget.dataset.value));
|
|
821
|
+
};
|
|
822
|
+
useImperativeHandle(inputRef, () => {
|
|
823
|
+
if (isFocused) {
|
|
824
|
+
return {
|
|
825
|
+
handleKeyDown
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
return inputRef.current;
|
|
829
|
+
}, [isFocused, handleKeyDown, inputRef]);
|
|
830
|
+
return /* @__PURE__ */ jsxDEV3(ShadowWrapper, {
|
|
831
|
+
tagName: "virtual-input",
|
|
832
|
+
css: `
|
|
833
|
+
.wrap {
|
|
834
|
+
white-space: pre;
|
|
835
|
+
position: relative;
|
|
836
|
+
cursor: text;
|
|
837
|
+
border-radius: 4px;
|
|
838
|
+
user-select: none;
|
|
839
|
+
}
|
|
840
|
+
.wrap::after {
|
|
841
|
+
content: " ";
|
|
842
|
+
}
|
|
843
|
+
.letter {
|
|
844
|
+
position: relative;
|
|
845
|
+
outline: none;
|
|
846
|
+
}
|
|
847
|
+
.letter.selected {
|
|
848
|
+
background-color: #b4d5fe;
|
|
849
|
+
}
|
|
850
|
+
@keyframes blink {
|
|
851
|
+
0%,
|
|
852
|
+
49% {
|
|
853
|
+
opacity: 1;
|
|
854
|
+
}
|
|
855
|
+
50%,
|
|
856
|
+
100% {
|
|
857
|
+
opacity: 0;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
.blink {
|
|
861
|
+
animation: blink 1s step-start infinite;
|
|
862
|
+
}
|
|
863
|
+
`,
|
|
864
|
+
children: /* @__PURE__ */ jsxDEV3("div", {
|
|
865
|
+
...props,
|
|
866
|
+
ref: divRef,
|
|
867
|
+
className: "wrap",
|
|
868
|
+
role: "textbox",
|
|
869
|
+
tabIndex: 0,
|
|
870
|
+
style: {
|
|
871
|
+
minHeight: "1.5em",
|
|
872
|
+
lineHeight: "1.5em",
|
|
873
|
+
outline: "none",
|
|
874
|
+
font: "inherit",
|
|
875
|
+
width: "100%"
|
|
876
|
+
},
|
|
877
|
+
onFocus: handleFocus,
|
|
878
|
+
onBlur: handleBlur,
|
|
879
|
+
onKeyDown: handleKeyDown,
|
|
880
|
+
onClick: handleClickWrap,
|
|
881
|
+
onPaste: handlePaste,
|
|
882
|
+
children: [
|
|
883
|
+
letters.map((char, i) => /* @__PURE__ */ jsxDEV3("span", {
|
|
884
|
+
children: [
|
|
885
|
+
caretIndex === i && isFocused && !hasSelection && /* @__PURE__ */ jsxDEV3(BlinkingCaret, {}, undefined, false, undefined, this),
|
|
886
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
887
|
+
role: "button",
|
|
888
|
+
"data-value": i,
|
|
889
|
+
onClick: handleClickLetterEvent,
|
|
890
|
+
className: `letter ${isSelected(i) ? "selected" : ""}`,
|
|
891
|
+
children: char
|
|
892
|
+
}, undefined, false, undefined, this)
|
|
893
|
+
]
|
|
894
|
+
}, `char-${char}-${i}`, true, undefined, this)),
|
|
895
|
+
caretIndex === letters.length && isFocused && !hasSelection && /* @__PURE__ */ jsxDEV3(BlinkingCaret, {}, undefined, false, undefined, this)
|
|
896
|
+
]
|
|
897
|
+
}, undefined, true, undefined, this)
|
|
898
|
+
}, undefined, false, undefined, this);
|
|
899
|
+
}
|
|
900
|
+
// src/components/Provider.tsx
|
|
901
|
+
import {
|
|
902
|
+
useState as useState5,
|
|
903
|
+
useRef as useRef2,
|
|
904
|
+
useCallback as useCallback4,
|
|
905
|
+
useEffect as useEffect5
|
|
906
|
+
} from "react";
|
|
907
|
+
|
|
908
|
+
// src/utils/isMobileAgent.ts
|
|
909
|
+
function isMobileAgent(userAgent = navigator.userAgent) {
|
|
910
|
+
const mobileRegex = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
|
|
911
|
+
return mobileRegex.test(userAgent);
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
// src/components/Keypad.tsx
|
|
915
|
+
import { useCallback as useCallback2 } from "react";
|
|
916
|
+
import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
|
|
917
|
+
function VirtualKeypad({
|
|
918
|
+
layout,
|
|
919
|
+
viewport
|
|
920
|
+
}) {
|
|
921
|
+
const {
|
|
922
|
+
focusId,
|
|
923
|
+
onBlur,
|
|
924
|
+
onFocus,
|
|
925
|
+
inputRef,
|
|
926
|
+
shift,
|
|
927
|
+
hangulMode,
|
|
928
|
+
toggleShift,
|
|
929
|
+
toggleKorean
|
|
930
|
+
} = useVirtualInputContext();
|
|
931
|
+
const handleFocus = useCallback2(() => {
|
|
932
|
+
if (!focusId)
|
|
933
|
+
return;
|
|
934
|
+
onFocus(focusId);
|
|
935
|
+
}, [onFocus, focusId]);
|
|
936
|
+
const getTransformedValue = useCallback2((cell) => {
|
|
937
|
+
if (cell.type === "char") {
|
|
938
|
+
if (hangulMode) {
|
|
939
|
+
return convertQwertyToHangul(cell.value);
|
|
940
|
+
}
|
|
941
|
+
if (shift) {
|
|
942
|
+
return cell.value.toUpperCase();
|
|
943
|
+
}
|
|
944
|
+
return cell.value;
|
|
945
|
+
}
|
|
946
|
+
return cell.label ?? cell.value;
|
|
947
|
+
}, [hangulMode, shift]);
|
|
948
|
+
const insertCharacter = useCallback2((e) => {
|
|
949
|
+
const target = e.target;
|
|
950
|
+
if (!(target instanceof HTMLButtonElement))
|
|
951
|
+
return;
|
|
952
|
+
const { value, dataset } = target;
|
|
953
|
+
const type = dataset.type;
|
|
954
|
+
if (type === "action") {
|
|
955
|
+
if (value === "Shift") {
|
|
956
|
+
toggleShift();
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
if (value === "HangulMode") {
|
|
960
|
+
toggleKorean();
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
const event = new KeyboardEvent("keydown", {
|
|
965
|
+
key: getTransformedValue({
|
|
966
|
+
value,
|
|
967
|
+
type
|
|
968
|
+
}),
|
|
969
|
+
code: `Key${value.toUpperCase()}`,
|
|
970
|
+
bubbles: true,
|
|
971
|
+
cancelable: true,
|
|
972
|
+
shiftKey: shift
|
|
973
|
+
});
|
|
974
|
+
inputRef.current?.handleKeyDown(event);
|
|
975
|
+
}, [inputRef, shift, toggleShift, toggleKorean, getTransformedValue]);
|
|
976
|
+
if (!focusId || !isMobileAgent())
|
|
977
|
+
return null;
|
|
978
|
+
return /* @__PURE__ */ jsxDEV4(ShadowWrapper, {
|
|
979
|
+
tagName: "virtual-keypad",
|
|
980
|
+
css: `
|
|
981
|
+
.keypad-container {
|
|
982
|
+
display: flex;
|
|
983
|
+
flex-direction: column;
|
|
984
|
+
position: fixed;
|
|
985
|
+
background-color: #f0f2f5;
|
|
986
|
+
padding: calc(8px / var(--scale-factor));
|
|
987
|
+
box-sizing: border-box;
|
|
988
|
+
gap: calc(8px / var(--scale-factor));
|
|
989
|
+
box-shadow: 0 calc(-2px / var(--scale-factor)) calc(10px / var(--scale-factor)) rgba(0, 0, 0, 0.1);
|
|
990
|
+
user-select: none;
|
|
991
|
+
touch-action: manipulation;
|
|
992
|
+
}
|
|
993
|
+
.keypad-row {
|
|
994
|
+
display: flex;
|
|
995
|
+
flex: 1;
|
|
996
|
+
gap: calc(8px / var(--scale-factor));
|
|
997
|
+
}
|
|
998
|
+
.keypad-button {
|
|
999
|
+
flex: 1;
|
|
1000
|
+
display: flex;
|
|
1001
|
+
justify-content: center;
|
|
1002
|
+
align-items: center;
|
|
1003
|
+
background-color: #ffffff;
|
|
1004
|
+
border: calc(1px / var(--scale-factor)) solid #ccc;
|
|
1005
|
+
border-radius: calc(8px / var(--scale-factor));
|
|
1006
|
+
font-size: calc(18px / var(--scale-factor));
|
|
1007
|
+
font-weight: 500;
|
|
1008
|
+
color: #333;
|
|
1009
|
+
cursor: pointer;
|
|
1010
|
+
box-shadow: 0 calc(2px / var(--scale-factor)) calc(2px / var(--scale-factor)) rgba(0, 0, 0, 0.05);
|
|
1011
|
+
}
|
|
1012
|
+
.keypad-button:active {
|
|
1013
|
+
background-color: #e0e0e0;
|
|
1014
|
+
transform: scale(0.98);
|
|
1015
|
+
box-shadow: 0 calc(1px / var(--scale-factor)) calc(1px / var(--scale-factor)) rgba(0, 0, 0, 0.1);
|
|
1016
|
+
transition: all 0.1s ease-in-out;
|
|
1017
|
+
}
|
|
1018
|
+
.keypad-button.action {
|
|
1019
|
+
background-color: #d1d5db;
|
|
1020
|
+
}
|
|
1021
|
+
.keypad-button.action:active {
|
|
1022
|
+
background-color: #b0b5bE;
|
|
1023
|
+
}
|
|
1024
|
+
`,
|
|
1025
|
+
children: /* @__PURE__ */ jsxDEV4("div", {
|
|
1026
|
+
onFocus: handleFocus,
|
|
1027
|
+
onBlur,
|
|
1028
|
+
tabIndex: -1,
|
|
1029
|
+
className: "keypad-container",
|
|
1030
|
+
style: {
|
|
1031
|
+
left: viewport.offsetLeft,
|
|
1032
|
+
width: viewport.width,
|
|
1033
|
+
top: Math.round(viewport.offsetTop + viewport.height - 200 / viewport.scale),
|
|
1034
|
+
height: Math.round(200 / viewport.scale),
|
|
1035
|
+
"--scale-factor": viewport.scale
|
|
1036
|
+
},
|
|
1037
|
+
children: layout?.map((row, i) => /* @__PURE__ */ jsxDEV4("div", {
|
|
1038
|
+
className: "keypad-row",
|
|
1039
|
+
children: row.map((cell, j) => /* @__PURE__ */ jsxDEV4("button", {
|
|
1040
|
+
type: "button",
|
|
1041
|
+
value: cell.value,
|
|
1042
|
+
"data-type": cell.type,
|
|
1043
|
+
onClick: insertCharacter,
|
|
1044
|
+
className: `keypad-button ${cell.type === "action" ? "action" : ""}`,
|
|
1045
|
+
children: getTransformedValue(cell)
|
|
1046
|
+
}, `${i}-${j}`, false, undefined, this))
|
|
1047
|
+
}, i, false, undefined, this))
|
|
1048
|
+
}, undefined, false, undefined, this)
|
|
1049
|
+
}, undefined, false, undefined, this);
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
// src/hooks/useStorage.ts
|
|
1053
|
+
import { useState as useState3, useCallback as useCallback3, useEffect as useEffect3 } from "react";
|
|
1054
|
+
var isBrowser = typeof window !== "undefined";
|
|
1055
|
+
function useStorage(key, initialValue) {
|
|
1056
|
+
const [storedValue, setStoredValue] = useState3(() => {
|
|
1057
|
+
if (!isBrowser) {
|
|
1058
|
+
return initialValue instanceof Function ? initialValue() : initialValue;
|
|
1059
|
+
}
|
|
1060
|
+
try {
|
|
1061
|
+
const item = window.localStorage.getItem(key);
|
|
1062
|
+
if (item) {
|
|
1063
|
+
return JSON.parse(item);
|
|
1064
|
+
} else {
|
|
1065
|
+
const valueToStore = initialValue instanceof Function ? initialValue() : initialValue;
|
|
1066
|
+
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
|
1067
|
+
return valueToStore;
|
|
1068
|
+
}
|
|
1069
|
+
} catch (error) {
|
|
1070
|
+
console.error(`Error reading localStorage key "${key}":`, error);
|
|
1071
|
+
return initialValue instanceof Function ? initialValue() : initialValue;
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1074
|
+
const setValue = useCallback3((value) => {
|
|
1075
|
+
if (!isBrowser) {
|
|
1076
|
+
console.warn(`Tried to set localStorage key "${key}" in a non-browser environment.`);
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
try {
|
|
1080
|
+
const valueToStore = value instanceof Function ? value(storedValue) : value;
|
|
1081
|
+
setStoredValue(valueToStore);
|
|
1082
|
+
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
|
1083
|
+
} catch (error) {
|
|
1084
|
+
console.error(`Error setting localStorage key "${key}":`, error);
|
|
1085
|
+
}
|
|
1086
|
+
}, [key, storedValue]);
|
|
1087
|
+
useEffect3(() => {
|
|
1088
|
+
if (!isBrowser)
|
|
1089
|
+
return;
|
|
1090
|
+
const handleStorageChange = (event) => {
|
|
1091
|
+
if (event.storageArea !== window.localStorage || event.key !== key) {
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
try {
|
|
1095
|
+
if (event.newValue) {
|
|
1096
|
+
if (JSON.stringify(storedValue) !== event.newValue) {
|
|
1097
|
+
setStoredValue(JSON.parse(event.newValue));
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
} catch (error) {
|
|
1101
|
+
console.error(`Error handling storage change for key "${key}":`, error);
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
window.addEventListener("storage", handleStorageChange);
|
|
1105
|
+
return () => window.removeEventListener("storage", handleStorageChange);
|
|
1106
|
+
}, [key, storedValue]);
|
|
1107
|
+
return [storedValue, setValue];
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// src/assets/qwerty.json
|
|
1111
|
+
var qwerty_default = [
|
|
1112
|
+
[
|
|
1113
|
+
{ label: "q", value: "q", type: "char" },
|
|
1114
|
+
{ label: "w", value: "w", type: "char" },
|
|
1115
|
+
{ label: "e", value: "e", type: "char" },
|
|
1116
|
+
{ label: "r", value: "r", type: "char" },
|
|
1117
|
+
{ label: "t", value: "t", type: "char" },
|
|
1118
|
+
{ label: "y", value: "y", type: "char" },
|
|
1119
|
+
{ label: "u", value: "u", type: "char" },
|
|
1120
|
+
{ label: "i", value: "i", type: "char" },
|
|
1121
|
+
{ label: "o", value: "o", type: "char" },
|
|
1122
|
+
{ label: "p", value: "p", type: "char" }
|
|
1123
|
+
],
|
|
1124
|
+
[
|
|
1125
|
+
{ label: "a", value: "a", type: "char" },
|
|
1126
|
+
{ label: "s", value: "s", type: "char" },
|
|
1127
|
+
{ label: "d", value: "d", type: "char" },
|
|
1128
|
+
{ label: "f", value: "f", type: "char" },
|
|
1129
|
+
{ label: "g", value: "g", type: "char" },
|
|
1130
|
+
{ label: "h", value: "h", type: "char" },
|
|
1131
|
+
{ label: "j", value: "j", type: "char" },
|
|
1132
|
+
{ label: "k", value: "k", type: "char" },
|
|
1133
|
+
{ label: "l", value: "l", type: "char" }
|
|
1134
|
+
],
|
|
1135
|
+
[
|
|
1136
|
+
{ label: "⇧", value: "Shift", type: "action" },
|
|
1137
|
+
{ label: "z", value: "z", type: "char" },
|
|
1138
|
+
{ label: "x", value: "x", type: "char" },
|
|
1139
|
+
{ label: "c", value: "c", type: "char" },
|
|
1140
|
+
{ label: "v", value: "v", type: "char" },
|
|
1141
|
+
{ label: "b", value: "b", type: "char" },
|
|
1142
|
+
{ label: "n", value: "n", type: "char" },
|
|
1143
|
+
{ label: "m", value: "m", type: "char" },
|
|
1144
|
+
{ label: "⌫", value: "Backspace", type: "action" }
|
|
1145
|
+
],
|
|
1146
|
+
[
|
|
1147
|
+
{ label: "␣", value: " ", width: 5, type: "action" },
|
|
1148
|
+
{ label: "⏎", value: `
|
|
1149
|
+
`, type: "action" },
|
|
1150
|
+
{ label: "🌐", value: "HangulMode", type: "action" }
|
|
1151
|
+
]
|
|
1152
|
+
];
|
|
1153
|
+
|
|
1154
|
+
// src/hooks/useVisualViewport.ts
|
|
1155
|
+
import { useState as useState4, useEffect as useEffect4 } from "react";
|
|
1156
|
+
var getVisualViewport = () => {
|
|
1157
|
+
if (typeof window !== "undefined" && window.visualViewport) {
|
|
1158
|
+
return {
|
|
1159
|
+
width: window.visualViewport.width,
|
|
1160
|
+
height: window.visualViewport.height,
|
|
1161
|
+
scale: window.visualViewport.scale,
|
|
1162
|
+
offsetLeft: window.visualViewport.offsetLeft,
|
|
1163
|
+
offsetTop: window.visualViewport.offsetTop
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
return {
|
|
1167
|
+
width: window.innerWidth,
|
|
1168
|
+
height: window.innerHeight,
|
|
1169
|
+
scale: 1,
|
|
1170
|
+
offsetLeft: 0,
|
|
1171
|
+
offsetTop: 0
|
|
1172
|
+
};
|
|
1173
|
+
};
|
|
1174
|
+
var useVisualViewport = () => {
|
|
1175
|
+
const [viewport, setViewport] = useState4(getVisualViewport);
|
|
1176
|
+
useEffect4(() => {
|
|
1177
|
+
const handleResize = () => {
|
|
1178
|
+
setViewport(getVisualViewport());
|
|
1179
|
+
};
|
|
1180
|
+
if (typeof window !== "undefined" && window.visualViewport) {
|
|
1181
|
+
window.visualViewport.addEventListener("resize", handleResize);
|
|
1182
|
+
window.visualViewport.addEventListener("scroll", handleResize);
|
|
1183
|
+
return () => {
|
|
1184
|
+
window.visualViewport?.removeEventListener("resize", handleResize);
|
|
1185
|
+
window.visualViewport?.removeEventListener("scroll", handleResize);
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
window.addEventListener("resize", handleResize);
|
|
1189
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
1190
|
+
}, []);
|
|
1191
|
+
return viewport;
|
|
1192
|
+
};
|
|
1193
|
+
|
|
1194
|
+
// src/components/Provider.tsx
|
|
1195
|
+
import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
|
|
1196
|
+
function VirtualInputProvider({
|
|
1197
|
+
children,
|
|
1198
|
+
layout = qwerty_default,
|
|
1199
|
+
defaultHangulMode = true
|
|
1200
|
+
}) {
|
|
1201
|
+
const inputRef = useRef2(null);
|
|
1202
|
+
const sti = useRef2(setTimeout(() => null, 0));
|
|
1203
|
+
const [focusId, setFocusId] = useState5();
|
|
1204
|
+
const [shift, setShift] = useState5(false);
|
|
1205
|
+
const [hangulMode, setHangulMode] = useStorage("virtual-keyboard-hangul-mode", defaultHangulMode);
|
|
1206
|
+
const viewport = useVisualViewport();
|
|
1207
|
+
useEffect5(() => {
|
|
1208
|
+
if (focusId) {
|
|
1209
|
+
document.body.style.paddingBottom = `${Math.round(200 / viewport.scale)}px`;
|
|
1210
|
+
} else {
|
|
1211
|
+
document.body.style.paddingBottom = "0px";
|
|
1212
|
+
}
|
|
1213
|
+
return () => {
|
|
1214
|
+
document.body.style.paddingBottom = "0px";
|
|
1215
|
+
};
|
|
1216
|
+
}, [focusId, viewport.scale]);
|
|
1217
|
+
const onFocus = (id) => {
|
|
1218
|
+
clearTimeout(sti.current);
|
|
1219
|
+
setFocusId(id);
|
|
1220
|
+
};
|
|
1221
|
+
const onBlur = () => {
|
|
1222
|
+
sti.current = setTimeout(() => {
|
|
1223
|
+
setFocusId(undefined);
|
|
1224
|
+
isCompositionRef.current = false;
|
|
1225
|
+
}, 0);
|
|
1226
|
+
};
|
|
1227
|
+
const toggleShift = useCallback4(() => {
|
|
1228
|
+
setShift((prev) => !prev);
|
|
1229
|
+
}, []);
|
|
1230
|
+
const toggleKorean = useCallback4(() => {
|
|
1231
|
+
setHangulMode((prev) => !prev);
|
|
1232
|
+
}, [setHangulMode]);
|
|
1233
|
+
const isCompositionRef = useRef2(undefined);
|
|
1234
|
+
return /* @__PURE__ */ jsxDEV5(VirtualInputContext.Provider, {
|
|
1235
|
+
value: {
|
|
1236
|
+
inputRef,
|
|
1237
|
+
isCompositionRef,
|
|
1238
|
+
onFocus,
|
|
1239
|
+
onBlur,
|
|
1240
|
+
focusId,
|
|
1241
|
+
setHangulMode,
|
|
1242
|
+
hangulMode,
|
|
1243
|
+
shift,
|
|
1244
|
+
toggleShift,
|
|
1245
|
+
toggleKorean
|
|
1246
|
+
},
|
|
1247
|
+
children: [
|
|
1248
|
+
children,
|
|
1249
|
+
/* @__PURE__ */ jsxDEV5(VirtualKeypad, {
|
|
1250
|
+
layout,
|
|
1251
|
+
viewport
|
|
1252
|
+
}, undefined, false, undefined, this)
|
|
1253
|
+
]
|
|
1254
|
+
}, undefined, true, undefined, this);
|
|
1255
|
+
}
|
|
1256
|
+
export {
|
|
1257
|
+
VirtualInputProvider,
|
|
1258
|
+
VirtualInput
|
|
1259
|
+
};
|