Six ways in, from one HTML tag to a SwiftUI screen. The four web examples run the code they show, right beside it: press things. The iOS and Android examples show their code beside a recording from the simulator and the emulator, in the demo app.
Every web example loads the player from jsDelivr, pinned to version 0.2.5. In a bundler, run npm install wisp-anim and import load from wisp-anim/player.
1
Web · HTML
One tag
<wisp-player> takes src, pointer, fit, seed, autoplay and rest. It stops drawing when nothing moves.
Running: drag the slider, press Warning, watch the line under it.
3
Web · React
A React component
Twenty lines around the same player: it loads once per src and pushes your state into the animation's inputs.
WispAnimation.jsx
import { useEffect, useRef, useState } from "react";
import { load } from "wisp-anim/player";// A Wisp animation as a React component. It loads once
// per `src` and pushes every change in `inputs` into the
// running animation.
export function WispAnimation(props) {
const { src, inputs = {}, onEvent, style } = props;
const canvas = useRef(null);
const [player, setPlayer] = useState(null);
useEffect(() => {
let p = null, gone = false;
const opts = { pointer: "canvas" };
load(src, canvas.current, opts).then((loaded) => {
if (gone) loaded.destroy();
else setPlayer((p = loaded));
});
return () => {
gone = true;
p?.destroy();
setPlayer(null);
};
}, [src]);
useEffect(() => {
for (const [name, value] of Object.entries(inputs)) {
player?.set(name, value);
}
}, [player, inputs]);
useEffect(() => {
if (!player || !onEvent) return;
return player.on("event", onEvent);
}, [player, onEvent]);
const size = { width: "100%", ...style };
return <canvas ref={canvas} style={size} />;
}
// Using it: the switch follows your app's state.
export function LampSwitch() {
const [on, setOn] = useState(false);
return (
<div>
<WispAnimation
src="./examples/hello/toggle.wisp.json"
inputs={{ on }}
style={{ aspectRatio: "300 / 180" }}
/>
<button onClick={() => setOn(!on)}>
{on ? "Turn it off" : "Turn it on"}
</button></div>
);
}
Running: this is <LampSwitch /> from the file on the left, rendered by React 19 on this page.
4
Anywhere · one file
One self-contained HTML file
The export holds the player and the document in a single file with nothing to fetch. Attach it to an email, drop it in a CMS, or put it in an <iframe>.
Running: the file this command wrote when this site was built. Click Kibo, or press its poke button.
5
iOS and Android
The same file in a native app
Today a phone app builds the library from a clone of this repository with a script (scripts/build-xcframework.sh for iOS, scripts/use-core.sh for Android); prebuilt packages are not published yet. It has run on the iOS simulator and an Android emulator, not yet on a physical phone.
5 iOS, SwiftUI
OnboardingScreen.swift
import SwiftUI
import WispKit
@MainActor
struct OnboardingScreen: View {
@State private var player: WispView?
var body: some View {
VStack {
if let player {
WispPlayerView(player: player)
Button("Next") {
player.setNumber("page", 1)
}
} else {
ProgressView()
}
}
.task {
guard player == nil else { return }
player = try? WispView(
resource: "onboarding.wisp.json")
}
}
}
WispKit is a Swift package on the Rust core (setup).