@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.
Files changed (140) hide show
  1. package/CHANGELOG.md +291 -0
  2. package/dist/h.d.ts +37 -0
  3. package/dist/h.js +214 -0
  4. package/dist/index.d.ts +32 -0
  5. package/dist/index.js +32 -0
  6. package/dist/jsx-runtime.d.ts +26 -0
  7. package/dist/jsx-runtime.js +41 -0
  8. package/dist/jsx.d.ts +44 -0
  9. package/dist/jsx.js +45 -0
  10. package/dist/namespace.d.ts +43 -0
  11. package/dist/namespace.js +57 -0
  12. package/dist/native.d.ts +18 -0
  13. package/dist/native.js +449 -0
  14. package/dist/node/attribute/predicate/has-name.d.ts +11 -0
  15. package/dist/node/attribute/predicate/has-name.js +13 -0
  16. package/dist/node/attribute/predicate.d.ts +2 -0
  17. package/dist/node/attribute/predicate.js +2 -0
  18. package/dist/node/attribute.d.ts +90 -0
  19. package/dist/node/attribute.js +164 -0
  20. package/dist/node/comment.d.ts +42 -0
  21. package/dist/node/comment.js +74 -0
  22. package/dist/node/document.d.ts +59 -0
  23. package/dist/node/document.js +113 -0
  24. package/dist/node/element/input-type.d.ts +12 -0
  25. package/dist/node/element/input-type.js +10 -0
  26. package/dist/node/element/predicate/has-attribute.d.ts +12 -0
  27. package/dist/node/element/predicate/has-attribute.js +11 -0
  28. package/dist/node/element/predicate/has-box.d.ts +9 -0
  29. package/dist/node/element/predicate/has-box.js +7 -0
  30. package/dist/node/element/predicate/has-display-size.d.ts +7 -0
  31. package/dist/node/element/predicate/has-display-size.js +28 -0
  32. package/dist/node/element/predicate/has-id.d.ts +16 -0
  33. package/dist/node/element/predicate/has-id.js +17 -0
  34. package/dist/node/element/predicate/has-input-type.d.ts +12 -0
  35. package/dist/node/element/predicate/has-input-type.js +17 -0
  36. package/dist/node/element/predicate/has-name.d.ts +11 -0
  37. package/dist/node/element/predicate/has-name.js +13 -0
  38. package/dist/node/element/predicate/has-namespace.d.ts +12 -0
  39. package/dist/node/element/predicate/has-namespace.js +13 -0
  40. package/dist/node/element/predicate/has-tab-index.d.ts +12 -0
  41. package/dist/node/element/predicate/has-tab-index.js +11 -0
  42. package/dist/node/element/predicate/has-unique-id.d.ts +7 -0
  43. package/dist/node/element/predicate/has-unique-id.js +31 -0
  44. package/dist/node/element/predicate/is-actually-disabled.d.ts +8 -0
  45. package/dist/node/element/predicate/is-actually-disabled.js +47 -0
  46. package/dist/node/element/predicate/is-browsing-context-container.d.ts +8 -0
  47. package/dist/node/element/predicate/is-browsing-context-container.js +20 -0
  48. package/dist/node/element/predicate/is-content.d.ts +10 -0
  49. package/dist/node/element/predicate/is-content.js +17 -0
  50. package/dist/node/element/predicate/is-document-element.d.ts +6 -0
  51. package/dist/node/element/predicate/is-document-element.js +13 -0
  52. package/dist/node/element/predicate/is-draggable.d.ts +8 -0
  53. package/dist/node/element/predicate/is-draggable.js +28 -0
  54. package/dist/node/element/predicate/is-editing-host.d.ts +8 -0
  55. package/dist/node/element/predicate/is-editing-host.js +20 -0
  56. package/dist/node/element/predicate/is-fallback.d.ts +15 -0
  57. package/dist/node/element/predicate/is-fallback.js +28 -0
  58. package/dist/node/element/predicate/is-replaced.d.ts +8 -0
  59. package/dist/node/element/predicate/is-replaced.js +17 -0
  60. package/dist/node/element/predicate/is-scoped-to.d.ts +7 -0
  61. package/dist/node/element/predicate/is-scoped-to.js +11 -0
  62. package/dist/node/element/predicate/is-suggested-focusable.d.ts +14 -0
  63. package/dist/node/element/predicate/is-suggested-focusable.js +47 -0
  64. package/dist/node/element/predicate.d.ts +20 -0
  65. package/dist/node/element/predicate.js +20 -0
  66. package/dist/node/element.d.ts +122 -0
  67. package/dist/node/element.js +330 -0
  68. package/dist/node/fragment.d.ts +38 -0
  69. package/dist/node/fragment.js +68 -0
  70. package/dist/node/predicate/has-child.d.ts +7 -0
  71. package/dist/node/predicate/has-child.js +8 -0
  72. package/dist/node/predicate/has-descendant.d.ts +7 -0
  73. package/dist/node/predicate/has-descendant.js +8 -0
  74. package/dist/node/predicate/has-inclusive-descendant.d.ts +7 -0
  75. package/dist/node/predicate/has-inclusive-descendant.js +8 -0
  76. package/dist/node/predicate/has-text-content.d.ts +7 -0
  77. package/dist/node/predicate/has-text-content.js +12 -0
  78. package/dist/node/predicate/is-root.d.ts +7 -0
  79. package/dist/node/predicate/is-root.js +7 -0
  80. package/dist/node/predicate.d.ts +6 -0
  81. package/dist/node/predicate.js +6 -0
  82. package/dist/node/query/element-descendants.d.ts +8 -0
  83. package/dist/node/query/element-descendants.js +17 -0
  84. package/dist/node/query/element-id-map.d.ts +14 -0
  85. package/dist/node/query/element-id-map.js +30 -0
  86. package/dist/node/query/inclusive-element-descendants.d.ts +8 -0
  87. package/dist/node/query/inclusive-element-descendants.js +10 -0
  88. package/dist/node/query/index.d.ts +12 -0
  89. package/dist/node/query/index.js +13 -0
  90. package/dist/node/shadow.d.ts +66 -0
  91. package/dist/node/shadow.js +128 -0
  92. package/dist/node/slot.d.ts +29 -0
  93. package/dist/node/slot.js +41 -0
  94. package/dist/node/slotable.d.ts +29 -0
  95. package/dist/node/slotable.js +40 -0
  96. package/dist/node/text.d.ts +46 -0
  97. package/dist/node/text.js +83 -0
  98. package/dist/node/traversal/get-nodes-between.d.ts +24 -0
  99. package/dist/node/traversal/get-nodes-between.js +62 -0
  100. package/dist/node/traversal/lowest-common-ancestor.d.ts +13 -0
  101. package/dist/node/traversal/lowest-common-ancestor.js +19 -0
  102. package/dist/node/traversal.d.ts +2 -0
  103. package/dist/node/traversal.js +2 -0
  104. package/dist/node/type.d.ts +45 -0
  105. package/dist/node/type.js +74 -0
  106. package/dist/node.d.ts +263 -0
  107. package/dist/node.js +325 -0
  108. package/dist/style/block.d.ts +30 -0
  109. package/dist/style/block.js +63 -0
  110. package/dist/style/declaration.d.ts +65 -0
  111. package/dist/style/declaration.js +103 -0
  112. package/dist/style/rule/condition.d.ts +21 -0
  113. package/dist/style/rule/condition.js +30 -0
  114. package/dist/style/rule/font-face.d.ts +29 -0
  115. package/dist/style/rule/font-face.js +47 -0
  116. package/dist/style/rule/grouping.d.ts +22 -0
  117. package/dist/style/rule/grouping.js +34 -0
  118. package/dist/style/rule/import.d.ts +47 -0
  119. package/dist/style/rule/import.js +114 -0
  120. package/dist/style/rule/keyframe.d.ts +32 -0
  121. package/dist/style/rule/keyframe.js +53 -0
  122. package/dist/style/rule/keyframes.d.ts +28 -0
  123. package/dist/style/rule/keyframes.js +49 -0
  124. package/dist/style/rule/layer.d.ts +61 -0
  125. package/dist/style/rule/layer.js +106 -0
  126. package/dist/style/rule/media.d.ts +32 -0
  127. package/dist/style/rule/media.js +54 -0
  128. package/dist/style/rule/namespace.d.ts +31 -0
  129. package/dist/style/rule/namespace.js +52 -0
  130. package/dist/style/rule/page.d.ts +32 -0
  131. package/dist/style/rule/page.js +53 -0
  132. package/dist/style/rule/style.d.ts +35 -0
  133. package/dist/style/rule/style.js +62 -0
  134. package/dist/style/rule/supports.d.ts +32 -0
  135. package/dist/style/rule/supports.js +56 -0
  136. package/dist/style/rule.d.ts +60 -0
  137. package/dist/style/rule.js +109 -0
  138. package/dist/style/sheet.d.ts +37 -0
  139. package/dist/style/sheet.js +66 -0
  140. package/package.json +69 -0
@@ -0,0 +1,31 @@
1
+ import { Option } from "@siteimprove/alfa-option";
2
+ import { Trampoline } from "@siteimprove/alfa-trampoline";
3
+ import { Rule } from "../rule.js";
4
+ /**
5
+ * @public
6
+ */
7
+ export declare class NamespaceRule extends Rule<"namespace"> {
8
+ static of(namespace: string, prefix: Option<string>): NamespaceRule;
9
+ private readonly _namespace;
10
+ private readonly _prefix;
11
+ private constructor();
12
+ get namespace(): string;
13
+ get prefix(): Option<string>;
14
+ toJSON(): NamespaceRule.JSON;
15
+ toString(): string;
16
+ }
17
+ /**
18
+ * @public
19
+ */
20
+ export declare namespace NamespaceRule {
21
+ interface JSON extends Rule.JSON<"namespace"> {
22
+ namespace: string;
23
+ prefix: string | null;
24
+ }
25
+ function isNamespaceRule(value: unknown): value is NamespaceRule;
26
+ /**
27
+ * @internal
28
+ */
29
+ function fromNamespaceRule(json: JSON): Trampoline<NamespaceRule>;
30
+ }
31
+ //# sourceMappingURL=namespace.d.ts.map
@@ -0,0 +1,52 @@
1
+ import { Option } from "@siteimprove/alfa-option";
2
+ import { Trampoline } from "@siteimprove/alfa-trampoline";
3
+ import { Rule } from "../rule.js";
4
+ /**
5
+ * @public
6
+ */
7
+ export class NamespaceRule extends Rule {
8
+ static of(namespace, prefix) {
9
+ return new NamespaceRule(namespace, prefix);
10
+ }
11
+ _namespace;
12
+ _prefix;
13
+ constructor(namespace, prefix) {
14
+ super("namespace");
15
+ this._namespace = namespace;
16
+ this._prefix = prefix;
17
+ }
18
+ get namespace() {
19
+ return this._namespace;
20
+ }
21
+ get prefix() {
22
+ return this._prefix;
23
+ }
24
+ toJSON() {
25
+ return {
26
+ ...super.toJSON(),
27
+ namespace: this._namespace,
28
+ prefix: this._prefix.getOr(null),
29
+ };
30
+ }
31
+ toString() {
32
+ const prefix = this._prefix.map((prefix) => ` ${prefix}`).getOr("");
33
+ return `@namespace ${prefix}url(${this._namespace})`;
34
+ }
35
+ }
36
+ /**
37
+ * @public
38
+ */
39
+ (function (NamespaceRule) {
40
+ function isNamespaceRule(value) {
41
+ return value instanceof NamespaceRule;
42
+ }
43
+ NamespaceRule.isNamespaceRule = isNamespaceRule;
44
+ /**
45
+ * @internal
46
+ */
47
+ function fromNamespaceRule(json) {
48
+ return Trampoline.done(NamespaceRule.of(json.namespace, Option.from(json.prefix)));
49
+ }
50
+ NamespaceRule.fromNamespaceRule = fromNamespaceRule;
51
+ })(NamespaceRule || (NamespaceRule = {}));
52
+ //# sourceMappingURL=namespace.js.map
@@ -0,0 +1,32 @@
1
+ import { Trampoline } from "@siteimprove/alfa-trampoline";
2
+ import { Block } from "../block.js";
3
+ import type { Declaration } from "../declaration.js";
4
+ import { Rule } from "../rule.js";
5
+ /**
6
+ * @public
7
+ */
8
+ export declare class PageRule extends Rule<"page"> {
9
+ static of(selector: string, declarations: Iterable<Declaration>): PageRule;
10
+ private readonly _selector;
11
+ private readonly _style;
12
+ private constructor();
13
+ get selector(): string;
14
+ get style(): Block;
15
+ toJSON(): PageRule.JSON;
16
+ toString(): string;
17
+ }
18
+ /**
19
+ * @public
20
+ */
21
+ export declare namespace PageRule {
22
+ interface JSON extends Rule.JSON<"page"> {
23
+ selector: string;
24
+ style: Block.JSON | string;
25
+ }
26
+ function isPageRule(value: unknown): value is PageRule;
27
+ /**
28
+ * @internal
29
+ */
30
+ function fromPageRule(json: JSON): Trampoline<PageRule>;
31
+ }
32
+ //# sourceMappingURL=page.d.ts.map
@@ -0,0 +1,53 @@
1
+ import { String } from "@siteimprove/alfa-string";
2
+ import { Trampoline } from "@siteimprove/alfa-trampoline";
3
+ import { Block } from "../block.js";
4
+ import { Rule } from "../rule.js";
5
+ /**
6
+ * @public
7
+ */
8
+ export class PageRule extends Rule {
9
+ static of(selector, declarations) {
10
+ return new PageRule(selector, Array.from(declarations));
11
+ }
12
+ _selector;
13
+ _style;
14
+ constructor(selector, declarations) {
15
+ super("page");
16
+ this._selector = selector;
17
+ this._style = Block.of(declarations.filter((declaration) => declaration._attachParent(this)));
18
+ }
19
+ get selector() {
20
+ return this._selector;
21
+ }
22
+ get style() {
23
+ return this._style;
24
+ }
25
+ toJSON() {
26
+ return {
27
+ ...super.toJSON(),
28
+ selector: this._selector,
29
+ style: this._style.toJSON(),
30
+ };
31
+ }
32
+ toString() {
33
+ const style = this._style.toString();
34
+ return `@page ${this._selector} {${style === "" ? "" : `\n${String.indent(style)}\n`}}`;
35
+ }
36
+ }
37
+ /**
38
+ * @public
39
+ */
40
+ (function (PageRule) {
41
+ function isPageRule(value) {
42
+ return value instanceof PageRule;
43
+ }
44
+ PageRule.isPageRule = isPageRule;
45
+ /**
46
+ * @internal
47
+ */
48
+ function fromPageRule(json) {
49
+ return Trampoline.done(PageRule.of(json.selector, Block.from(json.style)));
50
+ }
51
+ PageRule.fromPageRule = fromPageRule;
52
+ })(PageRule || (PageRule = {}));
53
+ //# sourceMappingURL=page.js.map
@@ -0,0 +1,35 @@
1
+ import { Trampoline } from "@siteimprove/alfa-trampoline";
2
+ import { Block } from "../block.js";
3
+ import type { Declaration } from "../declaration.js";
4
+ import { Rule } from "../rule.js";
5
+ /**
6
+ * @public
7
+ */
8
+ export declare class StyleRule extends Rule<"style"> {
9
+ static of(selector: string, declarations: Iterable<Declaration>, hint?: boolean): StyleRule;
10
+ private readonly _selector;
11
+ private readonly _style;
12
+ private readonly _hint;
13
+ private constructor();
14
+ get selector(): string;
15
+ get style(): Block;
16
+ get hint(): boolean;
17
+ toJSON(): StyleRule.JSON;
18
+ toString(): string;
19
+ }
20
+ /**
21
+ * @public
22
+ */
23
+ export declare namespace StyleRule {
24
+ interface JSON extends Rule.JSON<"style"> {
25
+ selector: string;
26
+ style: Block.JSON | string;
27
+ }
28
+ function isStyleRule(value: unknown): value is StyleRule;
29
+ function isEmpty(rule: StyleRule): boolean;
30
+ /**
31
+ * @internal
32
+ */
33
+ function fromStyleRule(json: JSON): Trampoline<StyleRule>;
34
+ }
35
+ //# sourceMappingURL=style.d.ts.map
@@ -0,0 +1,62 @@
1
+ import { String } from "@siteimprove/alfa-string";
2
+ import { Trampoline } from "@siteimprove/alfa-trampoline";
3
+ import { Block } from "../block.js";
4
+ import { Rule } from "../rule.js";
5
+ /**
6
+ * @public
7
+ */
8
+ export class StyleRule extends Rule {
9
+ static of(selector, declarations, hint = false) {
10
+ return new StyleRule(selector, Array.from(declarations), hint);
11
+ }
12
+ _selector;
13
+ _style;
14
+ _hint;
15
+ constructor(selector, declarations, hint) {
16
+ super("style");
17
+ this._selector = selector;
18
+ this._style = Block.of(declarations.filter((declaration) => declaration._attachParent(this)));
19
+ this._hint = hint;
20
+ }
21
+ get selector() {
22
+ return this._selector;
23
+ }
24
+ get style() {
25
+ return this._style;
26
+ }
27
+ get hint() {
28
+ return this._hint;
29
+ }
30
+ toJSON() {
31
+ return {
32
+ ...super.toJSON(),
33
+ selector: this._selector,
34
+ style: this._style.toJSON(),
35
+ };
36
+ }
37
+ toString() {
38
+ const style = this._style.toString();
39
+ return `${this._selector} {${style === "" ? "" : `\n${String.indent(style)}\n`}}`;
40
+ }
41
+ }
42
+ /**
43
+ * @public
44
+ */
45
+ (function (StyleRule) {
46
+ function isStyleRule(value) {
47
+ return value instanceof StyleRule;
48
+ }
49
+ StyleRule.isStyleRule = isStyleRule;
50
+ function isEmpty(rule) {
51
+ return rule.style.isEmpty();
52
+ }
53
+ StyleRule.isEmpty = isEmpty;
54
+ /**
55
+ * @internal
56
+ */
57
+ function fromStyleRule(json) {
58
+ return Trampoline.done(StyleRule.of(json.selector, Block.from(json.style)));
59
+ }
60
+ StyleRule.fromStyleRule = fromStyleRule;
61
+ })(StyleRule || (StyleRule = {}));
62
+ //# sourceMappingURL=style.js.map
@@ -0,0 +1,32 @@
1
+ import { Feature } from "@siteimprove/alfa-css-feature";
2
+ import type { Option } from "@siteimprove/alfa-option";
3
+ import { Trampoline } from "@siteimprove/alfa-trampoline";
4
+ import { Rule } from "../rule.js";
5
+ import { ConditionRule } from "./condition.js";
6
+ import type { Device } from "@siteimprove/alfa-device";
7
+ import type { Predicate } from "@siteimprove/alfa-predicate";
8
+ /**
9
+ * @public
10
+ */
11
+ export declare class SupportsRule extends ConditionRule<"supports"> {
12
+ static of(condition: string, rules: Iterable<Rule>): SupportsRule;
13
+ private readonly _query;
14
+ private constructor();
15
+ get query(): Option<Feature.Supports.Query>;
16
+ toJSON(): SupportsRule.JSON;
17
+ toString(): string;
18
+ }
19
+ /**
20
+ * @public
21
+ */
22
+ export declare namespace SupportsRule {
23
+ interface JSON extends ConditionRule.JSON<"supports"> {
24
+ }
25
+ function isSupportsRule(value: unknown): value is SupportsRule;
26
+ function matches(device: Device): Predicate<SupportsRule>;
27
+ /**
28
+ * @internal
29
+ */
30
+ function fromSupportsRule(json: JSON): Trampoline<SupportsRule>;
31
+ }
32
+ //# sourceMappingURL=supports.d.ts.map
@@ -0,0 +1,56 @@
1
+ import { Lexer } from "@siteimprove/alfa-css";
2
+ import { Feature } from "@siteimprove/alfa-css-feature";
3
+ import { String } from "@siteimprove/alfa-string";
4
+ import { Trampoline } from "@siteimprove/alfa-trampoline";
5
+ import { Rule } from "../rule.js";
6
+ import { ConditionRule } from "./condition.js";
7
+ /**
8
+ * @public
9
+ */
10
+ export class SupportsRule extends ConditionRule {
11
+ static of(condition, rules) {
12
+ return new SupportsRule(condition, Array.from(rules));
13
+ }
14
+ _query;
15
+ constructor(condition, rules) {
16
+ super("supports", condition, rules);
17
+ this._query = Feature.parseSupportsQuery(Lexer.lex(condition))
18
+ .map(([, query]) => query)
19
+ .ok();
20
+ }
21
+ get query() {
22
+ return this._query;
23
+ }
24
+ toJSON() {
25
+ return super.toJSON();
26
+ }
27
+ toString() {
28
+ const rules = this._rules
29
+ .map((rule) => String.indent(rule.toString()))
30
+ .join("\n\n");
31
+ return `@supports ${this._condition} {${rules === "" ? "" : `\n${rules}\n`}}`;
32
+ }
33
+ }
34
+ /**
35
+ * @public
36
+ */
37
+ (function (SupportsRule) {
38
+ function isSupportsRule(value) {
39
+ return value instanceof SupportsRule;
40
+ }
41
+ SupportsRule.isSupportsRule = isSupportsRule;
42
+ function matches(device) {
43
+ // If rule.query is None, Alfa couldn't parse the query which
44
+ // means it does not support it.
45
+ return (rule) => rule.query.some((query) => query.matches(device));
46
+ }
47
+ SupportsRule.matches = matches;
48
+ /**
49
+ * @internal
50
+ */
51
+ function fromSupportsRule(json) {
52
+ return Trampoline.traverse(json.rules, Rule.fromRule).map((rules) => SupportsRule.of(json.condition, rules));
53
+ }
54
+ SupportsRule.fromSupportsRule = fromSupportsRule;
55
+ })(SupportsRule || (SupportsRule = {}));
56
+ //# sourceMappingURL=supports.js.map
@@ -0,0 +1,60 @@
1
+ import type { Equatable } from "@siteimprove/alfa-equatable";
2
+ import { Iterable } from "@siteimprove/alfa-iterable";
3
+ import type { Serializable } from "@siteimprove/alfa-json";
4
+ import { Option } from "@siteimprove/alfa-option";
5
+ import type { Trampoline } from "@siteimprove/alfa-trampoline";
6
+ import type * as json from "@siteimprove/alfa-json";
7
+ import type { Sheet } from "./sheet.js";
8
+ import { FontFaceRule, ImportRule, KeyframeRule, KeyframesRule, Layer, MediaRule, NamespaceRule, PageRule, StyleRule, SupportsRule } from "../index.js";
9
+ /**
10
+ * @public
11
+ */
12
+ export declare abstract class Rule<T extends string = string> implements Equatable, Serializable {
13
+ protected _owner: Option<Sheet>;
14
+ protected _parent: Option<Rule>;
15
+ private readonly _type;
16
+ protected constructor(type: T);
17
+ get type(): T;
18
+ get owner(): Option<Sheet>;
19
+ get parent(): Option<Rule>;
20
+ children(): Iterable<Rule>;
21
+ descendants(): Iterable<Rule>;
22
+ ancestors(): Iterable<Rule>;
23
+ inclusiveAncestors(): Iterable<Rule>;
24
+ equals(value: unknown): value is this;
25
+ toJSON(): Rule.JSON<T>;
26
+ /**
27
+ * @internal
28
+ */
29
+ _attachOwner(owner: Sheet): boolean;
30
+ /**
31
+ * @internal
32
+ */
33
+ _attachParent(parent: Rule): boolean;
34
+ }
35
+ /**
36
+ * @public
37
+ */
38
+ export declare namespace Rule {
39
+ interface JSON<T extends string = string> {
40
+ [key: string]: json.JSON;
41
+ type: T;
42
+ }
43
+ function from(json: FontFaceRule.JSON): FontFaceRule;
44
+ function from(json: ImportRule.JSON): ImportRule;
45
+ function from(json: KeyframeRule.JSON): KeyframeRule;
46
+ function from(json: KeyframesRule.JSON): KeyframesRule;
47
+ function from(json: Layer.BlockRule.JSON): Layer.BlockRule;
48
+ function from(json: Layer.StatementRule.JSON): Layer.StatementRule;
49
+ function from(json: MediaRule.JSON): MediaRule;
50
+ function from(json: NamespaceRule.JSON): NamespaceRule;
51
+ function from(json: PageRule.JSON): PageRule;
52
+ function from(json: StyleRule.JSON): StyleRule;
53
+ function from(json: SupportsRule.JSON): SupportsRule;
54
+ function from(json: JSON): Rule;
55
+ /**
56
+ * @internal
57
+ */
58
+ function fromRule(json: JSON): Trampoline<Rule>;
59
+ }
60
+ //# sourceMappingURL=rule.d.ts.map
@@ -0,0 +1,109 @@
1
+ import { Iterable } from "@siteimprove/alfa-iterable";
2
+ import { None, Option } from "@siteimprove/alfa-option";
3
+ import { FontFaceRule, ImportRule, KeyframeRule, KeyframesRule, Layer, MediaRule, NamespaceRule, PageRule, StyleRule, SupportsRule, } from "../index.js";
4
+ /**
5
+ * @public
6
+ */
7
+ export class Rule {
8
+ _owner = None;
9
+ _parent = None;
10
+ _type;
11
+ constructor(type) {
12
+ this._type = type;
13
+ }
14
+ get type() {
15
+ return this._type;
16
+ }
17
+ get owner() {
18
+ return this._owner;
19
+ }
20
+ get parent() {
21
+ return this._parent;
22
+ }
23
+ *children() { }
24
+ *descendants() {
25
+ for (const child of this.children()) {
26
+ yield child;
27
+ yield* child.descendants();
28
+ }
29
+ }
30
+ *ancestors() {
31
+ for (const parent of this._parent) {
32
+ yield parent;
33
+ yield* parent.ancestors();
34
+ }
35
+ }
36
+ *inclusiveAncestors() {
37
+ yield this;
38
+ yield* this.ancestors();
39
+ }
40
+ equals(value) {
41
+ return value === this;
42
+ }
43
+ toJSON() {
44
+ return { type: this._type };
45
+ }
46
+ /**
47
+ * @internal
48
+ */
49
+ _attachOwner(owner) {
50
+ if (this._owner.isSome()) {
51
+ return false;
52
+ }
53
+ this._owner = Option.of(owner);
54
+ // Recursively attach the owner to all children.
55
+ return Iterable.every(this.children(), (rule) => rule._attachOwner(owner));
56
+ }
57
+ /**
58
+ * @internal
59
+ */
60
+ _attachParent(parent) {
61
+ if (this._parent.isSome()) {
62
+ return false;
63
+ }
64
+ this._parent = Option.of(parent);
65
+ return true;
66
+ }
67
+ }
68
+ /**
69
+ * @public
70
+ */
71
+ (function (Rule) {
72
+ function from(json) {
73
+ return fromRule(json).run();
74
+ }
75
+ Rule.from = from;
76
+ /**
77
+ * @internal
78
+ */
79
+ function fromRule(json) {
80
+ switch (json.type) {
81
+ case "font-face":
82
+ return FontFaceRule.fromFontFaceRule(json);
83
+ case "import":
84
+ return ImportRule.fromImportRule(json);
85
+ case "keyframe":
86
+ return KeyframeRule.fromKeyframeRule(json);
87
+ case "keyframes":
88
+ return KeyframesRule.fromKeyframesRule(json);
89
+ case "layer-block":
90
+ return Layer.BlockRule.fromLayerBlockRule(json);
91
+ case "layer-statement":
92
+ return Layer.StatementRule.fromLayerStatementRule(json);
93
+ case "media":
94
+ return MediaRule.fromMediaRule(json);
95
+ case "namespace":
96
+ return NamespaceRule.fromNamespaceRule(json);
97
+ case "page":
98
+ return PageRule.fromPageRule(json);
99
+ case "style":
100
+ return StyleRule.fromStyleRule(json);
101
+ case "supports":
102
+ return SupportsRule.fromSupportsRule(json);
103
+ default:
104
+ throw new Error(`Unexpected rule of type: ${json.type}`);
105
+ }
106
+ }
107
+ Rule.fromRule = fromRule;
108
+ })(Rule || (Rule = {}));
109
+ //# sourceMappingURL=rule.js.map
@@ -0,0 +1,37 @@
1
+ import type { Equatable } from "@siteimprove/alfa-equatable";
2
+ import type { Serializable } from "@siteimprove/alfa-json";
3
+ import { Option } from "@siteimprove/alfa-option";
4
+ import type * as json from "@siteimprove/alfa-json";
5
+ import { Rule } from "./rule.js";
6
+ /**
7
+ * @public
8
+ */
9
+ export declare class Sheet implements Equatable, Serializable {
10
+ static of(rules: Iterable<Rule>, disabled?: boolean, condition?: Option<string>): Sheet;
11
+ static empty(): Sheet;
12
+ private _rules;
13
+ private readonly _disabled;
14
+ private readonly _condition;
15
+ private constructor();
16
+ get rules(): Iterable<Rule>;
17
+ get disabled(): boolean;
18
+ get condition(): Option<string>;
19
+ children(): Iterable<Rule>;
20
+ descendants(): Iterable<Rule>;
21
+ equals(value: unknown): value is this;
22
+ toJSON(): Sheet.JSON;
23
+ toString(): string;
24
+ }
25
+ /**
26
+ * @public
27
+ */
28
+ export declare namespace Sheet {
29
+ interface JSON {
30
+ [key: string]: json.JSON;
31
+ rules: Array<Rule.JSON>;
32
+ disabled: boolean;
33
+ condition: string | null;
34
+ }
35
+ function from(json: JSON): Sheet;
36
+ }
37
+ //# sourceMappingURL=sheet.d.ts.map
@@ -0,0 +1,66 @@
1
+ import { Option, None } from "@siteimprove/alfa-option";
2
+ import { Rule } from "./rule.js";
3
+ /**
4
+ * @public
5
+ */
6
+ export class Sheet {
7
+ static of(rules, disabled = false, condition = None) {
8
+ return new Sheet(Array.from(rules), disabled, condition);
9
+ }
10
+ static empty() {
11
+ return new Sheet([], false, None);
12
+ }
13
+ _rules;
14
+ _disabled;
15
+ _condition;
16
+ constructor(rules, disabled, condition) {
17
+ this._rules = rules.filter((rule) => rule._attachOwner(this));
18
+ this._disabled = disabled;
19
+ this._condition = condition;
20
+ }
21
+ get rules() {
22
+ return this._rules;
23
+ }
24
+ get disabled() {
25
+ return this._disabled;
26
+ }
27
+ get condition() {
28
+ return this._condition;
29
+ }
30
+ *children() {
31
+ yield* this._rules;
32
+ }
33
+ *descendants() {
34
+ for (const child of this.children()) {
35
+ yield child;
36
+ yield* child.descendants();
37
+ }
38
+ }
39
+ equals(value) {
40
+ return (value instanceof Sheet &&
41
+ value._disabled === this._disabled &&
42
+ value._condition.equals(this._condition) &&
43
+ value._rules.length === this._rules.length &&
44
+ value._rules.every((rule, i) => rule.equals(this._rules[i])));
45
+ }
46
+ toJSON() {
47
+ return {
48
+ rules: [...this._rules].map((rule) => rule.toJSON()),
49
+ disabled: this._disabled,
50
+ condition: this._condition.getOr(null),
51
+ };
52
+ }
53
+ toString() {
54
+ return this._rules.join("\n");
55
+ }
56
+ }
57
+ /**
58
+ * @public
59
+ */
60
+ (function (Sheet) {
61
+ function from(json) {
62
+ return Sheet.of(json.rules.map(Rule.from), json.disabled, Option.from(json.condition));
63
+ }
64
+ Sheet.from = from;
65
+ })(Sheet || (Sheet = {}));
66
+ //# sourceMappingURL=sheet.js.map