@vizejs/composable 0.345.0 → 0.347.7

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.
Files changed (42) hide show
  1. package/dist/abort-signal.d.mts +96 -0
  2. package/dist/abort-signal.mjs +203 -0
  3. package/dist/async-resource.d.mts +97 -0
  4. package/dist/async-resource.mjs +99 -0
  5. package/dist/capability-BNpkvSy5.d.mts +93 -0
  6. package/dist/capability.d.mts +2 -0
  7. package/dist/capability.mjs +37 -0
  8. package/dist/catalog-CuWhR-0q.d.mts +506 -0
  9. package/dist/catalog-DOXTbk4r.mjs +529 -0
  10. package/dist/catalog.d.mts +2 -0
  11. package/dist/catalog.mjs +2 -0
  12. package/dist/disposal-scope.d.mts +93 -0
  13. package/dist/disposal-scope.mjs +119 -0
  14. package/dist/event-listener.d.mts +85 -0
  15. package/dist/event-listener.mjs +55 -0
  16. package/dist/index.d.mts +19 -786
  17. package/dist/index.mjs +19 -751
  18. package/dist/locale.d.mts +65 -0
  19. package/dist/locale.mjs +72 -0
  20. package/dist/media-query.d.mts +56 -0
  21. package/dist/media-query.mjs +56 -0
  22. package/dist/retry-async.d.mts +91 -0
  23. package/dist/retry-async.mjs +136 -0
  24. package/dist/retry-delay.d.mts +73 -0
  25. package/dist/retry-delay.mjs +50 -0
  26. package/dist/scope.d.mts +18 -0
  27. package/dist/scope.mjs +23 -0
  28. package/dist/timeout-scheduler.d.mts +18 -0
  29. package/dist/timeout-scheduler.mjs +1 -0
  30. package/dist/use-counter.d.mts +91 -0
  31. package/dist/use-counter.mjs +67 -0
  32. package/dist/use-debounced.d.mts +87 -0
  33. package/dist/use-debounced.mjs +98 -0
  34. package/dist/use-history.d.mts +105 -0
  35. package/dist/use-history.mjs +137 -0
  36. package/dist/use-previous.d.mts +43 -0
  37. package/dist/use-previous.mjs +11 -0
  38. package/dist/use-throttled.d.mts +107 -0
  39. package/dist/use-throttled.mjs +124 -0
  40. package/dist/use-toggle.d.mts +45 -0
  41. package/dist/use-toggle.mjs +34 -0
  42. package/package.json +91 -1
package/dist/index.d.mts CHANGED
@@ -1,786 +1,19 @@
1
- import { ComputedRef, MaybeRefOrGetter, Ref, ShallowRef } from "vue";
2
-
3
- //#region src/async-resource.d.ts
4
- /** Lifecycle state of an asynchronous resource. */
5
- type AsyncResourceStatus = "idle" | "pending" | "success" | "error" | "cancelled";
6
- /** Context supplied to an asynchronous resource loader. */
7
- interface AsyncResourceContext {
8
- /** Signal aborted by cancellation, reset, scope disposal, or a newer execution. */
9
- readonly signal: AbortSignal;
10
- }
11
- /** Explicit result of one asynchronous resource execution. */
12
- type AsyncResourceExecution<Data, Failure> = {
13
- readonly status: "success";
14
- readonly data: Data;
15
- } | {
16
- readonly status: "error";
17
- readonly error: Failure;
18
- } | {
19
- readonly status: "cancelled";
20
- readonly reason: unknown;
21
- } | {
22
- readonly status: "superseded";
23
- };
24
- /** Options for {@link useAsyncResource}. */
25
- interface UseAsyncResourceOptions<Data> {
26
- /**
27
- * Initial data restored by {@link AsyncResource.reset}.
28
- *
29
- * @default undefined
30
- */
31
- readonly initialData?: Data;
32
- /**
33
- * Abort the active execution when a newer execution starts.
34
- *
35
- * @default true
36
- */
37
- readonly cancelPrevious?: boolean;
38
- /**
39
- * Retain the current data while a new execution is pending.
40
- *
41
- * @default true
42
- */
43
- readonly keepData?: boolean;
44
- /**
45
- * Cancel an active execution when the current reactive scope is disposed.
46
- *
47
- * @default true
48
- */
49
- readonly scope?: boolean;
50
- }
51
- /** Reactive state and controls for an asynchronous loader. */
52
- interface AsyncResource<Data, Arguments extends readonly unknown[], Failure> {
53
- /** Data of the newest successful execution, retained according to `keepData`. */
54
- readonly data: Readonly<ShallowRef<Data | undefined>>;
55
- /** Failure of the newest settled execution, cleared when a new one starts. */
56
- readonly error: Readonly<ShallowRef<Failure | undefined>>;
57
- /** Current lifecycle status, driven only by the newest execution. */
58
- readonly status: Readonly<Ref<AsyncResourceStatus>>;
59
- /** Whether an execution is currently pending. */
60
- readonly pending: ComputedRef<boolean>;
61
- /**
62
- * Run the loader. The returned promise never rejects: loader failures,
63
- * cancellation, and supersession are reported as the discriminated result,
64
- * and stale executions leave the reactive state untouched.
65
- */
66
- readonly execute: (...arguments_: Arguments) => Promise<AsyncResourceExecution<Data, Failure>>;
67
- /**
68
- * Abort the active execution and mark the resource cancelled.
69
- *
70
- * @param reason Abort reason forwarded to the loader's signal.
71
- * @default reason DOMException("AbortError")
72
- * @returns Whether an active execution was cancelled.
73
- */
74
- readonly cancel: (reason?: unknown) => boolean;
75
- /** Cancel any active execution and restore the initial idle state. */
76
- readonly reset: () => void;
77
- }
78
- /**
79
- * Create a scoped, abortable asynchronous resource with latest-result-wins
80
- * state. Every execution returns a discriminated result, so cancellation,
81
- * supersession, loader failure, and successful `undefined` data stay distinct.
82
- *
83
- * When created inside an active reactive scope (and `scope` is enabled), the
84
- * active execution is aborted when that scope stops; outside a scope,
85
- * cancellation ownership stays with the caller. The execute promise never
86
- * rejects — synchronous and asynchronous loader failures both settle into
87
- * the `"error"` result. Safe during server rendering: no browser globals are
88
- * read and abort reasons use the runtime-native `DOMException`.
89
- *
90
- * @param loader Asynchronous loader receiving the abort context first.
91
- * @param options Data retention, supersession, and scope behavior.
92
- * @default options {}
93
- * @returns Reactive state and controls for the loader.
94
- */
95
- declare function useAsyncResource<Data, Arguments extends readonly unknown[], Failure = unknown>(loader: (context: AsyncResourceContext, ...arguments_: Arguments) => Promise<Data>, options?: UseAsyncResourceOptions<Data>): AsyncResource<Data, Arguments, Failure>;
96
- //#endregion
97
- //#region src/event-listener.d.ts
98
- /** Options for {@link useEventListener}. */
99
- interface UseEventListenerOptions {
100
- /**
101
- * Invoke the listener during the capture phase.
102
- *
103
- * @default false
104
- */
105
- readonly capture?: boolean;
106
- /**
107
- * Stop listening after the first event.
108
- *
109
- * @default false
110
- */
111
- readonly once?: boolean;
112
- /**
113
- * Declare that the listener does not cancel the event's default action.
114
- *
115
- * @default false
116
- */
117
- readonly passive?: boolean;
118
- /**
119
- * Stop listening when this signal is aborted. An already-aborted signal
120
- * prevents listening from ever starting.
121
- *
122
- * @default undefined
123
- */
124
- readonly signal?: AbortSignal;
125
- /**
126
- * Start listening during composable creation.
127
- *
128
- * @default true
129
- */
130
- readonly immediate?: boolean;
131
- /**
132
- * Reactive target update timing.
133
- *
134
- * @default "pre"
135
- */
136
- readonly flush?: "pre" | "post" | "sync";
137
- }
138
- /** Reactive controls returned by {@link useEventListener}. */
139
- interface EventListenerControls {
140
- /** Whether a concrete target currently owns the listener. */
141
- readonly isListening: Readonly<Ref<boolean>>;
142
- /**
143
- * Begin listening.
144
- *
145
- * @returns Whether a new reactive watcher was started. `false` while the
146
- * watcher is already active (including a null-target watcher with no
147
- * listener attached), after the abort signal has fired, and after the
148
- * owning reactive scope has been disposed.
149
- */
150
- readonly start: () => boolean;
151
- /** Stop listening. Repeated calls are safe. */
152
- readonly stop: () => void;
153
- }
154
- /**
155
- * Attach an event listener to a reactive target and clean it up with the
156
- * current reactive scope. Missing targets are valid during server rendering:
157
- * a `null`/`undefined` target keeps the listener detached until a concrete
158
- * target appears, so no browser globals are required.
159
- *
160
- * The listener is re-attached whenever the reactive target changes and is
161
- * removed when the owning reactive scope stops, when
162
- * {@link EventListenerControls.stop} is called, or when the abort signal
163
- * fires. Outside an active scope, teardown ownership stays with the caller,
164
- * who must call `stop` explicitly. Errors thrown by a custom target's
165
- * add/remove methods propagate to the active watcher run.
166
- *
167
- * @param target Reactive event target.
168
- * @param event Event name.
169
- * @param listener Typed event listener.
170
- * @param options Listener lifecycle and scheduling options.
171
- * @default options {}
172
- * @returns Controls to observe and change the listening state.
173
- */
174
- declare function useEventListener<Key extends keyof WindowEventMap>(target: MaybeRefOrGetter<Window | null | undefined>, event: Key, listener: (event: WindowEventMap[Key]) => void, options?: UseEventListenerOptions): EventListenerControls;
175
- declare function useEventListener<Key extends keyof DocumentEventMap>(target: MaybeRefOrGetter<Document | null | undefined>, event: Key, listener: (event: DocumentEventMap[Key]) => void, options?: UseEventListenerOptions): EventListenerControls;
176
- declare function useEventListener<Key extends keyof HTMLElementEventMap>(target: MaybeRefOrGetter<HTMLElement | null | undefined>, event: Key, listener: (event: HTMLElementEventMap[Key]) => void, options?: UseEventListenerOptions): EventListenerControls;
177
- declare function useEventListener(target: MaybeRefOrGetter<EventTarget | null | undefined>, event: string, listener: EventListener, options?: UseEventListenerOptions): EventListenerControls;
178
- //#endregion
179
- //#region src/locale.d.ts
180
- /** Text flow reported by the internationalization runtime. */
181
- type TextDirection = "ltr" | "rtl";
182
- /** Locale selection options for {@link useLocale}. */
183
- interface UseLocaleOptions {
184
- /**
185
- * Locale detector used when the reactive source has no value.
186
- *
187
- * @default navigator.language when available; otherwise undefined
188
- */
189
- readonly detect?: () => Intl.Locale | string | null | undefined;
190
- /**
191
- * Locale used when neither the source nor detector provides one.
192
- *
193
- * @default "en"
194
- */
195
- readonly fallback?: Intl.Locale | string;
196
- }
197
- /**
198
- * Reactive locale metadata and cached formatter factories.
199
- *
200
- * Formatter factories propagate `TypeError` and `RangeError` from the
201
- * platform `Intl` constructors when the supplied options are invalid.
202
- */
203
- interface LocaleControls {
204
- /** Canonical Unicode locale identifier. */
205
- readonly locale: ComputedRef<string>;
206
- /** Parsed locale details supplied by the internationalization runtime. */
207
- readonly details: ComputedRef<Intl.Locale>;
208
- /** Native writing direction for the active locale. */
209
- readonly direction: ComputedRef<TextDirection>;
210
- /** Return a cached number formatter for the active locale and options. */
211
- readonly number: (options?: Intl.NumberFormatOptions) => Intl.NumberFormat;
212
- /** Return a cached date and time formatter for the active locale and options. */
213
- readonly dateTime: (options?: Intl.DateTimeFormatOptions) => Intl.DateTimeFormat;
214
- /** Return a cached list formatter for the active locale and options. */
215
- readonly list: (options?: Intl.ListFormatOptions) => Intl.ListFormat;
216
- /** Return a cached relative-time formatter for the active locale and options. */
217
- readonly relativeTime: (options?: Intl.RelativeTimeFormatOptions) => Intl.RelativeTimeFormat;
218
- }
219
- /**
220
- * Create reactive locale metadata and platform-native formatter factories.
221
- *
222
- * Equivalent formatter options reuse instances. The bounded cache follows the
223
- * active locale automatically and prevents repeated constructor overhead in
224
- * reactive render paths.
225
- *
226
- * Detection is lazy and guarded: the default detector reads
227
- * `navigator.language` behind a `typeof` check at call time, so importing and
228
- * calling this during server rendering is safe, and runtimes without a
229
- * `navigator` resolve to the fallback locale. The composable owns no timers
230
- * or listeners, so no scope cleanup is required.
231
- *
232
- * @param source Reactive locale source. Empty values defer to the detector.
233
- * @param options Detection and fallback behavior.
234
- * @default options {}
235
- * @throws `RangeError` on first read of the reactive values when the winning
236
- * candidate is not a structurally valid locale identifier.
237
- * @returns Reactive locale metadata and cached formatter factories.
238
- */
239
- declare function useLocale(source?: MaybeRefOrGetter<Intl.Locale | string | null | undefined>, options?: UseLocaleOptions): LocaleControls;
240
- //#endregion
241
- //#region src/media-query.d.ts
242
- /** Capability required to evaluate media queries. */
243
- interface MediaQueryHost {
244
- /** Create an observable result for a media query. */
245
- readonly matchMedia: (query: string) => MediaQueryList;
246
- }
247
- /** Options for {@link useMediaQuery}. */
248
- interface UseMediaQueryOptions {
249
- /**
250
- * Value exposed when no media-query capability is available.
251
- *
252
- * @default false
253
- */
254
- readonly ssrValue?: boolean;
255
- /**
256
- * Reactive media-query capability for alternate runtimes and tests.
257
- *
258
- * @default globalThis.window when available
259
- */
260
- readonly host?: MaybeRefOrGetter<MediaQueryHost | null | undefined>;
261
- }
262
- /**
263
- * Evaluate a reactive media query without requiring browser globals.
264
- *
265
- * During server rendering (or whenever no capability host resolves) the ref
266
- * holds the configured server value and no subscription is created. The
267
- * change subscription follows the reactive query and host: each
268
- * re-evaluation removes the previous listener, and the final listener is
269
- * removed when the owning reactive scope stops. Call inside an active scope
270
- * so the subscription is released. A host whose matcher throws propagates
271
- * the error to the active effect run; the browser default never throws.
272
- *
273
- * @param query Reactive media-query source.
274
- * @param options Runtime capability and server-rendered fallback.
275
- * @default options {}
276
- * @returns Readonly ref that is `true` while the query matches.
277
- */
278
- declare function useMediaQuery(query: MaybeRefOrGetter<string>, options?: UseMediaQueryOptions): Readonly<Ref<boolean>>;
279
- /** User motion preference exposed by {@link useReducedMotion}. */
280
- type MotionPreference = "reduce" | "no-preference";
281
- /**
282
- * Return the reactive user motion preference.
283
- *
284
- * Shares {@link useMediaQuery} semantics: during server rendering the
285
- * preference is `"no-preference"` unless `ssrValue` is `true`, and the
286
- * underlying subscription is removed when the owning reactive scope stops.
287
- *
288
- * @param options Runtime capability and server-rendered fallback.
289
- * @default options {}
290
- * @returns Computed preference for `(prefers-reduced-motion: reduce)`.
291
- */
292
- declare function useReducedMotion(options?: UseMediaQueryOptions): ComputedRef<MotionPreference>;
293
- //#endregion
294
- //#region src/scope.d.ts
295
- /**
296
- * Register cleanup in the active reactive scope when one exists.
297
- *
298
- * This is the shared lifecycle primitive of the package: composables hand
299
- * their teardown here so owned resources are released when the surrounding
300
- * scope stops.
301
- *
302
- * Never throws and is safe during server rendering; no browser globals are
303
- * read. When no scope is active the cleanup is not registered and disposal
304
- * ownership stays with the caller.
305
- *
306
- * @param cleanup Cleanup invoked exactly once when the scope is disposed.
307
- * @returns Whether the cleanup was registered.
308
- */
309
- declare function tryOnScopeDispose(cleanup: () => void): boolean;
310
- //#endregion
311
- //#region src/timeout-scheduler.d.ts
312
- /**
313
- * Single-shot timer host used by the debounced and throttled state
314
- * utilities.
315
- *
316
- * Implement this interface to integrate a deterministic test clock, a native
317
- * runtime timer, or an application-owned scheduler. Handles are opaque: the
318
- * utilities only hand them back to {@link TimeoutScheduler.clearTimeout}.
319
- * This module declares types only and contributes no runtime code.
320
- */
321
- interface TimeoutScheduler {
322
- /** Starts a single-shot callback and returns its opaque cancellation handle. */
323
- readonly setTimeout: (callback: () => void, delayMs: number) => unknown;
324
- /** Cancels a handle previously returned by {@link TimeoutScheduler.setTimeout}. */
325
- readonly clearTimeout: (handle: unknown) => void;
326
- }
327
- //#endregion
328
- //#region src/use-counter.d.ts
329
- /** Options for {@link useCounter}. */
330
- interface UseCounterOptions {
331
- /**
332
- * Inclusive lower bound applied to every value the counter takes.
333
- *
334
- * @default Number.NEGATIVE_INFINITY
335
- */
336
- readonly min?: number;
337
- /**
338
- * Inclusive upper bound applied to every value the counter takes.
339
- *
340
- * @default Number.POSITIVE_INFINITY
341
- */
342
- readonly max?: number;
343
- }
344
- /** Reactive controls returned by {@link useCounter}. */
345
- interface CounterControls {
346
- /** Current count. Changes only through the controls, never by assignment. */
347
- readonly count: Readonly<ShallowRef<number>>;
348
- /** Whether the count currently sits on the configured lower bound. */
349
- readonly atMin: ComputedRef<boolean>;
350
- /** Whether the count currently sits on the configured upper bound. */
351
- readonly atMax: ComputedRef<boolean>;
352
- /**
353
- * Add `delta` (default `1`) to the count and clamp into the bounds.
354
- *
355
- * @param delta Amount added; may be negative or infinite.
356
- * @returns The count after clamping.
357
- */
358
- readonly increment: (delta?: number) => number;
359
- /**
360
- * Subtract `delta` (default `1`) from the count and clamp into the bounds.
361
- *
362
- * @param delta Amount subtracted; may be negative or infinite.
363
- * @returns The count after clamping.
364
- */
365
- readonly decrement: (delta?: number) => number;
366
- /**
367
- * Assign a value directly, clamped into the bounds.
368
- *
369
- * @returns The count after clamping.
370
- */
371
- readonly set: (value: number) => number;
372
- /**
373
- * Restore the reset baseline, or establish a new one.
374
- *
375
- * Without an argument the count returns to the creation-time initial value
376
- * (after its original clamping). With an argument, the clamped value
377
- * becomes both the new count and the baseline used by later `reset()`
378
- * calls.
379
- *
380
- * @param value Replacement baseline.
381
- * @returns The count after clamping.
382
- */
383
- readonly reset: (value?: number) => number;
384
- }
385
- /**
386
- * Create a clamped counter whose every transition stays inside `[min, max]`.
387
- *
388
- * All operations clamp instead of failing, including the initial value, so
389
- * the count is inside the bounds at every observable moment. Only `NaN` is
390
- * rejected — silently corrupting the count is never an option. Purely
391
- * synchronous state: safe during server rendering (no browser globals, no
392
- * timers) and nothing to dispose, so it works inside and outside reactive
393
- * scopes alike. Bounds are fixed at creation and not reactive.
394
- *
395
- * @example
396
- * ```ts
397
- * const { count, increment, atMax } = useCounter(9, { min: 0, max: 10 });
398
- * increment(); // 10
399
- * increment(); // 10 (clamped)
400
- * atMax.value; // true
401
- * ```
402
- *
403
- * @param initial Count before any operation, clamped into the bounds.
404
- * @default initial 0
405
- * @param options Inclusive bounds for every value the counter takes.
406
- * @default options {}
407
- * @throws `RangeError` tagged `VIZE_COMPOSE_COUNTER_INVALID_RANGE` when a
408
- * bound is `NaN` or `min` exceeds `max`.
409
- * @throws `RangeError` tagged `VIZE_COMPOSE_COUNTER_INVALID_VALUE` when an
410
- * initial value, operand, or arithmetic result is `NaN` (for example
411
- * incrementing `-Infinity` by `Infinity`); the count is left unchanged.
412
- * @returns Reactive count, bound flags, and mutation controls.
413
- */
414
- declare function useCounter(initial?: number, options?: UseCounterOptions): CounterControls;
415
- //#endregion
416
- //#region src/use-debounced.d.ts
417
- /** Options for {@link useDebounced}. */
418
- interface UseDebouncedOptions {
419
- /**
420
- * Applies the timing policy when no browser `window` is available.
421
- *
422
- * Keep this disabled during server rendering, where the debounced view
423
- * mirrors the source synchronously instead of starting timers. Enable it
424
- * for native, desktop, worker, and test runtimes whose scheduler is
425
- * lifecycle-bound.
426
- *
427
- * @default false
428
- */
429
- readonly runOnServer?: boolean;
430
- /**
431
- * Owns the single-shot timer.
432
- *
433
- * @default globalThis timer functions
434
- */
435
- readonly scheduler?: TimeoutScheduler;
436
- }
437
- /** Reactive debounced view and controls returned by {@link useDebounced}. */
438
- interface DebouncedControls<Value> {
439
- /** Readonly view of the source that settles `waitMs` after the last change. */
440
- readonly debounced: Readonly<ShallowRef<Value>>;
441
- /** Whether a trailing update is currently scheduled. */
442
- readonly pending: Readonly<ShallowRef<boolean>>;
443
- /**
444
- * Discard the scheduled trailing update and keep the last settled value.
445
- * Later source changes debounce again as usual.
446
- *
447
- * @returns Whether a scheduled update was discarded.
448
- */
449
- readonly cancel: () => boolean;
450
- /**
451
- * Apply the current source value immediately instead of waiting out the
452
- * delay.
453
- *
454
- * @returns Whether a scheduled update was applied.
455
- */
456
- readonly flush: () => boolean;
457
- }
458
- /**
459
- * Create a readonly debounced view of a reactive source.
460
- *
461
- * The view starts at the current source value. Each source change (observed
462
- * with `flush: "sync"`, so every synchronous write counts) restarts a
463
- * single-shot timer of `waitMs` milliseconds; when it fires, the view takes
464
- * the source value current at that moment. `waitMs` is reactive and is read
465
- * when a timer is scheduled; changing it does not restart an already-pending
466
- * timer. A wait of `0` still defers to the next scheduler tick.
467
- *
468
- * Server rendering is explicit: without a browser `window` (and with
469
- * {@link UseDebouncedOptions.runOnServer} disabled) no timer ever starts and
470
- * the view mirrors the source synchronously, so server-rendered output shows
471
- * current values and nothing leaks. `pending` stays `false` and the controls
472
- * report `false` in that mode.
473
- *
474
- * Cleanup rule: the watcher and any pending timer are released when the
475
- * owning reactive scope stops; call inside an active scope. Outside one, the
476
- * watcher lives as long as the source and `cancel()` only clears the pending
477
- * timer.
478
- *
479
- * @example
480
- * ```ts
481
- * const query = shallowRef("");
482
- * const { debounced, flush } = useDebounced(query, 300);
483
- * query.value = "vize"; // debounced.value still "" for 300ms
484
- * flush(); // debounced.value === "vize" immediately
485
- * ```
486
- *
487
- * @param source Reactive source to debounce.
488
- * @param waitMs Reactive delay in milliseconds; must be finite and at least
489
- * zero. Fractions are truncated.
490
- * @param options Runtime scheduling overrides.
491
- * @default options {}
492
- * @throws `RangeError` tagged `VIZE_COMPOSE_DEBOUNCE_INVALID_WAIT` when the
493
- * resolved wait is not finite or is negative, both synchronously at creation
494
- * (even in mirror mode) and again for every scheduled delay.
495
- * @returns Readonly debounced view, pending flag, and cancel/flush controls.
496
- */
497
- declare function useDebounced<Value>(source: MaybeRefOrGetter<Value>, waitMs: MaybeRefOrGetter<number>, options?: UseDebouncedOptions): DebouncedControls<Value>;
498
- //#endregion
499
- //#region src/use-history.d.ts
500
- /** Options for {@link useHistory}. */
501
- interface UseHistoryOptions<Value> {
502
- /**
503
- * Maximum number of undo entries retained; recording a change beyond it
504
- * drops the oldest entry. The redo stack is bounded by construction, since
505
- * redo entries only ever come from undone changes. Must be an integer
506
- * greater than zero and is fixed at creation.
507
- *
508
- * @default 100
509
- */
510
- readonly capacity?: number;
511
- /**
512
- * Clone applied to every value captured into history and to every value
513
- * restored out of it, isolating snapshots from later in-place mutation.
514
- *
515
- * @default identity — values are stored and restored by reference
516
- */
517
- readonly clone?: (value: Value) => Value;
518
- }
519
- /** Reactive undo/redo controls returned by {@link useHistory}. */
520
- interface HistoryControls {
521
- /** Whether {@link HistoryControls.undo} currently has an entry to restore. */
522
- readonly canUndo: ComputedRef<boolean>;
523
- /** Whether {@link HistoryControls.redo} currently has an entry to restore. */
524
- readonly canRedo: ComputedRef<boolean>;
525
- /** Number of retained undo entries. */
526
- readonly undoCount: ComputedRef<number>;
527
- /** Number of retained redo entries. */
528
- readonly redoCount: ComputedRef<number>;
529
- /**
530
- * Restore the newest undo entry and move the current value onto the redo
531
- * stack. The restoring write is not recorded.
532
- *
533
- * @returns Whether an entry was restored.
534
- */
535
- readonly undo: () => boolean;
536
- /**
537
- * Restore the newest redo entry and move the current value back onto the
538
- * undo stack. The restoring write is not recorded.
539
- *
540
- * @returns Whether an entry was restored.
541
- */
542
- readonly redo: () => boolean;
543
- /**
544
- * Group every source write inside `run` into at most one undo entry.
545
- *
546
- * The entry restores the value from just before the batch. It is committed
547
- * only when the final value differs (`Object.is`) from the starting value,
548
- * and it is committed even when `run` throws, so a partially applied batch
549
- * stays undoable as one step. Nested calls collapse into the outermost
550
- * batch. The callback's return value is passed through.
551
- */
552
- readonly batch: <Result>(run: () => Result) => Result;
553
- /** Drop every undo and redo entry while keeping the current value. */
554
- readonly clear: () => void;
555
- }
556
- /**
557
- * Record bounded undo/redo history over the writes of a ref.
558
- *
559
- * Recording is shallow and identity-based, matching Vue's own change
560
- * detection: assignments to `source.value` are recorded (observed with
561
- * `flush: "sync"`, so every synchronous write counts), writes that are
562
- * `Object.is`-equal to the current value are not changes, and in-place
563
- * mutations of object values are invisible — pair mutable values with
564
- * {@link UseHistoryOptions.clone} and reassign. Undoing and redoing restore
565
- * values through `clone` as well, so snapshots never share identity with the
566
- * live value unless the default identity clone is kept. When a
567
- * user-provided `clone` throws, the failed operation leaves history
568
- * unchanged and the error propagates.
569
- *
570
- * Safe during server rendering: no browser globals are read and no timers
571
- * start. Cleanup rule: when the owning reactive scope stops, recording stops
572
- * and every retained snapshot is released, so `undo`/`redo` return `false`
573
- * afterwards; call inside an active scope, or the watcher lives as long as
574
- * the source.
575
- *
576
- * @example
577
- * ```ts
578
- * const text = shallowRef("");
579
- * const { undo, redo, batch } = useHistory(text);
580
- * text.value = "a";
581
- * batch(() => {
582
- * text.value = "ab";
583
- * text.value = "abc";
584
- * });
585
- * undo(); // text.value === "a" (the batch is one step)
586
- * redo(); // text.value === "abc"
587
- * ```
588
- *
589
- * @param source Ref whose writes are recorded.
590
- * @param options Retention bound and snapshot cloning.
591
- * @default options {}
592
- * @throws `RangeError` tagged `VIZE_COMPOSE_HISTORY_INVALID_CAPACITY` when
593
- * the capacity is not an integer greater than zero.
594
- * @throws `Error` tagged `VIZE_COMPOSE_HISTORY_IN_BATCH` when `undo`,
595
- * `redo`, or `clear` is called inside {@link HistoryControls.batch}, where
596
- * stack movement would corrupt the pending group.
597
- * @returns Reactive undo/redo state and controls.
598
- */
599
- declare function useHistory<Value>(source: Ref<Value>, options?: UseHistoryOptions<Value>): HistoryControls;
600
- //#endregion
601
- //#region src/use-previous.d.ts
602
- /**
603
- * Track the value a reactive source held before its latest change.
604
- *
605
- * The semantics are precise and arity-based:
606
- *
607
- * - Without an `initial` argument the ref holds `undefined` until the source
608
- * changes for the first time.
609
- * - With an `initial` argument (including an explicit `undefined` when
610
- * `Value` allows it) the ref holds that value until the first change, and
611
- * the return type never widens with `undefined`.
612
- * - Every synchronous write is observed (`flush: "sync"`), so a sequence of
613
- * writes in one tick shifts the previous value step by step instead of
614
- * collapsing into one batch.
615
- * - Writes whose value is `Object.is`-equal to the current value do not
616
- * count as changes, matching Vue's own change detection.
617
- * - Tracking is shallow: reassignments are observed, in-place mutations of
618
- * object values are not.
619
- *
620
- * Safe during server rendering: no browser globals are read and no timers
621
- * start. The underlying watcher is bound to the current reactive scope and
622
- * stops with it; call inside an active scope, or the watcher lives as long
623
- * as the source. A plain non-reactive source never changes, so the ref stays
624
- * at its initial value.
625
- *
626
- * @example
627
- * ```ts
628
- * const route = shallowRef("/home");
629
- * const previousRoute = usePrevious(route, "/");
630
- * route.value = "/settings";
631
- * previousRoute.value; // "/home"
632
- * ```
633
- *
634
- * @param source Reactive source to observe.
635
- * @param initial Value reported before the first change.
636
- * @returns Readonly shallow ref holding the previous source value.
637
- */
638
- declare function usePrevious<Value>(source: MaybeRefOrGetter<Value>): Readonly<ShallowRef<Value | undefined>>;
639
- declare function usePrevious<Value>(source: MaybeRefOrGetter<Value>, initial: Value): Readonly<ShallowRef<Value>>;
640
- //#endregion
641
- //#region src/use-throttled.d.ts
642
- /** Options for {@link useThrottled}. */
643
- interface UseThrottledOptions {
644
- /**
645
- * Apply the first change of a cooldown window immediately.
646
- *
647
- * @default true
648
- */
649
- readonly leading?: boolean;
650
- /**
651
- * Apply the newest change collected during a cooldown window when the
652
- * window ends. When disabled, changes inside a window are dropped.
653
- *
654
- * @default true
655
- */
656
- readonly trailing?: boolean;
657
- /**
658
- * Applies the timing policy when no browser `window` is available.
659
- *
660
- * Keep this disabled during server rendering, where the throttled view
661
- * mirrors the source synchronously instead of starting timers. Enable it
662
- * for native, desktop, worker, and test runtimes whose scheduler is
663
- * lifecycle-bound.
664
- *
665
- * @default false
666
- */
667
- readonly runOnServer?: boolean;
668
- /**
669
- * Owns the single-shot cooldown timer.
670
- *
671
- * @default globalThis timer functions
672
- */
673
- readonly scheduler?: TimeoutScheduler;
674
- }
675
- /** Reactive throttled view and controls returned by {@link useThrottled}. */
676
- interface ThrottledControls<Value> {
677
- /** Readonly view of the source updated at most once per cooldown window. */
678
- readonly throttled: Readonly<ShallowRef<Value>>;
679
- /** Whether a trailing update is waiting for the current window to end. */
680
- readonly pending: Readonly<ShallowRef<boolean>>;
681
- /**
682
- * Discard the waiting trailing update and close the cooldown window, so
683
- * the next change starts fresh on a leading edge.
684
- *
685
- * @returns Whether a waiting trailing update was discarded.
686
- */
687
- readonly cancel: () => boolean;
688
- /**
689
- * Apply the waiting trailing update immediately and close the cooldown
690
- * window. Without a waiting update the window is left untouched.
691
- *
692
- * @returns Whether a waiting trailing update was applied.
693
- */
694
- readonly flush: () => boolean;
695
- }
696
- /**
697
- * Create a readonly throttled view of a reactive source.
698
- *
699
- * Changes are observed with `flush: "sync"`, so every synchronous write
700
- * counts. Outside a cooldown window, a change applies immediately when
701
- * {@link UseThrottledOptions.leading} is enabled (otherwise it waits as a
702
- * trailing update) and opens a window of `waitMs` milliseconds. Changes
703
- * inside a window are collected as the trailing candidate; when the window
704
- * ends with a candidate waiting, the source value current at that moment is
705
- * applied and the next window opens back to back, keeping applications
706
- * spaced by `waitMs`. A window that ends without a candidate closes silently.
707
- * `waitMs` is reactive and is read each time a window opens; changing it
708
- * never disturbs an already-open window. A wait of `0` still defers trailing
709
- * updates to the next scheduler tick.
710
- *
711
- * Server rendering is explicit: without a browser `window` (and with
712
- * {@link UseThrottledOptions.runOnServer} disabled) no timer ever starts and
713
- * the view mirrors the source synchronously, so server-rendered output shows
714
- * current values and nothing leaks. `pending` stays `false` and the controls
715
- * report `false` in that mode.
716
- *
717
- * Cleanup rule: the watcher and any open window timer are released when the
718
- * owning reactive scope stops; call inside an active scope. Outside one, the
719
- * watcher lives as long as the source and `cancel()` only clears the window.
720
- *
721
- * @example
722
- * ```ts
723
- * const scrollY = shallowRef(0);
724
- * const { throttled } = useThrottled(scrollY, 100);
725
- * scrollY.value = 40; // applied immediately (leading edge)
726
- * scrollY.value = 80; // applied when the 100ms window ends
727
- * ```
728
- *
729
- * @param source Reactive source to throttle.
730
- * @param waitMs Reactive cooldown in milliseconds; must be finite and at
731
- * least zero. Fractions are truncated.
732
- * @param options Edge policy and runtime scheduling overrides.
733
- * @default options {}
734
- * @throws `RangeError` tagged `VIZE_COMPOSE_THROTTLE_INVALID_WAIT` when the
735
- * resolved wait is not finite or is negative, both synchronously at creation
736
- * (even in mirror mode) and again each time a window opens.
737
- * @throws `TypeError` tagged `VIZE_COMPOSE_THROTTLE_INVALID_EDGES` when both
738
- * `leading` and `trailing` are disabled, because updates could then never
739
- * propagate.
740
- * @returns Readonly throttled view, pending flag, and cancel/flush controls.
741
- */
742
- declare function useThrottled<Value>(source: MaybeRefOrGetter<Value>, waitMs: MaybeRefOrGetter<number>, options?: UseThrottledOptions): ThrottledControls<Value>;
743
- //#endregion
744
- //#region src/use-toggle.d.ts
745
- /** Reactive controls returned by {@link useToggle}. */
746
- interface ToggleControls {
747
- /**
748
- * Owned boolean state.
749
- *
750
- * Deliberately writable: unlike the derived views elsewhere in this
751
- * package, the toggle owns its state, so assigning the ref directly (for
752
- * example through `v-model`) is equivalent to calling
753
- * {@link ToggleControls.toggle} with a forced value.
754
- */
755
- readonly state: Ref<boolean>;
756
- /**
757
- * Invert the state, or force it to `force` when the argument is given.
758
- * Passing an explicit `undefined` behaves like passing no argument.
759
- *
760
- * @param force Value assigned instead of inverting.
761
- * @returns The state after the change.
762
- */
763
- readonly toggle: (force?: boolean) => boolean;
764
- }
765
- /**
766
- * Create owned boolean state with an inverting control.
767
- *
768
- * Purely synchronous state: safe during server rendering (no browser
769
- * globals, no timers) and nothing to dispose, so it works inside and
770
- * outside reactive scopes alike.
771
- *
772
- * @example
773
- * ```ts
774
- * const { state: open, toggle } = useToggle();
775
- * toggle(); // true
776
- * toggle(false); // false
777
- * open.value; // false
778
- * ```
779
- *
780
- * @param initial State before the first toggle.
781
- * @default initial false
782
- * @returns The writable state and its toggle control.
783
- */
784
- declare function useToggle(initial?: boolean): ToggleControls;
785
- //#endregion
786
- export { AsyncResource, AsyncResourceContext, AsyncResourceExecution, AsyncResourceStatus, CounterControls, DebouncedControls, EventListenerControls, HistoryControls, LocaleControls, MediaQueryHost, MotionPreference, TextDirection, ThrottledControls, TimeoutScheduler, ToggleControls, UseAsyncResourceOptions, UseCounterOptions, UseDebouncedOptions, UseEventListenerOptions, UseHistoryOptions, UseLocaleOptions, UseMediaQueryOptions, UseThrottledOptions, tryOnScopeDispose, useAsyncResource, useCounter, useDebounced, useEventListener, useHistory, useLocale, useMediaQuery, usePrevious, useReducedMotion, useThrottled, useToggle };
1
+ import { TimeoutScheduler } from "./timeout-scheduler.mjs";
2
+ import { DeadlineAbortSignalOptions, TimeoutAbortSignalOptions, anyAbortSignal, deadlineAbortSignal, timeoutAbortSignal } from "./abort-signal.mjs";
3
+ import { AsyncResource, AsyncResourceContext, AsyncResourceExecution, AsyncResourceStatus, UseAsyncResourceOptions, useAsyncResource } from "./async-resource.mjs";
4
+ import { a as CapabilityUnavailableReason, c as isCapabilityAvailable, i as CapabilityTarget, l as isCapabilityUnavailable, n as CapabilityResult, o as UnavailableCapability, r as CapabilitySource, s as availableCapability, t as AvailableCapability, u as unavailableCapability } from "./capability-BNpkvSy5.mjs";
5
+ import { a as ComposableEntryMetadata, c as ComposableRootEntryMetadata, d as ComposableUtilityMetadata, i as ComposableCleanupOwner, l as ComposableSsrBehavior, n as ComposableCatalog, o as ComposableHydrationBehavior, r as ComposableCategory, s as ComposableInstallationAvailability, t as COMPOSABLE_CATALOG, u as ComposableStability } from "./catalog-CuWhR-0q.mjs";
6
+ import { CleanupRegistration, CreateDisposalScopeOptions, DISPOSAL_ERROR_CODE, DisposalError, DisposalScope, createDisposalScope } from "./disposal-scope.mjs";
7
+ import { EventListenerControls, UseEventListenerOptions, useEventListener } from "./event-listener.mjs";
8
+ import { LocaleControls, TextDirection, UseLocaleOptions, useLocale } from "./locale.mjs";
9
+ import { MediaQueryHost, MotionPreference, UseMediaQueryOptions, useMediaQuery, useReducedMotion } from "./media-query.mjs";
10
+ import { RetryDelayOptions, calculateRetryDelay } from "./retry-delay.mjs";
11
+ import { RetryAsyncOptions, RetryAttemptContext, RetryFailureContext, RetryScheduledContext, retryAsync } from "./retry-async.mjs";
12
+ import { tryOnScopeDispose } from "./scope.mjs";
13
+ import { CounterControls, UseCounterOptions, useCounter } from "./use-counter.mjs";
14
+ import { DebouncedControls, UseDebouncedOptions, useDebounced } from "./use-debounced.mjs";
15
+ import { HistoryControls, UseHistoryOptions, useHistory } from "./use-history.mjs";
16
+ import { usePrevious } from "./use-previous.mjs";
17
+ import { ThrottledControls, UseThrottledOptions, useThrottled } from "./use-throttled.mjs";
18
+ import { ToggleControls, useToggle } from "./use-toggle.mjs";
19
+ export { AsyncResource, AsyncResourceContext, AsyncResourceExecution, AsyncResourceStatus, AvailableCapability, COMPOSABLE_CATALOG, CapabilityResult, CapabilitySource, CapabilityTarget, CapabilityUnavailableReason, CleanupRegistration, ComposableCatalog, ComposableCategory, ComposableCleanupOwner, ComposableEntryMetadata, ComposableHydrationBehavior, ComposableInstallationAvailability, ComposableRootEntryMetadata, ComposableSsrBehavior, ComposableStability, ComposableUtilityMetadata, CounterControls, CreateDisposalScopeOptions, DISPOSAL_ERROR_CODE, DeadlineAbortSignalOptions, DebouncedControls, DisposalError, DisposalScope, EventListenerControls, HistoryControls, LocaleControls, MediaQueryHost, MotionPreference, RetryAsyncOptions, RetryAttemptContext, RetryDelayOptions, RetryFailureContext, RetryScheduledContext, TextDirection, ThrottledControls, TimeoutAbortSignalOptions, TimeoutScheduler, ToggleControls, UnavailableCapability, UseAsyncResourceOptions, UseCounterOptions, UseDebouncedOptions, UseEventListenerOptions, UseHistoryOptions, UseLocaleOptions, UseMediaQueryOptions, UseThrottledOptions, anyAbortSignal, availableCapability, calculateRetryDelay, createDisposalScope, deadlineAbortSignal, isCapabilityAvailable, isCapabilityUnavailable, retryAsync, timeoutAbortSignal, tryOnScopeDispose, unavailableCapability, useAsyncResource, useCounter, useDebounced, useEventListener, useHistory, useLocale, useMediaQuery, usePrevious, useReducedMotion, useThrottled, useToggle };