/** * Return an object that can hold a reference to an element and exposes a setter for that reference. * * @example * export class MyComp { * div = useRef(); * * componentDidLoad() { * console.log(this.div.ref); * } * * render() { * return
; * } * } */ export declare const useRef: ({ nullRefs }?: UseRefOptions) => { ref: T | undefined; setRef(el?: T): void; }; export interface UseRefOptions { /** * If true, `null` refs will also be set. A ref is set to `null` if the element is removed during render. Enable this if you dynamically/conditionally add and remove the referenced element. * * When moving an element around, it will be removed from its old location as well as added to its new location, each calling the `ref` prop callback. Depending on the order of execution of those two ref calls (depending on which one is encountered first in the DOM), the `null` ref might be called last, therefore giving an undesired ref. For that reason this option is disabled by default. */ nullRefs?: boolean; } /** * Wait for a given amount of time. * * @param t time in ms * * @returns a promise that resolves after the given time */ export declare const wait: (t: number) => Promise; /** * Debounce a function by the given delay. * * @param fn function to debounce * @param delay debounce time in ms */ export declare const debounce: any>(fn: T, delay: number) => (...args: Parameters) => void; /** * Throttle a function by the given delay. * * @param fn function to throttle * @param delay time in ms * @param skipFn optional function to execute when fn is skipped due to throttle */ export declare function throttle any>(fn: T, delay: number): (...args: Parameters) => ReturnType | void; export declare function throttle any, S extends (...args: Parameters) => any>(fn: T, delay: number, skipFn: S): (...args: Parameters) => ReturnType; /** * Get a random integer in the given range. */ export declare const getRandomInt: (min: number, max: number) => number; /** * Get a data url from a base64 encoded image (assumes jpg by default). */ export declare const base64ImageToDataUrl: (base64String: string, type?: string) => string; /** * Get the value at the path of an object. * * @example * const foo = { bar: { value: 'foobar' } }; * getByPath(foo, 'bar.value') // => 'foobar' * getByPath(foo, 'foo.bar') // => undefined */ export declare const getByPath: (object: any, path: string) => T; /** * Make a deep clone of an object. */ export declare const clone: (value: T) => T; /** * Download a file by opening it via a data url in a new window. * * @param data The file's data as a base64 encoded string. * @param mimeType The mime type also determines the file extension. * @param fileName Name of the file without extension. */ export declare const downloadFile: (data: string, mimeType: "text/csv", fileName: string, addTimestamp?: boolean) => void; /** * Run a callback on the queried element within the parent. This uses `requestAnimationFrame` to make sure of the element's existence in the DOM. * * @example * raf({ * parent: this.el, * selector: 'div.wrapper' as 'div', * inShadowRoot: true, * callback: div => { * div.style.color = 'red'; * } * }); */ export declare function raf(options: GenericRafOptions): void; export declare function raf(options: RafOptions): void; interface RafOptions { /** * The parent element to run the query on. */ parent: HTMLElement | undefined; /** * Whether to query on the element or the element's shadow root. Defaults to `false`. */ inShadowRoot?: boolean; /** * The selector to query for. */ selector: string; /** * The callback to run on the element queried by the selector. */ callback(el: HTMLElement): void; } interface GenericRafOptions extends RafOptions { selector: K; callback(el: HTMLElementTagNameMap[K]): void; } /** * Handler to stop event propagation. */ export declare const stopPropagation: (e: Event) => void; /** * Read a file using a `FileReader` and return its data as a base64 encoded string. * * Using `readAsBinaryString` and converting it to base64 is faster than using `readAsDataURL` and removing the data url prefix. However, `readAsBinaryString` is not supported in IE :roll_eyes:, in which case it falls back to the latter. */ export declare const readFile: (file: File, { asDataUrl }?: ReadFileOptions) => Promise; interface ReadFileOptions { /** * If set to `true`, it will read the file as a data url, and remove the data url prefix. If set to `keep-prefix`, it will return the data including the data url prefix. If set to `false`, the file will be read as a binary string and converted to base64. */ asDataUrl?: boolean | 'keep-prefix'; } /** * Generate a v4 compliant uuid. */ export declare const uuid: () => string; /** * Convert a data url to a blob. */ export declare const convertDataUrlToBlob: (dataUrl: string) => Promise; export {};