@siteimprove/alfa-dom 0.89.2
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 +291 -0
- package/dist/h.d.ts +37 -0
- package/dist/h.js +214 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +32 -0
- package/dist/jsx-runtime.d.ts +26 -0
- package/dist/jsx-runtime.js +41 -0
- package/dist/jsx.d.ts +44 -0
- package/dist/jsx.js +45 -0
- package/dist/namespace.d.ts +43 -0
- package/dist/namespace.js +57 -0
- package/dist/native.d.ts +18 -0
- package/dist/native.js +449 -0
- package/dist/node/attribute/predicate/has-name.d.ts +11 -0
- package/dist/node/attribute/predicate/has-name.js +13 -0
- package/dist/node/attribute/predicate.d.ts +2 -0
- package/dist/node/attribute/predicate.js +2 -0
- package/dist/node/attribute.d.ts +90 -0
- package/dist/node/attribute.js +164 -0
- package/dist/node/comment.d.ts +42 -0
- package/dist/node/comment.js +74 -0
- package/dist/node/document.d.ts +59 -0
- package/dist/node/document.js +113 -0
- package/dist/node/element/input-type.d.ts +12 -0
- package/dist/node/element/input-type.js +10 -0
- package/dist/node/element/predicate/has-attribute.d.ts +12 -0
- package/dist/node/element/predicate/has-attribute.js +11 -0
- package/dist/node/element/predicate/has-box.d.ts +9 -0
- package/dist/node/element/predicate/has-box.js +7 -0
- package/dist/node/element/predicate/has-display-size.d.ts +7 -0
- package/dist/node/element/predicate/has-display-size.js +28 -0
- package/dist/node/element/predicate/has-id.d.ts +16 -0
- package/dist/node/element/predicate/has-id.js +17 -0
- package/dist/node/element/predicate/has-input-type.d.ts +12 -0
- package/dist/node/element/predicate/has-input-type.js +17 -0
- package/dist/node/element/predicate/has-name.d.ts +11 -0
- package/dist/node/element/predicate/has-name.js +13 -0
- package/dist/node/element/predicate/has-namespace.d.ts +12 -0
- package/dist/node/element/predicate/has-namespace.js +13 -0
- package/dist/node/element/predicate/has-tab-index.d.ts +12 -0
- package/dist/node/element/predicate/has-tab-index.js +11 -0
- package/dist/node/element/predicate/has-unique-id.d.ts +7 -0
- package/dist/node/element/predicate/has-unique-id.js +31 -0
- package/dist/node/element/predicate/is-actually-disabled.d.ts +8 -0
- package/dist/node/element/predicate/is-actually-disabled.js +47 -0
- package/dist/node/element/predicate/is-browsing-context-container.d.ts +8 -0
- package/dist/node/element/predicate/is-browsing-context-container.js +20 -0
- package/dist/node/element/predicate/is-content.d.ts +10 -0
- package/dist/node/element/predicate/is-content.js +17 -0
- package/dist/node/element/predicate/is-document-element.d.ts +6 -0
- package/dist/node/element/predicate/is-document-element.js +13 -0
- package/dist/node/element/predicate/is-draggable.d.ts +8 -0
- package/dist/node/element/predicate/is-draggable.js +28 -0
- package/dist/node/element/predicate/is-editing-host.d.ts +8 -0
- package/dist/node/element/predicate/is-editing-host.js +20 -0
- package/dist/node/element/predicate/is-fallback.d.ts +15 -0
- package/dist/node/element/predicate/is-fallback.js +28 -0
- package/dist/node/element/predicate/is-replaced.d.ts +8 -0
- package/dist/node/element/predicate/is-replaced.js +17 -0
- package/dist/node/element/predicate/is-scoped-to.d.ts +7 -0
- package/dist/node/element/predicate/is-scoped-to.js +11 -0
- package/dist/node/element/predicate/is-suggested-focusable.d.ts +14 -0
- package/dist/node/element/predicate/is-suggested-focusable.js +47 -0
- package/dist/node/element/predicate.d.ts +20 -0
- package/dist/node/element/predicate.js +20 -0
- package/dist/node/element.d.ts +122 -0
- package/dist/node/element.js +330 -0
- package/dist/node/fragment.d.ts +38 -0
- package/dist/node/fragment.js +68 -0
- package/dist/node/predicate/has-child.d.ts +7 -0
- package/dist/node/predicate/has-child.js +8 -0
- package/dist/node/predicate/has-descendant.d.ts +7 -0
- package/dist/node/predicate/has-descendant.js +8 -0
- package/dist/node/predicate/has-inclusive-descendant.d.ts +7 -0
- package/dist/node/predicate/has-inclusive-descendant.js +8 -0
- package/dist/node/predicate/has-text-content.d.ts +7 -0
- package/dist/node/predicate/has-text-content.js +12 -0
- package/dist/node/predicate/is-root.d.ts +7 -0
- package/dist/node/predicate/is-root.js +7 -0
- package/dist/node/predicate.d.ts +6 -0
- package/dist/node/predicate.js +6 -0
- package/dist/node/query/element-descendants.d.ts +8 -0
- package/dist/node/query/element-descendants.js +17 -0
- package/dist/node/query/element-id-map.d.ts +14 -0
- package/dist/node/query/element-id-map.js +30 -0
- package/dist/node/query/inclusive-element-descendants.d.ts +8 -0
- package/dist/node/query/inclusive-element-descendants.js +10 -0
- package/dist/node/query/index.d.ts +12 -0
- package/dist/node/query/index.js +13 -0
- package/dist/node/shadow.d.ts +66 -0
- package/dist/node/shadow.js +128 -0
- package/dist/node/slot.d.ts +29 -0
- package/dist/node/slot.js +41 -0
- package/dist/node/slotable.d.ts +29 -0
- package/dist/node/slotable.js +40 -0
- package/dist/node/text.d.ts +46 -0
- package/dist/node/text.js +83 -0
- package/dist/node/traversal/get-nodes-between.d.ts +24 -0
- package/dist/node/traversal/get-nodes-between.js +62 -0
- package/dist/node/traversal/lowest-common-ancestor.d.ts +13 -0
- package/dist/node/traversal/lowest-common-ancestor.js +19 -0
- package/dist/node/traversal.d.ts +2 -0
- package/dist/node/traversal.js +2 -0
- package/dist/node/type.d.ts +45 -0
- package/dist/node/type.js +74 -0
- package/dist/node.d.ts +263 -0
- package/dist/node.js +325 -0
- package/dist/style/block.d.ts +30 -0
- package/dist/style/block.js +63 -0
- package/dist/style/declaration.d.ts +65 -0
- package/dist/style/declaration.js +103 -0
- package/dist/style/rule/condition.d.ts +21 -0
- package/dist/style/rule/condition.js +30 -0
- package/dist/style/rule/font-face.d.ts +29 -0
- package/dist/style/rule/font-face.js +47 -0
- package/dist/style/rule/grouping.d.ts +22 -0
- package/dist/style/rule/grouping.js +34 -0
- package/dist/style/rule/import.d.ts +47 -0
- package/dist/style/rule/import.js +114 -0
- package/dist/style/rule/keyframe.d.ts +32 -0
- package/dist/style/rule/keyframe.js +53 -0
- package/dist/style/rule/keyframes.d.ts +28 -0
- package/dist/style/rule/keyframes.js +49 -0
- package/dist/style/rule/layer.d.ts +61 -0
- package/dist/style/rule/layer.js +106 -0
- package/dist/style/rule/media.d.ts +32 -0
- package/dist/style/rule/media.js +54 -0
- package/dist/style/rule/namespace.d.ts +31 -0
- package/dist/style/rule/namespace.js +52 -0
- package/dist/style/rule/page.d.ts +32 -0
- package/dist/style/rule/page.js +53 -0
- package/dist/style/rule/style.d.ts +35 -0
- package/dist/style/rule/style.js +62 -0
- package/dist/style/rule/supports.d.ts +32 -0
- package/dist/style/rule/supports.js +56 -0
- package/dist/style/rule.d.ts +60 -0
- package/dist/style/rule.js +109 -0
- package/dist/style/sheet.d.ts +37 -0
- package/dist/style/sheet.js +66 -0
- package/package.json +69 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { Device } from "@siteimprove/alfa-device";
|
|
2
|
+
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
3
|
+
import { Option } from "@siteimprove/alfa-option";
|
|
4
|
+
import { Predicate } from "@siteimprove/alfa-predicate";
|
|
5
|
+
import { Rectangle } from "@siteimprove/alfa-rectangle";
|
|
6
|
+
import { Sequence } from "@siteimprove/alfa-sequence";
|
|
7
|
+
import { Trampoline } from "@siteimprove/alfa-trampoline";
|
|
8
|
+
import * as json from "@siteimprove/alfa-json";
|
|
9
|
+
import type { Namespace } from "../namespace.js";
|
|
10
|
+
import { Node } from "../node.js";
|
|
11
|
+
import { Block } from "../style/block.js";
|
|
12
|
+
import { Attribute } from "./attribute.js";
|
|
13
|
+
import { Document } from "./document.js";
|
|
14
|
+
import { Shadow } from "./shadow.js";
|
|
15
|
+
import { Slot } from "./slot.js";
|
|
16
|
+
import { Slotable } from "./slotable.js";
|
|
17
|
+
import * as helpers from "./element/input-type.js";
|
|
18
|
+
import * as predicate from "./element/predicate.js";
|
|
19
|
+
/**
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare class Element<N extends string = string> extends Node<"element"> implements Slot, Slotable {
|
|
23
|
+
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, serializationId?: string, extraData?: any): Element<N>;
|
|
24
|
+
private readonly _namespace;
|
|
25
|
+
private readonly _prefix;
|
|
26
|
+
private readonly _name;
|
|
27
|
+
private readonly _attributes;
|
|
28
|
+
private readonly _style;
|
|
29
|
+
private _shadow;
|
|
30
|
+
private _content;
|
|
31
|
+
private readonly _id;
|
|
32
|
+
private readonly _classes;
|
|
33
|
+
private readonly _boxes;
|
|
34
|
+
private constructor();
|
|
35
|
+
get namespace(): Option<Namespace>;
|
|
36
|
+
get prefix(): Option<string>;
|
|
37
|
+
get name(): N;
|
|
38
|
+
get qualifiedName(): string;
|
|
39
|
+
get attributes(): Sequence<Attribute>;
|
|
40
|
+
get style(): Option<Block>;
|
|
41
|
+
get shadow(): Option<Shadow>;
|
|
42
|
+
get content(): Option<Document>;
|
|
43
|
+
/**
|
|
44
|
+
* {@link https://dom.spec.whatwg.org/#concept-id}
|
|
45
|
+
*/
|
|
46
|
+
get id(): Option<string>;
|
|
47
|
+
/**
|
|
48
|
+
* {@link https://dom.spec.whatwg.org/#concept-class}
|
|
49
|
+
*/
|
|
50
|
+
get classes(): Sequence<string>;
|
|
51
|
+
getBoundingBox(device: Device): Option<Rectangle>;
|
|
52
|
+
children(options?: Node.Traversal): Sequence<Node>;
|
|
53
|
+
attribute<A extends string = string>(name: A): Option<Attribute<A>>;
|
|
54
|
+
attribute<A extends string = string>(predicate: Predicate<Attribute<A>>): Option<Attribute<A>>;
|
|
55
|
+
/**
|
|
56
|
+
* {@link https://html.spec.whatwg.org/#void-elements}
|
|
57
|
+
*/
|
|
58
|
+
isVoid(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* {@link https://html.spec.whatwg.org/#dom-tabindex}
|
|
61
|
+
*/
|
|
62
|
+
tabIndex(): Option<number>;
|
|
63
|
+
/**
|
|
64
|
+
* {@link https://dom.spec.whatwg.org/#dom-slotable-assignedslot}
|
|
65
|
+
*/
|
|
66
|
+
assignedSlot(): Option<Slot>;
|
|
67
|
+
/**
|
|
68
|
+
* {@link https://html.spec.whatwg.org/#dom-slot-assignednodes}
|
|
69
|
+
*/
|
|
70
|
+
assignedNodes(): Iterable<Slotable>;
|
|
71
|
+
/**
|
|
72
|
+
* @internal
|
|
73
|
+
**/
|
|
74
|
+
protected _internalPath(options?: Node.Traversal): string;
|
|
75
|
+
toJSON(options: Node.SerializationOptions & {
|
|
76
|
+
verbosity: json.Serializable.Verbosity.Minimal | json.Serializable.Verbosity.Low;
|
|
77
|
+
}): Element.MinimalJSON;
|
|
78
|
+
toJSON(options: Node.SerializationOptions & {
|
|
79
|
+
verbosity: json.Serializable.Verbosity.High;
|
|
80
|
+
}): Element.JSON & {
|
|
81
|
+
assignedSlot: Element.MinimalJSON | null;
|
|
82
|
+
};
|
|
83
|
+
toJSON(options?: Node.SerializationOptions): Element.JSON<N>;
|
|
84
|
+
toString(): string;
|
|
85
|
+
/**
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
_attachShadow(shadow: Shadow): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
_attachContent(document: Document): boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
export declare namespace Element {
|
|
98
|
+
interface MinimalJSON extends Node.JSON<"element"> {
|
|
99
|
+
}
|
|
100
|
+
interface JSON<N extends string = string> extends Node.JSON<"element"> {
|
|
101
|
+
namespace: string | null;
|
|
102
|
+
prefix: string | null;
|
|
103
|
+
name: N;
|
|
104
|
+
attributes: Array<Attribute.JSON>;
|
|
105
|
+
style: Block.JSON | string | null;
|
|
106
|
+
shadow: Shadow.JSON | null;
|
|
107
|
+
content: Document.JSON | null;
|
|
108
|
+
box: Rectangle.JSON | null;
|
|
109
|
+
}
|
|
110
|
+
function isElement(value: unknown): value is Element;
|
|
111
|
+
/**
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
114
|
+
function fromElement<N extends string = string>(json: JSON<N>, device?: Device): Trampoline<Element<N>>;
|
|
115
|
+
/**
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
function cloneElement(options: Node.ElementReplacementOptions, device?: Device): (element: Element) => Trampoline<Element>;
|
|
119
|
+
const hasAttribute: typeof predicate.hasAttribute, hasBox: typeof predicate.hasBox, hasDisplaySize: typeof predicate.hasDisplaySize, hasId: typeof predicate.hasId, hasInputType: typeof predicate.hasInputType, hasName: typeof predicate.hasName, hasNamespace: typeof predicate.hasNamespace, hasTabIndex: typeof predicate.hasTabIndex, hasUniqueId: Predicate<Element<string>>, isBrowsingContextContainer: typeof predicate.isBrowsingContextContainer, isContent: typeof predicate.isContent, isActuallyDisabled: typeof predicate.isActuallyDisabled, isDocumentElement: typeof predicate.isDocumentElement, isDraggable: typeof predicate.isDraggable, isEditingHost: typeof predicate.isEditingHost, isFallback: typeof predicate.isFallback, isScopedTo: typeof predicate.isScopedTo, isSuggestedFocusable: typeof predicate.isSuggestedFocusable, isReplaced: typeof predicate.isReplaced;
|
|
120
|
+
const inputType: typeof helpers.inputType;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=element.d.ts.map
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { Cache } from "@siteimprove/alfa-cache";
|
|
2
|
+
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
3
|
+
import { None, Option, Some } from "@siteimprove/alfa-option";
|
|
4
|
+
import { Predicate } from "@siteimprove/alfa-predicate";
|
|
5
|
+
import { Rectangle } from "@siteimprove/alfa-rectangle";
|
|
6
|
+
import { Sequence } from "@siteimprove/alfa-sequence";
|
|
7
|
+
import { String } from "@siteimprove/alfa-string";
|
|
8
|
+
import { Trampoline } from "@siteimprove/alfa-trampoline";
|
|
9
|
+
import * as json from "@siteimprove/alfa-json";
|
|
10
|
+
import { Node } from "../node.js";
|
|
11
|
+
import { Block } from "../style/block.js";
|
|
12
|
+
import { Declaration } from "../style/declaration.js";
|
|
13
|
+
import { Attribute } from "./attribute.js";
|
|
14
|
+
import { Document } from "./document.js";
|
|
15
|
+
import { Shadow } from "./shadow.js";
|
|
16
|
+
import { Slot } from "./slot.js";
|
|
17
|
+
import { Slotable } from "./slotable.js";
|
|
18
|
+
import * as helpers from "./element/input-type.js";
|
|
19
|
+
import * as predicate from "./element/predicate.js";
|
|
20
|
+
const { isEmpty } = Iterable;
|
|
21
|
+
const { not } = Predicate;
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export class Element extends Node {
|
|
26
|
+
static of(namespace, prefix, name, attributes = [], children = [], style = None, box = None, device = None, externalId, serializationId, extraData) {
|
|
27
|
+
return new Element(namespace, prefix, name, Array.from(attributes), Array.from(children), style, box, device, externalId, serializationId, extraData);
|
|
28
|
+
}
|
|
29
|
+
_namespace;
|
|
30
|
+
_prefix;
|
|
31
|
+
_name;
|
|
32
|
+
_attributes;
|
|
33
|
+
_style;
|
|
34
|
+
_shadow = None;
|
|
35
|
+
_content = None;
|
|
36
|
+
_id;
|
|
37
|
+
_classes;
|
|
38
|
+
_boxes;
|
|
39
|
+
constructor(namespace, prefix, name, attributes, children, style, box, device, externalId, serializationId, extraData) {
|
|
40
|
+
super(children, "element", externalId, serializationId, extraData);
|
|
41
|
+
this._namespace = namespace;
|
|
42
|
+
this._prefix = prefix;
|
|
43
|
+
this._name = name;
|
|
44
|
+
this._attributes = new Map(attributes
|
|
45
|
+
.filter((attribute) => attribute._attachOwner(this))
|
|
46
|
+
.map((attribute) => [attribute.qualifiedName, attribute]));
|
|
47
|
+
style.forEach((block) => Iterable.forEach(block, (declaration) => declaration._attachOwner(this)));
|
|
48
|
+
this._style = style;
|
|
49
|
+
this._id = this.attribute("id").map((attr) => attr.value);
|
|
50
|
+
this._classes = this.attribute("class")
|
|
51
|
+
.map((attr) => attr.value.trim().split(/\s+/))
|
|
52
|
+
.getOr([]);
|
|
53
|
+
this._boxes = Cache.from(device.isSome() && box.isSome() ? [[device.get(), box.get()]] : []);
|
|
54
|
+
}
|
|
55
|
+
get namespace() {
|
|
56
|
+
return this._namespace;
|
|
57
|
+
}
|
|
58
|
+
get prefix() {
|
|
59
|
+
return this._prefix;
|
|
60
|
+
}
|
|
61
|
+
get name() {
|
|
62
|
+
return this._name;
|
|
63
|
+
}
|
|
64
|
+
get qualifiedName() {
|
|
65
|
+
return this._prefix.reduce((name, prefix) => `${prefix}:${name}`, this._name);
|
|
66
|
+
}
|
|
67
|
+
get attributes() {
|
|
68
|
+
return Sequence.from(this._attributes.values());
|
|
69
|
+
}
|
|
70
|
+
get style() {
|
|
71
|
+
return this._style;
|
|
72
|
+
}
|
|
73
|
+
get shadow() {
|
|
74
|
+
return this._shadow;
|
|
75
|
+
}
|
|
76
|
+
get content() {
|
|
77
|
+
return this._content;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* {@link https://dom.spec.whatwg.org/#concept-id}
|
|
81
|
+
*/
|
|
82
|
+
get id() {
|
|
83
|
+
return this._id;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* {@link https://dom.spec.whatwg.org/#concept-class}
|
|
87
|
+
*/
|
|
88
|
+
get classes() {
|
|
89
|
+
return Sequence.from(this._classes);
|
|
90
|
+
}
|
|
91
|
+
getBoundingBox(device) {
|
|
92
|
+
return this._boxes.get(device);
|
|
93
|
+
}
|
|
94
|
+
children(options = Node.Traversal.empty) {
|
|
95
|
+
const treeChildren = this._children;
|
|
96
|
+
const children = [];
|
|
97
|
+
if (options.isSet(Node.Traversal.flattened)) {
|
|
98
|
+
if (this._shadow.isSome()) {
|
|
99
|
+
return this._shadow.get().children(options);
|
|
100
|
+
}
|
|
101
|
+
if (Slot.isSlot(this)) {
|
|
102
|
+
return Sequence.from(this.assignedNodes());
|
|
103
|
+
}
|
|
104
|
+
for (const child of treeChildren) {
|
|
105
|
+
if (Slot.isSlot(child)) {
|
|
106
|
+
children.push(...child.children(options));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
children.push(child);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
if (options.isSet(Node.Traversal.composed) && this._shadow.isSome()) {
|
|
115
|
+
children.push(this._shadow.get());
|
|
116
|
+
}
|
|
117
|
+
children.push(...treeChildren);
|
|
118
|
+
}
|
|
119
|
+
if (options.isSet(Node.Traversal.nested) && this._content.isSome()) {
|
|
120
|
+
children.push(this._content.get());
|
|
121
|
+
}
|
|
122
|
+
return Sequence.from(children);
|
|
123
|
+
}
|
|
124
|
+
attribute(nameOrPredicate) {
|
|
125
|
+
if (typeof nameOrPredicate === "string") {
|
|
126
|
+
return Option.from(this._attributes.get(nameOrPredicate));
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return Iterable.find(this._attributes.values(), nameOrPredicate);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* {@link https://html.spec.whatwg.org/#void-elements}
|
|
134
|
+
*/
|
|
135
|
+
isVoid() {
|
|
136
|
+
switch (this._name) {
|
|
137
|
+
case "area":
|
|
138
|
+
case "base":
|
|
139
|
+
case "basefont":
|
|
140
|
+
case "bgsound":
|
|
141
|
+
case "br":
|
|
142
|
+
case "col":
|
|
143
|
+
case "embed":
|
|
144
|
+
case "frame":
|
|
145
|
+
case "hr":
|
|
146
|
+
case "img":
|
|
147
|
+
case "input":
|
|
148
|
+
case "link":
|
|
149
|
+
case "meta":
|
|
150
|
+
case "param":
|
|
151
|
+
case "source":
|
|
152
|
+
case "track":
|
|
153
|
+
case "wbr":
|
|
154
|
+
return true;
|
|
155
|
+
default:
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* {@link https://html.spec.whatwg.org/#dom-tabindex}
|
|
161
|
+
*/
|
|
162
|
+
tabIndex() {
|
|
163
|
+
for (const tabIndex of this.attribute("tabindex")) {
|
|
164
|
+
const number = parseInt(tabIndex.value, 10);
|
|
165
|
+
//Checking if tabindex isn't NaN, undefined, null, Infinity
|
|
166
|
+
if (number === number && number === (number | 0)) {
|
|
167
|
+
return Some.of(number);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (Element.isSuggestedFocusable(this)) {
|
|
171
|
+
return Some.of(0);
|
|
172
|
+
}
|
|
173
|
+
return None;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* {@link https://dom.spec.whatwg.org/#dom-slotable-assignedslot}
|
|
177
|
+
*/
|
|
178
|
+
assignedSlot() {
|
|
179
|
+
return Slotable.findSlot(this);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* {@link https://html.spec.whatwg.org/#dom-slot-assignednodes}
|
|
183
|
+
*/
|
|
184
|
+
assignedNodes() {
|
|
185
|
+
return Slot.findSlotables(this);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* @internal
|
|
189
|
+
**/
|
|
190
|
+
_internalPath(options) {
|
|
191
|
+
let path = this.parent(options)
|
|
192
|
+
.map((parent) => parent.path(options))
|
|
193
|
+
.getOr("/");
|
|
194
|
+
path += path === "/" ? "" : "/";
|
|
195
|
+
path += this._name;
|
|
196
|
+
const index = this.preceding(options)
|
|
197
|
+
.filter(Element.isElement)
|
|
198
|
+
.count((element) => element._name === this._name);
|
|
199
|
+
path += `[${index + 1}]`;
|
|
200
|
+
return path;
|
|
201
|
+
}
|
|
202
|
+
toJSON(options) {
|
|
203
|
+
const verbosity = options?.verbosity ?? json.Serializable.Verbosity.Medium;
|
|
204
|
+
const result = super.toJSON(options);
|
|
205
|
+
if (verbosity < json.Serializable.Verbosity.Medium) {
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
if (verbosity >= json.Serializable.Verbosity.High) {
|
|
209
|
+
result.assignedSlot = this.assignedSlot()
|
|
210
|
+
.map((slot) => slot.toJSON({ verbosity: json.Serializable.Verbosity.Minimal }))
|
|
211
|
+
.getOr(null);
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
...result,
|
|
215
|
+
namespace: this._namespace.getOr(null),
|
|
216
|
+
prefix: this._prefix.getOr(null),
|
|
217
|
+
name: this._name,
|
|
218
|
+
attributes: [...this._attributes.values()].map((attribute) => attribute.toJSON(options)),
|
|
219
|
+
style: this._style.map((style) => style.toJSON()).getOr(null),
|
|
220
|
+
shadow: this._shadow.map((shadow) => shadow.toJSON(options)).getOr(null),
|
|
221
|
+
content: this._content
|
|
222
|
+
.map((content) => content.toJSON(options))
|
|
223
|
+
.getOr(null),
|
|
224
|
+
box: options?.device === undefined
|
|
225
|
+
? null
|
|
226
|
+
: this._boxes
|
|
227
|
+
.get(options.device)
|
|
228
|
+
.map((box) => box.toJSON())
|
|
229
|
+
.getOr(null),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
toString() {
|
|
233
|
+
const name = this.qualifiedName;
|
|
234
|
+
const attributes = [...this._attributes.values()]
|
|
235
|
+
.map((attribute) => ` ${attribute.toString()}`)
|
|
236
|
+
.join("");
|
|
237
|
+
if (this.isVoid()) {
|
|
238
|
+
return `<${name}${attributes}>`;
|
|
239
|
+
}
|
|
240
|
+
const children = [...this._shadow, ...this._children, ...this._content]
|
|
241
|
+
.map((child) => {
|
|
242
|
+
const value = child.toString();
|
|
243
|
+
// If the child is only spaces, we do not want to trim them to nothingness.
|
|
244
|
+
if (value.match(/\s+/) !== null) {
|
|
245
|
+
return value;
|
|
246
|
+
}
|
|
247
|
+
return value.trim();
|
|
248
|
+
})
|
|
249
|
+
.filter(not(isEmpty))
|
|
250
|
+
.map(String.indent)
|
|
251
|
+
.join("\n");
|
|
252
|
+
return `<${name}${attributes}>${children === "" ? "" : `\n${children}\n`}</${name}>`;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* @internal
|
|
256
|
+
*/
|
|
257
|
+
_attachShadow(shadow) {
|
|
258
|
+
if (this._frozen || this._shadow.isSome() || !shadow._attachHost(this)) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
this._shadow = Option.of(shadow);
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* @internal
|
|
266
|
+
*/
|
|
267
|
+
_attachContent(document) {
|
|
268
|
+
if (this._frozen ||
|
|
269
|
+
this._content.isSome() ||
|
|
270
|
+
!document._attachFrame(this)) {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
this._content = Option.of(document);
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* @public
|
|
279
|
+
*/
|
|
280
|
+
(function (Element) {
|
|
281
|
+
function isElement(value) {
|
|
282
|
+
return value instanceof Element;
|
|
283
|
+
}
|
|
284
|
+
Element.isElement = isElement;
|
|
285
|
+
/**
|
|
286
|
+
* @internal
|
|
287
|
+
*/
|
|
288
|
+
function fromElement(json, device) {
|
|
289
|
+
return Trampoline.traverse(json.children ?? [], (child) => Node.fromNode(child, device)).map((children) => {
|
|
290
|
+
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
|
|
291
|
+
? None
|
|
292
|
+
: Option.from(json.style).map(Block.from), Option.from(json.box).map(Rectangle.from), Option.from(device), json.externalId, json.serializationId);
|
|
293
|
+
if (json.shadow !== null) {
|
|
294
|
+
element._attachShadow(Shadow.fromShadow(json.shadow, device).run());
|
|
295
|
+
}
|
|
296
|
+
if (json.content !== null) {
|
|
297
|
+
element._attachContent(Document.fromDocument(json.content, device).run());
|
|
298
|
+
}
|
|
299
|
+
return element;
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
Element.fromElement = fromElement;
|
|
303
|
+
/**
|
|
304
|
+
* @internal
|
|
305
|
+
*/
|
|
306
|
+
function cloneElement(options, device) {
|
|
307
|
+
return (element) => Trampoline.traverse(element.children(), (child) => {
|
|
308
|
+
if (Element.isElement(child) && options.predicate(child)) {
|
|
309
|
+
return Trampoline.done(Array.from(options.newElements));
|
|
310
|
+
}
|
|
311
|
+
return Node.cloneNode(child, options, device).map((node) => [node]);
|
|
312
|
+
}).map((children) => {
|
|
313
|
+
const deviceOption = Option.from(device);
|
|
314
|
+
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) => {
|
|
315
|
+
return Block.of(Iterable.map(block.declarations, (declaration) => Declaration.of(declaration.name, declaration.value, declaration.important)));
|
|
316
|
+
}), deviceOption.flatMap((d) => element.getBoundingBox(d)), deviceOption, element.externalId, element.serializationId, element.extraData);
|
|
317
|
+
if (element.shadow.isSome()) {
|
|
318
|
+
clonedElement._attachShadow(Shadow.clone(element.shadow.get(), options, device));
|
|
319
|
+
}
|
|
320
|
+
if (element.content.isSome()) {
|
|
321
|
+
clonedElement._attachContent(Document.clone(element.content.get(), options, device));
|
|
322
|
+
}
|
|
323
|
+
return clonedElement;
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
Element.cloneElement = cloneElement;
|
|
327
|
+
Element.hasAttribute = predicate.hasAttribute, Element.hasBox = predicate.hasBox, 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;
|
|
328
|
+
Element.inputType = helpers.inputType;
|
|
329
|
+
})(Element || (Element = {}));
|
|
330
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Device } from "@siteimprove/alfa-device";
|
|
2
|
+
import { Trampoline } from "@siteimprove/alfa-trampoline";
|
|
3
|
+
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
4
|
+
import { Node } from "../node.js";
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class Fragment extends Node<"fragment"> {
|
|
9
|
+
static of(children: Iterable<Node>, externalId?: string, serializationId?: string, extraData?: any): Fragment;
|
|
10
|
+
static empty(): Fragment;
|
|
11
|
+
private constructor();
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
**/
|
|
15
|
+
protected _internalPath(): string;
|
|
16
|
+
toString(): string;
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
_attachParent(): boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare namespace Fragment {
|
|
26
|
+
interface JSON extends Node.JSON<"fragment"> {
|
|
27
|
+
}
|
|
28
|
+
function isFragment(value: unknown): value is Fragment;
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
function fromFragment(json: JSON, device?: Device): Trampoline<Fragment>;
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
function cloneFragment(options: Node.ElementReplacementOptions, device?: Device): (fragment: Fragment) => Trampoline<Fragment>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=fragment.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { String } from "@siteimprove/alfa-string";
|
|
2
|
+
import { Trampoline } from "@siteimprove/alfa-trampoline";
|
|
3
|
+
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
4
|
+
import { Node } from "../node.js";
|
|
5
|
+
import { Element } from "./element.js";
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export class Fragment extends Node {
|
|
10
|
+
static of(children, externalId, serializationId, extraData) {
|
|
11
|
+
return new Fragment(Array.from(children), externalId, serializationId, extraData);
|
|
12
|
+
}
|
|
13
|
+
static empty() {
|
|
14
|
+
return new Fragment([]);
|
|
15
|
+
}
|
|
16
|
+
constructor(children, externalId, serializationId, extraData) {
|
|
17
|
+
super(children, "fragment", externalId, serializationId, extraData);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
**/
|
|
22
|
+
_internalPath() {
|
|
23
|
+
return "/";
|
|
24
|
+
}
|
|
25
|
+
toString() {
|
|
26
|
+
const children = this._children
|
|
27
|
+
.map((child) => String.indent(child.toString()))
|
|
28
|
+
.join("\n");
|
|
29
|
+
return `#document-fragment${children === "" ? "" : `\n${children}`}`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
_attachParent() {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
(function (Fragment) {
|
|
42
|
+
function isFragment(value) {
|
|
43
|
+
return value instanceof Fragment;
|
|
44
|
+
}
|
|
45
|
+
Fragment.isFragment = isFragment;
|
|
46
|
+
/**
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
function fromFragment(json, device) {
|
|
50
|
+
return Trampoline.traverse(json.children ?? [], (child) => Node.fromNode(child, device)).map((children) => Fragment.of(children));
|
|
51
|
+
}
|
|
52
|
+
Fragment.fromFragment = fromFragment;
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
function cloneFragment(options, device) {
|
|
57
|
+
return (fragment) => Trampoline.traverse(fragment.children(), (child) => {
|
|
58
|
+
if (Element.isElement(child) && options.predicate(child)) {
|
|
59
|
+
return Trampoline.done(Array.from(options.newElements));
|
|
60
|
+
}
|
|
61
|
+
return Node.cloneNode(child, options, device).map((node) => [node]);
|
|
62
|
+
}).map((children) => {
|
|
63
|
+
return Fragment.of(Iterable.flatten(children), fragment.externalId);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
Fragment.cloneFragment = cloneFragment;
|
|
67
|
+
})(Fragment || (Fragment = {}));
|
|
68
|
+
//# sourceMappingURL=fragment.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Predicate } from "@siteimprove/alfa-predicate";
|
|
2
|
+
import { Node } from "../../node.js";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare function hasChild(predicate: Predicate<Node>, options?: Node.Traversal): Predicate<Node>;
|
|
7
|
+
//# sourceMappingURL=has-child.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Predicate } from "@siteimprove/alfa-predicate";
|
|
2
|
+
import { Node } from "../../node.js";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare function hasDescendant(predicate: Predicate<Node>, options?: Node.Traversal): Predicate<Node>;
|
|
7
|
+
//# sourceMappingURL=has-descendant.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Predicate } from "@siteimprove/alfa-predicate";
|
|
2
|
+
import { Node } from "../../node.js";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare function hasInclusiveDescendant(predicate: Predicate<Node>, options?: Node.Traversal): Predicate<Node>;
|
|
7
|
+
//# sourceMappingURL=has-inclusive-descendant.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Node } from "../../node.js";
|
|
2
|
+
/**
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export function hasInclusiveDescendant(predicate, options = Node.Traversal.empty) {
|
|
6
|
+
return (node) => node.inclusiveDescendants(options).some(predicate);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=has-inclusive-descendant.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Predicate } from "@siteimprove/alfa-predicate";
|
|
2
|
+
import { Node } from "../../node.js";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare function hasTextContent(predicate?: Predicate<string>, options?: Node.Traversal): Predicate<Node>;
|
|
7
|
+
//# sourceMappingURL=has-text-content.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Iterable } from "@siteimprove/alfa-iterable";
|
|
2
|
+
import { Predicate } from "@siteimprove/alfa-predicate";
|
|
3
|
+
import { Node } from "../../node.js";
|
|
4
|
+
const { isEmpty } = Iterable;
|
|
5
|
+
const { not } = Predicate;
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export function hasTextContent(predicate = not(isEmpty), options = Node.Traversal.empty) {
|
|
10
|
+
return (node) => predicate(node.textContent(options));
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=has-text-content.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./predicate/has-child.js";
|
|
2
|
+
export * from "./predicate/has-descendant.js";
|
|
3
|
+
export * from "./predicate/has-inclusive-descendant.js";
|
|
4
|
+
export * from "./predicate/has-text-content.js";
|
|
5
|
+
export * from "./predicate/is-root.js";
|
|
6
|
+
//# sourceMappingURL=predicate.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./predicate/has-child.js";
|
|
2
|
+
export * from "./predicate/has-descendant.js";
|
|
3
|
+
export * from "./predicate/has-inclusive-descendant.js";
|
|
4
|
+
export * from "./predicate/has-text-content.js";
|
|
5
|
+
export * from "./predicate/is-root.js";
|
|
6
|
+
//# sourceMappingURL=predicate.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Sequence } from "@siteimprove/alfa-sequence";
|
|
2
|
+
import { Node } from "../../node.js";
|
|
3
|
+
import { Element } from "../element.js";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare function getElementDescendants(node: Node, options?: Node.Traversal): Sequence<Element>;
|
|
8
|
+
//# sourceMappingURL=element-descendants.d.ts.map
|