@siteimprove/alfa-dom 0.112.0 → 0.114.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/dist/h.d.ts +14 -13
- package/dist/h.js +15 -13
- package/dist/index.d.ts +2 -28
- package/dist/index.js +2 -28
- package/dist/jsx.d.ts +2 -3
- package/dist/native.d.ts +10 -2
- package/dist/native.js +18 -2
- package/dist/node/attribute/predicate/has-name.d.ts +1 -1
- package/dist/node/attribute/predicate/has-name.js +2 -3
- package/dist/node/attribute.d.ts +9 -13
- package/dist/node/attribute.js +3 -10
- package/dist/node/comment.d.ts +7 -11
- package/dist/node/comment.js +2 -9
- package/dist/node/document.d.ts +11 -14
- package/dist/node/document.js +8 -23
- package/dist/node/element/augment.d.ts +1 -1
- package/dist/node/element/augment.js +1 -1
- package/dist/node/element/predicate/has-attribute.d.ts +1 -1
- package/dist/node/element/predicate/has-display-size.d.ts +1 -1
- package/dist/node/element/predicate/has-id.d.ts +1 -1
- package/dist/node/element/predicate/has-input-type.d.ts +1 -1
- package/dist/node/element/predicate/has-name.d.ts +1 -1
- package/dist/node/element/predicate/has-namespace.d.ts +1 -1
- package/dist/node/element/predicate/has-tab-index.d.ts +1 -1
- package/dist/node/element/predicate/has-unique-id.d.ts +3 -2
- package/dist/node/element/predicate/has-unique-id.js +21 -20
- package/dist/node/element/predicate/index.d.ts +19 -0
- package/dist/node/element/predicate/index.js +19 -0
- package/dist/node/element/predicate/is-actually-disabled.d.ts +4 -2
- package/dist/node/element/predicate/is-actually-disabled.js +37 -38
- package/dist/node/element/predicate/is-browsing-context-container.d.ts +1 -1
- package/dist/node/element/predicate/is-content.d.ts +5 -2
- package/dist/node/element/predicate/is-content.js +3 -4
- package/dist/node/element/predicate/is-document-element.d.ts +3 -2
- package/dist/node/element/predicate/is-document-element.js +2 -3
- package/dist/node/element/predicate/is-draggable.d.ts +1 -1
- package/dist/node/element/predicate/is-editing-host.d.ts +1 -1
- package/dist/node/element/predicate/is-fallback.d.ts +5 -2
- package/dist/node/element/predicate/is-fallback.js +5 -6
- package/dist/node/element/predicate/is-replaced.d.ts +1 -1
- package/dist/node/element/predicate/is-scoped-to.d.ts +3 -2
- package/dist/node/element/predicate/is-scoped-to.js +5 -5
- package/dist/node/element/predicate/is-suggested-focusable.d.ts +1 -1
- package/dist/node/element/predicate/is-suggested-focusable.js +3 -3
- package/dist/node/fragment.d.ts +6 -9
- package/dist/node/fragment.js +5 -20
- package/dist/node/index.d.ts +54 -0
- package/dist/node/index.js +74 -0
- package/dist/{node.d.ts → node/node.d.ts} +40 -160
- package/dist/{node.js → node/node.js} +57 -92
- package/dist/node/predicate/has-box.d.ts +1 -2
- package/dist/node/predicate/has-child.d.ts +1 -1
- package/dist/node/predicate/has-child.js +2 -2
- package/dist/node/predicate/has-descendant.d.ts +1 -1
- package/dist/node/predicate/has-descendant.js +2 -2
- package/dist/node/predicate/has-inclusive-descendant.d.ts +1 -1
- package/dist/node/predicate/has-inclusive-descendant.js +2 -2
- package/dist/node/predicate/has-text-content.d.ts +1 -1
- package/dist/node/predicate/has-text-content.js +2 -2
- package/dist/node/predicate/index.d.ts +7 -0
- package/dist/node/predicate/index.js +7 -0
- package/dist/node/predicate/is-root.d.ts +1 -1
- package/dist/node/query/descendants.d.ts +3 -3
- package/dist/node/query/descendants.js +6 -6
- package/dist/node/query/element-id-map.d.ts +2 -2
- package/dist/node/query/index.d.ts +2 -2
- package/dist/node/shadow.d.ts +11 -14
- package/dist/node/shadow.js +9 -24
- package/dist/node/{element.d.ts → slotable/element.d.ts} +28 -27
- package/dist/node/{element.js → slotable/element.js} +40 -51
- package/dist/node/slotable/index.d.ts +12 -0
- package/dist/node/slotable/index.js +15 -0
- package/dist/node/slotable/slot.d.ts +21 -0
- package/dist/node/slotable/slot.js +23 -0
- package/dist/node/slotable/slotable.d.ts +31 -0
- package/dist/node/slotable/slotable.js +16 -0
- package/dist/node/{text.d.ts → slotable/text.d.ts} +8 -11
- package/dist/node/{text.js → slotable/text.js} +13 -10
- package/dist/node/traversal/get-nodes-between.d.ts +1 -1
- package/dist/node/traversal/get-nodes-between.js +3 -3
- package/dist/node/traversal/index.d.ts +2 -0
- package/dist/node/traversal/index.js +2 -0
- package/dist/node/traversal/lowest-common-ancestor.d.ts +1 -1
- package/dist/node/traversal/lowest-common-ancestor.js +2 -2
- package/dist/node/type.d.ts +6 -10
- package/dist/node/type.js +2 -9
- package/dist/style/declaration.d.ts +2 -2
- package/dist/style/index.d.ts +5 -0
- package/dist/style/index.js +5 -0
- package/dist/style/rule/condition.d.ts +1 -1
- package/dist/style/rule/font-face.d.ts +3 -3
- package/dist/style/rule/font-face.js +2 -2
- package/dist/style/rule/grouping.d.ts +4 -3
- package/dist/style/rule/grouping.js +2 -2
- package/dist/style/rule/import.d.ts +3 -3
- package/dist/style/rule/import.js +2 -4
- package/dist/style/rule/index.d.ts +65 -0
- package/dist/style/rule/index.js +83 -0
- package/dist/style/rule/keyframe.d.ts +3 -3
- package/dist/style/rule/keyframe.js +2 -2
- package/dist/style/rule/keyframes.d.ts +2 -2
- package/dist/style/rule/keyframes.js +2 -3
- package/dist/style/rule/layer.d.ts +5 -4
- package/dist/style/rule/layer.js +4 -4
- package/dist/style/rule/media.d.ts +2 -2
- package/dist/style/rule/media.js +2 -3
- package/dist/style/rule/namespace.d.ts +3 -3
- package/dist/style/rule/namespace.js +2 -2
- package/dist/style/rule/page.d.ts +3 -3
- package/dist/style/rule/page.js +2 -2
- package/dist/style/rule/rule.d.ts +42 -0
- package/dist/style/rule/rule.js +64 -0
- package/dist/style/rule/style.d.ts +3 -3
- package/dist/style/rule/style.js +2 -2
- package/dist/style/rule/supports.d.ts +2 -2
- package/dist/style/rule/supports.js +2 -3
- package/dist/style/sheet.d.ts +1 -1
- package/dist/style/sheet.js +2 -2
- package/package.json +29 -30
- package/dist/node/element/predicate.d.ts +0 -19
- package/dist/node/element/predicate.js +0 -19
- package/dist/node/predicate.d.ts +0 -7
- package/dist/node/predicate.js +0 -7
- package/dist/node/slot.d.ts +0 -29
- package/dist/node/slot.js +0 -41
- package/dist/node/slotable.d.ts +0 -29
- package/dist/node/slotable.js +0 -40
- package/dist/node/traversal.d.ts +0 -2
- package/dist/node/traversal.js +0 -2
- package/dist/style/rule.d.ts +0 -60
- package/dist/style/rule.js +0 -109
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Cache } from "@siteimprove/alfa-cache";
|
|
2
|
+
import { Refinement } from "@siteimprove/alfa-refinement";
|
|
3
|
+
import { BaseNode as BaseNode } from "./node.js";
|
|
4
|
+
import { Attribute } from "./attribute.js";
|
|
5
|
+
import { Comment } from "./comment.js";
|
|
6
|
+
import { Document } from "./document.js";
|
|
7
|
+
import { Shadow } from "./shadow.js";
|
|
8
|
+
import { Element, Text } from "./slotable/index.js";
|
|
9
|
+
import { Fragment } from "./fragment.js";
|
|
10
|
+
import { Type } from "./type.js";
|
|
11
|
+
import * as predicate from "./predicate/index.js";
|
|
12
|
+
import * as traversal from "./traversal/index.js";
|
|
13
|
+
const { or } = Refinement;
|
|
14
|
+
export * from "./attribute.js";
|
|
15
|
+
export * from "./comment.js";
|
|
16
|
+
export * from "./document.js";
|
|
17
|
+
export * from "./shadow.js";
|
|
18
|
+
export * from "./slotable/index.js";
|
|
19
|
+
// Load the element specific augments.
|
|
20
|
+
import "./element/augment.js";
|
|
21
|
+
export * from "./fragment.js";
|
|
22
|
+
export * from "./type.js";
|
|
23
|
+
/**
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export var Node;
|
|
27
|
+
(function (Node) {
|
|
28
|
+
Node.isNode = or(Attribute.isAttribute, or(Comment.isComment, or(Document.isDocument, or(Element.isElement, or(Fragment.isFragment, or(Shadow.isShadow, or(Type.isType, Text.isText)))))));
|
|
29
|
+
Node.Traversal = BaseNode.Traversal;
|
|
30
|
+
Node.flatTree = BaseNode.flatTree;
|
|
31
|
+
Node.fullTree = BaseNode.fullTree;
|
|
32
|
+
Node.composedNested = BaseNode.composedNested;
|
|
33
|
+
const cacheWithDevice = Cache.empty();
|
|
34
|
+
const cacheWithoutDevice = Cache.empty();
|
|
35
|
+
function from(json, device) {
|
|
36
|
+
return device === undefined
|
|
37
|
+
? cacheWithoutDevice.get(json, () => fromNode(json, device).run())
|
|
38
|
+
: cacheWithDevice
|
|
39
|
+
.get(json, Cache.empty)
|
|
40
|
+
.get(device, () => fromNode(json, device).run());
|
|
41
|
+
}
|
|
42
|
+
Node.from = from;
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
function fromNode(json, device) {
|
|
47
|
+
switch (json.type) {
|
|
48
|
+
case "element":
|
|
49
|
+
return Element.fromElement(json, fromNode, device);
|
|
50
|
+
case "attribute":
|
|
51
|
+
return Attribute.fromAttribute(json);
|
|
52
|
+
case "text":
|
|
53
|
+
return Text.fromText(json, device);
|
|
54
|
+
case "comment":
|
|
55
|
+
return Comment.fromComment(json);
|
|
56
|
+
case "document":
|
|
57
|
+
return Document.fromDocument(json, fromNode, device);
|
|
58
|
+
case "type":
|
|
59
|
+
return Type.fromType(json);
|
|
60
|
+
case "fragment":
|
|
61
|
+
return Fragment.fromFragment(json, fromNode, device);
|
|
62
|
+
default:
|
|
63
|
+
throw new Error(`Unexpected node of type: ${json.type}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
Node.fromNode = fromNode;
|
|
67
|
+
Node.getNodesBetween = traversal.getNodesBetween;
|
|
68
|
+
Node.hasBox = predicate.hasBox, Node.isRoot = predicate.isRoot;
|
|
69
|
+
Node.hasChild = predicate.hasChild;
|
|
70
|
+
Node.hasDescendant = predicate.hasDescendant;
|
|
71
|
+
Node.hasInclusiveDescendant = predicate.hasInclusiveDescendant;
|
|
72
|
+
Node.hasTextContent = predicate.hasTextContent;
|
|
73
|
+
})(Node || (Node = {}));
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -5,84 +5,82 @@ import { Option } from "@siteimprove/alfa-option";
|
|
|
5
5
|
import type { Predicate } from "@siteimprove/alfa-predicate";
|
|
6
6
|
import type { Refinement } from "@siteimprove/alfa-refinement";
|
|
7
7
|
import { Sequence } from "@siteimprove/alfa-sequence";
|
|
8
|
-
import type { Trampoline } from "@siteimprove/alfa-trampoline";
|
|
9
8
|
import type * as earl from "@siteimprove/alfa-earl";
|
|
10
9
|
import * as json from "@siteimprove/alfa-json";
|
|
11
10
|
import type * as sarif from "@siteimprove/alfa-sarif";
|
|
12
11
|
import * as tree from "@siteimprove/alfa-tree";
|
|
13
|
-
import {
|
|
14
|
-
import * as predicate from "./node/predicate.js";
|
|
15
|
-
import * as traversal from "./node/traversal.js";
|
|
12
|
+
import type { Element, Node } from "./index.js";
|
|
16
13
|
/**
|
|
17
14
|
* @public
|
|
18
15
|
*/
|
|
19
|
-
export declare abstract class
|
|
16
|
+
export declare abstract class BaseNode<T extends string = string> extends tree.Node<"DOM traversal", BaseNode.TraversalFlags, T> implements earl.Serializable<BaseNode.EARL>, json.Serializable<tree.Node.JSON<T>>, sarif.Serializable<sarif.Location> {
|
|
20
17
|
protected constructor(children: Array<Node>, type: T, externalId?: string, internalId?: string, extraData?: any);
|
|
21
18
|
/**
|
|
22
19
|
* {@link https://dom.spec.whatwg.org/#concept-descendant-text-content}
|
|
23
20
|
*/
|
|
24
|
-
textContent(options?:
|
|
21
|
+
textContent(options?: BaseNode.Traversal): string;
|
|
25
22
|
/**
|
|
26
23
|
* Construct a sequence of descendants of this node sorted by tab index. Only
|
|
27
24
|
* nodes with a non-negative tab index are included in the sequence.
|
|
28
25
|
*
|
|
29
26
|
* {@link https://html.spec.whatwg.org/multipage/#tabindex-value}
|
|
30
27
|
*/
|
|
31
|
-
tabOrder(): Sequence<Element>;
|
|
28
|
+
tabOrder(this: Node): Sequence<Element>;
|
|
32
29
|
private _path;
|
|
33
30
|
/**
|
|
34
31
|
* @internal
|
|
35
32
|
*/
|
|
36
|
-
protected _internalPath(options?:
|
|
33
|
+
protected _internalPath(options?: BaseNode.Traversal): string;
|
|
37
34
|
/**
|
|
38
35
|
* Get an XPath that uniquely identifies the node across descendants of its
|
|
39
36
|
* root.
|
|
40
37
|
*/
|
|
41
|
-
path(options?:
|
|
42
|
-
equals(value:
|
|
38
|
+
path(options?: BaseNode.Traversal): string;
|
|
39
|
+
equals(value: BaseNode): boolean;
|
|
43
40
|
equals(value: unknown): value is this;
|
|
44
|
-
toJSON(options?: Serializable.Options):
|
|
45
|
-
toEARL():
|
|
41
|
+
toJSON(options?: Serializable.Options): BaseNode.JSON<T>;
|
|
42
|
+
toEARL(): BaseNode.EARL;
|
|
46
43
|
toSARIF(): sarif.Location;
|
|
47
44
|
}
|
|
48
45
|
/**
|
|
49
46
|
* @public
|
|
50
47
|
*/
|
|
51
|
-
export interface
|
|
52
|
-
parent(options?:
|
|
53
|
-
isParentOf(node: Node, options?:
|
|
54
|
-
root(options?:
|
|
55
|
-
isRootOf(node: Node, options?:
|
|
56
|
-
children(options?:
|
|
57
|
-
isChildOf(node: Node, options?:
|
|
58
|
-
descendants(options?:
|
|
59
|
-
isDescendantOf(node: Node, options?:
|
|
60
|
-
inclusiveDescendants(options?:
|
|
61
|
-
isInclusiveDescendantsOf(node: Node, options?:
|
|
62
|
-
ancestors(options?:
|
|
63
|
-
isAncestorOf(node: Node, options?:
|
|
64
|
-
inclusiveAncestors(options?:
|
|
65
|
-
isInclusiveAncestorOf(node: Node, options?:
|
|
66
|
-
siblings(options?:
|
|
67
|
-
isSiblingOf(node: Node, options?:
|
|
68
|
-
inclusiveSiblings(options?:
|
|
69
|
-
isInclusiveSiblingOf(node: Node, options?:
|
|
70
|
-
preceding(options?:
|
|
71
|
-
following(options?:
|
|
72
|
-
first(options?:
|
|
73
|
-
last(options?:
|
|
74
|
-
previous(options?:
|
|
75
|
-
next(options?:
|
|
76
|
-
index(options?:
|
|
77
|
-
closest<T extends Node>(refinement: Refinement<Node, T>, options?:
|
|
78
|
-
closest(predicate: Predicate<Node>, options?:
|
|
48
|
+
export interface BaseNode {
|
|
49
|
+
parent(options?: BaseNode.Traversal): Option<Node>;
|
|
50
|
+
isParentOf(node: Node, options?: BaseNode.Traversal): boolean;
|
|
51
|
+
root(options?: BaseNode.Traversal): Node;
|
|
52
|
+
isRootOf(node: Node, options?: BaseNode.Traversal): boolean;
|
|
53
|
+
children(options?: BaseNode.Traversal): Sequence<Node>;
|
|
54
|
+
isChildOf(node: Node, options?: BaseNode.Traversal): boolean;
|
|
55
|
+
descendants(options?: BaseNode.Traversal): Sequence<Node>;
|
|
56
|
+
isDescendantOf(node: Node, options?: BaseNode.Traversal): boolean;
|
|
57
|
+
inclusiveDescendants(options?: BaseNode.Traversal): Sequence<Node>;
|
|
58
|
+
isInclusiveDescendantsOf(node: Node, options?: BaseNode.Traversal): boolean;
|
|
59
|
+
ancestors(options?: BaseNode.Traversal): Sequence<Node>;
|
|
60
|
+
isAncestorOf(node: Node, options?: BaseNode.Traversal): boolean;
|
|
61
|
+
inclusiveAncestors(options?: BaseNode.Traversal): Sequence<Node>;
|
|
62
|
+
isInclusiveAncestorOf(node: Node, options?: BaseNode.Traversal): boolean;
|
|
63
|
+
siblings(options?: BaseNode.Traversal): Sequence<Node>;
|
|
64
|
+
isSiblingOf(node: Node, options?: BaseNode.Traversal): boolean;
|
|
65
|
+
inclusiveSiblings(options?: BaseNode.Traversal): Sequence<Node>;
|
|
66
|
+
isInclusiveSiblingOf(node: Node, options?: BaseNode.Traversal): boolean;
|
|
67
|
+
preceding(options?: BaseNode.Traversal): Sequence<Node>;
|
|
68
|
+
following(options?: BaseNode.Traversal): Sequence<Node>;
|
|
69
|
+
first(options?: BaseNode.Traversal): Option<Node>;
|
|
70
|
+
last(options?: BaseNode.Traversal): Option<Node>;
|
|
71
|
+
previous(options?: BaseNode.Traversal): Option<Node>;
|
|
72
|
+
next(options?: BaseNode.Traversal): Option<Node>;
|
|
73
|
+
index(options?: BaseNode.Traversal, predicate?: Predicate<Node>): number;
|
|
74
|
+
closest<T extends Node>(refinement: Refinement<Node, T>, options?: BaseNode.Traversal): Option<T>;
|
|
75
|
+
closest(predicate: Predicate<Node>, options?: BaseNode.Traversal): Option<Node>;
|
|
79
76
|
}
|
|
80
77
|
/**
|
|
81
78
|
* @public
|
|
82
79
|
*/
|
|
83
|
-
export declare namespace
|
|
80
|
+
export declare namespace BaseNode {
|
|
84
81
|
interface JSON<T extends string = string> extends tree.Node.JSON<T> {
|
|
85
82
|
path?: string;
|
|
83
|
+
children?: Array<Node.JSON>;
|
|
86
84
|
}
|
|
87
85
|
interface SerializationOptions extends json.Serializable.Options {
|
|
88
86
|
device?: Device;
|
|
@@ -102,7 +100,6 @@ export declare namespace Node {
|
|
|
102
100
|
"@id": string;
|
|
103
101
|
};
|
|
104
102
|
}
|
|
105
|
-
function isNode(value: unknown): value is Node;
|
|
106
103
|
const Traversal: {
|
|
107
104
|
of: (...flags: import("@siteimprove/alfa-array").Array<0 | 1 | 2 | 4 | "composed" | "flattened" | "nested">) => {
|
|
108
105
|
has(flag: 0 | 1 | 2 | 4 | "composed" | "flattened" | "nested"): boolean;
|
|
@@ -162,7 +159,7 @@ export declare namespace Node {
|
|
|
162
159
|
nested: 1 | 2 | 4;
|
|
163
160
|
};
|
|
164
161
|
type Traversal = ReturnType<(typeof Traversal)["of"]>;
|
|
165
|
-
type TraversalFlags = (typeof
|
|
162
|
+
type TraversalFlags = (typeof BaseNode.Traversal.allFlags)[number];
|
|
166
163
|
/**
|
|
167
164
|
* Traversal options to traverse the flat tree.
|
|
168
165
|
*
|
|
@@ -245,122 +242,5 @@ export declare namespace Node {
|
|
|
245
242
|
flattened: boolean;
|
|
246
243
|
nested: boolean;
|
|
247
244
|
};
|
|
248
|
-
function from(json: Element.JSON, device?: Device): Element;
|
|
249
|
-
function from(json: Attribute.JSON, device?: Device): Attribute;
|
|
250
|
-
function from(json: Text.JSON, device?: Device): Text;
|
|
251
|
-
function from(json: Comment.JSON, device?: Device): Comment;
|
|
252
|
-
function from(json: Document.JSON, device?: Device): Document;
|
|
253
|
-
function from(json: Type.JSON, device?: Device): Document;
|
|
254
|
-
function from(json: Fragment.JSON, device?: Device): Fragment;
|
|
255
|
-
function from(json: JSON, device?: Device): Node;
|
|
256
|
-
/**
|
|
257
|
-
* @internal
|
|
258
|
-
*/
|
|
259
|
-
function fromNode(json: JSON, device?: Device): Trampoline<Node>;
|
|
260
|
-
interface ElementReplacementOptions {
|
|
261
|
-
predicate: Predicate<Element>;
|
|
262
|
-
newElements: Iterable<Element>;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Creates a new `Element` instance with the same value as the original and
|
|
266
|
-
* deeply referentially non-equal. Optionally replaces child elements based
|
|
267
|
-
* on a predicate.
|
|
268
|
-
*
|
|
269
|
-
* @remarks
|
|
270
|
-
* The clone will have the same `externalId` as the original.
|
|
271
|
-
* The clone will *not* get `extraData` from the original, instead it will be
|
|
272
|
-
* `undefined`.
|
|
273
|
-
*/
|
|
274
|
-
function clone(node: Element, options?: ElementReplacementOptions, device?: Device): Element;
|
|
275
|
-
/**
|
|
276
|
-
* Creates a new `Attribute` instance with the same value as the original and
|
|
277
|
-
* referentially non-equal.
|
|
278
|
-
*
|
|
279
|
-
* @remarks
|
|
280
|
-
* The clone will have the same `externalId` as the original.
|
|
281
|
-
* The clone will *not* get `extraData` from the original, instead it will be
|
|
282
|
-
* `undefined`.
|
|
283
|
-
*/
|
|
284
|
-
function clone(node: Attribute, options?: ElementReplacementOptions, device?: Device): Attribute;
|
|
285
|
-
/**
|
|
286
|
-
* Creates a new `Text` instance with the same value as the original and
|
|
287
|
-
* referentially non-equal.
|
|
288
|
-
*
|
|
289
|
-
* @remarks
|
|
290
|
-
* The clone will have the same `externalId` as the original.
|
|
291
|
-
* The clone will *not* get `extraData` from the original, instead it will be
|
|
292
|
-
* `undefined`.
|
|
293
|
-
*/
|
|
294
|
-
function clone(node: Text, options?: ElementReplacementOptions, device?: Device): Text;
|
|
295
|
-
/**
|
|
296
|
-
* Creates a new `Comment` instance with the same value as the original and
|
|
297
|
-
* referentially non-equal.
|
|
298
|
-
*
|
|
299
|
-
* @remarks
|
|
300
|
-
* The clone will have the same `externalId` as the original.
|
|
301
|
-
* The clone will *not* get `extraData` from the original, instead it will be
|
|
302
|
-
* `undefined`.
|
|
303
|
-
*/
|
|
304
|
-
function clone(node: Comment, options?: ElementReplacementOptions, device?: Device): Comment;
|
|
305
|
-
/**
|
|
306
|
-
* Creates a new `Document` instance with the same value as the original and
|
|
307
|
-
* deeply referentially non-equal. Optionally replaces child elements based
|
|
308
|
-
* on a predicate.
|
|
309
|
-
*
|
|
310
|
-
* @remarks
|
|
311
|
-
* The clone will have the same `externalId` as the original.
|
|
312
|
-
* The clone will *not* get `extraData` from the original, instead it will be
|
|
313
|
-
* `undefined`.
|
|
314
|
-
*/
|
|
315
|
-
function clone(node: Document, options?: ElementReplacementOptions, device?: Device): Document;
|
|
316
|
-
/**
|
|
317
|
-
* Creates a new `Type` instance with the same value as the original and
|
|
318
|
-
* referentially non-equal.
|
|
319
|
-
*
|
|
320
|
-
* @remarks
|
|
321
|
-
* The clone will have the same `externalId` as the original.
|
|
322
|
-
* The clone will *not* get `extraData` from the original, instead it will be
|
|
323
|
-
* `undefined`.
|
|
324
|
-
*/
|
|
325
|
-
function clone(node: Type, options?: ElementReplacementOptions, device?: Device): Document;
|
|
326
|
-
/**
|
|
327
|
-
* Creates a new `Fragment` instance with the same value as the original and
|
|
328
|
-
* deeply referentially non-equal. Optionally replaces child elements based
|
|
329
|
-
* on a predicate.
|
|
330
|
-
*
|
|
331
|
-
* @remarks
|
|
332
|
-
* The clone will have the same `externalId` as the original.
|
|
333
|
-
* The clone will *not* get `extraData` from the original, instead it will be
|
|
334
|
-
* `undefined`.
|
|
335
|
-
*/
|
|
336
|
-
function clone(node: Fragment, options?: ElementReplacementOptions, device?: Device): Fragment;
|
|
337
|
-
/**
|
|
338
|
-
* Creates a new `Shadow` instance with the same value as the original and
|
|
339
|
-
* deeply referentially non-equal. Optionally replaces child elements based
|
|
340
|
-
* on a predicate.
|
|
341
|
-
*
|
|
342
|
-
* @remarks
|
|
343
|
-
* The clone will have the same `externalId` as the original.
|
|
344
|
-
* The clone will *not* get `extraData` from the original, instead it will be
|
|
345
|
-
* `undefined`.
|
|
346
|
-
*/
|
|
347
|
-
function clone(node: Shadow, options?: ElementReplacementOptions, device?: Device): Shadow;
|
|
348
|
-
/**
|
|
349
|
-
* Creates a new `Node` instance with the same value as the original and
|
|
350
|
-
* deeply referentially non-equal. Optionally replaces child elements based
|
|
351
|
-
* on a predicate.
|
|
352
|
-
*
|
|
353
|
-
* @remarks
|
|
354
|
-
* The clone will have the same `externalId` as the original.
|
|
355
|
-
* The clone will *not* get `extraData` from the original, instead it will be
|
|
356
|
-
* `undefined`.
|
|
357
|
-
*/
|
|
358
|
-
function clone(node: Node, options?: ElementReplacementOptions, device?: Device): Node;
|
|
359
|
-
/**
|
|
360
|
-
* @internal
|
|
361
|
-
*/
|
|
362
|
-
function cloneNode(node: Node, options?: ElementReplacementOptions, device?: Device): Trampoline<Node>;
|
|
363
|
-
const getNodesBetween: typeof traversal.getNodesBetween;
|
|
364
|
-
const hasBox: typeof predicate.hasBox, hasChild: typeof predicate.hasChild, hasDescendant: typeof predicate.hasDescendant, hasInclusiveDescendant: typeof predicate.hasInclusiveDescendant, hasTextContent: typeof predicate.hasTextContent, isRoot: typeof predicate.isRoot;
|
|
365
245
|
}
|
|
366
246
|
//# sourceMappingURL=node.d.ts.map
|
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
import { Cache } from "@siteimprove/alfa-cache";
|
|
2
1
|
import { Comparable, Comparison, } from "@siteimprove/alfa-comparable";
|
|
3
2
|
import { Flags } from "@siteimprove/alfa-flags";
|
|
4
3
|
import { Serializable } from "@siteimprove/alfa-json";
|
|
5
4
|
import { Lazy } from "@siteimprove/alfa-lazy";
|
|
6
5
|
import { Option } from "@siteimprove/alfa-option";
|
|
7
|
-
import { Selective } from "@siteimprove/alfa-selective";
|
|
8
6
|
import { Sequence } from "@siteimprove/alfa-sequence";
|
|
9
7
|
import { String } from "@siteimprove/alfa-string";
|
|
10
8
|
import * as json from "@siteimprove/alfa-json";
|
|
11
9
|
import * as tree from "@siteimprove/alfa-tree";
|
|
12
|
-
import { Attribute, Comment, Document, Element, Fragment, Shadow, Slot, Slotable, Text, Type, } from "./index.js";
|
|
13
|
-
import * as predicate from "./node/predicate.js";
|
|
14
|
-
import * as traversal from "./node/traversal.js";
|
|
15
10
|
/**
|
|
16
11
|
* @public
|
|
17
12
|
*/
|
|
18
|
-
export class
|
|
13
|
+
export class BaseNode extends tree.Node {
|
|
19
14
|
constructor(children, type, externalId, internalId, extraData) {
|
|
20
15
|
super(children, type, externalId, internalId, extraData);
|
|
21
16
|
}
|
|
22
17
|
/**
|
|
23
18
|
* {@link https://dom.spec.whatwg.org/#concept-descendant-text-content}
|
|
24
19
|
*/
|
|
25
|
-
textContent(options =
|
|
26
|
-
return String.flatten(this.descendants(options).filter(
|
|
20
|
+
textContent(options = BaseNode.Traversal.empty) {
|
|
21
|
+
return String.flatten(this.descendants(options).filter(isText).join(""));
|
|
27
22
|
}
|
|
28
23
|
/**
|
|
29
24
|
* Construct a sequence of descendants of this node sorted by tab index. Only
|
|
@@ -46,7 +41,7 @@ export class Node extends tree.Node {
|
|
|
46
41
|
* tabIndexes.
|
|
47
42
|
*/
|
|
48
43
|
function candidates(node) {
|
|
49
|
-
if (
|
|
44
|
+
if (isElement(node)) {
|
|
50
45
|
const element = node;
|
|
51
46
|
const tabIndex = element.tabIndex();
|
|
52
47
|
// If the element is a shadow host that doesn't block keyboard navigation
|
|
@@ -67,9 +62,9 @@ export class Node extends tree.Node {
|
|
|
67
62
|
return Sequence.of([element, tabIndex]);
|
|
68
63
|
}
|
|
69
64
|
// If the element is a slot, we replace it by its assigned nodes.
|
|
70
|
-
if (
|
|
65
|
+
if (isSlot(element)) {
|
|
71
66
|
return Sequence.from(element.assignedNodes())
|
|
72
|
-
.filter(
|
|
67
|
+
.filter(isElement)
|
|
73
68
|
.map((element) => [element, tabIndex]);
|
|
74
69
|
}
|
|
75
70
|
// If the element is keyboard focusable, record it and recurse.
|
|
@@ -138,20 +133,33 @@ export class Node extends tree.Node {
|
|
|
138
133
|
}
|
|
139
134
|
return candidates(this).sortWith(comparer).flatMap(expand);
|
|
140
135
|
}
|
|
141
|
-
|
|
136
|
+
/**
|
|
137
|
+
* @privateRemarks
|
|
138
|
+
* The type assertions to `Node` in here are technically incorrect.
|
|
139
|
+
* BaseNode could be extended to another class which is then not added to the
|
|
140
|
+
* Node union, in which case the assertions would be wrong. This scenario is
|
|
141
|
+
* however quite unlikely given that BaseNode is not exported out of this
|
|
142
|
+
* package. So it is only a matter of us not doing so, which sound OK enough.
|
|
143
|
+
* It is not possible at this level to do any sort of runtime type checking
|
|
144
|
+
* without creating circular dependencies, and the parent method here has
|
|
145
|
+
* to extends the one in `alfa-tree/Node`.
|
|
146
|
+
*/
|
|
147
|
+
parent(options = BaseNode.Traversal.empty) {
|
|
142
148
|
const parent = this._parent;
|
|
143
149
|
// If we traverse the flat tree, we want to jump over shadow roots.
|
|
144
|
-
if (options.isSet(
|
|
150
|
+
if (options.isSet(BaseNode.Traversal.flattened)) {
|
|
145
151
|
return parent.flatMap((parent) => {
|
|
146
|
-
if (
|
|
152
|
+
if (isShadow(parent)) {
|
|
147
153
|
return parent.host;
|
|
148
154
|
}
|
|
149
155
|
// Additionally, if this is a slottable light child of a shadow host, we want
|
|
150
156
|
// to search for where it is slotted, and return that parent instead.
|
|
151
|
-
if (
|
|
157
|
+
if (isElement(parent) &&
|
|
152
158
|
parent.shadow.isSome() &&
|
|
153
|
-
|
|
154
|
-
return this
|
|
159
|
+
isSlotable(this)) {
|
|
160
|
+
return this
|
|
161
|
+
.assignedSlot()
|
|
162
|
+
.flatMap((slot) => slot.parent(options));
|
|
155
163
|
}
|
|
156
164
|
return Option.of(parent);
|
|
157
165
|
});
|
|
@@ -182,7 +190,7 @@ export class Node extends tree.Node {
|
|
|
182
190
|
// For the sake of simplicity, and until we encounter errors due to this,
|
|
183
191
|
// we accept the risk of caching the value assuming that it will only be
|
|
184
192
|
// computed on fully frozen trees.
|
|
185
|
-
path(options =
|
|
193
|
+
path(options = BaseNode.Traversal.empty) {
|
|
186
194
|
if (this._path[options.value] == undefined) {
|
|
187
195
|
this._path[options.value] = this._internalPath(options);
|
|
188
196
|
}
|
|
@@ -193,11 +201,15 @@ export class Node extends tree.Node {
|
|
|
193
201
|
}
|
|
194
202
|
toJSON(options) {
|
|
195
203
|
const verbosity = options?.verbosity ?? json.Serializable.Verbosity.Medium;
|
|
204
|
+
// `super.toJSON` types the children as tree.Node.JSON, but we know they
|
|
205
|
+
// are generated by applying `#toJSON` on each child, and children are
|
|
206
|
+
// here forced to be Node.
|
|
207
|
+
const base = super.toJSON(options);
|
|
196
208
|
return {
|
|
197
|
-
...
|
|
209
|
+
...base,
|
|
198
210
|
...(json.Serializable.Verbosity.Minimal < verbosity &&
|
|
199
211
|
verbosity < json.Serializable.Verbosity.Medium
|
|
200
|
-
? { path: this.path(
|
|
212
|
+
? { path: this.path(BaseNode.composedNested) }
|
|
201
213
|
: {}),
|
|
202
214
|
};
|
|
203
215
|
}
|
|
@@ -228,89 +240,42 @@ export class Node extends tree.Node {
|
|
|
228
240
|
/**
|
|
229
241
|
* @public
|
|
230
242
|
*/
|
|
231
|
-
(function (
|
|
232
|
-
|
|
233
|
-
return value instanceof Node;
|
|
234
|
-
}
|
|
235
|
-
Node.isNode = isNode;
|
|
236
|
-
Node.Traversal = Flags.named("DOM traversal", "composed", "flattened", "nested");
|
|
243
|
+
(function (BaseNode) {
|
|
244
|
+
BaseNode.Traversal = Flags.named("DOM traversal", "composed", "flattened", "nested");
|
|
237
245
|
/**
|
|
238
246
|
* Traversal options to traverse the flat tree.
|
|
239
247
|
*
|
|
240
248
|
* {@link https://drafts.csswg.org/css-scoping-1/#flattening}
|
|
241
249
|
*/
|
|
242
|
-
|
|
250
|
+
BaseNode.flatTree = BaseNode.Traversal.of("flattened");
|
|
243
251
|
/**
|
|
244
252
|
* Traversal options to traverse all relevant nodes (flat tree and inside
|
|
245
253
|
* nested browsing container), a very frequent use case.
|
|
246
254
|
*/
|
|
247
|
-
|
|
255
|
+
BaseNode.fullTree = BaseNode.Traversal.of("flattened", "nested");
|
|
248
256
|
/**
|
|
249
257
|
* Traversal options to traverse in shadow-including tree order and inside
|
|
250
258
|
* nested browsing context container, a common use case.
|
|
251
259
|
*/
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
return Text.fromText(json, device);
|
|
274
|
-
case "comment":
|
|
275
|
-
return Comment.fromComment(json);
|
|
276
|
-
case "document":
|
|
277
|
-
return Document.fromDocument(json, device);
|
|
278
|
-
case "type":
|
|
279
|
-
return Type.fromType(json);
|
|
280
|
-
case "fragment":
|
|
281
|
-
return Fragment.fromFragment(json, device);
|
|
282
|
-
default:
|
|
283
|
-
throw new Error(`Unexpected node of type: ${json.type}`);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
Node.fromNode = fromNode;
|
|
287
|
-
function clone(node, options, device) {
|
|
288
|
-
return cloneNode(node, options, device).run();
|
|
289
|
-
}
|
|
290
|
-
Node.clone = clone;
|
|
291
|
-
/**
|
|
292
|
-
* @internal
|
|
293
|
-
*/
|
|
294
|
-
function cloneNode(node, options = {
|
|
295
|
-
predicate: () => false,
|
|
296
|
-
newElements: [],
|
|
297
|
-
}, device) {
|
|
298
|
-
return Selective.of(node)
|
|
299
|
-
.if(Element.isElement, Element.cloneElement(options, device))
|
|
300
|
-
.if(Attribute.isAttribute, Attribute.cloneAttribute)
|
|
301
|
-
.if(Text.isText, Text.cloneText(device))
|
|
302
|
-
.if(Comment.isComment, Comment.cloneComment)
|
|
303
|
-
.if(Document.isDocument, Document.cloneDocument(options, device))
|
|
304
|
-
.if(Type.isType, Type.cloneType)
|
|
305
|
-
.if(Fragment.isFragment, Fragment.cloneFragment(options, device))
|
|
306
|
-
.if(Shadow.isShadow, Shadow.cloneShadow(options, device))
|
|
307
|
-
.else(() => {
|
|
308
|
-
throw new Error(`Unexpected node of type: ${node.type}`);
|
|
309
|
-
})
|
|
310
|
-
.get();
|
|
311
|
-
}
|
|
312
|
-
Node.cloneNode = cloneNode;
|
|
313
|
-
Node.getNodesBetween = traversal.getNodesBetween;
|
|
314
|
-
Node.hasBox = predicate.hasBox, Node.hasChild = predicate.hasChild, Node.hasDescendant = predicate.hasDescendant, Node.hasInclusiveDescendant = predicate.hasInclusiveDescendant, Node.hasTextContent = predicate.hasTextContent, Node.isRoot = predicate.isRoot;
|
|
315
|
-
})(Node || (Node = {}));
|
|
260
|
+
BaseNode.composedNested = BaseNode.Traversal.of("composed", "nested");
|
|
261
|
+
})(BaseNode || (BaseNode = {}));
|
|
262
|
+
/*
|
|
263
|
+
* Sub-nodes type guards, we need to duplicate them to avoid circular references.
|
|
264
|
+
* Here, we only use the differentiating `type` property.
|
|
265
|
+
*/
|
|
266
|
+
function isElement(node) {
|
|
267
|
+
return node.type === "element";
|
|
268
|
+
}
|
|
269
|
+
function isSlot(element) {
|
|
270
|
+
return element.name === "slot";
|
|
271
|
+
}
|
|
272
|
+
function isShadow(node) {
|
|
273
|
+
return node.type === "shadow";
|
|
274
|
+
}
|
|
275
|
+
function isSlotable(node) {
|
|
276
|
+
return isElement(node) || isText(node);
|
|
277
|
+
}
|
|
278
|
+
function isText(node) {
|
|
279
|
+
return node.type === "text";
|
|
280
|
+
}
|
|
316
281
|
//# sourceMappingURL=node.js.map
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { Device } from "@siteimprove/alfa-device";
|
|
2
2
|
import type { Predicate } from "@siteimprove/alfa-predicate";
|
|
3
3
|
import type { Rectangle } from "@siteimprove/alfa-rectangle";
|
|
4
|
-
import type { Element } from "../
|
|
5
|
-
import type { Text } from "../text.js";
|
|
4
|
+
import type { Element, Text } from "../index.js";
|
|
6
5
|
/**
|
|
7
6
|
* @public
|
|
8
7
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseNode } from "../node.js";
|
|
2
2
|
/**
|
|
3
3
|
* @public
|
|
4
4
|
*/
|
|
5
|
-
export function hasChild(predicate, options =
|
|
5
|
+
export function hasChild(predicate, options = BaseNode.Traversal.empty) {
|
|
6
6
|
return (node) => node.children(options).some(predicate);
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=has-child.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseNode } from "../node.js";
|
|
2
2
|
/**
|
|
3
3
|
* @public
|
|
4
4
|
*/
|
|
5
|
-
export function hasDescendant(predicate, options =
|
|
5
|
+
export function hasDescendant(predicate, options = BaseNode.Traversal.empty) {
|
|
6
6
|
return (node) => node.descendants(options).some(predicate);
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=has-descendant.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseNode } from "../node.js";
|
|
2
2
|
/**
|
|
3
3
|
* @public
|
|
4
4
|
*/
|
|
5
|
-
export function hasInclusiveDescendant(predicate, options =
|
|
5
|
+
export function hasInclusiveDescendant(predicate, options = BaseNode.Traversal.empty) {
|
|
6
6
|
return (node) => node.inclusiveDescendants(options).some(predicate);
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=has-inclusive-descendant.js.map
|