UNPKG

vanillajs-browser-helpers

Version:

Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser

92 lines (91 loc) 3.18 kB
import type { GeneralWindow } from './shared/types'; interface Size { width: number; height: number; } export declare const enum SizeType { /** Size including margins and borders */ MARGIN_BOX = "margin-box", /** Size including borders */ OUTER = "outer", /** Size excluding borders and margins */ INNER = "inner", /** Size of the content (scrollable area minus padding) */ CONTENT_BOX = "content-box", /** Size excluding borders, margins and padding */ CONTENT = "content" } export declare function elmSize(elm: HTMLElement, type?: SizeType): Size; export declare function windowSize(win?: GeneralWindow, type?: SizeType): Size; /** * Find the size of the current Window. * * @param elm - The DOM element (or window) to find the size of * @param type - What type of size has to be computed. See `sizeType` for further details * @return Object describing width and height of the element * * @example * * ```ts * // Get the outer size the window * size(); * * // Get a specific size model of window * size(SizeType.MARGIN_BOX); * ``` */ declare function size(type?: SizeType): Size; /** * Find the size of a DOM element or a Window instance. * * @param elm - The DOM element (or window) to find the size of * @param type - What type of size has to be computed. See `sizeType` for further details * @return Object describing width and height of the element * * @example * * ```ts * // Get the outer size af given element * size(someElement); * * // Get a specific size model of a given element * size(someElement, SizeType.MARGIN_BOX); * ``` */ declare function size(elm: HTMLElement | GeneralWindow, type?: SizeType): Size; export default size; /** * Find the size of a DOM element or window including margins and borders * * @param elm - The DOM element (or window) to find the size of * @return Object describing width and height of the element */ export declare const marginBoxSize: (elm: HTMLElement | GeneralWindow) => Size; /** * Find the size of a DOM element or window including borders * * @param elm - The DOM element (or window) to find the size of * @return Object describing width and height of the element */ export declare const outerSize: (elm: HTMLElement | GeneralWindow) => Size; /** * Find the size of a DOM element or window excluding borders and margins * * @param elm - The DOM element (or window) to find the size of * @return Object describing width and height of the element */ export declare const innerSize: (elm: HTMLElement | GeneralWindow) => Size; /** * Find the size of the content (scrollable area minus padding) of a DOM element or window * * @param elm - The DOM element (or window) to find the size of * @return Object describing width and height of the element */ export declare const contentSize: (elm: HTMLElement | GeneralWindow) => Size; /** * Find the size of a DOM element or window excluding borders, margins and padding * * @param elm - The DOM element (or window) to find the size of * @return Object describing width and height of the element */ export declare const contentBoxSize: (elm: HTMLElement | GeneralWindow) => Size;