coily 0.12.2 → 0.14.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.
@@ -1,350 +0,0 @@
1
- //#region src/config.d.ts
2
- interface SpringState {
3
- readonly position: number;
4
- readonly velocity: number;
5
- }
6
- interface BaseOptions {
7
- /**
8
- * Mass of the spring system.
9
- * @default 1
10
- */
11
- mass?: number | undefined;
12
- /**
13
- * Precision for resting threshold.
14
- * @default 2
15
- */
16
- precision?: number | undefined;
17
- }
18
- interface WithTension {
19
- /**
20
- * Spring stiffness coefficient.
21
- * Must be greater than 0.
22
- */
23
- tension: number;
24
- }
25
- interface WithDamping {
26
- /**
27
- * Viscous damping coefficient.
28
- * Must be greater than or equal to 0.
29
- */
30
- damping: number;
31
- }
32
- interface WithDampingRatio {
33
- /**
34
- * Ratio of damping to critical damping (0 = undamped, 1 = critically damped).
35
- * Must be greater than or equal to 0.
36
- */
37
- dampingRatio: number;
38
- }
39
- interface WithBounce {
40
- /**
41
- * Bounciness of the spring. Converted to dampingRatio as `1 - bounce`.
42
- * [-1, 1]
43
- */
44
- bounce: number;
45
- }
46
- interface WithDuration {
47
- /**
48
- * Target settle duration in milliseconds.
49
- * Must be greater than 0.
50
- */
51
- duration: number;
52
- }
53
- interface WithDisplacement {
54
- /**
55
- * Initial displacement used for duration-based envelope calculation.
56
- * @default 1
57
- */
58
- displacement?: number | undefined;
59
- }
60
- interface DirectOptions extends BaseOptions, WithTension, WithDamping {}
61
- interface TensionRatioOptions extends BaseOptions, WithTension, WithDampingRatio {}
62
- interface TensionBounceOptions extends BaseOptions, WithTension, WithBounce {}
63
- interface DampingRatioOptions extends BaseOptions, WithDamping, WithDampingRatio {}
64
- interface DampingBounceOptions extends BaseOptions, WithDamping, WithBounce {}
65
- interface TensionDampingRatioOptions extends BaseOptions, WithTension, WithDamping, WithDampingRatio {}
66
- interface TensionDampingBounceOptions extends BaseOptions, WithTension, WithDamping, WithBounce {}
67
- interface DurationOptions extends BaseOptions, WithDampingRatio, WithDuration, WithDisplacement {}
68
- interface BounceDurationOptions extends BaseOptions, WithBounce, WithDuration, WithDisplacement {}
69
- interface TensionDurationOptions extends BaseOptions, WithTension, WithDampingRatio, WithDuration, WithDisplacement {}
70
- interface TensionBounceDurationOptions extends BaseOptions, WithTension, WithBounce, WithDuration, WithDisplacement {}
71
- interface DampingDurationOptions extends BaseOptions, WithDamping, WithDampingRatio, WithDuration, WithDisplacement {}
72
- interface DampingBounceDurationOptions extends BaseOptions, WithDamping, WithBounce, WithDuration, WithDisplacement {}
73
- type SpringOptions = DirectOptions | TensionRatioOptions | TensionBounceOptions | DampingRatioOptions | DampingBounceOptions | TensionDampingRatioOptions | TensionDampingBounceOptions | DurationOptions | BounceDurationOptions | TensionDurationOptions | TensionBounceDurationOptions | DampingDurationOptions | DampingBounceDurationOptions;
74
- /**
75
- * Immutable spring configuration.
76
- */
77
- declare class SpringConfig {
78
- static readonly default: SpringConfig;
79
- readonly mass: number;
80
- readonly tension: number;
81
- readonly damping: number;
82
- readonly precision: number;
83
- readonly naturalFrequency: number;
84
- readonly criticalDamping: number;
85
- readonly dampingRatio: number;
86
- readonly precisionMultiplier: number;
87
- readonly restingMagnitude: number;
88
- constructor(input: SpringOptions);
89
- /**
90
- * Analytically estimates the time remaining for a spring to come to rest,
91
- * given the current displacement and velocity.
92
- *
93
- * Uses the exponential decay envelope common to all three damping regimes.
94
- * The decay rate depends on the regime:
95
- * - Underdamped (ζ < 1): σ = ζωₙ
96
- * - Critically damped (ζ = 1): σ = ωₙ
97
- * - Overdamped (ζ > 1): σ = (ζ - √(ζ²-1))ωₙ (the slower eigenvalue)
98
- *
99
- * The effective initial amplitude accounts for both displacement and velocity,
100
- * since kinetic energy can convert to additional displacement:
101
- * A₀ = |x₀| + |v₀| / ωₙ
102
- *
103
- * Settling time: t = ln(A₀ / threshold) / σ, with a 2× safety factor
104
- * to account for polynomial terms in the critically damped solution.
105
- *
106
- * Returns the estimated time in milliseconds.
107
- */
108
- computeTimeRemaining(state: SpringState): number;
109
- }
110
- /**
111
- * Direct physical parameters. You control stiffness and friction exactly;
112
- * mass defaults to 1.
113
- */
114
- declare function defineSpring(input: DirectOptions): SpringConfig;
115
- /**
116
- * Tension sets the stiffness; dampingRatio controls oscillation character
117
- * (0 = undamped, 1 = critically damped, >1 = overdamped).
118
- * Damping is derived as `2 * dampingRatio * sqrt(mass * tension)`.
119
- */
120
- declare function defineSpring(input: TensionRatioOptions): SpringConfig;
121
- /**
122
- * Tension sets the stiffness; bounce controls how oscillatory the spring is,
123
- * from -1 (overdamped, no oscillation) to 1 (maximum bounce).
124
- * Damping is derived to match the requested bounciness.
125
- */
126
- declare function defineSpring(input: TensionBounceOptions): SpringConfig;
127
- /**
128
- * Damping is given directly; dampingRatio is used to derive tension
129
- * as `damping² / (4 * dampingRatio² * mass)`.
130
- * dampingRatio must be greater than 0.
131
- */
132
- declare function defineSpring(input: DampingRatioOptions): SpringConfig;
133
- /**
134
- * Damping is given directly; bounce controls how oscillatory the spring is.
135
- * Tension is derived to match the requested bounciness.
136
- * bounce must be less than 1.
137
- */
138
- declare function defineSpring(input: DampingBounceOptions): SpringConfig;
139
- /**
140
- * All three physical knobs specified — mass is derived
141
- * as `damping² / (4 * dampingRatio² * tension)`.
142
- * dampingRatio must be greater than 0.
143
- */
144
- declare function defineSpring(input: TensionDampingRatioOptions): SpringConfig;
145
- /**
146
- * All three physical knobs specified — mass is derived
147
- * from tension, damping, and the requested bounciness.
148
- * bounce must be less than 1.
149
- */
150
- declare function defineSpring(input: TensionDampingBounceOptions): SpringConfig;
151
- /**
152
- * Duration-based configuration. The spring is tuned so that its envelope
153
- * decays to the resting threshold within the given duration.
154
- * Duration assumes a displacement of 1 by default — provide `displacement`
155
- * to match your actual animation range for accurate timing.
156
- * Tension and damping are both derived from dampingRatio and duration.
157
- */
158
- declare function defineSpring(input: DurationOptions): SpringConfig;
159
- /**
160
- * Duration-based configuration. The spring is tuned so that its envelope
161
- * decays to the resting threshold within the given duration.
162
- * Duration assumes a displacement of 1 by default — provide `displacement`
163
- * to match your actual animation range for accurate timing.
164
- * Bounce controls how oscillatory the motion is while settling.
165
- * Tension and damping are both derived.
166
- */
167
- declare function defineSpring(input: BounceDurationOptions): SpringConfig;
168
- /**
169
- * Duration-based with a tension constraint. Mass is derived from tension
170
- * and the computed natural frequency; damping follows from mass and dampingRatio.
171
- * Duration assumes a displacement of 1 by default — provide `displacement`
172
- * to match your actual animation range for accurate timing.
173
- */
174
- declare function defineSpring(input: TensionDurationOptions): SpringConfig;
175
- /**
176
- * Duration-based with a tension constraint. Bounce controls how oscillatory
177
- * the motion is while settling. Mass is derived from tension and the
178
- * computed natural frequency.
179
- * Duration assumes a displacement of 1 by default — provide `displacement`
180
- * to match your actual animation range for accurate timing.
181
- */
182
- declare function defineSpring(input: TensionBounceDurationOptions): SpringConfig;
183
- /**
184
- * Duration-based with a damping constraint. Mass is derived from damping,
185
- * dampingRatio, and the computed natural frequency; tension follows from mass.
186
- * Duration assumes a displacement of 1 by default — provide `displacement`
187
- * to match your actual animation range for accurate timing.
188
- */
189
- declare function defineSpring(input: DampingDurationOptions): SpringConfig;
190
- /**
191
- * Duration-based with a damping constraint. Bounce controls how oscillatory
192
- * the motion is while settling. Mass is derived from damping and the
193
- * computed natural frequency.
194
- * Duration assumes a displacement of 1 by default — provide `displacement`
195
- * to match your actual animation range for accurate timing.
196
- */
197
- declare function defineSpring(input: DampingBounceDurationOptions): SpringConfig;
198
- //#endregion
199
- //#region src/motion.d.ts
200
- declare class Motion {
201
- #private;
202
- constructor(config: SpringConfig, position: number, velocity: number);
203
- get position(): number;
204
- set position(value: number);
205
- get velocity(): number;
206
- set velocity(value: number);
207
- get timeRemaining(): number;
208
- get isResting(): boolean;
209
- configure(config: SpringConfig): void;
210
- tick(dt: number, emit?: boolean): void;
211
- onUpdate(callback: () => void): () => void;
212
- onStart(callback: () => void): () => void;
213
- onStop(callback: () => void): () => void;
214
- dispose(): void;
215
- }
216
- //#endregion
217
- //#region src/motion-set.d.ts
218
- declare class MotionSet {
219
- #private;
220
- constructor(debug?: boolean);
221
- add(motion: Motion): void;
222
- remove(motion: Motion): void;
223
- tick(dt: number): void;
224
- }
225
- //#endregion
226
- //#region src/spring.d.ts
227
- interface SpringWithOffset {
228
- spring: Spring;
229
- offset?: number | undefined;
230
- }
231
- type SpringTarget = number | Spring | SpringWithOffset;
232
- interface DisplacedSpringPosition {
233
- target?: SpringTarget | undefined;
234
- value?: number | undefined;
235
- }
236
- type SpringPosition = number | DisplacedSpringPosition;
237
- declare class Spring {
238
- #private;
239
- constructor(motions: MotionSet, position: SpringPosition, config?: SpringConfig);
240
- get target(): number;
241
- set target(value: SpringTarget);
242
- get value(): number;
243
- set value(value: number);
244
- get velocity(): number;
245
- set velocity(value: number);
246
- get config(): SpringConfig | null;
247
- get mass(): number;
248
- get tension(): number;
249
- get damping(): number;
250
- get dampingRatio(): number;
251
- get precision(): number;
252
- set config(value: SpringConfig | null);
253
- get timeRemaining(): number;
254
- get isResting(): boolean;
255
- jumpTo(value: number): void;
256
- dispose(): void;
257
- onUpdate(callback: () => void): () => void;
258
- onStart(callback: () => void): () => void;
259
- onStop(callback: () => void): () => void;
260
- }
261
- //#endregion
262
- //#region src/vector2.d.ts
263
- interface Vector2 {
264
- x: number;
265
- y: number;
266
- }
267
- //#endregion
268
- //#region src/spring2d.d.ts
269
- interface Spring2DWithOffset {
270
- spring: Spring2D;
271
- offset?: Vector2 | undefined;
272
- }
273
- type Spring2DTarget = Vector2 | Spring2D | Spring2DWithOffset;
274
- interface DisplacedSpring2DPosition {
275
- target?: Spring2DTarget | undefined;
276
- value?: Vector2 | undefined;
277
- }
278
- type Spring2DPosition = Vector2 | DisplacedSpring2DPosition;
279
- declare class Spring2D {
280
- #private;
281
- constructor(motions: MotionSet, position: Spring2DPosition, config?: SpringConfig);
282
- get target(): Vector2;
283
- set target(value: Spring2DTarget);
284
- get value(): Readonly<Vector2>;
285
- set value(value: Vector2);
286
- get velocity(): Readonly<Vector2>;
287
- set velocity(value: Vector2);
288
- get config(): SpringConfig | null;
289
- get mass(): number;
290
- get tension(): number;
291
- get damping(): number;
292
- get dampingRatio(): number;
293
- get precision(): number;
294
- set config(value: SpringConfig | null);
295
- get timeRemaining(): number;
296
- get isResting(): boolean;
297
- jumpTo(value: Vector2): void;
298
- dispose(): void;
299
- onUpdate(callback: () => void): () => void;
300
- onStart(callback: () => void): () => void;
301
- onStop(callback: () => void): () => void;
302
- }
303
- //#endregion
304
- //#region src/ticker.d.ts
305
- interface TickerOptions {
306
- /**
307
- * The target frames per second for the simulation loop
308
- *
309
- * must be greater than 0, defaults to 60
310
- */
311
- fps?: number | undefined;
312
- /**
313
- * The maximum elapsed time (in ms) before a frame is considered a lag spike
314
- * (e.g. from a backgrounded tab). When exceeded, `adjustedLag` is used instead
315
- * of the real elapsed time. Set to 0 to disable lag detection.
316
- *
317
- * must be greater than or equal to 0, defaults to 500
318
- */
319
- lagThreshold?: number | undefined;
320
- /**
321
- * The substitute elapsed time (in ms) used when a lag spike is detected.
322
- * Clamped to be at most `lagThreshold`.
323
- *
324
- * must be greater than or equal to 0, defaults to 33
325
- */
326
- adjustedLag?: number | undefined;
327
- }
328
- //#endregion
329
- //#region src/system.d.ts
330
- interface SpringSystemOptions extends TickerOptions {
331
- debug?: boolean | undefined;
332
- }
333
- interface SpringSystem {
334
- createSpring(position: SpringPosition, config?: SpringConfig): Spring;
335
- createSpring2D(position: Spring2DPosition, config?: SpringConfig): Spring2D;
336
- /** Advance all springs by `dt` milliseconds, without affecting internal timing. */
337
- advance(dt: number): void;
338
- /** Start the animation loop. */
339
- start(): void;
340
- /** Stop the animation loop. */
341
- stop(): void;
342
- /** Whether the animation loop is currently running. */
343
- readonly running: boolean;
344
- fps: number;
345
- lagThreshold: number;
346
- adjustedLag: number;
347
- }
348
- declare function createSpringSystem(options?: SpringSystemOptions): SpringSystem;
349
- //#endregion
350
- export { defineSpring as _, Spring2D as a, Spring2DWithOffset as c, SpringPosition as d, SpringTarget as f, SpringState as g, SpringOptions as h, TickerOptions as i, Vector2 as l, SpringConfig as m, SpringSystemOptions as n, Spring2DPosition as o, SpringWithOffset as p, createSpringSystem as r, Spring2DTarget as s, SpringSystem as t, Spring as u };