@uiwwsw/virtual-keyboard 0.5.6 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -13,22 +13,23 @@ import {
|
|
|
13
13
|
import { useEffect, useState, memo } from "react";
|
|
14
14
|
import ReactDOM from "react-dom";
|
|
15
15
|
import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
|
|
16
|
-
var ShadowWrapper = memo(({
|
|
17
|
-
children,
|
|
18
|
-
css,
|
|
19
|
-
tagName
|
|
20
|
-
}) => {
|
|
16
|
+
var ShadowWrapper = memo((props) => {
|
|
21
17
|
const [host, setHost] = useState(null);
|
|
22
18
|
const [shadowRoot, setShadowRoot] = useState(null);
|
|
19
|
+
const { tagName, css, children, hostRef, ...rest } = props;
|
|
23
20
|
const Component = tagName;
|
|
24
21
|
useEffect(() => {
|
|
25
22
|
if (host && !shadowRoot) {
|
|
26
23
|
const shadow = host.attachShadow({ mode: "open" });
|
|
27
24
|
setShadowRoot(shadow);
|
|
28
25
|
}
|
|
29
|
-
|
|
26
|
+
if (hostRef) {
|
|
27
|
+
hostRef.current = host;
|
|
28
|
+
}
|
|
29
|
+
}, [host, shadowRoot, hostRef]);
|
|
30
30
|
return /* @__PURE__ */ jsxDEV(Component, {
|
|
31
31
|
ref: setHost,
|
|
32
|
+
...rest,
|
|
32
33
|
children: shadowRoot && ReactDOM.createPortal(/* @__PURE__ */ jsxDEV(Fragment, {
|
|
33
34
|
children: [
|
|
34
35
|
css && /* @__PURE__ */ jsxDEV("style", {
|
|
@@ -580,6 +581,14 @@ function VirtualInput({
|
|
|
580
581
|
const caretIndexRef = useRef(caretIndex);
|
|
581
582
|
const [selection, setSelection] = useState2({ start: null, end: null });
|
|
582
583
|
const [showCursor, setShowCursor] = useState2(true);
|
|
584
|
+
const showCursorRef = useRef(showCursor);
|
|
585
|
+
useEffect2(() => {
|
|
586
|
+
showCursorRef.current = showCursor;
|
|
587
|
+
}, [showCursor]);
|
|
588
|
+
const longPressTimerRef = useRef(null);
|
|
589
|
+
const [showCopyFeedback, setShowCopyFeedback] = useState2(false);
|
|
590
|
+
const pointerStartedRef = useRef(false);
|
|
591
|
+
const pointerStartPositionRef = useRef(null);
|
|
583
592
|
const charPositionsRef = useRef([]);
|
|
584
593
|
const scrollXRef = useRef(0);
|
|
585
594
|
useEffect2(() => {
|
|
@@ -677,16 +686,20 @@ function VirtualInput({
|
|
|
677
686
|
return;
|
|
678
687
|
}
|
|
679
688
|
ctx.fillStyle = color;
|
|
680
|
-
|
|
689
|
+
const text = internalValueRef.current;
|
|
690
|
+
const cIndex = caretIndexRef.current;
|
|
691
|
+
const currentScrollX = scrollXRef.current;
|
|
692
|
+
const isCursorVisible = showCursorRef.current;
|
|
693
|
+
if (charPositionsRef.current.length !== text.length + 1) {
|
|
681
694
|
const positions = [x];
|
|
682
|
-
for (let i = 0;i <
|
|
683
|
-
const w = ctx.measureText(
|
|
695
|
+
for (let i = 0;i < text.length; i++) {
|
|
696
|
+
const w = ctx.measureText(text.slice(0, i + 1)).width;
|
|
684
697
|
positions.push(x + w);
|
|
685
698
|
}
|
|
686
699
|
charPositionsRef.current = positions;
|
|
687
700
|
}
|
|
688
701
|
const charX = charPositionsRef.current;
|
|
689
|
-
const caretPos = charX[
|
|
702
|
+
const caretPos = charX[cIndex] ?? x;
|
|
690
703
|
const viewLeft = paddingLeft;
|
|
691
704
|
const viewRight = width - paddingRight - borderLeft - borderRight;
|
|
692
705
|
const safety = 2;
|
|
@@ -717,9 +730,9 @@ function VirtualInput({
|
|
|
717
730
|
ctx.fillRect(startX, 0, endX - startX, height);
|
|
718
731
|
ctx.fillStyle = color;
|
|
719
732
|
}
|
|
720
|
-
ctx.fillText(
|
|
721
|
-
if (isFocused &&
|
|
722
|
-
const caretX = charX[
|
|
733
|
+
ctx.fillText(text, x, y);
|
|
734
|
+
if (isFocused && isCursorVisible && !hasSelection) {
|
|
735
|
+
const caretX = charX[cIndex] ?? x;
|
|
723
736
|
ctx.beginPath();
|
|
724
737
|
ctx.moveTo(caretX, y - fontSize / 2);
|
|
725
738
|
ctx.lineTo(caretX, y + fontSize / 2);
|
|
@@ -727,8 +740,36 @@ function VirtualInput({
|
|
|
727
740
|
ctx.lineWidth = 1.5;
|
|
728
741
|
ctx.stroke();
|
|
729
742
|
}
|
|
743
|
+
if (showCopyFeedback) {
|
|
744
|
+
ctx.save();
|
|
745
|
+
ctx.fillStyle = "rgba(0, 0, 0, 0.7)";
|
|
746
|
+
const msg = "Copied!";
|
|
747
|
+
const msgWidth = ctx.measureText(msg).width + 20;
|
|
748
|
+
const msgHeight = fontSize + 10;
|
|
749
|
+
ctx.translate(scrollXRef.current, 0);
|
|
750
|
+
ctx.restore();
|
|
751
|
+
ctx.save();
|
|
752
|
+
const cx = width / 2;
|
|
753
|
+
const cy = height / 2;
|
|
754
|
+
ctx.fillStyle = "rgba(30, 41, 59, 0.9)";
|
|
755
|
+
const r = 6;
|
|
756
|
+
const rw = msgWidth;
|
|
757
|
+
const rh = msgHeight;
|
|
758
|
+
const rx = cx - rw / 2;
|
|
759
|
+
const ry = cy - rh / 2;
|
|
760
|
+
ctx.beginPath();
|
|
761
|
+
ctx.roundRect(rx, ry, rw, rh, r);
|
|
762
|
+
ctx.fill();
|
|
763
|
+
ctx.fillStyle = "#ffffff";
|
|
764
|
+
ctx.font = `bold ${fontSize * 0.8}px system-ui`;
|
|
765
|
+
ctx.textAlign = "center";
|
|
766
|
+
ctx.textBaseline = "middle";
|
|
767
|
+
ctx.fillText(msg, cx, cy);
|
|
768
|
+
ctx.restore();
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
730
771
|
ctx.restore();
|
|
731
|
-
}, [
|
|
772
|
+
}, [isFocused, placeholder, hasSelection, selection, showCopyFeedback]);
|
|
732
773
|
useEffect2(() => {
|
|
733
774
|
let animationFrameId;
|
|
734
775
|
const loop = () => {
|
|
@@ -783,12 +824,57 @@ function VirtualInput({
|
|
|
783
824
|
return internalValue.length;
|
|
784
825
|
}, [internalValue]);
|
|
785
826
|
const handleCanvasClick = useCallback((e) => {
|
|
827
|
+
if (showCopyFeedback)
|
|
828
|
+
return;
|
|
786
829
|
const index = getCharIndexFromX(e.clientX);
|
|
787
830
|
caretIndexRef.current = index;
|
|
788
831
|
setCaretIndex(index);
|
|
789
832
|
clearSelection();
|
|
790
833
|
onFocus(id);
|
|
791
|
-
}, [getCharIndexFromX, clearSelection, onFocus, id]);
|
|
834
|
+
}, [getCharIndexFromX, clearSelection, onFocus, id, showCopyFeedback]);
|
|
835
|
+
const cancelLongPress = useCallback(() => {
|
|
836
|
+
if (longPressTimerRef.current) {
|
|
837
|
+
clearTimeout(longPressTimerRef.current);
|
|
838
|
+
longPressTimerRef.current = null;
|
|
839
|
+
}
|
|
840
|
+
pointerStartedRef.current = false;
|
|
841
|
+
pointerStartPositionRef.current = null;
|
|
842
|
+
}, []);
|
|
843
|
+
const handlePointerDown = useCallback((e) => {
|
|
844
|
+
if (e.button !== 0)
|
|
845
|
+
return;
|
|
846
|
+
cancelLongPress();
|
|
847
|
+
pointerStartedRef.current = true;
|
|
848
|
+
pointerStartPositionRef.current = { x: e.clientX, y: e.clientY };
|
|
849
|
+
longPressTimerRef.current = window.setTimeout(async () => {
|
|
850
|
+
if (!pointerStartedRef.current)
|
|
851
|
+
return;
|
|
852
|
+
pointerStartedRef.current = false;
|
|
853
|
+
try {
|
|
854
|
+
if (internalValueRef.current) {
|
|
855
|
+
await navigator.clipboard.writeText(internalValueRef.current);
|
|
856
|
+
if (navigator.vibrate)
|
|
857
|
+
navigator.vibrate(50);
|
|
858
|
+
setShowCopyFeedback(true);
|
|
859
|
+
setTimeout(() => setShowCopyFeedback(false), 1500);
|
|
860
|
+
}
|
|
861
|
+
} catch (err) {
|
|
862
|
+
console.error("Failed to copy", err);
|
|
863
|
+
}
|
|
864
|
+
}, 600);
|
|
865
|
+
}, [cancelLongPress]);
|
|
866
|
+
const handlePointerMove = useCallback((e) => {
|
|
867
|
+
if (!pointerStartedRef.current || !pointerStartPositionRef.current)
|
|
868
|
+
return;
|
|
869
|
+
const dx = Math.abs(e.clientX - pointerStartPositionRef.current.x);
|
|
870
|
+
const dy = Math.abs(e.clientY - pointerStartPositionRef.current.y);
|
|
871
|
+
if (dx > 10 || dy > 10) {
|
|
872
|
+
cancelLongPress();
|
|
873
|
+
}
|
|
874
|
+
}, [cancelLongPress]);
|
|
875
|
+
const handlePointerUp = useCallback(() => {
|
|
876
|
+
cancelLongPress();
|
|
877
|
+
}, [cancelLongPress]);
|
|
792
878
|
const handleKeyDown = useCallback((e) => {
|
|
793
879
|
const currentVal = internalValueRef.current;
|
|
794
880
|
const currentCaret = caretIndexRef.current;
|
|
@@ -796,6 +882,20 @@ function VirtualInput({
|
|
|
796
882
|
setHangulMode(!hangulMode);
|
|
797
883
|
return;
|
|
798
884
|
}
|
|
885
|
+
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "c") {
|
|
886
|
+
if (hasSelection && selection.start !== null && selection.end !== null) {
|
|
887
|
+
const [start, end] = [selection.start, selection.end].sort((a, b) => a - b);
|
|
888
|
+
const textToCopy = currentVal.slice(start, end);
|
|
889
|
+
navigator.clipboard.writeText(textToCopy).then(() => {
|
|
890
|
+
if (navigator.vibrate)
|
|
891
|
+
navigator.vibrate(50);
|
|
892
|
+
setShowCopyFeedback(true);
|
|
893
|
+
setTimeout(() => setShowCopyFeedback(false), 1500);
|
|
894
|
+
}).catch(console.error);
|
|
895
|
+
e.preventDefault();
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
799
899
|
if (e.shiftKey && (e.key === "ArrowLeft" || e.key === "ArrowRight")) {
|
|
800
900
|
const newIndex = e.key === "ArrowLeft" ? Math.max(0, currentCaret - 1) : Math.min(currentVal.length, currentCaret + 1);
|
|
801
901
|
setSelection((prev) => ({
|
|
@@ -858,7 +958,17 @@ function VirtualInput({
|
|
|
858
958
|
updateValue(finalString, finalCaretIndex + text.length);
|
|
859
959
|
}
|
|
860
960
|
isCompositionRef.current = composing;
|
|
861
|
-
}, [
|
|
961
|
+
}, [
|
|
962
|
+
hangulMode,
|
|
963
|
+
setHangulMode,
|
|
964
|
+
isCompositionRef,
|
|
965
|
+
shift,
|
|
966
|
+
updateValue,
|
|
967
|
+
hasSelection,
|
|
968
|
+
deleteSelectedText,
|
|
969
|
+
clearSelection,
|
|
970
|
+
selection
|
|
971
|
+
]);
|
|
862
972
|
useImperativeHandle(inputRef, () => {
|
|
863
973
|
if (isFocused) {
|
|
864
974
|
return {
|
|
@@ -875,36 +985,48 @@ function VirtualInput({
|
|
|
875
985
|
}, [isFocused, handleKeyDown, inputRef]);
|
|
876
986
|
return /* @__PURE__ */ jsxDEV2(ShadowWrapper, {
|
|
877
987
|
tagName: "virtual-input-canvas",
|
|
988
|
+
hostRef: containerRef,
|
|
989
|
+
id,
|
|
990
|
+
className: props.className,
|
|
991
|
+
role: "textbox",
|
|
992
|
+
tabIndex: 0,
|
|
993
|
+
...props,
|
|
994
|
+
style: {
|
|
995
|
+
display: "inline-block",
|
|
996
|
+
minHeight: "1.5em",
|
|
997
|
+
height: "1.5em",
|
|
998
|
+
outline: "none",
|
|
999
|
+
font: "inherit",
|
|
1000
|
+
width: "100%",
|
|
1001
|
+
position: "relative",
|
|
1002
|
+
cursor: "text",
|
|
1003
|
+
...props.style
|
|
1004
|
+
},
|
|
1005
|
+
onFocus: () => onFocus(id, containerRef.current),
|
|
1006
|
+
onBlur: (e) => onBlur(e),
|
|
1007
|
+
onKeyDown: handleKeyDown,
|
|
1008
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
1009
|
+
onClick: handleCanvasClick,
|
|
1010
|
+
onPointerDown: handlePointerDown,
|
|
1011
|
+
onPointerMove: handlePointerMove,
|
|
1012
|
+
onPointerUp: handlePointerUp,
|
|
1013
|
+
onPointerLeave: handlePointerUp,
|
|
1014
|
+
onPointerCancel: handlePointerUp,
|
|
1015
|
+
"data-virtual-input": "true",
|
|
878
1016
|
css: `
|
|
1017
|
+
:host {
|
|
1018
|
+
display: inline-block;
|
|
1019
|
+
position: relative;
|
|
1020
|
+
}
|
|
879
1021
|
canvas {
|
|
880
1022
|
width: 100%;
|
|
881
1023
|
height: 100%;
|
|
882
|
-
cursor: text;
|
|
883
1024
|
display: block;
|
|
884
1025
|
}
|
|
885
1026
|
`,
|
|
886
|
-
children: /* @__PURE__ */ jsxDEV2("
|
|
887
|
-
ref:
|
|
888
|
-
|
|
889
|
-
role: "textbox",
|
|
890
|
-
tabIndex: 0,
|
|
891
|
-
style: {
|
|
892
|
-
minHeight: "1.5em",
|
|
893
|
-
height: "1.5em",
|
|
894
|
-
outline: "none",
|
|
895
|
-
font: "inherit",
|
|
896
|
-
width: "100%",
|
|
897
|
-
position: "relative",
|
|
898
|
-
...props.style
|
|
899
|
-
},
|
|
900
|
-
onFocus: () => onFocus(id),
|
|
901
|
-
onBlur: (e) => onBlur(e),
|
|
902
|
-
onKeyDown: handleKeyDown,
|
|
903
|
-
onClick: handleCanvasClick,
|
|
904
|
-
"data-virtual-input": "true",
|
|
905
|
-
children: /* @__PURE__ */ jsxDEV2("canvas", {
|
|
906
|
-
ref: canvasRef
|
|
907
|
-
}, undefined, false, undefined, this)
|
|
1027
|
+
children: /* @__PURE__ */ jsxDEV2("canvas", {
|
|
1028
|
+
ref: canvasRef,
|
|
1029
|
+
style: { width: "100%", height: "100%", display: "block" }
|
|
908
1030
|
}, undefined, false, undefined, this)
|
|
909
1031
|
}, undefined, false, undefined, this);
|
|
910
1032
|
}
|
|
@@ -917,11 +1039,8 @@ import {
|
|
|
917
1039
|
} from "react";
|
|
918
1040
|
|
|
919
1041
|
// src/components/Keypad.tsx
|
|
920
|
-
import {
|
|
921
|
-
|
|
922
|
-
useEffect as useEffect4,
|
|
923
|
-
useRef as useRef4
|
|
924
|
-
} from "react";
|
|
1042
|
+
import { useRef as useRef4, useEffect as useEffect4, useCallback as useCallback4 } from "react";
|
|
1043
|
+
import { createPortal } from "react-dom";
|
|
925
1044
|
|
|
926
1045
|
// src/utils/isMobileAgent.ts
|
|
927
1046
|
function isMobileAgent(userAgent = navigator.userAgent) {
|
|
@@ -977,11 +1096,16 @@ function useKeypadLayout({
|
|
|
977
1096
|
row.forEach((cell, colIndex) => {
|
|
978
1097
|
const flex = cell.width || 1;
|
|
979
1098
|
const cellW = flex * unitW;
|
|
1099
|
+
const halfGap = gap / 2;
|
|
980
1100
|
bounds.push({
|
|
981
1101
|
x: currentX,
|
|
982
1102
|
y: currentY,
|
|
983
1103
|
w: cellW,
|
|
984
1104
|
h: rowHeight,
|
|
1105
|
+
hitX: currentX - halfGap,
|
|
1106
|
+
hitY: currentY - halfGap,
|
|
1107
|
+
hitW: cellW + gap,
|
|
1108
|
+
hitH: rowHeight + gap,
|
|
985
1109
|
value: cell.value,
|
|
986
1110
|
type: cell.type,
|
|
987
1111
|
label: getTransformedValue(cell),
|
|
@@ -1069,7 +1193,7 @@ function useKeypadInteraction({
|
|
|
1069
1193
|
const rect = canvas.getBoundingClientRect();
|
|
1070
1194
|
const x = e.clientX - rect.left;
|
|
1071
1195
|
const y = e.clientY - rect.top;
|
|
1072
|
-
const hitKey = keyBoundsRef.current.find((k) => x >= k.
|
|
1196
|
+
const hitKey = keyBoundsRef.current.find((k) => x >= k.hitX && x <= k.hitX + k.hitW && y >= k.hitY && y <= k.hitY + k.hitH);
|
|
1073
1197
|
if (hitKey) {
|
|
1074
1198
|
const keyIndex = hitKey.rowIndex * 100 + hitKey.colIndex;
|
|
1075
1199
|
dispatchKeyEvent(hitKey.value, hitKey.type);
|
|
@@ -1100,7 +1224,7 @@ function useKeypadInteraction({
|
|
|
1100
1224
|
const rect = canvas.getBoundingClientRect();
|
|
1101
1225
|
const x = e.clientX - rect.left;
|
|
1102
1226
|
const y = e.clientY - rect.top;
|
|
1103
|
-
const hitKey = keyBoundsRef.current.find((k) => x >= k.
|
|
1227
|
+
const hitKey = keyBoundsRef.current.find((k) => x >= k.hitX && x <= k.hitX + k.hitW && y >= k.hitY && y <= k.hitY + k.hitH);
|
|
1104
1228
|
if (hitKey) {
|
|
1105
1229
|
const newKeyIndex = hitKey.rowIndex * 100 + hitKey.colIndex;
|
|
1106
1230
|
if (newKeyIndex !== press.keyIndex) {
|
|
@@ -1331,61 +1455,59 @@ function VirtualKeypad({
|
|
|
1331
1455
|
}, [draw]);
|
|
1332
1456
|
if (!focusId || !isMobileAgent())
|
|
1333
1457
|
return null;
|
|
1334
|
-
return /* @__PURE__ */ jsxDEV3(ShadowWrapper, {
|
|
1458
|
+
return createPortal(/* @__PURE__ */ jsxDEV3(ShadowWrapper, {
|
|
1335
1459
|
tagName: "virtual-keypad-canvas",
|
|
1460
|
+
hostRef: containerRef,
|
|
1461
|
+
style: {
|
|
1462
|
+
position: "fixed",
|
|
1463
|
+
bottom: 0,
|
|
1464
|
+
left: 0,
|
|
1465
|
+
right: 0,
|
|
1466
|
+
margin: "0 auto",
|
|
1467
|
+
width: viewport.width,
|
|
1468
|
+
height: Math.round(200 / viewport.scale),
|
|
1469
|
+
backgroundColor: theme === "dark" ? "#0f172a" : "#e2e8f0",
|
|
1470
|
+
borderRadius: `calc(18px / ${viewport.scale}) calc(18px / ${viewport.scale}) 0 0`,
|
|
1471
|
+
boxShadow: `0 calc(-6px / ${viewport.scale}) calc(30px / ${viewport.scale}) rgba(15, 23, 42, 0.2)`,
|
|
1472
|
+
zIndex: 9999,
|
|
1473
|
+
overflow: "hidden",
|
|
1474
|
+
userSelect: "none",
|
|
1475
|
+
touchAction: "none",
|
|
1476
|
+
"--scale-factor": viewport.scale,
|
|
1477
|
+
"--keypad-bg": theme === "dark" ? "#0f172a" : "#e2e8f0"
|
|
1478
|
+
},
|
|
1479
|
+
onFocus: () => {
|
|
1480
|
+
if (focusId)
|
|
1481
|
+
onFocus(focusId);
|
|
1482
|
+
},
|
|
1483
|
+
onBlur,
|
|
1484
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
1485
|
+
onPointerDown: (e) => e.preventDefault(),
|
|
1486
|
+
onClickCapture: (e) => {
|
|
1487
|
+
e.preventDefault();
|
|
1488
|
+
e.stopPropagation();
|
|
1489
|
+
},
|
|
1336
1490
|
css: `
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
}
|
|
1356
|
-
`,
|
|
1357
|
-
children: /* @__PURE__ */ jsxDEV3("div", {
|
|
1358
|
-
ref: containerRef,
|
|
1359
|
-
className: "keypad-wrapper",
|
|
1360
|
-
onFocus: () => {
|
|
1361
|
-
if (focusId)
|
|
1362
|
-
onFocus(focusId);
|
|
1363
|
-
},
|
|
1364
|
-
onBlur,
|
|
1365
|
-
onContextMenu: (e) => e.preventDefault(),
|
|
1366
|
-
onPointerDown: (e) => e.preventDefault(),
|
|
1367
|
-
onClickCapture: (e) => {
|
|
1368
|
-
e.preventDefault();
|
|
1369
|
-
e.stopPropagation();
|
|
1370
|
-
},
|
|
1371
|
-
style: {
|
|
1372
|
-
left: viewport.offsetLeft,
|
|
1373
|
-
width: viewport.width,
|
|
1374
|
-
top: Math.round(viewport.offsetTop + viewport.height - 200 / viewport.scale),
|
|
1375
|
-
height: Math.round(200 / viewport.scale),
|
|
1376
|
-
"--scale-factor": viewport.scale,
|
|
1377
|
-
"--keypad-bg": theme === "dark" ? "#0f172a" : "#e2e8f0"
|
|
1378
|
-
},
|
|
1379
|
-
children: /* @__PURE__ */ jsxDEV3("canvas", {
|
|
1380
|
-
ref: canvasRef,
|
|
1381
|
-
onPointerDown: handlePointerDown,
|
|
1382
|
-
onPointerMove: handlePointerMove,
|
|
1383
|
-
onPointerUp: handlePointerUp,
|
|
1384
|
-
onPointerLeave: handlePointerUp,
|
|
1385
|
-
onPointerCancel: handlePointerCancel
|
|
1386
|
-
}, undefined, false, undefined, this)
|
|
1491
|
+
:host {
|
|
1492
|
+
display: block;
|
|
1493
|
+
}
|
|
1494
|
+
canvas {
|
|
1495
|
+
display: block;
|
|
1496
|
+
width: 100%;
|
|
1497
|
+
height: 100%;
|
|
1498
|
+
touch-action: none;
|
|
1499
|
+
}
|
|
1500
|
+
`,
|
|
1501
|
+
children: /* @__PURE__ */ jsxDEV3("canvas", {
|
|
1502
|
+
ref: canvasRef,
|
|
1503
|
+
onPointerDown: handlePointerDown,
|
|
1504
|
+
onPointerMove: handlePointerMove,
|
|
1505
|
+
onPointerUp: handlePointerUp,
|
|
1506
|
+
onPointerLeave: handlePointerUp,
|
|
1507
|
+
onPointerCancel: handlePointerCancel,
|
|
1508
|
+
style: { width: "100%", height: "100%", display: "block" }
|
|
1387
1509
|
}, undefined, false, undefined, this)
|
|
1388
|
-
}, undefined, false, undefined, this);
|
|
1510
|
+
}, undefined, false, undefined, this), document.body);
|
|
1389
1511
|
}
|
|
1390
1512
|
|
|
1391
1513
|
// src/hooks/useStorage.ts
|
|
@@ -1587,21 +1709,36 @@ function VirtualInputProvider({
|
|
|
1587
1709
|
const viewport = useVisualViewport();
|
|
1588
1710
|
const systemTheme = useSystemTheme();
|
|
1589
1711
|
const effectiveTheme = theme ?? systemTheme;
|
|
1712
|
+
const focusedElementRef = useRef5(null);
|
|
1590
1713
|
useEffect8(() => {
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1714
|
+
if (focusId && focusedElementRef.current) {
|
|
1715
|
+
const paddingBottom = Math.round(200 / viewport.scale);
|
|
1716
|
+
document.body.style.paddingBottom = `${paddingBottom}px`;
|
|
1717
|
+
setTimeout(() => {
|
|
1718
|
+
const el = focusedElementRef.current;
|
|
1719
|
+
if (el) {
|
|
1720
|
+
const rect = el.getBoundingClientRect();
|
|
1721
|
+
const scrollTop = window.scrollY || document.documentElement.scrollTop;
|
|
1722
|
+
const elementTop = rect.top + scrollTop;
|
|
1723
|
+
const availableHeight = viewport.height - paddingBottom;
|
|
1724
|
+
const targetScroll = elementTop - availableHeight / 2 + rect.height / 2;
|
|
1725
|
+
window.scrollTo({
|
|
1726
|
+
top: targetScroll,
|
|
1727
|
+
behavior: "smooth"
|
|
1728
|
+
});
|
|
1729
|
+
}
|
|
1730
|
+
}, 100);
|
|
1596
1731
|
} else {
|
|
1597
1732
|
document.body.style.paddingBottom = "0px";
|
|
1598
1733
|
}
|
|
1599
1734
|
return () => {
|
|
1600
1735
|
document.body.style.paddingBottom = "0px";
|
|
1601
1736
|
};
|
|
1602
|
-
}, [focusId, viewport.scale]);
|
|
1603
|
-
const onFocus = (id) => {
|
|
1737
|
+
}, [focusId, viewport.scale, viewport.height, viewport.offsetTop]);
|
|
1738
|
+
const onFocus = (id, target) => {
|
|
1604
1739
|
clearTimeout(sti.current);
|
|
1740
|
+
if (target)
|
|
1741
|
+
focusedElementRef.current = target;
|
|
1605
1742
|
setFocusId(id);
|
|
1606
1743
|
};
|
|
1607
1744
|
const onBlur = useCallback6((e) => {
|
|
@@ -3,7 +3,7 @@ import type { VirtualInputHandle } from "./Input";
|
|
|
3
3
|
interface VirtualInputContextValue {
|
|
4
4
|
inputRef: RefObject<VirtualInputHandle | null>;
|
|
5
5
|
isCompositionRef: RefObject<boolean | undefined>;
|
|
6
|
-
onFocus: (id: string) => void;
|
|
6
|
+
onFocus: (id: string, target?: HTMLElement | null) => void;
|
|
7
7
|
onBlur: (e?: React.FocusEvent | boolean) => void;
|
|
8
8
|
focusId: string | undefined;
|
|
9
9
|
setHangulMode: Dispatch<SetStateAction<boolean>>;
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* @param css 스타일을 문자열로 받아서 <style>로 삽입
|
|
5
5
|
* @returns Shadow DOM 안에 children과 style을 렌더링
|
|
6
6
|
*/
|
|
7
|
-
export declare const ShadowWrapper: import("react").MemoExoticComponent<(
|
|
7
|
+
export declare const ShadowWrapper: import("react").MemoExoticComponent<(props: {
|
|
8
8
|
children: React.ReactNode;
|
|
9
9
|
css?: string;
|
|
10
|
-
tagName:
|
|
11
|
-
|
|
10
|
+
tagName: string;
|
|
11
|
+
hostRef?: React.MutableRefObject<HTMLElement | null>;
|
|
12
|
+
} & React.HTMLAttributes<HTMLElement>) => import("react/jsx-runtime").JSX.Element>;
|