PPM

@pixygon/anima

Shared Anima types, API layer, and UI components for Pixygon apps

Install

# .npmrc
@pixygon:registry=https://ppm.pixygon.io/

npm install @pixygon/anima@1.5.0

Versions

VersionPublishedIntegrity
1.5.0 latest2026-11-24sha512-rFwBWptdI6Uztih…
1.4.0 2026-10-03sha512-vizDtIg5r+WSrZa…
1.3.1 2026-06-16sha512-o2DSNw39ZIQWWXV…
1.3.0 2026-06-16sha512-chPHMM5tUNZnUzi…
1.2.0 2026-06-15sha512-KkX/ap3izZWTzKf…
1.0.0 2026-03-02sha512-KdC38Lg5P4NhUGt…

@pixygon/anima

The Anima layer — the universe's creature roster as types, colours, an RTK Query client, and a set of MUI components. 5 repos depend on it (Kartograf, pixygon.io, CoreFeed, PixygonAdmin, Animunda); everything below is how those repos actually wire it, not an idealised example.

The data lives in PixygonAPI under /v1/animas — species, moves, eggs ("cores"), owned animas, and trades. There is one central roster; never build a per-pearl creature table.


Pick your mode first — this is the whole decision

The package ships three independent export subpaths. Which ones you import is the integration; nothing else about this package is hard.

SubpathWhat you getNeeds a Redux store?Repos using it
@pixygon/animatypes + colour/label constants + animaThemeTokens. No React.nopixygon.io, CoreFeed, Animunda
@pixygon/anima/components12 presentational components. Pure props-in.noall 5
@pixygon/anima/apithe RTK Query slice + 17 hooksyesKartograf, pixygon.io

3 of the 5 consumers never import /api. CoreFeed, PixygonAdmin and Animunda feed the components from their own fetch layer, and that is correct — not a gap to be closed. verify.mjs detects the mode and only applies the api-layer checks when /api is actually in play.

There is no data provider. No AnimaProvider, no data context, no useAnima(). Do not go looking for one. The only two contexts are optional and presentational: AnimaFormProvider (draws hatched animas) and AnimaLocaleProvider (the language, see Language below).


Retrofitting it into an existing app (≈10 minutes)

Written for an agent. Do these in order. If you are in components-only mode, stop after step 3.

1. Install

npm i @pixygon/anima@^1.3.0

⚠ MUI 7 is a hard floor. The components use the v7 <Grid size={{ xs: 12 }}> API. On MUI 5/6 that prop does not exist, so every grid silently collapses to full-width rows — no error, just a broken layout. Same for @mui/icons-material. If the repo is still on MUI 6, upgrade MUI first.

Peers: react >=18, react-dom >=18, @mui/material >=7, @mui/icons-material >=7, @emotion/react >=11, @emotion/styled >=11, and — only in api mode — @reduxjs/toolkit >=2, react-redux >=9.

2. Types + constants (free, no wiring)

import {
  TYPE_COLORS, ELEMENT_COLORS, RARITY_COLORS, STAT_LABELS,
  statToPercent, animaThemeTokens,
  type Anima, type AnimaSpecies, type AnimaEgg, type AnimaTrade,
} from '@pixygon/anima'

CoreFeed and Animunda re-export these under their own local names (AnimaType as MonsterType) so their legacy code keeps compiling while the colours stay estate-canonical. That is a good pattern — copy it rather than forking the palette.

3. Mount components (components-only mode ends here)

Every component is presentational: it takes arrays and callbacks, holds only local UI state, and touches neither Redux nor the network. Feed it from whatever data layer the app already has.

import { AnimaPage } from '@pixygon/anima/components'

<AnimaPage
  userId={userId}
  species={species}
  animas={animas}          // ← see the _id gotcha below, this WILL bite you
  eggs={eggs}
  trades={trades}
  onActivateEgg={handleHatch}
  onProjectAnima={handleProject}
  onSetTradeable={handleTradeable}
  onAcceptTrade={handleAccept}
  onDeclineTrade={handleDecline}
  onCancelTrade={handleCancel}
/>

AnimaPage is the whole surface — a 4-tab shell (Animas / Cores / Dex / Trades) over AnimaCollection, AnimaCores, Animadex, AnimaTrades. Animunda mounts exactly this from plain fetch, with no RTK at all.

The callbacks are the buttons. AnimaCollection/AnimaDetail render Project and Lock Trading only when onProjectAnima/onSetTradeable are passed; AnimaTrades renders Accept/Decline/Cancel only when onAccept/onDecline/onCancel are. Omit them and the buttons don't exist — silently. (pixygon.io currently omits all of them; see gotchas.)

Language: English or Norwegian (locale)

Every component takes an optional locale prop: 'en' (the default) or 'nb' (Norwegian bokmål). <AnimaPage locale="nb"> also sets the language of the four tabs inside it. To set it once for the whole app, wrap it in AnimaLocaleProvider; a component's own locale prop always wins over it.

import { AnimaPage, AnimaLocaleProvider } from '@pixygon/anima/components'

<AnimaPage {...props} locale="nb" />            // this page in Norwegian

<AnimaLocaleProvider locale={i18n.language}>  // or the whole app ('nb', 'no', 'nn', 'nb-NO' → Norwegian; anything else → English)
  <AnimaPage {...props} />
</AnimaLocaleProvider>

With no prop and no provider the components render exactly the English they always did. Norwegian covers every label, tab, button, empty state and count, and the game terms (types, elements, rarities, natures, trade statuses, dex tiers, stat labels); the stored values stay the English keys. Names are kept: Anima, Animas, Animadex, Dex. Species, move, ribbon and app names are data and are shown as they come. useAnimaStrings(locale?) and ANIMA_STRINGS give an app the same words for its own UI around the components.

4. Configure the API layer — the step that silently breaks everything

baseUrl defaults to ''. If configureAnimaApi() never runs, every hook requests /species, /user/<id>, /trades/... same-origin-relative — your own SPA host — gets the index.html 404 shell back, and fails to parse. Nothing throws a useful error.

The real namespace is <API>/v1/animas (PixygonAPI routes_v1/routes.js: router.use("/animas", animaRoutes)).

// src/main.tsx — Kartograf
import { configureAnimaApi } from '@pixygon/anima/api'

const API_URL = import.meta.env.VITE_API_URL || 'https://api.pixygon.io/v1'
configureAnimaApi({
  baseUrl: `${API_URL}/animas`,
  getToken: () => store.getState().global.token,
})

Both config keys matter. baseUrl is read at query time, not at module load, so it is enough that configureAnimaApi() runs before the first hook renders — but it must. getToken feeds Authorization: Bearer on every request; only GET /species* and GET /moves accept an API key instead. Every /user/:id, /eggs, /trades route and every mutation is verifyToken-protected, so a () => null token means permanently empty collections with no error surfaced to the user.

5. Register the slice in the store — both halves

// src/store/store.ts — Kartograf
import { animaApi } from '@pixygon/anima/api'

const rootReducer = combineReducers({
  …,
  [animaApi.reducerPath]: animaApi.reducer,      // half 1
})

export const store = configureStore({
  reducer: rootReducer,
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({ … }).concat(kartografApi.middleware, animaApi.middleware),  // half 2
})

reducerPath is the literal string 'animaApi'. Adding the reducer without the middleware is the nastiest failure mode in this package: the cache slice exists so React Redux is happy and nothing throws, but no request is ever dispatched and every hook sits at isLoading: true forever. verify.mjs reports that case with its own distinct message.

And the store needs a <Provider store={store}> above anything using the hooks.

6. Use the hooks

import {
  useGetSpeciesQuery, useGetUserAnimasQuery, useGetUserEggsQuery,
  useGetUserTradesQuery, useGetMovesQuery,
} from '@pixygon/anima/api'

const { data: animasData } = useGetUserAnimasQuery(userId, { skip: !userId })
const { data: speciesData } = useGetSpeciesQuery()

const animas  = (animasData?.animas ?? []).map(a => ({ ...a, id: a._id }))  // ← required
const species = speciesData?.species ?? []

src/pages/AnimaDashboard.tsx in pixygon.io is the canonical hooks→components page. (It is also missing that .map, which is gotcha #1.)

7. Verify it worked

node node_modules/@pixygon/anima/verify.mjs
# or, from Dyson's registry:
pearl verify anima

Mode-aware static check — dependency + installed version, which subpaths are in use, peer floors, and (api mode only) configureAnimaApi, baseUrl/getToken, reducer and middleware, and <Provider>. It prints the detected mode and never fails a legitimate components-only repo. Exit 0 pass, 1 fail.

Add a live probe of the namespace:

node node_modules/@pixygon/anima/verify.mjs --url=https://api.pixygon.io/v1/animas
node node_modules/@pixygon/anima/verify.mjs --url=… --token=<jwt>     # asserts real species come back

Without a token a 401 is the pass — it proves the route exists and is guarded. A 404 means your baseUrl is wrong.

What verify can and cannot prove. It proves the package is installed, imported, and — in api mode — configured against a real store. It cannot prove configureAnimaApi() ran before the first hook fired, that the token is unexpired, that the env var behind baseUrl is defined in the deployed build (an undefined VITE_* yields "undefined/animas" and still passes), or that a single component rendered a single row. The components are pure props-in: an empty array and the _id/id mismatch below both produce an empty-but-passing UI. Open the page and count creatures.


API

ExportFromUse
TYPE_COLORS / ELEMENT_COLORS / RARITY_COLORS@pixygon/animathe canonical palettes — don't fork them
STAT_LABELS / CATEGORY_COLORS / NATURE_MODIFIERS@pixygon/animastat rows, move chips, nature maths
DISCOVERY_TIER_ORDER / _LABELS / _COLORS@pixygon/animathe 5 dex tiers (unknown→glimpsed→sensed→overcome→bonded)
statToPercent(v, max=255) / xpToPercent(xp, next)@pixygon/animabar fill maths
animaThemeTokens@pixygon/animaMUI theme fragment (palette.anima.*, Chip overrides)
Anima / AnimaSpecies / AnimaEgg / AnimaTrade / AnimaMove …@pixygon/anima49 exported types
configureAnimaApi({ baseUrl, getToken })@pixygon/anima/apicall once at app entry — see step 4
animaApi@pixygon/anima/apithe slice: reducerPath: 'animaApi', tags Species/Anima/Egg/Trade/Move/Summary
useGetSpeciesQuery() / useGetSpeciesByIdQuery(id) / useGetSpeciesLearnsetQuery(id)@pixygon/anima/apispecies catalogue
useGetMovesQuery()@pixygon/anima/apimove catalogue
useGetUserAnimasQuery(userId) / useGetAnimaByIdQuery(id) / useGetUserSummaryQuery(userId)@pixygon/anima/apia user's collection
useGetUserEggsQuery(userId)@pixygon/anima/apicores
useGetUserTradesQuery(userId) / useGetTradeOfferQuery(tradeId)@pixygon/anima/apitrades
usePlaceAnimaMutation() / useSetTradeableMutation() / useUpdatePartyMutation()@pixygon/anima/apiprojection, trade lock, party order
useCreateTradeMutation() / useAcceptTradeMutation() / useDeclineTradeMutation() / useCancelTradeMutation()@pixygon/anima/apithe trade lifecycle
<AnimaPage>@pixygon/anima/componentsthe whole surface — 4 tabs over the four below
<AnimaCollection> / <AnimaCores> / <Animadex> / <AnimaTrades>@pixygon/anima/componentsthe individual tabs
<AnimaCard> / <AnimaDetail> / <AnimaModelViewer>@pixygon/anima/componentscard, detail panel, 3D/sprite hero
<StatBar> / <TypeBadge> / <ElementBadge> / <RarityChip>@pixygon/anima/componentsthe primitives
locale prop ('en' | 'nb')every component abovethe language; wins over the provider
<AnimaLocaleProvider locale> / useAnimaLocale() / useAnimaStrings() / ANIMA_STRINGS / resolveAnimaLocale()@pixygon/anima/componentsthe language for a whole tree, and the words themselves

Config

configureAnimaApi({
  baseUrl?: string            // REQUIRED in practice — default '' means same-origin-relative 404s.
                              // Must be <API>/v1/animas
  getToken?: () => string | null   // default () => null. Everything except
                                   // GET /species* and GET /moves needs a real Bearer token
})

Gotchas

Publishing

npm run build && npm publish --access public

All packages · packument JSON