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