@siteimprove/alfa-dom 0.113.0 → 0.114.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/CHANGELOG.md +12 -0
- package/dist/node/element/predicate/is-content.d.ts +3 -2
- package/dist/node/element/predicate/is-content.js +3 -2
- package/dist/node/index.d.ts +6 -8
- package/dist/node/index.js +5 -5
- package/dist/node/predicate/has-child.d.ts +1 -1
- package/dist/node/predicate/has-child.js +3 -2
- package/dist/node/predicate/has-descendant.d.ts +1 -1
- package/dist/node/predicate/has-descendant.js +3 -2
- package/dist/node/predicate/has-inclusive-descendant.d.ts +1 -1
- package/dist/node/predicate/has-inclusive-descendant.js +3 -2
- package/dist/node/predicate/has-text-content.d.ts +1 -1
- package/dist/node/predicate/has-text-content.js +3 -2
- package/dist/node/query/descendants.d.ts +9 -9
- package/dist/node/query/element-id-map.d.ts +2 -2
- package/dist/node/query/index.d.ts +3 -3
- package/dist/node/slotable/element.d.ts +1 -1
- package/dist/node/slotable/element.js +1 -1
- package/dist/node/traversal/get-nodes-between.d.ts +1 -1
- package/dist/node/traversal/get-nodes-between.js +29 -30
- package/dist/node/traversal/lowest-common-ancestor.d.ts +2 -2
- package/dist/node/traversal/lowest-common-ancestor.js +3 -2
- package/package.json +28 -28
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @siteimprove/alfa-dom
|
|
2
2
|
|
|
3
|
+
## 0.114.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- **Fixed:** `fullTree` as default traversal in getNodesBetween has been restored after being changed to `Traversal.empty` in #2040. ([#2050](https://github.com/Siteimprove/alfa/pull/2050))
|
|
8
|
+
|
|
9
|
+
## 0.114.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- **Breaking:** Functions no longer accept injected default traversal. Defaults are set in the function signatures. ([#2049](https://github.com/Siteimprove/alfa/pull/2049))
|
|
14
|
+
|
|
3
15
|
## 0.113.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Predicate } from "@siteimprove/alfa-predicate";
|
|
2
2
|
import { Refinement } from "@siteimprove/alfa-refinement";
|
|
3
3
|
import type { Element } from "../../slotable/element.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { Node } from "../../index.js";
|
|
5
|
+
import { BaseNode } from "../../node.js";
|
|
5
6
|
/**
|
|
6
7
|
* A node is actual content (not just a container) if it has no children,
|
|
7
8
|
* or if it is a replaced element (assumed to be replaced by actual content).
|
|
8
9
|
*
|
|
9
10
|
* @public
|
|
10
11
|
*/
|
|
11
|
-
export declare function isContent(isElement: Refinement<unknown, Element
|
|
12
|
+
export declare function isContent(isElement: Refinement<unknown, Element>): (options: Node.Traversal) => Predicate<BaseNode>;
|
|
12
13
|
//# sourceMappingURL=is-content.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Predicate } from "@siteimprove/alfa-predicate";
|
|
2
2
|
import { Refinement } from "@siteimprove/alfa-refinement";
|
|
3
|
+
import { BaseNode } from "../../node.js";
|
|
3
4
|
import { isReplaced } from "./is-replaced.js";
|
|
4
5
|
const { or } = Predicate;
|
|
5
6
|
const { and } = Refinement;
|
|
@@ -9,7 +10,7 @@ const { and } = Refinement;
|
|
|
9
10
|
*
|
|
10
11
|
* @public
|
|
11
12
|
*/
|
|
12
|
-
export function isContent(isElement
|
|
13
|
-
return (options =
|
|
13
|
+
export function isContent(isElement) {
|
|
14
|
+
return (options = BaseNode.Traversal.empty) => or((node) => node.children(options).isEmpty(), and(isElement, isReplaced));
|
|
14
15
|
}
|
|
15
16
|
//# sourceMappingURL=is-content.js.map
|
package/dist/node/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { Element, Text } from "./slotable/index.js";
|
|
|
10
10
|
import { Fragment } from "./fragment.js";
|
|
11
11
|
import { Type } from "./type.js";
|
|
12
12
|
import * as predicate from "./predicate/index.js";
|
|
13
|
+
import * as traversal from "./traversal/index.js";
|
|
13
14
|
export * from "./attribute.js";
|
|
14
15
|
export * from "./comment.js";
|
|
15
16
|
export * from "./document.js";
|
|
@@ -43,14 +44,11 @@ export declare namespace Node {
|
|
|
43
44
|
* @internal
|
|
44
45
|
*/
|
|
45
46
|
function fromNode(json: JSON, device?: Device): Trampoline<Node>;
|
|
46
|
-
const getNodesBetween:
|
|
47
|
-
includeFirst: boolean;
|
|
48
|
-
includeSecond: boolean;
|
|
49
|
-
}) => import("@siteimprove/alfa-sequence").Sequence<Node>;
|
|
47
|
+
const getNodesBetween: typeof traversal.getNodesBetween;
|
|
50
48
|
const hasBox: typeof predicate.hasBox, isRoot: typeof predicate.isRoot;
|
|
51
|
-
const hasChild:
|
|
52
|
-
const hasDescendant:
|
|
53
|
-
const hasInclusiveDescendant:
|
|
54
|
-
const hasTextContent:
|
|
49
|
+
const hasChild: typeof predicate.hasChild;
|
|
50
|
+
const hasDescendant: typeof predicate.hasDescendant;
|
|
51
|
+
const hasInclusiveDescendant: typeof predicate.hasInclusiveDescendant;
|
|
52
|
+
const hasTextContent: typeof predicate.hasTextContent;
|
|
55
53
|
}
|
|
56
54
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/node/index.js
CHANGED
|
@@ -64,11 +64,11 @@ export var Node;
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
Node.fromNode = fromNode;
|
|
67
|
-
Node.getNodesBetween = traversal.getNodesBetween
|
|
67
|
+
Node.getNodesBetween = traversal.getNodesBetween;
|
|
68
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
|
|
69
|
+
Node.hasChild = predicate.hasChild;
|
|
70
|
+
Node.hasDescendant = predicate.hasDescendant;
|
|
71
|
+
Node.hasInclusiveDescendant = predicate.hasInclusiveDescendant;
|
|
72
|
+
Node.hasTextContent = predicate.hasTextContent;
|
|
73
73
|
})(Node || (Node = {}));
|
|
74
74
|
//# sourceMappingURL=index.js.map
|
|
@@ -3,5 +3,5 @@ import type { Node } from "../index.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export declare function hasChild(
|
|
6
|
+
export declare function hasChild(predicate: Predicate<Node>, options?: Node.Traversal): Predicate<Node>;
|
|
7
7
|
//# sourceMappingURL=has-child.d.ts.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { BaseNode } from "../node.js";
|
|
1
2
|
/**
|
|
2
3
|
* @public
|
|
3
4
|
*/
|
|
4
|
-
export function hasChild(
|
|
5
|
-
return (
|
|
5
|
+
export function hasChild(predicate, options = BaseNode.Traversal.empty) {
|
|
6
|
+
return (node) => node.children(options).some(predicate);
|
|
6
7
|
}
|
|
7
8
|
//# sourceMappingURL=has-child.js.map
|
|
@@ -3,5 +3,5 @@ import type { Node } from "../index.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export declare function hasDescendant(
|
|
6
|
+
export declare function hasDescendant(predicate: Predicate<Node>, options?: Node.Traversal): Predicate<Node>;
|
|
7
7
|
//# sourceMappingURL=has-descendant.d.ts.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { BaseNode } from "../node.js";
|
|
1
2
|
/**
|
|
2
3
|
* @public
|
|
3
4
|
*/
|
|
4
|
-
export function hasDescendant(
|
|
5
|
-
return (
|
|
5
|
+
export function hasDescendant(predicate, options = BaseNode.Traversal.empty) {
|
|
6
|
+
return (node) => node.descendants(options).some(predicate);
|
|
6
7
|
}
|
|
7
8
|
//# sourceMappingURL=has-descendant.js.map
|
|
@@ -3,5 +3,5 @@ import type { Node } from "../index.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export declare function hasInclusiveDescendant(
|
|
6
|
+
export declare function hasInclusiveDescendant(predicate: Predicate<Node>, options?: Node.Traversal): Predicate<Node>;
|
|
7
7
|
//# sourceMappingURL=has-inclusive-descendant.d.ts.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { BaseNode } from "../node.js";
|
|
1
2
|
/**
|
|
2
3
|
* @public
|
|
3
4
|
*/
|
|
4
|
-
export function hasInclusiveDescendant(
|
|
5
|
-
return (
|
|
5
|
+
export function hasInclusiveDescendant(predicate, options = BaseNode.Traversal.empty) {
|
|
6
|
+
return (node) => node.inclusiveDescendants(options).some(predicate);
|
|
6
7
|
}
|
|
7
8
|
//# sourceMappingURL=has-inclusive-descendant.js.map
|
|
@@ -3,5 +3,5 @@ import type { Node } from "../index.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export declare function hasTextContent(
|
|
6
|
+
export declare function hasTextContent(predicate?: Predicate<string>, options?: Node.Traversal): Predicate<Node>;
|
|
7
7
|
//# sourceMappingURL=has-text-content.d.ts.map
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
2
2
|
import { Predicate } from "@siteimprove/alfa-predicate";
|
|
3
|
+
import { BaseNode } from "../node.js";
|
|
3
4
|
const { isEmpty } = Iterable;
|
|
4
5
|
const { not } = Predicate;
|
|
5
6
|
/**
|
|
6
7
|
* @public
|
|
7
8
|
*/
|
|
8
|
-
export function hasTextContent(
|
|
9
|
-
return (
|
|
9
|
+
export function hasTextContent(predicate = not(isEmpty), options = BaseNode.Traversal.empty) {
|
|
10
|
+
return (node) => predicate(node.textContent(options));
|
|
10
11
|
}
|
|
11
12
|
//# sourceMappingURL=has-text-content.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Predicate } from "@siteimprove/alfa-predicate";
|
|
2
2
|
import type { Refinement } from "@siteimprove/alfa-refinement";
|
|
3
3
|
import { Sequence } from "@siteimprove/alfa-sequence";
|
|
4
|
-
import {
|
|
4
|
+
import type { Node } from "../index.js";
|
|
5
5
|
import { Element, Text } from "../slotable/index.js";
|
|
6
6
|
/**
|
|
7
7
|
* Get all descendants of a node that satisfy a given refinement.
|
|
@@ -12,7 +12,7 @@ import { Element, Text } from "../slotable/index.js";
|
|
|
12
12
|
*
|
|
13
13
|
* @public
|
|
14
14
|
*/
|
|
15
|
-
export declare function getDescendants<T extends
|
|
15
|
+
export declare function getDescendants<T extends Node>(refinement: Refinement<Node, T>): (node: Node, options?: Node.Traversal) => Sequence<T>;
|
|
16
16
|
/**
|
|
17
17
|
* Get all descendants of a node that satisfy a given predicate.
|
|
18
18
|
*
|
|
@@ -22,22 +22,22 @@ export declare function getDescendants<T extends BaseNode>(refinement: Refinemen
|
|
|
22
22
|
*
|
|
23
23
|
* @public
|
|
24
24
|
*/
|
|
25
|
-
export declare function getDescendants(predicate: Predicate<
|
|
25
|
+
export declare function getDescendants(predicate: Predicate<Node>): (node: Node, options?: Node.Traversal) => Sequence<Node>;
|
|
26
26
|
/**
|
|
27
27
|
* @public
|
|
28
28
|
*/
|
|
29
|
-
export declare const getElementDescendants: (node:
|
|
29
|
+
export declare const getElementDescendants: (node: Node, options?: Node.Traversal) => Sequence<Element<string>>;
|
|
30
30
|
/**
|
|
31
31
|
* @public
|
|
32
32
|
*/
|
|
33
|
-
export declare function getInclusiveElementDescendants(node: Element, options?:
|
|
33
|
+
export declare function getInclusiveElementDescendants(node: Element, options?: Node.Traversal): Sequence<Element>;
|
|
34
34
|
/**
|
|
35
35
|
* A group of text nodes with an associated label.
|
|
36
36
|
*
|
|
37
37
|
* @public
|
|
38
38
|
*/
|
|
39
39
|
export interface TextGroup {
|
|
40
|
-
node:
|
|
40
|
+
node: Node;
|
|
41
41
|
label: string;
|
|
42
42
|
text: Sequence<Text>;
|
|
43
43
|
}
|
|
@@ -46,8 +46,8 @@ export interface TextGroup {
|
|
|
46
46
|
*
|
|
47
47
|
* @public
|
|
48
48
|
*/
|
|
49
|
-
export interface TextGroupOptions<N extends
|
|
50
|
-
startsGroup: Refinement<
|
|
49
|
+
export interface TextGroupOptions<N extends Node = Node> {
|
|
50
|
+
startsGroup: Refinement<Node, N>;
|
|
51
51
|
getLabel: (node: N) => string;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
@@ -63,5 +63,5 @@ export interface TextGroupOptions<N extends BaseNode = BaseNode> {
|
|
|
63
63
|
*
|
|
64
64
|
* @public
|
|
65
65
|
*/
|
|
66
|
-
export declare function getTextDescendants<N extends
|
|
66
|
+
export declare function getTextDescendants<N extends Node = Node>(textOptions?: TextGroupOptions<N>): (node: Node, options?: Node.Traversal) => Sequence<Text | TextGroup>;
|
|
67
67
|
//# sourceMappingURL=descendants.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Map } from "@siteimprove/alfa-map";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Node } from "../index.js";
|
|
3
3
|
import type { Element } from "../slotable/element.js";
|
|
4
4
|
/**
|
|
5
5
|
* Returns a map from id to elements, in the subtree rooted at a given node.
|
|
@@ -10,5 +10,5 @@ import type { Element } from "../slotable/element.js";
|
|
|
10
10
|
*
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
|
-
export declare function getElementIdMap(node:
|
|
13
|
+
export declare function getElementIdMap(node: Node): Map<string, Element>;
|
|
14
14
|
//# sourceMappingURL=element-id-map.d.ts.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as descendants from "./descendants.js";
|
|
2
2
|
import * as elementIdMap from "./element-id-map.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Node } from "../index.js";
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
7
|
export declare namespace Query {
|
|
8
8
|
const getDescendants: typeof descendants.getDescendants;
|
|
9
|
-
const getElementDescendants: (node:
|
|
9
|
+
const getElementDescendants: (node: Node, options?: Node.Traversal) => import("@siteimprove/alfa-sequence").Sequence<import("../index.js").Element<string>>;
|
|
10
10
|
const getInclusiveElementDescendants: typeof descendants.getInclusiveElementDescendants;
|
|
11
11
|
const getTextDescendants: typeof descendants.getTextDescendants;
|
|
12
12
|
const getElementIdMap: typeof elementIdMap.getElementIdMap;
|
|
13
13
|
type TextGroup = descendants.TextGroup;
|
|
14
|
-
type TextGroupOptions<N extends
|
|
14
|
+
type TextGroupOptions<N extends Node = Node> = descendants.TextGroupOptions<N>;
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -128,7 +128,7 @@ export declare namespace Element {
|
|
|
128
128
|
const hasAttribute: typeof predicate.hasAttribute, hasDisplaySize: typeof predicate.hasDisplaySize, hasId: typeof predicate.hasId, hasInputType: typeof predicate.hasInputType, hasName: typeof predicate.hasName, hasNamespace: typeof predicate.hasNamespace, hasTabIndex: typeof predicate.hasTabIndex, isBrowsingContextContainer: typeof predicate.isBrowsingContextContainer, isDraggable: typeof predicate.isDraggable, isEditingHost: typeof predicate.isEditingHost, isSuggestedFocusable: typeof predicate.isSuggestedFocusable, isReplaced: typeof predicate.isReplaced;
|
|
129
129
|
const hasUniqueId: Predicate<Element<string>>;
|
|
130
130
|
const isActuallyDisabled: Predicate<Element<string>>;
|
|
131
|
-
const isContent: (options
|
|
131
|
+
const isContent: (options: Node.Traversal) => Predicate<BaseNode>;
|
|
132
132
|
const isDocumentElement: import("@siteimprove/alfa-refinement").Refinement<unknown, Element<"html">>;
|
|
133
133
|
const isFallback: Predicate<BaseNode<string>>;
|
|
134
134
|
const isScopedTo: (name: string, ...rest: Array<string>) => Predicate<Element>;
|
|
@@ -345,7 +345,7 @@ export class Element extends Slotable {
|
|
|
345
345
|
Element.hasAttribute = predicate.hasAttribute, Element.hasDisplaySize = predicate.hasDisplaySize, Element.hasId = predicate.hasId, Element.hasInputType = predicate.hasInputType, Element.hasName = predicate.hasName, Element.hasNamespace = predicate.hasNamespace, Element.hasTabIndex = predicate.hasTabIndex, Element.isBrowsingContextContainer = predicate.isBrowsingContextContainer, Element.isDraggable = predicate.isDraggable, Element.isEditingHost = predicate.isEditingHost, Element.isSuggestedFocusable = predicate.isSuggestedFocusable, Element.isReplaced = predicate.isReplaced;
|
|
346
346
|
Element.hasUniqueId = predicate.hasUniqueId(isElement);
|
|
347
347
|
Element.isActuallyDisabled = predicate.isActuallyDisabled(isElement);
|
|
348
|
-
Element.isContent = predicate.isContent(isElement
|
|
348
|
+
Element.isContent = predicate.isContent(isElement);
|
|
349
349
|
Element.isDocumentElement = predicate.isDocumentElement(isElement);
|
|
350
350
|
Element.isFallback = predicate.isFallback(isElement);
|
|
351
351
|
Element.isScopedTo = predicate.isScopedTo(isElement);
|
|
@@ -15,7 +15,7 @@ import type { Node } from "../index.js";
|
|
|
15
15
|
*
|
|
16
16
|
* @public
|
|
17
17
|
*/
|
|
18
|
-
export declare function getNodesBetween(
|
|
18
|
+
export declare function getNodesBetween(node1: Node, node2: Node, includeOptions?: Options, treeOptions?: Node.Traversal): Sequence<Node>;
|
|
19
19
|
type Options = {
|
|
20
20
|
includeFirst: boolean;
|
|
21
21
|
includeSecond: boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Predicate } from "@siteimprove/alfa-predicate";
|
|
2
2
|
import { Sequence } from "@siteimprove/alfa-sequence";
|
|
3
|
+
import { BaseNode } from "../node.js";
|
|
3
4
|
import { lowestCommonAncestor } from "./lowest-common-ancestor.js";
|
|
4
5
|
const { equals, or } = Predicate;
|
|
5
6
|
/**
|
|
@@ -17,43 +18,41 @@ const { equals, or } = Predicate;
|
|
|
17
18
|
*
|
|
18
19
|
* @public
|
|
19
20
|
*/
|
|
20
|
-
export function getNodesBetween(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (between.isEmpty()) {
|
|
25
|
-
return between;
|
|
26
|
-
}
|
|
27
|
-
// Do we keep the first node or skip its subtree?
|
|
28
|
-
if (!includeOptions.includeFirst) {
|
|
29
|
-
// By previous test, between is not empty
|
|
30
|
-
const first = between.first().getUnsafe();
|
|
31
|
-
// The 'first node after the subtree rooted at first' is the next sibling
|
|
32
|
-
// of the closest ancestor having one.
|
|
33
|
-
between = first
|
|
34
|
-
// Closest ancestor with a next sibling.
|
|
35
|
-
.closest((ancestor) => ancestor.next(treeOptions).isSome(), treeOptions)
|
|
36
|
-
// Get that sibling.
|
|
37
|
-
.flatMap((node) => node.next(treeOptions))
|
|
38
|
-
// Skip everything until next.
|
|
39
|
-
.map((next) => between.skipUntil((node) => node.equals(next)))
|
|
40
|
-
// If nothing after the subtree at first, just escape.
|
|
41
|
-
.getOrElse(Sequence.empty);
|
|
42
|
-
}
|
|
43
|
-
// Do we keep the second node or remove it?
|
|
44
|
-
between =
|
|
45
|
-
includeOptions.includeSecond || between.isEmpty()
|
|
46
|
-
? between
|
|
47
|
-
: between.skipLast(1);
|
|
21
|
+
export function getNodesBetween(node1, node2, includeOptions = { includeFirst: false, includeSecond: false }, treeOptions = BaseNode.fullTree) {
|
|
22
|
+
let between = getNodesInclusivelyBetween(node1, node2, treeOptions);
|
|
23
|
+
// If somehow there is nothing between them, escape now
|
|
24
|
+
if (between.isEmpty()) {
|
|
48
25
|
return between;
|
|
49
|
-
}
|
|
26
|
+
}
|
|
27
|
+
// Do we keep the first node or skip its subtree?
|
|
28
|
+
if (!includeOptions.includeFirst) {
|
|
29
|
+
// By previous test, between is not empty
|
|
30
|
+
const first = between.first().getUnsafe();
|
|
31
|
+
// The 'first node after the subtree rooted at first' is the next sibling
|
|
32
|
+
// of the closest ancestor having one.
|
|
33
|
+
between = first
|
|
34
|
+
// Closest ancestor with a next sibling.
|
|
35
|
+
.closest((ancestor) => ancestor.next(treeOptions).isSome(), treeOptions)
|
|
36
|
+
// Get that sibling.
|
|
37
|
+
.flatMap((node) => node.next(treeOptions))
|
|
38
|
+
// Skip everything until next.
|
|
39
|
+
.map((next) => between.skipUntil((node) => node.equals(next)))
|
|
40
|
+
// If nothing after the subtree at first, just escape.
|
|
41
|
+
.getOrElse(Sequence.empty);
|
|
42
|
+
}
|
|
43
|
+
// Do we keep the second node or remove it?
|
|
44
|
+
between =
|
|
45
|
+
includeOptions.includeSecond || between.isEmpty()
|
|
46
|
+
? between
|
|
47
|
+
: between.skipLast(1);
|
|
48
|
+
return between;
|
|
50
49
|
}
|
|
51
50
|
/**
|
|
52
51
|
* Get all nodes between node1 and node2, included.
|
|
53
52
|
*/
|
|
54
53
|
function getNodesInclusivelyBetween(node1, node2, treeOptions) {
|
|
55
54
|
const isFrontier = or(equals(node1), equals(node2));
|
|
56
|
-
return lowestCommonAncestor(
|
|
55
|
+
return lowestCommonAncestor(node1, node2)
|
|
57
56
|
.map((context) => context
|
|
58
57
|
.inclusiveDescendants(treeOptions)
|
|
59
58
|
.skipUntil(isFrontier)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Option } from "@siteimprove/alfa-option";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Node } from "../../index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Find the lowest common ancestor of two nodes:
|
|
5
5
|
* * get the ancestors chain of both
|
|
@@ -9,5 +9,5 @@ import type { BaseNode } from "../node.js";
|
|
|
9
9
|
*
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
export declare function lowestCommonAncestor(
|
|
12
|
+
export declare function lowestCommonAncestor(node1: Node, node2: Node, options?: Node.Traversal): Option<Node>;
|
|
13
13
|
//# sourceMappingURL=lowest-common-ancestor.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { None, Option } from "@siteimprove/alfa-option";
|
|
2
|
+
import { BaseNode } from "../node.js";
|
|
2
3
|
/**
|
|
3
4
|
* Find the lowest common ancestor of two nodes:
|
|
4
5
|
* * get the ancestors chain of both
|
|
@@ -8,8 +9,8 @@ import { None, Option } from "@siteimprove/alfa-option";
|
|
|
8
9
|
*
|
|
9
10
|
* @internal
|
|
10
11
|
*/
|
|
11
|
-
export function lowestCommonAncestor(
|
|
12
|
-
return
|
|
12
|
+
export function lowestCommonAncestor(node1, node2, options = BaseNode.Traversal.empty) {
|
|
13
|
+
return node1
|
|
13
14
|
.inclusiveAncestors(options)
|
|
14
15
|
.reverse()
|
|
15
16
|
.zip(node2.inclusiveAncestors(options).reverse())
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "http://json.schemastore.org/package",
|
|
3
3
|
"name": "@siteimprove/alfa-dom",
|
|
4
4
|
"homepage": "https://alfa.siteimprove.com",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.114.1",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "Implementations of the core DOM and CSSOM node types",
|
|
8
8
|
"repository": {
|
|
@@ -35,36 +35,36 @@
|
|
|
35
35
|
"dist/**/*.d.ts"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@siteimprove/alfa-array": "^0.
|
|
39
|
-
"@siteimprove/alfa-cache": "^0.
|
|
40
|
-
"@siteimprove/alfa-comparable": "^0.
|
|
41
|
-
"@siteimprove/alfa-css": "^0.
|
|
42
|
-
"@siteimprove/alfa-css-feature": "^0.
|
|
43
|
-
"@siteimprove/alfa-device": "^0.
|
|
44
|
-
"@siteimprove/alfa-earl": "^0.
|
|
45
|
-
"@siteimprove/alfa-equatable": "^0.
|
|
46
|
-
"@siteimprove/alfa-flags": "^0.
|
|
47
|
-
"@siteimprove/alfa-iterable": "^0.
|
|
48
|
-
"@siteimprove/alfa-json": "^0.
|
|
49
|
-
"@siteimprove/alfa-lazy": "^0.
|
|
50
|
-
"@siteimprove/alfa-map": "^0.
|
|
51
|
-
"@siteimprove/alfa-option": "^0.
|
|
52
|
-
"@siteimprove/alfa-parser": "^0.
|
|
53
|
-
"@siteimprove/alfa-predicate": "^0.
|
|
54
|
-
"@siteimprove/alfa-rectangle": "^0.
|
|
55
|
-
"@siteimprove/alfa-refinement": "^0.
|
|
56
|
-
"@siteimprove/alfa-result": "^0.
|
|
57
|
-
"@siteimprove/alfa-sarif": "^0.
|
|
58
|
-
"@siteimprove/alfa-sequence": "^0.
|
|
59
|
-
"@siteimprove/alfa-slice": "^0.
|
|
60
|
-
"@siteimprove/alfa-string": "^0.
|
|
61
|
-
"@siteimprove/alfa-trampoline": "^0.
|
|
62
|
-
"@siteimprove/alfa-tree": "^0.
|
|
38
|
+
"@siteimprove/alfa-array": "^0.114.1",
|
|
39
|
+
"@siteimprove/alfa-cache": "^0.114.1",
|
|
40
|
+
"@siteimprove/alfa-comparable": "^0.114.1",
|
|
41
|
+
"@siteimprove/alfa-css": "^0.114.1",
|
|
42
|
+
"@siteimprove/alfa-css-feature": "^0.114.1",
|
|
43
|
+
"@siteimprove/alfa-device": "^0.114.1",
|
|
44
|
+
"@siteimprove/alfa-earl": "^0.114.1",
|
|
45
|
+
"@siteimprove/alfa-equatable": "^0.114.1",
|
|
46
|
+
"@siteimprove/alfa-flags": "^0.114.1",
|
|
47
|
+
"@siteimprove/alfa-iterable": "^0.114.1",
|
|
48
|
+
"@siteimprove/alfa-json": "^0.114.1",
|
|
49
|
+
"@siteimprove/alfa-lazy": "^0.114.1",
|
|
50
|
+
"@siteimprove/alfa-map": "^0.114.1",
|
|
51
|
+
"@siteimprove/alfa-option": "^0.114.1",
|
|
52
|
+
"@siteimprove/alfa-parser": "^0.114.1",
|
|
53
|
+
"@siteimprove/alfa-predicate": "^0.114.1",
|
|
54
|
+
"@siteimprove/alfa-rectangle": "^0.114.1",
|
|
55
|
+
"@siteimprove/alfa-refinement": "^0.114.1",
|
|
56
|
+
"@siteimprove/alfa-result": "^0.114.1",
|
|
57
|
+
"@siteimprove/alfa-sarif": "^0.114.1",
|
|
58
|
+
"@siteimprove/alfa-sequence": "^0.114.1",
|
|
59
|
+
"@siteimprove/alfa-slice": "^0.114.1",
|
|
60
|
+
"@siteimprove/alfa-string": "^0.114.1",
|
|
61
|
+
"@siteimprove/alfa-trampoline": "^0.114.1",
|
|
62
|
+
"@siteimprove/alfa-tree": "^0.114.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@siteimprove/alfa-test": "^0.
|
|
65
|
+
"@siteimprove/alfa-test": "^0.114.1",
|
|
66
66
|
"@types/jsdom": "^28.0.1",
|
|
67
|
-
"jsdom": "^29.0.
|
|
67
|
+
"jsdom": "^29.0.2"
|
|
68
68
|
},
|
|
69
69
|
"publishConfig": {
|
|
70
70
|
"access": "public",
|