@moku-labs/game 0.15.162 → 0.15.164
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/dist/app/page.d.mts +1 -1
- package/dist/app/system.d.mts +3 -3
- package/dist/app.d.mts +3 -3
- package/dist/app.mjs +1 -1
- package/dist/assets.d.mts +1 -1
- package/dist/{commands-Gi8RMNnU.d.mts → commands-D5MG6t52.d.mts} +5 -5
- package/dist/control.d.mts +4 -4
- package/dist/{define-DSOTwTUY.d.mts → define-SHySD9Bw.d.mts} +2 -2
- package/dist/{headless-PANjNy6-.d.mts → headless-8XrFW9w1.d.mts} +1 -1
- package/dist/{index-CbMDaUan.d.mts → index-HsOHfkao.d.mts} +12 -12
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/inspect.d.mts +6 -6
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/{runtime-CkJJvWKb.d.mts → runtime-JG7kE0RP.d.mts} +1 -1
- package/dist/{src-mZkN8URR.mjs → src-CUi3Ytta.mjs} +924 -265
- package/dist/testing.d.mts +4 -4
- package/dist/testing.mjs +1 -1
- package/dist/{types-DTkhpupa.d.mts → types-B93wB7Sh.d.mts} +4 -2
- package/dist/{types-BuN6rLDs.d.mts → types-BEEPI3F3.d.mts} +2 -2
- package/dist/{types-DkQbqqw0.d.mts → types-CZguGD6b.d.mts} +4 -4
- package/dist/{types-CPiWOiSc.d.mts → types-Cs3a-2Km.d.mts} +1881 -39
- package/dist/types-VZL87Yhu.d.mts +1841 -0
- package/dist/{visual-nAxiy1aK.d.mts → visual-BrvFv5pU.d.mts} +5 -6
- package/dist/visual.d.mts +1 -1
- package/llms.txt +1 -1
- package/package.json +3 -3
- package/dist/types-D8D2ZtEi.d.mts +0 -3632
|
@@ -1,8 +1,1530 @@
|
|
|
1
|
-
import { $n as ChangeHook, Ar as Api$
|
|
1
|
+
import { $n as ChangeHook, Ar as Api$3, D as AxisPose, Fr as Api$6, Jn as Hint, M as SyncApi, Q as Api$4, Qn as AnchorTarget, Un as TypeTag, Wn as Descriptor, Wr as Json, Y as TransformValue, Zn as Answered, ar as NumericFields, bi as Require, br as Entity, cr as ReducedMotion, dr as TrackSegment, fr as ViewHandle, gr as ComponentHandle, hr as AnyComponentValue, ir as MotionHandle, it as PixiModule, kr as TagType, mn as Api$2, mr as AnyComponentType, nr as Motion, or as ProjectionMotion, pr as AnyComponent, rr as MotionCause, s as Events$2, t as Api$5, tr as Ease, tt as PixiContainer, ui as Api$1, ur as TrackOptions, vr as ComponentType, yi as Events$3, yt as ViewportSize } from "./types-B93wB7Sh.mjs";
|
|
2
2
|
import { Log } from "@moku-labs/common/browser";
|
|
3
3
|
import { PluginCtx } from "@moku-labs/core";
|
|
4
|
-
import { Node, Yoga } from "yoga-layout/load";
|
|
4
|
+
import { Align, Justify, Node, Overflow, Yoga } from "yoga-layout/load";
|
|
5
5
|
|
|
6
|
+
//#region src/plugins/debug/types.d.ts
|
|
7
|
+
declare namespace types_d_exports$5 {
|
|
8
|
+
export { Api, OverlayApi, OverlayMode };
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @file debug plugin — type definitions: the overlay call.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* The two visible modes of the editor's overlay: the small pill or the full card.
|
|
15
|
+
*/
|
|
16
|
+
type OverlayMode = "pill" | "card";
|
|
17
|
+
/**
|
|
18
|
+
* The editor's overlay, from the game: open it, close it, toggle it, ask whether it shows. Every call is a no-op that
|
|
19
|
+
* answers `false` on a page without the agent (a release build, a test): no import of the editor, no guard needed.
|
|
20
|
+
*/
|
|
21
|
+
type OverlayApi = {
|
|
22
|
+
/**
|
|
23
|
+
* Shows the overlay: the card, or the pill with `{ mode: "pill" }`.
|
|
24
|
+
*
|
|
25
|
+
* @param options - How the overlay shows.
|
|
26
|
+
* @param options.mode - `"card"` (the default) or `"pill"`.
|
|
27
|
+
* @returns True when an overlay took the call; false on a page without the agent.
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // A game's own "?" button of its settings sheet opens the overlay of a debug build.
|
|
31
|
+
* app.debug.overlay.open(); // true on `moku-game build --debug`; false on the store build
|
|
32
|
+
* app.debug.overlay.open({ mode: "pill" }); // true: the small pill
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
open(options?: {
|
|
36
|
+
mode?: OverlayMode;
|
|
37
|
+
}): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Hides the overlay.
|
|
40
|
+
*
|
|
41
|
+
* @returns True when an overlay took the call; false without the agent.
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* app.debug.overlay.close(); // true; app.debug.overlay.isOpen() is false after it
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
close(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Switches between hidden and the last visible mode.
|
|
50
|
+
*
|
|
51
|
+
* @returns True when an overlay took the call; false without the agent.
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* // A game binds a three-finger tap of its own to the overlay.
|
|
55
|
+
* app.debug.overlay.toggle(); // true: shown (the card, or the pill if the pill was the last mode)
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
toggle(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Tells whether the overlay shows, as the pill or the card.
|
|
61
|
+
*
|
|
62
|
+
* @returns True while it shows; false when hidden and without the agent.
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* app.debug.overlay.open({ mode: "pill" });
|
|
66
|
+
* app.debug.overlay.isOpen(); // true
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
isOpen(): boolean;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* The `debug` plugin's API: the overlay call.
|
|
73
|
+
*/
|
|
74
|
+
type Api = {
|
|
75
|
+
/**
|
|
76
|
+
* The editor's overlay. Usable anywhere the app is; a no-op without the agent. The ui tag `DebugTrigger` is one
|
|
77
|
+
* helper on top of it.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* // ui's DebugTrigger, after five taps:
|
|
82
|
+
* ctx.require(debugPlugin).overlay.open(); // true on a debug build
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
overlay: OverlayApi;
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/plugins/anim/tween/types.d.ts
|
|
89
|
+
/**
|
|
90
|
+
* One running track: the numeric fields of one component of one entity moving from the values
|
|
91
|
+
* read at the end of the delay to the exact target, straight or through keyframe segments. A
|
|
92
|
+
* track with repeats walks again from its first segment each time a run ends.
|
|
93
|
+
*/
|
|
94
|
+
type Track = {
|
|
95
|
+
readonly id: number;
|
|
96
|
+
readonly entity: Entity;
|
|
97
|
+
readonly component: AnyComponent;
|
|
98
|
+
/**
|
|
99
|
+
* The target fields. Retarget deletes the fields a newer absolute track took over. A frame reads
|
|
100
|
+
* the slots (`names`, `targets`, `live`) instead.
|
|
101
|
+
*/
|
|
102
|
+
to: Record<string, number>;
|
|
103
|
+
/**
|
|
104
|
+
* The key of the owner, bases and offsets tables per field, built once when the track starts.
|
|
105
|
+
* It keeps a field `to` lost, which nothing reads again.
|
|
106
|
+
*/
|
|
107
|
+
readonly keys: Readonly<Record<string, string>>;
|
|
108
|
+
readonly ms: number;
|
|
109
|
+
readonly ease: Ease;
|
|
110
|
+
readonly delayMs: number;
|
|
111
|
+
/**
|
|
112
|
+
* `[0]`: the milliseconds the track has run, its delay included; `[1]`: the normalised time of
|
|
113
|
+
* the write that runs. Cells and not fields, so a frame writes them in place: a double stored in
|
|
114
|
+
* an object field is a new heap number.
|
|
115
|
+
*/
|
|
116
|
+
readonly clock: Float64Array; /** True once the start values are read, when the delay ends, never earlier. */
|
|
117
|
+
begun: boolean; /** The target fields in slot order: every field `to` held when the track started. */
|
|
118
|
+
readonly names: readonly string[];
|
|
119
|
+
/**
|
|
120
|
+
* How many fields `to` still holds: `names.length` at the start, one less for every field a
|
|
121
|
+
* newer absolute track took. At 0 the track has nothing to drive and ends. The typed arrays
|
|
122
|
+
* below (`clock` to `partialMoved`) are views of one shared buffer.
|
|
123
|
+
*/
|
|
124
|
+
kept: number; /** The key of each slot: the strings of `keys`, by slot. */
|
|
125
|
+
readonly slotKeys: readonly string[]; /** The target of each slot. */
|
|
126
|
+
readonly targets: Float64Array; /** The start value of each slot, read when the delay ends. */
|
|
127
|
+
readonly starts: Float64Array; /** `1` while the track drives the slot, `0` once a newer absolute track took its field. */
|
|
128
|
+
readonly live: Uint8Array; /** `1` for a slot the frame that runs moved: a write of only some fields reads it. */
|
|
129
|
+
readonly moved: Uint8Array;
|
|
130
|
+
/**
|
|
131
|
+
* Per slot, the numbers of the write that runs: first what the slot contributes, then what the
|
|
132
|
+
* field reads, the base plus every offset. Kept here so no number crosses a call boxed.
|
|
133
|
+
*/
|
|
134
|
+
readonly values: Float64Array; /** `1` for a slot that is a colour field (`isColorField`): it mixes per channel and rounds (F219). */
|
|
135
|
+
readonly colors: Uint8Array;
|
|
136
|
+
/**
|
|
137
|
+
* Per slot, the value this track last left in the field or found there, `NaN` while unknown: at
|
|
138
|
+
* the start and while another writer holds the field. A frame whose value moved off it writes
|
|
139
|
+
* without reading the field back.
|
|
140
|
+
*/
|
|
141
|
+
readonly seen: Float64Array;
|
|
142
|
+
readonly muted: () => ReadonlySet<string>;
|
|
143
|
+
readonly additive: boolean; /** True for a track a timeline step advances by hand; the frame step leaves it alone. */
|
|
144
|
+
readonly driven: boolean; /** The frame step the track was born in. That step does not advance it a second time. */
|
|
145
|
+
readonly bornFrame: number;
|
|
146
|
+
ended: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* The keyframe segments the track walks over `ms`, or `undefined` for a straight track. A
|
|
149
|
+
* segment without an ease runs on the track's `ease`.
|
|
150
|
+
*/
|
|
151
|
+
readonly segments: readonly TrackSegment[] | undefined;
|
|
152
|
+
/**
|
|
153
|
+
* The runs still to go after the one that plays: `0` for a track that runs once, `Infinity`
|
|
154
|
+
* for a loop (`repeat: "forever"`), which never ends by itself.
|
|
155
|
+
*/
|
|
156
|
+
repeatsLeft: number;
|
|
157
|
+
/**
|
|
158
|
+
* True while a loop stands on its first key and has written it: the hold writes once, and the
|
|
159
|
+
* walk clears it, so the next hold writes the first key again.
|
|
160
|
+
*/
|
|
161
|
+
held: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* The fields an additive track skipped at its last write because another writer owned them.
|
|
164
|
+
* When such a field is given back, the track adds to the value it finds there and not to the
|
|
165
|
+
* base it kept. Empty for a track that owns its fields.
|
|
166
|
+
*/
|
|
167
|
+
masked: Set<string>; /** Started with `reduced: "keep"`: reduced motion neither shortens nor holds it. */
|
|
168
|
+
readonly keep: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* What the track writes that could show its view again, handed to `renderer.sync.loopsHeld` by an endless track
|
|
171
|
+
* (spec 26 R1.7.4): `"alpha"`, `"place"` (where the view is or how large), `"both"`, or `undefined` for a write
|
|
172
|
+
* that cannot (a tint, a fill colour). Computed once when the track is made.
|
|
173
|
+
*/
|
|
174
|
+
readonly reveals: "alpha" | "place" | "both" | undefined;
|
|
175
|
+
/**
|
|
176
|
+
* The patch the track writes when a frame moves every field, one per track with every field of
|
|
177
|
+
* `to` in it: a frame fills it in place instead of building one. Rebuilt when the track loses a
|
|
178
|
+
* field.
|
|
179
|
+
*/
|
|
180
|
+
patch: Record<string, unknown>;
|
|
181
|
+
/**
|
|
182
|
+
* The patch of a frame that moves only some fields (another writer holds one, or one stands
|
|
183
|
+
* still): exactly the fields `partialMoved` flags, filled in place by the next frame that moves
|
|
184
|
+
* the same ones and built again when they change, so a field the track lost, which never moves
|
|
185
|
+
* again, is never in it. `undefined` until the first such frame.
|
|
186
|
+
*/
|
|
187
|
+
partial: Record<string, unknown> | undefined; /** The `moved` flags `partial` was built for, by slot. */
|
|
188
|
+
readonly partialMoved: Uint8Array;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* A motion handle that can also be advanced by hand: what the timeline cursor needs, so a track
|
|
192
|
+
* born inside a frame step still consumes the remainder of that step's delta.
|
|
193
|
+
*/
|
|
194
|
+
type StepMotion = MotionHandle & {
|
|
195
|
+
/**
|
|
196
|
+
* Advances the track by one delta.
|
|
197
|
+
*
|
|
198
|
+
* @param deltaMs - Milliseconds of game time to consume.
|
|
199
|
+
* @returns The milliseconds left over past the end of the track.
|
|
200
|
+
*/
|
|
201
|
+
advance(deltaMs: number): number;
|
|
202
|
+
};
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/plugins/anim/timeline/steps.d.ts
|
|
205
|
+
/**
|
|
206
|
+
* Every haptic tick `haptic(kind)` takes, in one frozen list: the three impacts, the selection
|
|
207
|
+
* tick and the three notifications. `platform` checks a kind against it before it plays one.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* HAPTIC_KINDS.includes("light"); // true
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
declare const HAPTIC_KINDS: readonly ["light", "medium", "heavy", "selection", "success", "warning", "error"];
|
|
215
|
+
/**
|
|
216
|
+
* Runs the steps one after another. The remainder past a step's end reaches the next step in the
|
|
217
|
+
* same frame, so the tree takes exactly the sum of its durations. A step that never ends (a
|
|
218
|
+
* `tween` with `repeat: "forever"`, or a `parallel`, `sequence` or `use` that holds one) may only
|
|
219
|
+
* come last: the steps after it would never play.
|
|
220
|
+
*
|
|
221
|
+
* @param steps - The steps, in order.
|
|
222
|
+
* @returns The sequence step.
|
|
223
|
+
* @throws {Error} When a step that never ends has another step after it.
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* sequence(wait(100), mark("done"));
|
|
227
|
+
* // { kind: "sequence", steps: [{ kind: "wait", ms: 100 }, { kind: "mark", name: "done" }] }
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
declare function sequence(...steps: readonly Step[]): Step;
|
|
231
|
+
/**
|
|
232
|
+
* Runs every step at once and ends with the longest one.
|
|
233
|
+
*
|
|
234
|
+
* @param steps - The steps.
|
|
235
|
+
* @returns The parallel step.
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* parallel(wait(100), wait(300)); // ends after 300 ms
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
declare function parallel(...steps: readonly Step[]): Step;
|
|
242
|
+
/**
|
|
243
|
+
* Builds one step per item and starts each one `staggerMs` later than the one before. The build
|
|
244
|
+
* function runs here, so no function survives in the data.
|
|
245
|
+
*
|
|
246
|
+
* @param items - What to build a step for.
|
|
247
|
+
* @param staggerMs - Delay between two neighbouring items, in game milliseconds.
|
|
248
|
+
* @param build - Builds the step of one item.
|
|
249
|
+
* @returns The parallel of delayed sequences.
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* stagger(["a", "b"], 60, item => mark(item));
|
|
253
|
+
* // parallel(sequence(wait(0), mark("a")), sequence(wait(60), mark("b")))
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
declare function stagger<Item>(items: readonly Item[], staggerMs: number, build: (item: Item, index: number) => Step): Step;
|
|
257
|
+
/**
|
|
258
|
+
* Holds still for a while.
|
|
259
|
+
*
|
|
260
|
+
* @param durationMs - How long to wait, in game milliseconds.
|
|
261
|
+
* @returns The wait step.
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* wait(120); // { kind: "wait", ms: 120 }
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
declare function wait(durationMs: number): Step;
|
|
268
|
+
/**
|
|
269
|
+
* Names a point in the choreography. Reaching it emits `anim:mark`, calls the `onMark` listeners
|
|
270
|
+
* and appends the name to `marks()`. It is the only way out of a timeline.
|
|
271
|
+
*
|
|
272
|
+
* @param name - Name of the mark.
|
|
273
|
+
* @returns The mark step.
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* mark("landed"); // { kind: "mark", name: "landed" }
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
declare function mark(name: string): Step;
|
|
280
|
+
/**
|
|
281
|
+
* Moves the numeric fields of one component of one target to an exact target value. The component
|
|
282
|
+
* is any handle `world.ecs` takes, so the kit's `Sprite` and `NineSlice` of `defineGame` pass as
|
|
283
|
+
* they are.
|
|
284
|
+
*
|
|
285
|
+
* By default the fields are local: they are written into the target's own `Transform`. With
|
|
286
|
+
* `space: "root"` the `x`, `y`, `rotation` and `scale` of a `Transform` are a root pose, the space
|
|
287
|
+
* `at()` answers in, and are turned into the space of the target's `Parent` when the track starts.
|
|
288
|
+
* That aims a hosted view at another element: an order's board item inside the scaled board slot
|
|
289
|
+
* flies onto the order card with `{ x: at(card).x, y: at(card).y, scale: at(card).scale }` in the
|
|
290
|
+
* root space, covers the card at the card's size, and its `Transform` stays slot-local. A field
|
|
291
|
+
* the step does not name stays where it is, so under a turned parent name `x` and `y` together. A
|
|
292
|
+
* target without a parent, and a component other than `Transform`, move as in the local space. An
|
|
293
|
+
* additive walk names offsets, so it stays in the local space.
|
|
294
|
+
*
|
|
295
|
+
* @param target - The projection key or the entity to animate.
|
|
296
|
+
* @param component - The component to animate.
|
|
297
|
+
* @param to - The numeric target fields.
|
|
298
|
+
* @param options - Duration, easing, delay, the additive flag and the space of the fields.
|
|
299
|
+
* @param options.ms - Duration in game milliseconds.
|
|
300
|
+
* @param options.ease - Easing curve; `"out"` when omitted.
|
|
301
|
+
* @param options.delayMs - How long the track waits before it reads its start values.
|
|
302
|
+
* @param options.additive - `true` adds an offset instead of owning the fields.
|
|
303
|
+
* @param options.space - `"root"` reads the `Transform` fields as a root pose; `"local"` when
|
|
304
|
+
* omitted.
|
|
305
|
+
* @param options.reduced - `"keep"` plays the track at its length under reduced motion, a fade
|
|
306
|
+
* for one; `"cut"` (the default) lands it at once, and a `"forever"` track does not play.
|
|
307
|
+
* @param options.segments - Keyframe segments `{ at, ease?, to }` walked one after another over
|
|
308
|
+
* `ms` on one clock; a field a segment does not name holds, `to` is where the last one ends. An
|
|
309
|
+
* additive walk names offsets. The same as `TweenOptions` of `ViewHandle.tween`.
|
|
310
|
+
* @param options.repeat - How many more times the walk runs, or `"forever"`: the step never ends
|
|
311
|
+
* by itself, so it comes last in a `sequence`.
|
|
312
|
+
* @returns The tween step; `segments` and `repeat` are in it only when given.
|
|
313
|
+
* @throws {Error} When the segments are empty, an `at` is outside 0..1 or out of order, the last
|
|
314
|
+
* segment ends before 1, an additive walk names the root space, or the repeat is not a whole
|
|
315
|
+
* number of 0 or more.
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* // A ready chest (entity 1048576) hops 14 up and back every 2.4 s, as offsets over its pose.
|
|
319
|
+
* const chestBounce = defineAnimation("board.chestBounce", { slots: { chest: type<Target>() },
|
|
320
|
+
* build: ({ chest }) => tween(chest, Transform, { y: 0, scale: 0 }, { ms: 2400, additive: true,
|
|
321
|
+
* repeat: "forever", segments: [{ at: 0.08, ease: "out", to: { y: -14, scale: 0.06 } },
|
|
322
|
+
* { at: 0.22, ease: "in", to: { y: 0, scale: 0 } }, { at: 1, to: { y: 0, scale: 0 } }] }) });
|
|
323
|
+
* const bounce = res(AnimPlayer).play(chestBounce, { chest: 1_048_576 });
|
|
324
|
+
* // 192 ms later the chest stands 14 higher, its scale 0.06 larger; it bounces until cancelled
|
|
325
|
+
* bounce.cancel(); // it stands on its own pose again
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
declare function tween<Value extends object>(target: Target$1, component: ComponentHandle<Value>, to: Partial<NumericFields<Value>>, options: {
|
|
329
|
+
ms: number;
|
|
330
|
+
ease?: Ease;
|
|
331
|
+
delayMs?: number;
|
|
332
|
+
additive?: boolean;
|
|
333
|
+
space?: "local" | "root";
|
|
334
|
+
reduced?: ReducedMotion;
|
|
335
|
+
segments?: readonly {
|
|
336
|
+
at: number;
|
|
337
|
+
ease?: Ease;
|
|
338
|
+
to: Partial<NumericFields<Value>>;
|
|
339
|
+
}[];
|
|
340
|
+
repeat?: number | "forever";
|
|
341
|
+
}): Step;
|
|
342
|
+
/**
|
|
343
|
+
* Writes a component patch at once. Any field may be written, not only the numeric ones. The
|
|
344
|
+
* component is any handle `world.ecs` takes, the kit's `Sprite` and `NineSlice` included.
|
|
345
|
+
*
|
|
346
|
+
* @param target - The projection key or the entity to write.
|
|
347
|
+
* @param component - The component to write.
|
|
348
|
+
* @param patch - The fields to overwrite.
|
|
349
|
+
* @returns The set step.
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* set({ projection: "hud", key: "coins" }, Sprite, { texture: "hud.coin-gold" });
|
|
353
|
+
* // { kind: "set", patch: { texture: "hud.coin-gold" }, ... }
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
declare function set<Value extends object>(target: Target$1, component: ComponentHandle<Value>, patch: Partial<Value>): Step;
|
|
357
|
+
/**
|
|
358
|
+
* Plays a frame sprite: one texture key of the list per frame of `fps`, written into `Sprite`.
|
|
359
|
+
*
|
|
360
|
+
* @param target - The projection key or the entity to animate.
|
|
361
|
+
* @param options - The keys, the frame rate and whether the list repeats.
|
|
362
|
+
* @param options.keys - The texture keys, in play order.
|
|
363
|
+
* @param options.fps - Frames per second of the list.
|
|
364
|
+
* @param options.loop - `true` repeats the list until the step is finished.
|
|
365
|
+
* @returns The frames step.
|
|
366
|
+
* @example
|
|
367
|
+
* ```ts
|
|
368
|
+
* frames({ projection: "board", key: "c3" }, { keys: ["fx.pop-1", "fx.pop-2"], fps: 12 });
|
|
369
|
+
* // { kind: "frames", keys: ["fx.pop-1", "fx.pop-2"], fps: 12, loop: false, ... }
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
declare function frames(target: Target$1, options: {
|
|
373
|
+
keys: readonly string[];
|
|
374
|
+
fps: number;
|
|
375
|
+
loop?: boolean;
|
|
376
|
+
}): Step;
|
|
377
|
+
/**
|
|
378
|
+
* Makes a temporary entity when the step is reached: a flying coin, a toast sign, a sparkle. The
|
|
379
|
+
* entity is owned by `anim`, drawn in `layer` at `order`, and despawned when the timeline ends, is
|
|
380
|
+
* finished or is cancelled. Later steps of the same timeline aim at it with `spawned(id)`.
|
|
381
|
+
*
|
|
382
|
+
* @param id - Name of the entity inside this timeline; one timeline spawns each id once.
|
|
383
|
+
* @param components - The component values the entity starts with, as `world.ecs.spawn` takes.
|
|
384
|
+
* @param options - Where the entity is drawn.
|
|
385
|
+
* @param options.layer - The layer; `"ui"` when omitted.
|
|
386
|
+
* @param options.order - The draw order inside the layer; `0` when omitted.
|
|
387
|
+
* @returns The spawn step.
|
|
388
|
+
* @example
|
|
389
|
+
* ```ts
|
|
390
|
+
* spawn("coin1", [Sprite({ texture: "ui.icon-coin" }), Transform({ x: 540, y: 900 })], { order: 50 });
|
|
391
|
+
* // { kind: "spawn", id: "coin1", components: [...], layer: "ui", order: 50 }
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
declare function spawn(id: string, components: readonly AnyComponentValue[], options?: {
|
|
395
|
+
layer?: string;
|
|
396
|
+
order?: number;
|
|
397
|
+
}): Step;
|
|
398
|
+
/**
|
|
399
|
+
* Aims a later step at the entity a `spawn` step of the same timeline made. Before that step is
|
|
400
|
+
* reached nothing answers the id, so a step aimed at it ends silently.
|
|
401
|
+
*
|
|
402
|
+
* @param id - The id the `spawn` step was given.
|
|
403
|
+
* @returns The target.
|
|
404
|
+
* @example
|
|
405
|
+
* ```ts
|
|
406
|
+
* tween(spawned("coin1"), Transform, { x: 40, y: 120 }, { ms: 600, ease: "inCubic" });
|
|
407
|
+
* // { kind: "tween", target: { spawned: "coin1" }, ... }
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
declare function spawned(id: string): {
|
|
411
|
+
spawned: string;
|
|
412
|
+
};
|
|
413
|
+
/**
|
|
414
|
+
* A sound. `anim` owns the descriptor because it sits below `audio`; `audio` owns the handler,
|
|
415
|
+
* and a game without `audio` plays nothing and hears no error. A sound with an `id` is named:
|
|
416
|
+
* one sound plays per id, a new one with the same id fades the old one out over `fadeMs`, and
|
|
417
|
+
* `stopSfx(id)` stops it. The payload carries `id` and `fadeMs` only when they are given, so a
|
|
418
|
+
* sound without them stays `{ key, bus }`.
|
|
419
|
+
*
|
|
420
|
+
* @param key - Asset key of the sound.
|
|
421
|
+
* @param options - The bus, the name and the fade.
|
|
422
|
+
* @param options.bus - `"sfx"` when omitted.
|
|
423
|
+
* @param options.id - Name of the sound; one sound per id plays.
|
|
424
|
+
* @param options.fadeMs - Fade of the sound with the same id this one replaces; `audio`'s
|
|
425
|
+
* `sfxFadeMs` when omitted.
|
|
426
|
+
* @returns The descriptor, usable as a timeline step and as `fx(...)` in a node.
|
|
427
|
+
* @example
|
|
428
|
+
* ```ts
|
|
429
|
+
* sfx("board.merge"); // { kind: "sfx", payload: { key: "board.merge", bus: "sfx" }, cosmetic: true }
|
|
430
|
+
* sfx("voice.hello", { id: "voice", fadeMs: 200 });
|
|
431
|
+
* // { kind: "sfx", payload: { key: "voice.hello", bus: "sfx", id: "voice", fadeMs: 200 }, cosmetic: true }
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
declare function sfx(key: string, options?: {
|
|
435
|
+
bus?: string;
|
|
436
|
+
id?: string;
|
|
437
|
+
fadeMs?: number;
|
|
438
|
+
}): SfxDescriptor;
|
|
439
|
+
/**
|
|
440
|
+
* Stops the named sound `sfx(key, { id })` started, fading it out over `fadeMs`. `audio` owns the
|
|
441
|
+
* handler; an id nothing plays is silent. It works as `fx.start(stopSfx("voice"))` in a node, as a
|
|
442
|
+
* step a timeline reaches, and as the hint `hint("stopSfx", { id: "voice" })`. A timeline that is
|
|
443
|
+
* finished or cut fires no effect, this one included: a game that must stop the voice then stops
|
|
444
|
+
* it from the node.
|
|
445
|
+
*
|
|
446
|
+
* @param id - The id the sound was played with.
|
|
447
|
+
* @param options - The fade.
|
|
448
|
+
* @param options.fadeMs - Fade-out in ms; `audio`'s `sfxFadeMs` when omitted.
|
|
449
|
+
* @returns The descriptor, usable as a timeline step and as `fx(...)` in a node.
|
|
450
|
+
* @example
|
|
451
|
+
* ```ts
|
|
452
|
+
* stopSfx("voice", { fadeMs: 200 }); // { kind: "stopSfx", payload: { id: "voice", fadeMs: 200 }, cosmetic: true }
|
|
453
|
+
* stopSfx("voice"); // { kind: "stopSfx", payload: { id: "voice" }, cosmetic: true }
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
declare function stopSfx(id: string, options?: {
|
|
457
|
+
fadeMs?: number;
|
|
458
|
+
}): StopSfxDescriptor;
|
|
459
|
+
/**
|
|
460
|
+
* A haptic tick. `platform` owns the handler; a device without one stays still.
|
|
461
|
+
*
|
|
462
|
+
* @param kind - Which tick to play, one of `HAPTIC_KINDS`, for example `"light"`.
|
|
463
|
+
* @returns The descriptor, usable as a timeline step and as `fx(...)` in a node.
|
|
464
|
+
* @example
|
|
465
|
+
* ```ts
|
|
466
|
+
* haptic("light"); // { kind: "haptic", payload: { kind: "light" }, cosmetic: true }
|
|
467
|
+
* ```
|
|
468
|
+
*/
|
|
469
|
+
declare function haptic(kind: HapticKind): HapticDescriptor;
|
|
470
|
+
/**
|
|
471
|
+
* Reserved for Spine and the other external players. It throws until one arrives, so nobody
|
|
472
|
+
* builds a choreography on a door that is not open yet.
|
|
473
|
+
*
|
|
474
|
+
* @param _player - The player that would run the clip.
|
|
475
|
+
* @param _clip - Name of the clip.
|
|
476
|
+
* @throws {Error} Always.
|
|
477
|
+
* @example
|
|
478
|
+
* ```ts
|
|
479
|
+
* external(spine, "idle"); // throws: External players arrive with Spine.
|
|
480
|
+
* ```
|
|
481
|
+
*/
|
|
482
|
+
declare function external(_player: ExternalPlayer, _clip: string): never;
|
|
483
|
+
/**
|
|
484
|
+
* Nests one animation inside another. The nested tree is built here, so its marks are reported
|
|
485
|
+
* under the nested id and no function survives in the data. Pass the outer `tools` when the
|
|
486
|
+
* nested `build` reads `at` or `reducedMotion`.
|
|
487
|
+
*
|
|
488
|
+
* @param animation - The animation to nest.
|
|
489
|
+
* @param slots - One target, or a list of targets, per slot of the nested animation.
|
|
490
|
+
* @param tools - The build tools of the outer animation, which carry `at` and `reducedMotion`; without
|
|
491
|
+
* them `at` is the identity pose and `reducedMotion` is absent (false).
|
|
492
|
+
* @returns The use step.
|
|
493
|
+
* @example
|
|
494
|
+
* ```ts
|
|
495
|
+
* use(popCard, { card: { projection: "hud", key: "order" } });
|
|
496
|
+
* // { kind: "use", id: "hud.popCard", step: { kind: "sequence", ... } }
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
declare function use<Tags extends SlotTags>(animation: AnimationDefinition<Tags>, slots: SlotValues<Tags>, tools?: BuildTools): Step;
|
|
500
|
+
/**
|
|
501
|
+
* The effect descriptor a node awaits to play a choreography. The payload names the animation,
|
|
502
|
+
* so the handler resolves the definition from the registry the features filled.
|
|
503
|
+
*
|
|
504
|
+
* @param animation - The animation to play.
|
|
505
|
+
* @param slots - One target, or a list of targets, per slot.
|
|
506
|
+
* @returns The descriptor, cosmetic, so a failing build never breaks the node.
|
|
507
|
+
* @example
|
|
508
|
+
* ```ts
|
|
509
|
+
* play(coinsFly, { from: { projection: "hud", key: "purse" } });
|
|
510
|
+
* // { kind: "play", payload: { animation: "hud.coinsFly", slots: { from: { ... } } }, cosmetic: true }
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
declare function play<Tags extends SlotTags>(animation: AnimationDefinition<Tags>, slots: SlotValues<Tags>): PlayDescriptor;
|
|
514
|
+
/**
|
|
515
|
+
* Declares one animation: an id, the slots it takes and the pure function that builds its step
|
|
516
|
+
* tree. `build` runs once per play, so the same animation may play twice at once.
|
|
517
|
+
*
|
|
518
|
+
* @param id - Animation id, unique across the features of a game.
|
|
519
|
+
* @param spec - The slots and the build function.
|
|
520
|
+
* @returns The animation as frozen plain data.
|
|
521
|
+
* @example
|
|
522
|
+
* ```ts
|
|
523
|
+
* const coinsFly = defineAnimation("hud.coinsFly", {
|
|
524
|
+
* slots: { from: type<Target>() },
|
|
525
|
+
* build: ({ from }) => tween(from, Transform, { scale: 0.4 }, { ms: 600 })
|
|
526
|
+
* });
|
|
527
|
+
* coinsFly.id; // "hud.coinsFly"
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
declare function defineAnimation<Tags extends SlotTags>(id: string, spec: AnimationSpec<Tags>): AnimationDefinition<Tags>;
|
|
531
|
+
//#endregion
|
|
532
|
+
//#region src/plugins/anim/timeline/types.d.ts
|
|
533
|
+
/**
|
|
534
|
+
* The value of the component a step names, with its shape erased: the value type of
|
|
535
|
+
* `AnyComponent`. A step is built against the real component, so `set(target, Sprite, patch)`
|
|
536
|
+
* checks the patch; the step tree and the runtime then carry the component erased, which lets one
|
|
537
|
+
* choreography mix components.
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```ts
|
|
541
|
+
* const patch: ErasedFields = { texture: "hud.coin-gold" };
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
type ErasedFields = AnyComponent extends ComponentType<infer Value> ? Value : never;
|
|
545
|
+
/**
|
|
546
|
+
* A sound, owned by `anim` and handled by `audio`. It is a `flow` descriptor and a timeline step
|
|
547
|
+
* at once: `fx(sfx("board.merge"))` in a node, or `sfx("board.merge")` inside a `sequence`. A
|
|
548
|
+
* sound with an `id` is named: a second one with the same id fades the first out over `fadeMs`,
|
|
549
|
+
* and `stopSfx(id)` stops it. The payload carries `id` and `fadeMs` only when they were given.
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* ```ts
|
|
553
|
+
* const descriptor: SfxDescriptor = {
|
|
554
|
+
* kind: "sfx", payload: { key: "voice.hello", bus: "sfx", id: "voice", fadeMs: 200 }, cosmetic: true
|
|
555
|
+
* };
|
|
556
|
+
* ```
|
|
557
|
+
*/
|
|
558
|
+
type SfxDescriptor = {
|
|
559
|
+
readonly kind: "sfx";
|
|
560
|
+
readonly payload: {
|
|
561
|
+
readonly key: string;
|
|
562
|
+
readonly bus: string; /** Name of the sound: one sound per id plays, and `stopSfx(id)` stops it. */
|
|
563
|
+
readonly id?: string; /** Fade of the sound with the same id this one replaces; `audio`'s `sfxFadeMs` when absent. */
|
|
564
|
+
readonly fadeMs?: number;
|
|
565
|
+
};
|
|
566
|
+
readonly cosmetic: true; /** Never set: `await fx(sfx(...))` resolves nothing. */
|
|
567
|
+
readonly $result?: () => void;
|
|
568
|
+
};
|
|
569
|
+
/**
|
|
570
|
+
* Stops the named sound an `sfx(key, { id })` started, owned by `anim` and handled by `audio`.
|
|
571
|
+
* Like `sfx` it is a descriptor and a timeline step at once; an id nothing plays is silent.
|
|
572
|
+
*
|
|
573
|
+
* @example
|
|
574
|
+
* ```ts
|
|
575
|
+
* const descriptor: StopSfxDescriptor = {
|
|
576
|
+
* kind: "stopSfx", payload: { id: "voice", fadeMs: 200 }, cosmetic: true
|
|
577
|
+
* };
|
|
578
|
+
* ```
|
|
579
|
+
*/
|
|
580
|
+
type StopSfxDescriptor = {
|
|
581
|
+
readonly kind: "stopSfx";
|
|
582
|
+
readonly payload: {
|
|
583
|
+
readonly id: string; /** Fade-out of the sound; `audio`'s `sfxFadeMs` when absent. */
|
|
584
|
+
readonly fadeMs?: number;
|
|
585
|
+
};
|
|
586
|
+
readonly cosmetic: true; /** Never set: `await fx(stopSfx(...))` resolves nothing. */
|
|
587
|
+
readonly $result?: () => void;
|
|
588
|
+
};
|
|
589
|
+
/**
|
|
590
|
+
* One haptic tick a device can play: the impact, selection and notification families of Tauri.
|
|
591
|
+
* `HAPTIC_KINDS` lists the same seven at runtime.
|
|
592
|
+
*
|
|
593
|
+
* @example
|
|
594
|
+
* ```ts
|
|
595
|
+
* const kind: HapticKind = "success";
|
|
596
|
+
* ```
|
|
597
|
+
*/
|
|
598
|
+
type HapticKind = (typeof HAPTIC_KINDS)[number];
|
|
599
|
+
/**
|
|
600
|
+
* A haptic tick, owned by `anim` and handled by `platform`. Like `sfx` it is a descriptor and a
|
|
601
|
+
* timeline step at once.
|
|
602
|
+
*
|
|
603
|
+
* @example
|
|
604
|
+
* ```ts
|
|
605
|
+
* const descriptor: HapticDescriptor = {
|
|
606
|
+
* kind: "haptic", payload: { kind: "light" }, cosmetic: true
|
|
607
|
+
* };
|
|
608
|
+
* ```
|
|
609
|
+
*/
|
|
610
|
+
type HapticDescriptor = {
|
|
611
|
+
readonly kind: "haptic";
|
|
612
|
+
readonly payload: {
|
|
613
|
+
readonly kind: HapticKind;
|
|
614
|
+
};
|
|
615
|
+
readonly cosmetic: true; /** Never set: `await fx(haptic(...))` resolves nothing. */
|
|
616
|
+
readonly $result?: () => void;
|
|
617
|
+
};
|
|
618
|
+
/**
|
|
619
|
+
* The three descriptors `anim` owns. As a step, the descriptor is dispatched through
|
|
620
|
+
* `flow.fx.dispatch` when the step is reached; a kind nobody handles is silent.
|
|
621
|
+
*
|
|
622
|
+
* @example
|
|
623
|
+
* ```ts
|
|
624
|
+
* const step: FxStep = { kind: "haptic", payload: { kind: "light" }, cosmetic: true };
|
|
625
|
+
* ```
|
|
626
|
+
*/
|
|
627
|
+
type FxStep = SfxDescriptor | StopSfxDescriptor | HapticDescriptor;
|
|
628
|
+
/**
|
|
629
|
+
* The descriptor `play(animation, slots)` builds. The payload names the animation, so the
|
|
630
|
+
* handler resolves the definition from the registry instead of carrying a function.
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```ts
|
|
634
|
+
* const descriptor: PlayDescriptor = {
|
|
635
|
+
* kind: "play",
|
|
636
|
+
* payload: { animation: "hud.coinsFly", slots: { from: { projection: "hud", key: "coins" } } },
|
|
637
|
+
* cosmetic: true
|
|
638
|
+
* };
|
|
639
|
+
* ```
|
|
640
|
+
*/
|
|
641
|
+
type PlayDescriptor = {
|
|
642
|
+
readonly kind: "play";
|
|
643
|
+
readonly payload: {
|
|
644
|
+
readonly animation: string;
|
|
645
|
+
readonly slots: Json;
|
|
646
|
+
};
|
|
647
|
+
readonly cosmetic: true; /** Never set: `await fx(play(...))` resolves nothing. */
|
|
648
|
+
readonly $result?: () => void;
|
|
649
|
+
};
|
|
650
|
+
/**
|
|
651
|
+
* One step of a choreography: plain frozen data with no callback inside, so a step tree can be
|
|
652
|
+
* read, logged and compared. A `spawn` step carries the component values of a temporary entity,
|
|
653
|
+
* made when the step is reached and despawned when the timeline ends.
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```ts
|
|
657
|
+
* const step: Step = { kind: "wait", ms: 120 };
|
|
658
|
+
* ```
|
|
659
|
+
*/
|
|
660
|
+
type Step = {
|
|
661
|
+
readonly kind: "sequence";
|
|
662
|
+
readonly steps: readonly Step[];
|
|
663
|
+
} | {
|
|
664
|
+
readonly kind: "parallel";
|
|
665
|
+
readonly steps: readonly Step[];
|
|
666
|
+
} | {
|
|
667
|
+
readonly kind: "wait";
|
|
668
|
+
readonly ms: number;
|
|
669
|
+
} | {
|
|
670
|
+
readonly kind: "mark";
|
|
671
|
+
readonly name: string;
|
|
672
|
+
} | {
|
|
673
|
+
readonly kind: "tween";
|
|
674
|
+
readonly target: Target$1;
|
|
675
|
+
readonly component: AnyComponent;
|
|
676
|
+
readonly to: Readonly<Record<string, number>>;
|
|
677
|
+
readonly ms: number;
|
|
678
|
+
readonly ease: Ease;
|
|
679
|
+
readonly delayMs: number;
|
|
680
|
+
readonly additive: boolean; /** `"root"`: the `Transform` fields are a root pose, turned local when the track starts. */
|
|
681
|
+
readonly space: "local" | "root"; /** `"keep"`: reduced motion plays the track as written; `"cut"` lands it at once. */
|
|
682
|
+
readonly reduced: ReducedMotion;
|
|
683
|
+
/**
|
|
684
|
+
* The keyframe segments the track walks over `ms`, frozen; only on a step built with them.
|
|
685
|
+
* In the root space each segment's target is turned local when the track starts, like `to`.
|
|
686
|
+
*/
|
|
687
|
+
readonly segments?: readonly TrackSegment[];
|
|
688
|
+
/**
|
|
689
|
+
* The runs after the first one, or `"forever"` for a step that never ends by itself; only on
|
|
690
|
+
* a step built with it.
|
|
691
|
+
*/
|
|
692
|
+
readonly repeat?: number | "forever";
|
|
693
|
+
} | {
|
|
694
|
+
readonly kind: "set";
|
|
695
|
+
readonly target: Target$1;
|
|
696
|
+
readonly component: AnyComponent;
|
|
697
|
+
readonly patch: Readonly<ErasedFields>;
|
|
698
|
+
} | {
|
|
699
|
+
readonly kind: "frames";
|
|
700
|
+
readonly target: Target$1;
|
|
701
|
+
readonly keys: readonly string[];
|
|
702
|
+
readonly fps: number;
|
|
703
|
+
readonly loop: boolean;
|
|
704
|
+
} | {
|
|
705
|
+
readonly kind: "spawn";
|
|
706
|
+
readonly id: string;
|
|
707
|
+
readonly components: readonly AnyComponentValue[];
|
|
708
|
+
readonly layer: string;
|
|
709
|
+
readonly order: number;
|
|
710
|
+
} | FxStep | {
|
|
711
|
+
readonly kind: "use";
|
|
712
|
+
readonly id: string;
|
|
713
|
+
readonly step: Step;
|
|
714
|
+
};
|
|
715
|
+
/**
|
|
716
|
+
* Reserved for Spine and the other external players: `external` throws, and this is the shape it
|
|
717
|
+
* would take. Exported as a type only.
|
|
718
|
+
*
|
|
719
|
+
* @example
|
|
720
|
+
* ```ts
|
|
721
|
+
* const player: ExternalPlayer = { name: "spine", play: () => undefined };
|
|
722
|
+
* ```
|
|
723
|
+
*/
|
|
724
|
+
type ExternalPlayer = {
|
|
725
|
+
readonly name: string;
|
|
726
|
+
play(clip: string): unknown;
|
|
727
|
+
};
|
|
728
|
+
/**
|
|
729
|
+
* Where one step of a running timeline stands. One mutable record per step of the tree, built
|
|
730
|
+
* when the timeline starts.
|
|
731
|
+
*/
|
|
732
|
+
type Cursor = {
|
|
733
|
+
readonly step: Step;
|
|
734
|
+
readonly children: readonly Cursor[]; /** Position in a `sequence`, and the last written key of a `frames` step. */
|
|
735
|
+
index: number;
|
|
736
|
+
/**
|
|
737
|
+
* `[0]`: the consumed milliseconds of a `wait` or a `frames` step. A cell and not a field, so a
|
|
738
|
+
* frame writes it in place: a double stored in an object field is a new heap number.
|
|
739
|
+
*/
|
|
740
|
+
readonly clock: Float64Array;
|
|
741
|
+
motion: StepMotion | undefined;
|
|
742
|
+
started: boolean;
|
|
743
|
+
ended: boolean; /** The entity a running `frames` step holds against its `Frames` loop, until the step ends. */
|
|
744
|
+
held: Entity | undefined;
|
|
745
|
+
};
|
|
746
|
+
/**
|
|
747
|
+
* What the cursor reaches the rest of the engine through. Injected, so `timeline` never imports
|
|
748
|
+
* the run-time code of `tween` or of another plugin.
|
|
749
|
+
*/
|
|
750
|
+
type TimelineRuntime = {
|
|
751
|
+
/**
|
|
752
|
+
* Resolves a target to an entity.
|
|
753
|
+
*
|
|
754
|
+
* @param target - The projection key, the entity or the spawned id a step names.
|
|
755
|
+
* @param spawned - The spawn table of the timeline that asks; a spawned id resolves only there.
|
|
756
|
+
* @returns The entity, or `undefined` when no live view, element or spawned entity holds it.
|
|
757
|
+
*/
|
|
758
|
+
entityOf(target: Target$1, spawned?: ReadonlyMap<string, Entity>): Entity | undefined;
|
|
759
|
+
/**
|
|
760
|
+
* Spawns a temporary entity owned by `anim`. The timeline that spawned it despawns it when it
|
|
761
|
+
* ends, whichever way it ends.
|
|
762
|
+
*
|
|
763
|
+
* @param components - The component values the entity starts with, `Layer` and `Order` included.
|
|
764
|
+
* @returns The new entity.
|
|
765
|
+
*/
|
|
766
|
+
spawn(components: readonly AnyComponentValue[]): Entity;
|
|
767
|
+
/**
|
|
768
|
+
* Reads a component of an entity, which is also the liveness check of a step.
|
|
769
|
+
*
|
|
770
|
+
* @param entity - The entity to read.
|
|
771
|
+
* @param component - The component to read.
|
|
772
|
+
* @returns The stored value, or `undefined`.
|
|
773
|
+
*/
|
|
774
|
+
read(entity: Entity, component: AnyComponent): Readonly<ErasedFields> | undefined;
|
|
775
|
+
/**
|
|
776
|
+
* Writes a patch through `ecs.set`, so `changed()` sees it.
|
|
777
|
+
*
|
|
778
|
+
* @param entity - The entity to write.
|
|
779
|
+
* @param component - The component to write.
|
|
780
|
+
* @param patch - The fields to overwrite.
|
|
781
|
+
*/
|
|
782
|
+
write(entity: Entity, component: AnyComponent, patch: Partial<ErasedFields>): void;
|
|
783
|
+
/**
|
|
784
|
+
* Turns the root-space target of a `tween` step into the local target under the entity's
|
|
785
|
+
* parent, through `localPoseOf` of `renderer`.
|
|
786
|
+
*
|
|
787
|
+
* @param entity - The entity the step moves.
|
|
788
|
+
* @param component - The component the step drives; only `Transform` is converted.
|
|
789
|
+
* @param to - The numeric target fields, in root space.
|
|
790
|
+
* @returns The target fields in the space of the entity's parent.
|
|
791
|
+
*/
|
|
792
|
+
toLocal(entity: Entity, component: AnyComponent, to: Readonly<Record<string, number>>): Record<string, number>;
|
|
793
|
+
/**
|
|
794
|
+
* Starts one track on the tween core.
|
|
795
|
+
*
|
|
796
|
+
* @param entity - The entity to animate.
|
|
797
|
+
* @param component - The component to animate.
|
|
798
|
+
* @param to - The numeric target fields.
|
|
799
|
+
* @param options - Duration, easing, delay and the additive flag.
|
|
800
|
+
* @returns The motion of the track, advanceable by hand.
|
|
801
|
+
*/
|
|
802
|
+
start(entity: Entity, component: AnyComponent, to: Record<string, number>, options: TrackOptions): StepMotion;
|
|
803
|
+
/**
|
|
804
|
+
* Hands a descriptor step to `flow.fx.dispatch`.
|
|
805
|
+
*
|
|
806
|
+
* @param descriptor - The `sfx` or `haptic` step that was reached.
|
|
807
|
+
*/
|
|
808
|
+
dispatch(descriptor: FxStep): void;
|
|
809
|
+
/**
|
|
810
|
+
* Reports a mark: the event, the `onMark` listeners and the timeline's own list.
|
|
811
|
+
*
|
|
812
|
+
* @param animation - Id of the animation the mark belongs to.
|
|
813
|
+
* @param name - Name of the mark.
|
|
814
|
+
*/
|
|
815
|
+
mark(animation: string, name: string): void;
|
|
816
|
+
/**
|
|
817
|
+
* Lifts the idle frame rate, because something started to move.
|
|
818
|
+
*/
|
|
819
|
+
wake(): void;
|
|
820
|
+
/**
|
|
821
|
+
* Claims the sprite of an entity for a running `frames` step: the `Frames` loop of the entity
|
|
822
|
+
* writes nothing while any claim is open.
|
|
823
|
+
*
|
|
824
|
+
* @param entity - The entity the step writes.
|
|
825
|
+
*/
|
|
826
|
+
holdFrames(entity: Entity): void;
|
|
827
|
+
/**
|
|
828
|
+
* Gives one claim back. At the last one the `Frames` loop writes its current key again on its
|
|
829
|
+
* next step, so the sprite does not stay on the step's last key.
|
|
830
|
+
*
|
|
831
|
+
* @param entity - The entity the step wrote.
|
|
832
|
+
*/
|
|
833
|
+
releaseFrames(entity: Entity): void;
|
|
834
|
+
};
|
|
835
|
+
/**
|
|
836
|
+
* What the cursor functions carry down the tree: the runtime, the animation id marks are
|
|
837
|
+
* reported under, the list of marks reached so far, the entities the timeline spawned, by id, and
|
|
838
|
+
* the entities its key targets named when it started.
|
|
839
|
+
*/
|
|
840
|
+
type CursorCtx = {
|
|
841
|
+
/** The runtime of the frame step that walks the tree now. */rt: TimelineRuntime; /** Swapped for the nested id while a `use` step walks its tree, and set back after. */
|
|
842
|
+
animation: string;
|
|
843
|
+
readonly marks: string[];
|
|
844
|
+
readonly spawned: Map<string, Entity>; /** The entities the key targets named when the timeline started, by target object. */
|
|
845
|
+
readonly targets: ReadonlyMap<Target$1, Entity>;
|
|
846
|
+
};
|
|
847
|
+
/**
|
|
848
|
+
* One running timeline: its cursor, the marks it reached, the entities it counts on, the entities
|
|
849
|
+
* its key targets named at its start, the entities it spawned and despawns at its end, and the
|
|
850
|
+
* resolver of its `done` promise.
|
|
851
|
+
*/
|
|
852
|
+
type RunningTimeline = {
|
|
853
|
+
readonly id: number;
|
|
854
|
+
readonly animation: string; /** The slot values exactly as `play` received them, by reference: `timelines()` shows them. */
|
|
855
|
+
readonly slots: SlotRecord; /** The frame count of anim (`State.frame`) when the timeline started. */
|
|
856
|
+
readonly startFrame: number;
|
|
857
|
+
readonly cursor: Cursor;
|
|
858
|
+
readonly marks: string[];
|
|
859
|
+
readonly entities: readonly Entity[]; /** The entities its `{ projection, key }` targets named when it started, by target object. */
|
|
860
|
+
readonly targets: ReadonlyMap<Target$1, Entity>; /** The entities its `spawn` steps made, by spawn id. Despawned when the timeline ends. */
|
|
861
|
+
readonly spawned: Map<string, Entity>;
|
|
862
|
+
readonly resolve: () => void;
|
|
863
|
+
ended: boolean; /** The one cursor context of the timeline, made at its start and reused by every frame. */
|
|
864
|
+
readonly cctx: CursorCtx;
|
|
865
|
+
};
|
|
866
|
+
/**
|
|
867
|
+
* One slot of the ring of ended timelines. The sixteen records are made once with the state and
|
|
868
|
+
* written in place at every end, so an end allocates no record. Private: the API answers
|
|
869
|
+
* `EndedTimelineInfo` copies.
|
|
870
|
+
*/
|
|
871
|
+
type EndedRecord = {
|
|
872
|
+
timeline: number;
|
|
873
|
+
animation: string;
|
|
874
|
+
startFrame: number;
|
|
875
|
+
endFrame: number;
|
|
876
|
+
reason: TimelineEndReason;
|
|
877
|
+
};
|
|
878
|
+
declare namespace types_d_exports$4 {
|
|
879
|
+
export { AnimApi, AnimCtx, AnimPlayerValue, AnimationDefinition, AnimationSpec, AnyAnimationDefinition, BuildTools, Config$4 as Config, Cursor, Deps$3 as Deps, EndedTimelineInfo, ErasedFields, Events$1 as Events, ExternalPlayer, FrameLoop, FramesValue, FxStep, HapticDescriptor, HapticKind, KernelSlice$3 as KernelSlice, MarkListener, MotionKeyframe, PlayDescriptor, PlayHandle, Pose, RunningTimeline, RunningTimelineInfo, SfxDescriptor, SlotRecord, SlotTags, SlotValue, SlotValues, State$4 as State, Step, StepMotion, StopSfxDescriptor, Target$1 as Target, TimelineEndReason, TimelineRuntime, TimelinesSnapshot, Track };
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* What a step and a slot are pointed at: the projection key of a live view or of an element a
|
|
883
|
+
* plugin above registered with `registerKey`, an entity, or the id of an entity a `spawn` step of
|
|
884
|
+
* the same timeline made (`spawned(id)`). A node passes keys, never entities.
|
|
885
|
+
*
|
|
886
|
+
* @example
|
|
887
|
+
* ```ts
|
|
888
|
+
* const counter: Target = { projection: "hud", key: "coins" };
|
|
889
|
+
* const flyingCoin: Target = spawned("coin1"); // { spawned: "coin1" }
|
|
890
|
+
* ```
|
|
891
|
+
*/
|
|
892
|
+
type Target$1 = {
|
|
893
|
+
projection: string;
|
|
894
|
+
key: string;
|
|
895
|
+
} | Entity | {
|
|
896
|
+
spawned: string;
|
|
897
|
+
};
|
|
898
|
+
/**
|
|
899
|
+
* The pose `at(target)` answers with: where the target rests in root (reference) space, its rest
|
|
900
|
+
* `Transform` composed through the `Parent` chain, or the identity pose when nothing is there. The per-axis factors
|
|
901
|
+
* of the target (`scaleX`, `scaleY`) are not carried: `at()` answers the uniform `scale` only.
|
|
902
|
+
*
|
|
903
|
+
* @example
|
|
904
|
+
* ```ts
|
|
905
|
+
* const pose: Pose = { x: 540, y: 960, rotation: 0, scale: 1 };
|
|
906
|
+
* ```
|
|
907
|
+
*/
|
|
908
|
+
type Pose = {
|
|
909
|
+
x: number;
|
|
910
|
+
y: number;
|
|
911
|
+
rotation: number;
|
|
912
|
+
scale: number;
|
|
913
|
+
};
|
|
914
|
+
/**
|
|
915
|
+
* The slot declaration of an animation: one type tag per slot, each carrying one target or a
|
|
916
|
+
* list of targets.
|
|
917
|
+
*
|
|
918
|
+
* @example
|
|
919
|
+
* ```ts
|
|
920
|
+
* const slots: SlotTags = { items: type<Target[]>(), card: type<Target>() };
|
|
921
|
+
* ```
|
|
922
|
+
*/
|
|
923
|
+
type SlotTags = Readonly<Record<string, TypeTag<Target$1> | TypeTag<Target$1[]>>>;
|
|
924
|
+
/**
|
|
925
|
+
* The targets `play` and `use` take, read off the slot tags of the animation.
|
|
926
|
+
*
|
|
927
|
+
* @example
|
|
928
|
+
* ```ts
|
|
929
|
+
* type Slots = SlotValues<{ card: TypeTag<Target> }>; // { card: Target }
|
|
930
|
+
* ```
|
|
931
|
+
*/
|
|
932
|
+
type SlotValues<Tags extends SlotTags> = { [Name in keyof Tags]: SlotValue<Tags[Name]> };
|
|
933
|
+
/**
|
|
934
|
+
* What one slot tag stands for: a list of targets when the tag declared one, a single target
|
|
935
|
+
* otherwise. Distributive on purpose, so the erased `SlotTags` widens to both.
|
|
936
|
+
*
|
|
937
|
+
* @example
|
|
938
|
+
* ```ts
|
|
939
|
+
* type One = SlotValue<TypeTag<Target>>; // Target
|
|
940
|
+
* ```
|
|
941
|
+
*/
|
|
942
|
+
type SlotValue<Tag> = Tag extends TypeTag<Target$1[]> ? Target$1[] : Target$1;
|
|
943
|
+
/**
|
|
944
|
+
* The slots of a running animation with their tags erased, as `build` and the `play` handler
|
|
945
|
+
* read them.
|
|
946
|
+
*
|
|
947
|
+
* @example
|
|
948
|
+
* ```ts
|
|
949
|
+
* const slots: SlotRecord = { card: { projection: "hud", key: "order" } };
|
|
950
|
+
* ```
|
|
951
|
+
*/
|
|
952
|
+
type SlotRecord = SlotValues<SlotTags>;
|
|
953
|
+
/**
|
|
954
|
+
* What `build` is handed next to the slots: `at` reads where a target rests at play time, in root
|
|
955
|
+
* space (its rest `Transform` composed through the `Parent` chain, every pivot applied), so a
|
|
956
|
+
* choreography can fly one element to where another one rests, even inside a scaled slot. A view
|
|
957
|
+
* that has a `Parent` itself is aimed at that pose with a `tween` in `space: "root"`.
|
|
958
|
+
*
|
|
959
|
+
* `reducedMotion` is the live reduced-motion switch (`setReducedMotion`) read once, when the play
|
|
960
|
+
* starts, so `build` can choose a designed variant: fades in place, waits, marks, every track
|
|
961
|
+
* `reduced: "keep"`. The engine never guesses: a tween of that variant that is not marked `keep`
|
|
962
|
+
* is still cut. A switch while the timeline runs does not rebuild it. An absent `reducedMotion` reads as
|
|
963
|
+
* `false`, so a hand-written `{ at }` passes; a nested `use` sees it only when the outer tools are
|
|
964
|
+
* passed on.
|
|
965
|
+
*
|
|
966
|
+
* @example
|
|
967
|
+
* ```ts
|
|
968
|
+
* const giftFade = defineAnimation("puzzles.giftFade", {
|
|
969
|
+
* slots: { hero: type<Target>() },
|
|
970
|
+
* build: ({ hero }, { reducedMotion }) =>
|
|
971
|
+
* reducedMotion
|
|
972
|
+
* ? tween(hero, Shape, { alpha: 0 }, { ms: 200, reduced: "keep" })
|
|
973
|
+
* : tween(hero, Transform, { y: -300 }, { ms: 600 })
|
|
974
|
+
* });
|
|
975
|
+
* app.anim.setReducedMotion(true);
|
|
976
|
+
* app.anim.play(giftFade, { hero }); // build got reducedMotion: true: the hero fades in place over 200 ms
|
|
977
|
+
* ```
|
|
978
|
+
*/
|
|
979
|
+
type BuildTools = {
|
|
980
|
+
at(target: Target$1): Pose; /** Whether reduced motion was on when this play started. Absent reads as `false`. */
|
|
981
|
+
readonly reducedMotion?: boolean;
|
|
982
|
+
};
|
|
983
|
+
/**
|
|
984
|
+
* One animation: an id, the slots it takes and the pure function that builds its step tree. The
|
|
985
|
+
* same definition may play twice at once, because `build` runs per play.
|
|
986
|
+
*
|
|
987
|
+
* @example
|
|
988
|
+
* ```ts
|
|
989
|
+
* const coinsFly: AnimationDefinition<{ from: TypeTag<Target> }> = defineAnimation("hud.coinsFly", {
|
|
990
|
+
* slots: { from: type<Target>() },
|
|
991
|
+
* build: ({ from }) => tween(from, Transform, { scale: 0.4 }, { ms: 600 })
|
|
992
|
+
* });
|
|
993
|
+
* coinsFly.id; // "hud.coinsFly"
|
|
994
|
+
* ```
|
|
995
|
+
*/
|
|
996
|
+
type AnimationDefinition<Tags extends SlotTags = SlotTags> = {
|
|
997
|
+
readonly id: string;
|
|
998
|
+
readonly slots: Tags;
|
|
999
|
+
build(slots: SlotValues<Tags>, tools: BuildTools): Step;
|
|
1000
|
+
};
|
|
1001
|
+
/**
|
|
1002
|
+
* What `defineAnimation` is given: the slots the animation takes and the pure function that
|
|
1003
|
+
* builds its step tree.
|
|
1004
|
+
*
|
|
1005
|
+
* @example
|
|
1006
|
+
* ```ts
|
|
1007
|
+
* const spec: AnimationSpec<{ card: TypeTag<Target> }> = {
|
|
1008
|
+
* slots: { card: type<Target>() },
|
|
1009
|
+
* build: ({ card }) => tween(card, Transform, { scale: 1.2 }, { ms: 120 })
|
|
1010
|
+
* };
|
|
1011
|
+
* ```
|
|
1012
|
+
*/
|
|
1013
|
+
type AnimationSpec<Tags extends SlotTags> = {
|
|
1014
|
+
readonly slots: Tags;
|
|
1015
|
+
build(slots: SlotValues<Tags>, tools: BuildTools): Step;
|
|
1016
|
+
};
|
|
1017
|
+
/**
|
|
1018
|
+
* An animation with its slot tags erased, as the registry stores it.
|
|
1019
|
+
*
|
|
1020
|
+
* @example
|
|
1021
|
+
* ```ts
|
|
1022
|
+
* const stored: AnyAnimationDefinition = { id: "hud.coinsFly", slots: {}, build: () => wait(0) };
|
|
1023
|
+
* ```
|
|
1024
|
+
*/
|
|
1025
|
+
type AnyAnimationDefinition = AnimationDefinition<SlotTags>;
|
|
1026
|
+
/**
|
|
1027
|
+
* What `play` hands back: the motion contract over the whole step tree, the promise of its end
|
|
1028
|
+
* and the marks it reached so far.
|
|
1029
|
+
*
|
|
1030
|
+
* @example
|
|
1031
|
+
* ```ts
|
|
1032
|
+
* const deliverOrder = defineAnimation("orders.deliver", { slots: { card: type<Target>() },
|
|
1033
|
+
* build: ({ card }) => sequence(tween(card, Transform, { x: 100 }, { ms: 100 }), mark("done")) });
|
|
1034
|
+
* const handle: PlayHandle = app.anim.play(deliverOrder, { card: { projection: "board.items", key: "a" } });
|
|
1035
|
+
* handle.marks(); // []: nothing reached yet
|
|
1036
|
+
* ```
|
|
1037
|
+
*/
|
|
1038
|
+
type PlayHandle = MotionHandle & {
|
|
1039
|
+
readonly done: Promise<void>;
|
|
1040
|
+
marks(): readonly string[];
|
|
1041
|
+
};
|
|
1042
|
+
/**
|
|
1043
|
+
* A listener of `onMark`: the animation id and the name of the mark that was reached.
|
|
1044
|
+
*
|
|
1045
|
+
* @example
|
|
1046
|
+
* ```ts
|
|
1047
|
+
* const reached: string[] = [];
|
|
1048
|
+
* const listener: MarkListener = (_animation, mark) => reached.push(mark);
|
|
1049
|
+
* ```
|
|
1050
|
+
*/
|
|
1051
|
+
type MarkListener = (animation: string, mark: string) => void;
|
|
1052
|
+
/**
|
|
1053
|
+
* anim plugin events.
|
|
1054
|
+
*
|
|
1055
|
+
* @example
|
|
1056
|
+
* ```ts
|
|
1057
|
+
* // A feature plugin logs every mark a choreography reaches.
|
|
1058
|
+
* createPlugin("rewardLog", {
|
|
1059
|
+
* depends: [animPlugin],
|
|
1060
|
+
* hooks: ctx => ({ "anim:mark": ({ mark }) => ctx.log.info("mark", { mark }) })
|
|
1061
|
+
* }); // a reached mark("done") step logs { mark: "done" }
|
|
1062
|
+
* ```
|
|
1063
|
+
*/
|
|
1064
|
+
type Events$1 = {
|
|
1065
|
+
/** A `mark` step was reached, or jumped by `finish()`. */"anim:mark": {
|
|
1066
|
+
animation: string;
|
|
1067
|
+
mark: string;
|
|
1068
|
+
}; /** A timeline started: it is in `timelines()` and `play` has not returned yet. */
|
|
1069
|
+
"anim:started": {
|
|
1070
|
+
animation: string;
|
|
1071
|
+
timeline: number;
|
|
1072
|
+
}; /** A timeline was cancelled with `handle.cancel()`. `anim:finished` does not follow. */
|
|
1073
|
+
"anim:cancelled": {
|
|
1074
|
+
animation: string;
|
|
1075
|
+
timeline: number;
|
|
1076
|
+
};
|
|
1077
|
+
/**
|
|
1078
|
+
* A timeline ended or was finished, with `reason: "ended"` when its tree ran through and
|
|
1079
|
+
* `"finished"` for `finish()`, `finishAll()` and the abort of the node that played it. Not
|
|
1080
|
+
* emitted on `cancel()`.
|
|
1081
|
+
*/
|
|
1082
|
+
"anim:finished": {
|
|
1083
|
+
animation: string;
|
|
1084
|
+
timeline: number;
|
|
1085
|
+
reason: "ended" | "finished";
|
|
1086
|
+
};
|
|
1087
|
+
};
|
|
1088
|
+
/**
|
|
1089
|
+
* Why a timeline ended: it ran through its tree, it was finished early, or it was cancelled.
|
|
1090
|
+
*
|
|
1091
|
+
* @example
|
|
1092
|
+
* ```ts
|
|
1093
|
+
* // A timeline that played to its last step, then one a node's abort finished early.
|
|
1094
|
+
* const ran: TimelineEndReason = "ended";
|
|
1095
|
+
* const aborted: TimelineEndReason = "finished";
|
|
1096
|
+
* ```
|
|
1097
|
+
*/
|
|
1098
|
+
type TimelineEndReason = "ended" | "finished" | "cancelled";
|
|
1099
|
+
/**
|
|
1100
|
+
* One running timeline as `timelines()` reports it.
|
|
1101
|
+
*
|
|
1102
|
+
* @example
|
|
1103
|
+
* ```ts
|
|
1104
|
+
* // The delivery of order card "a", one frame in, with nothing reached yet.
|
|
1105
|
+
* const info: RunningTimelineInfo = {
|
|
1106
|
+
* timeline: 4, animation: "orders.deliver", startFrame: 0,
|
|
1107
|
+
* slots: { card: { projection: "board.items", key: "a" } }, entities: [1_048_576], marks: []
|
|
1108
|
+
* };
|
|
1109
|
+
* ```
|
|
1110
|
+
*/
|
|
1111
|
+
type RunningTimelineInfo = {
|
|
1112
|
+
/** The timeline number: the one `anim:started` and `anim:finished` carry. Ids are shared with tracks. */readonly timeline: number; /** The animation id. */
|
|
1113
|
+
readonly animation: string; /** The anim frame count when it started. */
|
|
1114
|
+
readonly startFrame: number; /** The targets as `play` received them: the very object, not a copy. Do not mutate it. */
|
|
1115
|
+
readonly slots: SlotRecord; /** The entities its targets resolved to at the start, each counted in `Animation`. A copy. */
|
|
1116
|
+
readonly entities: readonly Entity[]; /** The marks reached so far. A copy. */
|
|
1117
|
+
readonly marks: readonly string[];
|
|
1118
|
+
};
|
|
1119
|
+
/**
|
|
1120
|
+
* One ended timeline of the ring `timelines()` keeps.
|
|
1121
|
+
*
|
|
1122
|
+
* @example
|
|
1123
|
+
* ```ts
|
|
1124
|
+
* const info: EndedTimelineInfo = {
|
|
1125
|
+
* timeline: 4, animation: "orders.deliver", startFrame: 0, endFrame: 2, reason: "ended"
|
|
1126
|
+
* };
|
|
1127
|
+
* ```
|
|
1128
|
+
*/
|
|
1129
|
+
type EndedTimelineInfo = {
|
|
1130
|
+
/** The timeline number it ran under. */readonly timeline: number; /** The animation id. */
|
|
1131
|
+
readonly animation: string; /** The anim frame count when it started. */
|
|
1132
|
+
readonly startFrame: number; /** The anim frame count when it ended. */
|
|
1133
|
+
readonly endFrame: number; /** How it ended. */
|
|
1134
|
+
readonly reason: TimelineEndReason;
|
|
1135
|
+
};
|
|
1136
|
+
/**
|
|
1137
|
+
* What `timelines()` and the `game.timelines` source answer: the timelines that run now, in start
|
|
1138
|
+
* order, and the last sixteen that ended, oldest first.
|
|
1139
|
+
*
|
|
1140
|
+
* @example
|
|
1141
|
+
* ```ts
|
|
1142
|
+
* const idle: TimelinesSnapshot = { running: [], ended: [] };
|
|
1143
|
+
* ```
|
|
1144
|
+
*/
|
|
1145
|
+
type TimelinesSnapshot = {
|
|
1146
|
+
/** The running timelines, in start order. */readonly running: readonly RunningTimelineInfo[]; /** The last ended timelines, oldest first, at most 16. */
|
|
1147
|
+
readonly ended: readonly EndedTimelineInfo[];
|
|
1148
|
+
};
|
|
1149
|
+
/**
|
|
1150
|
+
* One key of a keyframe track in `defineMotion`: where on the track it sits (`at`, 0..1 of
|
|
1151
|
+
* `transition.ms`), the curve of the segment that ends on it (default `"inOut"`) and the pose.
|
|
1152
|
+
* `dx` and `dy` are offsets from the rest pose in reference units; `rotation` (radians), `scale`,
|
|
1153
|
+
* `scaleX`, `scaleY` and `alpha` are absolute. `scaleX` and `scaleY` stretch one axis on top of `scale`; a view
|
|
1154
|
+
* that sets neither rests at 1. A field the key leaves out holds the previous key's value.
|
|
1155
|
+
*
|
|
1156
|
+
* An enter walk starts on the first key and ends on the rest pose at `at: 1`; an exit walk starts
|
|
1157
|
+
* where the view is and ends on the last key, the pose the element leaves in.
|
|
1158
|
+
*
|
|
1159
|
+
* In a loop (`loop: { track }`) every Transform field is an offset added to the rest pose: `dx`, `dy`, `rotation`,
|
|
1160
|
+
* `scale`, `scaleX` and `scaleY` (`scale: 0.05` grows a scale-1 view to 1.05, `scaleX: 0.05` widens it alone). `alpha`
|
|
1161
|
+
* stays absolute. The loop stands on its first key until that key's `at`, and its last key repeats its first one.
|
|
1162
|
+
*
|
|
1163
|
+
* @example
|
|
1164
|
+
* ```ts
|
|
1165
|
+
* // A popup board at 42 % of its swing: 14 u below its rest, tilted 5°, slightly larger.
|
|
1166
|
+
* const key: MotionKeyframe = { at: 0.42, ease: "out", Transform: { dy: 14, rotation: 0.087, scale: 1.04 } };
|
|
1167
|
+
* // A ribbon at 65 % of its unfurl: 8 % wider than its rest, as tall as it rests.
|
|
1168
|
+
* const unfurl: MotionKeyframe = { at: 0.65, Transform: { scaleX: 1.08 } };
|
|
1169
|
+
* ```
|
|
1170
|
+
*/
|
|
1171
|
+
type MotionKeyframe = {
|
|
1172
|
+
readonly at: number;
|
|
1173
|
+
readonly ease?: Ease;
|
|
1174
|
+
readonly Transform?: {
|
|
1175
|
+
readonly dx?: number;
|
|
1176
|
+
readonly dy?: number;
|
|
1177
|
+
readonly rotation?: number;
|
|
1178
|
+
readonly scale?: number;
|
|
1179
|
+
readonly scaleX?: number;
|
|
1180
|
+
readonly scaleY?: number;
|
|
1181
|
+
};
|
|
1182
|
+
readonly Shape?: {
|
|
1183
|
+
readonly alpha?: number;
|
|
1184
|
+
};
|
|
1185
|
+
readonly Sprite?: {
|
|
1186
|
+
readonly alpha?: number;
|
|
1187
|
+
};
|
|
1188
|
+
readonly NineSlice?: {
|
|
1189
|
+
readonly alpha?: number;
|
|
1190
|
+
};
|
|
1191
|
+
};
|
|
1192
|
+
/**
|
|
1193
|
+
* The value of the `Frames` component: a frame loop that lives as long as its entity. `keys` and
|
|
1194
|
+
* `fps` mean what they mean on the `frames` step; `loop: false` stops on the last key and
|
|
1195
|
+
* `playing: false` holds the key on the screen. A new `keys` array restarts at key 0, the same
|
|
1196
|
+
* array keeps its phase.
|
|
1197
|
+
*
|
|
1198
|
+
* @example
|
|
1199
|
+
* ```ts
|
|
1200
|
+
* const spin: FramesValue = { keys: ["items.coin-0", "items.coin-1"], fps: 12, loop: true, playing: true };
|
|
1201
|
+
* ```
|
|
1202
|
+
*/
|
|
1203
|
+
type FramesValue = {
|
|
1204
|
+
keys: readonly string[];
|
|
1205
|
+
fps: number;
|
|
1206
|
+
loop: boolean;
|
|
1207
|
+
playing: boolean;
|
|
1208
|
+
};
|
|
1209
|
+
/**
|
|
1210
|
+
* Where the `Frames` loop of one entity stands. `keys` is the array last seen, for the restart
|
|
1211
|
+
* check; `index` is the key the clock last landed on, `-1` before the first one; `written` is
|
|
1212
|
+
* false while that key still has to reach the sprite.
|
|
1213
|
+
*/
|
|
1214
|
+
type FrameLoop = {
|
|
1215
|
+
keys: readonly string[];
|
|
1216
|
+
elapsed: number;
|
|
1217
|
+
index: number;
|
|
1218
|
+
written: boolean;
|
|
1219
|
+
};
|
|
1220
|
+
/**
|
|
1221
|
+
* anim plugin config. The timings live in the steps and in `defineMotion`, not here: a
|
|
1222
|
+
* choreography that reads its duration from a config cannot be read as text.
|
|
1223
|
+
*
|
|
1224
|
+
* @example
|
|
1225
|
+
* ```ts
|
|
1226
|
+
* createApp({ plugins: [...screen], pluginConfigs: { anim: { maxTracks: 500, reducedMotion: true } } });
|
|
1227
|
+
* ```
|
|
1228
|
+
*/
|
|
1229
|
+
type Config$4 = {
|
|
1230
|
+
/** Dev guard: one warning each time the running track count rises past this number. */maxTracks: number;
|
|
1231
|
+
/**
|
|
1232
|
+
* Start value of reduced motion: every track but a loop takes 0 ms and every loop stands on
|
|
1233
|
+
* its first key. `app.anim.setReducedMotion(on)` switches it while the game runs.
|
|
1234
|
+
*/
|
|
1235
|
+
reducedMotion: boolean;
|
|
1236
|
+
};
|
|
1237
|
+
/**
|
|
1238
|
+
* anim plugin state: the one track table, the field bookkeeping of the retarget policy and the
|
|
1239
|
+
* offsets accumulator, the running timelines and the animation registry.
|
|
1240
|
+
*/
|
|
1241
|
+
type State$4 = {
|
|
1242
|
+
/** The one track table. Insertion order is advance order. */tracks: Map<number, Track>;
|
|
1243
|
+
/**
|
|
1244
|
+
* The tracks of the table in start order, as a dense list the frame step walks by index. An ended
|
|
1245
|
+
* track stays in it until the next frame step drops it.
|
|
1246
|
+
*/
|
|
1247
|
+
trackList: Track[]; /** Ids of tracks and timelines. */
|
|
1248
|
+
nextId: number; /** `"<entity>:<component>:<field>"` to the id of the absolute track that drives the field. */
|
|
1249
|
+
owner: Map<string, number>;
|
|
1250
|
+
/**
|
|
1251
|
+
* Per field key, the delta each additive track contributes, in a one-number cell per track that
|
|
1252
|
+
* a frame writes in place.
|
|
1253
|
+
*/
|
|
1254
|
+
offsets: Map<string, Map<number, Float64Array>>;
|
|
1255
|
+
/**
|
|
1256
|
+
* Per field key, the value the offsets are added to, in a one-number cell a frame writes in
|
|
1257
|
+
* place. Dropped when no track drives the field.
|
|
1258
|
+
*/
|
|
1259
|
+
bases: Map<string, Float64Array>;
|
|
1260
|
+
/**
|
|
1261
|
+
* Per entity, its running additive tracks. `offsetsOf` of the driver reads it, so the cost of
|
|
1262
|
+
* one answer is the loops of that entity and not every track of the game.
|
|
1263
|
+
*/
|
|
1264
|
+
additive: Map<Entity, Set<Track>>; /** The running timelines, by id. */
|
|
1265
|
+
timelines: Map<number, RunningTimeline>;
|
|
1266
|
+
/**
|
|
1267
|
+
* The timelines in start order, as a dense list the frame step walks by index. An ended timeline
|
|
1268
|
+
* stays in it until the next frame step drops it.
|
|
1269
|
+
*/
|
|
1270
|
+
timelineList: RunningTimeline[];
|
|
1271
|
+
/**
|
|
1272
|
+
* The ring of the last 16 ended timelines. Its 16 records are made with the state and written
|
|
1273
|
+
* in place at every end, never replaced.
|
|
1274
|
+
*/
|
|
1275
|
+
ended: EndedRecord[]; /** The ring slot the next end writes, 0..15. */
|
|
1276
|
+
endedNext: number; /** How many slots of the ring hold a real record, 0..16. */
|
|
1277
|
+
endedCount: number; /** The `animations` of every feature, read in `onStart`. */
|
|
1278
|
+
registry: Map<string, AnyAnimationDefinition>; /** `onMark` subscribers, in subscription order. */
|
|
1279
|
+
markListeners: Set<MarkListener>; /** Counter of the frame steps. A track born in the running step is not advanced by it. */
|
|
1280
|
+
frame: number; /** True while the track count is over `maxTracks`, so the warning is one per crossing. */
|
|
1281
|
+
overMaxTracks: boolean; /** The animations already warned for a looping `frames` step that blocks the rest of a `sequence` (dev). */
|
|
1282
|
+
warnedLoops: Set<string>; /** The live reduced-motion switch. The frozen `Config.reducedMotion` only seeds it. */
|
|
1283
|
+
reducedMotion: boolean; /** Remover of `world.projection.setDriver`. */
|
|
1284
|
+
removeDriver: (() => void) | undefined; /** Remover of `time.onFrame("animate")`. */
|
|
1285
|
+
offFrame: (() => void) | undefined; /** Remover of `flow.fx.handle("play")`. */
|
|
1286
|
+
offPlay: (() => void) | undefined; /** Bound in `onInit`, so the teardown context can end everything with the state alone. */
|
|
1287
|
+
finishAll: (() => void) | undefined; /** One loop per entity that carries `Frames`, kept by the two world hooks. */
|
|
1288
|
+
frameLoops: Map<Entity, FrameLoop>; /** How many running `frames` steps write this entity now. Its loop writes nothing above 0. */
|
|
1289
|
+
framesHeld: Map<Entity, number>;
|
|
1290
|
+
/**
|
|
1291
|
+
* Per entity that carries `Frames`, the remover of its `world.projection.mute` on
|
|
1292
|
+
* `Sprite.texture`: the loop owns that field, so a projection never corrects it back.
|
|
1293
|
+
*/
|
|
1294
|
+
frameMutes: Map<Entity, () => void>; /** Removers of the `onAdded` and `onRemoved` hooks on `Frames`. */
|
|
1295
|
+
offFrames: Array<() => void>;
|
|
1296
|
+
/**
|
|
1297
|
+
* The renderer's `sync.loopsHeld`, bound in `onStart`: an endless loop of an entity it answers true for writes
|
|
1298
|
+
* nothing while its clock runs on (spec 22 O9), told what the loop reveals (spec 26 R1.7). `undefined` before the
|
|
1299
|
+
* start and after the stop: nothing is held.
|
|
1300
|
+
*/
|
|
1301
|
+
loopsHeld: SyncApi["loopsHeld"] | undefined;
|
|
1302
|
+
};
|
|
1303
|
+
/**
|
|
1304
|
+
* anim plugin API, `app.anim`: play a choreography, end everything, count what runs and listen
|
|
1305
|
+
* to the marks. A choreography may spawn temporary entities; they live exactly as long as its
|
|
1306
|
+
* timeline.
|
|
1307
|
+
*
|
|
1308
|
+
* @example
|
|
1309
|
+
* ```ts
|
|
1310
|
+
* // A choreography runs in game time: two frames of 50 ms play the 100 ms slide of a card.
|
|
1311
|
+
* const deliverOrder = defineAnimation("orders.deliver", { slots: { card: type<Target>() },
|
|
1312
|
+
* build: ({ card }) => sequence(tween(card, Transform, { x: 100 }, { ms: 100 }), mark("done")) });
|
|
1313
|
+
* app.anim.play(deliverOrder, { card: { projection: "board.items", key: "a" } });
|
|
1314
|
+
* app.time.step(50); // app.anim.active() is 1: the card slides
|
|
1315
|
+
* app.time.step(50); // app.anim.active() is 0: the card rests at x 100
|
|
1316
|
+
* ```
|
|
1317
|
+
*/
|
|
1318
|
+
type AnimApi = {
|
|
1319
|
+
/**
|
|
1320
|
+
* Builds the step tree of an animation with the given targets and starts it. The tree runs
|
|
1321
|
+
* from the next frame step on, in game time, so `time.setScale` and a pause apply to it. `at`
|
|
1322
|
+
* inside `build` answers where a target rests in root space, even inside a scaled slot. A
|
|
1323
|
+
* `tween` with `space: "root"` lands a hosted view on such a pose: a board item inside the board
|
|
1324
|
+
* slot flies onto an order card of the HUD.
|
|
1325
|
+
*
|
|
1326
|
+
* @param animation - What `defineAnimation` returned.
|
|
1327
|
+
* @param slots - One target, or a list of targets, per declared slot.
|
|
1328
|
+
* @returns The handle of the running timeline.
|
|
1329
|
+
* @throws {Error} When the tree spawns one id twice.
|
|
1330
|
+
* @example
|
|
1331
|
+
* ```ts
|
|
1332
|
+
* // The player delivers order card "a": it slides to x 100 in 100 ms, then reaches "done".
|
|
1333
|
+
* const deliverOrder = defineAnimation("orders.deliver", { slots: { card: type<Target>() },
|
|
1334
|
+
* build: ({ card }) => sequence(tween(card, Transform, { x: 100 }, { ms: 100 }), mark("done")) });
|
|
1335
|
+
* const handle = app.anim.play(deliverOrder, { card: { projection: "board.items", key: "a" } });
|
|
1336
|
+
* app.time.step(100);
|
|
1337
|
+
* handle.marks(); // ["done"], and handle.done resolves
|
|
1338
|
+
* ```
|
|
1339
|
+
*/
|
|
1340
|
+
play<Tags extends SlotTags>(animation: AnimationDefinition<Tags>, slots: SlotValues<Tags>): PlayHandle;
|
|
1341
|
+
/**
|
|
1342
|
+
* Ends every track and every timeline now: each writes its exact target, the marks of a
|
|
1343
|
+
* running timeline are jumped in tree order, every entity a timeline spawned is despawned and
|
|
1344
|
+
* every pending `done` resolves.
|
|
1345
|
+
*
|
|
1346
|
+
* @example
|
|
1347
|
+
* ```ts
|
|
1348
|
+
* // A /control tool skips the delivery mid-flight: the card lands on x 100 at once.
|
|
1349
|
+
* const deliverOrder = defineAnimation("orders.deliver", { slots: { card: type<Target>() },
|
|
1350
|
+
* build: ({ card }) => sequence(tween(card, Transform, { x: 100 }, { ms: 100 }), mark("done")) });
|
|
1351
|
+
* app.anim.play(deliverOrder, { card: { projection: "board.items", key: "a" } });
|
|
1352
|
+
* app.time.step(50);
|
|
1353
|
+
* app.anim.finishAll(); // app.anim.active() is 0
|
|
1354
|
+
* ```
|
|
1355
|
+
*/
|
|
1356
|
+
finishAll(): void;
|
|
1357
|
+
/**
|
|
1358
|
+
* How many tracks are in the table, the delayed ones and the running loops included. A loop
|
|
1359
|
+
* never ends by itself, so a screen at rest counts one track per loop lane it shows. A `Frames`
|
|
1360
|
+
* component is not a track: a spinning coin counts nothing.
|
|
1361
|
+
*
|
|
1362
|
+
* @returns The number of running tracks.
|
|
1363
|
+
* @example
|
|
1364
|
+
* ```ts
|
|
1365
|
+
* // The assertion every motion test ends with: the screen came to rest.
|
|
1366
|
+
* const deliverOrder = defineAnimation("orders.deliver", { slots: { card: type<Target>() },
|
|
1367
|
+
* build: ({ card }) => sequence(tween(card, Transform, { x: 100 }, { ms: 100 }), mark("done")) });
|
|
1368
|
+
* app.anim.play(deliverOrder, { card: { projection: "board.items", key: "a" } });
|
|
1369
|
+
* app.time.step(100);
|
|
1370
|
+
* app.anim.active(); // 0
|
|
1371
|
+
* ```
|
|
1372
|
+
*/
|
|
1373
|
+
active(): number;
|
|
1374
|
+
/**
|
|
1375
|
+
* What plays now and what ended last: every running timeline with the targets it was played
|
|
1376
|
+
* with, and the last 16 that ended with the reason of each end. Every call builds new plain
|
|
1377
|
+
* objects and copies `entities` and `marks`; `slots` is the very object `play` received, so do
|
|
1378
|
+
* not mutate it. A reader pays for the copies, the frame step does not. Stopping the app empties
|
|
1379
|
+
* the ring.
|
|
1380
|
+
*
|
|
1381
|
+
* @returns The running timelines in start order and the ended ones, oldest first.
|
|
1382
|
+
* @example
|
|
1383
|
+
* ```ts
|
|
1384
|
+
* // A test asks what the delivery did, one frame in and at its end.
|
|
1385
|
+
* const deliverOrder = defineAnimation("orders.deliver", { slots: { card: type<Target>() },
|
|
1386
|
+
* build: ({ card }) => sequence(tween(card, Transform, { x: 100 }, { ms: 100 }), mark("done")) });
|
|
1387
|
+
* app.anim.play(deliverOrder, { card: { projection: "board.items", key: "a" } });
|
|
1388
|
+
* app.time.step(50);
|
|
1389
|
+
* app.anim.timelines().running[0]?.animation; // "orders.deliver"
|
|
1390
|
+
* app.time.step(50);
|
|
1391
|
+
* app.anim.timelines().running; // []
|
|
1392
|
+
* app.anim.timelines().ended[0]?.reason; // "ended"
|
|
1393
|
+
* ```
|
|
1394
|
+
*/
|
|
1395
|
+
timelines(): TimelinesSnapshot;
|
|
1396
|
+
/**
|
|
1397
|
+
* Whether reduced motion is on. It starts at `Config.reducedMotion` and `setReducedMotion`
|
|
1398
|
+
* switches it.
|
|
1399
|
+
*
|
|
1400
|
+
* @returns True while every new track takes 0 ms and every loop stands on its first key.
|
|
1401
|
+
* @example
|
|
1402
|
+
* ```ts
|
|
1403
|
+
* // A settings popup shows the switch as the player left it.
|
|
1404
|
+
* app.anim.reducedMotion(); // false: the start value of Config.reducedMotion
|
|
1405
|
+
* ```
|
|
1406
|
+
*/
|
|
1407
|
+
reducedMotion(): boolean;
|
|
1408
|
+
/**
|
|
1409
|
+
* Switches reduced motion. While it is on, every track started from then on takes 0 ms: enter
|
|
1410
|
+
* and exit, state changes, change and settle motions, drag returns and timeline tweens land on
|
|
1411
|
+
* their target at the next frame, and their marks and sounds still fire. Every loop stands on
|
|
1412
|
+
* its first key, a running one at once. Tracks already running keep their length. A `Frames`
|
|
1413
|
+
* loop stops on the frame it shows and walks on from that frame when the switch goes off.
|
|
1414
|
+
*
|
|
1415
|
+
* @param on - True for less motion, false for the full motion.
|
|
1416
|
+
* @example
|
|
1417
|
+
* ```ts
|
|
1418
|
+
* // The player turns on "Less motion" in the settings popup.
|
|
1419
|
+
* app.anim.setReducedMotion(true);
|
|
1420
|
+
* app.anim.reducedMotion(); // true: a popup opened now stands in its rest pose next frame
|
|
1421
|
+
* ```
|
|
1422
|
+
*/
|
|
1423
|
+
setReducedMotion(on: boolean): void;
|
|
1424
|
+
/**
|
|
1425
|
+
* Registers a listener called for every mark a timeline reaches, next to the `anim:mark`
|
|
1426
|
+
* event. A listener that throws is logged and the listeners after it still run.
|
|
1427
|
+
*
|
|
1428
|
+
* @param fn - Called with the animation id and the mark name.
|
|
1429
|
+
* @returns The remover; calling it twice is a no-op.
|
|
1430
|
+
* @example
|
|
1431
|
+
* ```ts
|
|
1432
|
+
* // A test waits for the "done" mark instead of counting frames.
|
|
1433
|
+
* const ping = defineAnimation("fx.ping", { slots: {}, build: () => sequence(wait(100), mark("done")) });
|
|
1434
|
+
* const reached: string[] = [];
|
|
1435
|
+
* app.anim.onMark((animation, name) => reached.push(`${animation}:${name}`));
|
|
1436
|
+
* app.anim.play(ping, {});
|
|
1437
|
+
* app.time.step(100); // reached: ["fx.ping:done"]
|
|
1438
|
+
* ```
|
|
1439
|
+
*/
|
|
1440
|
+
onMark(fn: MarkListener): () => void;
|
|
1441
|
+
/**
|
|
1442
|
+
* Swaps a registered animation for a new definition of the same id. The dev hot swap of `ui`
|
|
1443
|
+
* calls it when a saved `animations.ts` exports one. The next `play` effect of a node builds
|
|
1444
|
+
* the new definition; a timeline that runs now keeps the tree it was built with.
|
|
1445
|
+
*
|
|
1446
|
+
* @param definition - The new definition; its id names the animation it replaces.
|
|
1447
|
+
* @throws {Error} When no feature registered an animation with that id.
|
|
1448
|
+
* @example
|
|
1449
|
+
* ```ts
|
|
1450
|
+
* // The ui hot swap: a save of `board/animations.ts` brings a bigger merge burst.
|
|
1451
|
+
* const mergeBurst = defineAnimation("board.mergeBurst", { slots: { cell: type<Target>() },
|
|
1452
|
+
* build: ({ cell }) => tween(cell, Transform, { scale: 1.4 }, { ms: 300 }) });
|
|
1453
|
+
* ctx.require(animPlugin).replace(mergeBurst);
|
|
1454
|
+
* // A node then runs fx(play(mergeBurst, { cell: { projection: "board.items", key: "i3" } })):
|
|
1455
|
+
* // the play effect builds the new tree, and item i3 grows to scale 1.4 in 300 ms.
|
|
1456
|
+
* ```
|
|
1457
|
+
*/
|
|
1458
|
+
replace(definition: AnyAnimationDefinition): void;
|
|
1459
|
+
};
|
|
1460
|
+
/**
|
|
1461
|
+
* What a system may do with anim, read with `res(AnimPlayer)`: play. A system that needs more
|
|
1462
|
+
* than play is a plugin. Play on a change, never on every frame: keep the handle in a resource, or
|
|
1463
|
+
* take away the tag that asked for the play.
|
|
1464
|
+
*
|
|
1465
|
+
* @example
|
|
1466
|
+
* ```ts
|
|
1467
|
+
* // A fresh item pops once: the system plays, then takes the Fresh tag away.
|
|
1468
|
+
* const popIn = system({ name: "popIn", phase: "input", query: [Fresh], run: (items, { world, res }) => {
|
|
1469
|
+
* for (const [entity] of items) {
|
|
1470
|
+
* res(AnimPlayer).play(pop, { thing: entity });
|
|
1471
|
+
* world.untag(entity, Fresh);
|
|
1472
|
+
* }
|
|
1473
|
+
* } });
|
|
1474
|
+
* ```
|
|
1475
|
+
*/
|
|
1476
|
+
type AnimPlayerValue = {
|
|
1477
|
+
/**
|
|
1478
|
+
* Plays an animation from a system, the way `app.anim.play` does. The registered animation of
|
|
1479
|
+
* `animation.id` wins when a feature brought one, so a hot swap reaches the system. Played from
|
|
1480
|
+
* phase `input`, the tree moves in `animate` of the same frame; from a later phase it moves
|
|
1481
|
+
* from the next frame.
|
|
1482
|
+
*
|
|
1483
|
+
* @param animation - What `defineAnimation` returned.
|
|
1484
|
+
* @param slots - One target, or a list of targets, per declared slot.
|
|
1485
|
+
* @returns The handle: `cancel()`, `finish()`, `active()`, `done`, `marks()`.
|
|
1486
|
+
* @throws {Error} Before `anim` started: `[game] AnimPlayer is not ready: anim has not started.`
|
|
1487
|
+
* @example
|
|
1488
|
+
* ```ts
|
|
1489
|
+
* const lift = defineAnimation("look.hover", { slots: { thing: type<Target>() },
|
|
1490
|
+
* build: ({ thing }) => tween(thing, Transform, { scale: 1.1 }, { ms: 100 }) });
|
|
1491
|
+
* // Inside a system of phase "input": entity 1048576 is the item under the pointer.
|
|
1492
|
+
* const handle = res(AnimPlayer).play(lift, { thing: 1_048_576 });
|
|
1493
|
+
* handle.active(); // true until the lift lands 100 ms later, then false
|
|
1494
|
+
* ```
|
|
1495
|
+
*/
|
|
1496
|
+
play<Tags extends SlotTags>(animation: AnimationDefinition<Tags>, slots: SlotValues<Tags>): PlayHandle;
|
|
1497
|
+
};
|
|
1498
|
+
/**
|
|
1499
|
+
* Resolved dependency APIs. `renderer` is not among them: `anim` writes its `Sprite` and reads
|
|
1500
|
+
* its `Transform` through the component objects, which are plain data, composes the root pose
|
|
1501
|
+
* of `at` with the pure `rootPoseOf` of `renderer/sync/pose.ts`, and turns the target of a
|
|
1502
|
+
* `tween` in `space: "root"` local with the pure `localPoseOf` of the same module.
|
|
1503
|
+
*/
|
|
1504
|
+
type Deps$3 = {
|
|
1505
|
+
time: Api$1;
|
|
1506
|
+
flow: Api$2;
|
|
1507
|
+
world: Api$3;
|
|
1508
|
+
};
|
|
1509
|
+
/**
|
|
1510
|
+
* What the kernel context offers before the deps are attached.
|
|
1511
|
+
*
|
|
1512
|
+
* `index.ts` writes `events` with an annotated `register` (core spec `14-EVENT-REGISTRATION.md`
|
|
1513
|
+
* row 8), so the own events reach the context the kernel hands the factories and `emit` is the
|
|
1514
|
+
* kernel's own, anim-typed one. No member of the context is cast.
|
|
1515
|
+
*/
|
|
1516
|
+
type KernelSlice$3 = PluginCtx<Config$4, State$4, Events$1> & {
|
|
1517
|
+
readonly global: object;
|
|
1518
|
+
readonly log: Log.LogApi;
|
|
1519
|
+
readonly require: Require;
|
|
1520
|
+
};
|
|
1521
|
+
/**
|
|
1522
|
+
* Domain context of the anim plugin: the kernel slice and the three resolved dependencies.
|
|
1523
|
+
*/
|
|
1524
|
+
type AnimCtx = KernelSlice$3 & {
|
|
1525
|
+
readonly deps: Deps$3;
|
|
1526
|
+
};
|
|
1527
|
+
//#endregion
|
|
6
1528
|
//#region src/plugins/ui/styles/types.d.ts
|
|
7
1529
|
/**
|
|
8
1530
|
* A length that may also come from the notch. The four tokens are replaced by `resolve` with the
|
|
@@ -405,8 +1927,8 @@ type StylesState = {
|
|
|
405
1927
|
flags: WhenFlags;
|
|
406
1928
|
viewport: Readonly<ViewportSize> | undefined;
|
|
407
1929
|
};
|
|
408
|
-
declare namespace types_d_exports$
|
|
409
|
-
export { Argument, CompiledMessage, CompiledMessages, Config$
|
|
1930
|
+
declare namespace types_d_exports$3 {
|
|
1931
|
+
export { Argument, CompiledMessage, CompiledMessages, Config$3 as Config, DurationStyle, ElementNode, Events, I18nApi, I18nCtx, I18nKit, IntlKit, KeysWithoutParameters, Message, Part, RegisteredModule, ResolvedModule, State$3 as State, StringTable, StringsLoader, TextKey, TypedTr };
|
|
410
1932
|
}
|
|
411
1933
|
/**
|
|
412
1934
|
* One interface element handed to a message as a parameter. Structural on purpose: it mirrors
|
|
@@ -547,7 +2069,7 @@ type StringsLoader = () => Promise<CompiledMessages | {
|
|
|
547
2069
|
* createApp({ pluginConfigs: { i18n: { locale: "ru", fallback: "en", locales: {} } } });
|
|
548
2070
|
* ```
|
|
549
2071
|
*/
|
|
550
|
-
type Config$
|
|
2072
|
+
type Config$3 = {
|
|
551
2073
|
/** The locale at start. */locale: string; /** The locale a missing key is read from before it is reported missing. */
|
|
552
2074
|
fallback: string;
|
|
553
2075
|
/**
|
|
@@ -579,7 +2101,7 @@ type ResolvedModule = {
|
|
|
579
2101
|
/**
|
|
580
2102
|
* i18n plugin state.
|
|
581
2103
|
*/
|
|
582
|
-
type State$
|
|
2104
|
+
type State$3 = {
|
|
583
2105
|
/** The current locale; `config.locale` until `setLocale`. */locale: string;
|
|
584
2106
|
/**
|
|
585
2107
|
* Per locale, one entry per feature and one for the config, filled in `onStart`. Coupled
|
|
@@ -802,7 +2324,7 @@ type I18nApi<Key extends string = string> = {
|
|
|
802
2324
|
* row 8), so the own event reaches the context the kernel hands the factories and `emit` is the
|
|
803
2325
|
* kernel's own, i18n-typed one. No member of the context is cast.
|
|
804
2326
|
*/
|
|
805
|
-
type I18nCtx = PluginCtx<Config$
|
|
2327
|
+
type I18nCtx = PluginCtx<Config$3, State$3, Events> & {
|
|
806
2328
|
readonly global: object;
|
|
807
2329
|
readonly log: Log.LogApi;
|
|
808
2330
|
readonly require: Require; /** Whether a plugin of that name is composed, whatever its place in the list. */
|
|
@@ -888,8 +2410,8 @@ type I18nKit<Table extends StringTable> = {
|
|
|
888
2410
|
*/
|
|
889
2411
|
key: <const Key extends TextKey<Table>>(key: Key) => Key;
|
|
890
2412
|
};
|
|
891
|
-
declare namespace types_d_exports$
|
|
892
|
-
export { Carried, Config$
|
|
2413
|
+
declare namespace types_d_exports$2 {
|
|
2414
|
+
export { Carried, Config$2 as Config, Deps$2 as Deps, Direction, GesturePhase, InputApi, InputCtx, KernelSlice$2 as KernelSlice, KeyInput, KeyListener, LockWindow, Point$1 as Point, PointerListener, RawSample, State$2 as State, TapListener, Target };
|
|
893
2415
|
}
|
|
894
2416
|
/**
|
|
895
2417
|
* A point in reference units, as `renderer.viewport.toReference` answers it.
|
|
@@ -1032,7 +2554,7 @@ type KeyListener = (key: KeyInput) => boolean | void;
|
|
|
1032
2554
|
* createApp({ plugins: [...screen], pluginConfigs: { input: { traceStepPx: 16 } } });
|
|
1033
2555
|
* ```
|
|
1034
2556
|
*/
|
|
1035
|
-
type Config$
|
|
2557
|
+
type Config$2 = {
|
|
1036
2558
|
/** Largest move, in reference px, that still counts as a tap or a long press. */tapSlopPx: number; /** Hold time, in ms of `time`, after which a `Pressable` answers. */
|
|
1037
2559
|
longPressMs: number; /** Move, in reference px, that turns a press on a `Draggable` into a drag. */
|
|
1038
2560
|
dragStartPx: number; /** Shortest swipe, in reference px. */
|
|
@@ -1078,7 +2600,7 @@ type Carried = {
|
|
|
1078
2600
|
/**
|
|
1079
2601
|
* input plugin state: the raw queue the DOM handlers write, and the one gesture in progress.
|
|
1080
2602
|
*/
|
|
1081
|
-
type State$
|
|
2603
|
+
type State$2 = {
|
|
1082
2604
|
/** Written by the DOM handlers, drained by the frame step. */samples: RawSample[];
|
|
1083
2605
|
phase: GesturePhase;
|
|
1084
2606
|
/**
|
|
@@ -1417,18 +2939,18 @@ type InputApi = {
|
|
|
1417
2939
|
/**
|
|
1418
2940
|
* Resolved dependency APIs.
|
|
1419
2941
|
*/
|
|
1420
|
-
type Deps$
|
|
1421
|
-
time: Api;
|
|
1422
|
-
flow: Api$
|
|
1423
|
-
world: Api$
|
|
1424
|
-
renderer: Api$
|
|
2942
|
+
type Deps$2 = {
|
|
2943
|
+
time: Api$1;
|
|
2944
|
+
flow: Api$2;
|
|
2945
|
+
world: Api$3;
|
|
2946
|
+
renderer: Api$4;
|
|
1425
2947
|
};
|
|
1426
2948
|
/**
|
|
1427
2949
|
* What the kernel context offers before the deps are attached.
|
|
1428
2950
|
*
|
|
1429
2951
|
* `input` owns no event, so `emit` is the kernel's and never called here.
|
|
1430
2952
|
*/
|
|
1431
|
-
type KernelSlice$
|
|
2953
|
+
type KernelSlice$2 = PluginCtx<Config$2, State$2> & {
|
|
1432
2954
|
readonly global: object;
|
|
1433
2955
|
readonly log: Log.LogApi;
|
|
1434
2956
|
readonly require: Require;
|
|
@@ -1436,8 +2958,8 @@ type KernelSlice$1 = PluginCtx<Config$1, State$1> & {
|
|
|
1436
2958
|
/**
|
|
1437
2959
|
* Domain context of the input plugin: the kernel slice plus the four resolved dependencies.
|
|
1438
2960
|
*/
|
|
1439
|
-
type InputCtx = KernelSlice$
|
|
1440
|
-
readonly deps: Deps$
|
|
2961
|
+
type InputCtx = KernelSlice$2 & {
|
|
2962
|
+
readonly deps: Deps$2;
|
|
1441
2963
|
};
|
|
1442
2964
|
//#endregion
|
|
1443
2965
|
//#region src/plugins/ui/jsx/component.d.ts
|
|
@@ -1473,8 +2995,8 @@ declare function defineComponent<Properties extends object, Local extends object
|
|
|
1473
2995
|
* ```
|
|
1474
2996
|
*/
|
|
1475
2997
|
declare function defineComponent<Properties extends object, Local extends object>(name: string, spec: ComponentSpec<Properties, Local, never>): ComponentDefinition<Properties, Local, undefined>;
|
|
1476
|
-
declare namespace types_d_exports {
|
|
1477
|
-
export { AdvanceTable, AssetsReplaced, BindField, BindOptions, BundleLoaded, BundleUnloaded, Config, CountdownValue, Deps, DrawCursor, DrawnLabel, FormattedNumber, IconRun, KernelSlice, LayoutOptions, Line, LocaleChanged, Point, Run, SeenText, ShownLayout, Size, State, TextAlign, TextApi, TextBind, TextCtx, TextFormat, TextFormatAnswer, TextFormatFunction, TextFormats, TextLayout, TextRun, TextRunStyle, TextShadow, TextStyle, TextStyleInput, TextStyles, TextValue, TextWrap, Warn };
|
|
2998
|
+
declare namespace types_d_exports$1 {
|
|
2999
|
+
export { AdvanceTable, AssetsReplaced, BindField, BindOptions, BundleLoaded, BundleUnloaded, Config$1 as Config, CountdownValue, Deps$1 as Deps, DrawCursor, DrawnLabel, FormattedNumber, IconRun, KernelSlice$1 as KernelSlice, LayoutOptions, Line, LocaleChanged, Point, Run, SeenText, ShownLayout, Size, State$1 as State, TextAlign, TextApi, TextBind, TextCtx, TextFormat, TextFormatAnswer, TextFormatFunction, TextFormats, TextLayout, TextRun, TextRunStyle, TextShadow, TextStyle, TextStyleInput, TextStyles, TextValue, TextWrap, Warn };
|
|
1478
3000
|
}
|
|
1479
3001
|
/**
|
|
1480
3002
|
* A point in reference units: where a label sits, and which point of the block sits there.
|
|
@@ -2084,7 +3606,7 @@ type SeenText = {
|
|
|
2084
3606
|
* createApp({ pluginConfigs: { text: { fonts: { body: "ui.body", digits: "ui.digits" } } } });
|
|
2085
3607
|
* ```
|
|
2086
3608
|
*/
|
|
2087
|
-
type Config = {
|
|
3609
|
+
type Config$1 = {
|
|
2088
3610
|
/** The two fonts every game ships in its boot bundle. They back the built-in styles. */fonts: {
|
|
2089
3611
|
body: string;
|
|
2090
3612
|
digits: string;
|
|
@@ -2093,7 +3615,7 @@ type Config = {
|
|
|
2093
3615
|
/**
|
|
2094
3616
|
* text plugin state.
|
|
2095
3617
|
*/
|
|
2096
|
-
type State = {
|
|
3618
|
+
type State$1 = {
|
|
2097
3619
|
/** Built-in styles first, then the styles of every feature in feature order. */styles: Map<string, TextStyle>;
|
|
2098
3620
|
/**
|
|
2099
3621
|
* A style that has `boldStyle` to the look of its `<b>` runs: the style with `boldStyle` laid
|
|
@@ -2261,21 +3783,21 @@ type TextApi = {
|
|
|
2261
3783
|
/**
|
|
2262
3784
|
* Resolved dependency APIs.
|
|
2263
3785
|
*/
|
|
2264
|
-
type Deps = {
|
|
2265
|
-
time: Api;
|
|
2266
|
-
flow: Api$
|
|
2267
|
-
world: Api$
|
|
2268
|
-
renderer: Api$
|
|
2269
|
-
assets: Api$
|
|
3786
|
+
type Deps$1 = {
|
|
3787
|
+
time: Api$1;
|
|
3788
|
+
flow: Api$2;
|
|
3789
|
+
world: Api$3;
|
|
3790
|
+
renderer: Api$4;
|
|
3791
|
+
assets: Api$5;
|
|
2270
3792
|
i18n: I18nApi;
|
|
2271
|
-
clock: Api$
|
|
3793
|
+
clock: Api$6;
|
|
2272
3794
|
};
|
|
2273
3795
|
/**
|
|
2274
3796
|
* What the kernel context offers before the deps are attached.
|
|
2275
3797
|
*
|
|
2276
3798
|
* `text` owns no event, so `emit` is the kernel's and never called here.
|
|
2277
3799
|
*/
|
|
2278
|
-
type KernelSlice = PluginCtx<Config, State> & {
|
|
3800
|
+
type KernelSlice$1 = PluginCtx<Config$1, State$1> & {
|
|
2279
3801
|
readonly global: object;
|
|
2280
3802
|
readonly log: Log.LogApi;
|
|
2281
3803
|
readonly require: Require;
|
|
@@ -2285,23 +3807,23 @@ type KernelSlice = PluginCtx<Config, State> & {
|
|
|
2285
3807
|
* layout options every layout and draw is handed, built once with the context: the warning of this
|
|
2286
3808
|
* app, the style table and the bold looks (both kept in place, so the references stand).
|
|
2287
3809
|
*/
|
|
2288
|
-
type TextCtx = KernelSlice & {
|
|
2289
|
-
readonly deps: Deps;
|
|
3810
|
+
type TextCtx = KernelSlice$1 & {
|
|
3811
|
+
readonly deps: Deps$1;
|
|
2290
3812
|
readonly layoutOptions: LayoutOptions;
|
|
2291
3813
|
};
|
|
2292
3814
|
/**
|
|
2293
3815
|
* Payload of the `assets:bundle-loaded` hook: a bundle landed, so a font may be readable now.
|
|
2294
3816
|
*/
|
|
2295
|
-
type BundleLoaded = Events$
|
|
3817
|
+
type BundleLoaded = Events$2["assets:bundle-loaded"];
|
|
2296
3818
|
/**
|
|
2297
3819
|
* Payload of the `assets:bundle-unloaded` hook: `keys` names the assets that left.
|
|
2298
3820
|
*/
|
|
2299
|
-
type BundleUnloaded = Events$
|
|
3821
|
+
type BundleUnloaded = Events$2["assets:bundle-unloaded"];
|
|
2300
3822
|
/**
|
|
2301
3823
|
* Payload of the `assets:replaced` hook: a dev hot swap put new bytes behind `keys`. Each of them
|
|
2302
3824
|
* answers a new font or texture already, and the old pages and textures are destroyed.
|
|
2303
3825
|
*/
|
|
2304
|
-
type AssetsReplaced = Events$
|
|
3826
|
+
type AssetsReplaced = Events$2["assets:replaced"];
|
|
2305
3827
|
/**
|
|
2306
3828
|
* Payload of the `i18n:locale-changed` hook: every message has to be resolved again.
|
|
2307
3829
|
*/
|
|
@@ -3021,6 +4543,26 @@ type Guide = {
|
|
|
3021
4543
|
ended: boolean; /** The frame the guide ended in; -1 while it stands. */
|
|
3022
4544
|
endedAt: number;
|
|
3023
4545
|
};
|
|
4546
|
+
/**
|
|
4547
|
+
* The Yoga-level values last written onto one node, one slot a scalar (an enum, a flex factor, the
|
|
4548
|
+
* aspect ratio) and two a length (its kind, then its number; `NaN` for unset). `apply.ts` owns the
|
|
4549
|
+
* slot order.
|
|
4550
|
+
*/
|
|
4551
|
+
type KeptStyle = Float64Array;
|
|
4552
|
+
/**
|
|
4553
|
+
* What a style write reads for one loaded Yoga module, built once: the module, the enum of every
|
|
4554
|
+
* word a style names, the kept record of a node Yoga just made (its scalars read from a fresh node's
|
|
4555
|
+
* getters, its lengths unset), and the record a write stages its numbers in.
|
|
4556
|
+
*/
|
|
4557
|
+
type StyleTables = {
|
|
4558
|
+
yoga: Yoga;
|
|
4559
|
+
justify: Readonly<Record<NonNullable<ResolvedStyle["justify"]>, Justify>>;
|
|
4560
|
+
align: Readonly<Record<NonNullable<ResolvedStyle["align"]>, Align>>;
|
|
4561
|
+
alignSelf: Readonly<Record<NonNullable<ResolvedStyle["alignSelf"]>, Align>>;
|
|
4562
|
+
overflow: Readonly<Record<NonNullable<ResolvedStyle["overflow"]>, Overflow>>;
|
|
4563
|
+
fresh: KeptStyle; /** The numbers of the write in hand, in the slot order of a kept record; written in place. */
|
|
4564
|
+
staged: KeptStyle;
|
|
4565
|
+
};
|
|
3024
4566
|
/**
|
|
3025
4567
|
* layout module state. `nodes` is attach minus detach: Yoga 3.2.1 has no instance counter.
|
|
3026
4568
|
* `scrolling` is the scroll the finger holds; `scrollClock` the ms the scroll step has run, the
|
|
@@ -3030,7 +4572,9 @@ type Guide = {
|
|
|
3030
4572
|
*/
|
|
3031
4573
|
type LayoutState = {
|
|
3032
4574
|
yoga: Yoga | undefined;
|
|
3033
|
-
byEntity: Map<Entity, Node>;
|
|
4575
|
+
byEntity: Map<Entity, Node>; /** The style tables of the loaded module; none before Yoga loads. */
|
|
4576
|
+
tables: StyleTables | undefined; /** The values last written onto each node, from its creation to its free. */
|
|
4577
|
+
kept: Map<Node, KeptStyle>;
|
|
3034
4578
|
nodes: number;
|
|
3035
4579
|
measured: number;
|
|
3036
4580
|
solves: number;
|
|
@@ -3065,6 +4609,281 @@ type MotionSpan = {
|
|
|
3065
4609
|
ease: Ease | undefined;
|
|
3066
4610
|
reduced: ReducedMotion | undefined;
|
|
3067
4611
|
};
|
|
4612
|
+
declare namespace types_d_exports {
|
|
4613
|
+
export { AnchorTarget, Config, Deps, ElementChange, ElementMotion, Finding, FocusRing, KernelSlice, State, TextInputLook, UiApi, UiCtx, UiNode };
|
|
4614
|
+
}
|
|
4615
|
+
/**
|
|
4616
|
+
* The look of the keyboard focus ring: a dashed ring with a solid halo under it, drawn around the
|
|
4617
|
+
* focused control. Colours are `0xRRGGBB`, lengths reference units.
|
|
4618
|
+
*
|
|
4619
|
+
* @example
|
|
4620
|
+
* ```ts
|
|
4621
|
+
* // A dashed ink ring with a cream halo, 9 u outside the control.
|
|
4622
|
+
* const ring: FocusRing = {
|
|
4623
|
+
* stroke: 0x3a2212, strokeWidth: 4, dash: 10, offset: 9, halo: 0xfff3d6, haloWidth: 12
|
|
4624
|
+
* };
|
|
4625
|
+
* ```
|
|
4626
|
+
*/
|
|
4627
|
+
type FocusRing = {
|
|
4628
|
+
/** The colour of the dashed ring. */stroke: number; /** The stroke width of the dashed ring. */
|
|
4629
|
+
strokeWidth: number; /** The dash length of the ring, with gaps of half a dash; 0 draws it solid. */
|
|
4630
|
+
dash: number; /** How far outside the control's rect the ring runs, on every side. */
|
|
4631
|
+
offset: number; /** The colour of the solid halo drawn under the ring. */
|
|
4632
|
+
halo: number; /** The stroke width of the halo, centred on the same path as the ring. */
|
|
4633
|
+
haloWidth: number;
|
|
4634
|
+
};
|
|
4635
|
+
/**
|
|
4636
|
+
* The look of a text field while it is edited: the caret, the selection box and the IME
|
|
4637
|
+
* underline. Colours are `0xRRGGBB`, lengths reference units, `keyboardMargin` CSS px. The caret
|
|
4638
|
+
* does not blink.
|
|
4639
|
+
*
|
|
4640
|
+
* @example
|
|
4641
|
+
* ```ts
|
|
4642
|
+
* // A thick ink caret, a pale blue selection, the field 16 px above the keyboard.
|
|
4643
|
+
* const look: TextInputLook = {
|
|
4644
|
+
* caretWidth: 3, caret: 0x3a2212, selection: 0x3390ff, selectionAlpha: 0.35,
|
|
4645
|
+
* composingUnderline: 3, keyboardMargin: 16
|
|
4646
|
+
* };
|
|
4647
|
+
* ```
|
|
4648
|
+
*/
|
|
4649
|
+
type TextInputLook = {
|
|
4650
|
+
/** The width of the caret. */caretWidth: number; /** The colour of the caret and of the underline under an IME composing range. */
|
|
4651
|
+
caret: number; /** The colour of the selection box. */
|
|
4652
|
+
selection: number; /** The alpha of the selection box. */
|
|
4653
|
+
selectionAlpha: number; /** The height of the underline under an IME composing range. */
|
|
4654
|
+
composingUnderline: number; /** How far above the keyboard the bottom of the edited field is lifted, in CSS px. */
|
|
4655
|
+
keyboardMargin: number;
|
|
4656
|
+
};
|
|
4657
|
+
/**
|
|
4658
|
+
* ui plugin config.
|
|
4659
|
+
*
|
|
4660
|
+
* @example
|
|
4661
|
+
* ```ts
|
|
4662
|
+
* createApp({ pluginConfigs: { ui: { tapTargetPt: 48, breakpoints: { tall: 2, wide: 1.5 } } } });
|
|
4663
|
+
* // A game with a white focus ring on a dark board.
|
|
4664
|
+
* createApp({
|
|
4665
|
+
* pluginConfigs: {
|
|
4666
|
+
* ui: {
|
|
4667
|
+
* focusRing: {
|
|
4668
|
+
* stroke: 0xffffff, strokeWidth: 4, dash: 10, offset: 9, halo: 0x000000, haloWidth: 12
|
|
4669
|
+
* }
|
|
4670
|
+
* }
|
|
4671
|
+
* }
|
|
4672
|
+
* });
|
|
4673
|
+
* // A game whose text fields have an ink caret.
|
|
4674
|
+
* createApp({
|
|
4675
|
+
* pluginConfigs: {
|
|
4676
|
+
* ui: {
|
|
4677
|
+
* textInput: {
|
|
4678
|
+
* caretWidth: 3, caret: 0x3a2212, selection: 0x3390ff, selectionAlpha: 0.35,
|
|
4679
|
+
* composingUnderline: 3, keyboardMargin: 16
|
|
4680
|
+
* }
|
|
4681
|
+
* }
|
|
4682
|
+
* }
|
|
4683
|
+
* });
|
|
4684
|
+
* ```
|
|
4685
|
+
*/
|
|
4686
|
+
type Config = {
|
|
4687
|
+
/** Smallest tap target `lint()` accepts, in CSS px (points). */tapTargetPt: number; /** `when` flags: `tall` when height / width is at least `tall`, `wide` the other way round. */
|
|
4688
|
+
breakpoints: {
|
|
4689
|
+
tall: number;
|
|
4690
|
+
wide: number;
|
|
4691
|
+
};
|
|
4692
|
+
/**
|
|
4693
|
+
* The ring drawn around the control the keyboard focused. Shallow merge: a game that sets
|
|
4694
|
+
* `focusRing` gives all six fields.
|
|
4695
|
+
*/
|
|
4696
|
+
focusRing: FocusRing;
|
|
4697
|
+
/**
|
|
4698
|
+
* The caret, the selection and the IME underline of a text field. Shallow merge: a game that
|
|
4699
|
+
* sets `textInput` gives all six fields.
|
|
4700
|
+
*/
|
|
4701
|
+
textInput: TextInputLook;
|
|
4702
|
+
};
|
|
4703
|
+
/**
|
|
4704
|
+
* ui plugin state: one branch per module.
|
|
4705
|
+
*/
|
|
4706
|
+
type State = {
|
|
4707
|
+
jsx: JsxState;
|
|
4708
|
+
styles: StylesState;
|
|
4709
|
+
layout: LayoutState;
|
|
4710
|
+
};
|
|
4711
|
+
/**
|
|
4712
|
+
* Resolved dependency APIs. `anim` is here for the dev hot swap, which replaces animations; the
|
|
4713
|
+
* motions of `ui` reach `anim` through the tween driver behind every `ViewHandle`.
|
|
4714
|
+
*/
|
|
4715
|
+
type Deps = {
|
|
4716
|
+
anim: AnimApi;
|
|
4717
|
+
debug: Api;
|
|
4718
|
+
time: Api$1;
|
|
4719
|
+
flow: Api$2;
|
|
4720
|
+
world: Api$3;
|
|
4721
|
+
renderer: Api$4;
|
|
4722
|
+
input: InputApi;
|
|
4723
|
+
i18n: I18nApi;
|
|
4724
|
+
text: TextApi;
|
|
4725
|
+
};
|
|
4726
|
+
/**
|
|
4727
|
+
* What the kernel context offers before the deps are attached.
|
|
4728
|
+
*
|
|
4729
|
+
* `ui` owns no event of its own; `emit` sends the global `ui:hot-swap` of the dev hot swap.
|
|
4730
|
+
*/
|
|
4731
|
+
type KernelSlice = PluginCtx<Config, State, Events$3> & {
|
|
4732
|
+
readonly global: object;
|
|
4733
|
+
readonly log: Log.LogApi;
|
|
4734
|
+
readonly require: Require;
|
|
4735
|
+
};
|
|
4736
|
+
/**
|
|
4737
|
+
* Domain context shared by the three modules: the kernel slice plus the resolved deps.
|
|
4738
|
+
*/
|
|
4739
|
+
type UiCtx = KernelSlice & {
|
|
4740
|
+
readonly deps: Deps;
|
|
4741
|
+
};
|
|
4742
|
+
/**
|
|
4743
|
+
* ui plugin API, `app.ui`. The screen is one more projection, so three members read it the way a
|
|
4744
|
+
* test reads the board: a snapshot, a key lookup and a list of findings; the fourth types into a
|
|
4745
|
+
* text field, the fifth scrolls a `scroll`, the sixth measures where a view or an element is drawn.
|
|
4746
|
+
*
|
|
4747
|
+
* @example
|
|
4748
|
+
* ```ts
|
|
4749
|
+
* // A headless scenario taps the claim button of the reward popup.
|
|
4750
|
+
* app.ui.tree().type; // "row", the root element of the HUD
|
|
4751
|
+
* app.input.tap(app.ui.find("claim") ?? 0);
|
|
4752
|
+
* app.ui.lint(); // []
|
|
4753
|
+
* ```
|
|
4754
|
+
*/
|
|
4755
|
+
type UiApi = {
|
|
4756
|
+
/**
|
|
4757
|
+
* The live screen as plain data: every root in layer order, every element in child order, with
|
|
4758
|
+
* its rect in root coordinates, its resolved style and its seven state flags. A rect is natural:
|
|
4759
|
+
* under a `fit: "contain"` element it is the rect before that scale, and the fitted element
|
|
4760
|
+
* adds `fitScale`. A windowed scroll adds `window`, and its content lists the live rows only.
|
|
4761
|
+
* Works headless.
|
|
4762
|
+
*
|
|
4763
|
+
* @returns The root node; several roots come back under one `screen` node.
|
|
4764
|
+
* @example
|
|
4765
|
+
* ```ts
|
|
4766
|
+
* // On an iPhone SE the 970 u board is drawn smaller to fit the slot between the bars.
|
|
4767
|
+
* const screen = app.ui.tree();
|
|
4768
|
+
* screen.children.map(child => child.key); // ["fitTop", "slot", "fitBottom"]
|
|
4769
|
+
* const board = screen.children[1]?.children[0];
|
|
4770
|
+
* board?.rect.w; // 970, the natural width
|
|
4771
|
+
* board?.fitScale; // 0.805, the 781 u the slot leaves over 970 u
|
|
4772
|
+
* ```
|
|
4773
|
+
*/
|
|
4774
|
+
tree(): UiNode;
|
|
4775
|
+
/**
|
|
4776
|
+
* The entity of a keyed element, so a test can tap it and `anim` can aim at it. Popup roots
|
|
4777
|
+
* come first, then the projection roots in layer order.
|
|
4778
|
+
*
|
|
4779
|
+
* @param key - The `key` prop of the element.
|
|
4780
|
+
* @returns The entity, or `undefined` for an unknown or exiting element.
|
|
4781
|
+
* @example
|
|
4782
|
+
* ```ts
|
|
4783
|
+
* // A headless scenario answers the gate through the button of the popup.
|
|
4784
|
+
* app.input.tap(app.ui.find("claim") ?? 0); // true
|
|
4785
|
+
* app.ui.find("nothing"); // undefined
|
|
4786
|
+
* ```
|
|
4787
|
+
*/
|
|
4788
|
+
find(key: string): Entity | undefined;
|
|
4789
|
+
/**
|
|
4790
|
+
* Reads the live screen against the six rules: a tap target under `tapTargetPt` at the size
|
|
4791
|
+
* it is drawn (a `fit: "contain"` on it or above it shrinks it), a text that does not fit its
|
|
4792
|
+
* box in some registered locale, an absolute element with no `reason`, a clipping element
|
|
4793
|
+
* (`scroll`, `overflow: "hidden"`) whose style names a nine-slice it never draws, a style that
|
|
4794
|
+
* is `hollow` with no nine-slice to hollow, and a root element whose style sets a `zIndex` it
|
|
4795
|
+
* ignores. Never throws; empty when nothing is mounted.
|
|
4796
|
+
*
|
|
4797
|
+
* @returns One finding per rule and element.
|
|
4798
|
+
* @example
|
|
4799
|
+
* ```ts
|
|
4800
|
+
* // A game test keeps the board honest on an iPhone SE: a 140 u cell in the 0.8 slot.
|
|
4801
|
+
* app.ui.lint(); // [{ rule: "tap-target", key: "cell", detail: "39 x 39 pt" }]
|
|
4802
|
+
* // A list styled with a nine-slice: the clip keeps it from drawing.
|
|
4803
|
+
* app.ui.lint(); // [{ rule: "nine-slice-clipped", key: "orders", detail: "scroll" }]
|
|
4804
|
+
* // A frame made hollow before its nine-slice was named: there is no rim to draw.
|
|
4805
|
+
* app.ui.lint(); // [{ rule: "hollow-without-nine-slice", key: "memFrost", detail: "stack" }]
|
|
4806
|
+
* // A screen root that asks to be drawn over the others: the layer decides that.
|
|
4807
|
+
* app.ui.lint(); // [{ rule: "z-index-on-root", key: "board", detail: "zIndex 2" }]
|
|
4808
|
+
* ```
|
|
4809
|
+
*/
|
|
4810
|
+
lint(): readonly Finding[];
|
|
4811
|
+
/**
|
|
4812
|
+
* Types into a text field the way a player does, for a headless test or an agent: the field
|
|
4813
|
+
* becomes the one being edited, `value` cut to its `maxLength` is written into it, and the
|
|
4814
|
+
* local field it names is written, so the component re-renders on the next frame. Nothing
|
|
4815
|
+
* reaches the gate: Enter submits.
|
|
4816
|
+
*
|
|
4817
|
+
* @param key - The `key` prop of the `input` element.
|
|
4818
|
+
* @param value - The text to type.
|
|
4819
|
+
* @returns True when the field took the text; false with one warning when no live `input` has
|
|
4820
|
+
* the key.
|
|
4821
|
+
* @example
|
|
4822
|
+
* ```ts
|
|
4823
|
+
* // A headless test renames the player through the Rename popup.
|
|
4824
|
+
* app.ui.fill("nameField", "Alex"); // true
|
|
4825
|
+
* app.time.step(16);
|
|
4826
|
+
* app.input.pressKey("Enter"); // true: the gate took { intent: "save", payload: { name: "Alex" } }
|
|
4827
|
+
* app.ui.fill("nothing", "Alex"); // false, with the warning "ui:fill-without-input"
|
|
4828
|
+
* ```
|
|
4829
|
+
*/
|
|
4830
|
+
fill(key: string, value: string): boolean;
|
|
4831
|
+
/**
|
|
4832
|
+
* Scrolls a `scroll` element to an offset from its start, at once: the offset is kept inside 0
|
|
4833
|
+
* to `max`, a fling or a glide stops, and `ScrollState` reads the new offset with
|
|
4834
|
+
* `moving: false`. A finger that holds the scroll goes on from there. Works headless, for a
|
|
4835
|
+
* test, an agent or a visual test (the `game.scroll` command, the step `{ scroll: { key, to } }`).
|
|
4836
|
+
*
|
|
4837
|
+
* @param key - The `key` prop of the `scroll` element.
|
|
4838
|
+
* @param to - How far from the start, in reference units. `NaN` leaves the scroll where it is.
|
|
4839
|
+
* @returns True when a live scroll took it. False in two cases, each with one warning `{ key }`:
|
|
4840
|
+
* `ui:scroll-without-scroll` when no live `scroll` has the key, and `ui:scroll-before-solve`
|
|
4841
|
+
* when the `scroll` came in this frame and its first solve has not placed it yet: call it
|
|
4842
|
+
* again after the frame.
|
|
4843
|
+
* @example
|
|
4844
|
+
* ```ts
|
|
4845
|
+
* // A test shows the order strip on its events: the strip is 306 u over a 696 u track.
|
|
4846
|
+
* app.ui.scroll("strip", 0); // true
|
|
4847
|
+
* app.world.ecs.get(app.ui.find("strip") ?? 0, ScrollState); // { offset: 0, max: 390, moving: false }
|
|
4848
|
+
* app.ui.scroll("strip", 999); // true: it stands on the end, offset 390
|
|
4849
|
+
* app.ui.scroll("nothing", 0); // false, with the warning "ui:scroll-without-scroll"
|
|
4850
|
+
* ```
|
|
4851
|
+
*/
|
|
4852
|
+
scroll(key: string, to: number): boolean;
|
|
4853
|
+
/**
|
|
4854
|
+
* Where a target is drawn, in screen reference units: the rect an `<anchor>` sits on. A ui
|
|
4855
|
+
* element's layout box, a nine-slice's panel, a shape's rectangle or a sprite's box, through its
|
|
4856
|
+
* root pose, so a fit, a slot, a scroll's offset and the motion of an ancestor move it; the
|
|
4857
|
+
* rotation is left out. A list gives the bounding rect of its shown targets. A target of no area
|
|
4858
|
+
* (an empty element, a width or a height of 0) answers its point, `{ x, y, w: 0, h: 0 }`. Not
|
|
4859
|
+
* shown: the key names no entity, or one leaving, built aside or drawn at alpha 0 (an image laid
|
|
4860
|
+
* out at no size is drawn at alpha 0), or a world sprite of no width or height, which the
|
|
4861
|
+
* renderer draws at its texture's size. Works in every build and headless; every call answers a
|
|
4862
|
+
* new object.
|
|
4863
|
+
*
|
|
4864
|
+
* @param target - A view or an element by projection and key, or a list of them.
|
|
4865
|
+
* @returns The rect, or `undefined` when no target is shown.
|
|
4866
|
+
* @example
|
|
4867
|
+
* ```ts
|
|
4868
|
+
* // The tutorial puts its hint beside the first seat of the board's order strip.
|
|
4869
|
+
* app.ui.rectOf({ projection: "board.strip", key: "seat0" }); // { x: 40, y: 1500, w: 116, h: 120 }
|
|
4870
|
+
* // The seat and the cell of the board fitted to 0.5: the rect around both.
|
|
4871
|
+
* app.ui.rectOf([
|
|
4872
|
+
* { projection: "board.strip", key: "seat0" },
|
|
4873
|
+
* { projection: "board.strip", key: "cell" }
|
|
4874
|
+
* ]); // { x: 40, y: 250, w: 680, h: 1370 }
|
|
4875
|
+
* app.ui.rectOf({ projection: "board.strip", key: "nowhere" }); // undefined
|
|
4876
|
+
* // An empty element of no area, the spot a card lands on: its point.
|
|
4877
|
+
* app.ui.rectOf({ projection: "point.board", key: "dot" }); // { x: 300, y: 400, w: 0, h: 0 }
|
|
4878
|
+
* ```
|
|
4879
|
+
*/
|
|
4880
|
+
rectOf(target: AnchorTarget | readonly AnchorTarget[]): Readonly<{
|
|
4881
|
+
x: number;
|
|
4882
|
+
y: number;
|
|
4883
|
+
w: number;
|
|
4884
|
+
h: number;
|
|
4885
|
+
}> | undefined;
|
|
4886
|
+
};
|
|
3068
4887
|
//#endregion
|
|
3069
4888
|
//#region src/plugins/ui/jsx/types.d.ts
|
|
3070
4889
|
/**
|
|
@@ -3579,6 +5398,27 @@ type TextState = {
|
|
|
3579
5398
|
watching: (() => void) | undefined;
|
|
3580
5399
|
cleanups: Array<() => void>;
|
|
3581
5400
|
};
|
|
5401
|
+
/**
|
|
5402
|
+
* The walks of the hosting step over `hosts` and `hosted`, a callback each made once per jsx state
|
|
5403
|
+
* (F230 U3), and the fields the walk under way reads and answers: the context of the step, the
|
|
5404
|
+
* projection whose owner is looked for and the owner found.
|
|
5405
|
+
*/
|
|
5406
|
+
type HostWalk = {
|
|
5407
|
+
ctx: UiCtx | undefined;
|
|
5408
|
+
name: string;
|
|
5409
|
+
owner: Entity | undefined; /** Notes the first live host that names `name` in `owner`. */
|
|
5410
|
+
owners: (host: Entity) => void; /** Hosts the views of one live host. */
|
|
5411
|
+
hosting: (host: Entity) => void; /** Takes the parent back from one hosted view its host no longer holds. */
|
|
5412
|
+
releasing: (host: Entity, view: Entity) => void;
|
|
5413
|
+
};
|
|
5414
|
+
/**
|
|
5415
|
+
* The walk of the popup step over `roots`, a callback made once per jsx state (F230 U3), and
|
|
5416
|
+
* whether the walk under way found a root that waits.
|
|
5417
|
+
*/
|
|
5418
|
+
type PopupWalk = {
|
|
5419
|
+
found: boolean; /** Notes a root that waits for the settle step. */
|
|
5420
|
+
waiting: (root: Root) => void;
|
|
5421
|
+
};
|
|
3582
5422
|
/**
|
|
3583
5423
|
* jsx module state. `hosts` holds the elements with a `hosts` prop; `hosted` maps a world view to
|
|
3584
5424
|
* the element that hosts it; `fields` holds the text fields by entity. `hints` buffers the hints
|
|
@@ -3600,7 +5440,9 @@ type JsxState = {
|
|
|
3600
5440
|
leading: Set<Entity>;
|
|
3601
5441
|
removing: Set<Entity>;
|
|
3602
5442
|
hosts: Set<Entity>;
|
|
3603
|
-
hosted: Map<Entity, Entity>;
|
|
5443
|
+
hosted: Map<Entity, Entity>; /** The walks of the hosting step, made at their first use. */
|
|
5444
|
+
hostWalk?: HostWalk; /** The walk of the popup step, made at its first use. */
|
|
5445
|
+
popupWalk?: PopupWalk;
|
|
3604
5446
|
hostsVersion: number;
|
|
3605
5447
|
hostsSeen: number;
|
|
3606
5448
|
membershipSeen: number; /** The host elements that became live in this solve: the solve hosts their views in the same frame (spec 16 U2). */
|
|
@@ -3866,4 +5708,4 @@ type CommonProps = {
|
|
|
3866
5708
|
components?: ElementComponents;
|
|
3867
5709
|
};
|
|
3868
5710
|
//#endregion
|
|
3869
|
-
export {
|
|
5711
|
+
export { Style as $, TextRunStyle as A, use as At, Argument as B, State$1 as C, set as Ct, TextFormatAnswer as D, stagger as Dt, TextFormat as E, spawned as Et, defineComponent as F, Part as G, I18nApi as H, Config$2 as I, TextKey as J, State$3 as K, InputApi as L, TextStyles as M, OverlayApi as Mt, TextValue as N, types_d_exports$5 as Nt, TextFormatFunction as O, stopSfx as Ot, types_d_exports$1 as P, ResolvedStyle as Q, State$2 as R, Point as S, sequence as St, TextBind as T, spawn as Tt, IntlKit as U, Config$3 as V, Message as W, types_d_exports$3 as X, TypedTr as Y, IsFlags as Z, BindField as _, frames as _t, Config as a, FramesValue as at, CountdownValue as b, parallel as bt, types_d_exports as c, Target$1 as ct, LocalWrite as d, HapticKind as dt, TextTagStyle as et, ScrollState as f, SfxDescriptor as ft, UiIntrinsicElements as g, external as gt, IntrinsicElementsFor as h, defineAnimation as ht, UiNode as i, Config$4 as it, TextStyleInput as j, wait as jt, TextFormats as k, tween as kt, Box as l, TimelinesSnapshot as lt, defineTokens as m, HAPTIC_KINDS as mt, JsxChild as n, AnimApi as nt, State as o, MotionKeyframe as ot, popup as p, Step as pt, StringTable as q, PopupComponent as r, AnimPlayerValue as rt, UiApi as s, State$4 as st, DescriptionNode as t, WhenFlags as tt, DebugTrigger as u, types_d_exports$4 as ut, BindOptions as v, haptic as vt, TextApi as w, sfx as wt, FormattedNumber as x, play as xt, Config$1 as y, mark as yt, types_d_exports$2 as z };
|