0.4.0 • Published 2 days ago

afrim-js v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 days ago

A binding of the afrim ime engine for the web.

Built with 🦀🕸 by @pythonbrad

🛠️ 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.

Installation

npm install afrim-js

Usage

import { Preprocessor, Translator } from "afrim-js";
import { convertTomlToJson } from "afrim-js";

(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 or http://opensource.org/licenses/MIT).

Contribution

We are open for contributions.

0.4.0

2 days ago

0.3.0

1 month ago

0.2.0

1 month ago

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago