simple-ime 1.0.0-beta.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.
@@ -0,0 +1 @@
1
+ export declare function getCandidates(pinyin: string): [string[], number[]];
@@ -0,0 +1,4 @@
1
+ export declare function handleBackspace(text: string, originPinyin: string, cursorPosition: number): {
2
+ html: string;
3
+ newCursorPosition: number;
4
+ };
@@ -0,0 +1,3 @@
1
+ import { SimpleImeInstance } from './types';
2
+
3
+ export declare function createSimpleIme(): SimpleImeInstance;
@@ -0,0 +1,63 @@
1
+ export declare class SimpleIme {
2
+ version: string;
3
+ private candPage;
4
+ private candIndex;
5
+ private cands;
6
+ private candsMatchLens;
7
+ private candsMathOriginPinyins;
8
+ private accMatchedPinyin;
9
+ private chiMode;
10
+ private flag;
11
+ private method;
12
+ private newIn;
13
+ private punct;
14
+ private shape;
15
+ private isOn;
16
+ private typeOn;
17
+ private originPinyin;
18
+ private toolbarHandle?;
19
+ private inputViewHandle?;
20
+ private cursorPosition;
21
+ private injectedStyleEl?;
22
+ private injectCSS;
23
+ private bindEvents;
24
+ private bindFocusEvent;
25
+ private bindKeyEvent;
26
+ private unbindEvents;
27
+ private handleKeyDownEvent;
28
+ private handleKeyPressEvent;
29
+ private handleFocusinEvent;
30
+ private handleFocusoutEvent;
31
+ private candidatePrev;
32
+ private candidateNext;
33
+ private candidatePageUp;
34
+ private candidatePageDown;
35
+ private clearCandidate;
36
+ private commitText;
37
+ private fetchCandidateAsync;
38
+ private getNthCandidate;
39
+ private getNthMatchLen;
40
+ private getNthMatchOriginPinyin;
41
+ private getPredictText;
42
+ private hideComposition;
43
+ private hideStatus;
44
+ private highBack;
45
+ private nthCandidateExists;
46
+ private selectCandidate;
47
+ private setCandidates;
48
+ private setMatchLens;
49
+ private setPredictText;
50
+ private showCandidates;
51
+ private showComposition;
52
+ private showStatus;
53
+ private switchMethod;
54
+ private switchShape;
55
+ private switchPunct;
56
+ private moveCursorPositionLeft;
57
+ private moveCursorPositionRight;
58
+ init(): void;
59
+ toggleOnOff(): void;
60
+ turnOn(): void;
61
+ turnOff(): void;
62
+ dispose(): void;
63
+ }
@@ -0,0 +1,12 @@
1
+ export interface SimpleImeInstance {
2
+ /** 输入法版本号 */
3
+ version: string;
4
+ /** 切换输入法开关状态 */
5
+ toggleOnOff: () => void;
6
+ /** 打开输入法 */
7
+ turnOn: () => void;
8
+ /** 关闭输入法 */
9
+ turnOff: () => void;
10
+ /** 销毁输入法实例 */
11
+ dispose: () => void;
12
+ }
@@ -0,0 +1,13 @@
1
+ export declare function insertCharAtCursorPosition(text: string, char: string, cursorPosition: number): string;
2
+ export declare function deleteCharAtCursorPosition(text: string, cursorPosition: number): string;
3
+ export declare function generateTextByCursorPosition(text: string, cursorPosition: number): string;
4
+ export declare function replaceTextAndUpdateCursorPosition(text: string, replacedPosition: number, replaceLength: number, replacedText: string, curPosition: number): {
5
+ cursorPosition: number;
6
+ html: string;
7
+ };
8
+ export declare function moveCursorPositionLeft(text: string, cursorPosition: number): number;
9
+ export declare function moveCursorPositionRight(text: string, cursorPosition: number): number;
10
+ export declare function findConvertPinyinByCursorPosition(text: string, cursorPosition: number): {
11
+ origin: string;
12
+ pinyin: string;
13
+ };
@@ -0,0 +1,2 @@
1
+ export declare function isEditableElement(element: any): any;
2
+ export declare function updateContent(element: Element, str: string): false | undefined;
@@ -0,0 +1,3 @@
1
+ export declare function isCompositionEvent(type: string): boolean;
2
+ export declare function dispatchInputEvent(element: Element, type: string): void;
3
+ export declare function dispatchCompositionEvent(element: Element, type: 'compositionstart' | 'compositionupdate' | 'compositionend', data: string): void;
@@ -0,0 +1,8 @@
1
+ export declare function findNextConvertPinyin(pinyin: string): {
2
+ pinyin: string;
3
+ quotes: number;
4
+ };
5
+ export declare function isLatin(code: number): boolean;
6
+ export declare function isChinese(code: number): boolean;
7
+ export declare function hasChinese(str: string): boolean;
8
+ export declare function lengthChinese(str: string): number;
@@ -0,0 +1,3 @@
1
+ export declare function createInputView(onSelectCand: (e: Event, index: number) => void, onClickPrevButton: (e: Event) => void, onClickNextButton: (e: Event) => void): {
2
+ dispose(): void;
3
+ };
@@ -0,0 +1,5 @@
1
+ export declare function createToolbar(switchMethod: (event: Event) => void, switchShape: (event: Event) => void, switchPunct: (event: Event) => void): {
2
+ hide(): void;
3
+ show(): void;
4
+ dispose(): void;
5
+ };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "simple-ime",
3
+ "type": "module",
4
+ "version": "1.0.0-beta.0",
5
+ "description": "An simple browser tool to use Chinese Pinyin Input Method (IME).",
6
+ "author": "nieyuyao <nieyuyao0826@hotmail.com>",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "url": "https://github.com/nieyuyao/simple-ime.git"
10
+ },
11
+ "main": "./dist/simple-ime.js",
12
+ "module": "./dist/simple-ime.es.js",
13
+ "unpkg": "./dist/simple-ime.umd.js",
14
+ "iife": "./dist/simple-ime.global.js",
15
+ "types": "./dist/src/index.d.ts",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "dev": "vite example --force",
21
+ "build": "vite build",
22
+ "test": "vitest",
23
+ "compressDict": "node --loader ts-node/esm --no-warnings=ExperimentalWarning scripts/compress-dict.ts",
24
+ "release": "bash ./release.sh"
25
+ },
26
+ "dependencies": {
27
+ "dawg-lookup": "^2.2.1"
28
+ },
29
+ "devDependencies": {
30
+ "@antfu/eslint-config": "^3.15.0",
31
+ "@types/jquery": "^3.5.32",
32
+ "@types/node": "^22.10.7",
33
+ "@vitejs/plugin-vue": "^5.2.1",
34
+ "sass": "^1.83.4",
35
+ "ts-node": "^10.9.2",
36
+ "typescript": "^5.7.3",
37
+ "vite": "^6.0.7",
38
+ "vite-plugin-dts": "^3.9.1",
39
+ "vite-svg-loader": "^5.1.0",
40
+ "vitest": "^3.0.4",
41
+ "vue": "^3.5.13",
42
+ "vue-router": "^4.5.0"
43
+ }
44
+ }