UNPKG

@medyll/idae-be

Version:

A modern, lightweight, and extensible DOM manipulation library built with TypeScript. Designed for precise element targeting and manipulation using a callback-based approach. Features include advanced DOM traversal, event handling, style management, attri

157 lines (156 loc) 6.96 kB
import { type AttrHandlerHandle, AttrHandler } from './modules/attrs.js'; import { StylesHandler, type BeStylesHandler } from './modules/styles.js'; import type { IsWhat } from './types.js'; import { type DataHandlerHandle, DataHandler } from './modules/data.js'; import { EventsHandler, type EventHandlerHandle } from './modules/events.js'; import { type ClassHandlerHandler, ClassesHandler } from './modules/classes.js'; import { DomHandler, type DomHandlerHandle } from './modules/dom.js'; import { PositionHandler, type PositionHandlerHandle } from './modules/position.js'; import { WalkHandler, type WalkHandlerHandle } from './modules/walk.js'; import { TextHandler, type TextHandlerHandle } from './modules/text.js'; import { TimersHandler, type TimerHandlerHandle } from './modules/timers.js'; import { HttpHandler, type HttpHandlerHandle } from './modules/http.js'; export declare class Be { [key: string]: unknown; inputNode: HTMLElement | HTMLElement[] | string; isWhat: IsWhat; timerOut: NodeJS.Timeout | null; timerInterval: NodeJS.Timeout | null; styles: (actions: BeStylesHandler) => Be; private styleHandler; setStyle: StylesHandler['set']; getStyle: StylesHandler['get']; unsetStyle: StylesHandler['unset']; data: (actions: DataHandlerHandle) => Be; private dataHandler; setData: DataHandler['set']; getData: DataHandler['get']; deleteData: DataHandler['delete']; getKey: DataHandler['getKey']; attrs: (actions: Partial<AttrHandlerHandle>) => Be; private attrHandler; setAttr: AttrHandler['set']; getAttr: AttrHandler['get']; deleteAttr: AttrHandler['delete']; position: (actions: PositionHandlerHandle) => Be; private positionHandler; clonePosition: PositionHandler['clonePosition']; overlapPosition: PositionHandler['overlapPosition']; snapTo: PositionHandler['snapTo']; dom: (actions: DomHandlerHandle) => Be; private domHandler; update: DomHandler['update']; append: DomHandler['append']; prepend: DomHandler['prepend']; insert: DomHandler['insert']; afterBegin: DomHandler['afterBegin']; afterEnd: DomHandler['afterEnd']; beforeBegin: DomHandler['beforeBegin']; beforeEnd: DomHandler['beforeEnd']; remove: DomHandler['remove']; replace: DomHandler['replace']; clear: DomHandler['clear']; normalize: DomHandler['normalize']; wrap: DomHandler['wrap']; unwrap: DomHandler['unwrap']; text: (actions: TextHandlerHandle) => Be; private textHandler; appendText: TextHandler['append']; prependText: TextHandler['prepend']; updateText: TextHandler['update']; replaceText: TextHandler['replace']; removeText: TextHandler['remove']; clearText: TextHandler['clear']; normalizeText: TextHandler['normalize']; wrapText: TextHandler['wrap']; events: (actions: EventHandlerHandle) => Be; private eventHandler; on: EventsHandler['on']; off: EventsHandler['off']; fire: EventsHandler['fire']; classes: (actions: ClassHandlerHandler) => Be; private classesHandler; addClass: ClassesHandler['add']; removeClass: ClassesHandler['remove']; toggleClass: ClassesHandler['toggle']; replaceClass: ClassesHandler['replace']; walk: (actions: WalkHandlerHandle) => Be; private walkHandler; up: WalkHandler['up']; next: WalkHandler['next']; without: WalkHandler['without']; previous: WalkHandler['previous']; siblings: WalkHandler['siblings']; children: WalkHandler['children']; closest: WalkHandler['closest']; lastChild: WalkHandler['lastChild']; firstChild: WalkHandler['firstChild']; find: WalkHandler['find']; findAll: WalkHandler['findAll']; timers: (actions: TimerHandlerHandle) => Be; private timerHandler; timeout: TimersHandler['timeout']; interval: TimersHandler['interval']; clearTimeout: TimersHandler['clearTimeout']; clearInterval: TimersHandler['clearInterval']; http: (actions: HttpHandlerHandle) => Be; private httpHandler; updateHttp: HttpHandler['update']; insertHttp: HttpHandler['insert']; private constructor(); /** * Normalizes the input to ensure `node` is always an HTMLElement or an array of HTMLElements. * @param input - The input to normalize (string, HTMLElement, or array of HTMLElements). * @returns A valid HTMLElement or an array of HTMLElements. */ private static getNode; static elem(node: HTMLElement | HTMLElement[] | string): Be; static createBe(tagOrHtml: CreateFragment, options?: { is?: string; style?: Record<string, string> | string; attributes?: Record<string, string>; className?: string; }): Be; /** * Creates a new `Be` element based on the provided string or HTMLElement. * If the input is an HTMLElement, it creates a new `Be` element and sets it as the child of the provided element. * If the input is a string, it checks if it is a valid HTML string and creates a new `Be` element based on it. * If the input is neither a string nor an HTMLElement, it creates a new `Be` element with the default tag. * * @param str - The string or HTMLElement to create the `Be` element from. * @param options - Additional options for creating the `Be` element. * @returns The created `Be` element. */ static toBe(str: string | HTMLElement, options?: { tag?: string; }): Be; fetch<T extends object>(options: { url: string; method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD' | 'CONNECT' | 'TRACE'; data?: T; headers?: Record<string, string>; }): Promise<any>; /** * Iterates over nodes based on the type of `this.isWhat` and applies a callback function to each node. * * @param callback - A function to be executed for each node. Receives the current node as an argument. * @param firstChild - Optional. If `true`, stops further iteration after the first child is processed. * * The behavior of the method depends on the value of `this.isWhat`: * - `'element'`: Applies the callback to a single HTMLElement (`this.inputNode`). * - `'array'`: Iterates over an array of HTMLElements (`this.inputNode`) and applies the callback to each. * - `'qy'`: Selects elements using a query selector string (`this.inputNode`) and applies the callback to each. */ eachNode(callback: (el: HTMLElement) => void, firstChild?: boolean): void; get html(): string | null; get node(): HTMLElement | HTMLElement[]; private attach; private handle; } type CreateFragment = `<${string}>${string}</${string}>` | string; /** set exports as root */ export declare const be: typeof Be.elem; export declare const toBe: typeof Be.toBe; export declare const beId: (id: string) => Be; export declare const createBe: typeof Be.createBe; export {};