expressive-charts 0.2.0 → 0.4.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 +69 -1
- package/README.md +10 -10
- package/dist/define-DeZLs1h7.js +95 -0
- package/dist/define-DeZLs1h7.js.map +1 -0
- package/dist/drawing-Dz_IvJPB.d.cts +208 -0
- package/dist/drawing-Dz_IvJPB.d.ts +208 -0
- package/dist/effect-CdH5449m.d.ts +232 -0
- package/dist/effect-uYC8Vs6_.d.cts +232 -0
- package/dist/expressive-charts.css +8 -1
- package/dist/expressive-charts.css.d.cts +1 -0
- package/dist/expressive-charts.css.d.ts +1 -0
- package/dist/expressive-charts.global.js +50 -47
- package/dist/expressive-charts.global.js.map +1 -1
- package/dist/icons/sport.cjs +211 -152
- package/dist/icons/sport.cjs.map +1 -1
- package/dist/icons/sport.d.cts +5 -7
- package/dist/icons/sport.d.ts +5 -7
- package/dist/icons/sport.js +122 -71
- package/dist/icons/sport.js.map +1 -1
- package/dist/index.cjs +12647 -9513
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +929 -859
- package/dist/index.d.ts +929 -859
- package/dist/index.js +10452 -7822
- package/dist/index.js.map +1 -1
- package/dist/path-data-DnEckjY8.js +123 -0
- package/dist/path-data-DnEckjY8.js.map +1 -0
- package/dist/testing.cjs +2034 -1222
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +137 -141
- package/dist/testing.d.ts +137 -141
- package/dist/testing.js +696 -501
- package/dist/testing.js.map +1 -1
- package/dist/transition-DSRt2DH3.js +2053 -0
- package/dist/transition-DSRt2DH3.js.map +1 -0
- package/package.json +18 -6
- package/dist/chunk-CVXP2L2J.js +0 -1182
- package/dist/chunk-CVXP2L2J.js.map +0 -1
- package/dist/chunk-N5IF2RO2.js +0 -66
- package/dist/chunk-N5IF2RO2.js.map +0 -1
- package/dist/chunk-V5IUTXRW.js +0 -571
- package/dist/chunk-V5IUTXRW.js.map +0 -1
- package/dist/drawing-DWZIXIeR.d.cts +0 -194
- package/dist/drawing-DWZIXIeR.d.ts +0 -194
- package/dist/effect-CZUckY0l.d.ts +0 -245
- package/dist/effect-CcGdU41j.d.cts +0 -245
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import { M as MarkGeometry, e as MarkHandle, L as Layer, d as IconSource } from './drawing-DWZIXIeR.js';
|
|
2
|
-
|
|
3
|
-
/** Where frames come from. The default uses requestAnimationFrame, or a 16 ms timer outside the browser. */
|
|
4
|
-
interface FrameSource {
|
|
5
|
-
now(): number;
|
|
6
|
-
/** Ask for one callback on the next frame. Returns a function that cancels it. */
|
|
7
|
-
request(callback: (now: number) => void): () => void;
|
|
8
|
-
}
|
|
9
|
-
interface Clock {
|
|
10
|
-
now(): number;
|
|
11
|
-
/** Call `callback` on every frame until the returned function is called. */
|
|
12
|
-
onFrame(callback: (now: number) => void): () => void;
|
|
13
|
-
}
|
|
14
|
-
/** A clock that only moves when told to. For tests. */
|
|
15
|
-
interface ManualClock extends Clock {
|
|
16
|
-
/** Move time forward by `ms` and run one frame at the new time. */
|
|
17
|
-
advance(ms: number): void;
|
|
18
|
-
/** True when nothing is waiting for a frame. */
|
|
19
|
-
readonly idle: boolean;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* One shared frame loop. It requests a frame only while something is
|
|
23
|
-
* subscribed, so an idle page costs nothing.
|
|
24
|
-
*/
|
|
25
|
-
declare function createClock(source?: FrameSource): Clock;
|
|
26
|
-
declare function manualClock(start?: number): ManualClock;
|
|
27
|
-
/** The page-wide clock every tween uses unless given another. */
|
|
28
|
-
declare const defaultClock: Clock;
|
|
29
|
-
|
|
30
|
-
/** Maps linear progress (0–1) to eased progress. Any function of this shape works. */
|
|
31
|
-
type Easing = (t: number) => number;
|
|
32
|
-
/** For playback, where speed should stay constant. */
|
|
33
|
-
declare const linear: Easing;
|
|
34
|
-
/** For data transitions: starts and ends gently. */
|
|
35
|
-
declare const easeInOutCubic: Easing;
|
|
36
|
-
/** For travel, and for animations retargeted mid-flight: starts at speed, settles gently. */
|
|
37
|
-
declare const easeOutCubic: Easing;
|
|
38
|
-
|
|
39
|
-
type MotionMode = "presentation" | "analysis" | "off";
|
|
40
|
-
/** What a duration is for. Each kind scales differently by mode. */
|
|
41
|
-
type Timing = "feedback" | "transition" | "effect" | "playback" | "stagger";
|
|
42
|
-
/** Base ms × factor, clamped to [min(base, min), max]. A floor never makes an animation longer than its base. */
|
|
43
|
-
interface ScalingRule {
|
|
44
|
-
readonly factor: number;
|
|
45
|
-
readonly min?: number;
|
|
46
|
-
readonly max?: number;
|
|
47
|
-
}
|
|
48
|
-
type ScaledMode = Exclude<MotionMode, "off">;
|
|
49
|
-
type ScalingTable = {
|
|
50
|
-
readonly [M in ScaledMode]: {
|
|
51
|
-
readonly [T in Timing]: ScalingRule;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
type ScalingOverrides = {
|
|
55
|
-
readonly [M in ScaledMode]?: {
|
|
56
|
-
readonly [T in Timing]?: ScalingRule;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
/** Starting values from the prototype; tuned in the demos. Off is always 0. */
|
|
60
|
-
declare const defaultScaling: ScalingTable;
|
|
61
|
-
/** What charts and effects need from the motion system. */
|
|
62
|
-
interface MotionView {
|
|
63
|
-
/** The effective mode, after the reduced-motion rule. */
|
|
64
|
-
readonly mode: MotionMode;
|
|
65
|
-
/** True only in presentation: split data changes into stages. */
|
|
66
|
-
readonly staged: boolean;
|
|
67
|
-
/** Scale a base duration (ms) for the current mode. 0 means "jump to the end". */
|
|
68
|
-
duration(base: number, timing?: Timing): number;
|
|
69
|
-
}
|
|
70
|
-
interface Motion extends MotionView {
|
|
71
|
-
/** The mode the page author asked for. */
|
|
72
|
-
readonly requested: MotionMode;
|
|
73
|
-
/** The mode the viewer picked in an on-page control, if any. */
|
|
74
|
-
readonly viewerChoice: MotionMode | undefined;
|
|
75
|
-
/** Live value of `prefers-reduced-motion: reduce`. */
|
|
76
|
-
readonly prefersReduced: boolean;
|
|
77
|
-
/** The author's default. Never overrides reduced motion. */
|
|
78
|
-
setMode(mode: MotionMode): void;
|
|
79
|
-
/** The viewer's explicit choice from an on-page control. Overrides reduced motion. */
|
|
80
|
-
chooseMode(mode: MotionMode): void;
|
|
81
|
-
/** Forget the viewer's choice and follow the author's mode and the device setting again. */
|
|
82
|
-
clearChoice(): void;
|
|
83
|
-
/** Called whenever the mode, the viewer's choice or the device setting changes. */
|
|
84
|
-
subscribe(listener: () => void): () => void;
|
|
85
|
-
}
|
|
86
|
-
/** A live reduced-motion preference. */
|
|
87
|
-
interface ReducedMotionSource {
|
|
88
|
-
readonly matches: boolean;
|
|
89
|
-
subscribe(listener: () => void): () => void;
|
|
90
|
-
}
|
|
91
|
-
interface MotionOptions {
|
|
92
|
-
/** The author's mode. Default "presentation". */
|
|
93
|
-
readonly mode?: MotionMode;
|
|
94
|
-
readonly scaling?: ScalingOverrides;
|
|
95
|
-
/** Default: the `prefers-reduced-motion` media query. */
|
|
96
|
-
readonly reducedMotion?: ReducedMotionSource;
|
|
97
|
-
}
|
|
98
|
-
declare function createMotion(options?: MotionOptions): Motion;
|
|
99
|
-
declare function scaleDuration(base: number, rule: ScalingRule): number;
|
|
100
|
-
/** Reads `prefers-reduced-motion` lazily: nothing touches the DOM until `matches` is read or someone subscribes. */
|
|
101
|
-
declare function mediaReducedMotion(query?: string): ReducedMotionSource;
|
|
102
|
-
/** The page-wide motion every chart follows unless given its own. */
|
|
103
|
-
declare const motion: Motion;
|
|
104
|
-
|
|
105
|
-
/** The clock and motion settings an animation runs against. */
|
|
106
|
-
interface MotionEnv {
|
|
107
|
-
readonly clock: Clock;
|
|
108
|
-
readonly motion: MotionView;
|
|
109
|
-
}
|
|
110
|
-
interface TweenOptions {
|
|
111
|
-
/** Base duration in ms, scaled by the motion mode. */
|
|
112
|
-
readonly duration: number;
|
|
113
|
-
/** Default "transition". */
|
|
114
|
-
readonly timing?: Timing;
|
|
115
|
-
/** Default easeInOutCubic. */
|
|
116
|
-
readonly ease?: Easing;
|
|
117
|
-
/** Base delay in ms before progress starts, scaled like the duration. */
|
|
118
|
-
readonly delay?: number;
|
|
119
|
-
/** Called with eased progress: once with ease(0) at the start, then every frame, then with ease(1) at the end. */
|
|
120
|
-
readonly update: (progress: number) => void;
|
|
121
|
-
readonly signal?: AbortSignal;
|
|
122
|
-
}
|
|
123
|
-
type TweenResult = "done" | "cancelled";
|
|
124
|
-
interface Tween {
|
|
125
|
-
/** Resolves when the tween ends. Never rejects. */
|
|
126
|
-
readonly finished: Promise<TweenResult>;
|
|
127
|
-
readonly state: "running" | TweenResult;
|
|
128
|
-
/** Stop where it is. */
|
|
129
|
-
cancel(): void;
|
|
130
|
-
/** Jump to the end now. */
|
|
131
|
-
finish(): void;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Animate progress from 0 to 1. If the motion mode scales the duration to 0,
|
|
135
|
-
* `update(ease(1))` runs synchronously, before `tween` returns. If the mode
|
|
136
|
-
* turns off while the tween runs, it jumps to the end on the next frame.
|
|
137
|
-
*/
|
|
138
|
-
declare function tween(options: TweenOptions, env?: Partial<MotionEnv>): Tween;
|
|
139
|
-
|
|
140
|
-
interface Sample {
|
|
141
|
-
/** Where along the walk, in [0, 1]. */
|
|
142
|
-
readonly t: number;
|
|
143
|
-
readonly value: number;
|
|
144
|
-
/** The x value or label behind the sample (a week, a date). */
|
|
145
|
-
readonly at?: string | number | Date;
|
|
146
|
-
}
|
|
147
|
-
interface MarkData<D = unknown> {
|
|
148
|
-
/**
|
|
149
|
-
* The row behind the mark: a bar's or a slice's row, a line point's row. A line's is the row at its
|
|
150
|
-
* revealed end; its other rows' values are in `samples`.
|
|
151
|
-
*/
|
|
152
|
-
readonly datum: D;
|
|
153
|
-
/** Data values along the walk, t ascending. */
|
|
154
|
-
readonly samples: readonly Sample[];
|
|
155
|
-
/** Another series in the same chart, if it exists. */
|
|
156
|
-
related(series: string): MarkData<D> | undefined;
|
|
157
|
-
/** The values before this update, for update effects that show change. */
|
|
158
|
-
readonly previous?: MarkData<D>;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
interface EffectContext {
|
|
162
|
-
/** Aborted on leave, re-trigger, data update or destroy. */
|
|
163
|
-
readonly signal: AbortSignal;
|
|
164
|
-
readonly motion: MotionView;
|
|
165
|
-
/** A tween with the clock, motion and signal already bound. */
|
|
166
|
-
tween(options: TweenOptions): Tween;
|
|
167
|
-
/** Restyles the mark itself; reset by the runner on clear. */
|
|
168
|
-
readonly mark: MarkHandle;
|
|
169
|
-
/** This run's own overlay group, above the marks; emptied on clear. */
|
|
170
|
-
readonly layer: Layer;
|
|
171
|
-
readonly icons: IconSource;
|
|
172
|
-
/** Position in a multi-mark event, for stagger. */
|
|
173
|
-
readonly batch: {
|
|
174
|
-
readonly index: number;
|
|
175
|
-
readonly count: number;
|
|
176
|
-
};
|
|
177
|
-
/** Called when the geometry moves (transitions, resizes, line reveals); unsubscribed on clear. */
|
|
178
|
-
onChange(listener: (mark: MarkGeometry, data?: MarkData) => void): void;
|
|
179
|
-
/** The mark's geometry before this update, on update events. */
|
|
180
|
-
readonly previous?: MarkGeometry;
|
|
181
|
-
}
|
|
182
|
-
interface GeometryEffect {
|
|
183
|
-
readonly kind: "geometry";
|
|
184
|
-
/** Resolves when done or cancelled. */
|
|
185
|
-
run(mark: MarkGeometry, ctx: EffectContext): Promise<void>;
|
|
186
|
-
/** Draws the final state immediately, on a fresh context. Used when the effective mode is off. */
|
|
187
|
-
end(mark: MarkGeometry, ctx: EffectContext): void;
|
|
188
|
-
/** Extra cleanup beyond what the runner does. */
|
|
189
|
-
clear(ctx: EffectContext): void;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* `run` and `end` are function-typed properties, not methods, on purpose: TypeScript checks method
|
|
193
|
-
* parameters loosely in both directions, which would let an effect that needs more fields than a
|
|
194
|
-
* chart's rows have (DataEffect<Row & { target: number }> on a chart of Row) slip through.
|
|
195
|
-
*/
|
|
196
|
-
interface DataEffect<D = unknown> {
|
|
197
|
-
readonly kind: "data";
|
|
198
|
-
/** Checked when the chart is created, so a missing series throws instead of drawing nothing. */
|
|
199
|
-
readonly needs?: {
|
|
200
|
-
readonly related?: readonly string[];
|
|
201
|
-
};
|
|
202
|
-
readonly run: (mark: MarkGeometry, data: MarkData<D>, ctx: EffectContext) => Promise<void>;
|
|
203
|
-
readonly end: (mark: MarkGeometry, data: MarkData<D>, ctx: EffectContext) => void;
|
|
204
|
-
readonly clear: (ctx: EffectContext) => void;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* A transition run's context. While a transition plays, both views' marks are hidden, so `mark` does
|
|
208
|
-
* nothing and `onChange` never fires: a resize lands the transition instead.
|
|
209
|
-
*/
|
|
210
|
-
interface TransitionContext extends EffectContext {
|
|
211
|
-
/**
|
|
212
|
-
* Where the run begins, from 0 to 1, in the effect's own progress (morph's is the shapes' eased
|
|
213
|
-
* progress). 0 plays it all. A switch back mid-way plays the reverse pair from 1 minus the progress
|
|
214
|
-
* the first had reached, so an effect that honours it retraces; one that ignores it replays from its
|
|
215
|
-
* beginning.
|
|
216
|
-
*/
|
|
217
|
-
readonly start: number;
|
|
218
|
-
}
|
|
219
|
-
/** Morph and future chart-to-chart transitions: from one geometry to another. */
|
|
220
|
-
interface TransitionEffect {
|
|
221
|
-
readonly kind: "transition";
|
|
222
|
-
/** Resolves when done or cancelled, leaving `to`'s end state drawn until cleared. */
|
|
223
|
-
run(from: MarkGeometry, to: MarkGeometry, ctx: TransitionContext): Promise<void>;
|
|
224
|
-
/** Draws the final state immediately, on a fresh context. Used when the effective mode is off. */
|
|
225
|
-
end(from: MarkGeometry, to: MarkGeometry, ctx: TransitionContext): void;
|
|
226
|
-
/** Extra cleanup beyond what the player does. */
|
|
227
|
-
clear(ctx: TransitionContext): void;
|
|
228
|
-
}
|
|
229
|
-
/** What combinators accept: any mark effect, whatever rows it reads. */
|
|
230
|
-
type AnyMarkEffect = GeometryEffect | DataEffect<any>;
|
|
231
|
-
type MarkEffect<D = unknown> = GeometryEffect | DataEffect<D>;
|
|
232
|
-
/** The row type a single effect needs; geometry effects need nothing (unknown). */
|
|
233
|
-
type RowNeeds<E> = E extends DataEffect<infer D> ? D : unknown;
|
|
234
|
-
/**
|
|
235
|
-
* The rows a combination needs: every part's needs at once (an intersection, not a union, so a
|
|
236
|
-
* generic part such as threshold() can't widen a typed part's needs back to unknown).
|
|
237
|
-
*/
|
|
238
|
-
type AllRowNeeds<E extends readonly unknown[]> = E extends readonly [] ? unknown : E extends readonly [infer First, ...infer Rest] ? RowNeeds<First> & AllRowNeeds<Rest> : E extends readonly (infer Item)[] ? RowNeeds<Item> : unknown;
|
|
239
|
-
/** What `sequence` and `parallel` return: a data effect if any part is one. */
|
|
240
|
-
type Combined<E extends readonly AnyMarkEffect[]> = [Extract<E[number], {
|
|
241
|
-
kind: "data";
|
|
242
|
-
}>] extends [never] ? GeometryEffect : DataEffect<AllRowNeeds<E>>;
|
|
243
|
-
|
|
244
|
-
export { motion as B, scaleDuration as H, tween as I, createClock as r, createMotion as s, defaultClock as t, defaultScaling as u, easeInOutCubic as v, easeOutCubic as w, linear as x, manualClock as y, mediaReducedMotion as z };
|
|
245
|
-
export type { AnyMarkEffect as A, Combined as C, DataEffect as D, Easing as E, FrameSource as F, GeometryEffect as G, MotionEnv as M, ReducedMotionSource as R, Sample as S, Timing as T, TweenResult as a, MarkEffect as b, MarkData as c, Motion as d, MotionMode as e, TransitionEffect as f, EffectContext as g, Clock as h, ManualClock as i, MotionOptions as j, MotionView as k, ScalingOverrides as l, ScalingRule as m, ScalingTable as n, TransitionContext as o, Tween as p, TweenOptions as q };
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import { M as MarkGeometry, e as MarkHandle, L as Layer, d as IconSource } from './drawing-DWZIXIeR.cjs';
|
|
2
|
-
|
|
3
|
-
/** Where frames come from. The default uses requestAnimationFrame, or a 16 ms timer outside the browser. */
|
|
4
|
-
interface FrameSource {
|
|
5
|
-
now(): number;
|
|
6
|
-
/** Ask for one callback on the next frame. Returns a function that cancels it. */
|
|
7
|
-
request(callback: (now: number) => void): () => void;
|
|
8
|
-
}
|
|
9
|
-
interface Clock {
|
|
10
|
-
now(): number;
|
|
11
|
-
/** Call `callback` on every frame until the returned function is called. */
|
|
12
|
-
onFrame(callback: (now: number) => void): () => void;
|
|
13
|
-
}
|
|
14
|
-
/** A clock that only moves when told to. For tests. */
|
|
15
|
-
interface ManualClock extends Clock {
|
|
16
|
-
/** Move time forward by `ms` and run one frame at the new time. */
|
|
17
|
-
advance(ms: number): void;
|
|
18
|
-
/** True when nothing is waiting for a frame. */
|
|
19
|
-
readonly idle: boolean;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* One shared frame loop. It requests a frame only while something is
|
|
23
|
-
* subscribed, so an idle page costs nothing.
|
|
24
|
-
*/
|
|
25
|
-
declare function createClock(source?: FrameSource): Clock;
|
|
26
|
-
declare function manualClock(start?: number): ManualClock;
|
|
27
|
-
/** The page-wide clock every tween uses unless given another. */
|
|
28
|
-
declare const defaultClock: Clock;
|
|
29
|
-
|
|
30
|
-
/** Maps linear progress (0–1) to eased progress. Any function of this shape works. */
|
|
31
|
-
type Easing = (t: number) => number;
|
|
32
|
-
/** For playback, where speed should stay constant. */
|
|
33
|
-
declare const linear: Easing;
|
|
34
|
-
/** For data transitions: starts and ends gently. */
|
|
35
|
-
declare const easeInOutCubic: Easing;
|
|
36
|
-
/** For travel, and for animations retargeted mid-flight: starts at speed, settles gently. */
|
|
37
|
-
declare const easeOutCubic: Easing;
|
|
38
|
-
|
|
39
|
-
type MotionMode = "presentation" | "analysis" | "off";
|
|
40
|
-
/** What a duration is for. Each kind scales differently by mode. */
|
|
41
|
-
type Timing = "feedback" | "transition" | "effect" | "playback" | "stagger";
|
|
42
|
-
/** Base ms × factor, clamped to [min(base, min), max]. A floor never makes an animation longer than its base. */
|
|
43
|
-
interface ScalingRule {
|
|
44
|
-
readonly factor: number;
|
|
45
|
-
readonly min?: number;
|
|
46
|
-
readonly max?: number;
|
|
47
|
-
}
|
|
48
|
-
type ScaledMode = Exclude<MotionMode, "off">;
|
|
49
|
-
type ScalingTable = {
|
|
50
|
-
readonly [M in ScaledMode]: {
|
|
51
|
-
readonly [T in Timing]: ScalingRule;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
type ScalingOverrides = {
|
|
55
|
-
readonly [M in ScaledMode]?: {
|
|
56
|
-
readonly [T in Timing]?: ScalingRule;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
/** Starting values from the prototype; tuned in the demos. Off is always 0. */
|
|
60
|
-
declare const defaultScaling: ScalingTable;
|
|
61
|
-
/** What charts and effects need from the motion system. */
|
|
62
|
-
interface MotionView {
|
|
63
|
-
/** The effective mode, after the reduced-motion rule. */
|
|
64
|
-
readonly mode: MotionMode;
|
|
65
|
-
/** True only in presentation: split data changes into stages. */
|
|
66
|
-
readonly staged: boolean;
|
|
67
|
-
/** Scale a base duration (ms) for the current mode. 0 means "jump to the end". */
|
|
68
|
-
duration(base: number, timing?: Timing): number;
|
|
69
|
-
}
|
|
70
|
-
interface Motion extends MotionView {
|
|
71
|
-
/** The mode the page author asked for. */
|
|
72
|
-
readonly requested: MotionMode;
|
|
73
|
-
/** The mode the viewer picked in an on-page control, if any. */
|
|
74
|
-
readonly viewerChoice: MotionMode | undefined;
|
|
75
|
-
/** Live value of `prefers-reduced-motion: reduce`. */
|
|
76
|
-
readonly prefersReduced: boolean;
|
|
77
|
-
/** The author's default. Never overrides reduced motion. */
|
|
78
|
-
setMode(mode: MotionMode): void;
|
|
79
|
-
/** The viewer's explicit choice from an on-page control. Overrides reduced motion. */
|
|
80
|
-
chooseMode(mode: MotionMode): void;
|
|
81
|
-
/** Forget the viewer's choice and follow the author's mode and the device setting again. */
|
|
82
|
-
clearChoice(): void;
|
|
83
|
-
/** Called whenever the mode, the viewer's choice or the device setting changes. */
|
|
84
|
-
subscribe(listener: () => void): () => void;
|
|
85
|
-
}
|
|
86
|
-
/** A live reduced-motion preference. */
|
|
87
|
-
interface ReducedMotionSource {
|
|
88
|
-
readonly matches: boolean;
|
|
89
|
-
subscribe(listener: () => void): () => void;
|
|
90
|
-
}
|
|
91
|
-
interface MotionOptions {
|
|
92
|
-
/** The author's mode. Default "presentation". */
|
|
93
|
-
readonly mode?: MotionMode;
|
|
94
|
-
readonly scaling?: ScalingOverrides;
|
|
95
|
-
/** Default: the `prefers-reduced-motion` media query. */
|
|
96
|
-
readonly reducedMotion?: ReducedMotionSource;
|
|
97
|
-
}
|
|
98
|
-
declare function createMotion(options?: MotionOptions): Motion;
|
|
99
|
-
declare function scaleDuration(base: number, rule: ScalingRule): number;
|
|
100
|
-
/** Reads `prefers-reduced-motion` lazily: nothing touches the DOM until `matches` is read or someone subscribes. */
|
|
101
|
-
declare function mediaReducedMotion(query?: string): ReducedMotionSource;
|
|
102
|
-
/** The page-wide motion every chart follows unless given its own. */
|
|
103
|
-
declare const motion: Motion;
|
|
104
|
-
|
|
105
|
-
/** The clock and motion settings an animation runs against. */
|
|
106
|
-
interface MotionEnv {
|
|
107
|
-
readonly clock: Clock;
|
|
108
|
-
readonly motion: MotionView;
|
|
109
|
-
}
|
|
110
|
-
interface TweenOptions {
|
|
111
|
-
/** Base duration in ms, scaled by the motion mode. */
|
|
112
|
-
readonly duration: number;
|
|
113
|
-
/** Default "transition". */
|
|
114
|
-
readonly timing?: Timing;
|
|
115
|
-
/** Default easeInOutCubic. */
|
|
116
|
-
readonly ease?: Easing;
|
|
117
|
-
/** Base delay in ms before progress starts, scaled like the duration. */
|
|
118
|
-
readonly delay?: number;
|
|
119
|
-
/** Called with eased progress: once with ease(0) at the start, then every frame, then with ease(1) at the end. */
|
|
120
|
-
readonly update: (progress: number) => void;
|
|
121
|
-
readonly signal?: AbortSignal;
|
|
122
|
-
}
|
|
123
|
-
type TweenResult = "done" | "cancelled";
|
|
124
|
-
interface Tween {
|
|
125
|
-
/** Resolves when the tween ends. Never rejects. */
|
|
126
|
-
readonly finished: Promise<TweenResult>;
|
|
127
|
-
readonly state: "running" | TweenResult;
|
|
128
|
-
/** Stop where it is. */
|
|
129
|
-
cancel(): void;
|
|
130
|
-
/** Jump to the end now. */
|
|
131
|
-
finish(): void;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Animate progress from 0 to 1. If the motion mode scales the duration to 0,
|
|
135
|
-
* `update(ease(1))` runs synchronously, before `tween` returns. If the mode
|
|
136
|
-
* turns off while the tween runs, it jumps to the end on the next frame.
|
|
137
|
-
*/
|
|
138
|
-
declare function tween(options: TweenOptions, env?: Partial<MotionEnv>): Tween;
|
|
139
|
-
|
|
140
|
-
interface Sample {
|
|
141
|
-
/** Where along the walk, in [0, 1]. */
|
|
142
|
-
readonly t: number;
|
|
143
|
-
readonly value: number;
|
|
144
|
-
/** The x value or label behind the sample (a week, a date). */
|
|
145
|
-
readonly at?: string | number | Date;
|
|
146
|
-
}
|
|
147
|
-
interface MarkData<D = unknown> {
|
|
148
|
-
/**
|
|
149
|
-
* The row behind the mark: a bar's or a slice's row, a line point's row. A line's is the row at its
|
|
150
|
-
* revealed end; its other rows' values are in `samples`.
|
|
151
|
-
*/
|
|
152
|
-
readonly datum: D;
|
|
153
|
-
/** Data values along the walk, t ascending. */
|
|
154
|
-
readonly samples: readonly Sample[];
|
|
155
|
-
/** Another series in the same chart, if it exists. */
|
|
156
|
-
related(series: string): MarkData<D> | undefined;
|
|
157
|
-
/** The values before this update, for update effects that show change. */
|
|
158
|
-
readonly previous?: MarkData<D>;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
interface EffectContext {
|
|
162
|
-
/** Aborted on leave, re-trigger, data update or destroy. */
|
|
163
|
-
readonly signal: AbortSignal;
|
|
164
|
-
readonly motion: MotionView;
|
|
165
|
-
/** A tween with the clock, motion and signal already bound. */
|
|
166
|
-
tween(options: TweenOptions): Tween;
|
|
167
|
-
/** Restyles the mark itself; reset by the runner on clear. */
|
|
168
|
-
readonly mark: MarkHandle;
|
|
169
|
-
/** This run's own overlay group, above the marks; emptied on clear. */
|
|
170
|
-
readonly layer: Layer;
|
|
171
|
-
readonly icons: IconSource;
|
|
172
|
-
/** Position in a multi-mark event, for stagger. */
|
|
173
|
-
readonly batch: {
|
|
174
|
-
readonly index: number;
|
|
175
|
-
readonly count: number;
|
|
176
|
-
};
|
|
177
|
-
/** Called when the geometry moves (transitions, resizes, line reveals); unsubscribed on clear. */
|
|
178
|
-
onChange(listener: (mark: MarkGeometry, data?: MarkData) => void): void;
|
|
179
|
-
/** The mark's geometry before this update, on update events. */
|
|
180
|
-
readonly previous?: MarkGeometry;
|
|
181
|
-
}
|
|
182
|
-
interface GeometryEffect {
|
|
183
|
-
readonly kind: "geometry";
|
|
184
|
-
/** Resolves when done or cancelled. */
|
|
185
|
-
run(mark: MarkGeometry, ctx: EffectContext): Promise<void>;
|
|
186
|
-
/** Draws the final state immediately, on a fresh context. Used when the effective mode is off. */
|
|
187
|
-
end(mark: MarkGeometry, ctx: EffectContext): void;
|
|
188
|
-
/** Extra cleanup beyond what the runner does. */
|
|
189
|
-
clear(ctx: EffectContext): void;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* `run` and `end` are function-typed properties, not methods, on purpose: TypeScript checks method
|
|
193
|
-
* parameters loosely in both directions, which would let an effect that needs more fields than a
|
|
194
|
-
* chart's rows have (DataEffect<Row & { target: number }> on a chart of Row) slip through.
|
|
195
|
-
*/
|
|
196
|
-
interface DataEffect<D = unknown> {
|
|
197
|
-
readonly kind: "data";
|
|
198
|
-
/** Checked when the chart is created, so a missing series throws instead of drawing nothing. */
|
|
199
|
-
readonly needs?: {
|
|
200
|
-
readonly related?: readonly string[];
|
|
201
|
-
};
|
|
202
|
-
readonly run: (mark: MarkGeometry, data: MarkData<D>, ctx: EffectContext) => Promise<void>;
|
|
203
|
-
readonly end: (mark: MarkGeometry, data: MarkData<D>, ctx: EffectContext) => void;
|
|
204
|
-
readonly clear: (ctx: EffectContext) => void;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* A transition run's context. While a transition plays, both views' marks are hidden, so `mark` does
|
|
208
|
-
* nothing and `onChange` never fires: a resize lands the transition instead.
|
|
209
|
-
*/
|
|
210
|
-
interface TransitionContext extends EffectContext {
|
|
211
|
-
/**
|
|
212
|
-
* Where the run begins, from 0 to 1, in the effect's own progress (morph's is the shapes' eased
|
|
213
|
-
* progress). 0 plays it all. A switch back mid-way plays the reverse pair from 1 minus the progress
|
|
214
|
-
* the first had reached, so an effect that honours it retraces; one that ignores it replays from its
|
|
215
|
-
* beginning.
|
|
216
|
-
*/
|
|
217
|
-
readonly start: number;
|
|
218
|
-
}
|
|
219
|
-
/** Morph and future chart-to-chart transitions: from one geometry to another. */
|
|
220
|
-
interface TransitionEffect {
|
|
221
|
-
readonly kind: "transition";
|
|
222
|
-
/** Resolves when done or cancelled, leaving `to`'s end state drawn until cleared. */
|
|
223
|
-
run(from: MarkGeometry, to: MarkGeometry, ctx: TransitionContext): Promise<void>;
|
|
224
|
-
/** Draws the final state immediately, on a fresh context. Used when the effective mode is off. */
|
|
225
|
-
end(from: MarkGeometry, to: MarkGeometry, ctx: TransitionContext): void;
|
|
226
|
-
/** Extra cleanup beyond what the player does. */
|
|
227
|
-
clear(ctx: TransitionContext): void;
|
|
228
|
-
}
|
|
229
|
-
/** What combinators accept: any mark effect, whatever rows it reads. */
|
|
230
|
-
type AnyMarkEffect = GeometryEffect | DataEffect<any>;
|
|
231
|
-
type MarkEffect<D = unknown> = GeometryEffect | DataEffect<D>;
|
|
232
|
-
/** The row type a single effect needs; geometry effects need nothing (unknown). */
|
|
233
|
-
type RowNeeds<E> = E extends DataEffect<infer D> ? D : unknown;
|
|
234
|
-
/**
|
|
235
|
-
* The rows a combination needs: every part's needs at once (an intersection, not a union, so a
|
|
236
|
-
* generic part such as threshold() can't widen a typed part's needs back to unknown).
|
|
237
|
-
*/
|
|
238
|
-
type AllRowNeeds<E extends readonly unknown[]> = E extends readonly [] ? unknown : E extends readonly [infer First, ...infer Rest] ? RowNeeds<First> & AllRowNeeds<Rest> : E extends readonly (infer Item)[] ? RowNeeds<Item> : unknown;
|
|
239
|
-
/** What `sequence` and `parallel` return: a data effect if any part is one. */
|
|
240
|
-
type Combined<E extends readonly AnyMarkEffect[]> = [Extract<E[number], {
|
|
241
|
-
kind: "data";
|
|
242
|
-
}>] extends [never] ? GeometryEffect : DataEffect<AllRowNeeds<E>>;
|
|
243
|
-
|
|
244
|
-
export { motion as B, scaleDuration as H, tween as I, createClock as r, createMotion as s, defaultClock as t, defaultScaling as u, easeInOutCubic as v, easeOutCubic as w, linear as x, manualClock as y, mediaReducedMotion as z };
|
|
245
|
-
export type { AnyMarkEffect as A, Combined as C, DataEffect as D, Easing as E, FrameSource as F, GeometryEffect as G, MotionEnv as M, ReducedMotionSource as R, Sample as S, Timing as T, TweenResult as a, MarkEffect as b, MarkData as c, Motion as d, MotionMode as e, TransitionEffect as f, EffectContext as g, Clock as h, ManualClock as i, MotionOptions as j, MotionView as k, ScalingOverrides as l, ScalingRule as m, ScalingTable as n, TransitionContext as o, Tween as p, TweenOptions as q };
|