@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
@@ -0,0 +1,16 @@
1
+ import { BaseNode } from "../node.js";
2
+ /**
3
+ * @public
4
+ */
5
+ export class Slotable extends BaseNode {
6
+ }
7
+ /**
8
+ * @public
9
+ */
10
+ (function (Slotable) {
11
+ function isSlotable(value) {
12
+ return value instanceof Slotable;
13
+ }
14
+ Slotable.isSlotable = isSlotable;
15
+ })(Slotable || (Slotable = {}));
16
+ //# sourceMappingURL=slotable.js.map
@@ -4,13 +4,13 @@ import { Predicate } from "@siteimprove/alfa-predicate";
4
4
  import { Rectangle } from "@siteimprove/alfa-rectangle";
5
5
  import { Trampoline } from "@siteimprove/alfa-trampoline";
6
6
  import * as json from "@siteimprove/alfa-json";
7
- import { Node } from "../node.js";
7
+ import { BaseNode } from "../node.js";
8
8
  import type { Slot } from "./slot.js";
9
9
  import { Slotable } from "./slotable.js";
10
10
  /**
11
11
  * @public
12
12
  */
13
- export declare class Text extends Node<"text"> implements Slotable {
13
+ export declare class Text extends Slotable<"text"> {
14
14
  static of(data: string, box?: Option<Rectangle>, device?: Option<Device>, externalId?: string, internalId?: string, extraData?: any): Text;
15
15
  static empty(): Text;
16
16
  private readonly _data;
@@ -18,25 +18,26 @@ export declare class Text extends Node<"text"> implements Slotable {
18
18
  protected constructor(data: string, box: Option<Rectangle>, device: Option<Device>, externalId?: string, internalId?: string, extraData?: any);
19
19
  get data(): string;
20
20
  assignedSlot(): Option<Slot>;
21
+ slotableName(): string;
21
22
  getBoundingBox(device: Device): Option<Rectangle>;
22
23
  is(predicate: Predicate<string>): boolean;
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
  }): Text.MinimalJSON;
30
- toJSON(options?: Node.SerializationOptions): Text.JSON;
31
+ toJSON(options?: BaseNode.SerializationOptions): Text.JSON;
31
32
  toString(): string;
32
33
  }
33
34
  /**
34
35
  * @public
35
36
  */
36
37
  export declare namespace Text {
37
- interface MinimalJSON extends Node.JSON<"text"> {
38
+ interface MinimalJSON extends BaseNode.JSON<"text"> {
38
39
  }
39
- interface JSON extends Node.JSON<"text"> {
40
+ interface JSON extends BaseNode.JSON<"text"> {
40
41
  data: string;
41
42
  box: Rectangle.JSON | null;
42
43
  }
@@ -46,9 +47,5 @@ export declare namespace Text {
46
47
  * @internal
47
48
  */
48
49
  function fromText(json: JSON, device?: Device): Trampoline<Text>;
49
- /**
50
- * @internal
51
- */
52
- function cloneText(device?: Device): (text: Text) => Trampoline<Text>;
53
50
  }
54
51
  //# sourceMappingURL=text.d.ts.map
@@ -4,12 +4,13 @@ import { Predicate } from "@siteimprove/alfa-predicate";
4
4
  import { Rectangle } from "@siteimprove/alfa-rectangle";
5
5
  import { Trampoline } from "@siteimprove/alfa-trampoline";
6
6
  import * as json from "@siteimprove/alfa-json";
7
- import { Node } from "../node.js";
7
+ import { BaseNode } from "../node.js";
8
+ import { Element } from "./element.js";
8
9
  import { Slotable } from "./slotable.js";
9
10
  /**
10
11
  * @public
11
12
  */
12
- export class Text extends Node {
13
+ export class Text extends Slotable {
13
14
  static of(data, box = None, device = None, externalId, internalId, extraData) {
14
15
  return new Text(data, box, device, externalId, internalId, extraData);
15
16
  }
@@ -27,7 +28,16 @@ export class Text extends Node {
27
28
  return this._data;
28
29
  }
29
30
  assignedSlot() {
30
- return Slotable.findSlot(this);
31
+ const name = this.slotableName();
32
+ return this.parent()
33
+ .filter(Element.isElement)
34
+ .flatMap((parent) => parent.shadow.flatMap((shadow) => shadow
35
+ .descendants()
36
+ .filter(Element.isSlot)
37
+ .find((slot) => slot.slotName() === name)));
38
+ }
39
+ slotableName() {
40
+ return "";
31
41
  }
32
42
  getBoundingBox(device) {
33
43
  return this._boxes.get(device);
@@ -95,12 +105,5 @@ export class Text extends Node {
95
105
  return Trampoline.done(Text.of(json.data, Option.from(json.box).map(Rectangle.from), Option.from(device), json.externalId, undefined, json.internalId));
96
106
  }
97
107
  Text.fromText = fromText;
98
- /**
99
- * @internal
100
- */
101
- function cloneText(device) {
102
- return (text) => Trampoline.done(Text.of(text.data, Option.from(device).flatMap((d) => text.getBoundingBox(d)), Option.from(device), text.externalId, text.extraData, text.internalId));
103
- }
104
- Text.cloneText = cloneText;
105
108
  })(Text || (Text = {}));
106
109
  //# sourceMappingURL=text.js.map
@@ -1,5 +1,5 @@
1
1
  import { Sequence } from "@siteimprove/alfa-sequence";
2
- import { Node } from "../../index.js";
2
+ import type { Node } from "../index.js";
3
3
  /**
4
4
  * Get content between two nodes. The relative order of the nodes is unknown.
5
5
  * Options let it choose whether the first or second node (in tree order)
@@ -1,6 +1,6 @@
1
1
  import { Predicate } from "@siteimprove/alfa-predicate";
2
2
  import { Sequence } from "@siteimprove/alfa-sequence";
3
- import { Node } from "../../index.js";
3
+ import { BaseNode } from "../node.js";
4
4
  import { lowestCommonAncestor } from "./lowest-common-ancestor.js";
5
5
  const { equals, or } = Predicate;
6
6
  /**
@@ -18,7 +18,7 @@ const { equals, or } = Predicate;
18
18
  *
19
19
  * @public
20
20
  */
21
- export function getNodesBetween(node1, node2, includeOptions = { includeFirst: false, includeSecond: false }, treeOptions = Node.fullTree) {
21
+ export function getNodesBetween(node1, node2, includeOptions = { includeFirst: false, includeSecond: false }, treeOptions = BaseNode.Traversal.empty) {
22
22
  let between = getNodesInclusivelyBetween(node1, node2, treeOptions);
23
23
  // If somehow there is nothing between them, escape now
24
24
  if (between.isEmpty()) {
@@ -52,7 +52,7 @@ export function getNodesBetween(node1, node2, includeOptions = { includeFirst: f
52
52
  */
53
53
  function getNodesInclusivelyBetween(node1, node2, treeOptions) {
54
54
  const isFrontier = or(equals(node1), equals(node2));
55
- return lowestCommonAncestor(node1, node2, treeOptions)
55
+ return lowestCommonAncestor(node1, node2)
56
56
  .map((context) => context
57
57
  .inclusiveDescendants(treeOptions)
58
58
  .skipUntil(isFrontier)
@@ -0,0 +1,2 @@
1
+ export * from "./get-nodes-between.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from "./get-nodes-between.js";
2
+ //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  import { Option } from "@siteimprove/alfa-option";
2
- import { Node } from "../../index.js";
2
+ import type { Node } from "../../index.js";
3
3
  /**
4
4
  * Find the lowest common ancestor of two nodes:
5
5
  * * get the ancestors chain of both
@@ -1,5 +1,5 @@
1
1
  import { None, Option } from "@siteimprove/alfa-option";
2
- import { Node } from "../../index.js";
2
+ import { BaseNode } from "../node.js";
3
3
  /**
4
4
  * Find the lowest common ancestor of two nodes:
5
5
  * * get the ancestors chain of both
@@ -9,7 +9,7 @@ import { Node } from "../../index.js";
9
9
  *
10
10
  * @internal
11
11
  */
12
- export function lowestCommonAncestor(node1, node2, options = Node.Traversal.empty) {
12
+ export function lowestCommonAncestor(node1, node2, options = BaseNode.Traversal.empty) {
13
13
  return node1
14
14
  .inclusiveAncestors(options)
15
15
  .reverse()
@@ -1,11 +1,11 @@
1
1
  import { Option } from "@siteimprove/alfa-option";
2
2
  import { Trampoline } from "@siteimprove/alfa-trampoline";
3
3
  import * as json from "@siteimprove/alfa-json";
4
- import { Node } from "../node.js";
4
+ import { BaseNode } from "./node.js";
5
5
  /**
6
6
  * @public
7
7
  */
8
- export declare class Type<N extends string = string> extends Node<"type"> {
8
+ export declare class Type<N extends string = string> extends BaseNode<"type"> {
9
9
  static of<N extends string = string>(name: N, publicId?: Option<string>, systemId?: Option<string>, externalId?: string, internalId?: string, extraData?: any): Type<N>;
10
10
  static empty(): Type;
11
11
  private readonly _name;
@@ -15,19 +15,19 @@ export declare class Type<N extends string = string> extends Node<"type"> {
15
15
  get name(): N;
16
16
  get publicId(): Option<string>;
17
17
  get systemId(): Option<string>;
18
- toJSON(options: Node.SerializationOptions & {
18
+ toJSON(options: BaseNode.SerializationOptions & {
19
19
  verbosity: json.Serializable.Verbosity.Minimal | json.Serializable.Verbosity.Low;
20
20
  }): Type.MinimalJSON;
21
- toJSON(options?: Node.SerializationOptions): Type.JSON<N>;
21
+ toJSON(options?: BaseNode.SerializationOptions): Type.JSON<N>;
22
22
  toString(): string;
23
23
  }
24
24
  /**
25
25
  * @public
26
26
  */
27
27
  export declare namespace Type {
28
- interface MinimalJSON extends Node.JSON<"type"> {
28
+ interface MinimalJSON extends BaseNode.JSON<"type"> {
29
29
  }
30
- interface JSON<N extends string = string> extends Node.JSON<"type"> {
30
+ interface JSON<N extends string = string> extends BaseNode.JSON<"type"> {
31
31
  name: N;
32
32
  publicId: string | null;
33
33
  systemId: string | null;
@@ -37,9 +37,5 @@ export declare namespace Type {
37
37
  * @internal
38
38
  */
39
39
  function fromType<N extends string = string>(json: JSON<N>): Trampoline<Type<N>>;
40
- /**
41
- * @internal
42
- */
43
- function cloneType<N extends string = string>(type: Type<N>): Trampoline<Type<N>>;
44
40
  }
45
41
  //# sourceMappingURL=type.d.ts.map
package/dist/node/type.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { None, Option } from "@siteimprove/alfa-option";
2
2
  import { Trampoline } from "@siteimprove/alfa-trampoline";
3
3
  import * as json from "@siteimprove/alfa-json";
4
- import { Node } from "../node.js";
4
+ import { BaseNode } from "./node.js";
5
5
  /**
6
6
  * @public
7
7
  */
8
- export class Type extends Node {
8
+ export class Type extends BaseNode {
9
9
  static of(name, publicId = None, systemId = None, externalId, internalId, extraData) {
10
10
  return new Type(name, publicId, systemId, externalId, internalId, extraData);
11
11
  }
@@ -63,12 +63,5 @@ export class Type extends Node {
63
63
  return Trampoline.done(Type.of(json.name, Option.from(json.publicId), Option.from(json.systemId), json.externalId, json.internalId));
64
64
  }
65
65
  Type.fromType = fromType;
66
- /**
67
- * @internal
68
- */
69
- function cloneType(type) {
70
- return Trampoline.done(Type.of(type.name, type.publicId, type.systemId, type.externalId, type.internalId));
71
- }
72
- Type.cloneType = cloneType;
73
66
  })(Type || (Type = {}));
74
67
  //# sourceMappingURL=type.js.map
@@ -2,8 +2,8 @@ import type { Equatable } from "@siteimprove/alfa-equatable";
2
2
  import type { Serializable } from "@siteimprove/alfa-json";
3
3
  import { Option } from "@siteimprove/alfa-option";
4
4
  import type * as json from "@siteimprove/alfa-json";
5
- import type { Element } from "../node/element.js";
6
- import type { Rule } from "./rule.js";
5
+ import type { Element } from "../node/slotable/element.js";
6
+ import type { Rule } from "./rule/index.js";
7
7
  /**
8
8
  * @public
9
9
  */
@@ -0,0 +1,5 @@
1
+ export * from "./block.js";
2
+ export * from "./declaration.js";
3
+ export * from "./rule/index.js";
4
+ export * from "./sheet.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ export * from "./block.js";
2
+ export * from "./declaration.js";
3
+ export * from "./rule/index.js";
4
+ export * from "./sheet.js";
5
+ //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import type { Rule } from "../rule.js";
1
+ import type { Rule } from "./index.js";
2
2
  import { GroupingRule } from "./grouping.js";
3
3
  /**
4
4
  * @public
@@ -1,11 +1,11 @@
1
1
  import { Trampoline } from "@siteimprove/alfa-trampoline";
2
2
  import { Block } from "../block.js";
3
3
  import type { Declaration } from "../declaration.js";
4
- import { Rule } from "../rule.js";
4
+ import { BaseRule } from "./rule.js";
5
5
  /**
6
6
  * @public
7
7
  */
8
- export declare class FontFaceRule extends Rule<"font-face"> {
8
+ export declare class FontFaceRule extends BaseRule<"font-face"> {
9
9
  static of(declarations: Iterable<Declaration>): FontFaceRule;
10
10
  private readonly _style;
11
11
  protected constructor(declarations: Array<Declaration>);
@@ -17,7 +17,7 @@ export declare class FontFaceRule extends Rule<"font-face"> {
17
17
  * @public
18
18
  */
19
19
  export declare namespace FontFaceRule {
20
- interface JSON extends Rule.JSON<"font-face"> {
20
+ interface JSON extends BaseRule.JSON<"font-face"> {
21
21
  style: Block.JSON | string;
22
22
  }
23
23
  function isFontFaceRule(value: unknown): value is FontFaceRule;
@@ -1,11 +1,11 @@
1
1
  import { String } from "@siteimprove/alfa-string";
2
2
  import { Trampoline } from "@siteimprove/alfa-trampoline";
3
3
  import { Block } from "../block.js";
4
- import { Rule } from "../rule.js";
4
+ import { BaseRule } from "./rule.js";
5
5
  /**
6
6
  * @public
7
7
  */
8
- export class FontFaceRule extends Rule {
8
+ export class FontFaceRule extends BaseRule {
9
9
  static of(declarations) {
10
10
  return new FontFaceRule(Array.from(declarations));
11
11
  }
@@ -1,9 +1,10 @@
1
1
  import { Array } from "@siteimprove/alfa-array";
2
- import { Rule } from "../rule.js";
2
+ import type { Rule } from "./index.js";
3
+ import { BaseRule } from "./rule.js";
3
4
  /**
4
5
  * @public
5
6
  */
6
- export declare abstract class GroupingRule<T extends string = string> extends Rule<T> {
7
+ export declare abstract class GroupingRule<T extends string = string> extends BaseRule<T> {
7
8
  protected readonly _rules: Array<Rule>;
8
9
  protected constructor(type: T, rules: Array<Rule>);
9
10
  get rules(): Iterable<Rule>;
@@ -14,7 +15,7 @@ export declare abstract class GroupingRule<T extends string = string> extends Ru
14
15
  * @public
15
16
  */
16
17
  export declare namespace GroupingRule {
17
- interface JSON<T extends string = string> extends Rule.JSON<T> {
18
+ interface JSON<T extends string = string> extends BaseRule.JSON<T> {
18
19
  rules: Array<Rule.JSON>;
19
20
  }
20
21
  function isGroupingRule(value: unknown): value is GroupingRule;
@@ -1,9 +1,9 @@
1
1
  import { Array } from "@siteimprove/alfa-array";
2
- import { Rule } from "../rule.js";
2
+ import { BaseRule } from "./rule.js";
3
3
  /**
4
4
  * @public
5
5
  */
6
- export class GroupingRule extends Rule {
6
+ export class GroupingRule extends BaseRule {
7
7
  _rules;
8
8
  constructor(type, rules) {
9
9
  super(type);
@@ -4,8 +4,8 @@ import { Iterable } from "@siteimprove/alfa-iterable";
4
4
  import { Option } from "@siteimprove/alfa-option";
5
5
  import { Predicate } from "@siteimprove/alfa-predicate";
6
6
  import { Trampoline } from "@siteimprove/alfa-trampoline";
7
- import { Rule } from "../rule.js";
8
- import { Sheet } from "../sheet.js";
7
+ import type { Rule } from "./index.js";
8
+ import type { Sheet } from "../sheet.js";
9
9
  import { ConditionRule } from "./condition.js";
10
10
  /**
11
11
  * @public
@@ -43,6 +43,6 @@ export declare namespace ImportRule {
43
43
  /**
44
44
  * @internal
45
45
  */
46
- function fromImportRule(json: JSON): Trampoline<ImportRule>;
46
+ function fromImportRule(json: JSON, fromRule: (json: Rule.JSON) => Trampoline<Rule>, sheetFactory: (rules: Iterable<Rule>) => Sheet): Trampoline<ImportRule>;
47
47
  }
48
48
  //# sourceMappingURL=import.d.ts.map
@@ -4,8 +4,6 @@ import { Iterable } from "@siteimprove/alfa-iterable";
4
4
  import { None, Option } from "@siteimprove/alfa-option";
5
5
  import { Predicate } from "@siteimprove/alfa-predicate";
6
6
  import { Trampoline } from "@siteimprove/alfa-trampoline";
7
- import { Rule } from "../rule.js";
8
- import { Sheet } from "../sheet.js";
9
7
  import { ConditionRule } from "./condition.js";
10
8
  const { and } = Predicate;
11
9
  /**
@@ -108,8 +106,8 @@ export class ImportRule extends ConditionRule {
108
106
  /**
109
107
  * @internal
110
108
  */
111
- function fromImportRule(json) {
112
- return Trampoline.traverse(json.rules, Rule.fromRule).map((rules) => ImportRule.of(json.href, Sheet.of(rules), Option.of(json.condition), Option.from(json.supportText), Option.from(json.layer)));
109
+ function fromImportRule(json, fromRule, sheetFactory) {
110
+ return Trampoline.traverse(json.rules, fromRule).map((rules) => ImportRule.of(json.href, sheetFactory(rules), Option.of(json.condition), Option.from(json.supportText), Option.from(json.layer)));
113
111
  }
114
112
  ImportRule.fromImportRule = fromImportRule;
115
113
  })(ImportRule || (ImportRule = {}));
@@ -0,0 +1,65 @@
1
+ import type { Trampoline } from "@siteimprove/alfa-trampoline";
2
+ import type { Sheet } from "../sheet.js";
3
+ import { FontFaceRule } from "./font-face.js";
4
+ import { GroupingRule } from "./grouping.js";
5
+ import { ImportRule } from "./import.js";
6
+ import { KeyframeRule } from "./keyframe.js";
7
+ import { KeyframesRule } from "./keyframes.js";
8
+ import { Layer as LayerRules } from "./layer.js";
9
+ import { MediaRule } from "./media.js";
10
+ import { NamespaceRule } from "./namespace.js";
11
+ import { PageRule } from "./page.js";
12
+ import { StyleRule } from "./style.js";
13
+ import { SupportsRule } from "./supports.js";
14
+ /**
15
+ * @public
16
+ */
17
+ export type Rule = Rule.FontFace | Rule.Grouping | Rule.Import | Rule.Keyframe | Rule.Keyframes | Rule.Layer.Block | Rule.Layer.Statement | Rule.Media | Rule.Namespace | Rule.Page | Rule.Style | Rule.Supports;
18
+ /**
19
+ * @public
20
+ */
21
+ export declare namespace Rule {
22
+ export import FontFace = FontFaceRule;
23
+ export import Grouping = GroupingRule;
24
+ export import Import = ImportRule;
25
+ export import Keyframe = KeyframeRule;
26
+ export import Keyframes = KeyframesRule;
27
+ namespace Layer {
28
+ export import Block = LayerRules.BlockRule;
29
+ export import Statement = LayerRules.StatementRule;
30
+ }
31
+ export import Media = MediaRule;
32
+ export import Namespace = NamespaceRule;
33
+ export import Page = PageRule;
34
+ export import Style = StyleRule;
35
+ export import Supports = SupportsRule;
36
+ type JSON = FontFace.JSON | Grouping.JSON | Import.JSON | Keyframe.JSON | Keyframes.JSON | Layer.Block.JSON | Layer.Statement.JSON | Media.JSON | Namespace.JSON | Page.JSON | Style.JSON | Supports.JSON;
37
+ const fontFace: typeof FontFace.of, isFontFaceRule: typeof FontFace.isFontFaceRule;
38
+ const importRule: typeof Import.of, isImportRule: typeof Import.isImportRule;
39
+ const keyframe: typeof Keyframe.of, isKeyframeRule: typeof Keyframe.isKeyframeRule;
40
+ const keyframes: typeof Keyframes.of, isKeyframesRule: typeof Keyframes.isKeyframesRule;
41
+ const layerBlock: typeof LayerRules.BlockRule.of, isLayerBlockRule: typeof LayerRules.BlockRule.isLayerBlockRule;
42
+ const layerStatement: typeof LayerRules.StatementRule.of, isLayerStatementRule: typeof LayerRules.StatementRule.isLayerStatementRule;
43
+ const media: typeof Media.of, isMediaRule: typeof Media.isMediaRule;
44
+ const namespace: typeof Namespace.of, isNamespaceRule: typeof Namespace.isNamespaceRule;
45
+ const page: typeof Page.of, isPageRule: typeof Page.isPageRule;
46
+ const style: typeof Style.of, isStyleRule: typeof Style.isStyleRule;
47
+ const supports: typeof Supports.of, isSupportsRule: typeof Supports.isSupportsRule;
48
+ function from(json: FontFace.JSON, sheetFactory: (rules: Iterable<Rule>) => Sheet): FontFace;
49
+ function from(json: Import.JSON, sheetFactory: (rules: Iterable<Rule>) => Sheet): Import;
50
+ function from(json: Keyframe.JSON, sheetFactory: (rules: Iterable<Rule>) => Sheet): Keyframe;
51
+ function from(json: Keyframes.JSON, sheetFactory: (rules: Iterable<Rule>) => Sheet): Keyframes;
52
+ function from(json: Layer.Block.JSON, sheetFactory: (rules: Iterable<Rule>) => Sheet): Layer.Block;
53
+ function from(json: Layer.Statement.JSON, sheetFactory: (rules: Iterable<Rule>) => Sheet): Layer.Statement;
54
+ function from(json: Media.JSON, sheetFactory: (rules: Iterable<Rule>) => Sheet): Media;
55
+ function from(json: Namespace.JSON, sheetFactory: (rules: Iterable<Rule>) => Sheet): Namespace;
56
+ function from(json: Page.JSON, sheetFactory: (rules: Iterable<Rule>) => Sheet): Page;
57
+ function from(json: Style.JSON, sheetFactory: (rules: Iterable<Rule>) => Sheet): Style;
58
+ function from(json: Supports.JSON, sheetFactory: (rules: Iterable<Rule>) => Sheet): Supports;
59
+ function from(json: Rule.JSON, sheetFactory: (rules: Iterable<Rule>) => Sheet): Rule;
60
+ /**
61
+ * @internal
62
+ */
63
+ function fromRule(sheetFactory: (rules: Iterable<Rule>) => Sheet): (json: Rule.JSON) => Trampoline<Rule>;
64
+ }
65
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,83 @@
1
+ import { FontFaceRule } from "./font-face.js";
2
+ import { GroupingRule } from "./grouping.js";
3
+ import { ImportRule } from "./import.js";
4
+ import { KeyframeRule } from "./keyframe.js";
5
+ import { KeyframesRule } from "./keyframes.js";
6
+ import { Layer as LayerRules } from "./layer.js";
7
+ import { MediaRule } from "./media.js";
8
+ import { NamespaceRule } from "./namespace.js";
9
+ import { PageRule } from "./page.js";
10
+ import { StyleRule } from "./style.js";
11
+ import { SupportsRule } from "./supports.js";
12
+ /**
13
+ * @public
14
+ */
15
+ export var Rule;
16
+ (function (Rule) {
17
+ var _a, _b;
18
+ Rule.FontFace = FontFaceRule;
19
+ Rule.Grouping = GroupingRule;
20
+ Rule.Import = ImportRule;
21
+ Rule.Keyframe = KeyframeRule;
22
+ Rule.Keyframes = KeyframesRule;
23
+ let Layer;
24
+ (function (Layer) {
25
+ Layer.Block = LayerRules.BlockRule;
26
+ Layer.Statement = LayerRules.StatementRule;
27
+ })(Layer = Rule.Layer || (Rule.Layer = {}));
28
+ Rule.Media = MediaRule;
29
+ Rule.Namespace = NamespaceRule;
30
+ Rule.Page = PageRule;
31
+ Rule.Style = StyleRule;
32
+ Rule.Supports = SupportsRule;
33
+ Rule.fontFace = Rule.FontFace.of, Rule.isFontFaceRule = Rule.FontFace.isFontFaceRule;
34
+ Rule.importRule = Rule.Import.of, Rule.isImportRule = Rule.Import.isImportRule;
35
+ Rule.keyframe = Rule.Keyframe.of, Rule.isKeyframeRule = Rule.Keyframe.isKeyframeRule;
36
+ Rule.keyframes = Rule.Keyframes.of, Rule.isKeyframesRule = Rule.Keyframes.isKeyframesRule;
37
+ _a = Layer.Block, Rule.layerBlock = _a.of, Rule.isLayerBlockRule = _a.isLayerBlockRule;
38
+ _b = Layer.Statement, Rule.layerStatement = _b.of, Rule.isLayerStatementRule = _b.isLayerStatementRule;
39
+ Rule.media = Rule.Media.of, Rule.isMediaRule = Rule.Media.isMediaRule;
40
+ Rule.namespace = Rule.Namespace.of, Rule.isNamespaceRule = Rule.Namespace.isNamespaceRule;
41
+ Rule.page = Rule.Page.of, Rule.isPageRule = Rule.Page.isPageRule;
42
+ Rule.style = Rule.Style.of, Rule.isStyleRule = Rule.Style.isStyleRule;
43
+ Rule.supports = Rule.Supports.of, Rule.isSupportsRule = Rule.Supports.isSupportsRule;
44
+ function from(json, sheetFactory) {
45
+ return fromRule(sheetFactory)(json).run();
46
+ }
47
+ Rule.from = from;
48
+ /**
49
+ * @internal
50
+ */
51
+ function fromRule(sheetFactory) {
52
+ return function from(json) {
53
+ switch (json.type) {
54
+ case "font-face":
55
+ return Rule.FontFace.fromFontFaceRule(json);
56
+ case "import":
57
+ return Rule.Import.fromImportRule(json, from, sheetFactory);
58
+ case "keyframe":
59
+ return Rule.Keyframe.fromKeyframeRule(json);
60
+ case "keyframes":
61
+ return Rule.Keyframes.fromKeyframesRule(json, from);
62
+ case "layer-block":
63
+ return Layer.Block.fromLayerBlockRule(json, from);
64
+ case "layer-statement":
65
+ return Layer.Statement.fromLayerStatementRule(json);
66
+ case "media":
67
+ return Rule.Media.fromMediaRule(json, from);
68
+ case "namespace":
69
+ return Rule.Namespace.fromNamespaceRule(json);
70
+ case "page":
71
+ return Rule.Page.fromPageRule(json);
72
+ case "style":
73
+ return Rule.Style.fromStyleRule(json);
74
+ case "supports":
75
+ return Rule.Supports.fromSupportsRule(json, from);
76
+ default:
77
+ throw new Error(`Unexpected rule of type: ${json.type}`);
78
+ }
79
+ };
80
+ }
81
+ Rule.fromRule = fromRule;
82
+ })(Rule || (Rule = {}));
83
+ //# sourceMappingURL=index.js.map
@@ -1,11 +1,11 @@
1
1
  import { Trampoline } from "@siteimprove/alfa-trampoline";
2
2
  import { Block } from "../block.js";
3
3
  import type { Declaration } from "../declaration.js";
4
- import { Rule } from "../rule.js";
4
+ import { BaseRule } from "./rule.js";
5
5
  /**
6
6
  * @public
7
7
  */
8
- export declare class KeyframeRule extends Rule<"keyframe"> {
8
+ export declare class KeyframeRule extends BaseRule<"keyframe"> {
9
9
  static of(key: string, declarations: Iterable<Declaration>): KeyframeRule;
10
10
  private readonly _key;
11
11
  private readonly _style;
@@ -19,7 +19,7 @@ export declare class KeyframeRule extends Rule<"keyframe"> {
19
19
  * @public
20
20
  */
21
21
  export declare namespace KeyframeRule {
22
- interface JSON extends Rule.JSON<"keyframe"> {
22
+ interface JSON extends BaseRule.JSON<"keyframe"> {
23
23
  key: string;
24
24
  style: Block.JSON | string;
25
25
  }
@@ -1,11 +1,11 @@
1
1
  import { String } from "@siteimprove/alfa-string";
2
2
  import { Trampoline } from "@siteimprove/alfa-trampoline";
3
3
  import { Block } from "../block.js";
4
- import { Rule } from "../rule.js";
4
+ import { BaseRule } from "./rule.js";
5
5
  /**
6
6
  * @public
7
7
  */
8
- export class KeyframeRule extends Rule {
8
+ export class KeyframeRule extends BaseRule {
9
9
  static of(key, declarations) {
10
10
  return new KeyframeRule(key, Array.from(declarations));
11
11
  }
@@ -1,5 +1,5 @@
1
1
  import { Trampoline } from "@siteimprove/alfa-trampoline";
2
- import { Rule } from "../rule.js";
2
+ import type { Rule } from "./index.js";
3
3
  import { GroupingRule } from "./grouping.js";
4
4
  /**
5
5
  * @public
@@ -23,6 +23,6 @@ export declare namespace KeyframesRule {
23
23
  /**
24
24
  * @internal
25
25
  */
26
- function fromKeyframesRule(json: JSON): Trampoline<KeyframesRule>;
26
+ function fromKeyframesRule(json: JSON, fromRule: (json: Rule.JSON) => Trampoline<Rule>): Trampoline<KeyframesRule>;
27
27
  }
28
28
  //# sourceMappingURL=keyframes.d.ts.map
@@ -1,6 +1,5 @@
1
1
  import { String } from "@siteimprove/alfa-string";
2
2
  import { Trampoline } from "@siteimprove/alfa-trampoline";
3
- import { Rule } from "../rule.js";
4
3
  import { GroupingRule } from "./grouping.js";
5
4
  /**
6
5
  * @public
@@ -41,8 +40,8 @@ export class KeyframesRule extends GroupingRule {
41
40
  /**
42
41
  * @internal
43
42
  */
44
- function fromKeyframesRule(json) {
45
- return Trampoline.traverse(json.rules, Rule.fromRule).map((rules) => KeyframesRule.of(json.name, rules));
43
+ function fromKeyframesRule(json, fromRule) {
44
+ return Trampoline.traverse(json.rules, fromRule).map((rules) => KeyframesRule.of(json.name, rules));
46
45
  }
47
46
  KeyframesRule.fromKeyframesRule = fromKeyframesRule;
48
47
  })(KeyframesRule || (KeyframesRule = {}));