@zh-keyboard/react 0.1.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 +190 -0
- package/README.md +220 -0
- package/dist/App.d.ts +2 -0
- package/dist/components/CandidateBar.d.ts +10 -0
- package/dist/components/CandidateList.d.ts +7 -0
- package/dist/components/CandidateSelection.d.ts +8 -0
- package/dist/components/HandwritingInput.d.ts +8 -0
- package/dist/components/KeyboardBase.d.ts +11 -0
- package/dist/components/NumericKeyboard.d.ts +8 -0
- package/dist/components/SymbolKeyboard.d.ts +8 -0
- package/dist/components/ZhKeyboard.d.ts +13 -0
- package/dist/hooks/useActiveElement.d.ts +6 -0
- package/dist/lib.d.ts +4 -0
- package/dist/main.d.ts +1 -0
- package/dist/style.css +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/utils/handwriting.d.ts +11 -0
- package/dist/utils/useHandwritingRecognizer.d.ts +3 -0
- package/dist/zh-keyboard-react.js +5401 -0
- package/dist/zh-keyboard-react.js.map +1 -0
- package/dist/zh-keyboard-react.umd.cjs +49 -0
- package/dist/zh-keyboard-react.umd.cjs.map +1 -0
- package/package.json +56 -0
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,220 @@
|
|
|
1
|
+
# 中文键盘 React 组件库
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
|
|
5
|
+
这是一个 React 的中文键盘组件库,支持拼音输入和手写输入。
|
|
6
|
+
|
|
7
|
+
## 功能特点
|
|
8
|
+
|
|
9
|
+
- 🔌 即插即用,自动绑定输入框
|
|
10
|
+
- ✨ 支持拼音输入,带候选词选择功能
|
|
11
|
+
- ✏️ 支持手写输入识别,支持连笔和简写
|
|
12
|
+
- 🔧 可自定义手写识别算法
|
|
13
|
+
- 📏 键盘大小可自定义缩放,灵活适配各种界面布局
|
|
14
|
+
- 🌐 纯前端实现,可作为静态网页部署,无需服务端支持
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @zh-keyboard/react
|
|
20
|
+
# 或者
|
|
21
|
+
yarn add @zh-keyboard/react
|
|
22
|
+
# 或者
|
|
23
|
+
pnpm add @zh-keyboard/react
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 属性
|
|
27
|
+
|
|
28
|
+
### Props
|
|
29
|
+
|
|
30
|
+
| 属性名 | 类型 | 默认值 | 说明 |
|
|
31
|
+
| --------------- | --------------------------------- | -------- | ---------------------------------- |
|
|
32
|
+
| defaultMode | 'en' \| 'zh' \| 'hand' \| 'num' | 'en' | 默认的键盘模式 |
|
|
33
|
+
| enableHandwriting| boolean | false | 是否启用手写输入 |
|
|
34
|
+
| position | 'static' \| 'float' \| 'bottom' | 'static' | 键盘定位模式 |
|
|
35
|
+
| value | string | '' | 输入框的值 |
|
|
36
|
+
| onChange | function | - | 值变化时的回调函数 |
|
|
37
|
+
|
|
38
|
+
### 事件
|
|
39
|
+
|
|
40
|
+
| 事件名 | 参数类型 | 说明 |
|
|
41
|
+
| ------ | -------- | ---- |
|
|
42
|
+
| onKey | KeyEvent | 当用户在键盘上点击按键时触发 |
|
|
43
|
+
|
|
44
|
+
## 基本使用
|
|
45
|
+
|
|
46
|
+
- 为了防止移动端设备弹出系统默认的键盘,建议在输入框上设置 `inputMode="none"` 属性。
|
|
47
|
+
- 此外,可以通过在输入框上设置 `data-inputmode` 属性来指定组件默认打开的键盘类型 (可选值为 `'en'`, `'zh'`, `'hand'`, `'num'`),具体键盘模式的说明请参考 `defaultMode` 属性。
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { ZhKeyboard } from '@zh-keyboard/react'
|
|
51
|
+
import { useState } from 'react'
|
|
52
|
+
import '@zh-keyboard/react/dist/style.css'
|
|
53
|
+
|
|
54
|
+
function App() {
|
|
55
|
+
const [inputText, setInputText] = useState('')
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div>
|
|
59
|
+
<input
|
|
60
|
+
value={inputText}
|
|
61
|
+
onChange={e => setInputText(e.target.value)}
|
|
62
|
+
data-inputmode="en"
|
|
63
|
+
inputMode="none"
|
|
64
|
+
placeholder="点击使用键盘输入"
|
|
65
|
+
/>
|
|
66
|
+
|
|
67
|
+
{/* 静态定位的键盘 */}
|
|
68
|
+
<ZhKeyboard
|
|
69
|
+
value={inputText}
|
|
70
|
+
onChange={setInputText}
|
|
71
|
+
/>
|
|
72
|
+
|
|
73
|
+
{/* 浮动定位的键盘(跟随输入框) */}
|
|
74
|
+
<ZhKeyboard
|
|
75
|
+
value={inputText}
|
|
76
|
+
onChange={setInputText}
|
|
77
|
+
position="float"
|
|
78
|
+
/>
|
|
79
|
+
|
|
80
|
+
{/* 底部固定的键盘 */}
|
|
81
|
+
<ZhKeyboard
|
|
82
|
+
value={inputText}
|
|
83
|
+
onChange={setInputText}
|
|
84
|
+
position="bottom"
|
|
85
|
+
/>
|
|
86
|
+
|
|
87
|
+
{/* 启用手写输入的键盘 */}
|
|
88
|
+
<ZhKeyboard
|
|
89
|
+
value={inputText}
|
|
90
|
+
onChange={setInputText}
|
|
91
|
+
enableHandwriting={true}
|
|
92
|
+
/>
|
|
93
|
+
|
|
94
|
+
{/* 数字键盘 */}
|
|
95
|
+
<ZhKeyboard
|
|
96
|
+
value={inputText}
|
|
97
|
+
onChange={setInputText}
|
|
98
|
+
defaultMode="num"
|
|
99
|
+
/>
|
|
100
|
+
</div>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export default App
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 输入模式
|
|
108
|
+
|
|
109
|
+
### 拼音输入模式 (zh)
|
|
110
|
+
|
|
111
|
+
拼音输入模式支持单字拼音输入,具有以下特性:
|
|
112
|
+
|
|
113
|
+
- 支持单字模糊拼音匹配
|
|
114
|
+
- 使用内置词库进行单字匹配
|
|
115
|
+
- 支持中英文快速切换
|
|
116
|
+
|
|
117
|
+
> 注:目前仅支持单个汉字的拼音输入,连续词组输入功能正在开发中
|
|
118
|
+
|
|
119
|
+
### 英文输入模式 (en)
|
|
120
|
+
|
|
121
|
+
标准的英文键盘布局,支持英文字母、数字和常用符号的输入。
|
|
122
|
+
|
|
123
|
+
### 手写输入模式 (hand)
|
|
124
|
+
|
|
125
|
+
手写输入模式允许用户通过手写输入汉字,启用此模式需要设置 `enableHandwriting` 为 `true`。
|
|
126
|
+
|
|
127
|
+
### 数字输入模式 (num)
|
|
128
|
+
|
|
129
|
+
数字输入模式提供一个数字和小数点键盘,方便用户输入数字、金额等。
|
|
130
|
+
|
|
131
|
+
## 手写识别
|
|
132
|
+
|
|
133
|
+
组件库支持自定义手写识别服务。您可以注册自己的手写识别服务来处理用户的手写输入。
|
|
134
|
+
|
|
135
|
+
### 手写识别接口
|
|
136
|
+
|
|
137
|
+
手写识别服务需要实现以下接口:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
interface HandwritingRecognizer {
|
|
141
|
+
/**
|
|
142
|
+
* 初始化手写识别服务
|
|
143
|
+
* @returns 返回是否初始化成功
|
|
144
|
+
*/
|
|
145
|
+
initialize(): Promise<boolean>
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 识别手写笔迹
|
|
149
|
+
* @param strokeData 笔迹数据,格式为 x y c x y c ...,其中x和y是坐标,c表示是否为笔画的最后一点(1表示是,0表示否)
|
|
150
|
+
* @returns 识别结果列表
|
|
151
|
+
*/
|
|
152
|
+
recognize(strokeData: number[]): Promise<string[]>
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 关闭手写识别服务
|
|
156
|
+
*/
|
|
157
|
+
close(): Promise<void>
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### 笔迹数据格式
|
|
162
|
+
|
|
163
|
+
笔迹数据以数组形式存储,格式为 `[x1, y1, c1, x2, y2, c2, ...]`,其中:
|
|
164
|
+
- `x`、`y` 是坐标点
|
|
165
|
+
- `c` 表示是否为笔画的最后一点:1表示是最后一点,0表示不是
|
|
166
|
+
|
|
167
|
+
例如,一个简单的笔画可能是:`[100, 150, 0, 101, 151, 0, 102, 152, 1]`,表示三个点的笔画,最后一个点是笔画的结束点。
|
|
168
|
+
|
|
169
|
+
### 注册手写识别服务
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { registerHandwritingRecognizer } from '@zh-keyboard/react'
|
|
173
|
+
import { MyHandwritingRecognizer } from './MyHandwritingRecognizer'
|
|
174
|
+
|
|
175
|
+
// 创建并注册您的手写识别服务
|
|
176
|
+
const recognizer = new MyHandwritingRecognizer()
|
|
177
|
+
registerHandwritingRecognizer(recognizer)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 示例实现
|
|
181
|
+
|
|
182
|
+
以下是一个简单的手写识别服务示例实现:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import type { HandwritingRecognizer } from '@zh-keyboard/react'
|
|
186
|
+
|
|
187
|
+
export class MyHandwritingRecognizer implements HandwritingRecognizer {
|
|
188
|
+
private initialized = false
|
|
189
|
+
|
|
190
|
+
async initialize(): Promise<boolean> {
|
|
191
|
+
console.log('初始化手写识别服务...')
|
|
192
|
+
// 在实际应用中,这里可能需要加载模型或连接到服务器
|
|
193
|
+
this.initialized = true
|
|
194
|
+
return true
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async recognize(strokeData: number[]): Promise<string[]> {
|
|
198
|
+
if (!this.initialized) {
|
|
199
|
+
throw new Error('手写识别服务未初始化')
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
console.log('识别笔迹数据:', strokeData)
|
|
203
|
+
|
|
204
|
+
// 这里调用您的手写识别API
|
|
205
|
+
// 返回识别结果
|
|
206
|
+
return ['你', '我', '他', '好', '的']
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async close(): Promise<void> {
|
|
210
|
+
console.log('关闭手写识别服务')
|
|
211
|
+
this.initialized = false
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## 生命周期
|
|
217
|
+
|
|
218
|
+
1. 当手写输入组件挂载时,会自动调用手写识别服务的 `initialize()` 方法
|
|
219
|
+
2. 当用户完成一个笔画时,会调用 `recognize()` 方法进行识别
|
|
220
|
+
3. 当手写输入组件卸载时,会调用 `close()` 方法关闭手写识别服务
|
package/dist/App.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { KeyEvent } from '../types';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
interface CandidateBarProps {
|
|
4
|
+
currentPinyin: string;
|
|
5
|
+
onKey: (payload: KeyEvent) => void;
|
|
6
|
+
onInput: (text: string) => void;
|
|
7
|
+
setCurrentPinyin: (pinyin: string) => void;
|
|
8
|
+
}
|
|
9
|
+
declare const CandidateBar: React.FC<CandidateBarProps>;
|
|
10
|
+
export default CandidateBar;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
interface CandidateSelectionProps {
|
|
3
|
+
candidates: string[];
|
|
4
|
+
onSelect: (candidate: string) => void;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
}
|
|
7
|
+
declare const CandidateSelection: React.FC<CandidateSelectionProps>;
|
|
8
|
+
export default CandidateSelection;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { KeyEvent } from '../types';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
interface HandwritingInputProps {
|
|
4
|
+
onKey: (payload: KeyEvent) => void;
|
|
5
|
+
onExit: () => void;
|
|
6
|
+
}
|
|
7
|
+
declare const HandwritingInput: React.FC<HandwritingInputProps>;
|
|
8
|
+
export default HandwritingInput;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { KeyBoardMode, KeyEvent } from '../types';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
interface KeyboardBaseProps {
|
|
4
|
+
recognizerInitialized?: boolean;
|
|
5
|
+
enableHandwriting?: boolean;
|
|
6
|
+
mode: KeyBoardMode;
|
|
7
|
+
onKey: (payload: KeyEvent) => void;
|
|
8
|
+
setMode: (mode: KeyBoardMode) => void;
|
|
9
|
+
}
|
|
10
|
+
declare const KeyboardBase: React.FC<KeyboardBaseProps>;
|
|
11
|
+
export default KeyboardBase;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { KeyEvent } from '../types';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
interface NumericKeyboardProps {
|
|
4
|
+
onKey: (payload: KeyEvent) => void;
|
|
5
|
+
onExit: () => void;
|
|
6
|
+
}
|
|
7
|
+
declare const NumericKeyboard: React.FC<NumericKeyboardProps>;
|
|
8
|
+
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,13 @@
|
|
|
1
|
+
import { KeyBoardMode, KeyEvent } from '../types';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
interface ZhKeyboardProps {
|
|
4
|
+
defaultMode?: KeyBoardMode;
|
|
5
|
+
enableHandwriting?: boolean;
|
|
6
|
+
position?: 'static' | 'float' | 'bottom';
|
|
7
|
+
disableWhenNoFocus?: boolean;
|
|
8
|
+
onKey?: (payload: KeyEvent) => void;
|
|
9
|
+
className?: string;
|
|
10
|
+
style?: React.CSSProperties;
|
|
11
|
+
}
|
|
12
|
+
declare const ZhKeyboard: React.FC<ZhKeyboardProps>;
|
|
13
|
+
export default ZhKeyboard;
|
package/dist/lib.d.ts
ADDED
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@charset "UTF-8";.zhk-candidate-list{flex:1;min-width:0;display:flex;overflow-x:auto;gap:var(--gap);scroll-behavior:smooth;scrollbar-width:none;-ms-overflow-style:none}.zhk-candidate-list::-webkit-scrollbar{display:none}.zhk-candidate-list__item{font-size:var(--candidate-font-size);display:flex;align-items:center;justify-content:center;background-color:transparent;border:none;cursor:pointer;white-space:nowrap;aspect-ratio:1;flex-shrink:0}.handwriting-input{display:flex;flex-direction:column;height:100%;background:var(--background-color, #f5f5f5);padding:var(--gap);gap:var(--gap);box-sizing:border-box}.handwriting-input .handwriting-content{flex:7;display:flex;flex-direction:row;align-items:flex-start;justify-content:center;flex-wrap:nowrap;overflow:hidden;gap:var(--gap)}.handwriting-input .handwriting-canvas-container{background:#fff;font-size:0}.handwriting-input .handwriting-canvas{touch-action:none}.handwriting-input .handwriting-buttons{flex:1;display:flex;flex-direction:column;justify-content:space-between;gap:var(--gap);max-width:calc(var(--keyboard-height) / 4);height:100%}.handwriting-input .handwriting-btn{flex:1;padding:var(--gap);border:1px solid var(--border-color, #dcdcdc);border-radius:var(--key-border-radius, 5px);background-color:var(--function-key-color, #e6e6e6);cursor:pointer;width:100%;display:flex;align-items:center;justify-content:center;white-space:nowrap;font-size:var(--key-font-size);font-weight:700;transition:all .1s}.handwriting-input .handwriting-btn:hover{background-color:#d9d9d9}.handwriting-input .handwriting-btn:active{transform:scale(.95)}.handwriting-input .handwriting-btn--function img{width:var(--key-icon-size);height:var(--key-icon-size)}.zhk-selection{position:absolute;top:0;left:0;width:100%;height:100%;background:#f5f5f5;z-index:2;display:flex;flex-wrap:nowrap;align-items:flex-start;justify-content:center;padding:var(--gap);gap:var(--gap);box-sizing:border-box}.zhk-selection__list{flex:5;min-width:0;display:grid;grid-template-columns:repeat(auto-fit,minmax(calc(var(--keyboard-height) / 6),1fr));background-color:var(--key-background-color, #fff);max-height:100%;overflow-y:auto;overflow-x:hidden}.zhk-selection__list::-webkit-scrollbar{width:6px}.zhk-selection__list::-webkit-scrollbar-thumb{background-color:var(--border-color, #dcdcdc);border-radius:3px}.zhk-selection__list::-webkit-scrollbar-track{background-color:transparent}.zhk-selection__text{font-size:var(--candidate-font-size);padding:10px;display:inline-flex;justify-content:center;align-items:center;border-bottom:1px solid var(--border-color, #dcdcdc);cursor:pointer}.zhk-selection__text:hover{background-color:var(--hover-key-color, #f0f0f0);z-index:1}.zhk-selection__func{flex:1;display:flex;justify-content:flex-end}.zhk-selection__func-btn{width:100%;font-size:var(--key-font-size);border:1px solid var(--border-color, #dcdcdc);border-radius:var(--key-border-radius, 5px);background-color:var(--function-key-color, #e6e6e6);padding:12px 0;cursor:pointer;color:#333;transition:all .1s;white-space:nowrap}.zhk-selection__func-btn:hover{background-color:var(--key-background-color, #fff)}.zhk-candidate{width:100%;height:100%;display:flex;align-items:center;box-sizing:border-box}.zhk-candidate__container{display:flex;flex-direction:column;flex:1;min-width:0;width:100%;height:100%;background-color:#f5f5f5}.zhk-candidate__pinyin{flex:1;font-size:var(--key-font-size);color:var(--primary-color, #4CAF50);box-sizing:border-box}.zhk-candidate__bottom-container{flex:3;display:flex;align-items:center;gap:var(--gap);width:100%}.zhk-candidate__more{cursor:pointer;display:flex;align-items:center;width:max(36px,var(--keyboard-height) / 8);background:none;border:none}.zhk-base{height:100%;display:flex;flex-direction:column;padding:var(--gap);box-sizing:border-box}.zhk-base__row{flex:1;min-height:0;display:flex;justify-content:center;gap:var(--gap);margin-bottom:4px}.zhk-base__row:last-child{margin-bottom:0}.zhk-base__key{width:var(--key-width);flex:none;min-height:40px;border:1px solid var(--border-color, #dcdcdc);border-radius:var(--key-border-radius, 5px);background-color:var(--key-background-color, #fff);color:var(--key-text-color, #333);font-size:var(--key-font-size);cursor:pointer;transition:all .1s;padding:0 5px;display:flex;align-items:center;justify-content:center}.zhk-base__key:active{transform:scale(.95)}.zhk-base__key--function{flex:none;width:var(--key-width);min-width:var(--key-min-width-function);background-color:var(--function-key-color, #e6e6e6);font-weight:700}.zhk-base__key--shift,.zhk-base__key--delete{flex:1;width:auto}.zhk-base__key--space{flex:1;width:auto;min-width:20px}.zhk-base__key--active{background-color:var(--primary-color, #4CAF50);border-color:var(--primary-color, #4CAF50);color:#fff}.zhk-base__key--active .zhk-base__key-icon{filter:brightness(0) invert(1)}.zhk-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}.zhk-base__key--disabled .zhk-base__key-icon{filter:brightness(.7)}.zhk-base__key-icon{width:var(--key-icon-size);height:var(--key-icon-size);vertical-align:middle;display:inline-block}.zhk-base__toggle-main{font-size:max(14px,var(--keyboard-height) / 30)}.zhk-base__toggle-sub{font-size:max(12px,var(--keyboard-height) / 40);color:var(--toggle-sub-color, #888);margin-left:2px}.num-keyboard{height:100%;display:flex;flex-direction:column;padding:8px;box-sizing:border-box}.num-keyboard__container{display:flex;height:100%;gap:8px}.num-keyboard__left{flex:3;display:flex;flex-direction:column}.num-keyboard__right{flex:1;display:flex;flex-direction:column;justify-content:space-between;gap:6px}.num-keyboard__rows{display:flex;flex-direction:column;flex:1;gap:var(--gap)}.num-keyboard__row{display:flex;flex:1;gap:var(--gap)}.num-keyboard__key{flex:1;display:flex;align-items:center;justify-content:center;background-color:var(--key-background-color, #fff);border:1px solid var(--border-color, #dcdcdc);border-radius:var(--key-border-radius, 5px);font-size:var(--key-font-size);font-weight:700;color:var(--key-text-color, #333);cursor:pointer;transition:all .1s}.num-keyboard__key:hover{background-color:#f7f7f7}.num-keyboard__key:active{transform:scale(.95)}.num-keyboard__key--function{height:calc(25% - 6px);background-color:var(--function-key-color, #e6e6e6);font-size:var(--key-font-size);font-weight:700}.num-keyboard__key--function:hover{background-color:#d9d9d9}.num-keyboard__key--back{font-size:var(--key-font-size);background-color:var(--function-key-color, #e6e6e6)}.num-keyboard__key--back:hover{background-color:#d9d9d9}.num-keyboard__key--space{font-size:var(--key-font-size)}.num-keyboard__key-icon{width:var(--key-icon-size);height:var(--key-icon-size)}.symbol-keyboard{height:100%;display:flex;flex-direction:column;padding:10px;box-sizing:border-box}.symbol-keyboard__content{display:flex;flex:1;gap:6px;height:100%}.symbol-keyboard__functions{display:flex;flex-direction:column;justify-content:space-between;gap:6px;width:60px}.symbol-keyboard__lang-selector{display:flex;flex-direction:column;height:126px}.symbol-keyboard__lang-btn{padding:10px 0;display:flex;align-items:center;justify-content:center;background-color:var(--key-background-color, #fff);border:1px solid var(--border-color, #dcdcdc);font-size:16px;cursor:pointer;transition:all .1s;margin:0;box-sizing:border-box;width:60px;flex:1;flex-shrink:0}.symbol-keyboard__lang-btn:first-child{border-radius:var(--key-border-radius, 5px) var(--key-border-radius, 5px) 0 0}.symbol-keyboard__lang-btn:last-child{margin-top:-1px;border-radius:0 0 var(--key-border-radius, 5px) var(--key-border-radius, 5px)}.symbol-keyboard__lang-btn:hover{filter:brightness(95%)}.symbol-keyboard__lang-btn--active{background-color:var(--primary-color, #4CAF50);color:#fff;border-color:var(--primary-color, #4CAF50);position:relative;z-index:1}.symbol-keyboard__control-group{display:flex;flex-direction:column;gap:8px}.symbol-keyboard__symbols-container{flex:1;width:100%;height:100%;overflow-y:auto;padding-right:5px}.symbol-keyboard__symbols-container::-webkit-scrollbar{width:6px}.symbol-keyboard__symbols-container::-webkit-scrollbar-track{background:#0000000d;border-radius:3px}.symbol-keyboard__symbols-container::-webkit-scrollbar-thumb{background:#0003;border-radius:3px}.symbol-keyboard__symbols-container::-webkit-scrollbar-thumb:hover{background:#0000004d}.symbol-keyboard__symbols-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(60px,1fr));gap:6px;width:100%;max-height:100%;padding-bottom:10px}.symbol-keyboard__key{display:flex;align-items:center;justify-content:center;background-color:var(--key-background-color, #fff);border:1px solid var(--border-color, #dcdcdc);border-radius:var(--key-border-radius, 5px);font-size:24px;font-weight:400;color:var(--key-text-color, #333);cursor:pointer;transition:all .1s;margin:0;box-sizing:border-box;min-width:60px;max-width:80px;width:100%;height:60px;aspect-ratio:1;flex-shrink:0}.symbol-keyboard__key:hover{background-color:#f7f7f7}.symbol-keyboard__key:active{transform:scale(.95)}.symbol-keyboard__key--function{background-color:var(--function-key-color, #e6e6e6);width:60px;height:60px;aspect-ratio:auto}.symbol-keyboard__key--function:hover{background-color:#d9d9d9}.symbol-keyboard__key--lock{padding:10px 0;font-size:18px;font-weight:700;display:flex;align-items:center;justify-content:center}.symbol-keyboard__key--lock img{width:24px;height:24px}.symbol-keyboard__key--locked{background-color:var(--primary-color, #4CAF50);color:#fff}.symbol-keyboard__key--locked:hover{background-color:#449d48}.symbol-keyboard__key--back{padding:10px 0;font-size:18px;font-weight:700;display:flex}.zhk{--key-font-size: max(1rem, calc(var(--keyboard-height) / 20));--candidate-font-size: max(24px, calc(var(--keyboard-height) / 12));--gap: 4px;--key-width: calc((100% - 9 * var(--gap)) / 10);--key-min-width-function: 45px;--key-icon-size: calc(var(--key-font-size) * 1.2);position:relative;width:400px;min-width:calc(var(--keyboard-height) + 100px);max-width:1080px;height:300px;min-height:300px;overflow:hidden;background-color:#f5f5f5;border-radius:8px;box-shadow:0 2px 10px #0000001a;font-family:PingFang SC,Microsoft YaHei,sans-serif;-webkit-user-select:none;user-select:none}.zhk--disabled{opacity:.7}.zhk--floating{position:fixed;z-index:9999;box-shadow:0 4px 20px #0003}.zhk--bottom{position:fixed;bottom:0;left:0;width:100%;min-width:min(var(--keyboard-height) + 100px,100%);max-width:100%;z-index:9999;border-radius:8px 8px 0 0;box-shadow:0 -2px 10px #0000001a}.zhk__disabled-overlay{position:absolute;top:0;left:0;width:100%;height:100%;display:flex;justify-content:center;align-items:center;background-color:#f5f5f5cc;z-index:10;border-radius:8px}.zhk__disabled-overlay span{font-size:16px;color:#666;padding:15px 30px;background-color:#e0e0e0;border-radius:5px}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HandwritingRecognizer } from '@zh-keyboard/core';
|
|
2
|
+
/**
|
|
3
|
+
* 注册手写识别服务
|
|
4
|
+
* @param recognizer 手写识别服务实现
|
|
5
|
+
*/
|
|
6
|
+
export declare function registerHandwritingRecognizer(recognizer: HandwritingRecognizer): void;
|
|
7
|
+
/**
|
|
8
|
+
* 获取手写识别服务实例
|
|
9
|
+
* @returns 手写识别服务实例
|
|
10
|
+
*/
|
|
11
|
+
export declare function getHandwritingRecognizer(): HandwritingRecognizer | null;
|