UNPKG

@reactive-vscode/vueuse

Version:

Useful VueUse utilities for VSCode extension development

1,375 lines (1,122 loc) 114 kB
import { ComponentInternalInstance } from '@reactive-vscode/reactivity'; import { ComputedGetter } from '@reactive-vscode/reactivity'; import { ComputedRef } from '@reactive-vscode/reactivity'; import { getCurrentInstance } from '@reactive-vscode/reactivity'; import { inject } from '@reactive-vscode/reactivity'; import { InjectionKey } from '@reactive-vscode/reactivity'; import { MaybeRef } from '@reactive-vscode/reactivity'; import { MaybeRefOrGetter } from '@reactive-vscode/reactivity'; import { MultiWatchSources } from '@reactive-vscode/reactivity'; import { Ref } from '@reactive-vscode/reactivity'; import { ShallowRef } from '@reactive-vscode/reactivity'; import { ShallowUnwrapRef as ShallowUnwrapRef_2 } from '@reactive-vscode/reactivity'; import { ToRef } from '@reactive-vscode/reactivity'; import { ToRefs } from '@reactive-vscode/reactivity'; import { UnwrapNestedRefs } from '@reactive-vscode/reactivity'; import { UnwrapRef } from '@reactive-vscode/reactivity'; import * as vue0 from '@reactive-vscode/reactivity'; import { WatchCallback } from '@reactive-vscode/reactivity'; import { WatchHandle } from '@reactive-vscode/reactivity'; import { WatchOptions } from '@reactive-vscode/reactivity'; import { WatchOptionsBase } from '@reactive-vscode/reactivity'; import { WatchSource } from '@reactive-vscode/reactivity'; import { WatchStopHandle } from '@reactive-vscode/reactivity'; import { WritableComputedOptions } from '@reactive-vscode/reactivity'; import { WritableComputedRef } from '@reactive-vscode/reactivity'; export declare interface AfterFetchContext<T = any> { response: Response; data: T | null; context: BeforeFetchContext; execute: (throwOnFailed?: boolean) => Promise<any>; } /** * Any function */ export declare type AnyFn = (...args: any[]) => any; export declare type ArgumentsType<T$1> = T$1 extends ((...args: infer U) => any) ? U : never; export declare type Arrayable<T$1> = T$1[] | T$1; export declare const assert: (condition: boolean, ...infos: any[]) => void; /** @deprecated use `computedAsync` instead */ export declare const asyncComputed: typeof computedAsync; /** * Handle overlapping async evaluations. * * @param cancelCallback The provided callback is invoked when a re-evaluation of the computed value is triggered before the previous one finished */ export declare type AsyncComputedOnCancel = (cancelCallback: Fn) => void; export declare interface AsyncComputedOptions<Lazy = boolean> { /** * Should value be evaluated lazily * * @default false */ lazy?: Lazy; /** * Ref passed to receive the updated of async evaluation */ evaluating?: Ref<boolean>; /** * Use shallowRef * * @default true */ shallow?: boolean; /** * The flush option allows for greater control over the timing of a history point, default to `pre` * * Possible values: `pre`, `post`, `sync` * * It works in the same way as the flush option in watch and watch effect in vue reactivity * @default 'sync' */ flush?: WatchOptionFlush; /** * Callback when error is caught. */ onError?: (e: unknown) => void; } /** @deprecated use `refAutoReset` instead */ export declare const autoResetRef: typeof refAutoReset; export declare type Awaitable<T$1> = Promise<T$1> | T$1; /** * Compatible with versions below TypeScript 4.5 Awaited */ declare type Awaited_2<T$1> = T$1 extends null | undefined ? T$1 : T$1 extends object & { then: (onfulfilled: infer F, ...args: infer _) => any; } ? F extends ((value: infer V, ...args: infer _) => any) ? Awaited_2<V> : never : T$1; export { Awaited_2 as Awaited } export declare interface BeforeFetchContext { /** * The computed url of the current request */ url: string; /** * The request options of the current request */ options: RequestInit; /** * Cancels the current request */ cancel: Fn; } declare interface BrowserLocationState { readonly trigger: string; readonly state?: any; readonly length?: number; readonly origin?: string; hash?: string; host?: string; hostname?: string; href?: string; pathname?: string; port?: string; protocol?: string; search?: string; } export declare const bypassFilter: EventFilter; declare type Callback<T$1> = IsAny<T$1> extends true ? (...param: any) => void : ([T$1] extends [void] ? (...param: unknown[]) => void : [T$1] extends [any[]] ? (...param: T$1) => void : (...param: [T$1, ...unknown[]]) => void); export declare const camelize: (str: string) => string; export declare const clamp: (n: number, min: number, max: number) => number; export declare type CloneFn<F, T = F> = (x: F) => T; export declare function cloneFnJSON<T>(source: T): T; declare type Combination = 'overwrite' | 'chain'; /** * Create an asynchronous computed dependency. * * @see https://vueuse.org/computedAsync * @param evaluationCallback The promise-returning callback which generates the computed value * @param initialState The initial state, used until the first evaluation finishes * @param optionsOrRef Additional options or a ref passed to receive the updates of the async evaluation */ export declare function computedAsync<T>(evaluationCallback: (onCancel: AsyncComputedOnCancel) => T | Promise<T>, initialState: T, optionsOrRef: AsyncComputedOptions<true>): ComputedRef<T>; export declare function computedAsync<T>(evaluationCallback: (onCancel: AsyncComputedOnCancel) => T | Promise<T>, initialState: undefined, optionsOrRef: AsyncComputedOptions<true>): ComputedRef<T | undefined>; export declare function computedAsync<T>(evaluationCallback: (onCancel: AsyncComputedOnCancel) => T | Promise<T>, initialState: T, optionsOrRef?: Ref<boolean> | AsyncComputedOptions): Ref<T>; export declare function computedAsync<T>(evaluationCallback: (onCancel: AsyncComputedOnCancel) => T | Promise<T>, initialState?: undefined, optionsOrRef?: Ref<boolean> | AsyncComputedOptions): Ref<T | undefined>; /** * * @deprecated This function will be removed in future version. * * Note: If you are using Vue 3.4+, you can straight use computed instead. * Because in Vue 3.4+, if computed new value does not change, * computed, effect, watch, watchEffect, render dependencies will not be triggered. * refer: https://github.com/vuejs/core/pull/5912 * * @param fn effect function * @param options WatchOptionsBase * @returns readonly shallowRef */ export declare function computedEager<T$1>(fn: () => T$1, options?: ComputedEagerOptions): ComputedEagerReturn<T$1>; export declare type ComputedEagerOptions = WatchOptionsBase; export declare type ComputedEagerReturn<T$1 = any> = Readonly<ShallowRef<T$1>>; declare type ComputedInjectGetter<T, K$1> = (source: T | undefined, oldValue?: K$1) => K$1; declare type ComputedInjectGetterWithDefault<T, K$1> = (source: T, oldValue?: K$1) => K$1; declare type ComputedInjectSetter<T> = (v: T) => void; export declare interface ComputedRefWithControl<T$1> extends ComputedRef<T$1>, ComputedWithControlRefExtra {} export declare function computedWithControl<T$1>(source: WatchSource | MultiWatchSources, fn: ComputedGetter<T$1>, options?: WatchOptions): ComputedRefWithControl<T$1>; export declare function computedWithControl<T$1>(source: WatchSource | MultiWatchSources, fn: WritableComputedOptions<T$1>, options?: WatchOptions): WritableComputedRefWithControl<T$1>; export declare type ComputedWithControlRef<T$1 = any> = ComputedRefWithControl<T$1> | WritableComputedRefWithControl<T$1>; export declare interface ComputedWithControlRefExtra { /** * Force update the computed value. */ trigger: () => void; } declare interface ConfigurableDeepRefs<D extends boolean> { /** * Return deep refs instead of shallow refs. * * @default true - will be changed to `false` by default in the next major */ deepRefs?: D; } export declare interface ConfigurableEventFilter { /** * Filter for if events should to be received. * * @see https://vueuse.org/guide/config.html#event-filters */ eventFilter?: EventFilter; } export declare interface ConfigurableFlush { /** * Timing for monitoring changes, refer to WatchOptions for more details * * @default 'pre' */ flush?: WatchOptionFlush; } export declare interface ConfigurableFlushSync { /** * Timing for monitoring changes, refer to WatchOptions for more details. * Unlike `watch()`, the default is set to `sync` * * @default 'sync' */ flush?: WatchOptionFlush; } declare interface ConfigurableNavigator { navigator?: Navigator; } declare interface ConfigurableWindow { window?: Window; } export declare function containsProp(obj: object, ...props: string[]): boolean; /** @deprecated use `computedWithControl` instead */ export declare const controlledComputed: typeof computedWithControl; /** @deprecated use `refWithControl` instead */ export declare const controlledRef: typeof refWithControl; export declare interface ControlledRefOptions<T$1> { /** * Callback function before the ref changing. * * Returning `false` to dismiss the change. */ onBeforeChange?: (value: T$1, oldValue: T$1) => void | boolean; /** * Callback function after the ref changed * * This happens synchronously, with less overhead compare to `watch` */ onChanged?: (value: T$1, oldValue: T$1) => void; } /** * Utility for creating event hooks * * @see https://vueuse.org/createEventHook * * @__NO_SIDE_EFFECTS__ */ export declare function createEventHook<T$1 = any>(): EventHookReturn<T$1>; export declare function createFetch(config?: CreateFetchOptions): typeof useFetch; export declare interface CreateFetchOptions { /** * The base URL that will be prefixed to all urls unless urls are absolute */ baseUrl?: MaybeRefOrGetter<string>; /** * Determine the inherit behavior for beforeFetch, afterFetch, onFetchError * @default 'chain' */ combination?: Combination; /** * Default Options for the useFetch function */ options?: UseFetchOptions; /** * Options for the fetch request */ fetchOptions?: RequestInit; } /* Excluded from this release type: createFilterWrapper */ /** * Keep states in the global scope to be reusable across Vue instances. * * @see https://vueuse.org/createGlobalState * @param stateFactory A factory function to create the state * * @__NO_SIDE_EFFECTS__ */ export declare function createGlobalState<Fn$1 extends AnyFn>(stateFactory: Fn$1): CreateGlobalStateReturn<Fn$1>; export declare type CreateGlobalStateReturn<Fn$1 extends AnyFn = AnyFn> = Fn$1; /** * Create global state that can be injected into components. * * @see https://vueuse.org/createInjectionState * * @__NO_SIDE_EFFECTS__ */ export declare function createInjectionState<Arguments extends Array<any>, Return>(composable: (...args: Arguments) => Return, options?: CreateInjectionStateOptions<Return>): CreateInjectionStateReturn<Arguments, Return>; export declare interface CreateInjectionStateOptions<Return> { /** * Custom injectionKey for InjectionState */ injectionKey?: string | InjectionKey<Return>; /** * Default value for the InjectionState */ defaultValue?: Return; } export declare type CreateInjectionStateReturn<Arguments extends Array<any>, Return> = Readonly<[ /** * Call this function in a provider component to create and provide the state. * * @param args Arguments passed to the composable * @returns The state returned by the composable */ useProvidingState: (...args: Arguments) => Return, /** * Call this function in a consumer component to inject the state. * * @returns The injected state, or `undefined` if not provided and no default value was set. */ useInjectedState: () => Return | undefined]>; /** @deprecated use `reactify` instead */ export declare const createReactiveFn: typeof reactify; /** * Returns a `deepRef` or `shallowRef` depending on the `deep` param. * * @example createRef(1) // ShallowRef<number> * @example createRef(1, false) // ShallowRef<number> * @example createRef(1, true) // Ref<number> * @example createRef("string") // ShallowRef<string> * @example createRef<"A"|"B">("A", true) // Ref<"A"|"B"> * * @param value * @param deep * @returns the `deepRef` or `shallowRef` * * @__NO_SIDE_EFFECTS__ */ export declare function createRef<T$1 = any, D extends boolean = false>(value: T$1, deep?: D): CreateRefReturn<T$1, D>; export declare type CreateRefReturn<T$1 = any, D extends boolean = false> = ShallowOrDeepRef<T$1, D>; /** * Make a composable function usable with multiple Vue instances. * * @see https://vueuse.org/createSharedComposable * * @__NO_SIDE_EFFECTS__ */ export declare function createSharedComposable<Fn$1 extends AnyFn>(composable: Fn$1): SharedComposableReturn<Fn$1>; /** * Create singleton promise function * * @example * ``` * const promise = createSingletonPromise(async () => { ... }) * * await promise() * await promise() // all of them will be bind to a single promise instance * await promise() // and be resolved together * ``` */ export declare function createSingletonPromise<T$1>(fn: () => Promise<T$1>): SingletonPromiseReturn<T$1>; /** * Make a plain function accepting ref and raw values as arguments. * Returns the same value the unconverted function returns, with proper typing. * * @__NO_SIDE_EFFECTS__ */ export declare function createUnrefFn<T extends Function>(fn: T): UnrefFn<T>; export declare type DateLike = Date | number | string | undefined; /** @deprecated use `refDebounced` instead */ export declare const debouncedRef: typeof refDebounced; /** @deprecated use `watchDebounced` instead */ export declare const debouncedWatch: typeof watchDebounced; /** * Create an EventFilter that debounce the events */ export declare function debounceFilter(ms: MaybeRefOrGetter<number>, options?: DebounceFilterOptions): EventFilter<any[], any, AnyFn>; export declare interface DebounceFilterOptions { /** * The maximum time allowed to be delayed before it's invoked. * In milliseconds. */ maxWait?: MaybeRefOrGetter<number>; /** * Whether to reject the last call if it's been cancel. * * @default false */ rejectOnCancel?: boolean; } /** * Make all the nested attributes of an object or array to MaybeRef<T> * * Good for accepting options that will be wrapped with `reactive` or `ref` * * ```ts * UnwrapRef<DeepMaybeRef<T>> === T * ``` */ export declare type DeepMaybeRef<T$1> = T$1 extends Ref<infer V> ? MaybeRef<V> : T$1 extends Array<any> | object ? { [K in keyof T$1]: DeepMaybeRef<T$1[K]> } : MaybeRef<T$1>; declare type Direction = 'ltr' | 'rtl' | 'both'; /** @deprecated use `computedEager` instead */ export declare const eagerComputed: typeof computedEager; /** * Infers the element type of an array */ export declare type ElementOf<T$1> = T$1 extends (infer E)[] ? E : never; /** * A = B */ declare type Equal<A$1, B> = [A$1] extends [B] ? ([B] extends [A$1] ? true : false) : false; declare interface EqualType<D extends Direction, L, R$1, O extends keyof Transform<L, R$1> = (D extends 'both' ? 'ltr' | 'rtl' : D)> { transform?: SpecificFieldPartial<Pick<Transform<L, R$1>, O>, O>; } export declare type EventBusEvents<T, P$1 = any> = Set<EventBusListener<T, P$1>>; export declare type EventBusIdentifier<T = unknown> = EventBusKey<T> | string | number; export declare interface EventBusKey<T> extends Symbol {} export declare type EventBusListener<T = unknown, P$1 = any> = (event: T, payload?: P$1) => void; export declare type EventFilter<Args extends any[] = any[], This = any, Invoke extends AnyFn = AnyFn> = (invoke: Invoke, options: FunctionWrapperOptions<Args, This>) => ReturnType<Invoke> | Promisify<ReturnType<Invoke>>; export declare interface EventHook<T$1 = any> { on: EventHookOn<T$1>; off: EventHookOff<T$1>; trigger: EventHookTrigger<T$1>; clear: () => void; } export declare type EventHookOff<T$1 = any> = (fn: Callback<T$1>) => void; export declare type EventHookOn<T$1 = any> = (fn: Callback<T$1>) => { off: () => void; }; export declare type EventHookReturn<T$1> = EventHook<T$1>; export declare type EventHookTrigger<T$1 = any> = (...param: Parameters<Callback<T$1>>) => Promise<unknown[]>; /** * Overload 1: Unwrap set to false */ export declare function extendRef<R$1 extends Ref<any>, Extend extends object, Options extends ExtendRefOptions<false>>(ref: R$1, extend: Extend, options?: Options): ShallowUnwrapRef_2<Extend> & R$1; /** * Overload 2: Unwrap unset or set to true */ export declare function extendRef<R$1 extends Ref<any>, Extend extends object, Options extends ExtendRefOptions>(ref: R$1, extend: Extend, options?: Options): Extend & R$1; export declare interface ExtendRefOptions<Unwrap extends boolean = boolean> { /** * Is the extends properties enumerable * * @default false */ enumerable?: boolean; /** * Unwrap for Ref properties * * @default true */ unwrap?: Unwrap; } export declare type ExtendRefReturn<T$1 = any> = Ref<T$1>; declare type Falsy = false | void | null | undefined | 0 | 0n | ''; /** * Void function */ export declare type Fn = () => void; export declare function formatDate(date: Date, formatStr: string, options?: UseDateFormatOptions): string; export declare function formatTimeAgo<UnitNames extends string = UseTimeAgoUnitNamesDefault>(from: Date, options?: FormatTimeAgoOptions<UnitNames>, now?: Date | number): string; export declare interface FormatTimeAgoOptions<UnitNames extends string = UseTimeAgoUnitNamesDefault> { /** * Maximum unit (of diff in milliseconds) to display the full date instead of relative * * @default undefined */ max?: UnitNames | number; /** * Formatter for full date */ fullDateFormatter?: (date: Date) => string; /** * Messages for formatting the string */ messages?: UseTimeAgoMessages<UnitNames>; /** * Minimum display time unit (default is minute) * * @default false */ showSecond?: boolean; /** * Rounding method to apply. * * @default 'round' */ rounding?: 'round' | 'ceil' | 'floor' | number; /** * Custom units */ units?: UseTimeAgoUnit<UnitNames>[]; } export declare type FunctionArgs<Args extends any[] = any[], Return = unknown> = (...args: Args) => Return; export declare interface FunctionWrapperOptions<Args extends any[] = any[], This = any> { fn: FunctionArgs<Args, This>; args: Args; thisArg: This; } export declare interface GeneralEventListener<E = Event> { (evt: E): void; } /** * Shorthand for accessing `ref.value` */ export declare function get<T$1>(ref: MaybeRef<T$1>): T$1; export declare function get<T$1, K$1 extends keyof T$1>(ref: MaybeRef<T$1>, key: K$1): T$1[K$1]; export declare function getLifeCycleTarget(target?: ComponentInternalInstance | null): ComponentInternalInstance | null; export declare const hasOwn: <T extends object, K extends keyof T>(val: T, key: K) => key is K; export declare const hyphenate: (str: string) => string; export declare function identity<T$1>(arg: T$1): T$1; export declare type IfAny<T$1, Y, N> = 0 extends (1 & T$1) ? Y : N; /** @deprecated use `watchIgnorable` instead */ export declare const ignorableWatch: typeof watchIgnorable; export declare type IgnoredPrevAsyncUpdates = () => void; export declare type IgnoredUpdater = (updater: () => void) => void; /** * A ⊆ B */ declare type IncludeButNotEqual<A$1, B> = Equal<A$1, B> extends true ? false : A$1 extends B ? true : false; /** * Increase string a value with unit * * @example '2px' + 1 = '3px' * @example '15em' + (-2) = '13em' */ export declare function increaseWithUnit(target: number, delta: number): number; export declare function increaseWithUnit(target: string, delta: number): string; export declare function increaseWithUnit(target: string | number, delta: number): string | number; /** * On the basis of `inject`, it is allowed to directly call inject to obtain the value after call provide in the same component. * * @example * ```ts * injectLocal('MyInjectionKey', 1) * const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1 * ``` * * @__NO_SIDE_EFFECTS__ */ export declare const injectLocal: typeof inject; export declare type InstanceProxy = NonNullable<NonNullable<ReturnType<typeof getCurrentInstance>>['proxy']>; /** * A ∩ B ≠ ∅ */ declare type IntersectButNotEqual<A$1, B> = Equal<A$1, B> extends true ? false : A$1 & B extends never ? false : true; declare type IntersectButNotEqualType<D extends Direction, L, R$1> = D extends 'both' ? { transform: Transform<L, R$1>; } : D extends Exclude<Direction, 'both'> ? { transform: Pick<Transform<L, R$1>, D>; } : never; export declare function invoke<T$1>(fn: () => T$1): T$1; /** * will return `true` if `T` is `any`, or `false` otherwise */ export declare type IsAny<T$1> = IfAny<T$1, true, false>; export declare const isDef: <T = any>(val?: T) => val is T; export declare function isDefined<T$1>(v: ComputedRef<T$1>): v is ComputedRef<Exclude<T$1, null | undefined>>; export declare function isDefined<T$1>(v: Ref<T$1>): v is Ref<Exclude<T$1, null | undefined>>; export declare function isDefined<T$1>(v: T$1): v is Exclude<T$1, null | undefined>; export declare type IsDefinedReturn = boolean; export declare const isObject: (val: any) => val is object; declare type LocalProvidedKey<T$1> = InjectionKey<T$1> | string | number; export declare function makeDestructurable<T$1 extends Record<string, unknown>, A$1 extends readonly any[]>(obj: T$1, arr: A$1): T$1 & A$1; /** * Define the shape of a ref that supports manual reset functionality. * * This interface extends the standard `Ref` type from Vue and adds a `reset` method. * The `reset` method allows the ref to be manually reset to its default value. */ export declare interface ManualResetRefReturn<T$1> extends Ref<T$1> { reset: Fn; } export declare type MapOldSources<T$1, Immediate> = { [K in keyof T$1]: T$1[K] extends WatchSource<infer V> ? Immediate extends true ? V | undefined : V : never }; declare type MapQueueTask<T extends any[]> = { [K in keyof T]: UseAsyncQueueTask<T[K]> }; export declare type MapSources<T$1> = { [K in keyof T$1]: T$1[K] extends WatchSource<infer V> ? V : never }; export { MultiWatchSources } export declare type Mutable<T$1> = { -readonly [P in keyof T$1]: T$1[P] }; export declare const noop: () => void; export declare function normalizeDate(date: DateLike): Date; /** * A ∩ B = ∅ */ declare type NotIntersect<A$1, B> = Equal<A$1, B> extends true ? false : A$1 & B extends never ? true : false; declare type NotIntersectType<D extends Direction, L, R$1> = IntersectButNotEqualType<D, L, R$1>; export declare const notNullish: <T = any>(val?: T | null | undefined) => val is T; export declare const now: () => number; export declare function objectEntries<T$1 extends object>(obj: T$1): Array<[keyof T$1, T$1[keyof T$1]]>; /** * Create a new subset object by omit giving keys */ export declare function objectOmit<O extends object, T$1 extends keyof O>(obj: O, keys: T$1[], omitUndefined?: boolean): Omit<O, T$1>; /** * Create a new subset object by giving keys */ export declare function objectPick<O extends object, T$1 extends keyof O>(obj: O, keys: T$1[], omitUndefined?: boolean): Pick<O, T$1>; declare type OnCleanup = (cleanupFn: () => void) => void; export declare interface OnFetchErrorContext<T = any, E = any> { error: E; data: T | null; response: Response | null; context: BeforeFetchContext; execute: (throwOnFailed?: boolean) => Promise<any>; } export declare interface Pausable { /** * A ref indicate whether a pausable instance is active */ readonly isActive: Readonly<ShallowRef<boolean>>; /** * Temporary pause the effect from executing */ pause: Fn; /** * Resume the effects */ resume: Fn; } /** * EventFilter that gives extra controls to pause and resume the filter * * @param extendFilter Extra filter to apply when the PausableFilter is active, default to none * @param options Options to configure the filter */ export declare function pausableFilter(extendFilter?: EventFilter, options?: PausableFilterOptions): Pausable & { eventFilter: EventFilter; }; export declare interface PausableFilterOptions { /** * The initial state * * @default 'active' */ initialState?: 'active' | 'paused'; } /** @deprecated use `watchPausable` instead */ export declare const pausableWatch: typeof watchPausable; declare type PostMessage = typeof Worker.prototype['postMessage']; export declare function promiseTimeout(ms: number, throwOnTimeout?: boolean, reason?: string): Promise<void>; export declare type Promisify<T$1> = Promise<Awaited_2<T$1>>; export declare type PromisifyFn<T$1 extends AnyFn> = (...args: ArgumentsType<T$1>) => Promisify<ReturnType<T$1>>; /** * On the basis of `provide`, it is allowed to directly call inject to obtain the value after call provide in the same component. * * @example * ```ts * provideLocal('MyInjectionKey', 1) * const injectedValue = injectLocal('MyInjectionKey') // injectedValue === 1 * ``` */ export declare function provideLocal<T$1, K$1 = LocalProvidedKey<T$1>>(key: K$1, value: K$1 extends InjectionKey<infer V> ? V : T$1): ProvideLocalReturn; export declare type ProvideLocalReturn = void; /** * Get a px value for SSR use, do not rely on this method outside of SSR as REM unit is assumed at 16px, which might not be the case on the client */ export declare function pxValue(px: string): number; export declare const rand: (min: number, max: number) => number; export declare type Reactified<T$1, Computed extends boolean> = T$1 extends ((...args: infer A) => infer R) ? (...args: { [K in keyof A]: Computed extends true ? MaybeRefOrGetter<A[K]> : MaybeRef<A[K]> }) => ComputedRef<R> : never; /** * Converts plain function into a reactive function. * The converted function accepts refs as it's arguments * and returns a ComputedRef, with proper typing. * * @param fn - Source function * @param options - Options * * @__NO_SIDE_EFFECTS__ */ export declare function reactify<T$1 extends AnyFn, K$1 extends boolean = true>(fn: T$1, options?: ReactifyOptions<K$1>): ReactifyReturn<T$1, K$1>; export declare type ReactifyNested<T$1, Keys extends keyof T$1 = keyof T$1, S$1 extends boolean = true> = { [K in Keys]: T$1[K] extends AnyFn ? Reactified<T$1[K], S$1> : T$1[K] }; /** * Apply `reactify` to an object * * @__NO_SIDE_EFFECTS__ */ export declare function reactifyObject<T$1 extends object, Keys extends keyof T$1>(obj: T$1, keys?: (keyof T$1)[]): ReactifyObjectReturn<T$1, Keys, true>; export declare function reactifyObject<T$1 extends object, S$1 extends boolean = true>(obj: T$1, options?: ReactifyObjectOptions<S$1>): ReactifyObjectReturn<T$1, keyof T$1, S$1>; export declare interface ReactifyObjectOptions<T$1 extends boolean> extends ReactifyOptions<T$1> { /** * Includes names from Object.getOwnPropertyNames * * @default true */ includeOwnProperties?: boolean; } export declare type ReactifyObjectReturn<T$1, Keys extends keyof T$1, S$1 extends boolean = true> = ReactifyNested<T$1, Keys, S$1>; export declare interface ReactifyOptions<T$1 extends boolean> { /** * Accept passing a function as a reactive getter * * @default true */ computedGetter?: T$1; } export declare type ReactifyReturn<T$1 extends AnyFn = AnyFn, K$1 extends boolean = true> = Reactified<T$1, K$1>; /** * Computed reactive object. */ export declare function reactiveComputed<T$1 extends object>(fn: ComputedGetter<T$1>): ReactiveComputedReturn<T$1>; export declare type ReactiveComputedReturn<T$1 extends object> = UnwrapNestedRefs<T$1>; export declare function reactiveOmit<T$1 extends object, K$1 extends keyof T$1>(obj: T$1, ...keys: (K$1 | K$1[])[]): ReactiveOmitReturn<T$1, K$1>; export declare function reactiveOmit<T$1 extends object>(obj: T$1, predicate: ReactiveOmitPredicate<T$1>): ReactiveOmitReturn<T$1>; export declare type ReactiveOmitPredicate<T$1> = (value: T$1[keyof T$1], key: keyof T$1) => boolean; export declare type ReactiveOmitReturn<T$1 extends object, K$1 extends keyof T$1 | undefined = undefined> = [K$1] extends [undefined] ? Partial<T$1> : Omit<T$1, Extract<K$1, keyof T$1>>; export declare function reactivePick<T$1 extends object, K$1 extends keyof T$1>(obj: T$1, ...keys: (K$1 | K$1[])[]): ReactivePickReturn<T$1, K$1>; export declare function reactivePick<T$1 extends object>(obj: T$1, predicate: ReactivePickPredicate<T$1>): ReactivePickReturn<T$1, keyof T$1>; export declare type ReactivePickPredicate<T$1> = (value: T$1[keyof T$1], key: keyof T$1) => boolean; export declare type ReactivePickReturn<T$1 extends object, K$1 extends keyof T$1> = { [S in K$1]: UnwrapRef<T$1[S]> }; /** * Maybe it's a computed ref, or a readonly value, or a getter function */ export declare type ReadonlyRefOrGetter<T$1> = ComputedRef<T$1> | (() => T$1); /** * Create a ref which will be reset to the default value after some time. * * @see https://vueuse.org/refAutoReset * @param defaultValue The value which will be set. * @param afterMs A zero-or-greater delay in milliseconds. */ export declare function refAutoReset<T$1>(defaultValue: MaybeRefOrGetter<T$1>, afterMs?: MaybeRefOrGetter<number>): RefAutoResetReturn<T$1>; export declare type RefAutoResetReturn<T$1 = any> = Ref<T$1>; /** * Debounce updates of a ref. * * @return A new debounced ref. */ export declare function refDebounced<T$1>(value: Ref<T$1>, ms?: MaybeRefOrGetter<number>, options?: DebounceFilterOptions): RefDebouncedReturn<T$1>; export declare type RefDebouncedReturn<T$1 = any> = Readonly<Ref<T$1>>; /** * Apply default value to a ref. * * @__NO_SIDE_EFFECTS__ */ export declare function refDefault<T$1>(source: Ref<T$1 | undefined | null>, defaultValue: T$1): Ref<T$1>; /** * Create a ref with manual reset functionality. * * @see https://vueuse.org/refManualReset * @param defaultValue The value which will be set. */ export declare function refManualReset<T$1>(defaultValue: MaybeRefOrGetter<T$1>): ManualResetRefReturn<T$1>; /** * Throttle execution of a function. Especially useful for rate limiting * execution of handlers on events like resize and scroll. * * @param value Ref value to be watched with throttle effect * @param delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful. * @param trailing if true, update the value again after the delay time is up * @param leading if true, update the value on the leading edge of the ms timeout */ export declare function refThrottled<T$1 = any>(value: Ref<T$1>, delay?: number, trailing?: boolean, leading?: boolean): RefThrottledReturn<T$1>; export declare type RefThrottledReturn<T$1 = any> = Ref<T$1>; /** * Fine-grained controls over ref and its reactivity. * * @__NO_SIDE_EFFECTS__ */ export declare function refWithControl<T$1>(initial: T$1, options?: ControlledRefOptions<T$1>): vue0.ShallowUnwrapRef<{ get: (tracking?: boolean) => T$1; set: (value: T$1, triggering?: boolean) => void; untrackedGet: () => T$1; silentSet: (v: T$1) => void; peek: () => T$1; lay: (v: T$1) => void; }> & vue0.Ref<T$1, T$1>; /** * A ref that allow to set null or undefined */ export declare type RemovableRef<T$1> = Ref<T$1, T$1 | null | undefined>; export declare interface Serializer<T> { read: (raw: string) => T; write: (value: T) => string; } export declare interface SerializerAsync<T> { read: (raw: string) => Awaitable<T>; write: (value: T) => Awaitable<string>; } export declare function set<T$1>(ref: Ref<T$1>, value: T$1): void; export declare function set<O extends object, K$1 extends keyof O>(target: O, key: K$1, value: O[K$1]): void; export declare type ShallowOrDeepRef<T$1 = any, D extends boolean = false> = D extends true ? Ref<T$1> : ShallowRef<T$1>; export declare type ShallowUnwrapRef<T$1> = T$1 extends Ref<infer P> ? P : T$1; export declare type SharedComposableReturn<T$1 extends AnyFn = AnyFn> = T$1; export declare interface SingletonPromiseReturn<T$1> { (): Promise<T$1>; /** * Reset current staled promise. * await it to have proper shutdown. */ reset: () => Promise<void>; } declare type SpecificFieldPartial<T$1, K$1 extends keyof T$1> = Partial<Pick<T$1, K$1>> & Omit<T$1, K$1>; export declare interface Stoppable<StartFnArgs extends any[] = any[]> { /** * A ref indicate whether a stoppable instance is executing */ readonly isPending: Readonly<Ref<boolean>>; /** * Stop the effect from executing */ stop: Fn; /** * Start the effects */ start: (...args: StartFnArgs) => void; } declare type StrictIncludeMap<IncludeType extends 'LR' | 'RL', D extends Exclude<Direction, 'both'>, L, R$1> = (Equal<[IncludeType, D], ['LR', 'ltr']> & Equal<[IncludeType, D], ['RL', 'rtl']>) extends true ? { transform?: SpecificFieldPartial<Pick<Transform<L, R$1>, D>, D>; } : { transform: Pick<Transform<L, R$1>, D>; }; declare type StrictIncludeType<IncludeType extends 'LR' | 'RL', D extends Direction, L, R$1> = D extends 'both' ? { transform: SpecificFieldPartial<Transform<L, R$1>, IncludeType extends 'LR' ? 'ltr' : 'rtl'>; } : D extends Exclude<Direction, 'both'> ? StrictIncludeMap<IncludeType, D, L, R$1> : never; /** * Two-way refs synchronization. * From the set theory perspective to restrict the option's type * Check in the following order: * 1. L = R * 2. L ∩ R ≠ ∅ * 3. L ⊆ R * 4. L ∩ R = ∅ */ export declare function syncRef<L, R$1, D extends Direction = 'both'>(left: Ref<L>, right: Ref<R$1>, ...[options]: Equal<L, R$1> extends true ? [options?: SyncRefOptions<L, R$1, D>] : [options: SyncRefOptions<L, R$1, D>]): () => void; export declare type SyncRefOptions<L, R$1, D extends Direction> = ConfigurableFlushSync & { /** * Watch deeply * * @default false */ deep?: boolean; /** * Sync values immediately * * @default true */ immediate?: boolean; /** * Direction of syncing. Value will be redefined if you define syncConvertors * * @default 'both' */ direction?: D; } & TransformType<D, L, R$1>; /** * Keep target ref(s) in sync with the source ref * * @param source source ref * @param targets */ export declare function syncRefs<T$1>(source: WatchSource<T$1>, targets: Ref<T$1> | Ref<T$1>[], options?: SyncRefsOptions): vue0.WatchHandle; export declare interface SyncRefsOptions extends ConfigurableFlushSync { /** * Watch deeply * * @default false */ deep?: boolean; /** * Sync values immediately * * @default true */ immediate?: boolean; } /** @deprecated use `refThrottled` instead */ export declare const throttledRef: typeof refThrottled; /** @deprecated use `watchThrottled` instead */ export declare const throttledWatch: typeof watchThrottled; /** * Create an EventFilter that throttle the events */ export declare function throttleFilter(ms: MaybeRefOrGetter<number>, trailing?: boolean, leading?: boolean, rejectOnCancel?: boolean): EventFilter; export declare function throttleFilter(options: ThrottleFilterOptions): EventFilter; export declare interface ThrottleFilterOptions { /** * The maximum time allowed to be delayed before it's invoked. */ delay: MaybeRefOrGetter<number>; /** * Whether to invoke on the trailing edge of the timeout. */ trailing?: boolean; /** * Whether to invoke on the leading edge of the timeout. */ leading?: boolean; /** * Whether to reject the last call if it's been cancel. */ rejectOnCancel?: boolean; } /** * Universal timer handle that works in both browser and Node.js environments */ export declare type TimerHandle = ReturnType<typeof setTimeout> | undefined; export declare const timestamp: () => number; export declare function toArray<T$1>(value: T$1 | readonly T$1[]): readonly T$1[]; export declare function toArray<T$1>(value: T$1 | T$1[]): T$1[]; export declare interface ToDataURLOptions extends UseBase64Options { /** * MIME type */ type?: string | undefined; /** * Image quality of jpeg or webp */ quality?: any; } export declare type ToggleFn = (value?: boolean) => void; /** * Converts ref to reactive. * * @see https://vueuse.org/toReactive * @param objectRef A ref of object */ export declare function toReactive<T$1 extends object>(objectRef: MaybeRef<T$1>): UnwrapNestedRefs<T$1>; /** * Normalize value/ref/getter to `ref` or `computed`. */ export declare function toRef<T$1>(r: () => T$1): Readonly<Ref<T$1>>; export declare function toRef<T$1>(r: ComputedRef<T$1>): ComputedRef<T$1>; export declare function toRef<T$1>(r: MaybeRefOrGetter<T$1>): Ref<T$1>; export declare function toRef<T$1>(r: T$1): Ref<T$1>; export declare function toRef<T$1 extends object, K$1 extends keyof T$1>(object: T$1, key: K$1): ToRef<T$1[K$1]>; export declare function toRef<T$1 extends object, K$1 extends keyof T$1>(object: T$1, key: K$1, defaultValue: T$1[K$1]): ToRef<Exclude<T$1[K$1], undefined>>; /** * Extended `toRefs` that also accepts refs of an object. * * @see https://vueuse.org/toRefs * @param objectRef A ref or normal object or array. * @param options Options */ export declare function toRefs<T$1 extends object>(objectRef: MaybeRef<T$1>, options?: ToRefsOptions): ToRefs<T$1>; export declare interface ToRefsOptions { /** * Replace the original ref with a copy on property update. * * @default true */ replaceRef?: MaybeRefOrGetter<boolean>; } declare interface Transform<L, R$1> { ltr: (left: L) => R$1; rtl: (right: R$1) => L; } declare type TransformType<D extends Direction, L, R$1> = Equal<L, R$1> extends true ? EqualType<D, L, R$1> : IncludeButNotEqual<L, R$1> extends true ? StrictIncludeType<'LR', D, L, R$1> : IncludeButNotEqual<R$1, L> extends true ? StrictIncludeType<'RL', D, L, R$1> : IntersectButNotEqual<L, R$1> extends true ? IntersectButNotEqualType<D, L, R$1> : NotIntersect<L, R$1> extends true ? NotIntersectType<D, L, R$1> : never; /** * Call onBeforeMount() if it's inside a component lifecycle, if not, just call the function * * @param fn * @param sync if set to false, it will run in the nextTick() of Vue * @param target */ export declare function tryOnBeforeMount(fn: Fn, sync?: boolean, target?: ComponentInternalInstance | null): void; /** * Call onBeforeUnmount() if it's inside a component lifecycle, if not, do nothing * * @param fn * @param target */ export declare function tryOnBeforeUnmount(fn: Fn, target?: ComponentInternalInstance | null): void; /** * Call onMounted() if it's inside a component lifecycle, if not, just call the function * * @param fn * @param sync if set to false, it will run in the nextTick() of Vue * @param target */ export declare function tryOnMounted(fn: Fn, sync?: boolean, target?: ComponentInternalInstance | null): void; /** * Call onScopeDispose() if it's inside an effect scope lifecycle, if not, do nothing * * @param fn */ export declare function tryOnScopeDispose(fn: Fn, failSilently?: boolean): boolean; /** * Call onUnmounted() if it's inside a component lifecycle, if not, do nothing * * @param fn * @param target */ export declare function tryOnUnmounted(fn: Fn, target?: ComponentInternalInstance | null): void; export declare type UnrefFn<T> = T extends ((...args: infer A) => infer R) ? (...args: { [K in keyof A]: MaybeRef<A[K]> }) => R : never; /** * Promised one-time watch for changes * * @see https://vueuse.org/until * @example * ``` * const { count } = useCounter() * * await until(count).toMatch(v => v > 7) * * alert('Counter is now larger than 7!') * ``` */ export declare function until<T$1 extends unknown[]>(r: WatchSource<T$1> | MaybeRefOrGetter<T$1>): UntilArrayInstance<T$1>; export declare function until<T$1>(r: WatchSource<T$1> | MaybeRefOrGetter<T$1>): UntilValueInstance<T$1>; export declare interface UntilArrayInstance<T$1> extends UntilBaseInstance<T$1> { readonly not: UntilArrayInstance<T$1>; toContains: (value: MaybeRefOrGetter<ElementOf<ShallowUnwrapRef<T$1>>>, options?: UntilToMatchOptions) => Promise<T$1>; } export declare interface UntilBaseInstance<T$1, Not extends boolean = false> { toMatch: (<U extends T$1 = T$1>(condition: (v: T$1) => v is U, options?: UntilToMatchOptions) => Not extends true ? Promise<Exclude<T$1, U>> : Promise<U>) & ((condition: (v: T$1) => boolean, options?: UntilToMatchOptions) => Promise<T$1>); changed: (options?: UntilToMatchOptions) => Promise<T$1>; changedTimes: (n?: number, options?: UntilToMatchOptions) => Promise<T$1>; } export declare interface UntilToMatchOptions { /** * Milliseconds timeout for promise to resolve/reject if the when condition does not meet. * 0 for never timed out * * @default 0 */ timeout?: number; /** * Reject the promise when timeout * * @default false */ throwOnTimeout?: boolean; /** * `flush` option for internal watch * * @default 'sync' */ flush?: WatchOptionFlush; /** * `deep` option for internal watch * * @default 'false' */ deep?: WatchOptions['deep']; } export declare interface UntilValueInstance<T$1, Not extends boolean = false> extends UntilBaseInstance<T$1, Not> { readonly not: UntilValueInstance<T$1, Not extends true ? false : true>; toBe: <P = T$1>(value: MaybeRefOrGetter<P>, options?: UntilToMatchOptions) => Not extends true ? Promise<T$1> : Promise<P>; toBeTruthy: (options?: UntilToMatchOptions) => Not extends true ? Promise<T$1 & Falsy> : Promise<Exclude<T$1, Falsy>>; toBeNull: (options?: UntilToMatchOptions) => Not extends true ? Promise<Exclude<T$1, null>> : Promise<null>; toBeUndefined: (options?: UntilToMatchOptions) => Not extends true ? Promise<Exclude<T$1, undefined>> : Promise<undefined>; toBeNaN: (options?: UntilToMatchOptions) => Promise<T$1>; } export declare type UrlParams = Record<string, string[] | string>; export declare function useArrayDifference<T$1>(list: MaybeRefOrGetter<T$1[]>, values: MaybeRefOrGetter<T$1[]>, key?: keyof T$1, options?: UseArrayDifferenceOptions): UseArrayDifferenceReturn<T$1>; export declare function useArrayDifference<T$1>(list: MaybeRefOrGetter<T$1[]>, values: MaybeRefOrGetter<T$1[]>, compareFn?: (value: T$1, othVal: T$1) => boolean, options?: UseArrayDifferenceOptions): UseArrayDifferenceReturn<T$1>; export declare interface UseArrayDifferenceOptions { /** * Returns asymmetric difference * * @see https://en.wikipedia.org/wiki/Symmetric_difference * @default false */ symmetric?: boolean; } export declare type UseArrayDifferenceReturn<T$1 = any> = ComputedRef<T$1[]>; /** * Reactive `Array.every` * * @see https://vueuse.org/useArrayEvery * @param list - the array was called upon. * @param fn - a function to test each element. * * @returns **true** if the `fn` function returns a **truthy** value for every element from the array. Otherwise, **false**. * * @__NO_SIDE_EFFECTS__ */ export declare function useArrayEvery<T$1>(list: MaybeRefOrGetter<MaybeRefOrGetter<T$1>[]>, fn: (element: T$1, index: number, array: MaybeRefOrGetter<T$1>[]) => unknown): UseArrayEveryReturn; export declare type UseArrayEveryReturn = ComputedRef<boolean>; /** * Reactive `Array.filter` * * @see https://vueuse.org/useArrayFilter * @param list - the array was called upon. * @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. * * @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. * * @__NO_SIDE_EFFECTS__ */ export declare function useArrayFilter<T$1, S$1 extends T$1>(list: MaybeRefOrGetter<MaybeRefOrGetter<T$1>[]>, fn: (element: T$1, index: number, array: T$1[]) => element is S$1): UseArrayFilterReturn<S$1>; export declare function useArrayFilter<T$1>(list: MaybeRefOrGetter<MaybeRefOrGetter<T$1>[]>, fn: (element: T$1, index: number, array: T$1[]) => unknown): UseArrayFilterReturn<T$1>; export declare type UseArrayFilterReturn<T$1 = any> = ComputedRef<T$1[]>; /** * Reactive `Array.find` * * @see https://vueuse.org/useArrayFind * @param list - the array was called upon. * @param fn - a function to test each element. * * @returns the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned. * * @__NO_SIDE_EFFECTS__ */ export declare function useArrayFind<T$1>(list: MaybeRefOrGetter<MaybeRefOrGetter<T$1>[]>, fn: (element: T$1, index: number, array: MaybeRefOrGetter<T$1>[]) => boolean): UseArrayFindReturn<T$1>; /** * Reactive `Array.findIndex` * * @see https://vueuse.org/useArrayFindIndex * @param list - the array was called upon. * @param fn - a function to test each element. * * @returns the index of the first element in the array that passes the test. Otherwise, "-1". * * @__NO_SIDE_EFFECTS__ */ export declare function useArrayFindIndex<T$1>(list: MaybeRefOrGetter<MaybeRefOrGetter<T$1>[]>, fn: (element: T$1, index: number, array: MaybeRefOrGetter<T$1>[]) => unknown): UseArrayFindIndexReturn; export declare type UseArrayFindIndexReturn = ComputedRef<number>; /** * Reactive `Array.findLast` * * @see https://vueuse.org/useArrayFindLast * @param list - the array was called upon. * @param fn - a function to test each element. * * @returns the last element in the array that satisfies the provided testing function. Otherwise, undefined is returned. * * @__NO_SIDE_EFFECTS__ */ export declare function useArrayFindLast<T$1>(list: MaybeRefOrGetter<MaybeRefOrGetter<T$1>[]>, fn: (element: T$1, index: number, array: MaybeRefOrGetter<T$1>[]) => boolean): UseArrayFindLastReturn<T$1>; export declare type UseArrayFindLastReturn<T$1 = any> = ComputedRef<T$1 | undefined>; export declare type UseArrayFindReturn<T$1 = any> = ComputedRef<T$1 | undefined>; /** * Reactive `Array.includes` * * @see https://vueuse.org/useArrayIncludes * * @returns true if the `value` is found in the array. Otherwise, false. * * @__NO_SIDE_EFFECTS__ */ export declare function useArrayIncludes<T$1, V$1 = any>(list: MaybeRefOrGetter<MaybeRefOrGetter<T$1>[]>, value: MaybeRefOrGetter<V$1>, comparator?: UseArrayIncludesComparatorFn<T$1, V$1>): UseArrayIncludesReturn; export declare function useArrayIncludes<T$1, V$1 = any>(list: MaybeRefOrGetter<MaybeRefOrGetter<T$1>[]>, value: MaybeRefOrGetter<V$1>, comparator?: keyof T$1): UseArrayIncludesReturn; export declare function useArrayIncludes<T$1, V$1 = any>(list: MaybeRefOrGetter<MaybeRefOrGetter<T$1>[]>, value: MaybeRefOrGetter<V$1>, options?: UseArrayIncludesOptions<T$1, V$1>): UseArrayIncludesReturn; export declare type UseArrayIncludesComparatorFn<T$1, V$1> = ((element: T$1, value: V$1, index: number, array: MaybeRefOrGetter<T$1>[]) => boolean); export declare interface UseArrayIncludesOptions<T$1, V$1> { fromIndex?: number; comparator?: UseArrayIncludesComparatorFn<T$1, V$1> | keyof T$1; } export declare type UseArrayIncludesReturn = ComputedRef<boolean>; /** * Reactive `Array.join` * * @see https://vueuse.org/useArrayJoin * @param list - the array was called upon. * @param separator - a string to separate each pair of adjacent elements of the array. If omitted, the array elements are separated with a comma (","). * * @returns a string with all array elements joined. If arr.length is 0, the empty string is returned. * * @__NO_SIDE_EFFECTS__ */ export declare function useArrayJoin(list: MaybeRefOrGetter<MaybeRefOrGetter<any>[]>, se