@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
| Version | Published | Integrity |
|---|---|---|
| 1.5.0 latest | 2026-11-24 | sha512-rFwBWptdI6Uztih… |
| 1.4.0 | 2026-10-03 | sha512-vizDtIg5r+WSrZa… |
| 1.3.1 | 2026-06-16 | sha512-o2DSNw39ZIQWWXV… |
| 1.3.0 | 2026-06-16 | sha512-chPHMM5tUNZnUzi… |
| 1.2.0 | 2026-06-15 | sha512-KkX/ap3izZWTzKf… |
| 1.0.0 | 2026-03-02 | sha512-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.
| Subpath | What you get | Needs a Redux store? | Repos using it |
|---|---|---|---|
@pixygon/anima | types + colour/label constants + animaThemeTokens. No React. | no | pixygon.io, CoreFeed, Animunda |
@pixygon/anima/components | 12 presentational components. Pure props-in. | no | all 5 |
@pixygon/anima/api | the RTK Query slice + 17 hooks | yes | Kartograf, 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
| Export | From | Use |
|---|---|---|
TYPE_COLORS / ELEMENT_COLORS / RARITY_COLORS | @pixygon/anima | the canonical palettes — don't fork them |
STAT_LABELS / CATEGORY_COLORS / NATURE_MODIFIERS | @pixygon/anima | stat rows, move chips, nature maths |
DISCOVERY_TIER_ORDER / _LABELS / _COLORS | @pixygon/anima | the 5 dex tiers (unknown→glimpsed→sensed→overcome→bonded) |
statToPercent(v, max=255) / xpToPercent(xp, next) | @pixygon/anima | bar fill maths |
animaThemeTokens | @pixygon/anima | MUI theme fragment (palette.anima.*, Chip overrides) |
Anima / AnimaSpecies / AnimaEgg / AnimaTrade / AnimaMove … | @pixygon/anima | 49 exported types |
configureAnimaApi({ baseUrl, getToken }) | @pixygon/anima/api | call once at app entry — see step 4 |
animaApi | @pixygon/anima/api | the slice: reducerPath: 'animaApi', tags Species/Anima/Egg/Trade/Move/Summary |
useGetSpeciesQuery() / useGetSpeciesByIdQuery(id) / useGetSpeciesLearnsetQuery(id) | @pixygon/anima/api | species catalogue |
useGetMovesQuery() | @pixygon/anima/api | move catalogue |
useGetUserAnimasQuery(userId) / useGetAnimaByIdQuery(id) / useGetUserSummaryQuery(userId) | @pixygon/anima/api | a user's collection |
useGetUserEggsQuery(userId) | @pixygon/anima/api | cores |
useGetUserTradesQuery(userId) / useGetTradeOfferQuery(tradeId) | @pixygon/anima/api | trades |
usePlaceAnimaMutation() / useSetTradeableMutation() / useUpdatePartyMutation() | @pixygon/anima/api | projection, trade lock, party order |
useCreateTradeMutation() / useAcceptTradeMutation() / useDeclineTradeMutation() / useCancelTradeMutation() | @pixygon/anima/api | the trade lifecycle |
<AnimaPage> | @pixygon/anima/components | the whole surface — 4 tabs over the four below |
<AnimaCollection> / <AnimaCores> / <Animadex> / <AnimaTrades> | @pixygon/anima/components | the individual tabs |
<AnimaCard> / <AnimaDetail> / <AnimaModelViewer> | @pixygon/anima/components | card, detail panel, 3D/sprite hero |
<StatBar> / <TypeBadge> / <ElementBadge> / <RarityChip> | @pixygon/anima/components | the primitives |
locale prop ('en' | 'nb') | every component above | the language; wins over the provider |
<AnimaLocaleProvider locale> / useAnimaLocale() / useAnimaStrings() / ANIMA_STRINGS / resolveAnimaLocale() | @pixygon/anima/components | the 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
_idvsid— this is a live bug, not a hypothetical. Every anima controller reads with Mongoose.lean(), so the JSON carries_idand not theidvirtual. But the package types declareid: string, andAnimaCollection/AnimaCores/AnimaTradesbothkey={x.id}and select onx.id. Feed API rows in raw and you getkey={undefined}on every card plus selection that never matches — an empty detail panel and dead clicks, with no console error. Animunda maps it (animas = monsters.map(m => ({ ...m, id: m._id }))); pixygon.io'sAnimaDashboard.tsxdoes not, and is broken today. Always remap:const animas = (data?.animas ?? []).map(a => ({ ...a, id: a._id }))AnimaModelViewerloads a script from unpkg.com. On first mount it appends<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js">todocument.head.AnimaCardandAnimaDetaildefaultshowHero={true}, soAnimaCollectionandAnimaPagepull it in transitively — you get a third-party CDN dependency just by rendering the collection tab. If the site has a CSP,script-srcmust includehttps://unpkg.com; if it is offline or air-gapped, the 3D hero degrades to sprite → emoji silently. PassshowHero={false}for text-only contexts. (pixygon.io'snginx.confCSP is currently Report-Only and omits unpkg.com — it doesn't block today, but it will the moment that policy is enforced.)- The list endpoints silently truncate. The server defaults
GET /animas/speciestolimit=100andGET /animas/user/:userId,/eggs/user/:userId,/trades/user/:userIdtolimit=50. The package's hooks send no query string at all, so past those counts data just stops arriving — the response'stotalfield is the only tell. Animunda works around it by calling its own fetch layer with{ limit: 200 }. If your roster is bigger than the default, you cannot use the plain hooks unchanged. - Reducer without middleware = eternal
isLoading. See step 5. It is the one wiring mistake that produces no error of any kind. configureAnimaApi()is global, not per-store. It mutates one module-level object. Two apps in one bundle, or a second call with a differentbaseUrl, and last-write-wins for everyone.AnimaPagerenders its own<Tabs>. Don't wrap it in another tab shell — pixygon.io deliberately uses the four sub-components directly instead, for exactly this reason.- Species are keyed by
speciesId, not_id.speciesMapin every component is built fromspecies.speciesId, andanima.speciesIdmust match it. Animunda has to remap (speciesId: m.species?._id ?? m.speciesId) because its legacy monster documents nest the species. If species art/name/types come up blank on otherwise-working cards, this join is why. - Colours belong to the roster, not to your site.
TYPE_COLORS/ELEMENT_COLORS/RARITY_COLORSare canon across the estate. Style the chrome around them from the site's own brand in@pixygon/design/tokens.mjs— don't recolour the creatures.
Publishing
npm run build && npm publish --access public