@xmldom/xmldom 0.9.8 → 0.9.10
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 +234 -70
- package/index.d.ts +186 -17
- package/lib/dom.js +757 -338
- package/lib/grammar.js +14 -0
- package/package.json +15 -11
- package/readme.md +7 -0
package/index.d.ts
CHANGED
|
@@ -448,7 +448,19 @@ declare module '@xmldom/xmldom' {
|
|
|
448
448
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/previousSibling)
|
|
449
449
|
*/
|
|
450
450
|
readonly previousSibling: Node | null;
|
|
451
|
-
/**
|
|
451
|
+
/**
|
|
452
|
+
* The text content of this node and its descendants.
|
|
453
|
+
*
|
|
454
|
+
* For {@link Element} and {@link DocumentFragment} nodes, returns the concatenation of the
|
|
455
|
+
* `nodeValue` of every descendant text node, excluding processing instruction and comment
|
|
456
|
+
* nodes. For all other node types, returns `nodeValue`.
|
|
457
|
+
*
|
|
458
|
+
* Setting `textContent` on an element or document fragment replaces all child nodes with a
|
|
459
|
+
* single text node; on other nodes it sets `data`, `value`, and `nodeValue` directly.
|
|
460
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Node/textContent)
|
|
461
|
+
*
|
|
462
|
+
* @see {@link https://dom.spec.whatwg.org/#dom-node-textcontent}
|
|
463
|
+
*/
|
|
452
464
|
textContent: string | null;
|
|
453
465
|
|
|
454
466
|
/**
|
|
@@ -488,7 +500,12 @@ declare module '@xmldom/xmldom' {
|
|
|
488
500
|
/**
|
|
489
501
|
* Checks whether the given node is equal to this node.
|
|
490
502
|
*
|
|
491
|
-
*
|
|
503
|
+
* Two nodes are equal when they have the same type, defining characteristics (for the type),
|
|
504
|
+
* and the same `childNodes`. The comparison is iterative to avoid stack overflows on deeply
|
|
505
|
+
* nested trees. `Attribute` nodes of each `Element` pair are also compared iteratively.
|
|
506
|
+
*
|
|
507
|
+
* @see {@link https://dom.spec.whatwg.org/#concept-node-equals}
|
|
508
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/isEqualNode}
|
|
492
509
|
*/
|
|
493
510
|
isEqualNode(other: Node): boolean;
|
|
494
511
|
|
|
@@ -771,8 +788,11 @@ declare module '@xmldom/xmldom' {
|
|
|
771
788
|
item(index: number): T | null;
|
|
772
789
|
/**
|
|
773
790
|
* Returns a string representation of the NodeList.
|
|
791
|
+
* Accepts the same options as `XMLSerializer.prototype.serializeToString`.
|
|
774
792
|
*/
|
|
775
|
-
toString(
|
|
793
|
+
toString(
|
|
794
|
+
options?: XMLSerializerOptions | ((node: T) => T | undefined)
|
|
795
|
+
): string;
|
|
776
796
|
/**
|
|
777
797
|
* Filters the NodeList based on a predicate.
|
|
778
798
|
*
|
|
@@ -827,6 +847,15 @@ declare module '@xmldom/xmldom' {
|
|
|
827
847
|
*/
|
|
828
848
|
readonly tagName: string;
|
|
829
849
|
|
|
850
|
+
/**
|
|
851
|
+
* Returns a live collection of the direct child elements of this element.
|
|
852
|
+
*
|
|
853
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/children)
|
|
854
|
+
*
|
|
855
|
+
* @see https://dom.spec.whatwg.org/#dom-parentnode-children
|
|
856
|
+
*/
|
|
857
|
+
readonly children: LiveNodeList<Element>;
|
|
858
|
+
|
|
830
859
|
/**
|
|
831
860
|
* Returns element's first attribute whose qualified name is qualifiedName, and null if there
|
|
832
861
|
* is no such attribute otherwise.
|
|
@@ -1085,6 +1114,16 @@ declare module '@xmldom/xmldom' {
|
|
|
1085
1114
|
*/
|
|
1086
1115
|
interface DocumentFragment extends Node {
|
|
1087
1116
|
readonly ownerDocument: Document;
|
|
1117
|
+
|
|
1118
|
+
/**
|
|
1119
|
+
* Returns a live collection of the direct child elements of this document fragment.
|
|
1120
|
+
*
|
|
1121
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/DocumentFragment/children)
|
|
1122
|
+
*
|
|
1123
|
+
* @see https://dom.spec.whatwg.org/#dom-parentnode-children
|
|
1124
|
+
*/
|
|
1125
|
+
readonly children: LiveNodeList<Element>;
|
|
1126
|
+
|
|
1088
1127
|
getElementById(elementId: string): Element | null;
|
|
1089
1128
|
}
|
|
1090
1129
|
var DocumentFragment: InstanceOf<DocumentFragment>;
|
|
@@ -1152,6 +1191,15 @@ declare module '@xmldom/xmldom' {
|
|
|
1152
1191
|
*/
|
|
1153
1192
|
readonly documentElement: Element | null;
|
|
1154
1193
|
|
|
1194
|
+
/**
|
|
1195
|
+
* Returns a live collection of the direct child elements of this document.
|
|
1196
|
+
*
|
|
1197
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/children)
|
|
1198
|
+
*
|
|
1199
|
+
* @see https://dom.spec.whatwg.org/#dom-parentnode-children
|
|
1200
|
+
*/
|
|
1201
|
+
readonly children: LiveNodeList<Element>;
|
|
1202
|
+
|
|
1155
1203
|
/**
|
|
1156
1204
|
* Creates an attribute object with a specified name.
|
|
1157
1205
|
*
|
|
@@ -1163,15 +1211,26 @@ declare module '@xmldom/xmldom' {
|
|
|
1163
1211
|
createAttributeNS(namespace: string | null, qualifiedName: string): Attr;
|
|
1164
1212
|
|
|
1165
1213
|
/**
|
|
1166
|
-
* Returns a CDATASection node whose data is data
|
|
1214
|
+
* Returns a new CDATASection node whose data is `data`.
|
|
1167
1215
|
*
|
|
1168
|
-
*
|
|
1216
|
+
* __This implementation differs from the specification:__ - calling this method on an HTML
|
|
1217
|
+
* document does not throw `NotSupportedError`.
|
|
1218
|
+
*
|
|
1219
|
+
* @throws {DOMException}
|
|
1220
|
+
* With code `INVALID_CHARACTER_ERR` if `data` contains `"]]>"`.
|
|
1221
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/createCDATASection
|
|
1222
|
+
* @see https://dom.spec.whatwg.org/#dom-document-createcdatasection
|
|
1169
1223
|
*/
|
|
1170
1224
|
createCDATASection(data: string): CDATASection;
|
|
1171
1225
|
|
|
1172
1226
|
/**
|
|
1173
1227
|
* Creates a comment object with the specified data.
|
|
1174
1228
|
*
|
|
1229
|
+
* No validation is performed at creation time. When the resulting document is serialized
|
|
1230
|
+
* with `requireWellFormed: true`, the serializer throws `InvalidStateError` if the comment
|
|
1231
|
+
* data contains `--` anywhere, ends with `-`, or contains characters outside the XML Char
|
|
1232
|
+
* production (W3C DOM Parsing §3.2.1.3). Without that option the data is emitted verbatim.
|
|
1233
|
+
*
|
|
1175
1234
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/createComment)
|
|
1176
1235
|
*/
|
|
1177
1236
|
createComment(data: string): Comment;
|
|
@@ -1225,12 +1284,21 @@ declare module '@xmldom/xmldom' {
|
|
|
1225
1284
|
createEntityReference(name: string): EntityReference;
|
|
1226
1285
|
|
|
1227
1286
|
/**
|
|
1228
|
-
* Returns a ProcessingInstruction node whose target is target and data is data.
|
|
1229
|
-
* not match the Name production an "InvalidCharacterError" DOMException will be thrown. If
|
|
1230
|
-
* data contains "?>" an "InvalidCharacterError" DOMException will be thrown.
|
|
1287
|
+
* Returns a ProcessingInstruction node whose target is target and data is data.
|
|
1231
1288
|
*
|
|
1232
|
-
*
|
|
1233
|
-
*
|
|
1289
|
+
* __This behavior is slightly different from the in the specs__:
|
|
1290
|
+
* - it does not do any input validation on the arguments and doesn't throw
|
|
1291
|
+
* "InvalidCharacterError".
|
|
1292
|
+
*
|
|
1293
|
+
* Note: When the resulting document is serialized with `requireWellFormed: true`, the
|
|
1294
|
+
* serializer throws `InvalidStateError` if `.target` contains `:` or is an ASCII
|
|
1295
|
+
* case-insensitive match for `"xml"`, or if `.data` contains `?>` or characters outside the
|
|
1296
|
+
* XML Char production (W3C DOM Parsing §3.2.1.7). Without that option the data is emitted
|
|
1297
|
+
* verbatim.
|
|
1298
|
+
*
|
|
1299
|
+
* @see https://developer.mozilla.org/docs/Web/API/Document/createProcessingInstruction
|
|
1300
|
+
* @see https://dom.spec.whatwg.org/#dom-document-createprocessinginstruction
|
|
1301
|
+
* @see https://www.w3.org/TR/DOM-Parsing/#dfn-concept-serialize-xml §3.2.1.7
|
|
1234
1302
|
*/
|
|
1235
1303
|
createProcessingInstruction(
|
|
1236
1304
|
target: string,
|
|
@@ -1308,11 +1376,12 @@ declare module '@xmldom/xmldom' {
|
|
|
1308
1376
|
localName: string
|
|
1309
1377
|
): LiveNodeList<Element>;
|
|
1310
1378
|
/**
|
|
1311
|
-
*
|
|
1312
|
-
*
|
|
1313
|
-
* If node is a document or a shadow root, throws a "NotSupportedError" DOMException.
|
|
1379
|
+
* Imports a node from another document into this document, creating a new copy owned by this
|
|
1380
|
+
* document. If `deep` is true, the copy also includes the node's descendants.
|
|
1314
1381
|
*
|
|
1315
1382
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/importNode)
|
|
1383
|
+
*
|
|
1384
|
+
* @see {@link https://dom.spec.whatwg.org/#dom-document-importnode}
|
|
1316
1385
|
*/
|
|
1317
1386
|
importNode<T extends Node>(node: T, deep?: boolean): T;
|
|
1318
1387
|
}
|
|
@@ -1327,10 +1396,32 @@ declare module '@xmldom/xmldom' {
|
|
|
1327
1396
|
interface DocumentType extends Node {
|
|
1328
1397
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DocumentType/name) */
|
|
1329
1398
|
readonly name: string;
|
|
1399
|
+
/**
|
|
1400
|
+
* The internal subset string (the raw content between `[` and `]`), or an empty string.
|
|
1401
|
+
* Declared `readonly` by the WHATWG DOM spec; xmldom does not enforce this — direct
|
|
1402
|
+
* property writes succeed and the written value is serialized verbatim.
|
|
1403
|
+
* When serialized with `requireWellFormed: true`, throws `InvalidStateError` if the value
|
|
1404
|
+
* contains `"]>"`.
|
|
1405
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/DocumentType/internalSubset)
|
|
1406
|
+
*/
|
|
1330
1407
|
readonly internalSubset: string;
|
|
1331
|
-
/**
|
|
1408
|
+
/**
|
|
1409
|
+
* The external subset public identifier, stored verbatim including surrounding quotes.
|
|
1410
|
+
* Declared `readonly` by the WHATWG DOM spec; xmldom does not enforce this — direct
|
|
1411
|
+
* property writes succeed and the written value is serialized verbatim.
|
|
1412
|
+
* When serialized with `requireWellFormed: true`, throws `InvalidStateError` if the value
|
|
1413
|
+
* is non-empty and does not match the XML `PubidLiteral` production (XML 1.0 [12]).
|
|
1414
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/DocumentType/publicId)
|
|
1415
|
+
*/
|
|
1332
1416
|
readonly publicId: string;
|
|
1333
|
-
/**
|
|
1417
|
+
/**
|
|
1418
|
+
* The external subset system identifier, stored verbatim including surrounding quotes.
|
|
1419
|
+
* Declared `readonly` by the WHATWG DOM spec; xmldom does not enforce this — direct
|
|
1420
|
+
* property writes succeed and the written value is serialized verbatim.
|
|
1421
|
+
* When serialized with `requireWellFormed: true`, throws `InvalidStateError` if the value
|
|
1422
|
+
* is non-empty and does not match the XML `SystemLiteral` production (XML 1.0 [11]).
|
|
1423
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/DocumentType/systemId)
|
|
1424
|
+
*/
|
|
1334
1425
|
readonly systemId: string;
|
|
1335
1426
|
}
|
|
1336
1427
|
|
|
@@ -1395,8 +1486,21 @@ declare module '@xmldom/xmldom' {
|
|
|
1395
1486
|
*/
|
|
1396
1487
|
createDocumentType(
|
|
1397
1488
|
qualifiedName: string,
|
|
1489
|
+
/**
|
|
1490
|
+
* External subset public identifier. Stored verbatim including surrounding quotes.
|
|
1491
|
+
* No creation-time validation — deferred to a future breaking release.
|
|
1492
|
+
*/
|
|
1398
1493
|
publicId?: string,
|
|
1399
|
-
|
|
1494
|
+
/**
|
|
1495
|
+
* External subset system identifier. Stored verbatim including surrounding quotes.
|
|
1496
|
+
* No creation-time validation — deferred to a future breaking release.
|
|
1497
|
+
*/
|
|
1498
|
+
systemId?: string,
|
|
1499
|
+
/**
|
|
1500
|
+
* Internal subset string (content between `[` and `]`). Stored verbatim.
|
|
1501
|
+
* No creation-time validation — deferred to a future breaking release.
|
|
1502
|
+
*/
|
|
1503
|
+
internalSubset?: string
|
|
1400
1504
|
): DocumentType;
|
|
1401
1505
|
|
|
1402
1506
|
/**
|
|
@@ -1429,8 +1533,73 @@ declare module '@xmldom/xmldom' {
|
|
|
1429
1533
|
hasFeature(feature: string, version?: string): true;
|
|
1430
1534
|
}
|
|
1431
1535
|
|
|
1536
|
+
/** Options accepted by `XMLSerializer.prototype.serializeToString` and `node.toString`. */
|
|
1537
|
+
interface XMLSerializerOptions {
|
|
1538
|
+
/**
|
|
1539
|
+
* When `true`, the serializer throws `InvalidStateError` for content that would produce
|
|
1540
|
+
* ill-formed XML: CDATASection data containing `"]]>"`; Text data with characters outside
|
|
1541
|
+
* the XML Char production; a Comment node whose data contains `--` anywhere or ends with
|
|
1542
|
+
* `-`; or a Document with no `documentElement`.
|
|
1543
|
+
*
|
|
1544
|
+
* @default false
|
|
1545
|
+
*/
|
|
1546
|
+
requireWellFormed?: boolean;
|
|
1547
|
+
/**
|
|
1548
|
+
* When `true` (the default), `"]]>"` sequences in CDATASection data are split across
|
|
1549
|
+
* concatenated CDATA sections. **Deprecated** — this option and the underlying split
|
|
1550
|
+
* mechanics will be removed in the next breaking release. Callers should migrate to `{
|
|
1551
|
+
* requireWellFormed: true }`, which throws `InvalidStateError` instead of transforming.
|
|
1552
|
+
*
|
|
1553
|
+
* @default true
|
|
1554
|
+
*/
|
|
1555
|
+
splitCDATASections?: boolean;
|
|
1556
|
+
/** A filter function applied to each node before serialization. */
|
|
1557
|
+
nodeFilter?: (node: Node) => Node | null | undefined;
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1432
1560
|
class XMLSerializer {
|
|
1433
|
-
|
|
1561
|
+
/**
|
|
1562
|
+
* Returns the result of serializing `node` to XML.
|
|
1563
|
+
*
|
|
1564
|
+
* When `options.requireWellFormed` is `true`, throws `InvalidStateError` for content that
|
|
1565
|
+
* would produce ill-formed XML. When `options.splitCDATASections` is `false`,
|
|
1566
|
+
* CDATASection data is emitted verbatim. Passing a function as `options` is treated as a
|
|
1567
|
+
* legacy `nodeFilter` for backward compatibility.
|
|
1568
|
+
*
|
|
1569
|
+
* __This implementation differs from the specification:__ - CDATASection serialization is
|
|
1570
|
+
* not specified by W3C DOM Parsing or WHATWG DOM Parsing (see
|
|
1571
|
+
* {@link https://github.com/w3c/DOM-Parsing/issues/38 w3c/DOM-Parsing#38}).
|
|
1572
|
+
* When `splitCDATASections` is `true` (the default), `"]]>"` sequences are split across
|
|
1573
|
+
* concatenated CDATA sections — **deprecated**, will be removed in the next breaking
|
|
1574
|
+
* release.
|
|
1575
|
+
* - W3C DOM Parsing §3.2.1.1 requires well-formedness checks on Element `localName`s,
|
|
1576
|
+
* prefixes, and attribute serialization when `requireWellFormed` is `true`. These checks are
|
|
1577
|
+
* **not implemented** in this release — see the tracking issue filed against the next
|
|
1578
|
+
* breaking milestone.
|
|
1579
|
+
*
|
|
1580
|
+
* @throws {DOMException}
|
|
1581
|
+
* `InvalidStateError` when `requireWellFormed` is `true` and any of the following conditions
|
|
1582
|
+
* hold:
|
|
1583
|
+
* - CDATASection data contains `"]]>"`
|
|
1584
|
+
* - Text data contains characters outside the XML Char production
|
|
1585
|
+
* - a Comment node's data contains `--` anywhere or ends with `-`
|
|
1586
|
+
* - a ProcessingInstruction's target contains `:` or is an ASCII case-insensitive match for
|
|
1587
|
+
* `"xml"`, or its data contains `?>` or characters outside the XML Char production
|
|
1588
|
+
* - a DocumentType's `publicId` is non-empty and does not match the XML `PubidLiteral`
|
|
1589
|
+
* production (W3C DOM Parsing §3.2.1.3; XML 1.0 production [12])
|
|
1590
|
+
* - a DocumentType's `systemId` is non-empty and does not match the XML `SystemLiteral`
|
|
1591
|
+
* production (W3C DOM Parsing §3.2.1.3; XML 1.0 production [11])
|
|
1592
|
+
* - a DocumentType's `internalSubset` contains `"]>"`
|
|
1593
|
+
* - the Document has no `documentElement`
|
|
1594
|
+
* @see https://developer.mozilla.org/docs/Web/API/XMLSerializer/serializeToString
|
|
1595
|
+
* @see https://html.spec.whatwg.org/#dom-xmlserializer-serializetostring
|
|
1596
|
+
* @see https://github.com/w3c/DOM-Parsing/issues/84
|
|
1597
|
+
* @prettierignore
|
|
1598
|
+
*/
|
|
1599
|
+
serializeToString(
|
|
1600
|
+
node: Node,
|
|
1601
|
+
options?: XMLSerializerOptions | ((node: Node) => Node | null | undefined)
|
|
1602
|
+
): string;
|
|
1434
1603
|
}
|
|
1435
1604
|
// END ./lib/dom.js
|
|
1436
1605
|
|