@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.
Files changed (132) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/h.d.ts +14 -13
  3. package/dist/h.js +15 -13
  4. package/dist/index.d.ts +2 -28
  5. package/dist/index.js +2 -28
  6. package/dist/jsx.d.ts +2 -3
  7. package/dist/native.d.ts +10 -2
  8. package/dist/native.js +18 -2
  9. package/dist/node/attribute/predicate/has-name.d.ts +1 -1
  10. package/dist/node/attribute/predicate/has-name.js +2 -3
  11. package/dist/node/attribute.d.ts +9 -13
  12. package/dist/node/attribute.js +3 -10
  13. package/dist/node/comment.d.ts +7 -11
  14. package/dist/node/comment.js +2 -9
  15. package/dist/node/document.d.ts +11 -14
  16. package/dist/node/document.js +8 -23
  17. package/dist/node/element/augment.d.ts +1 -1
  18. package/dist/node/element/augment.js +1 -1
  19. package/dist/node/element/predicate/has-attribute.d.ts +1 -1
  20. package/dist/node/element/predicate/has-display-size.d.ts +1 -1
  21. package/dist/node/element/predicate/has-id.d.ts +1 -1
  22. package/dist/node/element/predicate/has-input-type.d.ts +1 -1
  23. package/dist/node/element/predicate/has-name.d.ts +1 -1
  24. package/dist/node/element/predicate/has-namespace.d.ts +1 -1
  25. package/dist/node/element/predicate/has-tab-index.d.ts +1 -1
  26. package/dist/node/element/predicate/has-unique-id.d.ts +3 -2
  27. package/dist/node/element/predicate/has-unique-id.js +21 -20
  28. package/dist/node/element/predicate/index.d.ts +19 -0
  29. package/dist/node/element/predicate/index.js +19 -0
  30. package/dist/node/element/predicate/is-actually-disabled.d.ts +4 -2
  31. package/dist/node/element/predicate/is-actually-disabled.js +37 -38
  32. package/dist/node/element/predicate/is-browsing-context-container.d.ts +1 -1
  33. package/dist/node/element/predicate/is-content.d.ts +5 -2
  34. package/dist/node/element/predicate/is-content.js +3 -4
  35. package/dist/node/element/predicate/is-document-element.d.ts +3 -2
  36. package/dist/node/element/predicate/is-document-element.js +2 -3
  37. package/dist/node/element/predicate/is-draggable.d.ts +1 -1
  38. package/dist/node/element/predicate/is-editing-host.d.ts +1 -1
  39. package/dist/node/element/predicate/is-fallback.d.ts +5 -2
  40. package/dist/node/element/predicate/is-fallback.js +5 -6
  41. package/dist/node/element/predicate/is-replaced.d.ts +1 -1
  42. package/dist/node/element/predicate/is-scoped-to.d.ts +3 -2
  43. package/dist/node/element/predicate/is-scoped-to.js +5 -5
  44. package/dist/node/element/predicate/is-suggested-focusable.d.ts +1 -1
  45. package/dist/node/element/predicate/is-suggested-focusable.js +3 -3
  46. package/dist/node/fragment.d.ts +6 -9
  47. package/dist/node/fragment.js +5 -20
  48. package/dist/node/index.d.ts +54 -0
  49. package/dist/node/index.js +74 -0
  50. package/dist/{node.d.ts → node/node.d.ts} +40 -160
  51. package/dist/{node.js → node/node.js} +57 -92
  52. package/dist/node/predicate/has-box.d.ts +1 -2
  53. package/dist/node/predicate/has-child.d.ts +1 -1
  54. package/dist/node/predicate/has-child.js +2 -2
  55. package/dist/node/predicate/has-descendant.d.ts +1 -1
  56. package/dist/node/predicate/has-descendant.js +2 -2
  57. package/dist/node/predicate/has-inclusive-descendant.d.ts +1 -1
  58. package/dist/node/predicate/has-inclusive-descendant.js +2 -2
  59. package/dist/node/predicate/has-text-content.d.ts +1 -1
  60. package/dist/node/predicate/has-text-content.js +2 -2
  61. package/dist/node/predicate/index.d.ts +7 -0
  62. package/dist/node/predicate/index.js +7 -0
  63. package/dist/node/predicate/is-root.d.ts +1 -1
  64. package/dist/node/query/descendants.d.ts +3 -3
  65. package/dist/node/query/descendants.js +6 -6
  66. package/dist/node/query/element-id-map.d.ts +2 -2
  67. package/dist/node/query/index.d.ts +2 -2
  68. package/dist/node/shadow.d.ts +11 -14
  69. package/dist/node/shadow.js +9 -24
  70. package/dist/node/{element.d.ts → slotable/element.d.ts} +28 -27
  71. package/dist/node/{element.js → slotable/element.js} +40 -51
  72. package/dist/node/slotable/index.d.ts +12 -0
  73. package/dist/node/slotable/index.js +15 -0
  74. package/dist/node/slotable/slot.d.ts +21 -0
  75. package/dist/node/slotable/slot.js +23 -0
  76. package/dist/node/slotable/slotable.d.ts +31 -0
  77. package/dist/node/slotable/slotable.js +16 -0
  78. package/dist/node/{text.d.ts → slotable/text.d.ts} +8 -11
  79. package/dist/node/{text.js → slotable/text.js} +13 -10
  80. package/dist/node/traversal/get-nodes-between.d.ts +1 -1
  81. package/dist/node/traversal/get-nodes-between.js +3 -3
  82. package/dist/node/traversal/index.d.ts +2 -0
  83. package/dist/node/traversal/index.js +2 -0
  84. package/dist/node/traversal/lowest-common-ancestor.d.ts +1 -1
  85. package/dist/node/traversal/lowest-common-ancestor.js +2 -2
  86. package/dist/node/type.d.ts +6 -10
  87. package/dist/node/type.js +2 -9
  88. package/dist/style/declaration.d.ts +2 -2
  89. package/dist/style/index.d.ts +5 -0
  90. package/dist/style/index.js +5 -0
  91. package/dist/style/rule/condition.d.ts +1 -1
  92. package/dist/style/rule/font-face.d.ts +3 -3
  93. package/dist/style/rule/font-face.js +2 -2
  94. package/dist/style/rule/grouping.d.ts +4 -3
  95. package/dist/style/rule/grouping.js +2 -2
  96. package/dist/style/rule/import.d.ts +3 -3
  97. package/dist/style/rule/import.js +2 -4
  98. package/dist/style/rule/index.d.ts +65 -0
  99. package/dist/style/rule/index.js +83 -0
  100. package/dist/style/rule/keyframe.d.ts +3 -3
  101. package/dist/style/rule/keyframe.js +2 -2
  102. package/dist/style/rule/keyframes.d.ts +2 -2
  103. package/dist/style/rule/keyframes.js +2 -3
  104. package/dist/style/rule/layer.d.ts +5 -4
  105. package/dist/style/rule/layer.js +4 -4
  106. package/dist/style/rule/media.d.ts +2 -2
  107. package/dist/style/rule/media.js +2 -3
  108. package/dist/style/rule/namespace.d.ts +3 -3
  109. package/dist/style/rule/namespace.js +2 -2
  110. package/dist/style/rule/page.d.ts +3 -3
  111. package/dist/style/rule/page.js +2 -2
  112. package/dist/style/rule/rule.d.ts +42 -0
  113. package/dist/style/rule/rule.js +64 -0
  114. package/dist/style/rule/style.d.ts +3 -3
  115. package/dist/style/rule/style.js +2 -2
  116. package/dist/style/rule/supports.d.ts +2 -2
  117. package/dist/style/rule/supports.js +2 -3
  118. package/dist/style/sheet.d.ts +1 -1
  119. package/dist/style/sheet.js +2 -2
  120. package/package.json +29 -30
  121. package/dist/node/element/predicate.d.ts +0 -19
  122. package/dist/node/element/predicate.js +0 -19
  123. package/dist/node/predicate.d.ts +0 -7
  124. package/dist/node/predicate.js +0 -7
  125. package/dist/node/slot.d.ts +0 -29
  126. package/dist/node/slot.js +0 -41
  127. package/dist/node/slotable.d.ts +0 -29
  128. package/dist/node/slotable.js +0 -40
  129. package/dist/node/traversal.d.ts +0 -2
  130. package/dist/node/traversal.js +0 -2
  131. package/dist/style/rule.d.ts +0 -60
  132. 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 { Node } from "../../node.js";
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 = Node.Traversal.empty) {
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
@@ -0,0 +1,7 @@
1
+ export * from "./has-box.js";
2
+ export * from "./has-child.js";
3
+ export * from "./has-descendant.js";
4
+ export * from "./has-inclusive-descendant.js";
5
+ export * from "./has-text-content.js";
6
+ export * from "./is-root.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,7 @@
1
+ export * from "./has-box.js";
2
+ export * from "./has-child.js";
3
+ export * from "./has-descendant.js";
4
+ export * from "./has-inclusive-descendant.js";
5
+ export * from "./has-text-content.js";
6
+ export * from "./is-root.js";
7
+ //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  import type { Predicate } from "@siteimprove/alfa-predicate";
2
- import type { Node } from "../../node.js";
2
+ import type { Node } from "../index.js";
3
3
  /**
4
4
  * @public
5
5
  */
@@ -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 "../../node.js";
5
- import { Element } from "../element.js";
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 { Node } from "../../node.js";
4
- import { Element } from "../element.js";
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 = Node.Traversal.empty) => {
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 = Node.Traversal.empty) {
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 = Node.Traversal.empty) => {
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 "../../node.js";
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 "../../node.js";
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("../element.js").Element<string>>;
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;
@@ -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 { Element } from "./element.js";
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 Node<"shadow"> {
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?: Node.Traversal): Option<Node>;
23
+ parent(options?: BaseNode.Traversal): Option<Node>;
23
24
  /**
24
25
  * @internal
25
26
  **/
26
- protected _internalPath(options?: Node.Traversal): string;
27
- toJSON(options: Node.SerializationOptions & {
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?: Node.SerializationOptions): Shadow.JSON;
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 Node.JSON {
50
+ interface MinimalJSON extends BaseNode.JSON {
50
51
  }
51
- interface JSON extends Node.JSON {
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
@@ -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 { Element } from "./element.js";
7
+ import { BaseNode } from "./node.js";
9
8
  /**
10
9
  * @public
11
10
  */
12
- export class Shadow extends Node {
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 = Node.Traversal.empty) {
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(Node.Traversal.composed)) {
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 = Node.Traversal.empty) {
48
- if (options.isSet(Node.Traversal.composed)) {
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(Node.Traversal.flattened)) {
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) => Node.fromNode(child, device)).map((children) => Shadow.of(children, json.style.map(Sheet.from), json.mode, json.externalId, json.internalId));
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 "../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";
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 * as helpers from "./element/input-type.js";
18
- import * as predicate from "./element/predicate.js";
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 Node<"element"> implements Slot, Slotable {
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?: Node.Traversal): Sequence<Node>;
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?: Node.Traversal): string;
89
- toJSON(options: Node.SerializationOptions & {
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: Node.SerializationOptions & {
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?: Node.SerializationOptions): Element.JSON<N>;
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 Node.JSON<"element"> {
110
+ interface MinimalJSON extends BaseNode.JSON<"element"> {
113
111
  }
114
- interface JSON<N extends string = string> extends Node.JSON<"element"> {
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
- * @internal
131
- */
132
- function cloneElement(options: Node.ElementReplacementOptions, device?: Device): (element: Element) => Trampoline<Element>;
133
- 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, 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;
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 { 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";
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 "./element/predicate.js";
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 Node {
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 = Node.Traversal.empty) {
91
+ children(options = BaseNode.Traversal.empty) {
94
92
  const treeChildren = this._children;
95
93
  const children = [];
96
- if (options.isSet(Node.Traversal.flattened)) {
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 (Slot.isSlot(this)) {
98
+ if (Element.isSlot(this)) {
101
99
  return Sequence.from(this.assignedNodes());
102
100
  }
103
101
  for (const child of treeChildren) {
104
- if (Slot.isSlot(child)) {
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(Node.Traversal.composed) && this._shadow.isSome()) {
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(Node.Traversal.nested) && this._content.isSome()) {
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(Node.flatTree)
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
- return Slotable.findSlot(this);
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
- * {@link https://html.spec.whatwg.org/#dom-slot-assignednodes}
220
- */
221
- assignedNodes() {
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) => Node.fromNode(child, device)).map((children) => {
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
- * @internal
340
- */
341
- function cloneElement(options, device) {
342
- return (element) => Trampoline.traverse(element.children(), (child) => {
343
- if (Element.isElement(child) && options.predicate(child)) {
344
- return Trampoline.done(Array.from(options.newElements));
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