@usenavii/core

Framework-agnostic engine. Seed in, SVG string out. Pure TypeScript, zero runtime dependencies, ~8 KB gzipped target.

Install

npm i @usenavii/core
# or pnpm / yarn / bun

Functions

createAvatar(seed: string, options?: AvatarOptions): string
selectAvatar(seed: string, options?: AvatarOptions): AvatarSpec
renderAvatar(spec:  AvatarSpec, options?: AvatarOptions): string
renderAvatarInner(spec: AvatarSpec, options?: AvatarOptions): string
renderGroup(seeds:  string[], options?: GroupOptions): string

createAvatar is the convenience composition of selectAvatar + renderAvatar. Use the split pair when you want to inspect or mutate the spec between picking and rendering.

renderAvatarInner emits the SVG body without an outer <svg> wrapper — useful when composing multiple avatars into one SVG document (this is how renderGroup works internally).

AvatarOptions

OptionTypeDefaultDescription
sizenumber (px)96Output canvas size. SVG viewBox is fixed at 100×100; size scales it.
paletteIdstringseededForce a specific palette. Pass any palette id.
backgroundenum or { color: string }seededOverride scene fill. Enum form picks from 'none' | 'solid' | 'ring'; object form supplies an exact color.
titlestringAdds role="img" and aria-label.
animatedbooleanfalseEmits inline <style> with idle animations. Honors prefers-reduced-motion.
tileBgstringOpaque circular fill behind avatar. Any CSS color or 'auto' to use palette accent.

AvatarSpec

The resolved description of an individual avatar — what selectAvatar returns and what renderAvatar consumes.

interface AvatarSpec {
  seed:       string;
  palette:    Palette;
  body:       BodyShapeId;
  eyes:       EyeStyleId;
  mouth:      MouthStyleId;
  antenna:    AntennaStyleId;
  accessory:  AccessoryId;
  background: BackgroundId;
  topper:     TopperId;

  // Continuous tweaks
  hueShift:        number;  // degrees, signed
  bodyScale:       number;  // 0.92–1.08
  eyeGapShift:     number;  // px (viewBox units), signed
  mouthCurveScale: number;  // 0.85–1.15
  antennaTilt:     number;  // degrees, signed
}

All *Id types are string unions. Palette is an object: { id, bodyFrom, bodyTo, accent, ink, blush }.

Advanced: composition

The split selectAvatar + renderAvatar lets you override any part programmatically — not just the two the HTTP API exposes.

import { selectAvatar, renderAvatar } from '@usenavii/core';

const base = selectAvatar('alice');
const svg = renderAvatar({ ...base, body: 'tall', eyes: 'star' }, { size: 128 });

GroupOptions

Extends AvatarOptions with these additional fields:

OptionTypeDefaultDescription
sizenumber64Per-tile size.
overlapnumber0.3Tile overlap fraction (0–0.7).
maxnumberallCap tiles; remainder collapses into +N.
ringstring#ffffffBorder ring around each tile.
tileBgstring#ffffffSolid fill behind each avatar.
counterFillstring#E5E7EBBackground of the +N tile.
counterInkstring#374151Text color of the +N tile.

Other exports

  • createRng(seed) — the PRNG used internally. Returns { next(), range(min, max), pick(arr) }.
  • cyrb53(string) — fast 53-bit string hash. Used to seed the PRNG.
  • @usenavii/core/parts subpath — exports the part-id arrays (BODY_IDS, EYE_IDS, etc.) and PALETTES.