import { type ClipFiles, type DeliveryInput } from './delivery.js'; import { type ClipKind, type Value } from './engine.js'; import type { Host } from './media.js'; /** What the app hears (spec/player.md, "What the app sees"). */ export interface MaskoEvents { /** The mascot entered a pose. */ pose: { pose: string; }; /** A clip, or a pose's still (`still:`), is now on screen. */ clip: { clip: string; kind: ClipKind | 'still'; rate: number; }; /** A fire is done: used by a start, or spent unused. `name` is the full name, as `action::boop`. */ reactionDone: { name: string; used: boolean; }; /** A move with `movement` is now on screen: the app may move the mascot. */ movement: { edge: string; movement: unknown; rate: number; seconds: number; }; /** * Something went wrong, with a code from rules.md or the player and what it is about: the clip * of a clip error, the name of a refused value, the pose of a pose error. */ error: { code: string; detail?: string; }; } /** Options of `set` and `fire`. */ export interface ValueOptions { /** * What this value starts happens now: an Any State start goes straight into its target pose, * skipping every transition clip and route, and a move plays its own clip (rules.md 5.8). Off * by default. */ instant?: boolean; } export type MaskoEventName = keyof MaskoEvents; export type MaskoListener = (event: MaskoEvents[K]) => void; export interface PlayerOptions { /** The release delivery, its JSON, or the API response around it. */ delivery?: DeliveryInput; /** One animation's files, played on its own in a loop, in place of `delivery`. */ clip?: ClipFiles; /** Returns a fresh delivery of the same release, for signed links that expire. */ getDelivery?: () => DeliveryInput | Promise; /** Lets clips with their own voice (`hasAudio`) be heard. On by default; false mutes them. */ sound?: boolean; /** Starts at once. Defaults to the canvas's `autoPlay`, else true. */ autoPlay?: boolean; /** * What the player downloads ahead. `'next'` (the default): every clip that * can play next from the pose on screen. `'all'`: those first, then, once * the mascot shows, every other clip of the release, kept for the visit. */ preload?: 'next' | 'all'; /** Seeds the extra-clip rolls; random by default. */ seed?: number; } /** The clip on screen and its clip time, in seconds of its file. */ export interface Position { clip: string | null; time: number; } export declare class Player { private readonly host; private readonly options; private readonly clock; private readonly cache; private readonly listeners; private delivery; private json; private edges; private nodes; private engine; private readonly seed; private started; private wantStart; private destroyed; /** Nothing can play (the delivery was refused, or the engine cannot run): calls are dropped. */ private dead; private readonly holds; /** Calls kept until the engine loads, or until the mascot plays again. */ private queue; /** The app's calls before the start, for the first frame (rules.md 11.1). */ private early; /** With `autoPlay` false: the first frame is on screen, and which command it came from. */ private firstFrame; private firstKey; /** Steps running now (`step`): app calls their event handlers make wait in `deferred`. */ private depth; private deferred; private draining; private wakeTimer; private refreshTimer; /** When the refresh timer is due, on the wall clock: timers can sleep with the device. */ private refreshAt; /** When `getDelivery` was last asked, on the monotonic clock. */ private lastAsk; private asking; /** When the current delivery was taken, on the wall clock. */ private takenAt; private screen; private pending; /** Counts show commands: a still or a `clipShown` report that a later one overtook is stale. */ private showToken; /** A pose clip restarted in place by the commands running now, reported shown after them. */ private restarted; private readonly slotKeys; private sounds; /** Edges the engine was told cannot play. */ private readonly unplayable; /** Files that failed to load, tried last until the links are refreshed. */ private readonly failedKeys; private voices; /** Waiting for the person's next gesture, after the browser refused a voice. */ private voiceGesture; /** `preload: 'all'` has asked for every clip. */ private preloadedAll; /** Waits for the person's next gesture to start a blocked autoplay. */ private blockedGesture; readonly preview: { /** Editors and tools: cut to a pose at once (rules.md 13). */ showPose: (pose: string) => void; /** Editors and tools: play one move from the current pose (rules.md 13). */ playMove: (edge: string) => void; }; constructor(host: Host, options: PlayerOptions); set(name: string, value: Value, options?: ValueOptions): void; fire(name: string, options?: ValueOptions): void; reset(): void; /** Starts the mascot, or resumes it where it stopped. */ play(): void; /** * Lifts a blocked autoplay, from inside a gesture: the slot that is free * now is primed too, so the next clip starts without another one. The * caller syncs. */ private unblock; /** Stops play time, clips, timers and sounds; `set` and `fire` wait for `play`. */ pause(): void; /** The page is hidden or shown again: play time stops while hidden. */ setHidden(hidden: boolean): void; /** Lets clip voices be heard, from the next clip or loop on. */ setSound(on: boolean): void; /** * Checks the signed links again, for when the page is shown again or the * device is back online: the refresh timer may have slept with the device. */ checkLinks(): void; position(): Position; on(name: K, listener: MaskoListener): () => void; /** Swaps in a fresh delivery of the same release: its URLs only. */ updateDelivery(input: DeliveryInput): boolean; destroy(): void; private boot; /** * A lone clip's delivery, once its file's length is known: the preferred * format first, then the other one. When neither can be read nothing * plays, with `error` `clip_failed`. True when the delivery is ready. */ private readClip; private start; /** * With `autoPlay` false: the first pose's first frame, from a throwaway * engine that heard the same calls before the start. Shown again when a * later call changes it. */ private showFirstFrame; private running; /** An app call. Before the start, it also decides the first frame (rules.md 11.1). */ private appCall; /** * Runs an engine call now, or keeps it: until the step running now is done * (`inOrder` runs it at once, at the end of a step), or for when the mascot * plays. */ private call; /** One engine call; one that throws is reported outside and gives no commands. */ private ask; private exec; /** * Runs one step: a batch of commands, or a swap and its report. App calls * the event handlers make meanwhile wait until it is done, then run in * order, so they never run inside the batch that told them. */ private step; private drain; private run; private scheduleWake; private cancelWake; private setHold; /** Brings the clock, clips and sounds in line with the holds. */ private sync; private showClip; /** Whether this edge's clip plays muted: its own voice only with sound on (rules.md 9.6). */ private muted; private load; private playShowing; /** The showing's first frame is decoded: make it visible and hide the old one, in one frame. */ private swapIn; private swap; /** `preload: 'all'`: every clip of the release with a file this browser plays, after the engine's own preloads. */ private preloadAll; /** * Tells the engine the showing's first frame is on screen, at the play time * of now (rules.md 9.3). Called once per showing: at the swap, or after a * pose clip restarts in place. A showing a later show command overtook is * not reported, also when the report waits for play to resume. */ private reportShown; private ended; /** The file of this attempt failed: try the other format once, then report the clip failed. */ private fail; private showStill; private dropPending; private cancel; private detach; private preload; private playSound; private stopSounds; private useDelivery; /** * How long the signed links last from now, or null when they do not * expire. With `lastFetchedAt`, both times are the server's, so a device * clock that is off does not matter. */ private linksLeft; /** Asks `getDelivery` for fresh links before the signed ones expire. */ private scheduleRefresh; private refreshIn; private cancelRefresh; private refresh; private emit; private later; }