@uiwwsw/virtual-keyboard 0.5.5 → 0.5.6

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
@@ -910,10 +910,10 @@ function VirtualInput({
910
910
  }
911
911
  // src/components/Provider.tsx
912
912
  import {
913
- useState as useState5,
913
+ useState as useState6,
914
914
  useRef as useRef5,
915
915
  useCallback as useCallback6,
916
- useEffect as useEffect7
916
+ useEffect as useEffect8
917
917
  } from "react";
918
918
 
919
919
  // src/components/Keypad.tsx
@@ -1170,7 +1170,8 @@ function VirtualKeypad({
1170
1170
  shift,
1171
1171
  hangulMode,
1172
1172
  toggleShift,
1173
- toggleKorean
1173
+ toggleKorean,
1174
+ theme
1174
1175
  } = useVirtualInputContext();
1175
1176
  const canvasRef = useRef4(null);
1176
1177
  const containerRef = useRef4(null);
@@ -1198,44 +1199,50 @@ function VirtualKeypad({
1198
1199
  getTransformedValue,
1199
1200
  keyBoundsRef
1200
1201
  });
1201
- const drawKey = (ctx, key, isPressed, isActiveModifier, scale) => {
1202
- const r = 8 / scale;
1202
+ const drawKey = (ctx, key, isPressed, isActiveModifier, scale, currentTheme) => {
1203
+ const r = 10 / scale;
1203
1204
  const { x, y, w, h } = key;
1204
- const colors = {
1205
- bg: "#d1d5db",
1206
- keyBg: isPressed ? "#E5E7EB" : "#FFFFFF",
1207
- keyShadow: "#899499",
1208
- text: "#111827",
1209
- actionBg: isPressed ? "#cbd5e1" : "#e2e8f0",
1210
- activeModBg: isPressed ? "#bfdbfe" : "#dbeafe",
1205
+ const colors = currentTheme === "dark" ? {
1206
+ shadow: "#0f172a",
1207
+ keyFace: isPressed ? "#334155" : "#1e293b",
1208
+ text: "#f8fafc",
1209
+ actionFace: isPressed ? "#475569" : "#334155",
1210
+ activeModFace: isPressed ? "#f8fafc" : "#e2e8f0",
1211
+ activeModText: "#0f172a"
1212
+ } : {
1213
+ shadow: "#cbd5e1",
1214
+ keyFace: isPressed ? "#f1f5f9" : "#ffffff",
1215
+ text: "#1e293b",
1216
+ actionFace: isPressed ? "#e2e8f0" : "#f1f5f9",
1217
+ activeModFace: isPressed ? "#bfdbfe" : "#dbeafe",
1211
1218
  activeModText: "#1d4ed8"
1212
1219
  };
1220
+ let faceColor = colors.keyFace;
1221
+ let textColor = colors.text;
1213
1222
  if (key.isAction) {
1214
- colors.keyBg = colors.actionBg;
1223
+ faceColor = colors.actionFace;
1215
1224
  }
1216
1225
  if (isActiveModifier) {
1217
- colors.keyBg = colors.activeModBg;
1226
+ faceColor = colors.activeModFace;
1227
+ textColor = colors.activeModText;
1218
1228
  }
1219
- ctx.fillStyle = colors.keyShadow;
1220
- roundRect(ctx, x, y + 1 / scale, w, h, r);
1229
+ const depth = 4 / scale;
1230
+ const pressOffset = isPressed ? depth * 0.6 : 0;
1231
+ ctx.fillStyle = colors.shadow;
1232
+ roundRect(ctx, x, y + depth, w, h, r);
1221
1233
  ctx.fill();
1222
- const pressOffset = isPressed ? 1 / scale : 0;
1223
- const shadowOffset = isPressed ? 0 : 2 / scale;
1224
- ctx.fillStyle = colors.keyBg;
1225
- roundRect(ctx, x, y + pressOffset, w, h - shadowOffset, r);
1234
+ ctx.fillStyle = faceColor;
1235
+ roundRect(ctx, x, y + pressOffset, w, h, r);
1226
1236
  ctx.fill();
1227
1237
  ctx.textAlign = "center";
1228
1238
  ctx.textBaseline = "middle";
1229
1239
  let fontSize = 20 / scale;
1230
1240
  if (key.label.length > 1)
1231
1241
  fontSize = 16 / scale;
1232
- ctx.font = `500 ${fontSize}px "Inter", "system-ui", sans-serif`;
1233
- if (isActiveModifier) {
1234
- ctx.fillStyle = colors.activeModText;
1235
- } else {
1236
- ctx.fillStyle = colors.text;
1237
- }
1238
- ctx.fillText(key.label, x + w / 2, y + (h - shadowOffset) / 2 + pressOffset + 1 / scale);
1242
+ const fontFamily = currentTheme === "dark" ? "Inter, system-ui, sans-serif" : "Inter, system-ui, sans-serif";
1243
+ ctx.font = `500 ${fontSize}px "${fontFamily}"`;
1244
+ ctx.fillStyle = textColor;
1245
+ ctx.fillText(key.label, x + w / 2, y + h / 2 + pressOffset);
1239
1246
  };
1240
1247
  const roundRect = (ctx, x, y, w, h, r) => {
1241
1248
  if (w < 2 * r)
@@ -1270,7 +1277,11 @@ function VirtualKeypad({
1270
1277
  }
1271
1278
  const width = rect.width;
1272
1279
  const height = rect.height;
1273
- ctx.fillStyle = "#d1d5db";
1280
+ const bgColors = {
1281
+ dark: "#0f172a",
1282
+ light: "#e2e8f0"
1283
+ };
1284
+ ctx.fillStyle = bgColors[theme] || bgColors.light;
1274
1285
  ctx.fillRect(0, 0, width, height);
1275
1286
  const scale = viewport.scale;
1276
1287
  keyBoundsRef.current.forEach((key) => {
@@ -1283,9 +1294,9 @@ function VirtualKeypad({
1283
1294
  }
1284
1295
  }
1285
1296
  const isActiveModifier = key.value === "Shift" && shift || key.value === "HangulMode" && hangulMode;
1286
- drawKey(ctx, key, isPressed, isActiveModifier, scale);
1297
+ drawKey(ctx, key, isPressed, isActiveModifier, scale, theme);
1287
1298
  });
1288
- }, [calculateLayout, hangulMode, shift, viewport.scale, activePresses, keyBoundsRef]);
1299
+ }, [calculateLayout, hangulMode, shift, viewport.scale, activePresses, keyBoundsRef, theme]);
1289
1300
  useEffect4(() => {
1290
1301
  keyBoundsRef.current = [];
1291
1302
  }, [hangulMode, shift, keyBoundsRef]);
@@ -1325,7 +1336,7 @@ function VirtualKeypad({
1325
1336
  css: `
1326
1337
  .keypad-wrapper {
1327
1338
  position: fixed;
1328
- background-color: #d1d5db;
1339
+ background-color: var(--keypad-bg);
1329
1340
  border-radius: calc(18px / var(--scale-factor));
1330
1341
  box-shadow: 0 calc(-6px / var(--scale-factor)) calc(30px / var(--scale-factor)) rgba(15, 23, 42, 0.2);
1331
1342
  user-select: none;
@@ -1362,7 +1373,8 @@ function VirtualKeypad({
1362
1373
  width: viewport.width,
1363
1374
  top: Math.round(viewport.offsetTop + viewport.height - 200 / viewport.scale),
1364
1375
  height: Math.round(200 / viewport.scale),
1365
- "--scale-factor": viewport.scale
1376
+ "--scale-factor": viewport.scale,
1377
+ "--keypad-bg": theme === "dark" ? "#0f172a" : "#e2e8f0"
1366
1378
  },
1367
1379
  children: /* @__PURE__ */ jsxDEV3("canvas", {
1368
1380
  ref: canvasRef,
@@ -1536,21 +1548,49 @@ var useVisualViewport = () => {
1536
1548
  return viewport;
1537
1549
  };
1538
1550
 
1551
+ // src/hooks/useSystemTheme.ts
1552
+ import { useState as useState5, useEffect as useEffect7 } from "react";
1553
+ function useSystemTheme() {
1554
+ const [theme, setTheme] = useState5(() => {
1555
+ if (typeof window !== "undefined" && window.matchMedia) {
1556
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
1557
+ }
1558
+ return "light";
1559
+ });
1560
+ useEffect7(() => {
1561
+ if (typeof window === "undefined" || !window.matchMedia)
1562
+ return;
1563
+ const mq = window.matchMedia("(prefers-color-scheme: dark)");
1564
+ const handler = (e) => {
1565
+ setTheme(e.matches ? "dark" : "light");
1566
+ };
1567
+ mq.addEventListener("change", handler);
1568
+ return () => mq.removeEventListener("change", handler);
1569
+ }, []);
1570
+ return theme;
1571
+ }
1572
+
1539
1573
  // src/components/Provider.tsx
1540
1574
  import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
1541
1575
  function VirtualInputProvider({
1542
1576
  children,
1543
1577
  layout = qwerty_default,
1544
- defaultHangulMode = true
1578
+ defaultHangulMode = true,
1579
+ theme
1545
1580
  }) {
1546
1581
  const inputRef = useRef5(null);
1547
1582
  const sti = useRef5(setTimeout(() => null, 0));
1548
1583
  const isCompositionRef = useRef5(undefined);
1549
- const [focusId, setFocusId] = useState5();
1550
- const [shift, setShift] = useState5(false);
1584
+ const [focusId, setFocusId] = useState6();
1585
+ const [shift, setShift] = useState6(false);
1551
1586
  const [hangulMode, setHangulMode] = useStorage("virtual-keyboard-hangul-mode", defaultHangulMode);
1552
1587
  const viewport = useVisualViewport();
1553
- useEffect7(() => {
1588
+ const systemTheme = useSystemTheme();
1589
+ const effectiveTheme = theme ?? systemTheme;
1590
+ useEffect8(() => {
1591
+ console.log("[Provider] Theme Debug:", { prop: theme, system: systemTheme, effective: effectiveTheme });
1592
+ }, [theme, systemTheme, effectiveTheme]);
1593
+ useEffect8(() => {
1554
1594
  if (focusId) {
1555
1595
  document.body.style.paddingBottom = `${Math.round(200 / viewport.scale)}px`;
1556
1596
  } else {
@@ -1589,16 +1629,17 @@ function VirtualInputProvider({
1589
1629
  }, [setHangulMode]);
1590
1630
  return /* @__PURE__ */ jsxDEV4(VirtualInputContext.Provider, {
1591
1631
  value: {
1592
- inputRef,
1593
- isCompositionRef,
1594
- onFocus,
1595
- onBlur,
1596
1632
  focusId,
1597
- setHangulMode,
1598
1633
  hangulMode,
1599
1634
  shift,
1635
+ theme: effectiveTheme,
1636
+ onFocus,
1637
+ onBlur,
1638
+ setHangulMode,
1600
1639
  toggleShift,
1601
- toggleKorean
1640
+ toggleKorean,
1641
+ isCompositionRef,
1642
+ inputRef
1602
1643
  },
1603
1644
  children: [
1604
1645
  children,
@@ -9,6 +9,7 @@ interface VirtualInputContextValue {
9
9
  setHangulMode: Dispatch<SetStateAction<boolean>>;
10
10
  hangulMode: boolean;
11
11
  shift: boolean;
12
+ theme: "light" | "dark";
12
13
  toggleShift: () => void;
13
14
  toggleKorean: () => void;
14
15
  }
@@ -1,7 +1,8 @@
1
1
  import { type ReactNode } from "react";
2
2
  import { type KeypadLayout } from "./Keypad";
3
- export declare function VirtualInputProvider({ children, layout, defaultHangulMode, }: {
3
+ export declare function VirtualInputProvider({ children, layout, defaultHangulMode, theme, }: {
4
4
  layout?: KeypadLayout;
5
5
  children: ReactNode;
6
6
  defaultHangulMode?: boolean;
7
+ theme?: "light" | "dark";
7
8
  }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export declare function useSystemTheme(): "dark" | "light";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiwwsw/virtual-keyboard",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "type": "module",
5
5
  "types": "dist/types/index.d.ts",
6
6
  "main": "dist/index.js",