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

miaoda-game-scenario-react

v0.3.1

Published

React DOM bindings for branching dialogue and scenario flows.

Readme

miaoda-game-scenario-react

Use this React DOM adapter for branching dialogue, visual-novel scenes, cutscenes, and event flows. The core owns script parsing, branching, variables, and execution; this adapter exposes pending commands and choices for your components.

Install

pnpm add miaoda-game-scenario-react miaoda-game-scenario-core

Minimal dialogue view

const game = useScenarioController({
  source: 'say Guard "Welcome"\nchoice "Enter" -> enter\nlabel enter\nexit',
});
const view = useScenarioView(game);

if (view.status === 'idle') void game.start();
return view.choices.length > 0
  ? view.choices.map((option) => (
      <button key={option.index} onClick={() => game.choose(option.index)}>{option.text}</button>
    ))
  : <button onClick={() => game.continueCommand()}>{view.pendingCommand?.args.join(' ')}</button>;

pendingCommand contains the command name and string arguments for your dialogue or host effect. Call continueCommand() when that effect is complete; call choose(index) for a displayed choice. view.status and view.error provide application state.

The controller uses Scenario Core's pull-choice mode internally. start() still remains pending across menus until the script completes, while the runner itself becomes quiescent whenever view.choices is displayed. Core therefore owns the exact available options and target labels; the React adapter does not maintain a second branching state.

Save and restore

Persist view.snapshot at a quiescent statement boundary. A displayed choice is safe: its snapshot has running: false, waiting: null, and a serializable pendingChoice. Restore it into a fresh controller with loadSnapshot(snapshot), call resume(), then render and resolve the restored view.choices normally. resume() remains pending until the player chooses and the script finishes.

Pending commands are not safe checkpoint boundaries because a host presentation or effect may already have started. For chapter saves, store the core memory and restart from a label. Do not call loadSnapshot() on a controller whose status is still running; use a fresh controller so an old execution chain cannot race the restored one.

Calling stop() while choices are displayed cancels the pending menu, changes the view status to stopped, and settles the controller's start()/resume() promise without choosing a branch.

Public API

ScenarioController, useScenarioController, useScenarioView, ScenarioView, and all scenario-core exports are available. React 18.2+ is required. The adapter does not style or render dialogue, choices, animation, or audio.

DialoguePlayer is re-exported for a shared typewriter/page model. Keep one instance for the component lifetime, subscribe its snapshot through React state or an external-store hook, and drive update(deltaSeconds) from a cancellable animation/timer effect. The component owns DOM measurement and passes pre-measured page strings; cleanup must cancel the timer, unsubscribe, and call player.cancel().