Skip to content

@fungi.computer/sprite

AssetPolicy = object

Host-owned admission and resource limits for published avatar artwork.

readonly baseURL: string

readonly allowedOrigins: readonly string[]

readonly maxBytes: number

Maximum bytes admitted for one response.

readonly maxTotalBytes: number

Cumulative bytes admitted across one character selection.

readonly maxRequests: number

Number of requests admitted for one character selection.

readonly optional fetch?: typeof fetch


Asset = object

Decoded transport bytes; adapters use these instead of opening their own URLs.

readonly url: string

readonly bytes: Uint8Array<ArrayBuffer>>

readonly contentType: string


Control = z.infer<typeof controlSchema>>

A validated, character-owned customization control.


Appearance = Readonly<Record<string, string | number | boolean>>>>

Values saved by the shell; no renderer objects or transient activity.


Customization = z.infer<typeof customizationSchema>>

A parsed, saved Sprite customization.


CharacterDocument = z.infer<typeof characterSchema>>

A portable character, with renderer data still awaiting its native decoder.


CharacterSource = string | { local: string; }

A served document URL or a host-installed character key.


AvatarPresentation = object

One complete request. Omitted customization resets to character defaults.

readonly src: CharacterSource

readonly optional activity?: string

readonly optional expression?: string

readonly optional appearance?: Appearance

readonly optional renderStyle?: RenderStyle

SVG filter drawn over the character; omitted draws it plain.


NativePresentation = object

The resolved activity and appearance passed to a native renderer.

readonly activity: string

readonly expression: string | null

readonly appearance: Appearance


NativePlayer = object

The adapter registers native destruction in the selection scope.

readonly activities: readonly string[]

readonly expressions: readonly string[]

set(presentation): void

Update the existing native instance.

NativePresentation

void

pause(paused): void

Pause or resume animation without losing the current frame.

boolean

void


RendererContext = object

Native renderer access to the selected document and its admitted assets.

readonly target: HTMLElement

readonly document: CharacterDocument

readonly signal: AbortSignal

readonly maxPixels: number

readonly reportError: (error) => void

Report a native failure that occurs after the renderer has become ready.

Error

void

readonly assetURL: (reference) => Effect.Effect<string, Error, Scope.Scope>>

Admit an asset and revoke its object URL when the selection closes.

string

Effect.Effect<string, Error, Scope.Scope>


Renderer = (context) => Effect.Effect<NativePlayer, Error, Scope.Scope>>

A native renderer whose resources live in the character selection scope.

RendererContext

Effect.Effect<NativePlayer, Error, Scope.Scope>


EffectivePresentation = NativePresentation & object

A request after native fallback and appearance validation.

readonly renderStyle: RenderStyle

readonly requestedActivity: string

readonly requestedExpression: string | null

readonly fallback: boolean


PlayerState = { status: "empty" | "loading" | "destroyed"; } | { status: "error"; error: Error; } | { status: "ready"; document: CharacterDocument; presentation: EffectivePresentation; updateError?: Error; }

Observable loading, ready, error, and disposal states.


LocalCharacter = object

An installed document and its renderer, loaded together by the shell.

readonly document: CharacterDocument

readonly render: Renderer


SpriteOptions = object

Host-owned character registry and resource policy.

readonly optional assets?: AssetPolicy

Omit for local-only characters; network access is denied by default.

readonly optional maxPixels?: number

readonly optional renderers?: Readonly<Record<string, () => Promise<{ default: Renderer; }>>>

Native adapters allowed for served character documents.

readonly optional characters?: Readonly<Record<string, () => Promise<LocalCharacter>>>>>>

Lazy local characters installed by this shell.


AvatarPlayer = object

One mounted avatar; dispose releases its native and browser resources.

readonly state: PlayerState

Current public state.

subscribe(listener): () => void

Observe state changes until the returned unsubscribe function is called.

(next) => void

() => void

set(next): void

Select a source or update its activity and appearance.

AvatarPresentation

void

pause(value): void

Pause or resume the current native animation.

boolean

void

dispose(): Promise<void>>

Cancel loading and release the current native selection.

Promise<void>


SpriteService = object

Stable shell configuration that creates independent mounted players.

mount(target): AvatarPlayer

Claim one DOM host for a new avatar instance.

HTMLElement

AvatarPlayer


RenderStyle = z.infer<typeof renderStyleSchema>>

How a Sprite is drawn over its native renderer.


RenderStyleLayer = object

The filter layer owned by one mounted player.

set(style, stage): void

Draw stage in style; plain removes the filter.

"plain" | "pencil" | "manga" | "riso" | "halftone" | "blueprint" | "crt" | "watercolor"

HTMLElement

void

still(value): void

Hold one still frame: paused, hidden, or reduced motion.

boolean

void

dispose(): void

Stop the boil and remove the filter and its definitions.

void

const controlSchema: ZodDiscriminatedUnion<[ZodObject<{ type: ZodLiteral<"number">>; label: ZodString; default: ZodNumber; min: ZodNumber; max: ZodNumber; step: ZodOptional<ZodNumber>>; }, $strict>>, ZodObject<{ type: ZodLiteral<"choice">>; label: ZodString; default: ZodString; options: ZodArray<ZodObject<{ value: ZodString; label: ZodString; }, $strict>>>>; }, $strict>>, ZodObject<{ type: ZodLiteral<"color">>; label: ZodString; default: ZodString; }, $strict>>, ZodObject<{ type: ZodLiteral<"boolean">>; label: ZodString; default: ZodBoolean; }, $strict>>], "type">>

Portable editor descriptors; native input bindings belong to each renderer.


const customizationSchema: ZodObject<{ appearance: ZodOptional<ZodRecord<ZodString, ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>>; renderStyle: ZodDefault<ZodEnum<{ plain: "plain"; pencil: "pencil"; manga: "manga"; riso: "riso"; halftone: "halftone"; blueprint: "blueprint"; crt: "crt"; watercolor: "watercolor"; }>>; }, $strict>>

What a person saves about their Sprite. Hosts parse stored values with this schema at their boundary; character controls still validate appearance against the selected document when it is presented.


const characterSchema: ZodObject<{ version: ZodLiteral<1>>; name: ZodString; renderer: ZodString; controls: ZodDefault<ZodRecord<ZodString, ZodDiscriminatedUnion<[ZodObject<{ type: ZodLiteral<"number">>; label: ZodString; default: ZodNumber; min: ZodNumber; max: ZodNumber; step: ZodOptional<ZodNumber>>; }, $strict>>, ZodObject<{ type: ZodLiteral<"choice">>; label: ZodString; default: ZodString; options: ZodArray<ZodObject<{ value: …; label: …; }, $strict>>>>; }, $strict>>, ZodObject<{ type: ZodLiteral<"color">>; label: ZodString; default: ZodString; }, $strict>>, ZodObject<{ type: ZodLiteral<"boolean">>; label: ZodString; default: ZodBoolean; }, $strict>>], "type">>>>>>; poster: ZodOptional<ZodString>>; data: ZodJSONSchema; }, $strict>>

Shared envelope only. The selected adapter must decode data before use.


const renderStyles: readonly ["plain", "pencil", "manga", "riso", "halftone", "blueprint", "crt", "watercolor"]

Render styles: an SVG filter drawn over a mounted Sprite. This module owns the style vocabulary, every filter definition, and the DOM layer that mounts one filter per player with ids unique to that player.


const renderStyleSchema: ZodEnum<{ plain: "plain"; pencil: "pencil"; manga: "manga"; riso: "riso"; halftone: "halftone"; blueprint: "blueprint"; crt: "crt"; watercolor: "watercolor"; }>

A saved render style; unknown names fail at the boundary.


const renderStyleLabels: object

Picker labels for each style, in display order.

readonly plain: "Plain" = "Plain"

readonly pencil: "Pencil" = "Pencil"

readonly manga: "Manga" = "Manga"

readonly riso: "Riso" = "Riso"

readonly halftone: "Halftone" = "Halftone"

readonly blueprint: "Blueprint" = "Blueprint"

readonly crt: "CRT" = "CRT"

readonly watercolor: "Watercolor" = "Watercolor"

resolveAppearance(controls, overrides?): Appearance

Validate the complete appearance before applying any native updates.

Readonly<Record<string, Control>>

Appearance = {}

Appearance


createSprite(options): SpriteService

Stable shell service; each mounted player owns its own selection.

SpriteOptions

SpriteService


createRenderStyleLayer(host): RenderStyleLayer

Mount a render-style layer in host. The filter applies only to the stage box, and its boil runs only while the host is on screen and not still.

HTMLElement

RenderStyleLayer