Pixel buddy

Slant / People & chat

A seeded slanted-pixel avatar: one buddy per seed.

Demo

Usage

@tuttn/slant
import { PixelBuddy, buddySpec, seededBuddy } from '@tuttn/slant'

// Seeded: the same id always draws the same buddy.
<PixelBuddy seed={user.id} />

// Named for screen readers, and floating while it works.
<PixelBuddy seed={session.id} size={64} motion="working" label="Assistant, working" />

// A customization saved from AvatarEditor replaces the seeded look.
<PixelBuddy seed={user.id} avatar={user.avatar} />

// The data underneath: the starting customization, and what to draw.
seededBuddy(user.id)          // { version: 1, color: { kind: 'palette', id }, face, accent, accessory: 'none' }
buddySpec(user.id, saved)     // { fill, ink, face, accent, accessory }

Props

PropTypeDefaultDescription
seedstring—What the buddy is drawn from: a user or session id, an email, any stable string. The same seed always draws the same buddy.
avatarAvatarCustomization—A saved customization (from AvatarEditor), which replaces the seeded colour, face, accent and accessory.
sizenumber40Width and height, in pixels.
motion'rest' | 'working''rest'`rest` stands still and hops when a mouse passes over it; `working` floats and blinks, for someone busy: an agent thinking, a person typing.
labelstring—Names the buddy for screen readers (`role="img"`). Omitted, it is decorative and `aria-hidden`.
runningbooleantrueFalse holds the buddy still in its resting pose. It also rests off screen, in a hidden tab and under reduced motion.
…restSVGAttributes<SVGSVGElement>—className, style, the ref and other attributes go on the <svg>.

One seed, one buddy

A 32-bit FNV-1a hash of the seed picks the colour, the face and the accent from separate bits, so the same seed draws the same buddy on every visit and every device, and nothing leaves the browser to make it. Seeded buddies wear nothing; an accessory comes only from a customization. seededBuddy(seed) returns the seeded buddy as a customization (where an AvatarEditor starts), and buddySpec(seed, avatar) resolves what to draw. The tables are exported as buddyPalette, buddyFaces, buddyAccents and buddyAccessories.

The identity palette

A buddy's body colours are fixed brand colours, not theme tokens, so a person keeps their buddy in Sage, Moon, Ember and Paper alike: the one documented exception to Slant's tokens-only rule (the blush, shine and shade accents belong to the same palette). Every palette ink keeps at least 3:1 against its fill, the non-text contrast minimum. A custom fill takes whichever of the two inks reads better on it, and a custom fill that is not #RRGGBB falls back to the seeded colour. The ground under a working buddy and the motion come from the theme.

Accessibility

A buddy is decorative and aria-hidden by default, as it usually sits beside a visible name (use it in place of Avatar's initials). Given a label, it is role="img" with that name.

Motion

motion="working" floats and blinks, each buddy at its own point in the loop, so a row of busy sessions never bobs in step. A resting buddy stands still. Under a mouse, any running buddy hops once with a squash and stretch. Off screen, in a hidden tab or with running={false}, the buddy stands in its resting pose, on the ground with its eyes open, and the svg drops data-running. Under reduced motion it rests there too, and never hops.