tiny-essentials 1.16.2 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/legacy/crypto/decrypt.cjs +1 -0
- package/dist/legacy/crypto/decrypt.d.mts +1 -0
- package/dist/legacy/crypto/decrypt.mjs +1 -0
- package/dist/legacy/crypto/encrypt.cjs +1 -0
- package/dist/legacy/crypto/encrypt.d.mts +1 -0
- package/dist/legacy/crypto/encrypt.mjs +1 -0
- package/dist/legacy/get/decimalColor.cjs +1 -0
- package/dist/legacy/get/decimalColor.d.mts +1 -0
- package/dist/legacy/get/decimalColor.mjs +1 -0
- package/dist/legacy/get/pagination.cjs +1 -0
- package/dist/legacy/get/pagination.d.mts +1 -0
- package/dist/legacy/get/pagination.mjs +1 -0
- package/dist/legacy/get/queryUrlByName.cjs +1 -0
- package/dist/legacy/get/queryUrlByName.d.mts +1 -0
- package/dist/legacy/get/queryUrlByName.mjs +1 -0
- package/dist/legacy/get/queryUrlJSON.cjs +1 -0
- package/dist/legacy/get/queryUrlJSON.d.mts +1 -0
- package/dist/legacy/get/queryUrlJSON.mjs +1 -0
- package/dist/legacy/get/super_string_filter.cjs +1 -0
- package/dist/legacy/get/super_string_filter.d.mts +1 -0
- package/dist/legacy/get/super_string_filter.mjs +1 -0
- package/dist/legacy/get/versionCheck.cjs +1 -0
- package/dist/legacy/get/versionCheck.d.mts +1 -0
- package/dist/legacy/get/versionCheck.mjs +1 -0
- package/dist/legacy/http/HTTP-1.0.cjs +2 -0
- package/dist/legacy/http/HTTP-1.0.mjs +2 -0
- package/dist/legacy/http/auth.cjs +1 -0
- package/dist/legacy/http/auth.d.mts +1 -0
- package/dist/legacy/http/auth.mjs +1 -0
- package/dist/legacy/http/check_domain.cjs +11 -0
- package/dist/legacy/http/check_domain.d.mts +3 -0
- package/dist/legacy/http/check_domain.mjs +11 -0
- package/dist/legacy/http/csrfTokenAnalyze.cjs +1 -0
- package/dist/legacy/http/csrfTokenAnalyze.d.mts +1 -0
- package/dist/legacy/http/csrfTokenAnalyze.mjs +1 -0
- package/dist/legacy/http/domainValidator.cjs +1 -0
- package/dist/legacy/http/domainValidator.d.mts +1 -0
- package/dist/legacy/http/domainValidator.mjs +1 -0
- package/dist/legacy/http/errorsCallback.cjs +1 -0
- package/dist/legacy/http/errorsCallback.d.mts +1 -0
- package/dist/legacy/http/errorsCallback.mjs +1 -0
- package/dist/legacy/http/fetch/json.cjs +1 -0
- package/dist/legacy/http/fetch/json.d.mts +1 -0
- package/dist/legacy/http/fetch/json.mjs +1 -0
- package/dist/legacy/http/fetch/text.cjs +1 -0
- package/dist/legacy/http/fetch/text.d.mts +1 -0
- package/dist/legacy/http/fetch/text.mjs +1 -0
- package/dist/legacy/http/fileCache.cjs +1 -0
- package/dist/legacy/http/fileCache.d.mts +1 -0
- package/dist/legacy/http/fileCache.mjs +1 -0
- package/dist/legacy/http/getDomainURL.cjs +1 -0
- package/dist/legacy/http/getDomainURL.d.mts +1 -0
- package/dist/legacy/http/getDomainURL.mjs +1 -0
- package/dist/legacy/http/userIP.cjs +1 -0
- package/dist/legacy/http/userIP.d.mts +1 -0
- package/dist/legacy/http/userIP.mjs +1 -0
- package/dist/legacy/libs/capitalize.cjs +1 -0
- package/dist/legacy/libs/capitalize.d.mts +1 -0
- package/dist/legacy/libs/capitalize.mjs +1 -0
- package/dist/legacy/libs/convertBytes.cjs +2 -0
- package/dist/legacy/libs/convertBytes.mjs +2 -0
- package/dist/legacy/libs/custom_module_loader.cjs +2 -0
- package/dist/legacy/libs/custom_module_loader.mjs +2 -0
- package/dist/legacy/libs/dice.cjs +2 -0
- package/dist/legacy/libs/dice.mjs +2 -0
- package/dist/legacy/libs/markdown.cjs +1 -0
- package/dist/legacy/libs/markdown.mjs +1 -0
- package/dist/legacy/libs/percentage.cjs +1 -0
- package/dist/legacy/libs/percentage.mjs +1 -0
- package/dist/legacy/libs/regex/getLetter.cjs +2 -0
- package/dist/legacy/libs/regex/getLetter.d.mts +2 -0
- package/dist/legacy/libs/regex/getLetter.mjs +2 -0
- package/dist/legacy/libs/rule3.cjs +1 -0
- package/dist/legacy/libs/rule3.mjs +1 -0
- package/dist/legacy/momentjs/getAge.cjs +1 -0
- package/dist/legacy/momentjs/getAge.d.mts +1 -0
- package/dist/legacy/momentjs/getAge.mjs +1 -0
- package/dist/legacy/momentjs/timeDuration.cjs +1 -0
- package/dist/legacy/momentjs/timeDuration.d.mts +1 -0
- package/dist/legacy/momentjs/timeDuration.mjs +1 -0
- package/dist/legacy/socket.io/antiFlood/install.cjs +1 -0
- package/dist/legacy/socket.io/antiFlood/install.d.mts +1 -0
- package/dist/legacy/socket.io/antiFlood/install.mjs +1 -0
- package/dist/legacy/socket.io/antiFlood/verify.cjs +1 -0
- package/dist/legacy/socket.io/antiFlood/verify.d.mts +1 -0
- package/dist/legacy/socket.io/antiFlood/verify.mjs +1 -0
- package/dist/legacy/socket.io/cookie-session.cjs +1 -0
- package/dist/legacy/socket.io/cookie-session.d.mts +1 -0
- package/dist/legacy/socket.io/cookie-session.mjs +1 -0
- package/dist/legacy/socket.io/discord.cjs +1 -0
- package/dist/legacy/socket.io/discord.d.mts +1 -0
- package/dist/legacy/socket.io/discord.mjs +1 -0
- package/dist/v1/TinyBasicsEs.js +559 -71
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.js +486 -47
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +2496 -72
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +486 -47
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.js +6230 -0
- package/dist/v1/TinySmartScroller.min.js +1 -0
- package/dist/v1/TinyUploadClicker.js +1538 -72
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/UltraRandomMsgGen.js +995 -0
- package/dist/v1/UltraRandomMsgGen.min.js +1 -0
- package/dist/v1/basics/html.cjs +74 -24
- package/dist/v1/basics/html.d.mts +38 -15
- package/dist/v1/basics/html.mjs +63 -20
- package/dist/v1/build/TinySmartScroller.cjs +7 -0
- package/dist/v1/build/TinySmartScroller.d.mts +3 -0
- package/dist/v1/build/TinySmartScroller.mjs +2 -0
- package/dist/v1/build/UltraRandomMsgGen.cjs +7 -0
- package/dist/v1/build/UltraRandomMsgGen.d.mts +3 -0
- package/dist/v1/build/UltraRandomMsgGen.mjs +2 -0
- package/dist/v1/index.cjs +4 -0
- package/dist/v1/index.d.mts +3 -1
- package/dist/v1/index.mjs +3 -1
- package/dist/v1/libs/TinyHtml.cjs +486 -47
- package/dist/v1/libs/TinyHtml.d.mts +352 -139
- package/dist/v1/libs/TinyHtml.mjs +431 -47
- package/dist/v1/libs/TinySmartScroller.cjs +976 -0
- package/dist/v1/libs/TinySmartScroller.d.mts +458 -0
- package/dist/v1/libs/TinySmartScroller.mjs +856 -0
- package/dist/v1/libs/UltraRandomMsgGen.cjs +956 -0
- package/dist/v1/libs/UltraRandomMsgGen.d.mts +390 -0
- package/dist/v1/libs/UltraRandomMsgGen.mjs +825 -0
- package/docs/v1/README.md +2 -0
- package/docs/v1/basics/html.md +17 -2
- package/docs/v1/libs/TinyHtml.md +197 -8
- package/docs/v1/libs/TinySmartScroller.md +523 -0
- package/docs/v1/libs/UltraRandomMsgGen.md +289 -0
- package/package.json +1 -1
package/dist/v1/TinyHtml.js
CHANGED
|
@@ -525,6 +525,21 @@ const {
|
|
|
525
525
|
* @typedef {Element|Window} ElementAndWindow
|
|
526
526
|
*/
|
|
527
527
|
|
|
528
|
+
/**
|
|
529
|
+
* Represents a raw DOM element/window/document or an instance of TinyHtml.
|
|
530
|
+
* This type is used to abstract interactions with both plain elements
|
|
531
|
+
* and wrapped elements via the TinyHtml class.
|
|
532
|
+
*
|
|
533
|
+
* @typedef {ElementAndWinAndDoc|TinyHtml} TinyElementAndWinAndDoc
|
|
534
|
+
*/
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Represents a value that can be either a DOM Element, or the global Window object, or the document object.
|
|
538
|
+
* Useful for functions that operate generically on scrollable or measurable targets.
|
|
539
|
+
*
|
|
540
|
+
* @typedef {Element|Window|Document} ElementAndWinAndDoc
|
|
541
|
+
*/
|
|
542
|
+
|
|
528
543
|
/**
|
|
529
544
|
* A parameter type used for filtering or matching elements.
|
|
530
545
|
* It can be:
|
|
@@ -541,7 +556,7 @@ const {
|
|
|
541
556
|
* Elements accepted as constructor values for TinyHtml.
|
|
542
557
|
* These include common DOM elements and root containers.
|
|
543
558
|
*
|
|
544
|
-
* @typedef {Window|Element|Document} ConstructorElValues
|
|
559
|
+
* @typedef {Window|Element|Document|Text} ConstructorElValues
|
|
545
560
|
*/
|
|
546
561
|
|
|
547
562
|
/**
|
|
@@ -662,40 +677,114 @@ class TinyHtml {
|
|
|
662
677
|
|
|
663
678
|
static Utils = { ...collision_namespaceObject };
|
|
664
679
|
|
|
680
|
+
/**
|
|
681
|
+
* Creates a new DOM element with the specified tag name and options, then wraps it in a TinyHtml instance.
|
|
682
|
+
*
|
|
683
|
+
* @param {string} tagName - The tag name of the element to create (e.g., 'div', 'span').
|
|
684
|
+
* @param {ElementCreationOptions} ops - Optional settings for creating the element.
|
|
685
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM element.
|
|
686
|
+
* @throws {TypeError} If tagName is not a string or ops is not an object.
|
|
687
|
+
*/
|
|
688
|
+
static createElement(tagName, ops) {
|
|
689
|
+
if (typeof tagName !== 'string')
|
|
690
|
+
throw new TypeError(`[TinyHtml] createElement(): The tagName must be a string.`);
|
|
691
|
+
if (typeof ops !== 'undefined' && typeof ops !== 'object')
|
|
692
|
+
throw new TypeError(`[TinyHtml] createElement(): The ops must be a object.`);
|
|
693
|
+
return new TinyHtml(document.createElement(tagName, ops));
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Creates a new TinyHtml instance that wraps a DOM TextNode.
|
|
698
|
+
*
|
|
699
|
+
* This method is useful when you want to insert raw text content into the DOM
|
|
700
|
+
* without it being interpreted as HTML. The returned instance behaves like any
|
|
701
|
+
* other TinyHtml element and can be appended or manipulated as needed.
|
|
702
|
+
*
|
|
703
|
+
* @param {string} value - The plain text content to be wrapped in a TextNode.
|
|
704
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM TextNode.
|
|
705
|
+
* @throws {TypeError} If the provided value is not a string.
|
|
706
|
+
*/
|
|
707
|
+
static createTextNode(value) {
|
|
708
|
+
if (typeof value !== 'string')
|
|
709
|
+
throw new TypeError(`[TinyHtml] createTextNode(): The value must be a string.`);
|
|
710
|
+
return new TinyHtml(document.createTextNode(value));
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Creates an HTMLElement or TextNode from an HTML string.
|
|
715
|
+
* Supports both elements and plain text.
|
|
716
|
+
*
|
|
717
|
+
* @param {string} htmlString - The HTML string to convert.
|
|
718
|
+
* @returns {TinyHtml} - A single HTMLElement or TextNode.
|
|
719
|
+
*/
|
|
720
|
+
static createElementFromHTML(htmlString) {
|
|
721
|
+
const template = document.createElement('template');
|
|
722
|
+
htmlString = htmlString.trim();
|
|
723
|
+
|
|
724
|
+
// If it's only text (e.g., no "<" tag), return a TextNode
|
|
725
|
+
if (!htmlString.startsWith('<')) {
|
|
726
|
+
return TinyHtml.createTextNode(htmlString);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
template.innerHTML = htmlString;
|
|
730
|
+
if (!(template.content.firstChild instanceof Element)) throw new Error('');
|
|
731
|
+
return new TinyHtml(template.content.firstChild);
|
|
732
|
+
}
|
|
733
|
+
|
|
665
734
|
/**
|
|
666
735
|
* Queries the document for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
667
736
|
*
|
|
668
737
|
* @param {string} selector - A valid CSS selector string.
|
|
669
|
-
* @
|
|
670
|
-
* @
|
|
738
|
+
* @param {Document|Element} elem - Target element.
|
|
739
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
671
740
|
*/
|
|
672
|
-
static query(selector) {
|
|
673
|
-
const newEl =
|
|
674
|
-
if (!newEl)
|
|
741
|
+
static query(selector, elem = document) {
|
|
742
|
+
const newEl = elem.querySelector(selector);
|
|
743
|
+
if (!newEl) return null;
|
|
675
744
|
return new TinyHtml(newEl);
|
|
676
745
|
}
|
|
677
746
|
|
|
747
|
+
/**
|
|
748
|
+
* Queries the element for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
749
|
+
*
|
|
750
|
+
* @param {string} selector - A valid CSS selector string.
|
|
751
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
752
|
+
*/
|
|
753
|
+
querySelector(selector) {
|
|
754
|
+
return TinyHtml.query(selector, TinyHtml._preElem(this, 'query'));
|
|
755
|
+
}
|
|
756
|
+
|
|
678
757
|
/**
|
|
679
758
|
* Queries the document for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
680
759
|
*
|
|
681
760
|
* @param {string} selector - A valid CSS selector string.
|
|
761
|
+
* @param {Document|Element} elem - Target element.
|
|
682
762
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
683
763
|
*/
|
|
684
|
-
static queryAll(selector) {
|
|
685
|
-
const newEls =
|
|
764
|
+
static queryAll(selector, elem = document) {
|
|
765
|
+
const newEls = elem.querySelectorAll(selector);
|
|
686
766
|
return TinyHtml.toTinyElm([...newEls]);
|
|
687
767
|
}
|
|
688
768
|
|
|
769
|
+
/**
|
|
770
|
+
* Queries the element for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
771
|
+
*
|
|
772
|
+
* @param {string} selector - A valid CSS selector string.
|
|
773
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
774
|
+
*/
|
|
775
|
+
querySelectorAll(selector) {
|
|
776
|
+
return TinyHtml.queryAll(selector, TinyHtml._preElem(this, 'queryAll'));
|
|
777
|
+
}
|
|
778
|
+
|
|
689
779
|
/**
|
|
690
780
|
* Retrieves an element by its ID and wraps it in a TinyHtml instance.
|
|
691
781
|
*
|
|
692
782
|
* @param {string} selector - The ID of the element to retrieve.
|
|
693
|
-
* @returns {TinyHtml} A TinyHtml instance wrapping the found element.
|
|
694
|
-
* @throws {Error} If no element is found with the specified ID.
|
|
783
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the found element.
|
|
695
784
|
*/
|
|
696
785
|
static getById(selector) {
|
|
697
786
|
const newEl = document.getElementById(selector);
|
|
698
|
-
if (!newEl)
|
|
787
|
+
if (!newEl) return null;
|
|
699
788
|
return new TinyHtml(newEl);
|
|
700
789
|
}
|
|
701
790
|
|
|
@@ -703,13 +792,24 @@ class TinyHtml {
|
|
|
703
792
|
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
704
793
|
*
|
|
705
794
|
* @param {string} selector - The class name to search for.
|
|
795
|
+
* @param {Document|Element} elem - Target element.
|
|
706
796
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
707
797
|
*/
|
|
708
|
-
static getByClassName(selector) {
|
|
709
|
-
const newEls =
|
|
798
|
+
static getByClassName(selector, elem = document) {
|
|
799
|
+
const newEls = elem.getElementsByClassName(selector);
|
|
710
800
|
return TinyHtml.toTinyElm([...newEls]);
|
|
711
801
|
}
|
|
712
802
|
|
|
803
|
+
/**
|
|
804
|
+
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
805
|
+
*
|
|
806
|
+
* @param {string} selector - The class name to search for.
|
|
807
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
808
|
+
*/
|
|
809
|
+
getElementsByClassName(selector) {
|
|
810
|
+
return TinyHtml.getByClassName(selector, TinyHtml._preElem(this, 'getByClassName'));
|
|
811
|
+
}
|
|
812
|
+
|
|
713
813
|
/**
|
|
714
814
|
* Retrieves all elements with the specified name attribute and wraps them in TinyHtml instances.
|
|
715
815
|
*
|
|
@@ -727,13 +827,30 @@ class TinyHtml {
|
|
|
727
827
|
*
|
|
728
828
|
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
729
829
|
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
830
|
+
* @param {Document|Element} elem - Target element.
|
|
730
831
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
731
832
|
*/
|
|
732
|
-
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
733
|
-
const newEls =
|
|
833
|
+
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml', elem = document) {
|
|
834
|
+
const newEls = elem.getElementsByTagNameNS(namespaceURI, localName);
|
|
734
835
|
return TinyHtml.toTinyElm([...newEls]);
|
|
735
836
|
}
|
|
736
837
|
|
|
838
|
+
/**
|
|
839
|
+
* Retrieves all elements with the specified local tag name within the given namespace URI,
|
|
840
|
+
* and wraps them in TinyHtml instances.
|
|
841
|
+
*
|
|
842
|
+
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
843
|
+
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
844
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
845
|
+
*/
|
|
846
|
+
getElementsByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
847
|
+
return TinyHtml.getByTagNameNS(
|
|
848
|
+
localName,
|
|
849
|
+
namespaceURI,
|
|
850
|
+
TinyHtml._preElem(this, 'getByTagNameNS'),
|
|
851
|
+
);
|
|
852
|
+
}
|
|
853
|
+
|
|
737
854
|
//////////////////////////////////////////////////////////////////
|
|
738
855
|
|
|
739
856
|
/**
|
|
@@ -1014,6 +1131,45 @@ class TinyHtml {
|
|
|
1014
1131
|
return TinyHtml._preElemTemplate(elems, where, [Element, Window], ['Element', 'Window']);
|
|
1015
1132
|
}
|
|
1016
1133
|
|
|
1134
|
+
/**
|
|
1135
|
+
* Ensures the input is returned as an array.
|
|
1136
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
1137
|
+
*
|
|
1138
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
1139
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
1140
|
+
* @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
|
|
1141
|
+
* @readonly
|
|
1142
|
+
*/
|
|
1143
|
+
static _preElemsAndWinAndDoc(elems, where) {
|
|
1144
|
+
const result = TinyHtml._preElemsTemplate(
|
|
1145
|
+
elems,
|
|
1146
|
+
where,
|
|
1147
|
+
[Element, Window, Document],
|
|
1148
|
+
['Element', 'Window', 'Document'],
|
|
1149
|
+
);
|
|
1150
|
+
return result.map((elem) => (!(elem instanceof Document) ? elem : elem.documentElement));
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
/**
|
|
1154
|
+
* Ensures the input is returned as an single element/window/document element.
|
|
1155
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
1156
|
+
*
|
|
1157
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
1158
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
1159
|
+
* @returns {ElementAndWindow} - Always returns an single element/window element.
|
|
1160
|
+
* @readonly
|
|
1161
|
+
*/
|
|
1162
|
+
static _preElemAndWinAndDoc(elems, where) {
|
|
1163
|
+
const result = TinyHtml._preElemTemplate(
|
|
1164
|
+
elems,
|
|
1165
|
+
where,
|
|
1166
|
+
[Element, Window, Document],
|
|
1167
|
+
['Element', 'Window', 'Document'],
|
|
1168
|
+
);
|
|
1169
|
+
if (result instanceof Document) return result.documentElement;
|
|
1170
|
+
return result;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1017
1173
|
/**
|
|
1018
1174
|
* Normalizes and converts one or more DOM elements (or TinyHtml instances)
|
|
1019
1175
|
* into an array of `TinyHtml` instances.
|
|
@@ -1360,12 +1516,13 @@ class TinyHtml {
|
|
|
1360
1516
|
* @param {string} key - The key under which the data will be stored.
|
|
1361
1517
|
* @param {any} value - The value to store.
|
|
1362
1518
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
1363
|
-
* @returns {
|
|
1519
|
+
* @returns {TinyElement}
|
|
1364
1520
|
*/
|
|
1365
1521
|
static setData(el, key, value, isPrivate = false) {
|
|
1366
1522
|
const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('setData', el);
|
|
1367
1523
|
if (typeof key !== 'string') throw new TypeError('The key must be a string.');
|
|
1368
1524
|
data[key] = value;
|
|
1525
|
+
return el;
|
|
1369
1526
|
}
|
|
1370
1527
|
|
|
1371
1528
|
/**
|
|
@@ -1374,7 +1531,7 @@ class TinyHtml {
|
|
|
1374
1531
|
* @param {string} key - The key under which the data will be stored.
|
|
1375
1532
|
* @param {any} value - The value to store.
|
|
1376
1533
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
1377
|
-
* @returns {
|
|
1534
|
+
* @returns {TinyElement}
|
|
1378
1535
|
*/
|
|
1379
1536
|
setData(key, value, isPrivate = false) {
|
|
1380
1537
|
return TinyHtml.setData(this, key, value, isPrivate);
|
|
@@ -1721,18 +1878,21 @@ class TinyHtml {
|
|
|
1721
1878
|
/**
|
|
1722
1879
|
* Appends child elements or strings to the end of the target element(s).
|
|
1723
1880
|
*
|
|
1724
|
-
* @param {TinyElement
|
|
1881
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
1725
1882
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
1883
|
+
* @returns {TinyElement}
|
|
1726
1884
|
*/
|
|
1727
1885
|
static append(el, ...children) {
|
|
1728
1886
|
const elem = TinyHtml._preElem(el, 'append');
|
|
1729
1887
|
elem.append(...TinyHtml._appendChecker('append', ...children));
|
|
1888
|
+
return el;
|
|
1730
1889
|
}
|
|
1731
1890
|
|
|
1732
1891
|
/**
|
|
1733
1892
|
* Appends child elements or strings to the end of the target element(s).
|
|
1734
1893
|
*
|
|
1735
1894
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
1895
|
+
* @returns {TinyElement}
|
|
1736
1896
|
*/
|
|
1737
1897
|
append(...children) {
|
|
1738
1898
|
return TinyHtml.append(this, ...children);
|
|
@@ -1741,18 +1901,21 @@ class TinyHtml {
|
|
|
1741
1901
|
/**
|
|
1742
1902
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
1743
1903
|
*
|
|
1744
|
-
* @param {TinyElement
|
|
1904
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
1745
1905
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
1906
|
+
* @returns {TinyElement}
|
|
1746
1907
|
*/
|
|
1747
1908
|
static prepend(el, ...children) {
|
|
1748
1909
|
const elem = TinyHtml._preElem(el, 'prepend');
|
|
1749
1910
|
elem.prepend(...TinyHtml._appendChecker('prepend', ...children));
|
|
1911
|
+
return el;
|
|
1750
1912
|
}
|
|
1751
1913
|
|
|
1752
1914
|
/**
|
|
1753
1915
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
1754
1916
|
*
|
|
1755
1917
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
1918
|
+
* @returns {TinyElement}
|
|
1756
1919
|
*/
|
|
1757
1920
|
prepend(...children) {
|
|
1758
1921
|
return TinyHtml.prepend(this, ...children);
|
|
@@ -1761,18 +1924,21 @@ class TinyHtml {
|
|
|
1761
1924
|
/**
|
|
1762
1925
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
1763
1926
|
*
|
|
1764
|
-
* @param {TinyElement
|
|
1927
|
+
* @param {TinyElement} el - The target element(s) before which new content is inserted.
|
|
1765
1928
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
1929
|
+
* @returns {TinyElement}
|
|
1766
1930
|
*/
|
|
1767
1931
|
static before(el, ...children) {
|
|
1768
1932
|
const elem = TinyHtml._preElem(el, 'before');
|
|
1769
1933
|
elem.before(...TinyHtml._appendChecker('before', ...children));
|
|
1934
|
+
return el;
|
|
1770
1935
|
}
|
|
1771
1936
|
|
|
1772
1937
|
/**
|
|
1773
1938
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
1774
1939
|
*
|
|
1775
1940
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
1941
|
+
* @returns {TinyElement}
|
|
1776
1942
|
*/
|
|
1777
1943
|
before(...children) {
|
|
1778
1944
|
return TinyHtml.before(this, ...children);
|
|
@@ -1781,18 +1947,21 @@ class TinyHtml {
|
|
|
1781
1947
|
/**
|
|
1782
1948
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
1783
1949
|
*
|
|
1784
|
-
* @param {TinyElement
|
|
1950
|
+
* @param {TinyElement} el - The target element(s) after which new content is inserted.
|
|
1785
1951
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
1952
|
+
* @returns {TinyElement}
|
|
1786
1953
|
*/
|
|
1787
1954
|
static after(el, ...children) {
|
|
1788
1955
|
const elem = TinyHtml._preElem(el, 'after');
|
|
1789
1956
|
elem.after(...TinyHtml._appendChecker('after', ...children));
|
|
1957
|
+
return el;
|
|
1790
1958
|
}
|
|
1791
1959
|
|
|
1792
1960
|
/**
|
|
1793
1961
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
1794
1962
|
*
|
|
1795
1963
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
1964
|
+
* @returns {TinyElement}
|
|
1796
1965
|
*/
|
|
1797
1966
|
after(...children) {
|
|
1798
1967
|
return TinyHtml.after(this, ...children);
|
|
@@ -1801,18 +1970,21 @@ class TinyHtml {
|
|
|
1801
1970
|
/**
|
|
1802
1971
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
1803
1972
|
*
|
|
1804
|
-
* @param {TinyElement
|
|
1973
|
+
* @param {TinyElement} el - The element(s) to be replaced.
|
|
1805
1974
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
1975
|
+
* @returns {TinyElement}
|
|
1806
1976
|
*/
|
|
1807
1977
|
static replaceWith(el, ...newNodes) {
|
|
1808
1978
|
const elem = TinyHtml._preElem(el, 'replaceWith');
|
|
1809
1979
|
elem.replaceWith(...TinyHtml._appendChecker('replaceWith', ...newNodes));
|
|
1980
|
+
return el;
|
|
1810
1981
|
}
|
|
1811
1982
|
|
|
1812
1983
|
/**
|
|
1813
1984
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
1814
1985
|
*
|
|
1815
1986
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
1987
|
+
* @returns {TinyElement}
|
|
1816
1988
|
*/
|
|
1817
1989
|
replaceWith(...newNodes) {
|
|
1818
1990
|
return TinyHtml.replaceWith(this, ...newNodes);
|
|
@@ -1823,6 +1995,7 @@ class TinyHtml {
|
|
|
1823
1995
|
*
|
|
1824
1996
|
* @param {TinyNode | TinyNode[]} el - The element(s) to append.
|
|
1825
1997
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
1998
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1826
1999
|
*/
|
|
1827
2000
|
static appendTo(el, targets) {
|
|
1828
2001
|
const elems = TinyHtml._preNodeElems(el, 'appendTo');
|
|
@@ -1832,12 +2005,14 @@ class TinyHtml {
|
|
|
1832
2005
|
target.appendChild(i === tars.length - 1 ? elem : elem.cloneNode(true)),
|
|
1833
2006
|
);
|
|
1834
2007
|
});
|
|
2008
|
+
return el;
|
|
1835
2009
|
}
|
|
1836
2010
|
|
|
1837
2011
|
/**
|
|
1838
2012
|
* Appends the given element(s) to each target element in sequence.
|
|
1839
2013
|
*
|
|
1840
2014
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
2015
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1841
2016
|
*/
|
|
1842
2017
|
appendTo(targets) {
|
|
1843
2018
|
return TinyHtml.appendTo(this, targets);
|
|
@@ -1848,6 +2023,7 @@ class TinyHtml {
|
|
|
1848
2023
|
*
|
|
1849
2024
|
* @param {TinyElement | TinyElement[]} el - The element(s) to prepend.
|
|
1850
2025
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
2026
|
+
* @returns {TinyElement|TinyElement[]}
|
|
1851
2027
|
*/
|
|
1852
2028
|
static prependTo(el, targets) {
|
|
1853
2029
|
const elems = TinyHtml._preElems(el, 'prependTo');
|
|
@@ -1858,12 +2034,14 @@ class TinyHtml {
|
|
|
1858
2034
|
.reverse()
|
|
1859
2035
|
.forEach((elem) => target.prepend(i === tars.length - 1 ? elem : elem.cloneNode(true)));
|
|
1860
2036
|
});
|
|
2037
|
+
return el;
|
|
1861
2038
|
}
|
|
1862
2039
|
|
|
1863
2040
|
/**
|
|
1864
2041
|
* Prepends the given element(s) to each target element in sequence.
|
|
1865
2042
|
*
|
|
1866
2043
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
2044
|
+
* @returns {TinyElement|TinyElement[]}
|
|
1867
2045
|
*/
|
|
1868
2046
|
prependTo(targets) {
|
|
1869
2047
|
return TinyHtml.prependTo(this, targets);
|
|
@@ -1875,6 +2053,7 @@ class TinyHtml {
|
|
|
1875
2053
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
1876
2054
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1877
2055
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
2056
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1878
2057
|
*/
|
|
1879
2058
|
static insertBefore(el, target, child = null) {
|
|
1880
2059
|
const elem = TinyHtml._preNodeElem(el, 'insertBefore');
|
|
@@ -1882,6 +2061,7 @@ class TinyHtml {
|
|
|
1882
2061
|
const childNode = TinyHtml._preNodeElemWithNull(child, 'insertBefore');
|
|
1883
2062
|
if (!targ.parentNode) throw new Error('');
|
|
1884
2063
|
targ.parentNode.insertBefore(elem, childNode || targ);
|
|
2064
|
+
return el;
|
|
1885
2065
|
}
|
|
1886
2066
|
|
|
1887
2067
|
/**
|
|
@@ -1889,6 +2069,7 @@ class TinyHtml {
|
|
|
1889
2069
|
*
|
|
1890
2070
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1891
2071
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
2072
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1892
2073
|
*/
|
|
1893
2074
|
insertBefore(target, child) {
|
|
1894
2075
|
return TinyHtml.insertBefore(this, target, child);
|
|
@@ -1900,6 +2081,7 @@ class TinyHtml {
|
|
|
1900
2081
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
1901
2082
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1902
2083
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
2084
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1903
2085
|
*/
|
|
1904
2086
|
static insertAfter(el, target, child = null) {
|
|
1905
2087
|
const elem = TinyHtml._preNodeElem(el, 'insertAfter');
|
|
@@ -1907,6 +2089,7 @@ class TinyHtml {
|
|
|
1907
2089
|
const childNode = TinyHtml._preNodeElemWithNull(child, 'insertBefore');
|
|
1908
2090
|
if (!targ.parentNode) throw new Error('');
|
|
1909
2091
|
targ.parentNode.insertBefore(elem, childNode || targ.nextSibling);
|
|
2092
|
+
return el;
|
|
1910
2093
|
}
|
|
1911
2094
|
|
|
1912
2095
|
/**
|
|
@@ -1914,6 +2097,7 @@ class TinyHtml {
|
|
|
1914
2097
|
*
|
|
1915
2098
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1916
2099
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
2100
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1917
2101
|
*/
|
|
1918
2102
|
insertAfter(target, child) {
|
|
1919
2103
|
return TinyHtml.insertAfter(this, target, child);
|
|
@@ -1925,6 +2109,7 @@ class TinyHtml {
|
|
|
1925
2109
|
*
|
|
1926
2110
|
* @param {TinyNode | TinyNode[]} el - The new element(s) to insert.
|
|
1927
2111
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
2112
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1928
2113
|
*/
|
|
1929
2114
|
static replaceAll(el, targets) {
|
|
1930
2115
|
const elems = TinyHtml._preNodeElems(el, 'replaceAll');
|
|
@@ -1936,6 +2121,7 @@ class TinyHtml {
|
|
|
1936
2121
|
parent.replaceChild(i === tars.length - 1 ? elem : elem.cloneNode(true), target);
|
|
1937
2122
|
});
|
|
1938
2123
|
});
|
|
2124
|
+
return el;
|
|
1939
2125
|
}
|
|
1940
2126
|
|
|
1941
2127
|
/**
|
|
@@ -1943,6 +2129,7 @@ class TinyHtml {
|
|
|
1943
2129
|
* If multiple targets exist, the inserted elements are cloned accordingly.
|
|
1944
2130
|
*
|
|
1945
2131
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
2132
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1946
2133
|
*/
|
|
1947
2134
|
replaceAll(targets) {
|
|
1948
2135
|
return TinyHtml.replaceAll(this, targets);
|
|
@@ -1966,7 +2153,12 @@ class TinyHtml {
|
|
|
1966
2153
|
throw new Error(
|
|
1967
2154
|
`[TinyHtml] You are trying to put a TinyHtml inside another TinyHtml in constructor.`,
|
|
1968
2155
|
);
|
|
1969
|
-
if (
|
|
2156
|
+
if (
|
|
2157
|
+
!(el instanceof Element) &&
|
|
2158
|
+
!(el instanceof Window) &&
|
|
2159
|
+
!(el instanceof Document) &&
|
|
2160
|
+
!(el instanceof Text)
|
|
2161
|
+
)
|
|
1970
2162
|
throw new Error(`[TinyHtml] Invalid Target in constructor.`);
|
|
1971
2163
|
this.#el = el;
|
|
1972
2164
|
}
|
|
@@ -2416,6 +2608,7 @@ class TinyHtml {
|
|
|
2416
2608
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - The element to inspect.
|
|
2417
2609
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
2418
2610
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
2611
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2419
2612
|
*/
|
|
2420
2613
|
static setStyle(el, prop, value = null) {
|
|
2421
2614
|
TinyHtml._preHtmlElems(el, 'setStyle').forEach((elem) => {
|
|
@@ -2428,6 +2621,7 @@ class TinyHtml {
|
|
|
2428
2621
|
}
|
|
2429
2622
|
} else elem.style.setProperty(TinyHtml.toStyleKc(prop), value);
|
|
2430
2623
|
});
|
|
2624
|
+
return el;
|
|
2431
2625
|
}
|
|
2432
2626
|
|
|
2433
2627
|
/**
|
|
@@ -2438,6 +2632,7 @@ class TinyHtml {
|
|
|
2438
2632
|
*
|
|
2439
2633
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
2440
2634
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
2635
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2441
2636
|
*/
|
|
2442
2637
|
setStyle(prop, value) {
|
|
2443
2638
|
return TinyHtml.setStyle(this, prop, value);
|
|
@@ -2533,6 +2728,7 @@ class TinyHtml {
|
|
|
2533
2728
|
*
|
|
2534
2729
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - A single element or an array of elements.
|
|
2535
2730
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
2731
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2536
2732
|
*/
|
|
2537
2733
|
static removeStyle(el, prop) {
|
|
2538
2734
|
TinyHtml._preHtmlElems(el, 'removeStyle').forEach((elem) => {
|
|
@@ -2542,12 +2738,14 @@ class TinyHtml {
|
|
|
2542
2738
|
}
|
|
2543
2739
|
} else elem.style.removeProperty(TinyHtml.toStyleKc(prop));
|
|
2544
2740
|
});
|
|
2741
|
+
return el;
|
|
2545
2742
|
}
|
|
2546
2743
|
|
|
2547
2744
|
/**
|
|
2548
2745
|
* Removes one or more inline CSS properties from the given element(s).
|
|
2549
2746
|
*
|
|
2550
2747
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
2748
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2551
2749
|
*/
|
|
2552
2750
|
removeStyle(prop) {
|
|
2553
2751
|
return TinyHtml.removeStyle(this, prop);
|
|
@@ -2562,6 +2760,7 @@ class TinyHtml {
|
|
|
2562
2760
|
* @param {string} prop - The CSS property to toggle.
|
|
2563
2761
|
* @param {string} val1 - The first value (used as "current" check).
|
|
2564
2762
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
2763
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2565
2764
|
*/
|
|
2566
2765
|
static toggleStyle(el, prop, val1, val2) {
|
|
2567
2766
|
TinyHtml._preHtmlElems(el, 'toggleStyle').forEach((elem) => {
|
|
@@ -2569,6 +2768,7 @@ class TinyHtml {
|
|
|
2569
2768
|
const newVal = current === TinyHtml.toStyleKc(val1) ? val2 : val1;
|
|
2570
2769
|
TinyHtml.setStyle(elem, prop, newVal);
|
|
2571
2770
|
});
|
|
2771
|
+
return el;
|
|
2572
2772
|
}
|
|
2573
2773
|
|
|
2574
2774
|
/**
|
|
@@ -2579,6 +2779,7 @@ class TinyHtml {
|
|
|
2579
2779
|
* @param {string} prop - The CSS property to toggle.
|
|
2580
2780
|
* @param {string} val1 - The first value (used as "current" check).
|
|
2581
2781
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
2782
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2582
2783
|
*/
|
|
2583
2784
|
toggleStyle(prop, val1, val2) {
|
|
2584
2785
|
return TinyHtml.toggleStyle(this, prop, val1, val2);
|
|
@@ -2588,14 +2789,16 @@ class TinyHtml {
|
|
|
2588
2789
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
2589
2790
|
*
|
|
2590
2791
|
* @param {TinyElement|TinyElement[]} el - A single element or an array of elements.
|
|
2792
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2591
2793
|
*/
|
|
2592
2794
|
static clearStyle(el) {
|
|
2593
2795
|
TinyHtml._preElems(el, 'clearStyle').forEach((elem) => elem.removeAttribute('style'));
|
|
2796
|
+
return el;
|
|
2594
2797
|
}
|
|
2595
2798
|
|
|
2596
2799
|
/**
|
|
2597
2800
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
2598
|
-
*
|
|
2801
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2599
2802
|
*/
|
|
2600
2803
|
clearStyle() {
|
|
2601
2804
|
return TinyHtml.clearStyle(this);
|
|
@@ -2607,14 +2810,17 @@ class TinyHtml {
|
|
|
2607
2810
|
* Focus the element.
|
|
2608
2811
|
*
|
|
2609
2812
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
2813
|
+
* @returns {TinyHtmlElement}
|
|
2610
2814
|
*/
|
|
2611
2815
|
static focus(el) {
|
|
2612
2816
|
const elem = TinyHtml._preHtmlElem(el, 'focus');
|
|
2613
2817
|
elem.focus();
|
|
2818
|
+
return el;
|
|
2614
2819
|
}
|
|
2615
2820
|
|
|
2616
2821
|
/**
|
|
2617
2822
|
* Focus the element.
|
|
2823
|
+
* @returns {TinyHtmlElement}
|
|
2618
2824
|
*/
|
|
2619
2825
|
focus() {
|
|
2620
2826
|
return TinyHtml.focus(this);
|
|
@@ -2624,19 +2830,46 @@ class TinyHtml {
|
|
|
2624
2830
|
* Blur the element.
|
|
2625
2831
|
*
|
|
2626
2832
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
2833
|
+
* @returns {TinyHtmlElement}
|
|
2627
2834
|
*/
|
|
2628
2835
|
static blur(el) {
|
|
2629
2836
|
const elem = TinyHtml._preHtmlElem(el, 'blur');
|
|
2630
2837
|
elem.blur();
|
|
2838
|
+
return el;
|
|
2631
2839
|
}
|
|
2632
2840
|
|
|
2633
2841
|
/**
|
|
2634
2842
|
* Blur the element.
|
|
2843
|
+
* @returns {TinyHtmlElement}
|
|
2635
2844
|
*/
|
|
2636
2845
|
blur() {
|
|
2637
2846
|
return TinyHtml.blur(this);
|
|
2638
2847
|
}
|
|
2639
2848
|
|
|
2849
|
+
/**
|
|
2850
|
+
* Interprets a value as a boolean `true` if it matches a common truthy representation.
|
|
2851
|
+
*
|
|
2852
|
+
* This method checks if the input is any of the common forms used to represent `true`,
|
|
2853
|
+
* such as the string `'true'`, `'1'`, `'on'`, the boolean `true`, or the number `1`.
|
|
2854
|
+
*
|
|
2855
|
+
* @param {string|boolean|number} [value] - The value to interpret as boolean.
|
|
2856
|
+
* @returns {boolean} `true` if the value represents a truthy state, otherwise `false`.
|
|
2857
|
+
*/
|
|
2858
|
+
static boolCheck(value) {
|
|
2859
|
+
if (
|
|
2860
|
+
typeof value !== 'undefined' &&
|
|
2861
|
+
(value === 'true' ||
|
|
2862
|
+
value === '1' ||
|
|
2863
|
+
value === true ||
|
|
2864
|
+
value === 'on' ||
|
|
2865
|
+
(typeof value === 'number' && value > 0))
|
|
2866
|
+
) {
|
|
2867
|
+
return true;
|
|
2868
|
+
} else {
|
|
2869
|
+
return false;
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
|
|
2640
2873
|
//////////////////////////////////////////////////////////////////////
|
|
2641
2874
|
|
|
2642
2875
|
/**
|
|
@@ -2689,16 +2922,40 @@ class TinyHtml {
|
|
|
2689
2922
|
return window.innerWidth || document.documentElement.clientWidth;
|
|
2690
2923
|
}
|
|
2691
2924
|
|
|
2925
|
+
/**
|
|
2926
|
+
* Checks if the page is currently scrolled to the very top.
|
|
2927
|
+
*
|
|
2928
|
+
* This method compares the current vertical scroll position with the total document height.
|
|
2929
|
+
* It's useful for detecting if the user has reached the top of the page.
|
|
2930
|
+
*
|
|
2931
|
+
* @returns {boolean} `true` if the page is scrolled to the top, otherwise `false`.
|
|
2932
|
+
*/
|
|
2933
|
+
static isPageTop() {
|
|
2934
|
+
return window.scrollY === 0;
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
/**
|
|
2938
|
+
* Checks if the page is currently scrolled to the very bottom.
|
|
2939
|
+
*
|
|
2940
|
+
* This method uses the `scrollY` and `innerHeight` properties to determine if the
|
|
2941
|
+
* user has reached the end of the document.
|
|
2942
|
+
*
|
|
2943
|
+
* @returns {boolean} `true` if the page is scrolled to the bottom, otherwise `false`.
|
|
2944
|
+
*/
|
|
2945
|
+
static isPageBottom() {
|
|
2946
|
+
return window.innerHeight + window.scrollY >= document.body.offsetHeight;
|
|
2947
|
+
}
|
|
2948
|
+
|
|
2692
2949
|
/**
|
|
2693
2950
|
* Gets the width or height of an element based on the box model.
|
|
2694
|
-
* @param {
|
|
2951
|
+
* @param {TinyElementAndWinAndDoc} el - The element or window.
|
|
2695
2952
|
* @param {"width"|"height"} type - Dimension type.
|
|
2696
2953
|
* @param {"content"|"padding"|"border"|"margin"} [extra='content'] - Box model context.
|
|
2697
2954
|
* @returns {number} - Computed dimension.
|
|
2698
2955
|
* @throws {TypeError} If `type` or `extra` is not a string.
|
|
2699
2956
|
*/
|
|
2700
2957
|
static getDimension(el, type, extra = 'content') {
|
|
2701
|
-
const elem = TinyHtml.
|
|
2958
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'getDimension');
|
|
2702
2959
|
if (typeof type !== 'string') throw new TypeError('The type must be a string.');
|
|
2703
2960
|
if (typeof extra !== 'string') throw new TypeError('The extra must be a string.');
|
|
2704
2961
|
|
|
@@ -2786,17 +3043,20 @@ class TinyHtml {
|
|
|
2786
3043
|
* @param {TinyHtmlElement} el - Target element.
|
|
2787
3044
|
* @param {string|number} value - Height value.
|
|
2788
3045
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
3046
|
+
* @returns {TinyHtmlElement}
|
|
2789
3047
|
*/
|
|
2790
3048
|
static setHeight(el, value) {
|
|
2791
3049
|
const elem = TinyHtml._preHtmlElem(el, 'setHeight');
|
|
2792
3050
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
2793
3051
|
throw new TypeError('The value must be a string or number.');
|
|
2794
3052
|
elem.style.height = typeof value === 'number' ? `${value}px` : value;
|
|
3053
|
+
return el;
|
|
2795
3054
|
}
|
|
2796
3055
|
|
|
2797
3056
|
/**
|
|
2798
3057
|
* Sets the height of the element.
|
|
2799
3058
|
* @param {string|number} value - Height value.
|
|
3059
|
+
* @returns {TinyHtmlElement}
|
|
2800
3060
|
*/
|
|
2801
3061
|
setHeight(value) {
|
|
2802
3062
|
return TinyHtml.setHeight(this, value);
|
|
@@ -2807,17 +3067,20 @@ class TinyHtml {
|
|
|
2807
3067
|
* @param {TinyHtmlElement} el - Target element.
|
|
2808
3068
|
* @param {string|number} value - Width value.
|
|
2809
3069
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
3070
|
+
* @returns {TinyHtmlElement}
|
|
2810
3071
|
*/
|
|
2811
3072
|
static setWidth(el, value) {
|
|
2812
3073
|
const elem = TinyHtml._preHtmlElem(el, 'setWidth');
|
|
2813
3074
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
2814
3075
|
throw new TypeError('The value must be a string or number.');
|
|
2815
3076
|
elem.style.width = typeof value === 'number' ? `${value}px` : value;
|
|
3077
|
+
return el;
|
|
2816
3078
|
}
|
|
2817
3079
|
|
|
2818
3080
|
/**
|
|
2819
3081
|
* Sets the width of the element.
|
|
2820
3082
|
* @param {string|number} value - Width value.
|
|
3083
|
+
* @returns {TinyHtmlElement}
|
|
2821
3084
|
*/
|
|
2822
3085
|
setWidth(value) {
|
|
2823
3086
|
return TinyHtml.setWidth(this, value);
|
|
@@ -2825,11 +3088,11 @@ class TinyHtml {
|
|
|
2825
3088
|
|
|
2826
3089
|
/**
|
|
2827
3090
|
* Returns content box height.
|
|
2828
|
-
* @param {
|
|
3091
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2829
3092
|
* @returns {number}
|
|
2830
3093
|
*/
|
|
2831
3094
|
static height(el) {
|
|
2832
|
-
const elem = TinyHtml.
|
|
3095
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'height');
|
|
2833
3096
|
return TinyHtml.getDimension(elem, 'height', 'content');
|
|
2834
3097
|
}
|
|
2835
3098
|
|
|
@@ -2843,11 +3106,11 @@ class TinyHtml {
|
|
|
2843
3106
|
|
|
2844
3107
|
/**
|
|
2845
3108
|
* Returns content box width.
|
|
2846
|
-
* @param {
|
|
3109
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2847
3110
|
* @returns {number}
|
|
2848
3111
|
*/
|
|
2849
3112
|
static width(el) {
|
|
2850
|
-
const elem = TinyHtml.
|
|
3113
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'width');
|
|
2851
3114
|
return TinyHtml.getDimension(elem, 'width', 'content');
|
|
2852
3115
|
}
|
|
2853
3116
|
|
|
@@ -2861,11 +3124,11 @@ class TinyHtml {
|
|
|
2861
3124
|
|
|
2862
3125
|
/**
|
|
2863
3126
|
* Returns padding box height.
|
|
2864
|
-
* @param {
|
|
3127
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2865
3128
|
* @returns {number}
|
|
2866
3129
|
*/
|
|
2867
3130
|
static innerHeight(el) {
|
|
2868
|
-
const elem = TinyHtml.
|
|
3131
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerHeight');
|
|
2869
3132
|
return TinyHtml.getDimension(elem, 'height', 'padding');
|
|
2870
3133
|
}
|
|
2871
3134
|
|
|
@@ -2879,11 +3142,11 @@ class TinyHtml {
|
|
|
2879
3142
|
|
|
2880
3143
|
/**
|
|
2881
3144
|
* Returns padding box width.
|
|
2882
|
-
* @param {
|
|
3145
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2883
3146
|
* @returns {number}
|
|
2884
3147
|
*/
|
|
2885
3148
|
static innerWidth(el) {
|
|
2886
|
-
const elem = TinyHtml.
|
|
3149
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerWidth');
|
|
2887
3150
|
return TinyHtml.getDimension(elem, 'width', 'padding');
|
|
2888
3151
|
}
|
|
2889
3152
|
|
|
@@ -2897,14 +3160,14 @@ class TinyHtml {
|
|
|
2897
3160
|
|
|
2898
3161
|
/**
|
|
2899
3162
|
* Returns outer height of the element, optionally including margin.
|
|
2900
|
-
* @param {
|
|
3163
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2901
3164
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
2902
3165
|
* @returns {number}
|
|
2903
3166
|
*/
|
|
2904
3167
|
static outerHeight(el, includeMargin = false) {
|
|
2905
3168
|
if (typeof includeMargin !== 'boolean')
|
|
2906
3169
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
2907
|
-
const elem = TinyHtml.
|
|
3170
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerHeight');
|
|
2908
3171
|
return TinyHtml.getDimension(elem, 'height', includeMargin ? 'margin' : 'border');
|
|
2909
3172
|
}
|
|
2910
3173
|
|
|
@@ -2919,14 +3182,14 @@ class TinyHtml {
|
|
|
2919
3182
|
|
|
2920
3183
|
/**
|
|
2921
3184
|
* Returns outer width of the element, optionally including margin.
|
|
2922
|
-
* @param {
|
|
3185
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2923
3186
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
2924
3187
|
* @returns {number}
|
|
2925
3188
|
*/
|
|
2926
3189
|
static outerWidth(el, includeMargin = false) {
|
|
2927
3190
|
if (typeof includeMargin !== 'boolean')
|
|
2928
3191
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
2929
|
-
const elem = TinyHtml.
|
|
3192
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerWidth');
|
|
2930
3193
|
return TinyHtml.getDimension(elem, 'width', includeMargin ? 'margin' : 'border');
|
|
2931
3194
|
}
|
|
2932
3195
|
|
|
@@ -3099,6 +3362,7 @@ class TinyHtml {
|
|
|
3099
3362
|
* Sets the vertical scroll position.
|
|
3100
3363
|
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
3101
3364
|
* @param {number} value - Scroll top value.
|
|
3365
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3102
3366
|
*/
|
|
3103
3367
|
static setScrollTop(el, value) {
|
|
3104
3368
|
if (typeof value !== 'number') throw new TypeError('ScrollTop value must be a number.');
|
|
@@ -3112,11 +3376,13 @@ class TinyHtml {
|
|
|
3112
3376
|
elem.scrollTop = value;
|
|
3113
3377
|
}
|
|
3114
3378
|
});
|
|
3379
|
+
return el;
|
|
3115
3380
|
}
|
|
3116
3381
|
|
|
3117
3382
|
/**
|
|
3118
3383
|
* Sets the vertical scroll position.
|
|
3119
3384
|
* @param {number} value - Scroll top value.
|
|
3385
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3120
3386
|
*/
|
|
3121
3387
|
setScrollTop(value) {
|
|
3122
3388
|
return TinyHtml.setScrollTop(this, value);
|
|
@@ -3126,6 +3392,7 @@ class TinyHtml {
|
|
|
3126
3392
|
* Sets the horizontal scroll position.
|
|
3127
3393
|
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
3128
3394
|
* @param {number} value - Scroll left value.
|
|
3395
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3129
3396
|
*/
|
|
3130
3397
|
static setScrollLeft(el, value) {
|
|
3131
3398
|
if (typeof value !== 'number') throw new TypeError('ScrollLeft value must be a number.');
|
|
@@ -3139,11 +3406,13 @@ class TinyHtml {
|
|
|
3139
3406
|
elem.scrollLeft = value;
|
|
3140
3407
|
}
|
|
3141
3408
|
});
|
|
3409
|
+
return el;
|
|
3142
3410
|
}
|
|
3143
3411
|
|
|
3144
3412
|
/**
|
|
3145
3413
|
* Sets the horizontal scroll position.
|
|
3146
3414
|
* @param {number} value - Scroll left value.
|
|
3415
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3147
3416
|
*/
|
|
3148
3417
|
setScrollLeft(value) {
|
|
3149
3418
|
return TinyHtml.setScrollLeft(this, value);
|
|
@@ -3274,15 +3543,16 @@ class TinyHtml {
|
|
|
3274
3543
|
|
|
3275
3544
|
/**
|
|
3276
3545
|
* Adds one or more CSS class names to the element.
|
|
3277
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
3546
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
3278
3547
|
*/
|
|
3279
3548
|
static addClass(el, ...args) {
|
|
3280
3549
|
TinyHtml._preElems(el, 'addClass').forEach((elem) => elem.classList.add(...args));
|
|
3550
|
+
return el;
|
|
3281
3551
|
}
|
|
3282
3552
|
|
|
3283
3553
|
/**
|
|
3284
3554
|
* Adds one or more CSS class names to the element.
|
|
3285
|
-
* @type {(...tokens: string[]) =>
|
|
3555
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
3286
3556
|
*/
|
|
3287
3557
|
addClass(...args) {
|
|
3288
3558
|
return TinyHtml.addClass(this, ...args);
|
|
@@ -3290,15 +3560,16 @@ class TinyHtml {
|
|
|
3290
3560
|
|
|
3291
3561
|
/**
|
|
3292
3562
|
* Removes one or more CSS class names from the element.
|
|
3293
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
3563
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
3294
3564
|
*/
|
|
3295
3565
|
static removeClass(el, ...args) {
|
|
3296
3566
|
TinyHtml._preElems(el, 'removeClass').forEach((elem) => elem.classList.remove(...args));
|
|
3567
|
+
return el;
|
|
3297
3568
|
}
|
|
3298
3569
|
|
|
3299
3570
|
/**
|
|
3300
3571
|
* Removes one or more CSS class names from the element.
|
|
3301
|
-
* @type {(...tokens: string[]) =>
|
|
3572
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
3302
3573
|
*/
|
|
3303
3574
|
removeClass(...args) {
|
|
3304
3575
|
return TinyHtml.removeClass(this, ...args);
|
|
@@ -3508,15 +3779,18 @@ class TinyHtml {
|
|
|
3508
3779
|
* Set text content of elements.
|
|
3509
3780
|
* @param {TinyElement|TinyElement[]} el
|
|
3510
3781
|
* @param {string} value
|
|
3782
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3511
3783
|
*/
|
|
3512
3784
|
static setText(el, value) {
|
|
3513
3785
|
if (typeof value !== 'string') throw new Error('Value is not a valid string.');
|
|
3514
3786
|
TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = value));
|
|
3787
|
+
return el;
|
|
3515
3788
|
}
|
|
3516
3789
|
|
|
3517
3790
|
/**
|
|
3518
3791
|
* Set text content of the element.
|
|
3519
3792
|
* @param {string} value
|
|
3793
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3520
3794
|
*/
|
|
3521
3795
|
setText(value) {
|
|
3522
3796
|
return TinyHtml.setText(this, value);
|
|
@@ -3525,13 +3799,16 @@ class TinyHtml {
|
|
|
3525
3799
|
/**
|
|
3526
3800
|
* Remove all child nodes from each element.
|
|
3527
3801
|
* @param {TinyElement|TinyElement[]} el
|
|
3802
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3528
3803
|
*/
|
|
3529
3804
|
static empty(el) {
|
|
3530
3805
|
TinyHtml._preElems(el, 'empty').forEach((el) => (el.textContent = ''));
|
|
3806
|
+
return el;
|
|
3531
3807
|
}
|
|
3532
3808
|
|
|
3533
3809
|
/**
|
|
3534
3810
|
* Remove all child nodes of the element.
|
|
3811
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3535
3812
|
*/
|
|
3536
3813
|
empty() {
|
|
3537
3814
|
return TinyHtml.empty(this);
|
|
@@ -3539,35 +3816,40 @@ class TinyHtml {
|
|
|
3539
3816
|
|
|
3540
3817
|
/**
|
|
3541
3818
|
* Get the innerHTML of the element.
|
|
3542
|
-
* @param {TinyElement
|
|
3819
|
+
* @param {TinyElement} el
|
|
3820
|
+
* @param {GetHTMLOptions} [ops]
|
|
3543
3821
|
* @returns {string}
|
|
3544
3822
|
*/
|
|
3545
|
-
static html(el) {
|
|
3823
|
+
static html(el, ops) {
|
|
3546
3824
|
const elem = TinyHtml._preElem(el, 'html');
|
|
3547
|
-
return elem.
|
|
3825
|
+
return elem.getHTML(ops);
|
|
3548
3826
|
}
|
|
3549
3827
|
|
|
3550
3828
|
/**
|
|
3551
3829
|
* Get the innerHTML of the element.
|
|
3830
|
+
* @param {GetHTMLOptions} [ops]
|
|
3552
3831
|
* @returns {string}
|
|
3553
3832
|
*/
|
|
3554
|
-
html() {
|
|
3555
|
-
return TinyHtml.html(this);
|
|
3833
|
+
html(ops) {
|
|
3834
|
+
return TinyHtml.html(this, ops);
|
|
3556
3835
|
}
|
|
3557
3836
|
|
|
3558
3837
|
/**
|
|
3559
3838
|
* Set the innerHTML of each element.
|
|
3560
3839
|
* @param {TinyElement|TinyElement[]} el
|
|
3561
3840
|
* @param {string} value
|
|
3841
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3562
3842
|
*/
|
|
3563
3843
|
static setHtml(el, value) {
|
|
3564
3844
|
if (typeof value !== 'string') throw new Error('Value is not a valid string.');
|
|
3565
3845
|
TinyHtml._preElems(el, 'setHtml').forEach((el) => (el.innerHTML = value));
|
|
3846
|
+
return el;
|
|
3566
3847
|
}
|
|
3567
3848
|
|
|
3568
3849
|
/**
|
|
3569
3850
|
* Set the innerHTML of the element.
|
|
3570
3851
|
* @param {string} value
|
|
3852
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3571
3853
|
*/
|
|
3572
3854
|
setHtml(value) {
|
|
3573
3855
|
return TinyHtml.setHtml(this, value);
|
|
@@ -3701,6 +3983,7 @@ class TinyHtml {
|
|
|
3701
3983
|
* @param {TinyInputElement|TinyInputElement[]} el - Target element.
|
|
3702
3984
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
3703
3985
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
3986
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
3704
3987
|
*/
|
|
3705
3988
|
static setVal(el, value) {
|
|
3706
3989
|
TinyHtml._preInputElems(el, 'setVal').forEach((elem) => {
|
|
@@ -3740,6 +4023,7 @@ class TinyHtml {
|
|
|
3740
4023
|
if (typeof valToSet === 'string') elem.value = valToSet;
|
|
3741
4024
|
}
|
|
3742
4025
|
});
|
|
4026
|
+
return el;
|
|
3743
4027
|
}
|
|
3744
4028
|
|
|
3745
4029
|
/**
|
|
@@ -3747,6 +4031,7 @@ class TinyHtml {
|
|
|
3747
4031
|
* Accepts strings, numbers, booleans or arrays of these values, or a callback function that computes them.
|
|
3748
4032
|
*
|
|
3749
4033
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
4034
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
3750
4035
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
3751
4036
|
*/
|
|
3752
4037
|
setVal(value) {
|
|
@@ -4016,6 +4301,7 @@ class TinyHtml {
|
|
|
4016
4301
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
4017
4302
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
4018
4303
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
4304
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4019
4305
|
*/
|
|
4020
4306
|
static on(el, event, handler, options) {
|
|
4021
4307
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -4028,6 +4314,7 @@ class TinyHtml {
|
|
|
4028
4314
|
if (!Array.isArray(events[event])) events[event] = [];
|
|
4029
4315
|
events[event].push({ handler, options });
|
|
4030
4316
|
});
|
|
4317
|
+
return el;
|
|
4031
4318
|
}
|
|
4032
4319
|
|
|
4033
4320
|
/**
|
|
@@ -4036,6 +4323,7 @@ class TinyHtml {
|
|
|
4036
4323
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
4037
4324
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
4038
4325
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
4326
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4039
4327
|
*/
|
|
4040
4328
|
on(event, handler, options) {
|
|
4041
4329
|
return TinyHtml.on(this, event, handler, options);
|
|
@@ -4048,6 +4336,7 @@ class TinyHtml {
|
|
|
4048
4336
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
4049
4337
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
4050
4338
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
4339
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4051
4340
|
*/
|
|
4052
4341
|
static once(el, event, handler, options = {}) {
|
|
4053
4342
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -4065,6 +4354,7 @@ class TinyHtml {
|
|
|
4065
4354
|
typeof options === 'boolean' ? options : { ...options, once: true },
|
|
4066
4355
|
);
|
|
4067
4356
|
});
|
|
4357
|
+
return el;
|
|
4068
4358
|
}
|
|
4069
4359
|
|
|
4070
4360
|
/**
|
|
@@ -4073,6 +4363,7 @@ class TinyHtml {
|
|
|
4073
4363
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
4074
4364
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
4075
4365
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
4366
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4076
4367
|
*/
|
|
4077
4368
|
once(event, handler, options = {}) {
|
|
4078
4369
|
return TinyHtml.once(this, event, handler, options);
|
|
@@ -4085,6 +4376,7 @@ class TinyHtml {
|
|
|
4085
4376
|
* @param {string} event - The event type.
|
|
4086
4377
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
4087
4378
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
4379
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4088
4380
|
*/
|
|
4089
4381
|
static off(el, event, handler, options) {
|
|
4090
4382
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -4097,6 +4389,7 @@ class TinyHtml {
|
|
|
4097
4389
|
if (events[event].length === 0) delete events[event];
|
|
4098
4390
|
}
|
|
4099
4391
|
});
|
|
4392
|
+
return el;
|
|
4100
4393
|
}
|
|
4101
4394
|
|
|
4102
4395
|
/**
|
|
@@ -4105,6 +4398,7 @@ class TinyHtml {
|
|
|
4105
4398
|
* @param {string} event - The event type.
|
|
4106
4399
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
4107
4400
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
4401
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4108
4402
|
*/
|
|
4109
4403
|
off(event, handler, options) {
|
|
4110
4404
|
return TinyHtml.off(this, event, handler, options);
|
|
@@ -4115,6 +4409,7 @@ class TinyHtml {
|
|
|
4115
4409
|
*
|
|
4116
4410
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
4117
4411
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
4412
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4118
4413
|
*/
|
|
4119
4414
|
static offAll(el, event) {
|
|
4120
4415
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -4127,12 +4422,14 @@ class TinyHtml {
|
|
|
4127
4422
|
delete events[event];
|
|
4128
4423
|
}
|
|
4129
4424
|
});
|
|
4425
|
+
return el;
|
|
4130
4426
|
}
|
|
4131
4427
|
|
|
4132
4428
|
/**
|
|
4133
4429
|
* Removes all event listeners of a specific type from the element.
|
|
4134
4430
|
*
|
|
4135
4431
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
4432
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4136
4433
|
*/
|
|
4137
4434
|
offAll(event) {
|
|
4138
4435
|
return TinyHtml.offAll(this, event);
|
|
@@ -4144,6 +4441,7 @@ class TinyHtml {
|
|
|
4144
4441
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
4145
4442
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
4146
4443
|
* Optional filter function to selectively remove specific handlers.
|
|
4444
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4147
4445
|
*/
|
|
4148
4446
|
static offAllTypes(el, filterFn = null) {
|
|
4149
4447
|
if (filterFn !== null && typeof filterFn !== 'function')
|
|
@@ -4162,6 +4460,7 @@ class TinyHtml {
|
|
|
4162
4460
|
|
|
4163
4461
|
__eventRegistry.delete(elem);
|
|
4164
4462
|
});
|
|
4463
|
+
return el;
|
|
4165
4464
|
}
|
|
4166
4465
|
|
|
4167
4466
|
/**
|
|
@@ -4169,6 +4468,7 @@ class TinyHtml {
|
|
|
4169
4468
|
*
|
|
4170
4469
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
4171
4470
|
* Optional filter function to selectively remove specific handlers.
|
|
4471
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4172
4472
|
*/
|
|
4173
4473
|
offAllTypes(filterFn = null) {
|
|
4174
4474
|
return TinyHtml.offAllTypes(this, filterFn);
|
|
@@ -4180,6 +4480,7 @@ class TinyHtml {
|
|
|
4180
4480
|
* @param {TinyEventTarget|TinyEventTarget[]} el - Target element where the event should be triggered.
|
|
4181
4481
|
* @param {string} event - Name of the event to trigger.
|
|
4182
4482
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
4483
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4183
4484
|
*/
|
|
4184
4485
|
static trigger(el, event, payload = {}) {
|
|
4185
4486
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -4195,6 +4496,7 @@ class TinyHtml {
|
|
|
4195
4496
|
|
|
4196
4497
|
elem.dispatchEvent(evt);
|
|
4197
4498
|
});
|
|
4499
|
+
return el;
|
|
4198
4500
|
}
|
|
4199
4501
|
|
|
4200
4502
|
/**
|
|
@@ -4202,6 +4504,7 @@ class TinyHtml {
|
|
|
4202
4504
|
*
|
|
4203
4505
|
* @param {string} event - Name of the event to trigger.
|
|
4204
4506
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
4507
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4205
4508
|
*/
|
|
4206
4509
|
trigger(event, payload = {}) {
|
|
4207
4510
|
return TinyHtml.trigger(this, event, payload);
|
|
@@ -4244,6 +4547,7 @@ class TinyHtml {
|
|
|
4244
4547
|
* @param {TinyElement|TinyElement[]} el
|
|
4245
4548
|
* @param {string} name
|
|
4246
4549
|
* @param {string|null} [value=null]
|
|
4550
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4247
4551
|
*/
|
|
4248
4552
|
static setAttr(el, name, value = null) {
|
|
4249
4553
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -4253,12 +4557,14 @@ class TinyHtml {
|
|
|
4253
4557
|
if (value === null) elem.removeAttribute(name);
|
|
4254
4558
|
else elem.setAttribute(name, value);
|
|
4255
4559
|
});
|
|
4560
|
+
return el;
|
|
4256
4561
|
}
|
|
4257
4562
|
|
|
4258
4563
|
/**
|
|
4259
4564
|
* Set an attribute on an element.
|
|
4260
4565
|
* @param {string} name
|
|
4261
4566
|
* @param {string|null} [value=null]
|
|
4567
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4262
4568
|
*/
|
|
4263
4569
|
setAttr(name, value) {
|
|
4264
4570
|
return TinyHtml.setAttr(this, name, value);
|
|
@@ -4268,15 +4574,18 @@ class TinyHtml {
|
|
|
4268
4574
|
* Remove attribute(s) from an element.
|
|
4269
4575
|
* @param {TinyElement|TinyElement[]} el
|
|
4270
4576
|
* @param {string} name Space-separated list of attributes.
|
|
4577
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4271
4578
|
*/
|
|
4272
4579
|
static removeAttr(el, name) {
|
|
4273
4580
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
4274
4581
|
TinyHtml._preElems(el, 'removeAttr').forEach((elem) => elem.removeAttribute(name));
|
|
4582
|
+
return el;
|
|
4275
4583
|
}
|
|
4276
4584
|
|
|
4277
4585
|
/**
|
|
4278
4586
|
* Remove attribute(s) from an element.
|
|
4279
4587
|
* @param {string} name Space-separated list of attributes.
|
|
4588
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4280
4589
|
*/
|
|
4281
4590
|
removeAttr(name) {
|
|
4282
4591
|
return TinyHtml.removeAttr(this, name);
|
|
@@ -4331,6 +4640,7 @@ class TinyHtml {
|
|
|
4331
4640
|
* Set a property on an element.
|
|
4332
4641
|
* @param {TinyElement|TinyElement[]} el
|
|
4333
4642
|
* @param {string} name
|
|
4643
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4334
4644
|
*/
|
|
4335
4645
|
static addProp(el, name) {
|
|
4336
4646
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -4340,11 +4650,13 @@ class TinyHtml {
|
|
|
4340
4650
|
// @ts-ignore
|
|
4341
4651
|
elem[name] = true;
|
|
4342
4652
|
});
|
|
4653
|
+
return el;
|
|
4343
4654
|
}
|
|
4344
4655
|
|
|
4345
4656
|
/**
|
|
4346
4657
|
* Set a property on an element.
|
|
4347
4658
|
* @param {string} name
|
|
4659
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4348
4660
|
*/
|
|
4349
4661
|
addProp(name) {
|
|
4350
4662
|
return TinyHtml.addProp(this, name);
|
|
@@ -4354,6 +4666,7 @@ class TinyHtml {
|
|
|
4354
4666
|
* Remove a property from an element.
|
|
4355
4667
|
* @param {TinyElement|TinyElement[]} el
|
|
4356
4668
|
* @param {string} name
|
|
4669
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4357
4670
|
*/
|
|
4358
4671
|
static removeProp(el, name) {
|
|
4359
4672
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -4363,11 +4676,13 @@ class TinyHtml {
|
|
|
4363
4676
|
// @ts-ignore
|
|
4364
4677
|
elem[name] = false;
|
|
4365
4678
|
});
|
|
4679
|
+
return el;
|
|
4366
4680
|
}
|
|
4367
4681
|
|
|
4368
4682
|
/**
|
|
4369
4683
|
* Remove a property from an element.
|
|
4370
4684
|
* @param {string} name
|
|
4685
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4371
4686
|
*/
|
|
4372
4687
|
removeProp(name) {
|
|
4373
4688
|
return TinyHtml.removeProp(this, name);
|
|
@@ -4408,13 +4723,16 @@ class TinyHtml {
|
|
|
4408
4723
|
/**
|
|
4409
4724
|
* Removes an element from the DOM.
|
|
4410
4725
|
* @param {TinyElement|TinyElement[]} el - The DOM element or selector to remove.
|
|
4726
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4411
4727
|
*/
|
|
4412
4728
|
static remove(el) {
|
|
4413
4729
|
TinyHtml._preElems(el, 'remove').forEach((elem) => elem.remove());
|
|
4730
|
+
return el;
|
|
4414
4731
|
}
|
|
4415
4732
|
|
|
4416
4733
|
/**
|
|
4417
4734
|
* Removes the element from the DOM.
|
|
4735
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4418
4736
|
*/
|
|
4419
4737
|
remove() {
|
|
4420
4738
|
return TinyHtml.remove(this);
|
|
@@ -4758,6 +5076,14 @@ class TinyHtml {
|
|
|
4758
5076
|
*/
|
|
4759
5077
|
static isInViewport(el) {
|
|
4760
5078
|
const elem = TinyHtml._preElem(el, 'isInViewport');
|
|
5079
|
+
if (
|
|
5080
|
+
!elem.checkVisibility({
|
|
5081
|
+
contentVisibilityAuto: false,
|
|
5082
|
+
opacityProperty: false,
|
|
5083
|
+
visibilityProperty: false,
|
|
5084
|
+
})
|
|
5085
|
+
)
|
|
5086
|
+
return false;
|
|
4761
5087
|
const elementTop = TinyHtml.offset(elem).top;
|
|
4762
5088
|
const elementBottom = elementTop + TinyHtml.outerHeight(elem);
|
|
4763
5089
|
|
|
@@ -4784,6 +5110,14 @@ class TinyHtml {
|
|
|
4784
5110
|
*/
|
|
4785
5111
|
static isScrolledIntoView(el) {
|
|
4786
5112
|
const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
5113
|
+
if (
|
|
5114
|
+
!elem.checkVisibility({
|
|
5115
|
+
contentVisibilityAuto: false,
|
|
5116
|
+
opacityProperty: false,
|
|
5117
|
+
visibilityProperty: false,
|
|
5118
|
+
})
|
|
5119
|
+
)
|
|
5120
|
+
return false;
|
|
4787
5121
|
const docViewTop = TinyHtml.scrollTop(window);
|
|
4788
5122
|
const docViewBottom = docViewTop + TinyHtml.height(window);
|
|
4789
5123
|
|
|
@@ -4801,6 +5135,111 @@ class TinyHtml {
|
|
|
4801
5135
|
isScrolledIntoView() {
|
|
4802
5136
|
return TinyHtml.isScrolledIntoView(this);
|
|
4803
5137
|
}
|
|
5138
|
+
|
|
5139
|
+
/**
|
|
5140
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
5141
|
+
*
|
|
5142
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
5143
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
5144
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
5145
|
+
*/
|
|
5146
|
+
static isInContainer(el, cont) {
|
|
5147
|
+
const elem = TinyHtml._preElem(el, 'isInContainer');
|
|
5148
|
+
const container = TinyHtml._preElem(cont, 'isInContainer');
|
|
5149
|
+
|
|
5150
|
+
if (
|
|
5151
|
+
!elem.checkVisibility({
|
|
5152
|
+
contentVisibilityAuto: false,
|
|
5153
|
+
opacityProperty: false,
|
|
5154
|
+
visibilityProperty: false,
|
|
5155
|
+
})
|
|
5156
|
+
)
|
|
5157
|
+
return false;
|
|
5158
|
+
const elemRect = elem.getBoundingClientRect();
|
|
5159
|
+
const containerRect = container.getBoundingClientRect();
|
|
5160
|
+
|
|
5161
|
+
const verticallyVisible =
|
|
5162
|
+
elemRect.bottom > containerRect.top && elemRect.top < containerRect.bottom;
|
|
5163
|
+
|
|
5164
|
+
const horizontallyVisible =
|
|
5165
|
+
elemRect.right > containerRect.left && elemRect.left < containerRect.right;
|
|
5166
|
+
|
|
5167
|
+
return verticallyVisible && horizontallyVisible;
|
|
5168
|
+
}
|
|
5169
|
+
|
|
5170
|
+
/**
|
|
5171
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
5172
|
+
*
|
|
5173
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
5174
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
5175
|
+
*/
|
|
5176
|
+
isInContainer(cont) {
|
|
5177
|
+
return TinyHtml.isInContainer(this, cont);
|
|
5178
|
+
}
|
|
5179
|
+
|
|
5180
|
+
/**
|
|
5181
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
5182
|
+
*
|
|
5183
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
5184
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
5185
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
5186
|
+
*/
|
|
5187
|
+
static isFullyInContainer(el, cont) {
|
|
5188
|
+
const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
5189
|
+
const container = TinyHtml._preElem(cont, 'isInContainer');
|
|
5190
|
+
|
|
5191
|
+
if (
|
|
5192
|
+
!elem.checkVisibility({
|
|
5193
|
+
contentVisibilityAuto: false,
|
|
5194
|
+
opacityProperty: false,
|
|
5195
|
+
visibilityProperty: false,
|
|
5196
|
+
})
|
|
5197
|
+
)
|
|
5198
|
+
return false;
|
|
5199
|
+
const elemRect = elem.getBoundingClientRect();
|
|
5200
|
+
const containerRect = container.getBoundingClientRect();
|
|
5201
|
+
|
|
5202
|
+
const isFullyVisible =
|
|
5203
|
+
elemRect.top >= containerRect.top &&
|
|
5204
|
+
elemRect.bottom <= containerRect.bottom &&
|
|
5205
|
+
elemRect.left >= containerRect.left &&
|
|
5206
|
+
elemRect.right <= containerRect.right;
|
|
5207
|
+
|
|
5208
|
+
return isFullyVisible;
|
|
5209
|
+
}
|
|
5210
|
+
|
|
5211
|
+
/**
|
|
5212
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
5213
|
+
*
|
|
5214
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
5215
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
5216
|
+
*/
|
|
5217
|
+
isFullyInContainer(cont) {
|
|
5218
|
+
return TinyHtml.isFullyInContainer(this, cont);
|
|
5219
|
+
}
|
|
5220
|
+
|
|
5221
|
+
/**
|
|
5222
|
+
* Checks if an element has scrollable content.
|
|
5223
|
+
*
|
|
5224
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
5225
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
5226
|
+
*/
|
|
5227
|
+
static hasScroll(el) {
|
|
5228
|
+
const elem = TinyHtml._preElem(el, 'hasScroll');
|
|
5229
|
+
return {
|
|
5230
|
+
v: elem.scrollHeight > elem.clientHeight,
|
|
5231
|
+
h: elem.scrollWidth > elem.clientWidth,
|
|
5232
|
+
};
|
|
5233
|
+
}
|
|
5234
|
+
|
|
5235
|
+
/**
|
|
5236
|
+
* Checks if an element has scrollable content.
|
|
5237
|
+
*
|
|
5238
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
5239
|
+
*/
|
|
5240
|
+
hasScroll() {
|
|
5241
|
+
return TinyHtml.hasScroll(this);
|
|
5242
|
+
}
|
|
4804
5243
|
}
|
|
4805
5244
|
|
|
4806
5245
|
/* harmony default export */ const libs_TinyHtml = (TinyHtml);
|