Skip to content

Commit b06bb4c

Browse files
committed
Update to latest specs, add StaticRange and replaceChildren
1 parent f325f82 commit b06bb4c

35 files changed

+1120
-507
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
Fast, tiny, standards-compliant XML DOM implementation for node and the browser.
77

8-
This is a (partial) implementation of the [DOM living standard][domstandard], as last updated 1 March 2019, and the [DOM Parsing and Serialization W3C Editor's Draft][domparsing], as last updated 11 February 2019. See the 'Features and Limitations' section below for details on what's included and what's not.
8+
This is a (partial) implementation of the [DOM living standard][domstandard], as last updated 27 January 2021, and the [DOM Parsing and Serialization W3C Editor's Draft][domparsing], as last updated 20 April 2020. See the 'Features and Limitations' section below for details on what's included and what's not.
99

1010
[domstandard]: https://dom.spec.whatwg.org/
1111
[domparsing]: https://w3c.github.io/DOM-Parsing/
@@ -68,7 +68,7 @@ If you need to parse HTML, see [this example][parse5-example] which shows how to
6868

6969
### CSS Selectors and XPath
7070

71-
This library does not implement CSS selectors, which means no `querySelector` / `querySelectorAll` on `ParentNode` and no `closest` / `matches` / `webkitMatchesSelector` on `Element`.
71+
This library does not implement CSS selectors, which means no `querySelector` / `querySelectorAll` on `ParentNode` and no `closest` / `matches` / `webkitMatchesSelector` on `Element`. This library also does not implement XPath, which means no `XPathResult` / `XPathExpression` / `XPathEvaluator` interfaces and no `createExpression` / `createNSResolver` / `evaluate` on `Document`.
7272

7373
To query a slimdom document using XPath or XQuery, use [FontoXPath][fontoxpath].
7474

@@ -82,11 +82,11 @@ This implementation offers no special treatment of HTML documents, which means t
8282

8383
This library also does not currently implement events, including the `Event` / `EventTarget` interfaces. It also currently does not contain an implementation of `AbortController` / `AbortSignal`. As these may have wider applications than browser-specific use cases, please file an issue if you have a use for these in your application and would like support for them to be added.
8484

85-
There is currently no support for shadow DOM, so no `Slotable` / `ShadowRoot` interfaces and no `slot` / `attachShadow` / `shadowRoot` on `Element`. Slimdom also does not support the APIs for custom elements using the `is` option on `createElement` / `createElementNS`.
85+
There is currently no support for shadow DOM, so no `Slottable` / `ShadowRoot` interfaces and no `slot` / `attachShadow` / `shadowRoot` on `Element`. Slimdom also does not support the APIs for custom elements using the `is` option on `createElement` / `createElementNS`.
8686

87-
This library has no notion of URLs (`baseURI` on `Node`, and `URL` / `documentURI` / `origin` on `Document`), nor of encodings (`characterSet` / `charset` / `inputEncoding` on `Document`). This library only deals with JavaScript strings, not raw byte streams.
87+
This library has no notion of URLs (`baseURI` on `Node`, and `URL` / `documentURI` on `Document`), nor of encodings (`characterSet` / `charset` / `inputEncoding` on `Document`). This library only deals with JavaScript strings, not raw byte streams.
8888

89-
This library omits properties and methods that exist mainly for web compatibility reasons (`insertAdjacentElement` / `insertAdjacentText` on `Element`, `hasFeature` on `DOMImplementation`, and `specified` on `Attr`).
89+
This library omits properties and methods that exist mainly for web compatibility reasons (`insertAdjacentElement` / `insertAdjacentText` on `Element`, `hasFeature` on `DOMImplementation`, and `specified` on `Attr`). This also includes all interfaces and interface members listed as removed in the [DOM living standard][domstandard].
9090

9191
### Miscellaneous
9292

api/slimdom.api.json

Lines changed: 382 additions & 22 deletions
Large diffs are not rendered by default.

api/slimdom.api.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ export class Document extends Node implements NonElementParentNode, ParentNode {
146146
// (undocumented)
147147
prepend(...nodes: (Node | string)[]): void;
148148
// (undocumented)
149+
replaceChildren(...nodes: (Node | string)[]): void;
150+
// (undocumented)
149151
get textContent(): string | null;
150152
set textContent(_newValue: string | null);
151153
}
@@ -181,6 +183,8 @@ export class DocumentFragment extends Node implements NonElementParentNode, Pare
181183
// (undocumented)
182184
prepend(...nodes: (Node | string)[]): void;
183185
// (undocumented)
186+
replaceChildren(...nodes: (Node | string)[]): void;
187+
// (undocumented)
184188
get textContent(): string | null;
185189
set textContent(newValue: string | null);
186190
}
@@ -281,6 +285,8 @@ export class Element extends Node implements ParentNode, NonDocumentTypeChildNod
281285
removeAttributeNode(attr: Attr): Attr;
282286
removeAttributeNS(namespace: string | null, localName: string): void;
283287
// (undocumented)
288+
replaceChildren(...nodes: (Node | string)[]): void;
289+
// (undocumented)
284290
replaceWith(...nodes: (Node | string)[]): void;
285291
setAttribute(qualifiedName: string, value: string): void;
286292
setAttributeNode(attr: Attr): Attr | null;
@@ -463,6 +469,22 @@ export class Range implements AbstractRange {
463469
// @public
464470
export function serializeToWellFormedString(root: Node): string;
465471

472+
// @public
473+
export class StaticRange implements AbstractRange {
474+
// Warning: (ae-forgotten-export) The symbol "StaticRangeInit" needs to be exported by the entry point index.d.ts
475+
constructor(init: StaticRangeInit);
476+
// (undocumented)
477+
readonly collapsed: boolean;
478+
// (undocumented)
479+
readonly endContainer: Node;
480+
// (undocumented)
481+
readonly endOffset: number;
482+
// (undocumented)
483+
readonly startContainer: Node;
484+
// (undocumented)
485+
readonly startOffset: number;
486+
}
487+
466488
// @public
467489
export class Text extends CharacterData {
468490
constructor(data?: string);

src/Attr.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class Attr extends Node {
3131
public set nodeValue(newValue: string | null) {
3232
newValue = treatNullAsEmptyString(newValue);
3333

34-
// Set an existing attribute value with context object and new value.
34+
// Set an existing attribute value with this and new value.
3535
setExistingAttributeValue(this, newValue);
3636
}
3737

@@ -42,7 +42,7 @@ export default class Attr extends Node {
4242
public set textContent(newValue: string | null) {
4343
newValue = treatNullAsEmptyString(newValue);
4444

45-
// Set an existing attribute value with context object and new value.
45+
// Set an existing attribute value with this and new value.
4646
setExistingAttributeValue(this, newValue);
4747
}
4848

@@ -52,7 +52,7 @@ export default class Attr extends Node {
5252
// 1. If namespace is null or the empty string, then return null.
5353
// (not necessary due to recursion)
5454

55-
// 2. Switch on the context object:
55+
// 2. Switch on this:
5656
// Attr - Return the result of locating a namespace prefix for its element, if its element
5757
// is non-null, and null otherwise.
5858
if (this.ownerElement !== null) {
@@ -68,7 +68,7 @@ export default class Attr extends Node {
6868
// 1. If prefix is the empty string, then set it to null.
6969
// (not necessary due to recursion)
7070

71-
// 2. Return the result of running locate a namespace for the context object using prefix.
71+
// 2. Return the result of running locate a namespace for this using prefix.
7272

7373
// To locate a namespace for a node using prefix, switch on node: Attr
7474
// 1. If its element is null, then return null.
@@ -128,11 +128,11 @@ export default class Attr extends Node {
128128
}
129129

130130
/**
131-
* (non-standard) Creates a copy of the context object, not including its children.
131+
* (non-standard) Creates a copy of this, not including its children.
132132
*
133133
* @param document - The node document to associate with the copy
134134
*
135-
* @returns A shallow copy of the context object
135+
* @returns A shallow copy of this
136136
*/
137137
public _copy(document: Document): Attr {
138138
// Set copy’s namespace, namespace prefix, local name, and value, to those of node.
@@ -164,7 +164,7 @@ function setExistingAttributeValue(attribute: Attr, value: string) {
164164
if (element === null) {
165165
(attribute as any)._value = value;
166166
} else {
167-
// 2. Otherwise, change attribute from attribute’s element to value.
168-
changeAttribute(attribute, element, value);
167+
// 2. Otherwise, change attribute to value.
168+
changeAttribute(attribute, value);
169169
}
170170
}

src/CDATASection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ export default class CDATASection extends Text {
2929
}
3030

3131
/**
32-
* (non-standard) Creates a copy of the context object, not including its children.
32+
* (non-standard) Creates a copy of this, not including its children.
3333
*
3434
* @param document - The node document to associate with the copy
3535
*
36-
* @returns A shallow copy of the context object
36+
* @returns A shallow copy of this
3737
*/
3838
public _copy(document: Document): CDATASection {
3939
// Set copy’s data, to that of node.

src/CharacterData.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default abstract class CharacterData
3535
public set nodeValue(newValue: string | null) {
3636
newValue = treatNullAsEmptyString(newValue);
3737

38-
// Set an existing attribute value with context object and new value.
38+
// Set an existing attribute value with this and new value.
3939
replaceData(this, 0, this.length, newValue);
4040
}
4141

@@ -46,7 +46,7 @@ export default abstract class CharacterData
4646
public set textContent(newValue: string | null) {
4747
newValue = treatNullAsEmptyString(newValue);
4848

49-
// Set an existing attribute value with context object and new value.
49+
// Set an existing attribute value with this and new value.
5050
replaceData(this, 0, this.length, newValue);
5151
}
5252

@@ -56,7 +56,7 @@ export default abstract class CharacterData
5656
// 1. If namespace is null or the empty string, then return null.
5757
// (not necessary due to recursion)
5858

59-
// 2. Switch on the context object:
59+
// 2. Switch on this:
6060
// Any other node - Return the result of locating a namespace prefix for its parent element,
6161
// if its parent element is non-null, and null otherwise.
6262
const parentElement = this.parentElement;
@@ -73,7 +73,7 @@ export default abstract class CharacterData
7373
// 1. If prefix is the empty string, then set it to null.
7474
// (not necessary due to recursion)
7575

76-
// 2. Return the result of running locate a namespace for the context object using prefix.
76+
// 2. Return the result of running locate a namespace for this using prefix.
7777

7878
// To locate a namespace for a node using prefix, switch on node: Any other node
7979
// 1. If its parent element is null, then return null.
@@ -130,7 +130,7 @@ export default abstract class CharacterData
130130
// [TreatNullAs=EmptyString]
131131
newValue = treatNullAsEmptyString(newValue);
132132

133-
// replace data with node context object, offset 0, count context object’s length, and data
133+
// replace data with node this, offset 0, count this’s length, and data
134134
// new value.
135135
replaceData(this, 0, this.length, newValue);
136136
}
@@ -286,9 +286,8 @@ export function replaceData(
286286
}
287287
});
288288

289-
// 12. If node is a Text node and its parent is not null, run the child text content change
290-
// steps for node’s parent.
291-
// (child text content change steps not implemented)
289+
// 12. If node's parent is non-null, then run the children changed steps for node’s parent.
290+
// (children changed steps not implemented)
292291
}
293292

294293
/**

src/Comment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ export default class Comment extends CharacterData {
3333
}
3434

3535
/**
36-
* (non-standard) Creates a copy of the context object, not including its children.
36+
* (non-standard) Creates a copy of this, not including its children.
3737
*
3838
* @param document - The node document to associate with the copy
3939
*
40-
* @returns A shallow copy of the context object
40+
* @returns A shallow copy of this
4141
*/
4242
public _copy(document: Document): Comment {
4343
// Set copy’s data, to that of node.

src/DOMImplementation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default class DOMImplementation {
4343

4444
// 2. Return a new doctype, with qualifiedName as its name, publicId as its public ID, and
4545
// systemId as its system ID, and with its node document set to the associated document of
46-
// the context object.
46+
// this.
4747
const context = getContext(this._document);
4848
const doctype = new context.DocumentType(qualifiedName, publicId, systemId);
4949
doctype.ownerDocument = this._document;
@@ -97,7 +97,7 @@ export default class DOMImplementation {
9797
document.appendChild(element);
9898
}
9999

100-
// 6. document’s origin is context object’s associated document’s origin.
100+
// 6. document’s origin is this’s associated document’s origin.
101101
// (origin not implemented)
102102

103103
// 7. document’s content type is determined by namespace:
@@ -159,7 +159,7 @@ export default class DOMImplementation {
159159
// the html element created earlier.
160160
htmlElement.appendChild(createElement(doc, 'body', HTML_NAMESPACE));
161161

162-
// 8. doc’s origin is context object’s associated document’s origin.
162+
// 8. doc’s origin is this’s associated document’s origin.
163163
// (origin not implemented)
164164

165165
// 9. Return doc.

0 commit comments

Comments
 (0)