@rig-c/play 0.0.0-stage → 1.8.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.
@@ -0,0 +1,112 @@
1
+ import { type RegionImage } from './DomTexture.js';
2
+ /**
3
+ * Loads a rig built by `rigc build`: the compiled model document
4
+ * (`skeleton.model.json`, spec `rigc-compiled/3`) and the page images its
5
+ * `pages` section names, cut into region bitmaps once.
6
+ *
7
+ * The document states everything the player reads — the skeleton, the
8
+ * animations, and where every region sits on its page — so the `.atlas` and
9
+ * `skeleton.json` the build writes beside it are not fetched. A Spine export
10
+ * (`.json`, `.skel`) is refused by name: this package poses the compiled model
11
+ * through `rig-c/core` and reads nothing else.
12
+ */
13
+ export interface LoadModelOptions {
14
+ /** URL of the compiled model document (`skeleton.model.json`). */
15
+ modelUrl: string;
16
+ /**
17
+ * Maps a page name from the document's `pages` section to the URL its image
18
+ * lives at. Defaults to resolving the name against the model URL's
19
+ * directory: a build writes page names as paths relative to its own
20
+ * directory, which is where the document sits.
21
+ */
22
+ resolvePage?: (pageName: string, modelUrl: string) => string;
23
+ /**
24
+ * crossOrigin attribute for the page images. Needed when the images come
25
+ * from another origin: the region cut reads them into a canvas, and a
26
+ * tainted canvas cannot be exported (SecurityError from toBlob).
27
+ */
28
+ crossOrigin?: string;
29
+ /** fetch implementation, for custom headers or a test double. */
30
+ fetch?: typeof globalThis.fetch;
31
+ /**
32
+ * What the region cut produces — the rigid tier's per-region bitmaps, which
33
+ * only the DOM mode draws. `'blob'` (the default): `blob:` URLs the load
34
+ * owns and `dispose` frees. `'data'`: `data:` URLs, for a content policy or
35
+ * a snapshot that does not carry `blob:`; nothing to free. `'none'`: no cut
36
+ * at all, for a load that only ever draws in the canvas mode — the pages
37
+ * are loaded, `regionImages` is empty, and a DOM-mode player opened on the
38
+ * assets is refused by name.
39
+ */
40
+ regions?: RegionLoading;
41
+ }
42
+ /** `LoadModelOptions.regions`: how, or whether, the regions are cut. */
43
+ export type RegionLoading = 'blob' | 'data' | 'none';
44
+ /**
45
+ * What `new RigPlayer(root, assets)` draws from. The caller owns it: one load
46
+ * can back any number of players, and nothing a player does disposes it.
47
+ */
48
+ export interface ModelAssets {
49
+ /** The document's spec, e.g. `rigc-compiled/3`. */
50
+ readonly spec: string;
51
+ /** Every animation the document carries, in its order, with the runtime's duration. */
52
+ readonly animations: ReadonlyArray<{
53
+ readonly name: string;
54
+ readonly duration: number;
55
+ }>;
56
+ /** Every skin the document declares, in its order. */
57
+ readonly skins: readonly string[];
58
+ /**
59
+ * The document's `stage` section, in world units (Y up): the stage the
60
+ * build declared — the rig's own framing, for laying out a stage — or null
61
+ * where the document has none. Where its value comes from is rigc's rule,
62
+ * not this package's (rigc `docs/AUTHORING.md`, *Where the rebuild's stage
63
+ * comes from*): a source that states a stage is written as stated, and a
64
+ * source that states none gets the setup pose's bounding box in its place.
65
+ * So one rig's `stage` is a declared frame and another's is a box, and the
66
+ * field does not say which. For the box of what a pose draws, read
67
+ * `player.bounds()`.
68
+ */
69
+ readonly stage: {
70
+ readonly x: number;
71
+ readonly y: number;
72
+ readonly width: number;
73
+ readonly height: number;
74
+ } | null;
75
+ /** How the regions were cut (`LoadModelOptions.regions`): `'none'` means `regionImages` is empty and only the canvas mode can draw. */
76
+ readonly regions: RegionLoading;
77
+ /** Unpacked per-region bitmaps, keyed by region name — the rigid tier's. Empty on a `regions: 'none'` load. */
78
+ readonly regionImages: Map<string, RegionImage>;
79
+ /** Page images, keyed by the document's page names — the mesh tier's. */
80
+ readonly pageImages: Map<string, HTMLImageElement>;
81
+ /**
82
+ * The document as `rig-c/core` read it. Opaque to callers: the player poses
83
+ * it, and its shape is rig-c's, not this package's.
84
+ */
85
+ readonly document: ModelDocument;
86
+ /**
87
+ * Frees the blob URLs this load created (see revokeRegions). Idempotent.
88
+ * Call it after the players drawing from these assets are disposed — a live
89
+ * <img> would be left pointing at a dead URL.
90
+ */
91
+ dispose(): void;
92
+ }
93
+ /** The read document, held for the player. Deliberately opaque. */
94
+ export interface ModelDocument {
95
+ readonly spec: string;
96
+ }
97
+ /**
98
+ * Loads a rig built by `rigc build`.
99
+ *
100
+ * ```ts
101
+ * const assets = await loadModel({ modelUrl: '/rigs/walk/skeleton.model.json' });
102
+ * const player = new RigPlayer(root, assets);
103
+ * player.play('walk');
104
+ * // each frame: player.frame(dt)
105
+ * // …later: player.dispose(); assets.dispose();
106
+ * ```
107
+ *
108
+ * Page images load in parallel. If anything fails part-way, no blob URL is
109
+ * left behind.
110
+ */
111
+ export declare function loadModel(options: LoadModelOptions): Promise<ModelAssets>;
112
+ //# sourceMappingURL=loadModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadModel.d.ts","sourceRoot":"","sources":["../src/loadModel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAgC,MAAM,iBAAiB,CAAC;AAEjF;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAC7D;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAED,wEAAwE;AACxE,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAErD;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uFAAuF;IACvF,QAAQ,CAAC,UAAU,EAAE,aAAa,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACzF,sDAAsD;IACtD,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACnH,uIAAuI;IACvI,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,+GAA+G;IAC/G,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAChD,yEAAyE;IACzE,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACnD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC;;;;OAIG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,mEAAmE;AACnE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAgED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC,CA0C/E"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The one forced layout both renderers share: how many device pixels one of
3
+ * the root's CSS pixels covers on screen, read off a throwaway box.
4
+ *
5
+ * A renderer rasters at `world × pixelRatio` in the root's own coordinates,
6
+ * so a `transform: scale(z)` on an ancestor — how a pan/zoom stage is built —
7
+ * oversamples by 1/z² in backing pixels unless the zoom is folded into the
8
+ * ratio. Neither renderer measures this on its own: it is a layout read, and
9
+ * there is no per-frame layout read anywhere in this library. The caller
10
+ * invokes `syncPixelRatio()` when a zoom or a resize settles.
11
+ */
12
+ /**
13
+ * Measures `root`'s effective on-screen scale once and returns the ratio now
14
+ * in effect: `devicePixelRatio × scale` when that differs from `current` by
15
+ * more than the deadband, else `current` unchanged. A root that is not laid
16
+ * out (a `display: none` ancestor, a detached root) measures nothing, so
17
+ * nothing is decided and `current` comes back. Appends a hidden box to the
18
+ * root, reads its rect, removes it — the root's children are the same
19
+ * elements in the same order on both sides of the call.
20
+ */
21
+ export declare function syncedPixelRatio(root: HTMLElement, current: number): number;
22
+ //# sourceMappingURL=pixelRatio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pixelRatio.d.ts","sourceRoot":"","sources":["../src/pixelRatio.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAcH;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CA2B3E"}
@@ -0,0 +1,453 @@
1
+ import { CanvasRenderer } from './CanvasRenderer.js';
2
+ import { DomRenderer, type MeshBackend } from './DomRenderer.js';
3
+ import type { ModelAssets } from './loadModel.js';
4
+ import { type PosedFrame } from './posedFrame.js';
5
+ /**
6
+ * Plays a rig built by `rigc build` on a DOM root.
7
+ *
8
+ * The player owns the track and the renderer: `play` opens an animation on a
9
+ * live track (`openTrack` from `rig-c/core`), each `frame(dt)` steps it by
10
+ * `dt × timeScale`, turns the pose into a `PosedFrame` and hands that to its
11
+ * renderer — a `DomRenderer` (`mode: 'dom'`, the default) or a
12
+ * `CanvasRenderer` (`mode: 'canvas'`). Everything the pose holds is computed by
13
+ * the core from the compiled model document; this class schedules and draws.
14
+ */
15
+ /**
16
+ * How a player draws: `'dom'` — elements, the rigid tier as `<img>` and the
17
+ * mesh tier on per-part canvases (`DomRenderer`); `'canvas'` — the whole frame
18
+ * into one `<canvas>` through the shared WebGL context (`CanvasRenderer`).
19
+ */
20
+ export type RenderMode = 'dom' | 'canvas';
21
+ export interface RigPlayerOptions {
22
+ /**
23
+ * The skin to pose under. Absent is the runtime's "no skin set" — a fresh
24
+ * skeleton whose `setSkin` was never called (`underNoSkin`): no skin's bones
25
+ * or constraints applied, every slot resolved through the default skin.
26
+ */
27
+ skin?: string;
28
+ /** The per-pose adjustment of bone locals (`player.adjust`), set from the first pose. */
29
+ adjust?: BoneAdjust | null;
30
+ /** Which slots this player draws (`player.slots`); every slot when absent. */
31
+ slots?: SlotFilter | null;
32
+ /** How the player draws (see `RenderMode`). Default `'dom'`. Can be changed later through `mode`. */
33
+ mode?: RenderMode;
34
+ /** The mesh tier's rasterizer (see `DomRenderer.meshBackend`) — the DOM mode only. */
35
+ meshBackend?: MeshBackend;
36
+ /**
37
+ * The step `seek` walks the track forward with, in seconds. A seek is
38
+ * "reopen, then step to the time", never a jump: a physics rig has history,
39
+ * and the pose at a time depends on the steps taken to reach it.
40
+ */
41
+ seekStep?: number;
42
+ /**
43
+ * Stand the player on rig-c's live tracks from the first `play`, so the
44
+ * first composing call — a mix, another track, a queue, a clear — never
45
+ * replays. Without it a plain `play` runs on the single live track, and the
46
+ * first composing call carries it over by replaying the time played in
47
+ * `seekStep` increments (there is no hand-over of a live track's physics
48
+ * state in the core), which on a stage that idled a while is one long
49
+ * frame. Pick the single track for a rig whose animations key what the
50
+ * tracks do not mix (constraints, sequences, the draw order, a path's
51
+ * deform); pick the tracks for layering.
52
+ */
53
+ tracks?: boolean;
54
+ }
55
+ /** What `on('event', …)` hands a listener: one event key the step crossed. */
56
+ export interface RigEvent {
57
+ name: string;
58
+ /** The key's time in the animation. */
59
+ time: number;
60
+ int: number;
61
+ float: number;
62
+ string: string | null;
63
+ /**
64
+ * The track whose current entry fired it. The core's pose lists a step's
65
+ * events in track order without naming the track, so the player attributes
66
+ * them by counting what each track's current entry fires over the step;
67
+ * when that count does not match the pose (an entry replaced inside the
68
+ * step), the step's events carry no track rather than a guessed one.
69
+ */
70
+ track?: number;
71
+ }
72
+ /** What `on('complete', …)` hands a listener: the entry that completed, and its track. */
73
+ export interface RigComplete {
74
+ animation: string;
75
+ track: number;
76
+ }
77
+ /** How `play` starts an entry, and `queue` queues one. */
78
+ export interface PlayOptions {
79
+ /** Loop; true by default. */
80
+ loop?: boolean;
81
+ /** The track; 0 by default. A base on 0, a layer over it on 1, a one-shot on 2. */
82
+ track?: number;
83
+ /** Seconds the entry this one replaces mixes out over; 0 (the default) cuts. */
84
+ mix?: number;
85
+ /**
86
+ * The entry's weight, from 0 to 1 (1 by default), multiplied into every
87
+ * timeline it applies — the same clip at 0.6 and at 0.85. Change it while
88
+ * the entry plays with `setAlpha`. It does not touch events (fired at any
89
+ * alpha, 0 included) or attachments (kept at any alpha).
90
+ */
91
+ alpha?: number;
92
+ /**
93
+ * The entry adds its keyed bone and deform values to what the tracks below
94
+ * posed, rather than replacing them — a layer keying the same bone channels
95
+ * as the base without covering its motion (false by default). Fixed when the
96
+ * entry is set or queued. A rotation is added as it stands, with no
97
+ * shortest-angle wrap; mixing out, an additive entry fades with its alpha
98
+ * and is never held.
99
+ */
100
+ additive?: boolean;
101
+ }
102
+ export interface QueueOptions extends PlayOptions {
103
+ /**
104
+ * At or below 0 (the default 0): the entry starts when the one before it
105
+ * completes, less this entry's `mix` — a one-shot then mixes into the next
106
+ * over its last `mix` seconds. Above 0: that many seconds after the entry
107
+ * before it starts.
108
+ */
109
+ delay?: number;
110
+ }
111
+ /** A track's current entry as the player reads it (`entry(track)`). */
112
+ export interface TrackEntry {
113
+ /** What it plays; null for the empty animation a `clear` left. */
114
+ animation: string | null;
115
+ loop: boolean;
116
+ /** The entry's own track time, from its start. */
117
+ trackTime: number;
118
+ /** The animation time it applies at now: the track time wrapped, or held at the duration. */
119
+ animationTime: number;
120
+ duration: number;
121
+ /** The entry's weight as it stands (`PlayOptions.alpha`, `setAlpha`). */
122
+ alpha: number;
123
+ /** Whether the entry adds (`PlayOptions.additive`). */
124
+ additive: boolean;
125
+ }
126
+ type Listener<T> = (payload: T) => void;
127
+ /**
128
+ * One rig on one root.
129
+ *
130
+ * ```ts
131
+ * const player = new RigPlayer(root, assets);
132
+ * player.play('walk');
133
+ * requestAnimationFrame(function tick(now) { player.frame(dt); requestAnimationFrame(tick); });
134
+ * ```
135
+ */
136
+ /**
137
+ * One bone's local values at a pose, read and written in place: the seven
138
+ * channels the runtime's bone has, in its units (degrees, world-unit
139
+ * translation, scale factors, shear in degrees). What `BoneAdjust` receives
140
+ * through `AdjustableBones.bone`.
141
+ */
142
+ export interface BoneLocals {
143
+ rotation: number;
144
+ x: number;
145
+ y: number;
146
+ scaleX: number;
147
+ scaleY: number;
148
+ shearX: number;
149
+ shearY: number;
150
+ }
151
+ /** The bones of one pose, by name, as a `BoneAdjust` sees them. */
152
+ export interface AdjustableBones {
153
+ /** The document's bones, in its order. */
154
+ readonly names: readonly string[];
155
+ /** One bone's locals, read and written in place; a name the document has no bone for is refused by name. */
156
+ bone(name: string): BoneLocals;
157
+ }
158
+ /**
159
+ * A caller's adjustment of a pose's bone locals — a breath's scale, a look's
160
+ * rotation, a mouth's `scaleY` — called once per pose after the animation's
161
+ * timelines and before the world transforms, constraints and physics (the
162
+ * core's `openTrack({ adjust })`, held to the Spine runtime at tolerance 0
163
+ * by rig-c). **A write lasts one pose**: the core poses every step from the
164
+ * setup pose, so a value the caller wants held is written again each pose,
165
+ * and nothing compounds. A non-finite value, an unknown bone, or an error the
166
+ * function throws refuses that step in the core's words.
167
+ */
168
+ export type BoneAdjust = (bones: AdjustableBones) => void;
169
+ /**
170
+ * Where a bone is in the pose the player holds — world units, Y up, the
171
+ * numbers `rig-c/core` posed (`RawBone`): the world matrix `a b c d`, the
172
+ * world position, the world rotation of each axis in degrees and the world
173
+ * scale of each, and whether the bone is active under the player's skin.
174
+ */
175
+ export interface BoneWorld {
176
+ name: string;
177
+ active: boolean;
178
+ x: number;
179
+ y: number;
180
+ a: number;
181
+ b: number;
182
+ c: number;
183
+ d: number;
184
+ rotationX: number;
185
+ rotationY: number;
186
+ scaleX: number;
187
+ scaleY: number;
188
+ }
189
+ /**
190
+ * Which slots a player draws: an allow list of slot names, or a predicate
191
+ * over the name. The pose is the whole rig's whatever the filter — bones,
192
+ * constraints, physics, `bone()` and `adjust` are untouched — and only the
193
+ * draw is filtered. A clipping slot the filter leaves out does not clip.
194
+ */
195
+ export type SlotFilter = readonly string[] | ((slot: string) => boolean);
196
+ /** A box in world units, Y up: `y` is the bottom edge. */
197
+ export interface PoseBounds {
198
+ x: number;
199
+ y: number;
200
+ width: number;
201
+ height: number;
202
+ }
203
+ export declare class RigPlayer {
204
+ /**
205
+ * The renderer this player draws through — its knobs and counters are the
206
+ * caller's to read and set. A `DomRenderer` in the DOM mode, a
207
+ * `CanvasRenderer` in the canvas mode; a new object after `mode` changes.
208
+ */
209
+ get renderer(): DomRenderer | CanvasRenderer;
210
+ /** Multiplies every step. 0 holds the pose (nothing is re-posed); negative is refused by the track. */
211
+ timeScale: number;
212
+ /** The player's whole-rig colour, r g b a — multiplied into every slot's tint. Not a document value. */
213
+ color: [number, number, number, number];
214
+ private active;
215
+ private readonly root;
216
+ private readonly assets;
217
+ private readonly meshBackend;
218
+ private view;
219
+ private source;
220
+ private readonly read;
221
+ private skinName;
222
+ private readonly seekStep;
223
+ /**
224
+ * The single live track (`openTrack`): what a plain `play` on track 0 runs
225
+ * on, as every 1.x player did — one animation, every construct the core
226
+ * poses, `seek` and a skin change by reopening. Null once the player is
227
+ * composed.
228
+ */
229
+ private track;
230
+ /**
231
+ * The live tracks (`openTracks`): opened by the first composing call — a
232
+ * `play` with a mix or on another track, a `queue`, a `clear` — from the
233
+ * single track's animation stepped to its time. The mixing is the Spine
234
+ * runtime's, which does not mix a constraint, sequence, draw-order or
235
+ * path-deform timeline, so such an animation is refused here and plays on
236
+ * the single track only.
237
+ */
238
+ private tracks;
239
+ /** Track 0's animation and loop as `play` last set them — what `seek` and a skin change reopen. */
240
+ private animation;
241
+ private loop;
242
+ /** One past the highest track touched — how many `current(track)` reads a step takes. */
243
+ private trackCount;
244
+ /** `RigPlayerOptions.tracks`: every play opens the live tracks, never the single track. */
245
+ private readonly trackMode;
246
+ /** Set once anything beyond a plain play on track 0 happened: a mix, another track, a queue, a clear. `seek` and `skin` then cannot replay and refuse. */
247
+ private beyondBase;
248
+ private paused;
249
+ private pose;
250
+ private setup;
251
+ private adjustFn;
252
+ private slotFilter;
253
+ /** `slotFilter` as a predicate; every slot when null. */
254
+ private draws;
255
+ /** Handed to every track the player opens; reads the current `adjust` so setting it later needs no reopen. */
256
+ private readonly adjustHook;
257
+ private readonly listeners;
258
+ constructor(root: HTMLElement, assets: ModelAssets, options?: RigPlayerOptions);
259
+ /**
260
+ * How the player draws. Setting it swaps the renderer without reloading
261
+ * anything: the old one is disposed (its elements removed, its GPU pages
262
+ * handed back), the new one is created over the same root and the same
263
+ * assets, `pixelRatio` and `clipping` carry over, and the pose the player
264
+ * holds is drawn again at once.
265
+ */
266
+ get mode(): RenderMode;
267
+ set mode(mode: RenderMode);
268
+ private create;
269
+ /** What track 0 plays, or null before `play` and after a `clear` of track 0 has mixed out. */
270
+ get current(): string | null;
271
+ /** The player's time — the running sum of the steps since `play` (or the last `seek`). */
272
+ get time(): number;
273
+ /**
274
+ * Plays `name` on a track — track 0 by default, which is what `play(name)`
275
+ * has always meant: the first `play` opens the tracks at their first pose
276
+ * with the physics reset there, and the pose is drawn on the next `frame`.
277
+ * Later calls replace what the track plays: the entry it replaces mixes out
278
+ * over `mix` seconds (0 cuts), and every entry queued on that track is
279
+ * dropped. The pose the player holds is re-posed at once, so a held player
280
+ * shows the change on its next `draw`. The mixing is the Spine runtime's,
281
+ * which rig-c holds at tolerance 0; an animation keying what the tracks do
282
+ * not mix — a constraint, a sequence, the draw order, a path's deform — is
283
+ * refused here, by name, in the core's words.
284
+ */
285
+ play(name: string, options?: PlayOptions): void;
286
+ /**
287
+ * Queues `name` after the last entry on `track` (`QueueOptions`): with
288
+ * `delay` at or below 0 it starts when that entry completes less its own
289
+ * `mix`, so a one-shot hands over to it across a mix; on an empty track it
290
+ * is set. Before any `play`, the tracks are opened for it.
291
+ */
292
+ queue(name: string, options?: QueueOptions): void;
293
+ /**
294
+ * Mixes `track` out to nothing over `mix` seconds — the layer or one-shot
295
+ * gone and the tracks below showing through. Track 0 cleared shows the
296
+ * setup pose. The pose the player holds is re-posed at once.
297
+ */
298
+ clear(track?: number, options?: {
299
+ mix?: number;
300
+ }): void;
301
+ /**
302
+ * Queues a mix out to nothing after the last entry on `track`, over `mix`
303
+ * seconds; with `delay` 0 (the default) the mix ends as that entry
304
+ * completes, so a one-shot queued this way plays once and fades out over
305
+ * its last `mix` seconds.
306
+ */
307
+ queueClear(track?: number, options?: {
308
+ mix?: number;
309
+ delay?: number;
310
+ }): void;
311
+ /**
312
+ * Sets the weight of `track`'s current entry, from 0 to 1, from the next pose
313
+ * on — the pose the player holds is re-posed at once, so a held player shows
314
+ * it on its next `draw`. An entry it is mixing from keeps its own weight. A
315
+ * track playing nothing, or a weight outside 0..1, is refused in the core's
316
+ * words. On the single track this composes: the player moves onto the tracks.
317
+ */
318
+ setAlpha(track: number, alpha: number): void;
319
+ /** `track`'s current entry, or null where it plays nothing (and before `play`). */
320
+ entry(track?: number): TrackEntry | null;
321
+ /** Whether the player is composed: on the live tracks rather than the single track. */
322
+ get composed(): boolean;
323
+ /**
324
+ * The live tracks, opened by the first composing call (or by the first
325
+ * `play` under `tracks: true`). A single track in play is carried over by
326
+ * replay: track 0 set to its animation, pose 0 taken by `start()` (the
327
+ * player's — nothing steps before it) and the tracks stepped to the single
328
+ * track's time in `seekStep` increments, so a physics rig's history
329
+ * restarts there and nothing is fired on the way. The core offers no
330
+ * hand-over of a live track's state, so that replay costs one pose per
331
+ * `seekStep` of time played — which `tracks: true` avoids entirely.
332
+ */
333
+ private compose;
334
+ /** Stops stepping; `frame` keeps drawing the pose it holds. */
335
+ pause(): void;
336
+ /** Resumes stepping after `pause`. */
337
+ resume(): void;
338
+ /**
339
+ * Moves a single animation on track 0 to `time`: the tracks are reopened
340
+ * with that animation and stepped forward in `seekStep` increments (the
341
+ * last one shorter) until the time is reached. Events and completes crossed
342
+ * on the way are not fired. It has a meaning for one animation on one
343
+ * track only — the player cannot replay when a mix, a second track or a
344
+ * queue was asked for — so after any of those it refuses by name; step the
345
+ * player forward instead.
346
+ */
347
+ seek(time: number): void;
348
+ /** Whatever is open, opened again with track 0's animation as `play` last set it, at pose 0: the single track, or the tracks under `tracks: true`. */
349
+ private reopen;
350
+ /** Steps whatever is open forward to `time` in `seekStep` increments, the last one shorter. */
351
+ private stepTo;
352
+ /** Adds a listener; returns a function that removes it. */
353
+ on(type: 'event', listener: Listener<RigEvent>): () => void;
354
+ on(type: 'complete', listener: Listener<RigComplete>): () => void;
355
+ /**
356
+ * Advances the track by `dt × timeScale` seconds and draws the pose —
357
+ * `advance(dt)` then `draw()`.
358
+ */
359
+ frame(dt: number): void;
360
+ /**
361
+ * Steps the track by `dt × timeScale` seconds and fires the step's listeners,
362
+ * without drawing. A paused player, or a step of zero, keeps the pose it
363
+ * holds without re-posing it, so a held rig costs the renderer's dirty
364
+ * checks and nothing else.
365
+ */
366
+ advance(dt: number): void;
367
+ /** Draws the pose the player holds. */
368
+ draw(): void;
369
+ /**
370
+ * The skin the rig is posed under — `RigPlayerOptions.skin`, or undefined
371
+ * for no skin set. Setting it re-resolves the pose under the new skin
372
+ * (which attachment each slot shows, which bones and constraints are
373
+ * active) and keeps the animation, its loop and its track time: the track
374
+ * is reopened under the new skin and stepped to the same time the way
375
+ * `seek` does, so a physics rig's history restarts there and nothing is
376
+ * fired on the way. The pose is drawn on the next `draw`/`frame`. An
377
+ * unknown skin is refused by name, and the player is left as it was.
378
+ */
379
+ get skin(): string | undefined;
380
+ set skin(name: string | undefined);
381
+ /**
382
+ * Which slots this player draws (`SlotFilter`), or null for every slot.
383
+ * Settable on a live player: the next `draw` shows it, and `bounds()` reads
384
+ * the drawn slots. An allow list naming a slot the document does not have
385
+ * is refused by name. The pose is the whole rig's: `bone()`, `adjust`, the
386
+ * events and the tracks see no filter.
387
+ */
388
+ get slots(): SlotFilter | null;
389
+ set slots(filter: SlotFilter | null);
390
+ /**
391
+ * The per-pose adjustment of bone locals (`BoneAdjust`), or null for none.
392
+ * It is applied by every track the player opens — `play`, the reopen inside
393
+ * `seek` — and by the pose drawn again after `mode` changes, on every pose
394
+ * the animation is applied to, the first one included. Setting it re-poses
395
+ * the pose the player holds at once (`repose`), so a held or paused player
396
+ * shows the change on its next `draw` without a step.
397
+ */
398
+ get adjust(): BoneAdjust | null;
399
+ set adjust(fn: BoneAdjust | null);
400
+ /**
401
+ * Poses the held pose again at the same track time, through the current
402
+ * `adjust`, without stepping, firing or drawing. A paused player and a zero
403
+ * step re-pose nothing, so a caller whose adjustment reads its own state
404
+ * (a mouth driven while the body is held) calls this when that state
405
+ * changed, then `draw`. Nothing before `play`.
406
+ */
407
+ repose(): void;
408
+ /**
409
+ * Where `name` is in the pose the player holds — the pose of the last
410
+ * `advance`/`frame`/`seek`, or the setup pose before `play`. Read off the
411
+ * core's pose, so it is the same in `dom` and `canvas` mode and costs nothing
412
+ * until called. An unknown bone is refused by name.
413
+ */
414
+ bone(name: string): BoneWorld;
415
+ /**
416
+ * The box of what the pose the player holds draws, in world units, Y up:
417
+ * every region's four corners and every mesh's vertices, in the same frame
418
+ * record the renderer takes (`posedFrame`). A slot under a clip counts only
419
+ * inside the clip polygon's own box (an inverse clip removes nothing from
420
+ * the count); bounding boxes, paths and points are not drawn and do not
421
+ * count. `null` when nothing draws. The same numbers in `dom` and `canvas`
422
+ * mode; nothing is computed until called.
423
+ */
424
+ bounds(): PoseBounds | null;
425
+ /** The pose the reads above see: the track's, or the setup pose before `play` (posed once). */
426
+ private posed;
427
+ /**
428
+ * The pose the player holds, as the frame record the renderer draws — under
429
+ * this player's `slots` filter, or under `slots` given here instead (a
430
+ * second renderer over the same assets drawing this player's pose on
431
+ * another root: `other.render(player.posedFrame(['hand_f']))`, the one rig
432
+ * posed once).
433
+ */
434
+ posedFrame(slots?: SlotFilter | null): PosedFrame;
435
+ /** Removes the renderer's elements and hands its GPU pages back. The assets stay the caller's. */
436
+ dispose(): void;
437
+ /** The single track's step: its events (track 0) and its complete, as every 1.x player fired them. */
438
+ private dispatchSingle;
439
+ /**
440
+ * The step's events, then its completes, each with its track. The core
441
+ * fires a track's keys from its current entry (`pose.events`, in track
442
+ * order and in the runtime's order across a wrap) — an entry mixing out
443
+ * fires none — and leaves `complete` to the player, which derives it per
444
+ * track from that track's current entry: on a looping entry, once on a step
445
+ * whose whole cycles rose; on a held one, on the step that reaches its
446
+ * duration. An entry replaced inside the step — by `play`, or by a queued
447
+ * entry starting at its completion less the mix — is no longer current and
448
+ * completes no more than it fires, which is the runtime's rule too.
449
+ */
450
+ private dispatch;
451
+ }
452
+ export {};
453
+ //# sourceMappingURL=player.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"player.d.ts","sourceRoot":"","sources":["../src/player.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAA0C,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE1F;;;;;;;;;GASG;AAEH;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE1C,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yFAAyF;IACzF,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC3B,8EAA8E;IAC9E,KAAK,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1B,qGAAqG;IACrG,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,sFAAsF;IACtF,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B;;;;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