uger
Version:
```ts import { body } from "uger";
163 lines (162 loc) • 5.27 kB
TypeScript
import { OptionalCSSStyles } from "./formats";
declare type ElemCreationOptions = [
keyof HTMLElementTagNameMap,
...(string | {
[property: string]: string;
} | ((elem: Elem) => void) | ElemCreationOptions[] | Elem)[]
];
declare class Elem {
/** The HTML element passed to this object's constructor */
element: HTMLElement;
/** Style of this html element */
style: CSSStyleDeclaration;
/** Children of this element */
children: Elem[];
/** The element that is the parent of this element */
parent: Elem | undefined;
/**
* @param element Html element on which Elem is based.
* @param properties The class, id and name of this element.
* Similar to the query selector tag.
* For example ".book #first"
*/
constructor(element: HTMLElement, ...properties: (string | {
[property: string]: string;
} | ((elem: Elem) => void) | ElemCreationOptions[] | Elem)[]);
/**
* Change element's id, class and.
* @param properties The class, id and name of this element.
* Similar to the query selector tag.
* For example ".book #first"
* Or it can be an object of attributes
*/
_(properties: string | {
[property: string]: string;
} | ((elem: Elem) => void) | ElemCreationOptions[] | Elem): void;
/**
* Creates and adds a new element as a child of the current elements.
* @param tagName HTML map tag.
* @param properties The class, id and name of this element.
* Similar to the query selector tag.
* For example ".book #first"
* @returns {Elem}
*/
add(tagName: keyof HTMLElementTagNameMap, ...properties: (string | {
[property: string]: string;
} | ((elem: Elem) => void) | ElemCreationOptions[] | Elem)[]): Elem;
/**
* Adds an existing html element as a child of the current elements.
* @param element HTMLElement
* @returns {Elem}
*/
addFrom(element: HTMLElement): Elem;
/**
* Changes src attribute of element
* @param path source path of element
* @returns {Elem} Current element
*/
src(path: string): this;
/**
* Gets text from input element
* @returns {string}
*/
input(): string;
/**
* Change text of input element
* @param text new text
* @returns {Elem} Current element
*/
setInput(text: string): this;
/**
* Changes several css properties at once.
* @param css An css object to get properties from.
* For example { backgroundColor: "black", color: "white" }
* @returns {Elem} Current element
*/
styles(css: OptionalCSSStyles): this;
/**
* Remove child of this element.
* @param child the child element to remove.
*/
removeChild(child: Elem): void;
/**
* Removes element from the document.
*/
remove(): void;
/**
* Changes the id of this element.
* @returns {Elem} Current element
*/
id(id: string): this;
/**
* Gets the id of this element.
* @returns id
*/
getId(): string;
/**
* Changes the class of this element.
* @returns {Elem} Current element
*/
class(className: string): this;
/**
* Gets the class of this element.
* @returns class
*/
getClass(): string;
/**
* Changes the innerText of this element.
* @returns {Elem} Current element
*/
text(text: string): this;
/**
* Gets the innerText of this element.
* @returns innerText
*/
getText(): string;
/**
* Changes the innerHtml of this element.
* @returns {Elem} Current element
*/
html(text: string): this;
/**
* Gets the innerHTML of this element.
* @returns innerHTML
*/
getHtml(): string;
/**
* Adds another element as a child to this element.
* @param elem other element
*/
appendChild(elem: Elem): void;
/**
* Adds an event listener to this element.
* @param type event type
* @param listener your function
* @param options AddEventListenerOptions
* @returns {Elem} Current element
*/
on<K extends keyof HTMLElementEventMap>(type: K, listener: (ev: HTMLElementEventMap[K], elem: Elem) => any, options?: boolean | AddEventListenerOptions): this;
/**
* Adds an event listener to this element.
* But calls the listener only once.
* @param type event type
* @param listener your function
* @returns {Elem} Current element
*/
once<K extends keyof HTMLElementEventMap>(type: K, listener: (ev: HTMLElementEventMap[K], elem: Elem) => any): this;
/**
* Makes element fullscreen
*/
fullscreen(): void;
/**
* Makes element fullscreen
*/
pointerLock(): void;
}
declare function elem(tagName: keyof HTMLElementTagNameMap, ...properties: (string | {
[property: string]: string;
} | ((elem: Elem) => void) | ElemCreationOptions[])[]): Elem;
/** The beginning of everything */
declare const body: Elem;
declare const win: Elem;
export { Elem, elem, body, win };