Skip to Content
Documentation

songstress/ui

The reader every app reads your declared interface with, its caps, and Songstress's icon set.

See the declared interface. Every app reads what your renderers answer with this reader: readScreen, readPanel, readStatus and readAction keep what Songstress draws of a tree, keep a node they do not know as { type: "unknown" } ("needs a newer app"), and refuse a tree over UI_CAPS. Read your trees with them in your tests: a tree they keep whole is drawn as you wrote it.

An icon anywhere in a manifest or a tree is any name in the form of an id: the names of ICON_NAMES are drawn by every app with a glyph of its own, and any other name is drawn as the extension mark. Your editor offers these names first wherever the SDK types an icon (IconName).

songstress/ui imports nothing else, so an app or a test takes it alone.

What it exports is the SDK's own record of its public surface, which the SDK's tests hold to the code. Each type's fields, every description and every function's usage example are read from the SDK's source when the site is built, and each example is compiled against the SDK by its tests.

ALIGNS · AlbumItem · ArtistItem · AssetSize · AsyncState · Badge · BadgeProps · Box · BoxProps · Button · ButtonProps · Callout · CalloutProps · Canvas · CanvasFrame · CanvasPointer · CanvasProps · Checkbox · CheckboxProps · Collapsible · CollapsibleProps · Cover · CoverProps · DatePicker · DatePickerProps · Divider · DividerProps · DrawnBanner · DrawnBlock · DrawnBox · DrawnButton · DrawnCanvas · DrawnCard · DrawnCheckbox · DrawnCollapsible · DrawnDatePicker · DrawnDetail · DrawnEmpty · DrawnEmptyState · DrawnField · DrawnForm · DrawnGrid · DrawnGridBlock · DrawnIconButton · DrawnLeading · DrawnList · DrawnListBlock · DrawnListRow · DrawnMediaCard · DrawnMenu · DrawnMenuEntry · DrawnNode · DrawnPanel · DrawnRow · DrawnScreen · DrawnSearchField · DrawnSection · DrawnSegmented · DrawnSelect · DrawnShelf · DrawnSlider · DrawnStack · DrawnStatus · DrawnSwitch · DrawnTab · DrawnTable · DrawnTableRow · DrawnTabs · DrawnTextField · DrawnTrailing · DrawnTree · DrawnTreeBlock · DrawnTreeItem · EMPHASES · Empty · EmptyProps · Glyph · GlyphProps · Grid · GridProps · HStack · Handled · HandledButton · HandledConfirm · Handler · HandlerFunction · HandlerRef · ICON_NAMES · IconButton · IconButtonProps · Image · ImageProps · JUSTIFIES · LibraryItem · LibraryItemProps · List · ListItem · ListItemProps · ListProps · MOUNT_ID_LENGTH · MOUNT_INTERVAL · MOUNT_LIMIT · MOUNT_PUSH · MediaCard · MediaCardProps · Menu · MenuOption · MenuOptionProps · MenuProps · MountError · MountSession · MountUpdate · Placement · PlayButton · PlayButtonProps · PlaylistItem · Progress · ProgressProps · ProseText · ProseTextProps · Refusal · SIZES · SPACES · STORED_FILE_TYPES · SURFACE_CAPS · SdkComponent · SearchField · SearchFieldProps · Section · SectionProps · Segmented · SegmentedProps · Select · SelectProps · Shelf · ShelfProps · SignedImage · Skeleton · SkeletonProps · Slider · SliderProps · SongItem · Spacer · SpacerProps · Sprite · SpriteProps · SpriteRun · Stack · StackProps · SurfaceDeclared · SurfaceState · Switch · SwitchProps · TONES · Tab · TabProps · Table · TableProps · TableRow · Tabs · TabsProps · Text · TextInput · TextInputProps · TextProps · Tree · TreeItem · TreeItemProps · TreeProps · TreeRead · UI_CAPS · UiElement · UiNode · UnknownNode · VIEW_CAPS · VIEW_IMAGE · VIEW_MARKUP · VIEW_STYLE · VIEW_TOKENS · ViewFrameMessage · ViewPatchOp · ViewPatchRead · ViewStart · ViewTreeNode · ViewWeight · ViewWorkerMessage · WIDTHS · confirmed · controlValue · handledOf · imageFileName · isKnownIcon · isWebAddress · listOf · mergeSurfaceState · numberOf · objectOf · readAction · readOverlay · readPanel · readScreen · readStatus · readSurfaceState · readUpdate · readViewImage · readViewPatch · spriteRuns · storedFileType · stringsOf · textOf · uploadFolder · useAsync · useCallback · useEffect · useMemo · usePlayer · useReducer · useRef · useSetting · useState · useStored · viewOpChars · viewStyleRefused · viewStyleUnescaped · viewWeight · withValue

It also exports, as the modules that declare them document them: KnownIconName, UI_VERSION, ViewEvent, ViewImage, ViewTheme.

ALIGNS

How a stack's or a box's children line up across it.

export declare const ALIGNS: readonly ('start' | 'center' | 'end' | 'stretch')[];

AlbumItem

An album of the library: an album node.

export declare const AlbumItem: import("./types").SdkComponent<LibraryItemProps>;
Example
import { AlbumItem, Shelf } from 'songstress/ui'

const albumIds = ['al-1', 'al-2']
const albums = <Shelf title="Albums">{albumIds.map((id) => <AlbumItem key={id} id={id} />)}</Shelf>

Refers to SdkComponent, LibraryItemProps.

ArtistItem

An artist of the library: an artist node.

export declare const ArtistItem: import("./types").SdkComponent<LibraryItemProps>;
Example
import { ArtistItem, Shelf } from 'songstress/ui'

const artists = (
  <Shelf title="Artists">
    <ArtistItem id="ar-1" />
    <ArtistItem id="ar-2" />
  </Shelf>
)

Refers to SdkComponent, LibraryItemProps.

AssetSize

One of the package's own images, as the extension's entry in the server's contributions list names it: what a reader checks a sprite's frames against.

Prop

Type

AsyncState

What useAsync holds.

Prop

Type

Badge

A short word in a pill: a badge node. Its words are its children, or text.

export declare const Badge: import("./types").SdkComponent<BadgeProps>;
Example
import { Badge } from 'songstress/ui'

const fresh = <Badge tone="success">New</Badge>

Refers to SdkComponent, BadgeProps.

BadgeProps

A Badge's props: its words are its children joined, or text.

Prop

Type

Refers to BadgeBlock, UiNode.

Box

A surface around blocks: a box node, plain, the app's card, or a quiet inset.

export declare const Box: import("./types").SdkComponent<BoxProps>;
Example
import { Box, Text } from 'songstress/ui'

const week = (
  <Box variant="card" padding="medium" gap="xsmall">
    <Text style="label">This week</Text>
    <Text style="title">42 plays</Text>
  </Box>
)

Refers to SdkComponent, BoxProps.

BoxProps

A Box's props.

Prop

Type

Refers to BoxBlock, UiNode.

Button

A button: a button node, onPress its action.

export declare const Button: import("./types").SdkComponent<ButtonProps>;
Example
import { Button, Text, useState } from 'songstress/ui'

function Counter() {
  const [count, setCount] = useState(0)
  return (
    <>
      <Text>{`Pressed ${count} times`}</Text>
      <Button title="Add one" icon="add" emphasis="primary" onPress={() => setCount((was) => was + 1)} />
    </>
  )
}

Refers to SdkComponent, ButtonProps.

ButtonProps

A Button's props. Its look is emphasis; vocabulary 2's style is left out.

Prop

Type

Refers to ButtonBlock, Handler.

Callout

A banner: a notice across the top of a block, in a tone, with one button at most: a banner node. Its button is buttonTitle and onPress.

export declare const Callout: import("./types").SdkComponent<CalloutProps>;
Example
import { Callout } from 'songstress/ui'

const down = <Callout tone="warning" title="The lyrics service is down" text="Lyrics come back when it does." buttonTitle="Try again" onPress={{ type: 'refresh' }} />

Refers to SdkComponent, CalloutProps.

CalloutProps

A Callout's props: its button is buttonTitle and onPress.

Prop

Type

Refers to BannerBlock, Handler.

Canvas

Pixels the extension's client code draws: a canvas node, its draw called for each frame the app shows (at most 60 a second, none while it is out of sight). The web and the macOS desktop from 13.3 draw it; elsewhere the app says what it needs (read client.capabilities.canvas and draw something else where it is false). Client code only: the server refuses it.

export declare const Canvas: import("./types").SdkComponent<CanvasProps>;
Example
// tsconfig.json's `types` names "songstress/sandbox/canvas": the drawing types.
import { Canvas } from 'songstress/ui'

// A dot that crosses the canvas every two seconds.
const dot = (
  <Canvas
    height={80}
    description="A dot that moves"
    draw={(context, frame) => {
      const x = ((frame.time % 2000) / 2000) * frame.width
      context.fillStyle = '#e50043'
      context.beginPath()
      context.arc(x, frame.height / 2, 6, 0, Math.PI * 2)
      context.fill()
    }}
  />
)

Refers to SdkComponent, CanvasProps.

CanvasFrame

A frame a canvas is asked for: its laid-out size in whole points, the device pixels a point, and the milliseconds since it first drew.

Prop

Type

CanvasPointer

The pointer over a canvas, as its onPointer is told.

Prop

Type

CanvasProps

A Canvas's props: a 2D canvas (the default) or a WebGL 2 one, and the function that draws each frame. The canvas is clear at the start of every draw: draw the whole picture each time.

export type CanvasProps = (CanvasBase & {
    context?: '2d';
    draw: (context: OffscreenCanvasRenderingContext2D, frame: CanvasFrame) => void;
}) | (CanvasBase & {
    context: 'webgl2';
    draw: (context: WebGL2RenderingContext, frame: CanvasFrame) => void;
});

Refers to CanvasFrame.

Checkbox

On or off, as a checkbox: a checkbox node, told a boolean.

export declare const Checkbox: import("./types").SdkComponent<CheckboxProps>;
Example
import { Checkbox, useState } from 'songstress/ui'

function Intros() {
  const [skip, setSkip] = useState(true)
  return <Checkbox label="Skip intros" value={skip} onChange={setSkip} />
}

Refers to SdkComponent, CheckboxProps.

CheckboxProps

A Checkbox's props.

Prop

Type

Refers to CheckboxBlock, Handler.

Collapsible

Blocks a tap opens and closes: a collapsible node. With onChange, it is open exactly when open says.

export declare const Collapsible: import("./types").SdkComponent<CollapsibleProps>;
Example
import { Collapsible, Text, useState } from 'songstress/ui'

function Credits() {
  const [open, setOpen] = useState(false)
  return (
    <Collapsible title="Credits" open={open} onChange={setOpen}>
      <Text>Recorded in one take.</Text>
    </Collapsible>
  )
}

Refers to SdkComponent, CollapsibleProps.

CollapsibleProps

A Collapsible's props.

Prop

Type

Refers to CollapsibleBlock, Handler, UiNode.

Cover

The cover of something in the library: a cover node.

export declare const Cover: import("./types").SdkComponent<CoverProps>;
Example
import { Cover } from 'songstress/ui'

const art = <Cover of="album" id="al-1" size="large" description="Kind of Blue" />

Refers to SdkComponent, CoverProps.

CoverProps

A Cover's props.

export type CoverProps = Own<CoverBlock>;

Refers to CoverBlock.

DatePicker

A day: a date-picker node, told the day as YYYY-MM-DD.

export declare const DatePicker: import("./types").SdkComponent<DatePickerProps>;
Example
import { DatePicker, useState } from 'songstress/ui'

function Since() {
  const [since, setSince] = useState('2026-11-01')
  return <DatePicker label="Since" value={since} maximum="2026-12-31" onChange={setSince} />
}

Refers to SdkComponent, DatePickerProps.

DatePickerProps

A DatePicker's props.

Prop

Type

Refers to DatePickerBlock, Handler.

Divider

A line between blocks: a divider node.

export declare const Divider: import("./types").SdkComponent<DividerProps>;
Example
import { Divider, Stack, Text } from 'songstress/ui'

const parts = (
  <Stack gap="small">
    <Text>This week</Text>
    <Divider />
    <Text>Last week</Text>
  </Stack>
)

Refers to SdkComponent, DividerProps.

DividerProps

A Divider's props.

export type DividerProps = Own<DividerBlock>;

Refers to DividerBlock.

DrawnBanner

A banner, its button as an app draws it.

export type DrawnBanner = Omit<BannerBlock, 'button'> & {
    button?: HandledButton;
};

Refers to BannerBlock, HandledButton.

DrawnBlock

What a detail page, a section and a panel are built from.

export type DrawnBlock = DrawnStack | DrawnSection | DrawnCollapsible | DrawnShelf | TextBlock | IconBlock | ImageBlock | BadgeBlock | ProgressBlock | DrawnBanner | DividerBlock | SpacerBlock | DrawnButton | DrawnMenu | LibraryItem | DrawnGridBlock | DrawnBox | DrawnTabs | ProseTextBlock | SpriteBlock | CoverBlock | DrawnEmpty | SkeletonBlock | DrawnIconButton | DrawnSwitch | DrawnCheckbox | DrawnSlider | DrawnSelect | DrawnSegmented | DrawnTextField | DrawnSearchField | DrawnDatePicker | DrawnListBlock | DrawnTable | DrawnTreeBlock | PlayButtonBlock | DrawnMediaCard | DrawnCanvas | UnknownNode;

Refers to DrawnStack, DrawnSection, DrawnCollapsible, DrawnShelf, TextBlock, IconBlock, ImageBlock, BadgeBlock, ProgressBlock, DrawnBanner, DividerBlock, SpacerBlock, DrawnButton, DrawnMenu, LibraryItem, DrawnGridBlock, DrawnBox, DrawnTabs, ProseTextBlock, SpriteBlock, CoverBlock, DrawnEmpty, SkeletonBlock, DrawnIconButton, DrawnSwitch, DrawnCheckbox, DrawnSlider, DrawnSelect, DrawnSegmented, DrawnTextField, DrawnSearchField, DrawnDatePicker, DrawnListBlock, DrawnTable, DrawnTreeBlock, PlayButtonBlock, DrawnMediaCard, DrawnCanvas, UnknownNode.

DrawnBox

A box, its children as an app draws them.

export type DrawnBox = Omit<BoxBlock, 'children'> & {
    children: DrawnBlock[];
};

Refers to BoxBlock, DrawnBlock.

DrawnButton

A button, as an app draws it.

export type DrawnButton = Drawn<ButtonBlock>;

Refers to ButtonBlock.

DrawnCanvas

A canvas: pixels the extension's client code draws. It exists in a mounted tree alone: its draw is a function. Its width is its own, in points: left out, it is across its parent.

Prop

Type

Refers to Placed, HandlerRef.

DrawnCard

A card of a grid or a shelf.

export type DrawnCard = DrawnMediaCard | LibraryItem | UnknownNode;

Refers to DrawnMediaCard, LibraryItem, UnknownNode.

DrawnCheckbox

A checkbox, as an app draws it.

export type DrawnCheckbox = Drawn<CheckboxBlock>;

Refers to CheckboxBlock.

DrawnCollapsible

A collapsible block, its children as an app draws them.

export type DrawnCollapsible = Drawn<Omit<CollapsibleBlock, 'children'>> & {
    children: DrawnBlock[];
};

Refers to CollapsibleBlock, DrawnBlock.

DrawnDatePicker

A date picker, as an app draws it.

export type DrawnDatePicker = Drawn<DatePickerBlock>;

Refers to DatePickerBlock.

DrawnDetail

A detail screen: blocks, top to bottom.

Prop

Type

Refers to DrawnBlock.

DrawnEmpty

An empty state as a block, its button as an app draws it.

export type DrawnEmpty = Omit<EmptyBlock, 'button'> & {
    button?: HandledButton;
};

Refers to EmptyBlock, HandledButton.

DrawnEmptyState

What a list or a grid shows when it has nothing to show.

export type DrawnEmptyState = Omit<EmptyState, 'button'> & {
    button?: HandledButton;
};

Refers to EmptyState, HandledButton.

DrawnField

A field of a form.

export type DrawnField = Field | UnknownNode;

Refers to Field, UnknownNode.

DrawnForm

A form screen, its fields as an app draws them.

export type DrawnForm = Omit<FormScreen, 'sections'> & {
    sections: {
        title?: string;
        footer?: string;
        fields: DrawnField[];
    }[];
};

Refers to FormScreen, DrawnField.

DrawnGrid

A grid screen, its cards as an app draws them.

export type DrawnGrid = Omit<GridScreen, 'sections' | 'empty'> & {
    sections: {
        title?: string;
        items: DrawnCard[];
    }[];
    empty?: DrawnEmptyState;
};

Refers to GridScreen, DrawnCard, DrawnEmptyState.

DrawnGridBlock

A grid block, its children as an app draws them.

export type DrawnGridBlock = Omit<GridBlock, 'children'> & {
    children: DrawnBlock[];
};

Refers to GridBlock, DrawnBlock.

DrawnIconButton

A button that shows an icon alone, as an app draws it.

export type DrawnIconButton = Drawn<IconButtonBlock>;

Refers to IconButtonBlock.

DrawnLeading

What stands at a row's start.

export type DrawnLeading = IconBlock | ImageBlock | CoverBlock | SpriteBlock;

Refers to IconBlock, ImageBlock, CoverBlock, SpriteBlock.

DrawnList

A list screen, its rows as an app draws them.

export type DrawnList = Omit<ListScreen, 'sections' | 'empty'> & {
    sections: {
        title?: string;
        items: DrawnRow[];
    }[];
    empty?: DrawnEmptyState;
};

Refers to ListScreen, DrawnRow, DrawnEmptyState.

DrawnListBlock

A list block, its rows as an app draws them.

export type DrawnListBlock = Omit<ListBlock, 'items' | 'empty'> & {
    items: DrawnRow[];
    empty?: DrawnEmptyState;
};

Refers to ListBlock, DrawnRow, DrawnEmptyState.

DrawnListRow

A row of the extension's own, as an app draws it.

export type DrawnListRow = Omit<Row, keyof DrawnRowParts> & DrawnRowParts;

Refers to Row.

DrawnMediaCard

A card of the extension's own, as an app draws it.

export type DrawnMediaCard = Omit<Card, 'action' | 'menu'> & {
    action?: Handled;
    menu?: DrawnMenuEntry[];
};

Refers to Card, Handled, DrawnMenuEntry.

DrawnMenu

A menu button, its entries as an app draws them.

export type DrawnMenu = Omit<MenuBlock, 'items'> & {
    items: DrawnMenuEntry[];
};

Refers to MenuBlock, DrawnMenuEntry.

DrawnMenuEntry

One entry of a menu, as an app draws it.

export type DrawnMenuEntry = Drawn<MenuEntry>;

Refers to MenuEntry.

DrawnNode

A node of a tree, and what it holds.

export type DrawnNode = Omit<TreeNode, 'children' | keyof DrawnRowParts> & DrawnRowParts & {
    children?: DrawnTreeItem[];
};

Refers to TreeNode, DrawnTreeItem.

DrawnPanel

What a panel shows inside one of Songstress's own screens.

Prop

Type

Refers to DrawnBlock.

DrawnRow

A row of a list.

export type DrawnRow = DrawnListRow | SongRow | UnknownNode;

Refers to DrawnListRow, SongRow, UnknownNode.

DrawnScreen

What a whole page is.

export type DrawnScreen = DrawnList | DrawnGrid | DrawnDetail | DrawnForm | DrawnTree | UnknownNode;

Refers to DrawnList, DrawnGrid, DrawnDetail, DrawnForm, DrawnTree, UnknownNode.

DrawnSearchField

A search field, as an app draws it.

export type DrawnSearchField = Drawn<SearchFieldBlock>;

Refers to SearchFieldBlock.

DrawnSection

A section, its children as an app draws them.

export type DrawnSection = Omit<SectionBlock, 'children'> & {
    children: DrawnBlock[];
};

Refers to SectionBlock, DrawnBlock.

DrawnSegmented

A segmented control, as an app draws it.

export type DrawnSegmented = Drawn<SegmentedBlock>;

Refers to SegmentedBlock.

DrawnSelect

A select, as an app draws it.

export type DrawnSelect = Drawn<SelectBlock>;

Refers to SelectBlock.

DrawnShelf

A shelf, its cards as an app draws them.

export type DrawnShelf = Omit<ShelfBlock, 'items'> & {
    items: DrawnCard[];
};

Refers to ShelfBlock, DrawnCard.

DrawnSlider

A slider, as an app draws it.

export type DrawnSlider = Drawn<SliderBlock>;

Refers to SliderBlock.

DrawnStack

A stack, its children as an app draws them.

export type DrawnStack = Omit<StackBlock, 'children'> & {
    children: DrawnBlock[];
};

Refers to StackBlock, DrawnBlock.

DrawnStatus

What a status item shows in the player, as an app draws it.

export type DrawnStatus = Omit<StatusContent, 'action'> & {
    action?: Handled;
};

Refers to StatusContent, Handled.

DrawnSwitch

A switch, as an app draws it.

export type DrawnSwitch = Drawn<SwitchBlock>;

Refers to SwitchBlock.

DrawnTab

One tab of a tabs block, its blocks as an app draws them.

export type DrawnTab = Omit<TabsBlock['tabs'][number], 'children'> & {
    children: DrawnBlock[];
};

Refers to TabsBlock, DrawnBlock.

DrawnTable

A table, its rows as an app draws them.

export type DrawnTable = Omit<TableBlock, 'rows' | 'empty'> & {
    rows: DrawnTableRow[];
    empty?: DrawnEmptyState;
};

Refers to TableBlock, DrawnTableRow, DrawnEmptyState.

DrawnTableRow

A row of a table, as an app draws it.

export type DrawnTableRow = Omit<TableBlock['rows'][number], 'action'> & {
    action?: Handled;
};

Refers to TableBlock, Handled.

DrawnTabs

A tabs block, its tabs as an app draws them.

export type DrawnTabs = Omit<TabsBlock, 'tabs' | 'onSelect'> & {
    tabs: DrawnTab[];
    onSelect?: Handled;
};

Refers to TabsBlock, DrawnTab, Handled.

DrawnTextField

A text field, as an app draws it.

export type DrawnTextField = Drawn<TextFieldBlock>;

Refers to TextFieldBlock.

DrawnTrailing

What stands at a row's end.

export type DrawnTrailing = TextBlock | BadgeBlock | IconBlock | ProgressBlock | DrawnSwitch | DrawnIconButton | DrawnButton;

Refers to TextBlock, BadgeBlock, IconBlock, ProgressBlock, DrawnSwitch, DrawnIconButton, DrawnButton.

DrawnTree

A tree screen, its nodes as an app draws them.

export type DrawnTree = Omit<TreeScreen, 'nodes' | 'empty'> & {
    nodes: DrawnTreeItem[];
    empty?: DrawnEmptyState;
};

Refers to TreeScreen, DrawnTreeItem, DrawnEmptyState.

DrawnTreeBlock

A tree block, its nodes as an app draws them.

export type DrawnTreeBlock = Omit<TreeBlock, 'nodes' | 'onExpand'> & {
    nodes: DrawnTreeItem[];
    onExpand?: Handled;
};

Refers to TreeBlock, DrawnTreeItem, Handled.

DrawnTreeItem

What a tree holds at one level: nodes, songs, and what an app does not know.

export type DrawnTreeItem = DrawnNode | SongRow | UnknownNode;

Refers to DrawnNode, SongRow, UnknownNode.

EMPHASES

How much a button asks to be seen.

export declare const EMPHASES: readonly Emphasis[];

Refers to Emphasis.

Empty

The app's "nothing here": an empty node. Its button is buttonTitle and onPress.

export declare const Empty: import("./types").SdkComponent<EmptyProps>;
Example
import { Empty } from 'songstress/ui'

const none = <Empty title="Nothing played yet" text="Play a song to the end, and it shows here." icon="music" />

Refers to SdkComponent, EmptyProps.

EmptyProps

An Empty's props: its button is buttonTitle and onPress.

Prop

Type

Refers to EmptyBlock, Handler.

Glyph

An icon, by name, from Songstress's icon set: an icon node.

export declare const Glyph: import("./types").SdkComponent<GlyphProps>;
Example
import { Glyph } from 'songstress/ui'

const mark = <Glyph name="headphones" tone="accent" size="small" />

Refers to SdkComponent, GlyphProps.

GlyphProps

A Glyph's props.

export type GlyphProps = Own<IconBlock>;

Refers to IconBlock.

Grid

Blocks in columns: a grid node.

export declare const Grid: import("./types").SdkComponent<GridProps>;
Example
import { Box, Grid, Text } from 'songstress/ui'

const totals = (
  <Grid columns={2} gap="small">
    <Box variant="card"><Text style="label">Plays</Text><Text style="title">42</Text></Box>
    <Box variant="card"><Text style="label">Hours</Text><Text style="title">3</Text></Box>
  </Grid>
)

Refers to SdkComponent, GridProps.

GridProps

A Grid's props.

Prop

Type

Refers to GridBlock, UiNode.

HStack

Blocks beside one another, going on to a new line when they do not fit (wrap): a stack node with direction: "horizontal".

export declare const HStack: import("./types").SdkComponent<StackProps>;
Example
import { Badge, Glyph, HStack, Spacer, Text } from 'songstress/ui'

const row = (
  <HStack gap="small" align="center">
    <Glyph name="headphones" />
    <Text>Listening now</Text>
    <Spacer />
    <Badge tone="accent">Live</Badge>
  </HStack>
)

Refers to SdkComponent, StackProps.

Handled

What a control does, as an app reads it: an action, a function of the extension's client code, or a question before either.

export type Handled = Action | HandlerRef | HandledConfirm;

Refers to Action, HandlerRef, HandledConfirm.

HandledButton

A button of a banner or an empty state: a title and what it does.

Prop

Type

Refers to Handled.

HandledConfirm

A question first, then a handler: what confirmed writes around a function.

Prop

Type

Refers to ConfirmAction, Handled.

Handler

What a control does: an action anywhere, a function in client code only.

export type Handler<Payload = void> = Action | HandlerFunction<Payload>;

Refers to Action, HandlerFunction.

HandlerFunction

A function of the extension's client code: called in its worker when the person presses, types or slides. It may answer an action, which the app then carries out as it carries out a command's outcome.

export type HandlerFunction<Payload = void> = (payload: Payload) => Awaitable<Action | void>;

Refers to Awaitable, Action.

HandlerRef

A function of the extension's client code, by the id its mount gave it. Written by the SDK's runtime alone; an app sends it back to that mount, as an event, when the person uses the control.

Prop

Type

ICON_NAMES

Every name Songstress's apps draw with a glyph of their own, in order. A name outside the set is still allowed, and is drawn as the extension mark.

export declare const ICON_NAMES: readonly [
    "add",
    "album",
    "artist",
    "calendar",
    "chart",
    "check",
    "clock",
    "close",
    "cloud",
    "copy",
    "download",
    "edit",
    "extension",
    "external",
    "filter",
    "flame",
    "folder",
    "globe",
    "headphones",
    "heart",
    "image",
    "info",
    "key",
    "library",
    "link",
    "list",
    "lock",
    "lyrics",
    "mic",
    "music",
    "notification",
    "pause",
    "people",
    "person",
    "play",
    "playlist",
    "queue",
    "radio",
    "refresh",
    "remove",
    "search",
    "server",
    "settings",
    "share",
    "shuffle",
    "sparkles",
    "star",
    "sync",
    "tag",
    "timer",
    "trash",
    "warning"
];
Example
import { ICON_NAMES } from 'songstress/ui'

ICON_NAMES.includes('heart') // true

IconButton

A button that shows an icon alone: an icon-button node, onPress its action.

export declare const IconButton: import("./types").SdkComponent<IconButtonProps>;
Example
import { IconButton } from 'songstress/ui'

const reload = <IconButton icon="refresh" label="Look again" onPress={{ type: 'refresh' }} />

Refers to SdkComponent, IconButtonProps.

IconButtonProps

An IconButton's props.

Prop

Type

Refers to IconButtonBlock, Handler.

Image

A picture: an image node, a cover of the library, an address the app fetches through the server, or one of the package's own images.

export declare const Image: import("./types").SdkComponent<ImageProps>;
Example
import { Image } from 'songstress/ui'

// An image the package carries, by its path in the package.
const header = <Image source={{ asset: 'images/header.png' }} description="The radio's logo" shape="wide" />

Refers to SdkComponent, ImageProps.

ImageProps

An Image's props.

export type ImageProps = Own<ImageBlock>;

Refers to ImageBlock.

JUSTIFIES

How a stack's children share the room along it.

export declare const JUSTIFIES: readonly ('start' | 'center' | 'end' | 'between')[];

LibraryItem

One of Songstress's own rows and cards, named by library id.

export type LibraryItem = SongRow | AlbumCard | ArtistCard | PlaylistCard;

Refers to SongRow, AlbumCard, ArtistCard, PlaylistCard.

LibraryItemProps

The props of a SongItem, an AlbumItem, an ArtistItem or a PlaylistItem: something of the library, by its id.

Prop

Type

Refers to Placement.

List

Rows, as a block: a list node, its rows its children. Its empty state is emptyTitle, emptyText and emptyIcon.

export declare const List: import("./types").SdkComponent<ListProps>;
Example
import { List, SongItem } from 'songstress/ui'

const songIds = ['s1', 's2', 's3']
const recent = (
  <List title="Played lately" emptyTitle="Nothing played yet" emptyIcon="music">
    {songIds.map((id) => <SongItem key={id} id={id} />)}
  </List>
)

Refers to SdkComponent, ListProps.

ListItem

A row of a List: a row node, onPress its action.

export declare const ListItem: import("./types").SdkComponent<ListItemProps>;
Example
import { Badge, List, ListItem } from 'songstress/ui'

const stations = (
  <List>
    <ListItem id="night" title="Night radio" subtitle="Slow songs, after ten" icon="radio" trailing={<Badge>New</Badge>} onPress={{ type: 'navigate', to: { page: 'night' } }} />
  </List>
)

Refers to SdkComponent, ListItemProps.

ListItemProps

A ListItem's props: a row node.

Prop

Type

Refers to Row.

ListProps

A List's props: its rows are its children (ListItem, SongItem, or hand-written rows).

Prop

Type

Refers to ListBlock, IconName, UiNode.

MOUNT_ID_LENGTH

The longest mount id: "<kind>:<id>#<count>", made by the app.

export declare const MOUNT_ID_LENGTH = 80;

MOUNT_INTERVAL

The least time between two of a text field's or a slider's events while the person types or drags, in milliseconds; and between two renders of one bundle.

export declare const MOUNT_INTERVAL = 33;

MOUNT_LIMIT

The most targets one extension's client code holds mounted at once.

export declare const MOUNT_LIMIT = 16;

MOUNT_PUSH

The bridge member a mount pushes a newer tree, an acknowledgement or an error through. It is the bridge's, not the API's: no extension calls it by name, and the server refuses any member that starts with $.

export declare const MOUNT_PUSH = "$ui.render";

MediaCard

A card of the extension's own: a card node, onPress its action.

export declare const MediaCard: import("./types").SdkComponent<MediaCardProps>;
Example
import { MediaCard, Shelf } from 'songstress/ui'

const mixes = (
  <Shelf title="Mixes">
    <MediaCard id="night" title="Night radio" subtitle="Slow songs, after ten" image={{ asset: 'images/night.png' }} onPress={{ type: 'toast', message: 'Starting' }} />
  </Shelf>
)

Refers to SdkComponent, MediaCardProps.

MediaCardProps

A MediaCard's props: a card node.

Prop

Type

Refers to Card, Handler, UiNode.

Menu

A button that opens a menu: a menu node, its entries its MenuOption children.

export declare const Menu: import("./types").SdkComponent<MenuProps>;
Example
import { Menu, MenuOption } from 'songstress/ui'

const more = (
  <Menu title="More" icon="settings">
    <MenuOption title="Look again" icon="refresh" onSelect={{ type: 'refresh' }} />
    <MenuOption title="Say hello" onSelect={() => ({ type: 'toast', message: 'Hello' })} />
  </Menu>
)

Refers to SdkComponent, MenuProps.

MenuOption

A menu item: one entry of a Menu, or of a ListItem's, a TreeItem's or a MediaCard's menu. onSelect is what choosing it does.

export declare const MenuOption: import("./types").SdkComponent<MenuOptionProps>;
Example
import { confirmed, Menu, MenuOption } from 'songstress/ui'

const more = (
  <Menu title="More">
    <MenuOption title="Forget every play" icon="trash" destructive onSelect={confirmed({ title: 'Forget every play?' }, { type: 'invoke', command: 'forget' })} />
  </Menu>
)

Refers to SdkComponent, MenuOptionProps.

MenuOptionProps

A MenuOption's props.

Prop

Type

Refers to MenuEntry, Handler.

MenuProps

A Menu's props: its entries are its children, each a MenuOption.

Prop

Type

Refers to MenuBlock, UiNode.

MountError

Why a mount's render failed, as it says it: each part cut at 2,000 characters.

Prop

Type

MountSession

What the app asks a mount, as the second argument of the target's renderer: to mount it, to render it for a new context, to run a control's function, to draw a canvas's frame, or to take it down.

export type MountSession = {
    mount: string;
    op: 'mount' | 'context' | 'unmount';
} | {
    mount: string;
    op: 'event';
    handler: number;
    payload: unknown;
    seq: number;
} | {
    mount: string;
    op: 'tick';
    canvas: number;
    tick: number;
    frame: CanvasFrame;
};

Refers to mount, CanvasFrame.

MountUpdate

An answer or a push of a mount, as readUpdate reads it. A tree is still text: the app reads it with the reader of the target's kind when it draws it.

export type MountUpdate = {
    kind: 'render';
    mount?: string;
    n: number;
    ack: number;
    tree: string;
} | {
    kind: 'ack';
    mount?: string;
    ack: number;
} | {
    kind: 'error';
    mount?: string;
    error: MountError;
} | {
    kind: 'handled';
    handled: boolean;
    action: Action | null;
} | {
    kind: 'gone';
} | {
    kind: 'done';
} | {
    kind: 'plain';
    value: unknown;
} | {
    kind: 'refused';
    reason: Refusal;
};

Refers to mount, MountError, Action, Refusal.

Placement

What every component takes beside its own props: how it takes its parent's room. Its name among its siblings is the JSX key.

export type Placement = Omit<Placed, 'key'>;

Refers to Placed.

PlayButton

The app's own Play button, for songs, an album, an artist or a playlist: a play-button node.

export declare const PlayButton: import("./types").SdkComponent<PlayButtonProps>;
Example
import { PlayButton } from 'songstress/ui'

const play = <PlayButton what={{ albumId: 'al-1' }} title="Play the album" />

Refers to SdkComponent, PlayButtonProps.

PlayButtonProps

A PlayButton's props.

export type PlayButtonProps = Own<PlayButtonBlock>;

Refers to PlayButtonBlock.

PlaylistItem

A playlist of the library: a playlist node, a card of a Shelf (a List takes rows and songs alone).

export declare const PlaylistItem: import("./types").SdkComponent<LibraryItemProps>;
Example
import { PlaylistItem, Shelf } from 'songstress/ui'

const playlists = (
  <Shelf title="Your playlists">
    <PlaylistItem id="pl-1" />
  </Shelf>
)

Refers to SdkComponent, LibraryItemProps.

Progress

How far something has got, as a bar or a ring: a progress node.

export declare const Progress: import("./types").SdkComponent<ProgressProps>;
Example
import { Progress } from 'songstress/ui'

const imported = <Progress value={0.4} label="40 of 100 songs" />
const going = <Progress variant="ring" label="Looking" />

Refers to SdkComponent, ProgressProps.

ProgressProps

A Progress's props.

export type ProgressProps = Own<ProgressBlock>;

Refers to ProgressBlock.

ProseText

Prose: paragraphs, lists and emphasis in the manifest's prose format, a prose node. Its blocks are blocks, or its children's text a block a line, as the format has it: a paragraph, a heading or a list item is one line, and a blank line is nothing.

export declare const ProseText: import("./types").SdkComponent<ProseTextProps>;
Example
import { ProseText } from 'songstress/ui'

const about = <ProseText blocks={['Counts each song you play to the end.', 'Nothing leaves your server.']} />

Refers to SdkComponent, ProseTextProps.

ProseTextProps

A ProseText's props: its blocks are blocks, or its children's text a block a line, as the prose format has it (a list item on a line of its own is a list item; a blank line is no block).

Prop

Type

Refers to ProseTextBlock, UiNode.

Refusal

Why a tree is not drawn at all: it is over one of UI_CAPS, or it is not a tree.

export type Refusal = 'too-large' | 'unreadable';

SIZES

The steps of size.

export declare const SIZES: readonly Size[];

Refers to Size.

SPACES

The steps of room, between things (gap) or inside one (padding).

export declare const SPACES: readonly Space[];

Refers to Space.

STORED_FILE_TYPES

What a stored file is, by the ending of its name.

export declare const STORED_FILE_TYPES: Readonly<Record<string, StoredType>>;

Refers to StoredType.

SURFACE_CAPS

What a state holds and how often it may change, at most. The server holds the server entry's writes to them and an app holds client code's; an app reads what it is handed with them again.

export declare const SURFACE_CAPS: {
    readonly bytes: 16384;
    readonly badge: 9999;
    readonly contextText: 100;
    readonly statusBytes: 4096;
    readonly deviceWrites: 10;
    readonly deviceBurst: 20;
    readonly memberWrites: 10;
    readonly memberBurst: 20;
    readonly wideWrites: 1;
    readonly wideBurst: 5;
    readonly pushes: 4;
};
Example
import { SURFACE_CAPS } from 'songstress/ui/reader'

// A badge over the cap is refused: say "99+" yourself if you count more.
const badge = Math.min(4200, SURFACE_CAPS.badge)

SdkComponent

One of Songstress's components. On the server none of their props takes a function (songstress/ui/server's JSX); an author's own component keeps its function props there.

export type SdkComponent<Props> = ((props: Props) => UiElement) & {
    readonly [sdk]: true;
};

Refers to UiElement.

SearchField

The app's search field: a search-field node, told what it holds.

export declare const SearchField: import("./types").SdkComponent<SearchFieldProps>;
Example
import { SearchField, useState } from 'songstress/ui'

function Find() {
  const [term, setTerm] = useState('')
  return <SearchField placeholder="Search your plays" value={term} onChange={setTerm} />
}

Refers to SdkComponent, SearchFieldProps.

SearchFieldProps

A SearchField's props.

Prop

Type

Refers to SearchFieldBlock, Handler.

Section

Blocks under a heading: a section node.

export declare const Section: import("./types").SdkComponent<SectionProps>;
Example
import { Section, Text } from 'songstress/ui'

const today = (
  <Section title="Today" footer="Counted on this device.">
    <Text>3 songs started</Text>
  </Section>
)

Refers to SdkComponent, SectionProps.

SectionProps

A Section's props.

Prop

Type

Refers to SectionBlock, UiNode.

Segmented

One of a few, side by side: a segmented node, told the option's value.

export declare const Segmented: import("./types").SdkComponent<SegmentedProps>;
Example
import { Segmented, useState } from 'songstress/ui'

function Span() {
  const [span, setSpan] = useState('week')
  return (
    <Segmented
      label="Over"
      options={[{ value: 'week', title: 'Week' }, { value: 'year', title: 'Year' }]}
      value={span}
      onChange={setSpan}
    />
  )
}

Refers to SdkComponent, SegmentedProps.

SegmentedProps

A Segmented's props.

Prop

Type

Refers to SegmentedBlock, Handler.

Select

One of a list, in a menu: a select node, told the option's value.

export declare const Select: import("./types").SdkComponent<SelectProps>;
Example
import { Select, useState } from 'songstress/ui'

const ORDERS = [
  { value: 'recent', title: 'Most recent' },
  { value: 'plays', title: 'Most played' },
]

function Order() {
  const [order, setOrder] = useState('recent')
  return <Select label="Sort by" options={ORDERS} value={order} onChange={setOrder} />
}

Refers to SdkComponent, SelectProps.

SelectProps

A Select's props.

Prop

Type

Refers to SelectBlock, Handler.

Shelf

A row of cards that scrolls sideways: a shelf node, its cards its children.

export declare const Shelf: import("./types").SdkComponent<ShelfProps>;
Example
import { MediaCard, Shelf } from 'songstress/ui'

const mixes = (
  <Shelf title="Mixes">
    <MediaCard id="night" title="Night radio" image={{ asset: 'images/night.png' }} onPress={{ type: 'navigate', to: { page: 'night' } }} />
    <MediaCard id="morning" title="Morning" image={{ asset: 'images/morning.png' }} onPress={{ type: 'navigate', to: { page: 'morning' } }} />
  </Shelf>
)

Refers to SdkComponent, ShelfProps.

ShelfProps

A Shelf's props: its cards are its children (MediaCard, SongItem, AlbumItem, ArtistItem, PlaylistItem).

Prop

Type

Refers to ShelfBlock, UiNode.

SignedImage

A picture as the server hands it over: an address on the web comes with the server's signature (sig), the one its image route asks for, so the route fetches only what one of the extension's trees named; one of the extension's files with the digest of the file it found for the member looking (sha256).

export type SignedImage = ImageSource & {
    sig?: string;
    sha256?: string;
};

Refers to ImageSource.

Skeleton

The app's placeholder while something loads: a skeleton node.

export declare const Skeleton: import("./types").SdkComponent<SkeletonProps>;
Example
import { Skeleton } from 'songstress/ui'

const loading = <Skeleton shape="row" count={3} />

Refers to SdkComponent, SkeletonProps.

SkeletonProps

A Skeleton's props.

export type SkeletonProps = Own<SkeletonBlock>;

Refers to SkeletonBlock.

Slider

A number in a range: a slider node, told a number.

export declare const Slider: import("./types").SdkComponent<SliderProps>;
Example
import { Slider, useState } from 'songstress/ui'

function Fade() {
  const [seconds, setSeconds] = useState(4)
  return <Slider label="Fade" value={seconds} minimum={0} maximum={12} step={1} onChange={setSeconds} />
}

Refers to SdkComponent, SliderProps.

SliderProps

A Slider's props.

Prop

Type

Refers to SliderBlock, Handler.

SongItem

A song of the library, drawn as Songstress draws it: a song node.

export declare const SongItem: import("./types").SdkComponent<LibraryItemProps>;
Example
import { List, SongItem } from 'songstress/ui'

const songIds = ['s1', 's2']
const recent = <List title="Played lately">{songIds.map((id) => <SongItem key={id} id={id} />)}</List>

Refers to SdkComponent, LibraryItemProps.

Spacer

Room between blocks: a spacer node.

export declare const Spacer: import("./types").SdkComponent<SpacerProps>;
Example
import { HStack, Spacer, Text } from 'songstress/ui'

// In an HStack, a Spacer takes the room left: the count goes to the far end.
const line = (
  <HStack>
    <Text>So What</Text>
    <Spacer />
    <Text tone="muted">12 plays</Text>
  </HStack>
)

Refers to SdkComponent, SpacerProps.

SpacerProps

A Spacer's props.

export type SpacerProps = Own<SpacerBlock>;

Refers to SpacerBlock.

Sprite

One row of an image of frames, played: a sprite node.

export declare const Sprite: import("./types").SdkComponent<SpriteProps>;
Example
import { Sprite } from 'songstress/ui'

// Eight frames of 32 points in a row of the package's own image, twelve a second.
const bars = <Sprite source={{ asset: 'images/bars.png' }} frameWidth={32} frameHeight={32} frames={8} rate={12} loop description="Bars that move" />

Refers to SdkComponent, SpriteProps.

SpriteProps

A Sprite's props.

export type SpriteProps = Own<SpriteBlock>;

Refers to SpriteBlock.

SpriteRun

One animation of a sprite, ready to draw: the image's grid, the row, how many of its frames, and how long one pass of them takes.

Prop

Type

Stack

Blocks under one another: a stack node.

export declare const Stack: import("./types").SdkComponent<StackProps>;
Example
import { Stack, Text } from 'songstress/ui'

const header = (
  <Stack gap="xsmall">
    <Text style="heading">Played lately</Text>
    <Text tone="muted">12 songs this week</Text>
  </Stack>
)

Refers to SdkComponent, StackProps.

StackProps

A Stack's or an HStack's props.

Prop

Type

Refers to StackBlock, UiNode.

SurfaceDeclared

What one extension declares, which a state is held to.

Prop

Type

Refers to ContextKey, AssetSize.

SurfaceState

What code set of one extension's surfaces, as an app reads it.

Prop

Type

Refers to DrawnStatus.

Switch

On or off, as a switch: a switch node, told a boolean.

export declare const Switch: import("./types").SdkComponent<SwitchProps>;
Example
import { Switch, useState } from 'songstress/ui'

function Loud() {
  const [loud, setLoud] = useState(false)
  return <Switch label="Loud" help="Plays the next song louder." value={loud} onChange={setLoud} />
}

Refers to SdkComponent, SwitchProps.

SwitchProps

A Switch's props.

Prop

Type

Refers to SwitchBlock, Handler.

TONES

Colour by what it means; the theme decides the colour itself.

export declare const TONES: readonly Tone[];

Refers to Tone.

Tab

One tab of a Tabs: its id, its title on the switcher, and its blocks.

export declare const Tab: import("./types").SdkComponent<TabProps>;
Example
import { Tab, Tabs, Text } from 'songstress/ui'

const totals = (
  <Tabs>
    <Tab id="week" title="This week" icon="calendar"><Text>42 plays</Text></Tab>
    <Tab id="year" title="This year"><Text>1,204 plays</Text></Tab>
  </Tabs>
)

Refers to SdkComponent, TabProps.

TabProps

A Tab's props: one tab of a Tabs.

Prop

Type

Refers to IconName, UiNode.

Table

Rows of cells under column headings: a table node.

export declare const Table: import("./types").SdkComponent<TableProps>;
Example
import { Table } from 'songstress/ui'

const top = (
  <Table
    columns={[{ id: 'song', title: 'Song' }, { id: 'plays', title: 'Plays', align: 'end' }]}
    rows={[{ id: 's1', cells: ['So What', 12] }, { id: 's2', cells: ['Blue in Green', 9] }]}
  />
)

Refers to SdkComponent, TableProps.

TableProps

A Table's props.

Prop

Type

Refers to TableBlock, TableRow.

TableRow

A row of a Table.

Prop

Type

Refers to TableCell, Handler.

Tabs

One of several groups of blocks, under a switcher: a tabs node, its tabs its Tab children.

export declare const Tabs: import("./types").SdkComponent<TabsProps>;
Example
import { Tab, Tabs, Text, useState } from 'songstress/ui'

function Totals() {
  const [tab, setTab] = useState('week')
  return (
    <Tabs value={tab} onSelect={setTab}>
      <Tab id="week" title="This week"><Text>42 plays</Text></Tab>
      <Tab id="year" title="This year"><Text>1,204 plays</Text></Tab>
    </Tabs>
  )
}

Refers to SdkComponent, TabsProps.

TabsProps

A Tabs's props: its tabs are its children, each a Tab.

Prop

Type

Refers to TabsBlock, Handler, UiNode.

Text

Words, in one of six styles: a text node. Its words are its children, or text.

export declare const Text: import("./types").SdkComponent<TextProps>;
Example
import { Text } from 'songstress/ui'

const title = <Text style="title">Played lately</Text>
const note = <Text tone="muted" lines={2}>{`${12} songs, the last one an hour ago`}</Text>

Refers to SdkComponent, TextProps.

TextInput

A line of text, or several: a text-field node, told what it holds.

export declare const TextInput: import("./types").SdkComponent<TextInputProps>;
Example
import { TextInput, useState } from 'songstress/ui'

function MixName() {
  const [name, setName] = useState('')
  return (
    <TextInput
      label="Name"
      placeholder="A name for the mix"
      value={name}
      onChange={setName}
      onSubmit={(value) => ({ type: 'toast', message: `Saved ${value}` })}
    />
  )
}

Refers to SdkComponent, TextInputProps.

TextInputProps

A TextInput's props: the text-field node.

Prop

Type

Refers to TextFieldBlock, Handler.

TextProps

A Text's props: its words are its children joined, or text.

Prop

Type

Refers to TextBlock, UiNode.

Tree

Nodes that hold nodes, as a block: a tree node, its top nodes its children. A node's open is how it stands at first: the app keeps what the person opens and closes, and tells onExpand.

export declare const Tree: import("./types").SdkComponent<TreeProps>;
Example
import { Tree, TreeItem } from 'songstress/ui'

// 2026 stands open at first; a tap closes it, and the handler is told.
const years = (
  <Tree onExpand={({ id, open }) => console.log(id, open)}>
    <TreeItem id="2026" title="2026" open>
      <TreeItem id="2026-11" title="November" subtitle="42 plays" />
    </TreeItem>
  </Tree>
)

Refers to SdkComponent, TreeProps.

TreeItem

A node of a Tree: a node node, onPress its action, the nodes under it its children.

export declare const TreeItem: import("./types").SdkComponent<TreeItemProps>;
Example
import { Tree, TreeItem } from 'songstress/ui'

// A node whose nodes come later: `expandable`, and the tree's onExpand loads them.
const folders = (
  <Tree onExpand={{ type: 'refresh' }}>
    <TreeItem id="jazz" title="Jazz" icon="folder" expandable />
  </Tree>
)

Refers to SdkComponent, TreeItemProps.

TreeItemProps

A TreeItem's props: a tree's node; its children are the nodes under it (TreeItem, SongItem).

Prop

Type

Refers to TreeNode, UiNode.

TreeProps

A Tree's props: its top nodes are its children (TreeItem, SongItem).

Prop

Type

Refers to TreeBlock, Handler, UiNode.

TreeRead

A tree as an app read it: the tree it draws, or why it draws none.

export type TreeRead<Tree> = {
    ok: true;
    tree: Tree;
} | {
    ok: false;
    reason: Refusal;
};

Refers to Tree, Refusal.

UI_CAPS

What an app draws of one tree, at most (SPEC.md section 10: "the apps cap a tree's size, depth and number of rows ... and do not draw a tree over a cap"). A tree over a count is refused whole; a text over its length is cut.

export declare const UI_CAPS: {
    readonly nodes: 1500;
    readonly depth: 16;
    readonly items: 200;
    readonly sections: 30;
    readonly menu: 10;
    readonly fields: 50;
    readonly options: 100;
    readonly buttons: 2;
    readonly status: 24;
    readonly shelf: 30;
    readonly title: 120;
    readonly text: 2000;
    readonly handlers: 300;
    readonly bytes: 262144;
    readonly tabs: 6;
    readonly columns: 8;
    readonly segments: 5;
    readonly prose: 16;
    readonly lines: 6;
    readonly key: 64;
    readonly canvases: 2;
    readonly canvasSide: 720;
    readonly spriteFrames: 64;
    readonly spriteSide: 256;
    readonly spriteRate: 30;
    readonly spriteFrameMinMs: 16;
    readonly spriteFrameMaxMs: 10000;
    readonly overlayNodes: 60;
};
Example
import { UI_CAPS } from 'songstress/ui'

declare const songs: { id: string; title: string }[]

// One answer of a list holds at most UI_CAPS.items rows: the rest come by `nextCursor`.
const rows = songs.slice(0, UI_CAPS.items).map((song) => ({ type: 'row' as const, id: song.id, title: song.title }))

UiElement

What a component of songstress/ui makes: an element of a tree. Opaque: nothing but a component makes one. A renderer may answer one in place of a hand-written tree.

Prop

Type

UiNode

What a component holds as children, and what one may answer: an element, text, a hand-written node, nothing, or a list of these.

export type UiNode = UiElement | Block | Row | Card | TreeNode | string | number | boolean | null | undefined | readonly UiNode[];

Refers to UiElement, Block, Row, Card, TreeNode.

UnknownNode

A node the reader does not know, by the type it came with: an app draws it as "needs a newer app".

Prop

Type

VIEW_CAPS

What an in-app view may be, and do, at most.

export declare const VIEW_CAPS: {
    readonly fileBytes: number;
    readonly elements: 4000;
    readonly styleChars: 131072;
    readonly frames: 4;
    readonly patchOps: 200;
    readonly patchChars: 65536;
    readonly patchesPerSecond: 120;
    readonly textChars: 10000;
    readonly classChars: 1000;
    readonly pictures: 12;
    readonly picturesPerSecond: 4;
    readonly eventsPerSecond: 240;
    readonly canvases: 4;
    readonly canvasSide: 1440;
    readonly canvasPixels: 1166400;
    readonly canvasTicks: 60;
    readonly viewTicks: 120;
    readonly canvasFramesPerSecond: 130;
    readonly canvasMessagesPerSecond: 20;
    readonly postBytes: 16384;
    readonly postsPerSecond: 30;
    readonly slowFrameMs: 50;
    readonly slowWindowMs: 2000;
    readonly slowBudgetMs: 667;
    readonly opensPerMinute: 4;
};
Example
import { VIEW_CAPS } from 'songstress/ui/reader'

// A list a view keeps in its markup stays well under the app's element cap.
const rows = Math.min(500, VIEW_CAPS.elements / 4)

VIEW_IMAGE

What a view's picture may name, as the frame's script and the app read it (readViewImage): a cover of one of these kinds of the library by its id (letters and digits, as the server makes them), or one of the package's own images by its path. A picture of any other shape stops the view's code.

export declare const VIEW_IMAGE: {
    readonly covers: readonly [
        "song",
        "album",
        "artist",
        "playlist"
    ];
    readonly id: RegExp;
    readonly asset: RegExp;
    readonly assetChars: 200;
};
Example
import { VIEW_IMAGE } from 'songstress/ui/reader'

console.log(VIEW_IMAGE.id.test('4uLU6hMCjMI75M1A2tKUQC'), VIEW_IMAGE.id.test('https://example.com/a.png')) // true false

VIEW_MARKUP

The markup an app keeps of an in-app view: these elements and attributes (and any aria- or data- attribute); an input of these types; an img whose src is a data: address of these picture types. Everything else is taken out before the view is drawn: every script, link, frame, on… attribute, address and autofocus. Every field is given autocomplete="off".

export declare const VIEW_MARKUP: {
    readonly elements: readonly [
        "div",
        "span",
        "p",
        "h1",
        "h2",
        "h3",
        "h4",
        "h5",
        "h6",
        "ul",
        "ol",
        "li",
        "dl",
        "dt",
        "dd",
        "section",
        "article",
        "header",
        "footer",
        "main",
        "nav",
        "aside",
        "figure",
        "figcaption",
        "blockquote",
        "pre",
        "code",
        "em",
        "strong",
        "b",
        "i",
        "u",
        "s",
        "small",
        "sub",
        "sup",
        "mark",
        "br",
        "hr",
        "table",
        "caption",
        "colgroup",
        "col",
        "thead",
        "tbody",
        "tfoot",
        "tr",
        "th",
        "td",
        "style",
        "canvas",
        "img",
        "form",
        "button",
        "input",
        "select",
        "option",
        "optgroup",
        "textarea",
        "label",
        "fieldset",
        "legend",
        "progress",
        "meter",
        "output",
        "details",
        "summary"
    ];
    readonly attributes: readonly [
        "id",
        "class",
        "style",
        "title",
        "lang",
        "dir",
        "hidden",
        "tabindex",
        "role",
        "alt",
        "width",
        "height",
        "for",
        "name",
        "type",
        "value",
        "placeholder",
        "checked",
        "disabled",
        "readonly",
        "required",
        "min",
        "max",
        "step",
        "multiple",
        "selected",
        "rows",
        "cols",
        "maxlength",
        "minlength",
        "open",
        "colspan",
        "rowspan",
        "scope",
        "src"
    ];
    readonly attributePrefixes: readonly [
        "aria-",
        "data-"
    ];
    readonly inputTypes: readonly [
        "text",
        "search",
        "number",
        "range",
        "checkbox",
        "radio",
        "color",
        "date",
        "time",
        "email",
        "tel",
        "url",
        "button",
        "submit",
        "reset"
    ];
    readonly pictureTypes: readonly [
        "image/png",
        "image/jpeg",
        "image/webp"
    ];
};
Example
import { VIEW_MARKUP } from 'songstress/ui/reader'

const kept = (tag: string) => (VIEW_MARKUP.elements as readonly string[]).includes(tag)
console.log(kept('canvas'), kept('script')) // true false

VIEW_STYLE

What no in-app view's style may hold, in a style element or attribute, as the app and the frame's script read each (viewStyleRefused): text-security, with any prefix (-webkit-text-security), however it is written (in capitals, with CSS escapes, between comments). It draws what a person types as a password field's dots, and a view never dresses a field as a password box: a page of an extension's that asks for a password is what the frame exists to prevent. A view whose style holds it is not drawn. The word is refused as a name of its own wherever it stands, so a class of that exact name is refused too; --text-security-hint or .no-text-security is not.

export declare const VIEW_STYLE: {
    readonly escape: RegExp;
    readonly refused: RegExp;
};
Example
import { VIEW_STYLE } from 'songstress/ui/reader'

console.log(VIEW_STYLE.refused.test('input { -webkit-text-security: disc }')) // true

VIEW_TOKENS

The CSS variables an in-app view is handed, each --songstress- and a token of the theme that is on (dots as dashes), with the app's font, its monospace font, its corner radius and its focus ring: so a view's own CSS can look like the app with var(--songstress-text). The document's root also carries the class dark or light, and reduced-motion while the person asks for less motion.

export declare const VIEW_TOKENS: readonly [
    "--songstress-background",
    "--songstress-surface",
    "--songstress-surface-raised",
    "--songstress-surface-hover",
    "--songstress-border",
    "--songstress-text",
    "--songstress-text-muted",
    "--songstress-text-faint",
    "--songstress-accent",
    "--songstress-accent-fill",
    "--songstress-accent-fill-pressed",
    "--songstress-accent-on-fill",
    "--songstress-success",
    "--songstress-warning",
    "--songstress-danger",
    "--songstress-info",
    "--songstress-font",
    "--songstress-font-mono",
    "--songstress-radius",
    "--songstress-focus"
];
Example
import { VIEW_TOKENS } from 'songstress/ui/reader'

const css = `button { background: var(${VIEW_TOKENS[0]}) }`

Refers to songstress, on.

ViewFrameMessage

What the frame's script hands a view's worker, on the worker's own channel (not the bridge's text): the start, an event, and a canvas's tick, a frame wanted of the canvas whose element has that id.

export type ViewFrameMessage = ViewStart | {
    t: 'event';
    event: ViewEvent;
} | {
    t: 'tick';
    canvas: string;
    tick: number;
    frame: {
        width: number;
        height: number;
        pixelRatio: number;
        time: number;
    };
};

Refers to ViewStart, ViewEvent.

ViewPatchOp

One change of a patch: an element, by its id, and what of it changes.

export type ViewPatchOp = [
    id: string,
    field: 'text' | 'class',
    value: string
] | [
    id: string,
    field: 'hidden',
    value: boolean
] | [
    id: string,
    field: 'value',
    value: string | number | boolean
] | [
    id: string,
    field: 'image',
    value: ViewImage | null
];

Refers to ViewImage.

ViewPatchRead

A patch as the frame's script reads it: the changes to apply, or why it refuses the patch (and, with it, stops the worker).

export type ViewPatchRead = {
    ok: true;
    ops: ViewPatchOp[];
} | {
    ok: false;
    why: string;
};

Refers to ViewPatchOp.

ViewStart

What the frame tells a view's code once, before any event: which view, opened with what, at what size, in which theme, and whether it may draw on a canvas here. Changes come after as events (resize, theme, motion).

Prop

Type

Refers to ViewTheme.

ViewTreeNode

A node of a view's file as an HTML parser builds it, in what the browser's DOM and a parser's own tree (parse5's) both give: so the app and songstress check read one file alike (viewWeight). An element has a tagName; a text holds its characters in nodeValue (the DOM) or value (parse5); an element's attributes are its attributes (the DOM) or attrs (parse5).

Prop

Type

ViewWeight

What an app holds a view's file to, read from the file as parsed (viewWeight).

Prop

Type

ViewWorkerMessage

What a view's worker hands the frame's script, on the same channel: a patch, a canvas it draws on (or no longer does), and a frame drawn for a tick, as a bitmap. Anything else stops the worker.

export type ViewWorkerMessage = {
    t: 'patch';
    ops: ViewPatchOp[];
} | {
    t: 'canvas';
    id: string;
    context: '2d' | 'webgl2';
    motion: 'decorative' | 'essential';
    pointer: boolean;
} | {
    t: 'canvas';
    id: string;
    off: true;
} | {
    t: 'frame';
    canvas: string;
    tick: number;
    bitmap: unknown;
};

Refers to ViewPatchOp.

WIDTHS

Across its parent, or as wide as what it holds.

export declare const WIDTHS: readonly Width[];

Refers to Width.

confirmed

Asks first, then calls then, a function of client code, when the person agrees: a confirm action around a handler of its own. Asks first, then does then, an action, when the person agrees: a ConfirmAction, itself an action, so it is a handler in a server file (songstress/ui/server) too. Asks first, then runs then when the person agrees: a handler that is an action or a function of client code.

export declare function confirmed<Payload = void>(question: {
    title: string;
    message?: string;
    confirm?: string;
    destructive?: boolean;
}, then: HandlerFunction<Payload>): Handler<Payload>;
export declare function confirmed(question: {
    title: string;
    message?: string;
    confirm?: string;
    destructive?: boolean;
}, then: Action): ConfirmAction;
export declare function confirmed<Payload = void>(question: {
    title: string;
    message?: string;
    confirm?: string;
    destructive?: boolean;
}, then: Handler<Payload>): Handler<Payload>;
ParameterTypeDescription
question{ title: string; message?: string; confirm?: string; destructive?: boolean; }What is asked: its title, a message, the word on the button that agrees (confirm), and whether yes is destructive.
thenHandlerFunction<Payload>What runs on yes.

Returns Handler<Payload>; export declare function confirmed(question: { title: string; message?: string; confirm?: string; destructive?: boolean; }, then: Action): ConfirmAction; export declare function confirmed<Payload = void>(question: { title: string; message?: string; confirm?: string; destructive?: boolean; }, then: Handler<Payload>): Handler<Payload>.

Example
import { Button, confirmed, useState } from 'songstress/ui'

function Reset() {
  const [count, setCount] = useState(3)
  return <Button title={`Start again from ${count}`} onPress={confirmed({ title: 'Start again from 0?' }, () => setCount(0))} />
}

Refers to HandlerFunction, Handler, Action, ConfirmAction.

controlValue

What a control shows: what the person did, from the moment its event was sent until the mount has handled that event (an ack at or above its seq), and the tree's value from then on. So a tree that left the worker before the person's last keystroke never takes a letter away, and a handler that refuses a change still has the last word.

export declare function controlValue<Value>(local: Value | undefined, tree: Value, lastSent: number, ack: number): Value;
ParameterTypeDescription
localValue | undefinedWhat the person did, or undefined when they have done nothing yet.
treeValueThe value the newest tree holds.
lastSentnumberThe seq of the last event this control sent (0 for none).
acknumberThe newest ack the mount sent.

Returns Value.

Example
import { controlValue } from 'songstress/ui/reader'

controlValue('abc', 'ab', 7, 6) // 'abc': event 7 is not handled yet
controlValue('abc', 'ab', 7, 7) // 'ab': handled, and the handler kept "ab"

handledOf

What a control does, as an app reads it from a drawn tree: an action, a function of the extension's client code by the id its mount gave it ({ $handler: n }, which the app sends back to that mount as an event), or a confirm around either; null when it is neither. A server-rendered tree never holds a handler reference: the server's reader drops one.

export declare function handledOf(value: unknown): Handled | null;
ParameterTypeDescription
valueunknownWhat the tree holds where a handler stands.

Returns Handled | null.

Example
import { handledOf } from 'songstress/ui/reader'

handledOf({ $handler: 4 }) // { $handler: 4 }
handledOf({ type: 'toast', message: 'Saved' }) // the action, as readAction reads it
handledOf({ $handler: 1.5 }) // null

Refers to Handled.

imageFileName

The name of a stored image (PNG, JPEG or WebP), else "": what a tree may name as { file }.

export declare function imageFileName(value: unknown): string;
ParameterTypeDescription
valueunknownAny JSON value.

Returns string.

Example
import { imageFileName } from 'songstress/ui'

imageFileName('pets/prince.webp') // 'pets/prince.webp'
imageFileName('pets/pet.json') // ''

isKnownIcon

Whether name is one of the set's names, which an app draws as its own glyph; any other is drawn as the extension mark.

export declare function isKnownIcon(name: unknown): name is KnownIconName;
ParameterTypeDescription
nameunknown

Returns name is KnownIconName.

Example
import { isKnownIcon } from 'songstress/ui'

isKnownIcon('heart') // true
isKnownIcon('unicorn') // false: drawn as the extension mark

Refers to KnownIconName.

isWebAddress

Whether value is an address an app follows or fetches for a tree: http or https, with a host, no spaces, and 2,000 characters at most. An openUrl action or an image with any other address is left out.

export declare function isWebAddress(value: unknown): value is string;
ParameterTypeDescription
valueunknownThe address.

Returns value is string.

Example
import { isWebAddress } from 'songstress/ui'

isWebAddress('https://example.com/album/1') // true
isWebAddress('ftp://example.com/album/1') // false

listOf

value when it is an array, else [].

export declare const listOf: (value: unknown) => unknown[];
Example
import { listOf } from 'songstress/ui'

listOf([1, 2]).length // 2
listOf({ length: 2 }).length // 0

mergeSurfaceState

Layers of one extension's state laid one over another, key by key: a later layer's value stands over an earlier one's. An app lays every member's, then the member's, then this device's.

export declare function mergeSurfaceState(...layers: SurfaceState[]): SurfaceState;
ParameterTypeDescription
...layersSurfaceState[]The layers, the lowest first.

Returns SurfaceState.

Example
import { mergeSurfaceState } from 'songstress/ui/reader'

const empty = { badges: {}, context: {}, status: {}, overlays: {} }
const merged = mergeSurfaceState({ ...empty, badges: { inbox: 2 } }, { ...empty, badges: { inbox: 'dot' } })
// merged.badges.inbox === 'dot'

Refers to SurfaceState.

numberOf

value when it is a finite number, else null.

export declare const numberOf: (value: unknown) => number | null;
Example
import { numberOf } from 'songstress/ui'

numberOf(3.5) // 3.5
numberOf('3.5') // null

objectOf

value when it is a plain object, else {}.

export declare const objectOf: (value: unknown) => Record<string, unknown>;
Example
import { objectOf } from 'songstress/ui'

objectOf({ id: 'a' }).id // 'a'
objectOf(['a']).id // undefined: a list is no object

readAction

What a tap does, as an app reads an action an extension handed it (a command's outcome, a button's, a row's): null when it is no action an app carries out. A question (a confirm, a pick, an input, a notice) may lead to one more, and no further.

export declare function readAction(value: unknown): Action | null;
ParameterTypeDescription
valueunknownThe action, as the extension wrote it.

Returns Action | null.

Example
import { readAction } from 'songstress/ui'

console.log(readAction({ type: 'toast', message: 'Saved' })) // { type: 'toast', message: 'Saved' }
console.log(readAction({ type: 'teleport' })) // null

Refers to Action.

readOverlay

An overlay, as an app reads what its renderer answered: read as a panel is, held to UI_CAPS.overlayNodes nodes. tree is null when it has nothing to show now.

export declare function readOverlay(value: unknown, assets?: readonly AssetSize[]): TreeRead<DrawnPanel | null>;
ParameterTypeDescription
valueunknownWhat the renderer answered.
assets?readonly AssetSize[]The package's images and their sizes, as for readScreen.

Returns TreeRead<DrawnPanel | null>.

Example
import { readOverlay } from 'songstress/ui'

const read = readOverlay({ children: [{ type: 'text', text: 'Asleep' }] })
console.log(read.ok ? read.tree?.children.length : read.reason) // 1

Refers to AssetSize, TreeRead, DrawnPanel.

readPanel

A panel, as an app reads what an extension's renderer answered; tree is null when the panel has nothing to show here and is left out (nothing, or nothing readable). Only a panel over one of UI_CAPS is refused.

export declare function readPanel(value: unknown, assets?: readonly AssetSize[]): TreeRead<DrawnPanel | null>;
ParameterTypeDescription
valueunknownWhat the renderer answered.
assets?readonly AssetSize[]The package's images and their sizes, as for readScreen.

Returns TreeRead<DrawnPanel | null>.

Example
import { readPanel } from 'songstress/ui'

const read = readPanel({ children: [{ type: 'text', text: 'Played 12 times this week' }] })
console.log(read.ok ? read.tree?.children.length : read.reason) // 1

Refers to AssetSize, TreeRead, DrawnPanel.

readScreen

A page, as an app reads what an extension's renderer answered: ok with the tree it draws, or why it draws none (too-large: over one of UI_CAPS; unreadable: not a screen). A node it does not know is kept as { type: 'unknown' }, drawn as "needs a newer app"; a part an extension may not say is left out.

export declare function readScreen(value: unknown, assets?: readonly AssetSize[]): TreeRead<DrawnScreen>;
ParameterTypeDescription
valueunknownWhat the renderer answered.
assets?readonly AssetSize[]The package's images and their sizes, from the extension's entry in the server's contributions list: with them, a sprite whose frames do not fit its image is left out.

Returns TreeRead<DrawnScreen>.

Example
import { readScreen } from 'songstress/ui'

const page = { type: 'list', sections: [{ items: [{ type: 'row', id: 'a', title: 'Blue in Green' }] }] }
const read = readScreen(page)
// Kept whole: every app draws this page as written.
console.log(read.ok && JSON.stringify(read.tree) === JSON.stringify(page))

Refers to AssetSize, TreeRead, DrawnScreen.

readStatus

A status item, as an app reads what its renderer answered or code set; null when it has nothing to say now (nothing, or neither words, an icon nor a sprite). Its words are cut to UI_CAPS.status characters, its progress held between 0 and 1; its sprite is read as a sprite block is.

export declare function readStatus(value: unknown, assets?: readonly AssetSize[]): DrawnStatus | null;
ParameterTypeDescription
valueunknownWhat the renderer answered.
assets?readonly AssetSize[]The package's images and their sizes: with them, a sprite whose frames do not fit its image is left out.

Returns DrawnStatus | null.

Example
import { readStatus } from 'songstress/ui'

console.log(readStatus({ text: 'Synced', icon: 'sync', progress: 1.5 })) // { text: 'Synced', icon: 'sync', progress: 1 }

Refers to AssetSize, DrawnStatus.

readSurfaceState

One layer of an extension's state, as an app reads what it was handed (the server's answer, a push, or client code's own writes): each badge, key, status item and overlay the extension declares, read by its rules; anything else left out. A text is checked against SURFACE_CAPS.bytes before it is parsed; one over it, or one that is not JSON, reads as an empty state.

export declare function readSurfaceState(value: unknown, declared: SurfaceDeclared): SurfaceState;
ParameterTypeDescription
valueunknownThe state, as JSON text or as parsed JSON.
declaredSurfaceDeclaredWhat the extension declares.

Returns SurfaceState.

Example
import { readSurfaceState } from 'songstress/ui/reader'

const declared = { sidebar: ['inbox'], context: [{ key: 'asleep', type: 'boolean' as const }], status: [], overlays: ['pet'] }
const state = readSurfaceState({ badges: { inbox: 3, other: 1 }, context: { asleep: 'yes' }, overlays: { pet: false } }, declared)
// { badges: { inbox: 3 }, context: {}, status: {}, overlays: { pet: false } }

Refers to SurfaceDeclared, SurfaceState.

readUpdate

An answer of a mount (to a mount, context, event, tick or unmount) or a push through MOUNT_PUSH, read field by field. Anything without $mount: 1 is plain: the tree itself, from a bundle that holds no mount (built before API 0.1.12, or one whose renderer answers a hand-written tree), drawn as it is drawn today. A count that is not a whole number, a mount id that is not one, or a tree longer than UI_CAPS.bytes is refused. Whether an n rose and an ack is one the app sent is the app's to check, against what it holds of that mount.

export declare function readUpdate(value: unknown): MountUpdate;
ParameterTypeDescription
valueunknownWhat the renderer answered, or the push's one argument.

Returns MountUpdate.

Example
import { readUpdate } from 'songstress/ui/reader'

readUpdate({ $mount: 1, n: 1, ack: 0, tree: '{"type":"detail","children":[]}' })
// { kind: 'render', n: 1, ack: 0, tree: '{"type":"detail","children":[]}' }
readUpdate({ type: 'detail', children: [] }) // { kind: 'plain', value: … }: an older bundle's tree

Refers to MountUpdate.

readViewImage

A view's picture as the frame's script and the app read it: a cover of the library (one of VIEW_IMAGE.covers, by a library id) or one of the package's images (a plain path in the package); null, no picture; and undefined for anything else, which names no address the app would load.

export declare function readViewImage(value: unknown): ViewImage | null | undefined;
ParameterTypeDescription
valueunknownThe image change's value.

Returns ViewImage | null | undefined.

Example
import { readViewImage } from 'songstress/ui/reader'

console.log(readViewImage({ cover: 'album', id: '4uLU6hMCjMI75M1A2tKUQC' })) // { cover: 'album', id: '4uLU6hMCjMI75M1A2tKUQC' }
console.log(readViewImage({ cover: 'coverArt', id: 'https://example.com/a.png' })) // undefined

Refers to ViewImage.

readViewPatch

A patch as the frame's script reads what a view's worker posted: its changes, or why it is refused whole (more than VIEW_CAPS.patchOps changes, more than VIEW_CAPS.patchChars characters counted as viewOpChars counts them, or one change of another shape).

export declare function readViewPatch(value: unknown): ViewPatchRead;
ParameterTypeDescription
valueunknownWhat the worker posted.

Returns ViewPatchRead.

Example
import { readViewPatch } from 'songstress/ui/reader'

console.log(readViewPatch({ t: 'patch', ops: [['count', 'text', '3']] }).ok) // true
console.log(readViewPatch({ t: 'patch', ops: [['link', 'href', 'https://example.com']] }).ok) // false

Refers to ViewPatchRead.

spriteRuns

A sprite's first animation and the one that follows it (then, which plays at the sprite's own rate when it names none), or null when its frames do not fit its image: more frames than the image has across, or a row below its last.

export declare function spriteRuns(sprite: SpriteBlock, asset: {
    width: number;
    height: number;
}): {
    first: SpriteRun;
    then?: SpriteRun;
} | null;
ParameterTypeDescription
spriteSpriteBlockThe sprite, as the reader kept it.
asset{ width: number; height: number; }Its image's size in pixels, from the extension's list of assets.

Returns { first: SpriteRun; then?: SpriteRun; } | null.

Example
import { spriteRuns } from 'songstress/ui/reader'

const sprite = { type: 'sprite' as const, source: { asset: 'assets/pet.webp' }, frameWidth: 192, frameHeight: 208, frames: 6, row: 1, loop: false, then: { row: 0, frames: 6 } }
const runs = spriteRuns(sprite, { width: 1536, height: 1872 })
// runs?.first: row 1, 6 frames over 750 ms, once; runs?.then: row 0, again and again

Refers to SpriteBlock, SpriteRun.

storedFileType

What a stored file of this name is, or null for a name the store refuses: 1 to 128 characters, up to three folders, ending in one of STORED_FILE_TYPES' endings.

export declare function storedFileType(name: unknown): StoredType | null;
ParameterTypeDescription
nameunknownThe file's name.

Returns StoredType | null.

Example
import { storedFileType } from 'songstress/ui'

storedFileType('pets/prince.webp') // 'image/webp'
storedFileType('../secret.png') // null

Refers to StoredType.

stringsOf

The strings in value when it is an array, else [].

export declare const stringsOf: (value: unknown) => string[];
Example
import { stringsOf } from 'songstress/ui'

stringsOf(['a', 1, 'b']) // ['a', 'b']

textOf

value when it is a string, else "".

export declare const textOf: (value: unknown) => string;
Example
import { textOf } from 'songstress/ui'

textOf('Blue in Green') // 'Blue in Green'
textOf(42) // ''

uploadFolder

An upload's folder: up to three parts joined by / (a / at its end is dropped), "" for none, null for one the store would refuse.

export declare function uploadFolder(value: unknown): string | null;
ParameterTypeDescription
valueunknownAny JSON value.

Returns string | null.

Example
import { uploadFolder } from 'songstress/ui'

uploadFolder('pets/') // 'pets'
uploadFolder('Pets') // null

useAsync

What an async function answered for these deps: loading until it does, then data (or error). An answer for deps that have since changed, or that comes once the component is gone, is ignored. In one pass it holds loading: true: a server renderer awaits what it needs before it answers.

export declare function useAsync<Data>(load: () => Promise<Data>, deps: readonly unknown[]): AsyncState<Data>;
ParameterTypeDescription
load() => Promise<Data>Asks for the data.
depsreadonly unknown[]What it depends on: it asks again when one changes.

Returns AsyncState<Data>.

Example
import { Skeleton, Text, useAsync } from 'songstress/ui'
import { songstress } from 'songstress/client'

export function Synced() {
  const at = useAsync(() => songstress.storage.get<string>('synced-at'), [])
  if (at.loading) return <Skeleton />
  return <Text>{at.data ? `Synced ${at.data}` : 'Not synced yet'}</Text>
}

Refers to AsyncState.

useCallback

The same function while its deps hold, for a component that compares it.

export declare function useCallback<Fn extends (...args: never[]) => unknown>(fn: Fn, deps: readonly unknown[]): Fn;
Example
import { Switch, useCallback, useState } from 'songstress/ui'

export function Loud() {
  const [loud, setLoud] = useState(false)
  const toggle = useCallback((on: boolean) => setLoud(on), [])
  return <Switch label="Loud" value={loud} onChange={toggle} />
}

useEffect

Work done after the tree is handed over: a timer, a listener. The function it answers cleans up, before the effect runs again (when a dep changes) and when the component goes. It never runs in one pass.

export declare function useEffect(effect: () => void | (() => void), deps?: readonly unknown[]): void;
ParameterTypeDescription
effect() => void | (() => void)The work; it may answer its clean-up.
deps?readonly unknown[]What it depends on: it runs again when one changes. Left out, after every render.

Returns void.

Example
import { Text, useEffect, useState } from 'songstress/ui'

export function Clock() {
  const [now, setNow] = useState(() => new Date())
  useEffect(() => {
    const timer = setInterval(() => setNow(new Date()), 1000)
    return () => clearInterval(timer)
  }, [])
  return <Text>{now.toISOString().slice(11, 19)}</Text>
}

useMemo

A value worked out again only when one of its deps changes.

export declare function useMemo<Value>(make: () => Value, deps: readonly unknown[]): Value;
ParameterTypeDescription
make() => ValueWorks the value out.
depsreadonly unknown[]What it depends on.

Returns Value.

Example
import { Text, useMemo } from 'songstress/ui'

export function Total({ minutes }: { minutes: number[] }) {
  const total = useMemo(() => minutes.reduce((sum, each) => sum + each, 0), [minutes])
  return <Text>{`${total} minutes in all`}</Text>
}

usePlayer

This device's player, kept current: what player.getState answers, then the state each player hook hands over. Undefined until it is known, and always for an extension without the listening.read permission. A hook the manifest does not list under hooks.client is never delivered: list onPlay, onPause, onTrackChange, onSeek, onProgress and onVolumeChange as the component needs them.

export declare function usePlayer(): PlayerState | undefined;

Returns PlayerState | undefined.

Example
import { Text, usePlayer } from 'songstress/ui'

// The manifest asks for listening.read and lists onTrackChange under hooks.client.
export function NowPlaying() {
  const player = usePlayer()
  return <Text>{player?.song ? `Playing ${player.song.title}` : 'Nothing playing'}</Text>
}

Refers to PlayerState.

useReducer

State changed by a reducer: the next state from the state and a change.

export declare function useReducer<State, Change>(reducer: (state: State, change: Change) => State, initial: State): [
    State,
    (change: Change) => void
];
ParameterTypeDescription
reducer(state: State, change: Change) => StateWhat each change makes of the state.
initialStateThe first state.

Returns [ State, (change: Change) => void ].

Example
import { Button, Text, Stack, useReducer } from 'songstress/ui'

type Change = 'more' | 'reset'
const count = (state: number, change: Change) => (change === 'more' ? state + 1 : 0)

export function Tally() {
  const [state, change] = useReducer(count, 0)
  return (
    <Stack>
      <Text>{String(state)}</Text>
      <Button title="More" onPress={() => change('more')} />
      <Button title="Reset" emphasis="quiet" onPress={() => change('reset')} />
    </Stack>
  )
}

useRef

One object kept for the component's life: changing current renders nothing.

export declare function useRef<Value>(initial: Value): {
    current: Value;
};
ParameterTypeDescription
initialValueIts first current.

Returns { current: Value; }.

Example
import { Button, useRef } from 'songstress/ui'

export function Presses() {
  const presses = useRef(0)
  return <Button title="Press" onPress={() => void (presses.current += 1)} />
}

useSetting

One of the extension's settings, kept current: undefined until it is read, then its value, and each change to it after.

export declare function useSetting<Value extends SettingValue = SettingValue>(key: string): Value | undefined;
ParameterTypeDescription
keystringThe setting's key, as the manifest declares it.

Returns Value | undefined.

Example
import { Text, useSetting } from 'songstress/ui'

export function Greeting() {
  const name = useSetting<string>('name')
  return <Text>{`Hello, ${name ?? 'you'}`}</Text>
}

Refers to SettingValue.

useState

State of a component, kept between its renders: a change renders it again.

export declare function useState<State>(initial: State | (() => State)): [
    State,
    (next: State | ((was: State) => State)) => void
];
ParameterTypeDescription
initialState | (() => State)Its first value, or a function that makes it.

Returns [ State, (next: State | ((was: State) => State)) => void ].

Example
import { Button, Text, Stack, useState } from 'songstress/ui'

export function Counter() {
  const [count, setCount] = useState(0)
  return (
    <Stack>
      <Text>{`Pressed ${count} times`}</Text>
      <Button title="Add" onPress={() => setCount((was) => was + 1)} />
    </Stack>
  )
}

useStored

State kept in the extension's store (JSON), under key, for the member: initial until it is read (loading says when), the stored value after. set shows the new value at once and writes it; a write that fails is logged. It needs the storage permission.

export declare function useStored<Value = JsonValue>(key: string, initial: Value): [
    value: Value,
    set: (next: Value | ((was: Value) => Value)) => void,
    loading: boolean
];
ParameterTypeDescription
keystringWhere it is kept.
initialValueWhat it holds before it is read, and when nothing is kept.

Returns [ value: Value, set: (next: Value | ((was: Value) => Value)) => void, loading: boolean ].

Example
import { Switch, useStored } from 'songstress/ui'

export function Loud() {
  const [loud, setLoud, loading] = useStored('loud', false)
  return <Switch label="Loud" value={loud} disabled={loading} onChange={setLoud} />
}

Refers to JsonValue.

viewOpChars

What one change counts toward a patch's VIEW_CAPS.patchChars, as the frame counts it (its count is the contract): the element's id, and the text the change carries (a text, a class or a value that is text; a picture's kind and id, or its path).

export declare function viewOpChars(op: ViewPatchOp): number;
ParameterTypeDescription
opViewPatchOpOne change of a patch.

Returns number.

Example
import { viewOpChars } from 'songstress/ui/reader'

console.log(viewOpChars(['count', 'text', '3 plays'])) // 12

Refers to ViewPatchOp.

viewStyleRefused

Whether a view's style holds what VIEW_STYLE refuses: its escapes read, in lower case. The app refuses the view (it is not drawn), the frame's script ends it, and songstress check warns VIEW_TEXT_SECURITY.

export declare function viewStyleRefused(css: string): boolean;
ParameterTypeDescription
cssstringThe text of one style element or attribute, as the HTML parser hands it on.

Returns boolean.

Example
import { viewStyleRefused } from 'songstress/ui/reader'

console.log(viewStyleRefused('#pin { -webkit-text-\\73 ecurity: disc }'), viewStyleRefused('p { color: red }')) // true false

viewStyleUnescaped

A view's style with its CSS escapes read, as an engine reads them (a code point that is none, U+FFFD): the text every rule of VIEW_STYLE, and the app's reading of a style's pictures, is held to.

export declare function viewStyleUnescaped(css: string): string;
ParameterTypeDescription
cssstringThe text of one style element or attribute, as the HTML parser hands it on.

Returns string.

Example
import { viewStyleUnescaped } from 'songstress/ui/reader'

console.log(viewStyleUnescaped('p { background: url(d\\61 ta:image/png;base64,AA) }')) // p { background: url(data:image/png;base64,AA) }

viewWeight

What an app holds an in-app view's file to, read from the file as a browser parses it: its elements (every element of its body, its scripts among them, and each style element of its head; a table's implied tbody counts, and a < in a sheet, a comment or an attribute does not), its characters of style, and whether its style dresses a field as a password box (viewStyleRefused). The app and songstress check and build count by this, the app on its own parser's document, the command on parse5's, so a file the one takes the other takes.

export declare function viewWeight(document: ViewTreeNode): ViewWeight;
ParameterTypeDescription
documentViewTreeNodeThe view's file, parsed: the DOM's Document, or parse5's parse(file, { scriptingEnabled: false }).

Returns ViewWeight.

Example
import { viewWeight } from 'songstress/ui/reader'

// In a page: viewWeight(new DOMParser().parseFromString(file, 'text/html')). By hand, `<p style="color: red">`:
const p = { nodeName: 'P', tagName: 'P', attributes: [{ name: 'style', value: 'color: red' }] }
const html = { nodeName: 'HTML', tagName: 'HTML', childNodes: [{ nodeName: 'HEAD', tagName: 'HEAD' }, { nodeName: 'BODY', tagName: 'BODY', childNodes: [p] }] }
console.log(viewWeight({ nodeName: '#document', childNodes: [html] })) // { elements: 1, styleChars: 10, passwordStyle: false }

Refers to ViewTreeNode, ViewWeight.

withValue

The action a control's handler runs on the server, with the value the person chose in it: an invoke is handed the value as input.value (an input that is an object gains it, any other becomes { value }), and a confirm around an invoke hands it on to that invoke. Any other action runs as written, without the value. The server refuses an input of more than 8 KiB, as for any action.

export declare function withValue(action: Action, value: unknown): Action;
ParameterTypeDescription
actionActionThe control's onChange, onSubmit, onSelect or onExpand.
valueunknownWhat the control now holds (section 3 of SPEC.md's declared interface).

Returns Action.

Example
import { withValue } from 'songstress/ui/reader'

withValue({ type: 'invoke', command: 'set', input: { key: 'loud' } }, true)
// { type: 'invoke', command: 'set', input: { key: 'loud', value: true } }

Refers to Action.