@markuplint/ml-spec 2.1.1 → 3.0.0-alpha.1

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 (123) hide show
  1. package/lib/dom-traverse/accname-computation.d.ts +1 -0
  2. package/lib/dom-traverse/accname-computation.js +8 -0
  3. package/lib/dom-traverse/get-attr-specs.d.ts +2 -0
  4. package/lib/dom-traverse/get-attr-specs.js +8 -0
  5. package/lib/dom-traverse/get-computed-role.d.ts +2 -0
  6. package/lib/dom-traverse/get-computed-role.js +170 -0
  7. package/lib/dom-traverse/get-content-model.d.ts +3 -0
  8. package/lib/dom-traverse/get-content-model.js +28 -0
  9. package/lib/dom-traverse/get-explicit-role.d.ts +2 -0
  10. package/lib/dom-traverse/get-explicit-role.js +102 -0
  11. package/lib/dom-traverse/get-implicit-role.d.ts +3 -0
  12. package/lib/dom-traverse/get-implicit-role.js +37 -0
  13. package/lib/dom-traverse/get-non-presentational-ancestor.d.ts +5 -0
  14. package/lib/dom-traverse/get-non-presentational-ancestor.js +21 -0
  15. package/lib/dom-traverse/get-permitted-roles.d.ts +5 -0
  16. package/lib/dom-traverse/get-permitted-roles.js +8 -0
  17. package/lib/dom-traverse/get-spec.d.ts +2 -0
  18. package/lib/dom-traverse/get-spec.js +8 -0
  19. package/lib/dom-traverse/has-required-owned-elements.d.ts +3 -0
  20. package/lib/dom-traverse/has-required-owned-elements.js +81 -0
  21. package/lib/dom-traverse/may-be-focusable.d.ts +2 -0
  22. package/lib/dom-traverse/may-be-focusable.js +22 -0
  23. package/lib/index.d.ts +18 -6
  24. package/lib/index.js +18 -6
  25. package/lib/specs/aria-specs.d.ts +6 -0
  26. package/lib/specs/aria-specs.js +8 -0
  27. package/lib/specs/content-model-category-to-tag-names.d.ts +3 -0
  28. package/lib/specs/content-model-category-to-tag-names.js +15 -0
  29. package/lib/specs/get-aria.d.ts +3 -0
  30. package/lib/specs/get-aria.js +71 -0
  31. package/lib/specs/get-attr-specs.d.ts +8 -0
  32. package/lib/{get-attr-specs.js → specs/get-attr-specs.js} +8 -6
  33. package/lib/specs/get-implicit-role.d.ts +2 -0
  34. package/lib/specs/get-implicit-role.js +12 -0
  35. package/lib/specs/get-permitted-roles.d.ts +12 -0
  36. package/lib/specs/get-permitted-roles.js +61 -0
  37. package/lib/specs/get-role-spec.d.ts +5 -0
  38. package/lib/specs/get-role-spec.js +52 -0
  39. package/lib/specs/get-selectors-by-content-model-category.d.ts +3 -0
  40. package/lib/specs/get-selectors-by-content-model-category.js +8 -0
  41. package/lib/specs/get-spec-by-tag-name.d.ts +2 -0
  42. package/lib/specs/get-spec-by-tag-name.js +16 -0
  43. package/lib/specs/is-presentational.d.ts +1 -0
  44. package/lib/specs/is-presentational.js +10 -0
  45. package/lib/specs/resolve-version.d.ts +3 -0
  46. package/lib/specs/resolve-version.js +21 -0
  47. package/lib/specs/schema-to-spec.d.ts +13 -0
  48. package/lib/{get-spec.js → specs/schema-to-spec.js} +19 -11
  49. package/lib/types/aria.d.ts +136 -0
  50. package/lib/{attributes.js → types/aria.js} +0 -0
  51. package/lib/{attributes.d.ts → types/attributes.d.ts} +95 -48
  52. package/lib/{permitted-structres.js → types/attributes.js} +0 -0
  53. package/lib/{types.d.ts → types/index.d.ts} +55 -70
  54. package/lib/{types.js → types/index.js} +0 -0
  55. package/lib/types/permitted-structres.d.ts +58 -0
  56. package/lib/types/permitted-structres.js +8 -0
  57. package/lib/types/permitted-structures.d.ts +54 -0
  58. package/lib/types/permitted-structures.js +8 -0
  59. package/lib/utils/get-ns.d.ts +2 -0
  60. package/lib/{get-ns.js → utils/get-ns.js} +3 -0
  61. package/lib/{utils.d.ts → utils/merge-array.d.ts} +0 -0
  62. package/lib/{utils.js → utils/merge-array.js} +0 -0
  63. package/lib/utils/resolve-namespace.d.ts +9 -0
  64. package/lib/utils/resolve-namespace.js +31 -0
  65. package/package.json +12 -8
  66. package/schema.json +6 -6
  67. package/schemas/aria.schema.json +258 -0
  68. package/schemas/attributes.schema.json +3 -22
  69. package/schemas/content-models.schema.json +200 -0
  70. package/schemas/element.schema.json +11 -0
  71. package/src/dom-traverse/accname-computation.spec.ts +69 -0
  72. package/src/dom-traverse/accname-computation.ts +5 -0
  73. package/src/dom-traverse/get-attr-specs.ts +8 -0
  74. package/src/dom-traverse/get-computed-role.spec.ts +134 -0
  75. package/src/dom-traverse/get-computed-role.ts +181 -0
  76. package/src/dom-traverse/get-content-model.ts +32 -0
  77. package/src/dom-traverse/get-explicit-role.ts +112 -0
  78. package/src/dom-traverse/get-implicit-role.ts +36 -0
  79. package/src/dom-traverse/get-non-presentational-ancestor.ts +20 -0
  80. package/src/dom-traverse/get-permitted-roles.ts +7 -0
  81. package/src/dom-traverse/get-spec.ts +7 -0
  82. package/src/dom-traverse/has-required-owned-elements.spec.ts +36 -0
  83. package/src/dom-traverse/has-required-owned-elements.ts +85 -0
  84. package/src/dom-traverse/may-be-focusable.ts +21 -0
  85. package/src/index.ts +18 -6
  86. package/src/specs/aria-specs.ts +6 -0
  87. package/src/specs/content-model-category-to-tag-names.ts +15 -0
  88. package/src/specs/get-aria.ts +85 -0
  89. package/src/{get-attr-specs.spec.ts → specs/get-attr-specs.spec.ts} +4 -7
  90. package/src/{get-attr-specs.ts → specs/get-attr-specs.ts} +12 -7
  91. package/src/specs/get-implicit-role.spec.ts +81 -0
  92. package/src/specs/get-implicit-role.ts +17 -0
  93. package/src/specs/get-permitted-roles.spec.ts +420 -0
  94. package/src/specs/get-permitted-roles.ts +87 -0
  95. package/src/specs/get-role-spec.spec.ts +67 -0
  96. package/src/specs/get-role-spec.ts +72 -0
  97. package/src/specs/get-selectors-by-content-model-category.ts +10 -0
  98. package/src/specs/get-spec-by-tag-name.spec.ts +68 -0
  99. package/src/specs/get-spec-by-tag-name.ts +20 -0
  100. package/src/specs/is-presentational.ts +6 -0
  101. package/src/specs/resolve-version.ts +20 -0
  102. package/src/{get-spec.spec.ts → specs/schema-to-spec.spec.ts} +2 -2
  103. package/src/{get-spec.ts → specs/schema-to-spec.ts} +23 -9
  104. package/src/types/aria.ts +153 -0
  105. package/src/{attributes.ts → types/attributes.ts} +162 -117
  106. package/src/{types.ts → types/index.ts} +75 -74
  107. package/src/types/permitted-structres.ts +101 -0
  108. package/src/types/permitted-structures.ts +97 -0
  109. package/src/{get-ns.ts → utils/get-ns.ts} +6 -1
  110. package/src/{utils.ts → utils/merge-array.ts} +0 -0
  111. package/src/utils/resolve-namespace.spec.ts +37 -0
  112. package/src/utils/resolve-namespace.ts +40 -0
  113. package/tsconfig.tsbuildinfo +1 -1
  114. package/lib/get-attr-specs.d.ts +0 -7
  115. package/lib/get-ns.d.ts +0 -1
  116. package/lib/get-spec-by-tag-name.d.ts +0 -2
  117. package/lib/get-spec-by-tag-name.js +0 -31
  118. package/lib/get-spec.d.ts +0 -13
  119. package/lib/permitted-structres.d.ts +0 -73
  120. package/schemas/permitted-structures.schema.json +0 -244
  121. package/schemas/wai-aria.schema.json +0 -87
  122. package/src/get-spec-by-tag-name.ts +0 -32
  123. package/src/permitted-structres.ts +0 -118
@@ -0,0 +1,3 @@
1
+ import type { ARIAVersion, Matches, MLMLSpec } from '../types';
2
+ import type { ARIA } from '../types/aria';
3
+ export declare function getARIA(specs: Readonly<MLMLSpec>, localName: string, namespace: string | null, version: ARIAVersion, matches: Matches): Omit<ARIA, ARIAVersion | 'conditions'> | null;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getARIA = void 0;
4
+ const get_spec_by_tag_name_1 = require("./get-spec-by-tag-name");
5
+ const resolve_version_1 = require("./resolve-version");
6
+ const cache = new Map();
7
+ function getARIA(specs, localName, namespace, version, matches) {
8
+ var _a, _b, _c, _d, _e;
9
+ const aria = getVersionResolvedARIA(specs, localName, namespace, version);
10
+ if (!aria) {
11
+ return null;
12
+ }
13
+ const conditions = aria.conditions;
14
+ if (!conditions) {
15
+ return aria;
16
+ }
17
+ const conditionKeys = Object.keys(conditions);
18
+ let { implicitRole, permittedRoles, implicitProperties, properties, namingProhibited } = aria;
19
+ for (const cond of conditionKeys) {
20
+ if (!matches(cond)) {
21
+ continue;
22
+ }
23
+ const condARIA = conditions[cond];
24
+ implicitRole = (_a = condARIA.implicitRole) !== null && _a !== void 0 ? _a : implicitRole;
25
+ permittedRoles = (_b = condARIA.permittedRoles) !== null && _b !== void 0 ? _b : permittedRoles;
26
+ implicitProperties = (_c = condARIA.implicitProperties) !== null && _c !== void 0 ? _c : implicitProperties;
27
+ properties = (_d = condARIA.properties) !== null && _d !== void 0 ? _d : properties;
28
+ namingProhibited = (_e = condARIA.namingProhibited) !== null && _e !== void 0 ? _e : namingProhibited;
29
+ }
30
+ return {
31
+ implicitRole,
32
+ permittedRoles,
33
+ implicitProperties,
34
+ properties,
35
+ namingProhibited,
36
+ };
37
+ }
38
+ exports.getARIA = getARIA;
39
+ function getVersionResolvedARIA(specs, localName, namespace, version) {
40
+ var _a;
41
+ const key = localName + namespace + version;
42
+ let aria = cache.get(key);
43
+ if (aria !== undefined) {
44
+ return aria;
45
+ }
46
+ const spec = (_a = (0, get_spec_by_tag_name_1.getSpecByTagName)(specs.specs, localName, namespace)) === null || _a === void 0 ? void 0 : _a.aria;
47
+ if (!spec) {
48
+ cache.set(key, null);
49
+ return null;
50
+ }
51
+ aria = (0, resolve_version_1.resolveVersion)(spec, version);
52
+ if (aria.permittedRoles) {
53
+ aria.permittedRoles = optimizePermittedRoles(aria.permittedRoles);
54
+ }
55
+ cache.set(key, aria);
56
+ return aria;
57
+ }
58
+ function optimizePermittedRoles(permittedRoles) {
59
+ if (!Array.isArray(permittedRoles)) {
60
+ return permittedRoles;
61
+ }
62
+ const unique = new Set(permittedRoles);
63
+ // https://www.w3.org/TR/wai-aria-1.2/#note-regarding-the-aria-1-1-none-role
64
+ if (unique.has('presentation')) {
65
+ unique.add('none');
66
+ }
67
+ if (unique.has('none')) {
68
+ unique.add('presentation');
69
+ }
70
+ return Array.from(unique).sort();
71
+ }
@@ -0,0 +1,8 @@
1
+ import type { MLMLSpec, Attribute } from '../types';
2
+ import type { NamespaceURI } from '@markuplint/ml-ast';
3
+ export declare function getAttrSpecs(localName: string, namespace: NamespaceURI | null, schema: MLMLSpec): Attribute[] | null;
4
+ declare type HasName = {
5
+ name: string;
6
+ };
7
+ export declare function nameCompare(a: HasName | string, b: HasName | string): 1 | -1 | 0;
8
+ export {};
@@ -1,20 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nameCompare = exports.getAttrSpecs = void 0;
4
+ const resolve_namespace_1 = require("../utils/resolve-namespace");
4
5
  const cacheMap = new Map();
5
6
  const schemaCache = new WeakSet();
6
- function getAttrSpecs(nameWithNS, schema) {
7
+ function getAttrSpecs(localName, namespace, schema) {
7
8
  if (!schemaCache.has(schema)) {
8
9
  cacheMap.clear();
9
10
  }
10
- const cache = cacheMap.get(nameWithNS);
11
+ const { localNameWithNS } = (0, resolve_namespace_1.resolveNamespace)(localName, namespace || undefined);
12
+ const cache = cacheMap.get(localNameWithNS);
11
13
  if (cache !== undefined) {
12
14
  return cache;
13
15
  }
14
16
  schemaCache.add(schema);
15
- const elSpec = schema.specs.find(spec => spec.name === nameWithNS);
17
+ const elSpec = schema.specs.find(spec => spec.name === localNameWithNS);
16
18
  if (!elSpec) {
17
- cacheMap.set(nameWithNS, null);
19
+ cacheMap.set(localNameWithNS, null);
18
20
  return null;
19
21
  }
20
22
  const globalAttrs = schema.def['#globalAttrs'];
@@ -66,7 +68,7 @@ function getAttrSpecs(nameWithNS, schema) {
66
68
  });
67
69
  for (const attr of attrList) {
68
70
  if (!attr.type) {
69
- throw new Error(`The type is empty in the ${attr.name} attribute of the ${nameWithNS} element,
71
+ throw new Error(`The type is empty in the ${attr.name} attribute of the ${localName} element,
70
72
  'packages',
71
73
  '@markuplint',
72
74
  'html-spec',
@@ -77,7 +79,7 @@ function getAttrSpecs(nameWithNS, schema) {
77
79
  }
78
80
  }
79
81
  attrList.sort(nameCompare);
80
- cacheMap.set(nameWithNS, attrList);
82
+ cacheMap.set(localNameWithNS, attrList);
81
83
  return attrList;
82
84
  }
83
85
  exports.getAttrSpecs = getAttrSpecs;
@@ -0,0 +1,2 @@
1
+ import type { ARIAVersion, Matches, MLMLSpec } from '../types';
2
+ export declare function getImplicitRole(specs: Readonly<MLMLSpec>, localName: string, namespace: string | null, version: ARIAVersion, matches: Matches): import("..").ImplicitRole;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getImplicitRole = void 0;
4
+ const get_aria_1 = require("./get-aria");
5
+ function getImplicitRole(specs, localName, namespace, version, matches) {
6
+ const aria = (0, get_aria_1.getARIA)(specs, localName, namespace, version, matches);
7
+ if (!aria) {
8
+ return false;
9
+ }
10
+ return aria.implicitRole;
11
+ }
12
+ exports.getImplicitRole = getImplicitRole;
@@ -0,0 +1,12 @@
1
+ import type { ARIAVersion, Matches, MLMLSpec } from '../types';
2
+ /**
3
+ * Getting permitted ARIA roles.
4
+ *
5
+ * - If an array, it is role list.
6
+ * - If `true`, this mean is "Any".
7
+ * - If `false`, this mean is "No".
8
+ */
9
+ export declare function getPermittedRoles(specs: Readonly<MLMLSpec>, localName: string, namespace: string | null, version: ARIAVersion, matches: Matches): {
10
+ name: string;
11
+ deprecated?: boolean;
12
+ }[];
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPermittedRoles = void 0;
4
+ const merge_array_1 = require("../utils/merge-array");
5
+ const aria_specs_1 = require("./aria-specs");
6
+ const get_aria_1 = require("./get-aria");
7
+ /**
8
+ * Getting permitted ARIA roles.
9
+ *
10
+ * - If an array, it is role list.
11
+ * - If `true`, this mean is "Any".
12
+ * - If `false`, this mean is "No".
13
+ */
14
+ function getPermittedRoles(specs, localName, namespace, version, matches) {
15
+ const aria = (0, get_aria_1.getARIA)(specs, localName, namespace, version, matches);
16
+ if (!aria) {
17
+ return [];
18
+ }
19
+ const { implicitRole, permittedRoles } = aria;
20
+ const { roles, graphicsRoles } = (0, aria_specs_1.ariaSpecs)(specs, version);
21
+ let permittedRoleList = [];
22
+ if (permittedRoles === true) {
23
+ permittedRoleList = (0, merge_array_1.mergeArray)(permittedRoleList, roles
24
+ .filter(role => !role.isAbstract)
25
+ .map(role => ({
26
+ name: role.name,
27
+ })));
28
+ }
29
+ if (Array.isArray(permittedRoles)) {
30
+ permittedRoleList = (0, merge_array_1.mergeArray)(permittedRoleList, permittedRoles.map(role => {
31
+ if (typeof role === 'string') {
32
+ return {
33
+ name: role,
34
+ };
35
+ }
36
+ return role;
37
+ }));
38
+ }
39
+ else if (!(typeof permittedRoles === 'boolean')) {
40
+ if (permittedRoles['core-aam']) {
41
+ permittedRoleList = (0, merge_array_1.mergeArray)(permittedRoleList, roles
42
+ .filter(role => !role.isAbstract)
43
+ .map(role => ({
44
+ name: role.name,
45
+ })));
46
+ }
47
+ if (permittedRoles['graphics-aam']) {
48
+ permittedRoleList = (0, merge_array_1.mergeArray)(permittedRoleList, graphicsRoles
49
+ .filter(role => !role.isAbstract)
50
+ .map(role => ({
51
+ name: role.name,
52
+ })));
53
+ }
54
+ }
55
+ if (implicitRole) {
56
+ const implicitRoles = implicitRole === 'presentation' || implicitRole === 'none' ? ['none', 'presentation'] : [implicitRole];
57
+ return (0, merge_array_1.mergeArray)(implicitRoles.map(r => ({ name: r })), permittedRoleList);
58
+ }
59
+ return permittedRoleList;
60
+ }
61
+ exports.getPermittedRoles = getPermittedRoles;
@@ -0,0 +1,5 @@
1
+ import type { ARIAVersion, ARIARoleInSchema, MLMLSpec, ARIARole } from '../types';
2
+ import type { NamespaceURI } from '@markuplint/ml-ast';
3
+ export declare function getRoleSpec(specs: Readonly<MLMLSpec>, roleName: string, namespace: NamespaceURI, version: ARIAVersion): (ARIARole & {
4
+ superClassRoles: ARIARoleInSchema[];
5
+ }) | null;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRoleSpec = void 0;
4
+ const aria_specs_1 = require("./aria-specs");
5
+ function getRoleSpec(specs, roleName, namespace, version) {
6
+ var _a, _b, _c, _d;
7
+ const role = getRoleByName(specs, roleName, namespace, version);
8
+ if (!role) {
9
+ return null;
10
+ }
11
+ const superClassRoles = recursiveTraverseSuperClassRoles(specs, roleName, namespace, version);
12
+ return {
13
+ name: role.name,
14
+ isAbstract: !!role.isAbstract,
15
+ requiredContextRole: (_a = role.requiredContextRole) !== null && _a !== void 0 ? _a : [],
16
+ requiredOwnedElements: (_b = role.requiredOwnedElements) !== null && _b !== void 0 ? _b : [],
17
+ accessibleNameRequired: !!role.accessibleNameRequired,
18
+ accessibleNameFromAuthor: !!role.accessibleNameFromAuthor,
19
+ accessibleNameFromContent: !!role.accessibleNameFromContent,
20
+ accessibleNameProhibited: !!role.accessibleNameProhibited,
21
+ childrenPresentational: !!role.childrenPresentational,
22
+ ownedProperties: (_c = role.ownedProperties) !== null && _c !== void 0 ? _c : [],
23
+ prohibitedProperties: (_d = role.prohibitedProperties) !== null && _d !== void 0 ? _d : [],
24
+ superClassRoles,
25
+ };
26
+ }
27
+ exports.getRoleSpec = getRoleSpec;
28
+ function recursiveTraverseSuperClassRoles(specs, roleName, namespace, version) {
29
+ const roles = [];
30
+ const superClassRoles = getSuperClassRoles(specs, roleName, namespace, version);
31
+ if (superClassRoles) {
32
+ roles.push(...superClassRoles);
33
+ for (const superClassRole of superClassRoles) {
34
+ const ancestorRoles = recursiveTraverseSuperClassRoles(specs, superClassRole.name, namespace, version);
35
+ roles.push(...ancestorRoles);
36
+ }
37
+ }
38
+ return roles;
39
+ }
40
+ function getSuperClassRoles(specs, roleName, namespace, version) {
41
+ var _a;
42
+ const role = getRoleByName(specs, roleName, namespace, version);
43
+ return (((_a = role === null || role === void 0 ? void 0 : role.generalization) === null || _a === void 0 ? void 0 : _a.map(roleName => getRoleByName(specs, roleName, namespace, version)).filter((role) => !!role)) || null);
44
+ }
45
+ function getRoleByName(specs, roleName, namespace, version) {
46
+ const { roles, graphicsRoles } = (0, aria_specs_1.ariaSpecs)(specs, version);
47
+ let role = roles.find(r => r.name === roleName);
48
+ if (!role && namespace === 'http://www.w3.org/2000/svg') {
49
+ role = graphicsRoles.find(r => r.name === roleName);
50
+ }
51
+ return role;
52
+ }
@@ -0,0 +1,3 @@
1
+ import type { MLMLSpec } from '../types';
2
+ import type { Category } from '../types/permitted-structures';
3
+ export declare function getSelectorsByContentModelCategory(specs: Readonly<MLMLSpec>, category: Category): ReadonlyArray<string>;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSelectorsByContentModelCategory = void 0;
4
+ function getSelectorsByContentModelCategory(specs, category) {
5
+ const selectors = specs.def['#contentModels'][category];
6
+ return selectors || [];
7
+ }
8
+ exports.getSelectorsByContentModelCategory = getSelectorsByContentModelCategory;
@@ -0,0 +1,2 @@
1
+ import type { ElementSpec } from '../types';
2
+ export declare function getSpecByTagName<K extends keyof ElementSpec = keyof ElementSpec>(specs: Readonly<Pick<ElementSpec, 'name' | K>[]>, localName: string, namespace: string | null): Pick<ElementSpec, "name" | K> | null;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSpecByTagName = void 0;
4
+ const resolve_namespace_1 = require("../utils/resolve-namespace");
5
+ const cache = new Map();
6
+ function getSpecByTagName(specs, localName, namespace) {
7
+ const { localNameWithNS } = (0, resolve_namespace_1.resolveNamespace)(localName, namespace || undefined);
8
+ let spec = cache.get(localNameWithNS);
9
+ if (spec !== undefined) {
10
+ return spec;
11
+ }
12
+ spec = specs.find(spec => spec.name === localNameWithNS) || null;
13
+ cache.set(localNameWithNS, spec);
14
+ return spec;
15
+ }
16
+ exports.getSpecByTagName = getSpecByTagName;
@@ -0,0 +1 @@
1
+ export declare function isPresentational(roleName?: string): boolean;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPresentational = void 0;
4
+ function isPresentational(roleName) {
5
+ if (!roleName) {
6
+ return false;
7
+ }
8
+ return ['presentation', 'none'].includes(roleName);
9
+ }
10
+ exports.isPresentational = isPresentational;
@@ -0,0 +1,3 @@
1
+ import type { ARIAVersion } from '../types';
2
+ import type { ARIA } from '../types/aria';
3
+ export declare function resolveVersion(aria: ARIA, version: ARIAVersion): Omit<ARIA, ARIAVersion>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveVersion = void 0;
4
+ function resolveVersion(aria, version) {
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
6
+ const implicitRole = (_b = (_a = aria[version]) === null || _a === void 0 ? void 0 : _a.implicitRole) !== null && _b !== void 0 ? _b : aria.implicitRole;
7
+ const permittedRoles = (_d = (_c = aria[version]) === null || _c === void 0 ? void 0 : _c.permittedRoles) !== null && _d !== void 0 ? _d : aria.permittedRoles;
8
+ const implicitProperties = (_f = (_e = aria[version]) === null || _e === void 0 ? void 0 : _e.implicitProperties) !== null && _f !== void 0 ? _f : aria.implicitProperties;
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;
11
+ const conditions = (_m = (_l = aria[version]) === null || _l === void 0 ? void 0 : _l.conditions) !== null && _m !== void 0 ? _m : aria.conditions;
12
+ return {
13
+ implicitRole,
14
+ permittedRoles,
15
+ implicitProperties,
16
+ properties,
17
+ namingProhibited,
18
+ conditions,
19
+ };
20
+ }
21
+ exports.resolveVersion = resolveVersion;
@@ -0,0 +1,13 @@
1
+ import type { ElementSpec, ExtendedSpec, MLMLSpec } from '../types';
2
+ /**
3
+ * Merging HTML-spec schema and extended spec schemas
4
+ *
5
+ * Ex: `@markuplint/html-spec` + `{ specs: ["@markuplint/vue-spec"] }` in configure files.
6
+ *
7
+ * @param schemas `MLDocument.schemas`
8
+ */
9
+ export declare function schemaToSpec(schemas: readonly [MLMLSpec, ...ExtendedSpec[]]): {
10
+ cites: import("../types").Cites;
11
+ def: import("../types").SpecDefs;
12
+ specs: ElementSpec[];
13
+ };
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSpec = void 0;
4
- const utils_1 = require("./utils");
3
+ exports.schemaToSpec = void 0;
4
+ const merge_array_1 = require("../utils/merge-array");
5
5
  /**
6
6
  * Merging HTML-spec schema and extended spec schemas
7
7
  *
8
- * Ex: `@markuplint/html-spec` + `{ specs: ["@markuplint/vue-spec"] }` in cofigure files.
8
+ * Ex: `@markuplint/html-spec` + `{ specs: ["@markuplint/vue-spec"] }` in configure files.
9
9
  *
10
10
  * @param schemas `MLDocument.schemas`
11
11
  */
12
- function getSpec(schemas) {
12
+ function schemaToSpec(schemas) {
13
13
  var _a, _b, _c;
14
14
  const [main, ...extendedSpecs] = schemas;
15
15
  const result = { ...main };
@@ -18,17 +18,25 @@ function getSpec(schemas) {
18
18
  result.cites = [...result.cites, ...extendedSpec.cites];
19
19
  }
20
20
  if (extendedSpec.def) {
21
- if (extendedSpec.def['#ariaAttrs']) {
22
- result.def['#ariaAttrs'] = [...result.def['#ariaAttrs'], ...extendedSpec.def['#ariaAttrs']];
23
- }
24
21
  if ((_a = extendedSpec.def['#globalAttrs']) === null || _a === void 0 ? void 0 : _a['#extends']) {
25
22
  result.def['#globalAttrs']['#HTMLGlobalAttrs'] = {
26
23
  ...(((_b = result.def['#globalAttrs']) === null || _b === void 0 ? void 0 : _b['#HTMLGlobalAttrs']) || {}),
27
24
  ...(((_c = extendedSpec.def['#globalAttrs']) === null || _c === void 0 ? void 0 : _c['#extends']) || {}),
28
25
  };
29
26
  }
30
- if (extendedSpec.def['#roles']) {
31
- result.def['#roles'] = [...result.def['#roles'], ...extendedSpec.def['#roles']];
27
+ if (extendedSpec.def['#aria']) {
28
+ result.def['#aria'] = {
29
+ '1.1': {
30
+ roles: (0, merge_array_1.mergeArray)(result.def['#aria']['1.1'].roles, extendedSpec.def['#aria']['1.1'].roles),
31
+ props: (0, merge_array_1.mergeArray)(result.def['#aria']['1.1'].props, extendedSpec.def['#aria']['1.1'].props),
32
+ graphicsRoles: (0, merge_array_1.mergeArray)(result.def['#aria']['1.1'].graphicsRoles, extendedSpec.def['#aria']['1.1'].graphicsRoles),
33
+ },
34
+ '1.2': {
35
+ roles: (0, merge_array_1.mergeArray)(result.def['#aria']['1.2'].roles, extendedSpec.def['#aria']['1.2'].roles),
36
+ props: (0, merge_array_1.mergeArray)(result.def['#aria']['1.2'].props, extendedSpec.def['#aria']['1.2'].props),
37
+ graphicsRoles: (0, merge_array_1.mergeArray)(result.def['#aria']['1.2'].graphicsRoles, extendedSpec.def['#aria']['1.2'].graphicsRoles),
38
+ },
39
+ };
32
40
  }
33
41
  if (extendedSpec.def['#contentModels']) {
34
42
  const keys = new Set([
@@ -61,7 +69,7 @@ function getSpec(schemas) {
61
69
  ...exSpec.globalAttrs,
62
70
  },
63
71
  attributes: mergeAttrSpec(elSpec.attributes, exSpec.attributes),
64
- categories: (0, utils_1.mergeArray)(elSpec.categories, exSpec.categories),
72
+ categories: (0, merge_array_1.mergeArray)(elSpec.categories, exSpec.categories),
65
73
  });
66
74
  }
67
75
  result.specs = specs;
@@ -69,7 +77,7 @@ function getSpec(schemas) {
69
77
  }
70
78
  return result;
71
79
  }
72
- exports.getSpec = getSpec;
80
+ exports.schemaToSpec = schemaToSpec;
73
81
  function mergeAttrSpec(std, ex = {}) {
74
82
  const result = {};
75
83
  const keys = Array.from(new Set([...Object.keys(std), ...Object.keys(ex)]));
@@ -0,0 +1,136 @@
1
+ /**
2
+ * This file was automatically generated by json-schema-to-typescript.
3
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4
+ * and run json-schema-to-typescript to regenerate this file.
5
+ */
6
+ /**
7
+ * If `false`, this mean is "No corresponding role".
8
+ */
9
+ export declare type ImplicitRole = false | string;
10
+ /**
11
+ * If `true`, this mean is "Any". If `false`, this mean is "No".
12
+ */
13
+ export declare type PermittedRoles = boolean | (string | {
14
+ name: string;
15
+ deprecated?: true;
16
+ [k: string]: unknown;
17
+ })[] | {
18
+ 'core-aam'?: true;
19
+ 'graphics-aam'?: true;
20
+ };
21
+ /**
22
+ * If set false:
23
+ * > No role or aria-* attributes
24
+ */
25
+ export declare type PermittedARIAProperties = false | {
26
+ global?: true;
27
+ /**
28
+ * Set true if the spec says "and any aria-* attributes applicable to the allowed roles."
29
+ */
30
+ role?: true | string | [string, ...string[]];
31
+ /**
32
+ * @minItems 1
33
+ */
34
+ only?: [
35
+ (string | {
36
+ name: string;
37
+ value?: string;
38
+ }),
39
+ ...(string | {
40
+ name: string;
41
+ value?: string;
42
+ })[]
43
+ ];
44
+ /**
45
+ * @minItems 1
46
+ */
47
+ without?: [
48
+ {
49
+ type: 'not-recommended' | 'should-not' | 'must-not';
50
+ name: string;
51
+ value?: string;
52
+ alt?: {
53
+ method: 'remove-attr' | 'set-attr';
54
+ target: string;
55
+ };
56
+ },
57
+ ...{
58
+ type: 'not-recommended' | 'should-not' | 'must-not';
59
+ name: string;
60
+ value?: string;
61
+ alt?: {
62
+ method: 'remove-attr' | 'set-attr';
63
+ target: string;
64
+ };
65
+ }[]
66
+ ];
67
+ };
68
+ export interface AriaSchema {
69
+ _?: ARIA;
70
+ [k: string]: unknown;
71
+ }
72
+ export interface ARIA {
73
+ implicitRole: ImplicitRole;
74
+ permittedRoles: PermittedRoles;
75
+ namingProhibited?: true;
76
+ implicitProperties?: ImplicitProperties;
77
+ properties?: PermittedARIAProperties;
78
+ conditions?: {
79
+ /**
80
+ * This interface was referenced by `undefined`'s JSON-Schema definition
81
+ * via the `patternProperty` ".+".
82
+ */
83
+ [k: string]: {
84
+ implicitRole?: ImplicitRole;
85
+ permittedRoles?: PermittedRoles;
86
+ namingProhibited?: true;
87
+ implicitProperties?: ImplicitProperties;
88
+ properties?: PermittedARIAProperties;
89
+ };
90
+ };
91
+ '1.2'?: {
92
+ implicitRole?: ImplicitRole;
93
+ permittedRoles?: PermittedRoles;
94
+ namingProhibited?: true;
95
+ implicitProperties?: ImplicitProperties;
96
+ properties?: PermittedARIAProperties;
97
+ conditions?: {
98
+ /**
99
+ * This interface was referenced by `undefined`'s JSON-Schema definition
100
+ * via the `patternProperty` ".+".
101
+ */
102
+ [k: string]: {
103
+ implicitRole?: ImplicitRole;
104
+ permittedRoles?: PermittedRoles;
105
+ namingProhibited?: true;
106
+ implicitProperties?: ImplicitProperties;
107
+ properties?: PermittedARIAProperties;
108
+ };
109
+ };
110
+ };
111
+ '1.1'?: {
112
+ implicitRole?: ImplicitRole;
113
+ permittedRoles?: PermittedRoles;
114
+ implicitProperties?: ImplicitProperties;
115
+ properties?: PermittedARIAProperties;
116
+ conditions?: {
117
+ /**
118
+ * This interface was referenced by `undefined`'s JSON-Schema definition
119
+ * via the `patternProperty` ".+".
120
+ */
121
+ [k: string]: {
122
+ implicitRole?: ImplicitRole;
123
+ permittedRoles?: PermittedRoles;
124
+ implicitProperties?: ImplicitProperties;
125
+ properties?: PermittedARIAProperties;
126
+ };
127
+ };
128
+ };
129
+ }
130
+ export interface ImplicitProperties {
131
+ /**
132
+ * This interface was referenced by `ImplicitProperties`'s JSON-Schema definition
133
+ * via the `patternProperty` "^aria-.+".
134
+ */
135
+ [k: string]: string;
136
+ }
File without changes