coily 0.11.0 → 0.12.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.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/nuxt.d.ts +4 -1
- package/dist/nuxt.js +36 -11
- package/dist/{system-Dxxv4ee7.js → system-DPaqec-Z.js} +418 -39
- package/dist/{system-B_kZMcpg.d.ts → system-Do5rE0j7.d.ts} +111 -31
- package/dist/vue.d.ts +27 -16
- package/dist/vue.js +295 -49
- package/package.json +1 -1
package/dist/vue.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { n as SpringConfig, t as createSpringSystem } from "./system-
|
|
2
|
-
import { computed, customRef, defineComponent, inject, onBeforeUnmount, onMounted, provide, toRefs, toValue, watchSyncEffect } from "vue";
|
|
1
|
+
import { n as SpringConfig, t as createSpringSystem } from "./system-DPaqec-Z.js";
|
|
2
|
+
import { computed, customRef, defineComponent, getCurrentScope, inject, onBeforeUnmount, onMounted, onScopeDispose, provide, toRefs, toValue, watchSyncEffect } from "vue";
|
|
3
3
|
//#region src/vue/system.ts
|
|
4
4
|
const SpringSystemKey = Symbol.for("coily/spring-system");
|
|
5
5
|
function provideSpringSystem(system, app) {
|
|
6
6
|
if (app) app.provide(SpringSystemKey, system);
|
|
7
7
|
else provide(SpringSystemKey, system);
|
|
8
8
|
}
|
|
9
|
-
function useSpringSystem() {
|
|
10
|
-
const system = createSpringSystem();
|
|
9
|
+
function useSpringSystem(options) {
|
|
10
|
+
const system = createSpringSystem(options);
|
|
11
11
|
provideSpringSystem(system);
|
|
12
12
|
onMounted(() => {
|
|
13
13
|
system.start();
|
|
@@ -23,7 +23,17 @@ const defaultOptions = {
|
|
|
23
23
|
damping: 10,
|
|
24
24
|
precision: 2
|
|
25
25
|
};
|
|
26
|
+
/** @internal Symbol to access the underlying Spring from a SpringRef */
|
|
27
|
+
const SpringInstanceKey = Symbol("spring");
|
|
28
|
+
function hasSpringInstance(value) {
|
|
29
|
+
return typeof value === "object" && value !== null && SpringInstanceKey in value;
|
|
30
|
+
}
|
|
26
31
|
function useSpring(target, options) {
|
|
32
|
+
if (Array.isArray(target)) return Array.from(target, (t) => createSpringRef(t, options));
|
|
33
|
+
if (hasSpringInstance(target)) return createLinkedSpringRef(target, options);
|
|
34
|
+
return createSpringRef(target, options);
|
|
35
|
+
}
|
|
36
|
+
function createSpringRef(target, options) {
|
|
27
37
|
const system = inject(SpringSystemKey);
|
|
28
38
|
if (!system) throw new Error("No SpringSystem found");
|
|
29
39
|
const config = computed(() => {
|
|
@@ -37,43 +47,207 @@ function useSpring(target, options) {
|
|
|
37
47
|
});
|
|
38
48
|
let triggerValue;
|
|
39
49
|
let triggerVelocity;
|
|
50
|
+
let triggerTimeRemaining;
|
|
40
51
|
spring.onUpdate(() => {
|
|
41
52
|
triggerValue?.();
|
|
42
53
|
triggerVelocity?.();
|
|
54
|
+
triggerTimeRemaining?.();
|
|
43
55
|
});
|
|
44
|
-
const value = customRef((track, trigger) => {
|
|
45
|
-
|
|
56
|
+
const value = customRef((track, trigger) => ({
|
|
57
|
+
get() {
|
|
58
|
+
triggerValue ??= trigger;
|
|
59
|
+
track();
|
|
60
|
+
return spring.value;
|
|
61
|
+
},
|
|
62
|
+
set(value) {
|
|
63
|
+
spring.value = value;
|
|
64
|
+
trigger();
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
const velocity = customRef((track, trigger) => ({
|
|
68
|
+
get() {
|
|
69
|
+
triggerVelocity ??= trigger;
|
|
70
|
+
track();
|
|
71
|
+
return spring.velocity;
|
|
72
|
+
},
|
|
73
|
+
set(value) {
|
|
74
|
+
spring.velocity = value;
|
|
75
|
+
trigger();
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
78
|
+
const timeRemaining = customRef((track, trigger) => ({
|
|
79
|
+
get() {
|
|
80
|
+
triggerTimeRemaining ??= trigger;
|
|
81
|
+
track();
|
|
82
|
+
return spring.timeRemaining;
|
|
83
|
+
},
|
|
84
|
+
set() {}
|
|
85
|
+
}));
|
|
86
|
+
const isResting = customRef((track, trigger) => {
|
|
87
|
+
spring.onStart(trigger);
|
|
88
|
+
spring.onStop(trigger);
|
|
46
89
|
return {
|
|
47
90
|
get() {
|
|
48
91
|
track();
|
|
49
|
-
return spring.
|
|
92
|
+
return spring.isResting;
|
|
50
93
|
},
|
|
51
|
-
set(
|
|
52
|
-
spring.value = value;
|
|
53
|
-
trigger();
|
|
54
|
-
}
|
|
94
|
+
set() {}
|
|
55
95
|
};
|
|
56
96
|
});
|
|
57
|
-
|
|
58
|
-
|
|
97
|
+
watchSyncEffect(() => {
|
|
98
|
+
spring.target = toValue(target);
|
|
99
|
+
});
|
|
100
|
+
if (getCurrentScope()) onScopeDispose(() => spring.dispose());
|
|
101
|
+
const ref = Object.assign(value, {
|
|
102
|
+
velocity,
|
|
103
|
+
timeRemaining,
|
|
104
|
+
isResting,
|
|
105
|
+
jumpTo: (value) => spring.jumpTo(value)
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(ref, SpringInstanceKey, { value: spring });
|
|
108
|
+
return ref;
|
|
109
|
+
}
|
|
110
|
+
function createLinkedSpringRef(leaderRef, options) {
|
|
111
|
+
const system = inject(SpringSystemKey);
|
|
112
|
+
if (!system) throw new Error("No SpringSystem found");
|
|
113
|
+
const leaderSpring = leaderRef[SpringInstanceKey];
|
|
114
|
+
const config = computed(() => {
|
|
115
|
+
const opts = toValue(options);
|
|
116
|
+
if (!opts) return void 0;
|
|
117
|
+
if (opts instanceof SpringConfig) return opts;
|
|
118
|
+
return new SpringConfig(opts);
|
|
119
|
+
});
|
|
120
|
+
const spring = system.createSpring({ target: leaderSpring }, config.value);
|
|
121
|
+
watchSyncEffect(() => {
|
|
122
|
+
const c = config.value;
|
|
123
|
+
if (c) spring.configure(c);
|
|
124
|
+
else spring.clearConfigOverride();
|
|
125
|
+
});
|
|
126
|
+
let triggerValue;
|
|
127
|
+
let triggerVelocity;
|
|
128
|
+
let triggerTimeRemaining;
|
|
129
|
+
spring.onUpdate(() => {
|
|
130
|
+
triggerValue?.();
|
|
131
|
+
triggerVelocity?.();
|
|
132
|
+
triggerTimeRemaining?.();
|
|
133
|
+
});
|
|
134
|
+
const value = customRef((track, trigger) => ({
|
|
135
|
+
get() {
|
|
136
|
+
triggerValue ??= trigger;
|
|
137
|
+
track();
|
|
138
|
+
return spring.value;
|
|
139
|
+
},
|
|
140
|
+
set(value) {
|
|
141
|
+
spring.value = value;
|
|
142
|
+
trigger();
|
|
143
|
+
}
|
|
144
|
+
}));
|
|
145
|
+
const velocity = customRef((track, trigger) => ({
|
|
146
|
+
get() {
|
|
147
|
+
triggerVelocity ??= trigger;
|
|
148
|
+
track();
|
|
149
|
+
return spring.velocity;
|
|
150
|
+
},
|
|
151
|
+
set(value) {
|
|
152
|
+
spring.velocity = value;
|
|
153
|
+
trigger();
|
|
154
|
+
}
|
|
155
|
+
}));
|
|
156
|
+
const timeRemaining = customRef((track, trigger) => ({
|
|
157
|
+
get() {
|
|
158
|
+
triggerTimeRemaining ??= trigger;
|
|
159
|
+
track();
|
|
160
|
+
return spring.timeRemaining;
|
|
161
|
+
},
|
|
162
|
+
set() {}
|
|
163
|
+
}));
|
|
164
|
+
const isResting = customRef((track, trigger) => {
|
|
165
|
+
spring.onStart(trigger);
|
|
166
|
+
spring.onStop(trigger);
|
|
59
167
|
return {
|
|
60
168
|
get() {
|
|
61
169
|
track();
|
|
62
|
-
return spring.
|
|
170
|
+
return spring.isResting;
|
|
63
171
|
},
|
|
64
|
-
set(
|
|
65
|
-
spring.velocity = value;
|
|
66
|
-
trigger();
|
|
67
|
-
}
|
|
172
|
+
set() {}
|
|
68
173
|
};
|
|
69
174
|
});
|
|
70
|
-
|
|
175
|
+
if (getCurrentScope()) onScopeDispose(() => spring.dispose());
|
|
176
|
+
const ref = Object.assign(value, {
|
|
177
|
+
velocity,
|
|
178
|
+
timeRemaining,
|
|
179
|
+
isResting,
|
|
180
|
+
jumpTo: (value) => spring.jumpTo(value)
|
|
181
|
+
});
|
|
182
|
+
Object.defineProperty(ref, SpringInstanceKey, { value: spring });
|
|
183
|
+
return ref;
|
|
184
|
+
}
|
|
185
|
+
/** @internal Symbol to access the underlying Spring2D from a SpringRef2D */
|
|
186
|
+
const Spring2DInstanceKey = Symbol("spring2d");
|
|
187
|
+
function hasSpring2DInstance(value) {
|
|
188
|
+
return typeof value === "object" && value !== null && Spring2DInstanceKey in value;
|
|
189
|
+
}
|
|
190
|
+
function useSpring2D(target, options) {
|
|
191
|
+
if (hasSpring2DInstance(target)) return createLinkedSpringRef2D(target, options);
|
|
192
|
+
return createSpringRef2D(target, options);
|
|
193
|
+
}
|
|
194
|
+
function createSpringRef2D(target, options) {
|
|
195
|
+
const system = inject(SpringSystemKey);
|
|
196
|
+
if (!system) throw new Error("No SpringSystem found");
|
|
197
|
+
const config = computed(() => {
|
|
198
|
+
const opts = toValue(options);
|
|
199
|
+
if (opts instanceof SpringConfig) return opts;
|
|
200
|
+
return new SpringConfig(opts ?? defaultOptions);
|
|
201
|
+
});
|
|
202
|
+
const spring = system.createSpring2D(toValue(target), config.value);
|
|
203
|
+
watchSyncEffect(() => {
|
|
204
|
+
spring.configure(config.value);
|
|
205
|
+
});
|
|
206
|
+
let triggerValue;
|
|
207
|
+
let triggerVelocity;
|
|
208
|
+
let triggerTimeRemaining;
|
|
209
|
+
spring.onUpdate(() => {
|
|
210
|
+
triggerValue?.();
|
|
211
|
+
triggerVelocity?.();
|
|
212
|
+
triggerTimeRemaining?.();
|
|
213
|
+
});
|
|
214
|
+
const value = customRef((track, trigger) => ({
|
|
215
|
+
get() {
|
|
216
|
+
triggerValue ??= trigger;
|
|
217
|
+
track();
|
|
218
|
+
return spring.value;
|
|
219
|
+
},
|
|
220
|
+
set(value) {
|
|
221
|
+
spring.value = value;
|
|
222
|
+
trigger();
|
|
223
|
+
}
|
|
224
|
+
}));
|
|
225
|
+
const velocity = customRef((track, trigger) => ({
|
|
226
|
+
get() {
|
|
227
|
+
triggerVelocity ??= trigger;
|
|
228
|
+
track();
|
|
229
|
+
return spring.velocity;
|
|
230
|
+
},
|
|
231
|
+
set(value) {
|
|
232
|
+
spring.velocity = value;
|
|
233
|
+
trigger();
|
|
234
|
+
}
|
|
235
|
+
}));
|
|
236
|
+
const timeRemaining = customRef((track, trigger) => ({
|
|
237
|
+
get() {
|
|
238
|
+
triggerTimeRemaining ??= trigger;
|
|
239
|
+
track();
|
|
240
|
+
return spring.timeRemaining;
|
|
241
|
+
},
|
|
242
|
+
set() {}
|
|
243
|
+
}));
|
|
244
|
+
const isResting = customRef((track, trigger) => {
|
|
71
245
|
spring.onStart(trigger);
|
|
72
246
|
spring.onStop(trigger);
|
|
73
247
|
return {
|
|
74
248
|
get() {
|
|
75
249
|
track();
|
|
76
|
-
return spring.
|
|
250
|
+
return spring.isResting;
|
|
77
251
|
},
|
|
78
252
|
set() {}
|
|
79
253
|
};
|
|
@@ -81,41 +255,113 @@ function useSpring(target, options) {
|
|
|
81
255
|
watchSyncEffect(() => {
|
|
82
256
|
spring.target = toValue(target);
|
|
83
257
|
});
|
|
84
|
-
|
|
85
|
-
|
|
258
|
+
if (getCurrentScope()) onScopeDispose(() => spring.dispose());
|
|
259
|
+
const ref = Object.assign(value, {
|
|
86
260
|
velocity,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
261
|
+
timeRemaining,
|
|
262
|
+
isResting,
|
|
263
|
+
jumpTo: (value) => spring.jumpTo(value)
|
|
264
|
+
});
|
|
265
|
+
Object.defineProperty(ref, Spring2DInstanceKey, { value: spring });
|
|
266
|
+
return ref;
|
|
267
|
+
}
|
|
268
|
+
function createLinkedSpringRef2D(leaderRef, options) {
|
|
269
|
+
const system = inject(SpringSystemKey);
|
|
270
|
+
if (!system) throw new Error("No SpringSystem found");
|
|
271
|
+
const leaderSpring = leaderRef[Spring2DInstanceKey];
|
|
272
|
+
const config = computed(() => {
|
|
273
|
+
const opts = toValue(options);
|
|
274
|
+
if (!opts) return void 0;
|
|
275
|
+
if (opts instanceof SpringConfig) return opts;
|
|
276
|
+
return new SpringConfig(opts);
|
|
277
|
+
});
|
|
278
|
+
const spring = system.createSpring2D({ target: leaderSpring }, config.value);
|
|
279
|
+
watchSyncEffect(() => {
|
|
280
|
+
const c = config.value;
|
|
281
|
+
if (c) spring.configure(c);
|
|
282
|
+
else spring.clearConfigOverride();
|
|
283
|
+
});
|
|
284
|
+
let triggerValue;
|
|
285
|
+
let triggerVelocity;
|
|
286
|
+
let triggerTimeRemaining;
|
|
287
|
+
spring.onUpdate(() => {
|
|
288
|
+
triggerValue?.();
|
|
289
|
+
triggerVelocity?.();
|
|
290
|
+
triggerTimeRemaining?.();
|
|
291
|
+
});
|
|
292
|
+
const value = customRef((track, trigger) => ({
|
|
293
|
+
get() {
|
|
294
|
+
triggerValue ??= trigger;
|
|
295
|
+
track();
|
|
296
|
+
return spring.value;
|
|
297
|
+
},
|
|
298
|
+
set(value) {
|
|
299
|
+
spring.value = value;
|
|
300
|
+
trigger();
|
|
301
|
+
}
|
|
302
|
+
}));
|
|
303
|
+
const velocity = customRef((track, trigger) => ({
|
|
304
|
+
get() {
|
|
305
|
+
triggerVelocity ??= trigger;
|
|
306
|
+
track();
|
|
307
|
+
return spring.velocity;
|
|
308
|
+
},
|
|
309
|
+
set(value) {
|
|
310
|
+
spring.velocity = value;
|
|
311
|
+
trigger();
|
|
90
312
|
}
|
|
91
|
-
};
|
|
313
|
+
}));
|
|
314
|
+
const timeRemaining = customRef((track, trigger) => ({
|
|
315
|
+
get() {
|
|
316
|
+
triggerTimeRemaining ??= trigger;
|
|
317
|
+
track();
|
|
318
|
+
return spring.timeRemaining;
|
|
319
|
+
},
|
|
320
|
+
set() {}
|
|
321
|
+
}));
|
|
322
|
+
const isResting = customRef((track, trigger) => {
|
|
323
|
+
spring.onStart(trigger);
|
|
324
|
+
spring.onStop(trigger);
|
|
325
|
+
return {
|
|
326
|
+
get() {
|
|
327
|
+
track();
|
|
328
|
+
return spring.isResting;
|
|
329
|
+
},
|
|
330
|
+
set() {}
|
|
331
|
+
};
|
|
332
|
+
});
|
|
333
|
+
if (getCurrentScope()) onScopeDispose(() => spring.dispose());
|
|
334
|
+
const ref = Object.assign(value, {
|
|
335
|
+
velocity,
|
|
336
|
+
timeRemaining,
|
|
337
|
+
isResting,
|
|
338
|
+
jumpTo: (value) => spring.jumpTo(value)
|
|
339
|
+
});
|
|
340
|
+
Object.defineProperty(ref, Spring2DInstanceKey, { value: spring });
|
|
341
|
+
return ref;
|
|
92
342
|
}
|
|
93
343
|
//#endregion
|
|
94
344
|
//#region src/vue/component.ts
|
|
95
|
-
const SpringValue = defineComponent((props, { slots }) => {
|
|
96
|
-
const { target,
|
|
97
|
-
const spring = useSpring(target,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
345
|
+
const SpringValue = defineComponent((props, { slots, expose }) => {
|
|
346
|
+
const { target, config } = toRefs(props);
|
|
347
|
+
const spring = useSpring(target, config);
|
|
348
|
+
expose({
|
|
349
|
+
value: spring,
|
|
350
|
+
velocity: spring.velocity,
|
|
351
|
+
isResting: spring.isResting,
|
|
352
|
+
timeRemaining: spring.timeRemaining,
|
|
353
|
+
jumpTo: spring.jumpTo
|
|
354
|
+
});
|
|
355
|
+
return () => slots.default?.({
|
|
356
|
+
value: spring.value,
|
|
357
|
+
velocity: spring.velocity.value,
|
|
358
|
+
isResting: spring.isResting.value,
|
|
359
|
+
timeRemaining: spring.timeRemaining.value,
|
|
360
|
+
jumpTo: spring.jumpTo
|
|
361
|
+
}) ?? null;
|
|
110
362
|
}, {
|
|
111
363
|
name: "SpringValue",
|
|
112
|
-
props: [
|
|
113
|
-
"target",
|
|
114
|
-
"mass",
|
|
115
|
-
"tension",
|
|
116
|
-
"damping",
|
|
117
|
-
"precision"
|
|
118
|
-
]
|
|
364
|
+
props: ["target", "config"]
|
|
119
365
|
});
|
|
120
366
|
//#endregion
|
|
121
|
-
export { SpringValue, provideSpringSystem, useSpring, useSpringSystem };
|
|
367
|
+
export { SpringValue, provideSpringSystem, useSpring, useSpring2D, useSpringSystem };
|