UNPKG

@react-hive/honey-utils

Version:

A lightweight TypeScript utility library providing a collection of helper functions for common programming tasks

76 lines (75 loc) 2.75 kB
interface HTMLElementTransformationValues { translateX: number; translateY: number; scaleX: number; scaleY: number; skewX: number; skewY: number; } /** * Extracts transformation values (translate, scale, skew) from the 2D transformation matrix of a given HTML element. * * Only works with 2D transforms (i.e., `matrix(a, b, c, d, e, f)`). * * @param element - The element with a CSS transform applied. * @returns An object with parsed transformation values. * * @example * ```ts * const values = parse2DMatrix(myElement); * console.log(values.translateX); * console.log(values.scaleX); * ``` */ export declare const parse2DMatrix: (element: HTMLElement) => HTMLElementTransformationValues; /** * Creates a clone of a Blob object. * * @param blob - The Blob object to clone. * * @returns A new Blob with the same content and type as the original. */ export declare const cloneBlob: (blob: Blob) => Blob; /** * Converts a `Blob` object into a `File` object with the specified name. * * This is useful when you receive a `Blob` (e.g., from canvas, fetch, or file manipulation) * and need to convert it into a `File` to upload via `FormData` or file inputs. * * @param blob - The `Blob` to convert. * @param fileName - The desired name for the resulting file (including extension). * * @returns A `File` instance with the same content and MIME type as the input `Blob`. * * @example * ```ts * const blob = new Blob(['Hello world'], { type: 'text/plain' }); * const file = convertBlobToFile(blob, 'hello.txt'); * * console.log(file instanceof File); // true * ``` */ export declare const convertBlobToFile: (blob: Blob, fileName: string) => File; /** * Calculates the intersection ratio between two DOM rectangles. * * The ratio represents the proportion of the `targetRect` that is covered by `sourceRect`. * A value of `1` means `sourceRect` completely covers `targetRect`, and `0` means no overlap. * * @param sourceRect - The rectangle used to measure overlap against the target. * @param targetRect - The rectangle whose covered area is measured. * * @returns A number between `0` and `1` representing the intersection ratio. */ export declare const getDOMRectIntersectionRatio: (sourceRect: DOMRect, targetRect: DOMRect) => number; /** * Returns the bounding DOMRect of an element based on offset and client dimensions. * * This utility is useful when you need a stable, layout-based rect * without triggering a reflow via `getBoundingClientRect()`. * * @param element - The target HTML element. * @returns A `DOMRect` representing the element’s offset position and size. */ export declare const getElementOffsetRect: (element: HTMLElement) => DOMRect; export {};