# @humanmd/wasm

WASM bindings for the HMD Rust parser, validator, HTML renderer, and patch engine.

## Build

Install `wasm-pack` as a Rust CLI tool instead of an npm dependency:

```bash
cargo install wasm-pack --locked
npm run build
```

This keeps the npm package lockfile free of the vulnerable `binary-install`
dependency chain used by the npm-distributed `wasm-pack` wrapper.

```js
import init, { applyIntent, applyPatch, createPatch, parse, validate, renderHtml } from "@humanmd/wasm";

await init();

const ast = JSON.parse(parse(source));
const validation = JSON.parse(validate(source));
const html = renderHtml(source, JSON.stringify({ roundtrip: "semantic" }));
const patchJson = createPatch(source, JSON.stringify(intent));
const patchedFromPatch = applyPatch(source, patchJson);
const patchedFromIntent = applyIntent(source, JSON.stringify(intent));
```

The API returns JSON strings for parsed and validated data so browser and editor
integrations do not need to mirror Rust IR types in JavaScript.

Patch APIs do not access the filesystem. They throw on stale `targetHash`/`sourceHash`, invalid intent JSON, unsupported actions, and validation failures.
