npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mjswan

v0.10.2

Published

[![npm version](https://img.shields.io/npm/v/mjswan.svg?logo=nodedotjs)](https://www.npmjs.com/package/mjswan) [![docs](https://img.shields.io/readthedocs/mjswan?logo=readthedocs)](https://mjswan.readthedocs.io)

Readme

mjswan web engine

npm version docs

Browser-side runtime for mjswan. Interactive MuJoCo simulations with real-time policy control, running entirely in the browser via WebAssembly.

The package runs MuJoCo physics (mujoco-wasm), renders with three.js, and executes policies with ONNX Runtime Web.

Most users want the Python package. mjswan is primarily authored in Python (pip install mjswan), which bundles your models, policies, and UI into a static site. This npm package is the browser side, and is useful directly in two cases: embedding a published simulation in your own page, and authoring custom MDP terms in TypeScript with full type support. See the documentation for the full Python workflow.

Installation

npm install mjswan

Requires Node.js 24+ and a bundler that handles TypeScript sources (Vite recommended. See Custom MDP terms below for why).

Embedding a simulation

The package ships a self-contained library build (dist/mjswan.js) that renders an mjswan simulation into any element. It bundles every dependency and co-locates its WASM, runs single-threaded by default (no COOP/COEP headers needed), and works cross-origin — so it can be loaded straight from a CDN. Two layers, deliberately separate: createEngine is bytes in, snapshot out and never fetches; mjswan/manifest turns a build's manifest.json — the simulation document's one descriptor — into a lazy catalog of loadable things, and the page owns the fetching.

const { createEngine } = await import('https://cdn.jsdelivr.net/npm/mjswan/dist/mjswan.js');
const { parseManifest } = await import('https://cdn.jsdelivr.net/npm/mjswan/dist/manifest.js');

// Every other asset (scene.mjz, mdp/…/*.onnx, policy/*.onnx, assets/*.npz) resolves
// against the manifest's directory.
const base = 'https://example.com/myapp/';
const bytes = (path) => async () => (await fetch(new URL(path, base))).arrayBuffer();

const engine = await createEngine(container);
const catalog = parseManifest(await (await fetch(new URL('manifest.json', base))).text(), bytes);
await engine.loadScene(await catalog.projects[0].scenes[0].buildScene());

Or as a normal bundled import:

import { createEngine } from 'mjswan';
import { parseManifest } from 'mjswan/manifest';

The catalog's buildScene({ policy, splat }) takes ids — name2id of the display names, the same values the bundled app's ?scene= / ?policy= parameters use. A .swn document (the same tree as a ZIP) renders the same way once unpacked into an in-memory resolver. See the Engine API for setPolicy, camera, commands, subscribe, captureThumbnail and dispose.

Custom MDP terms

When authoring custom observations, commands, events, or terminations for a mjswan simulation, import the base classes and helpers from subpath exports instead of fragile relative paths. Install mjswan as a dev dependency and import directly:

import { ObservationBase } from 'mjswan/observation';
import { mjcToThreeCoordinate } from 'mjswan/coordinate';
import type { PolicyState } from 'mjswan/types';

export class MyObservation extends ObservationBase {
  get size(): number {
    return 3;
  }

  compute(state: PolicyState): Float32Array {
    // ... read MuJoCo state, return the observation vector
  }
}

The build step bundles your source into the engine. See the examples for complete custom terms.

Subpath exports point at TypeScript source (not compiled .d.ts), so consumers need a bundler that handles TypeScript. Vite does; plain tsc does not. This keeps full IDE IntelliSense without a separate types package — see ADR 0001.

Available subpaths

| Import | Provides | |---|---| | mjswan | createEngine, policyGraphRefs (the runtime library build) | | mjswan/manifest | parseManifest, sanitizeName, the Manifest types (the catalog parser) | | mjswan/observation | ObservationBase, ObservationConfig | | mjswan/command | CommandManager, command types and helpers | | mjswan/event | EventBase, event config and context types | | mjswan/termination | TerminationBase, termination config types | | mjswan/scene | Scene helpers (getPosition, getQuaternion, …) | | mjswan/npz | .npz loading (loadNpz, NpzEntry) | | mjswan/coordinate | MuJoCo ↔ three.js coordinate conversions | | mjswan/math | Quaternion / vector math utilities | | mjswan/types | Shared types (PolicyState, PolicyRunner, …) |

Links

License

Apache-2.0