@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
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
2
2
|
import { Predicate } from "@siteimprove/alfa-predicate";
|
|
3
|
-
import {
|
|
3
|
+
import { BaseNode } from "../node.js";
|
|
4
4
|
const { isEmpty } = Iterable;
|
|
5
5
|
const { not } = Predicate;
|
|
6
6
|
/**
|
|
7
7
|
* @public
|
|
8
8
|
*/
|
|
9
|
-
export function hasTextContent(predicate = not(isEmpty), options =
|
|
9
|
+
export function hasTextContent(predicate = not(isEmpty), options = BaseNode.Traversal.empty) {
|
|
10
10
|
return (node) => predicate(node.textContent(options));
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=has-text-content.js.map
|
|
@@ -1,9 +1,8 @@
|
|
|
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 { Node } from "
|
|
5
|
-
import { Element } from "../
|
|
6
|
-
import { Text } from "../text.js";
|
|
4
|
+
import type { Node } from "../index.js";
|
|
5
|
+
import { Element, Text } from "../slotable/index.js";
|
|
7
6
|
/**
|
|
8
7
|
* Get all descendants of a node that satisfy a given refinement.
|
|
9
8
|
*
|
|
@@ -38,6 +37,7 @@ export declare function getInclusiveElementDescendants(node: Element, options?:
|
|
|
38
37
|
* @public
|
|
39
38
|
*/
|
|
40
39
|
export interface TextGroup {
|
|
40
|
+
node: Node;
|
|
41
41
|
label: string;
|
|
42
42
|
text: Sequence<Text>;
|
|
43
43
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Cache } from "@siteimprove/alfa-cache";
|
|
2
2
|
import { Sequence } from "@siteimprove/alfa-sequence";
|
|
3
|
-
import {
|
|
4
|
-
import { Element } from "../
|
|
5
|
-
import { Text } from "../text.js";
|
|
3
|
+
import { BaseNode } from "../node.js";
|
|
4
|
+
import { Element, Text } from "../slotable/index.js";
|
|
6
5
|
const _descendantsCache = Cache.empty();
|
|
7
6
|
export function getDescendants(predicate) {
|
|
8
|
-
return (node, options =
|
|
7
|
+
return (node, options = BaseNode.Traversal.empty) => {
|
|
9
8
|
const optionsMap = _descendantsCache
|
|
10
9
|
.get(predicate, Cache.empty)
|
|
11
10
|
.get(node, () => []);
|
|
@@ -22,7 +21,7 @@ export const getElementDescendants = getDescendants(Element.isElement);
|
|
|
22
21
|
/**
|
|
23
22
|
* @public
|
|
24
23
|
*/
|
|
25
|
-
export function getInclusiveElementDescendants(node, options =
|
|
24
|
+
export function getInclusiveElementDescendants(node, options = BaseNode.Traversal.empty) {
|
|
26
25
|
return getElementDescendants(node, options).prepend(node);
|
|
27
26
|
}
|
|
28
27
|
const _textCache = Cache.empty();
|
|
@@ -44,7 +43,7 @@ const defaultTextOptions = {
|
|
|
44
43
|
* @public
|
|
45
44
|
*/
|
|
46
45
|
export function getTextDescendants(textOptions = defaultTextOptions) {
|
|
47
|
-
return (node, options =
|
|
46
|
+
return (node, options = BaseNode.Traversal.empty) => {
|
|
48
47
|
const optionsMap = _textCache
|
|
49
48
|
.get(textOptions, Cache.empty)
|
|
50
49
|
.get(node, () => []);
|
|
@@ -60,6 +59,7 @@ function* _getTextDescendants(node, textOptions, traversalOptions) {
|
|
|
60
59
|
if (startsGroup(child)) {
|
|
61
60
|
const groupText = getDescendants(Text.isText)(child, traversalOptions);
|
|
62
61
|
yield {
|
|
62
|
+
node: child,
|
|
63
63
|
label: getLabel(child),
|
|
64
64
|
text: groupText,
|
|
65
65
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Map } from "@siteimprove/alfa-map";
|
|
2
|
-
import type { Node } from "
|
|
3
|
-
import type { Element } from "../element.js";
|
|
2
|
+
import type { Node } from "../index.js";
|
|
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.
|
|
6
6
|
*
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as descendants from "./descendants.js";
|
|
2
2
|
import * as elementIdMap from "./element-id-map.js";
|
|
3
|
-
import type { Node } from "
|
|
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: Node, options?: Node.Traversal) => import("@siteimprove/alfa-sequence").Sequence<import("../
|
|
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;
|
package/dist/node/shadow.d.ts
CHANGED
|
@@ -3,13 +3,14 @@ import { Trampoline } from "@siteimprove/alfa-trampoline";
|
|
|
3
3
|
import type { Device } from "@siteimprove/alfa-device";
|
|
4
4
|
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
5
5
|
import * as json from "@siteimprove/alfa-json";
|
|
6
|
-
import { Node } from "../node.js";
|
|
7
6
|
import { Sheet } from "../style/sheet.js";
|
|
8
|
-
import {
|
|
7
|
+
import { BaseNode } from "./node.js";
|
|
8
|
+
import type { Element } from "./slotable/index.js";
|
|
9
|
+
import type { Node } from "./index.js";
|
|
9
10
|
/**
|
|
10
11
|
* @public
|
|
11
12
|
*/
|
|
12
|
-
export declare class Shadow extends
|
|
13
|
+
export declare class Shadow extends BaseNode<"shadow"> {
|
|
13
14
|
static of(children: Iterable<Node>, style?: Iterable<Sheet>, mode?: Shadow.Mode, externalId?: string, internalId?: string, extraData?: any): Shadow;
|
|
14
15
|
static empty(): Shadow;
|
|
15
16
|
private readonly _mode;
|
|
@@ -19,15 +20,15 @@ export declare class Shadow extends Node<"shadow"> {
|
|
|
19
20
|
get mode(): Shadow.Mode;
|
|
20
21
|
get host(): Option<Element>;
|
|
21
22
|
get style(): Iterable<Sheet>;
|
|
22
|
-
parent(options?:
|
|
23
|
+
parent(options?: BaseNode.Traversal): Option<Node>;
|
|
23
24
|
/**
|
|
24
25
|
* @internal
|
|
25
26
|
**/
|
|
26
|
-
protected _internalPath(options?:
|
|
27
|
-
toJSON(options:
|
|
27
|
+
protected _internalPath(options?: BaseNode.Traversal): string;
|
|
28
|
+
toJSON(options: BaseNode.SerializationOptions & {
|
|
28
29
|
verbosity: json.Serializable.Verbosity.Minimal | json.Serializable.Verbosity.Low;
|
|
29
30
|
}): Shadow.MinimalJSON;
|
|
30
|
-
toJSON(options?:
|
|
31
|
+
toJSON(options?: BaseNode.SerializationOptions): Shadow.JSON;
|
|
31
32
|
toString(): string;
|
|
32
33
|
/**
|
|
33
34
|
* @internal
|
|
@@ -46,9 +47,9 @@ export declare namespace Shadow {
|
|
|
46
47
|
Open = "open",
|
|
47
48
|
Closed = "closed"
|
|
48
49
|
}
|
|
49
|
-
interface MinimalJSON extends
|
|
50
|
+
interface MinimalJSON extends BaseNode.JSON {
|
|
50
51
|
}
|
|
51
|
-
interface JSON extends
|
|
52
|
+
interface JSON extends BaseNode.JSON {
|
|
52
53
|
type: "shadow";
|
|
53
54
|
mode: string;
|
|
54
55
|
style: Array<Sheet.JSON>;
|
|
@@ -57,10 +58,6 @@ export declare namespace Shadow {
|
|
|
57
58
|
/**
|
|
58
59
|
* @internal
|
|
59
60
|
*/
|
|
60
|
-
function fromShadow(json: JSON, device?: Device): Trampoline<Shadow>;
|
|
61
|
-
/**
|
|
62
|
-
* @internal
|
|
63
|
-
*/
|
|
64
|
-
function cloneShadow(options: Node.ElementReplacementOptions, device?: Device): (shadow: Shadow) => Trampoline<Shadow>;
|
|
61
|
+
function fromShadow(json: JSON, fromNode: (json: Node.JSON, device?: Device) => Trampoline<Node>, device?: Device): Trampoline<Shadow>;
|
|
65
62
|
}
|
|
66
63
|
//# sourceMappingURL=shadow.d.ts.map
|
package/dist/node/shadow.js
CHANGED
|
@@ -3,13 +3,12 @@ import { String } from "@siteimprove/alfa-string";
|
|
|
3
3
|
import { Trampoline } from "@siteimprove/alfa-trampoline";
|
|
4
4
|
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
5
5
|
import * as json from "@siteimprove/alfa-json";
|
|
6
|
-
import { Node } from "../node.js";
|
|
7
6
|
import { Sheet } from "../style/sheet.js";
|
|
8
|
-
import {
|
|
7
|
+
import { BaseNode } from "./node.js";
|
|
9
8
|
/**
|
|
10
9
|
* @public
|
|
11
10
|
*/
|
|
12
|
-
export class Shadow extends
|
|
11
|
+
export class Shadow extends BaseNode {
|
|
13
12
|
static of(children, style = [], mode = Shadow.Mode.Open, externalId, internalId, extraData) {
|
|
14
13
|
return new Shadow(Array.from(children), Array.from(style), mode, externalId, internalId, extraData);
|
|
15
14
|
}
|
|
@@ -33,10 +32,10 @@ export class Shadow extends Node {
|
|
|
33
32
|
get style() {
|
|
34
33
|
return this._style;
|
|
35
34
|
}
|
|
36
|
-
parent(options =
|
|
35
|
+
parent(options = BaseNode.Traversal.empty) {
|
|
37
36
|
// We only "land" on Shadow roots when traversing the composed tree.
|
|
38
37
|
// Notably, flattening the tree "jumps" over them.
|
|
39
|
-
if (options.isSet(
|
|
38
|
+
if (options.isSet(BaseNode.Traversal.composed)) {
|
|
40
39
|
return this._host;
|
|
41
40
|
}
|
|
42
41
|
return None;
|
|
@@ -44,12 +43,12 @@ export class Shadow extends Node {
|
|
|
44
43
|
/**
|
|
45
44
|
* @internal
|
|
46
45
|
**/
|
|
47
|
-
_internalPath(options =
|
|
48
|
-
if (options.isSet(
|
|
46
|
+
_internalPath(options = BaseNode.Traversal.empty) {
|
|
47
|
+
if (options.isSet(BaseNode.Traversal.composed)) {
|
|
49
48
|
return (this._host.map((host) => host.path(options)).getOr("") +
|
|
50
49
|
"/shadow-root()");
|
|
51
50
|
}
|
|
52
|
-
if (options.isSet(
|
|
51
|
+
if (options.isSet(BaseNode.Traversal.flattened)) {
|
|
53
52
|
return this._host.map((host) => host.path(options)).getOr("/");
|
|
54
53
|
}
|
|
55
54
|
return "/";
|
|
@@ -106,23 +105,9 @@ export class Shadow extends Node {
|
|
|
106
105
|
/**
|
|
107
106
|
* @internal
|
|
108
107
|
*/
|
|
109
|
-
function fromShadow(json, device) {
|
|
110
|
-
return Trampoline.traverse(json.children ?? [], (child) =>
|
|
108
|
+
function fromShadow(json, fromNode, device) {
|
|
109
|
+
return Trampoline.traverse(json.children ?? [], (child) => fromNode(child, device)).map((children) => Shadow.of(children, json.style.map(Sheet.from), json.mode, json.externalId, json.internalId));
|
|
111
110
|
}
|
|
112
111
|
Shadow.fromShadow = fromShadow;
|
|
113
|
-
/**
|
|
114
|
-
* @internal
|
|
115
|
-
*/
|
|
116
|
-
function cloneShadow(options, device) {
|
|
117
|
-
return (shadow) => Trampoline.traverse(shadow.children(), (child) => {
|
|
118
|
-
if (Element.isElement(child) && options.predicate(child)) {
|
|
119
|
-
return Trampoline.done(Array.from(options.newElements));
|
|
120
|
-
}
|
|
121
|
-
return Node.cloneNode(child, options, device).map((node) => [node]);
|
|
122
|
-
}).map((children) => {
|
|
123
|
-
return Shadow.of(Iterable.flatten(children), shadow.style, shadow.mode, shadow.externalId, shadow.extraData, shadow.internalId);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
Shadow.cloneShadow = cloneShadow;
|
|
127
112
|
})(Shadow || (Shadow = {}));
|
|
128
113
|
//# sourceMappingURL=shadow.js.map
|
|
@@ -6,20 +6,21 @@ import { Rectangle } from "@siteimprove/alfa-rectangle";
|
|
|
6
6
|
import { Sequence } from "@siteimprove/alfa-sequence";
|
|
7
7
|
import { Trampoline } from "@siteimprove/alfa-trampoline";
|
|
8
8
|
import * as json from "@siteimprove/alfa-json";
|
|
9
|
-
import type { Namespace } from "
|
|
10
|
-
import {
|
|
11
|
-
import { Block } from "
|
|
12
|
-
import { Attribute } from "
|
|
13
|
-
import { Document } from "
|
|
14
|
-
import { Shadow } from "
|
|
15
|
-
import { Slot } from "./slot.js";
|
|
9
|
+
import type { Namespace } from "../../namespace.js";
|
|
10
|
+
import { BaseNode } from "../node.js";
|
|
11
|
+
import { Block } from "../../style/index.js";
|
|
12
|
+
import { Attribute } from "../attribute.js";
|
|
13
|
+
import { Document } from "../document.js";
|
|
14
|
+
import { Shadow } from "../shadow.js";
|
|
15
|
+
import type { Slot } from "./slot.js";
|
|
16
16
|
import { Slotable } from "./slotable.js";
|
|
17
|
-
import type
|
|
18
|
-
import * as
|
|
17
|
+
import type { Node } from "../index.js";
|
|
18
|
+
import type * as helpers from "../element/input-type.js";
|
|
19
|
+
import * as predicate from "../element/predicate/index.js";
|
|
19
20
|
/**
|
|
20
21
|
* @public
|
|
21
22
|
*/
|
|
22
|
-
export declare class Element<N extends string = string> extends
|
|
23
|
+
export declare class Element<N extends string = string> extends Slotable<"element"> {
|
|
23
24
|
static of<N extends string = string>(namespace: Option<Namespace>, prefix: Option<string>, name: N, attributes?: Iterable<Attribute>, children?: Iterable<Node>, style?: Option<Block>, box?: Option<Rectangle>, device?: Option<Device>, externalId?: string, internalId?: string, extraData?: any): Element<N>;
|
|
24
25
|
private readonly _namespace;
|
|
25
26
|
private readonly _prefix;
|
|
@@ -49,7 +50,7 @@ export declare class Element<N extends string = string> extends Node<"element">
|
|
|
49
50
|
*/
|
|
50
51
|
get classes(): Sequence<string>;
|
|
51
52
|
getBoundingBox(device: Device): Option<Rectangle>;
|
|
52
|
-
children(options?:
|
|
53
|
+
children(options?: BaseNode.Traversal): Sequence<Node>;
|
|
53
54
|
attribute<A extends string = string>(name: A): Option<Attribute<A>>;
|
|
54
55
|
attribute<A extends string = string>(predicate: Predicate<Attribute<A>>): Option<Attribute<A>>;
|
|
55
56
|
/**
|
|
@@ -78,23 +79,20 @@ export declare class Element<N extends string = string> extends Node<"element">
|
|
|
78
79
|
* {@link https://dom.spec.whatwg.org/#dom-slotable-assignedslot}
|
|
79
80
|
*/
|
|
80
81
|
assignedSlot(): Option<Slot>;
|
|
81
|
-
|
|
82
|
-
* {@link https://html.spec.whatwg.org/#dom-slot-assignednodes}
|
|
83
|
-
*/
|
|
84
|
-
assignedNodes(): Iterable<Slotable>;
|
|
82
|
+
slotableName(): string;
|
|
85
83
|
/**
|
|
86
84
|
* @internal
|
|
87
85
|
**/
|
|
88
|
-
protected _internalPath(options?:
|
|
89
|
-
toJSON(options:
|
|
86
|
+
protected _internalPath(options?: BaseNode.Traversal): string;
|
|
87
|
+
toJSON(options: BaseNode.SerializationOptions & {
|
|
90
88
|
verbosity: json.Serializable.Verbosity.Minimal | json.Serializable.Verbosity.Low;
|
|
91
89
|
}): Element.MinimalJSON;
|
|
92
|
-
toJSON(options:
|
|
90
|
+
toJSON(options: BaseNode.SerializationOptions & {
|
|
93
91
|
verbosity: json.Serializable.Verbosity.High;
|
|
94
92
|
}): Element.JSON & {
|
|
95
93
|
assignedSlot: Element.MinimalJSON | null;
|
|
96
94
|
};
|
|
97
|
-
toJSON(options?:
|
|
95
|
+
toJSON(options?: BaseNode.SerializationOptions): Element.JSON<N>;
|
|
98
96
|
toString(): string;
|
|
99
97
|
/**
|
|
100
98
|
* @internal
|
|
@@ -109,9 +107,9 @@ export declare class Element<N extends string = string> extends Node<"element">
|
|
|
109
107
|
* @public
|
|
110
108
|
*/
|
|
111
109
|
export declare namespace Element {
|
|
112
|
-
interface MinimalJSON extends
|
|
110
|
+
interface MinimalJSON extends BaseNode.JSON<"element"> {
|
|
113
111
|
}
|
|
114
|
-
interface JSON<N extends string = string> extends
|
|
112
|
+
interface JSON<N extends string = string> extends BaseNode.JSON<"element"> {
|
|
115
113
|
namespace: string | null;
|
|
116
114
|
prefix: string | null;
|
|
117
115
|
name: N;
|
|
@@ -122,15 +120,18 @@ export declare namespace Element {
|
|
|
122
120
|
box: Rectangle.JSON | null;
|
|
123
121
|
}
|
|
124
122
|
function isElement(value: unknown): value is Element;
|
|
123
|
+
function isSlot(value: unknown): value is Slot;
|
|
125
124
|
/**
|
|
126
125
|
* @internal
|
|
127
126
|
*/
|
|
128
|
-
function fromElement<N extends string = string>(json: JSON<N>, device?: Device): Trampoline<Element<N>>;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
127
|
+
function fromElement<N extends string = string>(json: JSON<N>, fromNode: (json: Node.JSON, device?: Device) => Trampoline<Node>, device?: Device): Trampoline<Element<N>>;
|
|
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
|
+
const hasUniqueId: Predicate<Element<string>>;
|
|
130
|
+
const isActuallyDisabled: Predicate<Element<string>>;
|
|
131
|
+
const isContent: (options: Node.Traversal) => Predicate<BaseNode>;
|
|
132
|
+
const isDocumentElement: import("@siteimprove/alfa-refinement").Refinement<unknown, Element<"html">>;
|
|
133
|
+
const isFallback: Predicate<BaseNode<string>>;
|
|
134
|
+
const isScopedTo: (name: string, ...rest: Array<string>) => Predicate<Element>;
|
|
134
135
|
type InputType = helpers.InputType;
|
|
135
136
|
}
|
|
136
137
|
//# sourceMappingURL=element.d.ts.map
|
|
@@ -7,21 +7,19 @@ import { Sequence } from "@siteimprove/alfa-sequence";
|
|
|
7
7
|
import { String } from "@siteimprove/alfa-string";
|
|
8
8
|
import { Trampoline } from "@siteimprove/alfa-trampoline";
|
|
9
9
|
import * as json from "@siteimprove/alfa-json";
|
|
10
|
-
import {
|
|
11
|
-
import { Block } from "
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { Shadow } from "./shadow.js";
|
|
16
|
-
import { Slot } from "./slot.js";
|
|
10
|
+
import { BaseNode } from "../node.js";
|
|
11
|
+
import { Block } from "../../style/index.js";
|
|
12
|
+
import { Attribute } from "../attribute.js";
|
|
13
|
+
import { Document } from "../document.js";
|
|
14
|
+
import { Shadow } from "../shadow.js";
|
|
17
15
|
import { Slotable } from "./slotable.js";
|
|
18
|
-
import * as predicate from "
|
|
16
|
+
import * as predicate from "../element/predicate/index.js";
|
|
19
17
|
const { isEmpty } = Iterable;
|
|
20
18
|
const { and, not, or, test } = Predicate;
|
|
21
19
|
/**
|
|
22
20
|
* @public
|
|
23
21
|
*/
|
|
24
|
-
export class Element extends
|
|
22
|
+
export class Element extends Slotable {
|
|
25
23
|
static of(namespace, prefix, name, attributes = [], children = [], style = None, box = None, device = None, externalId, internalId, extraData) {
|
|
26
24
|
return new Element(namespace, prefix, name, Array.from(attributes), Array.from(children), style, box, device, externalId, internalId, extraData);
|
|
27
25
|
}
|
|
@@ -90,18 +88,18 @@ export class Element extends Node {
|
|
|
90
88
|
getBoundingBox(device) {
|
|
91
89
|
return this._boxes.get(device);
|
|
92
90
|
}
|
|
93
|
-
children(options =
|
|
91
|
+
children(options = BaseNode.Traversal.empty) {
|
|
94
92
|
const treeChildren = this._children;
|
|
95
93
|
const children = [];
|
|
96
|
-
if (options.isSet(
|
|
94
|
+
if (options.isSet(BaseNode.Traversal.flattened)) {
|
|
97
95
|
if (this._shadow.isSome()) {
|
|
98
96
|
return this._shadow.get().children(options);
|
|
99
97
|
}
|
|
100
|
-
if (
|
|
98
|
+
if (Element.isSlot(this)) {
|
|
101
99
|
return Sequence.from(this.assignedNodes());
|
|
102
100
|
}
|
|
103
101
|
for (const child of treeChildren) {
|
|
104
|
-
if (
|
|
102
|
+
if (Element.isSlot(child)) {
|
|
105
103
|
children.push(...child.children(options));
|
|
106
104
|
}
|
|
107
105
|
else {
|
|
@@ -110,12 +108,12 @@ export class Element extends Node {
|
|
|
110
108
|
}
|
|
111
109
|
}
|
|
112
110
|
else {
|
|
113
|
-
if (options.isSet(
|
|
111
|
+
if (options.isSet(BaseNode.Traversal.composed) && this._shadow.isSome()) {
|
|
114
112
|
children.push(this._shadow.get());
|
|
115
113
|
}
|
|
116
114
|
children.push(...treeChildren);
|
|
117
115
|
}
|
|
118
|
-
if (options.isSet(
|
|
116
|
+
if (options.isSet(BaseNode.Traversal.nested) && this._content.isSome()) {
|
|
119
117
|
children.push(this._content.get());
|
|
120
118
|
}
|
|
121
119
|
return Sequence.from(children);
|
|
@@ -189,7 +187,7 @@ export class Element extends Node {
|
|
|
189
187
|
not(and(Element.hasName("dialog"), Element.hasAttribute("open"))),
|
|
190
188
|
// and with an inert ancestor.
|
|
191
189
|
(element) => element
|
|
192
|
-
.parent(
|
|
190
|
+
.parent(BaseNode.flatTree)
|
|
193
191
|
.filter(Element.isElement)
|
|
194
192
|
.some((parent) => parent.isInert()))), this);
|
|
195
193
|
}
|
|
@@ -213,13 +211,18 @@ export class Element extends Node {
|
|
|
213
211
|
* {@link https://dom.spec.whatwg.org/#dom-slotable-assignedslot}
|
|
214
212
|
*/
|
|
215
213
|
assignedSlot() {
|
|
216
|
-
|
|
214
|
+
const name = this.slotableName();
|
|
215
|
+
return this.parent()
|
|
216
|
+
.filter(Element.isElement)
|
|
217
|
+
.flatMap((parent) => parent.shadow.flatMap((shadow) => shadow
|
|
218
|
+
.descendants()
|
|
219
|
+
.filter(Element.isSlot)
|
|
220
|
+
.find((slot) => slot.slotName() === name)));
|
|
217
221
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return Slot.findSlotables(this);
|
|
222
|
+
slotableName() {
|
|
223
|
+
return this.attribute("slot")
|
|
224
|
+
.map((slot) => slot.value)
|
|
225
|
+
.getOr("");
|
|
223
226
|
}
|
|
224
227
|
/**
|
|
225
228
|
* @internal
|
|
@@ -317,48 +320,34 @@ export class Element extends Node {
|
|
|
317
320
|
return value instanceof Element;
|
|
318
321
|
}
|
|
319
322
|
Element.isElement = isElement;
|
|
323
|
+
function isSlot(value) {
|
|
324
|
+
return Element.isElement(value) && value.name === "slot";
|
|
325
|
+
}
|
|
326
|
+
Element.isSlot = isSlot;
|
|
320
327
|
/**
|
|
321
328
|
* @internal
|
|
322
329
|
*/
|
|
323
|
-
function fromElement(json, device) {
|
|
324
|
-
return Trampoline.traverse(json.children ?? [], (child) =>
|
|
330
|
+
function fromElement(json, fromNode, device) {
|
|
331
|
+
return Trampoline.traverse(json.children ?? [], (child) => fromNode(child, device)).map((children) => {
|
|
325
332
|
const element = Element.of(Option.from(json.namespace), Option.from(json.prefix), json.name, json.attributes.map((attribute) => Attribute.fromAttribute(attribute).run()), children, json.style?.length === 0
|
|
326
333
|
? None
|
|
327
334
|
: Option.from(json.style).map(Block.from), Option.from(json.box).map(Rectangle.from), Option.from(device), json.externalId, json.internalId);
|
|
328
335
|
if (json.shadow !== null) {
|
|
329
|
-
element._attachShadow(Shadow.fromShadow(json.shadow, device).run());
|
|
336
|
+
element._attachShadow(Shadow.fromShadow(json.shadow, fromNode, device).run());
|
|
330
337
|
}
|
|
331
338
|
if (json.content !== null) {
|
|
332
|
-
element._attachContent(Document.fromDocument(json.content, device).run());
|
|
339
|
+
element._attachContent(Document.fromDocument(json.content, fromNode, device).run());
|
|
333
340
|
}
|
|
334
341
|
return element;
|
|
335
342
|
});
|
|
336
343
|
}
|
|
337
344
|
Element.fromElement = fromElement;
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
return Node.cloneNode(child, options, device).map((node) => [node]);
|
|
347
|
-
}).map((children) => {
|
|
348
|
-
const deviceOption = Option.from(device);
|
|
349
|
-
const clonedElement = Element.of(element.namespace, element.prefix, element.name, element.attributes.map((attribute) => Attribute.clone(attribute, options, device)), Iterable.flatten(children), element.style.map((block) => {
|
|
350
|
-
return Block.of(Iterable.map(block.declarations, (declaration) => Declaration.of(declaration.name, declaration.value, declaration.important)));
|
|
351
|
-
}), deviceOption.flatMap((d) => element.getBoundingBox(d)), deviceOption, element.externalId, element.internalId, element.extraData);
|
|
352
|
-
if (element.shadow.isSome()) {
|
|
353
|
-
clonedElement._attachShadow(Shadow.clone(element.shadow.get(), options, device));
|
|
354
|
-
}
|
|
355
|
-
if (element.content.isSome()) {
|
|
356
|
-
clonedElement._attachContent(Document.clone(element.content.get(), options, device));
|
|
357
|
-
}
|
|
358
|
-
return clonedElement;
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
Element.cloneElement = cloneElement;
|
|
362
|
-
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.hasUniqueId = predicate.hasUniqueId, Element.isBrowsingContextContainer = predicate.isBrowsingContextContainer, Element.isContent = predicate.isContent, Element.isActuallyDisabled = predicate.isActuallyDisabled, Element.isDocumentElement = predicate.isDocumentElement, Element.isDraggable = predicate.isDraggable, Element.isEditingHost = predicate.isEditingHost, Element.isFallback = predicate.isFallback, Element.isScopedTo = predicate.isScopedTo, Element.isSuggestedFocusable = predicate.isSuggestedFocusable, Element.isReplaced = predicate.isReplaced;
|
|
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
|
+
Element.hasUniqueId = predicate.hasUniqueId(isElement);
|
|
347
|
+
Element.isActuallyDisabled = predicate.isActuallyDisabled(isElement);
|
|
348
|
+
Element.isContent = predicate.isContent(isElement);
|
|
349
|
+
Element.isDocumentElement = predicate.isDocumentElement(isElement);
|
|
350
|
+
Element.isFallback = predicate.isFallback(isElement);
|
|
351
|
+
Element.isScopedTo = predicate.isScopedTo(isElement);
|
|
363
352
|
})(Element || (Element = {}));
|
|
364
353
|
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./element.js";
|
|
2
|
+
import "./slot.js";
|
|
3
|
+
export * from "./text.js";
|
|
4
|
+
import { Element } from "./element.js";
|
|
5
|
+
import { Text } from "./text.js";
|
|
6
|
+
/** @public */
|
|
7
|
+
export type Slotable = Element | Text;
|
|
8
|
+
/** @public */
|
|
9
|
+
export declare namespace Slotable {
|
|
10
|
+
function isSlotable(value: unknown): value is Slotable;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./element.js";
|
|
2
|
+
// Load the slot augments.
|
|
3
|
+
import "./slot.js";
|
|
4
|
+
export * from "./text.js";
|
|
5
|
+
import { Element } from "./element.js";
|
|
6
|
+
import { Text } from "./text.js";
|
|
7
|
+
/** @public */
|
|
8
|
+
export var Slotable;
|
|
9
|
+
(function (Slotable) {
|
|
10
|
+
function isSlotable(value) {
|
|
11
|
+
return Element.isElement(value) || Text.isText(value);
|
|
12
|
+
}
|
|
13
|
+
Slotable.isSlotable = isSlotable;
|
|
14
|
+
})(Slotable || (Slotable = {}));
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
2
|
+
import { Element } from "./element.js";
|
|
3
|
+
import type { Slotable } from "./index.js";
|
|
4
|
+
/** @public */
|
|
5
|
+
export type Slot = Element<"slot">;
|
|
6
|
+
declare module "./element.js" {
|
|
7
|
+
interface Element<N extends string> {
|
|
8
|
+
/**
|
|
9
|
+
* Get the slotables assigned to this slot.
|
|
10
|
+
*
|
|
11
|
+
* {@link https://html.spec.whatwg.org/#dom-slot-assignednodes}
|
|
12
|
+
* {@link https://dom.spec.whatwg.org/#find-slotables}
|
|
13
|
+
*/
|
|
14
|
+
assignedNodes(this: Slot): Iterable<Slotable>;
|
|
15
|
+
/**
|
|
16
|
+
* {@link https://dom.spec.whatwg.org/#slot-name}
|
|
17
|
+
*/
|
|
18
|
+
slotName(this: Slot): string;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=slot.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
2
|
+
import { Element } from "./element.js";
|
|
3
|
+
import { Shadow } from "../shadow.js";
|
|
4
|
+
import { Slotable as BaseSlotable } from "./slotable.js";
|
|
5
|
+
Element.prototype.assignedNodes = function* () {
|
|
6
|
+
const root = this.root();
|
|
7
|
+
if (Shadow.isShadow(root)) {
|
|
8
|
+
for (const host of root.host) {
|
|
9
|
+
for (const child of host.children()) {
|
|
10
|
+
if (BaseSlotable.isSlotable(child) &&
|
|
11
|
+
child.assignedSlot().includes(this)) {
|
|
12
|
+
yield child;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
Element.prototype.slotName = function () {
|
|
19
|
+
return this.attribute("name")
|
|
20
|
+
.map((name) => name.value)
|
|
21
|
+
.getOr("");
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=slot.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Option } from "@siteimprove/alfa-option";
|
|
2
|
+
import { BaseNode } from "../node.js";
|
|
3
|
+
import type { Slot } from "./slot.js";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class Slotable<T extends string = string> extends BaseNode<T> {
|
|
8
|
+
/**
|
|
9
|
+
* Get the slot that this slotable is assigned to.
|
|
10
|
+
*
|
|
11
|
+
* {@link https://dom.spec.whatwg.org/#dom-slotable-assignedslot}
|
|
12
|
+
* {@link https://dom.spec.whatwg.org/#find-a-slot}
|
|
13
|
+
*
|
|
14
|
+
* @privateRemarks
|
|
15
|
+
* While the implementation is the same for Element and Text nodes, it uses
|
|
16
|
+
* type guards from Element and therefore cannot really live here without
|
|
17
|
+
* creating circular dependencies.
|
|
18
|
+
*/
|
|
19
|
+
abstract assignedSlot(): Option<Slot>;
|
|
20
|
+
/**
|
|
21
|
+
* {@link https://dom.spec.whatwg.org/#slotable-name}
|
|
22
|
+
*/
|
|
23
|
+
abstract slotableName(): string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare namespace Slotable {
|
|
29
|
+
function isSlotable(value: unknown): value is Slotable;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=slotable.d.ts.map
|