coily 0.14.0 → 0.16.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/README.md +133 -51
- package/dist/config-B8M2xp26.d.ts +295 -0
- package/dist/css.d.ts +203 -0
- package/dist/css.js +318 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +99 -53
- package/dist/nuxt.d.ts +24 -15
- package/dist/nuxt.js +16 -5
- package/dist/solver-CAXuxdKj.js +243 -0
- package/dist/system-C7PbI4L0.d.ts +1213 -0
- package/dist/system-WejqGkfv.js +2920 -0
- package/dist/vue.d.ts +224 -128
- package/dist/vue.js +161 -41
- package/package.json +2 -1
- package/dist/system-BXxAHM2a.js +0 -1758
- package/dist/system-Ci-R4RaI.d.ts +0 -1032
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
//#region src/config.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A spring's instantaneous motion, measured relative to its target.
|
|
4
|
+
* `SpringDefinition.computeTimeRemaining` takes one. Build it from a live
|
|
5
|
+
* spring as `{ position: spring.value - spring.target, velocity: spring.velocity }`.
|
|
6
|
+
*/
|
|
7
|
+
interface SpringState {
|
|
8
|
+
/** Displacement from the target in value units. 0 means at the target. */
|
|
9
|
+
readonly position: number;
|
|
10
|
+
/** Rate of change of the displacement, in value units per second. */
|
|
11
|
+
readonly velocity: number;
|
|
12
|
+
}
|
|
13
|
+
interface BaseOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Decimal places of the resting threshold. A spring rests once its
|
|
16
|
+
* remaining motion fits within `0.5 * 10^-precision` (0.005 at the
|
|
17
|
+
* default). Values are never rounded.
|
|
18
|
+
*
|
|
19
|
+
* Duration configs are tuned against this threshold, so they rest at
|
|
20
|
+
* their `duration` at any precision. See
|
|
21
|
+
* https://github.com/tkofh/coily/blob/main/PRECISION.md.
|
|
22
|
+
*
|
|
23
|
+
* @default 2
|
|
24
|
+
*/
|
|
25
|
+
readonly precision?: number | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Velocity multiplier applied each time the value crosses the target.
|
|
28
|
+
*
|
|
29
|
+
* - `'passthrough'` (1) leaves the motion alone. The value swings
|
|
30
|
+
* through the target and settles as its damping allows.
|
|
31
|
+
* - `'stop'` (0) ends the motion at the first crossing, with no
|
|
32
|
+
* overshoot however bouncy the config.
|
|
33
|
+
* - A number between -1 and 1 sets the multiplier directly. Negative
|
|
34
|
+
* values rebound. `-0.75` reverses at three quarters speed on every
|
|
35
|
+
* return. Values between 0 and 1 pass through slower.
|
|
36
|
+
*
|
|
37
|
+
* A motion that never crosses ignores `arrival`. With `dampingRatio` 1
|
|
38
|
+
* or above (`bounce` 0 or below), a spring retargeted from rest closes
|
|
39
|
+
* in from one side. It crosses only when it starts with enough velocity
|
|
40
|
+
* toward the target, or when the target moves past it.
|
|
41
|
+
*
|
|
42
|
+
* Crossings are solved exactly, never sampled per frame, so `'stop'`
|
|
43
|
+
* lands exactly on the target at any frame timing. See
|
|
44
|
+
* https://github.com/tkofh/coily/blob/main/PRECISION.md.
|
|
45
|
+
*
|
|
46
|
+
* @default 'passthrough'
|
|
47
|
+
*/
|
|
48
|
+
readonly arrival?: 'passthrough' | 'stop' | number | undefined;
|
|
49
|
+
}
|
|
50
|
+
interface WithMass {
|
|
51
|
+
/**
|
|
52
|
+
* Mass of the moving value. Heavier springs accelerate more slowly and
|
|
53
|
+
* carry more momentum through the target. Must be greater than 0.
|
|
54
|
+
* @default 1
|
|
55
|
+
*/
|
|
56
|
+
readonly mass?: number | undefined;
|
|
57
|
+
}
|
|
58
|
+
interface WithoutMass {
|
|
59
|
+
/** Derived from the other parameters in this input shape. Cannot be provided. */
|
|
60
|
+
readonly mass?: undefined;
|
|
61
|
+
}
|
|
62
|
+
interface WithTension {
|
|
63
|
+
/**
|
|
64
|
+
* Spring stiffness. Higher tension pulls toward the target harder,
|
|
65
|
+
* making the whole motion faster. Must be greater than 0.
|
|
66
|
+
*/
|
|
67
|
+
readonly tension: number;
|
|
68
|
+
}
|
|
69
|
+
interface WithDamping {
|
|
70
|
+
/**
|
|
71
|
+
* Friction strength. Higher damping removes velocity faster and
|
|
72
|
+
* reduces bounce. At 0 the spring oscillates forever. Must be greater
|
|
73
|
+
* than or equal to 0.
|
|
74
|
+
*/
|
|
75
|
+
readonly damping: number;
|
|
76
|
+
}
|
|
77
|
+
interface WithDampingRatio {
|
|
78
|
+
/**
|
|
79
|
+
* Damping as a fraction of critical damping, the friction at which
|
|
80
|
+
* bounce disappears. It sets the motion's character independent of its
|
|
81
|
+
* speed. Below 1 the spring bounces, and at 0 it never settles. At 1 it
|
|
82
|
+
* settles fastest without overshooting. Above 1 it settles slower, still
|
|
83
|
+
* without overshooting. Must be greater than or equal to 0.
|
|
84
|
+
*/
|
|
85
|
+
readonly dampingRatio: number;
|
|
86
|
+
}
|
|
87
|
+
interface WithBounce {
|
|
88
|
+
/**
|
|
89
|
+
* Bounciness, converted to a damping ratio as `1 - bounce`. 0 settles
|
|
90
|
+
* fastest without overshooting. Positive values bounce. Negative values
|
|
91
|
+
* settle slower without bouncing. At 1 the ratio clamps just short of
|
|
92
|
+
* undamped, so the spring still settles. Must be between -1 and 1, and
|
|
93
|
+
* below 1 in a config that sets `damping` without `duration`.
|
|
94
|
+
*/
|
|
95
|
+
readonly bounce: number;
|
|
96
|
+
}
|
|
97
|
+
interface WithDuration {
|
|
98
|
+
/**
|
|
99
|
+
* Settle time in ms. Starting `displacement` away from the target, the
|
|
100
|
+
* spring rests within a frame of it at any `precision`. A bouncy config
|
|
101
|
+
* can rest earlier, by up to about one oscillation (several short ones
|
|
102
|
+
* when `bounce` is near 1). Must be greater than 0.
|
|
103
|
+
*/
|
|
104
|
+
readonly duration: number;
|
|
105
|
+
}
|
|
106
|
+
interface WithDisplacement {
|
|
107
|
+
/**
|
|
108
|
+
* The starting distance from the target that the `duration` tuning
|
|
109
|
+
* assumes. Set it to your animation's range (300 when animating 0 to
|
|
110
|
+
* 300). Timing drifts as the real distance departs from it. The sign is
|
|
111
|
+
* ignored. The magnitude must exceed the resting threshold,
|
|
112
|
+
* `0.5 * 10^-precision`.
|
|
113
|
+
* @default 1
|
|
114
|
+
*/
|
|
115
|
+
readonly displacement?: number | undefined;
|
|
116
|
+
}
|
|
117
|
+
interface DirectOptions extends BaseOptions, WithMass, WithTension, WithDamping {}
|
|
118
|
+
interface TensionRatioOptions extends BaseOptions, WithMass, WithTension, WithDampingRatio {}
|
|
119
|
+
interface TensionBounceOptions extends BaseOptions, WithMass, WithTension, WithBounce {}
|
|
120
|
+
interface DampingRatioOptions extends BaseOptions, WithMass, WithDamping, WithDampingRatio {}
|
|
121
|
+
interface DampingBounceOptions extends BaseOptions, WithMass, WithDamping, WithBounce {}
|
|
122
|
+
interface TensionDampingRatioOptions extends BaseOptions, WithoutMass, WithTension, WithDamping, WithDampingRatio {}
|
|
123
|
+
interface TensionDampingBounceOptions extends BaseOptions, WithoutMass, WithTension, WithDamping, WithBounce {}
|
|
124
|
+
interface DurationOptions extends BaseOptions, WithMass, WithDampingRatio, WithDuration, WithDisplacement {}
|
|
125
|
+
interface BounceDurationOptions extends BaseOptions, WithMass, WithBounce, WithDuration, WithDisplacement {}
|
|
126
|
+
interface TensionDurationOptions extends BaseOptions, WithoutMass, WithTension, WithDampingRatio, WithDuration, WithDisplacement {}
|
|
127
|
+
interface TensionBounceDurationOptions extends BaseOptions, WithoutMass, WithTension, WithBounce, WithDuration, WithDisplacement {}
|
|
128
|
+
interface DampingDurationOptions extends BaseOptions, WithoutMass, WithDamping, WithDampingRatio, WithDuration, WithDisplacement {}
|
|
129
|
+
interface DampingBounceDurationOptions extends BaseOptions, WithoutMass, WithDamping, WithBounce, WithDuration, WithDisplacement {}
|
|
130
|
+
/** Every option key accepted by at least one `defineSpring` input shape. */
|
|
131
|
+
type SpringOptionKeys = 'mass' | 'tension' | 'damping' | 'dampingRatio' | 'bounce' | 'duration' | 'displacement' | 'precision' | 'arrival';
|
|
132
|
+
/**
|
|
133
|
+
* Marks every option key foreign to `T` as absent or undefined, so mixing
|
|
134
|
+
* keys from different input shapes fails to type-check.
|
|
135
|
+
*/
|
|
136
|
+
type Exact<T> = T & { [K in Exclude<SpringOptionKeys, keyof T>]?: undefined; };
|
|
137
|
+
/**
|
|
138
|
+
* Every input `defineSpring` accepts: one of the documented parameter
|
|
139
|
+
* combinations, with no keys mixed in from another.
|
|
140
|
+
*/
|
|
141
|
+
type SpringDefinitionOptions = Exact<DirectOptions> | Exact<TensionRatioOptions> | Exact<TensionBounceOptions> | Exact<DampingRatioOptions> | Exact<DampingBounceOptions> | Exact<TensionDampingRatioOptions> | Exact<TensionDampingBounceOptions> | Exact<DurationOptions> | Exact<BounceDurationOptions> | Exact<TensionDurationOptions> | Exact<TensionBounceDurationOptions> | Exact<DampingDurationOptions> | Exact<DampingBounceDurationOptions>;
|
|
142
|
+
/**
|
|
143
|
+
* Resolved spring parameters, frozen and safe to share between springs.
|
|
144
|
+
* Whatever `defineSpring` input shape produced it, a config has concrete
|
|
145
|
+
* `mass`, `tension`, `damping`, `precision`, and `arrival`, plus the
|
|
146
|
+
* quantities derived from them. To change a spring's behavior, assign a
|
|
147
|
+
* new config to `spring.config`.
|
|
148
|
+
*/
|
|
149
|
+
declare class SpringDefinition {
|
|
150
|
+
/** The config for springs created without one: critically damped, settling in about 500ms. */
|
|
151
|
+
static readonly default: SpringDefinition;
|
|
152
|
+
/** Mass of the moving value, as provided or derived. */
|
|
153
|
+
readonly mass: number;
|
|
154
|
+
/** Spring stiffness, as provided or derived. */
|
|
155
|
+
readonly tension: number;
|
|
156
|
+
/** Friction strength, as provided or derived. */
|
|
157
|
+
readonly damping: number;
|
|
158
|
+
/** Decimal places of the resting threshold. See `restingMagnitude`. */
|
|
159
|
+
readonly precision: number;
|
|
160
|
+
/**
|
|
161
|
+
* Velocity multiplier applied each time the value crosses the target.
|
|
162
|
+
* `'passthrough'` resolves to 1, which leaves the motion untouched.
|
|
163
|
+
* `'stop'` resolves to 0, which ends it at the target. Negative values
|
|
164
|
+
* rebound.
|
|
165
|
+
*/
|
|
166
|
+
readonly arrival: number;
|
|
167
|
+
/** Oscillation rate with no damping: `sqrt(tension / mass)`, in radians per second. */
|
|
168
|
+
readonly naturalFrequency: number;
|
|
169
|
+
/** The damping at which bounce disappears: `2 * mass * naturalFrequency`. */
|
|
170
|
+
readonly criticalDamping: number;
|
|
171
|
+
/**
|
|
172
|
+
* `damping / criticalDamping`. Below 1 the spring bounces. At 1 it
|
|
173
|
+
* settles fastest without overshooting. Above 1 it settles slower.
|
|
174
|
+
*/
|
|
175
|
+
readonly dampingRatio: number;
|
|
176
|
+
/** Resting threshold in value units, `0.5 * 10^-precision`. */
|
|
177
|
+
readonly restingMagnitude: number;
|
|
178
|
+
constructor(input: SpringDefinitionOptions);
|
|
179
|
+
/**
|
|
180
|
+
* Computes the time in ms until a spring with this config rests from
|
|
181
|
+
* `state`, solved exactly from the motion's decay bound. The spring
|
|
182
|
+
* rests at the first tick at or after it.
|
|
183
|
+
*
|
|
184
|
+
* An underdamped spring can also rest earlier, on a frame that samples
|
|
185
|
+
* a dip in its pulsing rest amplitude, so read the result as "no later
|
|
186
|
+
* than". The motion an early rest cuts off never leaves the resting
|
|
187
|
+
* threshold. See https://github.com/tkofh/coily/blob/main/PRECISION.md.
|
|
188
|
+
*
|
|
189
|
+
* Returns 0 when `state` is already inside the resting threshold.
|
|
190
|
+
* Returns Infinity when the motion never settles: a `dampingRatio` of 0
|
|
191
|
+
* whose `arrival` neither stops nor slows it. With `arrival` 0, the
|
|
192
|
+
* result is capped at the first target crossing, where the spring rests
|
|
193
|
+
* exactly. Other multipliers fold their per-crossing velocity loss into
|
|
194
|
+
* the time.
|
|
195
|
+
*/
|
|
196
|
+
computeTimeRemaining(state: SpringState): number;
|
|
197
|
+
}
|
|
198
|
+
/** Creates a config with stiffness (`tension`) and friction (`damping`) set directly. */
|
|
199
|
+
declare function defineSpring(input: Exact<DirectOptions>): SpringDefinition;
|
|
200
|
+
/**
|
|
201
|
+
* Creates a config from stiffness and motion character. Damping is
|
|
202
|
+
* derived as `2 * dampingRatio * sqrt(mass * tension)`.
|
|
203
|
+
*/
|
|
204
|
+
declare function defineSpring(input: Exact<TensionRatioOptions>): SpringDefinition;
|
|
205
|
+
/**
|
|
206
|
+
* Creates a config from stiffness and bounciness. Damping is derived to
|
|
207
|
+
* match the requested bounce, from -1 (no bounce, slow settle) to 1
|
|
208
|
+
* (maximum bounce).
|
|
209
|
+
*/
|
|
210
|
+
declare function defineSpring(input: Exact<TensionBounceOptions>): SpringDefinition;
|
|
211
|
+
/**
|
|
212
|
+
* Creates a config from friction and motion character. Tension is
|
|
213
|
+
* derived as `damping^2 / (4 * dampingRatio^2 * mass)`. `dampingRatio`
|
|
214
|
+
* must be greater than 0.
|
|
215
|
+
*/
|
|
216
|
+
declare function defineSpring(input: Exact<DampingRatioOptions>): SpringDefinition;
|
|
217
|
+
/**
|
|
218
|
+
* Creates a config from friction and bounciness, deriving tension.
|
|
219
|
+
* `bounce` must be less than 1, since the derived tension grows without
|
|
220
|
+
* limit as it nears 1.
|
|
221
|
+
*/
|
|
222
|
+
declare function defineSpring(input: Exact<DampingBounceOptions>): SpringDefinition;
|
|
223
|
+
/**
|
|
224
|
+
* Creates a config from all three physical parameters. Mass is derived
|
|
225
|
+
* as `damping^2 / (4 * dampingRatio^2 * tension)` and cannot be
|
|
226
|
+
* provided. `dampingRatio` must be greater than 0.
|
|
227
|
+
*/
|
|
228
|
+
declare function defineSpring(input: Exact<TensionDampingRatioOptions>): SpringDefinition;
|
|
229
|
+
/**
|
|
230
|
+
* Creates a config from tension, damping, and bounce. Mass is derived and
|
|
231
|
+
* cannot be provided. `bounce` must be less than 1, since the derived
|
|
232
|
+
* mass grows without limit as it nears 1.
|
|
233
|
+
*/
|
|
234
|
+
declare function defineSpring(input: Exact<TensionDampingBounceOptions>): SpringDefinition;
|
|
235
|
+
/**
|
|
236
|
+
* Tunes the spring to rest at `duration` ms, deriving tension and
|
|
237
|
+
* damping. `dampingRatio` sets the motion's character and must be
|
|
238
|
+
* greater than 0.
|
|
239
|
+
*
|
|
240
|
+
* The timing assumes the motion starts `displacement` (default 1) away
|
|
241
|
+
* from the target. Pass your animation's range for accurate timing.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```ts
|
|
245
|
+
* // Tuned for a 300px move. Rests within 750ms.
|
|
246
|
+
* defineSpring({ duration: 750, dampingRatio: 1, displacement: 300 })
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
declare function defineSpring(input: Exact<DurationOptions>): SpringDefinition;
|
|
250
|
+
/**
|
|
251
|
+
* Tunes the spring to rest at `duration` ms, deriving tension and
|
|
252
|
+
* damping. `bounce` sets how oscillatory the settling motion is.
|
|
253
|
+
*
|
|
254
|
+
* The timing assumes the motion starts `displacement` (default 1) away
|
|
255
|
+
* from the target. Pass your animation's range for accurate timing.
|
|
256
|
+
*/
|
|
257
|
+
declare function defineSpring(input: Exact<BounceDurationOptions>): SpringDefinition;
|
|
258
|
+
/**
|
|
259
|
+
* Tunes a spring of the given stiffness to rest at `duration` ms. Mass is
|
|
260
|
+
* derived to meet the timing, then damping from mass and `dampingRatio`.
|
|
261
|
+
* Mass cannot be provided, and `dampingRatio` must be greater than 0.
|
|
262
|
+
*
|
|
263
|
+
* The timing assumes the motion starts `displacement` (default 1) away
|
|
264
|
+
* from the target. Pass your animation's range for accurate timing.
|
|
265
|
+
*/
|
|
266
|
+
declare function defineSpring(input: Exact<TensionDurationOptions>): SpringDefinition;
|
|
267
|
+
/**
|
|
268
|
+
* Tunes a spring of the given stiffness to rest at `duration` ms, with
|
|
269
|
+
* `bounce` setting how oscillatory the settling motion is. Mass is
|
|
270
|
+
* derived to meet the timing and cannot be provided.
|
|
271
|
+
*
|
|
272
|
+
* The timing assumes the motion starts `displacement` (default 1) away
|
|
273
|
+
* from the target. Pass your animation's range for accurate timing.
|
|
274
|
+
*/
|
|
275
|
+
declare function defineSpring(input: Exact<TensionBounceDurationOptions>): SpringDefinition;
|
|
276
|
+
/**
|
|
277
|
+
* Tunes a spring of the given friction to rest at `duration` ms. Mass is
|
|
278
|
+
* derived to meet the timing, then tension from mass. Mass cannot be
|
|
279
|
+
* provided, and `dampingRatio` must be greater than 0.
|
|
280
|
+
*
|
|
281
|
+
* The timing assumes the motion starts `displacement` (default 1) away
|
|
282
|
+
* from the target. Pass your animation's range for accurate timing.
|
|
283
|
+
*/
|
|
284
|
+
declare function defineSpring(input: Exact<DampingDurationOptions>): SpringDefinition;
|
|
285
|
+
/**
|
|
286
|
+
* Tunes a spring of the given friction to rest at `duration` ms, with
|
|
287
|
+
* `bounce` setting how oscillatory the settling motion is. Mass is
|
|
288
|
+
* derived to meet the timing and cannot be provided.
|
|
289
|
+
*
|
|
290
|
+
* The timing assumes the motion starts `displacement` (default 1) away
|
|
291
|
+
* from the target. Pass your animation's range for accurate timing.
|
|
292
|
+
*/
|
|
293
|
+
declare function defineSpring(input: Exact<DampingBounceDurationOptions>): SpringDefinition;
|
|
294
|
+
//#endregion
|
|
295
|
+
export { defineSpring as i, SpringDefinitionOptions as n, SpringState as r, SpringDefinition as t };
|
package/dist/css.d.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { r as SpringState, t as SpringDefinition } from "./config-B8M2xp26.js";
|
|
2
|
+
//#region src/css.d.ts
|
|
3
|
+
interface LinearEasingOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The size of the move the easing is timed for, in value units. A larger
|
|
6
|
+
* move takes longer to come within the fixed rest threshold, so it gets a
|
|
7
|
+
* longer duration, different `linear()` stop percentages, and possibly a
|
|
8
|
+
* different stop count. The keyframe helpers (`springToWaapi`,
|
|
9
|
+
* `springToCss`, `springToTransition`) default it to the largest move
|
|
10
|
+
* among their specs.
|
|
11
|
+
* @default 1
|
|
12
|
+
*/
|
|
13
|
+
readonly displacement?: number;
|
|
14
|
+
/**
|
|
15
|
+
* The largest output error allowed in the piecewise-linear
|
|
16
|
+
* approximation, in progress units (0 at the start, 1 at the target). A
|
|
17
|
+
* smaller value keeps more stops.
|
|
18
|
+
* @default 0.0025
|
|
19
|
+
*/
|
|
20
|
+
readonly maxError?: number;
|
|
21
|
+
/**
|
|
22
|
+
* The longest duration to generate, in ms. It cuts off configs with so
|
|
23
|
+
* little damping (friction) that they take very long to settle. A
|
|
24
|
+
* `'loop'` easing ignores the cap and lasts one half period.
|
|
25
|
+
* @default 10000
|
|
26
|
+
*/
|
|
27
|
+
readonly maxDuration?: number;
|
|
28
|
+
}
|
|
29
|
+
interface EasingBase {
|
|
30
|
+
/** A CSS `linear()` easing string. */
|
|
31
|
+
readonly easing: string;
|
|
32
|
+
/** Duration to pair the easing with, in ms. */
|
|
33
|
+
readonly duration: number;
|
|
34
|
+
/** Number of stops in the easing (diagnostic). */
|
|
35
|
+
readonly stops: number;
|
|
36
|
+
/** The largest error of `easing` against the dense samples (diagnostic). */
|
|
37
|
+
readonly maxError: number;
|
|
38
|
+
}
|
|
39
|
+
/** The easing of a spring that comes to rest: play it once over `duration`. */
|
|
40
|
+
interface SettlingEasing extends EasingBase {
|
|
41
|
+
readonly mode: 'settle';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The easing of a spring that never rests: an undamped oscillation (no
|
|
45
|
+
* friction), expressed as an infinite loop. Animate the property between
|
|
46
|
+
* its two swing extremes, `from` and `2 * target - from`, with the target
|
|
47
|
+
* at the 50% midpoint. Use `animation-iteration-count: infinite` and
|
|
48
|
+
* `animation-direction: alternate`. `duration` is one half period, in ms.
|
|
49
|
+
*/
|
|
50
|
+
interface LoopingEasing extends EasingBase {
|
|
51
|
+
readonly mode: 'loop';
|
|
52
|
+
readonly direction: 'alternate';
|
|
53
|
+
readonly iterations: 'infinite';
|
|
54
|
+
}
|
|
55
|
+
type LinearEasing = SettlingEasing | LoopingEasing;
|
|
56
|
+
/**
|
|
57
|
+
* Turns a spring config into a CSS `linear()` easing and the duration in
|
|
58
|
+
* ms to pair it with. A settling config returns a `'settle'` easing. A
|
|
59
|
+
* pure undamped config (`dampingRatio: 0` with passthrough `arrival`)
|
|
60
|
+
* never settles and returns a `'loop'` easing for an infinite alternating
|
|
61
|
+
* animation. Any other config that never settles, such as
|
|
62
|
+
* `dampingRatio: 0` with `arrival: -1`, returns a `'settle'` easing cut
|
|
63
|
+
* off at `maxDuration`.
|
|
64
|
+
*/
|
|
65
|
+
declare function springToLinear(config: SpringDefinition, options?: LinearEasingOptions): LinearEasing;
|
|
66
|
+
/**
|
|
67
|
+
* Like `springToLinear`, but for a spring caught mid-flight. `state`
|
|
68
|
+
* carries the displacement from the target (`position`) and the current
|
|
69
|
+
* `velocity`, so the easing continues the motion instead of restarting it.
|
|
70
|
+
* Use it to regenerate an animation when its target changes. The curve
|
|
71
|
+
* depends on the velocity, so compute it per interruption instead of
|
|
72
|
+
* caching it per config.
|
|
73
|
+
*
|
|
74
|
+
* The result is always a `'settle'` easing, timed from `position`, so
|
|
75
|
+
* `options.displacement` is ignored. A config that never settles is cut
|
|
76
|
+
* off at `maxDuration`. Throws when `position` is 0 (within 1e-9), even if
|
|
77
|
+
* `velocity` is not.
|
|
78
|
+
*/
|
|
79
|
+
declare function springFromState(config: SpringDefinition, state: SpringState, options?: LinearEasingOptions): LinearEasing;
|
|
80
|
+
/**
|
|
81
|
+
* Advances a spring `state` by `elapsedMs` ms and returns the new
|
|
82
|
+
* displacement and velocity. `elapsedMs <= 0` returns a copy of `state`.
|
|
83
|
+
*
|
|
84
|
+
* The Web Animations API doesn't expose velocity, so to interrupt a running
|
|
85
|
+
* `element.animate`, advance the state it started from by its `currentTime`
|
|
86
|
+
* and hand the result to `springFromState`.
|
|
87
|
+
*/
|
|
88
|
+
declare function springStateAt(config: SpringDefinition, state: SpringState, elapsedMs: number): SpringState;
|
|
89
|
+
/** What to animate: a CSS property from one numeric value to another. */
|
|
90
|
+
interface PropertySpec {
|
|
91
|
+
/** The CSS property, for example `'opacity'`, `'transform'`, or `'translate'`. */
|
|
92
|
+
readonly property: string;
|
|
93
|
+
/** The start value. */
|
|
94
|
+
readonly from: number;
|
|
95
|
+
/** The target value. */
|
|
96
|
+
readonly to: number;
|
|
97
|
+
/**
|
|
98
|
+
* Unit appended to numbers, for example `'px'`, `'%'`, or `'deg'`.
|
|
99
|
+
* @default ''
|
|
100
|
+
*/
|
|
101
|
+
readonly unit?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Formats an interpolated number into a property value, overriding
|
|
104
|
+
* `unit`. Use it for values that wrap the number, such as
|
|
105
|
+
* ``(v) => `translateX(${v}px)` ``.
|
|
106
|
+
*/
|
|
107
|
+
readonly format?: (value: number) => string;
|
|
108
|
+
/**
|
|
109
|
+
* The property's current velocity, in its units per second. Set it to
|
|
110
|
+
* regenerate an interrupted animation with its momentum instead of from
|
|
111
|
+
* rest. A spec with a nonzero velocity must be the only spec in the call,
|
|
112
|
+
* or the call throws.
|
|
113
|
+
*/
|
|
114
|
+
readonly velocity?: number;
|
|
115
|
+
}
|
|
116
|
+
interface CssOptions extends LinearEasingOptions {
|
|
117
|
+
/**
|
|
118
|
+
* Name for the generated `@keyframes` rule.
|
|
119
|
+
* @default 'coily'
|
|
120
|
+
*/
|
|
121
|
+
readonly name?: string;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Builds arguments for `element.animate(keyframes, options)`: two keyframes
|
|
125
|
+
* carrying the endpoint values, and options carrying the spring's `linear()`
|
|
126
|
+
* easing and duration. Pass an array of specs to drive several properties
|
|
127
|
+
* from one spring. A settling spring fills forwards. An undamped one repeats
|
|
128
|
+
* infinitely in alternating directions.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* const { keyframes, options } = springToWaapi(config, {
|
|
133
|
+
* property: 'translate',
|
|
134
|
+
* from: 0,
|
|
135
|
+
* to: 300,
|
|
136
|
+
* unit: 'px',
|
|
137
|
+
* })
|
|
138
|
+
* element.animate(keyframes, options)
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
declare function springToWaapi(config: SpringDefinition, spec: PropertySpec | PropertySpec[], options?: LinearEasingOptions): {
|
|
142
|
+
keyframes: Keyframe[];
|
|
143
|
+
options: KeyframeAnimationOptions;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Builds CSS text for the animation: a `@keyframes` rule named by `name`
|
|
147
|
+
* (default `'coily'`) and an `animation` shorthand value that references
|
|
148
|
+
* it, driving one property or several from one spring. A settling spring
|
|
149
|
+
* fills forwards. An undamped one repeats infinitely in alternating
|
|
150
|
+
* directions.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* const { keyframes, animation } = springToCss(config, {
|
|
155
|
+
* property: 'translate',
|
|
156
|
+
* from: 0,
|
|
157
|
+
* to: 300,
|
|
158
|
+
* unit: 'px',
|
|
159
|
+
* })
|
|
160
|
+
* const style = document.createElement('style')
|
|
161
|
+
* style.textContent = keyframes
|
|
162
|
+
* document.head.append(style)
|
|
163
|
+
* element.style.animation = animation
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
declare function springToCss(config: SpringDefinition, spec: PropertySpec | PropertySpec[], options?: CssOptions): {
|
|
167
|
+
keyframes: string;
|
|
168
|
+
animation: string;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Builds a CSS `transition` value that animates a property change with the
|
|
172
|
+
* spring. Set it on the element, then change the property, for example on
|
|
173
|
+
* `:hover`, with a toggled class, or with a state attribute. Pass several
|
|
174
|
+
* specs to build one `transition` for several properties.
|
|
175
|
+
*
|
|
176
|
+
* The values come from your CSS rules. Each spec's `from` and `to` only
|
|
177
|
+
* size the move, which tunes the duration. An undamped (looping) config
|
|
178
|
+
* throws, because a transition cannot loop.
|
|
179
|
+
*
|
|
180
|
+
* A transition starts from rest unless its spec carries a `velocity`, in
|
|
181
|
+
* the property's units per second, such as a drag's speed at release. The
|
|
182
|
+
* velocity reshapes the curve and the duration, so build the transition at
|
|
183
|
+
* the handoff. A spec with a velocity must be the only spec in the call.
|
|
184
|
+
*
|
|
185
|
+
* ```ts
|
|
186
|
+
* // Release a dragged card back to 0 at the drag's speed.
|
|
187
|
+
* card.style.transition = springToTransition(config, {
|
|
188
|
+
* property: 'translate',
|
|
189
|
+
* from: dragX,
|
|
190
|
+
* to: 0,
|
|
191
|
+
* velocity: releaseVelocity,
|
|
192
|
+
* })
|
|
193
|
+
* card.style.translate = '0px'
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* The browser carries no momentum between transitions, so a change that
|
|
197
|
+
* interrupts one mid-flight stalls at the turn. To keep the momentum, read
|
|
198
|
+
* the velocity with `springStateAt` and rebuild the transition with it.
|
|
199
|
+
* For motion that reverses often, drive a live `Spring` instead.
|
|
200
|
+
*/
|
|
201
|
+
declare function springToTransition(config: SpringDefinition, spec: PropertySpec | PropertySpec[], options?: LinearEasingOptions): string;
|
|
202
|
+
//#endregion
|
|
203
|
+
export { CssOptions, LinearEasing, LinearEasingOptions, LoopingEasing, PropertySpec, SettlingEasing, springFromState, springStateAt, springToCss, springToLinear, springToTransition, springToWaapi };
|