@zh-keyboard/core 0.5.1 → 1.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/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
- //#endregion
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
  * 键盘配置类型
@@ -103,6 +142,11 @@ interface KeyboardConfig {
103
142
  * 键盘定位模式
104
143
  */
105
144
  position?: 'static' | 'float' | 'bottom';
145
+ /**
146
+ * 浮动模式下键盘与输入框的距离
147
+ * @default 10
148
+ */
149
+ floatMarginTop?: number;
106
150
  /**
107
151
  * 当没有input获得焦点时是否禁用键盘
108
152
  */
@@ -111,6 +155,12 @@ interface KeyboardConfig {
111
155
  * 数字键盘的行配置
112
156
  */
113
157
  numKeys?: string[][];
158
+ /**
159
+ * RIME WASM 文件及数据文件的 URL 或路径前缀。
160
+ * 用于默认 RIME 引擎加载(当未通过 registerPinyinEngine 注册自定义引擎时)。
161
+ * @default '/rime'
162
+ */
163
+ wasmDir?: string;
114
164
  }
115
165
  /**
116
166
  * 获取全局键盘配置
@@ -130,6 +180,18 @@ declare function registerHandwritingRecognizer(recognizer: HandwritingRecognizer
130
180
  * @returns 手写识别服务实例
131
181
  */
132
182
  declare function getHandwritingRecognizer(): HandwritingRecognizer | null;
183
+ /**
184
+ * 注册拼音引擎。
185
+ * 注册后,CandidateBar 将使用此引擎而非默认的 RIME 引擎。
186
+ * 适用于自定义引擎或 Worker 中运行的引擎。
187
+ * @param engine 拼音引擎实现
188
+ */
189
+ declare function registerPinyinEngine(engine: PinyinEngine): void;
190
+ /**
191
+ * 获取已注册的拼音引擎实例
192
+ * @returns 拼音引擎实例,未注册时返回 null
193
+ */
194
+ declare function getPinyinEngine(): PinyinEngine | null;
133
195
 
134
196
  //#endregion
135
197
  //#region src/dom.d.ts
@@ -144,7 +206,7 @@ interface KeyboardPosition {
144
206
  * @param positionMode 位置模式:'static'(静态,不计算位置)、'float'(浮动,根据输入框位置计算)、'bottom'(固定在底部)
145
207
  * @returns 返回键盘的 top 和 left 位置,如果不需要计算则返回 null
146
208
  */
147
- declare function calculateKeyboardPosition(inputElement: HTMLElement | null, keyboardElement: HTMLElement | null, positionMode: 'static' | 'float' | 'bottom'): KeyboardPosition | null;
209
+ declare function calculateKeyboardPosition(inputElement: HTMLElement | null, keyboardElement: HTMLElement | null, positionMode: 'static' | 'float' | 'bottom', floatMarginTop?: number): KeyboardPosition | null;
148
210
 
149
211
  //#endregion
150
212
  //#region src/input.d.ts
@@ -177,41 +239,6 @@ declare function delToInputElement(inputElement: HTMLInputElement): void;
177
239
  */
178
240
  declare function moveCursor(inputElement: HTMLInputElement, index: number): void;
179
241
 
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
242
  //#endregion
216
243
  //#region src/repeat.d.ts
217
244
  interface KeyRepeatOptions {
@@ -233,5 +260,5 @@ interface KeyRepeater {
233
260
  declare function createKeyRepeater(options?: KeyRepeatOptions): KeyRepeater;
234
261
 
235
262
  //#endregion
236
- export { AdvancedPinyinEngine, CanvasDrawer, CanvasDrawerOptions, HandwritingRecognizer, KeyRepeatOptions, KeyRepeater, KeyboardConfig, KeyboardPosition, PinyinCharEntry, RecognizerInitOptions, SimplePinyinEngine, calculateKeyboardPosition, createKeyRepeater, delToInputElement, getHandwritingRecognizer, getInputElement, getKeyboardConfig, isInputElement, moveCursor, registerHandwritingRecognizer, setKeyboardConfig, writeToInputElement };
263
+ 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
264
  //# sourceMappingURL=index.d.ts.map