UNPKG

dom-maker

Version:

A library for create element by VanillaJs easily

139 lines 4.36 kB
declare const NS_MAP: { HTML: string; SVG: string; XBL: string; XUL: string; }; export declare class ElementPlus<E extends HTMLElement = HTMLElement> { /** * current element */ private element; /** * cache events to manage and remove them easily */ private eventsRegistry; constructor(tagName?: (keyof HTMLElementTagNameMap | string & {}), nameSpace?: keyof typeof NS_MAP); /** * get current element * * @returns {HTMLElement} */ getElm(): E; /** * check current element is ElementPlus * * @param {(HTMLElement|ElementPlus)} element * @returns {boolean} */ isElmPro(element: HTMLElement | ElementPlus): element is ElementPlus; /** * add multiple classes to element * * @param {(string|string[])} cls * @returns {ElementPlus} */ addClass(cls: string | string[]): this; /** * remove multiple classes from element * * @param {string|string[]} cls * @returns {ElementPlus} */ removeClass(cls: string | string[]): this; /** * check if element has a certain class * * @param {string} cls * @returns {boolean} */ hasClass(cls: string): boolean; /** * toggle element classes * * @param {string} cls * @returns {ElementPlus} */ toggleClass(cls: string): this; /** * add an attribute to element * * @param {string} key * @param {number | string | boolean} value * @returns {ElementPlus} */ setAttr<T extends (number | string | boolean)>(key: string, value: T): ElementPlus; /** * remove multiple attributes from element * * @param {string|string[]} key * @returns {ElementPlus} */ removeAttr(key: string | string[]): this; /** * add multiple children to current element * * @param {(HTMLElement|ElementPlus)[]} elements * @returns {ElementPlus} */ addChildren(elements: (HTMLElement | ElementPlus)[]): this; /** * add a event listener if here not exist and store listener to remove it easily * * @param {(string} type * @param {EventListenerOrEventListenerObject} listener * @param {boolean | AddEventListenerOptions} options * @returns {ElementPlus} */ on(type: keyof DocumentEventMap | string & {}, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): this; /** * remove event listener from current element * * @param {(string|string[]|undefined} type * @returns {ElementPlus} */ unbind(type?: string | string[]): this; /** * create custom event on current element * * @param {(string} type * @param {Record<string,any>} detail * @param {Omit<CustomEventInit,'detail'>} options * @returns {ElementPlus} */ dispatch(type: string, detail?: CustomEventInit, options?: Omit<CustomEventInit, 'detail'>): this; /** * set current element innerText * * @param {(string} text * @returns {ElementPlus} */ setText(text: string): this; /** * append innerHTML after current element * * @param {(string} text * @returns {ElementPlus} */ addInnerHtml(text: string, pos?: 'before' | 'after'): this; /** * set current element innerHtml * * @param {(string} html * @returns {ElementPlus} */ setHtml(html: string): this; /** * append current element to target element */ appendTo(selectors: string): void; } export declare const Div: () => ElementPlus<HTMLDivElement>; export declare const Span: () => ElementPlus<HTMLSpanElement>; export declare const Img: () => ElementPlus<HTMLImageElement>; export declare const Video: () => ElementPlus<HTMLVideoElement>; export declare const Input: () => ElementPlus<HTMLInputElement>; export declare const Button: () => ElementPlus<HTMLButtonElement>; declare const $: <E extends HTMLElement>(tagName: (keyof HTMLElementTagNameMap | (string & {})), nameSpace?: "HTML" | "SVG" | "XBL" | "XUL" | undefined) => ElementPlus<E>; export default $; //# sourceMappingURL=element.d.ts.map