tiny-essentials 1.14.0 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/v1/TinyBasicsEs.js +4585 -270
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.js +4386 -471
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +4634 -242
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +4327 -0
- package/dist/v1/TinyHtml.min.js +1 -0
- package/dist/v1/TinyUploadClicker.js +4628 -246
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/basics/collision.cjs +413 -0
- package/dist/v1/basics/collision.d.mts +187 -0
- package/dist/v1/basics/collision.mjs +350 -0
- package/dist/v1/basics/html.cjs +5 -109
- package/dist/v1/basics/html.d.mts +2 -28
- package/dist/v1/basics/html.mjs +5 -91
- package/dist/v1/basics/html_deprecated.cjs +124 -0
- package/dist/v1/basics/html_deprecated.d.mts +40 -0
- package/dist/v1/basics/html_deprecated.mjs +97 -0
- package/dist/v1/basics/index.cjs +27 -5
- package/dist/v1/basics/index.d.mts +26 -6
- package/dist/v1/basics/index.mjs +4 -2
- package/dist/v1/build/TinyHtml.cjs +7 -0
- package/dist/v1/build/TinyHtml.d.mts +3 -0
- package/dist/v1/build/TinyHtml.mjs +2 -0
- package/dist/v1/index.cjs +29 -5
- package/dist/v1/index.d.mts +27 -6
- package/dist/v1/index.mjs +5 -2
- package/dist/v1/libs/TinyDragger.cjs +91 -16
- package/dist/v1/libs/TinyDragger.d.mts +78 -2
- package/dist/v1/libs/TinyDragger.mjs +93 -17
- package/dist/v1/libs/TinyHtml.cjs +3859 -0
- package/dist/v1/libs/TinyHtml.d.mts +2151 -0
- package/dist/v1/libs/TinyHtml.mjs +3457 -0
- package/docs/v1/README.md +2 -0
- package/docs/v1/basics/collision.md +237 -0
- package/docs/v1/basics/html.md +1 -105
- package/docs/v1/basics/html_deprecated.md +127 -0
- package/docs/v1/libs/TinyDragger.md +45 -15
- package/docs/v1/libs/TinyHtml.md +1333 -0
- package/package.json +8 -2
|
@@ -0,0 +1,1333 @@
|
|
|
1
|
+
# 📚 TinyHtml Class
|
|
2
|
+
|
|
3
|
+
`TinyHtml` is a lightweight utility class that provides DOM element manipulation and querying utilities, inspired by jQuery — but with modern native browser APIs.
|
|
4
|
+
|
|
5
|
+
It supports both static and instance-level operations, making it easy to work with elements' dimensions, collisions, and more in a readable, performant way.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🧩 Type Definitions – Core Building Blocks
|
|
10
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
### 🧱 Basic Types
|
|
16
|
+
|
|
17
|
+
#### `TinyNode`
|
|
18
|
+
Represents a raw `Node`, a `TinyHtml` instance, or `null`.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
Node | TinyHtml | null
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
#### `TinyElement`
|
|
27
|
+
|
|
28
|
+
Represents either a raw `Element` or a `TinyHtml` instance.
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
Element | TinyHtml
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
#### `TinyHtmlElement`
|
|
37
|
+
|
|
38
|
+
Alias for `HTMLElement | TinyHtml`.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
#### `TinyEventTarget`
|
|
43
|
+
|
|
44
|
+
Represents any event target element or a `TinyHtml` instance.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
EventTarget | TinyHtml
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
#### `TinyInputElement`
|
|
53
|
+
|
|
54
|
+
Used for form elements that can hold values (e.g., input, select).
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
InputElement | TinyHtml
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
#### `TinyElementAndWindow`
|
|
63
|
+
|
|
64
|
+
Accepts both raw DOM elements and the `window` object.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
ElementAndWindow | TinyHtml
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
### 🔀 Union Types
|
|
73
|
+
|
|
74
|
+
#### `ElementAndWindow`
|
|
75
|
+
|
|
76
|
+
Used for scrollable or measurable targets.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
Element | Window
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
#### `WinnowRequest`
|
|
85
|
+
|
|
86
|
+
Flexible type for querying or filtering elements:
|
|
87
|
+
|
|
88
|
+
* `string` (CSS selector)
|
|
89
|
+
* `Element`
|
|
90
|
+
* `Element[]`
|
|
91
|
+
* `(index: number, el: Element) => boolean`
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
#### `ConstructorElValues`
|
|
96
|
+
|
|
97
|
+
Values accepted by the TinyHtml constructor:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
Window | Element | Document
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### 🎯 Event System Types
|
|
106
|
+
|
|
107
|
+
#### `EventRegistryHandle`
|
|
108
|
+
|
|
109
|
+
A basic event listener handler function.
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
(e: Event) => any
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
#### `EventRegistryOptions`
|
|
118
|
+
|
|
119
|
+
Options for `addEventListener` and `removeEventListener`.
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
boolean | AddEventListenerOptions
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
#### `EventRegistryItem`
|
|
128
|
+
|
|
129
|
+
Describes an individual event registration.
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
{
|
|
133
|
+
handler: EventRegistryHandle,
|
|
134
|
+
options?: EventRegistryOptions
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
#### `EventRegistryList`
|
|
141
|
+
|
|
142
|
+
Maps event names (like `"click"`) to lists of `EventRegistryItem`.
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
Record<string, EventRegistryItem[]>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
#### `__eventRegistry`
|
|
151
|
+
|
|
152
|
+
A `WeakMap` that stores event listeners by element.
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
WeakMap<ConstructorElValues|EventTarget, EventRegistryList>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
### 💾 Element Data
|
|
161
|
+
|
|
162
|
+
#### `ElementDataStore`
|
|
163
|
+
|
|
164
|
+
A key-value storage associated with an element.
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
Record<string, *>
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
#### `__elementDataMap`
|
|
173
|
+
|
|
174
|
+
A `WeakMap` to hold internal data for DOM elements.
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
WeakMap<ConstructorElValues, ElementDataStore>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
### 💥 Collision System
|
|
183
|
+
|
|
184
|
+
#### `CollisionDirLock`
|
|
185
|
+
|
|
186
|
+
Directions supported for collision lock:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
'top' | 'bottom' | 'left' | 'right'
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
#### `__elemCollision`
|
|
195
|
+
|
|
196
|
+
Stores directional collision locks per element.
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
{
|
|
200
|
+
top: WeakMap<Element, true>,
|
|
201
|
+
bottom: WeakMap<Element, true>,
|
|
202
|
+
left: WeakMap<Element, true>,
|
|
203
|
+
right: WeakMap<Element, true>
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
### 📐 Box Size Utilities
|
|
210
|
+
|
|
211
|
+
#### `HtmlElBoxSides`
|
|
212
|
+
|
|
213
|
+
Describes an element’s box sizes.
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
{
|
|
217
|
+
x: number, // total horizontal (left + right)
|
|
218
|
+
y: number, // total vertical (top + bottom)
|
|
219
|
+
left: number,
|
|
220
|
+
right: number,
|
|
221
|
+
top: number,
|
|
222
|
+
bottom: number
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
### 🔢 Value Types
|
|
229
|
+
|
|
230
|
+
#### `SetValueBase`
|
|
231
|
+
|
|
232
|
+
Primitive types accepted for form inputs.
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
string | number | Date | boolean | null
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
#### `SetValueList`
|
|
241
|
+
|
|
242
|
+
A single value or list of values for input fields.
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
SetValueBase | SetValueBase[]
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
#### `GetValueTypes`
|
|
251
|
+
|
|
252
|
+
Supported return types for `.val()` operations:
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
'string' | 'date' | 'number'
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
#### `InputElement`
|
|
261
|
+
|
|
262
|
+
Supported form controls used by TinyHtml.
|
|
263
|
+
|
|
264
|
+
```ts
|
|
265
|
+
HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | HTMLOptionElement
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## 🔎 Static DOM Selectors
|
|
271
|
+
|
|
272
|
+
These methods wrap native DOM query methods and return results as `TinyHtml` instances for consistency.
|
|
273
|
+
|
|
274
|
+
### `TinyHtml.query(selector)`
|
|
275
|
+
Finds the first element by CSS selector.
|
|
276
|
+
|
|
277
|
+
- **Parameters**:
|
|
278
|
+
- `selector` *(string)* — CSS selector
|
|
279
|
+
- **Returns**: `TinyHtml`
|
|
280
|
+
- **Throws**: If no element is found.
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
### `TinyHtml.queryAll(selector)`
|
|
285
|
+
Finds all elements by CSS selector.
|
|
286
|
+
|
|
287
|
+
- **Returns**: `TinyHtml[]`
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
### `TinyHtml.getById(selector)`
|
|
292
|
+
Selects an element by ID.
|
|
293
|
+
|
|
294
|
+
- **Throws**: If no element is found.
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
### `TinyHtml.getByClassName(selector)`
|
|
299
|
+
Finds elements by class name.
|
|
300
|
+
|
|
301
|
+
- **Returns**: `TinyHtml[]`
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
### `TinyHtml.getByName(selector)`
|
|
306
|
+
Finds elements by `name` attribute.
|
|
307
|
+
|
|
308
|
+
- **Returns**: `TinyHtml[]`
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
### `TinyHtml.getByTagNameNS(localName, namespaceURI?)`
|
|
313
|
+
Finds elements by tag name in a namespace (defaults to XHTML).
|
|
314
|
+
|
|
315
|
+
- **Returns**: `TinyHtml[]`
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## 🧩 Internal Element Access
|
|
320
|
+
|
|
321
|
+
### `get()`
|
|
322
|
+
Returns the raw DOM element associated with this instance.
|
|
323
|
+
|
|
324
|
+
- **Returns**: `ConstructorElValues`
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
### `_getElement(where)`
|
|
329
|
+
Safely returns the element with error checking.
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## 🛠️ Static Pre-Validation Utilities
|
|
334
|
+
|
|
335
|
+
These methods normalize, validate, and prepare elements/nodes before operations. They're internal and mainly used inside the class.
|
|
336
|
+
|
|
337
|
+
### General Templates
|
|
338
|
+
|
|
339
|
+
#### `_preElemsTemplate(...)`
|
|
340
|
+
Validates an array of elements against allowed constructors.
|
|
341
|
+
|
|
342
|
+
#### `_preElemTemplate(...)`
|
|
343
|
+
Validates a single element, optionally allowing `null`.
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
### Common Validators
|
|
348
|
+
|
|
349
|
+
Each method below ensures type and returns raw DOM objects:
|
|
350
|
+
|
|
351
|
+
| Method | Target Type | Return |
|
|
352
|
+
|-------------------------------|------------------|----------------|
|
|
353
|
+
| `_preElems(...)` | `Element[]` | `Element[]` |
|
|
354
|
+
| `_preElem(...)` | `Element` | `Element` |
|
|
355
|
+
| `_preNodeElems(...)` | `Node[]` | `Node[]` |
|
|
356
|
+
| `_preNodeElem(...)` | `Node` | `Node` |
|
|
357
|
+
| `_preNodeElemWithNull(...)` | `Node\|null` | `Node\|null` |
|
|
358
|
+
| `_preHtmlElems(...)` | `HTMLElement[]` | `HTMLElement[]`|
|
|
359
|
+
| `_preHtmlElem(...)` | `HTMLElement` | `HTMLElement` |
|
|
360
|
+
| `_preInputElems(...)` | `InputElement[]` | `InputElement[]` |
|
|
361
|
+
| `_preInputElem(...)` | `InputElement` | `InputElement` |
|
|
362
|
+
| `_preEventTargetElems(...)` | `EventTarget[]` | `EventTarget[]`|
|
|
363
|
+
| `_preEventTargetElem(...)` | `EventTarget` | `EventTarget` |
|
|
364
|
+
| `_preElemsAndWindow(...)` | `Element\|Window` | `ElementAndWindow[]` |
|
|
365
|
+
| `_preElemAndWindow(...)` | `Element\|Window` | `ElementAndWindow` |
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
## 🔁 Conversion Helpers
|
|
370
|
+
|
|
371
|
+
These methods convert between raw DOM and `TinyHtml` instances.
|
|
372
|
+
|
|
373
|
+
### `TinyHtml.toTinyElm(elems)`
|
|
374
|
+
Converts one or more raw elements or `TinyHtml` instances into `TinyHtml[]`.
|
|
375
|
+
|
|
376
|
+
```ts
|
|
377
|
+
TinyHtml.toTinyElm(Element | TinyHtml | Array<Element | TinyHtml>) => TinyHtml[]
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
### `TinyHtml.fromTinyElm(elems)`
|
|
383
|
+
Extracts native `Element`s from `TinyHtml` instances.
|
|
384
|
+
|
|
385
|
+
```ts
|
|
386
|
+
TinyHtml.fromTinyElm(Element | TinyHtml | Array<Element | TinyHtml>) => Element[]
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
## 🧹 Element Filtering & Matching
|
|
392
|
+
|
|
393
|
+
This section contains utilities for filtering, matching, and traversing DOM elements using selectors, functions, or references.
|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+
### 🎯 `TinyHtml.winnow(...)`
|
|
398
|
+
|
|
399
|
+
Advanced filtering engine used internally by many other methods.
|
|
400
|
+
|
|
401
|
+
- **Parameters**:
|
|
402
|
+
- `elems`: Elements to filter.
|
|
403
|
+
- `qualifier`: A selector, function, DOM element, or array of them.
|
|
404
|
+
- `where`: Context string for debugging.
|
|
405
|
+
- `not`: If `true`, invert the match.
|
|
406
|
+
- **Returns**: `Element[]`
|
|
407
|
+
|
|
408
|
+
---
|
|
409
|
+
|
|
410
|
+
### 🔍 Static Filter Utilities
|
|
411
|
+
|
|
412
|
+
#### `TinyHtml.filter(...)`
|
|
413
|
+
Filters elements based on a selector (with optional negation).
|
|
414
|
+
|
|
415
|
+
#### `TinyHtml.filterOnly(...)`
|
|
416
|
+
Same as `.filter()`, but calls `winnow()` directly without the `not` flag.
|
|
417
|
+
|
|
418
|
+
#### `TinyHtml.not(...)`
|
|
419
|
+
Excludes elements matching the qualifier.
|
|
420
|
+
|
|
421
|
+
#### `TinyHtml.is(...)`
|
|
422
|
+
Returns `true` if at least one element matches the qualifier.
|
|
423
|
+
|
|
424
|
+
#### `TinyHtml.has(...)`
|
|
425
|
+
Returns elements that contain a given child (selector or element).
|
|
426
|
+
|
|
427
|
+
#### `TinyHtml.closest(...)`
|
|
428
|
+
Finds the nearest ancestor matching a selector, optionally stopping at a context.
|
|
429
|
+
|
|
430
|
+
---
|
|
431
|
+
|
|
432
|
+
### 📦 Instance Filter Methods
|
|
433
|
+
|
|
434
|
+
#### `.not(selector)`
|
|
435
|
+
Returns all current elements excluding the ones that match.
|
|
436
|
+
|
|
437
|
+
#### `.is(selector)`
|
|
438
|
+
Checks if the current element matches the selector or qualifier.
|
|
439
|
+
|
|
440
|
+
#### `.has(target)`
|
|
441
|
+
Returns `true` if the current element contains the given target.
|
|
442
|
+
|
|
443
|
+
#### `.find(selector)`
|
|
444
|
+
Finds matching elements inside the current element.
|
|
445
|
+
|
|
446
|
+
#### `.closest(selector, context?)`
|
|
447
|
+
Finds the closest ancestor (including self) matching a selector or specific element.
|
|
448
|
+
|
|
449
|
+
#### `.isSameDom(elem)`
|
|
450
|
+
Checks if the given element is exactly the same DOM node (`===`).
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
454
|
+
## 💾 Element Data Store
|
|
455
|
+
|
|
456
|
+
TinyHtml supports storing arbitrary data on elements, either *publicly* or *privately*.
|
|
457
|
+
|
|
458
|
+
---
|
|
459
|
+
|
|
460
|
+
### 🔒 Internal Data System
|
|
461
|
+
|
|
462
|
+
```ts
|
|
463
|
+
static _dataSelector = {
|
|
464
|
+
public: (where, el) => { ... },
|
|
465
|
+
private: (where, el) => { ... },
|
|
466
|
+
};
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
* `public`: Data stored in a `WeakMap` attached to DOM nodes.
|
|
470
|
+
* `private`: Data stored in an internal property of the `TinyHtml` instance.
|
|
471
|
+
|
|
472
|
+
---
|
|
473
|
+
|
|
474
|
+
### 🗃️ Static Methods
|
|
475
|
+
|
|
476
|
+
#### `TinyHtml.data(el, key?, isPrivate?)`
|
|
477
|
+
|
|
478
|
+
Gets data from the element.
|
|
479
|
+
|
|
480
|
+
* **Returns**: Entire data object (if `key` omitted) or a single value.
|
|
481
|
+
|
|
482
|
+
#### `TinyHtml.setData(el, key, value, isPrivate?)`
|
|
483
|
+
|
|
484
|
+
Sets a value on the element’s data store.
|
|
485
|
+
|
|
486
|
+
---
|
|
487
|
+
|
|
488
|
+
### 📌 Instance Methods
|
|
489
|
+
|
|
490
|
+
#### `.data(key?, isPrivate?)`
|
|
491
|
+
|
|
492
|
+
Shortcut for getting data from the current instance’s element.
|
|
493
|
+
|
|
494
|
+
#### `.setData(key, value, isPrivate?)`
|
|
495
|
+
|
|
496
|
+
Shortcut for setting data on the current element.
|
|
497
|
+
|
|
498
|
+
---
|
|
499
|
+
|
|
500
|
+
## 🔄 DOM Traversal Methods
|
|
501
|
+
|
|
502
|
+
Navigate through the DOM tree easily: siblings, parents, children, and more.
|
|
503
|
+
|
|
504
|
+
---
|
|
505
|
+
|
|
506
|
+
### 🌱 `.parent()` / `TinyHtml.parent(...)`
|
|
507
|
+
Gets the **direct parent** of the element (ignores fragments).
|
|
508
|
+
|
|
509
|
+
---
|
|
510
|
+
|
|
511
|
+
### 🌳 `.parents(until?)` / `TinyHtml.parents(...)`
|
|
512
|
+
Collects all ancestor elements (like `.closest()`, but goes all the way up).
|
|
513
|
+
Stops before `until`, if provided.
|
|
514
|
+
|
|
515
|
+
---
|
|
516
|
+
|
|
517
|
+
### ↕️ Sibling Navigation
|
|
518
|
+
|
|
519
|
+
#### `.next()` / `TinyHtml.next(...)`
|
|
520
|
+
Returns the next sibling (ignoring non-element nodes).
|
|
521
|
+
|
|
522
|
+
#### `.prev()` / `TinyHtml.prev(...)`
|
|
523
|
+
Returns the previous sibling (ignoring non-element nodes).
|
|
524
|
+
|
|
525
|
+
#### `.nextAll()` / `TinyHtml.nextAll(...)`
|
|
526
|
+
All siblings after the current element.
|
|
527
|
+
|
|
528
|
+
#### `.prevAll()` / `TinyHtml.prevAll(...)`
|
|
529
|
+
All siblings before the current element.
|
|
530
|
+
|
|
531
|
+
#### `.nextUntil(until)` / `TinyHtml.nextUntil(...)`
|
|
532
|
+
All next siblings **up to (not including)** a matching selector or element.
|
|
533
|
+
|
|
534
|
+
#### `.prevUntil(until)` / `TinyHtml.prevUntil(...)`
|
|
535
|
+
All previous siblings **up to (not including)** a matching selector or element.
|
|
536
|
+
|
|
537
|
+
---
|
|
538
|
+
|
|
539
|
+
### 🧍 `.siblings()` / `TinyHtml.siblings(...)`
|
|
540
|
+
All siblings of the element **excluding itself**.
|
|
541
|
+
|
|
542
|
+
---
|
|
543
|
+
|
|
544
|
+
### 👶 `.children()` / `TinyHtml.children(...)`
|
|
545
|
+
All child nodes (elements only) of the element.
|
|
546
|
+
|
|
547
|
+
---
|
|
548
|
+
|
|
549
|
+
### 🧩 `.contents()` / `TinyHtml.contents(...)`
|
|
550
|
+
Returns the contents of the element:
|
|
551
|
+
- For `<template>`, returns its content.
|
|
552
|
+
- For `<iframe>`, returns the `contentDocument`.
|
|
553
|
+
- Otherwise, returns its child nodes.
|
|
554
|
+
|
|
555
|
+
---
|
|
556
|
+
|
|
557
|
+
### 📋 `.clone(deep = true)` / `TinyHtml.clone(...)`
|
|
558
|
+
Clones the current element (or a list of elements).
|
|
559
|
+
|
|
560
|
+
- If `deep` is `true` (default), clones all children too.
|
|
561
|
+
- Returns an array from static, or a single node from instance.
|
|
562
|
+
|
|
563
|
+
---
|
|
564
|
+
|
|
565
|
+
### 🛠 Internal Utilities
|
|
566
|
+
|
|
567
|
+
These aren't usually called directly by users, but power most traversal:
|
|
568
|
+
|
|
569
|
+
- `TinyHtml._getSibling(el, direction)`
|
|
570
|
+
- Gets the next/previous sibling that's an element.
|
|
571
|
+
- `TinyHtml._getSiblings(start, exclude)`
|
|
572
|
+
- Returns all element siblings from a starting point (optionally excluding one).
|
|
573
|
+
- `TinyHtml.domDir(el, direction, until)`
|
|
574
|
+
- Traverses in any direction (parent, next, previous), optionally until a selector or element.
|
|
575
|
+
|
|
576
|
+
---
|
|
577
|
+
|
|
578
|
+
## 🧱 DOM Manipulation
|
|
579
|
+
|
|
580
|
+
Methods to insert, move, or replace nodes in the DOM — just like jQuery, but tiny and classy ✨
|
|
581
|
+
|
|
582
|
+
---
|
|
583
|
+
|
|
584
|
+
### `.append(...children)` / `TinyHtml.append(el, ...children)`
|
|
585
|
+
Appends one or more nodes or strings to the end of the selected element.
|
|
586
|
+
|
|
587
|
+
```js
|
|
588
|
+
element.append('hello', otherEl);
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
---
|
|
592
|
+
|
|
593
|
+
### `.prepend(...children)` / `TinyHtml.prepend(el, ...children)`
|
|
594
|
+
|
|
595
|
+
Prepends one or more nodes or strings to the beginning of the selected element.
|
|
596
|
+
|
|
597
|
+
---
|
|
598
|
+
|
|
599
|
+
### `.before(...children)` / `TinyHtml.before(el, ...children)`
|
|
600
|
+
|
|
601
|
+
Inserts content **before** the selected element in the DOM.
|
|
602
|
+
|
|
603
|
+
---
|
|
604
|
+
|
|
605
|
+
### `.after(...children)` / `TinyHtml.after(el, ...children)`
|
|
606
|
+
|
|
607
|
+
Inserts content **after** the selected element in the DOM.
|
|
608
|
+
|
|
609
|
+
---
|
|
610
|
+
|
|
611
|
+
### `.replaceWith(...newNodes)` / `TinyHtml.replaceWith(el, ...newNodes)`
|
|
612
|
+
|
|
613
|
+
Replaces the element with one or more new nodes or strings.
|
|
614
|
+
|
|
615
|
+
---
|
|
616
|
+
|
|
617
|
+
### `.appendTo(targets)` / `TinyHtml.appendTo(el, targets)`
|
|
618
|
+
|
|
619
|
+
Appends the element to one or more target containers.
|
|
620
|
+
|
|
621
|
+
* If multiple targets are provided, the element is cloned.
|
|
622
|
+
* Think: `$(el).appendTo(targets)` from jQuery.
|
|
623
|
+
|
|
624
|
+
---
|
|
625
|
+
|
|
626
|
+
### `.prependTo(targets)` / `TinyHtml.prependTo(el, targets)`
|
|
627
|
+
|
|
628
|
+
Prepends the element to each of the target containers (cloning when needed).
|
|
629
|
+
|
|
630
|
+
---
|
|
631
|
+
|
|
632
|
+
### `.insertBefore(target, child?)` / `TinyHtml.insertBefore(el, target, child?)`
|
|
633
|
+
|
|
634
|
+
Inserts the element **before** a target element or its specific child.
|
|
635
|
+
|
|
636
|
+
* If `child` is provided, it is inserted before the child.
|
|
637
|
+
* Otherwise, it goes before the target.
|
|
638
|
+
|
|
639
|
+
---
|
|
640
|
+
|
|
641
|
+
### `.insertAfter(target, child?)` / `TinyHtml.insertAfter(el, target, child?)`
|
|
642
|
+
|
|
643
|
+
Inserts the element **after** a target element or its specific child.
|
|
644
|
+
|
|
645
|
+
---
|
|
646
|
+
|
|
647
|
+
### `.replaceAll(targets)` / `TinyHtml.replaceAll(el, targets)`
|
|
648
|
+
|
|
649
|
+
Replaces all target elements with the current element(s).
|
|
650
|
+
|
|
651
|
+
* When multiple targets are passed, clones the source accordingly.
|
|
652
|
+
|
|
653
|
+
---
|
|
654
|
+
|
|
655
|
+
### 🧰 Internal Util
|
|
656
|
+
|
|
657
|
+
#### `_appendChecker(where, ...nodes)`
|
|
658
|
+
|
|
659
|
+
Normalizes and converts input (elements, arrays, or strings) into appendable DOM nodes.
|
|
660
|
+
|
|
661
|
+
> 📌 Used internally by all `append`/`prepend`/`before`/`after` methods to ensure safe insertion.
|
|
662
|
+
|
|
663
|
+
---
|
|
664
|
+
|
|
665
|
+
## 📏 Dimensions (Size API)
|
|
666
|
+
|
|
667
|
+
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`.
|
|
668
|
+
|
|
669
|
+
---
|
|
670
|
+
|
|
671
|
+
### 🔍 Reading Dimensions
|
|
672
|
+
|
|
673
|
+
#### `.width()` / `TinyHtml.width(el)`
|
|
674
|
+
Returns the **content box width** (excluding padding, border, and margin).
|
|
675
|
+
|
|
676
|
+
#### `.height()` / `TinyHtml.height(el)`
|
|
677
|
+
Returns the **content box height**.
|
|
678
|
+
|
|
679
|
+
---
|
|
680
|
+
|
|
681
|
+
#### `.innerWidth()` / `TinyHtml.innerWidth(el)`
|
|
682
|
+
Returns the **padding box width** (content + padding).
|
|
683
|
+
|
|
684
|
+
#### `.innerHeight()` / `TinyHtml.innerHeight(el)`
|
|
685
|
+
Returns the **padding box height**.
|
|
686
|
+
|
|
687
|
+
---
|
|
688
|
+
|
|
689
|
+
#### `.outerWidth(includeMargin = false)` / `TinyHtml.outerWidth(el, includeMargin)`
|
|
690
|
+
Returns the **border box width**, and optionally includes margin.
|
|
691
|
+
|
|
692
|
+
#### `.outerHeight(includeMargin = false)` / `TinyHtml.outerHeight(el, includeMargin)`
|
|
693
|
+
Returns the **border box height**, and optionally includes margin.
|
|
694
|
+
|
|
695
|
+
---
|
|
696
|
+
|
|
697
|
+
#### `.getDimension(type, extra)` / `TinyHtml.getDimension(el, type, extra)`
|
|
698
|
+
The underlying function used for all size getters.
|
|
699
|
+
|
|
700
|
+
```js
|
|
701
|
+
// Example:
|
|
702
|
+
element.getDimension('width', 'margin'); // Full box including margin
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
* `type`: `"width"` or `"height"`
|
|
706
|
+
* `extra`: `"content"`, `"padding"`, `"border"`, `"margin"`
|
|
707
|
+
|
|
708
|
+
---
|
|
709
|
+
|
|
710
|
+
### ✏️ Setting Dimensions
|
|
711
|
+
|
|
712
|
+
#### `.setWidth(value)` / `TinyHtml.setWidth(el, value)`
|
|
713
|
+
|
|
714
|
+
Sets the `width` of the element.
|
|
715
|
+
|
|
716
|
+
```js
|
|
717
|
+
el.setWidth(100); // Sets width to 100px
|
|
718
|
+
el.setWidth("50%"); // Sets width to 50%
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
---
|
|
722
|
+
|
|
723
|
+
#### `.setHeight(value)` / `TinyHtml.setHeight(el, value)`
|
|
724
|
+
|
|
725
|
+
Sets the `height` of the element.
|
|
726
|
+
|
|
727
|
+
```js
|
|
728
|
+
el.setHeight("10rem");
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
---
|
|
732
|
+
|
|
733
|
+
## 📌 Position, Scroll & Box Spacing
|
|
734
|
+
|
|
735
|
+
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.
|
|
736
|
+
|
|
737
|
+
---
|
|
738
|
+
|
|
739
|
+
### 📍 Element Positioning
|
|
740
|
+
|
|
741
|
+
#### `.offset()` / `TinyHtml.offset(el)`
|
|
742
|
+
Returns the coordinates `{ top, left }` of the element **relative to the document**.
|
|
743
|
+
|
|
744
|
+
#### `.position()` / `TinyHtml.position(el)`
|
|
745
|
+
Returns the position **relative to the offset parent**, excluding margins.
|
|
746
|
+
|
|
747
|
+
#### `.offsetParent()` / `TinyHtml.offsetParent(el)`
|
|
748
|
+
Returns the nearest ancestor that has a position other than `static`. Useful for relative positioning logic.
|
|
749
|
+
|
|
750
|
+
---
|
|
751
|
+
|
|
752
|
+
### 🔃 Scroll Position
|
|
753
|
+
|
|
754
|
+
#### `.scrollTop()` / `TinyHtml.scrollTop(el)`
|
|
755
|
+
Returns the vertical scroll position of the element or window.
|
|
756
|
+
|
|
757
|
+
#### `.scrollLeft()` / `TinyHtml.scrollLeft(el)`
|
|
758
|
+
Returns the horizontal scroll position of the element or window.
|
|
759
|
+
|
|
760
|
+
#### `.setScrollTop(value)` / `TinyHtml.setScrollTop(el, value)`
|
|
761
|
+
Sets the vertical scroll position.
|
|
762
|
+
|
|
763
|
+
#### `.setScrollLeft(value)` / `TinyHtml.setScrollLeft(el, value)`
|
|
764
|
+
Sets the horizontal scroll position.
|
|
765
|
+
|
|
766
|
+
```js
|
|
767
|
+
element.setScrollTop(100); // Scrolls down 100px
|
|
768
|
+
window.setScrollLeft(50); // Scrolls the window horizontally
|
|
769
|
+
```
|
|
770
|
+
|
|
771
|
+
---
|
|
772
|
+
|
|
773
|
+
### 📦 Box Model Sides (Padding, Margin, Border)
|
|
774
|
+
|
|
775
|
+
All methods return an object of the form:
|
|
776
|
+
|
|
777
|
+
```js
|
|
778
|
+
{
|
|
779
|
+
x: number, // Horizontal total (left + right)
|
|
780
|
+
y: number, // Vertical total (top + bottom)
|
|
781
|
+
left: number,
|
|
782
|
+
right: number,
|
|
783
|
+
top: number,
|
|
784
|
+
bottom: number
|
|
785
|
+
}
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
#### `.margin()` / `TinyHtml.margin(el)`
|
|
789
|
+
|
|
790
|
+
Returns the margin size on all four sides.
|
|
791
|
+
|
|
792
|
+
#### `.padding()` / `TinyHtml.padding(el)`
|
|
793
|
+
|
|
794
|
+
Returns the padding size on all four sides.
|
|
795
|
+
|
|
796
|
+
#### `.borderWidth()` / `TinyHtml.borderWidth(el)`
|
|
797
|
+
|
|
798
|
+
Returns the border width (as in CSS `border-width`) on all sides.
|
|
799
|
+
|
|
800
|
+
#### `.border()` / `TinyHtml.border(el)`
|
|
801
|
+
|
|
802
|
+
Returns the full border value (`borderLeft`, `borderTop`, etc.) on all sides. Rarely needed unless you’re working with composite CSS values.
|
|
803
|
+
|
|
804
|
+
---
|
|
805
|
+
|
|
806
|
+
## 🎨 Class Manipulation
|
|
807
|
+
|
|
808
|
+
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.
|
|
809
|
+
|
|
810
|
+
---
|
|
811
|
+
|
|
812
|
+
### ➕ `.addClass(...classNames)` / `TinyHtml.addClass(el, ...classNames)`
|
|
813
|
+
Adds one or more class names to the element.
|
|
814
|
+
|
|
815
|
+
```js
|
|
816
|
+
element.addClass("highlight", "bold");
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
---
|
|
820
|
+
|
|
821
|
+
### ➖ `.removeClass(...classNames)` / `TinyHtml.removeClass(el, ...classNames)`
|
|
822
|
+
|
|
823
|
+
Removes one or more class names from the element.
|
|
824
|
+
|
|
825
|
+
```js
|
|
826
|
+
element.removeClass("highlight");
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
---
|
|
830
|
+
|
|
831
|
+
### 🔁 `.replaceClass(oldClass, newClass)` / `TinyHtml.replaceClass(el, oldClass, newClass)`
|
|
832
|
+
|
|
833
|
+
Replaces one class with another. Returns `true` if the replacement occurred.
|
|
834
|
+
|
|
835
|
+
```js
|
|
836
|
+
element.replaceClass("old", "new");
|
|
837
|
+
```
|
|
838
|
+
|
|
839
|
+
---
|
|
840
|
+
|
|
841
|
+
### ❓ `.hasClass(className)` / `TinyHtml.hasClass(el, className)`
|
|
842
|
+
|
|
843
|
+
Checks if the element has a specific class.
|
|
844
|
+
|
|
845
|
+
```js
|
|
846
|
+
element.hasClass("active"); // → true / false
|
|
847
|
+
```
|
|
848
|
+
|
|
849
|
+
---
|
|
850
|
+
|
|
851
|
+
### 🔃 `.toggleClass(className, [force])` / `TinyHtml.toggleClass(el, className, [force])`
|
|
852
|
+
|
|
853
|
+
Toggles a class on or off. If `force` is given:
|
|
854
|
+
|
|
855
|
+
* `true`: ensures the class is added.
|
|
856
|
+
* `false`: ensures the class is removed.
|
|
857
|
+
|
|
858
|
+
Returns whether the class is present **after** the toggle.
|
|
859
|
+
|
|
860
|
+
```js
|
|
861
|
+
element.toggleClass("visible");
|
|
862
|
+
element.toggleClass("enabled", true); // Force add
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
---
|
|
866
|
+
|
|
867
|
+
### 🔢 `.classLength()` / `TinyHtml.classLength(el)`
|
|
868
|
+
|
|
869
|
+
Returns the number of classes applied to the element.
|
|
870
|
+
|
|
871
|
+
```js
|
|
872
|
+
const count = element.classLength(); // → 3
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
---
|
|
876
|
+
|
|
877
|
+
### 🔍 `.classItem(index)` / `TinyHtml.classItem(el, index)`
|
|
878
|
+
|
|
879
|
+
Gets the class name at a specific index in the class list.
|
|
880
|
+
|
|
881
|
+
```js
|
|
882
|
+
element.classItem(0); // → "highlight"
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
---
|
|
886
|
+
|
|
887
|
+
### 📋 `.classList()` / `TinyHtml.classList(el)`
|
|
888
|
+
|
|
889
|
+
Returns all class names as an array.
|
|
890
|
+
|
|
891
|
+
```js
|
|
892
|
+
element.classList(); // → ["highlight", "bold", "selected"]
|
|
893
|
+
```
|
|
894
|
+
|
|
895
|
+
---
|
|
896
|
+
|
|
897
|
+
## 📄 Content & Element Info
|
|
898
|
+
|
|
899
|
+
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.
|
|
900
|
+
|
|
901
|
+
---
|
|
902
|
+
|
|
903
|
+
### 🏷 `.tagName()` / `TinyHtml.tagName(el)`
|
|
904
|
+
Returns the uppercase tag name of the element.
|
|
905
|
+
|
|
906
|
+
```js
|
|
907
|
+
element.tagName(); // → "DIV", "SPAN", etc.
|
|
908
|
+
```
|
|
909
|
+
|
|
910
|
+
---
|
|
911
|
+
|
|
912
|
+
### 🆔 `.id()` / `TinyHtml.id(el)`
|
|
913
|
+
|
|
914
|
+
Returns the ID attribute value of the element.
|
|
915
|
+
|
|
916
|
+
```js
|
|
917
|
+
element.id(); // → "my-element-id"
|
|
918
|
+
```
|
|
919
|
+
|
|
920
|
+
---
|
|
921
|
+
|
|
922
|
+
### 📝 `.text()` / `TinyHtml.text(el)`
|
|
923
|
+
|
|
924
|
+
Gets the text content of the element (returns `null` if none).
|
|
925
|
+
|
|
926
|
+
```js
|
|
927
|
+
element.text(); // → "Hello world"
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
---
|
|
931
|
+
|
|
932
|
+
### ✍️ `.setText(value)` / `TinyHtml.setText(el, value)`
|
|
933
|
+
|
|
934
|
+
Sets the text content of one or more elements. Throws if `value` is not a string.
|
|
935
|
+
|
|
936
|
+
```js
|
|
937
|
+
element.setText("New text content");
|
|
938
|
+
```
|
|
939
|
+
|
|
940
|
+
---
|
|
941
|
+
|
|
942
|
+
### 🧹 `.empty()` / `TinyHtml.empty(el)`
|
|
943
|
+
|
|
944
|
+
Removes all child nodes (clears content) from one or more elements.
|
|
945
|
+
|
|
946
|
+
```js
|
|
947
|
+
element.empty();
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
---
|
|
951
|
+
|
|
952
|
+
### 🔍 `.html()` / `TinyHtml.html(el)`
|
|
953
|
+
|
|
954
|
+
Gets the `innerHTML` string of the element.
|
|
955
|
+
|
|
956
|
+
```js
|
|
957
|
+
element.html(); // → "<p>Some HTML content</p>"
|
|
958
|
+
```
|
|
959
|
+
|
|
960
|
+
---
|
|
961
|
+
|
|
962
|
+
### 🛠 `.setHtml(value)` / `TinyHtml.setHtml(el, value)`
|
|
963
|
+
|
|
964
|
+
Sets the `innerHTML` of one or more elements. Throws if `value` is not a string.
|
|
965
|
+
|
|
966
|
+
```js
|
|
967
|
+
element.setHtml("<strong>Bold text</strong>");
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
---
|
|
971
|
+
|
|
972
|
+
## 🎛️ Form Value Handling & Input Hooks
|
|
973
|
+
|
|
974
|
+
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.
|
|
975
|
+
|
|
976
|
+
---
|
|
977
|
+
|
|
978
|
+
### 🪝 `_valHooks`
|
|
979
|
+
|
|
980
|
+
Internal value hooks for form controls
|
|
981
|
+
|
|
982
|
+
- **option**: Gets the option value or fallback to text.
|
|
983
|
+
- **select**: Handles single/multiple select value getting/setting.
|
|
984
|
+
- **radio**: Gets `'on'`/`'off'` based on checked state; sets checked with unchecking siblings.
|
|
985
|
+
- **checkbox**: Similar to radio, manages checked state.
|
|
986
|
+
|
|
987
|
+
These hooks ensure form controls behave consistently across different types.
|
|
988
|
+
|
|
989
|
+
---
|
|
990
|
+
|
|
991
|
+
### 🎯 `.setVal(el, value)` / `.setVal(value)`
|
|
992
|
+
|
|
993
|
+
Sets the value(s) of input/select/textarea elements.
|
|
994
|
+
Supports strings, numbers, booleans, arrays, or a callback returning these.
|
|
995
|
+
|
|
996
|
+
Throws if value is invalid or unsupported.
|
|
997
|
+
|
|
998
|
+
```js
|
|
999
|
+
element.setVal("hello");
|
|
1000
|
+
element.setVal(["option1", "option2"]);
|
|
1001
|
+
element.setVal((el, currentVal) => currentVal + " updated");
|
|
1002
|
+
```
|
|
1003
|
+
|
|
1004
|
+
---
|
|
1005
|
+
|
|
1006
|
+
### 🔍 `.val(el)` / `.val()`
|
|
1007
|
+
|
|
1008
|
+
Gets the normalized string value from an input/select element.
|
|
1009
|
+
Strips carriage returns and handles hooks automatically.
|
|
1010
|
+
|
|
1011
|
+
---
|
|
1012
|
+
|
|
1013
|
+
### ✍️ `.valTxt(el)` / `.valTxt()`
|
|
1014
|
+
|
|
1015
|
+
Gets the text string value, throwing if the value is not string-compatible.
|
|
1016
|
+
|
|
1017
|
+
---
|
|
1018
|
+
|
|
1019
|
+
### 🧮 `.valNb(el)` / `.valNb()`
|
|
1020
|
+
|
|
1021
|
+
Gets the value parsed as a number. Throws if value is `NaN` or element incompatible.
|
|
1022
|
+
|
|
1023
|
+
---
|
|
1024
|
+
|
|
1025
|
+
### 📅 `.valDate(el)` / `.valDate()`
|
|
1026
|
+
|
|
1027
|
+
Gets the value parsed as a `Date` object. Throws if value is invalid or element incompatible.
|
|
1028
|
+
|
|
1029
|
+
---
|
|
1030
|
+
|
|
1031
|
+
### ✔️ `.valBool(el)` / `.valBool()`
|
|
1032
|
+
|
|
1033
|
+
Returns boolean state for checkboxes/radios based on value `"on"` or `"off"`.
|
|
1034
|
+
|
|
1035
|
+
---
|
|
1036
|
+
|
|
1037
|
+
### 🧩 Internal helpers:
|
|
1038
|
+
|
|
1039
|
+
* `_valTypes`: Map of functions to get typed values (string, date, number).
|
|
1040
|
+
* `_getValByType`: Get typed value from element with validation.
|
|
1041
|
+
* `_val`: Core value getter that uses hooks or falls back to `_valTypes`.
|
|
1042
|
+
* `_valArr`: Ensures the returned value is an array (for multi-selects).
|
|
1043
|
+
|
|
1044
|
+
---
|
|
1045
|
+
|
|
1046
|
+
## 🎉 Event Handling
|
|
1047
|
+
|
|
1048
|
+
These methods allow you to easily register, remove, or trigger DOM events.
|
|
1049
|
+
All event listeners are tracked in a private registry for full control.
|
|
1050
|
+
|
|
1051
|
+
---
|
|
1052
|
+
|
|
1053
|
+
### 📥 `on()` / `once()`
|
|
1054
|
+
|
|
1055
|
+
Registering Events
|
|
1056
|
+
|
|
1057
|
+
```js
|
|
1058
|
+
element.on("click", (e) => console.log("Clicked!"));
|
|
1059
|
+
element.once("mouseenter", () => console.log("Hovered just once!"));
|
|
1060
|
+
```
|
|
1061
|
+
|
|
1062
|
+
* `on`: Attaches a persistent event listener.
|
|
1063
|
+
* `once`: Attaches a listener that auto-removes after its first trigger.
|
|
1064
|
+
|
|
1065
|
+
You can also use the static versions for multiple elements.
|
|
1066
|
+
|
|
1067
|
+
---
|
|
1068
|
+
|
|
1069
|
+
### ❌ `off()` / `offAll()` / `offAllTypes()`
|
|
1070
|
+
|
|
1071
|
+
Removing Events
|
|
1072
|
+
|
|
1073
|
+
```js
|
|
1074
|
+
element.off("click", myHandler);
|
|
1075
|
+
element.offAll("mouseover");
|
|
1076
|
+
element.offAllTypes((handler, event) => event.startsWith("key"));
|
|
1077
|
+
```
|
|
1078
|
+
|
|
1079
|
+
* `off`: Removes a specific listener.
|
|
1080
|
+
* `offAll`: Removes all listeners of a given type.
|
|
1081
|
+
* `offAllTypes`: Removes all listeners of all types, optionally filtered.
|
|
1082
|
+
|
|
1083
|
+
These methods ensure clean teardown of events and prevent memory leaks.
|
|
1084
|
+
|
|
1085
|
+
---
|
|
1086
|
+
|
|
1087
|
+
### 🚀 `trigger()`
|
|
1088
|
+
|
|
1089
|
+
Triggering Events
|
|
1090
|
+
|
|
1091
|
+
```js
|
|
1092
|
+
element.trigger("click");
|
|
1093
|
+
element.trigger("customEvent", { detail: "🔥 data!" });
|
|
1094
|
+
```
|
|
1095
|
+
|
|
1096
|
+
Simulates a user-triggered event.
|
|
1097
|
+
Supports native and custom events with optional payload.
|
|
1098
|
+
|
|
1099
|
+
---
|
|
1100
|
+
|
|
1101
|
+
## 🧬 Attribute & Property Manipulation
|
|
1102
|
+
|
|
1103
|
+
Use these helpers to interact with standard DOM attributes or element properties with added safety and normalization.
|
|
1104
|
+
|
|
1105
|
+
---
|
|
1106
|
+
|
|
1107
|
+
### 🏷️ `.attr()` / `.setAttr()` / `.removeAttr()` / `.hasAttr()`
|
|
1108
|
+
|
|
1109
|
+
Attributes
|
|
1110
|
+
|
|
1111
|
+
```js
|
|
1112
|
+
element.attr("href"); // Get
|
|
1113
|
+
element.setAttr("title", "Cool!"); // Set
|
|
1114
|
+
element.removeAttr("data-test"); // Remove
|
|
1115
|
+
element.hasAttr("id"); // Check
|
|
1116
|
+
```
|
|
1117
|
+
|
|
1118
|
+
Works on both single and multiple elements (static or instance).
|
|
1119
|
+
Safe and type-checked — throws if misuse is detected.
|
|
1120
|
+
|
|
1121
|
+
---
|
|
1122
|
+
|
|
1123
|
+
### 🧲 `.hasProp()` / `.addProp()` / `.removeProp()` / `.toggleProp()`
|
|
1124
|
+
|
|
1125
|
+
Properties
|
|
1126
|
+
|
|
1127
|
+
```js
|
|
1128
|
+
element.hasProp("disabled"); // true/false
|
|
1129
|
+
element.addProp("checked"); // set true
|
|
1130
|
+
element.removeProp("checked"); // set false
|
|
1131
|
+
element.toggleProp("disabled"); // flip
|
|
1132
|
+
element.toggleProp("readonly", true); // force enable
|
|
1133
|
+
```
|
|
1134
|
+
|
|
1135
|
+
These methods interact with real DOM properties (not just attributes).
|
|
1136
|
+
Includes jQuery-style `propFix` (e.g., `"for"` → `"htmlFor"`).
|
|
1137
|
+
|
|
1138
|
+
---
|
|
1139
|
+
|
|
1140
|
+
## 🛠️ Element Utilities
|
|
1141
|
+
|
|
1142
|
+
---
|
|
1143
|
+
|
|
1144
|
+
### 💨 `.remove()`
|
|
1145
|
+
|
|
1146
|
+
Remove from DOM
|
|
1147
|
+
|
|
1148
|
+
```js
|
|
1149
|
+
element.remove();
|
|
1150
|
+
```
|
|
1151
|
+
|
|
1152
|
+
Removes the selected element(s) from the document.
|
|
1153
|
+
Also available in static form: `TinyHtml.remove(el)`.
|
|
1154
|
+
|
|
1155
|
+
---
|
|
1156
|
+
|
|
1157
|
+
### 🔢 `.index()`
|
|
1158
|
+
|
|
1159
|
+
Element Index
|
|
1160
|
+
|
|
1161
|
+
```js
|
|
1162
|
+
element.index(); // Get index among siblings
|
|
1163
|
+
element.index(".some-class"); // Get index relative to a selector
|
|
1164
|
+
```
|
|
1165
|
+
|
|
1166
|
+
Returns the index of the current element:
|
|
1167
|
+
|
|
1168
|
+
* Among its siblings (default)
|
|
1169
|
+
* Or relative to a given selector or list of elements.
|
|
1170
|
+
|
|
1171
|
+
---
|
|
1172
|
+
|
|
1173
|
+
## 📦 Collision Detection
|
|
1174
|
+
|
|
1175
|
+
Useful for game dev, UI constraints, dragging logic, etc.
|
|
1176
|
+
|
|
1177
|
+
---
|
|
1178
|
+
|
|
1179
|
+
### 📏 `.isCollWith()`
|
|
1180
|
+
|
|
1181
|
+
Bounding Box Collision
|
|
1182
|
+
|
|
1183
|
+
```js
|
|
1184
|
+
element1.isCollWith(element2);
|
|
1185
|
+
element1.isCollWith(element2, { top: 5, left: 5 });
|
|
1186
|
+
```
|
|
1187
|
+
|
|
1188
|
+
Checks for overlap between bounding boxes of two elements.
|
|
1189
|
+
You can also extend the size of `element1`'s box using `extraRect`.
|
|
1190
|
+
|
|
1191
|
+
---
|
|
1192
|
+
|
|
1193
|
+
### 🎯 `.isCollPerfWith()`
|
|
1194
|
+
|
|
1195
|
+
Pixel-Perfect Collision
|
|
1196
|
+
|
|
1197
|
+
```js
|
|
1198
|
+
element1.isCollPerfWith(element2);
|
|
1199
|
+
```
|
|
1200
|
+
|
|
1201
|
+
Uses a higher-precision algorithm (like real pixel collision), ideal for:
|
|
1202
|
+
|
|
1203
|
+
* Tight hitboxes
|
|
1204
|
+
* Game-like interactions
|
|
1205
|
+
* Avoiding false positives near edges
|
|
1206
|
+
|
|
1207
|
+
---
|
|
1208
|
+
|
|
1209
|
+
## 🔐 Collision Locking System
|
|
1210
|
+
|
|
1211
|
+
Maintains a collision "state lock" until the element exits the target from a specific side.
|
|
1212
|
+
|
|
1213
|
+
---
|
|
1214
|
+
|
|
1215
|
+
### 🔄 `.isCollWithLock()`
|
|
1216
|
+
|
|
1217
|
+
Lock Until Exit (Bounding Box)
|
|
1218
|
+
|
|
1219
|
+
```js
|
|
1220
|
+
element1.isCollWithLock(element2, "top");
|
|
1221
|
+
```
|
|
1222
|
+
|
|
1223
|
+
Locks the collision detection to a **direction**:
|
|
1224
|
+
|
|
1225
|
+
* `top`, `bottom`, `left`, `right`
|
|
1226
|
+
|
|
1227
|
+
🔄 It keeps the state `true` until the element exits through the same side it entered.
|
|
1228
|
+
|
|
1229
|
+
---
|
|
1230
|
+
|
|
1231
|
+
### 🔬 `.isCollPerfWithLock()`
|
|
1232
|
+
|
|
1233
|
+
Lock Until Exit (Pixel-Precise)
|
|
1234
|
+
|
|
1235
|
+
```js
|
|
1236
|
+
element1.isCollPerfWithLock(element2, "left", { left: 10 });
|
|
1237
|
+
```
|
|
1238
|
+
|
|
1239
|
+
Just like `.isCollWithLock()`, but with pixel-precision.
|
|
1240
|
+
|
|
1241
|
+
---
|
|
1242
|
+
|
|
1243
|
+
## 🧼 Collision Lock Reset
|
|
1244
|
+
|
|
1245
|
+
Clear collision lock state to restart fresh.
|
|
1246
|
+
|
|
1247
|
+
---
|
|
1248
|
+
|
|
1249
|
+
### 🔁 `.resetCollLock()`
|
|
1250
|
+
|
|
1251
|
+
Reset All Directions
|
|
1252
|
+
|
|
1253
|
+
```js
|
|
1254
|
+
element.resetCollLock();
|
|
1255
|
+
```
|
|
1256
|
+
|
|
1257
|
+
Clears **all directional locks** for the element.
|
|
1258
|
+
|
|
1259
|
+
---
|
|
1260
|
+
|
|
1261
|
+
### ⬅️ `.resetCollLockDir()`
|
|
1262
|
+
|
|
1263
|
+
Reset One Direction
|
|
1264
|
+
|
|
1265
|
+
```js
|
|
1266
|
+
element.resetCollLockDir("right");
|
|
1267
|
+
```
|
|
1268
|
+
|
|
1269
|
+
Resets a **specific direction** lock.
|
|
1270
|
+
|
|
1271
|
+
---
|
|
1272
|
+
|
|
1273
|
+
## 👁️ Viewport Detection
|
|
1274
|
+
|
|
1275
|
+
Easily detect whether an element is partially or fully visible inside the browser window.
|
|
1276
|
+
|
|
1277
|
+
---
|
|
1278
|
+
|
|
1279
|
+
### 👀 `.isInViewport()`
|
|
1280
|
+
|
|
1281
|
+
Partially Visible
|
|
1282
|
+
|
|
1283
|
+
```js
|
|
1284
|
+
element.isInViewport();
|
|
1285
|
+
```
|
|
1286
|
+
|
|
1287
|
+
Checks if the element is **at least partially** visible in the current viewport.
|
|
1288
|
+
|
|
1289
|
+
#### ✅ Use when:
|
|
1290
|
+
|
|
1291
|
+
* You want to trigger animations when an element **starts entering** the screen.
|
|
1292
|
+
* Detect lazy loading or partial exposure of banners, sections, etc.
|
|
1293
|
+
|
|
1294
|
+
#### 🔍 Logic:
|
|
1295
|
+
|
|
1296
|
+
* Compares the element’s **top and bottom** against the **viewport’s top and bottom**.
|
|
1297
|
+
* Returns `true` if **any portion** of the element is inside the viewport.
|
|
1298
|
+
|
|
1299
|
+
#### 🔁 Static version:
|
|
1300
|
+
|
|
1301
|
+
```js
|
|
1302
|
+
TinyHtml.isInViewport(element);
|
|
1303
|
+
```
|
|
1304
|
+
|
|
1305
|
+
---
|
|
1306
|
+
|
|
1307
|
+
### 📏 `.isScrolledIntoView()`
|
|
1308
|
+
|
|
1309
|
+
Fully Visible
|
|
1310
|
+
|
|
1311
|
+
```js
|
|
1312
|
+
element.isScrolledIntoView();
|
|
1313
|
+
```
|
|
1314
|
+
|
|
1315
|
+
Checks if the element is **fully inside** the viewport — meaning:
|
|
1316
|
+
|
|
1317
|
+
* Its **top is not above** the screen
|
|
1318
|
+
* Its **bottom is not below** the screen
|
|
1319
|
+
|
|
1320
|
+
#### ✅ Use when:
|
|
1321
|
+
|
|
1322
|
+
* You want to detect **full visibility** before triggering something (e.g., playing a video).
|
|
1323
|
+
* Ensuring an element is **100% onscreen** before acting on it.
|
|
1324
|
+
|
|
1325
|
+
#### 🔍 Logic:
|
|
1326
|
+
|
|
1327
|
+
* Measures if the element's **entire height** fits between `scrollTop` and `scrollTop + window height`.
|
|
1328
|
+
|
|
1329
|
+
#### 🔁 Static version:
|
|
1330
|
+
|
|
1331
|
+
```js
|
|
1332
|
+
TinyHtml.isScrolledIntoView(element);
|
|
1333
|
+
```
|