@uiwwsw/virtual-keyboard 1.1.2 → 2.0.0

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/dist/index.js CHANGED
@@ -1,2 +1,1828 @@
1
- export * from "./components/Input";
2
- export * from "./components/Provider";
1
+ "use client";
2
+ import { jsxs as q, jsx as C, Fragment as ze } from "react/jsx-runtime";
3
+ import { useContext as qe, createContext as Ze, forwardRef as We, useId as Be, useRef as P, useState as R, useMemo as Ke, useCallback as k, useEffect as V, useImperativeHandle as _e, createElement as Je } from "react";
4
+ import { convertQwertyToHangul as Re, assemble as Ge, removeLastCharacter as Qe } from "es-hangul";
5
+ import { createPortal as ke } from "react-dom";
6
+ class Oe {
7
+ past = [];
8
+ future = [];
9
+ record(r, n) {
10
+ r.value !== n.value && (r.composing && n.composing && this.past.length || (this.past.push({ ...r, composing: !1 }), this.past.length > 100 && this.past.shift()), this.future = []);
11
+ }
12
+ undo(r) {
13
+ const n = this.past.pop();
14
+ return n ? (this.future.push({ ...r, composing: !1 }), n) : r;
15
+ }
16
+ redo(r) {
17
+ const n = this.future.pop();
18
+ return n ? (this.past.push({ ...r, composing: !1 }), n) : r;
19
+ }
20
+ clear() {
21
+ this.past = [], this.future = [];
22
+ }
23
+ }
24
+ const He = Ze(null);
25
+ function Fe() {
26
+ const e = qe(He);
27
+ if (!e)
28
+ throw new Error(
29
+ "VirtualInput must be used within a <VirtualInputProvider>."
30
+ );
31
+ return e;
32
+ }
33
+ function fe(e) {
34
+ return /^[\u1100-\u11FF\u3130-\u318F\uAC00-\uD7AF]$/.test(e);
35
+ }
36
+ function et(e, r) {
37
+ if (e.key === "HangulMode") return { handled: !0, toggleHangulMode: !0 };
38
+ if (e.ctrlKey || e.metaKey || e.altKey || [...e.key].length !== 1 || /[\r\n\t]/.test(e.key))
39
+ return { handled: !1 };
40
+ const n = r && /^[A-Za-z]$/.test(e.key) ? Re(e.key) : e.key;
41
+ return { handled: !0, text: n, composing: fe(n) };
42
+ }
43
+ const G = [
44
+ [
45
+ {
46
+ label: "q",
47
+ value: "q",
48
+ type: "char"
49
+ },
50
+ {
51
+ label: "w",
52
+ value: "w",
53
+ type: "char"
54
+ },
55
+ {
56
+ label: "e",
57
+ value: "e",
58
+ type: "char"
59
+ },
60
+ {
61
+ label: "r",
62
+ value: "r",
63
+ type: "char"
64
+ },
65
+ {
66
+ label: "t",
67
+ value: "t",
68
+ type: "char"
69
+ },
70
+ {
71
+ label: "y",
72
+ value: "y",
73
+ type: "char"
74
+ },
75
+ {
76
+ label: "u",
77
+ value: "u",
78
+ type: "char"
79
+ },
80
+ {
81
+ label: "i",
82
+ value: "i",
83
+ type: "char"
84
+ },
85
+ {
86
+ label: "o",
87
+ value: "o",
88
+ type: "char"
89
+ },
90
+ {
91
+ label: "p",
92
+ value: "p",
93
+ type: "char"
94
+ }
95
+ ],
96
+ [
97
+ {
98
+ label: "a",
99
+ value: "a",
100
+ type: "char"
101
+ },
102
+ {
103
+ label: "s",
104
+ value: "s",
105
+ type: "char"
106
+ },
107
+ {
108
+ label: "d",
109
+ value: "d",
110
+ type: "char"
111
+ },
112
+ {
113
+ label: "f",
114
+ value: "f",
115
+ type: "char"
116
+ },
117
+ {
118
+ label: "g",
119
+ value: "g",
120
+ type: "char"
121
+ },
122
+ {
123
+ label: "h",
124
+ value: "h",
125
+ type: "char"
126
+ },
127
+ {
128
+ label: "j",
129
+ value: "j",
130
+ type: "char"
131
+ },
132
+ {
133
+ label: "k",
134
+ value: "k",
135
+ type: "char"
136
+ },
137
+ {
138
+ label: "l",
139
+ value: "l",
140
+ type: "char"
141
+ }
142
+ ],
143
+ [
144
+ {
145
+ label: "⇧",
146
+ value: "Shift",
147
+ type: "action"
148
+ },
149
+ {
150
+ label: "z",
151
+ value: "z",
152
+ type: "char"
153
+ },
154
+ {
155
+ label: "x",
156
+ value: "x",
157
+ type: "char"
158
+ },
159
+ {
160
+ label: "c",
161
+ value: "c",
162
+ type: "char"
163
+ },
164
+ {
165
+ label: "v",
166
+ value: "v",
167
+ type: "char"
168
+ },
169
+ {
170
+ label: "b",
171
+ value: "b",
172
+ type: "char"
173
+ },
174
+ {
175
+ label: "n",
176
+ value: "n",
177
+ type: "char"
178
+ },
179
+ {
180
+ label: "m",
181
+ value: "m",
182
+ type: "char"
183
+ },
184
+ {
185
+ label: "⌫",
186
+ value: "Backspace",
187
+ type: "action"
188
+ }
189
+ ],
190
+ [
191
+ {
192
+ label: "편집",
193
+ value: "EnterSelectionMode",
194
+ type: "action"
195
+ },
196
+ {
197
+ label: "␣",
198
+ value: " ",
199
+ width: 4,
200
+ type: "action"
201
+ },
202
+ {
203
+ label: "⏎",
204
+ value: `
205
+ `,
206
+ type: "action"
207
+ },
208
+ {
209
+ value: "HangulMode",
210
+ type: "action",
211
+ width: 1.25
212
+ }
213
+ ]
214
+ ], tt = [
215
+ [
216
+ {
217
+ label: "1",
218
+ value: "1",
219
+ type: "char"
220
+ },
221
+ {
222
+ label: "2",
223
+ value: "2",
224
+ type: "char"
225
+ },
226
+ {
227
+ label: "3",
228
+ value: "3",
229
+ type: "char"
230
+ }
231
+ ],
232
+ [
233
+ {
234
+ label: "4",
235
+ value: "4",
236
+ type: "char"
237
+ },
238
+ {
239
+ label: "5",
240
+ value: "5",
241
+ type: "char"
242
+ },
243
+ {
244
+ label: "6",
245
+ value: "6",
246
+ type: "char"
247
+ }
248
+ ],
249
+ [
250
+ {
251
+ label: "7",
252
+ value: "7",
253
+ type: "char"
254
+ },
255
+ {
256
+ label: "8",
257
+ value: "8",
258
+ type: "char"
259
+ },
260
+ {
261
+ label: "9",
262
+ value: "9",
263
+ type: "char"
264
+ }
265
+ ],
266
+ [
267
+ {
268
+ label: ".",
269
+ value: ".",
270
+ type: "char"
271
+ },
272
+ {
273
+ label: "0",
274
+ value: "0",
275
+ type: "char"
276
+ },
277
+ {
278
+ label: "⌫",
279
+ value: "Backspace",
280
+ type: "action"
281
+ }
282
+ ]
283
+ ], rt = [
284
+ [
285
+ {
286
+ label: "1",
287
+ value: "1",
288
+ type: "char"
289
+ },
290
+ {
291
+ label: "2",
292
+ value: "2",
293
+ type: "char"
294
+ },
295
+ {
296
+ label: "3",
297
+ value: "3",
298
+ type: "char"
299
+ }
300
+ ],
301
+ [
302
+ {
303
+ label: "4",
304
+ value: "4",
305
+ type: "char"
306
+ },
307
+ {
308
+ label: "5",
309
+ value: "5",
310
+ type: "char"
311
+ },
312
+ {
313
+ label: "6",
314
+ value: "6",
315
+ type: "char"
316
+ }
317
+ ],
318
+ [
319
+ {
320
+ label: "7",
321
+ value: "7",
322
+ type: "char"
323
+ },
324
+ {
325
+ label: "8",
326
+ value: "8",
327
+ type: "char"
328
+ },
329
+ {
330
+ label: "9",
331
+ value: "9",
332
+ type: "char"
333
+ }
334
+ ],
335
+ [
336
+ {
337
+ label: "*",
338
+ value: "*",
339
+ type: "char"
340
+ },
341
+ {
342
+ label: "0",
343
+ value: "0",
344
+ type: "char"
345
+ },
346
+ {
347
+ label: "#",
348
+ value: "#",
349
+ type: "char"
350
+ }
351
+ ],
352
+ [
353
+ {
354
+ label: "+",
355
+ value: "+",
356
+ type: "char"
357
+ },
358
+ {
359
+ label: "⌫",
360
+ value: "Backspace",
361
+ width: 2,
362
+ type: "action"
363
+ }
364
+ ]
365
+ ];
366
+ function de(e) {
367
+ switch (e) {
368
+ case "hangul":
369
+ return !0;
370
+ case "alpha":
371
+ case "alphanumeric":
372
+ case "number":
373
+ case "tel":
374
+ return !1;
375
+ default:
376
+ return null;
377
+ }
378
+ }
379
+ const se = () => !0, nt = {
380
+ text: {
381
+ mode: "text",
382
+ layout: G,
383
+ filterKey: se,
384
+ sanitizeValue: (e) => e.replace(/[\r\n\t]+/g, " ")
385
+ },
386
+ number: {
387
+ mode: "number",
388
+ layout: tt,
389
+ filterKey: (e) => /^[0-9.]+$/.test(e),
390
+ sanitizeValue: (e) => e.replace(/[^0-9.]/g, "")
391
+ },
392
+ tel: {
393
+ mode: "tel",
394
+ layout: rt,
395
+ filterKey: (e) => /^[0-9*#+]+$/.test(e),
396
+ sanitizeValue: (e) => e.replace(/[^0-9*#+]/g, "")
397
+ },
398
+ hangul: {
399
+ mode: "hangul",
400
+ layout: G,
401
+ filterKey: se,
402
+ sanitizeValue: (e) => e.replace(/[A-Za-z]/g, "")
403
+ },
404
+ alpha: {
405
+ mode: "alpha",
406
+ layout: G,
407
+ filterKey: (e) => /^[A-Za-z]+$/.test(e),
408
+ sanitizeValue: (e) => e.replace(/[^A-Za-z]/g, "")
409
+ },
410
+ alphanumeric: {
411
+ mode: "alphanumeric",
412
+ layout: [
413
+ Array.from("1234567890", (e) => ({ value: e })),
414
+ ...G
415
+ ],
416
+ filterKey: (e) => /^[A-Za-z0-9]+$/.test(e),
417
+ sanitizeValue: (e) => e.replace(/[^A-Za-z0-9]/g, "")
418
+ },
419
+ custom: {
420
+ mode: "custom",
421
+ layout: G,
422
+ filterKey: se,
423
+ sanitizeValue: (e) => e.replace(/[\r\n\t]+/g, " ")
424
+ }
425
+ };
426
+ function ye(e) {
427
+ const r = e?.mode ?? "text", n = nt[r];
428
+ return {
429
+ mode: r,
430
+ layout: e?.layout ?? n.layout ?? G,
431
+ filterKey: e?.filterKey ?? n.filterKey ?? se,
432
+ sanitizeValue: e?.sanitizeValue ?? n.sanitizeValue ?? ((o) => o)
433
+ };
434
+ }
435
+ const ot = new Intl.Segmenter(void 0, { granularity: "grapheme" }), at = new Intl.Segmenter(void 0, { granularity: "word" });
436
+ function it(e, r) {
437
+ const n = Math.max(0, Math.min(r, e.length - 1));
438
+ for (const o of at.segment(e))
439
+ if (n < o.index + o.segment.length)
440
+ return [o.index, o.index + o.segment.length];
441
+ return [0, 0];
442
+ }
443
+ const Ee = (e) => Array.from(ot.segment(e));
444
+ function ue(e, r) {
445
+ return [
446
+ ...Ee(e).map((o) => o.index),
447
+ e.length
448
+ ].filter((o) => o <= Math.max(0, r)).at(-1) ?? 0;
449
+ }
450
+ function be(e, r, n) {
451
+ const o = [
452
+ ...Ee(e).map((i) => i.index),
453
+ e.length
454
+ ];
455
+ return n < 0 ? o.filter((i) => i < r).at(-1) ?? 0 : o.find((i) => i > r) ?? e.length;
456
+ }
457
+ const te = ({ anchor: e, caret: r }) => [Math.min(e, r), Math.max(e, r)];
458
+ function lt(e, r, n = !1, o) {
459
+ const [i, c] = te(e);
460
+ let h = e.value.slice(0, i), v = r;
461
+ i === c && e.composing && n && fe(h.at(-1) ?? "") && (v = Ge([h.at(-1), r]), h = h.slice(0, -1));
462
+ const d = h + v + e.value.slice(c);
463
+ if (o !== void 0 && d.length > o) return e;
464
+ const L = h.length + v.length;
465
+ return { value: d, caret: L, anchor: L, composing: n };
466
+ }
467
+ function me(e, r) {
468
+ let [n, o] = te(e);
469
+ if (n === o) {
470
+ if (r < 0 && e.composing && fe(e.value[n - 1] ?? "")) {
471
+ const i = e.value.slice(0, n - 1) + Qe(e.value[n - 1]);
472
+ return {
473
+ value: i + e.value.slice(o),
474
+ anchor: i.length,
475
+ caret: i.length,
476
+ composing: !0
477
+ };
478
+ }
479
+ r < 0 ? n = be(e.value, n, -1) : o = be(e.value, o, 1);
480
+ }
481
+ return {
482
+ value: e.value.slice(0, n) + e.value.slice(o),
483
+ caret: n,
484
+ anchor: n,
485
+ composing: !1
486
+ };
487
+ }
488
+ function Ve(e, r, n = !1) {
489
+ const [o, i] = te(e), c = r === "home" ? 0 : r === "end" ? e.value.length : !n && o !== i ? r < 0 ? o : i : be(e.value, e.caret, r);
490
+ return {
491
+ ...e,
492
+ caret: c,
493
+ anchor: n ? e.anchor : c,
494
+ composing: !1
495
+ };
496
+ }
497
+ const kt = We(
498
+ function({
499
+ value: r,
500
+ defaultValue: n = "",
501
+ placeholder: o,
502
+ onChange: i,
503
+ onValueChange: c,
504
+ onClipboardError: h,
505
+ mode: v = "text",
506
+ layout: d,
507
+ filterKey: L,
508
+ sanitizeValue: f,
509
+ disabled: l = !1,
510
+ readOnly: u = !1,
511
+ maxLength: I,
512
+ ...w
513
+ }, Q) {
514
+ const H = Be(), {
515
+ focusId: re,
516
+ onFocus: X,
517
+ onBlur: D,
518
+ defaultLayout: O,
519
+ inputRef: Z,
520
+ hangulMode: ne,
521
+ theme: p,
522
+ toggleKorean: S,
523
+ enterSelectionMode: g
524
+ } = Fe(), y = P(null), z = P(null), [A, j] = R(() => ({
525
+ value: r ?? n,
526
+ caret: (r ?? n).length,
527
+ anchor: (r ?? n).length,
528
+ composing: !1
529
+ })), T = r ?? A.value, s = P(A), m = P(0), U = P(new Oe()), W = P(!1), F = re === H, _ = P(F);
530
+ _.current = F;
531
+ const ae = r !== void 0 && r !== A.value;
532
+ ae && U.current.clear(), s.current = {
533
+ ...A,
534
+ value: T,
535
+ caret: ue(T, A.caret),
536
+ anchor: ue(T, A.anchor),
537
+ composing: ae ? !1 : A.composing
538
+ };
539
+ const N = Ke(
540
+ () => ye({
541
+ mode: v,
542
+ layout: d ?? (v === "text" || v === "custom" ? O : void 0),
543
+ filterKey: L,
544
+ sanitizeValue: f
545
+ }),
546
+ [v, d, O, L, f]
547
+ ), [b, K] = R(""), Y = P(
548
+ void 0
549
+ ), B = P(null), M = k(() => {
550
+ clearTimeout(Y.current), B.current = null;
551
+ }, []);
552
+ V(() => {
553
+ (l || u) && M();
554
+ }, [l, u, M]), V(() => {
555
+ const t = (a) => {
556
+ B.current && B.current.id !== a.pointerId && M();
557
+ };
558
+ return window.addEventListener("blur", M), window.addEventListener("scroll", M, !0), window.addEventListener("pointerdown", t, !0), document.addEventListener("visibilitychange", M), () => {
559
+ M(), window.removeEventListener("blur", M), window.removeEventListener("scroll", M, !0), window.removeEventListener("pointerdown", t, !0), document.removeEventListener("visibilitychange", M);
560
+ };
561
+ }, [M]);
562
+ const x = k(
563
+ (t, a = !0) => {
564
+ const E = s.current.value;
565
+ if (a && U.current.record(s.current, t), s.current = t, m.current++, j(t), t.value !== E) {
566
+ c?.(t.value);
567
+ const $ = { value: t.value };
568
+ i?.({
569
+ target: $,
570
+ currentTarget: $
571
+ });
572
+ }
573
+ },
574
+ [i, c]
575
+ ), ee = k(
576
+ (t, a = !1) => {
577
+ if (l || u) return;
578
+ const E = N.sanitizeValue(t).replace(/[\r\n\t]+/g, " ");
579
+ E && x(lt(s.current, E, a, I));
580
+ },
581
+ [l, u, N, I, x]
582
+ ), pe = k(() => {
583
+ !l && !u && x(U.current.undo(s.current), !1);
584
+ }, [l, u, x]), he = k(() => {
585
+ !l && !u && x(U.current.redo(s.current), !1);
586
+ }, [l, u, x]), Le = k(
587
+ () => x({
588
+ ...s.current,
589
+ caret: s.current.value.length,
590
+ anchor: 0,
591
+ composing: !1
592
+ }),
593
+ [x]
594
+ ), Se = k(
595
+ (t, a = !1) => x(Ve(s.current, t === "left" ? -1 : 1, a)),
596
+ [x]
597
+ ), Ne = (t) => {
598
+ if (w.onKeyDown?.(t), t.defaultPrevented || l) return;
599
+ const a = t.key;
600
+ if (a === "Escape") {
601
+ t.preventDefault(), x({ ...s.current, composing: !1 }), D(!0), y.current?.blur();
602
+ return;
603
+ }
604
+ if (a === "HangulMode") {
605
+ t.preventDefault(), x({ ...s.current, composing: !1 }), S();
606
+ return;
607
+ }
608
+ const E = t.ctrlKey || t.metaKey;
609
+ if (E && ["z", "y"].includes(a.toLowerCase())) {
610
+ t.preventDefault(), a.toLowerCase() === "y" || t.shiftKey ? he() : pe();
611
+ return;
612
+ }
613
+ if (E && a.toLowerCase() === "a") {
614
+ t.preventDefault(), x({
615
+ ...s.current,
616
+ caret: s.current.value.length,
617
+ anchor: 0,
618
+ composing: !1
619
+ });
620
+ return;
621
+ }
622
+ const $ = a === "Home" || a === "ArrowUp" || E && a === "ArrowLeft" ? "home" : a === "End" || a === "ArrowDown" || E && a === "ArrowRight" ? "end" : a === "ArrowLeft" ? -1 : a === "ArrowRight" ? 1 : null;
623
+ if ($ !== null) {
624
+ t.preventDefault(), x(Ve(s.current, $, t.shiftKey));
625
+ return;
626
+ }
627
+ if (a === "Tab" || a === "Enter") {
628
+ x({ ...s.current, composing: !1 });
629
+ return;
630
+ }
631
+ if (u) return;
632
+ if (a === "Backspace" || a === "Delete") {
633
+ t.preventDefault(), x(me(s.current, a === "Backspace" ? -1 : 1));
634
+ return;
635
+ }
636
+ const J = et(
637
+ t,
638
+ de(N.mode) ?? ne
639
+ );
640
+ J.handled && J.text && (t.preventDefault(), N.filterKey(J.text) && ee(J.text, J.composing));
641
+ }, ie = k(
642
+ (t) => {
643
+ const a = t instanceof Error ? t : new Error(String(t));
644
+ W.current && (K(
645
+ "클립보드에 접근할 수 없습니다. 키보드의 복사·붙여넣기 단축키를 사용해 주세요."
646
+ ), h?.(a));
647
+ },
648
+ [h]
649
+ ), le = k(async () => {
650
+ const [t, a] = te(s.current);
651
+ t !== a && (await navigator.clipboard.writeText(
652
+ s.current.value.slice(t, a)
653
+ ), W.current && K("선택한 내용을 복사했습니다."));
654
+ }, []), Ae = k(async () => {
655
+ if (l || u) return;
656
+ const t = s.current, a = m.current;
657
+ t.anchor !== t.caret && (await le(), W.current && _.current && m.current === a && s.current.value === t.value && x(me(t, -1)));
658
+ }, [l, u, le, x]), Pe = k(async () => {
659
+ if (l || u) return;
660
+ const t = m.current, a = s.current.value, E = await navigator.clipboard.readText();
661
+ W.current && _.current && m.current === t && s.current.value === a && ee(E);
662
+ }, [l, u, ee]), oe = Ke(
663
+ () => ({
664
+ focus: (t) => {
665
+ l || y.current?.focus(t);
666
+ },
667
+ blur: () => {
668
+ y.current?.blur(), _.current && D(!0);
669
+ },
670
+ getValue: () => s.current.value,
671
+ setSelectionRange: (t, a) => x({
672
+ ...s.current,
673
+ anchor: ue(s.current.value, t),
674
+ caret: ue(s.current.value, a),
675
+ composing: !1
676
+ }),
677
+ handleKeyDown: (t) => y.current?.dispatchEvent(
678
+ new KeyboardEvent("keydown", {
679
+ key: t.key,
680
+ shiftKey: t.shiftKey,
681
+ ctrlKey: t.ctrlKey,
682
+ metaKey: t.metaKey,
683
+ altKey: t.altKey,
684
+ code: t.code,
685
+ bubbles: !0,
686
+ cancelable: !0
687
+ })
688
+ ),
689
+ insertText: (t, a) => {
690
+ N.filterKey(t) && ee(t, a);
691
+ },
692
+ scrollIntoView: () => y.current?.scrollIntoView({ block: "nearest", inline: "nearest" }),
693
+ moveCaret: Se,
694
+ undo: pe,
695
+ redo: he,
696
+ selectAll: Le,
697
+ copySelection: () => le().catch(ie),
698
+ pasteClipboard: () => Pe().catch(ie),
699
+ cutSelection: () => Ae().catch(ie)
700
+ }),
701
+ [
702
+ N,
703
+ ee,
704
+ Se,
705
+ le,
706
+ Pe,
707
+ Ae,
708
+ ie,
709
+ pe,
710
+ he,
711
+ Le,
712
+ l,
713
+ D,
714
+ x
715
+ ]
716
+ );
717
+ _e(Q, () => oe, [oe]), V(() => {
718
+ F || j(
719
+ (t) => t.composing ? { ...t, composing: !1 } : t
720
+ );
721
+ }, [F]), V(() => {
722
+ if (!(!F || l || u))
723
+ return Z.current = oe, () => {
724
+ Z.current === oe && (Z.current = null);
725
+ };
726
+ }, [F, l, u, oe, Z]), V(() => {
727
+ F && y.current && (l || u ? D(!0) : X(H, y.current, N));
728
+ }, [F, l, u, H, N, X, D]), V(() => (W.current = !0, () => {
729
+ W.current = !1, clearTimeout(Y.current), _.current && D(!0);
730
+ }), [D]), V(() => {
731
+ if (!F || !y.current || !z.current) return;
732
+ const t = y.current.getBoundingClientRect(), a = z.current.getBoundingClientRect();
733
+ a.right > t.right - 12 ? y.current.scrollLeft += a.right - t.right + 12 : a.left < t.left + 12 && (y.current.scrollLeft -= t.left + 12 - a.left);
734
+ }, [T, A.caret, F]);
735
+ const Me = (t, a) => {
736
+ if (a ? w.onCut?.(t) : w.onCopy?.(t), t.defaultPrevented || l || a && u) return;
737
+ const [E, $] = te(s.current);
738
+ E !== $ && (t.preventDefault(), t.clipboardData.setData(
739
+ "text/plain",
740
+ s.current.value.slice(E, $)
741
+ ), a && x(me(s.current, -1)));
742
+ }, ce = (t, a = !0) => {
743
+ for (const E of y.current?.querySelectorAll(
744
+ "[data-char-index]"
745
+ ) ?? []) {
746
+ const $ = E.getBoundingClientRect();
747
+ if (t < $.left + $.width * (a ? 0.5 : 1))
748
+ return Number(E.dataset.charIndex);
749
+ }
750
+ return s.current.value.length;
751
+ }, ge = () => {
752
+ y.current?.focus({ preventScroll: !0 }), !u && y.current && X(H, y.current, N);
753
+ }, Xe = (t) => {
754
+ if (w.onPointerDown?.(t), t.defaultPrevented || l || t.button !== 0) return;
755
+ const a = t.pointerType === "mouse";
756
+ if (a || t.preventDefault(), B.current || t.isPrimary === !1) {
757
+ M();
758
+ return;
759
+ }
760
+ const E = ce(t.clientX), $ = t.shiftKey ? s.current.anchor : E;
761
+ B.current = {
762
+ id: t.pointerId,
763
+ x: t.clientX,
764
+ y: t.clientY,
765
+ anchor: $,
766
+ mouse: a,
767
+ held: !1
768
+ }, clearTimeout(Y.current), a ? (ge(), x({ ...s.current, caret: E, anchor: $, composing: !1 }), y.current?.setPointerCapture?.(t.pointerId)) : u || (Y.current = setTimeout(() => {
769
+ if (!B.current) return;
770
+ B.current.held = !0;
771
+ const [J, Ye] = it(
772
+ s.current.value,
773
+ ce(B.current.x, !1)
774
+ );
775
+ ge(), x({ ...s.current, anchor: J, caret: Ye, composing: !1 }), g();
776
+ }, 550));
777
+ }, [Ce, Ie] = te(s.current), Ue = Ee(T), Te = /* @__PURE__ */ C(
778
+ "span",
779
+ {
780
+ ref: z,
781
+ "aria-hidden": "true",
782
+ className: "vk-caret",
783
+ style: {
784
+ display: "inline-block",
785
+ width: 0,
786
+ height: "1.1em",
787
+ verticalAlign: "-0.15em",
788
+ position: "relative"
789
+ },
790
+ children: F && !u && !l && Ce === Ie && /* @__PURE__ */ C(
791
+ "span",
792
+ {
793
+ style: {
794
+ position: "absolute",
795
+ height: "100%",
796
+ borderLeft: "2px solid currentColor"
797
+ }
798
+ }
799
+ )
800
+ }
801
+ );
802
+ return /* @__PURE__ */ q(
803
+ "div",
804
+ {
805
+ ...w,
806
+ ref: y,
807
+ id: w.id ?? H,
808
+ role: "textbox",
809
+ tabIndex: l ? -1 : w.tabIndex ?? 0,
810
+ "aria-disabled": l || void 0,
811
+ "aria-readonly": u || void 0,
812
+ "aria-multiline": "false",
813
+ "aria-placeholder": o,
814
+ "data-virtual-input": "true",
815
+ "data-focused": F || void 0,
816
+ "data-value": T,
817
+ style: {
818
+ display: "block",
819
+ boxSizing: "border-box",
820
+ minHeight: "2.75em",
821
+ padding: "0.65em 0.8em",
822
+ border: "1px solid #94a3b8",
823
+ borderRadius: 8,
824
+ font: "inherit",
825
+ width: "100%",
826
+ whiteSpace: "pre",
827
+ overflowX: "auto",
828
+ scrollbarWidth: "none",
829
+ cursor: l ? "not-allowed" : "text",
830
+ userSelect: "none",
831
+ WebkitUserSelect: "none",
832
+ WebkitTouchCallout: "none",
833
+ touchAction: "manipulation",
834
+ opacity: l ? 0.5 : 1,
835
+ outlineOffset: 3,
836
+ ...w.style
837
+ },
838
+ onFocus: (t) => {
839
+ w.onFocus?.(t), !t.defaultPrevented && !l && !u && X(H, t.currentTarget, N);
840
+ },
841
+ onBlur: (t) => {
842
+ w.onBlur?.(t), M(), t.defaultPrevented || D(t);
843
+ },
844
+ onKeyDown: Ne,
845
+ onCopy: (t) => Me(t, !1),
846
+ onCut: (t) => Me(t, !0),
847
+ onPaste: (t) => {
848
+ w.onPaste?.(t), !t.defaultPrevented && !l && !u && (t.preventDefault(), ee(t.clipboardData.getData("text/plain")));
849
+ },
850
+ onPointerDown: Xe,
851
+ onPointerMove: (t) => {
852
+ if (w.onPointerMove?.(t), t.defaultPrevented) {
853
+ M();
854
+ return;
855
+ }
856
+ !B.current || B.current.id !== t.pointerId || Math.hypot(
857
+ t.clientX - B.current.x,
858
+ t.clientY - B.current.y
859
+ ) > 8 && (clearTimeout(Y.current), B.current.mouse ? x({
860
+ ...s.current,
861
+ caret: ce(t.clientX),
862
+ anchor: B.current.anchor,
863
+ composing: !1
864
+ }) : M());
865
+ },
866
+ onPointerUp: (t) => {
867
+ w.onPointerUp?.(t);
868
+ const a = B.current;
869
+ if (!t.defaultPrevented && a?.id === t.pointerId && !a.mouse && !a.held && Math.hypot(t.clientX - a.x, t.clientY - a.y) <= 8) {
870
+ const E = ce(t.clientX);
871
+ ge(), x({
872
+ ...s.current,
873
+ caret: E,
874
+ anchor: E,
875
+ composing: !1
876
+ });
877
+ }
878
+ M();
879
+ },
880
+ onPointerCancel: (t) => {
881
+ w.onPointerCancel?.(t), M();
882
+ },
883
+ onLostPointerCapture: (t) => {
884
+ w.onLostPointerCapture?.(t), B.current?.id === t.pointerId && M();
885
+ },
886
+ onContextMenu: (t) => {
887
+ w.onContextMenu?.(t), t.defaultPrevented || t.preventDefault();
888
+ },
889
+ children: [
890
+ Ue.map(({ segment: t, index: a }) => /* @__PURE__ */ q("span", { children: [
891
+ a === s.current.caret && Te,
892
+ /* @__PURE__ */ C(
893
+ "span",
894
+ {
895
+ "data-char-index": a,
896
+ style: a >= Ce && a < Ie ? { background: "#bfdbfe", color: "#0f172a" } : void 0,
897
+ children: t
898
+ }
899
+ )
900
+ ] }, a)),
901
+ s.current.caret === T.length && Te,
902
+ !T && /* @__PURE__ */ C(
903
+ "span",
904
+ {
905
+ "aria-hidden": "true",
906
+ style: { color: p === "dark" ? "#a6b7a9" : "#58665d" },
907
+ children: o || " "
908
+ }
909
+ ),
910
+ /* @__PURE__ */ C(
911
+ "span",
912
+ {
913
+ role: "status",
914
+ style: {
915
+ position: "absolute",
916
+ width: 1,
917
+ height: 1,
918
+ overflow: "hidden",
919
+ clipPath: "inset(50%)",
920
+ whiteSpace: "nowrap"
921
+ },
922
+ children: b
923
+ }
924
+ )
925
+ ]
926
+ }
927
+ );
928
+ }
929
+ ), ct = [
930
+ [
931
+ {
932
+ value: "1"
933
+ },
934
+ {
935
+ value: "2"
936
+ },
937
+ {
938
+ value: "3"
939
+ },
940
+ {
941
+ value: "4"
942
+ },
943
+ {
944
+ value: "5"
945
+ },
946
+ {
947
+ value: "6"
948
+ },
949
+ {
950
+ value: "7"
951
+ },
952
+ {
953
+ value: "8"
954
+ },
955
+ {
956
+ value: "9"
957
+ },
958
+ {
959
+ value: "0"
960
+ }
961
+ ],
962
+ [
963
+ {
964
+ value: "@"
965
+ },
966
+ {
967
+ value: "#"
968
+ },
969
+ {
970
+ value: "$"
971
+ },
972
+ {
973
+ value: "%"
974
+ },
975
+ {
976
+ value: "&"
977
+ },
978
+ {
979
+ value: "*"
980
+ },
981
+ {
982
+ value: "-"
983
+ },
984
+ {
985
+ value: "+"
986
+ },
987
+ {
988
+ value: "("
989
+ },
990
+ {
991
+ value: ")"
992
+ }
993
+ ],
994
+ [
995
+ {
996
+ value: "!"
997
+ },
998
+ {
999
+ value: "?"
1000
+ },
1001
+ {
1002
+ value: "/"
1003
+ },
1004
+ {
1005
+ value: ":"
1006
+ },
1007
+ {
1008
+ value: ";"
1009
+ },
1010
+ {
1011
+ value: '"'
1012
+ },
1013
+ {
1014
+ value: "'"
1015
+ },
1016
+ {
1017
+ value: "_"
1018
+ },
1019
+ {
1020
+ value: "Backspace",
1021
+ label: "⌫",
1022
+ type: "action"
1023
+ }
1024
+ ],
1025
+ [
1026
+ {
1027
+ value: ","
1028
+ },
1029
+ {
1030
+ value: ".",
1031
+ width: 1
1032
+ },
1033
+ {
1034
+ value: " ",
1035
+ label: "공백",
1036
+ width: 4,
1037
+ type: "action"
1038
+ },
1039
+ {
1040
+ value: "Enter",
1041
+ label: "↵",
1042
+ type: "action"
1043
+ }
1044
+ ]
1045
+ ];
1046
+ function ut({
1047
+ tagName: e,
1048
+ css: r,
1049
+ children: n,
1050
+ hostRef: o,
1051
+ ...i
1052
+ }) {
1053
+ const [c, h] = R(null), v = k(
1054
+ (d) => {
1055
+ o && (o.current = d), d && h(d.shadowRoot ?? d.attachShadow({ mode: "open" }));
1056
+ },
1057
+ [o]
1058
+ );
1059
+ return Je(
1060
+ e,
1061
+ { ...i, ref: v },
1062
+ c && ke(
1063
+ /* @__PURE__ */ q(ze, { children: [
1064
+ r && /* @__PURE__ */ C("style", { children: r }),
1065
+ n
1066
+ ] }),
1067
+ c
1068
+ )
1069
+ );
1070
+ }
1071
+ function De(e, r, n) {
1072
+ if (e.type === "action") return e.value === `
1073
+ ` ? "Enter" : e.value;
1074
+ if (!/^[a-zA-Z]$/.test(e.value)) return e.value;
1075
+ const o = n ? e.value.toUpperCase() : e.value;
1076
+ return r ? Re(o) : o;
1077
+ }
1078
+ function xe(e, { disabled: r = !1, repeat: n = !1 } = {}) {
1079
+ const o = P(e);
1080
+ o.current = e;
1081
+ const i = P(void 0), c = P(null), [h, v] = R(!1), d = k(() => {
1082
+ clearTimeout(i.current), c.current = null, v(!1);
1083
+ }, []);
1084
+ V(() => (window.addEventListener("blur", d), document.addEventListener("visibilitychange", d), () => {
1085
+ d(), window.removeEventListener("blur", d), document.removeEventListener("visibilitychange", d);
1086
+ }), [d]), V(() => {
1087
+ r && d();
1088
+ }, [r, d]);
1089
+ const L = (f) => {
1090
+ const l = c.current?.bounds;
1091
+ return !!l && f.clientX >= l.left && f.clientX <= l.right && f.clientY >= l.top && f.clientY <= l.bottom;
1092
+ };
1093
+ return {
1094
+ "data-pressed": h || void 0,
1095
+ onPointerDown: (f) => {
1096
+ if (!(r || f.button !== 0 || c.current)) {
1097
+ f.preventDefault(), c.current = {
1098
+ id: f.pointerId,
1099
+ bounds: f.currentTarget.getBoundingClientRect(),
1100
+ repeated: !1
1101
+ }, v(!0);
1102
+ try {
1103
+ f.currentTarget.setPointerCapture?.(f.pointerId);
1104
+ } catch {
1105
+ }
1106
+ if (n) {
1107
+ const l = () => {
1108
+ c.current && (c.current.repeated = !0, o.current(), i.current = setTimeout(l, 65));
1109
+ };
1110
+ i.current = setTimeout(l, 450);
1111
+ }
1112
+ }
1113
+ },
1114
+ onPointerMove: (f) => {
1115
+ c.current?.id === f.pointerId && !L(f) && d();
1116
+ },
1117
+ onPointerUp: (f) => {
1118
+ if (c.current?.id !== f.pointerId) return;
1119
+ const l = !r && L(f) && !c.current.repeated;
1120
+ d(), l && o.current();
1121
+ },
1122
+ onPointerCancel: (f) => {
1123
+ c.current?.id === f.pointerId && d();
1124
+ },
1125
+ onLostPointerCapture: (f) => {
1126
+ c.current?.id === f.pointerId && d();
1127
+ },
1128
+ onPointerLeave: (f) => {
1129
+ c.current?.id === f.pointerId && !L(f) && d();
1130
+ },
1131
+ onClick: (f) => {
1132
+ !r && f.detail === 0 && !c.current && o.current();
1133
+ }
1134
+ };
1135
+ }
1136
+ const $e = {
1137
+ Shift: "Shift",
1138
+ HangulMode: "한영 전환",
1139
+ Backspace: "지우기",
1140
+ Delete: "앞 글자 지우기",
1141
+ Enter: "입력 완료",
1142
+ EnterSelectionMode: "텍스트 편집",
1143
+ ExitSelectionMode: "키보드로 돌아가기",
1144
+ ToggleSelectionAdjust: "선택 범위 조절",
1145
+ ArrowLeft: "커서 왼쪽",
1146
+ ArrowRight: "커서 오른쪽",
1147
+ Copy: "복사",
1148
+ Paste: "붙여넣기",
1149
+ Cut: "잘라내기",
1150
+ " ": "공백",
1151
+ Undo: "실행 취소",
1152
+ Redo: "다시 실행",
1153
+ SelectAll: "전체 선택"
1154
+ };
1155
+ function st({
1156
+ cell: e,
1157
+ label: r,
1158
+ value: n,
1159
+ active: o,
1160
+ disabled: i,
1161
+ dispatch: c
1162
+ }) {
1163
+ const h = xe(c, {
1164
+ disabled: i,
1165
+ repeat: ["Backspace", "Delete", "ArrowLeft", "ArrowRight"].includes(n)
1166
+ }), v = e.type === "action" && n === "HangulMode";
1167
+ return /* @__PURE__ */ C(
1168
+ "button",
1169
+ {
1170
+ type: "button",
1171
+ disabled: i,
1172
+ "aria-label": $e[n] ?? r,
1173
+ "aria-pressed": o,
1174
+ className: v ? "key action language" : e.type === "action" ? "key action" : "key",
1175
+ title: v ? i ? `${o ? "한국어" : "영어"} 전용` : `${o ? "영어" : "한국어"}로 전환` : void 0,
1176
+ style: { flex: e.width && e.width > 0 ? e.width : 1 },
1177
+ ...h,
1178
+ children: v && !e.label ? /* @__PURE__ */ q("span", { className: "language-label", "aria-hidden": "true", children: [
1179
+ /* @__PURE__ */ q(
1180
+ "svg",
1181
+ {
1182
+ width: "19",
1183
+ height: "19",
1184
+ viewBox: "0 0 24 24",
1185
+ fill: "none",
1186
+ stroke: "currentColor",
1187
+ strokeWidth: "1.65",
1188
+ strokeLinecap: "round",
1189
+ strokeLinejoin: "round",
1190
+ focusable: "false",
1191
+ children: [
1192
+ /* @__PURE__ */ C("circle", { cx: "12", cy: "12", r: "9" }),
1193
+ /* @__PURE__ */ C("ellipse", { cx: "12", cy: "12", rx: "4", ry: "9" }),
1194
+ /* @__PURE__ */ C("path", { d: "M3 12h18" })
1195
+ ]
1196
+ }
1197
+ ),
1198
+ /* @__PURE__ */ C("span", { children: o ? "한" : "EN" })
1199
+ ] }) : r
1200
+ }
1201
+ );
1202
+ }
1203
+ function dt({
1204
+ layout: e,
1205
+ viewport: r,
1206
+ onHeightChange: n
1207
+ }) {
1208
+ const o = Fe(), {
1209
+ inputRef: i,
1210
+ hangulMode: c,
1211
+ shift: h,
1212
+ shiftLocked: v,
1213
+ theme: d,
1214
+ selectionMode: L,
1215
+ selectionAdjusting: f,
1216
+ activeInputPolicy: l,
1217
+ onBlur: u
1218
+ } = o, I = P(null), [w, Q] = R(!1), H = xe(() => Q((p) => !p)), re = xe(() => u(!0)), X = ["text", "hangul", "custom"].includes(
1219
+ l.mode
1220
+ ), D = w && X && !L ? ct : e;
1221
+ V(() => {
1222
+ if (!I.current) return;
1223
+ const p = () => {
1224
+ const g = I.current?.getBoundingClientRect().height ?? 0;
1225
+ n(g);
1226
+ };
1227
+ p();
1228
+ const S = new ResizeObserver(p);
1229
+ return S.observe(I.current), () => S.disconnect();
1230
+ }, [n]), V(() => {
1231
+ let p = null;
1232
+ const S = /* @__PURE__ */ new Set(), g = (m) => m.composedPath().some(
1233
+ (U) => U === I.current || U instanceof Element && U.hasAttribute("data-virtual-input")
1234
+ ), y = (m) => {
1235
+ S.add(m.pointerId), p = S.size !== 1 || m.button !== 0 || g(m) ? null : { x: m.clientX, y: m.clientY, id: m.pointerId };
1236
+ }, z = (m) => {
1237
+ p && p.id === m.pointerId && Math.hypot(m.clientX - p.x, m.clientY - p.y) < 10 && !g(m) && u(!0), p = null, S.delete(m.pointerId);
1238
+ }, A = (m) => {
1239
+ p?.id === m.pointerId && Math.hypot(m.clientX - p.x, m.clientY - p.y) >= 10 && (p = null);
1240
+ }, j = () => {
1241
+ p = null;
1242
+ }, T = (m) => {
1243
+ j(), S.delete(m.pointerId);
1244
+ }, s = () => {
1245
+ j(), S.clear();
1246
+ };
1247
+ return window.addEventListener("pointerdown", y, !0), window.addEventListener("pointermove", A, !0), window.addEventListener("pointerup", z, !0), window.addEventListener("pointercancel", T, !0), window.addEventListener("scroll", j, !0), window.addEventListener("blur", s), document.addEventListener("visibilitychange", s), () => {
1248
+ window.removeEventListener("pointerdown", y, !0), window.removeEventListener("pointermove", A, !0), window.removeEventListener("pointerup", z, !0), window.removeEventListener("pointercancel", T, !0), window.removeEventListener("scroll", j, !0), window.removeEventListener("blur", s), document.removeEventListener("visibilitychange", s);
1249
+ };
1250
+ }, [u]);
1251
+ const O = (p) => {
1252
+ const S = De(p, c, h);
1253
+ if (p.type !== "action") {
1254
+ i.current?.insertText(S, fe(S)), o.consumeShift();
1255
+ return;
1256
+ }
1257
+ switch (S) {
1258
+ case "Undo":
1259
+ i.current?.undo();
1260
+ break;
1261
+ case "Redo":
1262
+ i.current?.redo();
1263
+ break;
1264
+ case "SelectAll":
1265
+ i.current?.selectAll();
1266
+ break;
1267
+ case "Shift":
1268
+ o.toggleShift();
1269
+ break;
1270
+ case "HangulMode":
1271
+ i.current?.handleKeyDown(
1272
+ new KeyboardEvent("keydown", { key: S })
1273
+ );
1274
+ break;
1275
+ case "EnterSelectionMode":
1276
+ Q(!1), o.enterSelectionMode();
1277
+ break;
1278
+ case "ExitSelectionMode":
1279
+ o.exitSelectionMode();
1280
+ break;
1281
+ case "ToggleSelectionAdjust":
1282
+ o.toggleSelectionAdjust();
1283
+ break;
1284
+ case "Copy":
1285
+ i.current?.copySelection();
1286
+ break;
1287
+ case "Paste":
1288
+ i.current?.pasteClipboard();
1289
+ break;
1290
+ case "Cut":
1291
+ i.current?.cutSelection();
1292
+ break;
1293
+ case "ArrowLeft":
1294
+ i.current?.moveCaret("left", f);
1295
+ break;
1296
+ case "ArrowRight":
1297
+ i.current?.moveCaret("right", f);
1298
+ break;
1299
+ default:
1300
+ S === " " ? i.current?.insertText(" ") : i.current?.handleKeyDown(
1301
+ new KeyboardEvent("keydown", { key: S })
1302
+ );
1303
+ }
1304
+ }, Z = de(l.mode) !== null, ne = {
1305
+ position: "fixed",
1306
+ zIndex: 9999,
1307
+ boxSizing: "border-box",
1308
+ display: "block",
1309
+ width: Math.min(r.width || 760, 760),
1310
+ left: r.offsetLeft + r.width / 2,
1311
+ transform: r.height ? "translate(-50%, -100%)" : "translateX(-50%)",
1312
+ ...r.height ? { top: r.offsetTop + r.height } : { bottom: 0 },
1313
+ maxHeight: r.height ? r.height * 0.65 : "65dvh",
1314
+ overflowY: "auto",
1315
+ colorScheme: d,
1316
+ background: d === "dark" ? "#18201f" : "#e9eeeb",
1317
+ color: d === "dark" ? "#eef4ef" : "#203b31",
1318
+ border: "1px solid " + (d === "dark" ? "#35413c" : "#c8d3cb"),
1319
+ borderRadius: "20px 20px 0 0",
1320
+ boxShadow: "0 -8px 48px #10251a20",
1321
+ touchAction: "manipulation",
1322
+ userSelect: "none",
1323
+ WebkitUserSelect: "none"
1324
+ };
1325
+ return ke(
1326
+ /* @__PURE__ */ C(
1327
+ ut,
1328
+ {
1329
+ tagName: "virtual-keypad",
1330
+ hostRef: I,
1331
+ "data-virtual-keypad": "true",
1332
+ style: ne,
1333
+ onPointerDown: (p) => {
1334
+ p.button === 0 && p.preventDefault();
1335
+ },
1336
+ onMouseDown: (p) => {
1337
+ p.button === 0 && p.preventDefault();
1338
+ },
1339
+ onBlur: o.onBlur,
1340
+ onKeyDown: (p) => {
1341
+ p.key === "Escape" && (p.preventDefault(), u(!0));
1342
+ },
1343
+ css: `
1344
+ * {
1345
+ box-sizing: border-box;
1346
+ }
1347
+ .keyboard {
1348
+ padding: 10px 8px max(12px, env(safe-area-inset-bottom));
1349
+ font:
1350
+ 500 16px system-ui,
1351
+ sans-serif;
1352
+ }
1353
+ .toolbar {
1354
+ display: flex;
1355
+ align-items: center;
1356
+ justify-content: space-between;
1357
+ padding: 0 6px 8px;
1358
+ font-size: 12px;
1359
+ }
1360
+ .toolbar span {
1361
+ opacity: 0.75;
1362
+ }
1363
+ .close {
1364
+ background: transparent;
1365
+ color: inherit;
1366
+ border: 0;
1367
+ padding: 8px 12px;
1368
+ cursor: pointer;
1369
+ border-radius: 6px;
1370
+ min-width: 44px;
1371
+ min-height: 44px;
1372
+ touch-action: pan-y;
1373
+ }
1374
+ .row {
1375
+ display: flex;
1376
+ gap: clamp(3px, 1vw, 7px);
1377
+ margin-top: 7px;
1378
+ }
1379
+ .key {
1380
+ min-width: 0;
1381
+ min-height: 44px;
1382
+ border: 0;
1383
+ border-radius: 8px;
1384
+ background: ${d === "dark" ? "#303c37" : "#fff"};
1385
+ color: inherit;
1386
+ box-shadow: 0 2px 0 ${d === "dark" ? "#0d1611" : "#bdc9c1"};
1387
+ font: inherit;
1388
+ padding: 8px 0;
1389
+ touch-action: none;
1390
+ cursor: pointer;
1391
+ user-select: none;
1392
+ }
1393
+ .action {
1394
+ background: ${d === "dark" ? "#414e46" : "#d7e1db"};
1395
+ font-size: 14px;
1396
+ }
1397
+ .key[aria-pressed="true"]:not(.language) {
1398
+ background: #246447;
1399
+ color: #fff;
1400
+ }
1401
+ .language-label {
1402
+ display: flex;
1403
+ align-items: center;
1404
+ justify-content: center;
1405
+ gap: 5px;
1406
+ font-size: 12px;
1407
+ font-weight: 600;
1408
+ line-height: 1;
1409
+ white-space: nowrap;
1410
+ }
1411
+ .language-label svg {
1412
+ flex-shrink: 0;
1413
+ }
1414
+ .language-label span {
1415
+ min-width: 1.5em;
1416
+ }
1417
+ .key[data-pressed="true"],
1418
+ .close[data-pressed="true"] {
1419
+ filter: brightness(0.9);
1420
+ box-shadow: none;
1421
+ }
1422
+ button:focus-visible {
1423
+ outline: 3px solid #48a97e;
1424
+ outline-offset: 2px;
1425
+ }
1426
+ button:disabled {
1427
+ opacity: 0.38;
1428
+ cursor: default;
1429
+ }
1430
+ @media (max-height: 500px) {
1431
+ .key {
1432
+ min-height: 44px;
1433
+ padding: 5px 0;
1434
+ }
1435
+ .row {
1436
+ margin-top: 4px;
1437
+ }
1438
+ .keyboard {
1439
+ padding-top: 0;
1440
+ }
1441
+ .toolbar {
1442
+ padding-bottom: 0;
1443
+ }
1444
+ }
1445
+ `,
1446
+ children: /* @__PURE__ */ q("section", { className: "keyboard", role: "group", "aria-label": "가상 키보드", children: [
1447
+ /* @__PURE__ */ q("div", { className: "toolbar", children: [
1448
+ /* @__PURE__ */ q("span", { children: [
1449
+ L ? "텍스트 편집" : w && X ? "숫자 · 기호" : l.mode === "number" ? "숫자" : l.mode === "tel" ? "전화번호" : c ? "한국어 · 두벌식" : "English",
1450
+ v ? " · Shift 고정" : ""
1451
+ ] }),
1452
+ X && !L && /* @__PURE__ */ C(
1453
+ "button",
1454
+ {
1455
+ type: "button",
1456
+ className: "close",
1457
+ "aria-label": "숫자·기호 전환",
1458
+ "aria-pressed": w,
1459
+ ...H,
1460
+ children: w ? "가 / ABC" : "123 / #+="
1461
+ }
1462
+ ),
1463
+ /* @__PURE__ */ C(
1464
+ "button",
1465
+ {
1466
+ type: "button",
1467
+ className: "close",
1468
+ ...re,
1469
+ "aria-label": "키보드 닫기",
1470
+ children: "닫기 ↓"
1471
+ }
1472
+ )
1473
+ ] }),
1474
+ D.map((p, S) => /* @__PURE__ */ C("div", { className: "row", children: p.map((g, y) => {
1475
+ const z = De(g, c, h), A = g.type === "action" ? g.label ?? $e[z] ?? z : /^[A-Za-z]$/.test(g.value) ? z : g.label ?? z, j = g.value === "Shift" ? h : g.value === "HangulMode" ? c : g.value === "ToggleSelectionAdjust" ? f : void 0;
1476
+ return /* @__PURE__ */ C(
1477
+ st,
1478
+ {
1479
+ cell: g,
1480
+ label: A,
1481
+ value: z,
1482
+ active: j,
1483
+ disabled: g.value === "HangulMode" && Z || (g.type !== "action" || z === " ") && !l.filterKey(z),
1484
+ dispatch: () => O(g)
1485
+ },
1486
+ `${S}-${y}-${g.value}`
1487
+ );
1488
+ }) }, S))
1489
+ ] })
1490
+ }
1491
+ ),
1492
+ document.body
1493
+ );
1494
+ }
1495
+ const ve = "virtual-keyboard:storage";
1496
+ function ft(e, r) {
1497
+ const n = P(r), [o, i] = R(r), c = P(o), h = k(
1498
+ () => n.current instanceof Function ? n.current() : n.current,
1499
+ []
1500
+ );
1501
+ V(() => {
1502
+ const d = (u) => {
1503
+ try {
1504
+ const I = u === null ? h() : JSON.parse(u);
1505
+ return typeof I == typeof h() ? I : h();
1506
+ } catch {
1507
+ return h();
1508
+ }
1509
+ }, L = (u) => {
1510
+ c.current = d(u), i(c.current);
1511
+ };
1512
+ try {
1513
+ L(window.localStorage.getItem(e));
1514
+ } catch {
1515
+ }
1516
+ const f = (u) => {
1517
+ try {
1518
+ if (u.storageArea && u.storageArea !== window.localStorage)
1519
+ return;
1520
+ } catch {
1521
+ return;
1522
+ }
1523
+ (u.key === e || u.key === null) && L(u.newValue);
1524
+ }, l = (u) => {
1525
+ const I = u.detail;
1526
+ I.key === e && L(I.raw);
1527
+ };
1528
+ return window.addEventListener("storage", f), window.addEventListener(ve, l), () => {
1529
+ window.removeEventListener("storage", f), window.removeEventListener(ve, l);
1530
+ };
1531
+ }, [e, h]);
1532
+ const v = k(
1533
+ (d) => {
1534
+ c.current = d instanceof Function ? d(c.current) : d, i(c.current), window.dispatchEvent(
1535
+ new CustomEvent(ve, {
1536
+ detail: { key: e, raw: JSON.stringify(c.current) }
1537
+ })
1538
+ );
1539
+ try {
1540
+ window.localStorage.setItem(e, JSON.stringify(c.current));
1541
+ } catch {
1542
+ }
1543
+ },
1544
+ [e]
1545
+ );
1546
+ return [o, v];
1547
+ }
1548
+ const pt = [
1549
+ [
1550
+ {
1551
+ label: "전체 선택",
1552
+ value: "SelectAll",
1553
+ type: "action"
1554
+ },
1555
+ {
1556
+ label: "실행 취소",
1557
+ value: "Undo",
1558
+ type: "action"
1559
+ },
1560
+ {
1561
+ label: "다시 실행",
1562
+ value: "Redo",
1563
+ type: "action"
1564
+ }
1565
+ ],
1566
+ [
1567
+ {
1568
+ label: "범위 조절",
1569
+ value: "ToggleSelectionAdjust",
1570
+ width: 1.4,
1571
+ type: "action"
1572
+ },
1573
+ {
1574
+ label: "←",
1575
+ value: "ArrowLeft",
1576
+ type: "action"
1577
+ },
1578
+ {
1579
+ label: "→",
1580
+ value: "ArrowRight",
1581
+ type: "action"
1582
+ }
1583
+ ],
1584
+ [
1585
+ {
1586
+ label: "복사",
1587
+ value: "Copy",
1588
+ width: 1.4,
1589
+ type: "action"
1590
+ },
1591
+ {
1592
+ label: "붙여넣기",
1593
+ value: "Paste",
1594
+ width: 1.4,
1595
+ type: "action"
1596
+ },
1597
+ {
1598
+ label: "잘라내기",
1599
+ value: "Cut",
1600
+ width: 1.2,
1601
+ type: "action"
1602
+ },
1603
+ {
1604
+ label: "⌫",
1605
+ value: "Backspace",
1606
+ type: "action"
1607
+ }
1608
+ ],
1609
+ [
1610
+ {
1611
+ label: "키보드",
1612
+ value: "ExitSelectionMode",
1613
+ type: "action"
1614
+ },
1615
+ {
1616
+ label: "␣",
1617
+ value: " ",
1618
+ width: 2.8,
1619
+ type: "action"
1620
+ },
1621
+ {
1622
+ label: "⏎",
1623
+ value: `
1624
+ `,
1625
+ type: "action"
1626
+ }
1627
+ ]
1628
+ ], ht = () => typeof window > "u" ? { width: 0, height: 0, scale: 1, offsetLeft: 0, offsetTop: 0 } : typeof window < "u" && window.visualViewport ? {
1629
+ width: window.visualViewport.width,
1630
+ height: window.visualViewport.height,
1631
+ scale: window.visualViewport.scale,
1632
+ offsetLeft: window.visualViewport.offsetLeft,
1633
+ offsetTop: window.visualViewport.offsetTop
1634
+ } : {
1635
+ width: window.innerWidth,
1636
+ height: window.innerHeight,
1637
+ scale: 1,
1638
+ offsetLeft: 0,
1639
+ offsetTop: 0
1640
+ }, gt = (e, r) => e.width === r.width && e.height === r.height && e.scale === r.scale && e.offsetLeft === r.offsetLeft && e.offsetTop === r.offsetTop, mt = () => {
1641
+ const [e, r] = R(() => ({
1642
+ width: 0,
1643
+ height: 0,
1644
+ scale: 1,
1645
+ offsetLeft: 0,
1646
+ offsetTop: 0
1647
+ }));
1648
+ return V(() => {
1649
+ if (typeof window > "u") return;
1650
+ let n = null;
1651
+ const o = () => {
1652
+ const c = ht();
1653
+ r(
1654
+ (h) => gt(h, c) ? h : c
1655
+ );
1656
+ };
1657
+ o();
1658
+ const i = () => {
1659
+ n !== null && cancelAnimationFrame(n), n = requestAnimationFrame(o);
1660
+ };
1661
+ return window.visualViewport ? (window.visualViewport.addEventListener("resize", i, {
1662
+ passive: !0
1663
+ }), window.visualViewport.addEventListener("scroll", i, {
1664
+ passive: !0
1665
+ })) : window.addEventListener("resize", i, { passive: !0 }), () => {
1666
+ n !== null && cancelAnimationFrame(n), window.visualViewport ? (window.visualViewport.removeEventListener("resize", i), window.visualViewport.removeEventListener("scroll", i)) : window.removeEventListener("resize", i);
1667
+ };
1668
+ }, []), e;
1669
+ };
1670
+ function vt() {
1671
+ const [e, r] = R("light");
1672
+ return V(() => {
1673
+ if (typeof window > "u" || !window.matchMedia) return;
1674
+ const n = window.matchMedia("(prefers-color-scheme: dark)");
1675
+ r(n.matches ? "dark" : "light");
1676
+ const o = (i) => {
1677
+ r(i.matches ? "dark" : "light");
1678
+ };
1679
+ return n.addEventListener("change", o), () => n.removeEventListener("change", o);
1680
+ }, []), e;
1681
+ }
1682
+ function je(e) {
1683
+ return e !== void 0 ? /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
1684
+ e
1685
+ ) : typeof navigator > "u" ? !1 : je(navigator.userAgent) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1 || typeof window < "u" && !!window.matchMedia?.("(pointer: coarse)").matches;
1686
+ }
1687
+ const we = "virtual-keyboard:focus-change";
1688
+ function Et({
1689
+ children: e,
1690
+ layout: r = G,
1691
+ defaultHangulMode: n = !0,
1692
+ theme: o,
1693
+ keyboardVisibility: i = "auto"
1694
+ }) {
1695
+ const c = Be(), h = P(null), v = P(null), d = P(
1696
+ void 0
1697
+ ), [L, f] = R(), [l, u] = R(0), [I, w] = R(!1), [Q, H] = R(!1), [re, X] = ft(
1698
+ "virtual-keyboard-hangul-mode",
1699
+ n
1700
+ ), [D, O] = R(
1701
+ () => ye({ layout: r })
1702
+ ), [Z, ne] = R(!1), [p, S] = R(0), g = mt(), y = vt(), z = de(D.mode) ?? re, A = !!L && (i === "always" || i === "auto" && Z), j = P(A);
1703
+ j.current = A, V(() => {
1704
+ const b = () => ne(je());
1705
+ b();
1706
+ const K = window.matchMedia?.("(pointer: coarse)");
1707
+ return K?.addEventListener("change", b), () => K?.removeEventListener("change", b);
1708
+ }, []);
1709
+ const T = k(() => {
1710
+ clearTimeout(d.current), v.current = null, h.current = null, f(void 0), u(0), w(!1), H(!1);
1711
+ }, []);
1712
+ V(() => {
1713
+ const b = (K) => {
1714
+ K.detail !== c && T();
1715
+ };
1716
+ return window.addEventListener(we, b), () => {
1717
+ window.removeEventListener(we, b), clearTimeout(d.current);
1718
+ };
1719
+ }, [c, T]);
1720
+ const s = k(
1721
+ (b, K, Y) => {
1722
+ clearTimeout(d.current), v.current !== K && (u(0), w(!1), H(!1)), v.current = K, O(ye(Y)), f(b), window.dispatchEvent(
1723
+ new CustomEvent(we, { detail: c })
1724
+ );
1725
+ },
1726
+ [c]
1727
+ ), m = k(
1728
+ (b) => {
1729
+ if (b === !0) {
1730
+ T();
1731
+ return;
1732
+ }
1733
+ const K = typeof b == "object" ? b.relatedTarget : null;
1734
+ K?.closest?.("[data-virtual-input], [data-virtual-keypad]") || !K && j.current || (clearTimeout(d.current), d.current = setTimeout(T, 0));
1735
+ },
1736
+ [T]
1737
+ );
1738
+ V(() => {
1739
+ if (!A || !p || g.scale !== 1) return;
1740
+ const b = requestAnimationFrame(() => {
1741
+ const K = v.current?.getBoundingClientRect();
1742
+ if (!K) return;
1743
+ const Y = g.offsetTop + g.height - p - 16;
1744
+ K.bottom > Y && window.scrollBy({ top: K.bottom - Y, behavior: "instant" });
1745
+ });
1746
+ return () => cancelAnimationFrame(b);
1747
+ }, [
1748
+ L,
1749
+ A,
1750
+ p,
1751
+ g.height,
1752
+ g.offsetTop,
1753
+ g.scale
1754
+ ]);
1755
+ const U = k(() => {
1756
+ de(D.mode) === null && X((b) => !b);
1757
+ }, [D.mode, X]), W = k(
1758
+ () => u((b) => (b + 1) % 3),
1759
+ []
1760
+ ), F = k(
1761
+ () => u((b) => b === 1 ? 0 : b),
1762
+ []
1763
+ ), _ = k(() => {
1764
+ w(!0), H(!1);
1765
+ }, []), ae = k(() => {
1766
+ w(!1), H(!1);
1767
+ }, []), N = k(
1768
+ () => H((b) => !b),
1769
+ []
1770
+ );
1771
+ return /* @__PURE__ */ q(
1772
+ He.Provider,
1773
+ {
1774
+ value: {
1775
+ inputRef: h,
1776
+ focusId: L,
1777
+ onFocus: s,
1778
+ onBlur: m,
1779
+ defaultLayout: r,
1780
+ hangulMode: z,
1781
+ shift: l > 0,
1782
+ shiftLocked: l === 2,
1783
+ theme: o ?? y,
1784
+ toggleKorean: U,
1785
+ toggleShift: W,
1786
+ consumeShift: F,
1787
+ selectionMode: I,
1788
+ selectionAdjusting: Q,
1789
+ enterSelectionMode: _,
1790
+ exitSelectionMode: ae,
1791
+ toggleSelectionAdjust: N,
1792
+ activeInputPolicy: D
1793
+ },
1794
+ children: [
1795
+ e,
1796
+ A && /* @__PURE__ */ q(ze, { children: [
1797
+ ke(
1798
+ /* @__PURE__ */ C(
1799
+ "div",
1800
+ {
1801
+ "aria-hidden": "true",
1802
+ style: {
1803
+ height: p,
1804
+ pointerEvents: "none",
1805
+ background: (o ?? y) === "dark" ? "#121c17" : "#f7f8f4"
1806
+ }
1807
+ }
1808
+ ),
1809
+ document.body
1810
+ ),
1811
+ /* @__PURE__ */ C(
1812
+ dt,
1813
+ {
1814
+ layout: I ? pt : D.layout,
1815
+ viewport: g,
1816
+ onHeightChange: S
1817
+ },
1818
+ L
1819
+ )
1820
+ ] })
1821
+ ]
1822
+ }
1823
+ );
1824
+ }
1825
+ export {
1826
+ kt as VirtualInput,
1827
+ Et as VirtualInputProvider
1828
+ };