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,243 @@
|
|
|
1
|
+
//#region src/util.ts
|
|
2
|
+
function invariant(condition, message) {
|
|
3
|
+
if (condition) return;
|
|
4
|
+
const resolved = typeof message === "function" ? message() : message;
|
|
5
|
+
throw new Error(resolved ?? "Invariant Failed");
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* True for plain objects only. Excluding class instances makes shape walks
|
|
9
|
+
* reject a `Spring` instead of descending into it as a nested shape.
|
|
10
|
+
*/
|
|
11
|
+
function isRecord(value) {
|
|
12
|
+
if (typeof value !== "object" || value === null) return false;
|
|
13
|
+
const proto = Object.getPrototypeOf(value);
|
|
14
|
+
return proto === Object.prototype || proto === null;
|
|
15
|
+
}
|
|
16
|
+
function isRecordOrArray(value) {
|
|
17
|
+
return isRecord(value) || Array.isArray(value);
|
|
18
|
+
}
|
|
19
|
+
function isArray(value) {
|
|
20
|
+
return Array.isArray(value);
|
|
21
|
+
}
|
|
22
|
+
function isNumber(value) {
|
|
23
|
+
return typeof value === "number";
|
|
24
|
+
}
|
|
25
|
+
const RESOLVED = Promise.resolve();
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/state.ts
|
|
28
|
+
/**
|
|
29
|
+
* The mutable position and velocity that a motion and its solvers share,
|
|
30
|
+
* in displacement space. Position 0 means at the target.
|
|
31
|
+
*/
|
|
32
|
+
var State = class {
|
|
33
|
+
#config;
|
|
34
|
+
#position;
|
|
35
|
+
#velocity;
|
|
36
|
+
constructor(config, position, velocity) {
|
|
37
|
+
this.#config = config;
|
|
38
|
+
this.#position = position;
|
|
39
|
+
this.#velocity = velocity;
|
|
40
|
+
}
|
|
41
|
+
configure(config) {
|
|
42
|
+
this.#config = config;
|
|
43
|
+
}
|
|
44
|
+
get position() {
|
|
45
|
+
return this.#position;
|
|
46
|
+
}
|
|
47
|
+
set position(value) {
|
|
48
|
+
this.#position = value;
|
|
49
|
+
}
|
|
50
|
+
get velocity() {
|
|
51
|
+
return this.#velocity;
|
|
52
|
+
}
|
|
53
|
+
set velocity(value) {
|
|
54
|
+
this.#velocity = value;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* True when |x| + |v| / wn, the displacement plus what the velocity could
|
|
58
|
+
* still add, is within the config's resting threshold.
|
|
59
|
+
*/
|
|
60
|
+
get isResting() {
|
|
61
|
+
return Math.abs(this.#position) + Math.abs(this.#velocity) / this.#config.naturalFrequency <= this.#config.restingMagnitude;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/solver.ts
|
|
66
|
+
/** dampingRatio < 1: decaying oscillation, x(t) = exp(-sigma*t) * (c1*cos(wd*t) + c2*sin(wd*t)). */
|
|
67
|
+
var UnderdampedSolver = class {
|
|
68
|
+
#state;
|
|
69
|
+
#dampedFrequency = 0;
|
|
70
|
+
#decayRate = 0;
|
|
71
|
+
#arrival = 1;
|
|
72
|
+
#t = 0;
|
|
73
|
+
#c1 = 0;
|
|
74
|
+
#c2 = 0;
|
|
75
|
+
#crossing = Infinity;
|
|
76
|
+
constructor(state) {
|
|
77
|
+
this.#state = state;
|
|
78
|
+
}
|
|
79
|
+
configure(config) {
|
|
80
|
+
if (config) {
|
|
81
|
+
this.#decayRate = config.dampingRatio * config.naturalFrequency;
|
|
82
|
+
this.#dampedFrequency = config.naturalFrequency * Math.sqrt(1 - config.dampingRatio ** 2);
|
|
83
|
+
this.#arrival = config.arrival;
|
|
84
|
+
}
|
|
85
|
+
this.#t = 0;
|
|
86
|
+
this.#c1 = this.#state.position;
|
|
87
|
+
this.#c2 = (this.#state.velocity + this.#decayRate * this.#state.position) / this.#dampedFrequency;
|
|
88
|
+
if (this.#arrival === 1) this.#crossing = Infinity;
|
|
89
|
+
else {
|
|
90
|
+
let theta = Math.atan2(-this.#c1, this.#c2) % Math.PI;
|
|
91
|
+
if (theta <= 0) theta += Math.PI;
|
|
92
|
+
this.#crossing = theta / this.#dampedFrequency;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
tick(dt) {
|
|
96
|
+
let t = this.#t + dt;
|
|
97
|
+
while (t >= this.#crossing) {
|
|
98
|
+
t -= this.#crossing;
|
|
99
|
+
this.#arrive();
|
|
100
|
+
if (this.#state.isResting) return;
|
|
101
|
+
}
|
|
102
|
+
this.#t = t;
|
|
103
|
+
this.#evaluate();
|
|
104
|
+
}
|
|
105
|
+
#arrive() {
|
|
106
|
+
this.#t = this.#crossing;
|
|
107
|
+
this.#evaluate();
|
|
108
|
+
this.#state.position = 0;
|
|
109
|
+
this.#state.velocity *= this.#arrival;
|
|
110
|
+
this.configure();
|
|
111
|
+
}
|
|
112
|
+
#evaluate() {
|
|
113
|
+
const sin = Math.sin(this.#dampedFrequency * this.#t);
|
|
114
|
+
const cos = Math.cos(this.#dampedFrequency * this.#t);
|
|
115
|
+
const decay = Math.exp(-this.#decayRate * this.#t);
|
|
116
|
+
const decayVelocity = -this.#decayRate * decay;
|
|
117
|
+
const oscillation = this.#c1 * cos + this.#c2 * sin;
|
|
118
|
+
const oscillationVelocity = -this.#c1 * this.#dampedFrequency * sin + this.#c2 * this.#dampedFrequency * cos;
|
|
119
|
+
this.#state.position = decay * oscillation;
|
|
120
|
+
this.#state.velocity = decay * oscillationVelocity + decayVelocity * oscillation;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
/** dampingRatio = 1: fastest non-oscillating decay, x(t) = (c1 + c2*t) * exp(-wn*t). */
|
|
124
|
+
var CriticallyDampedSolver = class {
|
|
125
|
+
#state;
|
|
126
|
+
#naturalFrequency = 0;
|
|
127
|
+
#arrival = 1;
|
|
128
|
+
#t = 0;
|
|
129
|
+
#c1 = 0;
|
|
130
|
+
#c2 = 0;
|
|
131
|
+
#crossing = Infinity;
|
|
132
|
+
constructor(state) {
|
|
133
|
+
this.#state = state;
|
|
134
|
+
}
|
|
135
|
+
configure(config) {
|
|
136
|
+
if (config) {
|
|
137
|
+
this.#naturalFrequency = config.naturalFrequency;
|
|
138
|
+
this.#arrival = config.arrival;
|
|
139
|
+
}
|
|
140
|
+
this.#t = 0;
|
|
141
|
+
this.#c1 = this.#state.position;
|
|
142
|
+
this.#c2 = this.#state.velocity + this.#naturalFrequency * this.#state.position;
|
|
143
|
+
if (this.#arrival === 1) this.#crossing = Infinity;
|
|
144
|
+
else {
|
|
145
|
+
const t = -this.#c1 / this.#c2;
|
|
146
|
+
this.#crossing = t > 0 ? t : Infinity;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
tick(dt) {
|
|
150
|
+
let t = this.#t + dt;
|
|
151
|
+
while (t >= this.#crossing) {
|
|
152
|
+
t -= this.#crossing;
|
|
153
|
+
this.#arrive();
|
|
154
|
+
if (this.#state.isResting) return;
|
|
155
|
+
}
|
|
156
|
+
this.#t = t;
|
|
157
|
+
this.#evaluate();
|
|
158
|
+
}
|
|
159
|
+
#arrive() {
|
|
160
|
+
this.#t = this.#crossing;
|
|
161
|
+
this.#evaluate();
|
|
162
|
+
this.#state.position = 0;
|
|
163
|
+
this.#state.velocity *= this.#arrival;
|
|
164
|
+
this.configure();
|
|
165
|
+
}
|
|
166
|
+
#evaluate() {
|
|
167
|
+
const decay = Math.exp(-this.#naturalFrequency * this.#t);
|
|
168
|
+
const decayVelocity = -this.#naturalFrequency * decay;
|
|
169
|
+
const scale = this.#c1 + this.#c2 * this.#t;
|
|
170
|
+
const scaleVelocity = this.#c2;
|
|
171
|
+
this.#state.position = scale * decay;
|
|
172
|
+
this.#state.velocity = scaleVelocity * decay + decayVelocity * scale;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
/** The `wd * t` past which `OverdampedSolver` evaluates only its slow mode. */
|
|
176
|
+
const TAIL = 20;
|
|
177
|
+
/** dampingRatio > 1: slow non-oscillating decay, x(t) = exp(-sigma*t) * (c1*sinh(wd*t) + c2*cosh(wd*t)) / wd. */
|
|
178
|
+
var OverdampedSolver = class {
|
|
179
|
+
#state;
|
|
180
|
+
#dampedFrequency = 0;
|
|
181
|
+
#decayRate = 0;
|
|
182
|
+
#arrival = 1;
|
|
183
|
+
#t = 0;
|
|
184
|
+
#c1 = 0;
|
|
185
|
+
#c2 = 0;
|
|
186
|
+
#crossing = Infinity;
|
|
187
|
+
constructor(state) {
|
|
188
|
+
this.#state = state;
|
|
189
|
+
}
|
|
190
|
+
configure(config) {
|
|
191
|
+
if (config) {
|
|
192
|
+
this.#decayRate = config.dampingRatio * config.naturalFrequency;
|
|
193
|
+
this.#dampedFrequency = config.naturalFrequency * Math.sqrt(config.dampingRatio ** 2 - 1);
|
|
194
|
+
this.#arrival = config.arrival;
|
|
195
|
+
}
|
|
196
|
+
this.#t = 0;
|
|
197
|
+
this.#c1 = this.#state.velocity + this.#decayRate * this.#state.position;
|
|
198
|
+
this.#c2 = this.#state.position * this.#dampedFrequency;
|
|
199
|
+
if (this.#arrival === 1) this.#crossing = Infinity;
|
|
200
|
+
else {
|
|
201
|
+
const theta = Math.atanh(-this.#c2 / this.#c1);
|
|
202
|
+
this.#crossing = theta > 0 ? theta / this.#dampedFrequency : Infinity;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
tick(dt) {
|
|
206
|
+
let t = this.#t + dt;
|
|
207
|
+
while (t >= this.#crossing) {
|
|
208
|
+
t -= this.#crossing;
|
|
209
|
+
this.#arrive();
|
|
210
|
+
if (this.#state.isResting) return;
|
|
211
|
+
}
|
|
212
|
+
this.#t = t;
|
|
213
|
+
this.#evaluate();
|
|
214
|
+
}
|
|
215
|
+
#arrive() {
|
|
216
|
+
this.#t = this.#crossing;
|
|
217
|
+
this.#evaluate();
|
|
218
|
+
this.#state.position = 0;
|
|
219
|
+
this.#state.velocity *= this.#arrival;
|
|
220
|
+
this.configure();
|
|
221
|
+
}
|
|
222
|
+
#evaluate() {
|
|
223
|
+
const wd = this.#dampedFrequency;
|
|
224
|
+
const wdt = wd * this.#t;
|
|
225
|
+
if (wdt > TAIL) {
|
|
226
|
+
const slowRate = wd - this.#decayRate;
|
|
227
|
+
const position = (this.#c1 + this.#c2) / (2 * wd) * Math.exp(slowRate * this.#t);
|
|
228
|
+
this.#state.position = position;
|
|
229
|
+
this.#state.velocity = slowRate * position;
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const decay = Math.exp(-this.#decayRate * this.#t);
|
|
233
|
+
const decayVelocity = -this.#decayRate * decay;
|
|
234
|
+
const sinh = Math.sinh(wdt);
|
|
235
|
+
const cosh = Math.cosh(wdt);
|
|
236
|
+
const scale = this.#c1 * sinh + this.#c2 * cosh;
|
|
237
|
+
const scaleVelocity = this.#c1 * wd * cosh + this.#c2 * wd * sinh;
|
|
238
|
+
this.#state.position = scale * decay / wd;
|
|
239
|
+
this.#state.velocity = (scale * decayVelocity + scaleVelocity * decay) / wd;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
//#endregion
|
|
243
|
+
export { RESOLVED as a, isNumber as c, State as i, isRecord as l, OverdampedSolver as n, invariant as o, UnderdampedSolver as r, isArray as s, CriticallyDampedSolver as t, isRecordOrArray as u };
|