tiny-essentials 1.22.13 → 1.22.15

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.
@@ -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
 
@@ -2622,6 +2633,7 @@ class TinyHtml {
2622
2633
  */
2623
2634
  constructor(el) {
2624
2635
  this.#el = TinyHtml._selector(el);
2636
+ this.#mainDisplay = TinyHtml.#defaultDisplay;
2625
2637
  }
2626
2638
 
2627
2639
  /**
@@ -3723,6 +3735,48 @@ class TinyHtml {
3723
3735
 
3724
3736
  // TITLE: Animate DOM (Data)
3725
3737
 
3738
+ /** @type {string} */
3739
+ #mainDisplay = '';
3740
+
3741
+ /**
3742
+ * Gets the current display value.
3743
+ * @returns {string}
3744
+ */
3745
+ get mainDisplay() {
3746
+ return this.#mainDisplay;
3747
+ }
3748
+
3749
+ /**
3750
+ * Sets the display value.
3751
+ * @param {string} value
3752
+ * @throws {TypeError} If the value is not a string.
3753
+ */
3754
+ set mainDisplay(value) {
3755
+ if (typeof value !== 'string') throw new TypeError('mainDisplay must be a string.');
3756
+ this.#mainDisplay = value;
3757
+ }
3758
+
3759
+ /** @type {string} */
3760
+ static #defaultDisplay = 'block';
3761
+
3762
+ /**
3763
+ * Gets the default display value.
3764
+ * @returns {string}
3765
+ */
3766
+ static get defaultDisplay() {
3767
+ return TinyHtml.#defaultDisplay;
3768
+ }
3769
+
3770
+ /**
3771
+ * Sets the default display value.
3772
+ * @param {string} value
3773
+ * @throws {TypeError} If the value is not a string.
3774
+ */
3775
+ static set defaultDisplay(value) {
3776
+ if (typeof value !== 'string') throw new TypeError('defaultDisplay must be a string.');
3777
+ TinyHtml.#defaultDisplay = value;
3778
+ }
3779
+
3726
3780
  /**
3727
3781
  * Retrieves stored animation data for a given element and key.
3728
3782
  * If no data exists yet, initializes storage for that element.
@@ -4696,11 +4750,12 @@ class TinyHtml {
4696
4750
  * @param {TinyHtmlElement|TinyHtmlElement[]} el - Target element(s) to fade.
4697
4751
  * @param {number} opacity - Final opacity value (between 0 and 1).
4698
4752
  * @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
4753
+ * @param {string} [mainDisplay=TinyHtml.#defaultDisplay] - Sets the main display value.
4699
4754
  * @returns {StyleFxResult}
4700
4755
  * @throws {TypeError} If opacity is not a number between 0 and 1.
4701
4756
  * @throws {TypeError} If ops is not number|string|object when provided.
4702
4757
  */
4703
- static fadeTo(el, opacity, ops) {
4758
+ static fadeTo(el, opacity, ops, mainDisplay = TinyHtml.#defaultDisplay) {
4704
4759
  if (typeof opacity !== 'number' || isNaN(opacity) || opacity < 0 || opacity > 1)
4705
4760
  throw new TypeError('fadeTo: opacity must be a number between 0 and 1.');
4706
4761
 
@@ -4728,7 +4783,7 @@ class TinyHtml {
4728
4783
  if (isHidden) {
4729
4784
  // Ensure element is visible (like jQuery does before fading)
4730
4785
  const display = TinyHtml.getAnimateData(elem, `origdisplay`);
4731
- elem.style.display = typeof display === 'string' ? display : 'block';
4786
+ elem.style.display = typeof display === 'string' ? display : mainDisplay;
4732
4787
  }
4733
4788
 
4734
4789
  /** @type {AnimationSfxData} */
@@ -4752,12 +4807,13 @@ class TinyHtml {
4752
4807
  *
4753
4808
  * @param {number} opacity - Final opacity value (between 0 and 1).
4754
4809
  * @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
4810
+ * @param {string} [mainDisplay=this.#mainDisplay] - Sets the main display value.
4755
4811
  * @returns {StyleFxResult}
4756
4812
  * @throws {TypeError} If opacity is not a number between 0 and 1.
4757
4813
  * @throws {TypeError} If ops is not number|string|object when provided.
4758
4814
  */
4759
- fadeTo(opacity, ops) {
4760
- return TinyHtml.fadeTo(this, opacity, ops);
4815
+ fadeTo(opacity, ops, mainDisplay = this.#mainDisplay) {
4816
+ return TinyHtml.fadeTo(this, opacity, ops, mainDisplay);
4761
4817
  }
4762
4818
 
4763
4819
  ///////////////////////////////////////////////////////////////
@@ -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
  /**
@@ -2315,6 +2325,7 @@ class TinyHtml {
2315
2325
  */
2316
2326
  constructor(el) {
2317
2327
  this.#el = TinyHtml._selector(el);
2328
+ this.#mainDisplay = TinyHtml.#defaultDisplay;
2318
2329
  }
2319
2330
  /**
2320
2331
  * Checks whether the given object is a window.
@@ -3329,6 +3340,44 @@ class TinyHtml {
3329
3340
  }
3330
3341
  //////////////////////////////////////////////////
3331
3342
  // TITLE: Animate DOM (Data)
3343
+ /** @type {string} */
3344
+ #mainDisplay = '';
3345
+ /**
3346
+ * Gets the current display value.
3347
+ * @returns {string}
3348
+ */
3349
+ get mainDisplay() {
3350
+ return this.#mainDisplay;
3351
+ }
3352
+ /**
3353
+ * Sets the display value.
3354
+ * @param {string} value
3355
+ * @throws {TypeError} If the value is not a string.
3356
+ */
3357
+ set mainDisplay(value) {
3358
+ if (typeof value !== 'string')
3359
+ throw new TypeError('mainDisplay must be a string.');
3360
+ this.#mainDisplay = value;
3361
+ }
3362
+ /** @type {string} */
3363
+ static #defaultDisplay = 'block';
3364
+ /**
3365
+ * Gets the default display value.
3366
+ * @returns {string}
3367
+ */
3368
+ static get defaultDisplay() {
3369
+ return TinyHtml.#defaultDisplay;
3370
+ }
3371
+ /**
3372
+ * Sets the default display value.
3373
+ * @param {string} value
3374
+ * @throws {TypeError} If the value is not a string.
3375
+ */
3376
+ static set defaultDisplay(value) {
3377
+ if (typeof value !== 'string')
3378
+ throw new TypeError('defaultDisplay must be a string.');
3379
+ TinyHtml.#defaultDisplay = value;
3380
+ }
3332
3381
  /**
3333
3382
  * Retrieves stored animation data for a given element and key.
3334
3383
  * If no data exists yet, initializes storage for that element.
@@ -4217,11 +4266,12 @@ class TinyHtml {
4217
4266
  * @param {TinyHtmlElement|TinyHtmlElement[]} el - Target element(s) to fade.
4218
4267
  * @param {number} opacity - Final opacity value (between 0 and 1).
4219
4268
  * @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
4269
+ * @param {string} [mainDisplay=TinyHtml.#defaultDisplay] - Sets the main display value.
4220
4270
  * @returns {StyleFxResult}
4221
4271
  * @throws {TypeError} If opacity is not a number between 0 and 1.
4222
4272
  * @throws {TypeError} If ops is not number|string|object when provided.
4223
4273
  */
4224
- static fadeTo(el, opacity, ops) {
4274
+ static fadeTo(el, opacity, ops, mainDisplay = TinyHtml.#defaultDisplay) {
4225
4275
  if (typeof opacity !== 'number' || isNaN(opacity) || opacity < 0 || opacity > 1)
4226
4276
  throw new TypeError('fadeTo: opacity must be a number between 0 and 1.');
4227
4277
  if (ops !== undefined &&
@@ -4240,7 +4290,7 @@ class TinyHtml {
4240
4290
  if (isHidden) {
4241
4291
  // Ensure element is visible (like jQuery does before fading)
4242
4292
  const display = TinyHtml.getAnimateData(elem, `origdisplay`);
4243
- elem.style.display = typeof display === 'string' ? display : 'block';
4293
+ elem.style.display = typeof display === 'string' ? display : mainDisplay;
4244
4294
  }
4245
4295
  /** @type {AnimationSfxData} */
4246
4296
  const keyframes = {
@@ -4259,12 +4309,13 @@ class TinyHtml {
4259
4309
  *
4260
4310
  * @param {number} opacity - Final opacity value (between 0 and 1).
4261
4311
  * @param {number | KeyframeAnimationOptions | string} [ops] - Duration or animation options.
4312
+ * @param {string} [mainDisplay=this.#mainDisplay] - Sets the main display value.
4262
4313
  * @returns {StyleFxResult}
4263
4314
  * @throws {TypeError} If opacity is not a number between 0 and 1.
4264
4315
  * @throws {TypeError} If ops is not number|string|object when provided.
4265
4316
  */
4266
- fadeTo(opacity, ops) {
4267
- return TinyHtml.fadeTo(this, opacity, ops);
4317
+ fadeTo(opacity, ops, mainDisplay = this.#mainDisplay) {
4318
+ return TinyHtml.fadeTo(this, opacity, ops, mainDisplay);
4268
4319
  }
4269
4320
  ///////////////////////////////////////////////////////////////
4270
4321
  // 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.13",
3
+ "version": "1.22.15",
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",