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/dist/vue.d.ts CHANGED
@@ -1,57 +1,268 @@
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";
1
+ import { n as SpringDefinitionOptions, t as SpringDefinition } from "./config-OOMMRdK8.js";
2
+ import { c as ConfigShape, d as ReadonlyShape, f as Shape, i as SpringSystemOptions, l as PartialShape, m as Spring, n as SpringOptions, o as CompositeSpring, p as Purpose, r as SpringSystem, t as CompositeSpringOptions, y as SpringSource } from "./system-Du_fXXmO.js";
2
3
  import { App, MaybeRefOrGetter, Ref, SlotsType } from "vue";
3
4
  //#region src/vue/reactive-spring.d.ts
4
- type UseSpringOptions = MaybeRefOrGetter<SpringOptions | SpringConfig | undefined>;
5
- interface ReactiveSpringRef<V, W = V> extends Ref<V, W> {
5
+ /**
6
+ * Config for a scalar `useSpring`: a `SpringDefinition`, any option shape
7
+ * `defineSpring` accepts, or a ref/getter of either. Reactive config
8
+ * reconfigures the spring in place when it changes; `undefined` means the
9
+ * default config.
10
+ */
11
+ type UseSpringConfig = MaybeRefOrGetter<SpringDefinitionOptions | SpringDefinition | undefined>;
12
+ /**
13
+ * The reactive surface `useSpring` returns: a writable ref of the
14
+ * animated value with the rest of the spring attached. Reads track
15
+ * reactively and update once per tick while the spring moves.
16
+ *
17
+ * Writing the main ref displaces the spring — it springs back toward its
18
+ * target. To move the spring, drive the target you passed to
19
+ * `useSpring`.
20
+ *
21
+ * The ref is also a `SpringSource`: it goes anywhere a source does —
22
+ * another `useSpring`, a `mapSpring` leaf, a composite channel target.
23
+ * Followers read the backing spring through `SpringSourceSymbol`, never
24
+ * through the ref's tracked getter, so following registers no Vue
25
+ * dependencies — an effect that touches a follower's leader stays
26
+ * independent of the leader's animation.
27
+ */
28
+ interface ReactiveSpringRef<V, W = V> extends Ref<V, W>, SpringSource<V> {
29
+ /**
30
+ * The current velocity in value units per second, as a writable ref.
31
+ * Writing flings the spring; it settles back to its target.
32
+ */
6
33
  readonly velocity: Ref<V, W>;
34
+ /**
35
+ * Estimated milliseconds until the spring rests, as a reactive ref: 0
36
+ * while resting. Writes are ignored.
37
+ */
7
38
  readonly timeRemaining: Ref<number>;
39
+ /** Whether the spring is resting, as a reactive ref. Writes are ignored. */
8
40
  readonly isResting: Ref<boolean>;
41
+ /**
42
+ * A promise that resolves when the spring next comes to rest — already
43
+ * resolved while resting. Retargeting mid-flight extends the wait;
44
+ * disposal resolves it.
45
+ */
9
46
  readonly settled: Promise<void>;
47
+ /** Snaps the spring to `value` with no animation, target included. */
10
48
  readonly jumpTo: (value: W) => void;
11
49
  }
12
50
  //#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>> {}
51
+ //#region src/vue/composite-spring.d.ts
52
+ /**
53
+ * Config for an object `useSpring`: a `ConfigShape` — one `SpringDefinition`
54
+ * for every channel, `null`, or a shape with configs at any level — or a
55
+ * ref/getter of one. Reactive config reconfigures channels in place.
56
+ *
57
+ * Unlike scalar config, positions here take `SpringDefinition` instances
58
+ * only (build them with `defineSpring`): a plain object is always read as
59
+ * a per-channel shape.
60
+ */
61
+ type UseCompositeSpringConfig<T extends object> = MaybeRefOrGetter<ConfigShape<T> | undefined>;
62
+ /**
63
+ * The reactive handle for a composite spring: a ref reading the
64
+ * deep-readonly composite value and accepting partial shapes on writes,
65
+ * with `velocity`, `timeRemaining`, and `isResting` refs plus `settled`
66
+ * and `jumpTo` attached. Writing the main ref displaces the named
67
+ * channels; drive the `useSpring` target to move them.
68
+ */
69
+ interface CompositeSpringRef<T extends object> extends ReactiveSpringRef<ReadonlyShape<T>, PartialShape<T>> {}
16
70
  //#endregion
17
71
  //#region src/vue/spring.d.ts
72
+ /**
73
+ * The reactive handle for a scalar spring: a writable ref of the
74
+ * animated number, with `velocity`, `timeRemaining`, and `isResting`
75
+ * refs plus `settled` and `jumpTo` attached. Writing the main ref
76
+ * displaces the spring; drive the `useSpring` target to move it.
77
+ */
18
78
  interface SpringRef extends ReactiveSpringRef<number> {}
19
- declare function useSpring(target: MaybeRefOrGetter<number>, options?: UseSpringOptions): SpringRef;
20
- declare function useSpring(target: SpringRef, options?: UseSpringOptions): SpringRef;
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>;
79
+ /**
80
+ * Creates a scalar spring and returns it as a `SpringRef`. The target
81
+ * is a number to animate toward, or a `SpringSource` to follow — another
82
+ * `useSpring` ref, a `mapSpring` result, a pooled `Spring` — or a
83
+ * ref/getter of either. Reactive numbers retarget the spring whenever
84
+ * they change, momentum intact; a getter of a source re-follows when its
85
+ * own dependencies change, so `useSpring(() => (split.value ? left :
86
+ * right))` switches leaders live. Reactive `config` reconfigures the
87
+ * spring in place; while following, it configures the follower's own
88
+ * motion — the leader's config plays no part.
89
+ *
90
+ * Following bypasses Vue reactivity — the spring subscribes to the
91
+ * source directly — so effects and getters never gain a dependency on a
92
+ * leader's animation.
93
+ *
94
+ * Call it during `setup()` below a provided spring system (the
95
+ * coily/nuxt module, or `useSpringSystem()` in an ancestor). The spring
96
+ * is disposed with the component's scope, and composables are loop-safe:
97
+ * map over targets for several independent springs.
98
+ *
99
+ * `options.purpose` marks what the spring animates — `'appearance'`
100
+ * (a cross-fade, a color) keeps animating under reduced motion, `'motion'`
101
+ * (the default) snaps. It is read once, so unlike `config` it is not
102
+ * reactive.
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * const target = ref(0)
107
+ * const x = useSpring(target, { duration: 500, bounce: 0.3 })
108
+ * // template: <div :style="{ translate: `${x}px 0` }" @click="target = 300" />
109
+ *
110
+ * const opacity = useSpring(shown ? 1 : 0, undefined, { purpose: 'appearance' })
111
+ * ```
112
+ */
113
+ declare function useSpring(target: MaybeRefOrGetter<number | SpringSource>, config?: UseSpringConfig, options?: SpringOptions): SpringRef;
114
+ /**
115
+ * Creates a composite spring that follows another `useSpring` object ref
116
+ * channel by channel, animating toward the leader's live values.
117
+ *
118
+ * Call it during `setup()` below a provided spring system. The springs
119
+ * are disposed with the component's scope.
120
+ */
121
+ declare function useSpring<T extends object>(target: CompositeSpringRef<T>, config?: UseCompositeSpringConfig<T>, options?: CompositeSpringOptions<T>): CompositeSpringRef<T>;
122
+ /**
123
+ * Creates a composite spring over a numeric shape — a plain object or
124
+ * array whose leaves are all numbers, or a ref/getter of one — and
125
+ * returns a `CompositeSpringRef`: reads are the deep-readonly composite
126
+ * value, writes take partial shapes. The shape is fixed at creation.
127
+ * Reactive targets retarget the channels, momentum intact — a ref on
128
+ * replacement or nested mutation, a getter whenever its reactive
129
+ * dependencies change. Reactive `config` accepts a per-channel config
130
+ * shape.
131
+ *
132
+ * Call it during `setup()` below a provided spring system. The springs
133
+ * are disposed with the component's scope.
134
+ *
135
+ * `options.purpose` marks reduced-motion behavior per channel: a single
136
+ * `Purpose` for all, or a shape mirroring the value. It is read once, so
137
+ * unlike `config` it is not reactive.
138
+ */
139
+ declare function useSpring<T extends object>(target: MaybeRefOrGetter<T & Shape<T>>, config?: UseCompositeSpringConfig<T>, options?: CompositeSpringOptions<T>): CompositeSpringRef<T>;
140
+ /**
141
+ * Creates a composite spring driven by a getter of a numeric shape: the
142
+ * springs retarget whenever the getter's reactive dependencies change.
143
+ * The shape itself is fixed at creation.
144
+ *
145
+ * (This is the getter case of the shape overload above, split out
146
+ * because the shape doesn't infer through `MaybeRefOrGetter`'s
147
+ * function member.)
148
+ *
149
+ * Call it during `setup()` below a provided spring system. The springs
150
+ * are disposed with the component's scope.
151
+ */
152
+ declare function useSpring<T extends object>(target: () => T & Shape<T>, config?: UseCompositeSpringConfig<T>, options?: CompositeSpringOptions<T>): CompositeSpringRef<T>;
25
153
  //#endregion
26
154
  //#region src/vue/pool.d.ts
155
+ /**
156
+ * Imperative spring factories bound to the provided system, for dynamic
157
+ * sets of springs — particles, per-item effects — created and disposed
158
+ * at arbitrary times. Any pooled spring still alive when the creating
159
+ * scope tears down is disposed automatically; disposing one manually
160
+ * before that is fine.
161
+ */
27
162
  interface SpringPool {
28
- createSpring(position: SpringPosition, config?: SpringConfig): Spring;
29
- createSpringObject<T extends object>(value: T & Shape<T>, config?: ConfigShape<T>): SpringObject<T>;
163
+ /**
164
+ * Creates a pooled spring at rest at `value`. Without `config`, the
165
+ * default applies. `options.purpose` sets reduced-motion behavior —
166
+ * `'appearance'` keeps animating, `'motion'` (default) snaps.
167
+ */
168
+ createSpring(value: number, config?: SpringDefinition, options?: SpringOptions): Spring;
169
+ /**
170
+ * Creates a pooled spring already following `source`, starting at its
171
+ * current value. `options.purpose` sets reduced-motion behavior.
172
+ */
173
+ createSpring(source: SpringSource, config?: SpringDefinition, options?: SpringOptions): Spring;
174
+ /**
175
+ * Creates a pooled composite spring over a numeric shape whose leaves
176
+ * are all numbers. `config` applies per channel: one `SpringDefinition`
177
+ * for all, or a shape with configs at any level. `options.purpose` sets
178
+ * reduced-motion behavior per channel the same way.
179
+ */
180
+ createSpring<T extends object>(value: T & Shape<T>, config?: ConfigShape<T>, options?: CompositeSpringOptions<T>): CompositeSpring<T>;
30
181
  }
182
+ /**
183
+ * Returns spring factories bound to the provided spring system, with
184
+ * lifetimes tied to the current effect scope: every pooled spring still
185
+ * alive at scope teardown is disposed, so leaked motions are
186
+ * structurally impossible.
187
+ *
188
+ * Call it during `setup()` — or inside an effect scope — below a
189
+ * provided spring system. Outside a scope, pooled springs are only
190
+ * disposed manually.
191
+ */
31
192
  declare function useSpringPool(): SpringPool;
32
193
  //#endregion
33
194
  //#region src/vue/component.d.ts
34
195
  interface SpringValueProps {
196
+ /** The value to animate toward. Changing it retargets the spring, momentum intact. */
35
197
  target: number;
36
- config?: SpringOptions | SpringConfig;
198
+ /**
199
+ * Spring config: a `SpringDefinition` or any option shape `defineSpring`
200
+ * accepts. Changing it reconfigures the spring in place; omit it for
201
+ * the default.
202
+ */
203
+ config?: SpringDefinitionOptions | SpringDefinition;
204
+ /**
205
+ * What the spring animates — `'motion'` (default) or `'appearance'`.
206
+ * `'appearance'` (a cross-fade, a color) keeps animating under reduced
207
+ * motion. Read once at mount; later changes are ignored.
208
+ * @default 'motion'
209
+ */
210
+ purpose?: Purpose;
37
211
  }
212
+ /** `SpringValue` emits no events. */
38
213
  type SpringValueEmits = Record<string, never>;
214
+ /** What `SpringValue` passes to its default slot. */
39
215
  interface SpringValueSlotScope {
216
+ /** The current animated value. */
40
217
  value: number;
218
+ /** The current velocity, in value units per second. */
41
219
  velocity: number;
220
+ /** Whether the spring is resting. */
42
221
  isResting: boolean;
222
+ /** Estimated milliseconds until the spring rests. */
43
223
  timeRemaining: number;
224
+ /** Snaps the spring to `value` with no animation, target included. */
44
225
  jumpTo: (value: number) => void;
45
226
  }
227
+ /** Slot types: `default` receives the live `SpringValueSlotScope`. */
46
228
  type SpringValueSlots = SlotsType<{
47
229
  default: SpringValueSlotScope;
48
230
  }>;
231
+ /**
232
+ * Renderless component exposing one springed number through its default
233
+ * slot — the template-only sibling of `useSpring`. Must sit below a
234
+ * provided spring system.
235
+ *
236
+ * @example
237
+ * ```vue
238
+ * <SpringValue :target="expanded ? 1 : 0" purpose="appearance" v-slot="{ value }">
239
+ * <div :style="{ opacity: value }" />
240
+ * </SpringValue>
241
+ * ```
242
+ */
49
243
  declare const SpringValue: import("vue").DefineSetupFnComponent<SpringValueProps, SpringValueEmits, SpringValueSlots, SpringValueProps & {
50
244
  [x: `on${Capitalize<string>}`]: ((...args: unknown[]) => any) | undefined;
51
245
  }, import("vue").PublicProps>;
52
246
  //#endregion
53
247
  //#region src/vue/system.d.ts
248
+ /**
249
+ * Supplies a spring system you created and manage yourself — coily never
250
+ * starts or stops it. With `app`, the system is installed app-wide
251
+ * (what the Nuxt module does); without, it is provided to the current
252
+ * component and its descendants, including this component's own
253
+ * `useSpring` calls. Mostly useful in tests.
254
+ */
54
255
  declare function provideSpringSystem(system: SpringSystem, app?: App): void;
256
+ /**
257
+ * Returns the spring system provided by this component or an ancestor,
258
+ * creating one when none exists. A created system is provided to this
259
+ * component and its descendants and started/stopped with the component's
260
+ * mount lifecycle.
261
+ *
262
+ * Idempotent: call it near the root and again in any descendant.
263
+ * `options` only applies when the call actually creates a system.
264
+ * Throws outside `setup()`.
265
+ */
55
266
  declare function useSpringSystem(options?: SpringSystemOptions): SpringSystem;
56
267
  //#endregion
57
- export { type SpringObjectRef, type SpringPool, type SpringRef, SpringValue, type SpringValueProps, type SpringValueSlots, type UseSpringObjectOptions, provideSpringSystem, useSpring, useSpringPool, useSpringSystem };
268
+ export { type CompositeSpringRef, type SpringPool, type SpringRef, SpringValue, type SpringValueProps, type SpringValueSlots, provideSpringSystem, useSpring, useSpringPool, useSpringSystem };
package/dist/vue.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as SpringConfig, t as createSpringSystem } from "./system-Csho09XW.js";
1
+ import { n as SpringSourceSymbol, o as SpringDefinition, r as isSpringSource, t as createSpringSystem } from "./system-Br_cPnaN.js";
2
2
  import { computed, customRef, defineComponent, getCurrentInstance, getCurrentScope, inject, onBeforeUnmount, onMounted, onScopeDispose, provide, toRefs, toValue, watchSyncEffect } from "vue";
3
3
  //#region src/vue/local.ts
4
4
  const localProvides = /* @__PURE__ */ new WeakMap();
@@ -25,10 +25,27 @@ function injectLocal(key) {
25
25
  //#endregion
26
26
  //#region src/vue/system.ts
27
27
  const SpringSystemKey = Symbol.for("coily/spring-system");
28
+ /**
29
+ * Supplies a spring system you created and manage yourself — coily never
30
+ * starts or stops it. With `app`, the system is installed app-wide
31
+ * (what the Nuxt module does); without, it is provided to the current
32
+ * component and its descendants, including this component's own
33
+ * `useSpring` calls. Mostly useful in tests.
34
+ */
28
35
  function provideSpringSystem(system, app) {
29
36
  if (app) app.provide(SpringSystemKey, system);
30
37
  else provideLocal(SpringSystemKey, system);
31
38
  }
39
+ /**
40
+ * Returns the spring system provided by this component or an ancestor,
41
+ * creating one when none exists. A created system is provided to this
42
+ * component and its descendants and started/stopped with the component's
43
+ * mount lifecycle.
44
+ *
45
+ * Idempotent: call it near the root and again in any descendant.
46
+ * `options` only applies when the call actually creates a system.
47
+ * Throws outside `setup()`.
48
+ */
32
49
  function useSpringSystem(options) {
33
50
  if (!getCurrentInstance()) throw new Error("useSpringSystem must be called inside setup()");
34
51
  const existing = injectLocal(SpringSystemKey);
@@ -47,11 +64,11 @@ function injectSpringSystem() {
47
64
  if (!system) throw new Error("No SpringSystem found — install the coily/nuxt module or call useSpringSystem() in an ancestor component");
48
65
  return system;
49
66
  }
50
- function resolveSpringConfig(options) {
67
+ function resolveSpringConfig(config) {
51
68
  return computed(() => {
52
- const opts = toValue(options);
53
- if (opts instanceof SpringConfig) return opts;
54
- return opts ? new SpringConfig(opts) : void 0;
69
+ const resolved = toValue(config);
70
+ if (resolved instanceof SpringDefinition) return resolved;
71
+ return resolved ? new SpringDefinition(resolved) : void 0;
55
72
  });
56
73
  }
57
74
  function createReactiveSpringRef(spring, config, instanceKey) {
@@ -116,66 +133,78 @@ function createReactiveSpringRef(spring, config, instanceKey) {
116
133
  });
117
134
  Object.defineProperty(ref, "settled", { get: () => spring.settled });
118
135
  Object.defineProperty(ref, instanceKey, { value: spring });
136
+ Object.defineProperty(ref, SpringSourceSymbol, { value: spring[SpringSourceSymbol] });
119
137
  return ref;
120
138
  }
121
139
  //#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;
140
+ //#region src/vue/composite-spring.ts
141
+ const CompositeSpringInstanceKey = Symbol("composite-spring");
142
+ function hasCompositeSpringInstance(value) {
143
+ return typeof value === "object" && value !== null && CompositeSpringInstanceKey in value;
127
144
  }
128
- function resolveConfigShape(options) {
129
- return computed(() => toValue(options));
145
+ function resolveConfigShape(config) {
146
+ return computed(() => toValue(config));
130
147
  }
131
- function createSpringObjectRef(value, options) {
148
+ function createCompositeSpringRef(value, config, options) {
132
149
  const system = injectSpringSystem();
133
- const config = resolveConfigShape(options);
134
- const spring = system.createSpringObject(toValue(value), config.value);
135
- const ref = createReactiveSpringRef(spring, config, SpringObjectInstanceKey);
150
+ const resolvedConfig = resolveConfigShape(config);
151
+ const spring = system.createSpring(toValue(value), resolvedConfig.value, options);
152
+ const ref = createReactiveSpringRef(spring, resolvedConfig, CompositeSpringInstanceKey);
136
153
  watchSyncEffect(() => {
137
154
  spring.target = toValue(value);
138
155
  });
139
156
  return ref;
140
157
  }
141
- function createLinkedSpringObjectRef(leaderRef, options) {
158
+ function createLinkedCompositeSpringRef(leaderRef, config, options) {
142
159
  const system = injectSpringSystem();
143
- const leader = leaderRef[SpringObjectInstanceKey];
144
- const config = resolveConfigShape(options);
145
- const spring = system.createSpringObject(leader.value, config.value);
160
+ const leader = leaderRef[CompositeSpringInstanceKey];
161
+ const resolvedConfig = resolveConfigShape(config);
162
+ const spring = system.createSpring(leader.value, resolvedConfig.value, options);
146
163
  spring.target = leader;
147
- return createReactiveSpringRef(spring, config, SpringObjectInstanceKey);
164
+ return createReactiveSpringRef(spring, resolvedConfig, CompositeSpringInstanceKey);
148
165
  }
149
166
  //#endregion
150
167
  //#region src/vue/spring.ts
151
- /** @internal */
152
168
  const SpringInstanceKey = Symbol("spring");
153
169
  function hasSpringInstance(value) {
154
170
  return typeof value === "object" && value !== null && SpringInstanceKey in value;
155
171
  }
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);
172
+ function useSpring(target, config, options) {
173
+ if (hasSpringInstance(target)) return createLinkedSpringRef(target, config, options);
174
+ if (hasCompositeSpringInstance(target)) return createLinkedCompositeSpringRef(target, config, options);
175
+ const resolved = toValue(target);
176
+ if (typeof resolved === "number" || isSpringSource(resolved)) return createSpringRef(target, config, options);
177
+ return createCompositeSpringRef(target, config, options);
161
178
  }
162
- function createSpringRef(target, options) {
179
+ function createSpringRef(target, config, options) {
163
180
  const system = injectSpringSystem();
164
- const config = resolveSpringConfig(options);
165
- const spring = system.createSpring(toValue(target), config.value);
166
- const ref = createReactiveSpringRef(spring, config, SpringInstanceKey);
181
+ const resolvedConfig = resolveSpringConfig(config);
182
+ const initial = toValue(target);
183
+ const spring = system.createSpring(typeof initial === "number" ? initial : initial[SpringSourceSymbol].value, resolvedConfig.value, options);
184
+ const ref = createReactiveSpringRef(spring, resolvedConfig, SpringInstanceKey);
167
185
  watchSyncEffect(() => {
168
186
  spring.target = toValue(target);
169
187
  });
170
188
  return ref;
171
189
  }
172
- function createLinkedSpringRef(leaderRef, options) {
190
+ function createLinkedSpringRef(leaderRef, config, options) {
173
191
  const system = injectSpringSystem();
174
- const config = resolveSpringConfig(options);
175
- return createReactiveSpringRef(system.createSpring({ target: leaderRef[SpringInstanceKey] }, config.value), config, SpringInstanceKey);
192
+ const leader = leaderRef[SpringInstanceKey];
193
+ const resolvedConfig = resolveSpringConfig(config);
194
+ return createReactiveSpringRef(system.createSpring(leader, resolvedConfig.value, options), resolvedConfig, SpringInstanceKey);
176
195
  }
177
196
  //#endregion
178
197
  //#region src/vue/pool.ts
198
+ /**
199
+ * Returns spring factories bound to the provided spring system, with
200
+ * lifetimes tied to the current effect scope: every pooled spring still
201
+ * alive at scope teardown is disposed, so leaked motions are
202
+ * structurally impossible.
203
+ *
204
+ * Call it during `setup()` — or inside an effect scope — below a
205
+ * provided spring system. Outside a scope, pooled springs are only
206
+ * disposed manually.
207
+ */
179
208
  function useSpringPool() {
180
209
  const system = injectSpringSystem();
181
210
  const live = /* @__PURE__ */ new Set();
@@ -189,18 +218,27 @@ function useSpringPool() {
189
218
  onScopeDispose(() => {
190
219
  for (const spring of live) spring.dispose();
191
220
  }, true);
192
- return {
193
- createSpring: (position, config) => adopt(system.createSpring(position, config)),
194
- createSpringObject(value, config) {
195
- return adopt(system.createSpringObject(value, config));
196
- }
197
- };
221
+ const create = system.createSpring.bind(system);
222
+ const createSpring = ((value, config, options) => adopt(create(value, config, options)));
223
+ return { createSpring };
198
224
  }
199
225
  //#endregion
200
226
  //#region src/vue/component.ts
227
+ /**
228
+ * Renderless component exposing one springed number through its default
229
+ * slot — the template-only sibling of `useSpring`. Must sit below a
230
+ * provided spring system.
231
+ *
232
+ * @example
233
+ * ```vue
234
+ * <SpringValue :target="expanded ? 1 : 0" purpose="appearance" v-slot="{ value }">
235
+ * <div :style="{ opacity: value }" />
236
+ * </SpringValue>
237
+ * ```
238
+ */
201
239
  const SpringValue = defineComponent((props, { slots, expose }) => {
202
240
  const { target, config } = toRefs(props);
203
- const spring = useSpring(target, config);
241
+ const spring = useSpring(target, config, { purpose: props.purpose });
204
242
  expose({
205
243
  value: spring,
206
244
  velocity: spring.velocity,
@@ -217,7 +255,11 @@ const SpringValue = defineComponent((props, { slots, expose }) => {
217
255
  }) ?? null;
218
256
  }, {
219
257
  name: "SpringValue",
220
- props: ["target", "config"]
258
+ props: [
259
+ "target",
260
+ "config",
261
+ "purpose"
262
+ ]
221
263
  });
222
264
  //#endregion
223
265
  export { SpringValue, provideSpringSystem, useSpring, useSpringPool, useSpringSystem };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coily",
3
- "version": "0.13.1",
3
+ "version": "0.15.0",
4
4
  "description": "Simulate values using spring physics",
5
5
  "homepage": "https://github.com/tkofh/coily#readme",
6
6
  "bugs": {
@@ -19,6 +19,7 @@
19
19
  "sideEffects": false,
20
20
  "exports": {
21
21
  ".": "./dist/index.js",
22
+ "./css": "./dist/css.js",
22
23
  "./nuxt": "./dist/nuxt.js",
23
24
  "./vue": "./dist/vue.js",
24
25
  "./package.json": "./package.json"