Skip to content
API reference

sprite

Import
import * as api from "@fungi.computer/sprite";
Kind Export Description
type alias AssetPolicy Host-owned admission and resource limits for published avatar artwork.
type alias Asset Decoded transport bytes; adapters use these instead of opening their own URLs.
type alias Control A validated, character-owned customization control.
type alias Appearance Values saved by the shell; no renderer objects or transient activity.
type alias Customization A parsed, saved Sprite customization.
type alias CharacterDocument A portable character, with renderer data still awaiting its native decoder.
type alias Json An opaque JSON value; the selected adapter owns its schema.
type alias CharacterSource A served document URL or a host-installed character key.
type alias AvatarPresentation One complete request. Omitted customization resets to character defaults.
type alias NativePresentation The resolved activity and appearance passed to a native renderer.
type alias NativePlayer The adapter registers native destruction in the selection scope.
type alias RendererContext Native renderer access to the selected document and its admitted assets.
type alias Renderer A native renderer whose resources live in the character selection scope.
type alias EffectivePresentation A request after native fallback and appearance validation.
type alias PlayerState Observable loading, ready, error, and disposal states.
type alias LocalCharacter An installed document and its renderer, loaded together by the shell.
type alias SpriteOptions Host-owned character registry and resource policy.
type alias AvatarPlayer One mounted avatar; dispose releases its native and browser resources.
type alias SpriteService Stable shell configuration that creates independent mounted players.
type alias RenderStyle How a Sprite is drawn over its native renderer.
type alias RenderStyleLayer The filter layer owned by one mounted player.
constant controlSchema Portable editor descriptors; native input bindings belong to each renderer.
constant customizationSchema 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.
constant characterSchema Shared envelope only. The selected adapter must decode data before use.
constant renderStyles 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.
constant renderStyleSchema A saved render style; unknown names fail at the boundary.
constant renderStyleLabels Picker labels for each style, in display order.
function resolveAppearance() Validate the complete appearance before applying any native updates.
function createSprite() Stable shell service; each mounted player owns its own selection.
function createRenderStyleLayer() 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.

AssetPolicytype alias

Section titled “AssetPolicy”
Signature
type AssetPolicy = object;

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

Signature
readonly baseURL: string;
Signature
readonly allowedOrigins: readonly string[];
Signature
readonly maxBytes: number;

Maximum bytes admitted for one response.

Signature
readonly maxTotalBytes: number;

Cumulative bytes admitted across one character selection.

Signature
readonly maxRequests: number;

Number of requests admitted for one character selection.

Signature
readonly optional fetch?: typeof fetch;

Signature
type Asset = object;

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

Signature
readonly url: string;
Signature
readonly bytes: Uint8Array<ArrayBuffer>;
Signature
readonly contentType: string;

Signature
type Control = z.infer<typeof controlSchema>;

A validated, character-owned customization control.


Appearancetype alias

Section titled “Appearance”
Signature
type Appearance = Readonly<Record<string, string | number | boolean>>;

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


Customizationtype alias

Section titled “Customization”
Signature
type Customization = z.infer<typeof customizationSchema>;

A parsed, saved Sprite customization.


CharacterDocumenttype alias

Section titled “CharacterDocument”
Signature
type CharacterDocument = z.infer<typeof characterSchema>;

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


Signature
type Json = CharacterDocument["data"];

An opaque JSON value; the selected adapter owns its schema.


CharacterSourcetype alias

Section titled “CharacterSource”
Signature
type CharacterSource =
| string
| {
local: string;
};

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


AvatarPresentationtype alias

Section titled “AvatarPresentation”
Signature
type AvatarPresentation = object;

One complete request. Omitted customization resets to character defaults.

Signature
readonly optional timeMs?: number;

Optional host clock in milliseconds; native animation seeks instead of running live.

Signature
readonly src: CharacterSource;
Signature
readonly optional activity?: string;
Signature
readonly optional expression?: string;
Signature
readonly optional appearance?: Appearance;
Signature
readonly optional renderStyle?: RenderStyle;

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

Signature
readonly optional performance?: Json;

Renderer data for this presentation; Sprite never reads it. It is compared by identity, so keep the reference stable (for example with useMemo); a new object each render makes the renderer’s set run every time.


NativePresentationtype alias

Section titled “NativePresentation”
Signature
type NativePresentation = object;

The resolved activity and appearance passed to a native renderer.

Signature
readonly optional timeMs?: number;

Absolute animation time in milliseconds, when controlled by the host.

Signature
readonly activity: string;
Signature
readonly expression: string | null;
Signature
readonly appearance: Appearance;
Signature
readonly optional performance?: Json;

The request’s performance, unchanged and compared by identity.


NativePlayertype alias

Section titled “NativePlayer”
Signature
type NativePlayer = object;

The adapter registers native destruction in the selection scope.

Signature
readonly activities: readonly string[];
Signature
readonly expressions: readonly string[];
Signature
set(presentation): void;

Update the existing native instance.

Parameter Type
presentation NativePresentation

void

Signature
pause(paused): void;

Pause or resume animation without losing the current frame.

Parameter Type
paused boolean

void


RendererContexttype alias

Section titled “RendererContext”
Signature
type RendererContext = object;

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

Signature
readonly target: HTMLElement;
Signature
readonly document: CharacterDocument;
Signature
readonly signal: AbortSignal;
Signature
readonly maxPixels: number;
Signature
readonly reportError: (error) => void;

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

Parameter Type
error Error

void

Signature
readonly reportProgress: (progress) => void;

Publish renderer progress on the ready state; ignored once the selection closes.

Parameter Type
progress Json

void

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

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

Parameter Type
reference string

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


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

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

Parameter Type
context RendererContext

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


EffectivePresentationtype alias

Section titled “EffectivePresentation”
Signature
type EffectivePresentation = NativePresentation & object;

A request after native fallback and appearance validation.

Name Type
renderStyle RenderStyle
requestedActivity string
requestedExpression string | null
fallback boolean

PlayerStatetype alias

Section titled “PlayerState”
Signature
type PlayerState =
| {
status: "empty" | "loading" | "destroyed";
}
| {
status: "error";
error: Error;
}
| {
status: "ready";
document: CharacterDocument;
presentation: EffectivePresentation;
updateError?: Error;
progress?: Json;
};

Observable loading, ready, error, and disposal states.

Signature
{
status: "empty" | "loading" | "destroyed";
}

Signature
{
status: "error";
error: Error;
}

Signature
{
status: "ready";
document: CharacterDocument;
presentation: EffectivePresentation;
updateError?: Error;
progress?: Json;
}
Name Type Description
status "ready" -
document CharacterDocument -
presentation EffectivePresentation -
updateError? Error -
progress? Json The latest value the renderer passed to reportProgress.

LocalCharactertype alias

Section titled “LocalCharacter”
Signature
type LocalCharacter = object;

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

Signature
readonly document: CharacterDocument;
Signature
readonly render: Renderer;

SpriteOptionstype alias

Section titled “SpriteOptions”
Signature
type SpriteOptions = object;

Host-owned character registry and resource policy.

Signature
readonly optional assets?: AssetPolicy;

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

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

Native adapters allowed for served character documents.

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

Lazy local characters installed by this shell.


AvatarPlayertype alias

Section titled “AvatarPlayer”
Signature
type AvatarPlayer = object;

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

Signature
readonly state: PlayerState;

Current public state.

Signature
subscribe(listener): () => void;

Observe state changes until the returned unsubscribe function is called.

Parameter Type
listener (next) => void

() => void

Signature
set(next): void;

Select a source or update its activity and appearance.

Parameter Type
next AvatarPresentation

void

Signature
pause(value): void;

Pause or resume the current native animation.

Parameter Type
value boolean

void

Signature
dispose(): Promise<void>;

Cancel loading and release the current native selection.

Promise<void>


SpriteServicetype alias

Section titled “SpriteService”
Signature
type SpriteService = object;

Stable shell configuration that creates independent mounted players.

Signature
mount(target): AvatarPlayer;

Claim one DOM host for a new avatar instance.

Parameter Type
target HTMLElement

AvatarPlayer


RenderStyletype alias

Section titled “RenderStyle”
Signature
type RenderStyle = z.infer<typeof renderStyleSchema>;

How a Sprite is drawn over its native renderer.


RenderStyleLayertype alias

Section titled “RenderStyleLayer”
Signature
type RenderStyleLayer = object;

The filter layer owned by one mounted player.

Signature
set(style, stage): void;

Draw stage in style; plain removes the filter.

Parameter Type
style | "plain" | "pencil" | "manga" | "riso" | "halftone" | "blueprint" | "crt" | "watercolor"
stage HTMLElement

void

Signature
still(value): void;

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

Parameter Type
value boolean

void

Signature
dispose(): void;

Stop the boil and remove the filter and its definitions.

void

controlSchemaconstant

Section titled “controlSchema”
Signature
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.


customizationSchemaconstant

Section titled “customizationSchema”
Signature
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.


characterSchemaconstant

Section titled “characterSchema”
Signature
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.


renderStylesconstant

Section titled “renderStyles”
Signature
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.


renderStyleSchemaconstant

Section titled “renderStyleSchema”
Signature
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.


renderStyleLabelsconstant

Section titled “renderStyleLabels”
Signature
const renderStyleLabels: object;

Picker labels for each style, in display order.

Name Type Default value
plain "Plain" "Plain"
pencil "Pencil" "Pencil"
manga "Manga" "Manga"
riso "Riso" "Riso"
halftone "Halftone" "Halftone"
blueprint "Blueprint" "Blueprint"
crt "CRT" "CRT"
watercolor "Watercolor" "Watercolor"

resolveAppearance()function

Section titled “resolveAppearance()”
Signature
function resolveAppearance(controls, overrides?): Appearance;

Validate the complete appearance before applying any native updates.

Parameter Type
controls Readonly<Record<string, Control>>
overrides Appearance

Appearance


createSprite()function

Section titled “createSprite()”
Signature
function createSprite(options): SpriteService;

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

Parameter Type
options SpriteOptions

SpriteService


createRenderStyleLayer()function

Section titled “createRenderStyleLayer()”
Signature
function 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.

Parameter Type
host HTMLElement

RenderStyleLayer