@minimoji/heads 18.4.0 → 19.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/minimoji-heads-bursts.js +2 -0
- package/minimoji-heads.d.ts +117 -2
- package/minimoji-heads.js +195 -173
- package/package.json +2 -1
package/minimoji-heads.d.ts
CHANGED
|
@@ -49,10 +49,58 @@ export interface HeadPerformanceOptions {
|
|
|
49
49
|
* a screen face's effects); expressions, blush, lip sync (sound arcs and lines too) and head motion are untouched. Default true. Overrides
|
|
50
50
|
* `bursts`; applies to recipe heads, baked heads and every tile in this stage */
|
|
51
51
|
decorations?: boolean;
|
|
52
|
+
/** the head's still until it draws: a `mountHeadPoster` handle (mount it before fetching a bake) or the still's src.
|
|
53
|
+
* It gives way on the first frame; it stays, sharp, if mounting throws. */
|
|
54
|
+
poster?: HeadPoster | string | null;
|
|
52
55
|
/** a screen face's (D.A.S.H.'s) CRT look, scanlines and glass following the mood: 0 off, 1 (the default), 2 loud. A head of skin ignores it */
|
|
53
56
|
crt?: 0 | 1 | 2;
|
|
57
|
+
/** what the head shows for an agent: 'thinking' | 'working' | 'needsYou' | 'waiting' | 'done' | 'errored' | 'asleep'.
|
|
58
|
+
* D.A.S.H.'s screen shows it (bake 19); any other head its own face and one held sticker (working: a keyboard).
|
|
59
|
+
* null (the default) leaves the head as it was */
|
|
60
|
+
agentState?: string | null;
|
|
61
|
+
/** a screen face's glass colour over every mood and agent state, `#rrggbb`; null leaves it */
|
|
62
|
+
screenColor?: string | null;
|
|
63
|
+
/** a packed character's colours by slot for the solo `bakedHead`, `{ trim: '#7a3cff' }` (see `prepared.slots`);
|
|
64
|
+
* throws on an unknown slot or a head with no slot map */
|
|
65
|
+
colors?: Readonly<Record<string, string>> | null;
|
|
66
|
+
/** RECORD FRAME BY FRAME (video export): a stepped clock from `createManualClock({ seed })`. The stage runs no loop of
|
|
67
|
+
* its own and reads no wall clock or pointer: nothing advances and nothing draws until `stage.step(dt)`, each step
|
|
68
|
+
* is one frame advanced by exactly `dt`, and the same seed and calls draw the same frames. `frame`/`idleFrame` only
|
|
69
|
+
* set what the next step draws. A `poster` stays until `stage.ready` resolves, then leaves at once (no fade, no
|
|
70
|
+
* puff). Off by default */
|
|
71
|
+
clock?: ManualClock | null;
|
|
54
72
|
}
|
|
55
73
|
|
|
74
|
+
/** A STEPPED CLOCK for recording a head frame by frame. Mount the stage on it, `await stage.ready`, then `stage.step(1 / 30)`
|
|
75
|
+
* once per video frame: every clock the head has moves by exactly that much and one frame is drawn, however long the
|
|
76
|
+
* recorder takes between steps. A voiced performance on a stepped stage plays no sound: mux the audio yourself */
|
|
77
|
+
export interface ManualClock {
|
|
78
|
+
readonly manual: true;
|
|
79
|
+
readonly seed: number;
|
|
80
|
+
/** seconds: the sum of every step */
|
|
81
|
+
now(): number;
|
|
82
|
+
readonly time: number;
|
|
83
|
+
readonly steps: number;
|
|
84
|
+
/** move every clock by `dt` seconds (finite, ≥ 0) and draw one frame on every stage on this clock; answers the time */
|
|
85
|
+
step(dt: number): number;
|
|
86
|
+
/** resolves once nothing held on this clock is still loading (a stage's sculpted parts and stickers, a voiced
|
|
87
|
+
* performance's line being loaded or built). Rejects when a held load failed: an Error naming each (`failed` lists
|
|
88
|
+
* them), reported once, so a retry reads a clean `ready`. Wait for it before every step if a line can be selected
|
|
89
|
+
* while you record: the line then starts on the same step every run */
|
|
90
|
+
readonly ready: Promise<void>;
|
|
91
|
+
/** a seeded random source of its own for `salt` */
|
|
92
|
+
random(salt?: string): () => number;
|
|
93
|
+
/** run `fn` on every step; answers the unsubscribe */
|
|
94
|
+
onStep(fn: (dt: number, time: number) => void): () => void;
|
|
95
|
+
/** have `ready` wait for a load of yours too (and reject, naming `what`, if it fails); answers the promise as given */
|
|
96
|
+
hold<T>(promise: Promise<T>, what?: string): Promise<T>;
|
|
97
|
+
}
|
|
98
|
+
/** a stepped clock. `seed` deals the dice of every head on it (default 1): when it blinks, where the eyes glance, which
|
|
99
|
+
* emote of a mood plays, a poke's reaction. Two recordings match only with the same seed: derive it from a stable id
|
|
100
|
+
* for the content (a deck's id, a slide's id plus a speaker), never from `location`, a URL or a served path (a server
|
|
101
|
+
* that serves each run under a fresh prefix gives every run other blinks) */
|
|
102
|
+
export function createManualClock(options?: { seed?: number }): ManualClock;
|
|
103
|
+
|
|
56
104
|
/** a poke's answer: a face held a moment and a short move on the head (no sound: play your own from `onPoke`) */
|
|
57
105
|
export type Reaction = 'oof' | 'ah' | 'flinch' | 'giggle' | 'dizzy';
|
|
58
106
|
export interface Interactive {
|
|
@@ -74,10 +122,30 @@ export interface HeadPerformanceStage {
|
|
|
74
122
|
* the face held where a line jumped to (a seek, a stall), put back without its stickers */
|
|
75
123
|
setMood(mood: string, id?: string, catchUp?: boolean): void;
|
|
76
124
|
/** replace the stage's head(s) with one solo baked head (a tiled stage becomes solo) */
|
|
77
|
-
setBakedHead(prepared: PreparedBakedHead): void;
|
|
125
|
+
setBakedHead(prepared: PreparedBakedHead, options?: { colors?: Readonly<Record<string, string>> | null }): void;
|
|
126
|
+
/** recolour the solo baked head by colour slot, live (no reload); throws on an unknown slot, a colour that is not
|
|
127
|
+
* #rrggbb or a head with no slot map. A slot with no parts on this variant changes nothing */
|
|
128
|
+
setColors(colors: Readonly<Record<string, string>>): void;
|
|
129
|
+
/** what an agent is doing, on every head (see `agentState`); `color`/`glass` override the state's own colour */
|
|
130
|
+
setAgentState(state: string | null, opts?: { color?: string; glass?: number }): void;
|
|
131
|
+
/** light a screen face's glass in `hex` over every mood (`glass`: ≈.3 dark, 2.2 flooded); null hands it back */
|
|
132
|
+
setScreenColor(hex: string | null, opts?: { glass?: number }): void;
|
|
78
133
|
/** put a live source on a head (`setPerformance(await liveMic())`): its mouth is the head's while it talks, and the
|
|
79
134
|
* stage draws its own frames while one is set. null takes it off; `id` picks a tile */
|
|
80
135
|
setPerformance(source: LiveMicSession | { performance(t?: number): unknown } | ((t: number) => unknown) | null, id?: string): void;
|
|
136
|
+
/** resolves (to the stage) once every lazy load a frame depends on is in: the sculpted parts (and the head rebuilt
|
|
137
|
+
* with them), the sticker scripts (minimoji-heads-bursts.js) and their sprites. A stepped stage's rejects, naming
|
|
138
|
+
* them, when the sculpted parts failed (the head draws its fallback; the stage's ready and its clock's each report
|
|
139
|
+
* it once; stickers are decoration and never fail it); a live stage's always resolves. On a stepped stage
|
|
140
|
+
* the poster then leaves at once and the canvas holds the first frame, with no step (the head as mounted, at time 0);
|
|
141
|
+
* `step(0)` only redraws the frame as it stands: nothing moves, no line ticks, no dice are dealt */
|
|
142
|
+
readonly ready: Promise<HeadPerformanceStage>;
|
|
143
|
+
/** the stepped clock the stage runs on, or null */
|
|
144
|
+
readonly clock: ManualClock | null;
|
|
145
|
+
/** a stepped stage: move its clock (and every stage on it) by `dt` seconds and draw one frame. Throws on a live stage */
|
|
146
|
+
step(dt: number): void;
|
|
147
|
+
/** the frame just drawn as ImageData (device px): the head's canvas with its stickers behind and in front */
|
|
148
|
+
capture(): ImageData;
|
|
81
149
|
dispose(): void;
|
|
82
150
|
[member: string]: any;
|
|
83
151
|
}
|
|
@@ -104,6 +172,9 @@ export interface PreparedBakedHead {
|
|
|
104
172
|
readonly byteLength: number;
|
|
105
173
|
readonly bounds: Readonly<{ w: number; h: number; cy: number; minY: number; maxY: number }>;
|
|
106
174
|
readonly faceNames: readonly string[];
|
|
175
|
+
/** a packed character's colour slots: slot → the parts wearing it in this file (an empty list: not on this
|
|
176
|
+
* variant). null on a head with no slot map (another bake, or a pack from before it): its colours are fixed */
|
|
177
|
+
readonly slots: Readonly<Record<string, readonly string[]>> | null;
|
|
107
178
|
/** frees the template; heads already mounted from it keep working. Idempotent */
|
|
108
179
|
dispose(): void;
|
|
109
180
|
}
|
|
@@ -123,8 +194,17 @@ export function mountBakedHeadPerformance(container: HTMLElement, options: Omit<
|
|
|
123
194
|
|
|
124
195
|
/** a voiced performance: one owned media element per run; a selection is a `{ timeline, audio, duration }` or plain audio */
|
|
125
196
|
export function createVoicedPerformance(options: {
|
|
126
|
-
|
|
197
|
+
/** the element a run plays on. Required on a live stage. On a stepped stage it is optional and sets the timebase:
|
|
198
|
+
* given, the element's currentTime, paused and ended drive the line, as live (give a silent one for a recording,
|
|
199
|
+
* whose currentTime is your recorder's clock); left out, the line runs on the stage's clock with no element */
|
|
200
|
+
createMedia?: (url: string) => HTMLMediaElement;
|
|
201
|
+
/** a stepped stage's timebase, when you want to say it: 'media' (needs createMedia) or 'clock'. Default: 'media'
|
|
202
|
+
* when createMedia is given, else 'clock'. A live stage is always 'media'. Made on an object of your own to
|
|
203
|
+
* `attach` a stepped stage to: say 'clock' here to run on its clock with no element */
|
|
204
|
+
timebase?: 'media' | 'clock';
|
|
127
205
|
loadTimeline: (url: string, signal: AbortSignal) => Promise<unknown>;
|
|
206
|
+
/** the stage the calls go to (frame, reset, setMood, emote, gesture, look, brow): a stage, or an object of your own
|
|
207
|
+
* that forwards them. A stepped stage's clock and drive are read from it, or given with `attach(stage)` */
|
|
128
208
|
stage: unknown;
|
|
129
209
|
changed?: (state: unknown) => void;
|
|
130
210
|
claimVoice?: () => void;
|
|
@@ -133,9 +213,27 @@ export function createVoicedPerformance(options: {
|
|
|
133
213
|
muted?: boolean;
|
|
134
214
|
/** 0..1 on every element a run makes (and the live one); unset leaves the element as `createMedia` made it */
|
|
135
215
|
volume?: number;
|
|
216
|
+
/** where plain audio with no words is transcribed */
|
|
217
|
+
transcribe?: { key: string; service: string } | null;
|
|
136
218
|
}): {
|
|
219
|
+
/** on a stepped stage, timebase 'clock': start the line on the stage's clock, with no media and no sound; each
|
|
220
|
+
* `stage.step(dt)` moves it by `dt`, and it ends (status `ended`) on the step that reaches its duration. Timebase
|
|
221
|
+
* 'media': as live (play() on your element; its currentTime is the line's time); the steps draw it */
|
|
222
|
+
play(): void;
|
|
223
|
+
/** the line's time now (seconds), on its timebase: drive your own captions or reveals from it */
|
|
224
|
+
readonly time: number;
|
|
225
|
+
/** is the line playing (not loading, paused, buffering, stopped or ended)? */
|
|
226
|
+
readonly playing: boolean;
|
|
227
|
+
/** which clock the line follows: 'media' (the element's currentTime) or 'clock' (a stepped stage's) */
|
|
228
|
+
readonly timebase: 'media' | 'clock';
|
|
229
|
+
pause(): void;
|
|
230
|
+
stop(): void;
|
|
231
|
+
/** load a line (held on a stepped stage's clock until it has landed, so `clock.ready` waits for it) */
|
|
137
232
|
select(next: unknown): Promise<void>;
|
|
138
233
|
prepare(next: unknown): Promise<SpeechLine>;
|
|
234
|
+
/** point the voice at a stepped stage's clock and drive: for a `stage` of your own (it still gets the calls) or a
|
|
235
|
+
* head mounted again (the line goes on from where it was). Throws unless `stage` is stepped */
|
|
236
|
+
attach(stage: HeadPerformanceStage): void;
|
|
139
237
|
/** mute or unmute the live element at once and every later run's (a muted head still talks: the clock is the element's) */
|
|
140
238
|
setMuted(muted: boolean): void;
|
|
141
239
|
/** the volume (0..1, clamped) of the live element at once and every later run's */
|
|
@@ -154,6 +252,8 @@ export function createLineSession(opts?: {
|
|
|
154
252
|
onEnd?: (generation: number, reason: 'ended' | 'stopped' | 'failed', error?: Error) => void;
|
|
155
253
|
clips?: ClipCache;
|
|
156
254
|
audioContext?: () => AudioContext;
|
|
255
|
+
/** a stepped clock (createManualClock): the line on its time, no sound */
|
|
256
|
+
clock?: ManualClock | null;
|
|
157
257
|
}): { say(line: unknown, opts?: object): number | null; prepare(clip: unknown): Promise<SpeechLine>; stop(): void; dispose(): void; [member: string]: any };
|
|
158
258
|
|
|
159
259
|
/** why a live mic failed: `denied`, `no-device`, `busy` (another app has it), `unsupported` (an http:// page, an old
|
|
@@ -190,3 +290,18 @@ export function liveMic(opts?: LiveMicOptions): Promise<LiveMicSession>;
|
|
|
190
290
|
/** the session, not started */
|
|
191
291
|
export function createLiveMicSession(opts?: LiveMicOptions): LiveMicSession;
|
|
192
292
|
export const LIVE_MIC_CONSTRAINTS: Readonly<{ echoCancellation: true; noiseSuppression: true; autoGainControl: true }>;
|
|
293
|
+
|
|
294
|
+
/** The head's own loader without React: its still (soft, breathing) in `container`, under the stage's canvas. */
|
|
295
|
+
export interface HeadPoster {
|
|
296
|
+
readonly element: HTMLElement;
|
|
297
|
+
/** the head drew: the still fades and leaves the page (`instant`: at once, no fade or puff, as a stepped stage does) */
|
|
298
|
+
ready(options?: { instant?: boolean }): void;
|
|
299
|
+
/** the head will not draw: the still stays, sharp */
|
|
300
|
+
error(): void;
|
|
301
|
+
dispose(): void;
|
|
302
|
+
}
|
|
303
|
+
/** Show a head's still (GET /avatars/<key>.png?size=256) at once, before a bake is fetched; pass the handle to
|
|
304
|
+
* mountHeadPerformance's `poster`. Sets `data-minimoji` on the container (loading → ready or error). */
|
|
305
|
+
export function mountHeadPoster(container: HTMLElement, options: { src: string; puff?: string | null }): HeadPoster;
|
|
306
|
+
/** the loader's style sheet (mountHeadPoster adds it to the page once) */
|
|
307
|
+
export const POSTER_CSS: string;
|