MoonBit Hypermedia X (mhx) is a type-safe Hypermedia-Driven Architecture (HDA) library for the browser, inspired by htmx. It uses `mx-*` attributes to declare hypermedia behavior and runs as a compact JS runtime compiled from MoonBit.
npm install mhxMoonBit Hypermedia X (mhx) is a type-safe Hypermedia-Driven Architecture (HDA)
library for the browser, inspired by htmx. It uses mx-* attributes to declare
hypermedia behavior and runs as a compact JS runtime compiled from MoonBit.
``bash`
npm install mhx
Import the runtime and initialize it once on startup. The npm entry already
initializes the FFI glue.
`js
import mhx, { init_mhx } from "mhx";
init_mhx();
`
mhx uses mx- attributes (not hx-) to define hypermedia behaviors:
`html
mx-get="/api/search"
mx-trigger="input changed debounce:300ms"
mx-target="#search-results"
name="q"
/>
`
The npm entry exports the following helpers:
- init_mhx() - initialize mhx (call once after DOM is ready)process(element)
- - process newly added elementshandle_event(event)
- - manually dispatch an eventget_instance()
- - access the internal singleton instanceversion
- - runtime version string
`js
import { process } from "mhx";
const node = document.querySelector("#new-content");
process(node);
`
`bash`
pnpm build
This builds a single bundled file for each format:
- dist/mhx.esm.js - ES Module formatdist/mhx.umd.js
- - UMD format (for script tags)
You can load mhx directly from a CDN without npm:
`html`
The package structure has changed to use single-file bundles.
Before (v2026.1.19):
`js`
// Entry point was npm/index.js which imported from dist/
import mhx from "mhx";
import ffi from "mhx/ffi"; // Separate FFI import was available
After (v2026.1.20+):
`js`
// Single bundled entry point - FFI is included
import mhx from "mhx";
Key changes:
- The mhx/ffi export has been removed (FFI is now bundled)
- All functionality is in a single file per format
- UMD build available for direct