react-flick-keyboard 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 jarry3369
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # React Flick Keyboard
2
+
3
+ A reusable, accessible, and customizable Japanese Flick Keyboard component for React.
4
+
5
+ ## Features
6
+
7
+ - 🧠 **Headless Architecture**: Use `useFlickKeyboard` to build your own UI.
8
+ - 📱 **Touch & Mouse Support**: Works seamlessly on mobile and desktop.
9
+ - ⌨️ **Standard Layout**: Implements the standard 10-key Japanese flick layout.
10
+ - 🎨 **Optional UI**: Ready-to-use Tailwind styled components included.
11
+ - 🔄 **Flick & Toggle**: Supports both flick gestures and toggle (multi-tap) input.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install react-flick-keyboard
17
+ # or
18
+ yarn add react-flick-keyboard
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ### 1. Default UI (Easy Mode)
24
+
25
+ Import the styles and the component:
26
+
27
+ ```tsx
28
+ import { useState } from 'react';
29
+ import { FlickKeyboard } from 'react-flick-keyboard';
30
+ import 'react-flick-keyboard/dist/style.css'; // Import styles
31
+
32
+ function App() {
33
+ const [text, setText] = useState('');
34
+
35
+ const handleInput = (char: string) => {
36
+ setText((prev) => prev + char);
37
+ };
38
+
39
+ return (
40
+ <div className="p-4">
41
+ <input value={text} readOnly />
42
+ <FlickKeyboard
43
+ onInput={handleInput}
44
+ currentInput={text.slice(-1)}
45
+ />
46
+ </div>
47
+ );
48
+ }
49
+ ```
50
+
51
+ ### 2. Headless Mode (Custom UI)
52
+
53
+ Use the `useFlickKeyboard` hook to build your own interface.
54
+
55
+ ```tsx
56
+ import { useFlickKeyboard, FLICK_KEYBOARD_LAYOUT } from 'react-flick-keyboard';
57
+
58
+ function CustomKeyboard() {
59
+ const {
60
+ handleCharInput,
61
+ handleModifier
62
+ } = useFlickKeyboard({
63
+ onInput: (char) => console.log(char),
64
+ });
65
+
66
+ return (
67
+ <div>
68
+ {/* Build your own grid */}
69
+ <button onClick={() => handleCharInput('あ', 'a', true)}>あ</button>
70
+ {/* ... */}
71
+ </div>
72
+ );
73
+ }
74
+ ```
75
+
76
+ ## Development
77
+
78
+ 1. Install dependencies:
79
+ ```bash
80
+ npm install
81
+ ```
82
+
83
+ 2. Start dev server:
84
+ ```bash
85
+ npm run dev
86
+ ```
87
+
88
+ 3. Build library:
89
+ ```bash
90
+ npm run build
91
+ ```
92
+
93
+ ## License
94
+
95
+ MIT
@@ -0,0 +1,14 @@
1
+ import { FlickDirection } from '../types';
2
+
3
+ export interface FlickKeyboardProps {
4
+ onInput: (character: string) => void;
5
+ onReplace?: (oldChar: string, newChar: string) => void;
6
+ disabled?: boolean;
7
+ hintTarget?: {
8
+ key: string;
9
+ direction: FlickDirection;
10
+ } | null;
11
+ hintModifier?: boolean;
12
+ currentInput?: string;
13
+ }
14
+ export declare function FlickKeyboard({ onInput, onReplace, disabled, hintTarget, hintModifier, currentInput, }: FlickKeyboardProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,19 @@
1
+ import { FlickDirection, HiraganaKey } from '../types';
2
+
3
+ interface GlobalFlickGuideProps {
4
+ keyName: string;
5
+ hiraganaKey: HiraganaKey;
6
+ position: {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ direction: FlickDirection;
11
+ isModifier?: boolean;
12
+ lastChar?: string;
13
+ hintTarget?: {
14
+ key: string;
15
+ direction: FlickDirection;
16
+ } | null;
17
+ }
18
+ export declare function GlobalFlickGuide({ keyName, hiraganaKey, position, direction: currentDirection, isModifier, hintTarget, }: GlobalFlickGuideProps): import("react/jsx-runtime").JSX.Element;
19
+ export {};
@@ -0,0 +1,26 @@
1
+ import { FlickDirection, HiraganaKey } from '../types';
2
+
3
+ export interface ActiveGuideState {
4
+ keyName: string;
5
+ hiraganaKey: HiraganaKey;
6
+ position: {
7
+ x: number;
8
+ y: number;
9
+ };
10
+ direction: FlickDirection;
11
+ isModifier?: boolean;
12
+ lastChar?: string;
13
+ }
14
+ interface KeyButtonProps {
15
+ keyName: string;
16
+ hiraganaKey: HiraganaKey;
17
+ onInput: (character: string, keyName: string, isToggleable: boolean) => void;
18
+ disabled: boolean;
19
+ onGuideUpdate: (state: ActiveGuideState | null) => void;
20
+ hintTarget?: {
21
+ key: string;
22
+ direction: FlickDirection;
23
+ } | null;
24
+ }
25
+ export declare function KeyButton({ keyName, hiraganaKey, onInput, disabled, onGuideUpdate, hintTarget, }: KeyButtonProps): import("react/jsx-runtime").JSX.Element;
26
+ export {};
@@ -0,0 +1,9 @@
1
+ interface ModifierKeyProps {
2
+ onModifier: () => void;
3
+ disabled: boolean;
4
+ lastChar: string;
5
+ isHint?: boolean;
6
+ }
7
+ export declare function ModifierKey({ onModifier, disabled, lastChar: _lastChar, // Kept for API compatibility
8
+ isHint, }: ModifierKeyProps): import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,32 @@
1
+ import { FlickDirection, HiraganaKey } from '../types';
2
+
3
+ export interface UseFlickKeyboardProps {
4
+ onInput: (character: string) => void;
5
+ onReplace?: (oldChar: string, newChar: string) => void;
6
+ disabled?: boolean;
7
+ currentInput?: string;
8
+ }
9
+ export interface ToggleState {
10
+ keyName: string;
11
+ index: number;
12
+ timestamp: number;
13
+ }
14
+ export interface ActiveGuideState {
15
+ keyName: string;
16
+ hiraganaKey: HiraganaKey;
17
+ position: {
18
+ x: number;
19
+ y: number;
20
+ };
21
+ direction: FlickDirection;
22
+ isModifier?: boolean;
23
+ lastChar?: string;
24
+ }
25
+ export declare function useFlickKeyboard({ onInput, onReplace, disabled, currentInput, }: UseFlickKeyboardProps): {
26
+ lastChar: string;
27
+ activeGuide: ActiveGuideState | null;
28
+ setActiveGuide: import('react').Dispatch<import('react').SetStateAction<ActiveGuideState | null>>;
29
+ toggleState: ToggleState | null;
30
+ handleCharInput: (character: string, keyName: string, isToggleable: boolean) => void;
31
+ handleModifier: () => void;
32
+ };
@@ -0,0 +1,20 @@
1
+ import { FlickDirection } from '../types';
2
+
3
+ export declare function useFlickDetection(): {
4
+ isPressed: boolean;
5
+ currentDirection: FlickDirection;
6
+ touchHandlers: {
7
+ onTouchStart: (event: React.TouchEvent) => void;
8
+ onTouchMove: (event: React.TouchEvent) => void;
9
+ onTouchEnd: (onFlick?: (direction: FlickDirection) => void) => (event: React.TouchEvent) => void;
10
+ };
11
+ mouseHandlers: {
12
+ onMouseDown: (event: React.MouseEvent) => void;
13
+ onMouseMove: (event: React.MouseEvent) => void;
14
+ onMouseUp: (onFlick?: (direction: FlickDirection) => void) => (event: React.MouseEvent) => void;
15
+ };
16
+ };
17
+ export declare function getDirectionOffset(direction: FlickDirection, distance?: number): {
18
+ x: number;
19
+ y: number;
20
+ };
@@ -0,0 +1,10 @@
1
+
2
+ export { useFlickKeyboard } from './core/useFlickKeyboard';
3
+ export type { UseFlickKeyboardProps, ToggleState, ActiveGuideState } from './core/useFlickKeyboard';
4
+ export { FlickKeyboard } from './components/FlickKeyboard';
5
+ export { KeyButton } from './components/KeyButton';
6
+ export { ModifierKey } from './components/ModifierKey';
7
+ export { GlobalFlickGuide } from './components/GlobalFlickGuide';
8
+ export { useFlickDetection } from './hooks/useFlickDetection';
9
+ export * from './types';
10
+ export * from './utils/hiragana-data';