index.d.cts 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  1. import * as vue from 'vue';
  2. import { WatchOptionsBase, Ref, ComputedRef, WritableComputedRef, WatchSource, ComputedGetter, WritableComputedOptions, MaybeRef, WatchOptions, MaybeRefOrGetter, InjectionKey, ShallowUnwrapRef as ShallowUnwrapRef$1, inject, provide, UnwrapNestedRefs, UnwrapRef, ToRef, ToRefs, WatchCallback, WatchStopHandle } from 'vue';
  3. export { MaybeRef, MaybeRefOrGetter } from 'vue';
  4. /**
  5. * Note: If you are using Vue 3.4+, you can straight use computed instead.
  6. * Because in Vue 3.4+, if computed new value does not change,
  7. * computed, effect, watch, watchEffect, render dependencies will not be triggered.
  8. * refer: https://github.com/vuejs/core/pull/5912
  9. *
  10. * @param fn effect function
  11. * @param options WatchOptionsBase
  12. * @returns readonly ref
  13. */
  14. declare function computedEager<T>(fn: () => T, options?: WatchOptionsBase): Readonly<Ref<T>>;
  15. interface ComputedWithControlRefExtra {
  16. /**
  17. * Force update the computed value.
  18. */
  19. trigger: () => void;
  20. }
  21. interface ComputedRefWithControl<T> extends ComputedRef<T>, ComputedWithControlRefExtra {
  22. }
  23. interface WritableComputedRefWithControl<T> extends WritableComputedRef<T>, ComputedWithControlRefExtra {
  24. }
  25. declare function computedWithControl<T, S>(source: WatchSource<S> | WatchSource<S>[], fn: ComputedGetter<T>): ComputedRefWithControl<T>;
  26. declare function computedWithControl<T, S>(source: WatchSource<S> | WatchSource<S>[], fn: WritableComputedOptions<T>): WritableComputedRefWithControl<T>;
  27. /**
  28. * Void function
  29. */
  30. type Fn = () => void;
  31. /**
  32. * Any function
  33. */
  34. type AnyFn = (...args: any[]) => any;
  35. /**
  36. * A ref that allow to set null or undefined
  37. */
  38. type RemovableRef<T> = Omit<Ref<T>, 'value'> & {
  39. get value(): T;
  40. set value(value: T | null | undefined);
  41. };
  42. /**
  43. * Maybe it's a computed ref, or a readonly value, or a getter function
  44. */
  45. type ReadonlyRefOrGetter<T> = ComputedRef<T> | (() => T);
  46. /**
  47. * Make all the nested attributes of an object or array to MaybeRef<T>
  48. *
  49. * Good for accepting options that will be wrapped with `reactive` or `ref`
  50. *
  51. * ```ts
  52. * UnwrapRef<DeepMaybeRef<T>> === T
  53. * ```
  54. */
  55. type DeepMaybeRef<T> = T extends Ref<infer V> ? MaybeRef<V> : T extends Array<any> | object ? {
  56. [K in keyof T]: DeepMaybeRef<T[K]>;
  57. } : MaybeRef<T>;
  58. type Arrayable<T> = T[] | T;
  59. /**
  60. * Infers the element type of an array
  61. */
  62. type ElementOf<T> = T extends (infer E)[] ? E : never;
  63. type ShallowUnwrapRef<T> = T extends Ref<infer P> ? P : T;
  64. type Awaitable<T> = Promise<T> | T;
  65. type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;
  66. /**
  67. * Compatible with versions below TypeScript 4.5 Awaited
  68. */
  69. type Awaited<T> = T extends null | undefined ? T : T extends object & {
  70. then: (onfulfilled: infer F, ...args: infer _) => any;
  71. } ? F extends ((value: infer V, ...args: infer _) => any) ? Awaited<V> : never : T;
  72. type Promisify<T> = Promise<Awaited<T>>;
  73. type PromisifyFn<T extends AnyFn> = (...args: ArgumentsType<T>) => Promisify<ReturnType<T>>;
  74. interface Pausable {
  75. /**
  76. * A ref indicate whether a pausable instance is active
  77. */
  78. isActive: Readonly<Ref<boolean>>;
  79. /**
  80. * Temporary pause the effect from executing
  81. */
  82. pause: Fn;
  83. /**
  84. * Resume the effects
  85. */
  86. resume: Fn;
  87. }
  88. interface Stoppable<StartFnArgs extends any[] = any[]> {
  89. /**
  90. * A ref indicate whether a stoppable instance is executing
  91. */
  92. isPending: Readonly<Ref<boolean>>;
  93. /**
  94. * Stop the effect from executing
  95. */
  96. stop: Fn;
  97. /**
  98. * Start the effects
  99. */
  100. start: (...args: StartFnArgs) => void;
  101. }
  102. interface ConfigurableFlush {
  103. /**
  104. * Timing for monitoring changes, refer to WatchOptions for more details
  105. *
  106. * @default 'pre'
  107. */
  108. flush?: WatchOptions['flush'];
  109. }
  110. interface ConfigurableFlushSync {
  111. /**
  112. * Timing for monitoring changes, refer to WatchOptions for more details.
  113. * Unlike `watch()`, the default is set to `sync`
  114. *
  115. * @default 'sync'
  116. */
  117. flush?: WatchOptions['flush'];
  118. }
  119. type MultiWatchSources = (WatchSource<unknown> | object)[];
  120. type MapSources<T> = {
  121. [K in keyof T]: T[K] extends WatchSource<infer V> ? V : never;
  122. };
  123. type MapOldSources<T, Immediate> = {
  124. [K in keyof T]: T[K] extends WatchSource<infer V> ? Immediate extends true ? V | undefined : V : never;
  125. };
  126. type Mutable<T> = {
  127. -readonly [P in keyof T]: T[P];
  128. };
  129. type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
  130. /**
  131. * will return `true` if `T` is `any`, or `false` otherwise
  132. */
  133. type IsAny<T> = IfAny<T, true, false>;
  134. /**
  135. * The source code for this function was inspired by vue-apollo's `useEventHook` util
  136. * https://github.com/vuejs/vue-apollo/blob/v4/packages/vue-apollo-composable/src/util/useEventHook.ts
  137. */
  138. type Callback<T> = IsAny<T> extends true ? (...param: any) => void : ([
  139. T
  140. ] extends [void] ? (...param: unknown[]) => void : (...param: [T, ...unknown[]]) => void);
  141. type EventHookOn<T = any> = (fn: Callback<T>) => {
  142. off: () => void;
  143. };
  144. type EventHookOff<T = any> = (fn: Callback<T>) => void;
  145. type EventHookTrigger<T = any> = (...param: IsAny<T> extends true ? unknown[] : [T, ...unknown[]]) => Promise<unknown[]>;
  146. interface EventHook<T = any> {
  147. on: EventHookOn<T>;
  148. off: EventHookOff<T>;
  149. trigger: EventHookTrigger<T>;
  150. }
  151. /**
  152. * Utility for creating event hooks
  153. *
  154. * @see https://vueuse.org/createEventHook
  155. */
  156. declare function createEventHook<T = any>(): EventHook<T>;
  157. type FunctionArgs<Args extends any[] = any[], Return = void> = (...args: Args) => Return;
  158. interface FunctionWrapperOptions<Args extends any[] = any[], This = any> {
  159. fn: FunctionArgs<Args, This>;
  160. args: Args;
  161. thisArg: This;
  162. }
  163. type EventFilter<Args extends any[] = any[], This = any, Invoke extends AnyFn = AnyFn> = (invoke: Invoke, options: FunctionWrapperOptions<Args, This>) => ReturnType<Invoke> | Promisify<ReturnType<Invoke>>;
  164. interface ConfigurableEventFilter {
  165. /**
  166. * Filter for if events should to be received.
  167. *
  168. * @see https://vueuse.org/guide/config.html#event-filters
  169. */
  170. eventFilter?: EventFilter;
  171. }
  172. interface DebounceFilterOptions {
  173. /**
  174. * The maximum time allowed to be delayed before it's invoked.
  175. * In milliseconds.
  176. */
  177. maxWait?: MaybeRefOrGetter<number>;
  178. /**
  179. * Whether to reject the last call if it's been cancel.
  180. *
  181. * @default false
  182. */
  183. rejectOnCancel?: boolean;
  184. }
  185. /**
  186. * @internal
  187. */
  188. declare function createFilterWrapper<T extends AnyFn>(filter: EventFilter, fn: T): (this: any, ...args: ArgumentsType<T>) => Promise<Awaited<ReturnType<T>>>;
  189. declare const bypassFilter: EventFilter;
  190. /**
  191. * Create an EventFilter that debounce the events
  192. */
  193. declare function debounceFilter(ms: MaybeRefOrGetter<number>, options?: DebounceFilterOptions): EventFilter<any[], any, AnyFn>;
  194. interface ThrottleFilterOptions {
  195. /**
  196. * The maximum time allowed to be delayed before it's invoked.
  197. */
  198. delay: MaybeRefOrGetter<number>;
  199. /**
  200. * Whether to invoke on the trailing edge of the timeout.
  201. */
  202. trailing?: boolean;
  203. /**
  204. * Whether to invoke on the leading edge of the timeout.
  205. */
  206. leading?: boolean;
  207. /**
  208. * Whether to reject the last call if it's been cancel.
  209. */
  210. rejectOnCancel?: boolean;
  211. }
  212. /**
  213. * Create an EventFilter that throttle the events
  214. *
  215. * @param ms
  216. * @param [trailing]
  217. * @param [leading]
  218. * @param [rejectOnCancel]
  219. */
  220. declare function throttleFilter(ms: MaybeRefOrGetter<number>, trailing?: boolean, leading?: boolean, rejectOnCancel?: boolean): EventFilter;
  221. declare function throttleFilter(options: ThrottleFilterOptions): EventFilter;
  222. /**
  223. * EventFilter that gives extra controls to pause and resume the filter
  224. *
  225. * @param extendFilter Extra filter to apply when the PausableFilter is active, default to none
  226. *
  227. */
  228. declare function pausableFilter(extendFilter?: EventFilter): Pausable & {
  229. eventFilter: EventFilter;
  230. };
  231. declare const isClient: boolean;
  232. declare const isWorker: boolean;
  233. declare const isDef: <T = any>(val?: T) => val is T;
  234. declare const notNullish: <T = any>(val?: T | null | undefined) => val is T;
  235. declare const assert: (condition: boolean, ...infos: any[]) => void;
  236. declare const isObject: (val: any) => val is object;
  237. declare const now: () => number;
  238. declare const timestamp: () => number;
  239. declare const clamp: (n: number, min: number, max: number) => number;
  240. declare const noop: () => void;
  241. declare const rand: (min: number, max: number) => number;
  242. declare const hasOwn: <T extends object, K extends keyof T>(val: T, key: K) => key is K;
  243. declare const isIOS: boolean | "";
  244. declare const hyphenate: (str: string) => string;
  245. declare const camelize: (str: string) => string;
  246. declare function promiseTimeout(ms: number, throwOnTimeout?: boolean, reason?: string): Promise<void>;
  247. declare function identity<T>(arg: T): T;
  248. interface SingletonPromiseReturn<T> {
  249. (): Promise<T>;
  250. /**
  251. * Reset current staled promise.
  252. * await it to have proper shutdown.
  253. */
  254. reset: () => Promise<void>;
  255. }
  256. /**
  257. * Create singleton promise function
  258. *
  259. * @example
  260. * ```
  261. * const promise = createSingletonPromise(async () => { ... })
  262. *
  263. * await promise()
  264. * await promise() // all of them will be bind to a single promise instance
  265. * await promise() // and be resolved together
  266. * ```
  267. */
  268. declare function createSingletonPromise<T>(fn: () => Promise<T>): SingletonPromiseReturn<T>;
  269. declare function invoke<T>(fn: () => T): T;
  270. declare function containsProp(obj: object, ...props: string[]): boolean;
  271. /**
  272. * Increase string a value with unit
  273. *
  274. * @example '2px' + 1 = '3px'
  275. * @example '15em' + (-2) = '13em'
  276. */
  277. declare function increaseWithUnit(target: number, delta: number): number;
  278. declare function increaseWithUnit(target: string, delta: number): string;
  279. declare function increaseWithUnit(target: string | number, delta: number): string | number;
  280. /**
  281. * Create a new subset object by giving keys
  282. */
  283. declare function objectPick<O extends object, T extends keyof O>(obj: O, keys: T[], omitUndefined?: boolean): Pick<O, T>;
  284. /**
  285. * Create a new subset object by omit giving keys
  286. */
  287. declare function objectOmit<O extends object, T extends keyof O>(obj: O, keys: T[], omitUndefined?: boolean): Omit<O, T>;
  288. declare function objectEntries<T extends object>(obj: T): Array<[keyof T, T[keyof T]]>;
  289. declare function getLifeCycleTarget(target?: any): any;
  290. /**
  291. * Keep states in the global scope to be reusable across Vue instances.
  292. *
  293. * @see https://vueuse.org/createGlobalState
  294. * @param stateFactory A factory function to create the state
  295. */
  296. declare function createGlobalState<Fn extends AnyFn>(stateFactory: Fn): Fn;
  297. interface CreateInjectionStateOptions<Return> {
  298. /**
  299. * Custom injectionKey for InjectionState
  300. */
  301. injectionKey?: string | InjectionKey<Return>;
  302. /**
  303. * Default value for the InjectionState
  304. */
  305. defaultValue?: Return;
  306. }
  307. /**
  308. * Create global state that can be injected into components.
  309. *
  310. * @see https://vueuse.org/createInjectionState
  311. *
  312. */
  313. declare function createInjectionState<Arguments extends Array<any>, Return>(composable: (...args: Arguments) => Return, options?: CreateInjectionStateOptions<Return>): readonly [useProvidingState: (...args: Arguments) => Return, useInjectedState: () => Return | undefined];
  314. /**
  315. * Make a composable function usable with multiple Vue instances.
  316. *
  317. * @see https://vueuse.org/createSharedComposable
  318. */
  319. declare function createSharedComposable<Fn extends AnyFn>(composable: Fn): Fn;
  320. interface ExtendRefOptions<Unwrap extends boolean = boolean> {
  321. /**
  322. * Is the extends properties enumerable
  323. *
  324. * @default false
  325. */
  326. enumerable?: boolean;
  327. /**
  328. * Unwrap for Ref properties
  329. *
  330. * @default true
  331. */
  332. unwrap?: Unwrap;
  333. }
  334. /**
  335. * Overload 1: Unwrap set to false
  336. */
  337. declare function extendRef<R extends Ref<any>, Extend extends object, Options extends ExtendRefOptions<false>>(ref: R, extend: Extend, options?: Options): ShallowUnwrapRef$1<Extend> & R;
  338. /**
  339. * Overload 2: Unwrap unset or set to true
  340. */
  341. declare function extendRef<R extends Ref<any>, Extend extends object, Options extends ExtendRefOptions>(ref: R, extend: Extend, options?: Options): Extend & R;
  342. /**
  343. * Shorthand for accessing `ref.value`
  344. */
  345. declare function get<T>(ref: MaybeRef<T>): T;
  346. declare function get<T, K extends keyof T>(ref: MaybeRef<T>, key: K): T[K];
  347. /**
  348. * On the basis of `inject`, it is allowed to directly call inject to obtain the value after call provide in the same component.
  349. *
  350. * @example
  351. * ```ts
  352. * injectLocal('MyInjectionKey', 1)
  353. * const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
  354. * ```
  355. */
  356. declare const injectLocal: typeof inject;
  357. declare function isDefined<T>(v: ComputedRef<T>): v is ComputedRef<Exclude<T, null | undefined>>;
  358. declare function isDefined<T>(v: Ref<T>): v is Ref<Exclude<T, null | undefined>>;
  359. declare function isDefined<T>(v: T): v is Exclude<T, null | undefined>;
  360. declare function makeDestructurable<T extends Record<string, unknown>, A extends readonly any[]>(obj: T, arr: A): T & A;
  361. /**
  362. * On the basis of `provide`, it is allowed to directly call inject to obtain the value after call provide in the same component.
  363. *
  364. * @example
  365. * ```ts
  366. * provideLocal('MyInjectionKey', 1)
  367. * const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1
  368. * ```
  369. */
  370. declare const provideLocal: typeof provide;
  371. type Reactified<T, Computed extends boolean> = T extends (...args: infer A) => infer R ? (...args: {
  372. [K in keyof A]: Computed extends true ? MaybeRefOrGetter<A[K]> : MaybeRef<A[K]>;
  373. }) => ComputedRef<R> : never;
  374. interface ReactifyOptions<T extends boolean> {
  375. /**
  376. * Accept passing a function as a reactive getter
  377. *
  378. * @default true
  379. */
  380. computedGetter?: T;
  381. }
  382. /**
  383. * Converts plain function into a reactive function.
  384. * The converted function accepts refs as it's arguments
  385. * and returns a ComputedRef, with proper typing.
  386. *
  387. * @param fn - Source function
  388. */
  389. declare function reactify<T extends Function, K extends boolean = true>(fn: T, options?: ReactifyOptions<K>): Reactified<T, K>;
  390. type ReactifyNested<T, Keys extends keyof T = keyof T, S extends boolean = true> = {
  391. [K in Keys]: T[K] extends AnyFn ? Reactified<T[K], S> : T[K];
  392. };
  393. interface ReactifyObjectOptions<T extends boolean> extends ReactifyOptions<T> {
  394. /**
  395. * Includes names from Object.getOwnPropertyNames
  396. *
  397. * @default true
  398. */
  399. includeOwnProperties?: boolean;
  400. }
  401. /**
  402. * Apply `reactify` to an object
  403. */
  404. declare function reactifyObject<T extends object, Keys extends keyof T>(obj: T, keys?: (keyof T)[]): ReactifyNested<T, Keys, true>;
  405. declare function reactifyObject<T extends object, S extends boolean = true>(obj: T, options?: ReactifyObjectOptions<S>): ReactifyNested<T, keyof T, S>;
  406. /**
  407. * Computed reactive object.
  408. */
  409. declare function reactiveComputed<T extends object>(fn: () => T): UnwrapNestedRefs<T>;
  410. type ReactiveOmitPredicate<T> = (value: T[keyof T], key: keyof T) => boolean;
  411. declare function reactiveOmit<T extends object, K extends keyof T>(obj: T, ...keys: (K | K[])[]): Omit<T, K>;
  412. declare function reactiveOmit<T extends object>(obj: T, predicate: ReactiveOmitPredicate<T>): Partial<T>;
  413. type ReactivePickPredicate<T> = (value: T[keyof T], key: keyof T) => boolean;
  414. declare function reactivePick<T extends object, K extends keyof T>(obj: T, ...keys: (K | K[])[]): {
  415. [S in K]: UnwrapRef<T[S]>;
  416. };
  417. declare function reactivePick<T extends object>(obj: T, predicate: ReactivePickPredicate<T>): {
  418. [S in keyof T]?: UnwrapRef<T[S]>;
  419. };
  420. /**
  421. * Create a ref which will be reset to the default value after some time.
  422. *
  423. * @see https://vueuse.org/refAutoReset
  424. * @param defaultValue The value which will be set.
  425. * @param afterMs A zero-or-greater delay in milliseconds.
  426. */
  427. declare function refAutoReset<T>(defaultValue: MaybeRefOrGetter<T>, afterMs?: MaybeRefOrGetter<number>): Ref<T>;
  428. /**
  429. * Debounce updates of a ref.
  430. *
  431. * @return A new debounced ref.
  432. */
  433. declare function refDebounced<T>(value: Ref<T>, ms?: MaybeRefOrGetter<number>, options?: DebounceFilterOptions): Readonly<Ref<T>>;
  434. /**
  435. * Apply default value to a ref.
  436. */
  437. declare function refDefault<T>(source: Ref<T | undefined | null>, defaultValue: T): Ref<T>;
  438. /**
  439. * Throttle execution of a function. Especially useful for rate limiting
  440. * execution of handlers on events like resize and scroll.
  441. *
  442. * @param value Ref value to be watched with throttle effect
  443. * @param delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
  444. * @param [trailing] if true, update the value again after the delay time is up
  445. * @param [leading] if true, update the value on the leading edge of the ms timeout
  446. */
  447. declare function refThrottled<T>(value: Ref<T>, delay?: number, trailing?: boolean, leading?: boolean): Ref<T, T>;
  448. interface ControlledRefOptions<T> {
  449. /**
  450. * Callback function before the ref changing.
  451. *
  452. * Returning `false` to dismiss the change.
  453. */
  454. onBeforeChange?: (value: T, oldValue: T) => void | boolean;
  455. /**
  456. * Callback function after the ref changed
  457. *
  458. * This happens synchronously, with less overhead compare to `watch`
  459. */
  460. onChanged?: (value: T, oldValue: T) => void;
  461. }
  462. /**
  463. * Fine-grained controls over ref and its reactivity.
  464. */
  465. declare function refWithControl<T>(initial: T, options?: ControlledRefOptions<T>): vue.ShallowUnwrapRef<{
  466. get: (tracking?: boolean) => T;
  467. set: (value: T, triggering?: boolean) => void;
  468. untrackedGet: () => T;
  469. silentSet: (v: T) => void;
  470. peek: () => T;
  471. lay: (v: T) => void;
  472. }> & vue.Ref<T, T>;
  473. /**
  474. * Alias for `refWithControl`
  475. */
  476. declare const controlledRef: typeof refWithControl;
  477. declare function set<T>(ref: Ref<T>, value: T): void;
  478. declare function set<O extends object, K extends keyof O>(target: O, key: K, value: O[K]): void;
  479. type Direction = 'ltr' | 'rtl' | 'both';
  480. type SpecificFieldPartial<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
  481. /**
  482. * A = B
  483. */
  484. type Equal<A, B> = [A] extends [B] ? ([B] extends [A] ? true : false) : false;
  485. /**
  486. * A ∩ B ≠ ∅
  487. */
  488. type IntersectButNotEqual<A, B> = Equal<A, B> extends true ? false : A & B extends never ? false : true;
  489. /**
  490. * A ⊆ B
  491. */
  492. type IncludeButNotEqual<A, B> = Equal<A, B> extends true ? false : A extends B ? true : false;
  493. /**
  494. * A ∩ B = ∅
  495. */
  496. type NotIntersect<A, B> = Equal<A, B> extends true ? false : A & B extends never ? true : false;
  497. interface EqualType<D extends Direction, L, R, O extends keyof Transform<L, R> = D extends 'both' ? 'ltr' | 'rtl' : D> {
  498. transform?: SpecificFieldPartial<Pick<Transform<L, R>, O>, O>;
  499. }
  500. type StrictIncludeMap<IncludeType extends 'LR' | 'RL', D extends Exclude<Direction, 'both'>, L, R> = (Equal<[IncludeType, D], ['LR', 'ltr']> & Equal<[IncludeType, D], ['RL', 'rtl']>) extends true ? {
  501. transform?: SpecificFieldPartial<Pick<Transform<L, R>, D>, D>;
  502. } : {
  503. transform: Pick<Transform<L, R>, D>;
  504. };
  505. type StrictIncludeType<IncludeType extends 'LR' | 'RL', D extends Direction, L, R> = D extends 'both' ? {
  506. transform: SpecificFieldPartial<Transform<L, R>, IncludeType extends 'LR' ? 'ltr' : 'rtl'>;
  507. } : D extends Exclude<Direction, 'both'> ? StrictIncludeMap<IncludeType, D, L, R> : never;
  508. type IntersectButNotEqualType<D extends Direction, L, R> = D extends 'both' ? {
  509. transform: Transform<L, R>;
  510. } : D extends Exclude<Direction, 'both'> ? {
  511. transform: Pick<Transform<L, R>, D>;
  512. } : never;
  513. type NotIntersectType<D extends Direction, L, R> = IntersectButNotEqualType<D, L, R>;
  514. interface Transform<L, R> {
  515. ltr: (left: L) => R;
  516. rtl: (right: R) => L;
  517. }
  518. type TransformType<D extends Direction, L, R> = Equal<L, R> extends true ? EqualType<D, L, R> : IncludeButNotEqual<L, R> extends true ? StrictIncludeType<'LR', D, L, R> : IncludeButNotEqual<R, L> extends true ? StrictIncludeType<'RL', D, L, R> : IntersectButNotEqual<L, R> extends true ? IntersectButNotEqualType<D, L, R> : NotIntersect<L, R> extends true ? NotIntersectType<D, L, R> : never;
  519. type SyncRefOptions<L, R, D extends Direction> = ConfigurableFlushSync & {
  520. /**
  521. * Watch deeply
  522. *
  523. * @default false
  524. */
  525. deep?: boolean;
  526. /**
  527. * Sync values immediately
  528. *
  529. * @default true
  530. */
  531. immediate?: boolean;
  532. /**
  533. * Direction of syncing. Value will be redefined if you define syncConvertors
  534. *
  535. * @default 'both'
  536. */
  537. direction?: D;
  538. } & TransformType<D, L, R>;
  539. /**
  540. * Two-way refs synchronization.
  541. * From the set theory perspective to restrict the option's type
  542. * Check in the following order:
  543. * 1. L = R
  544. * 2. L ∩ R ≠ ∅
  545. * 3. L ⊆ R
  546. * 4. L ∩ R = ∅
  547. */
  548. declare function syncRef<L, R, D extends Direction = 'both'>(left: Ref<L>, right: Ref<R>, ...[options]: Equal<L, R> extends true ? [options?: SyncRefOptions<L, R, D>] : [options: SyncRefOptions<L, R, D>]): () => void;
  549. interface SyncRefsOptions extends ConfigurableFlushSync {
  550. /**
  551. * Watch deeply
  552. *
  553. * @default false
  554. */
  555. deep?: boolean;
  556. /**
  557. * Sync values immediately
  558. *
  559. * @default true
  560. */
  561. immediate?: boolean;
  562. }
  563. /**
  564. * Keep target ref(s) in sync with the source ref
  565. *
  566. * @param source source ref
  567. * @param targets
  568. */
  569. declare function syncRefs<T>(source: WatchSource<T>, targets: Ref<T> | Ref<T>[], options?: SyncRefsOptions): vue.WatchHandle;
  570. /**
  571. * Converts ref to reactive.
  572. *
  573. * @see https://vueuse.org/toReactive
  574. * @param objectRef A ref of object
  575. */
  576. declare function toReactive<T extends object>(objectRef: MaybeRef<T>): UnwrapNestedRefs<T>;
  577. /**
  578. * Normalize value/ref/getter to `ref` or `computed`.
  579. */
  580. declare function toRef<T>(r: () => T): Readonly<Ref<T>>;
  581. declare function toRef<T>(r: ComputedRef<T>): ComputedRef<T>;
  582. declare function toRef<T>(r: MaybeRefOrGetter<T>): Ref<T>;
  583. declare function toRef<T>(r: T): Ref<T>;
  584. declare function toRef<T extends object, K extends keyof T>(object: T, key: K): ToRef<T[K]>;
  585. declare function toRef<T extends object, K extends keyof T>(object: T, key: K, defaultValue: T[K]): ToRef<Exclude<T[K], undefined>>;
  586. /**
  587. * @deprecated use `toRef` instead
  588. */
  589. declare const resolveRef: typeof toRef;
  590. interface ToRefsOptions {
  591. /**
  592. * Replace the original ref with a copy on property update.
  593. *
  594. * @default true
  595. */
  596. replaceRef?: MaybeRefOrGetter<boolean>;
  597. }
  598. /**
  599. * Extended `toRefs` that also accepts refs of an object.
  600. *
  601. * @see https://vueuse.org/toRefs
  602. * @param objectRef A ref or normal object or array.
  603. */
  604. declare function toRefs<T extends object>(objectRef: MaybeRef<T>, options?: ToRefsOptions): ToRefs<T>;
  605. /**
  606. * Get the value of value/ref/getter.
  607. */
  608. declare function toValue<T>(r: MaybeRefOrGetter<T>): T;
  609. /**
  610. * @deprecated use `toValue` instead
  611. */
  612. declare const resolveUnref: typeof toValue;
  613. /**
  614. * Call onBeforeMount() if it's inside a component lifecycle, if not, just call the function
  615. *
  616. * @param fn
  617. * @param sync if set to false, it will run in the nextTick() of Vue
  618. * @param target
  619. */
  620. declare function tryOnBeforeMount(fn: Fn, sync?: boolean, target?: any): void;
  621. /**
  622. * Call onBeforeUnmount() if it's inside a component lifecycle, if not, do nothing
  623. *
  624. * @param fn
  625. * @param target
  626. */
  627. declare function tryOnBeforeUnmount(fn: Fn, target?: any): void;
  628. /**
  629. * Call onMounted() if it's inside a component lifecycle, if not, just call the function
  630. *
  631. * @param fn
  632. * @param sync if set to false, it will run in the nextTick() of Vue
  633. * @param target
  634. */
  635. declare function tryOnMounted(fn: Fn, sync?: boolean, target?: any): void;
  636. /**
  637. * Call onScopeDispose() if it's inside an effect scope lifecycle, if not, do nothing
  638. *
  639. * @param fn
  640. */
  641. declare function tryOnScopeDispose(fn: Fn): boolean;
  642. /**
  643. * Call onUnmounted() if it's inside a component lifecycle, if not, do nothing
  644. *
  645. * @param fn
  646. * @param target
  647. */
  648. declare function tryOnUnmounted(fn: Fn, target?: any): void;
  649. interface UntilToMatchOptions {
  650. /**
  651. * Milliseconds timeout for promise to resolve/reject if the when condition does not meet.
  652. * 0 for never timed out
  653. *
  654. * @default 0
  655. */
  656. timeout?: number;
  657. /**
  658. * Reject the promise when timeout
  659. *
  660. * @default false
  661. */
  662. throwOnTimeout?: boolean;
  663. /**
  664. * `flush` option for internal watch
  665. *
  666. * @default 'sync'
  667. */
  668. flush?: WatchOptions['flush'];
  669. /**
  670. * `deep` option for internal watch
  671. *
  672. * @default 'false'
  673. */
  674. deep?: WatchOptions['deep'];
  675. }
  676. interface UntilBaseInstance<T, Not extends boolean = false> {
  677. toMatch: (<U extends T = T>(condition: (v: T) => v is U, options?: UntilToMatchOptions) => Not extends true ? Promise<Exclude<T, U>> : Promise<U>) & ((condition: (v: T) => boolean, options?: UntilToMatchOptions) => Promise<T>);
  678. changed: (options?: UntilToMatchOptions) => Promise<T>;
  679. changedTimes: (n?: number, options?: UntilToMatchOptions) => Promise<T>;
  680. }
  681. type Falsy = false | void | null | undefined | 0 | 0n | '';
  682. interface UntilValueInstance<T, Not extends boolean = false> extends UntilBaseInstance<T, Not> {
  683. readonly not: UntilValueInstance<T, Not extends true ? false : true>;
  684. toBe: <P = T>(value: MaybeRefOrGetter<P>, options?: UntilToMatchOptions) => Not extends true ? Promise<T> : Promise<P>;
  685. toBeTruthy: (options?: UntilToMatchOptions) => Not extends true ? Promise<T & Falsy> : Promise<Exclude<T, Falsy>>;
  686. toBeNull: (options?: UntilToMatchOptions) => Not extends true ? Promise<Exclude<T, null>> : Promise<null>;
  687. toBeUndefined: (options?: UntilToMatchOptions) => Not extends true ? Promise<Exclude<T, undefined>> : Promise<undefined>;
  688. toBeNaN: (options?: UntilToMatchOptions) => Promise<T>;
  689. }
  690. interface UntilArrayInstance<T> extends UntilBaseInstance<T> {
  691. readonly not: UntilArrayInstance<T>;
  692. toContains: (value: MaybeRefOrGetter<ElementOf<ShallowUnwrapRef<T>>>, options?: UntilToMatchOptions) => Promise<T>;
  693. }
  694. /**
  695. * Promised one-time watch for changes
  696. *
  697. * @see https://vueuse.org/until
  698. * @example
  699. * ```
  700. * const { count } = useCounter()
  701. *
  702. * await until(count).toMatch(v => v > 7)
  703. *
  704. * alert('Counter is now larger than 7!')
  705. * ```
  706. */
  707. declare function until<T extends unknown[]>(r: WatchSource<T> | MaybeRefOrGetter<T>): UntilArrayInstance<T>;
  708. declare function until<T>(r: WatchSource<T> | MaybeRefOrGetter<T>): UntilValueInstance<T>;
  709. declare function useArrayDifference<T>(list: MaybeRefOrGetter<T[]>, values: MaybeRefOrGetter<T[]>, key?: keyof T): ComputedRef<T[]>;
  710. declare function useArrayDifference<T>(list: MaybeRefOrGetter<T[]>, values: MaybeRefOrGetter<T[]>, compareFn?: (value: T, othVal: T) => boolean): ComputedRef<T[]>;
  711. /**
  712. * Reactive `Array.every`
  713. *
  714. * @see https://vueuse.org/useArrayEvery
  715. * @param list - the array was called upon.
  716. * @param fn - a function to test each element.
  717. *
  718. * @returns **true** if the `fn` function returns a **truthy** value for every element from the array. Otherwise, **false**.
  719. */
  720. declare function useArrayEvery<T>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, fn: (element: T, index: number, array: MaybeRefOrGetter<T>[]) => unknown): ComputedRef<boolean>;
  721. /**
  722. * Reactive `Array.filter`
  723. *
  724. * @see https://vueuse.org/useArrayFilter
  725. * @param list - the array was called upon.
  726. * @param fn - a function that is called for every element of the given `list`. Each time `fn` executes, the returned value is added to the new array.
  727. *
  728. * @returns a shallow copy of a portion of the given array, filtered down to just the elements from the given array that pass the test implemented by the provided function. If no elements pass the test, an empty array will be returned.
  729. */
  730. declare function useArrayFilter<T, S extends T>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, fn: (element: T, index: number, array: T[]) => element is S): ComputedRef<S[]>;
  731. declare function useArrayFilter<T>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, fn: (element: T, index: number, array: T[]) => unknown): ComputedRef<T[]>;
  732. /**
  733. * Reactive `Array.find`
  734. *
  735. * @see https://vueuse.org/useArrayFind
  736. * @param list - the array was called upon.
  737. * @param fn - a function to test each element.
  738. *
  739. * @returns the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
  740. */
  741. declare function useArrayFind<T>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, fn: (element: T, index: number, array: MaybeRefOrGetter<T>[]) => boolean): ComputedRef<T | undefined>;
  742. /**
  743. * Reactive `Array.findIndex`
  744. *
  745. * @see https://vueuse.org/useArrayFindIndex
  746. * @param list - the array was called upon.
  747. * @param fn - a function to test each element.
  748. *
  749. * @returns the index of the first element in the array that passes the test. Otherwise, "-1".
  750. */
  751. declare function useArrayFindIndex<T>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, fn: (element: T, index: number, array: MaybeRefOrGetter<T>[]) => unknown): ComputedRef<number>;
  752. /**
  753. * Reactive `Array.findLast`
  754. *
  755. * @see https://vueuse.org/useArrayFindLast
  756. * @param list - the array was called upon.
  757. * @param fn - a function to test each element.
  758. *
  759. * @returns the last element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
  760. */
  761. declare function useArrayFindLast<T>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, fn: (element: T, index: number, array: MaybeRefOrGetter<T>[]) => boolean): ComputedRef<T | undefined>;
  762. type UseArrayIncludesComparatorFn<T, V> = ((element: T, value: V, index: number, array: MaybeRefOrGetter<T>[]) => boolean);
  763. interface UseArrayIncludesOptions<T, V> {
  764. fromIndex?: number;
  765. comparator?: UseArrayIncludesComparatorFn<T, V> | keyof T;
  766. }
  767. /**
  768. * Reactive `Array.includes`
  769. *
  770. * @see https://vueuse.org/useArrayIncludes
  771. *
  772. * @returns true if the `value` is found in the array. Otherwise, false.
  773. */
  774. declare function useArrayIncludes<T, V = any>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, value: MaybeRefOrGetter<V>, comparator?: UseArrayIncludesComparatorFn<T, V>): ComputedRef<boolean>;
  775. declare function useArrayIncludes<T, V = any>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, value: MaybeRefOrGetter<V>, comparator?: keyof T): ComputedRef<boolean>;
  776. declare function useArrayIncludes<T, V = any>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, value: MaybeRefOrGetter<V>, options?: UseArrayIncludesOptions<T, V>): ComputedRef<boolean>;
  777. /**
  778. * Reactive `Array.join`
  779. *
  780. * @see https://vueuse.org/useArrayJoin
  781. * @param list - the array was called upon.
  782. * @param separator - a string to separate each pair of adjacent elements of the array. If omitted, the array elements are separated with a comma (",").
  783. *
  784. * @returns a string with all array elements joined. If arr.length is 0, the empty string is returned.
  785. */
  786. declare function useArrayJoin(list: MaybeRefOrGetter<MaybeRefOrGetter<any>[]>, separator?: MaybeRefOrGetter<string>): ComputedRef<string>;
  787. /**
  788. * Reactive `Array.map`
  789. *
  790. * @see https://vueuse.org/useArrayMap
  791. * @param list - the array was called upon.
  792. * @param fn - a function that is called for every element of the given `list`. Each time `fn` executes, the returned value is added to the new array.
  793. *
  794. * @returns a new array with each element being the result of the callback function.
  795. */
  796. declare function useArrayMap<T, U = T>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, fn: (element: T, index: number, array: T[]) => U): ComputedRef<U[]>;
  797. type UseArrayReducer<PV, CV, R> = (previousValue: PV, currentValue: CV, currentIndex: number) => R;
  798. /**
  799. * Reactive `Array.reduce`
  800. *
  801. * @see https://vueuse.org/useArrayReduce
  802. * @param list - the array was called upon.
  803. * @param reducer - a "reducer" function.
  804. *
  805. * @returns the value that results from running the "reducer" callback function to completion over the entire array.
  806. */
  807. declare function useArrayReduce<T>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, reducer: UseArrayReducer<T, T, T>): ComputedRef<T>;
  808. /**
  809. * Reactive `Array.reduce`
  810. *
  811. * @see https://vueuse.org/useArrayReduce
  812. * @param list - the array was called upon.
  813. * @param reducer - a "reducer" function.
  814. * @param initialValue - a value to be initialized the first time when the callback is called.
  815. *
  816. * @returns the value that results from running the "reducer" callback function to completion over the entire array.
  817. */
  818. declare function useArrayReduce<T, U>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, reducer: UseArrayReducer<U, T, U>, initialValue: MaybeRefOrGetter<U>): ComputedRef<U>;
  819. /**
  820. * Reactive `Array.some`
  821. *
  822. * @see https://vueuse.org/useArraySome
  823. * @param list - the array was called upon.
  824. * @param fn - a function to test each element.
  825. *
  826. * @returns **true** if the `fn` function returns a **truthy** value for any element from the array. Otherwise, **false**.
  827. */
  828. declare function useArraySome<T>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, fn: (element: T, index: number, array: MaybeRefOrGetter<T>[]) => unknown): ComputedRef<boolean>;
  829. /**
  830. * reactive unique array
  831. * @see https://vueuse.org/useArrayUnique
  832. * @param list - the array was called upon.
  833. * @param compareFn
  834. * @returns A computed ref that returns a unique array of items.
  835. */
  836. declare function useArrayUnique<T>(list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>, compareFn?: (a: T, b: T, array: T[]) => boolean): ComputedRef<T[]>;
  837. interface UseCounterOptions {
  838. min?: number;
  839. max?: number;
  840. }
  841. /**
  842. * Basic counter with utility functions.
  843. *
  844. * @see https://vueuse.org/useCounter
  845. * @param [initialValue]
  846. * @param options
  847. */
  848. declare function useCounter(initialValue?: MaybeRef<number>, options?: UseCounterOptions): {
  849. count: vue.Ref<number, MaybeRef<number>>;
  850. inc: (delta?: number) => number;
  851. dec: (delta?: number) => number;
  852. get: () => number;
  853. set: (val: number) => number;
  854. reset: (val?: number) => number;
  855. };
  856. type DateLike = Date | number | string | undefined;
  857. interface UseDateFormatOptions {
  858. /**
  859. * The locale(s) to used for dd/ddd/dddd/MMM/MMMM format
  860. *
  861. * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument).
  862. */
  863. locales?: MaybeRefOrGetter<Intl.LocalesArgument>;
  864. /**
  865. * A custom function to re-modify the way to display meridiem
  866. *
  867. */
  868. customMeridiem?: (hours: number, minutes: number, isLowercase?: boolean, hasPeriod?: boolean) => string;
  869. }
  870. declare function formatDate(date: Date, formatStr: string, options?: UseDateFormatOptions): string;
  871. declare function normalizeDate(date: DateLike): Date;
  872. /**
  873. * Get the formatted date according to the string of tokens passed in.
  874. *
  875. * @see https://vueuse.org/useDateFormat
  876. * @param date - The date to format, can either be a `Date` object, a timestamp, or a string
  877. * @param formatStr - The combination of tokens to format the date
  878. * @param options - UseDateFormatOptions
  879. */
  880. declare function useDateFormat(date: MaybeRefOrGetter<DateLike>, formatStr?: MaybeRefOrGetter<string>, options?: UseDateFormatOptions): vue.ComputedRef<string>;
  881. type UseDateFormatReturn = ReturnType<typeof useDateFormat>;
  882. /**
  883. * Debounce execution of a function.
  884. *
  885. * @see https://vueuse.org/useDebounceFn
  886. * @param fn A function to be executed after delay milliseconds debounced.
  887. * @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
  888. * @param options Options
  889. *
  890. * @return A new, debounce, function.
  891. */
  892. declare function useDebounceFn<T extends FunctionArgs>(fn: T, ms?: MaybeRefOrGetter<number>, options?: DebounceFilterOptions): PromisifyFn<T>;
  893. interface UseIntervalOptions<Controls extends boolean> {
  894. /**
  895. * Expose more controls
  896. *
  897. * @default false
  898. */
  899. controls?: Controls;
  900. /**
  901. * Execute the update immediately on calling
  902. *
  903. * @default true
  904. */
  905. immediate?: boolean;
  906. /**
  907. * Callback on every interval
  908. */
  909. callback?: (count: number) => void;
  910. }
  911. interface UseIntervalControls {
  912. counter: Ref<number>;
  913. reset: () => void;
  914. }
  915. /**
  916. * Reactive counter increases on every interval
  917. *
  918. * @see https://vueuse.org/useInterval
  919. * @param interval
  920. * @param options
  921. */
  922. declare function useInterval(interval?: MaybeRefOrGetter<number>, options?: UseIntervalOptions<false>): Ref<number>;
  923. declare function useInterval(interval: MaybeRefOrGetter<number>, options: UseIntervalOptions<true>): UseIntervalControls & Pausable;
  924. interface UseIntervalFnOptions {
  925. /**
  926. * Start the timer immediately
  927. *
  928. * @default true
  929. */
  930. immediate?: boolean;
  931. /**
  932. * Execute the callback immediately after calling `resume`
  933. *
  934. * @default false
  935. */
  936. immediateCallback?: boolean;
  937. }
  938. /**
  939. * Wrapper for `setInterval` with controls
  940. *
  941. * @param cb
  942. * @param interval
  943. * @param options
  944. */
  945. declare function useIntervalFn(cb: Fn, interval?: MaybeRefOrGetter<number>, options?: UseIntervalFnOptions): Pausable;
  946. interface UseLastChangedOptions<Immediate extends boolean, InitialValue extends number | null | undefined = undefined> extends WatchOptions<Immediate> {
  947. initialValue?: InitialValue;
  948. }
  949. /**
  950. * Records the timestamp of the last change
  951. *
  952. * @see https://vueuse.org/useLastChanged
  953. */
  954. declare function useLastChanged(source: WatchSource, options?: UseLastChangedOptions<false>): Ref<number | null>;
  955. declare function useLastChanged(source: WatchSource, options: UseLastChangedOptions<true> | UseLastChangedOptions<boolean, number>): Ref<number>;
  956. /**
  957. * Throttle execution of a function. Especially useful for rate limiting
  958. * execution of handlers on events like resize and scroll.
  959. *
  960. * @param fn A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
  961. * to `callback` when the throttled-function is executed.
  962. * @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
  963. * (default value: 200)
  964. *
  965. * @param [trailing] if true, call fn again after the time is up (default value: false)
  966. *
  967. * @param [leading] if true, call fn on the leading edge of the ms timeout (default value: true)
  968. *
  969. * @param [rejectOnCancel] if true, reject the last call if it's been cancel (default value: false)
  970. *
  971. * @return A new, throttled, function.
  972. */
  973. declare function useThrottleFn<T extends FunctionArgs>(fn: T, ms?: MaybeRefOrGetter<number>, trailing?: boolean, leading?: boolean, rejectOnCancel?: boolean): PromisifyFn<T>;
  974. interface UseTimeoutFnOptions {
  975. /**
  976. * Start the timer immediate after calling this function
  977. *
  978. * @default true
  979. */
  980. immediate?: boolean;
  981. }
  982. /**
  983. * Wrapper for `setTimeout` with controls.
  984. *
  985. * @param cb
  986. * @param interval
  987. * @param options
  988. */
  989. declare function useTimeoutFn<CallbackFn extends AnyFn>(cb: CallbackFn, interval: MaybeRefOrGetter<number>, options?: UseTimeoutFnOptions): Stoppable<Parameters<CallbackFn> | []>;
  990. interface UseTimeoutOptions<Controls extends boolean> extends UseTimeoutFnOptions {
  991. /**
  992. * Expose more controls
  993. *
  994. * @default false
  995. */
  996. controls?: Controls;
  997. /**
  998. * Callback on timeout
  999. */
  1000. callback?: Fn;
  1001. }
  1002. /**
  1003. * Update value after a given time with controls.
  1004. *
  1005. * @see {@link https://vueuse.org/useTimeout}
  1006. * @param interval
  1007. * @param options
  1008. */
  1009. declare function useTimeout(interval?: MaybeRefOrGetter<number>, options?: UseTimeoutOptions<false>): ComputedRef<boolean>;
  1010. declare function useTimeout(interval: MaybeRefOrGetter<number>, options: UseTimeoutOptions<true>): {
  1011. ready: ComputedRef<boolean>;
  1012. } & Stoppable;
  1013. interface UseToNumberOptions {
  1014. /**
  1015. * Method to use to convert the value to a number.
  1016. *
  1017. * @default 'parseFloat'
  1018. */
  1019. method?: 'parseFloat' | 'parseInt';
  1020. /**
  1021. * The base in mathematical numeral systems passed to `parseInt`.
  1022. * Only works with `method: 'parseInt'`
  1023. */
  1024. radix?: number;
  1025. /**
  1026. * Replace NaN with zero
  1027. *
  1028. * @default false
  1029. */
  1030. nanToZero?: boolean;
  1031. }
  1032. /**
  1033. * Reactively convert a string ref to number.
  1034. */
  1035. declare function useToNumber(value: MaybeRefOrGetter<number | string>, options?: UseToNumberOptions): ComputedRef<number>;
  1036. /**
  1037. * Reactively convert a ref to string.
  1038. *
  1039. * @see https://vueuse.org/useToString
  1040. */
  1041. declare function useToString(value: MaybeRefOrGetter<unknown>): ComputedRef<string>;
  1042. interface UseToggleOptions<Truthy, Falsy> {
  1043. truthyValue?: MaybeRefOrGetter<Truthy>;
  1044. falsyValue?: MaybeRefOrGetter<Falsy>;
  1045. }
  1046. declare function useToggle<Truthy, Falsy, T = Truthy | Falsy>(initialValue: Ref<T>, options?: UseToggleOptions<Truthy, Falsy>): (value?: T) => T;
  1047. declare function useToggle<Truthy = true, Falsy = false, T = Truthy | Falsy>(initialValue?: T, options?: UseToggleOptions<Truthy, Falsy>): [Ref<T>, (value?: T) => T];
  1048. declare type WatchArrayCallback<V = any, OV = any> = (value: V, oldValue: OV, added: V, removed: OV, onCleanup: (cleanupFn: () => void) => void) => any;
  1049. /**
  1050. * Watch for an array with additions and removals.
  1051. *
  1052. * @see https://vueuse.org/watchArray
  1053. */
  1054. declare function watchArray<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T[]> | T[], cb: WatchArrayCallback<T[], Immediate extends true ? T[] | undefined : T[]>, options?: WatchOptions<Immediate>): vue.WatchHandle;
  1055. interface WatchWithFilterOptions<Immediate> extends WatchOptions<Immediate>, ConfigurableEventFilter {
  1056. }
  1057. declare function watchWithFilter<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(sources: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchWithFilterOptions<Immediate>): WatchStopHandle;
  1058. declare function watchWithFilter<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): WatchStopHandle;
  1059. declare function watchWithFilter<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): WatchStopHandle;
  1060. interface WatchAtMostOptions<Immediate> extends WatchWithFilterOptions<Immediate> {
  1061. count: MaybeRefOrGetter<number>;
  1062. }
  1063. interface WatchAtMostReturn {
  1064. stop: WatchStopHandle;
  1065. count: Ref<number>;
  1066. }
  1067. declare function watchAtMost<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(sources: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options: WatchAtMostOptions<Immediate>): WatchAtMostReturn;
  1068. declare function watchAtMost<T, Immediate extends Readonly<boolean> = false>(sources: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options: WatchAtMostOptions<Immediate>): WatchAtMostReturn;
  1069. interface WatchDebouncedOptions<Immediate> extends WatchOptions<Immediate>, DebounceFilterOptions {
  1070. debounce?: MaybeRefOrGetter<number>;
  1071. }
  1072. declare function watchDebounced<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(sources: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchDebouncedOptions<Immediate>): WatchStopHandle;
  1073. declare function watchDebounced<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchDebouncedOptions<Immediate>): WatchStopHandle;
  1074. declare function watchDebounced<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchDebouncedOptions<Immediate>): WatchStopHandle;
  1075. declare function watchDeep<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(source: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: Omit<WatchOptions<Immediate>, 'deep'>): WatchStopHandle;
  1076. declare function watchDeep<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: Omit<WatchOptions<Immediate>, 'deep'>): WatchStopHandle;
  1077. declare function watchDeep<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: Omit<WatchOptions<Immediate>, 'deep'>): WatchStopHandle;
  1078. type IgnoredUpdater = (updater: () => void) => void;
  1079. interface WatchIgnorableReturn {
  1080. ignoreUpdates: IgnoredUpdater;
  1081. ignorePrevAsyncUpdates: () => void;
  1082. stop: WatchStopHandle;
  1083. }
  1084. declare function watchIgnorable<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(sources: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchWithFilterOptions<Immediate>): WatchIgnorableReturn;
  1085. declare function watchIgnorable<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): WatchIgnorableReturn;
  1086. declare function watchIgnorable<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): WatchIgnorableReturn;
  1087. declare function watchImmediate<T extends Readonly<WatchSource<unknown>[]>>(source: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, true>>, options?: Omit<WatchOptions<true>, 'immediate'>): WatchStopHandle;
  1088. declare function watchImmediate<T>(source: WatchSource<T>, cb: WatchCallback<T, T | undefined>, options?: Omit<WatchOptions<true>, 'immediate'>): WatchStopHandle;
  1089. declare function watchImmediate<T extends object>(source: T, cb: WatchCallback<T, T | undefined>, options?: Omit<WatchOptions<true>, 'immediate'>): WatchStopHandle;
  1090. declare function watchOnce<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(source: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchOptions<Immediate>): WatchStopHandle;
  1091. declare function watchOnce<T, Immediate extends Readonly<boolean> = false>(sources: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchOptions<Immediate>): WatchStopHandle;
  1092. interface WatchPausableReturn extends Pausable {
  1093. stop: WatchStopHandle;
  1094. }
  1095. declare function watchPausable<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(sources: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchWithFilterOptions<Immediate>): WatchPausableReturn;
  1096. declare function watchPausable<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): WatchPausableReturn;
  1097. declare function watchPausable<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchWithFilterOptions<Immediate>): WatchPausableReturn;
  1098. interface WatchThrottledOptions<Immediate> extends WatchOptions<Immediate> {
  1099. throttle?: MaybeRefOrGetter<number>;
  1100. trailing?: boolean;
  1101. leading?: boolean;
  1102. }
  1103. declare function watchThrottled<T extends Readonly<WatchSource<unknown>[]>, Immediate extends Readonly<boolean> = false>(sources: [...T], cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>, options?: WatchThrottledOptions<Immediate>): WatchStopHandle;
  1104. declare function watchThrottled<T, Immediate extends Readonly<boolean> = false>(source: WatchSource<T>, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchThrottledOptions<Immediate>): WatchStopHandle;
  1105. declare function watchThrottled<T extends object, Immediate extends Readonly<boolean> = false>(source: T, cb: WatchCallback<T, Immediate extends true ? T | undefined : T>, options?: WatchThrottledOptions<Immediate>): WatchStopHandle;
  1106. interface WatchTriggerableReturn<FnReturnT = void> extends WatchIgnorableReturn {
  1107. /** Execute `WatchCallback` immediately */
  1108. trigger: () => FnReturnT;
  1109. }
  1110. type OnCleanup = (cleanupFn: () => void) => void;
  1111. type WatchTriggerableCallback<V = any, OV = any, R = void> = (value: V, oldValue: OV, onCleanup: OnCleanup) => R;
  1112. declare function watchTriggerable<T extends Readonly<WatchSource<unknown>[]>, FnReturnT>(sources: [...T], cb: WatchTriggerableCallback<MapSources<T>, MapOldSources<T, true>, FnReturnT>, options?: WatchWithFilterOptions<boolean>): WatchTriggerableReturn<FnReturnT>;
  1113. declare function watchTriggerable<T, FnReturnT>(source: WatchSource<T>, cb: WatchTriggerableCallback<T, T | undefined, FnReturnT>, options?: WatchWithFilterOptions<boolean>): WatchTriggerableReturn<FnReturnT>;
  1114. declare function watchTriggerable<T extends object, FnReturnT>(source: T, cb: WatchTriggerableCallback<T, T | undefined, FnReturnT>, options?: WatchWithFilterOptions<boolean>): WatchTriggerableReturn<FnReturnT>;
  1115. interface WheneverOptions extends WatchOptions {
  1116. /**
  1117. * Only trigger once when the condition is met
  1118. *
  1119. * Override the `once` option in `WatchOptions`
  1120. *
  1121. * @default false
  1122. */
  1123. once?: boolean;
  1124. }
  1125. /**
  1126. * Shorthand for watching value to be truthy
  1127. *
  1128. * @see https://vueuse.org/whenever
  1129. */
  1130. declare function whenever<T>(source: WatchSource<T | false | null | undefined>, cb: WatchCallback<T>, options?: WheneverOptions): vue.WatchHandle;
  1131. export { type AnyFn, type ArgumentsType, type Arrayable, type Awaitable, type Awaited, type ComputedRefWithControl, type ComputedWithControlRefExtra, type ConfigurableEventFilter, type ConfigurableFlush, type ConfigurableFlushSync, type ControlledRefOptions, type CreateInjectionStateOptions, type DateLike, type DebounceFilterOptions, type DeepMaybeRef, type ElementOf, type EventFilter, type EventHook, type EventHookOff, type EventHookOn, type EventHookTrigger, type ExtendRefOptions, type Fn, type FunctionArgs, type FunctionWrapperOptions, type IfAny, type IgnoredUpdater, type IsAny, type MapOldSources, type MapSources, type MultiWatchSources, type Mutable, type Pausable, type Promisify, type PromisifyFn, type Reactified, type ReactifyNested, type ReactifyObjectOptions, type ReactifyOptions, type ReactiveOmitPredicate, type ReactivePickPredicate, type ReadonlyRefOrGetter, type RemovableRef, type ShallowUnwrapRef, type SingletonPromiseReturn, type Stoppable, type SyncRefOptions, type SyncRefsOptions, type ThrottleFilterOptions, type ToRefsOptions, type UntilArrayInstance, type UntilBaseInstance, type UntilToMatchOptions, type UntilValueInstance, type UseArrayIncludesComparatorFn, type UseArrayIncludesOptions, type UseArrayReducer, type UseCounterOptions, type UseDateFormatOptions, type UseDateFormatReturn, type UseIntervalControls, type UseIntervalFnOptions, type UseIntervalOptions, type UseLastChangedOptions, type UseTimeoutFnOptions, type UseTimeoutOptions, type UseToNumberOptions, type UseToggleOptions, type WatchArrayCallback, type WatchAtMostOptions, type WatchAtMostReturn, type WatchDebouncedOptions, type WatchIgnorableReturn, type WatchPausableReturn, type WatchThrottledOptions, type WatchTriggerableCallback, type WatchTriggerableReturn, type WatchWithFilterOptions, type WheneverOptions, type WritableComputedRefWithControl, assert, refAutoReset as autoResetRef, bypassFilter, camelize, clamp, computedEager, computedWithControl, containsProp, computedWithControl as controlledComputed, controlledRef, createEventHook, createFilterWrapper, createGlobalState, createInjectionState, reactify as createReactiveFn, createSharedComposable, createSingletonPromise, debounceFilter, refDebounced as debouncedRef, watchDebounced as debouncedWatch, computedEager as eagerComputed, extendRef, formatDate, get, getLifeCycleTarget, hasOwn, hyphenate, identity, watchIgnorable as ignorableWatch, increaseWithUnit, injectLocal, invoke, isClient, isDef, isDefined, isIOS, isObject, isWorker, makeDestructurable, noop, normalizeDate, notNullish, now, objectEntries, objectOmit, objectPick, pausableFilter, watchPausable as pausableWatch, promiseTimeout, provideLocal, rand, reactify, reactifyObject, reactiveComputed, reactiveOmit, reactivePick, refAutoReset, refDebounced, refDefault, refThrottled, refWithControl, resolveRef, resolveUnref, set, syncRef, syncRefs, throttleFilter, refThrottled as throttledRef, watchThrottled as throttledWatch, timestamp, toReactive, toRef, toRefs, toValue, tryOnBeforeMount, tryOnBeforeUnmount, tryOnMounted, tryOnScopeDispose, tryOnUnmounted, until, useArrayDifference, useArrayEvery, useArrayFilter, useArrayFind, useArrayFindIndex, useArrayFindLast, useArrayIncludes, useArrayJoin, useArrayMap, useArrayReduce, useArraySome, useArrayUnique, useCounter, useDateFormat, refDebounced as useDebounce, useDebounceFn, useInterval, useIntervalFn, useLastChanged, refThrottled as useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useToNumber, useToString, useToggle, watchArray, watchAtMost, watchDebounced, watchDeep, watchIgnorable, watchImmediate, watchOnce, watchPausable, watchThrottled, watchTriggerable, watchWithFilter, whenever };