https://github.com/fodydev/afrim-js
JS binding of the afrim input method engine.
https://github.com/fodydev/afrim-js
afrim ime rust wasm
Last synced: 5 months ago
JSON representation
JS binding of the afrim input method engine.
- Host: GitHub
- URL: https://github.com/fodydev/afrim-js
- Owner: fodydev
- License: mit
- Created: 2023-10-29T17:07:07.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-12T17:05:18.000Z (about 1 year ago)
- Last Synced: 2025-08-16T15:39:08.068Z (10 months ago)
- Topics: afrim, ime, rust, wasm
- Language: Rust
- Homepage: https://www.npmjs.org/package/afrim-js
- Size: 40 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
### 🛠️ Build with `wasm-pack build`
```
wasm-pack build
```
**Note**: Always use `wasm-pack build --debug` in debug mode.
### 🔋 Features Included
* `strsim` for text similarity.
* `rhai` for scripting.
### Lite Version
We also offer a lite version of this library for those who need a more lightweight solution.
You can find it here [npm/afrim-lite](https://www.npmjs.com/package/afrim-lite).
**Note:** This version implies the dropped rhai feature.
### Installation
```
npm install afrim
```
### Usage
```javascript
import { Preprocessor, Translator } from "afrim";
import { convertTomlToJson } from "afrim";
(async function () {
// We execute preprocessor commands in idle.
var processCommand = () => {
var cmd = JSON.parse(preprocessor.popQueue());
// ...
requestAnimationFrame(processCommand);
};
// ...
// We config the afrim ime.
var preprocessor = new Preprocessor(data, 64);
var translator = new Translator(dictionary, false);
Object.entries(scripts).forEach((e) =>
translator.register(e[0], e[1]),
);
// ...
// We listen keyboard events.
textFieldElement.addEventListener(
"keyup",
(event) => {
// ...
// Commit the predicate.
if (event.code == "Space") {
var predicate = global.memory.predicates[global.memory.predicateId];
if (predicate) preprocessor.commit(predicate[3]);
clearPredicate();
}
var changed = preprocessor.process(event.key, "keydown");
var input = preprocessor.getInput();
// We update the predicates
if (!changed) return;
tooltipInputElement.innerText = "📝 " + input;
var predicates = translator.translate(input);
loadPredicates(predicates);
updatePredicate();
// ...
},
false,
);
// ...
// We start the processor.
requestAnimationFrame(processCommand);
})();
```
### License
Licensed under MIT license ([LICENSE](LICENSE) or http://opensource.org/licenses/MIT).
### Contribution
We are open for contributions.