@uiwwsw/virtual-keyboard 1.1.2 → 2.0.1

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,2015 @@
1
- export * from "./components/Input";
2
- export * from "./components/Provider";
1
+ "use client";
2
+ import { jsxs as Y, jsx as L, Fragment as Pe } from "react/jsx-runtime";
3
+ import { useContext as tt, createContext as nt, forwardRef as rt, useId as qe, useRef as T, useState as $, useMemo as Fe, useCallback as E, useEffect as K, useImperativeHandle as ot, useLayoutEffect as at, createElement as ct } from "react";
4
+ import { convertQwertyToHangul as Ye, assemble as it, removeLastCharacter as lt } from "es-hangul";
5
+ import { createPortal as Ie } from "react-dom";
6
+ class ut {
7
+ past = [];
8
+ future = [];
9
+ record(n, r) {
10
+ n.value !== r.value && (n.composing && r.composing && this.past.length || (this.past.push({ ...n, composing: !1 }), this.past.length > 100 && this.past.shift()), this.future = []);
11
+ }
12
+ undo(n) {
13
+ const r = this.past.pop();
14
+ return r ? (this.future.push({ ...n, composing: !1 }), r) : n;
15
+ }
16
+ redo(n) {
17
+ const r = this.future.pop();
18
+ return r ? (this.past.push({ ...n, composing: !1 }), r) : n;
19
+ }
20
+ clear() {
21
+ this.past = [], this.future = [];
22
+ }
23
+ }
24
+ const Ze = nt(null);
25
+ function _e() {
26
+ const e = tt(Ze);
27
+ if (!e)
28
+ throw new Error(
29
+ "VirtualInput must be used within a <VirtualInputProvider>."
30
+ );
31
+ return e;
32
+ }
33
+ function we(e) {
34
+ return /^[\u1100-\u11FF\u3130-\u318F\uAC00-\uD7AF]$/.test(e);
35
+ }
36
+ function st(e, n) {
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 r = n && /^[A-Za-z]$/.test(e.key) ? Ye(e.key) : e.key;
41
+ return { handled: !0, text: r, composing: we(r) };
42
+ }
43
+ const ee = [
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
+ ], dt = [
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
+ ], ft = [
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 ge(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 he = () => !0, pt = {
380
+ text: {
381
+ mode: "text",
382
+ layout: ee,
383
+ filterKey: he,
384
+ sanitizeValue: (e) => e.replace(/[\r\n\t]+/g, " ")
385
+ },
386
+ number: {
387
+ mode: "number",
388
+ layout: dt,
389
+ filterKey: (e) => /^[0-9.]+$/.test(e),
390
+ sanitizeValue: (e) => e.replace(/[^0-9.]/g, "")
391
+ },
392
+ tel: {
393
+ mode: "tel",
394
+ layout: ft,
395
+ filterKey: (e) => /^[0-9*#+]+$/.test(e),
396
+ sanitizeValue: (e) => e.replace(/[^0-9*#+]/g, "")
397
+ },
398
+ hangul: {
399
+ mode: "hangul",
400
+ layout: ee,
401
+ filterKey: he,
402
+ sanitizeValue: (e) => e.replace(/[A-Za-z]/g, "")
403
+ },
404
+ alpha: {
405
+ mode: "alpha",
406
+ layout: ee,
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
+ ...ee
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: ee,
422
+ filterKey: he,
423
+ sanitizeValue: (e) => e.replace(/[\r\n\t]+/g, " ")
424
+ }
425
+ };
426
+ function Le(e) {
427
+ const n = e?.mode ?? "text", r = pt[n];
428
+ return {
429
+ mode: n,
430
+ layout: e?.layout ?? r.layout ?? ee,
431
+ filterKey: e?.filterKey ?? r.filterKey ?? he,
432
+ sanitizeValue: e?.sanitizeValue ?? r.sanitizeValue ?? ((a) => a)
433
+ };
434
+ }
435
+ const ht = new Intl.Segmenter(void 0, { granularity: "grapheme" }), gt = new Intl.Segmenter(void 0, { granularity: "word" });
436
+ function mt(e, n) {
437
+ const r = Math.max(0, Math.min(n, e.length - 1));
438
+ for (const a of gt.segment(e))
439
+ if (r < a.index + a.segment.length)
440
+ return [a.index, a.index + a.segment.length];
441
+ return [0, 0];
442
+ }
443
+ const me = (e) => Array.from(ht.segment(e));
444
+ function oe(e, n) {
445
+ return [
446
+ ...me(e).map((a) => a.index),
447
+ e.length
448
+ ].filter((a) => a <= Math.max(0, n)).at(-1) ?? 0;
449
+ }
450
+ function Ce(e, n, r) {
451
+ const a = [
452
+ ...me(e).map((i) => i.index),
453
+ e.length
454
+ ];
455
+ return r < 0 ? a.filter((i) => i < n).at(-1) ?? 0 : a.find((i) => i > n) ?? e.length;
456
+ }
457
+ const te = ({ anchor: e, caret: n }) => [Math.min(e, n), Math.max(e, n)];
458
+ function wt(e, n, r = !1, a) {
459
+ const [i, s] = te(e);
460
+ let m = e.value.slice(0, i), v = n;
461
+ i === s && e.composing && r && we(m.at(-1) ?? "") && (v = it([m.at(-1), n]), m = m.slice(0, -1));
462
+ const d = m + v + e.value.slice(s);
463
+ if (a !== void 0 && d.length > a) return e;
464
+ const k = m.length + v.length;
465
+ return { value: d, caret: k, anchor: k, composing: r };
466
+ }
467
+ function ke(e, n) {
468
+ let [r, a] = te(e);
469
+ if (r === a) {
470
+ if (n < 0 && e.composing && we(e.value[r - 1] ?? "")) {
471
+ const i = e.value.slice(0, r - 1) + lt(e.value[r - 1]);
472
+ return {
473
+ value: i + e.value.slice(a),
474
+ anchor: i.length,
475
+ caret: i.length,
476
+ composing: !0
477
+ };
478
+ }
479
+ n < 0 ? r = Ce(e.value, r, -1) : a = Ce(e.value, a, 1);
480
+ }
481
+ return {
482
+ value: e.value.slice(0, r) + e.value.slice(a),
483
+ caret: r,
484
+ anchor: r,
485
+ composing: !1
486
+ };
487
+ }
488
+ function je(e, n, r = !1) {
489
+ const [a, i] = te(e), s = n === "home" ? 0 : n === "end" ? e.value.length : !r && a !== i ? n < 0 ? a : i : Ce(e.value, e.caret, n);
490
+ return {
491
+ ...e,
492
+ caret: s,
493
+ anchor: r ? e.anchor : s,
494
+ composing: !1
495
+ };
496
+ }
497
+ function Ae(e) {
498
+ const n = e.ownerDocument.getSelection();
499
+ if (!n?.anchorNode || !n.focusNode || !e.contains(n.anchorNode) || !e.contains(n.focusNode))
500
+ return null;
501
+ const r = (i, s) => s >= 0 && s <= (i.nodeType === Node.TEXT_NODE ? i.textContent?.length ?? 0 : i.childNodes.length);
502
+ if (!r(n.anchorNode, n.anchorOffset) || !r(n.focusNode, n.focusOffset))
503
+ return null;
504
+ const a = (i, s) => {
505
+ const m = e.ownerDocument.createRange();
506
+ return m.selectNodeContents(e), m.setEnd(i, s), m.toString().length;
507
+ };
508
+ return {
509
+ anchor: a(n.anchorNode, n.anchorOffset),
510
+ caret: a(n.focusNode, n.focusOffset)
511
+ };
512
+ }
513
+ function vt(e, n, r) {
514
+ const a = e.ownerDocument.getSelection();
515
+ if (!a) return;
516
+ const i = Ae(e);
517
+ if (i?.anchor === n && i.caret === r) return;
518
+ const s = (p) => {
519
+ const l = e.ownerDocument.createTreeWalker(
520
+ e,
521
+ NodeFilter.SHOW_TEXT
522
+ );
523
+ let u = l.nextNode(), P = p;
524
+ for (; u; ) {
525
+ const w = u.textContent?.length ?? 0;
526
+ if (P <= w) return [u, P];
527
+ P -= w, u = l.nextNode();
528
+ }
529
+ return [e, e.childNodes.length];
530
+ }, [m, v] = s(n), [d, k] = s(r);
531
+ a.setBaseAndExtent(m, v, d, k);
532
+ }
533
+ const Xe = typeof window > "u" ? K : at, Dt = rt(
534
+ function({
535
+ value: n,
536
+ defaultValue: r = "",
537
+ placeholder: a,
538
+ onChange: i,
539
+ onValueChange: s,
540
+ onClipboardError: m,
541
+ mode: v = "text",
542
+ layout: d,
543
+ filterKey: k,
544
+ sanitizeValue: p,
545
+ disabled: l = !1,
546
+ readOnly: u = !1,
547
+ maxLength: P,
548
+ ...w
549
+ }, _) {
550
+ const B = qe(), {
551
+ focusId: ae,
552
+ onFocus: Z,
553
+ onBlur: F,
554
+ defaultLayout: O,
555
+ inputRef: X,
556
+ hangulMode: ce,
557
+ theme: ie,
558
+ toggleKorean: h,
559
+ setEditingStatus: b
560
+ } = _e(), g = T(null), A = T(null), I = T(null), U = T(!1), [C, J] = $(() => ({
561
+ value: n ?? r,
562
+ caret: (n ?? r).length,
563
+ anchor: (n ?? r).length,
564
+ composing: !1
565
+ })), M = n ?? C.value, c = T(C), W = T(0), ne = T(new ut()), G = T(!1), V = ae === B, Q = T(V);
566
+ Q.current = V;
567
+ const le = n !== void 0 && n !== C.value;
568
+ le && ne.current.clear(), c.current = {
569
+ ...C,
570
+ value: M,
571
+ caret: oe(M, C.caret),
572
+ anchor: oe(M, C.anchor),
573
+ composing: le ? !1 : C.composing
574
+ };
575
+ const j = Fe(
576
+ () => Le({
577
+ mode: v,
578
+ layout: d ?? (v === "text" || v === "custom" ? O : void 0),
579
+ filterKey: k,
580
+ sanitizeValue: p
581
+ }),
582
+ [v, d, O, k, p]
583
+ ), [y, D] = $(""), q = T(
584
+ void 0
585
+ ), R = T(null), z = E(() => {
586
+ clearTimeout(q.current), R.current = null;
587
+ }, []);
588
+ K(() => {
589
+ (l || u) && z();
590
+ }, [l, u, z]), K(() => {
591
+ const t = (o) => {
592
+ R.current && R.current.id !== o.pointerId && z();
593
+ };
594
+ return window.addEventListener("blur", z), window.addEventListener("scroll", z, !0), window.addEventListener("pointerdown", t, !0), document.addEventListener("visibilitychange", z), () => {
595
+ z(), window.removeEventListener("blur", z), window.removeEventListener("scroll", z, !0), window.removeEventListener("pointerdown", t, !0), document.removeEventListener("visibilitychange", z);
596
+ };
597
+ }, [z]);
598
+ const S = E(
599
+ (t, o = !0, f = !1) => {
600
+ const x = c.current.value;
601
+ if (o && ne.current.record(c.current, t), U.current = !f, c.current = t, W.current++, D(""), J(t), t.value !== x) {
602
+ s?.(t.value);
603
+ const N = { value: t.value };
604
+ i?.({
605
+ target: N,
606
+ currentTarget: N
607
+ });
608
+ }
609
+ },
610
+ [i, s]
611
+ ), H = E(() => {
612
+ const t = A.current;
613
+ if (!t || l || U.current || t.textContent !== c.current.value)
614
+ return null;
615
+ const o = Ae(t);
616
+ if (!o) return null;
617
+ const f = oe(c.current.value, o.anchor), x = oe(c.current.value, o.caret);
618
+ return (f !== c.current.anchor || x !== c.current.caret || f !== o.anchor || x !== o.caret) && S(
619
+ { ...c.current, anchor: f, caret: x, composing: !1 },
620
+ !1,
621
+ f === o.anchor && x === o.caret
622
+ ), { anchor: f, caret: x };
623
+ }, [l, S]);
624
+ K(() => {
625
+ const t = () => {
626
+ const o = H();
627
+ o && o.anchor !== o.caret && (clearTimeout(q.current), R.current && (R.current.held = !0), !u && g.current && !Q.current && (g.current.focus({ preventScroll: !0 }), Z(B, g.current, j)));
628
+ };
629
+ return document.addEventListener("selectionchange", t), () => document.removeEventListener("selectionchange", t);
630
+ }, [H, u, Z, B, j]), Xe(() => {
631
+ (V || document.activeElement === g.current) && !l && A.current && (U.current || le) && vt(
632
+ A.current,
633
+ c.current.anchor,
634
+ c.current.caret
635
+ ), U.current = !1;
636
+ }), K(() => {
637
+ if (!V) return;
638
+ const [t, o] = te(c.current);
639
+ b({
640
+ selectionLength: me(M.slice(t, o)).length,
641
+ hasValue: !!M,
642
+ message: y
643
+ });
644
+ }, [
645
+ M,
646
+ C.anchor,
647
+ C.caret,
648
+ y,
649
+ V,
650
+ b
651
+ ]);
652
+ const re = E(
653
+ (t, o = !1) => {
654
+ if (l || u) return;
655
+ H();
656
+ const f = j.sanitizeValue(t).replace(/[\r\n\t]+/g, " ");
657
+ f && S(wt(c.current, f, o, P));
658
+ },
659
+ [l, u, j, P, S, H]
660
+ ), ve = E(() => {
661
+ !l && !u && S(ne.current.undo(c.current), !1);
662
+ }, [l, u, S]), ye = E(() => {
663
+ !l && !u && S(ne.current.redo(c.current), !1);
664
+ }, [l, u, S]), De = E(
665
+ () => S({
666
+ ...c.current,
667
+ caret: c.current.value.length,
668
+ anchor: 0,
669
+ composing: !1
670
+ }),
671
+ [S]
672
+ ), Ke = E(
673
+ (t, o = !1) => {
674
+ H(), S(je(c.current, t === "left" ? -1 : 1, o));
675
+ },
676
+ [S, H]
677
+ ), Ge = (t) => {
678
+ if (w.onKeyDown?.(t), t.defaultPrevented || l) return;
679
+ H();
680
+ const o = t.key;
681
+ if (o === "Escape") {
682
+ t.preventDefault(), S({ ...c.current, composing: !1 }), F(!0), g.current?.blur();
683
+ return;
684
+ }
685
+ if (o === "HangulMode") {
686
+ t.preventDefault(), S({ ...c.current, composing: !1 }), h();
687
+ return;
688
+ }
689
+ const f = t.ctrlKey || t.metaKey;
690
+ if (f && ["z", "y"].includes(o.toLowerCase())) {
691
+ t.preventDefault(), o.toLowerCase() === "y" || t.shiftKey ? ye() : ve();
692
+ return;
693
+ }
694
+ if (f && o.toLowerCase() === "a") {
695
+ t.preventDefault(), S({
696
+ ...c.current,
697
+ caret: c.current.value.length,
698
+ anchor: 0,
699
+ composing: !1
700
+ });
701
+ return;
702
+ }
703
+ const x = o === "Home" || o === "ArrowUp" || f && o === "ArrowLeft" ? "home" : o === "End" || o === "ArrowDown" || f && o === "ArrowRight" ? "end" : o === "ArrowLeft" ? -1 : o === "ArrowRight" ? 1 : null;
704
+ if (x !== null) {
705
+ t.preventDefault(), S(je(c.current, x, t.shiftKey));
706
+ return;
707
+ }
708
+ if (o === "Tab" || o === "Enter") {
709
+ S({ ...c.current, composing: !1 });
710
+ return;
711
+ }
712
+ if (u) return;
713
+ if (o === "Backspace" || o === "Delete") {
714
+ t.preventDefault(), S(ke(c.current, o === "Backspace" ? -1 : 1));
715
+ return;
716
+ }
717
+ const N = st(
718
+ t,
719
+ ge(j.mode) ?? ce
720
+ );
721
+ N.handled && N.text && (t.preventDefault(), j.filterKey(N.text) && re(N.text, N.composing));
722
+ }, de = E(
723
+ (t) => {
724
+ const o = t instanceof Error ? t : new Error(String(t));
725
+ G.current && (D(
726
+ "클립보드에 접근할 수 없습니다. 선택한 글자를 길게 눌러 기본 복사 메뉴를 사용해 주세요."
727
+ ), m?.(o));
728
+ },
729
+ [m]
730
+ ), fe = E(async () => {
731
+ H();
732
+ const [t, o] = te(c.current);
733
+ if (t === o) return;
734
+ const f = c.current.value.slice(t, o);
735
+ try {
736
+ if (!navigator.clipboard?.writeText)
737
+ throw new Error("Clipboard API unavailable");
738
+ await navigator.clipboard.writeText(f);
739
+ } catch (x) {
740
+ if (!A.current || document.getSelection()?.toString() !== f || !document.execCommand?.("copy"))
741
+ throw x;
742
+ }
743
+ G.current && D("복사했어요");
744
+ }, [H]), Ve = E(async () => {
745
+ if (l || u) return;
746
+ H();
747
+ const t = c.current, o = W.current;
748
+ t.anchor !== t.caret && (await fe(), G.current && Q.current && W.current === o && c.current.value === t.value && S(ke(t, -1)));
749
+ }, [l, u, fe, S, H]), ze = E(async () => {
750
+ if (l || u) return;
751
+ H();
752
+ const t = W.current, o = c.current.value, f = await navigator.clipboard.readText();
753
+ G.current && Q.current && W.current === t && c.current.value === o && re(f);
754
+ }, [l, u, re, H]), ue = Fe(
755
+ () => ({
756
+ focus: (t) => {
757
+ l || g.current?.focus(t);
758
+ },
759
+ blur: () => {
760
+ g.current?.blur(), Q.current && F(!0);
761
+ },
762
+ getValue: () => c.current.value,
763
+ setSelectionRange: (t, o) => S({
764
+ ...c.current,
765
+ anchor: oe(c.current.value, t),
766
+ caret: oe(c.current.value, o),
767
+ composing: !1
768
+ }),
769
+ handleKeyDown: (t) => g.current?.dispatchEvent(
770
+ new KeyboardEvent("keydown", {
771
+ key: t.key,
772
+ shiftKey: t.shiftKey,
773
+ ctrlKey: t.ctrlKey,
774
+ metaKey: t.metaKey,
775
+ altKey: t.altKey,
776
+ code: t.code,
777
+ bubbles: !0,
778
+ cancelable: !0
779
+ })
780
+ ),
781
+ insertText: (t, o) => {
782
+ j.filterKey(t) && re(t, o);
783
+ },
784
+ scrollIntoView: () => g.current?.scrollIntoView({ block: "nearest", inline: "nearest" }),
785
+ moveCaret: Ke,
786
+ undo: ve,
787
+ redo: ye,
788
+ selectAll: De,
789
+ copySelection: () => fe().catch(de),
790
+ pasteClipboard: () => ze().catch(de),
791
+ cutSelection: () => Ve().catch(de)
792
+ }),
793
+ [
794
+ j,
795
+ re,
796
+ Ke,
797
+ fe,
798
+ ze,
799
+ Ve,
800
+ de,
801
+ ve,
802
+ ye,
803
+ De,
804
+ l,
805
+ F,
806
+ S
807
+ ]
808
+ );
809
+ ot(_, () => ue, [ue]), K(() => {
810
+ V || J(
811
+ (t) => t.composing ? { ...t, composing: !1 } : t
812
+ );
813
+ }, [V]), K(() => {
814
+ if (!(!V || l || u))
815
+ return X.current = ue, () => {
816
+ X.current === ue && (X.current = null);
817
+ };
818
+ }, [V, l, u, ue, X]), K(() => {
819
+ V && g.current && (l || u ? F(!0) : Z(B, g.current, j));
820
+ }, [V, l, u, B, j, Z, F]), K(() => (G.current = !0, () => {
821
+ G.current = !1, clearTimeout(q.current), Q.current && F(!0);
822
+ }), [F]), Xe(() => {
823
+ if (!g.current || !A.current || !I.current)
824
+ return;
825
+ const t = () => {
826
+ const f = g.current, x = A.current, N = f.getBoundingClientRect(), $e = x.querySelector(
827
+ `[data-char-index="${c.current.caret}"]`
828
+ ), pe = ($e ?? x).getBoundingClientRect(), se = $e || !c.current.value ? pe.left : pe.right;
829
+ Object.assign(I.current.style, {
830
+ left: `${se - N.left + f.scrollLeft - f.clientLeft}px`,
831
+ top: `${pe.top - N.top + f.scrollTop - f.clientTop}px`,
832
+ height: `${pe.height}px`
833
+ }), !(!V || c.current.anchor !== c.current.caret) && (se > N.right - 12 ? f.scrollLeft += se - N.right + 12 : se < N.left + 12 && (f.scrollLeft -= N.left + 12 - se));
834
+ };
835
+ t();
836
+ const o = typeof ResizeObserver > "u" ? null : new ResizeObserver(t);
837
+ return o?.observe(g.current), () => o?.disconnect();
838
+ }, [M, C.caret, C.anchor, V]);
839
+ const Ne = (t, o) => {
840
+ if (o ? w.onCut?.(t) : w.onCopy?.(t), t.defaultPrevented || l || o && u) return;
841
+ const f = document.getSelection();
842
+ if (f && !f.isCollapsed && A.current && !Ae(A.current))
843
+ return;
844
+ H();
845
+ const [x, N] = te(c.current);
846
+ x !== N && (t.preventDefault(), t.clipboardData.setData(
847
+ "text/plain",
848
+ c.current.value.slice(x, N)
849
+ ), o ? S(ke(c.current, -1)) : D("복사했어요"));
850
+ }, be = (t, o = !0) => {
851
+ for (const f of g.current?.querySelectorAll(
852
+ "[data-char-index]"
853
+ ) ?? []) {
854
+ const x = f.getBoundingClientRect();
855
+ if (t < x.left + x.width * (o ? 0.5 : 1))
856
+ return Number(f.dataset.charIndex);
857
+ }
858
+ return c.current.value.length;
859
+ }, xe = () => {
860
+ g.current?.focus({ preventScroll: !0 }), !u && g.current && Z(B, g.current, j);
861
+ }, Be = (t) => {
862
+ const [o, f] = mt(
863
+ c.current.value,
864
+ be(t, !1)
865
+ );
866
+ xe(), S({ ...c.current, anchor: o, caret: f, composing: !1 });
867
+ }, Qe = (t) => {
868
+ if (w.onPointerDown?.(t), t.defaultPrevented || l || t.button !== 0) return;
869
+ const o = t.pointerType === "mouse";
870
+ if (R.current || t.isPrimary === !1) {
871
+ z();
872
+ return;
873
+ }
874
+ const f = be(t.clientX), x = t.shiftKey ? c.current.anchor : f;
875
+ R.current = {
876
+ id: t.pointerId,
877
+ x: t.clientX,
878
+ y: t.clientY,
879
+ anchor: x,
880
+ mouse: o,
881
+ held: !1
882
+ }, clearTimeout(q.current), o ? xe() : q.current = setTimeout(() => {
883
+ R.current && (R.current.held = !0, Be(R.current.x));
884
+ }, 550);
885
+ }, [Re, He] = te(c.current), Oe = me(M), et = /* @__PURE__ */ L(
886
+ "span",
887
+ {
888
+ ref: I,
889
+ "aria-hidden": "true",
890
+ className: "vk-caret",
891
+ style: {
892
+ display: V && !u && !l && Re === He ? "block" : "none",
893
+ width: 0,
894
+ height: "1.1em",
895
+ position: "absolute",
896
+ pointerEvents: "none",
897
+ userSelect: "none"
898
+ },
899
+ children: V && !u && !l && Re === He && /* @__PURE__ */ L(
900
+ "span",
901
+ {
902
+ style: {
903
+ position: "absolute",
904
+ height: "100%",
905
+ borderLeft: "2px solid currentColor"
906
+ }
907
+ }
908
+ )
909
+ }
910
+ );
911
+ return /* @__PURE__ */ Y(
912
+ "div",
913
+ {
914
+ ...w,
915
+ ref: g,
916
+ id: w.id ?? B,
917
+ role: "textbox",
918
+ tabIndex: l ? -1 : w.tabIndex ?? 0,
919
+ "aria-disabled": l || void 0,
920
+ "aria-readonly": u || void 0,
921
+ "aria-multiline": "false",
922
+ "aria-placeholder": a,
923
+ "data-virtual-input": "true",
924
+ "data-focused": V || void 0,
925
+ "data-value": M,
926
+ style: {
927
+ display: "block",
928
+ position: "relative",
929
+ boxSizing: "border-box",
930
+ minHeight: "2.75em",
931
+ padding: "0.65em 0.8em",
932
+ border: "1px solid #94a3b8",
933
+ borderRadius: 8,
934
+ font: "inherit",
935
+ width: "100%",
936
+ whiteSpace: "pre",
937
+ overflowX: "auto",
938
+ scrollbarWidth: "none",
939
+ cursor: l ? "not-allowed" : "text",
940
+ userSelect: l ? "none" : "text",
941
+ WebkitUserSelect: l ? "none" : "text",
942
+ WebkitTouchCallout: "default",
943
+ touchAction: "manipulation",
944
+ opacity: l ? 0.5 : 1,
945
+ outlineOffset: 3,
946
+ ...w.style
947
+ },
948
+ onFocus: (t) => {
949
+ w.onFocus?.(t), !t.defaultPrevented && !l && !u && Z(B, t.currentTarget, j);
950
+ },
951
+ onBlur: (t) => {
952
+ w.onBlur?.(t), z(), t.defaultPrevented || F(t);
953
+ },
954
+ onKeyDown: Ge,
955
+ onCopy: (t) => Ne(t, !1),
956
+ onCut: (t) => Ne(t, !0),
957
+ onPaste: (t) => {
958
+ w.onPaste?.(t), !t.defaultPrevented && !l && !u && (t.preventDefault(), re(t.clipboardData.getData("text/plain")));
959
+ },
960
+ onPointerDown: Qe,
961
+ onDoubleClick: (t) => {
962
+ w.onDoubleClick?.(t), !(t.defaultPrevented || l || t.button !== 0) && (t.preventDefault(), Be(t.clientX));
963
+ },
964
+ onPointerMove: (t) => {
965
+ if (w.onPointerMove?.(t), t.defaultPrevented) {
966
+ z();
967
+ return;
968
+ }
969
+ !R.current || R.current.id !== t.pointerId || Math.hypot(
970
+ t.clientX - R.current.x,
971
+ t.clientY - R.current.y
972
+ ) > 8 && (clearTimeout(q.current), R.current.mouse || z());
973
+ },
974
+ onPointerUp: (t) => {
975
+ w.onPointerUp?.(t);
976
+ const o = R.current;
977
+ if (!t.defaultPrevented && o?.id === t.pointerId && !o.held && Math.hypot(t.clientX - o.x, t.clientY - o.y) <= 8) {
978
+ const f = H();
979
+ if (!f || !o.mouse && f.anchor === f.caret) {
980
+ const x = be(t.clientX);
981
+ xe(), S({
982
+ ...c.current,
983
+ caret: x,
984
+ anchor: t.shiftKey ? o.anchor : x,
985
+ composing: !1
986
+ });
987
+ }
988
+ }
989
+ z();
990
+ },
991
+ onPointerCancel: (t) => {
992
+ w.onPointerCancel?.(t), z();
993
+ },
994
+ onLostPointerCapture: (t) => {
995
+ w.onLostPointerCapture?.(t), R.current?.id === t.pointerId && z();
996
+ },
997
+ onContextMenu: (t) => {
998
+ w.onContextMenu?.(t), t.defaultPrevented || H();
999
+ },
1000
+ children: [
1001
+ /* @__PURE__ */ L("span", { ref: A, "data-input-text": "true", children: Oe.map(({ segment: t, index: o }) => /* @__PURE__ */ L("span", { "data-char-index": o, children: t }, o)) }),
1002
+ et,
1003
+ !M && /* @__PURE__ */ L(
1004
+ "span",
1005
+ {
1006
+ "aria-hidden": "true",
1007
+ style: {
1008
+ color: ie === "dark" ? "#a6b7a9" : "#58665d",
1009
+ userSelect: "none",
1010
+ WebkitUserSelect: "none"
1011
+ },
1012
+ children: a || " "
1013
+ }
1014
+ ),
1015
+ /* @__PURE__ */ L(
1016
+ "span",
1017
+ {
1018
+ role: "status",
1019
+ style: {
1020
+ position: "absolute",
1021
+ width: 1,
1022
+ height: 1,
1023
+ overflow: "hidden",
1024
+ clipPath: "inset(50%)",
1025
+ whiteSpace: "nowrap",
1026
+ userSelect: "none",
1027
+ WebkitUserSelect: "none"
1028
+ },
1029
+ children: y
1030
+ }
1031
+ )
1032
+ ]
1033
+ }
1034
+ );
1035
+ }
1036
+ ), yt = [
1037
+ [
1038
+ {
1039
+ value: "1"
1040
+ },
1041
+ {
1042
+ value: "2"
1043
+ },
1044
+ {
1045
+ value: "3"
1046
+ },
1047
+ {
1048
+ value: "4"
1049
+ },
1050
+ {
1051
+ value: "5"
1052
+ },
1053
+ {
1054
+ value: "6"
1055
+ },
1056
+ {
1057
+ value: "7"
1058
+ },
1059
+ {
1060
+ value: "8"
1061
+ },
1062
+ {
1063
+ value: "9"
1064
+ },
1065
+ {
1066
+ value: "0"
1067
+ }
1068
+ ],
1069
+ [
1070
+ {
1071
+ value: "@"
1072
+ },
1073
+ {
1074
+ value: "#"
1075
+ },
1076
+ {
1077
+ value: "$"
1078
+ },
1079
+ {
1080
+ value: "%"
1081
+ },
1082
+ {
1083
+ value: "&"
1084
+ },
1085
+ {
1086
+ value: "*"
1087
+ },
1088
+ {
1089
+ value: "-"
1090
+ },
1091
+ {
1092
+ value: "+"
1093
+ },
1094
+ {
1095
+ value: "("
1096
+ },
1097
+ {
1098
+ value: ")"
1099
+ }
1100
+ ],
1101
+ [
1102
+ {
1103
+ value: "!"
1104
+ },
1105
+ {
1106
+ value: "?"
1107
+ },
1108
+ {
1109
+ value: "/"
1110
+ },
1111
+ {
1112
+ value: ":"
1113
+ },
1114
+ {
1115
+ value: ";"
1116
+ },
1117
+ {
1118
+ value: '"'
1119
+ },
1120
+ {
1121
+ value: "'"
1122
+ },
1123
+ {
1124
+ value: "_"
1125
+ },
1126
+ {
1127
+ value: "Backspace",
1128
+ label: "⌫",
1129
+ type: "action"
1130
+ }
1131
+ ],
1132
+ [
1133
+ {
1134
+ value: ","
1135
+ },
1136
+ {
1137
+ value: ".",
1138
+ width: 1
1139
+ },
1140
+ {
1141
+ value: " ",
1142
+ label: "공백",
1143
+ width: 4,
1144
+ type: "action"
1145
+ },
1146
+ {
1147
+ value: "Enter",
1148
+ label: "↵",
1149
+ type: "action"
1150
+ }
1151
+ ]
1152
+ ];
1153
+ function bt({
1154
+ tagName: e,
1155
+ css: n,
1156
+ children: r,
1157
+ hostRef: a,
1158
+ ...i
1159
+ }) {
1160
+ const [s, m] = $(null), v = E(
1161
+ (d) => {
1162
+ a && (a.current = d), d && m(d.shadowRoot ?? d.attachShadow({ mode: "open" }));
1163
+ },
1164
+ [a]
1165
+ );
1166
+ return ct(
1167
+ e,
1168
+ { ...i, ref: v },
1169
+ s && Ie(
1170
+ /* @__PURE__ */ Y(Pe, { children: [
1171
+ n && /* @__PURE__ */ L("style", { children: n }),
1172
+ r
1173
+ ] }),
1174
+ s
1175
+ )
1176
+ );
1177
+ }
1178
+ function Ue(e, n, r) {
1179
+ if (e.type === "action") return e.value === `
1180
+ ` ? "Enter" : e.value;
1181
+ if (!/^[a-zA-Z]$/.test(e.value)) return e.value;
1182
+ const a = r ? e.value.toUpperCase() : e.value;
1183
+ return n ? Ye(a) : a;
1184
+ }
1185
+ function Me(e, { disabled: n = !1, repeat: r = !1 } = {}) {
1186
+ const a = T(e);
1187
+ a.current = e;
1188
+ const i = T(void 0), s = T(null), [m, v] = $(!1), d = E(() => {
1189
+ clearTimeout(i.current), s.current = null, v(!1);
1190
+ }, []);
1191
+ K(() => (window.addEventListener("blur", d), document.addEventListener("visibilitychange", d), () => {
1192
+ d(), window.removeEventListener("blur", d), document.removeEventListener("visibilitychange", d);
1193
+ }), [d]), K(() => {
1194
+ n && d();
1195
+ }, [n, d]);
1196
+ const k = (p) => {
1197
+ const l = s.current?.bounds;
1198
+ return !!l && p.clientX >= l.left && p.clientX <= l.right && p.clientY >= l.top && p.clientY <= l.bottom;
1199
+ };
1200
+ return {
1201
+ "data-pressed": m || void 0,
1202
+ onPointerDown: (p) => {
1203
+ if (!(n || p.button !== 0 || s.current)) {
1204
+ p.preventDefault(), s.current = {
1205
+ id: p.pointerId,
1206
+ bounds: p.currentTarget.getBoundingClientRect(),
1207
+ repeated: !1
1208
+ }, v(!0);
1209
+ try {
1210
+ p.currentTarget.setPointerCapture?.(p.pointerId);
1211
+ } catch {
1212
+ }
1213
+ if (r) {
1214
+ const l = () => {
1215
+ s.current && (s.current.repeated = !0, a.current(), i.current = setTimeout(l, 65));
1216
+ };
1217
+ i.current = setTimeout(l, 450);
1218
+ }
1219
+ }
1220
+ },
1221
+ onPointerMove: (p) => {
1222
+ s.current?.id === p.pointerId && !k(p) && d();
1223
+ },
1224
+ onPointerUp: (p) => {
1225
+ if (s.current?.id !== p.pointerId) return;
1226
+ const l = !n && k(p) && !s.current.repeated;
1227
+ d(), l && a.current();
1228
+ },
1229
+ onPointerCancel: (p) => {
1230
+ s.current?.id === p.pointerId && d();
1231
+ },
1232
+ onLostPointerCapture: (p) => {
1233
+ s.current?.id === p.pointerId && d();
1234
+ },
1235
+ onPointerLeave: (p) => {
1236
+ s.current?.id === p.pointerId && !k(p) && d();
1237
+ },
1238
+ onClick: (p) => {
1239
+ !n && p.detail === 0 && !s.current && a.current();
1240
+ }
1241
+ };
1242
+ }
1243
+ const Te = {
1244
+ Shift: "Shift",
1245
+ HangulMode: "한영 전환",
1246
+ Backspace: "지우기",
1247
+ Delete: "앞 글자 지우기",
1248
+ Enter: "입력 완료",
1249
+ EnterSelectionMode: "텍스트 편집",
1250
+ ExitSelectionMode: "키보드로 돌아가기",
1251
+ ToggleSelectionAdjust: "선택 범위 조절",
1252
+ ArrowLeft: "커서 왼쪽",
1253
+ ArrowRight: "커서 오른쪽",
1254
+ Copy: "복사",
1255
+ Paste: "붙여넣기",
1256
+ Cut: "잘라내기",
1257
+ " ": "공백",
1258
+ Undo: "실행 취소",
1259
+ Redo: "다시 실행",
1260
+ SelectAll: "전체 선택"
1261
+ };
1262
+ function We({
1263
+ cell: e,
1264
+ label: n,
1265
+ value: r,
1266
+ active: a,
1267
+ disabled: i,
1268
+ dispatch: s
1269
+ }) {
1270
+ const m = Me(s, {
1271
+ disabled: i,
1272
+ repeat: ["Backspace", "Delete", "ArrowLeft", "ArrowRight"].includes(r)
1273
+ }), v = e.type === "action" && r === "HangulMode", d = e.type === "action" && (r === "Backspace" && (!e.label || e.label === "⌫") || r === "Delete" && (!e.label || e.label === "⌦"));
1274
+ return /* @__PURE__ */ L(
1275
+ "button",
1276
+ {
1277
+ type: "button",
1278
+ disabled: i,
1279
+ "aria-label": Te[r] ?? n,
1280
+ "aria-pressed": a,
1281
+ className: v ? "key action language" : e.type === "action" ? "key action" : "key",
1282
+ title: v ? i ? `${a ? "한국어" : "영어"} 전용` : `${a ? "영어" : "한국어"}로 전환` : void 0,
1283
+ style: { flex: e.width && e.width > 0 ? e.width : 1 },
1284
+ ...m,
1285
+ children: d ? /* @__PURE__ */ Y(
1286
+ "svg",
1287
+ {
1288
+ "data-key-icon": r === "Backspace" ? "backspace" : "delete",
1289
+ "aria-hidden": "true",
1290
+ width: "24",
1291
+ height: "24",
1292
+ viewBox: "0 0 24 24",
1293
+ fill: "none",
1294
+ stroke: "currentColor",
1295
+ strokeWidth: "1.7",
1296
+ strokeLinecap: "round",
1297
+ strokeLinejoin: "round",
1298
+ focusable: "false",
1299
+ style: r === "Delete" ? { transform: "scaleX(-1)" } : void 0,
1300
+ children: [
1301
+ /* @__PURE__ */ L("path", { d: "M9 5H20a1.5 1.5 0 0 1 1.5 1.5v11A1.5 1.5 0 0 1 20 19H9l-7-7 7-7Z" }),
1302
+ /* @__PURE__ */ L("path", { d: "m12 9 6 6m0-6-6 6" })
1303
+ ]
1304
+ }
1305
+ ) : v && !e.label ? /* @__PURE__ */ Y("span", { className: "language-label", "aria-hidden": "true", children: [
1306
+ /* @__PURE__ */ Y(
1307
+ "svg",
1308
+ {
1309
+ width: "19",
1310
+ height: "19",
1311
+ viewBox: "0 0 24 24",
1312
+ fill: "none",
1313
+ stroke: "currentColor",
1314
+ strokeWidth: "1.65",
1315
+ strokeLinecap: "round",
1316
+ strokeLinejoin: "round",
1317
+ focusable: "false",
1318
+ children: [
1319
+ /* @__PURE__ */ L("circle", { cx: "12", cy: "12", r: "9" }),
1320
+ /* @__PURE__ */ L("ellipse", { cx: "12", cy: "12", rx: "4", ry: "9" }),
1321
+ /* @__PURE__ */ L("path", { d: "M3 12h18" })
1322
+ ]
1323
+ }
1324
+ ),
1325
+ /* @__PURE__ */ L("span", { children: a ? "한" : "EN" })
1326
+ ] }) : n
1327
+ }
1328
+ );
1329
+ }
1330
+ function xt({
1331
+ layout: e,
1332
+ viewport: n,
1333
+ onHeightChange: r
1334
+ }) {
1335
+ const a = _e(), {
1336
+ inputRef: i,
1337
+ hangulMode: s,
1338
+ shift: m,
1339
+ shiftLocked: v,
1340
+ theme: d,
1341
+ selectionMode: k,
1342
+ selectionAdjusting: p,
1343
+ activeInputPolicy: l,
1344
+ editingStatus: u,
1345
+ onBlur: P
1346
+ } = a, w = T(null), [_, B] = $(!1), ae = Me(() => B((h) => !h)), Z = Me(() => P(!0)), F = ["text", "hangul", "custom"].includes(
1347
+ l.mode
1348
+ ), O = _ && F && !k ? yt : e;
1349
+ K(() => {
1350
+ if (!w.current) return;
1351
+ const h = () => {
1352
+ const g = w.current?.getBoundingClientRect().height ?? 0;
1353
+ r(g);
1354
+ };
1355
+ h();
1356
+ const b = new ResizeObserver(h);
1357
+ return b.observe(w.current), () => b.disconnect();
1358
+ }, [r]), K(() => {
1359
+ let h = null;
1360
+ const b = /* @__PURE__ */ new Set(), g = (c) => c.composedPath().some(
1361
+ (W) => W === w.current || W instanceof Element && W.hasAttribute("data-virtual-input")
1362
+ ), A = (c) => {
1363
+ b.add(c.pointerId), h = b.size !== 1 || c.button !== 0 || g(c) ? null : { x: c.clientX, y: c.clientY, id: c.pointerId };
1364
+ }, I = (c) => {
1365
+ h && h.id === c.pointerId && Math.hypot(c.clientX - h.x, c.clientY - h.y) < 10 && !g(c) && P(!0), h = null, b.delete(c.pointerId);
1366
+ }, U = (c) => {
1367
+ h?.id === c.pointerId && Math.hypot(c.clientX - h.x, c.clientY - h.y) >= 10 && (h = null);
1368
+ }, C = () => {
1369
+ h = null;
1370
+ }, J = (c) => {
1371
+ C(), b.delete(c.pointerId);
1372
+ }, M = () => {
1373
+ C(), b.clear();
1374
+ };
1375
+ return window.addEventListener("pointerdown", A, !0), window.addEventListener("pointermove", U, !0), window.addEventListener("pointerup", I, !0), window.addEventListener("pointercancel", J, !0), window.addEventListener("scroll", C, !0), window.addEventListener("blur", M), document.addEventListener("visibilitychange", M), () => {
1376
+ window.removeEventListener("pointerdown", A, !0), window.removeEventListener("pointermove", U, !0), window.removeEventListener("pointerup", I, !0), window.removeEventListener("pointercancel", J, !0), window.removeEventListener("scroll", C, !0), window.removeEventListener("blur", M), document.removeEventListener("visibilitychange", M);
1377
+ };
1378
+ }, [P]);
1379
+ const X = (h) => {
1380
+ const b = Ue(h, s, m);
1381
+ if (h.type !== "action") {
1382
+ i.current?.insertText(b, we(b)), a.consumeShift();
1383
+ return;
1384
+ }
1385
+ switch (b) {
1386
+ case "Undo":
1387
+ i.current?.undo();
1388
+ break;
1389
+ case "Redo":
1390
+ i.current?.redo();
1391
+ break;
1392
+ case "SelectAll":
1393
+ i.current?.selectAll();
1394
+ break;
1395
+ case "Shift":
1396
+ a.toggleShift();
1397
+ break;
1398
+ case "HangulMode":
1399
+ i.current?.handleKeyDown(
1400
+ new KeyboardEvent("keydown", { key: b })
1401
+ );
1402
+ break;
1403
+ case "EnterSelectionMode":
1404
+ B(!1), a.enterSelectionMode();
1405
+ break;
1406
+ case "ExitSelectionMode":
1407
+ a.exitSelectionMode();
1408
+ break;
1409
+ case "ToggleSelectionAdjust":
1410
+ a.toggleSelectionAdjust();
1411
+ break;
1412
+ case "Copy":
1413
+ i.current?.copySelection();
1414
+ break;
1415
+ case "Paste":
1416
+ i.current?.pasteClipboard();
1417
+ break;
1418
+ case "Cut":
1419
+ i.current?.cutSelection();
1420
+ break;
1421
+ case "ArrowLeft":
1422
+ i.current?.moveCaret("left", p);
1423
+ break;
1424
+ case "ArrowRight":
1425
+ i.current?.moveCaret("right", p);
1426
+ break;
1427
+ default:
1428
+ b === " " ? i.current?.insertText(" ") : i.current?.handleKeyDown(
1429
+ new KeyboardEvent("keydown", { key: b })
1430
+ );
1431
+ }
1432
+ }, ce = ge(l.mode) !== null, ie = {
1433
+ position: "fixed",
1434
+ zIndex: 9999,
1435
+ boxSizing: "border-box",
1436
+ display: "block",
1437
+ width: Math.min(n.width || 760, 760),
1438
+ left: n.offsetLeft + n.width / 2,
1439
+ transform: n.height ? "translate(-50%, -100%)" : "translateX(-50%)",
1440
+ ...n.height ? { top: n.offsetTop + n.height } : { bottom: 0 },
1441
+ maxHeight: n.height ? n.height * 0.65 : "65dvh",
1442
+ overflowY: "auto",
1443
+ colorScheme: d,
1444
+ background: d === "dark" ? "#18201f" : "#e9eeeb",
1445
+ color: d === "dark" ? "#eef4ef" : "#203b31",
1446
+ border: "1px solid " + (d === "dark" ? "#35413c" : "#c8d3cb"),
1447
+ borderRadius: "20px 20px 0 0",
1448
+ boxShadow: "0 -8px 48px #10251a20",
1449
+ touchAction: "manipulation",
1450
+ userSelect: "none",
1451
+ WebkitUserSelect: "none"
1452
+ };
1453
+ return Ie(
1454
+ /* @__PURE__ */ L(
1455
+ bt,
1456
+ {
1457
+ tagName: "virtual-keypad",
1458
+ hostRef: w,
1459
+ "data-virtual-keypad": "true",
1460
+ style: ie,
1461
+ onPointerDown: (h) => {
1462
+ h.button === 0 && h.preventDefault();
1463
+ },
1464
+ onMouseDown: (h) => {
1465
+ h.button === 0 && h.preventDefault();
1466
+ },
1467
+ onBlur: a.onBlur,
1468
+ onKeyDown: (h) => {
1469
+ h.key === "Escape" && (h.preventDefault(), P(!0));
1470
+ },
1471
+ css: `
1472
+ * {
1473
+ box-sizing: border-box;
1474
+ }
1475
+ .keyboard {
1476
+ padding: 10px 8px max(12px, env(safe-area-inset-bottom));
1477
+ font:
1478
+ 500 16px system-ui,
1479
+ sans-serif;
1480
+ }
1481
+ .toolbar {
1482
+ display: flex;
1483
+ align-items: center;
1484
+ justify-content: space-between;
1485
+ padding: 0 6px 8px;
1486
+ font-size: 12px;
1487
+ min-height: 52px;
1488
+ gap: 5px;
1489
+ }
1490
+ .toolbar span {
1491
+ opacity: 0.75;
1492
+ }
1493
+ .close {
1494
+ background: transparent;
1495
+ color: inherit;
1496
+ border: 0;
1497
+ padding: 8px 12px;
1498
+ cursor: pointer;
1499
+ border-radius: 6px;
1500
+ min-width: 44px;
1501
+ min-height: 44px;
1502
+ touch-action: pan-y;
1503
+ }
1504
+ .row {
1505
+ display: flex;
1506
+ gap: clamp(3px, 1vw, 7px);
1507
+ margin-top: 7px;
1508
+ }
1509
+ .key {
1510
+ display: inline-flex;
1511
+ align-items: center;
1512
+ justify-content: center;
1513
+ min-width: 0;
1514
+ min-height: 44px;
1515
+ border: 0;
1516
+ border-radius: 8px;
1517
+ background: ${d === "dark" ? "#303c37" : "#fff"};
1518
+ color: inherit;
1519
+ box-shadow: 0 2px 0 ${d === "dark" ? "#0d1611" : "#bdc9c1"};
1520
+ font: inherit;
1521
+ padding: 8px 0;
1522
+ touch-action: none;
1523
+ cursor: pointer;
1524
+ user-select: none;
1525
+ }
1526
+ .action {
1527
+ background: ${d === "dark" ? "#414e46" : "#d7e1db"};
1528
+ font-size: 14px;
1529
+ }
1530
+ .selection-count {
1531
+ min-width: 48px;
1532
+ white-space: nowrap;
1533
+ font-size: 11px;
1534
+ }
1535
+ .selection-actions {
1536
+ display: flex;
1537
+ flex: 1;
1538
+ gap: 5px;
1539
+ }
1540
+ .selection-actions .key {
1541
+ font-size: 12px;
1542
+ box-shadow: none;
1543
+ white-space: nowrap;
1544
+ }
1545
+ .feedback {
1546
+ margin: 0 6px 6px;
1547
+ font-size: 12px;
1548
+ line-height: 1.5;
1549
+ }
1550
+ .key[aria-pressed="true"]:not(.language) {
1551
+ background: #246447;
1552
+ color: #fff;
1553
+ }
1554
+ .language-label {
1555
+ display: flex;
1556
+ align-items: center;
1557
+ justify-content: center;
1558
+ gap: 5px;
1559
+ font-size: 12px;
1560
+ font-weight: 600;
1561
+ line-height: 1;
1562
+ white-space: nowrap;
1563
+ }
1564
+ .language-label svg {
1565
+ flex-shrink: 0;
1566
+ }
1567
+ .language-label span {
1568
+ min-width: 1.5em;
1569
+ }
1570
+ .key[data-pressed="true"],
1571
+ .close[data-pressed="true"] {
1572
+ filter: brightness(0.9);
1573
+ box-shadow: none;
1574
+ }
1575
+ button:focus-visible {
1576
+ outline: 3px solid #48a97e;
1577
+ outline-offset: 2px;
1578
+ }
1579
+ button:disabled {
1580
+ opacity: 0.38;
1581
+ cursor: default;
1582
+ }
1583
+ @media (max-height: 500px) {
1584
+ .key {
1585
+ min-height: 44px;
1586
+ padding: 5px 0;
1587
+ }
1588
+ .row {
1589
+ margin-top: 4px;
1590
+ }
1591
+ .keyboard {
1592
+ padding-top: 0;
1593
+ }
1594
+ .toolbar {
1595
+ padding-bottom: 0;
1596
+ }
1597
+ }
1598
+ `,
1599
+ children: /* @__PURE__ */ Y("section", { className: "keyboard", role: "group", "aria-label": "가상 키보드", children: [
1600
+ /* @__PURE__ */ Y("div", { className: "toolbar", children: [
1601
+ u.selectionLength > 0 && !k ? /* @__PURE__ */ Y(Pe, { children: [
1602
+ /* @__PURE__ */ L(
1603
+ "span",
1604
+ {
1605
+ className: "selection-count",
1606
+ title: u.message || void 0,
1607
+ children: u.message === "복사했어요" ? "복사했어요" : `${u.selectionLength}자 선택`
1608
+ }
1609
+ ),
1610
+ /* @__PURE__ */ L(
1611
+ "div",
1612
+ {
1613
+ className: "selection-actions",
1614
+ role: "group",
1615
+ "aria-label": "선택한 텍스트 편집",
1616
+ children: ["Copy", "Cut", "SelectAll"].map((h) => /* @__PURE__ */ L(
1617
+ We,
1618
+ {
1619
+ cell: { value: h, type: "action" },
1620
+ value: h,
1621
+ label: Te[h],
1622
+ dispatch: () => X({ value: h, type: "action" })
1623
+ },
1624
+ h
1625
+ ))
1626
+ }
1627
+ )
1628
+ ] }) : /* @__PURE__ */ Y("span", { children: [
1629
+ k ? u.message === "복사했어요" ? "복사했어요" : "텍스트 편집" : _ && F ? "숫자 · 기호" : l.mode === "number" ? "숫자" : l.mode === "tel" ? "전화번호" : s ? "한국어 · 두벌식" : "English",
1630
+ v ? " · Shift 고정" : ""
1631
+ ] }),
1632
+ F && !k && !u.selectionLength && /* @__PURE__ */ L(
1633
+ "button",
1634
+ {
1635
+ type: "button",
1636
+ className: "close",
1637
+ "aria-label": "숫자·기호 전환",
1638
+ "aria-pressed": _,
1639
+ ...ae,
1640
+ children: _ ? "가 / ABC" : "123 / #+="
1641
+ }
1642
+ ),
1643
+ /* @__PURE__ */ L(
1644
+ "button",
1645
+ {
1646
+ type: "button",
1647
+ className: "close",
1648
+ ...Z,
1649
+ "aria-label": "키보드 닫기",
1650
+ children: "닫기 ↓"
1651
+ }
1652
+ )
1653
+ ] }),
1654
+ u.message && u.message !== "복사했어요" && /* @__PURE__ */ L("p", { className: "feedback", children: u.message }),
1655
+ O.map((h, b) => /* @__PURE__ */ L("div", { className: "row", children: h.map((g, A) => {
1656
+ const I = Ue(g, s, m), U = g.type === "action" ? g.label ?? Te[I] ?? I : /^[A-Za-z]$/.test(g.value) ? I : g.label ?? I, C = g.value === "Shift" ? m : g.value === "HangulMode" ? s : g.value === "ToggleSelectionAdjust" ? p : void 0;
1657
+ return /* @__PURE__ */ L(
1658
+ We,
1659
+ {
1660
+ cell: g,
1661
+ label: U,
1662
+ value: I,
1663
+ active: C,
1664
+ disabled: g.value === "HangulMode" && ce || ["Copy", "Cut"].includes(I) && !u.selectionLength || I === "SelectAll" && !u.hasValue || (g.type !== "action" || I === " ") && !l.filterKey(I),
1665
+ dispatch: () => X(g)
1666
+ },
1667
+ `${b}-${A}-${g.value}`
1668
+ );
1669
+ }) }, b))
1670
+ ] })
1671
+ }
1672
+ ),
1673
+ document.body
1674
+ );
1675
+ }
1676
+ const Se = "virtual-keyboard:storage";
1677
+ function kt(e, n) {
1678
+ const r = T(n), [a, i] = $(n), s = T(a), m = E(
1679
+ () => r.current instanceof Function ? r.current() : r.current,
1680
+ []
1681
+ );
1682
+ K(() => {
1683
+ const d = (u) => {
1684
+ try {
1685
+ const P = u === null ? m() : JSON.parse(u);
1686
+ return typeof P == typeof m() ? P : m();
1687
+ } catch {
1688
+ return m();
1689
+ }
1690
+ }, k = (u) => {
1691
+ s.current = d(u), i(s.current);
1692
+ };
1693
+ try {
1694
+ k(window.localStorage.getItem(e));
1695
+ } catch {
1696
+ }
1697
+ const p = (u) => {
1698
+ try {
1699
+ if (u.storageArea && u.storageArea !== window.localStorage)
1700
+ return;
1701
+ } catch {
1702
+ return;
1703
+ }
1704
+ (u.key === e || u.key === null) && k(u.newValue);
1705
+ }, l = (u) => {
1706
+ const P = u.detail;
1707
+ P.key === e && k(P.raw);
1708
+ };
1709
+ return window.addEventListener("storage", p), window.addEventListener(Se, l), () => {
1710
+ window.removeEventListener("storage", p), window.removeEventListener(Se, l);
1711
+ };
1712
+ }, [e, m]);
1713
+ const v = E(
1714
+ (d) => {
1715
+ s.current = d instanceof Function ? d(s.current) : d, i(s.current), window.dispatchEvent(
1716
+ new CustomEvent(Se, {
1717
+ detail: { key: e, raw: JSON.stringify(s.current) }
1718
+ })
1719
+ );
1720
+ try {
1721
+ window.localStorage.setItem(e, JSON.stringify(s.current));
1722
+ } catch {
1723
+ }
1724
+ },
1725
+ [e]
1726
+ );
1727
+ return [a, v];
1728
+ }
1729
+ const St = [
1730
+ [
1731
+ {
1732
+ label: "전체 선택",
1733
+ value: "SelectAll",
1734
+ type: "action"
1735
+ },
1736
+ {
1737
+ label: "실행 취소",
1738
+ value: "Undo",
1739
+ type: "action"
1740
+ },
1741
+ {
1742
+ label: "다시 실행",
1743
+ value: "Redo",
1744
+ type: "action"
1745
+ }
1746
+ ],
1747
+ [
1748
+ {
1749
+ label: "범위 조절",
1750
+ value: "ToggleSelectionAdjust",
1751
+ width: 1.4,
1752
+ type: "action"
1753
+ },
1754
+ {
1755
+ label: "←",
1756
+ value: "ArrowLeft",
1757
+ type: "action"
1758
+ },
1759
+ {
1760
+ label: "→",
1761
+ value: "ArrowRight",
1762
+ type: "action"
1763
+ }
1764
+ ],
1765
+ [
1766
+ {
1767
+ label: "복사",
1768
+ value: "Copy",
1769
+ width: 1.4,
1770
+ type: "action"
1771
+ },
1772
+ {
1773
+ label: "붙여넣기",
1774
+ value: "Paste",
1775
+ width: 1.4,
1776
+ type: "action"
1777
+ },
1778
+ {
1779
+ label: "잘라내기",
1780
+ value: "Cut",
1781
+ width: 1.2,
1782
+ type: "action"
1783
+ },
1784
+ {
1785
+ label: "⌫",
1786
+ value: "Backspace",
1787
+ type: "action"
1788
+ }
1789
+ ],
1790
+ [
1791
+ {
1792
+ label: "키보드",
1793
+ value: "ExitSelectionMode",
1794
+ type: "action"
1795
+ },
1796
+ {
1797
+ label: "␣",
1798
+ value: " ",
1799
+ width: 2.8,
1800
+ type: "action"
1801
+ },
1802
+ {
1803
+ label: "⏎",
1804
+ value: `
1805
+ `,
1806
+ type: "action"
1807
+ }
1808
+ ]
1809
+ ], Et = () => typeof window > "u" ? { width: 0, height: 0, scale: 1, offsetLeft: 0, offsetTop: 0 } : typeof window < "u" && window.visualViewport ? {
1810
+ width: window.visualViewport.width,
1811
+ height: window.visualViewport.height,
1812
+ scale: window.visualViewport.scale,
1813
+ offsetLeft: window.visualViewport.offsetLeft,
1814
+ offsetTop: window.visualViewport.offsetTop
1815
+ } : {
1816
+ width: window.innerWidth,
1817
+ height: window.innerHeight,
1818
+ scale: 1,
1819
+ offsetLeft: 0,
1820
+ offsetTop: 0
1821
+ }, Lt = (e, n) => e.width === n.width && e.height === n.height && e.scale === n.scale && e.offsetLeft === n.offsetLeft && e.offsetTop === n.offsetTop, Ct = () => {
1822
+ const [e, n] = $(() => ({
1823
+ width: 0,
1824
+ height: 0,
1825
+ scale: 1,
1826
+ offsetLeft: 0,
1827
+ offsetTop: 0
1828
+ }));
1829
+ return K(() => {
1830
+ if (typeof window > "u") return;
1831
+ let r = null;
1832
+ const a = () => {
1833
+ const s = Et();
1834
+ n(
1835
+ (m) => Lt(m, s) ? m : s
1836
+ );
1837
+ };
1838
+ a();
1839
+ const i = () => {
1840
+ r !== null && cancelAnimationFrame(r), r = requestAnimationFrame(a);
1841
+ };
1842
+ return window.visualViewport ? (window.visualViewport.addEventListener("resize", i, {
1843
+ passive: !0
1844
+ }), window.visualViewport.addEventListener("scroll", i, {
1845
+ passive: !0
1846
+ })) : window.addEventListener("resize", i, { passive: !0 }), () => {
1847
+ r !== null && cancelAnimationFrame(r), window.visualViewport ? (window.visualViewport.removeEventListener("resize", i), window.visualViewport.removeEventListener("scroll", i)) : window.removeEventListener("resize", i);
1848
+ };
1849
+ }, []), e;
1850
+ };
1851
+ function At() {
1852
+ const [e, n] = $("light");
1853
+ return K(() => {
1854
+ if (typeof window > "u" || !window.matchMedia) return;
1855
+ const r = window.matchMedia("(prefers-color-scheme: dark)");
1856
+ n(r.matches ? "dark" : "light");
1857
+ const a = (i) => {
1858
+ n(i.matches ? "dark" : "light");
1859
+ };
1860
+ return r.addEventListener("change", a), () => r.removeEventListener("change", a);
1861
+ }, []), e;
1862
+ }
1863
+ function Je(e) {
1864
+ return e !== void 0 ? /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
1865
+ e
1866
+ ) : typeof navigator > "u" ? !1 : Je(navigator.userAgent) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1 || typeof window < "u" && !!window.matchMedia?.("(pointer: coarse)").matches;
1867
+ }
1868
+ const Ee = "virtual-keyboard:focus-change";
1869
+ function Kt({
1870
+ children: e,
1871
+ layout: n = ee,
1872
+ defaultHangulMode: r = !0,
1873
+ theme: a,
1874
+ keyboardVisibility: i = "auto"
1875
+ }) {
1876
+ const s = qe(), m = T(null), v = T(null), d = T(
1877
+ void 0
1878
+ ), [k, p] = $(), [l, u] = $(0), [P, w] = $(!1), [_, B] = $(!1), [ae, Z] = $({
1879
+ selectionLength: 0,
1880
+ hasValue: !1,
1881
+ message: ""
1882
+ }), [F, O] = kt(
1883
+ "virtual-keyboard-hangul-mode",
1884
+ r
1885
+ ), [X, ce] = $(
1886
+ () => Le({ layout: n })
1887
+ ), [ie, h] = $(!1), [b, g] = $(0), A = Ct(), I = At(), U = ge(X.mode) ?? F, C = !!k && (i === "always" || i === "auto" && ie), J = T(C);
1888
+ J.current = C, K(() => {
1889
+ const y = () => h(Je());
1890
+ y();
1891
+ const D = window.matchMedia?.("(pointer: coarse)");
1892
+ return D?.addEventListener("change", y), () => D?.removeEventListener("change", y);
1893
+ }, []);
1894
+ const M = E(() => {
1895
+ clearTimeout(d.current), v.current = null, m.current = null, p(void 0), u(0), w(!1), B(!1);
1896
+ }, []);
1897
+ K(() => {
1898
+ const y = (D) => {
1899
+ D.detail !== s && M();
1900
+ };
1901
+ return window.addEventListener(Ee, y), () => {
1902
+ window.removeEventListener(Ee, y), clearTimeout(d.current);
1903
+ };
1904
+ }, [s, M]);
1905
+ const c = E(
1906
+ (y, D, q) => {
1907
+ clearTimeout(d.current), v.current !== D && (u(0), w(!1), B(!1)), v.current = D, ce(Le(q)), p(y), window.dispatchEvent(
1908
+ new CustomEvent(Ee, { detail: s })
1909
+ );
1910
+ },
1911
+ [s]
1912
+ ), W = E(
1913
+ (y) => {
1914
+ if (y === !0) {
1915
+ M();
1916
+ return;
1917
+ }
1918
+ const D = typeof y == "object" ? y.relatedTarget : null;
1919
+ D?.closest?.("[data-virtual-input], [data-virtual-keypad]") || !D && J.current || (clearTimeout(d.current), d.current = setTimeout(M, 0));
1920
+ },
1921
+ [M]
1922
+ );
1923
+ K(() => {
1924
+ if (!C || !b || A.scale !== 1) return;
1925
+ const y = requestAnimationFrame(() => {
1926
+ const D = v.current?.getBoundingClientRect();
1927
+ if (!D) return;
1928
+ const q = A.offsetTop + A.height - b - 16;
1929
+ D.bottom > q && window.scrollBy({ top: D.bottom - q, behavior: "instant" });
1930
+ });
1931
+ return () => cancelAnimationFrame(y);
1932
+ }, [
1933
+ k,
1934
+ C,
1935
+ b,
1936
+ A.height,
1937
+ A.offsetTop,
1938
+ A.scale
1939
+ ]);
1940
+ const ne = E(() => {
1941
+ ge(X.mode) === null && O((y) => !y);
1942
+ }, [X.mode, O]), G = E(
1943
+ () => u((y) => (y + 1) % 3),
1944
+ []
1945
+ ), V = E(
1946
+ () => u((y) => y === 1 ? 0 : y),
1947
+ []
1948
+ ), Q = E(() => {
1949
+ w(!0), B(!1);
1950
+ }, []), le = E(() => {
1951
+ w(!1), B(!1);
1952
+ }, []), j = E(
1953
+ () => B((y) => !y),
1954
+ []
1955
+ );
1956
+ return /* @__PURE__ */ Y(
1957
+ Ze.Provider,
1958
+ {
1959
+ value: {
1960
+ inputRef: m,
1961
+ focusId: k,
1962
+ onFocus: c,
1963
+ onBlur: W,
1964
+ defaultLayout: n,
1965
+ hangulMode: U,
1966
+ shift: l > 0,
1967
+ shiftLocked: l === 2,
1968
+ theme: a ?? I,
1969
+ toggleKorean: ne,
1970
+ toggleShift: G,
1971
+ consumeShift: V,
1972
+ selectionMode: P,
1973
+ selectionAdjusting: _,
1974
+ enterSelectionMode: Q,
1975
+ exitSelectionMode: le,
1976
+ toggleSelectionAdjust: j,
1977
+ activeInputPolicy: X,
1978
+ editingStatus: ae,
1979
+ setEditingStatus: Z
1980
+ },
1981
+ children: [
1982
+ e,
1983
+ C && /* @__PURE__ */ Y(Pe, { children: [
1984
+ Ie(
1985
+ /* @__PURE__ */ L(
1986
+ "div",
1987
+ {
1988
+ "aria-hidden": "true",
1989
+ style: {
1990
+ height: b,
1991
+ pointerEvents: "none",
1992
+ background: (a ?? I) === "dark" ? "#121c17" : "#f7f8f4"
1993
+ }
1994
+ }
1995
+ ),
1996
+ document.body
1997
+ ),
1998
+ /* @__PURE__ */ L(
1999
+ xt,
2000
+ {
2001
+ layout: P ? St : X.layout,
2002
+ viewport: A,
2003
+ onHeightChange: g
2004
+ },
2005
+ k
2006
+ )
2007
+ ] })
2008
+ ]
2009
+ }
2010
+ );
2011
+ }
2012
+ export {
2013
+ Dt as VirtualInput,
2014
+ Kt as VirtualInputProvider
2015
+ };