@uiwwsw/virtual-keyboard 0.5.2 → 0.5.4
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
|
@@ -23,7 +23,7 @@ var ShadowWrapper = memo(({
|
|
|
23
23
|
const Component = tagName;
|
|
24
24
|
useEffect(() => {
|
|
25
25
|
if (host && !shadowRoot) {
|
|
26
|
-
const shadow = host.attachShadow({ mode: "
|
|
26
|
+
const shadow = host.attachShadow({ mode: "open" });
|
|
27
27
|
setShadowRoot(shadow);
|
|
28
28
|
}
|
|
29
29
|
}, [host, shadowRoot]);
|
|
@@ -581,6 +581,7 @@ function VirtualInput({
|
|
|
581
581
|
const [selection, setSelection] = useState2({ start: null, end: null });
|
|
582
582
|
const [showCursor, setShowCursor] = useState2(true);
|
|
583
583
|
const charPositionsRef = useRef([]);
|
|
584
|
+
const scrollXRef = useRef(0);
|
|
584
585
|
useEffect2(() => {
|
|
585
586
|
charPositionsRef.current = [];
|
|
586
587
|
}, [internalValue]);
|
|
@@ -650,12 +651,18 @@ function VirtualInput({
|
|
|
650
651
|
const height = rect.height;
|
|
651
652
|
ctx.clearRect(0, 0, width, height);
|
|
652
653
|
const computedStyle = window.getComputedStyle(container);
|
|
653
|
-
const font = `${computedStyle.fontSize} ${computedStyle.fontFamily}`;
|
|
654
|
+
const font = `${computedStyle.fontStyle} ${computedStyle.fontVariant} ${computedStyle.fontWeight} ${computedStyle.fontSize} ${computedStyle.fontFamily}`;
|
|
654
655
|
ctx.font = font;
|
|
655
656
|
ctx.textBaseline = "middle";
|
|
656
657
|
const fontSize = parseFloat(computedStyle.fontSize);
|
|
658
|
+
const paddingLeft = parseFloat(computedStyle.paddingLeft) || 0;
|
|
659
|
+
const paddingRight = parseFloat(computedStyle.paddingRight) || 0;
|
|
660
|
+
const borderLeft = parseFloat(computedStyle.borderLeftWidth) || 0;
|
|
661
|
+
const borderRight = parseFloat(computedStyle.borderRightWidth) || 0;
|
|
662
|
+
const color = computedStyle.color || "black";
|
|
663
|
+
const caretColor = (computedStyle.caretColor !== "auto" ? computedStyle.caretColor : color) || "black";
|
|
657
664
|
const y = height / 2;
|
|
658
|
-
const x =
|
|
665
|
+
const x = borderLeft + paddingLeft;
|
|
659
666
|
if (!internalValue && placeholder) {
|
|
660
667
|
ctx.fillStyle = "#aaa";
|
|
661
668
|
ctx.fillText(placeholder, x, y);
|
|
@@ -663,31 +670,53 @@ function VirtualInput({
|
|
|
663
670
|
ctx.beginPath();
|
|
664
671
|
ctx.moveTo(x, y - fontSize / 2);
|
|
665
672
|
ctx.lineTo(x, y + fontSize / 2);
|
|
666
|
-
ctx.strokeStyle =
|
|
673
|
+
ctx.strokeStyle = caretColor;
|
|
667
674
|
ctx.lineWidth = 1.5;
|
|
668
675
|
ctx.stroke();
|
|
669
676
|
}
|
|
670
677
|
return;
|
|
671
678
|
}
|
|
672
|
-
ctx.fillStyle =
|
|
679
|
+
ctx.fillStyle = color;
|
|
673
680
|
if (charPositionsRef.current.length !== internalValue.length + 1) {
|
|
674
681
|
let currentX = x;
|
|
675
682
|
const positions = [x];
|
|
676
683
|
for (let i = 0;i < internalValue.length; i++) {
|
|
677
|
-
const w = ctx.measureText(internalValue
|
|
678
|
-
|
|
679
|
-
positions.push(currentX);
|
|
684
|
+
const w = ctx.measureText(internalValue.slice(0, i + 1)).width;
|
|
685
|
+
positions.push(x + w);
|
|
680
686
|
}
|
|
681
687
|
charPositionsRef.current = positions;
|
|
682
688
|
}
|
|
683
689
|
const charX = charPositionsRef.current;
|
|
690
|
+
const caretPos = charX[caretIndex] ?? x;
|
|
691
|
+
const viewLeft = paddingLeft;
|
|
692
|
+
const viewRight = width - paddingRight - borderLeft - borderRight;
|
|
693
|
+
const safety = 2;
|
|
694
|
+
const totalTextWidth = (charX[charX.length - 1] ?? x) - x;
|
|
695
|
+
const availableWidth = viewRight - viewLeft;
|
|
696
|
+
if (totalTextWidth < availableWidth) {
|
|
697
|
+
scrollXRef.current = 0;
|
|
698
|
+
} else {
|
|
699
|
+
let s = scrollXRef.current;
|
|
700
|
+
if (caretPos - s > viewRight - safety) {
|
|
701
|
+
s = caretPos - viewRight + safety;
|
|
702
|
+
}
|
|
703
|
+
if (caretPos - s < viewLeft + safety) {
|
|
704
|
+
s = caretPos - viewLeft - safety;
|
|
705
|
+
}
|
|
706
|
+
const contentEnd = charX[charX.length - 1] ?? x;
|
|
707
|
+
const maxScroll = Math.max(0, contentEnd - viewRight + safety);
|
|
708
|
+
s = Math.max(0, Math.min(s, maxScroll));
|
|
709
|
+
scrollXRef.current = s;
|
|
710
|
+
}
|
|
711
|
+
ctx.save();
|
|
712
|
+
ctx.translate(-scrollXRef.current, 0);
|
|
684
713
|
if (hasSelection && selection.start !== null && selection.end !== null) {
|
|
685
714
|
const [start, end] = [selection.start, selection.end].sort((a, b) => a - b);
|
|
686
715
|
const startX = charX[start] ?? x;
|
|
687
716
|
const endX = charX[end] ?? charX[charX.length - 1];
|
|
688
717
|
ctx.fillStyle = "#b4d5fe";
|
|
689
718
|
ctx.fillRect(startX, 0, endX - startX, height);
|
|
690
|
-
ctx.fillStyle =
|
|
719
|
+
ctx.fillStyle = color;
|
|
691
720
|
}
|
|
692
721
|
ctx.fillText(internalValue, x, y);
|
|
693
722
|
if (isFocused && showCursor && !hasSelection) {
|
|
@@ -695,10 +724,11 @@ function VirtualInput({
|
|
|
695
724
|
ctx.beginPath();
|
|
696
725
|
ctx.moveTo(caretX, y - fontSize / 2);
|
|
697
726
|
ctx.lineTo(caretX, y + fontSize / 2);
|
|
698
|
-
ctx.strokeStyle =
|
|
727
|
+
ctx.strokeStyle = caretColor;
|
|
699
728
|
ctx.lineWidth = 1.5;
|
|
700
729
|
ctx.stroke();
|
|
701
730
|
}
|
|
731
|
+
ctx.restore();
|
|
702
732
|
}, [internalValue, caretIndex, isFocused, showCursor, placeholder, hasSelection, selection]);
|
|
703
733
|
useEffect2(() => {
|
|
704
734
|
let animationFrameId;
|
|
@@ -728,7 +758,7 @@ function VirtualInput({
|
|
|
728
758
|
if (!canvas)
|
|
729
759
|
return 0;
|
|
730
760
|
const rect = canvas.getBoundingClientRect();
|
|
731
|
-
const x = clientX - rect.left;
|
|
761
|
+
const x = clientX - rect.left + scrollXRef.current;
|
|
732
762
|
if (charPositionsRef.current.length === internalValue.length + 1) {
|
|
733
763
|
const charX = charPositionsRef.current;
|
|
734
764
|
for (let i = 0;i < charX.length - 1; i++) {
|
|
@@ -832,7 +862,15 @@ function VirtualInput({
|
|
|
832
862
|
}, [hangulMode, setHangulMode, isCompositionRef, shift, updateValue, hasSelection, deleteSelectedText, clearSelection]);
|
|
833
863
|
useImperativeHandle(inputRef, () => {
|
|
834
864
|
if (isFocused) {
|
|
835
|
-
return {
|
|
865
|
+
return {
|
|
866
|
+
handleKeyDown,
|
|
867
|
+
scrollIntoView: () => {
|
|
868
|
+
containerRef.current?.scrollIntoView({
|
|
869
|
+
behavior: "smooth",
|
|
870
|
+
block: "nearest"
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
};
|
|
836
874
|
}
|
|
837
875
|
return inputRef.current;
|
|
838
876
|
}, [isFocused, handleKeyDown, inputRef]);
|
|
@@ -857,12 +895,14 @@ function VirtualInput({
|
|
|
857
895
|
outline: "none",
|
|
858
896
|
font: "inherit",
|
|
859
897
|
width: "100%",
|
|
860
|
-
position: "relative"
|
|
898
|
+
position: "relative",
|
|
899
|
+
...props.style
|
|
861
900
|
},
|
|
862
901
|
onFocus: () => onFocus(id),
|
|
863
|
-
onBlur,
|
|
902
|
+
onBlur: (e) => onBlur(e),
|
|
864
903
|
onKeyDown: handleKeyDown,
|
|
865
904
|
onClick: handleCanvasClick,
|
|
905
|
+
"data-virtual-input": "true",
|
|
866
906
|
children: /* @__PURE__ */ jsxDEV2("canvas", {
|
|
867
907
|
ref: canvasRef
|
|
868
908
|
}, undefined, false, undefined, this)
|
|
@@ -874,13 +914,13 @@ import {
|
|
|
874
914
|
useState as useState5,
|
|
875
915
|
useRef as useRef5,
|
|
876
916
|
useCallback as useCallback6,
|
|
877
|
-
useEffect as
|
|
917
|
+
useEffect as useEffect7
|
|
878
918
|
} from "react";
|
|
879
919
|
|
|
880
920
|
// src/components/Keypad.tsx
|
|
881
921
|
import {
|
|
882
922
|
useCallback as useCallback4,
|
|
883
|
-
useEffect as
|
|
923
|
+
useEffect as useEffect4,
|
|
884
924
|
useRef as useRef4
|
|
885
925
|
} from "react";
|
|
886
926
|
|
|
@@ -964,7 +1004,7 @@ function useKeypadLayout({
|
|
|
964
1004
|
}
|
|
965
1005
|
|
|
966
1006
|
// src/hooks/useKeypadInteraction.ts
|
|
967
|
-
import { useCallback as useCallback3, useRef as useRef3, useMemo as useMemo2 } from "react";
|
|
1007
|
+
import { useCallback as useCallback3, useRef as useRef3, useMemo as useMemo2, useEffect as useEffect3 } from "react";
|
|
968
1008
|
function useKeypadInteraction({
|
|
969
1009
|
inputRef,
|
|
970
1010
|
toggleShift,
|
|
@@ -997,6 +1037,7 @@ function useKeypadInteraction({
|
|
|
997
1037
|
shiftKey: shift
|
|
998
1038
|
});
|
|
999
1039
|
inputRef.current?.handleKeyDown(event);
|
|
1040
|
+
inputRef.current?.scrollIntoView();
|
|
1000
1041
|
}, [getTransformedValue, inputRef, shift, toggleKorean, toggleShift]);
|
|
1001
1042
|
const clearRepeat = useCallback3((press) => {
|
|
1002
1043
|
if (!press?.repeatTimeout)
|
|
@@ -1025,6 +1066,7 @@ function useKeypadInteraction({
|
|
|
1025
1066
|
const canvas = e.currentTarget;
|
|
1026
1067
|
if (!canvas)
|
|
1027
1068
|
return;
|
|
1069
|
+
canvas.setPointerCapture(e.pointerId);
|
|
1028
1070
|
const rect = canvas.getBoundingClientRect();
|
|
1029
1071
|
const x = e.clientX - rect.left;
|
|
1030
1072
|
const y = e.clientY - rect.top;
|
|
@@ -1040,6 +1082,12 @@ function useKeypadInteraction({
|
|
|
1040
1082
|
};
|
|
1041
1083
|
activePresses.current.set(e.pointerId, press);
|
|
1042
1084
|
startRepeat(press);
|
|
1085
|
+
} else {
|
|
1086
|
+
activePresses.current.set(e.pointerId, {
|
|
1087
|
+
pointerId: e.pointerId,
|
|
1088
|
+
value: "",
|
|
1089
|
+
keyIndex: -1
|
|
1090
|
+
});
|
|
1043
1091
|
}
|
|
1044
1092
|
}, [dispatchKeyEvent, startRepeat, keyBoundsRef]);
|
|
1045
1093
|
const handlePointerMove = useCallback3((e) => {
|
|
@@ -1069,8 +1117,14 @@ function useKeypadInteraction({
|
|
|
1069
1117
|
startRepeat(newPress);
|
|
1070
1118
|
}
|
|
1071
1119
|
} else {
|
|
1072
|
-
|
|
1073
|
-
|
|
1120
|
+
if (press.keyIndex !== -1) {
|
|
1121
|
+
clearRepeat(press);
|
|
1122
|
+
activePresses.current.set(e.pointerId, {
|
|
1123
|
+
pointerId: e.pointerId,
|
|
1124
|
+
value: "",
|
|
1125
|
+
keyIndex: -1
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1074
1128
|
}
|
|
1075
1129
|
}, [clearRepeat, dispatchKeyEvent, startRepeat, keyBoundsRef]);
|
|
1076
1130
|
const handlePointerUp = useCallback3((e) => {
|
|
@@ -1081,11 +1135,25 @@ function useKeypadInteraction({
|
|
|
1081
1135
|
activePresses.current.delete(e.pointerId);
|
|
1082
1136
|
}
|
|
1083
1137
|
}, [clearRepeat]);
|
|
1138
|
+
useEffect3(() => {
|
|
1139
|
+
return () => {
|
|
1140
|
+
activePresses.current.forEach((press) => {
|
|
1141
|
+
if (press.repeatTimeout) {
|
|
1142
|
+
window.clearTimeout(press.repeatTimeout);
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
activePresses.current.clear();
|
|
1146
|
+
};
|
|
1147
|
+
}, []);
|
|
1148
|
+
const handlePointerCancel = useCallback3((e) => {
|
|
1149
|
+
handlePointerUp(e);
|
|
1150
|
+
}, [handlePointerUp]);
|
|
1084
1151
|
return {
|
|
1085
1152
|
activePresses,
|
|
1086
1153
|
handlePointerDown,
|
|
1087
1154
|
handlePointerMove,
|
|
1088
|
-
handlePointerUp
|
|
1155
|
+
handlePointerUp,
|
|
1156
|
+
handlePointerCancel
|
|
1089
1157
|
};
|
|
1090
1158
|
}
|
|
1091
1159
|
|
|
@@ -1121,7 +1189,8 @@ function VirtualKeypad({
|
|
|
1121
1189
|
activePresses,
|
|
1122
1190
|
handlePointerDown,
|
|
1123
1191
|
handlePointerMove,
|
|
1124
|
-
handlePointerUp
|
|
1192
|
+
handlePointerUp,
|
|
1193
|
+
handlePointerCancel
|
|
1125
1194
|
} = useKeypadInteraction({
|
|
1126
1195
|
inputRef,
|
|
1127
1196
|
toggleShift,
|
|
@@ -1130,17 +1199,56 @@ function VirtualKeypad({
|
|
|
1130
1199
|
getTransformedValue,
|
|
1131
1200
|
keyBoundsRef
|
|
1132
1201
|
});
|
|
1133
|
-
const
|
|
1202
|
+
const drawKey = (ctx, key, isPressed, isActiveModifier, scale) => {
|
|
1203
|
+
const r = 8 / scale;
|
|
1204
|
+
const { x, y, w, h } = key;
|
|
1205
|
+
const colors = {
|
|
1206
|
+
bg: "#d1d5db",
|
|
1207
|
+
keyBg: isPressed ? "#E5E7EB" : "#FFFFFF",
|
|
1208
|
+
keyShadow: "#899499",
|
|
1209
|
+
text: "#111827",
|
|
1210
|
+
actionBg: isPressed ? "#cbd5e1" : "#e2e8f0",
|
|
1211
|
+
activeModBg: isPressed ? "#bfdbfe" : "#dbeafe",
|
|
1212
|
+
activeModText: "#1d4ed8"
|
|
1213
|
+
};
|
|
1214
|
+
if (key.isAction) {
|
|
1215
|
+
colors.keyBg = colors.actionBg;
|
|
1216
|
+
}
|
|
1217
|
+
if (isActiveModifier) {
|
|
1218
|
+
colors.keyBg = colors.activeModBg;
|
|
1219
|
+
}
|
|
1220
|
+
ctx.fillStyle = colors.keyShadow;
|
|
1221
|
+
roundRect(ctx, x, y + 1 / scale, w, h, r);
|
|
1222
|
+
ctx.fill();
|
|
1223
|
+
const pressOffset = isPressed ? 1 / scale : 0;
|
|
1224
|
+
const shadowOffset = isPressed ? 0 : 2 / scale;
|
|
1225
|
+
ctx.fillStyle = colors.keyBg;
|
|
1226
|
+
roundRect(ctx, x, y + pressOffset, w, h - shadowOffset, r);
|
|
1227
|
+
ctx.fill();
|
|
1228
|
+
ctx.textAlign = "center";
|
|
1229
|
+
ctx.textBaseline = "middle";
|
|
1230
|
+
let fontSize = 20 / scale;
|
|
1231
|
+
if (key.label.length > 1)
|
|
1232
|
+
fontSize = 16 / scale;
|
|
1233
|
+
ctx.font = `500 ${fontSize}px "Inter", "system-ui", sans-serif`;
|
|
1234
|
+
if (isActiveModifier) {
|
|
1235
|
+
ctx.fillStyle = colors.activeModText;
|
|
1236
|
+
} else {
|
|
1237
|
+
ctx.fillStyle = colors.text;
|
|
1238
|
+
}
|
|
1239
|
+
ctx.fillText(key.label, x + w / 2, y + (h - shadowOffset) / 2 + pressOffset + 1 / scale);
|
|
1240
|
+
};
|
|
1241
|
+
const roundRect = (ctx, x, y, w, h, r) => {
|
|
1242
|
+
if (w < 2 * r)
|
|
1243
|
+
r = w / 2;
|
|
1244
|
+
if (h < 2 * r)
|
|
1245
|
+
r = h / 2;
|
|
1134
1246
|
ctx.beginPath();
|
|
1135
1247
|
ctx.moveTo(x + r, y);
|
|
1136
|
-
ctx.
|
|
1137
|
-
ctx.
|
|
1138
|
-
ctx.
|
|
1139
|
-
ctx.
|
|
1140
|
-
ctx.lineTo(x + r, y + h);
|
|
1141
|
-
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
|
|
1142
|
-
ctx.lineTo(x, y + r);
|
|
1143
|
-
ctx.quadraticCurveTo(x, y, x + r, y);
|
|
1248
|
+
ctx.arcTo(x + w, y, x + w, y + h, r);
|
|
1249
|
+
ctx.arcTo(x + w, y + h, x, y + h, r);
|
|
1250
|
+
ctx.arcTo(x, y + h, x, y, r);
|
|
1251
|
+
ctx.arcTo(x, y, x + w, y, r);
|
|
1144
1252
|
ctx.closePath();
|
|
1145
1253
|
};
|
|
1146
1254
|
const draw = useCallback4(() => {
|
|
@@ -1163,7 +1271,7 @@ function VirtualKeypad({
|
|
|
1163
1271
|
}
|
|
1164
1272
|
const width = rect.width;
|
|
1165
1273
|
const height = rect.height;
|
|
1166
|
-
ctx.fillStyle = "#
|
|
1274
|
+
ctx.fillStyle = "#d1d5db";
|
|
1167
1275
|
ctx.fillRect(0, 0, width, height);
|
|
1168
1276
|
const scale = viewport.scale;
|
|
1169
1277
|
keyBoundsRef.current.forEach((key) => {
|
|
@@ -1176,63 +1284,33 @@ function VirtualKeypad({
|
|
|
1176
1284
|
}
|
|
1177
1285
|
}
|
|
1178
1286
|
const isActiveModifier = key.value === "Shift" && shift || key.value === "HangulMode" && hangulMode;
|
|
1179
|
-
|
|
1180
|
-
let drawX = key.x;
|
|
1181
|
-
let drawY = key.y;
|
|
1182
|
-
let drawW = key.w;
|
|
1183
|
-
let drawH = key.h;
|
|
1184
|
-
if (isPressed) {
|
|
1185
|
-
const shrink = 2;
|
|
1186
|
-
drawX += shrink;
|
|
1187
|
-
drawY += shrink;
|
|
1188
|
-
drawW -= shrink * 2;
|
|
1189
|
-
drawH -= shrink * 2;
|
|
1190
|
-
}
|
|
1191
|
-
drawRoundedRect(ctx, drawX, drawY, drawW, drawH, radius);
|
|
1192
|
-
if (isPressed) {
|
|
1193
|
-
const gradient = ctx.createLinearGradient(drawX, drawY, drawX, drawY + drawH);
|
|
1194
|
-
gradient.addColorStop(0, "rgba(248, 249, 251, 0.95)");
|
|
1195
|
-
gradient.addColorStop(1, "#c9d2df");
|
|
1196
|
-
ctx.fillStyle = gradient;
|
|
1197
|
-
} else if (isActiveModifier) {
|
|
1198
|
-
const gradient = ctx.createLinearGradient(drawX, drawY, drawX, drawY + drawH);
|
|
1199
|
-
gradient.addColorStop(0, "#e0ecff");
|
|
1200
|
-
gradient.addColorStop(1, "#99b7ff");
|
|
1201
|
-
ctx.fillStyle = gradient;
|
|
1202
|
-
} else if (key.isAction) {
|
|
1203
|
-
const gradient = ctx.createLinearGradient(drawX, drawY, drawX, drawY + drawH);
|
|
1204
|
-
gradient.addColorStop(0, "#f8fafc");
|
|
1205
|
-
gradient.addColorStop(1, "#cbd5f5");
|
|
1206
|
-
ctx.fillStyle = gradient;
|
|
1207
|
-
} else {
|
|
1208
|
-
const gradient = ctx.createLinearGradient(drawX, drawY, drawX, drawY + drawH);
|
|
1209
|
-
gradient.addColorStop(0, "rgba(255, 255, 255, 0.95)");
|
|
1210
|
-
gradient.addColorStop(1, "#dfe3eb");
|
|
1211
|
-
ctx.fillStyle = gradient;
|
|
1212
|
-
}
|
|
1213
|
-
ctx.fill();
|
|
1214
|
-
ctx.lineWidth = 1 / scale;
|
|
1215
|
-
if (isActiveModifier) {
|
|
1216
|
-
ctx.strokeStyle = "rgba(37, 99, 235, 0.25)";
|
|
1217
|
-
} else if (key.isAction) {
|
|
1218
|
-
ctx.strokeStyle = "rgba(59, 130, 246, 0.55)";
|
|
1219
|
-
} else {
|
|
1220
|
-
ctx.strokeStyle = "rgba(148, 163, 184, 0.7)";
|
|
1221
|
-
}
|
|
1222
|
-
ctx.stroke();
|
|
1223
|
-
ctx.textAlign = "center";
|
|
1224
|
-
ctx.textBaseline = "middle";
|
|
1225
|
-
const fontSize = 18 / scale;
|
|
1226
|
-
ctx.font = `600 ${fontSize}px sans-serif`;
|
|
1227
|
-
if (isActiveModifier || key.isAction) {
|
|
1228
|
-
ctx.fillStyle = "#1e3a8a";
|
|
1229
|
-
} else {
|
|
1230
|
-
ctx.fillStyle = "#1f2933";
|
|
1231
|
-
}
|
|
1232
|
-
ctx.fillText(key.label, drawX + drawW / 2, drawY + drawH / 2);
|
|
1287
|
+
drawKey(ctx, key, isPressed, isActiveModifier, scale);
|
|
1233
1288
|
});
|
|
1234
1289
|
}, [calculateLayout, hangulMode, shift, viewport.scale, activePresses, keyBoundsRef]);
|
|
1235
|
-
|
|
1290
|
+
useEffect4(() => {
|
|
1291
|
+
keyBoundsRef.current = [];
|
|
1292
|
+
}, [hangulMode, shift, keyBoundsRef]);
|
|
1293
|
+
useEffect4(() => {
|
|
1294
|
+
const handleGlobalPointerDown = (e) => {
|
|
1295
|
+
if (!containerRef.current || !focusId)
|
|
1296
|
+
return;
|
|
1297
|
+
const path = e.composedPath();
|
|
1298
|
+
if (path.includes(containerRef.current)) {
|
|
1299
|
+
return;
|
|
1300
|
+
}
|
|
1301
|
+
const isInput = path.some((node) => {
|
|
1302
|
+
return node instanceof Element && node.getAttribute("data-virtual-input") === "true";
|
|
1303
|
+
});
|
|
1304
|
+
if (isInput)
|
|
1305
|
+
return;
|
|
1306
|
+
onBlur(true);
|
|
1307
|
+
};
|
|
1308
|
+
window.addEventListener("pointerdown", handleGlobalPointerDown, { capture: true });
|
|
1309
|
+
return () => {
|
|
1310
|
+
window.removeEventListener("pointerdown", handleGlobalPointerDown, { capture: true });
|
|
1311
|
+
};
|
|
1312
|
+
}, [focusId, onBlur]);
|
|
1313
|
+
useEffect4(() => {
|
|
1236
1314
|
let handle;
|
|
1237
1315
|
const loop = () => {
|
|
1238
1316
|
draw();
|
|
@@ -1248,12 +1326,14 @@ function VirtualKeypad({
|
|
|
1248
1326
|
css: `
|
|
1249
1327
|
.keypad-wrapper {
|
|
1250
1328
|
position: fixed;
|
|
1251
|
-
background-color: #
|
|
1329
|
+
background-color: #d1d5db;
|
|
1252
1330
|
border-radius: calc(18px / var(--scale-factor));
|
|
1253
1331
|
box-shadow: 0 calc(-6px / var(--scale-factor)) calc(30px / var(--scale-factor)) rgba(15, 23, 42, 0.2);
|
|
1254
1332
|
user-select: none;
|
|
1255
1333
|
-webkit-user-select: none;
|
|
1256
|
-
touch-action: none;
|
|
1334
|
+
touch-action: none; /* Critical for iOS */
|
|
1335
|
+
-webkit-touch-callout: none; /* Disable magnifier/menu */
|
|
1336
|
+
-webkit-tap-highlight-color: transparent; /* No gray tap box */
|
|
1257
1337
|
z-index: 9999;
|
|
1258
1338
|
overflow: hidden; /* Canvas containment */
|
|
1259
1339
|
}
|
|
@@ -1261,6 +1341,7 @@ function VirtualKeypad({
|
|
|
1261
1341
|
display: block;
|
|
1262
1342
|
width: 100%;
|
|
1263
1343
|
height: 100%;
|
|
1344
|
+
touch-action: none; /* Extra safety */
|
|
1264
1345
|
}
|
|
1265
1346
|
`,
|
|
1266
1347
|
children: /* @__PURE__ */ jsxDEV3("div", {
|
|
@@ -1273,6 +1354,10 @@ function VirtualKeypad({
|
|
|
1273
1354
|
onBlur,
|
|
1274
1355
|
onContextMenu: (e) => e.preventDefault(),
|
|
1275
1356
|
onPointerDown: (e) => e.preventDefault(),
|
|
1357
|
+
onClickCapture: (e) => {
|
|
1358
|
+
e.preventDefault();
|
|
1359
|
+
e.stopPropagation();
|
|
1360
|
+
},
|
|
1276
1361
|
style: {
|
|
1277
1362
|
left: viewport.offsetLeft,
|
|
1278
1363
|
width: viewport.width,
|
|
@@ -1286,14 +1371,14 @@ function VirtualKeypad({
|
|
|
1286
1371
|
onPointerMove: handlePointerMove,
|
|
1287
1372
|
onPointerUp: handlePointerUp,
|
|
1288
1373
|
onPointerLeave: handlePointerUp,
|
|
1289
|
-
onPointerCancel:
|
|
1374
|
+
onPointerCancel: handlePointerCancel
|
|
1290
1375
|
}, undefined, false, undefined, this)
|
|
1291
1376
|
}, undefined, false, undefined, this)
|
|
1292
1377
|
}, undefined, false, undefined, this);
|
|
1293
1378
|
}
|
|
1294
1379
|
|
|
1295
1380
|
// src/hooks/useStorage.ts
|
|
1296
|
-
import { useState as useState3, useCallback as useCallback5, useEffect as
|
|
1381
|
+
import { useState as useState3, useCallback as useCallback5, useEffect as useEffect5 } from "react";
|
|
1297
1382
|
var isBrowser = typeof window !== "undefined";
|
|
1298
1383
|
function useStorage(key, initialValue) {
|
|
1299
1384
|
const [storedValue, setStoredValue] = useState3(() => {
|
|
@@ -1327,7 +1412,7 @@ function useStorage(key, initialValue) {
|
|
|
1327
1412
|
console.error(`Error setting localStorage key "${key}":`, error);
|
|
1328
1413
|
}
|
|
1329
1414
|
}, [key, storedValue]);
|
|
1330
|
-
|
|
1415
|
+
useEffect5(() => {
|
|
1331
1416
|
if (!isBrowser)
|
|
1332
1417
|
return;
|
|
1333
1418
|
const handleStorageChange = (event) => {
|
|
@@ -1395,7 +1480,7 @@ var qwerty_default = [
|
|
|
1395
1480
|
];
|
|
1396
1481
|
|
|
1397
1482
|
// src/hooks/useVisualViewport.ts
|
|
1398
|
-
import { useEffect as
|
|
1483
|
+
import { useEffect as useEffect6, useState as useState4 } from "react";
|
|
1399
1484
|
var getVisualViewport = () => {
|
|
1400
1485
|
if (typeof window !== "undefined" && window.visualViewport) {
|
|
1401
1486
|
return {
|
|
@@ -1417,7 +1502,7 @@ var getVisualViewport = () => {
|
|
|
1417
1502
|
var isSameViewport = (prev, next) => prev.width === next.width && prev.height === next.height && prev.scale === next.scale && prev.offsetLeft === next.offsetLeft && prev.offsetTop === next.offsetTop;
|
|
1418
1503
|
var useVisualViewport = () => {
|
|
1419
1504
|
const [viewport, setViewport] = useState4(getVisualViewport);
|
|
1420
|
-
|
|
1505
|
+
useEffect6(() => {
|
|
1421
1506
|
if (typeof window === "undefined")
|
|
1422
1507
|
return;
|
|
1423
1508
|
let rafId = null;
|
|
@@ -1461,11 +1546,12 @@ function VirtualInputProvider({
|
|
|
1461
1546
|
}) {
|
|
1462
1547
|
const inputRef = useRef5(null);
|
|
1463
1548
|
const sti = useRef5(setTimeout(() => null, 0));
|
|
1549
|
+
const isCompositionRef = useRef5(undefined);
|
|
1464
1550
|
const [focusId, setFocusId] = useState5();
|
|
1465
1551
|
const [shift, setShift] = useState5(false);
|
|
1466
1552
|
const [hangulMode, setHangulMode] = useStorage("virtual-keyboard-hangul-mode", defaultHangulMode);
|
|
1467
1553
|
const viewport = useVisualViewport();
|
|
1468
|
-
|
|
1554
|
+
useEffect7(() => {
|
|
1469
1555
|
if (focusId) {
|
|
1470
1556
|
document.body.style.paddingBottom = `${Math.round(200 / viewport.scale)}px`;
|
|
1471
1557
|
} else {
|
|
@@ -1479,19 +1565,29 @@ function VirtualInputProvider({
|
|
|
1479
1565
|
clearTimeout(sti.current);
|
|
1480
1566
|
setFocusId(id);
|
|
1481
1567
|
};
|
|
1482
|
-
const onBlur = () => {
|
|
1483
|
-
|
|
1568
|
+
const onBlur = useCallback6((e) => {
|
|
1569
|
+
if (e === true) {
|
|
1484
1570
|
setFocusId(undefined);
|
|
1485
1571
|
isCompositionRef.current = false;
|
|
1486
|
-
|
|
1487
|
-
|
|
1572
|
+
return;
|
|
1573
|
+
}
|
|
1574
|
+
if (e && typeof e === "object" && "relatedTarget" in e && e.relatedTarget) {
|
|
1575
|
+
if (e.relatedTarget.getAttribute("data-virtual-input")) {
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1578
|
+
sti.current = setTimeout(() => {
|
|
1579
|
+
setFocusId(undefined);
|
|
1580
|
+
isCompositionRef.current = false;
|
|
1581
|
+
}, 0);
|
|
1582
|
+
return;
|
|
1583
|
+
}
|
|
1584
|
+
}, [setFocusId, isCompositionRef]);
|
|
1488
1585
|
const toggleShift = useCallback6(() => {
|
|
1489
1586
|
setShift((prev) => !prev);
|
|
1490
1587
|
}, []);
|
|
1491
1588
|
const toggleKorean = useCallback6(() => {
|
|
1492
1589
|
setHangulMode((prev) => !prev);
|
|
1493
1590
|
}, [setHangulMode]);
|
|
1494
|
-
const isCompositionRef = useRef5(undefined);
|
|
1495
1591
|
return /* @__PURE__ */ jsxDEV4(VirtualInputContext.Provider, {
|
|
1496
1592
|
value: {
|
|
1497
1593
|
inputRef,
|
|
@@ -4,7 +4,7 @@ interface VirtualInputContextValue {
|
|
|
4
4
|
inputRef: RefObject<VirtualInputHandle | null>;
|
|
5
5
|
isCompositionRef: RefObject<boolean | undefined>;
|
|
6
6
|
onFocus: (id: string) => void;
|
|
7
|
-
onBlur: () => void;
|
|
7
|
+
onBlur: (e?: React.FocusEvent | boolean) => void;
|
|
8
8
|
focusId: string | undefined;
|
|
9
9
|
setHangulMode: Dispatch<SetStateAction<boolean>>;
|
|
10
10
|
hangulMode: boolean;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
export interface VirtualInputHandle {
|
|
3
3
|
handleKeyDown: (e: KeyboardEvent | React.KeyboardEvent) => void;
|
|
4
|
+
scrollIntoView: () => void;
|
|
4
5
|
}
|
|
5
|
-
export interface VirtualInputProps {
|
|
6
|
+
export interface VirtualInputProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
6
7
|
value?: string;
|
|
7
8
|
defaultValue?: string;
|
|
8
9
|
placeholder?: string;
|
|
@@ -25,5 +25,6 @@ export declare function useKeypadInteraction({ inputRef, toggleShift, toggleKore
|
|
|
25
25
|
handlePointerDown: (e: React.PointerEvent<HTMLCanvasElement>) => void;
|
|
26
26
|
handlePointerMove: (e: React.PointerEvent<HTMLCanvasElement>) => void;
|
|
27
27
|
handlePointerUp: (e: React.PointerEvent<HTMLCanvasElement>) => void;
|
|
28
|
+
handlePointerCancel: (e: React.PointerEvent<HTMLCanvasElement>) => void;
|
|
28
29
|
};
|
|
29
30
|
export {};
|