sprite
Import
Section titled “Import”import * as api from "@fungi.computer/sprite";Exports
Section titled “Exports”| 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”type AssetPolicy = object;Host-owned admission and resource limits for published avatar artwork.
Properties
Section titled “Properties”baseURL
Section titled “baseURL”readonly baseURL: string;allowedOrigins
Section titled “allowedOrigins”readonly allowedOrigins: readonly string[];maxBytes
Section titled “maxBytes”readonly maxBytes: number;Maximum bytes admitted for one response.
maxTotalBytes
Section titled “maxTotalBytes”readonly maxTotalBytes: number;Cumulative bytes admitted across one character selection.
maxRequests
Section titled “maxRequests”readonly maxRequests: number;Number of requests admitted for one character selection.
fetch?
Section titled “fetch?”readonly optional fetch?: typeof fetch;Assettype alias
Section titled “Asset”type Asset = object;Decoded transport bytes; adapters use these instead of opening their own URLs.
Properties
Section titled “Properties”readonly url: string;readonly bytes: Uint8Array<ArrayBuffer>;contentType
Section titled “contentType”readonly contentType: string;Controltype alias
Section titled “Control”type Control = z.infer<typeof controlSchema>;A validated, character-owned customization control.
Appearancetype alias
Section titled “Appearance”type Appearance = Readonly<Record<string, string | number | boolean>>;Values saved by the shell; no renderer objects or transient activity.
Customizationtype alias
Section titled “Customization”type Customization = z.infer<typeof customizationSchema>;A parsed, saved Sprite customization.
CharacterDocumenttype alias
Section titled “CharacterDocument”type CharacterDocument = z.infer<typeof characterSchema>;A portable character, with renderer data still awaiting its native decoder.
Jsontype alias
Section titled “Json”type Json = CharacterDocument["data"];An opaque JSON value; the selected adapter owns its schema.
CharacterSourcetype alias
Section titled “CharacterSource”type CharacterSource = | string | { local: string; };A served document URL or a host-installed character key.
AvatarPresentationtype alias
Section titled “AvatarPresentation”type AvatarPresentation = object;One complete request. Omitted customization resets to character defaults.
Properties
Section titled “Properties”timeMs?
Section titled “timeMs?”readonly optional timeMs?: number;Optional host clock in milliseconds; native animation seeks instead of running live.
readonly src: CharacterSource;activity?
Section titled “activity?”readonly optional activity?: string;expression?
Section titled “expression?”readonly optional expression?: string;appearance?
Section titled “appearance?”readonly optional appearance?: Appearance;renderStyle?
Section titled “renderStyle?”readonly optional renderStyle?: RenderStyle;SVG filter drawn over the character; omitted draws it plain.
performance?
Section titled “performance?”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”type NativePresentation = object;The resolved activity and appearance passed to a native renderer.
Properties
Section titled “Properties”timeMs?
Section titled “timeMs?”readonly optional timeMs?: number;Absolute animation time in milliseconds, when controlled by the host.
activity
Section titled “activity”readonly activity: string;expression
Section titled “expression”readonly expression: string | null;appearance
Section titled “appearance”readonly appearance: Appearance;performance?
Section titled “performance?”readonly optional performance?: Json;The request’s performance, unchanged and compared by identity.
NativePlayertype alias
Section titled “NativePlayer”type NativePlayer = object;The adapter registers native destruction in the selection scope.
Properties
Section titled “Properties”activities
Section titled “activities”readonly activities: readonly string[];expressions
Section titled “expressions”readonly expressions: readonly string[];Methods
Section titled “Methods”set(presentation): void;Update the existing native instance.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
presentation |
NativePresentation |
Returns
Section titled “Returns”void
pause()
Section titled “pause()”pause(paused): void;Pause or resume animation without losing the current frame.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
paused |
boolean |
Returns
Section titled “Returns”void
RendererContexttype alias
Section titled “RendererContext”type RendererContext = object;Native renderer access to the selected document and its admitted assets.
Properties
Section titled “Properties”target
Section titled “target”readonly target: HTMLElement;document
Section titled “document”readonly document: CharacterDocument;signal
Section titled “signal”readonly signal: AbortSignal;maxPixels
Section titled “maxPixels”readonly maxPixels: number;reportError
Section titled “reportError”readonly reportError: (error) => void;Report a native failure that occurs after the renderer has become ready.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
error |
Error |
Returns
Section titled “Returns”void
reportProgress
Section titled “reportProgress”readonly reportProgress: (progress) => void;Publish renderer progress on the ready state; ignored once the selection closes.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
progress |
Json |
Returns
Section titled “Returns”void
assetURL
Section titled “assetURL”readonly assetURL: (reference) => Effect.Effect<string, Error, Scope.Scope>;Admit an asset and revoke its object URL when the selection closes.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
reference |
string |
Returns
Section titled “Returns”Effect.Effect<string, Error, Scope.Scope>
Renderertype alias
Section titled “Renderer”type Renderer = (context) => Effect.Effect<NativePlayer, Error, Scope.Scope>;A native renderer whose resources live in the character selection scope.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
context |
RendererContext |
Returns
Section titled “Returns”Effect.Effect<NativePlayer, Error, Scope.Scope>
EffectivePresentationtype alias
Section titled “EffectivePresentation”type EffectivePresentation = NativePresentation & object;A request after native fallback and appearance validation.
Type Declaration
Section titled “Type Declaration”| Name | Type |
|---|---|
renderStyle |
RenderStyle |
requestedActivity |
string |
requestedExpression |
string | null |
fallback |
boolean |
PlayerStatetype alias
Section titled “PlayerState”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.
Union Members
Section titled “Union Members”Type Literal
Section titled “Type Literal”{ status: "empty" | "loading" | "destroyed";}Type Literal
Section titled “Type Literal”{ status: "error"; error: Error;}Type Literal
Section titled “Type Literal”{ 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”type LocalCharacter = object;An installed document and its renderer, loaded together by the shell.
Properties
Section titled “Properties”document
Section titled “document”readonly document: CharacterDocument;render
Section titled “render”readonly render: Renderer;SpriteOptionstype alias
Section titled “SpriteOptions”type SpriteOptions = object;Host-owned character registry and resource policy.
Properties
Section titled “Properties”assets?
Section titled “assets?”readonly optional assets?: AssetPolicy;Omit for local-only characters; network access is denied by default.
maxPixels?
Section titled “maxPixels?”readonly optional maxPixels?: number;renderers?
Section titled “renderers?”readonly optional renderers?: Readonly<Record<string, () => Promise<{ default: Renderer;}>>>;Native adapters allowed for served character documents.
characters?
Section titled “characters?”readonly optional characters?: Readonly<Record<string, () => Promise<LocalCharacter>>>;Lazy local characters installed by this shell.
AvatarPlayertype alias
Section titled “AvatarPlayer”type AvatarPlayer = object;One mounted avatar; dispose releases its native and browser resources.
Properties
Section titled “Properties”readonly state: PlayerState;Current public state.
Methods
Section titled “Methods”subscribe()
Section titled “subscribe()”subscribe(listener): () => void;Observe state changes until the returned unsubscribe function is called.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
listener |
(next) => void |
Returns
Section titled “Returns”() => void
set(next): void;Select a source or update its activity and appearance.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
next |
AvatarPresentation |
Returns
Section titled “Returns”void
pause()
Section titled “pause()”pause(value): void;Pause or resume the current native animation.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
boolean |
Returns
Section titled “Returns”void
dispose()
Section titled “dispose()”dispose(): Promise<void>;Cancel loading and release the current native selection.
Returns
Section titled “Returns”Promise<void>
SpriteServicetype alias
Section titled “SpriteService”type SpriteService = object;Stable shell configuration that creates independent mounted players.
Methods
Section titled “Methods”mount()
Section titled “mount()”mount(target): AvatarPlayer;Claim one DOM host for a new avatar instance.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
target |
HTMLElement |
Returns
Section titled “Returns”RenderStyletype alias
Section titled “RenderStyle”type RenderStyle = z.infer<typeof renderStyleSchema>;How a Sprite is drawn over its native renderer.
RenderStyleLayertype alias
Section titled “RenderStyleLayer”type RenderStyleLayer = object;The filter layer owned by one mounted player.
Methods
Section titled “Methods”set(style, stage): void;Draw stage in style; plain removes the filter.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
style |
| "plain" | "pencil" | "manga" | "riso" | "halftone" | "blueprint" | "crt" | "watercolor" |
stage |
HTMLElement |
Returns
Section titled “Returns”void
still()
Section titled “still()”still(value): void;Hold one still frame: paused, hidden, or reduced motion.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
boolean |
Returns
Section titled “Returns”void
dispose()
Section titled “dispose()”dispose(): void;Stop the boil and remove the filter and its definitions.
Returns
Section titled “Returns”void
controlSchemaconstant
Section titled “controlSchema”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”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”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”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”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”const renderStyleLabels: object;Picker labels for each style, in display order.
Type Declaration
Section titled “Type Declaration”resolveAppearance()function
Section titled “resolveAppearance()”function resolveAppearance(controls, overrides?): Appearance;Validate the complete appearance before applying any native updates.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
controls |
Readonly<Record<string, Control>> |
overrides |
Appearance |
Returns
Section titled “Returns”createSprite()function
Section titled “createSprite()”function createSprite(options): SpriteService;Stable shell service; each mounted player owns its own selection.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
SpriteOptions |
Returns
Section titled “Returns”createRenderStyleLayer()function
Section titled “createRenderStyleLayer()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
host |
HTMLElement |