ts-browser-helpers
Version:
A collection of utility classes, functions and decorators for javascript/typescript projects, for use in the browser.
62 lines • 2.12 kB
TypeScript
/**
* Creates a HTML canvas element.
* @category DOM
*/
export declare function createCanvasElement(): HTMLCanvasElement;
/**
* Creates an HTML div element.
* @param innerHTML - HTML string to add to the div
* @param id - id of the div
* @param classList - list of classes to add to the div
* @param addToBody - add the div to the body
* @param elementTag - tag of the element to create (default: div)
*
* @category DOM
*/
export declare function createDiv<T extends keyof HTMLElementTagNameMap = 'div'>({ innerHTML, id, classList, addToBody, elementTag }: {
innerHTML?: string;
id?: string;
classList?: string[];
addToBody?: boolean;
elementTag?: T;
}): HTMLElementTagNameMap[T];
/**
* Creates a HTML image element from a url.
* @param url - url of the image
*
* @category DOM
*/
export declare function createImage(url: string): Promise<HTMLImageElement>;
/**
* Creates a HTML style element with the given styles.
* @param styles - CSS string
* @param root - root element to add the style to (default: head)
*
* @category DOM
*/
export declare function createStyles(styles: string, root?: Element | undefined): HTMLStyleElement;
/**
* Creates a HTML script element from a url.
* @param url - url of the script
* @param root - root element to add the script to (default: head)
*
* @category DOM
*/
export declare function createScriptFromURL(url: string, root?: HTMLHeadElement): Promise<HTMLScriptElement>;
/**
* Sets the innerHTML of an element and recreates all script tags so they are executed.
* @param element - element to set the innerHTML of
* @param html - innerHTML string to set
*
* @category DOM
*/
export declare function setInnerHTMLWithScripts(element: HTMLElement, html: string): Promise<void>;
/**
* Clones a script tag.
* @param script - script tag to clone
* @param newScript - optional new script tag to clone into. If not provided a new script tag will be created.
*
* @category DOM
*/
export declare function cloneScriptTag(script: HTMLScriptElement, newScript?: HTMLScriptElement): HTMLScriptElement;
//# sourceMappingURL=dom.d.ts.map