tiny-essentials 1.20.0 β 1.20.2
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/README.md +5 -0
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/basics/html.cjs +33 -2
- package/dist/v1/basics/html.d.mts +14 -4
- package/dist/v1/basics/html.mjs +27 -2
- package/dist/v1/basics/index.cjs +2 -0
- package/dist/v1/basics/index.d.mts +3 -1
- package/dist/v1/basics/index.mjs +3 -3
- package/dist/v1/basics/simpleMath.cjs +23 -4
- package/dist/v1/basics/simpleMath.d.mts +18 -4
- package/dist/v1/basics/simpleMath.mjs +22 -4
- package/dist/v1/index.cjs +2 -0
- package/dist/v1/index.d.mts +3 -1
- package/dist/v1/index.mjs +3 -3
- package/dist/v1/libs/TinyDragger.cjs +1 -1
- package/dist/v1/libs/TinyDragger.mjs +1 -1
- package/dist/v1/libs/TinyHtml.cjs +500 -105
- package/dist/v1/libs/TinyHtml.d.mts +251 -42
- package/dist/v1/libs/TinyHtml.mjs +448 -96
- package/dist/v1/libs/TinyIframeEvents.cjs +2 -1
- package/dist/v1/libs/TinyNewWinEvents.cjs +4 -2
- package/docs/v1/basics/html.md +78 -22
- package/docs/v1/basics/simpleMath.md +22 -4
- package/docs/v1/libs/TinyHtml.md +268 -6
- package/package.json +1 -1
- package/dist/v1/ColorSafeStringify.js +0 -235
- package/dist/v1/TinyAfterScrollWatcher.js +0 -219
- package/dist/v1/TinyBasicsEs.js +0 -9334
- package/dist/v1/TinyClipboard.js +0 -459
- package/dist/v1/TinyColorConverter.js +0 -617
- package/dist/v1/TinyDomReadyManager.js +0 -213
- package/dist/v1/TinyDragDropDetector.js +0 -307
- package/dist/v1/TinyDragger.js +0 -6569
- package/dist/v1/TinyEssentials.js +0 -20792
- package/dist/v1/TinyEvents.js +0 -402
- package/dist/v1/TinyHtml.js +0 -5545
- package/dist/v1/TinyIframeEvents.js +0 -854
- package/dist/v1/TinyLevelUp.js +0 -291
- package/dist/v1/TinyLocalStorage.js +0 -1440
- package/dist/v1/TinyNewWinEvents.js +0 -888
- package/dist/v1/TinyNotifications.js +0 -408
- package/dist/v1/TinyNotifyCenter.js +0 -493
- package/dist/v1/TinyPromiseQueue.js +0 -299
- package/dist/v1/TinyRateLimiter.js +0 -611
- package/dist/v1/TinySmartScroller.js +0 -7039
- package/dist/v1/TinyTextRangeEditor.js +0 -497
- package/dist/v1/TinyTimeout.js +0 -233
- package/dist/v1/TinyToastNotify.js +0 -441
- package/dist/v1/TinyUploadClicker.js +0 -14353
- package/dist/v1/UltraRandomMsgGen.js +0 -995
|
@@ -261,7 +261,8 @@ class TinyIframeEvents {
|
|
|
261
261
|
* @throws {TypeError} If the value is not a string.
|
|
262
262
|
*/
|
|
263
263
|
set secretEventName(name) {
|
|
264
|
-
if (typeof name !== 'string')
|
|
264
|
+
if (typeof name !== 'string')
|
|
265
|
+
throw new TypeError('TinyIframeEvents: secretEventName must be a string.');
|
|
265
266
|
this.#secretEventName = name;
|
|
266
267
|
}
|
|
267
268
|
|
|
@@ -253,7 +253,8 @@ class TinyNewWinEvents {
|
|
|
253
253
|
* @throws {TypeError} If the value is not a string.
|
|
254
254
|
*/
|
|
255
255
|
set readyEventName(name) {
|
|
256
|
-
if (typeof name !== 'string')
|
|
256
|
+
if (typeof name !== 'string')
|
|
257
|
+
throw new TypeError('TinyNewWinEvents: readyEventName must be a string.');
|
|
257
258
|
this.#readyEventName = name;
|
|
258
259
|
}
|
|
259
260
|
|
|
@@ -271,7 +272,8 @@ class TinyNewWinEvents {
|
|
|
271
272
|
* @throws {TypeError} If the value is not a string.
|
|
272
273
|
*/
|
|
273
274
|
set routeEventName(name) {
|
|
274
|
-
if (typeof name !== 'string')
|
|
275
|
+
if (typeof name !== 'string')
|
|
276
|
+
throw new TypeError('TinyNewWinEvents: routeEventName must be a string.');
|
|
275
277
|
this.#routeEventName = name;
|
|
276
278
|
}
|
|
277
279
|
|
package/docs/v1/basics/html.md
CHANGED
|
@@ -142,11 +142,11 @@ saveJsonFile('yasmin.json', data);
|
|
|
142
142
|
|
|
143
143
|
### π `fetchTemplate(...)`
|
|
144
144
|
|
|
145
|
-
Loads data from a remote URL using Fetch API, with support for custom HTTP methods, retries, timeouts, headers, and even external abort controllers.
|
|
145
|
+
Loads data from a remote URL using the Fetch API, with support for custom HTTP methods, retries, timeouts, headers, and even external abort controllers.
|
|
146
146
|
|
|
147
147
|
#### π₯ Parameters
|
|
148
148
|
|
|
149
|
-
* `url` *(string)*: The full URL to fetch
|
|
149
|
+
* `url` *(string)*: The full URL to fetch from (must start with `http://`, `https://`, `/`, `./`, or `../`).
|
|
150
150
|
* `options` *(object)* *(optional)*:
|
|
151
151
|
|
|
152
152
|
* `signal` *(`AbortSignal` | `null`)*: Custom abort signal.
|
|
@@ -156,42 +156,88 @@ Loads data from a remote URL using Fetch API, with support for custom HTTP metho
|
|
|
156
156
|
* `headers` *(object)*: Additional headers to include in the request.
|
|
157
157
|
* `body` *(object)*: Request body. If the value is a plain object, it will be automatically stringified as JSON.
|
|
158
158
|
|
|
159
|
-
#### `fetchJson(url, options?)
|
|
159
|
+
#### `fetchJson(url, options?)`
|
|
160
160
|
|
|
161
|
-
Loads and parses a JSON.
|
|
161
|
+
Loads and parses a remote JSON file.
|
|
162
162
|
|
|
163
|
-
*
|
|
164
|
-
* `options` *(object)* *(optional)*:
|
|
163
|
+
* **Parameters**:
|
|
165
164
|
|
|
166
|
-
|
|
165
|
+
* `url` *(string)*: URL to fetch the JSON from.
|
|
166
|
+
* `options` *(object)* *(optional)*: Same structure as `fetchTemplate`.
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
* **Returns**:
|
|
169
|
+
`Promise<any[] | Record<string | number | symbol, unknown>>` β The parsed JSON data.
|
|
169
170
|
|
|
170
|
-
*
|
|
171
|
-
* `allowedMimeTypes` Optional list of accepted MIME types (e.g., ['image/jpeg']).
|
|
172
|
-
* `options` *(object)* *(optional)*:
|
|
171
|
+
* **Throws**:
|
|
173
172
|
|
|
174
|
-
|
|
173
|
+
* `Error` if the fetch fails, times out, or returns invalid JSON.
|
|
174
|
+
* `Error` if the `Content-Type` is not `application/json`.
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
---
|
|
177
177
|
|
|
178
|
-
|
|
179
|
-
* Retry logic is **disabled**
|
|
180
|
-
* Abortion is handled externally
|
|
178
|
+
#### `fetchBlob(url, allowedMimeTypes?, options?)`
|
|
181
179
|
|
|
182
|
-
|
|
180
|
+
Loads a remote file as a Blob object.
|
|
181
|
+
|
|
182
|
+
* **Parameters**:
|
|
183
|
+
|
|
184
|
+
* `url` *(string)*: URL of the remote file.
|
|
185
|
+
* `allowedMimeTypes` *(string\[])* *(optional)*: List of accepted MIME types.
|
|
186
|
+
* `options` *(object)* *(optional)*: Same structure as `fetchTemplate`.
|
|
187
|
+
|
|
188
|
+
* **Returns**:
|
|
189
|
+
`Promise<Blob>`
|
|
190
|
+
|
|
191
|
+
* **Throws**:
|
|
192
|
+
|
|
193
|
+
* `Error` if fetch fails or the MIME type is not allowed.
|
|
194
|
+
* `Error` if the response is not OK.
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
#### `fetchText(url, allowedMimeTypes?, options?)`
|
|
199
|
+
|
|
200
|
+
Loads a remote file as **plain text** using the Fetch API.
|
|
201
|
+
|
|
202
|
+
* **Parameters**:
|
|
203
|
+
|
|
204
|
+
* `url` *(string)*: Full URL of the file to fetch.
|
|
205
|
+
* `allowedMimeTypes` *(string\[])* *(optional)*: List of accepted MIME types (e.g., `['text/plain']`).
|
|
206
|
+
* `options` *(object)* *(optional)*: Same structure as `fetchTemplate`.
|
|
207
|
+
|
|
208
|
+
* **Returns**:
|
|
209
|
+
`Promise<string>` β The content of the file as a text string.
|
|
210
|
+
|
|
211
|
+
* **Throws**:
|
|
183
212
|
|
|
184
|
-
* `
|
|
213
|
+
* `Error` if the fetch fails or the response is not OK.
|
|
214
|
+
* `Error` if the MIME type is not in the allowed list (when provided).
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
#### π€ Returns (for all helpers)
|
|
219
|
+
|
|
220
|
+
* `Promise<any>` β Depends on the function:
|
|
221
|
+
|
|
222
|
+
* `fetchJson`: Parsed JSON
|
|
223
|
+
* `fetchBlob`: File as a Blob
|
|
224
|
+
* `fetchText`: File as plain text
|
|
225
|
+
|
|
226
|
+
---
|
|
185
227
|
|
|
186
228
|
#### β οΈ Throws
|
|
187
229
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
* `Error` if the
|
|
230
|
+
All functions may throw the following:
|
|
231
|
+
|
|
232
|
+
* `Error` if the request fails or the response times out.
|
|
233
|
+
* `Error` if `Content-Type` does not match expected type (JSON, Blob, Text, etc).
|
|
234
|
+
* `Error` if response is malformed or rejected by MIME type filter.
|
|
235
|
+
|
|
236
|
+
---
|
|
191
237
|
|
|
192
238
|
#### π§ Tip
|
|
193
239
|
|
|
194
|
-
|
|
240
|
+
Using a custom `signal` disables both `timeout` and `retries`. This is useful when you want to handle cancellation yourself, like in user interfaces or abortable workflows.
|
|
195
241
|
|
|
196
242
|
#### π§ͺ Example
|
|
197
243
|
|
|
@@ -210,6 +256,16 @@ const data = await fetchJson('https://api.example.com/data', {
|
|
|
210
256
|
});
|
|
211
257
|
```
|
|
212
258
|
|
|
259
|
+
```js
|
|
260
|
+
const text = await fetchText('/example.txt', ['text/plain'], {
|
|
261
|
+
timeout: 3000,
|
|
262
|
+
});
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
```js
|
|
266
|
+
const blob = await fetchBlob('/image.jpg', ['image/jpeg']);
|
|
267
|
+
```
|
|
268
|
+
|
|
213
269
|
---
|
|
214
270
|
|
|
215
271
|
### π¦ `HtmlElBoxSides` Type
|
|
@@ -36,19 +36,37 @@ ruleOfThree(2, 6, 3, true); // β 4
|
|
|
36
36
|
|
|
37
37
|
### π― `getSimplePerc(price, percentage)`
|
|
38
38
|
|
|
39
|
-
**Calculates the percentage of a
|
|
39
|
+
**Calculates the actual value that corresponds to a percentage of a base number.**
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
Unlike `getPercentage`, which tells how much something represents in percent,
|
|
42
|
+
this function tells how much a given percentage *is worth* in actual value.
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
- **`price`**: The base number to apply the percentage to.
|
|
45
|
+
- **`percentage`**: The percentage to calculate from the base.
|
|
45
46
|
|
|
47
|
+
#### Example:
|
|
46
48
|
```js
|
|
47
49
|
getSimplePerc(200, 15); // β 30
|
|
48
50
|
```
|
|
49
51
|
|
|
50
52
|
---
|
|
51
53
|
|
|
54
|
+
### π `getPercentage(part, total)`
|
|
55
|
+
|
|
56
|
+
**Calculates how much percent a partial value represents of the total value.**
|
|
57
|
+
|
|
58
|
+
This function is useful when you want to know what fraction of the total a value is, in percentage form.
|
|
59
|
+
|
|
60
|
+
- **`part`**: The partial value to compare.
|
|
61
|
+
- **`total`**: The total or maximum value.
|
|
62
|
+
|
|
63
|
+
#### Example:
|
|
64
|
+
```js
|
|
65
|
+
getPercentage(5, 100); // β 5
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
52
70
|
### π `getAge(timeData, now)`
|
|
53
71
|
|
|
54
72
|
**Calculates the age based on a birthdate.**
|
package/docs/v1/libs/TinyHtml.md
CHANGED
|
@@ -310,6 +310,40 @@ HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | HTMLOptionElement
|
|
|
310
310
|
|
|
311
311
|
---
|
|
312
312
|
|
|
313
|
+
## π¨ Element Creation
|
|
314
|
+
|
|
315
|
+
### `TinyHtml.createFrom(tagName, attrs?)`
|
|
316
|
+
|
|
317
|
+
Creates a new `TinyHtml` element from a given tag name and optional attributes.
|
|
318
|
+
|
|
319
|
+
* **Parameters**:
|
|
320
|
+
|
|
321
|
+
* `tagName` *(string)* β The HTML tag name (e.g., `'div'`, `'span'`, `'button'`).
|
|
322
|
+
* `attrs` *(object)* β *(optional)* Key-value pairs representing HTML attributes.
|
|
323
|
+
|
|
324
|
+
* **Returns**: `TinyHtml` β A new `TinyHtml` instance representing the created element.
|
|
325
|
+
|
|
326
|
+
* **Throws**:
|
|
327
|
+
|
|
328
|
+
* `TypeError` β If `tagName` is not a string.
|
|
329
|
+
* `TypeError` β If `attrs` is defined but not a plain object.
|
|
330
|
+
|
|
331
|
+
### π‘ Example
|
|
332
|
+
|
|
333
|
+
```js
|
|
334
|
+
const div = TinyHtml.createFrom('div', { class: 'container' });
|
|
335
|
+
const span = TinyHtml.createFrom('span', { id: 'my-span', title: null });
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
The method can also be aliased for convenience:
|
|
339
|
+
|
|
340
|
+
```js
|
|
341
|
+
const createElement = TinyHtml.createFrom;
|
|
342
|
+
const button = createElement('button', { type: 'submit', class: 'btn' });
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
313
347
|
## π Static DOM Selectors
|
|
314
348
|
|
|
315
349
|
These methods wrap native DOM query methods and return results as `TinyHtml` instances for consistency.
|
|
@@ -377,7 +411,7 @@ Finds the first element by CSS selector.
|
|
|
377
411
|
### `TinyHtml.queryAll(selector)`
|
|
378
412
|
Finds all elements by CSS selector.
|
|
379
413
|
|
|
380
|
-
- **Returns**: `TinyHtml
|
|
414
|
+
- **Returns**: `TinyHtml`
|
|
381
415
|
|
|
382
416
|
---
|
|
383
417
|
|
|
@@ -393,38 +427,204 @@ Selects an element by ID.
|
|
|
393
427
|
### `TinyHtml.getByClassName(selector)`
|
|
394
428
|
Finds elements by class name.
|
|
395
429
|
|
|
396
|
-
- **Returns**: `TinyHtml
|
|
430
|
+
- **Returns**: `TinyHtml`
|
|
397
431
|
|
|
398
432
|
---
|
|
399
433
|
|
|
400
434
|
### `TinyHtml.getByName(selector)`
|
|
401
435
|
Finds elements by `name` attribute.
|
|
402
436
|
|
|
403
|
-
- **Returns**: `TinyHtml
|
|
437
|
+
- **Returns**: `TinyHtml`
|
|
404
438
|
|
|
405
439
|
---
|
|
406
440
|
|
|
407
441
|
### `TinyHtml.getByTagNameNS(localName, namespaceURI?)`
|
|
408
442
|
Finds elements by tag name in a namespace (defaults to XHTML).
|
|
409
443
|
|
|
410
|
-
- **Returns**: `TinyHtml
|
|
444
|
+
- **Returns**: `TinyHtml`
|
|
445
|
+
|
|
446
|
+
---
|
|
447
|
+
|
|
448
|
+
## π HTML Parser
|
|
449
|
+
|
|
450
|
+
### Type Definition
|
|
451
|
+
|
|
452
|
+
A parsed HTML element represented as an array:
|
|
453
|
+
|
|
454
|
+
```ts
|
|
455
|
+
type HtmlParsed = [
|
|
456
|
+
tagName: string, // e.g., 'div', 'span', 'img'
|
|
457
|
+
attributes: Record<string, string>, // Key-value map of all element attributes
|
|
458
|
+
...children: (string | HtmlParsed)[] // Nested elements or text content
|
|
459
|
+
];
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
---
|
|
463
|
+
|
|
464
|
+
### `fetchHtmlFile(url, ops?)`
|
|
465
|
+
|
|
466
|
+
Fetches an HTML file from a URL and parses it into a JSON-like structure.
|
|
467
|
+
|
|
468
|
+
```ts
|
|
469
|
+
static async fetchHtmlFile(url: string | URL | Request, ops?: RequestInit): Promise<HtmlParsed[]>
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
* **url**: The URL of the HTML file.
|
|
473
|
+
* **ops**: (Optional) `fetch()` options (method, headers, etc).
|
|
474
|
+
* **Returns**: Promise of parsed JSON structure (`HtmlParsed[]`).
|
|
475
|
+
* Throws if content-type is not `text/html`.
|
|
476
|
+
|
|
477
|
+
---
|
|
478
|
+
|
|
479
|
+
### `fetchHtmlNodes(url, ops?)`
|
|
480
|
+
|
|
481
|
+
Fetches an HTML file and returns it as DOM nodes.
|
|
482
|
+
|
|
483
|
+
```ts
|
|
484
|
+
static async fetchHtmlNodes(url: string, ops?: RequestInit): Promise<(HTMLElement | Text)[]>
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
* **Returns**: Array of real DOM nodes (`HTMLElement | Text`).
|
|
488
|
+
|
|
489
|
+
---
|
|
490
|
+
|
|
491
|
+
### `fetchHtmlTinyElems(url, ops?)`
|
|
492
|
+
|
|
493
|
+
Fetches HTML and converts it into an array of `TinyHtml` instances.
|
|
494
|
+
|
|
495
|
+
```ts
|
|
496
|
+
static async fetchHtmlTinyElems(url: string, ops?: RequestInit): Promise<TinyHtml[]>
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
* **Returns**: `TinyHtml[]` (custom wrapper elements).
|
|
500
|
+
|
|
501
|
+
---
|
|
502
|
+
|
|
503
|
+
### `templateToJson(template)`
|
|
504
|
+
|
|
505
|
+
Converts the contents of a `<template>` to JSON format.
|
|
506
|
+
|
|
507
|
+
```ts
|
|
508
|
+
static templateToJson(template: HTMLTemplateElement): HtmlParsed[]
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
* **Returns**: Structured JSON representation (`HtmlParsed[]`).
|
|
512
|
+
|
|
513
|
+
---
|
|
514
|
+
|
|
515
|
+
### `templateToNodes(template)`
|
|
516
|
+
|
|
517
|
+
Converts `<template>` content into real DOM nodes.
|
|
518
|
+
|
|
519
|
+
```ts
|
|
520
|
+
static templateToNodes(template: HTMLTemplateElement): (Element | Text)[]
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
* **Returns**: Cloned nodes excluding comments.
|
|
524
|
+
* Throws error if unexpected node types are encountered.
|
|
525
|
+
|
|
526
|
+
---
|
|
527
|
+
|
|
528
|
+
### `templateToTinyElems(template)`
|
|
529
|
+
|
|
530
|
+
Converts a `<template>` into `TinyHtml` instances.
|
|
531
|
+
|
|
532
|
+
```ts
|
|
533
|
+
static templateToTinyElems(template: HTMLTemplateElement): TinyHtml[]
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
* **Returns**: Array of `TinyHtml` objects.
|
|
537
|
+
|
|
538
|
+
---
|
|
539
|
+
|
|
540
|
+
### `htmlToJson(htmlString)`
|
|
541
|
+
|
|
542
|
+
Parses an HTML string into structured JSON (`HtmlParsed[]`).
|
|
543
|
+
|
|
544
|
+
```ts
|
|
545
|
+
static htmlToJson(htmlString: string): HtmlParsed[]
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
* **Returns**: Parsed representation as an array of `[tag, attributes, ...children]`.
|
|
549
|
+
|
|
550
|
+
---
|
|
551
|
+
|
|
552
|
+
### `jsonToNodes(jsonArray)`
|
|
553
|
+
|
|
554
|
+
Converts parsed JSON back into actual DOM nodes.
|
|
555
|
+
|
|
556
|
+
```ts
|
|
557
|
+
static jsonToNodes(jsonArray: HtmlParsed[]): (HTMLElement | Text)[]
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
* **Returns**: Array of DOM elements/text nodes.
|
|
561
|
+
* Skips comments.
|
|
562
|
+
|
|
563
|
+
---
|
|
564
|
+
|
|
565
|
+
### `jsonToTinyElems(jsonArray)`
|
|
566
|
+
|
|
567
|
+
Converts parsed JSON back into `TinyHtml` instances.
|
|
568
|
+
|
|
569
|
+
```ts
|
|
570
|
+
static jsonToTinyElems(jsonArray: HtmlParsed[]): TinyHtml[]
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
* **Returns**: TinyHtml-wrapped elements.
|
|
574
|
+
|
|
575
|
+
---
|
|
576
|
+
|
|
577
|
+
π‘ **Tip**: All conversion methods rely on a consistent internal format (`HtmlParsed[]`). That means you can seamlessly switch between representations (JSON β DOM β TinyHtml)!
|
|
411
578
|
|
|
412
579
|
---
|
|
413
580
|
|
|
414
581
|
## π§© Internal Element Access
|
|
415
582
|
|
|
416
|
-
### `
|
|
583
|
+
### `exists(index)`
|
|
584
|
+
Checks whether the element exists at the given index.
|
|
585
|
+
|
|
586
|
+
- **Returns**: `boolean`
|
|
587
|
+
|
|
588
|
+
---
|
|
589
|
+
|
|
590
|
+
### `get(index)`
|
|
417
591
|
Returns the raw DOM element associated with this instance.
|
|
418
592
|
|
|
419
593
|
- **Returns**: `ConstructorElValues`
|
|
420
594
|
|
|
421
595
|
---
|
|
422
596
|
|
|
423
|
-
### `
|
|
597
|
+
### `size`
|
|
598
|
+
Returns the number of elements currently stored in the internal element list.
|
|
599
|
+
|
|
600
|
+
- **Returns**: `number`
|
|
601
|
+
|
|
602
|
+
---
|
|
603
|
+
|
|
604
|
+
### `extract(index)`
|
|
605
|
+
Extracts a single DOM element from the internal list at the specified index.
|
|
606
|
+
|
|
607
|
+
- **Returns**: `TinyHtml`
|
|
608
|
+
|
|
609
|
+
---
|
|
610
|
+
|
|
611
|
+
### `getAll()`
|
|
612
|
+
Returns the current targets held by this instance.
|
|
613
|
+
|
|
614
|
+
- **Returns**: `ConstructorElValues[]`
|
|
615
|
+
|
|
616
|
+
---
|
|
617
|
+
|
|
618
|
+
### `_getElement(where, index)`
|
|
424
619
|
Safely returns the element with error checking.
|
|
425
620
|
|
|
426
621
|
---
|
|
427
622
|
|
|
623
|
+
### `_getElements(where)`
|
|
624
|
+
Returns the current Elements held by this instance.
|
|
625
|
+
|
|
626
|
+
---
|
|
627
|
+
|
|
428
628
|
## π οΈ Static Pre-Validation Utilities
|
|
429
629
|
|
|
430
630
|
These methods normalize, validate, and prepare elements/nodes before operations. They're internal and mainly used inside the class.
|
|
@@ -1719,6 +1919,68 @@ TinyHtml.hasScroll(element);
|
|
|
1719
1919
|
|
|
1720
1920
|
---
|
|
1721
1921
|
|
|
1922
|
+
## π§ Property Name Normalization
|
|
1923
|
+
|
|
1924
|
+
The object `TinyHtml.propFix` maps HTML attribute names (as strings) to their corresponding JavaScript DOM property names. This works similarly to jQueryβs `propFix`.
|
|
1925
|
+
|
|
1926
|
+
```js
|
|
1927
|
+
TinyHtml.propFix['for']; // "htmlFor"
|
|
1928
|
+
TinyHtml.propFix['class']; // "className"
|
|
1929
|
+
```
|
|
1930
|
+
|
|
1931
|
+
β οΈ **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.
|
|
1932
|
+
|
|
1933
|
+
### βοΈ Adding a New Property Mapping
|
|
1934
|
+
|
|
1935
|
+
To add a new property normalization:
|
|
1936
|
+
|
|
1937
|
+
```js
|
|
1938
|
+
TinyHtml.propFix['readonly'] = 'readOnly';
|
|
1939
|
+
```
|
|
1940
|
+
|
|
1941
|
+
This will automatically make this available:
|
|
1942
|
+
|
|
1943
|
+
```js
|
|
1944
|
+
TinyHtml.attrFix['readOnly']; // "readonly"
|
|
1945
|
+
```
|
|
1946
|
+
|
|
1947
|
+
---
|
|
1948
|
+
|
|
1949
|
+
## π Attribute β Property Mapping
|
|
1950
|
+
|
|
1951
|
+
### π§ `TinyHtml.getPropName(name)`
|
|
1952
|
+
|
|
1953
|
+
Normalizes an HTML attribute name to its corresponding DOM property name.
|
|
1954
|
+
|
|
1955
|
+
```js
|
|
1956
|
+
TinyHtml.getPropName('for'); // "htmlFor"
|
|
1957
|
+
TinyHtml.getPropName('class'); // "className"
|
|
1958
|
+
TinyHtml.getPropName('title'); // "title" (not mapped, returns input)
|
|
1959
|
+
```
|
|
1960
|
+
|
|
1961
|
+
Useful when setting DOM properties programmatically.
|
|
1962
|
+
|
|
1963
|
+
### π§ `TinyHtml.getAttrName(name)`
|
|
1964
|
+
|
|
1965
|
+
Converts a DOM property name back to its equivalent HTML attribute name.
|
|
1966
|
+
|
|
1967
|
+
```js
|
|
1968
|
+
TinyHtml.getAttrName('htmlFor'); // "for"
|
|
1969
|
+
TinyHtml.getAttrName('className'); // "class"
|
|
1970
|
+
TinyHtml.getAttrName('title'); // "title" (not mapped, returns input)
|
|
1971
|
+
```
|
|
1972
|
+
|
|
1973
|
+
Useful when serializing an element back to HTML or attributes.
|
|
1974
|
+
|
|
1975
|
+
### π Behind the Scenes
|
|
1976
|
+
|
|
1977
|
+
* `TinyHtml.propFix` (public) is a proxy of the internal `#propFix` object.
|
|
1978
|
+
* `TinyHtml.attrFix` is auto-generated from `#propFix`, mapping values back in reverse.
|
|
1979
|
+
|
|
1980
|
+
These mappings are kept **in sync automatically** whenever you assign a new property to `TinyHtml.propFix`.
|
|
1981
|
+
|
|
1982
|
+
---
|
|
1983
|
+
|
|
1722
1984
|
## π¨ CSS Property Aliases (`cssPropAliases`)
|
|
1723
1985
|
|
|
1724
1986
|
TinyHtml provides automatic conversion between `camelCase` and `kebab-case` style properties to simplify working with inline styles in HTML elements.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-essentials",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.2",
|
|
4
4
|
"description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "npm run test:mjs && npm run test:cjs && npm run test:js",
|