coily 0.1.1 → 0.2.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/dist/index.cjs +19 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +15 -5
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
|
|
23
26
|
// src/index.ts
|
|
@@ -51,13 +54,14 @@ var getArrivalFunction = (behavior) => {
|
|
|
51
54
|
return result;
|
|
52
55
|
};
|
|
53
56
|
var createSpringImpl = (initial, config, options) => {
|
|
57
|
+
var _a, _b, _c;
|
|
54
58
|
let state = "resting";
|
|
55
59
|
let velocity = 0;
|
|
56
60
|
let target = initial;
|
|
57
61
|
let value = initial;
|
|
58
|
-
const restingDistance = Math.max((options == null ? void 0 : options.restingDistance)
|
|
59
|
-
const restingVelocity = Math.max((options == null ? void 0 : options.restingVelocity)
|
|
60
|
-
const arrivalFunction = getArrivalFunction((options == null ? void 0 : options.arrivalBehavior)
|
|
62
|
+
const restingDistance = Math.max((_a = options == null ? void 0 : options.restingDistance) != null ? _a : 1e-4, 0);
|
|
63
|
+
const restingVelocity = Math.max((_b = options == null ? void 0 : options.restingVelocity) != null ? _b : 1e-4, 0);
|
|
64
|
+
const arrivalFunction = getArrivalFunction((_c = options == null ? void 0 : options.arrivalBehavior) != null ? _c : 1);
|
|
61
65
|
const emitter = (0, import_mitt.default)();
|
|
62
66
|
const { emit, ...emitterApi } = emitter;
|
|
63
67
|
const spring = {
|
|
@@ -161,7 +165,12 @@ var createSpringChainImpl = (initial, links, config, options) => {
|
|
|
161
165
|
if (typeof link === "number") {
|
|
162
166
|
spring.target = previousSpring.value + link;
|
|
163
167
|
} else {
|
|
164
|
-
spring.target = link(
|
|
168
|
+
spring.target = link(
|
|
169
|
+
previousSpring.value,
|
|
170
|
+
previousSpring.target,
|
|
171
|
+
spring.value,
|
|
172
|
+
spring.target
|
|
173
|
+
);
|
|
165
174
|
}
|
|
166
175
|
targets[index + 1] = spring.target;
|
|
167
176
|
states[index + 1] = spring.state;
|
|
@@ -169,7 +178,11 @@ var createSpringChainImpl = (initial, links, config, options) => {
|
|
|
169
178
|
state = "moving";
|
|
170
179
|
}
|
|
171
180
|
} else {
|
|
172
|
-
const [spring, simulate2] = createSpringImpl(
|
|
181
|
+
const [spring, simulate2] = createSpringImpl(
|
|
182
|
+
typeof link === "number" ? previousSpring.value + link : link(previousSpring.value, previousSpring.target),
|
|
183
|
+
config,
|
|
184
|
+
options
|
|
185
|
+
);
|
|
173
186
|
springs.push(spring);
|
|
174
187
|
simulateFns.push(simulate2);
|
|
175
188
|
targets[index + 1] = spring.target;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,14 +5,14 @@ interface SpringConfig {
|
|
|
5
5
|
tension: number;
|
|
6
6
|
friction: number;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
type SpringArrivalBehavior = 'bounce' | 'clamp' | 'none' | number | ((velocity: number) => number);
|
|
9
9
|
interface SpringOptions {
|
|
10
10
|
restingDistance?: number;
|
|
11
11
|
restingVelocity?: number;
|
|
12
12
|
arrivalBehavior?: SpringArrivalBehavior;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
type SpringState = 'moving' | 'frozen' | 'resting';
|
|
15
|
+
type SpringEmitter = Emitter<{
|
|
16
16
|
'update:value': number;
|
|
17
17
|
'update:state': SpringState;
|
|
18
18
|
'*': number | SpringState;
|
|
@@ -26,12 +26,12 @@ interface Spring extends Omit<SpringEmitter, 'emit'> {
|
|
|
26
26
|
readonly freeze: () => void;
|
|
27
27
|
readonly unfreeze: () => void;
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
type SimulateFn = (delta: number) => void;
|
|
30
30
|
interface StandaloneSpring extends Spring {
|
|
31
31
|
readonly simulate: SimulateFn;
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
type SpringChainLinkGetter = number | ((previousValue: number, previousTarget: number, currentValue?: number, currentTarget?: number) => number);
|
|
34
|
+
type SpringChainEmitter = Emitter<{
|
|
35
35
|
'update:value': number[];
|
|
36
36
|
'update:state': SpringState;
|
|
37
37
|
'*': number[] | SpringState;
|
package/dist/index.js
CHANGED
|
@@ -20,13 +20,14 @@ var getArrivalFunction = (behavior) => {
|
|
|
20
20
|
return result;
|
|
21
21
|
};
|
|
22
22
|
var createSpringImpl = (initial, config, options) => {
|
|
23
|
+
var _a, _b, _c;
|
|
23
24
|
let state = "resting";
|
|
24
25
|
let velocity = 0;
|
|
25
26
|
let target = initial;
|
|
26
27
|
let value = initial;
|
|
27
|
-
const restingDistance = Math.max((options == null ? void 0 : options.restingDistance)
|
|
28
|
-
const restingVelocity = Math.max((options == null ? void 0 : options.restingVelocity)
|
|
29
|
-
const arrivalFunction = getArrivalFunction((options == null ? void 0 : options.arrivalBehavior)
|
|
28
|
+
const restingDistance = Math.max((_a = options == null ? void 0 : options.restingDistance) != null ? _a : 1e-4, 0);
|
|
29
|
+
const restingVelocity = Math.max((_b = options == null ? void 0 : options.restingVelocity) != null ? _b : 1e-4, 0);
|
|
30
|
+
const arrivalFunction = getArrivalFunction((_c = options == null ? void 0 : options.arrivalBehavior) != null ? _c : 1);
|
|
30
31
|
const emitter = mitt();
|
|
31
32
|
const { emit, ...emitterApi } = emitter;
|
|
32
33
|
const spring = {
|
|
@@ -130,7 +131,12 @@ var createSpringChainImpl = (initial, links, config, options) => {
|
|
|
130
131
|
if (typeof link === "number") {
|
|
131
132
|
spring.target = previousSpring.value + link;
|
|
132
133
|
} else {
|
|
133
|
-
spring.target = link(
|
|
134
|
+
spring.target = link(
|
|
135
|
+
previousSpring.value,
|
|
136
|
+
previousSpring.target,
|
|
137
|
+
spring.value,
|
|
138
|
+
spring.target
|
|
139
|
+
);
|
|
134
140
|
}
|
|
135
141
|
targets[index + 1] = spring.target;
|
|
136
142
|
states[index + 1] = spring.state;
|
|
@@ -138,7 +144,11 @@ var createSpringChainImpl = (initial, links, config, options) => {
|
|
|
138
144
|
state = "moving";
|
|
139
145
|
}
|
|
140
146
|
} else {
|
|
141
|
-
const [spring, simulate2] = createSpringImpl(
|
|
147
|
+
const [spring, simulate2] = createSpringImpl(
|
|
148
|
+
typeof link === "number" ? previousSpring.value + link : link(previousSpring.value, previousSpring.target),
|
|
149
|
+
config,
|
|
150
|
+
options
|
|
151
|
+
);
|
|
142
152
|
springs.push(spring);
|
|
143
153
|
simulateFns.push(simulate2);
|
|
144
154
|
targets[index + 1] = spring.target;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coily",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Simulate values using spring physics",
|
|
5
5
|
"author": "Tim Morris <timthewebguy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/tkofh/coily#readme",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"test": "vitest run",
|
|
33
33
|
"test:watch": "vitest watch",
|
|
34
34
|
"test:ui": "vitest --ui",
|
|
35
|
-
"prepublish": "
|
|
35
|
+
"prepublish": "pnpm test && pnpm build"
|
|
36
36
|
},
|
|
37
37
|
"bugs": {
|
|
38
38
|
"url": "https://github.com/tkofh/coily/issues"
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"mitt": "^3.0.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "f2a3ee966126e974e2fd3576bc0968c03c0287ca"
|
|
49
49
|
}
|