coily 0.10.1 → 0.11.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 +1 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/nuxt.d.ts +6 -0
- package/dist/nuxt.js +44 -0
- package/dist/system-B_kZMcpg.d.ts +276 -0
- package/dist/system-Dxxv4ee7.js +614 -0
- package/dist/vue.d.ts +38 -0
- package/dist/vue.js +121 -0
- package/package.json +47 -28
- package/dist/api.d.mts +0 -110
- package/dist/api.d.ts +0 -110
- package/dist/api.mjs +0 -460
- package/dist/loop.d.mts +0 -5
- package/dist/loop.d.ts +0 -5
- package/dist/loop.mjs +0 -14
package/README.md
CHANGED
|
@@ -32,7 +32,6 @@ The `createSpring` function takes the following arguments:
|
|
|
32
32
|
|
|
33
33
|
- `config: SpringConfig`
|
|
34
34
|
The configuration for the spring. `SpringConfig` takes the following parameters:
|
|
35
|
-
|
|
36
35
|
- `config.mass: number`
|
|
37
36
|
How massive the spring is. A lower number will allow the spring to speed up and slow down more quickly than a
|
|
38
37
|
larger number. Larger numbers are more likely to overshoot the `target`
|
|
@@ -47,7 +46,6 @@ The `createSpring` function takes the following arguments:
|
|
|
47
46
|
|
|
48
47
|
- `options: SpringOptions`
|
|
49
48
|
Additional options for the spring. `SpringOptions` takes the following parameters:
|
|
50
|
-
|
|
51
49
|
- `options.restingDistance: number`
|
|
52
50
|
The minimum difference between the `target` and `value` at which the spring will consider itself "at" the `target`
|
|
53
51
|
|
|
@@ -229,7 +227,7 @@ The links take one of two forms:
|
|
|
229
227
|
const chain = createSpringChain(
|
|
230
228
|
0, // initial
|
|
231
229
|
[50, 50, (value) => value * 1.25],
|
|
232
|
-
{ mass: 10, tension: 3000, friction: 300 } // config
|
|
230
|
+
{ mass: 10, tension: 3000, friction: 300 }, // config
|
|
233
231
|
)
|
|
234
232
|
```
|
|
235
233
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SpringPosition, c as defineSpring, i as Spring, n as createSpringSystem, o as SpringConfig, r as TickerOptions, s as SpringOptions, t as SpringSystem } from "./system-B_kZMcpg.js";
|
|
2
|
+
export { type Spring, type SpringConfig, type SpringOptions, type SpringPosition, type SpringSystem, type TickerOptions, createSpringSystem, defineSpring };
|
package/dist/index.js
ADDED
package/dist/nuxt.d.ts
ADDED
package/dist/nuxt.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { addComponent, addImports, addPluginTemplate, defineNuxtModule } from "@nuxt/kit";
|
|
2
|
+
//#region src/vue/nuxt.ts
|
|
3
|
+
const pluginTemplate = `import { createSpringSystem } from 'coily'
|
|
4
|
+
import { provideSpringSystem } from 'coily/vue'
|
|
5
|
+
|
|
6
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
7
|
+
nuxtApp.hook('app:created', (vueApp) => {
|
|
8
|
+
const system = createSpringSystem()
|
|
9
|
+
provideSpringSystem(system, vueApp)
|
|
10
|
+
|
|
11
|
+
if(import.meta.client) {
|
|
12
|
+
system.start()
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
})`;
|
|
16
|
+
const coilyModule = defineNuxtModule({
|
|
17
|
+
meta: {
|
|
18
|
+
name: "coily",
|
|
19
|
+
configKey: "coily"
|
|
20
|
+
},
|
|
21
|
+
async setup() {
|
|
22
|
+
addPluginTemplate({
|
|
23
|
+
name: "coily",
|
|
24
|
+
filename: "coily.plugin.mjs",
|
|
25
|
+
mode: "all",
|
|
26
|
+
getContents: () => pluginTemplate
|
|
27
|
+
});
|
|
28
|
+
addImports([{
|
|
29
|
+
from: "coily/vue",
|
|
30
|
+
name: "useSpring"
|
|
31
|
+
}, {
|
|
32
|
+
from: "coily",
|
|
33
|
+
name: "defineSpring"
|
|
34
|
+
}]);
|
|
35
|
+
addComponent({
|
|
36
|
+
name: "SpringValue",
|
|
37
|
+
filePath: "coily/vue",
|
|
38
|
+
export: "SpringValue",
|
|
39
|
+
chunkName: "placement"
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
//#endregion
|
|
44
|
+
export { coilyModule as default };
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
//#region src/config.d.ts
|
|
2
|
+
interface BaseOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Mass of the spring system.
|
|
5
|
+
* @default 1
|
|
6
|
+
*/
|
|
7
|
+
mass?: number | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Precision for resting threshold.
|
|
10
|
+
* @default 2
|
|
11
|
+
*/
|
|
12
|
+
precision?: number | undefined;
|
|
13
|
+
}
|
|
14
|
+
interface WithTension {
|
|
15
|
+
/**
|
|
16
|
+
* Spring stiffness coefficient.
|
|
17
|
+
* Must be greater than 0.
|
|
18
|
+
*/
|
|
19
|
+
tension: number;
|
|
20
|
+
}
|
|
21
|
+
interface WithDamping {
|
|
22
|
+
/**
|
|
23
|
+
* Viscous damping coefficient.
|
|
24
|
+
* Must be greater than or equal to 0.
|
|
25
|
+
*/
|
|
26
|
+
damping: number;
|
|
27
|
+
}
|
|
28
|
+
interface WithDampingRatio {
|
|
29
|
+
/**
|
|
30
|
+
* Ratio of damping to critical damping (0 = undamped, 1 = critically damped).
|
|
31
|
+
* Must be greater than or equal to 0.
|
|
32
|
+
*/
|
|
33
|
+
dampingRatio: number;
|
|
34
|
+
}
|
|
35
|
+
interface WithBounce {
|
|
36
|
+
/**
|
|
37
|
+
* Bounciness of the spring. Converted to dampingRatio as `1 - bounce`.
|
|
38
|
+
* [-1, 1]
|
|
39
|
+
*/
|
|
40
|
+
bounce: number;
|
|
41
|
+
}
|
|
42
|
+
interface WithDuration {
|
|
43
|
+
/**
|
|
44
|
+
* Target settle duration in milliseconds.
|
|
45
|
+
* Must be greater than 0.
|
|
46
|
+
*/
|
|
47
|
+
duration: number;
|
|
48
|
+
}
|
|
49
|
+
interface WithDisplacement {
|
|
50
|
+
/**
|
|
51
|
+
* Initial displacement used for duration-based envelope calculation.
|
|
52
|
+
* @default 1
|
|
53
|
+
*/
|
|
54
|
+
displacement?: number | undefined;
|
|
55
|
+
}
|
|
56
|
+
interface DirectOptions extends BaseOptions, WithTension, WithDamping {}
|
|
57
|
+
interface TensionRatioOptions extends BaseOptions, WithTension, WithDampingRatio {}
|
|
58
|
+
interface TensionBounceOptions extends BaseOptions, WithTension, WithBounce {}
|
|
59
|
+
interface DampingRatioOptions extends BaseOptions, WithDamping, WithDampingRatio {}
|
|
60
|
+
interface DampingBounceOptions extends BaseOptions, WithDamping, WithBounce {}
|
|
61
|
+
interface TensionDampingRatioOptions extends BaseOptions, WithTension, WithDamping, WithDampingRatio {}
|
|
62
|
+
interface TensionDampingBounceOptions extends BaseOptions, WithTension, WithDamping, WithBounce {}
|
|
63
|
+
interface DurationOptions extends BaseOptions, WithDampingRatio, WithDuration, WithDisplacement {}
|
|
64
|
+
interface BounceDurationOptions extends BaseOptions, WithBounce, WithDuration, WithDisplacement {}
|
|
65
|
+
interface TensionDurationOptions extends BaseOptions, WithTension, WithDampingRatio, WithDuration, WithDisplacement {}
|
|
66
|
+
interface TensionBounceDurationOptions extends BaseOptions, WithTension, WithBounce, WithDuration, WithDisplacement {}
|
|
67
|
+
interface DampingDurationOptions extends BaseOptions, WithDamping, WithDampingRatio, WithDuration, WithDisplacement {}
|
|
68
|
+
interface DampingBounceDurationOptions extends BaseOptions, WithDamping, WithBounce, WithDuration, WithDisplacement {}
|
|
69
|
+
type SpringOptions = DirectOptions | TensionRatioOptions | TensionBounceOptions | DampingRatioOptions | DampingBounceOptions | TensionDampingRatioOptions | TensionDampingBounceOptions | DurationOptions | BounceDurationOptions | TensionDurationOptions | TensionBounceDurationOptions | DampingDurationOptions | DampingBounceDurationOptions;
|
|
70
|
+
/**
|
|
71
|
+
* Immutable spring configuration.
|
|
72
|
+
*/
|
|
73
|
+
declare class SpringConfig {
|
|
74
|
+
readonly mass: number;
|
|
75
|
+
readonly tension: number;
|
|
76
|
+
readonly damping: number;
|
|
77
|
+
readonly precision: number;
|
|
78
|
+
readonly naturalFrequency: number;
|
|
79
|
+
readonly criticalDamping: number;
|
|
80
|
+
readonly dampingRatio: number;
|
|
81
|
+
readonly precisionMultiplier: number;
|
|
82
|
+
readonly restingMagnitude: number;
|
|
83
|
+
constructor(input: SpringOptions);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Direct physical parameters. You control stiffness and friction exactly;
|
|
87
|
+
* mass defaults to 1.
|
|
88
|
+
*/
|
|
89
|
+
declare function defineSpring(input: DirectOptions): SpringConfig;
|
|
90
|
+
/**
|
|
91
|
+
* Tension sets the stiffness; dampingRatio controls oscillation character
|
|
92
|
+
* (0 = undamped, 1 = critically damped, >1 = overdamped).
|
|
93
|
+
* Damping is derived as `2 * dampingRatio * sqrt(mass * tension)`.
|
|
94
|
+
*/
|
|
95
|
+
declare function defineSpring(input: TensionRatioOptions): SpringConfig;
|
|
96
|
+
/**
|
|
97
|
+
* Tension sets the stiffness; bounce controls how oscillatory the spring is,
|
|
98
|
+
* from -1 (overdamped, no oscillation) to 1 (maximum bounce).
|
|
99
|
+
* Damping is derived to match the requested bounciness.
|
|
100
|
+
*/
|
|
101
|
+
declare function defineSpring(input: TensionBounceOptions): SpringConfig;
|
|
102
|
+
/**
|
|
103
|
+
* Damping is given directly; dampingRatio is used to derive tension
|
|
104
|
+
* as `damping² / (4 * dampingRatio² * mass)`.
|
|
105
|
+
* dampingRatio must be greater than 0.
|
|
106
|
+
*/
|
|
107
|
+
declare function defineSpring(input: DampingRatioOptions): SpringConfig;
|
|
108
|
+
/**
|
|
109
|
+
* Damping is given directly; bounce controls how oscillatory the spring is.
|
|
110
|
+
* Tension is derived to match the requested bounciness.
|
|
111
|
+
* bounce must be less than 1.
|
|
112
|
+
*/
|
|
113
|
+
declare function defineSpring(input: DampingBounceOptions): SpringConfig;
|
|
114
|
+
/**
|
|
115
|
+
* All three physical knobs specified — mass is derived
|
|
116
|
+
* as `damping² / (4 * dampingRatio² * tension)`.
|
|
117
|
+
* dampingRatio must be greater than 0.
|
|
118
|
+
*/
|
|
119
|
+
declare function defineSpring(input: TensionDampingRatioOptions): SpringConfig;
|
|
120
|
+
/**
|
|
121
|
+
* All three physical knobs specified — mass is derived
|
|
122
|
+
* from tension, damping, and the requested bounciness.
|
|
123
|
+
* bounce must be less than 1.
|
|
124
|
+
*/
|
|
125
|
+
declare function defineSpring(input: TensionDampingBounceOptions): SpringConfig;
|
|
126
|
+
/**
|
|
127
|
+
* Duration-based configuration. The spring is tuned so that its envelope
|
|
128
|
+
* decays to the resting threshold within the given duration.
|
|
129
|
+
* Tension and damping are both derived from dampingRatio and duration.
|
|
130
|
+
*/
|
|
131
|
+
declare function defineSpring(input: DurationOptions): SpringConfig;
|
|
132
|
+
/**
|
|
133
|
+
* Duration-based configuration. The spring is tuned so that its envelope
|
|
134
|
+
* decays to the resting threshold within the given duration.
|
|
135
|
+
* Bounce controls how oscillatory the motion is while settling.
|
|
136
|
+
* Tension and damping are both derived.
|
|
137
|
+
*/
|
|
138
|
+
declare function defineSpring(input: BounceDurationOptions): SpringConfig;
|
|
139
|
+
/**
|
|
140
|
+
* Duration-based with a tension constraint. Mass is derived from tension
|
|
141
|
+
* and the computed natural frequency; damping follows from mass and dampingRatio.
|
|
142
|
+
*/
|
|
143
|
+
declare function defineSpring(input: TensionDurationOptions): SpringConfig;
|
|
144
|
+
/**
|
|
145
|
+
* Duration-based with a tension constraint. Bounce controls how oscillatory
|
|
146
|
+
* the motion is while settling. Mass is derived from tension and the
|
|
147
|
+
* computed natural frequency.
|
|
148
|
+
*/
|
|
149
|
+
declare function defineSpring(input: TensionBounceDurationOptions): SpringConfig;
|
|
150
|
+
/**
|
|
151
|
+
* Duration-based with a damping constraint. Mass is derived from damping,
|
|
152
|
+
* dampingRatio, and the computed natural frequency; tension follows from mass.
|
|
153
|
+
*/
|
|
154
|
+
declare function defineSpring(input: DampingDurationOptions): SpringConfig;
|
|
155
|
+
/**
|
|
156
|
+
* Duration-based with a damping constraint. Bounce controls how oscillatory
|
|
157
|
+
* the motion is while settling. Mass is derived from damping and the
|
|
158
|
+
* computed natural frequency.
|
|
159
|
+
*/
|
|
160
|
+
declare function defineSpring(input: DampingBounceDurationOptions): SpringConfig;
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/motion.d.ts
|
|
163
|
+
declare class Motion {
|
|
164
|
+
#private;
|
|
165
|
+
constructor(config: SpringConfig, position: number, velocity: number);
|
|
166
|
+
get position(): number;
|
|
167
|
+
set position(value: number);
|
|
168
|
+
get velocity(): number;
|
|
169
|
+
set velocity(value: number);
|
|
170
|
+
get resting(): boolean;
|
|
171
|
+
configure(config: SpringConfig): void;
|
|
172
|
+
tick(dt: number, emit?: boolean): void;
|
|
173
|
+
onUpdate(callback: () => void): () => void;
|
|
174
|
+
onStart(callback: () => void): () => void;
|
|
175
|
+
onStop(callback: () => void): () => void;
|
|
176
|
+
dispose(): void;
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/motion-set.d.ts
|
|
180
|
+
declare class MotionSet {
|
|
181
|
+
#private;
|
|
182
|
+
add(motion: Motion): void;
|
|
183
|
+
remove(motion: Motion): void;
|
|
184
|
+
tick(dt: number): void;
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/spring.d.ts
|
|
188
|
+
interface DisplacedSpringPosition {
|
|
189
|
+
target?: number | undefined;
|
|
190
|
+
value?: number | undefined;
|
|
191
|
+
}
|
|
192
|
+
type SpringPosition = number | DisplacedSpringPosition;
|
|
193
|
+
declare class Spring {
|
|
194
|
+
#private;
|
|
195
|
+
constructor(motions: MotionSet, position: SpringPosition, config: SpringConfig);
|
|
196
|
+
get target(): number;
|
|
197
|
+
set target(value: number);
|
|
198
|
+
get value(): number;
|
|
199
|
+
set value(value: number);
|
|
200
|
+
get velocity(): number;
|
|
201
|
+
set velocity(value: number);
|
|
202
|
+
get mass(): number;
|
|
203
|
+
get tension(): number;
|
|
204
|
+
get damping(): number;
|
|
205
|
+
get dampingRatio(): number;
|
|
206
|
+
get precision(): number;
|
|
207
|
+
get resting(): boolean;
|
|
208
|
+
configure(config: SpringConfig): void;
|
|
209
|
+
onUpdate(callback: () => void): () => void;
|
|
210
|
+
onStart(callback: () => void): () => void;
|
|
211
|
+
onStop(callback: () => void): () => void;
|
|
212
|
+
jumpTo(value: number): void;
|
|
213
|
+
dispose(): void;
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/ticker.d.ts
|
|
217
|
+
interface TickerOptions {
|
|
218
|
+
/**
|
|
219
|
+
* The target frames per second for the simulation loop
|
|
220
|
+
*
|
|
221
|
+
* must be greater than 0, defaults to 60
|
|
222
|
+
*/
|
|
223
|
+
fps?: number | undefined;
|
|
224
|
+
/**
|
|
225
|
+
* The maximum elapsed time (in ms) before a frame is considered a lag spike
|
|
226
|
+
* (e.g. from a backgrounded tab). When exceeded, `adjustedLag` is used instead
|
|
227
|
+
* of the real elapsed time. Set to 0 to disable lag detection.
|
|
228
|
+
*
|
|
229
|
+
* must be greater than or equal to 0, defaults to 500
|
|
230
|
+
*/
|
|
231
|
+
lagThreshold?: number | undefined;
|
|
232
|
+
/**
|
|
233
|
+
* The substitute elapsed time (in ms) used when a lag spike is detected.
|
|
234
|
+
* Clamped to be at most `lagThreshold`.
|
|
235
|
+
*
|
|
236
|
+
* must be greater than or equal to 0, defaults to 33
|
|
237
|
+
*/
|
|
238
|
+
adjustedLag?: number | undefined;
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region src/system.d.ts
|
|
242
|
+
interface SpringSystem {
|
|
243
|
+
createSpring(position: SpringPosition, config: SpringConfig): Spring;
|
|
244
|
+
/** Advance all springs by `dt` milliseconds, without affecting internal timing. */
|
|
245
|
+
advance(dt: number): void;
|
|
246
|
+
/** Start the animation loop. */
|
|
247
|
+
start(): void;
|
|
248
|
+
/** Stop the animation loop. */
|
|
249
|
+
stop(): void;
|
|
250
|
+
/** Whether the animation loop is currently running. */
|
|
251
|
+
readonly running: boolean;
|
|
252
|
+
/**
|
|
253
|
+
* The target frames per second for the simulation loop.
|
|
254
|
+
*
|
|
255
|
+
* must be greater than 0
|
|
256
|
+
*/
|
|
257
|
+
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
|
+
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
|
+
adjustedLag: number;
|
|
273
|
+
}
|
|
274
|
+
declare function createSpringSystem(options?: TickerOptions): SpringSystem;
|
|
275
|
+
//#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 };
|