UNPKG

tiny-essentials

Version:

Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.

2,130 lines (1,328 loc) โ€ข 53.7 kB
# ๐Ÿ“š TinyHtml Class `TinyHtml` is a lightweight utility class that provides DOM element manipulation and querying utilities, inspired by jQuery โ€” but built with modern native browser APIs. It supports both static and instance-level operations, making it easy to work with elementsโ€™ dimensions, collisions, and more in a readable and performant way. Most instance methods that do not return a specific value are designed to return the `TinyHtml` instance itself, enabling **method chaining**. This allows you to write fluent and expressive code like: ```js TinyHtml.createElement('div') .addClass('box') .setAttr('role', 'dialog') .appendTo(document.body); ``` This design keeps your code concise while maintaining clarity and control over the DOM structure. ## ๐Ÿงฉ Type Definitions โ€“ Core Building Blocks This section documents the internal types, helpers, and data structures used by the `TinyHtml` class. These types provide a flexible abstraction over raw DOM elements and enhanced TinyHtml objects. --- ### ๐Ÿงฑ Basic Types #### `TinyNode` Represents a raw `Node`, a `TinyHtml` instance, or `null`. ```ts Node | TinyHtml | null ``` --- #### `TinyElement` Represents either a raw `Element` or a `TinyHtml` instance. ```ts Element | TinyHtml ``` --- #### `TinyHtmlElement` Alias for `HTMLElement | TinyHtml`. --- #### `TinyEventTarget` Represents any event target element or a `TinyHtml` instance. ```ts EventTarget | TinyHtml ``` --- #### `TinyInputElement` Used for form elements that can hold values (e.g., input, select). ```ts InputElement | TinyHtml ``` --- #### `TinyElementAndWindow` Accepts both raw DOM elements and the `window` object. ```ts ElementAndWindow | TinyHtml ``` --- #### `TinyElementAndWinAndDoc` Accepts both raw DOM elements, `document`, and the `window` object. ```ts ElementAndWinAndDoc | TinyHtml ``` --- #### `TinyElementWithDoc` Accepts both raw DOM elements, the `document` object, or a `TinyHtml` wrapper. ```ts ElementWithDoc | TinyHtml ``` Used to abstract interactions with either native elements or enhanced wrappers. --- ### ๐Ÿ”€ Union Types #### `ElementWithDoc` A raw DOM `Element` or the `document` object. ```ts Element | Document ``` Commonly used when the target might be either a single HTML element or the whole document, particularly in layout and measurement utilities. --- #### `ElementAndWinAndDoc` Used for scrollable or measurable targets. ```ts Element | Window | Document ``` --- #### `ElementAndWindow` Used for scrollable or measurable targets. ```ts Element | Window ``` --- #### `WinnowRequest` Flexible type for querying or filtering elements: * `string` (CSS selector) * `Element` * `Element[]` * `(index: number, el: Element) => boolean` --- #### `ConstructorElValues` Values accepted by the TinyHtml constructor: ```ts Window | Element | Document | Text ``` --- #### `EventRegistryOptions` Options for `addEventListener` and `removeEventListener`. ```ts boolean | AddEventListenerOptions ``` --- #### `EventRegistryItem` Describes an individual event registration. ```ts { handler: EventListenerOrEventListenerObject | null, options?: EventRegistryOptions } ``` --- #### `EventRegistryList` Maps event names (like `"click"`) to lists of `EventRegistryItem`. ```ts Record<string, EventRegistryItem[]> ``` --- #### `__eventRegistry` A `WeakMap` that stores event listeners by element. ```ts WeakMap<ConstructorElValues|EventTarget, EventRegistryList> ``` --- ### ๐Ÿ’พ Element Data #### `ElementDataStore` A key-value storage associated with an element. ```ts Record<string, *> ``` --- #### `__elementDataMap` A `WeakMap` to hold internal data for DOM elements. ```ts WeakMap<ConstructorElValues, ElementDataStore> ``` --- ### ๐Ÿ’ฅ Collision System #### `CollisionDirLock` Directions supported for collision lock: ```ts 'top' | 'bottom' | 'left' | 'right' ``` --- #### `__elemCollision` Stores directional collision locks per element. ```ts { top: WeakMap<Element, true>, bottom: WeakMap<Element, true>, left: WeakMap<Element, true>, right: WeakMap<Element, true> } ``` --- ### ๐Ÿ“ Box Size Utilities #### `HtmlElBoxSides` Describes an elementโ€™s box sizes. ```ts { x: number, // total horizontal (left + right) y: number, // total vertical (top + bottom) left: number, right: number, top: number, bottom: number } ``` --- ### ๐Ÿ”ข Value Types #### `SetValueBase` Primitive types accepted for form inputs. ```ts string | number | Date | boolean | null ``` --- #### `SetValueList` A single value or list of values for input fields. ```ts SetValueBase | SetValueBase[] ``` --- #### `GetValueTypes` Supported return types for `.val()` operations: ```ts 'string' | 'date' | 'number' ``` --- #### `InputElement` Supported form controls used by TinyHtml. ```ts HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | HTMLOptionElement ``` --- ## ๐Ÿ”จ Element Creation ### `TinyHtml.createFrom(tagName, attrs?)` Creates a new `TinyHtml` element from a given tag name and optional attributes. * **Parameters**: * `tagName` *(string)* โ€” The HTML tag name (e.g., `'div'`, `'span'`, `'button'`). * `attrs` *(object)* โ€” *(optional)* Key-value pairs representing HTML attributes. * **Returns**: `TinyHtml` โ€” A new `TinyHtml` instance representing the created element. * **Throws**: * `TypeError` โ€” If `tagName` is not a string. * `TypeError` โ€” If `attrs` is defined but not a plain object. ### ๐Ÿ’ก Example ```js const div = TinyHtml.createFrom('div', { class: 'container' }); const span = TinyHtml.createFrom('span', { id: 'my-span', title: null }); ``` The method can also be aliased for convenience: ```js const createElement = TinyHtml.createFrom; const button = createElement('button', { type: 'submit', class: 'btn' }); ``` --- ## ๐Ÿ”Ž Static DOM Selectors These methods wrap native DOM query methods and return results as `TinyHtml` instances for consistency. ### `TinyHtml.createElement(tagName, ops)` Creates a new DOM element with the given tag name and optional creation options. * **Parameters**: * `tagName` *(string)* โ€” The tag name of the element to create (e.g., `'div'`, `'span'`). * `ops` *(ElementCreationOptions)* โ€” *(optional)* Options for advanced element creation. * **Returns**: `TinyHtml` โ€” A `TinyHtml` instance wrapping the newly created element. * **Throws**: * `TypeError` โ€” If `tagName` is not a string. * `TypeError` โ€” If `ops` is defined but not an object. --- ### `TinyHtml.createTextNode(value)` Creates a new `TinyHtml` instance that wraps a DOM `TextNode`. This method is useful when you want to insert raw text content into the DOM without it being interpreted as HTML. The returned instance behaves like any other `TinyHtml` element and can be appended or manipulated as needed. * **Parameters**: * `value` *(string)* โ€” The plain text content to be wrapped in a `TextNode`. * **Returns**: `TinyHtml` โ€” A `TinyHtml` instance wrapping the newly created DOM `TextNode`. * **Throws**: * `TypeError` โ€” If the provided `value` is not a string. --- ### `TinyHtml.createElementFromHTML(htmlString)` Creates an `HTMLElement` or `TextNode` from an HTML string. Supports both elements and plain text. * **Parameters**: * `htmlString` *(string)* โ€” The HTML string to convert. * **Returns**: `TinyHtml` โ€” A `TinyHtml` instance wrapping the resulting `HTMLElement` or `TextNode`. * **Throws**: * `Error` โ€” If the parsed content does not produce a valid `Element` when expecting an HTML structure. --- ### `TinyHtml.query(selector)` Finds the first element by CSS selector. - **Parameters**: - `selector` *(string)* โ€” CSS selector - **Returns**: `TinyHtml` or `null` --- ### `TinyHtml.queryAll(selector)` Finds all elements by CSS selector. - **Returns**: `TinyHtml` --- ### `TinyHtml.getById(selector)` Selects an element by ID. - **Parameters**: - `selector` *(string)* โ€” Id selector - **Returns**: `TinyHtml` or `null` --- ### `TinyHtml.getByClassName(selector)` Finds elements by class name. - **Returns**: `TinyHtml` --- ### `TinyHtml.getByName(selector)` Finds elements by `name` attribute. - **Returns**: `TinyHtml` --- ### `TinyHtml.getByTagNameNS(localName, namespaceURI?)` Finds elements by tag name in a namespace (defaults to XHTML). - **Returns**: `TinyHtml` --- ## ๐Ÿ“‘ HTML Parser ### Type Definition A parsed HTML element represented as an array: ```ts type HtmlParsed = [ tagName: string, // e.g., 'div', 'span', 'img' attributes: Record<string, string>, // Key-value map of all element attributes ...children: (string | HtmlParsed)[] // Nested elements or text content ]; ``` --- ### `fetchHtmlFile(url, ops?)` Fetches an HTML file from a URL and parses it into a JSON-like structure. ```ts static async fetchHtmlFile(url: string | URL | Request, ops?: RequestInit): Promise<HtmlParsed[]> ``` * **url**: The URL of the HTML file. * **ops**: (Optional) `fetch()` options (method, headers, etc). * **Returns**: Promise of parsed JSON structure (`HtmlParsed[]`). * Throws if content-type is not `text/html`. --- ### `fetchHtmlNodes(url, ops?)` Fetches an HTML file and returns it as DOM nodes. ```ts static async fetchHtmlNodes(url: string, ops?: RequestInit): Promise<(HTMLElement | Text)[]> ``` * **Returns**: Array of real DOM nodes (`HTMLElement | Text`). --- ### `fetchHtmlTinyElems(url, ops?)` Fetches HTML and converts it into an array of `TinyHtml` instances. ```ts static async fetchHtmlTinyElems(url: string, ops?: RequestInit): Promise<TinyHtml[]> ``` * **Returns**: `TinyHtml[]` (custom wrapper elements). --- ### `templateToJson(template)` Converts the contents of a `<template>` to JSON format. ```ts static templateToJson(template: HTMLTemplateElement): HtmlParsed[] ``` * **Returns**: Structured JSON representation (`HtmlParsed[]`). --- ### `templateToNodes(template)` Converts `<template>` content into real DOM nodes. ```ts static templateToNodes(template: HTMLTemplateElement): (Element | Text)[] ``` * **Returns**: Cloned nodes excluding comments. * Throws error if unexpected node types are encountered. --- ### `templateToTinyElems(template)` Converts a `<template>` into `TinyHtml` instances. ```ts static templateToTinyElems(template: HTMLTemplateElement): TinyHtml[] ``` * **Returns**: Array of `TinyHtml` objects. --- ### `htmlToJson(htmlString)` Parses an HTML string into structured JSON (`HtmlParsed[]`). ```ts static htmlToJson(htmlString: string): HtmlParsed[] ``` * **Returns**: Parsed representation as an array of `[tag, attributes, ...children]`. --- ### `jsonToNodes(jsonArray)` Converts parsed JSON back into actual DOM nodes. ```ts static jsonToNodes(jsonArray: HtmlParsed[]): (HTMLElement | Text)[] ``` * **Returns**: Array of DOM elements/text nodes. * Skips comments. --- ### `jsonToTinyElems(jsonArray)` Converts parsed JSON back into `TinyHtml` instances. ```ts static jsonToTinyElems(jsonArray: HtmlParsed[]): TinyHtml[] ``` * **Returns**: TinyHtml-wrapped elements. --- ๐Ÿ’ก **Tip**: All conversion methods rely on a consistent internal format (`HtmlParsed[]`). That means you can seamlessly switch between representations (JSON โ‡„ DOM โ‡„ TinyHtml)! --- ## ๐Ÿงฉ Internal Element Access ### `exists(index)` Checks whether the element exists at the given index. - **Returns**: `boolean` --- ### `get(index)` Returns the raw DOM element associated with this instance. - **Returns**: `ConstructorElValues` --- ### `size` Returns the number of elements currently stored in the internal element list. - **Returns**: `number` --- ### `extract(index)` Extracts a single DOM element from the internal list at the specified index. - **Returns**: `TinyHtml` --- ### `getAll()` Returns the current targets held by this instance. - **Returns**: `ConstructorElValues[]` --- ### `_getElement(where, index)` Safely returns the element with error checking. --- ### `_getElements(where)` Returns the current Elements held by this instance. --- ## ๐Ÿ› ๏ธ Static Pre-Validation Utilities These methods normalize, validate, and prepare elements/nodes before operations. They're internal and mainly used inside the class. ### General Templates #### `_preElemsTemplate(...)` Validates an array of elements against allowed constructors. #### `_preElemTemplate(...)` Validates a single element, optionally allowing `null`. --- ### Common Validators Each method below ensures type and returns raw DOM objects: | Method | Target Type | Return | |-------------------------------|------------------|----------------| | `_preElems(...)` | `Element[]` | `Element[]` | | `_preElem(...)` | `Element` | `Element` | | `_preNodeElems(...)` | `Node[]` | `Node[]` | | `_preNodeElem(...)` | `Node` | `Node` | | `_preNodeElemWithNull(...)` | `Node\|null` | `Node\|null` | | `_preHtmlElems(...)` | `HTMLElement[]` | `HTMLElement[]`| | `_preHtmlElem(...)` | `HTMLElement` | `HTMLElement` | | `_preInputElems(...)` | `InputElement[]` | `InputElement[]` | | `_preInputElem(...)` | `InputElement` | `InputElement` | | `_preEventTargetElems(...)` | `EventTarget[]` | `EventTarget[]`| | `_preEventTargetElem(...)` | `EventTarget` | `EventTarget` | | `_preElemsAndWindow(...)` | `Element\|Window` | `ElementAndWindow[]` | | `_preElemAndWindow(...)` | `Element\|Window` | `ElementAndWindow` | | `_preElemsAndWinAndDoc(...)` | `Element\|Window\|Document` | `ElementAndWindow[]` | | `_preElemAndWinAndDoc(...)` | `Element\|Window\|Document` | `ElementAndWindow` | | `_preElemsWithDoc(...)` | `Element\|Document` | `ElementWithDoc[]` | | `_preElemWithDoc(...)` | `Element\|Document` | `ElementWithDoc` | --- ## ๐Ÿ” Conversion Helpers These methods convert between raw DOM and `TinyHtml` instances. ### `TinyHtml.toTinyElm(elems)` Converts one or more raw elements or `TinyHtml` instances into `TinyHtml[]`. ```ts TinyHtml.toTinyElm(Element | TinyHtml | Array<Element | TinyHtml>) => TinyHtml[] ``` --- ### `TinyHtml.fromTinyElm(elems)` Extracts native `Element`s from `TinyHtml` instances. ```ts TinyHtml.fromTinyElm(Element | TinyHtml | Array<Element | TinyHtml>) => Element[] ``` --- ## ๐Ÿงน Element Filtering & Matching This section contains utilities for filtering, matching, and traversing DOM elements using selectors, functions, or references. --- ### ๐ŸŽฏ `TinyHtml.winnow(...)` Advanced filtering engine used internally by many other methods. - **Parameters**: - `elems`: Elements to filter. - `qualifier`: A selector, function, DOM element, or array of them. - `where`: Context string for debugging. - `not`: If `true`, invert the match. - **Returns**: `Element[]` --- ### ๐Ÿ” Static Filter Utilities #### `TinyHtml.filter(...)` Filters elements based on a selector (with optional negation). #### `TinyHtml.filterOnly(...)` Same as `.filter()`, but calls `winnow()` directly without the `not` flag. #### `TinyHtml.not(...)` Excludes elements matching the qualifier. #### `TinyHtml.is(...)` Returns `true` if at least one element matches the qualifier. #### `TinyHtml.has(...)` Returns elements that contain a given child (selector or element). #### `TinyHtml.closest(...)` Finds the nearest ancestor matching a selector, optionally stopping at a context. --- ### ๐Ÿ“ฆ Instance Filter Methods #### `.not(selector)` Returns all current elements excluding the ones that match. #### `.is(selector)` Checks if the current element matches the selector or qualifier. #### `.has(target)` Returns `true` if the current element contains the given target. #### `.find(selector)` Finds matching elements inside the current element. #### `.closest(selector, context?)` Finds the closest ancestor (including self) matching a selector or specific element. #### `.isSameDom(elem)` Checks if the given element is exactly the same DOM node (`===`). --- ## ๐Ÿ’พ Element Data Store TinyHtml supports storing arbitrary data on elements, either *publicly* or *privately*. --- ### ๐Ÿ”’ Internal Data System ```ts static _dataSelector = { public: (where, el) => { ... }, private: (where, el) => { ... }, }; ``` * `public`: Data stored in a `WeakMap` attached to DOM nodes. * `private`: Data stored in an internal property of the `TinyHtml` instance. --- ### ๐Ÿ—ƒ๏ธ Static Methods #### `TinyHtml.data(el, key?, isPrivate?)` Gets data from the element. * **Returns**: Entire data object (if `key` omitted) or a single value. #### `TinyHtml.setData(el, key, value, isPrivate?)` Sets a value on the elementโ€™s data store. --- ### ๐Ÿ“Œ Instance Methods #### `.data(key?, isPrivate?)` Shortcut for getting data from the current instanceโ€™s element. #### `.setData(key, value, isPrivate?)` Shortcut for setting data on the current element. --- ## ๐Ÿ”„ DOM Traversal Methods Navigate through the DOM tree easily: siblings, parents, children, and more. --- ### ๐ŸŒฑ `.parent()` / `TinyHtml.parent(...)` Gets the **direct parent** of the element (ignores fragments). --- ### ๐ŸŒณ `.parents(until?)` / `TinyHtml.parents(...)` Collects all ancestor elements (like `.closest()`, but goes all the way up). Stops before `until`, if provided. --- ### โ†•๏ธ Sibling Navigation #### `.next()` / `TinyHtml.next(...)` Returns the next sibling (ignoring non-element nodes). #### `.prev()` / `TinyHtml.prev(...)` Returns the previous sibling (ignoring non-element nodes). #### `.nextAll()` / `TinyHtml.nextAll(...)` All siblings after the current element. #### `.prevAll()` / `TinyHtml.prevAll(...)` All siblings before the current element. #### `.nextUntil(until)` / `TinyHtml.nextUntil(...)` All next siblings **up to (not including)** a matching selector or element. #### `.prevUntil(until)` / `TinyHtml.prevUntil(...)` All previous siblings **up to (not including)** a matching selector or element. --- ### ๐Ÿง `.siblings()` / `TinyHtml.siblings(...)` All siblings of the element **excluding itself**. --- ### ๐Ÿ‘ถ `.children()` / `TinyHtml.children(...)` All child nodes (elements only) of the element. --- ### ๐Ÿงฉ `.contents()` / `TinyHtml.contents(...)` Returns the contents of the element: - For `<template>`, returns its content. - For `<iframe>`, returns the `contentDocument`. - Otherwise, returns its child nodes. --- ### ๐Ÿ“‹ `.clone(deep = true)` / `TinyHtml.clone(...)` Clones the current element (or a list of elements). - If `deep` is `true` (default), clones all children too. - Returns an array from static, or a single node from instance. --- ### ๐Ÿ›  Internal Utilities These aren't usually called directly by users, but power most traversal: - `TinyHtml._getSibling(el, direction)` - Gets the next/previous sibling that's an element. - `TinyHtml._getSiblings(start, exclude)` - Returns all element siblings from a starting point (optionally excluding one). - `TinyHtml.domDir(el, direction, until)` - Traverses in any direction (parent, next, previous), optionally until a selector or element. --- ## ๐Ÿงฑ DOM Manipulation Methods to insert, move, or replace nodes in the DOM โ€” just like jQuery, but tiny and classy โœจ --- ### `.append(...children)` / `TinyHtml.append(el, ...children)` Appends one or more nodes or strings to the end of the selected element. ```js element.append('hello', otherEl); ``` --- ### `.prepend(...children)` / `TinyHtml.prepend(el, ...children)` Prepends one or more nodes or strings to the beginning of the selected element. --- ### `.before(...children)` / `TinyHtml.before(el, ...children)` Inserts content **before** the selected element in the DOM. --- ### `.after(...children)` / `TinyHtml.after(el, ...children)` Inserts content **after** the selected element in the DOM. --- ### `.replaceWith(...newNodes)` / `TinyHtml.replaceWith(el, ...newNodes)` Replaces the element with one or more new nodes or strings. --- ### `.appendTo(targets)` / `TinyHtml.appendTo(el, targets)` Appends the element to one or more target containers. * If multiple targets are provided, the element is cloned. * Think: `$(el).appendTo(targets)` from jQuery. --- ### `.prependTo(targets)` / `TinyHtml.prependTo(el, targets)` Prepends the element to each of the target containers (cloning when needed). --- ### `.insertBefore(target, child?)` / `TinyHtml.insertBefore(el, target, child?)` Inserts the element **before** a target element or its specific child. * If `child` is provided, it is inserted before the child. * Otherwise, it goes before the target. --- ### `.insertAfter(target, child?)` / `TinyHtml.insertAfter(el, target, child?)` Inserts the element **after** a target element or its specific child. --- ### `.replaceAll(targets)` / `TinyHtml.replaceAll(el, targets)` Replaces all target elements with the current element(s). * When multiple targets are passed, clones the source accordingly. --- ### ๐Ÿงฐ Internal Util #### `_appendChecker(where, ...nodes)` Normalizes and converts input (elements, arrays, or strings) into appendable DOM nodes. > ๐Ÿ“Œ Used internally by all `append`/`prepend`/`before`/`after` methods to ensure safe insertion. --- ## ๐Ÿงฎ Easing Functions ### `TinyHtml.easings` A collection of predefined easing functions used for scroll and animation calculations. Each easing function takes a normalized time (`t` from 0 to 1) and returns a transformed progress value. | Name | Description | | ---------------- | ------------------------------------- | | `linear` | Constant speed, no easing. | | `easeInQuad` | Accelerates from zero velocity. | | `easeOutQuad` | Decelerates to zero velocity. | | `easeInOutQuad` | Accelerates, then decelerates. | | `easeInCubic` | Starts slow, speeds up sharply. | | `easeOutCubic` | Starts fast, slows down gradually. | | `easeInOutCubic` | Smooth acceleration and deceleration. | ```ts type Easings = | 'linear' | 'easeInQuad' | 'easeOutQuad' | 'easeInOutQuad' | 'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic'; ``` ```ts TinyHtml.easings = { linear: (t) => t, easeInQuad: (t) => t * t, easeOutQuad: (t) => t * (2 - t), easeInOutQuad: (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t), easeInCubic: (t) => t * t * t, easeOutCubic: (t) => --t * t * t + 1, easeInOutCubic: (t) => (t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1), }; ``` --- ## ๐Ÿงญ Smooth Scrolling ### `TinyHtml.scrollToXY(el, settings)` Smoothly scrolls one or more elements (or `window`) to a target position using a custom duration and easing. If no `duration` or invalid `easing` is provided, the scroll happens instantly. ```ts TinyHtml.scrollToXY(el, { targetX?: number, targetY?: number, duration?: number, easing?: Easings, }); ``` | Parameter | Type | Description | | -------------------- | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- | | `el` | `TinyElementAndWindow \| TinyElementAndWindow[]` | One or more elements or the `window` to scroll. | | `settings` | `Object` | Scroll configuration. | | `targetX` | `number` *(optional)* | Final horizontal scroll position. | | `targetY` | `number` *(optional)* | Final vertical scroll position. | | `duration` | `number` *(optional)* | Duration of the scroll animation in milliseconds. | | `easing` | `Easings` *(optional)* | Name of easing function to control animation curve. | | `onAnimation` | `OnScrollAnimation` *(optional)* | Optional callback invoked on each animation frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag. | --- ## โš™๏ธ Internal Scroll Mechanism When called, `scrollToXY()` performs: 1. **Start Position Detection** โ€“ Gets current scroll positions. 2. **Delta Calculation** โ€“ Calculates the distance to scroll. 3. **Easing Evaluation** โ€“ Determines the easing curve to use. 4. **Scroll Loop** โ€“ Uses `requestAnimationFrame` to animate over time. 5. **Instant Scroll Fallback** โ€“ If no easing/duration is defined, scrolls instantly. ```ts function executeScroll(elem, newX, newY) { if (elem instanceof Window) { window.scrollTo(newX, newY); } else if (elem.nodeType === 9) { elem.defaultView.scrollTo(newX, newY); // For documents } else { if (elem.scrollLeft !== newX) elem.scrollLeft = newX; if (elem.scrollTop !== newY) elem.scrollTop = newY; } } ``` --- ## ๐Ÿ“ Dimensions (Size API) TinyHtml provides methods to **read** and **set** an element's dimensions, similar to jQueryโ€™s width/height API, with support for box models: `content`, `padding`, `border`, and `margin`. --- ### ๐Ÿ” Reading Dimensions #### `.width()` / `TinyHtml.width(el)` Returns the **content box width** (excluding padding, border, and margin). #### `.height()` / `TinyHtml.height(el)` Returns the **content box height**. --- #### `.innerWidth()` / `TinyHtml.innerWidth(el)` Returns the **padding box width** (content + padding). #### `.innerHeight()` / `TinyHtml.innerHeight(el)` Returns the **padding box height**. --- #### `.outerWidth(includeMargin = false)` / `TinyHtml.outerWidth(el, includeMargin)` Returns the **border box width**, and optionally includes margin. #### `.outerHeight(includeMargin = false)` / `TinyHtml.outerHeight(el, includeMargin)` Returns the **border box height**, and optionally includes margin. --- #### `.getDimension(type, extra)` / `TinyHtml.getDimension(el, type, extra)` The underlying function used for all size getters. ```js // Example: element.getDimension('width', 'margin'); // Full box including margin ``` * `type`: `"width"` or `"height"` * `extra`: `"content"`, `"padding"`, `"border"`, `"margin"` --- ### โœ๏ธ Setting Dimensions #### `.setWidth(value)` / `TinyHtml.setWidth(el, value)` Sets the `width` of the element. ```js el.setWidth(100); // Sets width to 100px el.setWidth("50%"); // Sets width to 50% ``` --- #### `.setHeight(value)` / `TinyHtml.setHeight(el, value)` Sets the `height` of the element. ```js el.setHeight("10rem"); ``` --- ## ๐Ÿ“Œ Position, Scroll & Box Spacing This API set focuses on **measuring element offsets**, **scroll positions**, and **box sides** such as padding, margin, and border. It helps you understand where an element is and how much space it takes. --- ### ๐Ÿ“ Element Positioning #### `.animate(keyframes, ops?)` / `TinyHtml.animate(el, keyframes, ops?)` Applies an animation to one or more TinyElement instances using the Web Animations API. #### `.offset()` / `TinyHtml.offset(el)` Returns the coordinates `{ top, left }` of the element **relative to the document**. #### `.position()` / `TinyHtml.position(el)` Returns the position **relative to the offset parent**, excluding margins. #### `.offsetParent()` / `TinyHtml.offsetParent(el)` Returns the nearest ancestor that has a position other than `static`. Useful for relative positioning logic. --- ### ๐Ÿ”ƒ Scroll Position #### `.scrollTop()` / `TinyHtml.scrollTop(el)` Returns the vertical scroll position of the element or window. #### `.scrollLeft()` / `TinyHtml.scrollLeft(el)` Returns the horizontal scroll position of the element or window. #### `.setScrollTop(value)` / `TinyHtml.setScrollTop(el, value)` Sets the vertical scroll position. #### `.setScrollLeft(value)` / `TinyHtml.setScrollLeft(el, value)` Sets the horizontal scroll position. ```js element.setScrollTop(100); // Scrolls down 100px window.setScrollLeft(50); // Scrolls the window horizontally ``` --- ### ๐Ÿ“ฆ Box Model Sides (Padding, Margin, Border) All methods return an object of the form: ```js { x: number, // Horizontal total (left + right) y: number, // Vertical total (top + bottom) left: number, right: number, top: number, bottom: number } ``` #### `.margin()` / `TinyHtml.margin(el)` Returns the margin size on all four sides. #### `.padding()` / `TinyHtml.padding(el)` Returns the padding size on all four sides. #### `.borderWidth()` / `TinyHtml.borderWidth(el)` Returns the border width (as in CSS `border-width`) on all sides. #### `.border()` / `TinyHtml.border(el)` Returns the full border value (`borderLeft`, `borderTop`, etc.) on all sides. Rarely needed unless youโ€™re working with composite CSS values. --- ## ๐ŸŽจ Class Manipulation These methods help you add, remove, toggle, and inspect class names applied to elements. All class-related operations use the native `classList` interface under the hood. --- ### โž• `.addClass(...classNames)` / `TinyHtml.addClass(el, ...classNames)` Adds one or more class names to the element. ```js element.addClass("highlight", "bold"); ``` --- ### โž– `.removeClass(...classNames)` / `TinyHtml.removeClass(el, ...classNames)` Removes one or more class names from the element. ```js element.removeClass("highlight"); ``` --- ### ๐Ÿ” `.replaceClass(oldClass, newClass)` / `TinyHtml.replaceClass(el, oldClass, newClass)` Replaces one class with another. Returns `true` if the replacement occurred. ```js element.replaceClass("old", "new"); ``` --- ### โ“ `.hasClass(className)` / `TinyHtml.hasClass(el, className)` Checks if the element has a specific class. ```js element.hasClass("active"); // โ†’ true / false ``` --- ### ๐Ÿ”ƒ `.toggleClass(className, [force])` / `TinyHtml.toggleClass(el, className, [force])` Toggles a class on or off. If `force` is given: * `true`: ensures the class is added. * `false`: ensures the class is removed. Returns whether the class is present **after** the toggle. ```js element.toggleClass("visible"); element.toggleClass("enabled", true); // Force add ``` --- ### ๐Ÿ”ข `.classLength()` / `TinyHtml.classLength(el)` Returns the number of classes applied to the element. ```js const count = element.classLength(); // โ†’ 3 ``` --- ### ๐Ÿ” `.classItem(index)` / `TinyHtml.classItem(el, index)` Gets the class name at a specific index in the class list. ```js element.classItem(0); // โ†’ "highlight" ``` --- ### ๐Ÿ“‹ `.classList()` / `TinyHtml.classList(el)` Returns all class names as an array. ```js element.classList(); // โ†’ ["highlight", "bold", "selected"] ``` --- ## ๐Ÿ“„ Content & Element Info These methods let you get or set basic element info like tag name, ID, text content, or HTML content. Useful for reading or updating elements without dealing directly with DOM properties. --- ### ๐Ÿท `.tagName()` / `TinyHtml.tagName(el)` Returns the uppercase tag name of the element. ```js element.tagName(); // โ†’ "DIV", "SPAN", etc. ``` --- ### ๐Ÿ†” `.id()` / `TinyHtml.id(el)` Returns the ID attribute value of the element. ```js element.id(); // โ†’ "my-element-id" ``` --- ### ๐Ÿ“ `.text()` / `TinyHtml.text(el)` Gets the text content of the element (returns `null` if none). ```js element.text(); // โ†’ "Hello world" ``` --- ### โœ๏ธ `.setText(value)` / `TinyHtml.setText(el, value)` Sets the text content of one or more elements. Throws if `value` is not a string. ```js element.setText("New text content"); ``` --- ### ๐Ÿงน `.empty()` / `TinyHtml.empty(el)` Removes all child nodes (clears content) from one or more elements. ```js element.empty(); ``` --- ### ๐Ÿ” `.html(ops?)` / `TinyHtml.html(el, ops?)` Gets the `innerHTML` string of the element. * `ops?`: GetHTMLOptions from native DOM. ```js element.html(); // โ†’ "<p>Some HTML content</p>" ``` --- ### ๐Ÿ›  `.setHtml(value)` / `TinyHtml.setHtml(el, value)` Sets the `innerHTML` of one or more elements. Throws if `value` is not a string. ```js element.setHtml("<strong>Bold text</strong>"); ``` --- ## ๐ŸŽ›๏ธ Form Value Handling & Input Hooks This section handles reading and writing values for form controls (`input`, `select`, `option`, `checkbox`, `radio`, etc.) with support for custom hooks to manage special cases seamlessly. --- ### ๐Ÿช `_valHooks` Internal value hooks for form controls - **option**: Gets the option value or fallback to text. - **select**: Handles single/multiple select value getting/setting. - **radio**: Gets `'on'`/`'off'` based on checked state; sets checked with unchecking siblings. - **checkbox**: Similar to radio, manages checked state. These hooks ensure form controls behave consistently across different types. --- ### ๐ŸŽฏ `.setVal(el, value)` / `.setVal(value)` Sets the value(s) of input/select/textarea elements. Supports strings, numbers, booleans, arrays, or a callback returning these. Throws if value is invalid or unsupported. ```js element.setVal("hello"); element.setVal(["option1", "option2"]); element.setVal((el, currentVal) => currentVal + " updated"); ``` --- ### ๐Ÿ” `.val(el)` / `.val()` Gets the normalized string value from an input/select element. Strips carriage returns and handles hooks automatically. --- ### โœ๏ธ `.valTxt(el)` / `.valTxt()` Gets the text string value, throwing if the value is not string-compatible. --- ### ๐Ÿงฎ `.valNb(el)` / `.valNb()` Gets the value parsed as a number. Throws if value is `NaN` or element incompatible. --- ### ๐Ÿ“… `.valDate(el)` / `.valDate()` Gets the value parsed as a `Date` object. Throws if value is invalid or element incompatible. --- ### โœ”๏ธ `.valBool(el)` / `.valBool()` Returns boolean state for checkboxes/radios based on value `"on"` or `"off"`. --- ### ๐Ÿงฉ Internal helpers: * `_valTypes`: Map of functions to get typed values (string, date, number). * `_getValByType`: Get typed value from element with validation. * `_val`: Core value getter that uses hooks or falls back to `_valTypes`. * `_valArr`: Ensures the returned value is an array (for multi-selects). --- ## ๐ŸŽ‰ Event Handling These methods allow you to easily register, remove, or trigger DOM events. All event listeners are tracked in a private registry for full control. --- ### ๐Ÿ“‹ `listenForPaste()` Handling Pasted Files and Text ```js element.listenForPaste({ onFilePaste(item, file) { console.log("Pasted file:", file.name); }, onTextPaste(item, text) { console.log("Pasted text:", text); }, }); ``` Registers a listener for the `"paste"` event to extract files or plain text directly from the clipboard. * `onFilePaste(item, file)` โ€“ Triggered once for each file pasted (e.g., images or documents). * `onTextPaste(item, text)` โ€“ Triggered when plain text is pasted. Use this to build file dropzones, rich editors, or custom paste behavior. You can also use the static version for multiple elements: ```js TinyHtml.listenForPaste([el1, el2], { onFilePaste(item, file) { console.log("Pasted a file into multiple elements!"); } }); ``` Returns the internal paste handler function. --- ### ๐Ÿ“ก `hasEventListener()` Checking for Event Presence ```js if (element.hasEventListener("click")) { console.log("Click handler already registered."); } ``` Checks whether any handler is currently registered on `__eventRegistry` for the given event name on an element. * Returns `true` if any listener exists for the event, otherwise `false`. Also available as a static version: ```js TinyHtml.hasEventListener(el, "paste"); ``` --- ### ๐ŸŽฏ `hasExactEventListener()` Checking for a Specific Handler ```js function onClick() {} element.on("click", onClick); if (element.hasExactEventListener("click", onClick)) { console.log("The exact click handler is registered."); } ``` Checks whether an element has **that exact function** registered on `__eventRegistry` for the given event. * Returns `true` only if the same reference to the function is found. * Helps prevent duplicate listeners or for conditional removal logic. Also available as a static version: ```js TinyHtml.hasExactEventListener(el, "click", onClick); ``` --- ### ๐Ÿ“ฅ `on()` / `once()` Registering Events ```js element.on("click", (e) => console.log("Clicked!")); element.once("mouseenter", () => console.log("Hovered just once!")); ``` * `on`: Attaches a persistent event listener. * `once`: Attaches a listener that auto-removes after its first trigger. You can also use the static versions for multiple elements. --- ### โŒ `off()` / `offAll()` / `offAllTypes()` Removing Events ```js element.off("click", myHandler); element.offAll("mouseover"); element.offAllTypes((handler, event) => event.startsWith("key")); ``` * `off`: Removes a specific listener. * `offAll`: Removes all listeners of a given type. * `offAllTypes`: Removes all listeners of all types, optionally filtered. These methods ensure clean teardown of events and prevent memory leaks. --- ### ๐Ÿš€ `trigger()` Triggering Events ```js element.trigger("click"); element.trigger("customEvent", { detail: "๐Ÿ”ฅ data!" }); ``` Simulates a user-triggered event. Supports native and custom events with optional payload. --- ## ๐Ÿงฌ Attribute & Property Manipulation Use these helpers to interact with standard DOM attributes or element properties with added safety and normalization. --- ### ๐Ÿท๏ธ `.attr()` / `.setAttr()` / `.removeAttr()` / `.hasAttr()` Attributes ```js element.attr("href"); // Get element.setAttr("title", "Cool!"); // Set element.removeAttr("data-test"); // Remove element.hasAttr("id"); // Check ``` Works on both single and multiple elements (static or instance). Safe and type-checked โ€” throws if misuse is detected. --- ### ๐Ÿงฒ `.hasProp()` / `.addProp()` / `.removeProp()` / `.toggleProp()` Properties ```js element.hasProp("disabled"); // true/false element.addProp("checked"); // set true element.removeProp("checked"); // set false element.toggleProp("disabled"); // flip element.toggleProp("readonly", true); // force enable ``` These methods interact with real DOM properties (not just attributes). Includes jQuery-style `propFix` (e.g., `"for"` โ†’ `"htmlFor"`). --- ## ๐Ÿ› ๏ธ Element Utilities --- ### ๐Ÿ’จ `.remove()` Remove from DOM ```js element.remove(); ``` Removes the selected element(s) from the document. Also available in static form: `TinyHtml.remove(el)`. --- ### ๐Ÿ”ข `.index()` Element Index ```js element.index(); // Get index among siblings element.index(".some-class"); // Get index relative to a selector ``` Returns the index of the current element: * Among its siblings (default) * Or relative to a given selector or list of elements. --- ## ๐Ÿ“ฆ Collision Detection Useful for game dev, UI constraints, dragging logic, etc. --- ### ๐Ÿ“ `.isCollWith()` Bounding Box Collision ```js element1.isCollWith(element2); element1.isCollWith(element2, { top: 5, left: 5 }); ``` Checks for overlap between bounding boxes of two elements. You can also extend the size of `element1`'s box using `extraRect`. --- ### ๐ŸŽฏ `.isCollPerfWith()` Pixel-Perfect Collision ```js element1.isCollPerfWith(element2); ``` Uses a higher-precision algorithm (like real pixel collision), ideal for: * Tight hitboxes * Game-like interactions * Avoiding false positives near edges --- ## ๐Ÿ” Collision Locking System Maintains a collision "state lock" until the element exits the target from a specific side. --- ### ๐Ÿ”„ `.isCollWithLock()` Lock Until Exit (Bounding Box) ```js element1.isCollWithLock(element2, "top"); ``` Locks the collision detection to a **direction**: * `top`, `bottom`, `left`, `right` ๐Ÿ”„ It keeps the state `true` until the element exits through the same side it entered. --- ### ๐Ÿ”ฌ `.isCollPerfWithLock()` Lock Until Exit (Pixel-Precise) ```js element1.isCollPerfWithLock(element2, "left", { left: 10 }); ``` Just like `.isCollWithLock()`, but with pixel-precision. --- ## ๐Ÿงผ Collision Lock Reset Clear collision lock state to restart fresh. --- ### ๐Ÿ” `.resetCollLock()` Reset All Directions ```js element.resetCollLock(); ``` Clears **all directional locks** for the element. --- ### โฌ…๏ธ `.resetCollLockDir()` Reset One Direction ```js element.resetCollLockDir("right"); ``` Resets a **specific direction** lock. --- ## ๐Ÿ‘๏ธ Viewport Detection Easily detect whether an element is partially or fully visible inside the browser window. --- ### ๐Ÿ‘€ `.isInViewport()` Partially Visible ```js element.isInViewport(); ``` Checks if the element is **at least partially** visible in the current viewport. #### โœ… Use when: * You want to trigger animations when an element **starts entering** the screen. * Detect lazy loading or partial exposure of banners, sections, etc. #### ๐Ÿ” Logic: * Compares the elementโ€™s **top and bottom** against the **viewportโ€™s top and bottom**. * Returns `true` if **any portion** of the element is inside the viewport. #### ๐Ÿ” Static version: ```js TinyHtml.isInViewport(element); ``` --- ### ๐Ÿ“ `.isScrolledIntoView()` Fully Visible ```js element.isScrolledIntoView(); ``` Checks if the element is **fully inside** the viewport โ€” meaning: * Its **top is not above** the screen * Its **bottom is not below** the screen #### โœ… Use when: * You want to detect **full visibility** before triggering something (e.g., playing a video). * Ensuring an element is **100% onscreen** before acting on it. #### ๐Ÿ” Logic: * Measures if the element's **entire height** fits between `scrollTop` and `scrollTop + window height`. #### ๐Ÿ” Static version: ```js TinyHtml.isScrolledIntoView(element); ``` --- ### ๐Ÿซฃ `.isInContainer(container)` Partially Visible in Container ```js element.isInContainer(container); ``` Checks if **any part** of the element is visible **inside the scrollable container** โ€” meaning: * It **overlaps** the visible area of the container. * At least part of it is within the containerโ€™s viewport. #### โœ… Use when: * You want to detect if an element is **partially scrolled into view**. * Useful for triggering **lazy loading**, **animations**, or **UI changes** when something starts to appear. #### ๐Ÿ” Logic: * It compares the element's `getBoundingClientRect()` with the containerโ€™s. * Ensures there's **some overlap**, vertically or horizontally. #### ๐Ÿ” Static version: ```js TinyHtml.isInContainer(element, container); ``` --- ### โœ… `.isFullyInContainer(container)` Fully Visible in Container ```js element.isFullyInContainer(container); ``` Checks if the element is **completely visible** inside the scrollable container โ€” meaning: * **Top and bottom** of the element are within the container. * **Left and right** are also inside the containerโ€™s boundaries. #### โœ… Use when: * You want to detect if an element is **entirely inside** its scrollable container. * Useful for triggering **lazy loading**, **animations**, or **UI changes** when something starts to appear. #### ๐Ÿ” Logic: * It compares the full bounding box of the element to the container's. * All four edges must be within bounds to return `true`. #### ๐Ÿ” Static version: ```js TinyHtml.isFullyInContainer(element, container); ``` --- ### โœ… `.hasScroll()` Detect Scrollability in Any Direction ```js element.hasScroll(); ``` Checks if the element has **scrollable content** in either vertical or horizontal direction. Returns: ```js { v: true|false, h: true|false } ``` Where: * `v` = vertical scroll present * `h` = horizontal scroll present #### โœ… Use when: * You want to detect **whether an element needs scrollbars**. * Useful for adjusting layout, showing scroll indicators, or enabling custom scrolling behaviors. #### ๐Ÿ” Logic: * It compares the element's `scrollHeight` with `clientHeight` for vertical, * And `scrollWidth` with `clientWidth` for horizontal. * If content overflows in either direction, it returns `true` for that axis. #### ๐Ÿ” Static version: ```js TinyHtml.hasScroll(element); ``` --- ## ๐Ÿง  Property Name Normalization The object `TinyHtml.propFix` maps HTML attribute names (as strings) to their corresponding JavaScript DOM property names. This works similarly to jQueryโ€™s `propFix`. ```js TinyHtml.propFix['for']; // "htmlFor" TinyHtml.propFix['class']; // "className" ``` โš ๏ธ **Do not modify** the internal `#propFix` object directly. Instead, use `TinyHtml.propFix` (the public proxy) to ensure the reverse mapping in `TinyHtml.attrFix` stays in sync. ### โœ๏ธ Adding a New Property Mapping To add a new property normalization: ```js TinyHtml.propFix['readonly'] = 'readOnly'; ``` This will automatically make this available: ```js TinyHtml.attrFix['readOnly']; // "readonly" ``` --- ## ๐Ÿ” Attribute โ†” Property Mapping ### ๐Ÿงญ `TinyHtml.getPropName(name)` Normalizes an HTML attribute name to its corresponding DOM property name. ```js TinyHtml.getPropName('for'); // "htmlFor" TinyHtml.getPropName('class'); // "className" TinyHtml.getPropName('title'); // "title" (not mapped, returns input) ``` Useful when setting DOM properties programmatically. ### ๐Ÿงญ `TinyHtml.getAttrName(name)` Converts a DOM property name back to its equivalent HTML attribute name. ```js TinyHtml.getAttrName('htmlFor'); // "for" TinyHtml.getAttrName('className'); // "class" TinyHtml.getAttrName('title'); // "title" (not mapped, returns input) ``` Useful when serializing an element back to HTML or attributes. ### ๐Ÿ”„ Behind the Scenes * `TinyHtml.propFix` (public) is a proxy of the internal `#propFix` object. * `TinyHtml.attrFix` is auto-generated from `#propFix`, mapping values back in reverse. These mappings are kept **in sync automatically** whenever you assign a new property to `TinyHtml.propFix`. --- ## ๐ŸŽจ CSS Property Aliases (`cssPropAliases`) TinyHtml provides automatic conversion between `camelCase` and `kebab-case` style properties to simplify working with inline styles in HTML elements. This is useful for working with both JavaScript style names and the raw `style=""` attribute. ### ๐Ÿ” Alias Mapping The object `cssPropAliases` maps JavaScript-style property names (`camelCase`) to their CSS equivalents (`kebab-case`), for example: ```js TinyHtml.cssPropAliases.backgroundColor; // "background-color" ``` โš ๏ธ Do not modify the internal `#cssPropAliases` object directly. Instead, use the `TinyHtml.cssPropAliases` proxy. ### โœ๏ธ Adding a New Alias To add a new alias and automatically generate the reverse mapping: ```js TinyHtml.cssPropAliases.tinyPudding = 'tiny-pudding'; ``` This will automatically make this available: ```js TinyHtml.cssPropRevAliases['tiny-pudding']; // "tinyPudding" ``` --- ## โœ‚๏ธ Utility Functions ### ๐Ÿ”ก `TinyHtml.toStyleKc(str)` Converts a camelCase property to kebab-case if it exists in the alias list. ```js TinyHtml.toStyleKc('marginLeft'); // "margin-left" ``` ### ๐Ÿ”ก `TinyHtml.toStyleCc(str)` Converts a kebab-case property to camelCase if it exists in the reverse alias list. ```js TinyHtml.toStyleCc('font-weight'); // "fontWeight" ``` --- ## ๐Ÿงฉ Style Methods ### ๐ŸŽฏ `TinyHtml.setStyle(el, prop, value)` Sets one or more inline CSS properties on an element or a list of elements. ```js TinyHtml.setStyle(element, 'backgroundColor', 'blue'); TinyHtml.setStyle(element, { fontSize: '14px', color: 'white', }); ``` --- ### ๐Ÿ” `TinyHtml.getStyle(el, prop)` Returns the value of an inline style property (not computed). ```js TinyHtml.getStyle(element, 'backgroundColor'); // "blue" ``` --- ### ๐Ÿงพ `TinyHtml.style(el, settings = {})` Returns all inline styles defined directly on the element (`style` attribute), as an object. You can customize the output by passing an optional settings object: * `camelCase` (`boolean`, default `false`) โ€“ If `true`, property names will be returned in camelCase format. * `rawAttr` (`boolean`, default `false`) โ€“ If `true`, the raw `style` attribute string will be parsed manually instead of using the element's `style` object. #### โœ… Examples ```js TinyHtml.style(element, { rawAttr: true, camelCase: false }); // { // "background-color": "tomato", // "border-radius": "10px" // } TinyHtml.style(element, { rawAttr: true, camelCase: true }); // { // backgroundColor: "tomato", // borderRadius: "10px" // } TinyHtml.style(element, { rawAttr: false, camelCase: true }); // { // "backgroundColor":"tomato", // "borderTopLeftRadius":"10px", // "borderTopRightRadius":"10px", // "borderBottomRightRadius":"10px", // "borderBottomLeftRadius":"10px", // "borderTopStyle":"dashed", // "borderRightStyle":"dashed", // "borderBottomStyle":"dashed", // "borderLeftStyle":"dashed" // } ``` --- ### โŒ `TinyHtml.removeStyle(el, prop)` Removes one or more properties from an elementโ€™s inline styles. ```js TinyHtml.removeStyle(element, 'color'); TinyHtml.removeStyle(element, ['fontSize', 'padding']); ``` --- ### ๐Ÿ” `TinyHtml.toggleStyle(el, prop, val1, val2)` Toggles a CSS inline property between two values. ```js TinyHtml.toggleStyle(element, 'backgroundColor', 'blue', 'red'); ``` --- ### ๐Ÿงผ `TinyHtml.clearStyle(el)` Removes all inline styles (`style=""`) from the element(s). ```js TinyHtml.clearStyle(elemen