tiny-essentials 1.16.2 → 1.17.1
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 +729 -93
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.js +656 -69
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +2688 -116
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +656 -69
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.js +6378 -0
- package/dist/v1/TinySmartScroller.min.js +1 -0
- package/dist/v1/TinyUploadClicker.js +1732 -118
- 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 +656 -69
- package/dist/v1/libs/TinyHtml.d.mts +440 -139
- package/dist/v1/libs/TinyHtml.mjs +591 -72
- 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 +296 -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
|
@@ -470,6 +470,19 @@ const {
|
|
|
470
470
|
areElsCollRight: TinyHtml_areElsCollRight,
|
|
471
471
|
} = collision_namespaceObject;
|
|
472
472
|
|
|
473
|
+
/**
|
|
474
|
+
* Callback invoked on each animation frame with the current scroll position,
|
|
475
|
+
* normalized animation time (`0` to `1`), and a completion flag.
|
|
476
|
+
*
|
|
477
|
+
* @typedef {(progress: { x: number, y: number, isComplete: boolean, time: number }) => void} OnScrollAnimation
|
|
478
|
+
*/
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* A list of supported easing function names for smooth animations.
|
|
482
|
+
*
|
|
483
|
+
* @typedef {'linear' | 'easeInQuad' | 'easeOutQuad' | 'easeInOutQuad' | 'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic'} Easings
|
|
484
|
+
*/
|
|
485
|
+
|
|
473
486
|
/**
|
|
474
487
|
* Represents a raw Node element or an instance of TinyHtml.
|
|
475
488
|
* This type is used to abstract interactions with both plain elements
|
|
@@ -525,6 +538,21 @@ const {
|
|
|
525
538
|
* @typedef {Element|Window} ElementAndWindow
|
|
526
539
|
*/
|
|
527
540
|
|
|
541
|
+
/**
|
|
542
|
+
* Represents a raw DOM element/window/document or an instance of TinyHtml.
|
|
543
|
+
* This type is used to abstract interactions with both plain elements
|
|
544
|
+
* and wrapped elements via the TinyHtml class.
|
|
545
|
+
*
|
|
546
|
+
* @typedef {ElementAndWinAndDoc|TinyHtml} TinyElementAndWinAndDoc
|
|
547
|
+
*/
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Represents a value that can be either a DOM Element, or the global Window object, or the document object.
|
|
551
|
+
* Useful for functions that operate generically on scrollable or measurable targets.
|
|
552
|
+
*
|
|
553
|
+
* @typedef {Element|Window|Document} ElementAndWinAndDoc
|
|
554
|
+
*/
|
|
555
|
+
|
|
528
556
|
/**
|
|
529
557
|
* A parameter type used for filtering or matching elements.
|
|
530
558
|
* It can be:
|
|
@@ -541,7 +569,7 @@ const {
|
|
|
541
569
|
* Elements accepted as constructor values for TinyHtml.
|
|
542
570
|
* These include common DOM elements and root containers.
|
|
543
571
|
*
|
|
544
|
-
* @typedef {Window|Element|Document} ConstructorElValues
|
|
572
|
+
* @typedef {Window|Element|Document|Text} ConstructorElValues
|
|
545
573
|
*/
|
|
546
574
|
|
|
547
575
|
/**
|
|
@@ -662,40 +690,114 @@ class TinyHtml {
|
|
|
662
690
|
|
|
663
691
|
static Utils = { ...collision_namespaceObject };
|
|
664
692
|
|
|
693
|
+
/**
|
|
694
|
+
* Creates a new DOM element with the specified tag name and options, then wraps it in a TinyHtml instance.
|
|
695
|
+
*
|
|
696
|
+
* @param {string} tagName - The tag name of the element to create (e.g., 'div', 'span').
|
|
697
|
+
* @param {ElementCreationOptions} ops - Optional settings for creating the element.
|
|
698
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM element.
|
|
699
|
+
* @throws {TypeError} If tagName is not a string or ops is not an object.
|
|
700
|
+
*/
|
|
701
|
+
static createElement(tagName, ops) {
|
|
702
|
+
if (typeof tagName !== 'string')
|
|
703
|
+
throw new TypeError(`[TinyHtml] createElement(): The tagName must be a string.`);
|
|
704
|
+
if (typeof ops !== 'undefined' && typeof ops !== 'object')
|
|
705
|
+
throw new TypeError(`[TinyHtml] createElement(): The ops must be a object.`);
|
|
706
|
+
return new TinyHtml(document.createElement(tagName, ops));
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* Creates a new TinyHtml instance that wraps a DOM TextNode.
|
|
711
|
+
*
|
|
712
|
+
* This method is useful when you want to insert raw text content into the DOM
|
|
713
|
+
* without it being interpreted as HTML. The returned instance behaves like any
|
|
714
|
+
* other TinyHtml element and can be appended or manipulated as needed.
|
|
715
|
+
*
|
|
716
|
+
* @param {string} value - The plain text content to be wrapped in a TextNode.
|
|
717
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM TextNode.
|
|
718
|
+
* @throws {TypeError} If the provided value is not a string.
|
|
719
|
+
*/
|
|
720
|
+
static createTextNode(value) {
|
|
721
|
+
if (typeof value !== 'string')
|
|
722
|
+
throw new TypeError(`[TinyHtml] createTextNode(): The value must be a string.`);
|
|
723
|
+
return new TinyHtml(document.createTextNode(value));
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Creates an HTMLElement or TextNode from an HTML string.
|
|
728
|
+
* Supports both elements and plain text.
|
|
729
|
+
*
|
|
730
|
+
* @param {string} htmlString - The HTML string to convert.
|
|
731
|
+
* @returns {TinyHtml} - A single HTMLElement or TextNode.
|
|
732
|
+
*/
|
|
733
|
+
static createElementFromHTML(htmlString) {
|
|
734
|
+
const template = document.createElement('template');
|
|
735
|
+
htmlString = htmlString.trim();
|
|
736
|
+
|
|
737
|
+
// If it's only text (e.g., no "<" tag), return a TextNode
|
|
738
|
+
if (!htmlString.startsWith('<')) {
|
|
739
|
+
return TinyHtml.createTextNode(htmlString);
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
template.innerHTML = htmlString;
|
|
743
|
+
if (!(template.content.firstChild instanceof Element)) throw new Error('');
|
|
744
|
+
return new TinyHtml(template.content.firstChild);
|
|
745
|
+
}
|
|
746
|
+
|
|
665
747
|
/**
|
|
666
748
|
* Queries the document for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
667
749
|
*
|
|
668
750
|
* @param {string} selector - A valid CSS selector string.
|
|
669
|
-
* @
|
|
670
|
-
* @
|
|
751
|
+
* @param {Document|Element} elem - Target element.
|
|
752
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
671
753
|
*/
|
|
672
|
-
static query(selector) {
|
|
673
|
-
const newEl =
|
|
674
|
-
if (!newEl)
|
|
754
|
+
static query(selector, elem = document) {
|
|
755
|
+
const newEl = elem.querySelector(selector);
|
|
756
|
+
if (!newEl) return null;
|
|
675
757
|
return new TinyHtml(newEl);
|
|
676
758
|
}
|
|
677
759
|
|
|
760
|
+
/**
|
|
761
|
+
* Queries the element for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
762
|
+
*
|
|
763
|
+
* @param {string} selector - A valid CSS selector string.
|
|
764
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
765
|
+
*/
|
|
766
|
+
querySelector(selector) {
|
|
767
|
+
return TinyHtml.query(selector, TinyHtml._preElem(this, 'query'));
|
|
768
|
+
}
|
|
769
|
+
|
|
678
770
|
/**
|
|
679
771
|
* Queries the document for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
680
772
|
*
|
|
681
773
|
* @param {string} selector - A valid CSS selector string.
|
|
774
|
+
* @param {Document|Element} elem - Target element.
|
|
682
775
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
683
776
|
*/
|
|
684
|
-
static queryAll(selector) {
|
|
685
|
-
const newEls =
|
|
777
|
+
static queryAll(selector, elem = document) {
|
|
778
|
+
const newEls = elem.querySelectorAll(selector);
|
|
686
779
|
return TinyHtml.toTinyElm([...newEls]);
|
|
687
780
|
}
|
|
688
781
|
|
|
782
|
+
/**
|
|
783
|
+
* Queries the element for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
784
|
+
*
|
|
785
|
+
* @param {string} selector - A valid CSS selector string.
|
|
786
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
787
|
+
*/
|
|
788
|
+
querySelectorAll(selector) {
|
|
789
|
+
return TinyHtml.queryAll(selector, TinyHtml._preElem(this, 'queryAll'));
|
|
790
|
+
}
|
|
791
|
+
|
|
689
792
|
/**
|
|
690
793
|
* Retrieves an element by its ID and wraps it in a TinyHtml instance.
|
|
691
794
|
*
|
|
692
795
|
* @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.
|
|
796
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the found element.
|
|
695
797
|
*/
|
|
696
798
|
static getById(selector) {
|
|
697
799
|
const newEl = document.getElementById(selector);
|
|
698
|
-
if (!newEl)
|
|
800
|
+
if (!newEl) return null;
|
|
699
801
|
return new TinyHtml(newEl);
|
|
700
802
|
}
|
|
701
803
|
|
|
@@ -703,13 +805,24 @@ class TinyHtml {
|
|
|
703
805
|
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
704
806
|
*
|
|
705
807
|
* @param {string} selector - The class name to search for.
|
|
808
|
+
* @param {Document|Element} elem - Target element.
|
|
706
809
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
707
810
|
*/
|
|
708
|
-
static getByClassName(selector) {
|
|
709
|
-
const newEls =
|
|
811
|
+
static getByClassName(selector, elem = document) {
|
|
812
|
+
const newEls = elem.getElementsByClassName(selector);
|
|
710
813
|
return TinyHtml.toTinyElm([...newEls]);
|
|
711
814
|
}
|
|
712
815
|
|
|
816
|
+
/**
|
|
817
|
+
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
818
|
+
*
|
|
819
|
+
* @param {string} selector - The class name to search for.
|
|
820
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
821
|
+
*/
|
|
822
|
+
getElementsByClassName(selector) {
|
|
823
|
+
return TinyHtml.getByClassName(selector, TinyHtml._preElem(this, 'getByClassName'));
|
|
824
|
+
}
|
|
825
|
+
|
|
713
826
|
/**
|
|
714
827
|
* Retrieves all elements with the specified name attribute and wraps them in TinyHtml instances.
|
|
715
828
|
*
|
|
@@ -727,13 +840,30 @@ class TinyHtml {
|
|
|
727
840
|
*
|
|
728
841
|
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
729
842
|
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
843
|
+
* @param {Document|Element} elem - Target element.
|
|
730
844
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
731
845
|
*/
|
|
732
|
-
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
733
|
-
const newEls =
|
|
846
|
+
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml', elem = document) {
|
|
847
|
+
const newEls = elem.getElementsByTagNameNS(namespaceURI, localName);
|
|
734
848
|
return TinyHtml.toTinyElm([...newEls]);
|
|
735
849
|
}
|
|
736
850
|
|
|
851
|
+
/**
|
|
852
|
+
* Retrieves all elements with the specified local tag name within the given namespace URI,
|
|
853
|
+
* and wraps them in TinyHtml instances.
|
|
854
|
+
*
|
|
855
|
+
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
856
|
+
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
857
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
858
|
+
*/
|
|
859
|
+
getElementsByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
860
|
+
return TinyHtml.getByTagNameNS(
|
|
861
|
+
localName,
|
|
862
|
+
namespaceURI,
|
|
863
|
+
TinyHtml._preElem(this, 'getByTagNameNS'),
|
|
864
|
+
);
|
|
865
|
+
}
|
|
866
|
+
|
|
737
867
|
//////////////////////////////////////////////////////////////////
|
|
738
868
|
|
|
739
869
|
/**
|
|
@@ -1014,6 +1144,45 @@ class TinyHtml {
|
|
|
1014
1144
|
return TinyHtml._preElemTemplate(elems, where, [Element, Window], ['Element', 'Window']);
|
|
1015
1145
|
}
|
|
1016
1146
|
|
|
1147
|
+
/**
|
|
1148
|
+
* Ensures the input is returned as an array.
|
|
1149
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
1150
|
+
*
|
|
1151
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
1152
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
1153
|
+
* @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
|
|
1154
|
+
* @readonly
|
|
1155
|
+
*/
|
|
1156
|
+
static _preElemsAndWinAndDoc(elems, where) {
|
|
1157
|
+
const result = TinyHtml._preElemsTemplate(
|
|
1158
|
+
elems,
|
|
1159
|
+
where,
|
|
1160
|
+
[Element, Window, Document],
|
|
1161
|
+
['Element', 'Window', 'Document'],
|
|
1162
|
+
);
|
|
1163
|
+
return result.map((elem) => (!(elem instanceof Document) ? elem : elem.documentElement));
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
/**
|
|
1167
|
+
* Ensures the input is returned as an single element/window/document element.
|
|
1168
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
1169
|
+
*
|
|
1170
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
1171
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
1172
|
+
* @returns {ElementAndWindow} - Always returns an single element/window element.
|
|
1173
|
+
* @readonly
|
|
1174
|
+
*/
|
|
1175
|
+
static _preElemAndWinAndDoc(elems, where) {
|
|
1176
|
+
const result = TinyHtml._preElemTemplate(
|
|
1177
|
+
elems,
|
|
1178
|
+
where,
|
|
1179
|
+
[Element, Window, Document],
|
|
1180
|
+
['Element', 'Window', 'Document'],
|
|
1181
|
+
);
|
|
1182
|
+
if (result instanceof Document) return result.documentElement;
|
|
1183
|
+
return result;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1017
1186
|
/**
|
|
1018
1187
|
* Normalizes and converts one or more DOM elements (or TinyHtml instances)
|
|
1019
1188
|
* into an array of `TinyHtml` instances.
|
|
@@ -1360,12 +1529,13 @@ class TinyHtml {
|
|
|
1360
1529
|
* @param {string} key - The key under which the data will be stored.
|
|
1361
1530
|
* @param {any} value - The value to store.
|
|
1362
1531
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
1363
|
-
* @returns {
|
|
1532
|
+
* @returns {TinyElement}
|
|
1364
1533
|
*/
|
|
1365
1534
|
static setData(el, key, value, isPrivate = false) {
|
|
1366
1535
|
const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('setData', el);
|
|
1367
1536
|
if (typeof key !== 'string') throw new TypeError('The key must be a string.');
|
|
1368
1537
|
data[key] = value;
|
|
1538
|
+
return el;
|
|
1369
1539
|
}
|
|
1370
1540
|
|
|
1371
1541
|
/**
|
|
@@ -1374,7 +1544,7 @@ class TinyHtml {
|
|
|
1374
1544
|
* @param {string} key - The key under which the data will be stored.
|
|
1375
1545
|
* @param {any} value - The value to store.
|
|
1376
1546
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
1377
|
-
* @returns {
|
|
1547
|
+
* @returns {TinyElement}
|
|
1378
1548
|
*/
|
|
1379
1549
|
setData(key, value, isPrivate = false) {
|
|
1380
1550
|
return TinyHtml.setData(this, key, value, isPrivate);
|
|
@@ -1721,18 +1891,21 @@ class TinyHtml {
|
|
|
1721
1891
|
/**
|
|
1722
1892
|
* Appends child elements or strings to the end of the target element(s).
|
|
1723
1893
|
*
|
|
1724
|
-
* @param {TinyElement
|
|
1894
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
1725
1895
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
1896
|
+
* @returns {TinyElement}
|
|
1726
1897
|
*/
|
|
1727
1898
|
static append(el, ...children) {
|
|
1728
1899
|
const elem = TinyHtml._preElem(el, 'append');
|
|
1729
1900
|
elem.append(...TinyHtml._appendChecker('append', ...children));
|
|
1901
|
+
return el;
|
|
1730
1902
|
}
|
|
1731
1903
|
|
|
1732
1904
|
/**
|
|
1733
1905
|
* Appends child elements or strings to the end of the target element(s).
|
|
1734
1906
|
*
|
|
1735
1907
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
1908
|
+
* @returns {TinyElement}
|
|
1736
1909
|
*/
|
|
1737
1910
|
append(...children) {
|
|
1738
1911
|
return TinyHtml.append(this, ...children);
|
|
@@ -1741,18 +1914,21 @@ class TinyHtml {
|
|
|
1741
1914
|
/**
|
|
1742
1915
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
1743
1916
|
*
|
|
1744
|
-
* @param {TinyElement
|
|
1917
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
1745
1918
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
1919
|
+
* @returns {TinyElement}
|
|
1746
1920
|
*/
|
|
1747
1921
|
static prepend(el, ...children) {
|
|
1748
1922
|
const elem = TinyHtml._preElem(el, 'prepend');
|
|
1749
1923
|
elem.prepend(...TinyHtml._appendChecker('prepend', ...children));
|
|
1924
|
+
return el;
|
|
1750
1925
|
}
|
|
1751
1926
|
|
|
1752
1927
|
/**
|
|
1753
1928
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
1754
1929
|
*
|
|
1755
1930
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
1931
|
+
* @returns {TinyElement}
|
|
1756
1932
|
*/
|
|
1757
1933
|
prepend(...children) {
|
|
1758
1934
|
return TinyHtml.prepend(this, ...children);
|
|
@@ -1761,18 +1937,21 @@ class TinyHtml {
|
|
|
1761
1937
|
/**
|
|
1762
1938
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
1763
1939
|
*
|
|
1764
|
-
* @param {TinyElement
|
|
1940
|
+
* @param {TinyElement} el - The target element(s) before which new content is inserted.
|
|
1765
1941
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
1942
|
+
* @returns {TinyElement}
|
|
1766
1943
|
*/
|
|
1767
1944
|
static before(el, ...children) {
|
|
1768
1945
|
const elem = TinyHtml._preElem(el, 'before');
|
|
1769
1946
|
elem.before(...TinyHtml._appendChecker('before', ...children));
|
|
1947
|
+
return el;
|
|
1770
1948
|
}
|
|
1771
1949
|
|
|
1772
1950
|
/**
|
|
1773
1951
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
1774
1952
|
*
|
|
1775
1953
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
1954
|
+
* @returns {TinyElement}
|
|
1776
1955
|
*/
|
|
1777
1956
|
before(...children) {
|
|
1778
1957
|
return TinyHtml.before(this, ...children);
|
|
@@ -1781,18 +1960,21 @@ class TinyHtml {
|
|
|
1781
1960
|
/**
|
|
1782
1961
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
1783
1962
|
*
|
|
1784
|
-
* @param {TinyElement
|
|
1963
|
+
* @param {TinyElement} el - The target element(s) after which new content is inserted.
|
|
1785
1964
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
1965
|
+
* @returns {TinyElement}
|
|
1786
1966
|
*/
|
|
1787
1967
|
static after(el, ...children) {
|
|
1788
1968
|
const elem = TinyHtml._preElem(el, 'after');
|
|
1789
1969
|
elem.after(...TinyHtml._appendChecker('after', ...children));
|
|
1970
|
+
return el;
|
|
1790
1971
|
}
|
|
1791
1972
|
|
|
1792
1973
|
/**
|
|
1793
1974
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
1794
1975
|
*
|
|
1795
1976
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
1977
|
+
* @returns {TinyElement}
|
|
1796
1978
|
*/
|
|
1797
1979
|
after(...children) {
|
|
1798
1980
|
return TinyHtml.after(this, ...children);
|
|
@@ -1801,18 +1983,21 @@ class TinyHtml {
|
|
|
1801
1983
|
/**
|
|
1802
1984
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
1803
1985
|
*
|
|
1804
|
-
* @param {TinyElement
|
|
1986
|
+
* @param {TinyElement} el - The element(s) to be replaced.
|
|
1805
1987
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
1988
|
+
* @returns {TinyElement}
|
|
1806
1989
|
*/
|
|
1807
1990
|
static replaceWith(el, ...newNodes) {
|
|
1808
1991
|
const elem = TinyHtml._preElem(el, 'replaceWith');
|
|
1809
1992
|
elem.replaceWith(...TinyHtml._appendChecker('replaceWith', ...newNodes));
|
|
1993
|
+
return el;
|
|
1810
1994
|
}
|
|
1811
1995
|
|
|
1812
1996
|
/**
|
|
1813
1997
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
1814
1998
|
*
|
|
1815
1999
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
2000
|
+
* @returns {TinyElement}
|
|
1816
2001
|
*/
|
|
1817
2002
|
replaceWith(...newNodes) {
|
|
1818
2003
|
return TinyHtml.replaceWith(this, ...newNodes);
|
|
@@ -1823,6 +2008,7 @@ class TinyHtml {
|
|
|
1823
2008
|
*
|
|
1824
2009
|
* @param {TinyNode | TinyNode[]} el - The element(s) to append.
|
|
1825
2010
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
2011
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1826
2012
|
*/
|
|
1827
2013
|
static appendTo(el, targets) {
|
|
1828
2014
|
const elems = TinyHtml._preNodeElems(el, 'appendTo');
|
|
@@ -1832,12 +2018,14 @@ class TinyHtml {
|
|
|
1832
2018
|
target.appendChild(i === tars.length - 1 ? elem : elem.cloneNode(true)),
|
|
1833
2019
|
);
|
|
1834
2020
|
});
|
|
2021
|
+
return el;
|
|
1835
2022
|
}
|
|
1836
2023
|
|
|
1837
2024
|
/**
|
|
1838
2025
|
* Appends the given element(s) to each target element in sequence.
|
|
1839
2026
|
*
|
|
1840
2027
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
2028
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1841
2029
|
*/
|
|
1842
2030
|
appendTo(targets) {
|
|
1843
2031
|
return TinyHtml.appendTo(this, targets);
|
|
@@ -1848,6 +2036,7 @@ class TinyHtml {
|
|
|
1848
2036
|
*
|
|
1849
2037
|
* @param {TinyElement | TinyElement[]} el - The element(s) to prepend.
|
|
1850
2038
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
2039
|
+
* @returns {TinyElement|TinyElement[]}
|
|
1851
2040
|
*/
|
|
1852
2041
|
static prependTo(el, targets) {
|
|
1853
2042
|
const elems = TinyHtml._preElems(el, 'prependTo');
|
|
@@ -1858,12 +2047,14 @@ class TinyHtml {
|
|
|
1858
2047
|
.reverse()
|
|
1859
2048
|
.forEach((elem) => target.prepend(i === tars.length - 1 ? elem : elem.cloneNode(true)));
|
|
1860
2049
|
});
|
|
2050
|
+
return el;
|
|
1861
2051
|
}
|
|
1862
2052
|
|
|
1863
2053
|
/**
|
|
1864
2054
|
* Prepends the given element(s) to each target element in sequence.
|
|
1865
2055
|
*
|
|
1866
2056
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
2057
|
+
* @returns {TinyElement|TinyElement[]}
|
|
1867
2058
|
*/
|
|
1868
2059
|
prependTo(targets) {
|
|
1869
2060
|
return TinyHtml.prependTo(this, targets);
|
|
@@ -1875,6 +2066,7 @@ class TinyHtml {
|
|
|
1875
2066
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
1876
2067
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1877
2068
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
2069
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1878
2070
|
*/
|
|
1879
2071
|
static insertBefore(el, target, child = null) {
|
|
1880
2072
|
const elem = TinyHtml._preNodeElem(el, 'insertBefore');
|
|
@@ -1882,6 +2074,7 @@ class TinyHtml {
|
|
|
1882
2074
|
const childNode = TinyHtml._preNodeElemWithNull(child, 'insertBefore');
|
|
1883
2075
|
if (!targ.parentNode) throw new Error('');
|
|
1884
2076
|
targ.parentNode.insertBefore(elem, childNode || targ);
|
|
2077
|
+
return el;
|
|
1885
2078
|
}
|
|
1886
2079
|
|
|
1887
2080
|
/**
|
|
@@ -1889,6 +2082,7 @@ class TinyHtml {
|
|
|
1889
2082
|
*
|
|
1890
2083
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1891
2084
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
2085
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1892
2086
|
*/
|
|
1893
2087
|
insertBefore(target, child) {
|
|
1894
2088
|
return TinyHtml.insertBefore(this, target, child);
|
|
@@ -1900,6 +2094,7 @@ class TinyHtml {
|
|
|
1900
2094
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
1901
2095
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1902
2096
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
2097
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1903
2098
|
*/
|
|
1904
2099
|
static insertAfter(el, target, child = null) {
|
|
1905
2100
|
const elem = TinyHtml._preNodeElem(el, 'insertAfter');
|
|
@@ -1907,6 +2102,7 @@ class TinyHtml {
|
|
|
1907
2102
|
const childNode = TinyHtml._preNodeElemWithNull(child, 'insertBefore');
|
|
1908
2103
|
if (!targ.parentNode) throw new Error('');
|
|
1909
2104
|
targ.parentNode.insertBefore(elem, childNode || targ.nextSibling);
|
|
2105
|
+
return el;
|
|
1910
2106
|
}
|
|
1911
2107
|
|
|
1912
2108
|
/**
|
|
@@ -1914,6 +2110,7 @@ class TinyHtml {
|
|
|
1914
2110
|
*
|
|
1915
2111
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1916
2112
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
2113
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1917
2114
|
*/
|
|
1918
2115
|
insertAfter(target, child) {
|
|
1919
2116
|
return TinyHtml.insertAfter(this, target, child);
|
|
@@ -1925,6 +2122,7 @@ class TinyHtml {
|
|
|
1925
2122
|
*
|
|
1926
2123
|
* @param {TinyNode | TinyNode[]} el - The new element(s) to insert.
|
|
1927
2124
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
2125
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1928
2126
|
*/
|
|
1929
2127
|
static replaceAll(el, targets) {
|
|
1930
2128
|
const elems = TinyHtml._preNodeElems(el, 'replaceAll');
|
|
@@ -1936,6 +2134,7 @@ class TinyHtml {
|
|
|
1936
2134
|
parent.replaceChild(i === tars.length - 1 ? elem : elem.cloneNode(true), target);
|
|
1937
2135
|
});
|
|
1938
2136
|
});
|
|
2137
|
+
return el;
|
|
1939
2138
|
}
|
|
1940
2139
|
|
|
1941
2140
|
/**
|
|
@@ -1943,6 +2142,7 @@ class TinyHtml {
|
|
|
1943
2142
|
* If multiple targets exist, the inserted elements are cloned accordingly.
|
|
1944
2143
|
*
|
|
1945
2144
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
2145
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1946
2146
|
*/
|
|
1947
2147
|
replaceAll(targets) {
|
|
1948
2148
|
return TinyHtml.replaceAll(this, targets);
|
|
@@ -1966,7 +2166,12 @@ class TinyHtml {
|
|
|
1966
2166
|
throw new Error(
|
|
1967
2167
|
`[TinyHtml] You are trying to put a TinyHtml inside another TinyHtml in constructor.`,
|
|
1968
2168
|
);
|
|
1969
|
-
if (
|
|
2169
|
+
if (
|
|
2170
|
+
!(el instanceof Element) &&
|
|
2171
|
+
!(el instanceof Window) &&
|
|
2172
|
+
!(el instanceof Document) &&
|
|
2173
|
+
!(el instanceof Text)
|
|
2174
|
+
)
|
|
1970
2175
|
throw new Error(`[TinyHtml] Invalid Target in constructor.`);
|
|
1971
2176
|
this.#el = el;
|
|
1972
2177
|
}
|
|
@@ -2416,6 +2621,7 @@ class TinyHtml {
|
|
|
2416
2621
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - The element to inspect.
|
|
2417
2622
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
2418
2623
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
2624
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2419
2625
|
*/
|
|
2420
2626
|
static setStyle(el, prop, value = null) {
|
|
2421
2627
|
TinyHtml._preHtmlElems(el, 'setStyle').forEach((elem) => {
|
|
@@ -2428,6 +2634,7 @@ class TinyHtml {
|
|
|
2428
2634
|
}
|
|
2429
2635
|
} else elem.style.setProperty(TinyHtml.toStyleKc(prop), value);
|
|
2430
2636
|
});
|
|
2637
|
+
return el;
|
|
2431
2638
|
}
|
|
2432
2639
|
|
|
2433
2640
|
/**
|
|
@@ -2438,6 +2645,7 @@ class TinyHtml {
|
|
|
2438
2645
|
*
|
|
2439
2646
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
2440
2647
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
2648
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2441
2649
|
*/
|
|
2442
2650
|
setStyle(prop, value) {
|
|
2443
2651
|
return TinyHtml.setStyle(this, prop, value);
|
|
@@ -2533,6 +2741,7 @@ class TinyHtml {
|
|
|
2533
2741
|
*
|
|
2534
2742
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - A single element or an array of elements.
|
|
2535
2743
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
2744
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2536
2745
|
*/
|
|
2537
2746
|
static removeStyle(el, prop) {
|
|
2538
2747
|
TinyHtml._preHtmlElems(el, 'removeStyle').forEach((elem) => {
|
|
@@ -2542,12 +2751,14 @@ class TinyHtml {
|
|
|
2542
2751
|
}
|
|
2543
2752
|
} else elem.style.removeProperty(TinyHtml.toStyleKc(prop));
|
|
2544
2753
|
});
|
|
2754
|
+
return el;
|
|
2545
2755
|
}
|
|
2546
2756
|
|
|
2547
2757
|
/**
|
|
2548
2758
|
* Removes one or more inline CSS properties from the given element(s).
|
|
2549
2759
|
*
|
|
2550
2760
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
2761
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2551
2762
|
*/
|
|
2552
2763
|
removeStyle(prop) {
|
|
2553
2764
|
return TinyHtml.removeStyle(this, prop);
|
|
@@ -2562,6 +2773,7 @@ class TinyHtml {
|
|
|
2562
2773
|
* @param {string} prop - The CSS property to toggle.
|
|
2563
2774
|
* @param {string} val1 - The first value (used as "current" check).
|
|
2564
2775
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
2776
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2565
2777
|
*/
|
|
2566
2778
|
static toggleStyle(el, prop, val1, val2) {
|
|
2567
2779
|
TinyHtml._preHtmlElems(el, 'toggleStyle').forEach((elem) => {
|
|
@@ -2569,6 +2781,7 @@ class TinyHtml {
|
|
|
2569
2781
|
const newVal = current === TinyHtml.toStyleKc(val1) ? val2 : val1;
|
|
2570
2782
|
TinyHtml.setStyle(elem, prop, newVal);
|
|
2571
2783
|
});
|
|
2784
|
+
return el;
|
|
2572
2785
|
}
|
|
2573
2786
|
|
|
2574
2787
|
/**
|
|
@@ -2579,6 +2792,7 @@ class TinyHtml {
|
|
|
2579
2792
|
* @param {string} prop - The CSS property to toggle.
|
|
2580
2793
|
* @param {string} val1 - The first value (used as "current" check).
|
|
2581
2794
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
2795
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2582
2796
|
*/
|
|
2583
2797
|
toggleStyle(prop, val1, val2) {
|
|
2584
2798
|
return TinyHtml.toggleStyle(this, prop, val1, val2);
|
|
@@ -2588,14 +2802,16 @@ class TinyHtml {
|
|
|
2588
2802
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
2589
2803
|
*
|
|
2590
2804
|
* @param {TinyElement|TinyElement[]} el - A single element or an array of elements.
|
|
2805
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2591
2806
|
*/
|
|
2592
2807
|
static clearStyle(el) {
|
|
2593
2808
|
TinyHtml._preElems(el, 'clearStyle').forEach((elem) => elem.removeAttribute('style'));
|
|
2809
|
+
return el;
|
|
2594
2810
|
}
|
|
2595
2811
|
|
|
2596
2812
|
/**
|
|
2597
2813
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
2598
|
-
*
|
|
2814
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2599
2815
|
*/
|
|
2600
2816
|
clearStyle() {
|
|
2601
2817
|
return TinyHtml.clearStyle(this);
|
|
@@ -2607,14 +2823,17 @@ class TinyHtml {
|
|
|
2607
2823
|
* Focus the element.
|
|
2608
2824
|
*
|
|
2609
2825
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
2826
|
+
* @returns {TinyHtmlElement}
|
|
2610
2827
|
*/
|
|
2611
2828
|
static focus(el) {
|
|
2612
2829
|
const elem = TinyHtml._preHtmlElem(el, 'focus');
|
|
2613
2830
|
elem.focus();
|
|
2831
|
+
return el;
|
|
2614
2832
|
}
|
|
2615
2833
|
|
|
2616
2834
|
/**
|
|
2617
2835
|
* Focus the element.
|
|
2836
|
+
* @returns {TinyHtmlElement}
|
|
2618
2837
|
*/
|
|
2619
2838
|
focus() {
|
|
2620
2839
|
return TinyHtml.focus(this);
|
|
@@ -2624,19 +2843,46 @@ class TinyHtml {
|
|
|
2624
2843
|
* Blur the element.
|
|
2625
2844
|
*
|
|
2626
2845
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
2846
|
+
* @returns {TinyHtmlElement}
|
|
2627
2847
|
*/
|
|
2628
2848
|
static blur(el) {
|
|
2629
2849
|
const elem = TinyHtml._preHtmlElem(el, 'blur');
|
|
2630
2850
|
elem.blur();
|
|
2851
|
+
return el;
|
|
2631
2852
|
}
|
|
2632
2853
|
|
|
2633
2854
|
/**
|
|
2634
2855
|
* Blur the element.
|
|
2856
|
+
* @returns {TinyHtmlElement}
|
|
2635
2857
|
*/
|
|
2636
2858
|
blur() {
|
|
2637
2859
|
return TinyHtml.blur(this);
|
|
2638
2860
|
}
|
|
2639
2861
|
|
|
2862
|
+
/**
|
|
2863
|
+
* Interprets a value as a boolean `true` if it matches a common truthy representation.
|
|
2864
|
+
*
|
|
2865
|
+
* This method checks if the input is any of the common forms used to represent `true`,
|
|
2866
|
+
* such as the string `'true'`, `'1'`, `'on'`, the boolean `true`, or the number `1`.
|
|
2867
|
+
*
|
|
2868
|
+
* @param {string|boolean|number} [value] - The value to interpret as boolean.
|
|
2869
|
+
* @returns {boolean} `true` if the value represents a truthy state, otherwise `false`.
|
|
2870
|
+
*/
|
|
2871
|
+
static boolCheck(value) {
|
|
2872
|
+
if (
|
|
2873
|
+
typeof value !== 'undefined' &&
|
|
2874
|
+
(value === 'true' ||
|
|
2875
|
+
value === '1' ||
|
|
2876
|
+
value === true ||
|
|
2877
|
+
value === 'on' ||
|
|
2878
|
+
(typeof value === 'number' && value > 0))
|
|
2879
|
+
) {
|
|
2880
|
+
return true;
|
|
2881
|
+
} else {
|
|
2882
|
+
return false;
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2640
2886
|
//////////////////////////////////////////////////////////////////////
|
|
2641
2887
|
|
|
2642
2888
|
/**
|
|
@@ -2645,7 +2891,7 @@ class TinyHtml {
|
|
|
2645
2891
|
*/
|
|
2646
2892
|
static setWinScrollTop(value) {
|
|
2647
2893
|
if (typeof value !== 'number') throw new TypeError('The value must be a number.');
|
|
2648
|
-
|
|
2894
|
+
TinyHtml.setScrollTop(window, value);
|
|
2649
2895
|
}
|
|
2650
2896
|
|
|
2651
2897
|
/**
|
|
@@ -2654,7 +2900,7 @@ class TinyHtml {
|
|
|
2654
2900
|
*/
|
|
2655
2901
|
static setWinScrollLeft(value) {
|
|
2656
2902
|
if (typeof value !== 'number') throw new TypeError('The value must be a number.');
|
|
2657
|
-
|
|
2903
|
+
TinyHtml.setScrollLeft(window, value);
|
|
2658
2904
|
}
|
|
2659
2905
|
|
|
2660
2906
|
/**
|
|
@@ -2689,16 +2935,40 @@ class TinyHtml {
|
|
|
2689
2935
|
return window.innerWidth || document.documentElement.clientWidth;
|
|
2690
2936
|
}
|
|
2691
2937
|
|
|
2938
|
+
/**
|
|
2939
|
+
* Checks if the page is currently scrolled to the very top.
|
|
2940
|
+
*
|
|
2941
|
+
* This method compares the current vertical scroll position with the total document height.
|
|
2942
|
+
* It's useful for detecting if the user has reached the top of the page.
|
|
2943
|
+
*
|
|
2944
|
+
* @returns {boolean} `true` if the page is scrolled to the top, otherwise `false`.
|
|
2945
|
+
*/
|
|
2946
|
+
static isPageTop() {
|
|
2947
|
+
return window.scrollY === 0;
|
|
2948
|
+
}
|
|
2949
|
+
|
|
2950
|
+
/**
|
|
2951
|
+
* Checks if the page is currently scrolled to the very bottom.
|
|
2952
|
+
*
|
|
2953
|
+
* This method uses the `scrollY` and `innerHeight` properties to determine if the
|
|
2954
|
+
* user has reached the end of the document.
|
|
2955
|
+
*
|
|
2956
|
+
* @returns {boolean} `true` if the page is scrolled to the bottom, otherwise `false`.
|
|
2957
|
+
*/
|
|
2958
|
+
static isPageBottom() {
|
|
2959
|
+
return window.innerHeight + window.scrollY >= document.body.offsetHeight;
|
|
2960
|
+
}
|
|
2961
|
+
|
|
2692
2962
|
/**
|
|
2693
2963
|
* Gets the width or height of an element based on the box model.
|
|
2694
|
-
* @param {
|
|
2964
|
+
* @param {TinyElementAndWinAndDoc} el - The element or window.
|
|
2695
2965
|
* @param {"width"|"height"} type - Dimension type.
|
|
2696
2966
|
* @param {"content"|"padding"|"border"|"margin"} [extra='content'] - Box model context.
|
|
2697
2967
|
* @returns {number} - Computed dimension.
|
|
2698
2968
|
* @throws {TypeError} If `type` or `extra` is not a string.
|
|
2699
2969
|
*/
|
|
2700
2970
|
static getDimension(el, type, extra = 'content') {
|
|
2701
|
-
const elem = TinyHtml.
|
|
2971
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'getDimension');
|
|
2702
2972
|
if (typeof type !== 'string') throw new TypeError('The type must be a string.');
|
|
2703
2973
|
if (typeof extra !== 'string') throw new TypeError('The extra must be a string.');
|
|
2704
2974
|
|
|
@@ -2786,17 +3056,20 @@ class TinyHtml {
|
|
|
2786
3056
|
* @param {TinyHtmlElement} el - Target element.
|
|
2787
3057
|
* @param {string|number} value - Height value.
|
|
2788
3058
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
3059
|
+
* @returns {TinyHtmlElement}
|
|
2789
3060
|
*/
|
|
2790
3061
|
static setHeight(el, value) {
|
|
2791
3062
|
const elem = TinyHtml._preHtmlElem(el, 'setHeight');
|
|
2792
3063
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
2793
3064
|
throw new TypeError('The value must be a string or number.');
|
|
2794
3065
|
elem.style.height = typeof value === 'number' ? `${value}px` : value;
|
|
3066
|
+
return el;
|
|
2795
3067
|
}
|
|
2796
3068
|
|
|
2797
3069
|
/**
|
|
2798
3070
|
* Sets the height of the element.
|
|
2799
3071
|
* @param {string|number} value - Height value.
|
|
3072
|
+
* @returns {TinyHtmlElement}
|
|
2800
3073
|
*/
|
|
2801
3074
|
setHeight(value) {
|
|
2802
3075
|
return TinyHtml.setHeight(this, value);
|
|
@@ -2807,17 +3080,20 @@ class TinyHtml {
|
|
|
2807
3080
|
* @param {TinyHtmlElement} el - Target element.
|
|
2808
3081
|
* @param {string|number} value - Width value.
|
|
2809
3082
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
3083
|
+
* @returns {TinyHtmlElement}
|
|
2810
3084
|
*/
|
|
2811
3085
|
static setWidth(el, value) {
|
|
2812
3086
|
const elem = TinyHtml._preHtmlElem(el, 'setWidth');
|
|
2813
3087
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
2814
3088
|
throw new TypeError('The value must be a string or number.');
|
|
2815
3089
|
elem.style.width = typeof value === 'number' ? `${value}px` : value;
|
|
3090
|
+
return el;
|
|
2816
3091
|
}
|
|
2817
3092
|
|
|
2818
3093
|
/**
|
|
2819
3094
|
* Sets the width of the element.
|
|
2820
3095
|
* @param {string|number} value - Width value.
|
|
3096
|
+
* @returns {TinyHtmlElement}
|
|
2821
3097
|
*/
|
|
2822
3098
|
setWidth(value) {
|
|
2823
3099
|
return TinyHtml.setWidth(this, value);
|
|
@@ -2825,11 +3101,11 @@ class TinyHtml {
|
|
|
2825
3101
|
|
|
2826
3102
|
/**
|
|
2827
3103
|
* Returns content box height.
|
|
2828
|
-
* @param {
|
|
3104
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2829
3105
|
* @returns {number}
|
|
2830
3106
|
*/
|
|
2831
3107
|
static height(el) {
|
|
2832
|
-
const elem = TinyHtml.
|
|
3108
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'height');
|
|
2833
3109
|
return TinyHtml.getDimension(elem, 'height', 'content');
|
|
2834
3110
|
}
|
|
2835
3111
|
|
|
@@ -2843,11 +3119,11 @@ class TinyHtml {
|
|
|
2843
3119
|
|
|
2844
3120
|
/**
|
|
2845
3121
|
* Returns content box width.
|
|
2846
|
-
* @param {
|
|
3122
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2847
3123
|
* @returns {number}
|
|
2848
3124
|
*/
|
|
2849
3125
|
static width(el) {
|
|
2850
|
-
const elem = TinyHtml.
|
|
3126
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'width');
|
|
2851
3127
|
return TinyHtml.getDimension(elem, 'width', 'content');
|
|
2852
3128
|
}
|
|
2853
3129
|
|
|
@@ -2861,11 +3137,11 @@ class TinyHtml {
|
|
|
2861
3137
|
|
|
2862
3138
|
/**
|
|
2863
3139
|
* Returns padding box height.
|
|
2864
|
-
* @param {
|
|
3140
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2865
3141
|
* @returns {number}
|
|
2866
3142
|
*/
|
|
2867
3143
|
static innerHeight(el) {
|
|
2868
|
-
const elem = TinyHtml.
|
|
3144
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerHeight');
|
|
2869
3145
|
return TinyHtml.getDimension(elem, 'height', 'padding');
|
|
2870
3146
|
}
|
|
2871
3147
|
|
|
@@ -2879,11 +3155,11 @@ class TinyHtml {
|
|
|
2879
3155
|
|
|
2880
3156
|
/**
|
|
2881
3157
|
* Returns padding box width.
|
|
2882
|
-
* @param {
|
|
3158
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2883
3159
|
* @returns {number}
|
|
2884
3160
|
*/
|
|
2885
3161
|
static innerWidth(el) {
|
|
2886
|
-
const elem = TinyHtml.
|
|
3162
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerWidth');
|
|
2887
3163
|
return TinyHtml.getDimension(elem, 'width', 'padding');
|
|
2888
3164
|
}
|
|
2889
3165
|
|
|
@@ -2897,14 +3173,14 @@ class TinyHtml {
|
|
|
2897
3173
|
|
|
2898
3174
|
/**
|
|
2899
3175
|
* Returns outer height of the element, optionally including margin.
|
|
2900
|
-
* @param {
|
|
3176
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2901
3177
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
2902
3178
|
* @returns {number}
|
|
2903
3179
|
*/
|
|
2904
3180
|
static outerHeight(el, includeMargin = false) {
|
|
2905
3181
|
if (typeof includeMargin !== 'boolean')
|
|
2906
3182
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
2907
|
-
const elem = TinyHtml.
|
|
3183
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerHeight');
|
|
2908
3184
|
return TinyHtml.getDimension(elem, 'height', includeMargin ? 'margin' : 'border');
|
|
2909
3185
|
}
|
|
2910
3186
|
|
|
@@ -2919,14 +3195,14 @@ class TinyHtml {
|
|
|
2919
3195
|
|
|
2920
3196
|
/**
|
|
2921
3197
|
* Returns outer width of the element, optionally including margin.
|
|
2922
|
-
* @param {
|
|
3198
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2923
3199
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
2924
3200
|
* @returns {number}
|
|
2925
3201
|
*/
|
|
2926
3202
|
static outerWidth(el, includeMargin = false) {
|
|
2927
3203
|
if (typeof includeMargin !== 'boolean')
|
|
2928
3204
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
2929
|
-
const elem = TinyHtml.
|
|
3205
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerWidth');
|
|
2930
3206
|
return TinyHtml.getDimension(elem, 'width', includeMargin ? 'margin' : 'border');
|
|
2931
3207
|
}
|
|
2932
3208
|
|
|
@@ -2941,6 +3217,30 @@ class TinyHtml {
|
|
|
2941
3217
|
|
|
2942
3218
|
//////////////////////////////////////////////////
|
|
2943
3219
|
|
|
3220
|
+
/**
|
|
3221
|
+
* Applies an animation to one or multiple TinyElement instances.
|
|
3222
|
+
*
|
|
3223
|
+
* @param {TinyElement|TinyElement[]} el - A single TinyElement or an array of TinyElements to animate.
|
|
3224
|
+
* @param {Keyframe[] | PropertyIndexedKeyframes | null} keyframes - The keyframes used to define the animation.
|
|
3225
|
+
* @param {number | KeyframeAnimationOptions} [ops] - Timing or configuration options for the animation.
|
|
3226
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3227
|
+
*/
|
|
3228
|
+
static animate(el, keyframes, ops) {
|
|
3229
|
+
TinyHtml._preElems(el, 'animate').forEach((elem) => elem.animate(keyframes, ops));
|
|
3230
|
+
return el;
|
|
3231
|
+
}
|
|
3232
|
+
|
|
3233
|
+
/**
|
|
3234
|
+
* Applies an animation to one or multiple TinyElement instances.
|
|
3235
|
+
*
|
|
3236
|
+
* @param {Keyframe[] | PropertyIndexedKeyframes | null} keyframes - The keyframes used to define the animation.
|
|
3237
|
+
* @param {number | KeyframeAnimationOptions} [ops] - Timing or configuration options for the animation.
|
|
3238
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3239
|
+
*/
|
|
3240
|
+
animate(keyframes, ops) {
|
|
3241
|
+
return TinyHtml.animate(this, keyframes, ops);
|
|
3242
|
+
}
|
|
3243
|
+
|
|
2944
3244
|
/**
|
|
2945
3245
|
* Gets the offset of the element relative to the document.
|
|
2946
3246
|
* @param {TinyElement} el - Target element.
|
|
@@ -3096,27 +3396,151 @@ class TinyHtml {
|
|
|
3096
3396
|
}
|
|
3097
3397
|
|
|
3098
3398
|
/**
|
|
3099
|
-
*
|
|
3100
|
-
*
|
|
3101
|
-
*
|
|
3399
|
+
* Collection of easing functions used for scroll and animation calculations.
|
|
3400
|
+
* Each function receives a normalized time value (`t` from 0 to 1) and returns the eased progress.
|
|
3401
|
+
*
|
|
3402
|
+
* @type {Record<string, (t: number) => number>}
|
|
3102
3403
|
*/
|
|
3103
|
-
static
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3404
|
+
static easings = {
|
|
3405
|
+
linear: (t) => t,
|
|
3406
|
+
easeInQuad: (t) => t * t,
|
|
3407
|
+
easeOutQuad: (t) => t * (2 - t),
|
|
3408
|
+
easeInOutQuad: (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t),
|
|
3409
|
+
easeInCubic: (t) => t * t * t,
|
|
3410
|
+
easeOutCubic: (t) => --t * t * t + 1,
|
|
3411
|
+
easeInOutCubic: (t) => (t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1),
|
|
3412
|
+
};
|
|
3413
|
+
|
|
3414
|
+
/**
|
|
3415
|
+
* Smoothly scrolls one or more elements (or the window) to the specified X and Y coordinates
|
|
3416
|
+
* using a custom duration and easing function.
|
|
3417
|
+
*
|
|
3418
|
+
* If `duration` or a valid `easing` is not provided, the scroll will be performed immediately.
|
|
3419
|
+
*
|
|
3420
|
+
* @param {TinyElementAndWindow | TinyElementAndWindow[]} el - A single element, array of elements, or the window to scroll.
|
|
3421
|
+
* @param {Object} [settings={}] - Configuration object for the scroll animation.
|
|
3422
|
+
* @param {number} [settings.targetX] - The horizontal scroll target in pixels.
|
|
3423
|
+
* @param {number} [settings.targetY] - The vertical scroll target in pixels.
|
|
3424
|
+
* @param {number} [settings.duration] - The duration of the animation in milliseconds.
|
|
3425
|
+
* @param {Easings} [settings.easing] - The easing function name to use for the scroll animation.
|
|
3426
|
+
* @param {OnScrollAnimation} [settings.onAnimation] - Optional callback invoked on each animation
|
|
3427
|
+
* frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag.
|
|
3428
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3429
|
+
* @throws {TypeError} If `el` is not a valid element, array, or window.
|
|
3430
|
+
* @throws {TypeError} If `targetX` or `targetY` is defined but not a number.
|
|
3431
|
+
* @throws {TypeError} If `duration` is defined but not a number.
|
|
3432
|
+
* @throws {TypeError} If `easing` is defined but not a valid easing function name.
|
|
3433
|
+
* @throws {TypeError} If `onAnimation` is defined but not a function.
|
|
3434
|
+
*/
|
|
3435
|
+
static scrollToXY(el, { targetX, targetY, duration, easing, onAnimation } = {}) {
|
|
3436
|
+
if (targetX !== undefined && typeof targetX !== 'number')
|
|
3437
|
+
throw new TypeError('`targetX` must be a number if provided.');
|
|
3438
|
+
if (targetY !== undefined && typeof targetY !== 'number')
|
|
3439
|
+
throw new TypeError('`targetY` must be a number if provided.');
|
|
3440
|
+
if (duration !== undefined && typeof duration !== 'number')
|
|
3441
|
+
throw new TypeError('`duration` must be a number if provided.');
|
|
3442
|
+
if (easing !== undefined && typeof easing !== 'string')
|
|
3443
|
+
throw new TypeError('`easing` must be a string if provided.');
|
|
3444
|
+
if (easing !== undefined && typeof TinyHtml.easings[easing] !== 'function')
|
|
3445
|
+
throw new TypeError(`Unknown easing function: "${easing}".`);
|
|
3446
|
+
if (onAnimation !== undefined && typeof onAnimation !== 'function')
|
|
3447
|
+
throw new TypeError('`onAnimation` must be a function if provided.');
|
|
3448
|
+
|
|
3449
|
+
/**
|
|
3450
|
+
* Performs an instant scroll to the given coordinates.
|
|
3451
|
+
*
|
|
3452
|
+
* @param {ElementAndWindow} elem - The element or window to scroll.
|
|
3453
|
+
* @param {number} newX - The final horizontal scroll position.
|
|
3454
|
+
* @param {number} newY - The final vertical scroll position.
|
|
3455
|
+
* @param {number} time - Normalized progress value.
|
|
3456
|
+
*/
|
|
3457
|
+
const executeScroll = (elem, newX, newY, time) => {
|
|
3458
|
+
if (elem instanceof Window) {
|
|
3459
|
+
window.scrollTo(newX, newY);
|
|
3108
3460
|
} else if (elem.nodeType === 9) {
|
|
3109
3461
|
// @ts-ignore
|
|
3110
|
-
elem.defaultView.scrollTo(
|
|
3462
|
+
elem.defaultView.scrollTo(newX, newY);
|
|
3111
3463
|
} else {
|
|
3112
|
-
elem.
|
|
3464
|
+
const startX = elem instanceof Window ? window.scrollX : elem.scrollLeft;
|
|
3465
|
+
const startY = elem instanceof Window ? window.scrollY : elem.scrollTop;
|
|
3466
|
+
if (startX !== newX) elem.scrollLeft = newX;
|
|
3467
|
+
if (startY !== newY) elem.scrollTop = newY;
|
|
3113
3468
|
}
|
|
3469
|
+
if (typeof onAnimation === 'function')
|
|
3470
|
+
onAnimation({ x: newX, y: newY, isComplete: time >= 1, time });
|
|
3471
|
+
};
|
|
3472
|
+
|
|
3473
|
+
TinyHtml._preElemsAndWindow(el, 'scrollToXY').forEach((elem) => {
|
|
3474
|
+
const startX = elem instanceof Window ? window.scrollX : elem.scrollLeft;
|
|
3475
|
+
const startY = elem instanceof Window ? window.scrollY : elem.scrollTop;
|
|
3476
|
+
const targX = targetX ?? startX;
|
|
3477
|
+
const targY = targetY ?? startY;
|
|
3478
|
+
|
|
3479
|
+
const changeX = targX - startX;
|
|
3480
|
+
const changeY = targY - startY;
|
|
3481
|
+
|
|
3482
|
+
const ease = (typeof easing === 'string' && TinyHtml.easings[easing]) || null;
|
|
3483
|
+
if (typeof duration !== 'number' || typeof ease !== 'function')
|
|
3484
|
+
return executeScroll(elem, targX, targY, 1);
|
|
3485
|
+
const startTime = performance.now();
|
|
3486
|
+
const dur = duration ?? 0;
|
|
3487
|
+
|
|
3488
|
+
/**
|
|
3489
|
+
* Animates the scroll position based on easing and time.
|
|
3490
|
+
*
|
|
3491
|
+
* @param {number} currentTime - Timestamp provided by requestAnimationFrame.
|
|
3492
|
+
*/
|
|
3493
|
+
function animateScroll(currentTime) {
|
|
3494
|
+
if (typeof ease !== 'function') return;
|
|
3495
|
+
const time = Math.min(1, (currentTime - startTime) / dur);
|
|
3496
|
+
const easedTime = ease(time);
|
|
3497
|
+
|
|
3498
|
+
const newX = startX + changeX * easedTime;
|
|
3499
|
+
const newY = startY + changeY * easedTime;
|
|
3500
|
+
executeScroll(elem, newX, newY, time);
|
|
3501
|
+
|
|
3502
|
+
if (time < 1) requestAnimationFrame(animateScroll);
|
|
3503
|
+
}
|
|
3504
|
+
|
|
3505
|
+
requestAnimationFrame(animateScroll);
|
|
3114
3506
|
});
|
|
3507
|
+
return el;
|
|
3508
|
+
}
|
|
3509
|
+
|
|
3510
|
+
/**
|
|
3511
|
+
* Smoothly scrolls one or more elements (or the window) to the specified X and Y coordinates
|
|
3512
|
+
* using a custom duration and easing function.
|
|
3513
|
+
*
|
|
3514
|
+
* If `duration` or a valid `easing` is not provided, the scroll will be performed immediately.
|
|
3515
|
+
*
|
|
3516
|
+
* @param {Object} [settings={}] - Configuration object for the scroll animation.
|
|
3517
|
+
* @param {number} [settings.targetX] - The horizontal scroll target in pixels.
|
|
3518
|
+
* @param {number} [settings.targetY] - The vertical scroll target in pixels.
|
|
3519
|
+
* @param {number} [settings.duration] - The duration of the animation in milliseconds.
|
|
3520
|
+
* @param {Easings} [settings.easing] - The easing function name to use for the scroll animation.
|
|
3521
|
+
* @param {OnScrollAnimation} [settings.onAnimation] - Optional callback invoked on each animation
|
|
3522
|
+
* frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag.
|
|
3523
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3524
|
+
*/
|
|
3525
|
+
scrollToXY({ targetX, targetY, duration, easing, onAnimation } = {}) {
|
|
3526
|
+
return TinyHtml.scrollToXY(this, { targetX, targetY, duration, easing, onAnimation });
|
|
3527
|
+
}
|
|
3528
|
+
|
|
3529
|
+
/**
|
|
3530
|
+
* Sets the vertical scroll position.
|
|
3531
|
+
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
3532
|
+
* @param {number} value - Scroll top value.
|
|
3533
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3534
|
+
*/
|
|
3535
|
+
static setScrollTop(el, value) {
|
|
3536
|
+
if (typeof value !== 'number') throw new TypeError('ScrollTop value must be a number.');
|
|
3537
|
+
return TinyHtml.scrollToXY(el, { targetY: value });
|
|
3115
3538
|
}
|
|
3116
3539
|
|
|
3117
3540
|
/**
|
|
3118
3541
|
* Sets the vertical scroll position.
|
|
3119
3542
|
* @param {number} value - Scroll top value.
|
|
3543
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3120
3544
|
*/
|
|
3121
3545
|
setScrollTop(value) {
|
|
3122
3546
|
return TinyHtml.setScrollTop(this, value);
|
|
@@ -3126,24 +3550,17 @@ class TinyHtml {
|
|
|
3126
3550
|
* Sets the horizontal scroll position.
|
|
3127
3551
|
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
3128
3552
|
* @param {number} value - Scroll left value.
|
|
3553
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3129
3554
|
*/
|
|
3130
3555
|
static setScrollLeft(el, value) {
|
|
3131
3556
|
if (typeof value !== 'number') throw new TypeError('ScrollLeft value must be a number.');
|
|
3132
|
-
TinyHtml.
|
|
3133
|
-
if (TinyHtml.isWindow(elem)) {
|
|
3134
|
-
elem.scrollTo(value, elem.pageYOffset);
|
|
3135
|
-
} else if (elem.nodeType === 9) {
|
|
3136
|
-
// @ts-ignore
|
|
3137
|
-
elem.defaultView.scrollTo(value, elem.defaultView.pageYOffset);
|
|
3138
|
-
} else {
|
|
3139
|
-
elem.scrollLeft = value;
|
|
3140
|
-
}
|
|
3141
|
-
});
|
|
3557
|
+
return TinyHtml.scrollToXY(el, { targetX: value });
|
|
3142
3558
|
}
|
|
3143
3559
|
|
|
3144
3560
|
/**
|
|
3145
3561
|
* Sets the horizontal scroll position.
|
|
3146
3562
|
* @param {number} value - Scroll left value.
|
|
3563
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3147
3564
|
*/
|
|
3148
3565
|
setScrollLeft(value) {
|
|
3149
3566
|
return TinyHtml.setScrollLeft(this, value);
|
|
@@ -3274,15 +3691,16 @@ class TinyHtml {
|
|
|
3274
3691
|
|
|
3275
3692
|
/**
|
|
3276
3693
|
* Adds one or more CSS class names to the element.
|
|
3277
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
3694
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
3278
3695
|
*/
|
|
3279
3696
|
static addClass(el, ...args) {
|
|
3280
3697
|
TinyHtml._preElems(el, 'addClass').forEach((elem) => elem.classList.add(...args));
|
|
3698
|
+
return el;
|
|
3281
3699
|
}
|
|
3282
3700
|
|
|
3283
3701
|
/**
|
|
3284
3702
|
* Adds one or more CSS class names to the element.
|
|
3285
|
-
* @type {(...tokens: string[]) =>
|
|
3703
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
3286
3704
|
*/
|
|
3287
3705
|
addClass(...args) {
|
|
3288
3706
|
return TinyHtml.addClass(this, ...args);
|
|
@@ -3290,15 +3708,16 @@ class TinyHtml {
|
|
|
3290
3708
|
|
|
3291
3709
|
/**
|
|
3292
3710
|
* Removes one or more CSS class names from the element.
|
|
3293
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
3711
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
3294
3712
|
*/
|
|
3295
3713
|
static removeClass(el, ...args) {
|
|
3296
3714
|
TinyHtml._preElems(el, 'removeClass').forEach((elem) => elem.classList.remove(...args));
|
|
3715
|
+
return el;
|
|
3297
3716
|
}
|
|
3298
3717
|
|
|
3299
3718
|
/**
|
|
3300
3719
|
* Removes one or more CSS class names from the element.
|
|
3301
|
-
* @type {(...tokens: string[]) =>
|
|
3720
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
3302
3721
|
*/
|
|
3303
3722
|
removeClass(...args) {
|
|
3304
3723
|
return TinyHtml.removeClass(this, ...args);
|
|
@@ -3508,15 +3927,18 @@ class TinyHtml {
|
|
|
3508
3927
|
* Set text content of elements.
|
|
3509
3928
|
* @param {TinyElement|TinyElement[]} el
|
|
3510
3929
|
* @param {string} value
|
|
3930
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3511
3931
|
*/
|
|
3512
3932
|
static setText(el, value) {
|
|
3513
3933
|
if (typeof value !== 'string') throw new Error('Value is not a valid string.');
|
|
3514
3934
|
TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = value));
|
|
3935
|
+
return el;
|
|
3515
3936
|
}
|
|
3516
3937
|
|
|
3517
3938
|
/**
|
|
3518
3939
|
* Set text content of the element.
|
|
3519
3940
|
* @param {string} value
|
|
3941
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3520
3942
|
*/
|
|
3521
3943
|
setText(value) {
|
|
3522
3944
|
return TinyHtml.setText(this, value);
|
|
@@ -3525,13 +3947,16 @@ class TinyHtml {
|
|
|
3525
3947
|
/**
|
|
3526
3948
|
* Remove all child nodes from each element.
|
|
3527
3949
|
* @param {TinyElement|TinyElement[]} el
|
|
3950
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3528
3951
|
*/
|
|
3529
3952
|
static empty(el) {
|
|
3530
3953
|
TinyHtml._preElems(el, 'empty').forEach((el) => (el.textContent = ''));
|
|
3954
|
+
return el;
|
|
3531
3955
|
}
|
|
3532
3956
|
|
|
3533
3957
|
/**
|
|
3534
3958
|
* Remove all child nodes of the element.
|
|
3959
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3535
3960
|
*/
|
|
3536
3961
|
empty() {
|
|
3537
3962
|
return TinyHtml.empty(this);
|
|
@@ -3539,35 +3964,40 @@ class TinyHtml {
|
|
|
3539
3964
|
|
|
3540
3965
|
/**
|
|
3541
3966
|
* Get the innerHTML of the element.
|
|
3542
|
-
* @param {TinyElement
|
|
3967
|
+
* @param {TinyElement} el
|
|
3968
|
+
* @param {GetHTMLOptions} [ops]
|
|
3543
3969
|
* @returns {string}
|
|
3544
3970
|
*/
|
|
3545
|
-
static html(el) {
|
|
3971
|
+
static html(el, ops) {
|
|
3546
3972
|
const elem = TinyHtml._preElem(el, 'html');
|
|
3547
|
-
return elem.
|
|
3973
|
+
return elem.getHTML(ops);
|
|
3548
3974
|
}
|
|
3549
3975
|
|
|
3550
3976
|
/**
|
|
3551
3977
|
* Get the innerHTML of the element.
|
|
3978
|
+
* @param {GetHTMLOptions} [ops]
|
|
3552
3979
|
* @returns {string}
|
|
3553
3980
|
*/
|
|
3554
|
-
html() {
|
|
3555
|
-
return TinyHtml.html(this);
|
|
3981
|
+
html(ops) {
|
|
3982
|
+
return TinyHtml.html(this, ops);
|
|
3556
3983
|
}
|
|
3557
3984
|
|
|
3558
3985
|
/**
|
|
3559
3986
|
* Set the innerHTML of each element.
|
|
3560
3987
|
* @param {TinyElement|TinyElement[]} el
|
|
3561
3988
|
* @param {string} value
|
|
3989
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3562
3990
|
*/
|
|
3563
3991
|
static setHtml(el, value) {
|
|
3564
3992
|
if (typeof value !== 'string') throw new Error('Value is not a valid string.');
|
|
3565
3993
|
TinyHtml._preElems(el, 'setHtml').forEach((el) => (el.innerHTML = value));
|
|
3994
|
+
return el;
|
|
3566
3995
|
}
|
|
3567
3996
|
|
|
3568
3997
|
/**
|
|
3569
3998
|
* Set the innerHTML of the element.
|
|
3570
3999
|
* @param {string} value
|
|
4000
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3571
4001
|
*/
|
|
3572
4002
|
setHtml(value) {
|
|
3573
4003
|
return TinyHtml.setHtml(this, value);
|
|
@@ -3701,6 +4131,7 @@ class TinyHtml {
|
|
|
3701
4131
|
* @param {TinyInputElement|TinyInputElement[]} el - Target element.
|
|
3702
4132
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
3703
4133
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
4134
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
3704
4135
|
*/
|
|
3705
4136
|
static setVal(el, value) {
|
|
3706
4137
|
TinyHtml._preInputElems(el, 'setVal').forEach((elem) => {
|
|
@@ -3740,6 +4171,7 @@ class TinyHtml {
|
|
|
3740
4171
|
if (typeof valToSet === 'string') elem.value = valToSet;
|
|
3741
4172
|
}
|
|
3742
4173
|
});
|
|
4174
|
+
return el;
|
|
3743
4175
|
}
|
|
3744
4176
|
|
|
3745
4177
|
/**
|
|
@@ -3747,6 +4179,7 @@ class TinyHtml {
|
|
|
3747
4179
|
* Accepts strings, numbers, booleans or arrays of these values, or a callback function that computes them.
|
|
3748
4180
|
*
|
|
3749
4181
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
4182
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
3750
4183
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
3751
4184
|
*/
|
|
3752
4185
|
setVal(value) {
|
|
@@ -4016,6 +4449,7 @@ class TinyHtml {
|
|
|
4016
4449
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
4017
4450
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
4018
4451
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
4452
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4019
4453
|
*/
|
|
4020
4454
|
static on(el, event, handler, options) {
|
|
4021
4455
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -4028,6 +4462,7 @@ class TinyHtml {
|
|
|
4028
4462
|
if (!Array.isArray(events[event])) events[event] = [];
|
|
4029
4463
|
events[event].push({ handler, options });
|
|
4030
4464
|
});
|
|
4465
|
+
return el;
|
|
4031
4466
|
}
|
|
4032
4467
|
|
|
4033
4468
|
/**
|
|
@@ -4036,6 +4471,7 @@ class TinyHtml {
|
|
|
4036
4471
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
4037
4472
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
4038
4473
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
4474
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4039
4475
|
*/
|
|
4040
4476
|
on(event, handler, options) {
|
|
4041
4477
|
return TinyHtml.on(this, event, handler, options);
|
|
@@ -4048,6 +4484,7 @@ class TinyHtml {
|
|
|
4048
4484
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
4049
4485
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
4050
4486
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
4487
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4051
4488
|
*/
|
|
4052
4489
|
static once(el, event, handler, options = {}) {
|
|
4053
4490
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -4065,6 +4502,7 @@ class TinyHtml {
|
|
|
4065
4502
|
typeof options === 'boolean' ? options : { ...options, once: true },
|
|
4066
4503
|
);
|
|
4067
4504
|
});
|
|
4505
|
+
return el;
|
|
4068
4506
|
}
|
|
4069
4507
|
|
|
4070
4508
|
/**
|
|
@@ -4073,6 +4511,7 @@ class TinyHtml {
|
|
|
4073
4511
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
4074
4512
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
4075
4513
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
4514
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4076
4515
|
*/
|
|
4077
4516
|
once(event, handler, options = {}) {
|
|
4078
4517
|
return TinyHtml.once(this, event, handler, options);
|
|
@@ -4085,6 +4524,7 @@ class TinyHtml {
|
|
|
4085
4524
|
* @param {string} event - The event type.
|
|
4086
4525
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
4087
4526
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
4527
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4088
4528
|
*/
|
|
4089
4529
|
static off(el, event, handler, options) {
|
|
4090
4530
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -4097,6 +4537,7 @@ class TinyHtml {
|
|
|
4097
4537
|
if (events[event].length === 0) delete events[event];
|
|
4098
4538
|
}
|
|
4099
4539
|
});
|
|
4540
|
+
return el;
|
|
4100
4541
|
}
|
|
4101
4542
|
|
|
4102
4543
|
/**
|
|
@@ -4105,6 +4546,7 @@ class TinyHtml {
|
|
|
4105
4546
|
* @param {string} event - The event type.
|
|
4106
4547
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
4107
4548
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
4549
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4108
4550
|
*/
|
|
4109
4551
|
off(event, handler, options) {
|
|
4110
4552
|
return TinyHtml.off(this, event, handler, options);
|
|
@@ -4115,6 +4557,7 @@ class TinyHtml {
|
|
|
4115
4557
|
*
|
|
4116
4558
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
4117
4559
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
4560
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4118
4561
|
*/
|
|
4119
4562
|
static offAll(el, event) {
|
|
4120
4563
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -4127,12 +4570,14 @@ class TinyHtml {
|
|
|
4127
4570
|
delete events[event];
|
|
4128
4571
|
}
|
|
4129
4572
|
});
|
|
4573
|
+
return el;
|
|
4130
4574
|
}
|
|
4131
4575
|
|
|
4132
4576
|
/**
|
|
4133
4577
|
* Removes all event listeners of a specific type from the element.
|
|
4134
4578
|
*
|
|
4135
4579
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
4580
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4136
4581
|
*/
|
|
4137
4582
|
offAll(event) {
|
|
4138
4583
|
return TinyHtml.offAll(this, event);
|
|
@@ -4144,6 +4589,7 @@ class TinyHtml {
|
|
|
4144
4589
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
4145
4590
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
4146
4591
|
* Optional filter function to selectively remove specific handlers.
|
|
4592
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4147
4593
|
*/
|
|
4148
4594
|
static offAllTypes(el, filterFn = null) {
|
|
4149
4595
|
if (filterFn !== null && typeof filterFn !== 'function')
|
|
@@ -4162,6 +4608,7 @@ class TinyHtml {
|
|
|
4162
4608
|
|
|
4163
4609
|
__eventRegistry.delete(elem);
|
|
4164
4610
|
});
|
|
4611
|
+
return el;
|
|
4165
4612
|
}
|
|
4166
4613
|
|
|
4167
4614
|
/**
|
|
@@ -4169,6 +4616,7 @@ class TinyHtml {
|
|
|
4169
4616
|
*
|
|
4170
4617
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
4171
4618
|
* Optional filter function to selectively remove specific handlers.
|
|
4619
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4172
4620
|
*/
|
|
4173
4621
|
offAllTypes(filterFn = null) {
|
|
4174
4622
|
return TinyHtml.offAllTypes(this, filterFn);
|
|
@@ -4180,6 +4628,7 @@ class TinyHtml {
|
|
|
4180
4628
|
* @param {TinyEventTarget|TinyEventTarget[]} el - Target element where the event should be triggered.
|
|
4181
4629
|
* @param {string} event - Name of the event to trigger.
|
|
4182
4630
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
4631
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4183
4632
|
*/
|
|
4184
4633
|
static trigger(el, event, payload = {}) {
|
|
4185
4634
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -4195,6 +4644,7 @@ class TinyHtml {
|
|
|
4195
4644
|
|
|
4196
4645
|
elem.dispatchEvent(evt);
|
|
4197
4646
|
});
|
|
4647
|
+
return el;
|
|
4198
4648
|
}
|
|
4199
4649
|
|
|
4200
4650
|
/**
|
|
@@ -4202,6 +4652,7 @@ class TinyHtml {
|
|
|
4202
4652
|
*
|
|
4203
4653
|
* @param {string} event - Name of the event to trigger.
|
|
4204
4654
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
4655
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
4205
4656
|
*/
|
|
4206
4657
|
trigger(event, payload = {}) {
|
|
4207
4658
|
return TinyHtml.trigger(this, event, payload);
|
|
@@ -4244,6 +4695,7 @@ class TinyHtml {
|
|
|
4244
4695
|
* @param {TinyElement|TinyElement[]} el
|
|
4245
4696
|
* @param {string} name
|
|
4246
4697
|
* @param {string|null} [value=null]
|
|
4698
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4247
4699
|
*/
|
|
4248
4700
|
static setAttr(el, name, value = null) {
|
|
4249
4701
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -4253,12 +4705,14 @@ class TinyHtml {
|
|
|
4253
4705
|
if (value === null) elem.removeAttribute(name);
|
|
4254
4706
|
else elem.setAttribute(name, value);
|
|
4255
4707
|
});
|
|
4708
|
+
return el;
|
|
4256
4709
|
}
|
|
4257
4710
|
|
|
4258
4711
|
/**
|
|
4259
4712
|
* Set an attribute on an element.
|
|
4260
4713
|
* @param {string} name
|
|
4261
4714
|
* @param {string|null} [value=null]
|
|
4715
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4262
4716
|
*/
|
|
4263
4717
|
setAttr(name, value) {
|
|
4264
4718
|
return TinyHtml.setAttr(this, name, value);
|
|
@@ -4268,15 +4722,18 @@ class TinyHtml {
|
|
|
4268
4722
|
* Remove attribute(s) from an element.
|
|
4269
4723
|
* @param {TinyElement|TinyElement[]} el
|
|
4270
4724
|
* @param {string} name Space-separated list of attributes.
|
|
4725
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4271
4726
|
*/
|
|
4272
4727
|
static removeAttr(el, name) {
|
|
4273
4728
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
4274
4729
|
TinyHtml._preElems(el, 'removeAttr').forEach((elem) => elem.removeAttribute(name));
|
|
4730
|
+
return el;
|
|
4275
4731
|
}
|
|
4276
4732
|
|
|
4277
4733
|
/**
|
|
4278
4734
|
* Remove attribute(s) from an element.
|
|
4279
4735
|
* @param {string} name Space-separated list of attributes.
|
|
4736
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4280
4737
|
*/
|
|
4281
4738
|
removeAttr(name) {
|
|
4282
4739
|
return TinyHtml.removeAttr(this, name);
|
|
@@ -4331,6 +4788,7 @@ class TinyHtml {
|
|
|
4331
4788
|
* Set a property on an element.
|
|
4332
4789
|
* @param {TinyElement|TinyElement[]} el
|
|
4333
4790
|
* @param {string} name
|
|
4791
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4334
4792
|
*/
|
|
4335
4793
|
static addProp(el, name) {
|
|
4336
4794
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -4340,11 +4798,13 @@ class TinyHtml {
|
|
|
4340
4798
|
// @ts-ignore
|
|
4341
4799
|
elem[name] = true;
|
|
4342
4800
|
});
|
|
4801
|
+
return el;
|
|
4343
4802
|
}
|
|
4344
4803
|
|
|
4345
4804
|
/**
|
|
4346
4805
|
* Set a property on an element.
|
|
4347
4806
|
* @param {string} name
|
|
4807
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4348
4808
|
*/
|
|
4349
4809
|
addProp(name) {
|
|
4350
4810
|
return TinyHtml.addProp(this, name);
|
|
@@ -4354,6 +4814,7 @@ class TinyHtml {
|
|
|
4354
4814
|
* Remove a property from an element.
|
|
4355
4815
|
* @param {TinyElement|TinyElement[]} el
|
|
4356
4816
|
* @param {string} name
|
|
4817
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4357
4818
|
*/
|
|
4358
4819
|
static removeProp(el, name) {
|
|
4359
4820
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -4363,11 +4824,13 @@ class TinyHtml {
|
|
|
4363
4824
|
// @ts-ignore
|
|
4364
4825
|
elem[name] = false;
|
|
4365
4826
|
});
|
|
4827
|
+
return el;
|
|
4366
4828
|
}
|
|
4367
4829
|
|
|
4368
4830
|
/**
|
|
4369
4831
|
* Remove a property from an element.
|
|
4370
4832
|
* @param {string} name
|
|
4833
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4371
4834
|
*/
|
|
4372
4835
|
removeProp(name) {
|
|
4373
4836
|
return TinyHtml.removeProp(this, name);
|
|
@@ -4408,13 +4871,16 @@ class TinyHtml {
|
|
|
4408
4871
|
/**
|
|
4409
4872
|
* Removes an element from the DOM.
|
|
4410
4873
|
* @param {TinyElement|TinyElement[]} el - The DOM element or selector to remove.
|
|
4874
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4411
4875
|
*/
|
|
4412
4876
|
static remove(el) {
|
|
4413
4877
|
TinyHtml._preElems(el, 'remove').forEach((elem) => elem.remove());
|
|
4878
|
+
return el;
|
|
4414
4879
|
}
|
|
4415
4880
|
|
|
4416
4881
|
/**
|
|
4417
4882
|
* Removes the element from the DOM.
|
|
4883
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4418
4884
|
*/
|
|
4419
4885
|
remove() {
|
|
4420
4886
|
return TinyHtml.remove(this);
|
|
@@ -4758,6 +5224,14 @@ class TinyHtml {
|
|
|
4758
5224
|
*/
|
|
4759
5225
|
static isInViewport(el) {
|
|
4760
5226
|
const elem = TinyHtml._preElem(el, 'isInViewport');
|
|
5227
|
+
if (
|
|
5228
|
+
!elem.checkVisibility({
|
|
5229
|
+
contentVisibilityAuto: false,
|
|
5230
|
+
opacityProperty: false,
|
|
5231
|
+
visibilityProperty: false,
|
|
5232
|
+
})
|
|
5233
|
+
)
|
|
5234
|
+
return false;
|
|
4761
5235
|
const elementTop = TinyHtml.offset(elem).top;
|
|
4762
5236
|
const elementBottom = elementTop + TinyHtml.outerHeight(elem);
|
|
4763
5237
|
|
|
@@ -4784,6 +5258,14 @@ class TinyHtml {
|
|
|
4784
5258
|
*/
|
|
4785
5259
|
static isScrolledIntoView(el) {
|
|
4786
5260
|
const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
5261
|
+
if (
|
|
5262
|
+
!elem.checkVisibility({
|
|
5263
|
+
contentVisibilityAuto: false,
|
|
5264
|
+
opacityProperty: false,
|
|
5265
|
+
visibilityProperty: false,
|
|
5266
|
+
})
|
|
5267
|
+
)
|
|
5268
|
+
return false;
|
|
4787
5269
|
const docViewTop = TinyHtml.scrollTop(window);
|
|
4788
5270
|
const docViewBottom = docViewTop + TinyHtml.height(window);
|
|
4789
5271
|
|
|
@@ -4801,6 +5283,111 @@ class TinyHtml {
|
|
|
4801
5283
|
isScrolledIntoView() {
|
|
4802
5284
|
return TinyHtml.isScrolledIntoView(this);
|
|
4803
5285
|
}
|
|
5286
|
+
|
|
5287
|
+
/**
|
|
5288
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
5289
|
+
*
|
|
5290
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
5291
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
5292
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
5293
|
+
*/
|
|
5294
|
+
static isInContainer(el, cont) {
|
|
5295
|
+
const elem = TinyHtml._preElem(el, 'isInContainer');
|
|
5296
|
+
const container = TinyHtml._preElem(cont, 'isInContainer');
|
|
5297
|
+
|
|
5298
|
+
if (
|
|
5299
|
+
!elem.checkVisibility({
|
|
5300
|
+
contentVisibilityAuto: false,
|
|
5301
|
+
opacityProperty: false,
|
|
5302
|
+
visibilityProperty: false,
|
|
5303
|
+
})
|
|
5304
|
+
)
|
|
5305
|
+
return false;
|
|
5306
|
+
const elemRect = elem.getBoundingClientRect();
|
|
5307
|
+
const containerRect = container.getBoundingClientRect();
|
|
5308
|
+
|
|
5309
|
+
const verticallyVisible =
|
|
5310
|
+
elemRect.bottom > containerRect.top && elemRect.top < containerRect.bottom;
|
|
5311
|
+
|
|
5312
|
+
const horizontallyVisible =
|
|
5313
|
+
elemRect.right > containerRect.left && elemRect.left < containerRect.right;
|
|
5314
|
+
|
|
5315
|
+
return verticallyVisible && horizontallyVisible;
|
|
5316
|
+
}
|
|
5317
|
+
|
|
5318
|
+
/**
|
|
5319
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
5320
|
+
*
|
|
5321
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
5322
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
5323
|
+
*/
|
|
5324
|
+
isInContainer(cont) {
|
|
5325
|
+
return TinyHtml.isInContainer(this, cont);
|
|
5326
|
+
}
|
|
5327
|
+
|
|
5328
|
+
/**
|
|
5329
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
5330
|
+
*
|
|
5331
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
5332
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
5333
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
5334
|
+
*/
|
|
5335
|
+
static isFullyInContainer(el, cont) {
|
|
5336
|
+
const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
5337
|
+
const container = TinyHtml._preElem(cont, 'isInContainer');
|
|
5338
|
+
|
|
5339
|
+
if (
|
|
5340
|
+
!elem.checkVisibility({
|
|
5341
|
+
contentVisibilityAuto: false,
|
|
5342
|
+
opacityProperty: false,
|
|
5343
|
+
visibilityProperty: false,
|
|
5344
|
+
})
|
|
5345
|
+
)
|
|
5346
|
+
return false;
|
|
5347
|
+
const elemRect = elem.getBoundingClientRect();
|
|
5348
|
+
const containerRect = container.getBoundingClientRect();
|
|
5349
|
+
|
|
5350
|
+
const isFullyVisible =
|
|
5351
|
+
elemRect.top >= containerRect.top &&
|
|
5352
|
+
elemRect.bottom <= containerRect.bottom &&
|
|
5353
|
+
elemRect.left >= containerRect.left &&
|
|
5354
|
+
elemRect.right <= containerRect.right;
|
|
5355
|
+
|
|
5356
|
+
return isFullyVisible;
|
|
5357
|
+
}
|
|
5358
|
+
|
|
5359
|
+
/**
|
|
5360
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
5361
|
+
*
|
|
5362
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
5363
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
5364
|
+
*/
|
|
5365
|
+
isFullyInContainer(cont) {
|
|
5366
|
+
return TinyHtml.isFullyInContainer(this, cont);
|
|
5367
|
+
}
|
|
5368
|
+
|
|
5369
|
+
/**
|
|
5370
|
+
* Checks if an element has scrollable content.
|
|
5371
|
+
*
|
|
5372
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
5373
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
5374
|
+
*/
|
|
5375
|
+
static hasScroll(el) {
|
|
5376
|
+
const elem = TinyHtml._preElem(el, 'hasScroll');
|
|
5377
|
+
return {
|
|
5378
|
+
v: elem.scrollHeight > elem.clientHeight,
|
|
5379
|
+
h: elem.scrollWidth > elem.clientWidth,
|
|
5380
|
+
};
|
|
5381
|
+
}
|
|
5382
|
+
|
|
5383
|
+
/**
|
|
5384
|
+
* Checks if an element has scrollable content.
|
|
5385
|
+
*
|
|
5386
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
5387
|
+
*/
|
|
5388
|
+
hasScroll() {
|
|
5389
|
+
return TinyHtml.hasScroll(this);
|
|
5390
|
+
}
|
|
4804
5391
|
}
|
|
4805
5392
|
|
|
4806
5393
|
/* harmony default export */ const libs_TinyHtml = (TinyHtml);
|