inputx-wubi-wasm 1.0.1

WASM bindings for inputx-wubi — Wubi 86 encoder + dictionary, browser/Node ready. Powers the Inputx IME web surface.
Documentation

@goliapkg/wubi (WASM)

Browser / Node bindings for inputx-wubi — a self-developed Wubi 86 (五笔字型) encoder + dictionary with built-in L0 / L1+ ranking and per-user auto-learning. Pre-built into a ~3 MB WebAssembly module (135K-entry dictionary embedded).

The web surface of the Inputx IME.

License: MIT OR Apache-2.0.

Read this in 简体中文 · 日本語.

Install

npm install @goliapkg/wubi

Usage

import init, { WubiEngine, Layer } from "@goliapkg/wubi";

await init();                              // load + instantiate the .wasm
const eng = new WubiEngine();              // ~µs, header-parse only

// L0/L1-ranked lookup
console.log(eng.lookup("khlg"));           // ["中国", "跑车", "跨国", ...]
console.log(eng.lookup("ipbf"));           // ["学"]

// Prefix lookup — for IME predictive candidates
const hits = eng.prefix("g");
hits.slice(0, 5).forEach(h => console.log(h.code, h.word));

// User picks a candidate → dict learns. After 3 picks of the same
// (code, word) the dict auto-pins it to L0.
eng.recordPick("khlg", "跑车");

// Layer prefs (advanced; default Auto = 0.7, others = 1.0)
eng.setLayerPref(Layer.Phrase, 1.5);

// Persistence — caller chooses storage
const state = eng.exportL0();
localStorage.setItem("wubi-l0", JSON.stringify(state));
// later:
eng.importL0(JSON.parse(localStorage.getItem("wubi-l0") ?? "{}"));

What ships

  • wubi_wasm_bg.wasm — packed FST + ranking + L0 logic (~3 MB)
  • wubi_wasm.js — ES-module wrapper
  • wubi_wasm.d.ts — TypeScript types
  • 135,822 dictionary entries (字根 / 简码 / phrases / auto-decomposed CJK)

Build from source

git clone https://github.com/goliajp/inputx
wasm-pack build core/crates/inputx-wubi-wasm --target web --release
# output in core/crates/inputx-wubi-wasm/pkg/

For Node-target bundles: wasm-pack build --target nodejs.

See also