@markuplint/ml-spec 3.6.1 → 3.7.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.
@@ -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';
@@ -1,2 +1,7 @@
1
1
  import type { ARIAVersion, ComputedRole, MLMLSpec } from '../types';
2
- export declare function getComputedRole(specs: 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,14 +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
13
  function getComputedRole(specs,
13
14
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
14
- el, version) {
15
- var _a, _b, _c;
15
+ el, version, assumeSingleNode = false) {
16
+ var _a, _b;
16
17
  const implicitRole = (0, get_implicit_role_1.getImplicitRole)(specs, el, version);
17
18
  const explicitRole = (0, get_explicit_role_1.getExplicitRole)(specs, el, version);
18
- 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
+ }
19
31
  /**
20
32
  * Presentational Roles Conflict Resolution
21
33
  *
@@ -42,6 +54,19 @@ el, version) {
42
54
  * according to the sample code in WAI-ARIA specification.
43
55
  */
44
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
+ }
45
70
  const nonPresentationalAncestor = (0, get_non_presentational_ancestor_1.getNonPresentationalAncestor)(el, specs, version);
46
71
  if (!nonPresentationalAncestor.role) {
47
72
  return {
@@ -50,7 +75,7 @@ el, version) {
50
75
  errorType: 'NO_OWNER',
51
76
  };
52
77
  }
53
- if (!((_a = computedRole.role) === null || _a === void 0 ? void 0 : _a.requiredContextRole.includes(nonPresentationalAncestor.role.name))) {
78
+ if (!(0, matches_context_role_1.matchesContextRole)(computedRole.role.requiredContextRole, el, specs, version)) {
54
79
  return {
55
80
  el,
56
81
  role: null,
@@ -113,7 +138,7 @@ el, version) {
113
138
  */
114
139
  if (explicitRole.role) {
115
140
  const nonPresentationalAncestor = (0, get_non_presentational_ancestor_1.getNonPresentationalAncestor)(el, specs, version);
116
- if (nonPresentationalAncestor.role && ((_b = nonPresentationalAncestor.role) === null || _b === void 0 ? void 0 : _b.requiredOwnedElements.length) > 0) {
141
+ if (nonPresentationalAncestor.role && ((_a = nonPresentationalAncestor.role) === null || _a === void 0 ? void 0 : _a.requiredOwnedElements.length) > 0) {
117
142
  if (nonPresentationalAncestor.role.requiredOwnedElements.some(expected => {
118
143
  // const ancestor = nonPresentationalAncestor.el;
119
144
  // const ancestorImplicitRole = getImplicitRole(specs, ancestor, version);
@@ -139,7 +164,7 @@ el, version) {
139
164
  */
140
165
  const { props } = (0, aria_specs_1.ariaSpecs)(specs, version);
141
166
  for (const attr of Array.from(el.attributes)) {
142
- if ((_c = props.find(p => p.name === attr.name)) === null || _c === void 0 ? void 0 : _c.isGlobal) {
167
+ if ((_b = props.find(p => p.name === attr.name)) === null || _b === void 0 ? void 0 : _b.isGlobal) {
143
168
  return {
144
169
  ...implicitRole,
145
170
  errorType: 'GLOBAL_PROP_MUST_NOT_BE_PRESENTATIONAL',
@@ -8,8 +8,14 @@ function getNonPresentationalAncestor(
8
8
  el, specs, version) {
9
9
  var _a;
10
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';
11
17
  while (ancestor) {
12
- const ancestorRole = (0, get_computed_role_1.getComputedRole)(specs, ancestor, version);
18
+ const ancestorRole = (0, get_computed_role_1.getComputedRole)(specs, ancestor, version, assumeSingleNode);
13
19
  if (!(0, is_presentational_1.isPresentational)((_a = ancestorRole.role) === null || _a === void 0 ? void 0 : _a.name)) {
14
20
  return ancestorRole;
15
21
  }
@@ -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
+ }
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './constant/aria-version';
1
2
  export * from './dom-traverse/accname-computation';
2
3
  export * from './dom-traverse/get-attr-specs';
3
4
  export * from './dom-traverse/get-computed-aria-props';
@@ -23,3 +24,4 @@ export * from './types/aria';
23
24
  export * from './types/attributes';
24
25
  export * from './types/permitted-structures';
25
26
  export * from './utils/resolve-namespace';
27
+ export * from './utils/validateAriaVersion';
package/lib/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./constant/aria-version"), exports);
4
5
  tslib_1.__exportStar(require("./dom-traverse/accname-computation"), exports);
5
6
  tslib_1.__exportStar(require("./dom-traverse/get-attr-specs"), exports);
6
7
  tslib_1.__exportStar(require("./dom-traverse/get-computed-aria-props"), exports);
@@ -26,3 +27,4 @@ tslib_1.__exportStar(require("./types/aria"), exports);
26
27
  tslib_1.__exportStar(require("./types/attributes"), exports);
27
28
  tslib_1.__exportStar(require("./types/permitted-structures"), exports);
28
29
  tslib_1.__exportStar(require("./utils/resolve-namespace"), exports);
30
+ tslib_1.__exportStar(require("./utils/validateAriaVersion"), exports);
@@ -1,12 +1,8 @@
1
1
  import type { MLMLSpec, Attribute } from '../types';
2
2
  import type { NamespaceURI } from '@markuplint/ml-ast';
3
- export declare function getAttrSpecs(
4
- localName: string,
5
- namespace: NamespaceURI | null,
6
- schema: MLMLSpec,
7
- ): readonly Attribute[] | null;
3
+ export declare function getAttrSpecs(localName: string, namespace: NamespaceURI | null, schema: MLMLSpec): readonly Attribute[] | null;
8
4
  type HasName = {
9
- readonly name: string;
5
+ readonly name: string;
10
6
  };
11
- export declare function nameCompare(a: HasName | string, b: HasName | string): 1 | -1 | 0;
7
+ export declare function nameCompare(a: HasName | string, b: HasName | string): 0 | 1 | -1;
12
8
  export {};
@@ -7,7 +7,7 @@ function resolveVersion(aria, version) {
7
7
  const permittedRoles = (_d = (_c = aria[version]) === null || _c === void 0 ? void 0 : _c.permittedRoles) !== null && _d !== void 0 ? _d : aria.permittedRoles;
8
8
  const implicitProperties = (_f = (_e = aria[version]) === null || _e === void 0 ? void 0 : _e.implicitProperties) !== null && _f !== void 0 ? _f : aria.implicitProperties;
9
9
  const properties = (_h = (_g = aria[version]) === null || _g === void 0 ? void 0 : _g.properties) !== null && _h !== void 0 ? _h : aria.properties;
10
- const namingProhibited = version === '1.2' ? (_k = (_j = aria[version]) === null || _j === void 0 ? void 0 : _j.namingProhibited) !== null && _k !== void 0 ? _k : aria.namingProhibited : aria.namingProhibited;
10
+ const namingProhibited = version === '1.1' ? aria.namingProhibited : (_k = (_j = aria[version]) === null || _j === void 0 ? void 0 : _j.namingProhibited) !== null && _k !== void 0 ? _k : aria.namingProhibited;
11
11
  const conditions = (_m = (_l = aria[version]) === null || _l === void 0 ? void 0 : _l.conditions) !== null && _m !== void 0 ? _m : aria.conditions;
12
12
  return {
13
13
  implicitRole,
@@ -39,6 +39,11 @@ function schemaToSpec(schemas) {
39
39
  props: (0, merge_array_1.mergeArray)(def['#aria']['1.2'].props, extendedSpec.def['#aria']['1.2'].props),
40
40
  graphicsRoles: (0, merge_array_1.mergeArray)(def['#aria']['1.2'].graphicsRoles, extendedSpec.def['#aria']['1.2'].graphicsRoles),
41
41
  },
42
+ '1.3': {
43
+ roles: (0, merge_array_1.mergeArray)(def['#aria']['1.3'].roles, extendedSpec.def['#aria']['1.3'].roles),
44
+ props: (0, merge_array_1.mergeArray)(def['#aria']['1.3'].props, extendedSpec.def['#aria']['1.3'].props),
45
+ graphicsRoles: (0, merge_array_1.mergeArray)(def['#aria']['1.3'].graphicsRoles, extendedSpec.def['#aria']['1.3'].graphicsRoles),
46
+ },
42
47
  };
43
48
  }
44
49
  if (extendedSpec.def['#contentModels']) {
@@ -99,6 +99,26 @@ export interface ARIA {
99
99
  properties?: PermittedARIAProperties;
100
100
  };
101
101
  };
102
+ '1.3'?: {
103
+ implicitRole?: ImplicitRole;
104
+ permittedRoles?: PermittedRoles;
105
+ namingProhibited?: true;
106
+ implicitProperties?: ImplicitProperties;
107
+ properties?: PermittedARIAProperties;
108
+ conditions?: {
109
+ /**
110
+ * This interface was referenced by `undefined`'s JSON-Schema definition
111
+ * via the `patternProperty` ".+".
112
+ */
113
+ [k: string]: {
114
+ implicitRole?: ImplicitRole;
115
+ permittedRoles?: PermittedRoles;
116
+ namingProhibited?: true;
117
+ implicitProperties?: ImplicitProperties;
118
+ properties?: PermittedARIAProperties;
119
+ };
120
+ };
121
+ };
102
122
  '1.2'?: {
103
123
  implicitRole?: ImplicitRole;
104
124
  permittedRoles?: PermittedRoles;
@@ -1,6 +1,7 @@
1
1
  import type { ARIA } from './aria';
2
2
  import type { AttributeJSON, AttributeType, GlobalAttributes } from './attributes';
3
3
  import type { ContentModel, Category } from './permitted-structures';
4
+ import type { ariaVersions } from '../constant/aria-version';
4
5
  import type { NamespaceURI } from '@markuplint/ml-ast';
5
6
  import type { ReadonlyDeep } from 'type-fest';
6
7
  /**
@@ -29,6 +30,7 @@ export type SpecDefs = {
29
30
  readonly [category: string]: Readonly<Record<string, Partial<Attribute>>>;
30
31
  };
31
32
  readonly '#aria': {
33
+ readonly '1.3': ARIASpec;
32
34
  readonly '1.2': ARIASpec;
33
35
  readonly '1.1': ARIASpec;
34
36
  };
@@ -189,7 +191,7 @@ export type ARIAAttributeValue =
189
191
  | 'token'
190
192
  | 'token list'
191
193
  | 'URI';
192
- export type ARIAVersion = '1.1' | '1.2';
194
+ export type ARIAVersion = (typeof ariaVersions)[number];
193
195
  export type EquivalentHtmlAttr = {
194
196
  readonly htmlAttrName: string;
195
197
  readonly isNotStrictEquivalent?: true;
@@ -0,0 +1,2 @@
1
+ import type { ARIAVersion } from '../types';
2
+ export declare function validateAriaVersion(version: string): version is ARIAVersion;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateAriaVersion = void 0;
4
+ const aria_version_1 = require("../constant/aria-version");
5
+ function validateAriaVersion(version) {
6
+ return aria_version_1.ariaVersions.includes(version);
7
+ }
8
+ exports.validateAriaVersion = validateAriaVersion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-spec",
3
- "version": "3.6.1",
3
+ "version": "3.7.0",
4
4
  "description": "Types and schema that specs of the Markup languages for markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -31,10 +31,10 @@
31
31
  "tslib": "^2.4.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@markuplint/test-tools": "3.1.0",
34
+ "@markuplint/test-tools": "3.2.0",
35
35
  "@markuplint/types": "3.5.1",
36
36
  "json-schema-to-typescript": "11.0.2",
37
37
  "type-fest": "^3.6.1"
38
38
  },
39
- "gitHead": "3cdf5a088b2da03773d5d4461d0e65ec32290a00"
39
+ "gitHead": "42b97b47d22b37437024e693a72a458e2963e261"
40
40
  }