@gotipe/wasm
v0.1.2
Published
Rust document engine of the GoTipe editor compiled to WebAssembly, loaded by @gotipe/core.
Maintainers
Readme
@gotipe/wasm
The Rust document engine of GoTipe, compiled to WebAssembly. @gotipe/core loads it when an
editor is created with engine: "wasm" or engine: "auto" (the default); collaboration runs
only on this engine.
Docs · Website · Repository
Install
npm install @gotipe/core @gotipe/wasmThe package has no dependencies. It is an ES module only; you use it through @gotipe/core
rather than calling it directly.
Usage
import { createEditor } from "@gotipe/core";
import { DefaultPreset } from "@gotipe/core/presets";
const editor = await createEditor({ extensions: [DefaultPreset], engine: "wasm" });
console.log(editor.engine); // "wasm"With engine: "auto" the core falls back to the JS engine and logs a warning when the module
can't be loaded; engine: "wasm" rejects with WASM_INIT_FAILED instead.
In the browser the module finds gotipe_wasm_bg.wasm with new URL(…, import.meta.url), so
your bundler must emit the file as an asset. For the Vite dev server, exclude the package from
pre-bundling:
// vite.config.ts
import { defineConfig } from "vite";
export default defineConfig({
optimizeDeps: { exclude: ["@gotipe/wasm"] },
});To load the binary yourself (a CDN, or a bundler that can't emit the asset), pass a loader. With Vite, for example:
import { createEditorWithLoader, type WasmModuleLoader } from "@gotipe/core";
import { DefaultPreset } from "@gotipe/core/presets";
import wasmUrl from "@gotipe/wasm/pkg/gotipe_wasm_bg.wasm?url";
const loadWasm: WasmModuleLoader = async () => {
const wasm = await import("@gotipe/wasm");
await wasm.default({ module_or_path: wasmUrl });
return wasm;
};
const editor = await createEditorWithLoader({ extensions: [DefaultPreset], engine: "wasm" }, loadWasm);- Serve
.wasmfiles asapplication/wasm. - Under a Content Security Policy, allow
'wasm-unsafe-eval'inscript-srcand the binary's URL inconnect-src. - In Node, the package's
nodeexport condition reads the binary from the installed package; no loader is needed.
License
MIT. See LICENSE. Notices for the bundled third-party code and data are in THIRD_PARTY_NOTICES.md.
