tiny-essentials 1.22.9 → 1.22.11
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/10.md +15 -0
- package/changelog/1/22/11.md +12 -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 +44 -17
- package/dist/v1/libs/TinyHtml.d.mts +34 -24
- package/dist/v1/libs/TinyHtml.mjs +42 -18
- package/docs/v1/libs/TinyHtml.md +3 -3
- package/package.json +5 -1
|
@@ -815,6 +815,8 @@ class TinyHtml {
|
|
|
815
815
|
}
|
|
816
816
|
|
|
817
817
|
/**
|
|
818
|
+
* @deprecated Use the {@link createFromHTML} instead.
|
|
819
|
+
*
|
|
818
820
|
* Creates an HTMLElement or TextNode from an HTML string.
|
|
819
821
|
* Supports both elements and plain text.
|
|
820
822
|
*
|
|
@@ -836,6 +838,24 @@ class TinyHtml {
|
|
|
836
838
|
return new TinyHtml(template.content.firstChild);
|
|
837
839
|
}
|
|
838
840
|
|
|
841
|
+
/**
|
|
842
|
+
* Creates an HTMLElement or TextNode from an HTML string.
|
|
843
|
+
* Supports both elements and plain text.
|
|
844
|
+
*
|
|
845
|
+
* @param {string} htmlString - The HTML string to convert.
|
|
846
|
+
* @returns {TinyHtml<Element>} - A single HTMLElement or TextNode.
|
|
847
|
+
*/
|
|
848
|
+
static createFromHTML(htmlString) {
|
|
849
|
+
const template = document.createElement('template');
|
|
850
|
+
htmlString = htmlString.trim();
|
|
851
|
+
|
|
852
|
+
template.innerHTML = htmlString;
|
|
853
|
+
const elems = Array.from(template.content.childNodes);
|
|
854
|
+
if (!elems.every((item) => item instanceof Element || item instanceof Text))
|
|
855
|
+
throw new Error('The HTML string must contain a valid HTML element.');
|
|
856
|
+
return new TinyHtml(elems);
|
|
857
|
+
}
|
|
858
|
+
|
|
839
859
|
///////////////////////////////////////////////////
|
|
840
860
|
// TITLE: Query Script
|
|
841
861
|
|
|
@@ -1627,12 +1647,12 @@ class TinyHtml {
|
|
|
1627
1647
|
}
|
|
1628
1648
|
|
|
1629
1649
|
/**
|
|
1630
|
-
*
|
|
1650
|
+
* Returns elements from the current list that contain the given target(s).
|
|
1631
1651
|
* @param {string|TinyElement|TinyElement[]} target - Selector or DOM element(s).
|
|
1632
|
-
* @returns {
|
|
1652
|
+
* @returns {Element[]} Elements that contain the target.
|
|
1633
1653
|
*/
|
|
1634
1654
|
has(target) {
|
|
1635
|
-
return TinyHtml.has(this, target)
|
|
1655
|
+
return TinyHtml.has(this, target);
|
|
1636
1656
|
}
|
|
1637
1657
|
|
|
1638
1658
|
/**
|
|
@@ -2154,7 +2174,7 @@ class TinyHtml {
|
|
|
2154
2174
|
/**
|
|
2155
2175
|
* Normalize and validate nodes before DOM insertion.
|
|
2156
2176
|
* Converts TinyNode-like structures or strings into DOM-compatible nodes.
|
|
2157
|
-
* @type {(where: string, ...nodes: AppendCheckerValues[]) => (Node | string)[]}
|
|
2177
|
+
* @type {(where: string, ...nodes: (AppendCheckerValues|Record<string, AppendCheckerValues>)[]) => (Node | string)[]}
|
|
2158
2178
|
* @readonly
|
|
2159
2179
|
*/
|
|
2160
2180
|
static _appendChecker(where, ...nodes) {
|
|
@@ -2162,9 +2182,16 @@ class TinyHtml {
|
|
|
2162
2182
|
const results = [];
|
|
2163
2183
|
for (const item of nodes) {
|
|
2164
2184
|
if (typeof item === 'undefined' || item === null || item === false) continue;
|
|
2165
|
-
if (typeof item !== 'string') {
|
|
2166
|
-
if (
|
|
2167
|
-
|
|
2185
|
+
if (typeof item !== 'string' && typeof item !== 'number') {
|
|
2186
|
+
if (item instanceof Node || item instanceof TinyHtml)
|
|
2187
|
+
results.push(...TinyHtml._preNodeElems(item, where));
|
|
2188
|
+
else if (Array.isArray(item)) results.push(...TinyHtml._appendChecker(where, ...item));
|
|
2189
|
+
else {
|
|
2190
|
+
for (const name in item) {
|
|
2191
|
+
const elems = item[name];
|
|
2192
|
+
results.push(...TinyHtml._appendChecker(where, elems));
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2168
2195
|
} else results.push(item);
|
|
2169
2196
|
}
|
|
2170
2197
|
return results;
|
|
@@ -2175,7 +2202,7 @@ class TinyHtml {
|
|
|
2175
2202
|
*
|
|
2176
2203
|
* @template {TinyElement} T
|
|
2177
2204
|
* @param {T} el - The target element(s) to receive children.
|
|
2178
|
-
* @param {...AppendCheckerValues} children - The child elements or text to append.
|
|
2205
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - The child elements or text to append.
|
|
2179
2206
|
* @returns {T}
|
|
2180
2207
|
*/
|
|
2181
2208
|
static append(el, ...children) {
|
|
@@ -2187,7 +2214,7 @@ class TinyHtml {
|
|
|
2187
2214
|
/**
|
|
2188
2215
|
* Appends child elements or strings to the end of the target element(s).
|
|
2189
2216
|
*
|
|
2190
|
-
* @param {...AppendCheckerValues} children - The child elements or text to append.
|
|
2217
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - The child elements or text to append.
|
|
2191
2218
|
* @returns {this}
|
|
2192
2219
|
*/
|
|
2193
2220
|
append(...children) {
|
|
@@ -2199,7 +2226,7 @@ class TinyHtml {
|
|
|
2199
2226
|
*
|
|
2200
2227
|
* @template {TinyElement} T
|
|
2201
2228
|
* @param {T} el - The target element(s) to receive children.
|
|
2202
|
-
* @param {...AppendCheckerValues} children - The child elements or text to prepend.
|
|
2229
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - The child elements or text to prepend.
|
|
2203
2230
|
* @returns {T}
|
|
2204
2231
|
*/
|
|
2205
2232
|
static prepend(el, ...children) {
|
|
@@ -2211,7 +2238,7 @@ class TinyHtml {
|
|
|
2211
2238
|
/**
|
|
2212
2239
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
2213
2240
|
*
|
|
2214
|
-
* @param {...AppendCheckerValues} children - The child elements or text to prepend.
|
|
2241
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - The child elements or text to prepend.
|
|
2215
2242
|
* @returns {this}
|
|
2216
2243
|
*/
|
|
2217
2244
|
prepend(...children) {
|
|
@@ -2223,7 +2250,7 @@ class TinyHtml {
|
|
|
2223
2250
|
*
|
|
2224
2251
|
* @template {TinyElement} T
|
|
2225
2252
|
* @param {T} el - The target element(s) before which new content is inserted.
|
|
2226
|
-
* @param {...AppendCheckerValues} children - Elements or text to insert before the target.
|
|
2253
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - Elements or text to insert before the target.
|
|
2227
2254
|
* @returns {T}
|
|
2228
2255
|
*/
|
|
2229
2256
|
static before(el, ...children) {
|
|
@@ -2235,7 +2262,7 @@ class TinyHtml {
|
|
|
2235
2262
|
/**
|
|
2236
2263
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
2237
2264
|
*
|
|
2238
|
-
* @param {...AppendCheckerValues} children - Elements or text to insert before the target.
|
|
2265
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - Elements or text to insert before the target.
|
|
2239
2266
|
* @returns {this}
|
|
2240
2267
|
*/
|
|
2241
2268
|
before(...children) {
|
|
@@ -2247,7 +2274,7 @@ class TinyHtml {
|
|
|
2247
2274
|
*
|
|
2248
2275
|
* @template {TinyElement} T
|
|
2249
2276
|
* @param {T} el - The target element(s) after which new content is inserted.
|
|
2250
|
-
* @param {...AppendCheckerValues} children - Elements or text to insert after the target.
|
|
2277
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - Elements or text to insert after the target.
|
|
2251
2278
|
* @returns {T}
|
|
2252
2279
|
*/
|
|
2253
2280
|
static after(el, ...children) {
|
|
@@ -2259,7 +2286,7 @@ class TinyHtml {
|
|
|
2259
2286
|
/**
|
|
2260
2287
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
2261
2288
|
*
|
|
2262
|
-
* @param {...AppendCheckerValues} children - Elements or text to insert after the target.
|
|
2289
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - Elements or text to insert after the target.
|
|
2263
2290
|
* @returns {this}
|
|
2264
2291
|
*/
|
|
2265
2292
|
after(...children) {
|
|
@@ -2271,7 +2298,7 @@ class TinyHtml {
|
|
|
2271
2298
|
*
|
|
2272
2299
|
* @template {TinyElement} T
|
|
2273
2300
|
* @param {T} el - The element(s) to be replaced.
|
|
2274
|
-
* @param {...AppendCheckerValues} newNodes - New elements or text to replace the target.
|
|
2301
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} newNodes - New elements or text to replace the target.
|
|
2275
2302
|
* @returns {T}
|
|
2276
2303
|
*/
|
|
2277
2304
|
static replaceWith(el, ...newNodes) {
|
|
@@ -2283,7 +2310,7 @@ class TinyHtml {
|
|
|
2283
2310
|
/**
|
|
2284
2311
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
2285
2312
|
*
|
|
2286
|
-
* @param {...AppendCheckerValues} newNodes - New elements or text to replace the target.
|
|
2313
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} newNodes - New elements or text to replace the target.
|
|
2287
2314
|
* @returns {this}
|
|
2288
2315
|
*/
|
|
2289
2316
|
replaceWith(...newNodes) {
|
|
@@ -473,6 +473,8 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
|
|
|
473
473
|
*/
|
|
474
474
|
static createTextNode(value: string): TinyHtml<Text>;
|
|
475
475
|
/**
|
|
476
|
+
* @deprecated Use the {@link createFromHTML} instead.
|
|
477
|
+
*
|
|
476
478
|
* Creates an HTMLElement or TextNode from an HTML string.
|
|
477
479
|
* Supports both elements and plain text.
|
|
478
480
|
*
|
|
@@ -480,6 +482,14 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
|
|
|
480
482
|
* @returns {TinyHtml<Element>} - A single HTMLElement or TextNode.
|
|
481
483
|
*/
|
|
482
484
|
static createElementFromHTML(htmlString: string): TinyHtml<Element>;
|
|
485
|
+
/**
|
|
486
|
+
* Creates an HTMLElement or TextNode from an HTML string.
|
|
487
|
+
* Supports both elements and plain text.
|
|
488
|
+
*
|
|
489
|
+
* @param {string} htmlString - The HTML string to convert.
|
|
490
|
+
* @returns {TinyHtml<Element>} - A single HTMLElement or TextNode.
|
|
491
|
+
*/
|
|
492
|
+
static createFromHTML(htmlString: string): TinyHtml<Element>;
|
|
483
493
|
/**
|
|
484
494
|
* Queries the document for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
485
495
|
*
|
|
@@ -977,52 +987,52 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
|
|
|
977
987
|
* @returns {Node[]}
|
|
978
988
|
*/
|
|
979
989
|
static clone(el: TinyNode | TinyNode[], deep?: boolean): Node[];
|
|
980
|
-
static readonly _appendChecker(where: string, ...nodes: AppendCheckerValues[]): (Node | string)[];
|
|
990
|
+
static readonly _appendChecker(where: string, ...nodes: (AppendCheckerValues | Record<string, AppendCheckerValues>)[]): (Node | string)[];
|
|
981
991
|
/**
|
|
982
992
|
* Appends child elements or strings to the end of the target element(s).
|
|
983
993
|
*
|
|
984
994
|
* @template {TinyElement} T
|
|
985
995
|
* @param {T} el - The target element(s) to receive children.
|
|
986
|
-
* @param {...AppendCheckerValues} children - The child elements or text to append.
|
|
996
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - The child elements or text to append.
|
|
987
997
|
* @returns {T}
|
|
988
998
|
*/
|
|
989
|
-
static append<T extends TinyElement>(el: T, ...children: AppendCheckerValues[]): T;
|
|
999
|
+
static append<T extends TinyElement>(el: T, ...children: (AppendCheckerValues | Record<string, AppendCheckerValues>)[]): T;
|
|
990
1000
|
/**
|
|
991
1001
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
992
1002
|
*
|
|
993
1003
|
* @template {TinyElement} T
|
|
994
1004
|
* @param {T} el - The target element(s) to receive children.
|
|
995
|
-
* @param {...AppendCheckerValues} children - The child elements or text to prepend.
|
|
1005
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - The child elements or text to prepend.
|
|
996
1006
|
* @returns {T}
|
|
997
1007
|
*/
|
|
998
|
-
static prepend<T extends TinyElement>(el: T, ...children: AppendCheckerValues[]): T;
|
|
1008
|
+
static prepend<T extends TinyElement>(el: T, ...children: (AppendCheckerValues | Record<string, AppendCheckerValues>)[]): T;
|
|
999
1009
|
/**
|
|
1000
1010
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
1001
1011
|
*
|
|
1002
1012
|
* @template {TinyElement} T
|
|
1003
1013
|
* @param {T} el - The target element(s) before which new content is inserted.
|
|
1004
|
-
* @param {...AppendCheckerValues} children - Elements or text to insert before the target.
|
|
1014
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - Elements or text to insert before the target.
|
|
1005
1015
|
* @returns {T}
|
|
1006
1016
|
*/
|
|
1007
|
-
static before<T extends TinyElement>(el: T, ...children: AppendCheckerValues[]): T;
|
|
1017
|
+
static before<T extends TinyElement>(el: T, ...children: (AppendCheckerValues | Record<string, AppendCheckerValues>)[]): T;
|
|
1008
1018
|
/**
|
|
1009
1019
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
1010
1020
|
*
|
|
1011
1021
|
* @template {TinyElement} T
|
|
1012
1022
|
* @param {T} el - The target element(s) after which new content is inserted.
|
|
1013
|
-
* @param {...AppendCheckerValues} children - Elements or text to insert after the target.
|
|
1023
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - Elements or text to insert after the target.
|
|
1014
1024
|
* @returns {T}
|
|
1015
1025
|
*/
|
|
1016
|
-
static after<T extends TinyElement>(el: T, ...children: AppendCheckerValues[]): T;
|
|
1026
|
+
static after<T extends TinyElement>(el: T, ...children: (AppendCheckerValues | Record<string, AppendCheckerValues>)[]): T;
|
|
1017
1027
|
/**
|
|
1018
1028
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
1019
1029
|
*
|
|
1020
1030
|
* @template {TinyElement} T
|
|
1021
1031
|
* @param {T} el - The element(s) to be replaced.
|
|
1022
|
-
* @param {...AppendCheckerValues} newNodes - New elements or text to replace the target.
|
|
1032
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} newNodes - New elements or text to replace the target.
|
|
1023
1033
|
* @returns {T}
|
|
1024
1034
|
*/
|
|
1025
|
-
static replaceWith<T extends TinyElement>(el: T, ...newNodes: AppendCheckerValues[]): T;
|
|
1035
|
+
static replaceWith<T extends TinyElement>(el: T, ...newNodes: (AppendCheckerValues | Record<string, AppendCheckerValues>)[]): T;
|
|
1026
1036
|
/**
|
|
1027
1037
|
* Appends the given element(s) to each target element in sequence.
|
|
1028
1038
|
*
|
|
@@ -2821,11 +2831,11 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
|
|
|
2821
2831
|
*/
|
|
2822
2832
|
is(selector: WinnowRequest): boolean;
|
|
2823
2833
|
/**
|
|
2824
|
-
*
|
|
2834
|
+
* Returns elements from the current list that contain the given target(s).
|
|
2825
2835
|
* @param {string|TinyElement|TinyElement[]} target - Selector or DOM element(s).
|
|
2826
|
-
* @returns {
|
|
2836
|
+
* @returns {Element[]} Elements that contain the target.
|
|
2827
2837
|
*/
|
|
2828
|
-
has(target: string | TinyElement | TinyElement[]):
|
|
2838
|
+
has(target: string | TinyElement | TinyElement[]): Element[];
|
|
2829
2839
|
/**
|
|
2830
2840
|
* Finds the closest ancestor (including self) that matches the selector.
|
|
2831
2841
|
*
|
|
@@ -2952,38 +2962,38 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
|
|
|
2952
2962
|
/**
|
|
2953
2963
|
* Appends child elements or strings to the end of the target element(s).
|
|
2954
2964
|
*
|
|
2955
|
-
* @param {...AppendCheckerValues} children - The child elements or text to append.
|
|
2965
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - The child elements or text to append.
|
|
2956
2966
|
* @returns {this}
|
|
2957
2967
|
*/
|
|
2958
|
-
append(...children: AppendCheckerValues[]): this;
|
|
2968
|
+
append(...children: (AppendCheckerValues | Record<string, AppendCheckerValues>)[]): this;
|
|
2959
2969
|
/**
|
|
2960
2970
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
2961
2971
|
*
|
|
2962
|
-
* @param {...AppendCheckerValues} children - The child elements or text to prepend.
|
|
2972
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - The child elements or text to prepend.
|
|
2963
2973
|
* @returns {this}
|
|
2964
2974
|
*/
|
|
2965
|
-
prepend(...children: AppendCheckerValues[]): this;
|
|
2975
|
+
prepend(...children: (AppendCheckerValues | Record<string, AppendCheckerValues>)[]): this;
|
|
2966
2976
|
/**
|
|
2967
2977
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
2968
2978
|
*
|
|
2969
|
-
* @param {...AppendCheckerValues} children - Elements or text to insert before the target.
|
|
2979
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - Elements or text to insert before the target.
|
|
2970
2980
|
* @returns {this}
|
|
2971
2981
|
*/
|
|
2972
|
-
before(...children: AppendCheckerValues[]): this;
|
|
2982
|
+
before(...children: (AppendCheckerValues | Record<string, AppendCheckerValues>)[]): this;
|
|
2973
2983
|
/**
|
|
2974
2984
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
2975
2985
|
*
|
|
2976
|
-
* @param {...AppendCheckerValues} children - Elements or text to insert after the target.
|
|
2986
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - Elements or text to insert after the target.
|
|
2977
2987
|
* @returns {this}
|
|
2978
2988
|
*/
|
|
2979
|
-
after(...children: AppendCheckerValues[]): this;
|
|
2989
|
+
after(...children: (AppendCheckerValues | Record<string, AppendCheckerValues>)[]): this;
|
|
2980
2990
|
/**
|
|
2981
2991
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
2982
2992
|
*
|
|
2983
|
-
* @param {...AppendCheckerValues} newNodes - New elements or text to replace the target.
|
|
2993
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} newNodes - New elements or text to replace the target.
|
|
2984
2994
|
* @returns {this}
|
|
2985
2995
|
*/
|
|
2986
|
-
replaceWith(...newNodes: AppendCheckerValues[]): this;
|
|
2996
|
+
replaceWith(...newNodes: (AppendCheckerValues | Record<string, AppendCheckerValues>)[]): this;
|
|
2987
2997
|
/**
|
|
2988
2998
|
* Appends the given element(s) to each target element in sequence.
|
|
2989
2999
|
*
|
|
@@ -702,6 +702,8 @@ class TinyHtml {
|
|
|
702
702
|
return new TinyHtml(document.createTextNode(value));
|
|
703
703
|
}
|
|
704
704
|
/**
|
|
705
|
+
* @deprecated Use the {@link createFromHTML} instead.
|
|
706
|
+
*
|
|
705
707
|
* Creates an HTMLElement or TextNode from an HTML string.
|
|
706
708
|
* Supports both elements and plain text.
|
|
707
709
|
*
|
|
@@ -720,6 +722,22 @@ class TinyHtml {
|
|
|
720
722
|
throw new Error('The HTML string must contain a valid HTML element.');
|
|
721
723
|
return new TinyHtml(template.content.firstChild);
|
|
722
724
|
}
|
|
725
|
+
/**
|
|
726
|
+
* Creates an HTMLElement or TextNode from an HTML string.
|
|
727
|
+
* Supports both elements and plain text.
|
|
728
|
+
*
|
|
729
|
+
* @param {string} htmlString - The HTML string to convert.
|
|
730
|
+
* @returns {TinyHtml<Element>} - A single HTMLElement or TextNode.
|
|
731
|
+
*/
|
|
732
|
+
static createFromHTML(htmlString) {
|
|
733
|
+
const template = document.createElement('template');
|
|
734
|
+
htmlString = htmlString.trim();
|
|
735
|
+
template.innerHTML = htmlString;
|
|
736
|
+
const elems = Array.from(template.content.childNodes);
|
|
737
|
+
if (!elems.every((item) => item instanceof Element || item instanceof Text))
|
|
738
|
+
throw new Error('The HTML string must contain a valid HTML element.');
|
|
739
|
+
return new TinyHtml(elems);
|
|
740
|
+
}
|
|
723
741
|
///////////////////////////////////////////////////
|
|
724
742
|
// TITLE: Query Script
|
|
725
743
|
/**
|
|
@@ -1405,12 +1423,12 @@ class TinyHtml {
|
|
|
1405
1423
|
return TinyHtml._preElems(roots, 'has').filter((root) => targets.some((t) => root && root.contains(t)));
|
|
1406
1424
|
}
|
|
1407
1425
|
/**
|
|
1408
|
-
*
|
|
1426
|
+
* Returns elements from the current list that contain the given target(s).
|
|
1409
1427
|
* @param {string|TinyElement|TinyElement[]} target - Selector or DOM element(s).
|
|
1410
|
-
* @returns {
|
|
1428
|
+
* @returns {Element[]} Elements that contain the target.
|
|
1411
1429
|
*/
|
|
1412
1430
|
has(target) {
|
|
1413
|
-
return TinyHtml.has(this, target)
|
|
1431
|
+
return TinyHtml.has(this, target);
|
|
1414
1432
|
}
|
|
1415
1433
|
/**
|
|
1416
1434
|
* Finds the closest ancestor (including self) that matches the selector.
|
|
@@ -1878,7 +1896,7 @@ class TinyHtml {
|
|
|
1878
1896
|
/**
|
|
1879
1897
|
* Normalize and validate nodes before DOM insertion.
|
|
1880
1898
|
* Converts TinyNode-like structures or strings into DOM-compatible nodes.
|
|
1881
|
-
* @type {(where: string, ...nodes: AppendCheckerValues[]) => (Node | string)[]}
|
|
1899
|
+
* @type {(where: string, ...nodes: (AppendCheckerValues|Record<string, AppendCheckerValues>)[]) => (Node | string)[]}
|
|
1882
1900
|
* @readonly
|
|
1883
1901
|
*/
|
|
1884
1902
|
static _appendChecker(where, ...nodes) {
|
|
@@ -1887,11 +1905,17 @@ class TinyHtml {
|
|
|
1887
1905
|
for (const item of nodes) {
|
|
1888
1906
|
if (typeof item === 'undefined' || item === null || item === false)
|
|
1889
1907
|
continue;
|
|
1890
|
-
if (typeof item !== 'string') {
|
|
1891
|
-
if (
|
|
1892
|
-
results.push(TinyHtml._preNodeElems(item, where)
|
|
1893
|
-
else
|
|
1908
|
+
if (typeof item !== 'string' && typeof item !== 'number') {
|
|
1909
|
+
if (item instanceof Node || item instanceof TinyHtml)
|
|
1910
|
+
results.push(...TinyHtml._preNodeElems(item, where));
|
|
1911
|
+
else if (Array.isArray(item))
|
|
1894
1912
|
results.push(...TinyHtml._appendChecker(where, ...item));
|
|
1913
|
+
else {
|
|
1914
|
+
for (const name in item) {
|
|
1915
|
+
const elems = item[name];
|
|
1916
|
+
results.push(...TinyHtml._appendChecker(where, elems));
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1895
1919
|
}
|
|
1896
1920
|
else
|
|
1897
1921
|
results.push(item);
|
|
@@ -1903,7 +1927,7 @@ class TinyHtml {
|
|
|
1903
1927
|
*
|
|
1904
1928
|
* @template {TinyElement} T
|
|
1905
1929
|
* @param {T} el - The target element(s) to receive children.
|
|
1906
|
-
* @param {...AppendCheckerValues} children - The child elements or text to append.
|
|
1930
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - The child elements or text to append.
|
|
1907
1931
|
* @returns {T}
|
|
1908
1932
|
*/
|
|
1909
1933
|
static append(el, ...children) {
|
|
@@ -1914,7 +1938,7 @@ class TinyHtml {
|
|
|
1914
1938
|
/**
|
|
1915
1939
|
* Appends child elements or strings to the end of the target element(s).
|
|
1916
1940
|
*
|
|
1917
|
-
* @param {...AppendCheckerValues} children - The child elements or text to append.
|
|
1941
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - The child elements or text to append.
|
|
1918
1942
|
* @returns {this}
|
|
1919
1943
|
*/
|
|
1920
1944
|
append(...children) {
|
|
@@ -1925,7 +1949,7 @@ class TinyHtml {
|
|
|
1925
1949
|
*
|
|
1926
1950
|
* @template {TinyElement} T
|
|
1927
1951
|
* @param {T} el - The target element(s) to receive children.
|
|
1928
|
-
* @param {...AppendCheckerValues} children - The child elements or text to prepend.
|
|
1952
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - The child elements or text to prepend.
|
|
1929
1953
|
* @returns {T}
|
|
1930
1954
|
*/
|
|
1931
1955
|
static prepend(el, ...children) {
|
|
@@ -1936,7 +1960,7 @@ class TinyHtml {
|
|
|
1936
1960
|
/**
|
|
1937
1961
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
1938
1962
|
*
|
|
1939
|
-
* @param {...AppendCheckerValues} children - The child elements or text to prepend.
|
|
1963
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - The child elements or text to prepend.
|
|
1940
1964
|
* @returns {this}
|
|
1941
1965
|
*/
|
|
1942
1966
|
prepend(...children) {
|
|
@@ -1947,7 +1971,7 @@ class TinyHtml {
|
|
|
1947
1971
|
*
|
|
1948
1972
|
* @template {TinyElement} T
|
|
1949
1973
|
* @param {T} el - The target element(s) before which new content is inserted.
|
|
1950
|
-
* @param {...AppendCheckerValues} children - Elements or text to insert before the target.
|
|
1974
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - Elements or text to insert before the target.
|
|
1951
1975
|
* @returns {T}
|
|
1952
1976
|
*/
|
|
1953
1977
|
static before(el, ...children) {
|
|
@@ -1958,7 +1982,7 @@ class TinyHtml {
|
|
|
1958
1982
|
/**
|
|
1959
1983
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
1960
1984
|
*
|
|
1961
|
-
* @param {...AppendCheckerValues} children - Elements or text to insert before the target.
|
|
1985
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - Elements or text to insert before the target.
|
|
1962
1986
|
* @returns {this}
|
|
1963
1987
|
*/
|
|
1964
1988
|
before(...children) {
|
|
@@ -1969,7 +1993,7 @@ class TinyHtml {
|
|
|
1969
1993
|
*
|
|
1970
1994
|
* @template {TinyElement} T
|
|
1971
1995
|
* @param {T} el - The target element(s) after which new content is inserted.
|
|
1972
|
-
* @param {...AppendCheckerValues} children - Elements or text to insert after the target.
|
|
1996
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - Elements or text to insert after the target.
|
|
1973
1997
|
* @returns {T}
|
|
1974
1998
|
*/
|
|
1975
1999
|
static after(el, ...children) {
|
|
@@ -1980,7 +2004,7 @@ class TinyHtml {
|
|
|
1980
2004
|
/**
|
|
1981
2005
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
1982
2006
|
*
|
|
1983
|
-
* @param {...AppendCheckerValues} children - Elements or text to insert after the target.
|
|
2007
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} children - Elements or text to insert after the target.
|
|
1984
2008
|
* @returns {this}
|
|
1985
2009
|
*/
|
|
1986
2010
|
after(...children) {
|
|
@@ -1991,7 +2015,7 @@ class TinyHtml {
|
|
|
1991
2015
|
*
|
|
1992
2016
|
* @template {TinyElement} T
|
|
1993
2017
|
* @param {T} el - The element(s) to be replaced.
|
|
1994
|
-
* @param {...AppendCheckerValues} newNodes - New elements or text to replace the target.
|
|
2018
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} newNodes - New elements or text to replace the target.
|
|
1995
2019
|
* @returns {T}
|
|
1996
2020
|
*/
|
|
1997
2021
|
static replaceWith(el, ...newNodes) {
|
|
@@ -2002,7 +2026,7 @@ class TinyHtml {
|
|
|
2002
2026
|
/**
|
|
2003
2027
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
2004
2028
|
*
|
|
2005
|
-
* @param {...AppendCheckerValues} newNodes - New elements or text to replace the target.
|
|
2029
|
+
* @param {...(AppendCheckerValues|Record<string, AppendCheckerValues>)} newNodes - New elements or text to replace the target.
|
|
2006
2030
|
* @returns {this}
|
|
2007
2031
|
*/
|
|
2008
2032
|
replaceWith(...newNodes) {
|
package/docs/v1/libs/TinyHtml.md
CHANGED
|
@@ -702,16 +702,16 @@ This method is useful when you want to insert raw text content into the DOM with
|
|
|
702
702
|
|
|
703
703
|
---
|
|
704
704
|
|
|
705
|
-
### `TinyHtml.
|
|
705
|
+
### `TinyHtml.createFromHTML(htmlString)`
|
|
706
706
|
|
|
707
|
-
Creates an `HTMLElement`
|
|
707
|
+
Creates an `HTMLElement` from an HTML string.
|
|
708
708
|
Supports both elements and plain text.
|
|
709
709
|
|
|
710
710
|
* **Parameters**:
|
|
711
711
|
|
|
712
712
|
* `htmlString` *(string)* — The HTML string to convert.
|
|
713
713
|
|
|
714
|
-
* **Returns**: `TinyHtml` — A `TinyHtml` instance wrapping the resulting `HTMLElement
|
|
714
|
+
* **Returns**: `TinyHtml` — A `TinyHtml` instance wrapping the resulting `HTMLElement`.
|
|
715
715
|
|
|
716
716
|
* **Throws**:
|
|
717
717
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-essentials",
|
|
3
|
-
"version": "1.22.
|
|
3
|
+
"version": "1.22.11",
|
|
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",
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"types": "./dist/v1/index.d.mts",
|
|
39
39
|
"ethereum": "jasmindreasond.x",
|
|
40
40
|
"exports": {
|
|
41
|
+
"./css/aiMarker.min.css": "./dist/v1/css/aiMarker.min.css",
|
|
42
|
+
"./css/TinyCookieConsent.min.css": "./dist/v1/css/TinyCookieConsent.min.css",
|
|
43
|
+
"./css/TinyDraggerExample.min.css": "./dist/v1/css/TinyDraggerExample.min.css",
|
|
44
|
+
"./css/TinyNotify.min.css": "./dist/v1/css/TinyNotify.min.css",
|
|
41
45
|
".": {
|
|
42
46
|
"require": "./dist/v1/index.cjs",
|
|
43
47
|
"import": "./dist/v1/index.mjs"
|