@tdh-keyboard/react 1.0.0

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,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 dusionlike
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,278 @@
1
+ # 中文键盘 React 组件库
2
+
3
+ 这是一个 React 的中文键盘组件库,支持拼音输入和手写输入。
4
+
5
+ ## 功能特点
6
+
7
+ - 🔌 即插即用,自动绑定输入框
8
+ - ✨ 支持拼音输入,带候选词选择功能
9
+ - ✏️ 支持手写输入识别,支持连笔和简写
10
+ - 🔧 可自定义手写识别算法
11
+ - 📏 键盘大小可自定义缩放,灵活适配各种界面布局
12
+ - 🌐 纯前端实现,可作为静态网页部署,无需服务端支持
13
+
14
+ ## 安装
15
+
16
+ ```bash
17
+ npm install @tdh-keyboard/react
18
+ # 或者
19
+ yarn add @tdh-keyboard/react
20
+ # 或者
21
+ pnpm add @tdh-keyboard/react
22
+ ```
23
+
24
+ ## 属性
25
+
26
+ ### Props
27
+
28
+ | 属性名 | 类型 | 默认值 | 说明 |
29
+ | --------------- | --------------------------------- | -------- | ---------------------------------- |
30
+ | defaultMode | 'en' \| 'zh' \| 'hand' \| 'num' | 'en' | 默认的键盘模式 |
31
+ | enableHandwriting| boolean | false | 是否启用手写输入 |
32
+ | position | 'static' \| 'float' \| 'bottom' | 'static' | 键盘定位模式 |
33
+ | floatMarginTop | number | 0 | 浮动模式下键盘与输入框的距离 |
34
+ | disableWhenNoFocus | boolean | true | 当没有输入框获得焦点时是否禁用键盘 |
35
+ | manual | boolean | false | 是否启用手动打开模式 |
36
+ | numKeys | string[][] | - | 数字键盘的行配置 |
37
+
38
+ ### 事件
39
+
40
+ | 事件名 | 参数类型 | 说明 |
41
+ | ------ | -------- | ---- |
42
+ | onKey | KeyEvent | 当用户在键盘上点击按键时触发 |
43
+
44
+ ## 基本使用
45
+
46
+ ### 全局配置
47
+
48
+ 可以在项目入口文件中设置全局配置:
49
+
50
+ ```typescript
51
+ import { setKeyboardConfig } from '@tdh-keyboard/react'
52
+
53
+ setKeyboardConfig({
54
+ defaultMode: 'zh',
55
+ enableHandwriting: true,
56
+ position: 'float'
57
+ })
58
+ ```
59
+
60
+ ### 基础用法
61
+
62
+ - 为了防止移动端设备弹出系统默认的键盘,建议在输入框上设置 `inputMode="none"` 属性。
63
+ - 此外,可以通过在输入框上设置 `data-inputmode` 属性来指定组件默认打开的键盘类型 (可选值为 `'en'`, `'zh'`, `'hand'`, `'num'`),具体键盘模式的说明请参考 `defaultMode` 属性。
64
+
65
+ ```tsx
66
+ import { TdhKeyboard } from '@tdh-keyboard/react'
67
+ import { useState } from 'react'
68
+ import '@tdh-keyboard/react/style.css'
69
+
70
+ function App() {
71
+ const [inputText, setInputText] = useState('')
72
+
73
+ return (
74
+ <div>
75
+ <input
76
+ value={inputText}
77
+ onChange={e => setInputText(e.target.value)}
78
+ data-inputmode="en_cap"
79
+ inputMode="none"
80
+ placeholder="点击使用键盘输入"
81
+ />
82
+
83
+ {/* 静态定位的键盘 */}
84
+ <TdhKeyboard />
85
+
86
+ {/* 浮动定位的键盘(跟随输入框) */}
87
+ <TdhKeyboard position="float" />
88
+
89
+ {/* 底部固定的键盘 */}
90
+ <TdhKeyboard position="bottom" />
91
+
92
+ {/* 启用手写输入的键盘 */}
93
+ <TdhKeyboard enableHandwriting={true} />
94
+
95
+ {/* 数字键盘 */}
96
+ <TdhKeyboard defaultMode="num" />
97
+ </div>
98
+ )
99
+ }
100
+
101
+ export default App
102
+ ```
103
+
104
+ ### 手动打开模式
105
+
106
+ 设置 `manual` 后,键盘不会再根据输入框焦点自动显示,需要通过 `ref` 手动控制:
107
+
108
+ ```tsx
109
+ import type { KeyboardInstance } from '@tdh-keyboard/react'
110
+ import { TdhKeyboard } from '@tdh-keyboard/react'
111
+ import { useRef } from 'react'
112
+
113
+ function App() {
114
+ const keyboardRef = useRef<KeyboardInstance>(null)
115
+ const inputRef = useRef<HTMLInputElement>(null)
116
+
117
+ return (
118
+ <>
119
+ <input ref={inputRef} inputMode="none" />
120
+ <button onClick={() => keyboardRef.current?.open(inputRef.current)}>打开键盘</button>
121
+ <button onClick={() => keyboardRef.current?.close()}>关闭键盘</button>
122
+ <button onClick={() => keyboardRef.current?.destroy()}>销毁键盘</button>
123
+ <TdhKeyboard ref={keyboardRef} manual position="bottom" />
124
+ </>
125
+ )
126
+ }
127
+ ```
128
+
129
+ 实例方法说明:
130
+
131
+ - `open(target?)`:打开键盘,可选传入当前要写入的 `input` / `textarea`
132
+ - `close()`:关闭键盘
133
+ - `destroy()`:销毁当前键盘状态并清空绑定的输入框
134
+
135
+ ## 拼音引擎初始化
136
+
137
+ ### 使用 RIME WASM 拼音引擎
138
+
139
+ 拼音输入功能需要初始化拼音引擎。推荐使用基于 RIME WASM 的拼音引擎:
140
+
141
+ ```typescript
142
+ import { createRimePinyinEngine } from '@tdh-keyboard/pinyin'
143
+ import { registerPinyinEngine } from '@tdh-keyboard/react'
144
+
145
+ // 注册 RIME 拼音引擎
146
+ registerPinyinEngine(new RimePinyinEngine({
147
+ wasmDir: '/data',
148
+ }))
149
+ ```
150
+
151
+ worker写法参考 `examples`。
152
+
153
+ ### WASM 文件部署
154
+
155
+ 需要将以下文件发布到 `public/data/` 目录:
156
+
157
+ - `rime-api.wasm` - RIME 引擎本体
158
+ - `default.yaml` - 默认配置
159
+ - `luna_pinyin.schema.yaml` - 拼音方案
160
+ - `luna_pinyin.table.bin` 、`luna_pinyin.prism.bin` 、`luna_pinyin.reverse.bin` - 词典文件
161
+
162
+ 这些文件来自 `@tdh-keyboard/pinyin` 包的 `data/` 目录。
163
+ ```
164
+
165
+ ## 输入模式
166
+
167
+ ### 拼音输入模式 (zh)
168
+
169
+ 拼音输入模式支持单字拼音输入,具有以下特性:
170
+
171
+ - 支持单字模糊拼音匹配
172
+ - 使用内置词库进行单字匹配
173
+ - 支持中英文快速切换
174
+
175
+ > 注:目前仅支持单个汉字的拼音输入,连续词组输入功能正在开发中
176
+
177
+ ### 英文输入模式 (en)
178
+
179
+ 标准的英文键盘布局,支持英文字母、数字和常用符号的输入。
180
+
181
+ ### 手写输入模式 (hand)
182
+
183
+ 手写输入模式允许用户通过手写输入汉字,启用此模式需要设置 `enableHandwriting` 为 `true`。
184
+
185
+ ### 数字输入模式 (num)
186
+
187
+ 数字输入模式提供一个数字和小数点键盘,方便用户输入数字、金额等。
188
+
189
+ ## 手写识别
190
+
191
+ 组件库支持自定义手写识别服务。您可以注册自己的手写识别服务来处理用户的手写输入。
192
+
193
+ ### 手写识别接口
194
+
195
+ 手写识别服务需要实现以下接口:
196
+
197
+ ```typescript
198
+ interface HandwritingRecognizer {
199
+ /**
200
+ * 初始化手写识别服务
201
+ * @returns 返回是否初始化成功
202
+ */
203
+ initialize(): Promise<boolean>
204
+
205
+ /**
206
+ * 识别手写笔迹
207
+ * @param strokeData 笔迹数据,格式为 x y c x y c ...,其中x和y是坐标,c表示是否为笔画的最后一点(1表示是,0表示否)
208
+ * @returns 识别结果列表
209
+ */
210
+ recognize(strokeData: number[]): Promise<string[]>
211
+
212
+ /**
213
+ * 关闭手写识别服务
214
+ */
215
+ close(): Promise<void>
216
+ }
217
+ ```
218
+
219
+ ### 笔迹数据格式
220
+
221
+ 笔迹数据以数组形式存储,格式为 `[x1, y1, c1, x2, y2, c2, ...]`,其中:
222
+ - `x`、`y` 是坐标点
223
+ - `c` 表示是否为笔画的最后一点:1表示是最后一点,0表示不是
224
+
225
+ 例如,一个简单的笔画可能是:`[100, 150, 0, 101, 151, 0, 102, 152, 1]`,表示三个点的笔画,最后一个点是笔画的结束点。
226
+
227
+ ### 注册手写识别服务
228
+
229
+ ```typescript
230
+ import { registerHandwritingRecognizer } from '@tdh-keyboard/react'
231
+ import { MyHandwritingRecognizer } from './MyHandwritingRecognizer'
232
+
233
+ // 创建并注册您的手写识别服务
234
+ const recognizer = new MyHandwritingRecognizer()
235
+ registerHandwritingRecognizer(recognizer)
236
+ ```
237
+
238
+ ### 示例实现
239
+
240
+ 以下是一个简单的手写识别服务示例实现:
241
+
242
+ ```typescript
243
+ import type { HandwritingRecognizer } from '@tdh-keyboard/react'
244
+
245
+ export class MyHandwritingRecognizer implements HandwritingRecognizer {
246
+ private initialized = false
247
+
248
+ async initialize(): Promise<boolean> {
249
+ console.log('初始化手写识别服务...')
250
+ // 在实际应用中,这里可能需要加载模型或连接到服务器
251
+ this.initialized = true
252
+ return true
253
+ }
254
+
255
+ async recognize(strokeData: number[]): Promise<string[]> {
256
+ if (!this.initialized) {
257
+ throw new Error('手写识别服务未初始化')
258
+ }
259
+
260
+ console.log('识别笔迹数据:', strokeData)
261
+
262
+ // 这里调用您的手写识别API
263
+ // 返回识别结果
264
+ return ['你', '我', '他', '好', '的']
265
+ }
266
+
267
+ async close(): Promise<void> {
268
+ console.log('关闭手写识别服务')
269
+ this.initialized = false
270
+ }
271
+ }
272
+ ```
273
+
274
+ ## 生命周期
275
+
276
+ 1. 当手写输入组件挂载时,会自动调用手写识别服务的 `initialize()` 方法
277
+ 2. 当用户完成一个笔画时,会调用 `recognize()` 方法进行识别
278
+ 3. 当手写输入组件卸载时,会调用 `close()` 方法关闭手写识别服务
package/dist/App.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare function App(): import("react/jsx-runtime").JSX.Element;
2
+ export default App;
@@ -0,0 +1,12 @@
1
+ import { KeyEvent } from '../types';
2
+ interface CandidateBarProps {
3
+ currentPinyin: string;
4
+ onKey: (payload: KeyEvent) => void;
5
+ onInput: (text: string) => void;
6
+ setCurrentPinyin: (pinyin: string) => void;
7
+ }
8
+ export interface CandidateBarRef {
9
+ handleSelection: (globalIndex: number) => Promise<void>;
10
+ }
11
+ declare const CandidateBar: import('react').ForwardRefExoticComponent<CandidateBarProps & import('react').RefAttributes<CandidateBarRef>>;
12
+ export default CandidateBar;
@@ -0,0 +1,7 @@
1
+ import { default as React } from 'react';
2
+ interface CandidateListProps {
3
+ candidates: string[];
4
+ onSelect: (index: number) => void;
5
+ }
6
+ declare const CandidateList: React.FC<CandidateListProps>;
7
+ export default CandidateList;
@@ -0,0 +1,8 @@
1
+ import { default as React } from 'react';
2
+ interface CandidateSelectionProps {
3
+ candidates: string[];
4
+ onSelect: (index: number) => void;
5
+ onClose: () => void;
6
+ }
7
+ declare const CandidateSelection: React.FC<CandidateSelectionProps>;
8
+ export default CandidateSelection;
@@ -0,0 +1,12 @@
1
+ import { KeyEvent } from '../types';
2
+ import { default as React } from 'react';
3
+ interface HandwritingInputProps {
4
+ recognizerInitialized: boolean;
5
+ recognizerProgress: number;
6
+ onKey: (payload: KeyEvent) => void;
7
+ onCollapse: () => void;
8
+ onSwitchToSymbol: () => void;
9
+ onToggleKeyboard: () => void;
10
+ }
11
+ declare const HandwritingInput: React.FC<HandwritingInputProps>;
12
+ export default HandwritingInput;
@@ -0,0 +1,14 @@
1
+ import { KeyBoardMode, KeyEvent } from '../types';
2
+ import { default as React } from 'react';
3
+ interface KeyboardBaseProps {
4
+ enableHandwriting?: boolean;
5
+ capsReturnToChinese: boolean;
6
+ mode: KeyBoardMode;
7
+ onKey: (payload: KeyEvent) => void;
8
+ onCollapse: () => void;
9
+ onToggleKeyboard: () => void;
10
+ setCapsReturnToChinese: (value: boolean) => void;
11
+ setMode: (mode: KeyBoardMode) => void;
12
+ }
13
+ declare const KeyboardBase: React.FC<KeyboardBaseProps>;
14
+ export default KeyboardBase;
@@ -0,0 +1,9 @@
1
+ import { default as React } from 'react';
2
+ interface KeyboardToolbarProps {
3
+ enableHandwriting?: boolean;
4
+ isHandwritingMode?: boolean;
5
+ onToggleKeyboard: () => void;
6
+ onCollapse: () => void;
7
+ }
8
+ declare const KeyboardToolbar: React.FC<KeyboardToolbarProps>;
9
+ export default KeyboardToolbar;
@@ -0,0 +1,9 @@
1
+ import { KeyEvent } from '../types';
2
+ import { default as React } from 'react';
3
+ interface NumericKeyboardProps {
4
+ onKey: (payload: KeyEvent) => void;
5
+ onExit: () => void;
6
+ keyboardRows?: string[][];
7
+ }
8
+ declare const NumericKeyboard: React.FC<NumericKeyboardProps>;
9
+ export default NumericKeyboard;
@@ -0,0 +1,8 @@
1
+ import { KeyEvent } from '../types';
2
+ import { default as React } from 'react';
3
+ interface SymbolKeyboardProps {
4
+ onKey: (payload: KeyEvent) => void;
5
+ onExit: () => void;
6
+ }
7
+ declare const SymbolKeyboard: React.FC<SymbolKeyboardProps>;
8
+ export default SymbolKeyboard;
@@ -0,0 +1,16 @@
1
+ import { KeyBoardMode, KeyEvent, KeyboardInstance } from '../types';
2
+ import { default as React } from 'react';
3
+ export interface TdhKeyboardProps {
4
+ defaultMode?: KeyBoardMode;
5
+ enableHandwriting?: boolean;
6
+ position?: 'static' | 'float' | 'bottom';
7
+ floatMarginTop?: number;
8
+ disableWhenNoFocus?: boolean;
9
+ manual?: boolean;
10
+ onKey?: (payload: KeyEvent) => void;
11
+ className?: string;
12
+ style?: React.CSSProperties;
13
+ numKeys?: string[][];
14
+ }
15
+ declare const TdhKeyboard: React.ForwardRefExoticComponent<TdhKeyboardProps & React.RefAttributes<KeyboardInstance>>;
16
+ export default TdhKeyboard;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * React hook for tracking `document.activeElement`
3
+ *
4
+ * @returns 当前激活的元素
5
+ */
6
+ export declare function useActiveElement<T extends HTMLElement>(): T | null | undefined;
@@ -0,0 +1 @@
1
+ export declare function useInit(fn: () => void): void;
@@ -0,0 +1,5 @@
1
+ import { default as React } from 'react';
2
+ export declare function useKeyRepeater(): {
3
+ startRepeat: (e: React.PointerEvent, action: () => void) => void;
4
+ stopRepeat: () => void;
5
+ };
package/dist/lib.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { default as TdhKeyboard } from './components/TdhKeyboard';
2
+ export * from '@tdh-keyboard/core';
3
+ export type * from './types';
4
+ export { TdhKeyboard };
5
+ export default TdhKeyboard;
package/dist/main.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/style.css ADDED
@@ -0,0 +1,2 @@
1
+ .tdhk-candidate-list{gap:var(--gap);scroll-behavior:smooth;scrollbar-width:none;-ms-overflow-style:none;flex:1;min-width:0;display:flex;overflow-x:auto}.tdhk-candidate-list::-webkit-scrollbar{display:none}.tdhk-candidate-list__item{font-size:var(--candidate-font-size);min-width:var(--candidate-font-size);padding:0 calc(var(--candidate-font-size) * .35);color:var(--key-text-color,#333);cursor:pointer;white-space:nowrap;background-color:#0000;border:none;border-radius:4px;flex-shrink:0;justify-content:center;align-items:center;transition:all .1s;display:flex}.tdhk-candidate-list__item:first-child{color:var(--primary-color,#0076f5);font-weight:500}.tdhk-candidate-list__item:hover{background-color:#0000000d}.tdhk-toolbar{align-items:center;gap:clamp(8px, var(--keyboard-height) / 18, 18px);width:100%;min-height:100%;padding:0 clamp(8px, var(--keyboard-height) / 18, 18px);border-radius:calc(var(--key-border-radius,6px) * 1.5);background-color:var(--background-color,#f7f8f9);box-sizing:border-box;display:flex}.tdhk-toolbar__button{color:#5e6773;width:clamp(34px, var(--keyboard-header-height) * .9, 46px);height:clamp(26px, var(--keyboard-header-height) * .72, 34px);cursor:pointer;background:0 0;border:none;border-radius:12px;justify-content:center;align-items:center;padding:0;transition:background-color .12s,transform .12s,opacity .12s;display:inline-flex}.tdhk-toolbar__button:hover{background-color:#5e677314}.tdhk-toolbar__button:active{background-color:#5e67731f;transform:translateY(1px)}.tdhk-toolbar__button:disabled{cursor:not-allowed;opacity:.45;background-color:#0000;transform:none}.tdhk-toolbar__button--collapse{width:clamp(40px, var(--keyboard-header-height) * 1.05, 50px)}.tdhk-toolbar__icon{width:clamp(20px, var(--keyboard-header-height) * .5, 26px);height:clamp(20px, var(--keyboard-header-height) * .5, 26px);object-fit:contain;display:block}.tdhk-toolbar__spacer{flex:1}.tdhk-toolbar__divider{background:linear-gradient(#c4cad200 0%,#c4cad2e6 50%,#c4cad200 100%);align-self:stretch;width:1px;margin:4px 0}.handwriting-input{background:var(--background-color,#f5f5f5);height:100%;padding:var(--gap);gap:var(--keyboard-stack-gap);box-sizing:border-box;flex-direction:column;display:flex}.handwriting-input__header{flex:0 0 var(--keyboard-header-height);height:var(--keyboard-header-height);min-height:var(--keyboard-header-height);display:flex;overflow:hidden}.handwriting-input__candidates{box-sizing:border-box;background-color:var(--background-color,#f7f8f9);border-radius:calc(var(--key-border-radius,6px) * 1.5);flex:1;align-items:center;min-width:0;height:100%;padding:0 8px;display:flex;overflow:hidden}.handwriting-input .handwriting-content{flex:1 0 var(--keyboard-body-min-height);justify-content:center;align-items:flex-start;gap:var(--gap);flex-flow:row;min-height:0;display:flex;overflow:hidden}.handwriting-input .handwriting-canvas-container{background:#fff;flex:4;justify-content:center;align-items:center;height:100%;font-size:0;display:flex}.handwriting-input .handwriting-canvas-container .handwriting-loading{width:100%;height:100%;padding:calc(var(--gap) * 2);box-sizing:border-box;flex-direction:column;justify-content:center;align-items:center;display:flex}.handwriting-input .handwriting-canvas-container .handwriting-loading .loading-text{color:var(--text-color,#333);margin-bottom:calc(var(--gap) * 2);text-align:center;font-size:16px}.handwriting-input .handwriting-canvas-container .handwriting-loading .progress-bar{background-color:var(--border-color,#dcdcdc);width:80%;height:8px;margin-bottom:var(--gap);border-radius:4px;overflow:hidden}.handwriting-input .handwriting-canvas-container .handwriting-loading .progress-bar .progress-fill{background-color:var(--primary-color,#007bff);border-radius:4px;height:100%;transition:width .3s}.handwriting-input .handwriting-canvas-container .handwriting-loading .progress-text{color:var(--text-color,#666);font-size:14px;font-weight:500}.handwriting-input .handwriting-canvas{touch-action:none;width:100%;height:100%;display:block}.handwriting-input .handwriting-buttons{justify-content:space-between;gap:var(--gap);max-width:calc(var(--keyboard-height) / 4);flex-direction:column;flex:1;height:100%;display:flex}.handwriting-input .handwriting-btn{padding:var(--gap);border:1px solid var(--border-color,#d1d5da);border-radius:var(--key-border-radius,6px);background-color:var(--function-key-color,#e4e7ea);box-shadow:var(--key-shadow,0 1px 2px #0000001a);cursor:pointer;white-space:nowrap;width:100%;font-size:var(--key-font-size);color:#555;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;touch-action:manipulation;flex:1;justify-content:center;align-items:center;font-weight:500;transition:all .12s;display:flex}.handwriting-input .handwriting-btn:hover{filter:brightness(98%)}.handwriting-input .handwriting-btn:active{box-shadow:var(--key-active-shadow,0 0px 1px #0000000d);background-color:#cdd3d8;transform:translateY(1px)}.handwriting-input .handwriting-btn--function img{width:calc(1em * var(--key-icon-scale,1.15));height:calc(1em * var(--key-icon-scale,1.15));object-fit:contain;flex-shrink:0}.tdhk-selection{z-index:2;width:100%;height:100%;padding:var(--gap);justify-content:center;align-items:flex-start;gap:var(--gap);box-sizing:border-box;background:#f5f5f5;flex-wrap:nowrap;display:flex;position:absolute;top:0;left:0}.tdhk-selection__list{grid-template-columns:repeat(auto-fit, minmax(calc(var(--keyboard-height) / 7), 1fr));background-color:var(--key-background-color,#fff);border-radius:8px;flex:5;min-width:0;max-height:100%;display:grid;overflow:hidden auto;box-shadow:0 1px 4px #0000000d}.tdhk-selection__list::-webkit-scrollbar{width:4px}.tdhk-selection__list::-webkit-scrollbar-thumb{background-color:var(--border-color,#d1d5da);border-radius:2px}.tdhk-selection__list::-webkit-scrollbar-track{background-color:#0000}.tdhk-selection__text{font-size:var(--candidate-font-size);border-bottom:1px solid var(--border-color,#f0f0f0);border-right:1px solid var(--border-color,#f0f0f0);color:var(--key-text-color,#333);cursor:pointer;justify-content:center;align-items:center;padding:12px 8px;transition:background-color .12s;display:inline-flex}.tdhk-selection__text:hover{color:var(--primary-color,#0076f5);z-index:1;background-color:#f5f8ff}.tdhk-selection__text--span-2{grid-column:span 2}.tdhk-selection__text--span-3{grid-column:span 3}.tdhk-selection__func{flex:1;justify-content:flex-end;display:flex}.tdhk-selection__func-btn{width:100%;font-size:var(--key-font-size);border:1px solid var(--border-color,#d1d5da);border-radius:var(--key-border-radius,6px);background-color:var(--function-key-color,#e4e7ea);cursor:pointer;color:#555;white-space:nowrap;padding:12px 0;font-weight:500;transition:all .12s;box-shadow:0 1px 2px #0000000d}.tdhk-selection__func-btn:hover{background-color:#dbdfe3}.tdhk-selection__func-btn:active{box-shadow:none;transform:translateY(1px)}.tdhk-candidate{box-sizing:border-box;align-items:center;width:100%;height:100%;display:flex;overflow:hidden}.tdhk-candidate__container{background-color:var(--background-color,#f7f8f9);border-radius:calc(var(--key-border-radius,6px) * 1.5);flex-direction:column;flex:1;width:100%;min-width:0;height:100%;padding:0 8px;display:flex;overflow:hidden}.tdhk-candidate__pinyin{font-size:var(--candidate-pinyin-font-size,14px);color:var(--primary-color,#0076f5);letter-spacing:.5px;box-sizing:border-box;flex:1;align-items:center;padding-left:4px;display:flex}.tdhk-candidate__bottom-container{align-items:center;gap:var(--gap);flex:3;width:100%;display:flex}.tdhk-candidate__more{cursor:pointer;width:clamp(30px, var(--keyboard-header-height) * .62, 38px);background:0 0;border:none;justify-content:center;align-items:center;display:flex}.tdhk-base{height:100%;padding:var(--gap);box-sizing:border-box;flex-direction:column;display:flex}.tdhk-base__row{flex:1 0 var(--keyboard-row-min-height);min-height:var(--keyboard-row-min-height);justify-content:center;gap:var(--gap);margin-bottom:var(--keyboard-stack-gap);display:flex}.tdhk-base__row:last-child{margin-bottom:0}.tdhk-base__row--header{flex:0 0 var(--keyboard-header-height);height:var(--keyboard-header-height);min-height:var(--keyboard-header-height);overflow:hidden}.tdhk-base__key{width:var(--key-width);border:1px solid var(--border-color,#d1d5da);border-radius:var(--key-border-radius,6px);background-color:var(--key-background-color,#fff);min-height:36px;box-shadow:var(--key-shadow,0 1px 2px #0000001a);color:var(--key-text-color,#333);font-size:var(--key-font-size);cursor:pointer;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;touch-action:manipulation;flex:none;justify-content:center;align-items:center;padding:0 5px;transition:all .12s;display:flex}.tdhk-base__key:hover{filter:brightness(98%);border-color:#c3c8cf}.tdhk-base__key:active{box-shadow:var(--key-active-shadow,0 0px 1px #0000000d);background-color:#ebebeb;transform:translateY(1px)}.tdhk-base__key--function{width:var(--key-width);min-width:var(--key-min-width-function);background-color:var(--function-key-color,#e4e7ea);color:#555;flex:none;font-weight:500}.tdhk-base__key--function:active{background-color:#cdd3d8}.tdhk-base__key--shift,.tdhk-base__key--delete{flex:1;width:auto}.tdhk-base__key--space{flex:1;width:auto;min-width:20px}.tdhk-base__key--active{background-color:var(--primary-color,#0076f5);border-color:var(--primary-color,#0076f5);color:#fff}.tdhk-base__key--active:hover{filter:brightness(110%)}.tdhk-base__key--active:active{background-color:#005dc2}.tdhk-base__key--active .tdhk-base__key-icon{filter:brightness(0)invert()}.tdhk-base__key--disabled{background-color:var(--disabled-key-color,#f5f5f5);border-color:var(--disabled-key-border-color,#e0e0e0);color:var(--disabled-key-text-color,#bdbdbd);cursor:not-allowed}.tdhk-base__key--disabled .tdhk-base__key-icon{filter:brightness(.7)}.tdhk-base__key-icon{width:calc(1em * var(--key-icon-scale,1.15));height:calc(1em * var(--key-icon-scale,1.15));vertical-align:middle;object-fit:contain;flex-shrink:0;display:inline-block}.tdhk-base__toggle-main{font-size:max(14px, var(--keyboard-height) / 30)}.tdhk-base__toggle-sub{font-size:max(12px, var(--keyboard-height) / 40);color:var(--toggle-sub-color,#888);margin-left:2px}.num-keyboard{box-sizing:border-box;flex-direction:column;height:100%;padding:8px;display:flex}.num-keyboard__container{gap:8px;height:100%;display:flex}.num-keyboard__left{flex-direction:column;flex:3;display:flex}.num-keyboard__right{flex-direction:column;flex:1;justify-content:space-between;gap:6px;display:flex}.num-keyboard__rows{gap:var(--gap);flex-direction:column;flex:1;display:flex}.num-keyboard__row{gap:var(--gap);flex:1;display:flex}.num-keyboard__key{background-color:var(--key-background-color,#fff);border:1px solid var(--border-color,#d1d5da);border-radius:var(--key-border-radius,6px);box-shadow:var(--key-shadow,0 1px 2px #0000001a);font-size:var(--key-font-size);color:var(--key-text-color,#333);cursor:pointer;flex:1;justify-content:center;align-items:center;font-weight:500;transition:all .12s;display:flex}.num-keyboard__key:hover{filter:brightness(98%)}.num-keyboard__key:active{box-shadow:var(--key-active-shadow,0 0px 1px #0000000d);background-color:#ebebeb;transform:translateY(1px)}.num-keyboard__key--function{background-color:var(--function-key-color,#e4e7ea);height:calc(25% - 6px);font-size:var(--key-font-size);color:#555;font-weight:500}.num-keyboard__key--function:active{background-color:#cdd3d8}.num-keyboard__key--back{font-size:var(--key-font-size);background-color:var(--function-key-color,#e4e7ea)}.num-keyboard__key--back:active{background-color:#cdd3d8}.num-keyboard__key--space{font-size:var(--key-font-size)}.num-keyboard__key-icon{width:calc(1em * var(--key-icon-scale,1.15));height:calc(1em * var(--key-icon-scale,1.15));object-fit:contain;flex-shrink:0;display:inline-block}.symbol-keyboard{--key-size:max(45px, calc(var(--keyboard-height,220px) / 5));--lang-btn-size:var(--key-size);--gap:max(4px, calc(var(--keyboard-height,220px) / 75));--function-width:var(--key-size);--symbol-min-size:calc(var(--key-size) * .85);box-sizing:border-box;flex-direction:column;height:100%;padding:10px;display:flex}.symbol-keyboard__content{gap:var(--gap);flex:1;height:100%;display:flex}.symbol-keyboard__functions{justify-content:space-between;gap:var(--gap);width:var(--function-width);flex-direction:column;display:flex}.symbol-keyboard__lang-selector{height:calc(var(--lang-btn-size) * 2 + var(--gap));flex-direction:column;display:flex}.symbol-keyboard__lang-btn{background-color:var(--key-background-color,#fff);border:1px solid var(--border-color,#d1d5da);font-size:max(12px, var(--key-font-size,1rem) * .8);cursor:pointer;box-sizing:border-box;width:var(--lang-btn-size);flex:1 0;justify-content:center;align-items:center;margin:0;padding:10px 0;transition:all .12s;display:flex}.symbol-keyboard__lang-btn:first-child{border-radius:var(--key-border-radius,6px) var(--key-border-radius,6px) 0 0}.symbol-keyboard__lang-btn:last-child{border-radius:0 0 var(--key-border-radius,6px) var(--key-border-radius,6px);margin-top:-1px}.symbol-keyboard__lang-btn:hover{filter:brightness(98%)}.symbol-keyboard__lang-btn--active{background-color:var(--primary-color,#0076f5);color:#fff;border-color:var(--primary-color,#0076f5);z-index:1;position:relative}.symbol-keyboard__lang-btn--active:hover{filter:brightness(110%)}.symbol-keyboard__control-group{gap:calc(var(--gap) + 2px);flex-direction:column;display:flex}.symbol-keyboard__symbols-container{flex:1;width:100%;height:100%;padding-right:5px;overflow-y:auto}.symbol-keyboard__symbols-container::-webkit-scrollbar{width:4px}.symbol-keyboard__symbols-container::-webkit-scrollbar-track{background:#0000000d;border-radius:2px}.symbol-keyboard__symbols-container::-webkit-scrollbar-thumb{background:#00000026;border-radius:2px}.symbol-keyboard__symbols-container::-webkit-scrollbar-thumb:hover{background:#00000040}.symbol-keyboard__symbols-grid{grid-template-columns:repeat(auto-fit, minmax(var(--symbol-min-size), 1fr));gap:var(--gap);width:100%;max-height:100%;padding-bottom:10px;display:grid}.symbol-keyboard__key{background-color:var(--key-background-color,#fff);border:1px solid var(--border-color,#d1d5da);border-radius:var(--key-border-radius,6px);box-shadow:var(--key-shadow,0 1px 2px #0000001a);font-size:max(18px, var(--key-font-size,1rem));color:var(--key-text-color,#333);cursor:pointer;box-sizing:border-box;min-width:var(--symbol-min-size);max-width:var(--key-size);width:100%;height:var(--key-size);aspect-ratio:1;flex-shrink:0;justify-content:center;align-items:center;margin:0;font-weight:400;transition:all .12s;display:flex}.symbol-keyboard__key:hover{filter:brightness(98%)}.symbol-keyboard__key:active{box-shadow:var(--key-active-shadow,0 0px 1px #0000000d);background-color:#ebebeb;transform:translateY(1px)}.symbol-keyboard__key--function{background-color:var(--function-key-color,#e4e7ea);width:var(--function-width);height:var(--key-size);aspect-ratio:auto;color:#555;font-weight:500}.symbol-keyboard__key--function:active{background-color:#cdd3d8}.symbol-keyboard__key--lock{justify-content:center;align-items:center;padding:10px 0;font-size:18px;font-weight:700;display:flex}.symbol-keyboard__key--lock img{width:24px;height:24px}.symbol-keyboard__key--locked{background-color:var(--primary-color,#0076f5);color:#fff;border-color:var(--primary-color,#0076f5)}.symbol-keyboard__key--locked:hover{filter:brightness(110%)}.symbol-keyboard__key--locked:active{background-color:#005dc2}.symbol-keyboard__key--back{padding:10px 0;font-size:18px;font-weight:700;display:flex}.tdhk{--keyboard-scale-height:max(220px, var(--keyboard-height));--key-font-size:max(1rem, calc(var(--keyboard-scale-height) / 20));--candidate-font-size:clamp(18px, calc(var(--keyboard-scale-height) / 13.5), 22px);--candidate-pinyin-font-size:clamp(13px, calc(var(--keyboard-scale-height) / 16), 16px);--gap:clamp(4px, calc(var(--keyboard-scale-height) / 75), 6px);--keyboard-stack-gap:var(--gap);--keyboard-header-height:clamp(42px, calc(var(--keyboard-scale-height) / 4.8), 52px);--keyboard-row-min-height:clamp(36px, calc(var(--keyboard-scale-height) / 6.1), 42px);--keyboard-body-min-height:calc(var(--keyboard-row-min-height) * 4 + var(--keyboard-stack-gap) * 3);--key-width:calc((100% - 9 * var(--gap)) / 10);--key-min-width-function:45px;--key-icon-size:calc(var(--key-font-size) * 1.2);--keyboard-shell-radius:var(--key-border-radius,6px);--key-shadow:0 1px 2px #0000001a;--key-active-shadow:0 0px 1px #0000000d;border-radius:var(--keyboard-shell-radius);-webkit-user-select:none;user-select:none;background-color:#f7f8f9;width:320px;min-width:320px;max-width:1080px;height:220px;min-height:220px;font-family:PingFang SC,Microsoft YaHei,-apple-system,sans-serif;position:relative;overflow:hidden;box-shadow:0 8px 30px #0000001a}.tdhk--disabled{opacity:.7}.tdhk--floating{z-index:9999;position:fixed;box-shadow:0 4px 20px #0003}.tdhk--bottom{width:100%;min-width:min(var(--keyboard-height) + 100px, 100%);z-index:9999;border-radius:var(--keyboard-shell-radius) var(--keyboard-shell-radius) 0 0;max-width:100%;position:fixed;bottom:0;left:0;box-shadow:0 -2px 10px #0000001a}.tdhk__disabled-overlay{z-index:10;border-radius:var(--keyboard-shell-radius);background-color:#f5f5f5cc;justify-content:center;align-items:center;width:100%;height:100%;display:flex;position:absolute;top:0;left:0}.tdhk__disabled-overlay span{color:#666;background-color:#e0e0e0;border-radius:5px;padding:15px 30px;font-size:16px}
2
+ /*$vite$:1*/