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

codex-pet-web-react

v0.3.1

Published

React wrapper for Codex pet spritesheets.

Readme

codex-pet-web-react

React wrapper for rendering Codex pet spritesheets in web products.

Install

npm install codex-pet-web-react codex-pet-web

react is a peer dependency.

Next.js

codex-pet-web-react is client-only and ships "use client" markers. In a Next.js App Router app, import it from a client component and render that client component from your layout or page:

"use client";

import { CodexPet, CodexPetProvider } from "codex-pet-web-react";

export function PetLayer() {
  return (
    <CodexPetProvider
      pets={{
        assistant: {
          spritesheetUrl: "/codex-pets/sapling/spritesheet.webp",
          scale: 0.45,
          floating: { x: 24, y: 24 },
          draggable: true
        }
      }}
    >
      <CodexPet id="assistant" />
    </CodexPetProvider>
  );
}

Basic Usage

import { CodexPet } from "codex-pet-web-react";

export function PetPreview() {
  return (
    <CodexPet
      spritesheetUrl="/pets/sapling/spritesheet.webp"
      state="idle"
      scale={2}
    />
  );
}

Add Pet Assets

spritesheetUrl must point at a public asset. To use the examples bundled with codex-pet-web, copy them into your app:

mkdir -p public/codex-pets
cp -R node_modules/codex-pet-web/example-pets/* public/codex-pets/

Then render one:

<CodexPet
  spritesheetUrl="/codex-pets/carrot/spritesheet.webp"
  state="idle"
/>

Floating And Dragging

<CodexPet
  draggable
  floating={{ x: 24, y: 24, zIndex: 100 }}
  spritesheetUrl="/pets/sapling/spritesheet.webp"
  onPetDragEnd={({ x, y }) => {
    console.log("pet position", x, y);
  }}
/>

Use a ref to move a floating pet programmatically:

const ref = useRef<CodexPetHandle>(null);

ref.current?.setPosition({ x: 48, y: 48 });

During drag, horizontal movement automatically switches the pet to running-left or running-right. When the pointer is released, it restores the previous base state and plays one jumping loop before returning to that state.

Provider And Hooks

Use CodexPetProvider when pet state should survive route or component changes, or when one app controls multiple pets:

import {
  CodexPet,
  CodexPetProvider,
  useCodexPet,
  useCodexPetRandomActions
} from "codex-pet-web-react";

function AssistantControls() {
  const pet = useCodexPet("assistant");

  useCodexPetRandomActions("assistant", {
    averageIntervalSeconds: 120,
    minIntervalSeconds: 45,
    maxIntervalSeconds: 300,
    actions: [
      { state: "waving", weight: 3 },
      { state: "jumping", weight: 2 },
      { state: "waiting", weight: 1 },
      { state: "review", weight: 1 }
    ]
  });

  return (
    <>
      <button onClick={() => pet.play("waving")}>Wave</button>
      <button onClick={() => pet.hide()}>Hide</button>
      <button onClick={() => pet.show()}>Show</button>
    </>
  );
}

export function AppPet() {
  return (
    <CodexPetProvider
      pets={{
        assistant: {
          spritesheetUrl: "/codex-pets/sapling/spritesheet.webp",
          scale: 0.45,
          floating: { x: 24, y: 24 },
          draggable: true
        }
      }}
    >
      <AssistantControls />
      <CodexPet id="assistant" aria-label="Assistant pet" />
    </CodexPetProvider>
  );
}

The provider is a thin React adapter over the core registry. The core controller owns behavior; React only binds a DOM node to it.

Controlled State

<CodexPet
  spritesheetUrl="/pets/sapling/spritesheet.webp"
  state={isLoading ? "running" : "idle"}
/>

Use stateFps to keep idle calm without slowing action states:

<CodexPet
  fps={8}
  stateFps={{ idle: 2, waiting: 3 }}
  spritesheetUrl="/pets/sapling/spritesheet.webp"
/>

Temporary Actions

Use a ref for short-lived actions. Props remain the persistent source of truth.

import { useRef } from "react";
import { CodexPet, type CodexPetHandle } from "codex-pet-web-react";

export function ActionPet() {
  const pet = useRef<CodexPetHandle>(null);

  return (
    <CodexPet
      ref={pet}
      spritesheetUrl="/pets/sapling/spritesheet.webp"
      state="idle"
      onClick={() => pet.current?.play("waving", { loops: 1 })}
      onDoubleClick={() => pet.current?.setState("running", { interrupt: true })}
      onAnimationEnd={({ state }) => console.log(`${state} finished`)}
    />
  );
}

The component does not re-render every animation frame. It mounts one DOM node and lets codex-pet-web update background position directly.

Pass { interrupt: true } to setState when the new persistent state should cancel a temporary action started with play.

Accessibility

Pets are decorative by default. Add aria-label when a pet is meaningful:

<CodexPet
  aria-label="Sapling pet"
  spritesheetUrl="/pets/sapling/spritesheet.webp"
/>