SDK & Types

Everything you need to interact with the package programmatically.
SDK

1. Package Installation

The @usespaceui/avatars package renders SVG markup synchronously. It has no raster encoder: PNG and WebP are provided by the HTTP API.

Installation

React

2. React Component Usage

Import <Avatar /> to render SVG avatars directly as React JSX elements.

Constants

3. Runtime Object Constants

Use exported runtime object constants (AvatarFamily AvatarEffect, AvatarVariant, AvatarOutputFormat) for clean dot-notation autocompletion. They are values, not functions, so they do not return anything. AvatarOutputFormat applies only to package output: SVG or JSON.

TypeScript

4. TypeScript Types

TypeScript types such as AvatarProps, CreateAvatarOptions, AvatarColors, AvatarJson, and AvatarDetails only exist during type checking and will not be compiled into your bundle.

Generator

5. Pure TS createAvatar(options) Function

createAvatar(options) generates deterministic avatar output. Set format: AvatarOutputFormat.svg (default) to return an SVG string, or format: AvatarOutputFormat.json to return a structured JSON object with dataURIs.

Functions

6. Resolving Variants

resolveVariant turns a variant or family into one concrete variant. Use getFamilyVariants to list the variants belonging to a specific family.

FunctionReturn TypeDescription
resolveVariant(value)AvatarVariantResolves a concrete variant or a deterministic variant from a family.
getFamilyVariants(family)AvatarVariant[]Lists the concrete variants in one family; an unknown family gives an empty list.
Functions

7. Inspecting Capabilities

Metadata functions expose the catalog and capabilities without duplicating constants.

FunctionReturn TypeDescription
getAvatarDetails(variant)AvatarDetails | undefinedReturns one capability record; an unknown variant returns undefined.
getAllAvatarDetails()AvatarDetails[]Returns detached capability records for every variant.
Functions

8. Animation Capability Check

Verify if a variant supports animation for a particular effect dynamically.

FunctionReturn TypeDescription
isAnimateActive(variant, effect)booleanTrue only when animation can run for that variant and effect combination.