@msb235/blits 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +136 -0
- package/README.md +31 -7
- package/dist/bare.js +7 -1
- package/dist/book.d.ts +7 -0
- package/dist/book.js +35 -4
- package/dist/chain.d.ts +2 -1
- package/dist/chain.js +7 -3
- package/dist/channels.d.ts +12 -19
- package/dist/channels.js +18 -118
- package/dist/clock.d.ts +9 -2
- package/dist/clock.js +10 -2
- package/dist/closed.d.ts +15 -0
- package/dist/closed.js +144 -0
- package/dist/color.d.ts +61 -0
- package/dist/color.js +229 -0
- package/dist/columns.js +2 -1
- package/dist/crowd.d.ts +1 -1
- package/dist/crowd.js +4 -1
- package/dist/cue.d.ts +2 -0
- package/dist/cue.js +78 -27
- package/dist/due.js +3 -0
- package/dist/fade.d.ts +13 -0
- package/dist/fade.js +55 -4
- package/dist/fill.d.ts +1 -1
- package/dist/fill.js +15 -8
- package/dist/fit.d.ts +144 -0
- package/dist/fit.js +181 -0
- package/dist/fold.d.ts +3 -3
- package/dist/fold.js +18 -11
- package/dist/gather.d.ts +6 -0
- package/dist/gather.js +18 -0
- package/dist/handle.d.ts +27 -2
- package/dist/handle.js +60 -11
- package/dist/held.js +4 -0
- package/dist/history.d.ts +15 -2
- package/dist/history.js +54 -9
- package/dist/hosts.d.ts +2 -2
- package/dist/hosts.js +18 -5
- package/dist/index.d.ts +8 -2
- package/dist/index.js +5 -1
- package/dist/lane.d.ts +1 -1
- package/dist/lanes.d.ts +32 -9
- package/dist/lanes.js +53 -24
- package/dist/locus.d.ts +3 -3
- package/dist/locus.js +1 -1
- package/dist/marks.d.ts +3 -0
- package/dist/marks.js +80 -12
- package/dist/meet.d.ts +3 -2
- package/dist/meet.js +15 -3
- package/dist/mixer.d.ts +52 -36
- package/dist/mixer.js +148 -86
- package/dist/motion.d.ts +2 -199
- package/dist/motion.js +2 -652
- package/dist/motions.d.ts +266 -0
- package/dist/motions.js +724 -0
- package/dist/move.d.ts +1 -1
- package/dist/move.js +23 -7
- package/dist/owner.d.ts +1 -1
- package/dist/owner.js +3 -3
- package/dist/pace.d.ts +2 -0
- package/dist/pace.js +8 -0
- package/dist/pack.d.ts +31 -0
- package/dist/pack.js +65 -0
- package/dist/paging.d.ts +63 -0
- package/dist/paging.js +110 -0
- package/dist/patch.d.ts +3 -0
- package/dist/patch.js +2 -0
- package/dist/place.js +74 -25
- package/dist/project.d.ts +7 -4
- package/dist/project.js +117 -78
- package/dist/pull.js +4 -3
- package/dist/qualify.js +4 -2
- package/dist/revive.d.ts +58 -0
- package/dist/revive.js +158 -0
- package/dist/sample.d.ts +1 -1
- package/dist/sample.js +6 -1
- package/dist/seek.d.ts +3 -0
- package/dist/seek.js +311 -0
- package/dist/spans.d.ts +29 -0
- package/dist/spans.js +165 -0
- package/dist/strays.d.ts +1 -1
- package/dist/strays.js +21 -0
- package/dist/tape.d.ts +21 -0
- package/dist/tape.js +65 -0
- package/dist/ticker.d.ts +28 -3
- package/dist/ticker.js +3 -0
- package/dist/transport.d.ts +121 -0
- package/dist/transport.js +271 -0
- package/dist/types.d.ts +404 -38
- package/dist/unpage.d.ts +8 -0
- package/dist/unpage.js +163 -0
- package/dist/voice.d.ts +73 -7
- package/dist/voice.js +116 -4
- package/dist/weigh.js +2 -2
- package/docs/schema.html +120 -31
- package/package.json +2 -1
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import type { Curve } from './easing.js';
|
|
2
|
+
import type { MotionSpec } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* One closed-form stretch: released at `at` (voice ms) from `x0` moving at `v0`, toward `to`, over
|
|
5
|
+
* `ms` for a tween (0 for any other shape).
|
|
6
|
+
*/
|
|
7
|
+
export interface Segment {
|
|
8
|
+
at: number;
|
|
9
|
+
ms: number;
|
|
10
|
+
x0: number[];
|
|
11
|
+
v0: number[];
|
|
12
|
+
to: number[];
|
|
13
|
+
/** The change that released it; undefined for a subject's first stretch. */
|
|
14
|
+
change?: Change;
|
|
15
|
+
}
|
|
16
|
+
export interface Change {
|
|
17
|
+
/**
|
|
18
|
+
* Voice ms it takes effect at; absent, until the subject's next read stamps it with that read's
|
|
19
|
+
* time, for one made while no frame had met the subject.
|
|
20
|
+
*/
|
|
21
|
+
at?: number;
|
|
22
|
+
to?: number[];
|
|
23
|
+
v?: number[];
|
|
24
|
+
/** The mix clock when it was made, NaN where no mix was playing the patch. */
|
|
25
|
+
made?: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The mix playing a patch, asked with its voice's id: an owner and an id, where a pair of closures
|
|
29
|
+
* cost two functions, their contexts and a weak reference per voice.
|
|
30
|
+
*/
|
|
31
|
+
export interface MotionOwner {
|
|
32
|
+
/** The subject's voice time at the mix's latest frame; NaN where no frame of the voice met it. */
|
|
33
|
+
frame(id: number, subject: unknown): number;
|
|
34
|
+
/** Brings a subject the voice faded out back to it, so a change is not made for nothing. */
|
|
35
|
+
revive(id: number, subject: unknown): void;
|
|
36
|
+
/** The mix clock at its latest frame; NaN before the first. */
|
|
37
|
+
now(): number;
|
|
38
|
+
/**
|
|
39
|
+
* The host made a change, already given its time, which a seek makes again on the patch its
|
|
40
|
+
* voice plays then: a voice a history store paged out comes back with a patch of its own.
|
|
41
|
+
*/
|
|
42
|
+
changed<I>(id: number, motion: Motions<I>, subject: I, change: Change): void;
|
|
43
|
+
/** History leaving memory for a subject, which a mix with a history store pages out. */
|
|
44
|
+
page(id: number, stream: 'released' | 'stretch', subject: unknown, out: Paging[]): void;
|
|
45
|
+
}
|
|
46
|
+
/** A record of a motion patch's history leaving memory, at a mix time. */
|
|
47
|
+
export interface Paging {
|
|
48
|
+
at: number;
|
|
49
|
+
data: unknown;
|
|
50
|
+
}
|
|
51
|
+
/** A subject's run as plain data: its flags, its stretches oldest first, and changes still to apply. */
|
|
52
|
+
export interface Run {
|
|
53
|
+
flags: number;
|
|
54
|
+
stretches: Segment[];
|
|
55
|
+
pending: Change[] | undefined;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* What a mix keeping copies of a patch's stretches is told, with its id and the subject's number,
|
|
59
|
+
* before one changes.
|
|
60
|
+
*/
|
|
61
|
+
export interface Watcher {
|
|
62
|
+
stretchChanged(id: number, s: number): void;
|
|
63
|
+
}
|
|
64
|
+
export interface Shape<I> {
|
|
65
|
+
from: (subject: I) => number[];
|
|
66
|
+
/** How fast each axis starts moving, given where it starts: still unless the options say. */
|
|
67
|
+
velocity: (subject: I, x: number[]) => number[];
|
|
68
|
+
/** Where it heads when released from `x` at `v`, given where it was heading. */
|
|
69
|
+
aim: (x: number[], v: number[], was: number[] | null, subject: I) => number[];
|
|
70
|
+
/** `[form, settle, k1, k2, k3]`. */
|
|
71
|
+
law: readonly number[];
|
|
72
|
+
/** Whether a subject's value is a number rather than an array. */
|
|
73
|
+
scalar: (subject: I) => boolean;
|
|
74
|
+
/** Whether every subject's value is a number; undefined where that depends on the subject. */
|
|
75
|
+
scalarEvery(): boolean | undefined;
|
|
76
|
+
/** A tween's easing, which its law cannot hold; undefined, but present, on every other shape. */
|
|
77
|
+
ease: Curve | undefined;
|
|
78
|
+
/** A tween's seconds for a stretch the subject starts now; undefined, but present, on the rest. */
|
|
79
|
+
ms: ((subject: I) => number) | undefined;
|
|
80
|
+
/** The patch's kind and constants, as `Patch.motion` reports them. */
|
|
81
|
+
spec(): MotionSpec;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A motion patch's subjects: the stretch each is playing, in one flat array by a number the patch
|
|
85
|
+
* gives it, with earlier stretches a read back may reach and changes not yet applied beside them.
|
|
86
|
+
* The one copy, read by `at` and by a mix's lane alike.
|
|
87
|
+
*
|
|
88
|
+
* After the law, each subject's run of `stride` numbers is its release time, its flags, a tween's
|
|
89
|
+
* seconds for the stretch, then `x0`, `v0` and `to` per axis. A live sample reads this one buffer and nothing else the patch owns: at
|
|
90
|
+
* 10k springs of one subject each, a buffer per field, a map lookup per sample and the law in an
|
|
91
|
+
* object of its own took a call from 130 ns to 490.
|
|
92
|
+
*/
|
|
93
|
+
export declare class Motions<I> {
|
|
94
|
+
private readonly shape;
|
|
95
|
+
private readonly numbers;
|
|
96
|
+
/** Numbers by subject once a second is numbered: till then the one subject is found by `numbers`. */
|
|
97
|
+
private readonly slots;
|
|
98
|
+
/** Axes per subject; -1 until the first subject sets it. */
|
|
99
|
+
n: number;
|
|
100
|
+
private cap;
|
|
101
|
+
private stride;
|
|
102
|
+
/**
|
|
103
|
+
* The law, then each subject's run; empty until the first subject, the law read from `shape`.
|
|
104
|
+
* Read outside, at `bareAt`, and written only here.
|
|
105
|
+
*/
|
|
106
|
+
runs: Float64Array<ArrayBuffer>;
|
|
107
|
+
/**
|
|
108
|
+
* Where `sample` leaves a subject's position and velocity, per axis. Shared by every patch, so
|
|
109
|
+
* read it before the next sample.
|
|
110
|
+
*/
|
|
111
|
+
xs: Float64Array<ArrayBuffer>;
|
|
112
|
+
vs: Float64Array<ArrayBuffer>;
|
|
113
|
+
/**
|
|
114
|
+
* By subject number, changes not yet applied and earlier stretches a read back may reach: null
|
|
115
|
+
* until a subject first has one, since many patches are never changed. Each starts with room for
|
|
116
|
+
* one: an empty array written at 0 reserves 17, and most patches have one subject.
|
|
117
|
+
*/
|
|
118
|
+
private pending;
|
|
119
|
+
private older;
|
|
120
|
+
/** By subject number, the change that released the stretch it is playing; null until one has. */
|
|
121
|
+
private causes;
|
|
122
|
+
/**
|
|
123
|
+
* The mix playing the patch and its voice's id, which an untimed change and a `read` with no time
|
|
124
|
+
* ask for the latest frame. Set by the mix that cues the patch, and cleared when its voice retires.
|
|
125
|
+
*/
|
|
126
|
+
owner: MotionOwner | null;
|
|
127
|
+
ownerId: number;
|
|
128
|
+
/** Whether the channel it was cued on holds a number; undefined until it is cued. */
|
|
129
|
+
private holdsNumber;
|
|
130
|
+
private channel;
|
|
131
|
+
/**
|
|
132
|
+
* Records what the channel the patch is cued on holds, refusing a value of the other kind: at once
|
|
133
|
+
* where every subject's value is one kind, else on the first sample of a subject whose value is not.
|
|
134
|
+
*/
|
|
135
|
+
cuedOn(channel: string, holdsNumber: boolean): void;
|
|
136
|
+
private frame;
|
|
137
|
+
constructor(shape: Shape<I>);
|
|
138
|
+
/** The patch's number for `subject`, made with its first stretch on first ask. */
|
|
139
|
+
slot(subject: I): number;
|
|
140
|
+
/** Sets the axes every subject moves on, at the first. */
|
|
141
|
+
private size;
|
|
142
|
+
/** Numbers `subject`, with room for its run. */
|
|
143
|
+
private take;
|
|
144
|
+
/** The patch's number for `subject`, undefined where it has none. */
|
|
145
|
+
private known;
|
|
146
|
+
/**
|
|
147
|
+
* Subjects released at a mix time a rewind may still reach, with their run as it stood, so a
|
|
148
|
+
* rewind before the release plays them on from there. Empty without history.
|
|
149
|
+
*/
|
|
150
|
+
private released;
|
|
151
|
+
/**
|
|
152
|
+
* Forgets a subject, so a later ask starts it afresh from `from`. Given the mix time `at`, under
|
|
153
|
+
* history, its run is kept for a rewind before then, until `reach` passes it.
|
|
154
|
+
*/
|
|
155
|
+
release(subject: I, at?: number, reach?: number): void;
|
|
156
|
+
/** Puts back each subject released after mix time `t`, as it stood when released. */
|
|
157
|
+
private unrelease;
|
|
158
|
+
/** Subject `s`'s run as it stands. */
|
|
159
|
+
private runAt;
|
|
160
|
+
/** A subject's run as plain data, for a voice leaving memory; undefined where it has none. */
|
|
161
|
+
pack(subject: I): Run | undefined;
|
|
162
|
+
/** Puts a subject's run back as `pack` or a release left it, replacing any it has now. */
|
|
163
|
+
unpack(subject: I, run: Run): void;
|
|
164
|
+
/** A released run a history store gave back, for a rewind to before its release. */
|
|
165
|
+
reclaim(subject: I, at: number, run: Run): void;
|
|
166
|
+
/**
|
|
167
|
+
* Stretches a history store gave back, each by the mix time it was in force by: each life of the
|
|
168
|
+
* subject, ended by a release, takes those from its own, ahead of the earliest it still keeps.
|
|
169
|
+
*/
|
|
170
|
+
restretch(subject: I, back: readonly Paging[]): void;
|
|
171
|
+
/**
|
|
172
|
+
* Told, with `watchId`, whenever a subject's stretch or what is pending for it changes, so a mix
|
|
173
|
+
* keeping a copy of it knows to read it again. Set by the mix, cleared when its voice retires. An
|
|
174
|
+
* owner and an id, where a callback cost a closure and its context per patch.
|
|
175
|
+
*/
|
|
176
|
+
watcher: Watcher | null;
|
|
177
|
+
watchId: number;
|
|
178
|
+
/** The easing a tween's stretches follow; undefined for every other shape. */
|
|
179
|
+
get ease(): Curve | undefined;
|
|
180
|
+
/** The patch's kind and constants. */
|
|
181
|
+
spec(): MotionSpec;
|
|
182
|
+
/** A copy of the patch's law, `[form, settle, k1, k2, k3]`. */
|
|
183
|
+
law(): Float64Array;
|
|
184
|
+
/** Whether `law` holds this patch's law, number for number, as `Object.is` compares them. */
|
|
185
|
+
hasLaw(law: Float64Array): boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Copies subject `s`'s current stretch into `out` from `o` as its release time, its seconds, then
|
|
188
|
+
* `x0`, `v0` and `to` per axis; false, copying nothing, while it has a change pending or an
|
|
189
|
+
* earlier stretch kept, which only `sample` handles.
|
|
190
|
+
*/
|
|
191
|
+
stretchInto(s: number, out: Float64Array, o: number): boolean;
|
|
192
|
+
/** Whether subject `s`'s value is a number rather than an array. */
|
|
193
|
+
scalar(s: number): boolean;
|
|
194
|
+
/** The value `at` hands the mix: the first axis for a number, a fresh array otherwise. */
|
|
195
|
+
value(s: number, xs: Float64Array): number | number[];
|
|
196
|
+
/**
|
|
197
|
+
* Position and velocity at voice time `t` into `xo` and `vo`, a tween's velocity left at 0. A live
|
|
198
|
+
* read stamps every untimed change with `t` and commits every change due by then, in time order;
|
|
199
|
+
* a projection's read applies the timed ones to a copy and commits nothing.
|
|
200
|
+
*/
|
|
201
|
+
sample(s: number, t: number, xo: Float64Array, vo: Float64Array): void;
|
|
202
|
+
/**
|
|
203
|
+
* Where subject `s`'s run starts in `runs` (its release time, then flags, seconds, `x0`, `v0`
|
|
204
|
+
* and `to`) while it has nothing pending and no earlier stretch kept; -1 for any other.
|
|
205
|
+
*/
|
|
206
|
+
bareAt(s: number): number;
|
|
207
|
+
/**
|
|
208
|
+
* A live `sample` at `t` for a subject with nothing pending and no earlier stretch kept, true
|
|
209
|
+
* then; false, writing nothing, for any other, which `quiet` and `sample` take instead.
|
|
210
|
+
*/
|
|
211
|
+
sampleBare(s: number, t: number, xo: Float64Array, vo: Float64Array): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Whether every subject has landed on its target at its voice time at the latest frame, as a
|
|
214
|
+
* sample there would find; one with a change waiting has not. Commits nothing.
|
|
215
|
+
*/
|
|
216
|
+
landed(): boolean;
|
|
217
|
+
/**
|
|
218
|
+
* Whether a live `sample` at `t` would leave the subject's state as it is: nothing to stamp or
|
|
219
|
+
* commit by then, and nothing older than `reading.horizon` to let go of.
|
|
220
|
+
*/
|
|
221
|
+
quiet(s: number, t: number): boolean;
|
|
222
|
+
/** Position and velocity at `at`, default the latest frame; undefined until there is one. */
|
|
223
|
+
read(subject: I, at?: number): {
|
|
224
|
+
x: Float64Array;
|
|
225
|
+
v: Float64Array;
|
|
226
|
+
s: number;
|
|
227
|
+
} | undefined;
|
|
228
|
+
/**
|
|
229
|
+
* Queues a retarget or push, untimed at the latest frame, for `subject`'s next read past its time.
|
|
230
|
+
* The queue keeps the changes with a time in time order, ahead of any still waiting for one.
|
|
231
|
+
*/
|
|
232
|
+
change(subject: I, c: Change): void;
|
|
233
|
+
/** Files a change with a time after every one due by then, ahead of those still waiting for one. */
|
|
234
|
+
private queue;
|
|
235
|
+
/** Every change due by `t` applied to a copy of the stretch playing then, committing nothing. */
|
|
236
|
+
private peek;
|
|
237
|
+
private check;
|
|
238
|
+
private flag;
|
|
239
|
+
forget(s: number): void;
|
|
240
|
+
/**
|
|
241
|
+
* Takes back every change made after mix time `t`: each subject plays from its earliest stretch
|
|
242
|
+
* kept, with the changes made by then queued to be applied again.
|
|
243
|
+
*/
|
|
244
|
+
rewind(t: number): void;
|
|
245
|
+
private cut;
|
|
246
|
+
/** Where subject `s`'s run starts in `runs`. */
|
|
247
|
+
base(s: number): number;
|
|
248
|
+
private grow;
|
|
249
|
+
private write;
|
|
250
|
+
/** The stretch subject `s` is playing now, as an object. */
|
|
251
|
+
private latest;
|
|
252
|
+
/** The stretch playing at voice time `t`: the latest released by then, else the first. */
|
|
253
|
+
private playing;
|
|
254
|
+
private applied;
|
|
255
|
+
private commit;
|
|
256
|
+
private insert;
|
|
257
|
+
/**
|
|
258
|
+
* The mix time a stretch was in force by, which a store keys it under: when the change that
|
|
259
|
+
* ended it was made, which falls in the same life of the subject.
|
|
260
|
+
*/
|
|
261
|
+
private made;
|
|
262
|
+
/** Lets go of stretches older than the one in force at `reading.horizon`. */
|
|
263
|
+
private prune;
|
|
264
|
+
private evaluateSegment;
|
|
265
|
+
private evaluate;
|
|
266
|
+
}
|