@xmldom/xmldom 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.9.2](https://github.com/xmldom/xmldom/compare/0.9.1...0.9.2)
8
+
9
+ ### Feature
10
+
11
+ - add `Element.getElementsByClassName` [`#722`](https://github.com/xmldom/xmldom/pull/722)
12
+
13
+ ### Fixed
14
+
15
+ - add missing types for `Document.documentElement` and `Element.tagName` [`#721`](https://github.com/xmldom/xmldom/pull/721) [`#720`](https://github.com/xmldom/xmldom/issues/720)
16
+
17
+ Thank you, [@censujiang](https://github.com/censujiang), [@Mathias-S](https://github.com/Mathias-S), for your contributions
18
+
19
+
7
20
  ## [0.9.1](https://github.com/xmldom/xmldom/compare/0.9.0...0.9.1)
8
21
 
9
22
  ### Fixed
@@ -16,8 +29,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
16
29
 
17
30
  - minimum tested node version is 14 [`#710`](https://github.com/xmldom/xmldom/pull/710)
18
31
 
19
- Thank you, [@krystofwoldrich](https://github.com/krystofwoldrich), [@marvinruder](https://github.com/marvinruder),
20
- [@amacneil](https://github.com/amacneil), [@defunctzombie](https://github.com/defunctzombie),
32
+ Thank you, [@krystofwoldrich](https://github.com/krystofwoldrich), [@marvinruder](https://github.com/marvinruder), [@amacneil](https://github.com/amacneil), [@defunctzombie](https://github.com/defunctzombie),
21
33
  [@tjhorner](https://github.com/tjhorner), [@danon](https://github.com/danon), for your contributions
22
34
 
23
35
 
package/index.d.ts CHANGED
@@ -770,6 +770,13 @@ declare module '@xmldom/xmldom' {
770
770
 
771
771
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/attributes) */
772
772
  readonly attributes: NamedNodeMap;
773
+ /**
774
+ * Returns the HTML-uppercased qualified name.
775
+ *
776
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/tagName)
777
+ */
778
+ readonly tagName: string;
779
+
773
780
  /**
774
781
  * Returns element's first attribute whose qualified name is qualifiedName, and null if there
775
782
  * is no such attribute otherwise.
@@ -797,7 +804,22 @@ declare module '@xmldom/xmldom' {
797
804
  namespace: string | null,
798
805
  localName: string
799
806
  ): Attr | null;
800
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/getBoundingClientRect) */
807
+ /**
808
+ * Returns a LiveNodeList of all child elements which have **all** of the given class
809
+ * name(s).
810
+ *
811
+ * Returns an empty list if `classNames` is an empty string or only contains HTML white space
812
+ * characters.
813
+ *
814
+ * Warning: This returns a live LiveNodeList.
815
+ * Changes in the DOM will reflect in the array as the changes occur.
816
+ * If an element selected by this array no longer qualifies for the selector,
817
+ * it will automatically be removed. Be aware of this for iteration purposes.
818
+ *
819
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByClassName
820
+ * @see https://dom.spec.whatwg.org/#concept-getelementsbyclassname
821
+ */
822
+ getElementsByClassName(classNames: string): LiveNodeList;
801
823
 
802
824
  /**
803
825
  * Returns a LiveNodeList of elements with the given qualifiedName.
@@ -1067,6 +1089,12 @@ declare module '@xmldom/xmldom' {
1067
1089
  readonly nodeName: '#document';
1068
1090
  readonly nodeType: typeof Node.DOCUMENT_NODE;
1069
1091
  readonly doctype: DocumentType | null;
1092
+ /**
1093
+ * Gets a reference to the root node of the document.
1094
+ *
1095
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/documentElement)
1096
+ */
1097
+ readonly documentElement: Element | null;
1070
1098
 
1071
1099
  /**
1072
1100
  * Creates an attribute object with a specified name.
@@ -1105,7 +1133,6 @@ declare module '@xmldom/xmldom' {
1105
1133
  */
1106
1134
  createDocumentFragment(): DocumentFragment;
1107
1135
 
1108
-
1109
1136
  createElement(tagName: string): Element;
1110
1137
 
1111
1138
  /**
@@ -1128,10 +1155,7 @@ declare module '@xmldom/xmldom' {
1128
1155
  *
1129
1156
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/createElementNS)
1130
1157
  */
1131
- createElementNS(
1132
- namespace: string | null,
1133
- qualifiedName: string,
1134
- ): Element;
1158
+ createElementNS(namespace: string | null, qualifiedName: string): Element;
1135
1159
 
1136
1160
  /**
1137
1161
  * Returns a ProcessingInstruction node whose target is target and data is data. If target does
@@ -1165,20 +1189,17 @@ declare module '@xmldom/xmldom' {
1165
1189
  getElementById(elementId: string): Element | null;
1166
1190
 
1167
1191
  /**
1168
- * The `getElementsByClassName` method of `Document` interface returns an array-like object
1169
- * of all child elements which have **all** of the given class name(s).
1192
+ * Returns a LiveNodeList of all child elements which have **all** of the given class
1193
+ * name(s).
1170
1194
  *
1171
- * Returns an empty list if `classeNames` is an empty string or only contains HTML white
1172
- * space characters.
1195
+ * Returns an empty list if `classNames` is an empty string or only contains HTML white space
1196
+ * characters.
1173
1197
  *
1174
- * Warning: This is a live LiveNodeList.
1198
+ * Warning: This returns a live LiveNodeList.
1175
1199
  * Changes in the DOM will reflect in the array as the changes occur.
1176
1200
  * If an element selected by this array no longer qualifies for the selector,
1177
1201
  * it will automatically be removed. Be aware of this for iteration purposes.
1178
1202
  *
1179
- * @param {string} classNames
1180
- * Is a string representing the class name(s) to match; multiple class names are separated by
1181
- * (ASCII-)whitespace.
1182
1203
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName
1183
1204
  * @see https://dom.spec.whatwg.org/#concept-getelementsbyclassname
1184
1205
  */
package/lib/dom.js CHANGED
@@ -2003,51 +2003,6 @@ Document.prototype = {
2003
2003
  return rtv;
2004
2004
  },
2005
2005
 
2006
- /**
2007
- * The `getElementsByClassName` method of `Document` interface returns an array-like object of
2008
- * all child elements which have **all** of the given class name(s).
2009
- *
2010
- * Returns an empty list if `classeNames` is an empty string or only contains HTML white space
2011
- * characters.
2012
- *
2013
- * Warning: This is a live LiveNodeList.
2014
- * Changes in the DOM will reflect in the array as the changes occur.
2015
- * If an element selected by this array no longer qualifies for the selector,
2016
- * it will automatically be removed. Be aware of this for iteration purposes.
2017
- *
2018
- * @param {string} classNames
2019
- * Is a string representing the class name(s) to match; multiple class names are separated by
2020
- * (ASCII-)whitespace.
2021
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName
2022
- * @see https://dom.spec.whatwg.org/#concept-getelementsbyclassname
2023
- */
2024
- getElementsByClassName: function (classNames) {
2025
- var classNamesSet = toOrderedSet(classNames);
2026
- return new LiveNodeList(this, function (base) {
2027
- var ls = [];
2028
- if (classNamesSet.length > 0) {
2029
- _visitNode(base.documentElement, function (node) {
2030
- if (node !== base && node.nodeType === ELEMENT_NODE) {
2031
- var nodeClassNames = node.getAttribute('class');
2032
- // can be null if the attribute does not exist
2033
- if (nodeClassNames) {
2034
- // before splitting and iterating just compare them for the most common case
2035
- var matches = classNames === nodeClassNames;
2036
- if (!matches) {
2037
- var nodeClassNamesSet = toOrderedSet(nodeClassNames);
2038
- matches = classNamesSet.every(arrayIncludes(nodeClassNamesSet));
2039
- }
2040
- if (matches) {
2041
- ls.push(node);
2042
- }
2043
- }
2044
- }
2045
- });
2046
- }
2047
- return ls;
2048
- });
2049
- },
2050
-
2051
2006
  /**
2052
2007
  * Creates a new `Element` that is owned by this `Document`.
2053
2008
  * In HTML Documents `localName` is the lower cased `tagName`,
@@ -2302,6 +2257,51 @@ Element.prototype = {
2302
2257
  return this.attributes.getNamedItemNS(namespaceURI, localName);
2303
2258
  },
2304
2259
 
2260
+ /**
2261
+ * Returns a LiveNodeList of all child elements which have **all** of the given class name(s).
2262
+ *
2263
+ * Returns an empty list if `classNames` is an empty string or only contains HTML white space
2264
+ * characters.
2265
+ *
2266
+ * Warning: This returns a live LiveNodeList.
2267
+ * Changes in the DOM will reflect in the array as the changes occur.
2268
+ * If an element selected by this array no longer qualifies for the selector,
2269
+ * it will automatically be removed. Be aware of this for iteration purposes.
2270
+ *
2271
+ * @param {string} classNames
2272
+ * Is a string representing the class name(s) to match; multiple class names are separated by
2273
+ * (ASCII-)whitespace.
2274
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByClassName
2275
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName
2276
+ * @see https://dom.spec.whatwg.org/#concept-getelementsbyclassname
2277
+ */
2278
+ getElementsByClassName: function (classNames) {
2279
+ var classNamesSet = toOrderedSet(classNames);
2280
+ return new LiveNodeList(this, function (base) {
2281
+ var ls = [];
2282
+ if (classNamesSet.length > 0) {
2283
+ _visitNode(base, function (node) {
2284
+ if (node !== base && node.nodeType === ELEMENT_NODE) {
2285
+ var nodeClassNames = node.getAttribute('class');
2286
+ // can be null if the attribute does not exist
2287
+ if (nodeClassNames) {
2288
+ // before splitting and iterating just compare them for the most common case
2289
+ var matches = classNames === nodeClassNames;
2290
+ if (!matches) {
2291
+ var nodeClassNamesSet = toOrderedSet(nodeClassNames);
2292
+ matches = classNamesSet.every(arrayIncludes(nodeClassNamesSet));
2293
+ }
2294
+ if (matches) {
2295
+ ls.push(node);
2296
+ }
2297
+ }
2298
+ }
2299
+ });
2300
+ }
2301
+ return ls;
2302
+ });
2303
+ },
2304
+
2305
2305
  /**
2306
2306
  * Returns a LiveNodeList of elements with the given qualifiedName.
2307
2307
  * Searching for all descendants can be done by passing `*` as `qualifiedName`.
@@ -2365,6 +2365,7 @@ Element.prototype = {
2365
2365
  });
2366
2366
  },
2367
2367
  };
2368
+ Document.prototype.getElementsByClassName = Element.prototype.getElementsByClassName;
2368
2369
  Document.prototype.getElementsByTagName = Element.prototype.getElementsByTagName;
2369
2370
  Document.prototype.getElementsByTagNameNS = Element.prototype.getElementsByTagNameNS;
2370
2371
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmldom/xmldom",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.",
5
5
  "keywords": [
6
6
  "w3c",