coily 0.11.0 → 0.12.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,4 +1,8 @@
1
1
  //#region src/config.d.ts
2
+ interface SpringState {
3
+ readonly position: number;
4
+ readonly velocity: number;
5
+ }
2
6
  interface BaseOptions {
3
7
  /**
4
8
  * Mass of the spring system.
@@ -67,10 +71,8 @@ interface TensionBounceDurationOptions extends BaseOptions, WithTension, WithBou
67
71
  interface DampingDurationOptions extends BaseOptions, WithDamping, WithDampingRatio, WithDuration, WithDisplacement {}
68
72
  interface DampingBounceDurationOptions extends BaseOptions, WithDamping, WithBounce, WithDuration, WithDisplacement {}
69
73
  type SpringOptions = DirectOptions | TensionRatioOptions | TensionBounceOptions | DampingRatioOptions | DampingBounceOptions | TensionDampingRatioOptions | TensionDampingBounceOptions | DurationOptions | BounceDurationOptions | TensionDurationOptions | TensionBounceDurationOptions | DampingDurationOptions | DampingBounceDurationOptions;
70
- /**
71
- * Immutable spring configuration.
72
- */
73
74
  declare class SpringConfig {
75
+ #private;
74
76
  readonly mass: number;
75
77
  readonly tension: number;
76
78
  readonly damping: number;
@@ -81,6 +83,29 @@ declare class SpringConfig {
81
83
  readonly precisionMultiplier: number;
82
84
  readonly restingMagnitude: number;
83
85
  constructor(input: SpringOptions);
86
+ static get globalVersion(): number;
87
+ static version(config: SpringConfig): number;
88
+ static assign(target: SpringConfig, source: SpringConfig): void;
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;
84
109
  }
85
110
  /**
86
111
  * Direct physical parameters. You control stiffness and friction exactly;
@@ -126,12 +151,16 @@ declare function defineSpring(input: TensionDampingBounceOptions): SpringConfig;
126
151
  /**
127
152
  * Duration-based configuration. The spring is tuned so that its envelope
128
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.
129
156
  * Tension and damping are both derived from dampingRatio and duration.
130
157
  */
131
158
  declare function defineSpring(input: DurationOptions): SpringConfig;
132
159
  /**
133
160
  * Duration-based configuration. The spring is tuned so that its envelope
134
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.
135
164
  * Bounce controls how oscillatory the motion is while settling.
136
165
  * Tension and damping are both derived.
137
166
  */
@@ -139,23 +168,31 @@ declare function defineSpring(input: BounceDurationOptions): SpringConfig;
139
168
  /**
140
169
  * Duration-based with a tension constraint. Mass is derived from tension
141
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.
142
173
  */
143
174
  declare function defineSpring(input: TensionDurationOptions): SpringConfig;
144
175
  /**
145
176
  * Duration-based with a tension constraint. Bounce controls how oscillatory
146
177
  * the motion is while settling. Mass is derived from tension and the
147
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.
148
181
  */
149
182
  declare function defineSpring(input: TensionBounceDurationOptions): SpringConfig;
150
183
  /**
151
184
  * Duration-based with a damping constraint. Mass is derived from damping,
152
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.
153
188
  */
154
189
  declare function defineSpring(input: DampingDurationOptions): SpringConfig;
155
190
  /**
156
191
  * Duration-based with a damping constraint. Bounce controls how oscillatory
157
192
  * the motion is while settling. Mass is derived from damping and the
158
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.
159
196
  */
160
197
  declare function defineSpring(input: DampingBounceDurationOptions): SpringConfig;
161
198
  //#endregion
@@ -167,7 +204,8 @@ declare class Motion {
167
204
  set position(value: number);
168
205
  get velocity(): number;
169
206
  set velocity(value: number);
170
- get resting(): boolean;
207
+ get timeRemaining(): number;
208
+ get isResting(): boolean;
171
209
  configure(config: SpringConfig): void;
172
210
  tick(dt: number, emit?: boolean): void;
173
211
  onUpdate(callback: () => void): () => void;
@@ -179,38 +217,94 @@ declare class Motion {
179
217
  //#region src/motion-set.d.ts
180
218
  declare class MotionSet {
181
219
  #private;
220
+ constructor(debug?: boolean);
182
221
  add(motion: Motion): void;
183
222
  remove(motion: Motion): void;
184
223
  tick(dt: number): void;
185
224
  }
186
225
  //#endregion
187
226
  //#region src/spring.d.ts
188
- interface DisplacedSpringPosition {
227
+ interface SpringWithOffset {
228
+ spring: Spring;
229
+ offset?: number | undefined;
230
+ }
231
+ type SpringTarget = number | Spring | SpringWithOffset;
232
+ interface StandaloneSpringPosition {
189
233
  target?: number | undefined;
190
234
  value?: number | undefined;
191
235
  }
192
- type SpringPosition = number | DisplacedSpringPosition;
236
+ interface FollowingSpringPosition {
237
+ target: Spring | SpringWithOffset;
238
+ value?: number | undefined;
239
+ }
240
+ type SpringPosition = number | StandaloneSpringPosition | FollowingSpringPosition;
193
241
  declare class Spring {
194
242
  #private;
195
- constructor(motions: MotionSet, position: SpringPosition, config: SpringConfig);
243
+ constructor(motions: MotionSet, position: SpringPosition, config?: SpringConfig);
196
244
  get target(): number;
197
- set target(value: number);
245
+ set target(value: SpringTarget);
198
246
  get value(): number;
199
247
  set value(value: number);
200
248
  get velocity(): number;
201
249
  set velocity(value: number);
250
+ get config(): SpringConfig;
202
251
  get mass(): number;
203
252
  get tension(): number;
204
253
  get damping(): number;
205
254
  get dampingRatio(): number;
206
255
  get precision(): number;
207
- get resting(): boolean;
208
256
  configure(config: SpringConfig): void;
257
+ clearConfigOverride(): void;
258
+ get timeRemaining(): number;
259
+ get isResting(): boolean;
260
+ jumpTo(value: number): void;
261
+ dispose(): void;
209
262
  onUpdate(callback: () => void): () => void;
210
263
  onStart(callback: () => void): () => void;
211
264
  onStop(callback: () => void): () => void;
212
- jumpTo(value: number): void;
265
+ }
266
+ //#endregion
267
+ //#region src/vector2.d.ts
268
+ interface Vector2 {
269
+ x: number;
270
+ y: number;
271
+ }
272
+ //#endregion
273
+ //#region src/spring2d.d.ts
274
+ interface Spring2DWithOffset {
275
+ spring: Spring2D;
276
+ offset?: Vector2 | undefined;
277
+ }
278
+ type Spring2DTarget = Vector2 | Spring2D | Spring2DWithOffset;
279
+ interface DisplacedSpring2DPosition {
280
+ target?: Spring2DTarget | undefined;
281
+ value?: Vector2 | undefined;
282
+ }
283
+ type Spring2DPosition = Vector2 | DisplacedSpring2DPosition;
284
+ declare class Spring2D {
285
+ #private;
286
+ constructor(motions: MotionSet, position: Spring2DPosition, config?: SpringConfig);
287
+ get target(): Vector2;
288
+ set target(value: Spring2DTarget);
289
+ get value(): Readonly<Vector2>;
290
+ set value(value: Vector2);
291
+ get velocity(): Readonly<Vector2>;
292
+ set velocity(value: Vector2);
293
+ get config(): SpringConfig;
294
+ get mass(): number;
295
+ get tension(): number;
296
+ get damping(): number;
297
+ get dampingRatio(): number;
298
+ get precision(): number;
299
+ configure(config: SpringConfig): void;
300
+ clearConfigOverride(): void;
301
+ get timeRemaining(): number;
302
+ get isResting(): boolean;
303
+ jumpTo(value: Vector2): void;
213
304
  dispose(): void;
305
+ onUpdate(callback: () => void): () => void;
306
+ onStart(callback: () => void): () => void;
307
+ onStop(callback: () => void): () => void;
214
308
  }
215
309
  //#endregion
216
310
  //#region src/ticker.d.ts
@@ -239,8 +333,12 @@ interface TickerOptions {
239
333
  }
240
334
  //#endregion
241
335
  //#region src/system.d.ts
336
+ interface SpringSystemOptions extends TickerOptions {
337
+ debug?: boolean | undefined;
338
+ }
242
339
  interface SpringSystem {
243
- createSpring(position: SpringPosition, config: SpringConfig): Spring;
340
+ createSpring(position: SpringPosition, config?: SpringConfig): Spring;
341
+ createSpring2D(position: Spring2DPosition, config?: SpringConfig): Spring2D;
244
342
  /** Advance all springs by `dt` milliseconds, without affecting internal timing. */
245
343
  advance(dt: number): void;
246
344
  /** Start the animation loop. */
@@ -249,28 +347,10 @@ interface SpringSystem {
249
347
  stop(): void;
250
348
  /** Whether the animation loop is currently running. */
251
349
  readonly running: boolean;
252
- /**
253
- * The target frames per second for the simulation loop.
254
- *
255
- * must be greater than 0
256
- */
257
350
  fps: number;
258
- /**
259
- * The maximum elapsed time (in ms) before a frame is considered a lag spike
260
- * (e.g. from a backgrounded tab). When exceeded, `adjustedLag` is used instead
261
- * of the real elapsed time. Set to 0 to disable lag detection.
262
- *
263
- * must be greater than or equal to 0
264
- */
265
351
  lagThreshold: number;
266
- /**
267
- * The substitute elapsed time (in ms) used when a lag spike is detected.
268
- * Clamped to be at most `lagThreshold`.
269
- *
270
- * must be greater than or equal to 0
271
- */
272
352
  adjustedLag: number;
273
353
  }
274
- declare function createSpringSystem(options?: TickerOptions): SpringSystem;
354
+ declare function createSpringSystem(options?: SpringSystemOptions): SpringSystem;
275
355
  //#endregion
276
- export { SpringPosition as a, defineSpring as c, Spring as i, createSpringSystem as n, SpringConfig as o, TickerOptions as r, SpringOptions as s, SpringSystem as t };
356
+ 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 };
package/dist/vue.d.ts CHANGED
@@ -1,31 +1,42 @@
1
- import { o as SpringConfig, s as SpringOptions, t as SpringSystem } from "./system-B_kZMcpg.js";
1
+ import { h as SpringOptions, l as Vector2, m as SpringConfig, n as SpringSystemOptions, t as SpringSystem } from "./system-Do5rE0j7.js";
2
2
  import * as vue from "vue";
3
3
  import { App, MaybeRefOrGetter, Ref, SlotsType } from "vue";
4
4
 
5
5
  //#region src/vue/spring.d.ts
6
- interface UseSpringReturn {
7
- readonly value: Ref<number>;
6
+ type UseSpringOptions = MaybeRefOrGetter<SpringOptions | SpringConfig | undefined>;
7
+ interface SpringRef extends Ref<number> {
8
8
  readonly velocity: Ref<number>;
9
- readonly resting: Readonly<Ref<boolean>>;
9
+ readonly timeRemaining: Ref<number>;
10
+ readonly isResting: Ref<boolean>;
10
11
  readonly jumpTo: (value: number) => void;
11
12
  }
12
- declare function useSpring(target: MaybeRefOrGetter<number>, options?: MaybeRefOrGetter<SpringOptions | SpringConfig>): UseSpringReturn;
13
+ declare function useSpring(target: MaybeRefOrGetter<number>, options?: UseSpringOptions): SpringRef;
14
+ declare function useSpring(target: SpringRef, options?: UseSpringOptions): SpringRef;
15
+ declare function useSpring<const T extends readonly MaybeRefOrGetter<number>[]>(targets: T, options?: UseSpringOptions): { [K in keyof T]: SpringRef };
16
+ interface SpringRef2D extends Ref<Readonly<Vector2>> {
17
+ readonly velocity: Ref<Readonly<Vector2>>;
18
+ readonly timeRemaining: Ref<number>;
19
+ readonly isResting: Ref<boolean>;
20
+ readonly jumpTo: (value: Vector2) => void;
21
+ }
22
+ declare function useSpring2D(target: MaybeRefOrGetter<Vector2>, options?: UseSpringOptions): SpringRef2D;
23
+ declare function useSpring2D(target: SpringRef2D, options?: UseSpringOptions): SpringRef2D;
13
24
  //#endregion
14
25
  //#region src/vue/component.d.ts
15
26
  interface SpringValueProps {
16
27
  target: number;
17
- mass?: number;
18
- tension?: number;
19
- damping?: number;
20
- precision?: number;
28
+ config?: SpringOptions | SpringConfig;
21
29
  }
22
30
  type SpringValueEmits = Record<string, never>;
31
+ interface SpringValueSlotScope {
32
+ value: number;
33
+ velocity: number;
34
+ isResting: boolean;
35
+ timeRemaining: number;
36
+ jumpTo: (value: number) => void;
37
+ }
23
38
  type SpringValueSlots = SlotsType<{
24
- default: {
25
- value: number;
26
- velocity: number;
27
- resting: boolean;
28
- };
39
+ default: SpringValueSlotScope;
29
40
  }>;
30
41
  declare const SpringValue: vue.DefineSetupFnComponent<SpringValueProps, SpringValueEmits, SpringValueSlots, SpringValueProps & {
31
42
  [x: `on${Capitalize<string>}`]: ((...args: unknown[]) => any) | undefined;
@@ -33,6 +44,6 @@ declare const SpringValue: vue.DefineSetupFnComponent<SpringValueProps, SpringVa
33
44
  //#endregion
34
45
  //#region src/vue/system.d.ts
35
46
  declare function provideSpringSystem(system: SpringSystem, app?: App): void;
36
- declare function useSpringSystem(): void;
47
+ declare function useSpringSystem(options?: SpringSystemOptions): void;
37
48
  //#endregion
38
- export { SpringValue, type SpringValueProps, type SpringValueSlots, provideSpringSystem, useSpring, useSpringSystem };
49
+ export { type SpringRef, type SpringRef2D, SpringValue, type SpringValueProps, type SpringValueSlots, provideSpringSystem, useSpring, useSpring2D, useSpringSystem };