coily 0.11.0 → 0.12.1

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.
@@ -71,6 +75,8 @@ type SpringOptions = DirectOptions | TensionRatioOptions | TensionBounceOptions
71
75
  * Immutable spring configuration.
72
76
  */
73
77
  declare class SpringConfig {
78
+ #private;
79
+ static readonly default: SpringConfig;
74
80
  readonly mass: number;
75
81
  readonly tension: number;
76
82
  readonly damping: number;
@@ -81,6 +87,28 @@ declare class SpringConfig {
81
87
  readonly precisionMultiplier: number;
82
88
  readonly restingMagnitude: number;
83
89
  constructor(input: SpringOptions);
90
+ static version(config: SpringConfig): number;
91
+ static assign(target: SpringConfig, source: SpringConfig): void;
92
+ /**
93
+ * Analytically estimates the time remaining for a spring to come to rest,
94
+ * given the current displacement and velocity.
95
+ *
96
+ * Uses the exponential decay envelope common to all three damping regimes.
97
+ * The decay rate depends on the regime:
98
+ * - Underdamped (ζ < 1): σ = ζωₙ
99
+ * - Critically damped (ζ = 1): σ = ωₙ
100
+ * - Overdamped (ζ > 1): σ = (ζ - √(ζ²-1))ωₙ (the slower eigenvalue)
101
+ *
102
+ * The effective initial amplitude accounts for both displacement and velocity,
103
+ * since kinetic energy can convert to additional displacement:
104
+ * A₀ = |x₀| + |v₀| / ωₙ
105
+ *
106
+ * Settling time: t = ln(A₀ / threshold) / σ, with a 2× safety factor
107
+ * to account for polynomial terms in the critically damped solution.
108
+ *
109
+ * Returns the estimated time in milliseconds.
110
+ */
111
+ computeTimeRemaining(state: SpringState): number;
84
112
  }
85
113
  /**
86
114
  * Direct physical parameters. You control stiffness and friction exactly;
@@ -126,12 +154,16 @@ declare function defineSpring(input: TensionDampingBounceOptions): SpringConfig;
126
154
  /**
127
155
  * Duration-based configuration. The spring is tuned so that its envelope
128
156
  * decays to the resting threshold within the given duration.
157
+ * Duration assumes a displacement of 1 by default — provide `displacement`
158
+ * to match your actual animation range for accurate timing.
129
159
  * Tension and damping are both derived from dampingRatio and duration.
130
160
  */
131
161
  declare function defineSpring(input: DurationOptions): SpringConfig;
132
162
  /**
133
163
  * Duration-based configuration. The spring is tuned so that its envelope
134
164
  * decays to the resting threshold within the given duration.
165
+ * Duration assumes a displacement of 1 by default — provide `displacement`
166
+ * to match your actual animation range for accurate timing.
135
167
  * Bounce controls how oscillatory the motion is while settling.
136
168
  * Tension and damping are both derived.
137
169
  */
@@ -139,23 +171,31 @@ declare function defineSpring(input: BounceDurationOptions): SpringConfig;
139
171
  /**
140
172
  * Duration-based with a tension constraint. Mass is derived from tension
141
173
  * and the computed natural frequency; damping follows from mass and dampingRatio.
174
+ * Duration assumes a displacement of 1 by default — provide `displacement`
175
+ * to match your actual animation range for accurate timing.
142
176
  */
143
177
  declare function defineSpring(input: TensionDurationOptions): SpringConfig;
144
178
  /**
145
179
  * Duration-based with a tension constraint. Bounce controls how oscillatory
146
180
  * the motion is while settling. Mass is derived from tension and the
147
181
  * computed natural frequency.
182
+ * Duration assumes a displacement of 1 by default — provide `displacement`
183
+ * to match your actual animation range for accurate timing.
148
184
  */
149
185
  declare function defineSpring(input: TensionBounceDurationOptions): SpringConfig;
150
186
  /**
151
187
  * Duration-based with a damping constraint. Mass is derived from damping,
152
188
  * dampingRatio, and the computed natural frequency; tension follows from mass.
189
+ * Duration assumes a displacement of 1 by default — provide `displacement`
190
+ * to match your actual animation range for accurate timing.
153
191
  */
154
192
  declare function defineSpring(input: DampingDurationOptions): SpringConfig;
155
193
  /**
156
194
  * Duration-based with a damping constraint. Bounce controls how oscillatory
157
195
  * the motion is while settling. Mass is derived from damping and the
158
196
  * computed natural frequency.
197
+ * Duration assumes a displacement of 1 by default — provide `displacement`
198
+ * to match your actual animation range for accurate timing.
159
199
  */
160
200
  declare function defineSpring(input: DampingBounceDurationOptions): SpringConfig;
161
201
  //#endregion
@@ -167,7 +207,8 @@ declare class Motion {
167
207
  set position(value: number);
168
208
  get velocity(): number;
169
209
  set velocity(value: number);
170
- get resting(): boolean;
210
+ get timeRemaining(): number;
211
+ get isResting(): boolean;
171
212
  configure(config: SpringConfig): void;
172
213
  tick(dt: number, emit?: boolean): void;
173
214
  onUpdate(callback: () => void): () => void;
@@ -179,38 +220,88 @@ declare class Motion {
179
220
  //#region src/motion-set.d.ts
180
221
  declare class MotionSet {
181
222
  #private;
223
+ constructor(debug?: boolean);
182
224
  add(motion: Motion): void;
183
225
  remove(motion: Motion): void;
184
226
  tick(dt: number): void;
185
227
  }
186
228
  //#endregion
187
229
  //#region src/spring.d.ts
230
+ interface SpringWithOffset {
231
+ spring: Spring;
232
+ offset?: number | undefined;
233
+ }
234
+ type SpringTarget = number | Spring | SpringWithOffset;
188
235
  interface DisplacedSpringPosition {
189
- target?: number | undefined;
236
+ target?: SpringTarget | undefined;
190
237
  value?: number | undefined;
191
238
  }
192
239
  type SpringPosition = number | DisplacedSpringPosition;
193
240
  declare class Spring {
194
241
  #private;
195
- constructor(motions: MotionSet, position: SpringPosition, config: SpringConfig);
242
+ constructor(motions: MotionSet, position: SpringPosition, config?: SpringConfig);
196
243
  get target(): number;
197
- set target(value: number);
244
+ set target(value: SpringTarget);
198
245
  get value(): number;
199
246
  set value(value: number);
200
247
  get velocity(): number;
201
248
  set velocity(value: number);
249
+ get config(): SpringConfig | null;
202
250
  get mass(): number;
203
251
  get tension(): number;
204
252
  get damping(): number;
205
253
  get dampingRatio(): number;
206
254
  get precision(): number;
207
- get resting(): boolean;
208
- configure(config: SpringConfig): void;
255
+ set config(value: SpringConfig | null);
256
+ get timeRemaining(): number;
257
+ get isResting(): boolean;
258
+ jumpTo(value: number): void;
259
+ dispose(): void;
209
260
  onUpdate(callback: () => void): () => void;
210
261
  onStart(callback: () => void): () => void;
211
262
  onStop(callback: () => void): () => void;
212
- jumpTo(value: number): void;
263
+ }
264
+ //#endregion
265
+ //#region src/vector2.d.ts
266
+ interface Vector2 {
267
+ x: number;
268
+ y: number;
269
+ }
270
+ //#endregion
271
+ //#region src/spring2d.d.ts
272
+ interface Spring2DWithOffset {
273
+ spring: Spring2D;
274
+ offset?: Vector2 | undefined;
275
+ }
276
+ type Spring2DTarget = Vector2 | Spring2D | Spring2DWithOffset;
277
+ interface DisplacedSpring2DPosition {
278
+ target?: Spring2DTarget | undefined;
279
+ value?: Vector2 | undefined;
280
+ }
281
+ type Spring2DPosition = Vector2 | DisplacedSpring2DPosition;
282
+ declare class Spring2D {
283
+ #private;
284
+ constructor(motions: MotionSet, position: Spring2DPosition, config?: SpringConfig);
285
+ get target(): Vector2;
286
+ set target(value: Spring2DTarget);
287
+ get value(): Readonly<Vector2>;
288
+ set value(value: Vector2);
289
+ get velocity(): Readonly<Vector2>;
290
+ set velocity(value: Vector2);
291
+ get config(): SpringConfig | null;
292
+ get mass(): number;
293
+ get tension(): number;
294
+ get damping(): number;
295
+ get dampingRatio(): number;
296
+ get precision(): number;
297
+ set config(value: SpringConfig | null);
298
+ get timeRemaining(): number;
299
+ get isResting(): boolean;
300
+ jumpTo(value: Vector2): void;
213
301
  dispose(): void;
302
+ onUpdate(callback: () => void): () => void;
303
+ onStart(callback: () => void): () => void;
304
+ onStop(callback: () => void): () => void;
214
305
  }
215
306
  //#endregion
216
307
  //#region src/ticker.d.ts
@@ -239,8 +330,12 @@ interface TickerOptions {
239
330
  }
240
331
  //#endregion
241
332
  //#region src/system.d.ts
333
+ interface SpringSystemOptions extends TickerOptions {
334
+ debug?: boolean | undefined;
335
+ }
242
336
  interface SpringSystem {
243
- createSpring(position: SpringPosition, config: SpringConfig): Spring;
337
+ createSpring(position: SpringPosition, config?: SpringConfig): Spring;
338
+ createSpring2D(position: Spring2DPosition, config?: SpringConfig): Spring2D;
244
339
  /** Advance all springs by `dt` milliseconds, without affecting internal timing. */
245
340
  advance(dt: number): void;
246
341
  /** Start the animation loop. */
@@ -249,28 +344,10 @@ interface SpringSystem {
249
344
  stop(): void;
250
345
  /** Whether the animation loop is currently running. */
251
346
  readonly running: boolean;
252
- /**
253
- * The target frames per second for the simulation loop.
254
- *
255
- * must be greater than 0
256
- */
257
347
  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
348
  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
349
  adjustedLag: number;
273
350
  }
274
- declare function createSpringSystem(options?: TickerOptions): SpringSystem;
351
+ declare function createSpringSystem(options?: SpringSystemOptions): SpringSystem;
275
352
  //#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 };
353
+ 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,45 @@
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-CMaMt_7p.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
+ //#endregion
17
+ //#region src/vue/spring2d.d.ts
18
+ interface SpringRef2D extends Ref<Readonly<Vector2>> {
19
+ readonly velocity: Ref<Readonly<Vector2>>;
20
+ readonly timeRemaining: Ref<number>;
21
+ readonly isResting: Ref<boolean>;
22
+ readonly jumpTo: (value: Vector2) => void;
23
+ }
24
+ declare function useSpring2D(target: MaybeRefOrGetter<Vector2>, options?: UseSpringOptions): SpringRef2D;
25
+ declare function useSpring2D(target: SpringRef2D, options?: UseSpringOptions): SpringRef2D;
26
+ declare function useSpring2D<const T extends readonly MaybeRefOrGetter<Vector2>[]>(targets: T, options?: UseSpringOptions): { [K in keyof T]: SpringRef2D };
13
27
  //#endregion
14
28
  //#region src/vue/component.d.ts
15
29
  interface SpringValueProps {
16
30
  target: number;
17
- mass?: number;
18
- tension?: number;
19
- damping?: number;
20
- precision?: number;
31
+ config?: SpringOptions | SpringConfig;
21
32
  }
22
33
  type SpringValueEmits = Record<string, never>;
34
+ interface SpringValueSlotScope {
35
+ value: number;
36
+ velocity: number;
37
+ isResting: boolean;
38
+ timeRemaining: number;
39
+ jumpTo: (value: number) => void;
40
+ }
23
41
  type SpringValueSlots = SlotsType<{
24
- default: {
25
- value: number;
26
- velocity: number;
27
- resting: boolean;
28
- };
42
+ default: SpringValueSlotScope;
29
43
  }>;
30
44
  declare const SpringValue: vue.DefineSetupFnComponent<SpringValueProps, SpringValueEmits, SpringValueSlots, SpringValueProps & {
31
45
  [x: `on${Capitalize<string>}`]: ((...args: unknown[]) => any) | undefined;
@@ -33,6 +47,6 @@ declare const SpringValue: vue.DefineSetupFnComponent<SpringValueProps, SpringVa
33
47
  //#endregion
34
48
  //#region src/vue/system.d.ts
35
49
  declare function provideSpringSystem(system: SpringSystem, app?: App): void;
36
- declare function useSpringSystem(): void;
50
+ declare function useSpringSystem(options?: SpringSystemOptions): void;
37
51
  //#endregion
38
- export { SpringValue, type SpringValueProps, type SpringValueSlots, provideSpringSystem, useSpring, useSpringSystem };
52
+ export { type SpringRef, type SpringRef2D, SpringValue, type SpringValueProps, type SpringValueSlots, provideSpringSystem, useSpring, useSpring2D, useSpringSystem };