diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b273f65 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,59 @@ +name: ci + +on: + push: + branches: + - master + pull_request: + +jobs: + build: + runs-on: ubuntu-24.04 + env: + EMSCRIPTEN_VERSION: '3.1.74' + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - uses: actions/setup-node@v4 + with: + node-version: 22.x + + - name: Install dependencies + run: | + sudo apt install -y \ + ninja-build \ + gettext + npm i -g pnpm + pnpm i + ./scripts/install-deps.sh + + - name: Install emsdk + run: | + git clone https://github.com/emscripten-core/emsdk + cd emsdk + ./emsdk install ${{ env.EMSCRIPTEN_VERSION }} + ./emsdk activate ${{ env.EMSCRIPTEN_VERSION }} + + - name: Build + run: | + . emsdk/emsdk_env.sh + pnpm run configure + pnpm run build + npm pack + + - name: Setup tmate session + if: ${{ failure() }} + uses: mxschmitt/action-tmate@v3 + + - name: Release + if: ${{ github.ref == 'refs/heads/master' }} + uses: 'marvinpinto/action-automatic-releases@latest' + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + automatic_release_tag: latest + prerelease: true + title: "Nightly Build" + files: | + fcitx5-rime.js-*.tgz diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f40e608 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.27) + +project(fcitx5-rime-js VERSION 0.1.0) + +option(RIME_ONLY "" ON) +add_subdirectory(fcitx5-js) +target_link_libraries(Fcitx5 + "--embed-file ${PROJECT_BINARY_DIR}/sysroot/usr/lib/fcitx5/librime.so@/usr/lib/fcitx5/librime.so" + "--embed-file ${PROJECT_BINARY_DIR}/sysroot/usr/share/fcitx5/addon/rime.conf@/usr/share/fcitx5/addon/rime.conf" + "--embed-file ${PROJECT_BINARY_DIR}/sysroot/usr/share/fcitx5/inputmethod/rime.conf@/usr/share/fcitx5/inputmethod/rime.conf" + "--embed-file ${PROJECT_BINARY_DIR}/sysroot/usr/share/rime-data/opencc@/usr/share/rime-data/opencc" + "--embed-file ${PROJECT_SOURCE_DIR}/cache/placeholder.yaml@/usr/share/rime-data/default.yaml" # fcitx5-rime requires this file. + "--extern-post-js ${PROJECT_SOURCE_DIR}/src/rime.js" +) diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/cache/placeholder.yaml b/cache/placeholder.yaml new file mode 100644 index 0000000..e69de29 diff --git a/index.html b/index.html new file mode 100644 index 0000000..6293e23 --- /dev/null +++ b/index.html @@ -0,0 +1,11 @@ + + +
+ + + + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..72282f2 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "fcitx5-rime.js", + "version": "0.1.0", + "description": "Fcitx5 Rime as a JavaScript library", + "type": "module", + "files": [ + "dist" + ], + "author": { + "name": "Qijia Liu", + "email": "liumeo@pku.edu.cn", + "url": "https://github.com/eagleoflqj" + }, + "scripts": { + "configure": "emcmake cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug", + "build": "EMCC_FORCE_STDLIBS=libc++ FCITX_DISTRIBUTION=fcitx5-js cmake --build build", + "preview": "serve -S", + "prepack": "bash scripts/prepack.sh" + }, + "license": "AGPL-3.0-or-later", + "devDependencies": { + "serve": "^14.2.4" + } +} diff --git a/scripts/install-deps.sh b/scripts/install-deps.sh new file mode 100755 index 0000000..1272bcf --- /dev/null +++ b/scripts/install-deps.sh @@ -0,0 +1,13 @@ +set -e + +pnpm i --prefix=fcitx5-js +pnpm i --prefix=fcitx5-js/fcitx5-webview + +./fcitx5-js/scripts/install-deps.sh +file=rime.zip +[[ -f cache/$file ]] || wget -P cache https://github.com/fcitx-contrib/fcitx5-plugins/releases/download/js/$file +unzip -d build/sysroot/usr cache/$file + +mkdir -p build/fcitx5-js +ln -sf ../sysroot build/fcitx5-js +ln -sf ../build/fcitx5-js fcitx5-js/build diff --git a/scripts/prepack.sh b/scripts/prepack.sh new file mode 100755 index 0000000..6d4dea1 --- /dev/null +++ b/scripts/prepack.sh @@ -0,0 +1,8 @@ +set -e + +rm -rf dist/* +mkdir -p dist + +cp build/sysroot/usr/lib/libFcitx5* dist +cp build/fcitx5-js/src/Fcitx5.* dist +cp fcitx5-js/page/Fcitx5.d.ts dist diff --git a/src/rime.js b/src/rime.js new file mode 100644 index 0000000..f1e99b7 --- /dev/null +++ b/src/rime.js @@ -0,0 +1,9 @@ +export async function loadZip(url) { + const [_, schema] = await Promise.all([ + fcitxReady, + fetch(url).then(res => res.arrayBuffer()) + ]) + window.fcitx.unzip(schema, '/usr/share/rime-data') + window.fcitx.enable() + window.fcitx.setInputMethods(['rime']) +}