@markuplint/ml-spec 3.0.0-canary.5 → 3.0.0-dev.176

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 (128) hide show
  1. package/README.md +1 -1
  2. package/lib/constant/aria-version.d.ts +2 -0
  3. package/lib/constant/aria-version.js +5 -0
  4. package/lib/dom-traverse/accname-computation.js +3 -1
  5. package/lib/dom-traverse/get-attr-specs.d.ts +1 -1
  6. package/lib/dom-traverse/get-attr-specs.js +3 -1
  7. package/lib/dom-traverse/get-computed-aria-props.d.ts +6 -6
  8. package/lib/dom-traverse/get-computed-aria-props.js +4 -2
  9. package/lib/dom-traverse/get-computed-role.d.ts +6 -1
  10. package/lib/dom-traverse/get-computed-role.js +41 -10
  11. package/lib/dom-traverse/get-content-model.d.ts +28 -2
  12. package/lib/dom-traverse/get-content-model.js +4 -2
  13. package/lib/dom-traverse/get-explicit-role.js +9 -4
  14. package/lib/dom-traverse/get-implicit-role.d.ts +6 -2
  15. package/lib/dom-traverse/get-implicit-role.js +6 -2
  16. package/lib/dom-traverse/get-non-presentational-ancestor.d.ts +10 -4
  17. package/lib/dom-traverse/get-non-presentational-ancestor.js +10 -2
  18. package/lib/dom-traverse/get-permitted-roles.d.ts +7 -3
  19. package/lib/dom-traverse/get-permitted-roles.js +3 -1
  20. package/lib/dom-traverse/get-spec.d.ts +4 -1
  21. package/lib/dom-traverse/get-spec.js +3 -1
  22. package/lib/dom-traverse/has-required-owned-elements.d.ts +8 -2
  23. package/lib/dom-traverse/has-required-owned-elements.js +14 -8
  24. package/lib/dom-traverse/is-exposed.d.ts +1 -1
  25. package/lib/dom-traverse/is-exposed.js +43 -7
  26. package/lib/dom-traverse/matches-context-role.d.ts +7 -0
  27. package/lib/dom-traverse/matches-context-role.js +27 -0
  28. package/lib/dom-traverse/may-be-focusable.d.ts +1 -1
  29. package/lib/dom-traverse/may-be-focusable.js +3 -1
  30. package/lib/index.d.ts +4 -0
  31. package/lib/index.js +4 -0
  32. package/lib/specs/aria-specs.d.ts +7 -4
  33. package/lib/specs/content-model-category-to-tag-names.d.ts +4 -1
  34. package/lib/specs/get-aria.d.ts +8 -1
  35. package/lib/specs/get-aria.js +8 -2
  36. package/lib/specs/get-attr-specs.d.ts +6 -2
  37. package/lib/specs/get-attr-specs.js +2 -14
  38. package/lib/specs/get-implicit-role.d.ts +7 -1
  39. package/lib/specs/get-permitted-roles.d.ts +9 -3
  40. package/lib/specs/get-permitted-roles.js +19 -15
  41. package/lib/specs/get-role-spec.d.ts +10 -3
  42. package/lib/specs/get-role-spec.js +2 -2
  43. package/lib/specs/get-selectors-by-content-model-category.d.ts +1 -1
  44. package/lib/specs/get-selectors-by-content-model-category.js +1 -1
  45. package/lib/specs/get-spec-by-tag-name.d.ts +5 -1
  46. package/lib/specs/get-spec-by-tag-name.js +3 -2
  47. package/lib/specs/is-nothing-content-model.d.ts +5 -0
  48. package/lib/specs/is-nothing-content-model.js +14 -0
  49. package/lib/specs/is-palpable-elements.d.ts +8 -4
  50. package/lib/specs/is-palpable-elements.js +6 -4
  51. package/lib/specs/is-void-element.js +3 -1
  52. package/lib/specs/resolve-version.d.ts +5 -1
  53. package/lib/specs/resolve-version.js +1 -1
  54. package/lib/specs/schema-to-spec.d.ts +4 -4
  55. package/lib/specs/schema-to-spec.js +29 -18
  56. package/lib/types/aria.d.ts +149 -114
  57. package/lib/types/attributes.d.ts +1490 -111
  58. package/lib/types/index.d.ts +178 -149
  59. package/lib/types/permitted-structures.d.ts +74 -31
  60. package/lib/utils/merge-array.d.ts +9 -4
  61. package/lib/utils/resolve-namespace.d.ts +4 -4
  62. package/lib/utils/resolve-namespace.js +3 -2
  63. package/lib/utils/validateAriaVersion.d.ts +2 -0
  64. package/lib/utils/validateAriaVersion.js +8 -0
  65. package/package.json +13 -8
  66. package/{src/dom-traverse/accname-computation.spec.ts → test/dom-traverse/accname-computation.spec.js} +4 -4
  67. package/test/dom-traverse/get-computed-aria-props.spec.js +758 -0
  68. package/test/dom-traverse/get-computed-role.spec.js +294 -0
  69. package/test/dom-traverse/get-implicit-role.spec.js +40 -0
  70. package/{src/dom-traverse/has-required-owned-elements.spec.ts → test/dom-traverse/has-required-owned-elements.spec.js} +7 -9
  71. package/{src/dom-traverse/is-exposed.spec.ts → test/dom-traverse/is-exposed.spec.js} +29 -9
  72. package/test/dom-traverse/matches-context-role.spec.js +60 -0
  73. package/{src/specs/get-attr-specs.spec.ts → test/specs/get-attr-specs.spec.js} +2 -8
  74. package/{src/specs/get-implicit-role.spec.ts → test/specs/get-implicit-role.spec.js} +9 -11
  75. package/{src/specs/get-permitted-roles.spec.ts → test/specs/get-permitted-roles.spec.js} +8 -10
  76. package/{src/specs/get-role-spec.spec.ts → test/specs/get-role-spec.spec.js} +4 -4
  77. package/{src/specs/get-spec-by-tag-name.spec.ts → test/specs/get-spec-by-tag-name.spec.js} +2 -2
  78. package/test/specs/resolve-version.spec.js +34 -0
  79. package/test/specs/schema-to-spec.spec.js +61 -0
  80. package/{src/utils/resolve-namespace.spec.ts → test/utils/resolve-namespace.spec.js} +1 -1
  81. package/lib/types/permitted-structres.d.ts +0 -58
  82. package/lib/types/permitted-structres.js +0 -8
  83. package/schemas/aria.schema.json +0 -258
  84. package/schemas/attributes.schema.json +0 -204
  85. package/schemas/content-models.schema.json +0 -199
  86. package/schemas/element.schema.json +0 -11
  87. package/schemas/global-attributes.schema.json +0 -761
  88. package/src/dom-traverse/accname-computation.ts +0 -5
  89. package/src/dom-traverse/get-attr-specs.ts +0 -8
  90. package/src/dom-traverse/get-computed-aria-props.spec.ts +0 -368
  91. package/src/dom-traverse/get-computed-aria-props.ts +0 -130
  92. package/src/dom-traverse/get-computed-role.spec.ts +0 -134
  93. package/src/dom-traverse/get-computed-role.ts +0 -181
  94. package/src/dom-traverse/get-content-model.ts +0 -32
  95. package/src/dom-traverse/get-explicit-role.ts +0 -112
  96. package/src/dom-traverse/get-implicit-role.ts +0 -36
  97. package/src/dom-traverse/get-non-presentational-ancestor.ts +0 -20
  98. package/src/dom-traverse/get-permitted-roles.ts +0 -7
  99. package/src/dom-traverse/get-spec.ts +0 -7
  100. package/src/dom-traverse/has-required-owned-elements.ts +0 -85
  101. package/src/dom-traverse/is-exposed.ts +0 -196
  102. package/src/dom-traverse/may-be-focusable.ts +0 -21
  103. package/src/index.ts +0 -23
  104. package/src/specs/aria-specs.ts +0 -6
  105. package/src/specs/content-model-category-to-tag-names.ts +0 -15
  106. package/src/specs/get-aria.ts +0 -85
  107. package/src/specs/get-attr-specs.ts +0 -116
  108. package/src/specs/get-implicit-role.ts +0 -17
  109. package/src/specs/get-permitted-roles.ts +0 -87
  110. package/src/specs/get-role-spec.ts +0 -72
  111. package/src/specs/get-selectors-by-content-model-category.ts +0 -10
  112. package/src/specs/get-spec-by-tag-name.ts +0 -20
  113. package/src/specs/is-palpable-elements.ts +0 -55
  114. package/src/specs/is-presentational.ts +0 -6
  115. package/src/specs/is-void-element.ts +0 -22
  116. package/src/specs/resolve-version.ts +0 -20
  117. package/src/specs/schema-to-spec.spec.ts +0 -39
  118. package/src/specs/schema-to-spec.ts +0 -103
  119. package/src/types/aria.ts +0 -153
  120. package/src/types/attributes.ts +0 -1473
  121. package/src/types/index.ts +0 -255
  122. package/src/types/permitted-structres.ts +0 -100
  123. package/src/types/permitted-structures.ts +0 -96
  124. package/src/utils/get-ns.ts +0 -18
  125. package/src/utils/merge-array.ts +0 -35
  126. package/src/utils/resolve-namespace.ts +0 -40
  127. package/tsconfig.test.json +0 -3
  128. package/tsconfig.tsbuildinfo +0 -1
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  <details>
10
10
  <summary>If you are installing purposely, how below:</summary>
11
11
 
12
- ```sh
12
+ ```shell
13
13
  $ npm install @markuplint/ml-spec
14
14
 
15
15
  $ yarn add @markuplint/ml-spec
@@ -0,0 +1,2 @@
1
+ export declare const ariaVersions: readonly ['1.1', '1.2', '1.3'];
2
+ export declare const ARIA_RECOMMENDED_VERSION: '1.2';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ARIA_RECOMMENDED_VERSION = exports.ariaVersions = void 0;
4
+ exports.ariaVersions = ['1.1', '1.2', '1.3'];
5
+ exports.ARIA_RECOMMENDED_VERSION = '1.2';
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAccname = void 0;
4
4
  const dom_accessibility_api_1 = require("dom-accessibility-api");
5
- function getAccname(el) {
5
+ function getAccname(
6
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
7
+ el) {
6
8
  return (0, dom_accessibility_api_1.computeAccessibleName)(el);
7
9
  }
8
10
  exports.getAccname = getAccname;
@@ -1,2 +1,2 @@
1
1
  import type { MLMLSpec } from '../types';
2
- export declare function getAttrSpecs(el: Element, schema: MLMLSpec): import("../types").Attribute[] | null;
2
+ export declare function getAttrSpecs(el: Element, schema: MLMLSpec): readonly import('../types').Attribute[] | null;
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAttrSpecs = void 0;
4
4
  const get_attr_specs_1 = require("../specs/get-attr-specs");
5
- function getAttrSpecs(el, schema) {
5
+ function getAttrSpecs(
6
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
7
+ el, schema) {
6
8
  return (0, get_attr_specs_1.getAttrSpecs)(el.localName, el.namespaceURI, schema);
7
9
  }
8
10
  exports.getAttrSpecs = getAttrSpecs;
@@ -1,12 +1,12 @@
1
1
  import type { ARIAVersion, MLMLSpec } from '../types';
2
2
  type ARIAProps = Record<string, ARIAProp>;
3
3
  type ARIAProp = {
4
- name: string;
5
- value: string | undefined;
6
- required: boolean;
7
- deprecated: boolean;
8
- from: ARIAPropReferenceType;
4
+ name: string;
5
+ value: string | undefined;
6
+ required: boolean;
7
+ deprecated: boolean;
8
+ from: ARIAPropReferenceType;
9
9
  };
10
10
  type ARIAPropReferenceType = 'default' | 'html-attr' | 'aria-attr';
11
- export declare function getComputedAriaProps(specs: Readonly<MLMLSpec>, el: Element, version: ARIAVersion): ARIAProps;
11
+ export declare function getComputedAriaProps(specs: MLMLSpec, el: Element, version: ARIAVersion): ARIAProps;
12
12
  export {};
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getComputedAriaProps = void 0;
4
4
  const aria_specs_1 = require("../specs/aria-specs");
5
5
  const get_computed_role_1 = require("./get-computed-role");
6
- function getComputedAriaProps(specs, el, version) {
6
+ function getComputedAriaProps(specs,
7
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
8
+ el, version) {
7
9
  const ariaSpecs = (0, aria_specs_1.ariaSpecs)(specs, version);
8
10
  const { role } = (0, get_computed_role_1.getComputedRole)(specs, el, version);
9
11
  if (!role) {
@@ -88,7 +90,7 @@ function isValidAriaValue(spec, role, value, enumList) {
88
90
  }
89
91
  case 'token':
90
92
  case 'token list': {
91
- if (!enumList.length) {
93
+ if (enumList.length === 0) {
92
94
  throw new Error('Need an enum list in token and token list types');
93
95
  }
94
96
  return enumList.includes(value.toLowerCase());
@@ -1,2 +1,7 @@
1
1
  import type { ARIAVersion, ComputedRole, MLMLSpec } from '../types';
2
- export declare function getComputedRole(specs: Readonly<MLMLSpec>, el: Element, version: ARIAVersion): ComputedRole;
2
+ export declare function getComputedRole(
3
+ specs: MLMLSpec,
4
+ el: Element,
5
+ version: ARIAVersion,
6
+ assumeSingleNode?: boolean,
7
+ ): ComputedRole;
@@ -8,12 +8,26 @@ const get_explicit_role_1 = require("./get-explicit-role");
8
8
  const get_implicit_role_1 = require("./get-implicit-role");
9
9
  const get_non_presentational_ancestor_1 = require("./get-non-presentational-ancestor");
10
10
  const has_required_owned_elements_1 = require("./has-required-owned-elements");
11
+ const matches_context_role_1 = require("./matches-context-role");
11
12
  const may_be_focusable_1 = require("./may-be-focusable");
12
- function getComputedRole(specs, el, version) {
13
- var _a, _b, _c, _d;
13
+ function getComputedRole(specs,
14
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
15
+ el, version, assumeSingleNode = false) {
16
+ var _a, _b;
14
17
  const implicitRole = (0, get_implicit_role_1.getImplicitRole)(specs, el, version);
15
18
  const explicitRole = (0, get_explicit_role_1.getExplicitRole)(specs, el, version);
16
- const computedRole = explicitRole.role ? explicitRole : implicitRole;
19
+ const computedRole = explicitRole.role
20
+ ? explicitRole
21
+ : {
22
+ ...implicitRole,
23
+ errorType: explicitRole.errorType === 'NO_EXPLICIT' ? undefined : explicitRole.errorType,
24
+ };
25
+ if (assumeSingleNode) {
26
+ return {
27
+ ...computedRole,
28
+ errorType: 'NO_OWNER',
29
+ };
30
+ }
17
31
  /**
18
32
  * Presentational Roles Conflict Resolution
19
33
  *
@@ -39,7 +53,20 @@ function getComputedRole(specs, el, version) {
39
53
  * However, the presentational role behaves transparently
40
54
  * according to the sample code in WAI-ARIA specification.
41
55
  */
42
- if ((_a = computedRole.role) === null || _a === void 0 ? void 0 : _a.requiredContextRole.length) {
56
+ if (computedRole.role && computedRole.role.requiredContextRole.length > 0) {
57
+ /**
58
+ * An element fragment that serves as the root without a parent element
59
+ * cannot satisfy the "Required Context Role" condition.
60
+ * Therefore, under normal circumstances, the `role` will disappear.
61
+ * However, in this specific case, it will fall back to both explicit
62
+ * and implicit roles. Note that the explicit role takes precedence.
63
+ */
64
+ if (el.parentElement === null) {
65
+ return {
66
+ ...computedRole,
67
+ errorType: 'NO_OWNER',
68
+ };
69
+ }
43
70
  const nonPresentationalAncestor = (0, get_non_presentational_ancestor_1.getNonPresentationalAncestor)(el, specs, version);
44
71
  if (!nonPresentationalAncestor.role) {
45
72
  return {
@@ -48,7 +75,7 @@ function getComputedRole(specs, el, version) {
48
75
  errorType: 'NO_OWNER',
49
76
  };
50
77
  }
51
- if (!((_b = computedRole.role) === null || _b === void 0 ? void 0 : _b.requiredContextRole.includes(nonPresentationalAncestor.role.name))) {
78
+ if (!(0, matches_context_role_1.matchesContextRole)(computedRole.role.requiredContextRole, el, specs, version)) {
52
79
  return {
53
80
  el,
54
81
  role: null,
@@ -111,12 +138,12 @@ function getComputedRole(specs, el, version) {
111
138
  */
112
139
  if (explicitRole.role) {
113
140
  const nonPresentationalAncestor = (0, get_non_presentational_ancestor_1.getNonPresentationalAncestor)(el, specs, version);
114
- if ((_c = nonPresentationalAncestor.role) === null || _c === void 0 ? void 0 : _c.requiredOwnedElements.length) {
141
+ if (nonPresentationalAncestor.role && ((_a = nonPresentationalAncestor.role) === null || _a === void 0 ? void 0 : _a.requiredOwnedElements.length) > 0) {
115
142
  if (nonPresentationalAncestor.role.requiredOwnedElements.some(expected => {
116
143
  // const ancestor = nonPresentationalAncestor.el;
117
144
  // const ancestorImplicitRole = getImplicitRole(specs, ancestor, version);
118
145
  // console.log({ nonPresentationalAncestor, ancestorImplicitRole });
119
- return (0, has_required_owned_elements_1.isRequiredOwnedElement)(implicitRole, expected, specs, version);
146
+ return (0, has_required_owned_elements_1.isRequiredOwnedElement)(implicitRole.el, implicitRole.role, expected, specs, version);
120
147
  })) {
121
148
  return {
122
149
  ...implicitRole,
@@ -137,7 +164,7 @@ function getComputedRole(specs, el, version) {
137
164
  */
138
165
  const { props } = (0, aria_specs_1.ariaSpecs)(specs, version);
139
166
  for (const attr of Array.from(el.attributes)) {
140
- if ((_d = props.find(p => p.name === attr.name)) === null || _d === void 0 ? void 0 : _d.isGlobal) {
167
+ if ((_b = props.find(p => p.name === attr.name)) === null || _b === void 0 ? void 0 : _b.isGlobal) {
141
168
  return {
142
169
  ...implicitRole,
143
170
  errorType: 'GLOBAL_PROP_MUST_NOT_BE_PRESENTATIONAL',
@@ -151,7 +178,9 @@ exports.getComputedRole = getComputedRole;
151
178
  * The attribute is available in its owner element,
152
179
  * it has the attribute.
153
180
  */
154
- function isEnabledAttr(el, specs, attrName) {
181
+ function isEnabledAttr(
182
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
183
+ el, specs, attrName) {
155
184
  const attrs = (0, get_attr_specs_1.getAttrSpecs)(el, specs);
156
185
  const attr = attrs === null || attrs === void 0 ? void 0 : attrs.find(attr => attr.name === attrName);
157
186
  return !!attr && el.hasAttribute(attrName);
@@ -159,7 +188,9 @@ function isEnabledAttr(el, specs, attrName) {
159
188
  /**
160
189
  * Determines whether some ancestors match the condition that the specified callback function.
161
190
  */
162
- function someAncestors(el, predicate) {
191
+ function someAncestors(
192
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
193
+ el, predicate) {
163
194
  const list = [];
164
195
  let current = el;
165
196
  while (current) {
@@ -1,3 +1,29 @@
1
1
  import type { ElementSpec } from '../types';
2
- import type { PermittedContentPattern } from '../types/permitted-structures';
3
- export declare function getContentModel(el: Element, specs: Pick<ElementSpec, 'name' | 'contentModel'>[]): boolean | PermittedContentPattern[] | null;
2
+ type Specs = readonly Pick<ElementSpec, 'name' | 'contentModel'>[];
3
+ export declare function getContentModel(
4
+ el: Element,
5
+ specs: Specs,
6
+ ):
7
+ | boolean
8
+ | readonly (
9
+ | import('type-fest/source/readonly-deep').ReadonlyObjectDeep<
10
+ import('../types/permitted-structures').PermittedContentRequire
11
+ >
12
+ | import('type-fest/source/readonly-deep').ReadonlyObjectDeep<
13
+ import('../types/permitted-structures').PermittedContentOptional
14
+ >
15
+ | import('type-fest/source/readonly-deep').ReadonlyObjectDeep<
16
+ import('../types/permitted-structures').PermittedContentOneOrMore
17
+ >
18
+ | import('type-fest/source/readonly-deep').ReadonlyObjectDeep<
19
+ import('../types/permitted-structures').PermittedContentZeroOrMore
20
+ >
21
+ | import('type-fest/source/readonly-deep').ReadonlyObjectDeep<
22
+ import('../types/permitted-structures').PermittedContentChoice
23
+ >
24
+ | import('type-fest/source/readonly-deep').ReadonlyObjectDeep<
25
+ import('../types/permitted-structures').PermittedContentTransparent
26
+ >
27
+ )[]
28
+ | null;
29
+ export {};
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getContentModel = void 0;
4
4
  const get_spec_1 = require("./get-spec");
5
5
  const cachesBySpecs = new Map();
6
- function getContentModel(el, specs) {
6
+ function getContentModel(
7
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
8
+ el, specs) {
7
9
  var _a, _b;
8
10
  const cacheByEl = (_a = cachesBySpecs.get(specs)) !== null && _a !== void 0 ? _a : new Map();
9
11
  const cached = cacheByEl.get(el);
10
- if (cached) {
12
+ if (cached !== undefined) {
11
13
  return cached;
12
14
  }
13
15
  const spec = (0, get_spec_1.getSpec)(el, specs);
@@ -4,16 +4,19 @@ exports.getExplicitRole = void 0;
4
4
  const get_role_spec_1 = require("../specs/get-role-spec");
5
5
  const resolve_namespace_1 = require("../utils/resolve-namespace");
6
6
  const get_permitted_roles_1 = require("./get-permitted-roles");
7
- function getExplicitRole(specs, el, version) {
7
+ function getExplicitRole(specs,
8
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
9
+ el, version) {
10
+ var _a;
8
11
  const roleValue = el.getAttribute('role');
9
- const roleNames = (roleValue === null || roleValue === void 0 ? void 0 : roleValue.toLowerCase().trim().split(/\s+/g)) || [];
12
+ const roleNames = (_a = roleValue === null || roleValue === void 0 ? void 0 : roleValue.toLowerCase().trim().split(/\s+/g)) !== null && _a !== void 0 ? _a : [];
10
13
  const permittedRoles = (0, get_permitted_roles_1.getPermittedRoles)(el, version, specs);
11
14
  const { namespaceURI } = (0, resolve_namespace_1.resolveNamespace)(el.localName, el.namespaceURI);
12
15
  let error = 'NO_EXPLICIT';
13
16
  /**
14
17
  * Resolve from values and **Handling Author Errors**
15
18
  *
16
- * @see https://w3c.github.io/aria/#document-handling_author-errors_roles
19
+ * @see https://w3c.github.io/aria/#document-handling_author-errors
17
20
  */
18
21
  for (const roleName of roleNames) {
19
22
  const spec = (0, get_role_spec_1.getRoleSpec)(specs, roleName, namespaceURI, version);
@@ -83,7 +86,9 @@ exports.getExplicitRole = getExplicitRole;
83
86
  function isLandmarkRole(role) {
84
87
  return role === null || role === void 0 ? void 0 : role.superClassRoles.some(su => su.name === 'landmark');
85
88
  }
86
- function isValidLandmarkRole(el, role) {
89
+ function isValidLandmarkRole(
90
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
91
+ el, role) {
87
92
  if (!role.accessibleNameRequired) {
88
93
  return true;
89
94
  }
@@ -1,3 +1,7 @@
1
1
  import type { ARIAVersion, ComputedRole, MLMLSpec } from '../types';
2
- export declare function getImplicitRole(specs: Readonly<MLMLSpec>, el: Element, version: ARIAVersion): ComputedRole;
3
- export declare function getImplicitRoleName(el: Element, version: ARIAVersion, specs: Readonly<MLMLSpec>): import("..").ImplicitRole;
2
+ export declare function getImplicitRole(specs: MLMLSpec, el: Element, version: ARIAVersion): ComputedRole;
3
+ export declare function getImplicitRoleName(
4
+ el: Element,
5
+ version: ARIAVersion,
6
+ specs: MLMLSpec,
7
+ ): import('..').ImplicitRole;
@@ -4,7 +4,9 @@ exports.getImplicitRoleName = exports.getImplicitRole = void 0;
4
4
  const get_implicit_role_1 = require("../specs/get-implicit-role");
5
5
  const get_role_spec_1 = require("../specs/get-role-spec");
6
6
  const resolve_namespace_1 = require("../utils/resolve-namespace");
7
- function getImplicitRole(specs, el, version) {
7
+ function getImplicitRole(specs,
8
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
9
+ el, version) {
8
10
  const implicitRole = getImplicitRoleName(el, version, specs);
9
11
  if (implicitRole === false) {
10
12
  // No Corresponding Role
@@ -31,7 +33,9 @@ function getImplicitRole(specs, el, version) {
31
33
  };
32
34
  }
33
35
  exports.getImplicitRole = getImplicitRole;
34
- function getImplicitRoleName(el, version, specs) {
36
+ function getImplicitRoleName(
37
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
38
+ el, version, specs) {
35
39
  return (0, get_implicit_role_1.getImplicitRole)(specs, el.localName, el.namespaceURI, version, el.matches.bind(el));
36
40
  }
37
41
  exports.getImplicitRoleName = getImplicitRoleName;
@@ -1,5 +1,11 @@
1
1
  import type { ARIAVersion, MLMLSpec } from '../types';
2
- export declare function getNonPresentationalAncestor(el: Element, specs: MLMLSpec, version: ARIAVersion): import("../types").ComputedRole | {
3
- el: null;
4
- role: null;
5
- };
2
+ export declare function getNonPresentationalAncestor(
3
+ el: Element,
4
+ specs: MLMLSpec,
5
+ version: ARIAVersion,
6
+ ):
7
+ | import('../types').ComputedRole
8
+ | {
9
+ el: null;
10
+ role: null;
11
+ };
@@ -3,11 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNonPresentationalAncestor = void 0;
4
4
  const is_presentational_1 = require("../specs/is-presentational");
5
5
  const get_computed_role_1 = require("./get-computed-role");
6
- function getNonPresentationalAncestor(el, specs, version) {
6
+ function getNonPresentationalAncestor(
7
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
8
+ el, specs, version) {
7
9
  var _a;
8
10
  let ancestor = el.parentElement;
11
+ /**
12
+ * In ARIA 1.1 and 1.2, the role of an element is not affected by the role of its ancestor elements.
13
+ *
14
+ * It is due to implementation considerations in Markuplint.
15
+ */
16
+ const assumeSingleNode = version !== '1.1' && version !== '1.2';
9
17
  while (ancestor) {
10
- const ancestorRole = (0, get_computed_role_1.getComputedRole)(specs, ancestor, version);
18
+ const ancestorRole = (0, get_computed_role_1.getComputedRole)(specs, ancestor, version, assumeSingleNode);
11
19
  if (!(0, is_presentational_1.isPresentational)((_a = ancestorRole.role) === null || _a === void 0 ? void 0 : _a.name)) {
12
20
  return ancestorRole;
13
21
  }
@@ -1,5 +1,9 @@
1
1
  import type { ARIAVersion, MLMLSpec } from '../types';
2
- export declare function getPermittedRoles(el: Element, version: ARIAVersion, specs: Readonly<MLMLSpec>): {
3
- name: string;
4
- deprecated?: boolean | undefined;
2
+ export declare function getPermittedRoles(
3
+ el: Element,
4
+ version: ARIAVersion,
5
+ specs: MLMLSpec,
6
+ ): readonly {
7
+ readonly name: string;
8
+ readonly deprecated?: boolean | undefined;
5
9
  }[];
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPermittedRoles = void 0;
4
4
  const get_permitted_roles_1 = require("../specs/get-permitted-roles");
5
- function getPermittedRoles(el, version, specs) {
5
+ function getPermittedRoles(
6
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
7
+ el, version, specs) {
6
8
  return (0, get_permitted_roles_1.getPermittedRoles)(specs, el.localName, el.namespaceURI, version, el.matches.bind(el));
7
9
  }
8
10
  exports.getPermittedRoles = getPermittedRoles;
@@ -1,2 +1,5 @@
1
1
  import type { ElementSpec } from '../types';
2
- export declare function getSpec<K extends keyof ElementSpec>(el: Element, specs: Pick<ElementSpec, 'name' | K>[]): Pick<ElementSpec, "name" | K> | null;
2
+ export declare function getSpec<K extends keyof ElementSpec>(
3
+ el: Element,
4
+ specs: readonly Pick<ElementSpec, 'name' | K>[],
5
+ ): Pick<ElementSpec, 'name' | K> | null;
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSpec = void 0;
4
4
  const get_spec_by_tag_name_1 = require("../specs/get-spec-by-tag-name");
5
- function getSpec(el, specs) {
5
+ function getSpec(
6
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
7
+ el, specs) {
6
8
  return (0, get_spec_by_tag_name_1.getSpecByTagName)(specs, el.localName, el.namespaceURI);
7
9
  }
8
10
  exports.getSpec = getSpec;
@@ -1,3 +1,9 @@
1
1
  import type { ARIAVersion, ComputedRole, MLMLSpec } from '../types';
2
- export declare function hasRequiredOwnedElement(el: Element, specs: Readonly<MLMLSpec>, version: ARIAVersion): boolean;
3
- export declare function isRequiredOwnedElement(owned: ComputedRole, query: string, specs: MLMLSpec, version: ARIAVersion): boolean;
2
+ export declare function hasRequiredOwnedElement(el: Element, specs: MLMLSpec, version: ARIAVersion): boolean;
3
+ export declare function isRequiredOwnedElement(
4
+ el: Element,
5
+ role: ComputedRole['role'],
6
+ query: string,
7
+ specs: MLMLSpec,
8
+ version: ARIAVersion,
9
+ ): boolean;
@@ -5,7 +5,9 @@ const is_presentational_1 = require("../specs/is-presentational");
5
5
  const get_computed_role_1 = require("./get-computed-role");
6
6
  const get_explicit_role_1 = require("./get-explicit-role");
7
7
  const get_implicit_role_1 = require("./get-implicit-role");
8
- function hasRequiredOwnedElement(el, specs, version) {
8
+ function hasRequiredOwnedElement(
9
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
10
+ el, specs, version) {
9
11
  /**
10
12
  * The element has aria-owns which means it may have owned elements.
11
13
  *
@@ -24,7 +26,7 @@ function hasRequiredOwnedElement(el, specs, version) {
24
26
  }
25
27
  for (const expectRole of computed.role.requiredOwnedElements) {
26
28
  for (const owned of getClosestNonPresentationalDescendants(el, specs, version)) {
27
- if (isRequiredOwnedElement(owned, expectRole, specs, version)) {
29
+ if (isRequiredOwnedElement(owned.el, owned.role, expectRole, specs, version)) {
28
30
  return true;
29
31
  }
30
32
  }
@@ -32,17 +34,19 @@ function hasRequiredOwnedElement(el, specs, version) {
32
34
  return false;
33
35
  }
34
36
  exports.hasRequiredOwnedElement = hasRequiredOwnedElement;
35
- function isRequiredOwnedElement(owned, query, specs, version) {
36
- var _a, _b;
37
+ function isRequiredOwnedElement(
38
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
39
+ el, role, query, specs, version) {
40
+ var _a;
37
41
  const [baseRole, owningRole] = query.split(' > ');
38
- if (((_a = owned.role) === null || _a === void 0 ? void 0 : _a.name) !== baseRole) {
42
+ if ((role === null || role === void 0 ? void 0 : role.name) !== baseRole) {
39
43
  return false;
40
44
  }
41
45
  if (!owningRole) {
42
46
  return true;
43
47
  }
44
- for (const owning of getClosestNonPresentationalDescendants(owned.el, specs, version)) {
45
- if (((_b = owning.role) === null || _b === void 0 ? void 0 : _b.name) === owningRole) {
48
+ for (const owning of getClosestNonPresentationalDescendants(el, specs, version)) {
49
+ if (((_a = owning.role) === null || _a === void 0 ? void 0 : _a.name) === owningRole) {
46
50
  return true;
47
51
  }
48
52
  }
@@ -64,7 +68,9 @@ exports.isRequiredOwnedElement = isRequiredOwnedElement;
64
68
  * However, the presentational role behaves transparently
65
69
  * according to the sample code in WAI-ARIA specification.
66
70
  */
67
- function getClosestNonPresentationalDescendants(el, specs, version) {
71
+ function getClosestNonPresentationalDescendants(
72
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
73
+ el, specs, version) {
68
74
  var _a;
69
75
  const owned = [];
70
76
  for (const child of Array.from(el.children)) {
@@ -8,4 +8,4 @@ import type { ARIAVersion, MLMLSpec } from '../types';
8
8
  * @param el
9
9
  * @param version
10
10
  */
11
- export declare function isExposed(el: Element, specs: Readonly<MLMLSpec>, version: ARIAVersion): boolean;
11
+ export declare function isExposed(el: Element, specs: MLMLSpec, version: ARIAVersion): boolean;
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isExposed = void 0;
4
4
  const aria_specs_1 = require("../specs/aria-specs");
5
- const is_palpable_elements_1 = require("../specs/is-palpable-elements");
5
+ const get_spec_by_tag_name_1 = require("../specs/get-spec-by-tag-name");
6
6
  const is_presentational_1 = require("../specs/is-presentational");
7
+ const resolve_namespace_1 = require("../utils/resolve-namespace");
7
8
  const get_computed_role_1 = require("./get-computed-role");
8
9
  /**
9
10
  * Detect including/excluding from the Accessibility Tree
@@ -14,14 +15,22 @@ const get_computed_role_1 = require("./get-computed-role");
14
15
  * @param el
15
16
  * @param version
16
17
  */
17
- function isExposed(el, specs, version) {
18
+ function isExposed(
19
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
20
+ el, specs, version) {
18
21
  // According to WAI-ARIA
19
22
  if (isExcluding(el, specs, version)) {
20
23
  return false;
21
24
  }
25
+ // Return true if the element is unknown, deprecated, or obsolete.
26
+ const { localName, namespace } = (0, resolve_namespace_1.resolveNamespace)(el.localName, el.namespaceURI);
27
+ const spec = (0, get_spec_by_tag_name_1.getSpecByTagName)(specs.specs, localName, namespace);
28
+ if (!spec || spec.deprecated || spec.obsolete != null) {
29
+ return true;
30
+ }
22
31
  // According to HTML and SVG Specs with **the author's interpretation**
23
32
  {
24
- if (!(0, is_palpable_elements_1.isPalpableElement)(el, specs, { extendsSvg: true, extendsExposableElements: true })) {
33
+ if (!isExposedElement(el, specs)) {
25
34
  return false;
26
35
  }
27
36
  }
@@ -45,7 +54,10 @@ exports.isExposed = isExposed;
45
54
  * @param el
46
55
  * @param version
47
56
  */
48
- function isExcluding(el, specs, version) {
57
+ function isExcluding(
58
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
59
+ el, specs, version) {
60
+ var _a;
49
61
  /**
50
62
  * The following elements are not exposed via the accessibility API and
51
63
  * user agents MUST NOT include them in the accessibility tree:
@@ -70,7 +82,7 @@ function isExcluding(el, specs, version) {
70
82
  * These exceptions and conditions are documented in the presentation (role)
71
83
  * section.
72
84
  */
73
- if ((0, is_presentational_1.isPresentational)((el.getAttribute('role') || '').split(/\s+/)[0])) {
85
+ if ((0, is_presentational_1.isPresentational)(((_a = el.getAttribute('role')) !== null && _a !== void 0 ? _a : '').split(/\s+/)[0])) {
74
86
  return true;
75
87
  }
76
88
  /**
@@ -124,7 +136,9 @@ function isExcluding(el, specs, version) {
124
136
  * @param el
125
137
  * @param version
126
138
  */
127
- function isIncluding(el, specs, version) {
139
+ function isIncluding(
140
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
141
+ el, specs, version) {
128
142
  /**
129
143
  * > **meet any** of the following criteria:
130
144
  */
@@ -171,7 +185,9 @@ function isIncluding(el, specs, version) {
171
185
  // results.push(true);
172
186
  return results.includes(true);
173
187
  }
174
- function hasDisplayNodeOrVisibilityHidden(el) {
188
+ function hasDisplayNodeOrVisibilityHidden(
189
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
190
+ el) {
175
191
  const style = el.getAttribute('style');
176
192
  if (!style) {
177
193
  return false;
@@ -179,3 +195,23 @@ function hasDisplayNodeOrVisibilityHidden(el) {
179
195
  // TODO: Improve accuracy
180
196
  return /display\s*:\s*none|visibility\s*:\s*hidden/gi.test(style);
181
197
  }
198
+ function isExposedElement(
199
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
200
+ el, specs) {
201
+ var _a;
202
+ const svgRenderedConditions = (_a = specs.def['#contentModels']['#SVGRenderable']) === null || _a === void 0 ? void 0 : _a.join(',');
203
+ if (svgRenderedConditions && el.matches(svgRenderedConditions)) {
204
+ return true;
205
+ }
206
+ return isNotMetaOrHiddenHTMLElement(el, specs);
207
+ }
208
+ function isNotMetaOrHiddenHTMLElement(
209
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
210
+ el, specs) {
211
+ var _a;
212
+ const metadataConditions = (_a = specs.def['#contentModels']['#metadata']) === null || _a === void 0 ? void 0 : _a.join(',');
213
+ if (metadataConditions && el.matches(metadataConditions)) {
214
+ return false;
215
+ }
216
+ return !el.matches('input[type=hidden i]');
217
+ }
@@ -0,0 +1,7 @@
1
+ import type { ARIAVersion, MLMLSpec } from '../types';
2
+ export declare function matchesContextRole(
3
+ conditions: readonly string[],
4
+ ownedEl: Element,
5
+ specs: MLMLSpec,
6
+ version: ARIAVersion,
7
+ ): boolean;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchesContextRole = void 0;
4
+ const get_computed_role_1 = require("./get-computed-role");
5
+ function matchesContextRole(conditions,
6
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
7
+ ownedEl, specs, version) {
8
+ return conditions.some(condition => matchesCondition(condition, ownedEl.parentElement, specs, version));
9
+ }
10
+ exports.matchesContextRole = matchesContextRole;
11
+ function matchesCondition(condition,
12
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
13
+ parentEl, specs, version) {
14
+ const conditions = condition.split(/\s+>\s+/g).reverse();
15
+ while (conditions.length > 0) {
16
+ if (!parentEl) {
17
+ return false;
18
+ }
19
+ const condition = conditions.shift();
20
+ const parentRole = (0, get_computed_role_1.getComputedRole)(specs, parentEl, version, true).role;
21
+ if (condition !== (parentRole === null || parentRole === void 0 ? void 0 : parentRole.name)) {
22
+ return false;
23
+ }
24
+ parentEl = parentEl.parentElement;
25
+ }
26
+ return true;
27
+ }
@@ -1,2 +1,2 @@
1
1
  import type { MLMLSpec } from '../types';
2
- export declare function mayBeFocusable(el: Element, specs: Readonly<MLMLSpec>): boolean;
2
+ export declare function mayBeFocusable(el: Element, specs: MLMLSpec): boolean;
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mayBeFocusable = void 0;
4
4
  const get_selectors_by_content_model_category_1 = require("../specs/get-selectors-by-content-model-category");
5
- function mayBeFocusable(el, specs) {
5
+ function mayBeFocusable(
6
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
7
+ el, specs) {
6
8
  return [
7
9
  /**
8
10
  * Interactive content