tiny-essentials 1.22.13 → 1.22.14
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/changelog/1/22/{12.md → 13.md} +1 -1
- package/changelog/1/22/14.md +21 -0
- 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/libs/TinyHtml.cjs +59 -4
- package/dist/v1/libs/TinyHtml.d.mts +36 -2
- package/dist/v1/libs/TinyHtml.mjs +54 -4
- package/docs/v1/README.md +8 -0
- package/docs/v1/libs/TinyHtmlTips.md +140 -0
- package/package.json +1 -1
|
@@ -871,6 +871,17 @@ class TinyHtml {
|
|
|
871
871
|
return new TinyHtml(elems);
|
|
872
872
|
}
|
|
873
873
|
|
|
874
|
+
/**
|
|
875
|
+
* Creates an HTMLElement or TextNode from an HTML string.
|
|
876
|
+
* Supports both elements and plain text.
|
|
877
|
+
*
|
|
878
|
+
* @param {string} htmlString - The HTML string to convert.
|
|
879
|
+
* @returns {TinyHtml<Element>} - A single HTMLElement or TextNode.
|
|
880
|
+
*/
|
|
881
|
+
static createFromHtml(htmlString) {
|
|
882
|
+
return TinyHtml.createFromHTML(htmlString);
|
|
883
|
+
}
|
|
884
|
+
|
|
874
885
|
///////////////////////////////////////////////////
|
|
875
886
|
// TITLE: Query Script
|
|
876
887
|
|
|
@@ -3723,6 +3734,48 @@ class TinyHtml {
|
|
|
3723
3734
|
|
|
3724
3735
|
// TITLE: Animate DOM (Data)
|
|
3725
3736
|
|
|
3737
|
+
/** @type {string} */
|
|
3738
|
+
#mainDisplay = 'block';
|
|
3739
|
+
|
|
3740
|
+
/**
|
|
3741
|
+
* Gets the current display value.
|
|
3742
|
+
* @returns {string}
|
|
3743
|
+
*/
|
|
3744
|
+
get mainDisplay() {
|
|
3745
|
+
return this.#mainDisplay;
|
|
3746
|
+
}
|
|
3747
|
+
|
|
3748
|
+
/**
|
|
3749
|
+
* Sets the display value.
|
|
3750
|
+
* @param {string} value
|
|
3751
|
+
* @throws {TypeError} If the value is not a string.
|
|
3752
|
+
*/
|
|
3753
|
+
set mainDisplay(value) {
|
|
3754
|
+
if (typeof value !== 'string') throw new TypeError('mainDisplay must be a string.');
|
|
3755
|
+
this.#mainDisplay = value;
|
|
3756
|
+
}
|
|
3757
|
+
|
|
3758
|
+
/** @type {string} */
|
|
3759
|
+
static #defaultDisplay = 'block';
|
|
3760
|
+
|
|
3761
|
+
/**
|
|
3762
|
+
* Gets the default display value.
|
|
3763
|
+
* @returns {string}
|
|
3764
|
+
*/
|
|
3765
|
+
static get defaultDisplay() {
|
|
3766
|
+
return TinyHtml.#defaultDisplay;
|
|
3767
|
+
}
|
|
3768
|
+
|
|
3769
|
+
/**
|
|
3770
|
+
* Sets the default display value.
|
|
3771
|
+
* @param {string} value
|
|
3772
|
+
* @throws {TypeError} If the value is not a string.
|
|
3773
|
+
*/
|
|
3774
|
+
static set defaultDisplay(value) {
|
|
3775
|
+
if (typeof value !== 'string') throw new TypeError('defaultDisplay must be a string.');
|
|
3776
|
+
TinyHtml.#defaultDisplay = value;
|
|
3777
|
+
}
|
|
3778
|
+
|
|
3726
3779
|
/**
|
|
3727
3780
|
* Retrieves stored animation data for a given element and key.
|
|
3728
3781
|
* If no data exists yet, initializes storage for that element.
|
|
@@ -4696,11 +4749,12 @@ class TinyHtml {
|
|
|
4696
4749
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - Target element(s) to fade.
|
|
4697
4750
|
* @param {number} opacity - Final opacity value (between 0 and 1).
|
|
4698
4751
|
* @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
|
|
4752
|
+
* @param {string} [mainDisplay=TinyHtml.#defaultDisplay] - Sets the main display value.
|
|
4699
4753
|
* @returns {StyleFxResult}
|
|
4700
4754
|
* @throws {TypeError} If opacity is not a number between 0 and 1.
|
|
4701
4755
|
* @throws {TypeError} If ops is not number|string|object when provided.
|
|
4702
4756
|
*/
|
|
4703
|
-
static fadeTo(el, opacity, ops) {
|
|
4757
|
+
static fadeTo(el, opacity, ops, mainDisplay = TinyHtml.#defaultDisplay) {
|
|
4704
4758
|
if (typeof opacity !== 'number' || isNaN(opacity) || opacity < 0 || opacity > 1)
|
|
4705
4759
|
throw new TypeError('fadeTo: opacity must be a number between 0 and 1.');
|
|
4706
4760
|
|
|
@@ -4728,7 +4782,7 @@ class TinyHtml {
|
|
|
4728
4782
|
if (isHidden) {
|
|
4729
4783
|
// Ensure element is visible (like jQuery does before fading)
|
|
4730
4784
|
const display = TinyHtml.getAnimateData(elem, `origdisplay`);
|
|
4731
|
-
elem.style.display = typeof display === 'string' ? display :
|
|
4785
|
+
elem.style.display = typeof display === 'string' ? display : mainDisplay;
|
|
4732
4786
|
}
|
|
4733
4787
|
|
|
4734
4788
|
/** @type {AnimationSfxData} */
|
|
@@ -4752,12 +4806,13 @@ class TinyHtml {
|
|
|
4752
4806
|
*
|
|
4753
4807
|
* @param {number} opacity - Final opacity value (between 0 and 1).
|
|
4754
4808
|
* @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
|
|
4809
|
+
* @param {string} [mainDisplay=this.#mainDisplay] - Sets the main display value.
|
|
4755
4810
|
* @returns {StyleFxResult}
|
|
4756
4811
|
* @throws {TypeError} If opacity is not a number between 0 and 1.
|
|
4757
4812
|
* @throws {TypeError} If ops is not number|string|object when provided.
|
|
4758
4813
|
*/
|
|
4759
|
-
fadeTo(opacity, ops) {
|
|
4760
|
-
return TinyHtml.fadeTo(this, opacity, ops);
|
|
4814
|
+
fadeTo(opacity, ops, mainDisplay = this.#mainDisplay) {
|
|
4815
|
+
return TinyHtml.fadeTo(this, opacity, ops, mainDisplay);
|
|
4761
4816
|
}
|
|
4762
4817
|
|
|
4763
4818
|
///////////////////////////////////////////////////////////////
|
|
@@ -510,6 +510,14 @@ declare class TinyHtml<TinyHtmlT extends TinyHtmlConstructor> {
|
|
|
510
510
|
* @returns {TinyHtml<Element>} - A single HTMLElement or TextNode.
|
|
511
511
|
*/
|
|
512
512
|
static createFromHTML(htmlString: string): TinyHtml<Element>;
|
|
513
|
+
/**
|
|
514
|
+
* Creates an HTMLElement or TextNode from an HTML string.
|
|
515
|
+
* Supports both elements and plain text.
|
|
516
|
+
*
|
|
517
|
+
* @param {string} htmlString - The HTML string to convert.
|
|
518
|
+
* @returns {TinyHtml<Element>} - A single HTMLElement or TextNode.
|
|
519
|
+
*/
|
|
520
|
+
static createFromHtml(htmlString: string): TinyHtml<Element>;
|
|
513
521
|
/**
|
|
514
522
|
* Queries the document for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
515
523
|
*
|
|
@@ -1442,6 +1450,19 @@ declare class TinyHtml<TinyHtmlT extends TinyHtmlConstructor> {
|
|
|
1442
1450
|
* @returns {number}
|
|
1443
1451
|
*/
|
|
1444
1452
|
static outerWidth(el: TinyElementAndWinAndDoc, includeMargin?: boolean): number;
|
|
1453
|
+
/** @type {string} */
|
|
1454
|
+
static "__#8@#defaultDisplay": string;
|
|
1455
|
+
/**
|
|
1456
|
+
* Sets the default display value.
|
|
1457
|
+
* @param {string} value
|
|
1458
|
+
* @throws {TypeError} If the value is not a string.
|
|
1459
|
+
*/
|
|
1460
|
+
static set defaultDisplay(value: string);
|
|
1461
|
+
/**
|
|
1462
|
+
* Gets the default display value.
|
|
1463
|
+
* @returns {string}
|
|
1464
|
+
*/
|
|
1465
|
+
static get defaultDisplay(): string;
|
|
1445
1466
|
/**
|
|
1446
1467
|
* Retrieves stored animation data for a given element and key.
|
|
1447
1468
|
* If no data exists yet, initializes storage for that element.
|
|
@@ -1815,11 +1836,12 @@ declare class TinyHtml<TinyHtmlT extends TinyHtmlConstructor> {
|
|
|
1815
1836
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - Target element(s) to fade.
|
|
1816
1837
|
* @param {number} opacity - Final opacity value (between 0 and 1).
|
|
1817
1838
|
* @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
|
|
1839
|
+
* @param {string} [mainDisplay=TinyHtml.#defaultDisplay] - Sets the main display value.
|
|
1818
1840
|
* @returns {StyleFxResult}
|
|
1819
1841
|
* @throws {TypeError} If opacity is not a number between 0 and 1.
|
|
1820
1842
|
* @throws {TypeError} If ops is not number|string|object when provided.
|
|
1821
1843
|
*/
|
|
1822
|
-
static fadeTo(el: TinyHtmlElement | TinyHtmlElement[], opacity: number, ops?: number | KeyframeAnimationOptions | string): StyleFxResult;
|
|
1844
|
+
static fadeTo(el: TinyHtmlElement | TinyHtmlElement[], opacity: number, ops?: number | KeyframeAnimationOptions | string, mainDisplay?: string): StyleFxResult;
|
|
1823
1845
|
/**
|
|
1824
1846
|
* Gets the offset of the element relative to the document.
|
|
1825
1847
|
* @param {TinyElement} el - Target element.
|
|
@@ -3272,6 +3294,17 @@ declare class TinyHtml<TinyHtmlT extends TinyHtmlConstructor> {
|
|
|
3272
3294
|
* @returns {number}
|
|
3273
3295
|
*/
|
|
3274
3296
|
outerWidth(includeMargin?: boolean): number;
|
|
3297
|
+
/**
|
|
3298
|
+
* Sets the display value.
|
|
3299
|
+
* @param {string} value
|
|
3300
|
+
* @throws {TypeError} If the value is not a string.
|
|
3301
|
+
*/
|
|
3302
|
+
set mainDisplay(value: string);
|
|
3303
|
+
/**
|
|
3304
|
+
* Gets the current display value.
|
|
3305
|
+
* @returns {string}
|
|
3306
|
+
*/
|
|
3307
|
+
get mainDisplay(): string;
|
|
3275
3308
|
/**
|
|
3276
3309
|
* Applies style-based effects (slide, fade) to one or more elements.
|
|
3277
3310
|
* Converts abstract effect definitions (e.g., `{ height: "show" }`)
|
|
@@ -3345,11 +3378,12 @@ declare class TinyHtml<TinyHtmlT extends TinyHtmlConstructor> {
|
|
|
3345
3378
|
*
|
|
3346
3379
|
* @param {number} opacity - Final opacity value (between 0 and 1).
|
|
3347
3380
|
* @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
|
|
3381
|
+
* @param {string} [mainDisplay=this.#mainDisplay] - Sets the main display value.
|
|
3348
3382
|
* @returns {StyleFxResult}
|
|
3349
3383
|
* @throws {TypeError} If opacity is not a number between 0 and 1.
|
|
3350
3384
|
* @throws {TypeError} If ops is not number|string|object when provided.
|
|
3351
3385
|
*/
|
|
3352
|
-
fadeTo(opacity: number, ops?: number | KeyframeAnimationOptions | string): StyleFxResult;
|
|
3386
|
+
fadeTo(opacity: number, ops?: number | KeyframeAnimationOptions | string, mainDisplay?: string): StyleFxResult;
|
|
3353
3387
|
/**
|
|
3354
3388
|
* Gets the offset of the element relative to the document.
|
|
3355
3389
|
* @returns {{top: number, left: number}}
|
|
@@ -752,6 +752,16 @@ class TinyHtml {
|
|
|
752
752
|
throw new Error('The HTML string must contain a valid HTML element.');
|
|
753
753
|
return new TinyHtml(elems);
|
|
754
754
|
}
|
|
755
|
+
/**
|
|
756
|
+
* Creates an HTMLElement or TextNode from an HTML string.
|
|
757
|
+
* Supports both elements and plain text.
|
|
758
|
+
*
|
|
759
|
+
* @param {string} htmlString - The HTML string to convert.
|
|
760
|
+
* @returns {TinyHtml<Element>} - A single HTMLElement or TextNode.
|
|
761
|
+
*/
|
|
762
|
+
static createFromHtml(htmlString) {
|
|
763
|
+
return TinyHtml.createFromHTML(htmlString);
|
|
764
|
+
}
|
|
755
765
|
///////////////////////////////////////////////////
|
|
756
766
|
// TITLE: Query Script
|
|
757
767
|
/**
|
|
@@ -3329,6 +3339,44 @@ class TinyHtml {
|
|
|
3329
3339
|
}
|
|
3330
3340
|
//////////////////////////////////////////////////
|
|
3331
3341
|
// TITLE: Animate DOM (Data)
|
|
3342
|
+
/** @type {string} */
|
|
3343
|
+
#mainDisplay = 'block';
|
|
3344
|
+
/**
|
|
3345
|
+
* Gets the current display value.
|
|
3346
|
+
* @returns {string}
|
|
3347
|
+
*/
|
|
3348
|
+
get mainDisplay() {
|
|
3349
|
+
return this.#mainDisplay;
|
|
3350
|
+
}
|
|
3351
|
+
/**
|
|
3352
|
+
* Sets the display value.
|
|
3353
|
+
* @param {string} value
|
|
3354
|
+
* @throws {TypeError} If the value is not a string.
|
|
3355
|
+
*/
|
|
3356
|
+
set mainDisplay(value) {
|
|
3357
|
+
if (typeof value !== 'string')
|
|
3358
|
+
throw new TypeError('mainDisplay must be a string.');
|
|
3359
|
+
this.#mainDisplay = value;
|
|
3360
|
+
}
|
|
3361
|
+
/** @type {string} */
|
|
3362
|
+
static #defaultDisplay = 'block';
|
|
3363
|
+
/**
|
|
3364
|
+
* Gets the default display value.
|
|
3365
|
+
* @returns {string}
|
|
3366
|
+
*/
|
|
3367
|
+
static get defaultDisplay() {
|
|
3368
|
+
return TinyHtml.#defaultDisplay;
|
|
3369
|
+
}
|
|
3370
|
+
/**
|
|
3371
|
+
* Sets the default display value.
|
|
3372
|
+
* @param {string} value
|
|
3373
|
+
* @throws {TypeError} If the value is not a string.
|
|
3374
|
+
*/
|
|
3375
|
+
static set defaultDisplay(value) {
|
|
3376
|
+
if (typeof value !== 'string')
|
|
3377
|
+
throw new TypeError('defaultDisplay must be a string.');
|
|
3378
|
+
TinyHtml.#defaultDisplay = value;
|
|
3379
|
+
}
|
|
3332
3380
|
/**
|
|
3333
3381
|
* Retrieves stored animation data for a given element and key.
|
|
3334
3382
|
* If no data exists yet, initializes storage for that element.
|
|
@@ -4217,11 +4265,12 @@ class TinyHtml {
|
|
|
4217
4265
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - Target element(s) to fade.
|
|
4218
4266
|
* @param {number} opacity - Final opacity value (between 0 and 1).
|
|
4219
4267
|
* @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
|
|
4268
|
+
* @param {string} [mainDisplay=TinyHtml.#defaultDisplay] - Sets the main display value.
|
|
4220
4269
|
* @returns {StyleFxResult}
|
|
4221
4270
|
* @throws {TypeError} If opacity is not a number between 0 and 1.
|
|
4222
4271
|
* @throws {TypeError} If ops is not number|string|object when provided.
|
|
4223
4272
|
*/
|
|
4224
|
-
static fadeTo(el, opacity, ops) {
|
|
4273
|
+
static fadeTo(el, opacity, ops, mainDisplay = TinyHtml.#defaultDisplay) {
|
|
4225
4274
|
if (typeof opacity !== 'number' || isNaN(opacity) || opacity < 0 || opacity > 1)
|
|
4226
4275
|
throw new TypeError('fadeTo: opacity must be a number between 0 and 1.');
|
|
4227
4276
|
if (ops !== undefined &&
|
|
@@ -4240,7 +4289,7 @@ class TinyHtml {
|
|
|
4240
4289
|
if (isHidden) {
|
|
4241
4290
|
// Ensure element is visible (like jQuery does before fading)
|
|
4242
4291
|
const display = TinyHtml.getAnimateData(elem, `origdisplay`);
|
|
4243
|
-
elem.style.display = typeof display === 'string' ? display :
|
|
4292
|
+
elem.style.display = typeof display === 'string' ? display : mainDisplay;
|
|
4244
4293
|
}
|
|
4245
4294
|
/** @type {AnimationSfxData} */
|
|
4246
4295
|
const keyframes = {
|
|
@@ -4259,12 +4308,13 @@ class TinyHtml {
|
|
|
4259
4308
|
*
|
|
4260
4309
|
* @param {number} opacity - Final opacity value (between 0 and 1).
|
|
4261
4310
|
* @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
|
|
4311
|
+
* @param {string} [mainDisplay=this.#mainDisplay] - Sets the main display value.
|
|
4262
4312
|
* @returns {StyleFxResult}
|
|
4263
4313
|
* @throws {TypeError} If opacity is not a number between 0 and 1.
|
|
4264
4314
|
* @throws {TypeError} If ops is not number|string|object when provided.
|
|
4265
4315
|
*/
|
|
4266
|
-
fadeTo(opacity, ops) {
|
|
4267
|
-
return TinyHtml.fadeTo(this, opacity, ops);
|
|
4316
|
+
fadeTo(opacity, ops, mainDisplay = this.#mainDisplay) {
|
|
4317
|
+
return TinyHtml.fadeTo(this, opacity, ops, mainDisplay);
|
|
4268
4318
|
}
|
|
4269
4319
|
///////////////////////////////////////////////////////////////
|
|
4270
4320
|
// TITLE: DOM Positions
|
package/docs/v1/README.md
CHANGED
|
@@ -64,6 +64,14 @@ This folder contains the core scripts we have worked on so far. Each file is a m
|
|
|
64
64
|
|
|
65
65
|
---
|
|
66
66
|
|
|
67
|
+
## 📚 Tip Directories
|
|
68
|
+
|
|
69
|
+
### 1. **`libs/`**
|
|
70
|
+
|
|
71
|
+
- 🧱 **[TinyHtml](./libs/TinyHtmlTips.md)** — Usage examples and practical tips.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
67
75
|
## 🚀 Usage
|
|
68
76
|
|
|
69
77
|
To get started, navigate to the appropriate directory and explore the files listed. Each script includes detailed documentation on how to use the respective functionality.
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# 🔧 TinyHtml Shortcuts & Aliases
|
|
2
|
+
|
|
3
|
+
One of the coolest things about **TinyHtml** is that you can give its static methods **custom names (aliases)** 🎉.
|
|
4
|
+
This allows you to mimic the style of jQuery, native browser functions, or even create your own conventions for working with the DOM.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 🎭 Mimic jQuery Style
|
|
9
|
+
|
|
10
|
+
If you’re a fan of jQuery’s `$` syntax, you can directly alias TinyHtml methods:
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
// Select multiple elements (like jQuery's $)
|
|
14
|
+
const $ = TinyHtml.queryAll;
|
|
15
|
+
|
|
16
|
+
// Usage
|
|
17
|
+
$('.my-class').forEach(el => console.log(el));
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 💎 Super jQuery-like Style
|
|
23
|
+
|
|
24
|
+
If you want TinyHtml to feel **almost exactly like jQuery**, you can define `$` as a **function wrapper** that automatically instantiates a `TinyHtml` object from a CSS selector.
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
// jQuery-style $ function
|
|
28
|
+
const $ = (queryString) => new TinyHtml(queryString);
|
|
29
|
+
|
|
30
|
+
// Usage
|
|
31
|
+
$('#my-id').addClass('highlight');
|
|
32
|
+
$('.btn').on('click', () => alert('Clicked!'));
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 🌐 Mimic Native Browser Querying
|
|
38
|
+
|
|
39
|
+
If you prefer the style of the **native browser query** functions (`querySelector` and `querySelectorAll`), you can do:
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
// Select single element (like document.querySelector)
|
|
43
|
+
const $ = TinyHtml.query;
|
|
44
|
+
|
|
45
|
+
// Select multiple elements (like document.querySelectorAll)
|
|
46
|
+
const $$ = TinyHtml.queryAll;
|
|
47
|
+
|
|
48
|
+
// Usage
|
|
49
|
+
const button = $('#my-button');
|
|
50
|
+
const divs = $$('.container');
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 🛠️ Extra: Element Creation Shortcut
|
|
56
|
+
|
|
57
|
+
TinyHtml also supports element creation. You can alias this too for faster coding:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
// Create elements from plain strings
|
|
61
|
+
const $$$ = TinyHtml.createFrom;
|
|
62
|
+
|
|
63
|
+
// OR, if you want it more explicit:
|
|
64
|
+
const $$$ = TinyHtml.createFromHtml;
|
|
65
|
+
|
|
66
|
+
// Usage
|
|
67
|
+
const newDiv = $$$('<div class="box">Hello!</div>');
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 🚀 Why Aliases?
|
|
73
|
+
|
|
74
|
+
Aliases are especially handy when:
|
|
75
|
+
|
|
76
|
+
* You want **shorter code** ✨
|
|
77
|
+
* You’re working on **personal projects** with a custom coding style
|
|
78
|
+
* You want to **simulate familiar APIs** like jQuery or browser query functions
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
👉 In summary, **TinyHtml is flexible**: you can stick to its original method names for clarity, or create **shortcuts** to match your own workflow.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
# 📦 Creating a TinyHtml Shortcuts Module
|
|
87
|
+
|
|
88
|
+
Instead of redefining your shortcuts (`$`, `$$`, `$$$`) in every file, you can create a **dedicated module** that exports them.
|
|
89
|
+
This makes your setup **cleaner, reusable, and consistent** across the whole project.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 🛠️ Example: shortcuts.js
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
// Enable debugging mode
|
|
97
|
+
TinyHtml.elemDebug = true;
|
|
98
|
+
|
|
99
|
+
// jQuery-style single element selector
|
|
100
|
+
export const $ = (queryString) => new TinyHtml(queryString);
|
|
101
|
+
|
|
102
|
+
// Create elements from HTML objects
|
|
103
|
+
export const $$ = TinyHtml.createFrom;
|
|
104
|
+
|
|
105
|
+
// Create elements from HTML strings
|
|
106
|
+
export const $$$ = TinyHtml.createFromHTML;
|
|
107
|
+
|
|
108
|
+
// Export TinyHtml’s observer utility
|
|
109
|
+
export const mainObserver = TinyHtml.tinyObserver;
|
|
110
|
+
|
|
111
|
+
// Set TinyHtml’s default display css
|
|
112
|
+
TinyHtml.defaultDisplay = 'block';
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 🚀 Usage in Your Project
|
|
118
|
+
|
|
119
|
+
Now you can simply import the shortcuts wherever you need them:
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
import { $, $$, $$$ } from './shortcuts.js';
|
|
123
|
+
|
|
124
|
+
// Select a button
|
|
125
|
+
const btn = $('#submit');
|
|
126
|
+
|
|
127
|
+
// Create and append an element
|
|
128
|
+
const newBox = $$('div', { class: 'box' });
|
|
129
|
+
|
|
130
|
+
// Set element's default display css
|
|
131
|
+
newBox.mainDisplay = 'block';
|
|
132
|
+
|
|
133
|
+
// Create an element
|
|
134
|
+
const newBox2 = $$$('<div class="box">Hello!</div>');
|
|
135
|
+
$('body').append(newBox);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
👉 With this setup, you end up with your own **personalized DOM toolkit**, powered by TinyHtml but feeling **as smooth as jQuery**.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-essentials",
|
|
3
|
-
"version": "1.22.
|
|
3
|
+
"version": "1.22.14",
|
|
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",
|