coily 0.13.1 → 0.15.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 +76 -40
- package/dist/config-OOMMRdK8.d.ts +312 -0
- package/dist/css.d.ts +175 -0
- package/dist/css.js +294 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +91 -2
- package/dist/nuxt.d.ts +46 -0
- package/dist/nuxt.js +14 -14
- package/dist/solver-CVXOTDkZ.js +235 -0
- package/dist/system-Br_cPnaN.js +2188 -0
- package/dist/system-Du_fXXmO.d.ts +940 -0
- package/dist/vue.d.ts +227 -16
- package/dist/vue.js +84 -42
- package/package.json +2 -1
- package/dist/system-86fsXJN_.d.ts +0 -386
- package/dist/system-Csho09XW.js +0 -1384
|
@@ -0,0 +1,235 @@
|
|
|
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. Class instances are excluded so shape
|
|
9
|
+
* walks reject values like a `Spring` instead of descending into their
|
|
10
|
+
* fields as if they were nested shapes.
|
|
11
|
+
*/
|
|
12
|
+
function isRecord(value) {
|
|
13
|
+
if (typeof value !== "object" || value === null) return false;
|
|
14
|
+
const proto = Object.getPrototypeOf(value);
|
|
15
|
+
return proto === Object.prototype || proto === null;
|
|
16
|
+
}
|
|
17
|
+
function isRecordOrArray(value) {
|
|
18
|
+
return isRecord(value) || Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
function isArray(value) {
|
|
21
|
+
return Array.isArray(value);
|
|
22
|
+
}
|
|
23
|
+
function isNumber(value) {
|
|
24
|
+
return typeof value === "number";
|
|
25
|
+
}
|
|
26
|
+
const RESOLVED = Promise.resolve();
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/state.ts
|
|
29
|
+
/**
|
|
30
|
+
* The mutable position/velocity pair a motion and its solvers share, in
|
|
31
|
+
* displacement space: position 0 means at the target.
|
|
32
|
+
*/
|
|
33
|
+
var State = class {
|
|
34
|
+
#config;
|
|
35
|
+
#position;
|
|
36
|
+
#velocity;
|
|
37
|
+
constructor(config, position, velocity) {
|
|
38
|
+
this.#config = config;
|
|
39
|
+
this.#position = position;
|
|
40
|
+
this.#velocity = velocity;
|
|
41
|
+
}
|
|
42
|
+
configure(config) {
|
|
43
|
+
this.#config = config;
|
|
44
|
+
}
|
|
45
|
+
get position() {
|
|
46
|
+
return this.#position;
|
|
47
|
+
}
|
|
48
|
+
set position(value) {
|
|
49
|
+
this.#position = value;
|
|
50
|
+
}
|
|
51
|
+
get velocity() {
|
|
52
|
+
return this.#velocity;
|
|
53
|
+
}
|
|
54
|
+
set velocity(value) {
|
|
55
|
+
this.#velocity = value;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The rest test: displacement, plus the displacement the current
|
|
59
|
+
* velocity could still convert into (|x| + |v| / wn), is inside the
|
|
60
|
+
* config's resting threshold.
|
|
61
|
+
*/
|
|
62
|
+
get isResting() {
|
|
63
|
+
return Math.abs(this.#position) + Math.abs(this.#velocity) / this.#config.naturalFrequency <= this.#config.restingMagnitude;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/solver.ts
|
|
68
|
+
/** dampingRatio < 1: decaying oscillation, x(t) = exp(-sigma*t) * (c1*cos(wd*t) + c2*sin(wd*t)). */
|
|
69
|
+
var UnderdampedSolver = class {
|
|
70
|
+
#state;
|
|
71
|
+
#dampedFrequency = 0;
|
|
72
|
+
#decayRate = 0;
|
|
73
|
+
#arrival = 1;
|
|
74
|
+
#t = 0;
|
|
75
|
+
#c1 = 0;
|
|
76
|
+
#c2 = 0;
|
|
77
|
+
#crossing = Infinity;
|
|
78
|
+
constructor(state) {
|
|
79
|
+
this.#state = state;
|
|
80
|
+
}
|
|
81
|
+
configure(config) {
|
|
82
|
+
if (config) {
|
|
83
|
+
this.#decayRate = config.dampingRatio * config.naturalFrequency;
|
|
84
|
+
this.#dampedFrequency = config.naturalFrequency * Math.sqrt(1 - config.dampingRatio ** 2);
|
|
85
|
+
this.#arrival = config.arrival;
|
|
86
|
+
}
|
|
87
|
+
this.#t = 0;
|
|
88
|
+
this.#c1 = this.#state.position;
|
|
89
|
+
this.#c2 = (this.#state.velocity + this.#decayRate * this.#state.position) / this.#dampedFrequency;
|
|
90
|
+
if (this.#arrival === 1) this.#crossing = Infinity;
|
|
91
|
+
else {
|
|
92
|
+
let theta = Math.atan2(-this.#c1, this.#c2) % Math.PI;
|
|
93
|
+
if (theta <= 0) theta += Math.PI;
|
|
94
|
+
this.#crossing = theta / this.#dampedFrequency;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
tick(dt) {
|
|
98
|
+
let t = this.#t + dt;
|
|
99
|
+
while (t >= this.#crossing) {
|
|
100
|
+
t -= this.#crossing;
|
|
101
|
+
this.#arrive();
|
|
102
|
+
if (this.#state.isResting) return;
|
|
103
|
+
}
|
|
104
|
+
this.#t = t;
|
|
105
|
+
this.#evaluate();
|
|
106
|
+
}
|
|
107
|
+
#arrive() {
|
|
108
|
+
this.#t = this.#crossing;
|
|
109
|
+
this.#evaluate();
|
|
110
|
+
this.#state.position = 0;
|
|
111
|
+
this.#state.velocity *= this.#arrival;
|
|
112
|
+
this.configure();
|
|
113
|
+
}
|
|
114
|
+
#evaluate() {
|
|
115
|
+
const sin = Math.sin(this.#dampedFrequency * this.#t);
|
|
116
|
+
const cos = Math.cos(this.#dampedFrequency * this.#t);
|
|
117
|
+
const decay = Math.exp(-this.#decayRate * this.#t);
|
|
118
|
+
const decayVelocity = -this.#decayRate * decay;
|
|
119
|
+
const oscillation = this.#c1 * cos + this.#c2 * sin;
|
|
120
|
+
const oscillationVelocity = -this.#c1 * this.#dampedFrequency * sin + this.#c2 * this.#dampedFrequency * cos;
|
|
121
|
+
this.#state.position = decay * oscillation;
|
|
122
|
+
this.#state.velocity = decay * oscillationVelocity + decayVelocity * oscillation;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
/** dampingRatio = 1: fastest non-oscillating decay, x(t) = (c1 + c2*t) * exp(-wn*t). */
|
|
126
|
+
var CriticallyDampedSolver = class {
|
|
127
|
+
#state;
|
|
128
|
+
#naturalFrequency = 0;
|
|
129
|
+
#arrival = 1;
|
|
130
|
+
#t = 0;
|
|
131
|
+
#c1 = 0;
|
|
132
|
+
#c2 = 0;
|
|
133
|
+
#crossing = Infinity;
|
|
134
|
+
constructor(state) {
|
|
135
|
+
this.#state = state;
|
|
136
|
+
}
|
|
137
|
+
configure(config) {
|
|
138
|
+
if (config) {
|
|
139
|
+
this.#naturalFrequency = config.naturalFrequency;
|
|
140
|
+
this.#arrival = config.arrival;
|
|
141
|
+
}
|
|
142
|
+
this.#t = 0;
|
|
143
|
+
this.#c1 = this.#state.position;
|
|
144
|
+
this.#c2 = this.#state.velocity + this.#naturalFrequency * this.#state.position;
|
|
145
|
+
if (this.#arrival === 1) this.#crossing = Infinity;
|
|
146
|
+
else {
|
|
147
|
+
const t = -this.#c1 / this.#c2;
|
|
148
|
+
this.#crossing = t > 0 ? t : Infinity;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
tick(dt) {
|
|
152
|
+
let t = this.#t + dt;
|
|
153
|
+
while (t >= this.#crossing) {
|
|
154
|
+
t -= this.#crossing;
|
|
155
|
+
this.#arrive();
|
|
156
|
+
if (this.#state.isResting) return;
|
|
157
|
+
}
|
|
158
|
+
this.#t = t;
|
|
159
|
+
this.#evaluate();
|
|
160
|
+
}
|
|
161
|
+
#arrive() {
|
|
162
|
+
this.#t = this.#crossing;
|
|
163
|
+
this.#evaluate();
|
|
164
|
+
this.#state.position = 0;
|
|
165
|
+
this.#state.velocity *= this.#arrival;
|
|
166
|
+
this.configure();
|
|
167
|
+
}
|
|
168
|
+
#evaluate() {
|
|
169
|
+
const decay = Math.exp(-this.#naturalFrequency * this.#t);
|
|
170
|
+
const decayVelocity = -this.#naturalFrequency * decay;
|
|
171
|
+
const scale = this.#c1 + this.#c2 * this.#t;
|
|
172
|
+
const scaleVelocity = this.#c2;
|
|
173
|
+
this.#state.position = scale * decay;
|
|
174
|
+
this.#state.velocity = scaleVelocity * decay + decayVelocity * scale;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
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 decay = Math.exp(-this.#decayRate * this.#t);
|
|
224
|
+
const decayVelocity = -this.#decayRate * decay;
|
|
225
|
+
const clamped = Math.min(this.#dampedFrequency * this.#t, 300);
|
|
226
|
+
const sinh = Math.sinh(clamped);
|
|
227
|
+
const cosh = Math.cosh(clamped);
|
|
228
|
+
const scale = this.#c1 * sinh + this.#c2 * cosh;
|
|
229
|
+
const scaleVelocity = this.#c1 * this.#dampedFrequency * cosh + this.#c2 * this.#dampedFrequency * sinh;
|
|
230
|
+
this.#state.position = scale * decay / this.#dampedFrequency;
|
|
231
|
+
this.#state.velocity = (scale * decayVelocity + scaleVelocity * decay) / this.#dampedFrequency;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
//#endregion
|
|
235
|
+
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 };
|