@pixerate/flair 0.8.0 → 0.10.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 +21 -0
- package/README.md +13 -6
- package/dist/catalog/index.d.ts +9 -3
- package/dist/catalog/index.js +2 -1
- package/dist/chunk-OHW7UG6D.js +336 -0
- package/dist/chunk-OHW7UG6D.js.map +1 -0
- package/dist/chunk-P5TSANZY.js +1 -0
- package/dist/{chunk-EQS4EXNM.js → chunk-SH66CNLC.js} +52 -6
- package/dist/chunk-SH66CNLC.js.map +1 -0
- package/dist/{chunk-FHXOMIQY.js → chunk-STGGN4MR.js} +2185 -209
- package/dist/chunk-STGGN4MR.js.map +1 -0
- package/dist/{chunk-TDMD5XAU.js → chunk-YACVME3D.js} +75 -4
- package/dist/{chunk-TDMD5XAU.js.map → chunk-YACVME3D.js.map} +1 -1
- package/dist/{chunk-EZRRKQFV.js → chunk-YLJWC4N2.js} +96 -1
- package/dist/chunk-YLJWC4N2.js.map +1 -0
- package/dist/cli.js +2 -2
- package/dist/editor/index.d.ts +3 -4
- package/dist/editor/index.js +5 -4
- package/dist/editor/index.js.map +1 -1
- package/dist/index.d.ts +65 -6
- package/dist/index.js +18 -4
- package/dist/index.js.map +1 -1
- package/dist/{renderer-0_Ap1tyi.d.ts → renderer-SNYZu__R.d.ts} +17 -0
- package/dist/svg-CpeanaE_.d.ts +375 -0
- package/dist/{types-CNPIrnTf.d.ts → types-D8uhzDyN.d.ts} +8 -2
- package/dist/vector/index.d.ts +21 -112
- package/dist/vector/index.js +8 -2
- package/package.json +1 -1
- package/dist/chunk-CFCLT2XL.js +0 -1
- package/dist/chunk-EQS4EXNM.js.map +0 -1
- package/dist/chunk-EZRRKQFV.js.map +0 -1
- package/dist/chunk-FHXOMIQY.js.map +0 -1
- package/dist/clock-BhdXWH-n.d.ts +0 -47
- package/dist/motion-Ce0lmzm3.d.ts +0 -179
- /package/dist/{chunk-CFCLT2XL.js.map → chunk-P5TSANZY.js.map} +0 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vector motion: animated SVG pictures described as data. A picture changes in
|
|
3
|
+
* steps (step 0 when it starts, step n at `steps[n - 1]` ms), and everything
|
|
4
|
+
* here is a pure function of its arguments, so a frame comes out the same
|
|
5
|
+
* however it is reached (played, stepped for a recording, or seeked).
|
|
6
|
+
*/
|
|
7
|
+
/** Easing curves by name. */
|
|
8
|
+
declare const EASES: {
|
|
9
|
+
readonly linear: (t: number) => number;
|
|
10
|
+
readonly "in-out": (t: number) => number;
|
|
11
|
+
readonly out: (t: number) => number;
|
|
12
|
+
};
|
|
13
|
+
type EaseName = keyof typeof EASES;
|
|
14
|
+
/** How long a change takes by default, in ms. */
|
|
15
|
+
declare const STEP_MS = 800;
|
|
16
|
+
/**
|
|
17
|
+
* When `step` starts, in ms since the media started (step 0 at 0, step n at
|
|
18
|
+
* `steps[n - 1]`), or undefined if it has not started yet.
|
|
19
|
+
*/
|
|
20
|
+
declare function stepStart(steps: readonly number[], step: number): number | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* How far a change that plays on `step` (after `delay` ms, over `ms`) has
|
|
23
|
+
* got at `timeMs`, eased: 0 before it starts, 1 once it is over.
|
|
24
|
+
*/
|
|
25
|
+
declare function stepProgress(steps: readonly number[], timeMs: number, step: number, options?: {
|
|
26
|
+
delay?: number;
|
|
27
|
+
ms?: number;
|
|
28
|
+
ease?: EaseName;
|
|
29
|
+
}): number;
|
|
30
|
+
/** The key an item in a list of data keeps from one state to the next. */
|
|
31
|
+
type DataKey = (item: unknown, index: number) => string;
|
|
32
|
+
/**
|
|
33
|
+
* Keys items by their `id`, `key`, `name` or `label` (or a link's `source`
|
|
34
|
+
* and `target`), else by position.
|
|
35
|
+
*/
|
|
36
|
+
declare const defaultDataKey: DataKey;
|
|
37
|
+
/**
|
|
38
|
+
* Data between two states, `u` of the way from `a` to `b`. Numbers blend;
|
|
39
|
+
* lists match their items by key (`keyOf`), so each keeps its identity and
|
|
40
|
+
* moves rather than jumping, with items only in `b` growing from nothing and
|
|
41
|
+
* items only in `a` shrinking away; objects blend field by field; anything
|
|
42
|
+
* else changes halfway.
|
|
43
|
+
*/
|
|
44
|
+
declare function lerpData<D>(a: D, b: D, u: number, keyOf?: DataKey): D;
|
|
45
|
+
/**
|
|
46
|
+
* The data to show at `timeMs`, for media whose data has a state per step:
|
|
47
|
+
* `states[n]` is shown from step n (the last one stays), reached by moving
|
|
48
|
+
* from the state before it over `ms`.
|
|
49
|
+
*/
|
|
50
|
+
declare function stepData<D>(states: readonly D[], steps: readonly number[], timeMs: number, options?: {
|
|
51
|
+
ms?: number;
|
|
52
|
+
ease?: EaseName;
|
|
53
|
+
keyOf?: DataKey;
|
|
54
|
+
}): D;
|
|
55
|
+
/**
|
|
56
|
+
* An animated SVG picture: markup plus changes to its elements. Draw it with
|
|
57
|
+
* `SvgPlayer` (or `svgView`), or compute frames yourself with `svgFrame`.
|
|
58
|
+
*/
|
|
59
|
+
interface SvgMotion {
|
|
60
|
+
/** One self-contained `<svg>` with a `viewBox`: no scripts, no outside links. */
|
|
61
|
+
svg: string;
|
|
62
|
+
/** Changes to its elements, each on a step. */
|
|
63
|
+
animate?: SvgAnimation[];
|
|
64
|
+
}
|
|
65
|
+
/** A box in an SVG's `viewBox` units: `[x, y, width, height]`. */
|
|
66
|
+
type SvgBox = readonly [number, number, number, number];
|
|
67
|
+
/** A change to one element of an {@link SvgMotion}, or (with `view`) to the whole picture. */
|
|
68
|
+
interface SvgAnimation {
|
|
69
|
+
/** The element's `id` in the SVG (not needed for `view`). */
|
|
70
|
+
id?: string;
|
|
71
|
+
/** The step it plays on: 0 (default) when the media starts, 1 with the next shot, and so on. */
|
|
72
|
+
step?: number;
|
|
73
|
+
/** Ms after the step starts. */
|
|
74
|
+
delay?: number;
|
|
75
|
+
/** How long it takes, in ms (default {@link STEP_MS}). */
|
|
76
|
+
ms?: number;
|
|
77
|
+
ease?: EaseName;
|
|
78
|
+
/**
|
|
79
|
+
* Attributes from one value to another: numbers, colours (`#rrggbb`), or
|
|
80
|
+
* strings whose numbers change while the rest stays the same (a path's
|
|
81
|
+
* `d`, a `transform`, `points`).
|
|
82
|
+
*/
|
|
83
|
+
attrs?: Record<string, readonly [string | number, string | number]>;
|
|
84
|
+
/** Draws a line or outline on along its length, from 0 to 1 (or between two fractions). */
|
|
85
|
+
draw?: boolean | readonly [number, number];
|
|
86
|
+
/**
|
|
87
|
+
* Zooms and pans the whole picture to frame a box (`[x, y, width, height]`
|
|
88
|
+
* in the `viewBox`'s units) or an element by id (with a margin round it),
|
|
89
|
+
* from where the last `view` left it (at first, the whole `viewBox`).
|
|
90
|
+
*/
|
|
91
|
+
view?: SvgBox | string;
|
|
92
|
+
/**
|
|
93
|
+
* Moves the element along a path (by id) from its start to its end, or
|
|
94
|
+
* between the fractions in `at`; draw the element round (0, 0), like a
|
|
95
|
+
* circle at `cx="0" cy="0"`.
|
|
96
|
+
*/
|
|
97
|
+
along?: string;
|
|
98
|
+
/** How far along the path `along` moves the element, from and to (default [0, 1]). */
|
|
99
|
+
at?: readonly [number, number];
|
|
100
|
+
/** Counts the element's text from one number to the other. */
|
|
101
|
+
count?: readonly [number, number];
|
|
102
|
+
/** How a count is written: `{n}` stands for the number ("{n}%", "$ {n}M"). */
|
|
103
|
+
format?: string;
|
|
104
|
+
/** Decimals in a count (default 0). */
|
|
105
|
+
decimals?: number;
|
|
106
|
+
/**
|
|
107
|
+
* Writes this text into the element letter by letter: none of it when the
|
|
108
|
+
* change starts, all of it when it ends (a typewriter).
|
|
109
|
+
*/
|
|
110
|
+
write?: string;
|
|
111
|
+
/**
|
|
112
|
+
* With `write`: letters not yet written show characters picked from this
|
|
113
|
+
* string, changing every {@link SCRAMBLE_MS} ms, so the text decodes
|
|
114
|
+
* rather than types. The same time always picks the same characters.
|
|
115
|
+
*/
|
|
116
|
+
scramble?: string;
|
|
117
|
+
/** With `write`: shown after the written letters while it writes ("▌", "|"). */
|
|
118
|
+
caret?: string;
|
|
119
|
+
}
|
|
120
|
+
/** How often scrambled letters change, in ms (see `SvgAnimation.scramble`). */
|
|
121
|
+
declare const SCRAMBLE_MS = 50;
|
|
122
|
+
/**
|
|
123
|
+
* `text` with `u` (0–1) of its letters written (see `SvgAnimation.write`):
|
|
124
|
+
* the rest scrambled from `scramble` (picked by `timeMs`) or left off, then
|
|
125
|
+
* the caret while it is unfinished. Letters are code points, so emoji and
|
|
126
|
+
* accents are never split.
|
|
127
|
+
*/
|
|
128
|
+
declare function writtenText(text: string, u: number, options?: {
|
|
129
|
+
scramble?: string;
|
|
130
|
+
caret?: string;
|
|
131
|
+
timeMs?: number;
|
|
132
|
+
}): string;
|
|
133
|
+
/** What one element of an animated SVG shows at a time. */
|
|
134
|
+
interface SvgElementFrame {
|
|
135
|
+
attrs: Record<string, string>;
|
|
136
|
+
/** How much of its length is drawn, 0–1. */
|
|
137
|
+
draw?: number;
|
|
138
|
+
text?: string;
|
|
139
|
+
/** Where it is along a path: the path's id and the fraction of its length. */
|
|
140
|
+
along?: {
|
|
141
|
+
path: string;
|
|
142
|
+
at: number;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* The whole picture's framing (on the frame for {@link SVG_PICTURE}): `u`
|
|
146
|
+
* of the way from one view to the next, `null` being the whole `viewBox`.
|
|
147
|
+
*/
|
|
148
|
+
view?: {
|
|
149
|
+
from: SvgBox | string | null;
|
|
150
|
+
to: SvgBox | string;
|
|
151
|
+
u: number;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/** The key of the whole picture's frame in {@link svgFrame}'s result (for `view`). */
|
|
155
|
+
declare const SVG_PICTURE = "";
|
|
156
|
+
/** A value `u` of the way between two attribute values (see `SvgAnimation.attrs`). */
|
|
157
|
+
declare function lerpAttr(a: string | number, b: string | number, u: number): string;
|
|
158
|
+
/** Formats a number for a count animation (`{n}` stands for the rounded number). */
|
|
159
|
+
declare function formatCount(value: number, options?: {
|
|
160
|
+
decimals?: number;
|
|
161
|
+
format?: string;
|
|
162
|
+
}): string;
|
|
163
|
+
/**
|
|
164
|
+
* What each animated element shows at `timeMs`. For each attribute (or
|
|
165
|
+
* line, count or writing) the latest change to have started wins; before the first
|
|
166
|
+
* one starts, the element shows that change's starting value, so something
|
|
167
|
+
* that grows in later is hidden until then.
|
|
168
|
+
*/
|
|
169
|
+
declare function svgFrame(animations: readonly SvgAnimation[], steps: readonly number[], timeMs: number): Map<string, SvgElementFrame>;
|
|
170
|
+
/**
|
|
171
|
+
* The opening tag of the root element at the start of `markup` (up to its
|
|
172
|
+
* first `>`), cut out without a regular expression, so checks on it stay
|
|
173
|
+
* linear however long or odd the markup is.
|
|
174
|
+
*/
|
|
175
|
+
declare function svgOpeningTag(markup: string): string;
|
|
176
|
+
/** Problems with an {@link SvgMotion}, as sentences; none when it can be drawn. */
|
|
177
|
+
declare function svgMotionIssues(motion: unknown): string[];
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Time source for generative animations and playback.
|
|
181
|
+
* By default that is real time (animation frames and timers).
|
|
182
|
+
* A ManualClock instead moves only when told to, enabling frame-exact
|
|
183
|
+
* rendering, video recording, scrubbing, or fast simulation without waiting.
|
|
184
|
+
*/
|
|
185
|
+
interface Clock {
|
|
186
|
+
/** Current time in milliseconds. */
|
|
187
|
+
now(): number;
|
|
188
|
+
/** Resolves on the next frame. */
|
|
189
|
+
frame(): Promise<void>;
|
|
190
|
+
/** Resolves after `ms` milliseconds of this clock's time. */
|
|
191
|
+
sleep(ms: number): Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Whether the clock follows wall time. Live clocks stop when the tab is in
|
|
194
|
+
* the background (browsers pause animation frames there).
|
|
195
|
+
*/
|
|
196
|
+
readonly live: boolean;
|
|
197
|
+
}
|
|
198
|
+
declare const pageHidden: () => boolean;
|
|
199
|
+
declare const realClock: Clock;
|
|
200
|
+
/**
|
|
201
|
+
* A clock that only moves when {@link advance} or {@link tick} is called.
|
|
202
|
+
* Each call fires the sleeps that fall due, in order, letting awaiting code
|
|
203
|
+
* run before the next sleep fires, then resolves pending frames.
|
|
204
|
+
*/
|
|
205
|
+
declare class ManualClock implements Clock {
|
|
206
|
+
readonly live = false;
|
|
207
|
+
private time;
|
|
208
|
+
private frames;
|
|
209
|
+
private sleepers;
|
|
210
|
+
private seq;
|
|
211
|
+
constructor(start?: number);
|
|
212
|
+
now(): number;
|
|
213
|
+
frame(): Promise<void>;
|
|
214
|
+
sleep(ms: number): Promise<void>;
|
|
215
|
+
get pending(): boolean;
|
|
216
|
+
advance(ms: number): Promise<void>;
|
|
217
|
+
tick(fps?: number): Promise<void>;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* A repeatable pseudo-random number in [0, 1) for a key and index.
|
|
221
|
+
* Useful for deterministic, reproducible animations.
|
|
222
|
+
*/
|
|
223
|
+
declare function jitter(key: string, n: number): number;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Drawing animated SVG pictures (see `SvgMotion`) in the DOM: a sanitising
|
|
227
|
+
* parser, a view that applies frames, and a player that runs on a `Clock`.
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* The `<svg>` in `markup`, parsed and made safe to show: no scripts, event
|
|
232
|
+
* handlers, `<foreignObject>` or links outside itself. Undefined when it is
|
|
233
|
+
* not an SVG.
|
|
234
|
+
*/
|
|
235
|
+
declare function parseSvg(markup: string): SVGSVGElement | undefined;
|
|
236
|
+
interface SvgViewOptions {
|
|
237
|
+
/** Called with the id of the innermost element with an id that is clicked. */
|
|
238
|
+
onPick?: (id: string) => void;
|
|
239
|
+
}
|
|
240
|
+
/** An {@link SvgMotion} drawn into an element; call `draw` with a time to show it then. */
|
|
241
|
+
interface SvgView {
|
|
242
|
+
/** A `div` filled by the picture; put it anywhere. */
|
|
243
|
+
readonly element: HTMLDivElement;
|
|
244
|
+
/** Shows the picture at `timeMs`, with steps starting at `steps` (ms). */
|
|
245
|
+
draw(timeMs: number, steps?: readonly number[]): void;
|
|
246
|
+
/** An image of the picture as drawn now. */
|
|
247
|
+
capture(pixels: {
|
|
248
|
+
width: number;
|
|
249
|
+
height: number;
|
|
250
|
+
}): Promise<HTMLCanvasElement | undefined>;
|
|
251
|
+
}
|
|
252
|
+
/** Shows an {@link SvgMotion} as a live view; with `onPick`, clicks report the id of the element clicked. */
|
|
253
|
+
declare function svgView(motion: SvgMotion, options?: SvgViewOptions): SvgView;
|
|
254
|
+
/** How long an {@link SvgMotion} runs: its last change's end, in ms (at least 1). */
|
|
255
|
+
declare function svgDuration(motion: SvgMotion, steps?: readonly number[]): number;
|
|
256
|
+
interface SvgPlayerOptions extends SvgViewOptions {
|
|
257
|
+
/** Time source (default: animation frames). Pass a `ManualClock` to step frames yourself. */
|
|
258
|
+
clock?: Clock;
|
|
259
|
+
/** Start playing at once (default `true`). */
|
|
260
|
+
autoplay?: boolean;
|
|
261
|
+
/** Start again at the end (default `true`). */
|
|
262
|
+
loop?: boolean;
|
|
263
|
+
/** Loop length in ms (default: the picture's own, see {@link svgDuration}, plus `hold`). */
|
|
264
|
+
duration?: number;
|
|
265
|
+
/** Ms to rest on the last frame before looping (default 600). */
|
|
266
|
+
hold?: number;
|
|
267
|
+
/** Playback speed (default 1). */
|
|
268
|
+
speed?: number;
|
|
269
|
+
/** Step start times in ms, for pictures that change on steps (default none). */
|
|
270
|
+
steps?: readonly number[];
|
|
271
|
+
/** Pause the animation loop when scrolled out of view via IntersectionObserver (default false). */
|
|
272
|
+
pauseWhenHidden?: boolean;
|
|
273
|
+
/** Wait to start playing until the element enters the viewport via IntersectionObserver (default false). When true, autoplay is deferred until first visible. */
|
|
274
|
+
playOnEnter?: boolean;
|
|
275
|
+
/** Hide the view (`visibility: hidden`) whenever playback is paused or reset (default false). */
|
|
276
|
+
hideWhenPaused?: boolean;
|
|
277
|
+
/**
|
|
278
|
+
* Plays in answer to the pointer instead of on its own (see {@link SvgTrigger}):
|
|
279
|
+
* `"hover"` and `"press"` play to the end while hovered or held and back to
|
|
280
|
+
* the start after; `"click"` plays the next step on each click, starting
|
|
281
|
+
* over after the last. `autoplay`, `loop` and `steps` are ignored.
|
|
282
|
+
*/
|
|
283
|
+
trigger?: SvgTrigger;
|
|
284
|
+
/** The element whose pointer events trigger it (default the container). */
|
|
285
|
+
triggerTarget?: HTMLElement;
|
|
286
|
+
}
|
|
287
|
+
/** What makes a triggered {@link SvgPlayer} play. */
|
|
288
|
+
type SvgTrigger = "hover" | "press" | "click";
|
|
289
|
+
/**
|
|
290
|
+
* Plays an {@link SvgMotion} inside `container`: loops by default, and can be
|
|
291
|
+
* paused, sought and sped up. Dispose it to stop and remove the picture.
|
|
292
|
+
*/
|
|
293
|
+
declare class SvgPlayer {
|
|
294
|
+
private readonly container;
|
|
295
|
+
readonly view: SvgView;
|
|
296
|
+
private readonly clock;
|
|
297
|
+
private steps;
|
|
298
|
+
private readonly loop;
|
|
299
|
+
private length;
|
|
300
|
+
private readonly motion;
|
|
301
|
+
private readonly trigger?;
|
|
302
|
+
private readonly triggerTarget?;
|
|
303
|
+
/** With a hover or press trigger: 1 playing to the end, -1 back to the start. */
|
|
304
|
+
private direction;
|
|
305
|
+
/** With a click trigger: when each click came, in ms of playback. */
|
|
306
|
+
private clicks;
|
|
307
|
+
private readonly hideWhenPaused;
|
|
308
|
+
private speed;
|
|
309
|
+
private time;
|
|
310
|
+
private last;
|
|
311
|
+
private playing;
|
|
312
|
+
private disposed;
|
|
313
|
+
private wasPlayingBeforeHidden;
|
|
314
|
+
private hasEnteredViewport;
|
|
315
|
+
private intersectionObserver?;
|
|
316
|
+
constructor(container: HTMLElement, motion: SvgMotion, options?: SvgPlayerOptions);
|
|
317
|
+
/** The loop length in ms. */
|
|
318
|
+
get duration(): number;
|
|
319
|
+
/** The time shown, in ms. */
|
|
320
|
+
get currentTime(): number;
|
|
321
|
+
get isPlaying(): boolean;
|
|
322
|
+
play(): void;
|
|
323
|
+
pause(): void;
|
|
324
|
+
/** Stops playback, rewinds to `0 ms`, and hides the view if `hideWhenPaused` is enabled. */
|
|
325
|
+
reset(): void;
|
|
326
|
+
/** Shows the picture at `ms` (wrapped into the loop when looping). */
|
|
327
|
+
seek(ms: number): void;
|
|
328
|
+
setSpeed(speed: number): void;
|
|
329
|
+
/**
|
|
330
|
+
* Plays to the end (`true`) or back to the start (`false`) from wherever it
|
|
331
|
+
* is: what a hover or press trigger does, for hosts that drive it themselves
|
|
332
|
+
* (a hovered card, a focused button).
|
|
333
|
+
*/
|
|
334
|
+
setActive(active: boolean): void;
|
|
335
|
+
/**
|
|
336
|
+
* Plays the picture's next step (what a click trigger does): steps 1, 2, …
|
|
337
|
+
* in turn, then step 1 again, so a picture whose last step leads back to
|
|
338
|
+
* how it started toggles; one with no steps plays again from the start.
|
|
339
|
+
*/
|
|
340
|
+
advance(): void;
|
|
341
|
+
dispose(): void;
|
|
342
|
+
private onEnter;
|
|
343
|
+
private onLeave;
|
|
344
|
+
private onClick;
|
|
345
|
+
private listen;
|
|
346
|
+
private run;
|
|
347
|
+
}
|
|
348
|
+
interface AnimateCountOptions {
|
|
349
|
+
/** Starting number. */
|
|
350
|
+
from: number;
|
|
351
|
+
/** Ending number. */
|
|
352
|
+
to: number;
|
|
353
|
+
/** Duration in ms (default {@link STEP_MS}). */
|
|
354
|
+
ms?: number;
|
|
355
|
+
/** Delay before starting in ms (default 0). */
|
|
356
|
+
delay?: number;
|
|
357
|
+
/** Easing curve (default `"out"`). */
|
|
358
|
+
ease?: EaseName;
|
|
359
|
+
/** Number of decimal places (default 0). */
|
|
360
|
+
decimals?: number;
|
|
361
|
+
/** Format template where `{n}` is replaced by the formatted number (default `"{n}"`). */
|
|
362
|
+
format?: string;
|
|
363
|
+
/** Time source (default: animation frames). */
|
|
364
|
+
clock?: Clock;
|
|
365
|
+
/** Called with each formatted text frame (and raw numeric value). */
|
|
366
|
+
onUpdate: (text: string, value: number) => void;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Counts a number from `from` to `to` over `ms` using Flair's easing curves
|
|
370
|
+
* and `Clock`, calling `onUpdate` with the formatted string on each frame.
|
|
371
|
+
* Returns a cancel function that stops the animation.
|
|
372
|
+
*/
|
|
373
|
+
declare function animateCount(options: AnimateCountOptions): () => void;
|
|
374
|
+
|
|
375
|
+
export { type AnimateCountOptions as A, svgMotionIssues as B, type Clock as C, type DataKey as D, EASES as E, svgOpeningTag as F, svgView as G, writtenText as H, ManualClock as M, type SvgMotion as S, type SvgTrigger as a, type EaseName as b, SCRAMBLE_MS as c, STEP_MS as d, SVG_PICTURE as e, type SvgAnimation as f, type SvgBox as g, type SvgElementFrame as h, SvgPlayer as i, type SvgPlayerOptions as j, type SvgView as k, type SvgViewOptions as l, animateCount as m, defaultDataKey as n, formatCount as o, jitter as p, lerpAttr as q, lerpData as r, pageHidden as s, parseSvg as t, realClock as u, stepData as v, stepProgress as w, stepStart as x, svgDuration as y, svgFrame as z };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { C as ControlValue, a as ControlDef } from './controls-Syr6drzO.js';
|
|
2
|
-
import { S as SvgMotion } from './
|
|
2
|
+
import { S as SvgMotion, a as SvgTrigger } from './svg-CpeanaE_.js';
|
|
3
3
|
|
|
4
4
|
/** What an effect is for, used to group the catalog. */
|
|
5
|
-
type EffectCategory = "gradient" | "organic" | "pattern" | "light" | "space" | "retro" | "image" | "overlay" | "text" | "transition" | "loader" | "data" | "icon";
|
|
5
|
+
type EffectCategory = "gradient" | "organic" | "pattern" | "light" | "space" | "retro" | "image" | "overlay" | "text" | "morph" | "interaction" | "transition" | "loader" | "data" | "icon";
|
|
6
6
|
/** Every category, in the order the catalog lists them. */
|
|
7
7
|
declare const EFFECT_CATEGORIES: readonly EffectCategory[];
|
|
8
8
|
/** Named control values: a look an effect can be switched to. */
|
|
@@ -67,6 +67,12 @@ interface VectorEffect extends EffectBase {
|
|
|
67
67
|
derived?: (values: Record<string, ControlValue>) => Record<string, string | number>;
|
|
68
68
|
/** Ms to rest on the last frame before it loops (default 600). */
|
|
69
69
|
hold?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Plays in answer to the pointer rather than on a loop: pass it to
|
|
72
|
+
* `SvgPlayer` (`{ trigger: effect.trigger }`). Click-triggered pictures
|
|
73
|
+
* change on steps, each click playing the next.
|
|
74
|
+
*/
|
|
75
|
+
trigger?: SvgTrigger;
|
|
70
76
|
}
|
|
71
77
|
type EffectDefinition = ShaderEffect | VectorEffect;
|
|
72
78
|
/** The types a vector effect's `{{name: type …}}` placeholder can declare. */
|
package/dist/vector/index.d.ts
CHANGED
|
@@ -1,121 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
export { D as DataKey, E as EASES, b as SCRAMBLE_MS, c as STEP_MS, d as SVG_PICTURE, e as SvgAnimation, f as SvgBox, g as SvgElementFrame, h as defaultDataKey, i as formatCount, l as lerpAttr, j as lerpData, s as stepData, k as stepProgress, m as stepStart, n as svgFrame, o as svgMotionIssues, p as svgOpeningTag, w as writtenText } from '../motion-Ce0lmzm3.js';
|
|
3
|
-
import { C as Clock } from '../clock-BhdXWH-n.js';
|
|
1
|
+
export { A as AnimateCountOptions, D as DataKey, E as EASES, b as EaseName, c as SCRAMBLE_MS, d as STEP_MS, e as SVG_PICTURE, f as SvgAnimation, g as SvgBox, h as SvgElementFrame, S as SvgMotion, i as SvgPlayer, j as SvgPlayerOptions, a as SvgTrigger, k as SvgView, l as SvgViewOptions, m as animateCount, n as defaultDataKey, o as formatCount, q as lerpAttr, r as lerpData, t as parseSvg, v as stepData, w as stepProgress, x as stepStart, y as svgDuration, z as svgFrame, B as svgMotionIssues, F as svgOpeningTag, G as svgView, H as writtenText } from '../svg-CpeanaE_.js';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Shape morphing: any SVG paths turned into paths with the same structure, so
|
|
5
|
+
* an `attrs` change on `d` (see `SvgAnimation`) blends one into the other
|
|
6
|
+
* point by point. Pure functions of their arguments, with no DOM.
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*/
|
|
15
|
-
declare function parseSvg(markup: string): SVGSVGElement | undefined;
|
|
16
|
-
interface SvgViewOptions {
|
|
17
|
-
/** Called with the id of the innermost element with an id that is clicked. */
|
|
18
|
-
onPick?: (id: string) => void;
|
|
19
|
-
}
|
|
20
|
-
/** An {@link SvgMotion} drawn into an element; call `draw` with a time to show it then. */
|
|
21
|
-
interface SvgView {
|
|
22
|
-
/** A `div` filled by the picture; put it anywhere. */
|
|
23
|
-
readonly element: HTMLDivElement;
|
|
24
|
-
/** Shows the picture at `timeMs`, with steps starting at `steps` (ms). */
|
|
25
|
-
draw(timeMs: number, steps?: readonly number[]): void;
|
|
26
|
-
/** An image of the picture as drawn now. */
|
|
27
|
-
capture(pixels: {
|
|
28
|
-
width: number;
|
|
29
|
-
height: number;
|
|
30
|
-
}): Promise<HTMLCanvasElement | undefined>;
|
|
31
|
-
}
|
|
32
|
-
/** Shows an {@link SvgMotion} as a live view; with `onPick`, clicks report the id of the element clicked. */
|
|
33
|
-
declare function svgView(motion: SvgMotion, options?: SvgViewOptions): SvgView;
|
|
34
|
-
/** How long an {@link SvgMotion} runs: its last change's end, in ms (at least 1). */
|
|
35
|
-
declare function svgDuration(motion: SvgMotion, steps?: readonly number[]): number;
|
|
36
|
-
interface SvgPlayerOptions extends SvgViewOptions {
|
|
37
|
-
/** Time source (default: animation frames). Pass a `ManualClock` to step frames yourself. */
|
|
38
|
-
clock?: Clock;
|
|
39
|
-
/** Start playing at once (default `true`). */
|
|
40
|
-
autoplay?: boolean;
|
|
41
|
-
/** Start again at the end (default `true`). */
|
|
42
|
-
loop?: boolean;
|
|
43
|
-
/** Loop length in ms (default: the picture's own, see {@link svgDuration}, plus `hold`). */
|
|
44
|
-
duration?: number;
|
|
45
|
-
/** Ms to rest on the last frame before looping (default 600). */
|
|
46
|
-
hold?: number;
|
|
47
|
-
/** Playback speed (default 1). */
|
|
48
|
-
speed?: number;
|
|
49
|
-
/** Step start times in ms, for pictures that change on steps (default none). */
|
|
50
|
-
steps?: readonly number[];
|
|
51
|
-
/** Pause the animation loop when scrolled out of view via IntersectionObserver (default false). */
|
|
52
|
-
pauseWhenHidden?: boolean;
|
|
53
|
-
/** Wait to start playing until the element enters the viewport via IntersectionObserver (default false). When true, autoplay is deferred until first visible. */
|
|
54
|
-
playOnEnter?: boolean;
|
|
55
|
-
/** Hide the view (`visibility: hidden`) whenever playback is paused or reset (default false). */
|
|
56
|
-
hideWhenPaused?: boolean;
|
|
8
|
+
interface MorphOptions {
|
|
9
|
+
/** Points per piece of the shape (default 72): more follows curves more closely. */
|
|
10
|
+
points?: number;
|
|
11
|
+
/** Decimals in the numbers written (default 2). */
|
|
12
|
+
decimals?: number;
|
|
57
13
|
}
|
|
58
14
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
15
|
+
* Paths with one structure for a sequence of shapes, so each blends into the
|
|
16
|
+
* next (and the last into the first) with `attrs: { d: [a, b] }`. Any path
|
|
17
|
+
* commands work, curves and arcs included, and shapes can have different
|
|
18
|
+
* numbers of pieces (an icon's parts, a letter's holes): pieces are paired by
|
|
19
|
+
* position and size, and one without a partner grows from or shrinks to a
|
|
20
|
+
* point. Draw the results with `fill-rule="evenodd"`, since a piece's
|
|
21
|
+
* direction can change. Throws a sentence when a path cannot be read.
|
|
61
22
|
*/
|
|
62
|
-
declare
|
|
63
|
-
private readonly container;
|
|
64
|
-
readonly view: SvgView;
|
|
65
|
-
private readonly clock;
|
|
66
|
-
private readonly steps;
|
|
67
|
-
private readonly loop;
|
|
68
|
-
private readonly length;
|
|
69
|
-
private readonly hideWhenPaused;
|
|
70
|
-
private speed;
|
|
71
|
-
private time;
|
|
72
|
-
private last;
|
|
73
|
-
private playing;
|
|
74
|
-
private disposed;
|
|
75
|
-
private wasPlayingBeforeHidden;
|
|
76
|
-
private hasEnteredViewport;
|
|
77
|
-
private intersectionObserver?;
|
|
78
|
-
constructor(container: HTMLElement, motion: SvgMotion, options?: SvgPlayerOptions);
|
|
79
|
-
/** The loop length in ms. */
|
|
80
|
-
get duration(): number;
|
|
81
|
-
/** The time shown, in ms. */
|
|
82
|
-
get currentTime(): number;
|
|
83
|
-
get isPlaying(): boolean;
|
|
84
|
-
play(): void;
|
|
85
|
-
pause(): void;
|
|
86
|
-
/** Stops playback, rewinds to `0 ms`, and hides the view if `hideWhenPaused` is enabled. */
|
|
87
|
-
reset(): void;
|
|
88
|
-
/** Shows the picture at `ms` (wrapped into the loop when looping). */
|
|
89
|
-
seek(ms: number): void;
|
|
90
|
-
setSpeed(speed: number): void;
|
|
91
|
-
dispose(): void;
|
|
92
|
-
private run;
|
|
93
|
-
}
|
|
94
|
-
interface AnimateCountOptions {
|
|
95
|
-
/** Starting number. */
|
|
96
|
-
from: number;
|
|
97
|
-
/** Ending number. */
|
|
98
|
-
to: number;
|
|
99
|
-
/** Duration in ms (default {@link STEP_MS}). */
|
|
100
|
-
ms?: number;
|
|
101
|
-
/** Delay before starting in ms (default 0). */
|
|
102
|
-
delay?: number;
|
|
103
|
-
/** Easing curve (default `"out"`). */
|
|
104
|
-
ease?: EaseName;
|
|
105
|
-
/** Number of decimal places (default 0). */
|
|
106
|
-
decimals?: number;
|
|
107
|
-
/** Format template where `{n}` is replaced by the formatted number (default `"{n}"`). */
|
|
108
|
-
format?: string;
|
|
109
|
-
/** Time source (default: animation frames). */
|
|
110
|
-
clock?: Clock;
|
|
111
|
-
/** Called with each formatted text frame (and raw numeric value). */
|
|
112
|
-
onUpdate: (text: string, value: number) => void;
|
|
113
|
-
}
|
|
23
|
+
declare function morphSequence(paths: readonly string[], options?: MorphOptions): string[];
|
|
114
24
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* Returns a cancel function that stops the animation.
|
|
25
|
+
* Two paths turned into paths with one structure, so `attrs: { d: [from, to] }`
|
|
26
|
+
* blends one into the other (see {@link morphSequence}).
|
|
118
27
|
*/
|
|
119
|
-
declare function
|
|
28
|
+
declare function morphPaths(from: string, to: string, options?: MorphOptions): [string, string];
|
|
120
29
|
|
|
121
|
-
export { type
|
|
30
|
+
export { type MorphOptions, morphPaths, morphSequence };
|
package/dist/vector/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-P5TSANZY.js";
|
|
2
2
|
import {
|
|
3
3
|
EASES,
|
|
4
4
|
SCRAMBLE_MS,
|
|
@@ -20,7 +20,11 @@ import {
|
|
|
20
20
|
svgOpeningTag,
|
|
21
21
|
svgView,
|
|
22
22
|
writtenText
|
|
23
|
-
} from "../chunk-
|
|
23
|
+
} from "../chunk-YACVME3D.js";
|
|
24
|
+
import {
|
|
25
|
+
morphPaths,
|
|
26
|
+
morphSequence
|
|
27
|
+
} from "../chunk-OHW7UG6D.js";
|
|
24
28
|
import "../chunk-WMZQCUFJ.js";
|
|
25
29
|
export {
|
|
26
30
|
EASES,
|
|
@@ -33,6 +37,8 @@ export {
|
|
|
33
37
|
formatCount,
|
|
34
38
|
lerpAttr,
|
|
35
39
|
lerpData,
|
|
40
|
+
morphPaths,
|
|
41
|
+
morphSequence,
|
|
36
42
|
parseSvg,
|
|
37
43
|
stepData,
|
|
38
44
|
stepProgress,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/flair",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Web visual effects and motion graphics: WebGL2 shader effects, animated vector effects, a catalog of ready-made effects, and a UI-agnostic, agent-ready effect editor.",
|
|
5
5
|
"author": "Pixerate",
|
|
6
6
|
"license": "MIT",
|
package/dist/chunk-CFCLT2XL.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=chunk-CFCLT2XL.js.map
|