coily 0.12.2 → 0.13.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.
- package/README.md +109 -192
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/nuxt.d.ts +4 -1
- package/dist/nuxt.js +18 -3
- package/dist/{system-coAFNYnb.d.ts → system-86fsXJN_.d.ts} +133 -97
- package/dist/system-Csho09XW.js +1384 -0
- package/dist/vue.d.ts +26 -21
- package/dist/vue.js +118 -264
- package/package.json +16 -16
- package/dist/system-Bzrx4uso.js +0 -976
package/dist/vue.d.ts
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as vue from "vue";
|
|
1
|
+
import { _ as SpringOptions, a as ConfigShape, c as Shape, f as Spring, g as SpringConfig, l as SpringObject, n as SpringSystemOptions, o as PartialShape, p as SpringPosition, s as ReadonlyShape, t as SpringSystem } from "./system-86fsXJN_.js";
|
|
3
2
|
import { App, MaybeRefOrGetter, Ref, SlotsType } from "vue";
|
|
4
|
-
|
|
5
|
-
//#region src/vue/spring.d.ts
|
|
3
|
+
//#region src/vue/reactive-spring.d.ts
|
|
6
4
|
type UseSpringOptions = MaybeRefOrGetter<SpringOptions | SpringConfig | undefined>;
|
|
7
|
-
interface
|
|
8
|
-
readonly velocity: Ref<
|
|
5
|
+
interface ReactiveSpringRef<V, W = V> extends Ref<V, W> {
|
|
6
|
+
readonly velocity: Ref<V, W>;
|
|
9
7
|
readonly timeRemaining: Ref<number>;
|
|
10
8
|
readonly isResting: Ref<boolean>;
|
|
11
|
-
readonly
|
|
9
|
+
readonly settled: Promise<void>;
|
|
10
|
+
readonly jumpTo: (value: W) => void;
|
|
12
11
|
}
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/vue/spring-object.d.ts
|
|
14
|
+
type UseSpringObjectOptions<T extends object> = MaybeRefOrGetter<ConfigShape<T> | undefined>;
|
|
15
|
+
interface SpringObjectRef<T extends object> extends ReactiveSpringRef<ReadonlyShape<T>, PartialShape<T>> {}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/vue/spring.d.ts
|
|
18
|
+
interface SpringRef extends ReactiveSpringRef<number> {}
|
|
13
19
|
declare function useSpring(target: MaybeRefOrGetter<number>, options?: UseSpringOptions): SpringRef;
|
|
14
20
|
declare function useSpring(target: SpringRef, options?: UseSpringOptions): SpringRef;
|
|
15
|
-
declare function useSpring<
|
|
21
|
+
declare function useSpring<T extends object>(target: SpringObjectRef<T>, options?: UseSpringObjectOptions<T>): SpringObjectRef<T>;
|
|
22
|
+
declare function useSpring<T extends object>(target: T & Shape<T>, options?: UseSpringObjectOptions<T>): SpringObjectRef<T>;
|
|
23
|
+
declare function useSpring<T extends object>(target: Ref<T & Shape<T>>, options?: UseSpringObjectOptions<T>): SpringObjectRef<T>;
|
|
24
|
+
declare function useSpring<T extends object>(target: () => T & Shape<T>, options?: UseSpringObjectOptions<T>): SpringObjectRef<T>;
|
|
16
25
|
//#endregion
|
|
17
|
-
//#region src/vue/
|
|
18
|
-
interface
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
readonly isResting: Ref<boolean>;
|
|
22
|
-
readonly jumpTo: (value: Vector2) => void;
|
|
26
|
+
//#region src/vue/pool.d.ts
|
|
27
|
+
interface SpringPool {
|
|
28
|
+
createSpring(position: SpringPosition, config?: SpringConfig): Spring;
|
|
29
|
+
createSpringObject<T extends object>(value: T & Shape<T>, config?: ConfigShape<T>): SpringObject<T>;
|
|
23
30
|
}
|
|
24
|
-
declare function
|
|
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 };
|
|
31
|
+
declare function useSpringPool(): SpringPool;
|
|
27
32
|
//#endregion
|
|
28
33
|
//#region src/vue/component.d.ts
|
|
29
34
|
interface SpringValueProps {
|
|
@@ -41,12 +46,12 @@ interface SpringValueSlotScope {
|
|
|
41
46
|
type SpringValueSlots = SlotsType<{
|
|
42
47
|
default: SpringValueSlotScope;
|
|
43
48
|
}>;
|
|
44
|
-
declare const SpringValue: vue.DefineSetupFnComponent<SpringValueProps, SpringValueEmits, SpringValueSlots, SpringValueProps & {
|
|
49
|
+
declare const SpringValue: import("vue").DefineSetupFnComponent<SpringValueProps, SpringValueEmits, SpringValueSlots, SpringValueProps & {
|
|
45
50
|
[x: `on${Capitalize<string>}`]: ((...args: unknown[]) => any) | undefined;
|
|
46
|
-
}, vue.PublicProps>;
|
|
51
|
+
}, import("vue").PublicProps>;
|
|
47
52
|
//#endregion
|
|
48
53
|
//#region src/vue/system.d.ts
|
|
49
54
|
declare function provideSpringSystem(system: SpringSystem, app?: App): void;
|
|
50
|
-
declare function useSpringSystem(options?: SpringSystemOptions):
|
|
55
|
+
declare function useSpringSystem(options?: SpringSystemOptions): SpringSystem;
|
|
51
56
|
//#endregion
|
|
52
|
-
export { type
|
|
57
|
+
export { type SpringObjectRef, type SpringPool, type SpringRef, SpringValue, type SpringValueProps, type SpringValueSlots, type UseSpringObjectOptions, provideSpringSystem, useSpring, useSpringPool, useSpringSystem };
|
package/dist/vue.js
CHANGED
|
@@ -1,46 +1,62 @@
|
|
|
1
|
-
import { n as SpringConfig, t as createSpringSystem } from "./system-
|
|
2
|
-
import { computed, customRef, defineComponent, getCurrentScope, inject, onBeforeUnmount, onMounted, onScopeDispose, provide, toRefs, toValue, watchSyncEffect } from "vue";
|
|
1
|
+
import { n as SpringConfig, t as createSpringSystem } from "./system-Csho09XW.js";
|
|
2
|
+
import { computed, customRef, defineComponent, getCurrentInstance, getCurrentScope, inject, onBeforeUnmount, onMounted, onScopeDispose, provide, toRefs, toValue, watchSyncEffect } from "vue";
|
|
3
|
+
//#region src/vue/local.ts
|
|
4
|
+
const localProvides = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
function provideLocal(key, value) {
|
|
6
|
+
const instance = getCurrentInstance();
|
|
7
|
+
if (instance) {
|
|
8
|
+
let values = localProvides.get(instance);
|
|
9
|
+
if (!values) {
|
|
10
|
+
values = /* @__PURE__ */ new Map();
|
|
11
|
+
localProvides.set(instance, values);
|
|
12
|
+
}
|
|
13
|
+
values.set(key, value);
|
|
14
|
+
}
|
|
15
|
+
provide(key, value);
|
|
16
|
+
}
|
|
17
|
+
function injectLocal(key) {
|
|
18
|
+
const instance = getCurrentInstance();
|
|
19
|
+
if (instance) {
|
|
20
|
+
const values = localProvides.get(instance);
|
|
21
|
+
if (values?.has(key)) return values.get(key);
|
|
22
|
+
}
|
|
23
|
+
return inject(key, void 0);
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
3
26
|
//#region src/vue/system.ts
|
|
4
27
|
const SpringSystemKey = Symbol.for("coily/spring-system");
|
|
5
28
|
function provideSpringSystem(system, app) {
|
|
6
29
|
if (app) app.provide(SpringSystemKey, system);
|
|
7
|
-
else
|
|
30
|
+
else provideLocal(SpringSystemKey, system);
|
|
8
31
|
}
|
|
9
32
|
function useSpringSystem(options) {
|
|
33
|
+
if (!getCurrentInstance()) throw new Error("useSpringSystem must be called inside setup()");
|
|
34
|
+
const existing = injectLocal(SpringSystemKey);
|
|
35
|
+
if (existing) return existing;
|
|
10
36
|
const system = createSpringSystem(options);
|
|
11
|
-
|
|
12
|
-
onMounted(() =>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
onBeforeUnmount(() => {
|
|
16
|
-
system.stop();
|
|
17
|
-
});
|
|
37
|
+
provideLocal(SpringSystemKey, system);
|
|
38
|
+
onMounted(() => system.start());
|
|
39
|
+
onBeforeUnmount(() => system.stop());
|
|
40
|
+
return system;
|
|
18
41
|
}
|
|
19
42
|
//#endregion
|
|
20
|
-
//#region src/vue/spring.ts
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
function useSpring(target, options) {
|
|
27
|
-
if (Array.isArray(target)) return Array.from(target, (t) => createSpringRef(t, options));
|
|
28
|
-
if (hasSpringInstance(target)) return createLinkedSpringRef(target, options);
|
|
29
|
-
return createSpringRef(target, options);
|
|
43
|
+
//#region src/vue/reactive-spring.ts
|
|
44
|
+
const divergentRef = customRef;
|
|
45
|
+
function injectSpringSystem() {
|
|
46
|
+
const system = injectLocal(SpringSystemKey);
|
|
47
|
+
if (!system) throw new Error("No SpringSystem found — install the coily/nuxt module or call useSpringSystem() in an ancestor component");
|
|
48
|
+
return system;
|
|
30
49
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
if (!system) throw new Error("No SpringSystem found");
|
|
34
|
-
const config = computed(() => {
|
|
50
|
+
function resolveSpringConfig(options) {
|
|
51
|
+
return computed(() => {
|
|
35
52
|
const opts = toValue(options);
|
|
36
53
|
if (opts instanceof SpringConfig) return opts;
|
|
37
54
|
return opts ? new SpringConfig(opts) : void 0;
|
|
38
55
|
});
|
|
39
|
-
|
|
56
|
+
}
|
|
57
|
+
function createReactiveSpringRef(spring, config, instanceKey) {
|
|
40
58
|
watchSyncEffect(() => {
|
|
41
|
-
|
|
42
|
-
if (c) spring.config = c;
|
|
43
|
-
else spring.config = null;
|
|
59
|
+
spring.config = config.value ?? null;
|
|
44
60
|
});
|
|
45
61
|
let triggerValue;
|
|
46
62
|
let triggerVelocity;
|
|
@@ -50,25 +66,25 @@ function createSpringRef(target, options) {
|
|
|
50
66
|
triggerVelocity?.();
|
|
51
67
|
triggerTimeRemaining?.();
|
|
52
68
|
});
|
|
53
|
-
const value =
|
|
69
|
+
const value = divergentRef((track, trigger) => ({
|
|
54
70
|
get() {
|
|
55
71
|
triggerValue ??= trigger;
|
|
56
72
|
track();
|
|
57
73
|
return spring.value;
|
|
58
74
|
},
|
|
59
|
-
set(
|
|
60
|
-
spring.value =
|
|
75
|
+
set(next) {
|
|
76
|
+
spring.value = next;
|
|
61
77
|
trigger();
|
|
62
78
|
}
|
|
63
79
|
}));
|
|
64
|
-
const velocity =
|
|
80
|
+
const velocity = divergentRef((track, trigger) => ({
|
|
65
81
|
get() {
|
|
66
82
|
triggerVelocity ??= trigger;
|
|
67
83
|
track();
|
|
68
84
|
return spring.velocity;
|
|
69
85
|
},
|
|
70
|
-
set(
|
|
71
|
-
spring.velocity =
|
|
86
|
+
set(next) {
|
|
87
|
+
spring.velocity = next;
|
|
72
88
|
trigger();
|
|
73
89
|
}
|
|
74
90
|
}));
|
|
@@ -91,256 +107,94 @@ function createSpringRef(target, options) {
|
|
|
91
107
|
set() {}
|
|
92
108
|
};
|
|
93
109
|
});
|
|
94
|
-
watchSyncEffect(() => {
|
|
95
|
-
spring.target = toValue(target);
|
|
96
|
-
});
|
|
97
110
|
if (getCurrentScope()) onScopeDispose(() => spring.dispose());
|
|
98
111
|
const ref = Object.assign(value, {
|
|
99
112
|
velocity,
|
|
100
113
|
timeRemaining,
|
|
101
114
|
isResting,
|
|
102
|
-
jumpTo: (
|
|
115
|
+
jumpTo: (next) => spring.jumpTo(next)
|
|
103
116
|
});
|
|
104
|
-
Object.defineProperty(ref,
|
|
117
|
+
Object.defineProperty(ref, "settled", { get: () => spring.settled });
|
|
118
|
+
Object.defineProperty(ref, instanceKey, { value: spring });
|
|
105
119
|
return ref;
|
|
106
120
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/vue/spring-object.ts
|
|
123
|
+
/** @internal */
|
|
124
|
+
const SpringObjectInstanceKey = Symbol("spring-object");
|
|
125
|
+
function hasSpringObjectInstance(value) {
|
|
126
|
+
return typeof value === "object" && value !== null && SpringObjectInstanceKey in value;
|
|
127
|
+
}
|
|
128
|
+
function resolveConfigShape(options) {
|
|
129
|
+
return computed(() => toValue(options));
|
|
130
|
+
}
|
|
131
|
+
function createSpringObjectRef(value, options) {
|
|
132
|
+
const system = injectSpringSystem();
|
|
133
|
+
const config = resolveConfigShape(options);
|
|
134
|
+
const spring = system.createSpringObject(toValue(value), config.value);
|
|
135
|
+
const ref = createReactiveSpringRef(spring, config, SpringObjectInstanceKey);
|
|
118
136
|
watchSyncEffect(() => {
|
|
119
|
-
|
|
120
|
-
if (c) spring.config = c;
|
|
121
|
-
else spring.config = null;
|
|
137
|
+
spring.target = toValue(value);
|
|
122
138
|
});
|
|
123
|
-
let triggerValue;
|
|
124
|
-
let triggerVelocity;
|
|
125
|
-
let triggerTimeRemaining;
|
|
126
|
-
spring.onUpdate(() => {
|
|
127
|
-
triggerValue?.();
|
|
128
|
-
triggerVelocity?.();
|
|
129
|
-
triggerTimeRemaining?.();
|
|
130
|
-
});
|
|
131
|
-
const value = customRef((track, trigger) => ({
|
|
132
|
-
get() {
|
|
133
|
-
triggerValue ??= trigger;
|
|
134
|
-
track();
|
|
135
|
-
return spring.value;
|
|
136
|
-
},
|
|
137
|
-
set(value) {
|
|
138
|
-
spring.value = value;
|
|
139
|
-
trigger();
|
|
140
|
-
}
|
|
141
|
-
}));
|
|
142
|
-
const velocity = customRef((track, trigger) => ({
|
|
143
|
-
get() {
|
|
144
|
-
triggerVelocity ??= trigger;
|
|
145
|
-
track();
|
|
146
|
-
return spring.velocity;
|
|
147
|
-
},
|
|
148
|
-
set(value) {
|
|
149
|
-
spring.velocity = value;
|
|
150
|
-
trigger();
|
|
151
|
-
}
|
|
152
|
-
}));
|
|
153
|
-
const timeRemaining = customRef((track, trigger) => ({
|
|
154
|
-
get() {
|
|
155
|
-
triggerTimeRemaining ??= trigger;
|
|
156
|
-
track();
|
|
157
|
-
return spring.timeRemaining;
|
|
158
|
-
},
|
|
159
|
-
set() {}
|
|
160
|
-
}));
|
|
161
|
-
const isResting = customRef((track, trigger) => {
|
|
162
|
-
spring.onStart(trigger);
|
|
163
|
-
spring.onStop(trigger);
|
|
164
|
-
return {
|
|
165
|
-
get() {
|
|
166
|
-
track();
|
|
167
|
-
return spring.isResting;
|
|
168
|
-
},
|
|
169
|
-
set() {}
|
|
170
|
-
};
|
|
171
|
-
});
|
|
172
|
-
if (getCurrentScope()) onScopeDispose(() => spring.dispose());
|
|
173
|
-
const ref = Object.assign(value, {
|
|
174
|
-
velocity,
|
|
175
|
-
timeRemaining,
|
|
176
|
-
isResting,
|
|
177
|
-
jumpTo: (value) => spring.jumpTo(value)
|
|
178
|
-
});
|
|
179
|
-
Object.defineProperty(ref, SpringInstanceKey, { value: spring });
|
|
180
139
|
return ref;
|
|
181
140
|
}
|
|
141
|
+
function createLinkedSpringObjectRef(leaderRef, options) {
|
|
142
|
+
const system = injectSpringSystem();
|
|
143
|
+
const leader = leaderRef[SpringObjectInstanceKey];
|
|
144
|
+
const config = resolveConfigShape(options);
|
|
145
|
+
const spring = system.createSpringObject(leader.value, config.value);
|
|
146
|
+
spring.target = leader;
|
|
147
|
+
return createReactiveSpringRef(spring, config, SpringObjectInstanceKey);
|
|
148
|
+
}
|
|
182
149
|
//#endregion
|
|
183
|
-
//#region src/vue/
|
|
184
|
-
/** @internal
|
|
185
|
-
const
|
|
186
|
-
function
|
|
187
|
-
return typeof value === "object" && value !== null &&
|
|
150
|
+
//#region src/vue/spring.ts
|
|
151
|
+
/** @internal */
|
|
152
|
+
const SpringInstanceKey = Symbol("spring");
|
|
153
|
+
function hasSpringInstance(value) {
|
|
154
|
+
return typeof value === "object" && value !== null && SpringInstanceKey in value;
|
|
188
155
|
}
|
|
189
|
-
function
|
|
190
|
-
if (
|
|
191
|
-
if (
|
|
192
|
-
return
|
|
156
|
+
function useSpring(target, options) {
|
|
157
|
+
if (hasSpringInstance(target)) return createLinkedSpringRef(target, options);
|
|
158
|
+
if (hasSpringObjectInstance(target)) return createLinkedSpringObjectRef(target, options);
|
|
159
|
+
if (typeof toValue(target) === "number") return createSpringRef(target, options);
|
|
160
|
+
return createSpringObjectRef(target, options);
|
|
193
161
|
}
|
|
194
|
-
function
|
|
195
|
-
const system =
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
if (opts instanceof SpringConfig) return opts;
|
|
200
|
-
return opts ? new SpringConfig(opts) : void 0;
|
|
201
|
-
});
|
|
202
|
-
const spring = system.createSpring2D(toValue(target), config.value ?? void 0);
|
|
203
|
-
watchSyncEffect(() => {
|
|
204
|
-
const c = config.value;
|
|
205
|
-
if (c) spring.config = c;
|
|
206
|
-
else spring.config = null;
|
|
207
|
-
});
|
|
208
|
-
let triggerValue;
|
|
209
|
-
let triggerVelocity;
|
|
210
|
-
let triggerTimeRemaining;
|
|
211
|
-
spring.onUpdate(() => {
|
|
212
|
-
triggerValue?.();
|
|
213
|
-
triggerVelocity?.();
|
|
214
|
-
triggerTimeRemaining?.();
|
|
215
|
-
});
|
|
216
|
-
const value = customRef((track, trigger) => ({
|
|
217
|
-
get() {
|
|
218
|
-
triggerValue ??= trigger;
|
|
219
|
-
track();
|
|
220
|
-
return spring.value;
|
|
221
|
-
},
|
|
222
|
-
set(value) {
|
|
223
|
-
spring.value = value;
|
|
224
|
-
trigger();
|
|
225
|
-
}
|
|
226
|
-
}));
|
|
227
|
-
const velocity = customRef((track, trigger) => ({
|
|
228
|
-
get() {
|
|
229
|
-
triggerVelocity ??= trigger;
|
|
230
|
-
track();
|
|
231
|
-
return spring.velocity;
|
|
232
|
-
},
|
|
233
|
-
set(value) {
|
|
234
|
-
spring.velocity = value;
|
|
235
|
-
trigger();
|
|
236
|
-
}
|
|
237
|
-
}));
|
|
238
|
-
const timeRemaining = customRef((track, trigger) => ({
|
|
239
|
-
get() {
|
|
240
|
-
triggerTimeRemaining ??= trigger;
|
|
241
|
-
track();
|
|
242
|
-
return spring.timeRemaining;
|
|
243
|
-
},
|
|
244
|
-
set() {}
|
|
245
|
-
}));
|
|
246
|
-
const isResting = customRef((track, trigger) => {
|
|
247
|
-
spring.onStart(trigger);
|
|
248
|
-
spring.onStop(trigger);
|
|
249
|
-
return {
|
|
250
|
-
get() {
|
|
251
|
-
track();
|
|
252
|
-
return spring.isResting;
|
|
253
|
-
},
|
|
254
|
-
set() {}
|
|
255
|
-
};
|
|
256
|
-
});
|
|
162
|
+
function createSpringRef(target, options) {
|
|
163
|
+
const system = injectSpringSystem();
|
|
164
|
+
const config = resolveSpringConfig(options);
|
|
165
|
+
const spring = system.createSpring(toValue(target), config.value);
|
|
166
|
+
const ref = createReactiveSpringRef(spring, config, SpringInstanceKey);
|
|
257
167
|
watchSyncEffect(() => {
|
|
258
168
|
spring.target = toValue(target);
|
|
259
169
|
});
|
|
260
|
-
if (getCurrentScope()) onScopeDispose(() => spring.dispose());
|
|
261
|
-
const ref = Object.assign(value, {
|
|
262
|
-
velocity,
|
|
263
|
-
timeRemaining,
|
|
264
|
-
isResting,
|
|
265
|
-
jumpTo: (value) => spring.jumpTo(value)
|
|
266
|
-
});
|
|
267
|
-
Object.defineProperty(ref, Spring2DInstanceKey, { value: spring });
|
|
268
170
|
return ref;
|
|
269
171
|
}
|
|
270
|
-
function
|
|
271
|
-
const system =
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const value = customRef((track, trigger) => ({
|
|
295
|
-
get() {
|
|
296
|
-
triggerValue ??= trigger;
|
|
297
|
-
track();
|
|
298
|
-
return spring.value;
|
|
299
|
-
},
|
|
300
|
-
set(value) {
|
|
301
|
-
spring.value = value;
|
|
302
|
-
trigger();
|
|
303
|
-
}
|
|
304
|
-
}));
|
|
305
|
-
const velocity = customRef((track, trigger) => ({
|
|
306
|
-
get() {
|
|
307
|
-
triggerVelocity ??= trigger;
|
|
308
|
-
track();
|
|
309
|
-
return spring.velocity;
|
|
310
|
-
},
|
|
311
|
-
set(value) {
|
|
312
|
-
spring.velocity = value;
|
|
313
|
-
trigger();
|
|
172
|
+
function createLinkedSpringRef(leaderRef, options) {
|
|
173
|
+
const system = injectSpringSystem();
|
|
174
|
+
const config = resolveSpringConfig(options);
|
|
175
|
+
return createReactiveSpringRef(system.createSpring({ target: leaderRef[SpringInstanceKey] }, config.value), config, SpringInstanceKey);
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/vue/pool.ts
|
|
179
|
+
function useSpringPool() {
|
|
180
|
+
const system = injectSpringSystem();
|
|
181
|
+
const live = /* @__PURE__ */ new Set();
|
|
182
|
+
const adopt = (spring) => {
|
|
183
|
+
live.add(spring);
|
|
184
|
+
spring.onDispose(() => {
|
|
185
|
+
live.delete(spring);
|
|
186
|
+
});
|
|
187
|
+
return spring;
|
|
188
|
+
};
|
|
189
|
+
onScopeDispose(() => {
|
|
190
|
+
for (const spring of live) spring.dispose();
|
|
191
|
+
}, true);
|
|
192
|
+
return {
|
|
193
|
+
createSpring: (position, config) => adopt(system.createSpring(position, config)),
|
|
194
|
+
createSpringObject(value, config) {
|
|
195
|
+
return adopt(system.createSpringObject(value, config));
|
|
314
196
|
}
|
|
315
|
-
}
|
|
316
|
-
const timeRemaining = customRef((track, trigger) => ({
|
|
317
|
-
get() {
|
|
318
|
-
triggerTimeRemaining ??= trigger;
|
|
319
|
-
track();
|
|
320
|
-
return spring.timeRemaining;
|
|
321
|
-
},
|
|
322
|
-
set() {}
|
|
323
|
-
}));
|
|
324
|
-
const isResting = customRef((track, trigger) => {
|
|
325
|
-
spring.onStart(trigger);
|
|
326
|
-
spring.onStop(trigger);
|
|
327
|
-
return {
|
|
328
|
-
get() {
|
|
329
|
-
track();
|
|
330
|
-
return spring.isResting;
|
|
331
|
-
},
|
|
332
|
-
set() {}
|
|
333
|
-
};
|
|
334
|
-
});
|
|
335
|
-
if (getCurrentScope()) onScopeDispose(() => spring.dispose());
|
|
336
|
-
const ref = Object.assign(value, {
|
|
337
|
-
velocity,
|
|
338
|
-
timeRemaining,
|
|
339
|
-
isResting,
|
|
340
|
-
jumpTo: (value) => spring.jumpTo(value)
|
|
341
|
-
});
|
|
342
|
-
Object.defineProperty(ref, Spring2DInstanceKey, { value: spring });
|
|
343
|
-
return ref;
|
|
197
|
+
};
|
|
344
198
|
}
|
|
345
199
|
//#endregion
|
|
346
200
|
//#region src/vue/component.ts
|
|
@@ -366,4 +220,4 @@ const SpringValue = defineComponent((props, { slots, expose }) => {
|
|
|
366
220
|
props: ["target", "config"]
|
|
367
221
|
});
|
|
368
222
|
//#endregion
|
|
369
|
-
export { SpringValue, provideSpringSystem, useSpring,
|
|
223
|
+
export { SpringValue, provideSpringSystem, useSpring, useSpringPool, useSpringSystem };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coily",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "Simulate values using spring physics",
|
|
5
5
|
"homepage": "https://github.com/tkofh/coily#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -27,22 +27,24 @@
|
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@nuxt/kit": "^4.4.
|
|
31
|
-
"@nuxt/schema": "^4.4.
|
|
32
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
33
|
-
"@vitest/browser-playwright": "^4.1.
|
|
34
|
-
"@vitest/coverage-v8": "^4.1.
|
|
35
|
-
"@vue/test-utils": "^2.4.
|
|
36
|
-
"fast-check": "^4.
|
|
37
|
-
"happy-dom": "^20.
|
|
38
|
-
"
|
|
39
|
-
"
|
|
30
|
+
"@nuxt/kit": "^4.4.8",
|
|
31
|
+
"@nuxt/schema": "^4.4.8",
|
|
32
|
+
"@vitejs/plugin-vue": "^6.0.7",
|
|
33
|
+
"@vitest/browser-playwright": "^4.1.10",
|
|
34
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
35
|
+
"@vue/test-utils": "^2.4.11",
|
|
36
|
+
"fast-check": "^4.9.0",
|
|
37
|
+
"happy-dom": "^20.10.6",
|
|
38
|
+
"playwright": "1.61.1",
|
|
39
|
+
"tsdown": "^0.22.4",
|
|
40
|
+
"typescript": "^6.0.0",
|
|
41
|
+
"vitest": "^4.1.10",
|
|
40
42
|
"vitest-browser-vue": "^2.1.0",
|
|
41
|
-
"vue": "^3.5.
|
|
43
|
+
"vue": "^3.5.39"
|
|
42
44
|
},
|
|
43
45
|
"peerDependencies": {
|
|
44
46
|
"@nuxt/kit": "^4.0.0",
|
|
45
|
-
"vue": "^3.
|
|
47
|
+
"vue": "^3.5.0"
|
|
46
48
|
},
|
|
47
49
|
"peerDependenciesMeta": {
|
|
48
50
|
"vue": {
|
|
@@ -52,11 +54,9 @@
|
|
|
52
54
|
"optional": true
|
|
53
55
|
}
|
|
54
56
|
},
|
|
55
|
-
"engines": {
|
|
56
|
-
"node": ">=24.10.0"
|
|
57
|
-
},
|
|
58
57
|
"scripts": {
|
|
59
58
|
"build": "tsdown",
|
|
59
|
+
"check": "tsc -p .",
|
|
60
60
|
"test": "vitest run",
|
|
61
61
|
"test:coverage": "vitest run --coverage",
|
|
62
62
|
"bench": "vitest bench --run",
|