@zh-keyboard/core 0.5.1 → 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 +190 -190
- package/dist/index.d.mts +82 -60
- package/dist/index.d.ts +82 -60
- package/dist/index.js +33 -1064
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -1041
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
//#region src/advanced-pinyin.d.ts
|
|
2
|
-
interface PinyinCharEntry {
|
|
3
|
-
id?: number;
|
|
4
|
-
pinyin: string;
|
|
5
|
-
char: string;
|
|
6
|
-
weight: number;
|
|
7
|
-
}
|
|
8
|
-
declare class AdvancedPinyinEngine {
|
|
9
|
-
private currentInput;
|
|
10
|
-
private candidates;
|
|
11
|
-
private db;
|
|
12
|
-
private pinyinDict;
|
|
13
|
-
private pinyinCharTable;
|
|
14
|
-
private initializationPromise;
|
|
15
|
-
constructor();
|
|
16
|
-
private initializeDatabase;
|
|
17
|
-
processInput(input: string): Promise<string[]>;
|
|
18
|
-
selectCandidate(selectedChar: string): Promise<void>;
|
|
19
|
-
clear(): void;
|
|
20
|
-
getCurrentInput(): string;
|
|
21
|
-
getCandidates(): string[];
|
|
22
|
-
} //#endregion
|
|
23
1
|
//#region src/canvas.d.ts
|
|
24
2
|
interface CanvasDrawerOptions {
|
|
25
3
|
onDrawEnd?: () => void;
|
|
@@ -83,9 +61,70 @@ interface HandwritingRecognizer {
|
|
|
83
61
|
* 关闭手写识别服务
|
|
84
62
|
*/
|
|
85
63
|
close(): Promise<void>;
|
|
64
|
+
} //#endregion
|
|
65
|
+
//#region src/pinyin-engine.d.ts
|
|
66
|
+
interface Candidate {
|
|
67
|
+
text: string;
|
|
68
|
+
comment: string;
|
|
86
69
|
}
|
|
87
|
-
|
|
88
|
-
|
|
70
|
+
interface PinyinState {
|
|
71
|
+
/** 已提交(最终)文本;若无提交则为 null。 */
|
|
72
|
+
committed: string | null;
|
|
73
|
+
/** 选区前的预编辑文本。 */
|
|
74
|
+
preeditHead: string;
|
|
75
|
+
/** 当前被选中的预编辑部分。 */
|
|
76
|
+
preeditBody: string;
|
|
77
|
+
/** 选区后的预编辑文本。 */
|
|
78
|
+
preeditTail: string;
|
|
79
|
+
/** 预编辑中的光标位置。 */
|
|
80
|
+
cursorPos: number;
|
|
81
|
+
/** 当前页的候选项列表。 */
|
|
82
|
+
candidates: Candidate[];
|
|
83
|
+
/** 当前页码(从 0 开始)。 */
|
|
84
|
+
pageNo: number;
|
|
85
|
+
/** 是否为候选的最后一页。 */
|
|
86
|
+
isLastPage: boolean;
|
|
87
|
+
/** 高亮候选的索引。 */
|
|
88
|
+
highlightedIndex: number;
|
|
89
|
+
/** 候选选择键的标签数组。 */
|
|
90
|
+
selectLabels: string[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 拼音引擎通用接口
|
|
94
|
+
* 所有拼音引擎实现必须遵循此接口
|
|
95
|
+
*/
|
|
96
|
+
interface PinyinEngine {
|
|
97
|
+
/**
|
|
98
|
+
* 初始化引擎,加载必要资源
|
|
99
|
+
*/
|
|
100
|
+
initialize(): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* 处理完整的拼音输入串,返回所有候选词列表(跨所有页)。
|
|
103
|
+
* 引擎内部负责增量 vs 重置的优化,调用方只传完整拼音。
|
|
104
|
+
* @param pinyin 完整的拼音字符串
|
|
105
|
+
* @returns 候选词状态,包括所有页的候选词集合和分页信息
|
|
106
|
+
*/
|
|
107
|
+
processInput(pinyin: string): Promise<PinyinState | null>;
|
|
108
|
+
/**
|
|
109
|
+
* 按全局索引选择候选词,返回已提交的文本。
|
|
110
|
+
* @param index 候选词在全量列表中的全局索引(从0开始)
|
|
111
|
+
* @returns 候选词状态,包括所有页的候选词集合和分页信息
|
|
112
|
+
*/
|
|
113
|
+
pickCandidate(index: number): Promise<PinyinState>;
|
|
114
|
+
/**
|
|
115
|
+
* 清除引擎当前的预编辑输入状态
|
|
116
|
+
*/
|
|
117
|
+
clearInput(): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* 切换简体/繁体输出(可选,引擎不支持时忽略)
|
|
120
|
+
* @param simplified true 为简体,false 为繁体
|
|
121
|
+
*/
|
|
122
|
+
setSimplified?(simplified: boolean): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* 销毁引擎,释放所有持有的资源
|
|
125
|
+
*/
|
|
126
|
+
destroy(): Promise<void>;
|
|
127
|
+
} //#endregion
|
|
89
128
|
//#region src/config.d.ts
|
|
90
129
|
/**
|
|
91
130
|
* 键盘配置类型
|
|
@@ -111,6 +150,12 @@ interface KeyboardConfig {
|
|
|
111
150
|
* 数字键盘的行配置
|
|
112
151
|
*/
|
|
113
152
|
numKeys?: string[][];
|
|
153
|
+
/**
|
|
154
|
+
* RIME WASM 文件及数据文件的 URL 或路径前缀。
|
|
155
|
+
* 用于默认 RIME 引擎加载(当未通过 registerPinyinEngine 注册自定义引擎时)。
|
|
156
|
+
* @default '/rime'
|
|
157
|
+
*/
|
|
158
|
+
wasmDir?: string;
|
|
114
159
|
}
|
|
115
160
|
/**
|
|
116
161
|
* 获取全局键盘配置
|
|
@@ -130,6 +175,18 @@ declare function registerHandwritingRecognizer(recognizer: HandwritingRecognizer
|
|
|
130
175
|
* @returns 手写识别服务实例
|
|
131
176
|
*/
|
|
132
177
|
declare function getHandwritingRecognizer(): HandwritingRecognizer | null;
|
|
178
|
+
/**
|
|
179
|
+
* 注册拼音引擎。
|
|
180
|
+
* 注册后,CandidateBar 将使用此引擎而非默认的 RIME 引擎。
|
|
181
|
+
* 适用于自定义引擎或 Worker 中运行的引擎。
|
|
182
|
+
* @param engine 拼音引擎实现
|
|
183
|
+
*/
|
|
184
|
+
declare function registerPinyinEngine(engine: PinyinEngine): void;
|
|
185
|
+
/**
|
|
186
|
+
* 获取已注册的拼音引擎实例
|
|
187
|
+
* @returns 拼音引擎实例,未注册时返回 null
|
|
188
|
+
*/
|
|
189
|
+
declare function getPinyinEngine(): PinyinEngine | null;
|
|
133
190
|
|
|
134
191
|
//#endregion
|
|
135
192
|
//#region src/dom.d.ts
|
|
@@ -177,41 +234,6 @@ declare function delToInputElement(inputElement: HTMLInputElement): void;
|
|
|
177
234
|
*/
|
|
178
235
|
declare function moveCursor(inputElement: HTMLInputElement, index: number): void;
|
|
179
236
|
|
|
180
|
-
//#endregion
|
|
181
|
-
//#region src/pinyin.d.ts
|
|
182
|
-
/**
|
|
183
|
-
* 简单拼音输入法引擎
|
|
184
|
-
*/
|
|
185
|
-
declare class SimplePinyinEngine {
|
|
186
|
-
private currentInput;
|
|
187
|
-
private candidates;
|
|
188
|
-
private pinyinMap;
|
|
189
|
-
/**
|
|
190
|
-
* 处理拼音输入
|
|
191
|
-
* @param input 用户输入的拼音
|
|
192
|
-
* @returns 候选词列表
|
|
193
|
-
*/
|
|
194
|
-
processInput(input: string): string[];
|
|
195
|
-
/**
|
|
196
|
-
* 清空当前输入
|
|
197
|
-
*/
|
|
198
|
-
clear(): void;
|
|
199
|
-
/**
|
|
200
|
-
* 获取当前输入码
|
|
201
|
-
*/
|
|
202
|
-
getCurrentInput(): string;
|
|
203
|
-
/**
|
|
204
|
-
* 获取当前候选词列表
|
|
205
|
-
*/
|
|
206
|
-
getCandidates(): string[];
|
|
207
|
-
/**
|
|
208
|
-
* 选择候选词
|
|
209
|
-
* @param index 候选词索引
|
|
210
|
-
* @returns 选中的候选词
|
|
211
|
-
*/
|
|
212
|
-
selectCandidate(index: number): string | null;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
237
|
//#endregion
|
|
216
238
|
//#region src/repeat.d.ts
|
|
217
239
|
interface KeyRepeatOptions {
|
|
@@ -233,5 +255,5 @@ interface KeyRepeater {
|
|
|
233
255
|
declare function createKeyRepeater(options?: KeyRepeatOptions): KeyRepeater;
|
|
234
256
|
|
|
235
257
|
//#endregion
|
|
236
|
-
export {
|
|
258
|
+
export { Candidate, CanvasDrawer, CanvasDrawerOptions, HandwritingRecognizer, KeyRepeatOptions, KeyRepeater, KeyboardConfig, KeyboardPosition, PinyinEngine, PinyinState, RecognizerInitOptions, calculateKeyboardPosition, createKeyRepeater, delToInputElement, getHandwritingRecognizer, getInputElement, getKeyboardConfig, getPinyinEngine, isInputElement, moveCursor, registerHandwritingRecognizer, registerPinyinEngine, setKeyboardConfig, writeToInputElement };
|
|
237
259
|
//# sourceMappingURL=index.d.ts.map
|