@markuplint/ml-spec 2.0.1 → 3.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) 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/focusability-computation.d.ts +1 -0
  4. package/lib/dom-traverse/focusability-computation.js +8 -0
  5. package/lib/dom-traverse/get-aria.d.ts +9 -0
  6. package/lib/dom-traverse/get-aria.js +54 -0
  7. package/lib/dom-traverse/get-attr-specs.d.ts +2 -0
  8. package/lib/dom-traverse/get-attr-specs.js +8 -0
  9. package/lib/dom-traverse/get-computed-role.d.ts +2 -0
  10. package/lib/dom-traverse/get-computed-role.js +170 -0
  11. package/lib/dom-traverse/get-explicit-role.d.ts +2 -0
  12. package/lib/dom-traverse/get-explicit-role.js +102 -0
  13. package/lib/dom-traverse/get-implicit-role.d.ts +3 -0
  14. package/lib/dom-traverse/get-implicit-role.js +37 -0
  15. package/lib/dom-traverse/get-non-presentational-ancestor.d.ts +5 -0
  16. package/lib/dom-traverse/get-non-presentational-ancestor.js +21 -0
  17. package/lib/dom-traverse/get-permitted-roles.d.ts +5 -0
  18. package/lib/dom-traverse/get-permitted-roles.js +8 -0
  19. package/lib/dom-traverse/get-spec.d.ts +2 -0
  20. package/lib/dom-traverse/get-spec.js +8 -0
  21. package/lib/dom-traverse/has-required-owned-elements.d.ts +3 -0
  22. package/lib/dom-traverse/has-required-owned-elements.js +81 -0
  23. package/lib/dom-traverse/may-be-focusable.d.ts +2 -0
  24. package/lib/dom-traverse/may-be-focusable.js +22 -0
  25. package/lib/index.d.ts +17 -6
  26. package/lib/index.js +18 -7
  27. package/lib/specs/aria-spec.d.ts +5 -0
  28. package/lib/specs/aria-spec.js +12 -0
  29. package/lib/specs/aria-specs.d.ts +6 -0
  30. package/lib/specs/aria-specs.js +8 -0
  31. package/lib/specs/content-model-category-to-tag-names.d.ts +3 -0
  32. package/lib/specs/content-model-category-to-tag-names.js +15 -0
  33. package/lib/specs/get-aria.d.ts +3 -0
  34. package/lib/specs/get-aria.js +71 -0
  35. package/lib/specs/get-attr-specs.d.ts +8 -0
  36. package/lib/{get-attr-specs.js → specs/get-attr-specs.js} +8 -6
  37. package/lib/specs/get-implicit-role.d.ts +2 -0
  38. package/lib/specs/get-implicit-role.js +12 -0
  39. package/lib/specs/get-permitted-roles.d.ts +12 -0
  40. package/lib/specs/get-permitted-roles.js +61 -0
  41. package/lib/specs/get-role-spec.d.ts +5 -0
  42. package/lib/specs/get-role-spec.js +52 -0
  43. package/lib/specs/get-selectors-by-content-model-category.d.ts +3 -0
  44. package/lib/specs/get-selectors-by-content-model-category.js +8 -0
  45. package/lib/specs/get-spec-by-tag-name.d.ts +2 -0
  46. package/lib/specs/get-spec-by-tag-name.js +16 -0
  47. package/lib/{get-spec.d.ts → specs/get-spec.d.ts} +4 -4
  48. package/lib/{get-spec.js → specs/get-spec.js} +1 -1
  49. package/lib/specs/html-spec.d.ts +6 -0
  50. package/lib/specs/html-spec.js +16 -0
  51. package/lib/specs/is-presentational.d.ts +1 -0
  52. package/lib/specs/is-presentational.js +10 -0
  53. package/lib/specs/resolve-namespace.d.ts +9 -0
  54. package/lib/specs/resolve-namespace.js +26 -0
  55. package/lib/specs/resolve-version.d.ts +3 -0
  56. package/lib/specs/resolve-version.js +21 -0
  57. package/lib/specs/schema-to-spec.d.ts +13 -0
  58. package/lib/specs/schema-to-spec.js +93 -0
  59. package/lib/types/aria.d.ts +130 -0
  60. package/lib/{attributes.js → types/aria.js} +0 -0
  61. package/lib/{attributes.d.ts → types/attributes.d.ts} +5 -12
  62. package/lib/{permitted-structres.js → types/attributes.js} +0 -0
  63. package/lib/{types.d.ts → types/index.d.ts} +50 -65
  64. package/lib/{types.js → types/index.js} +0 -0
  65. package/lib/{permitted-structres.d.ts → types/permitted-structres.d.ts} +14 -23
  66. package/lib/types/permitted-structres.js +8 -0
  67. package/lib/utils/cache.d.ts +10 -0
  68. package/lib/utils/cache.js +42 -0
  69. package/lib/utils/get-ns.d.ts +2 -0
  70. package/lib/{get-ns.js → utils/get-ns.js} +3 -0
  71. package/lib/utils/merge-array.d.ts +5 -0
  72. package/lib/utils/merge-array.js +36 -0
  73. package/lib/utils/resolve-namespace.d.ts +9 -0
  74. package/lib/utils/resolve-namespace.js +31 -0
  75. package/lib/utils.d.ts +6 -3
  76. package/lib/utils.js +15 -1
  77. package/package.json +10 -6
  78. package/schemas/aria.schema.json +258 -0
  79. package/schemas/attributes.schema.json +5 -23
  80. package/schemas/{permitted-structures.schema.json → content-models.schema.json} +52 -81
  81. package/schemas/element.schema.json +11 -0
  82. package/schemas/global-attributes.schema.json +6 -2
  83. package/src/dom-traverse/accname-computation.spec.ts +69 -0
  84. package/src/dom-traverse/accname-computation.ts +5 -0
  85. package/src/dom-traverse/get-attr-specs.ts +8 -0
  86. package/src/dom-traverse/get-computed-role.spec.ts +134 -0
  87. package/src/dom-traverse/get-computed-role.ts +181 -0
  88. package/src/dom-traverse/get-explicit-role.ts +112 -0
  89. package/src/dom-traverse/get-implicit-role.ts +36 -0
  90. package/src/dom-traverse/get-non-presentational-ancestor.ts +20 -0
  91. package/src/dom-traverse/get-permitted-roles.ts +7 -0
  92. package/src/dom-traverse/get-spec.ts +7 -0
  93. package/src/dom-traverse/has-required-owned-elements.spec.ts +36 -0
  94. package/src/dom-traverse/has-required-owned-elements.ts +85 -0
  95. package/src/dom-traverse/may-be-focusable.ts +21 -0
  96. package/src/index.ts +17 -6
  97. package/src/specs/aria-specs.ts +6 -0
  98. package/src/specs/content-model-category-to-tag-names.ts +15 -0
  99. package/src/specs/get-aria.ts +85 -0
  100. package/src/{get-attr-specs.spec.ts → specs/get-attr-specs.spec.ts} +9 -6
  101. package/src/{get-attr-specs.ts → specs/get-attr-specs.ts} +12 -7
  102. package/src/specs/get-implicit-role.spec.ts +81 -0
  103. package/src/specs/get-implicit-role.ts +17 -0
  104. package/src/specs/get-permitted-roles.spec.ts +420 -0
  105. package/src/specs/get-permitted-roles.ts +87 -0
  106. package/src/specs/get-role-spec.spec.ts +67 -0
  107. package/src/specs/get-role-spec.ts +72 -0
  108. package/src/specs/get-selectors-by-content-model-category.ts +10 -0
  109. package/src/specs/get-spec-by-tag-name.spec.ts +68 -0
  110. package/src/specs/get-spec-by-tag-name.ts +16 -0
  111. package/src/specs/is-presentational.ts +6 -0
  112. package/src/specs/resolve-version.ts +20 -0
  113. package/src/{get-spec.spec.ts → specs/schema-to-spec.spec.ts} +2 -2
  114. package/src/{get-spec.ts → specs/schema-to-spec.ts} +22 -8
  115. package/src/types/aria.ts +147 -0
  116. package/src/{attributes.ts → types/attributes.ts} +5 -12
  117. package/src/{types.ts → types/index.ts} +70 -69
  118. package/src/{permitted-structres.ts → types/permitted-structres.ts} +15 -25
  119. package/src/{get-ns.ts → utils/get-ns.ts} +6 -1
  120. package/src/{utils.ts → utils/merge-array.ts} +0 -0
  121. package/src/utils/resolve-namespace.spec.ts +37 -0
  122. package/src/utils/resolve-namespace.ts +40 -0
  123. package/tsconfig.tsbuildinfo +1 -1
  124. package/lib/get-attr-specs.d.ts +0 -7
  125. package/lib/get-ns.d.ts +0 -1
  126. package/lib/get-spec-by-tag-name.d.ts +0 -2
  127. package/lib/get-spec-by-tag-name.js +0 -31
  128. package/schemas/wai-aria.schema.json +0 -87
  129. package/src/get-spec-by-tag-name.ts +0 -32
@@ -0,0 +1,5 @@
1
+ import type { MLMLSpec } from '../types';
2
+ export declare function ariaSpec(specs: Readonly<MLMLSpec>): {
3
+ roles: import('../types').ARIRRoleAttribute[];
4
+ ariaAttrs: import('../types').ARIAAttribute[];
5
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ariaSpec = void 0;
4
+ function ariaSpec(specs) {
5
+ const roles = specs.def['#roles'];
6
+ const ariaAttrs = specs.def['#ariaAttrs'];
7
+ return {
8
+ roles,
9
+ ariaAttrs,
10
+ };
11
+ }
12
+ exports.ariaSpec = ariaSpec;
@@ -0,0 +1,6 @@
1
+ import type { ARIAVersion, MLMLSpec } from '../types';
2
+ export declare function ariaSpecs(specs: Readonly<MLMLSpec>, version: ARIAVersion): {
3
+ roles: import("../types").ARIARoleInSchema[];
4
+ graphicsRoles: import("../types").ARIARoleInSchema[];
5
+ props: import("../types").ARIAProperty[];
6
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ariaSpecs = void 0;
4
+ function ariaSpecs(specs, version) {
5
+ const aria = specs.def['#aria'];
6
+ return aria[version];
7
+ }
8
+ exports.ariaSpecs = ariaSpecs;
@@ -0,0 +1,3 @@
1
+ import type { MLMLSpec } from '../types';
2
+ import type { Category } from '../types/permitted-structres';
3
+ export declare function contentModelCategoryToTagNames(contentModel: Category, specs: MLMLSpec): ReadonlyArray<string>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.contentModelCategoryToTagNames = void 0;
4
+ const cache = new Map();
5
+ function contentModelCategoryToTagNames(contentModel, specs) {
6
+ const cached = cache.get(contentModel);
7
+ if (cached) {
8
+ return cached;
9
+ }
10
+ const tags = specs.def['#contentModels'][contentModel];
11
+ const sortedTag = Object.freeze(tags && Array.isArray(tags) ? tags.sort() : []);
12
+ cache.set(contentModel, sortedTag);
13
+ return sortedTag;
14
+ }
15
+ exports.contentModelCategoryToTagNames = contentModelCategoryToTagNames;
@@ -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 conds = Object.keys(conditions);
18
+ let { implicitRole, permittedRoles, implicitProperties, properties, namingProhibited } = aria;
19
+ for (const cond of conds) {
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, 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): 0 | 1 | -1;
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-structres';
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, MLMLSpec } from '../types';
2
+ export declare function getSpecByTagName(specs: Readonly<MLMLSpec>, localName: string, namespace: string | null): ElementSpec | 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.specs.find(spec => spec.name === localNameWithNS) || null;
13
+ cache.set(localNameWithNS, spec);
14
+ return spec;
15
+ }
16
+ exports.getSpecByTagName = getSpecByTagName;
@@ -1,4 +1,4 @@
1
- import type { ElementSpec, ExtendedSpec, MLMLSpec } from './types';
1
+ import type { ElementSpec, ExtendedSpec, MLMLSpec } from '../types';
2
2
  /**
3
3
  * Merging HTML-spec schema and extended spec schemas
4
4
  *
@@ -7,7 +7,7 @@ import type { ElementSpec, ExtendedSpec, MLMLSpec } from './types';
7
7
  * @param schemas `MLDocument.schemas`
8
8
  */
9
9
  export declare function getSpec(schemas: readonly [MLMLSpec, ...ExtendedSpec[]]): {
10
- cites: import("./types").Cites;
11
- def: import("./types").SpecDefs;
12
- specs: ElementSpec[];
10
+ cites: import('../types').Cites;
11
+ def: import('../types').SpecDefs;
12
+ specs: ElementSpec[];
13
13
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSpec = void 0;
4
- const utils_1 = require("./utils");
4
+ const utils_1 = require("../utils");
5
5
  /**
6
6
  * Merging HTML-spec schema and extended spec schemas
7
7
  *
@@ -0,0 +1,6 @@
1
+ import type { ElementSpec, MLMLSpec } from '../types';
2
+ export declare function htmlSpec(
3
+ specs: Readonly<MLMLSpec>,
4
+ localName: string,
5
+ namespace: string | null,
6
+ ): ElementSpec | null;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.htmlSpec = void 0;
4
+ const resolve_namespace_1 = require("../utils/resolve-namespace");
5
+ const cache = new Map();
6
+ function htmlSpec(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.specs.find(spec => spec.name === localNameWithNS) || null;
13
+ cache.set(localNameWithNS, spec);
14
+ return spec;
15
+ }
16
+ exports.htmlSpec = htmlSpec;
@@ -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,9 @@
1
+ import type { NamespaceURI } from '@markuplint/ml-ast';
2
+ declare type NamespacedElementName = {
3
+ localNameWithNS: string;
4
+ localName: string;
5
+ namespace: 'html' | 'svg' | 'mml';
6
+ namespaceURI: NamespaceURI;
7
+ };
8
+ export declare function resolveNamespace(localName: string, namespaceURI?: string): NamespacedElementName;
9
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveNamespace = void 0;
4
+ const utils_1 = require("../utils");
5
+ const cache = new Map();
6
+ function resolveNamespace(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
7
+ const cached = cache.get(localName + namespaceURI);
8
+ if (cached) {
9
+ return cached;
10
+ }
11
+ const name = localName.split(':')[1] || localName;
12
+ const ns = (0, utils_1.getNS)(namespaceURI || null);
13
+ const result = {
14
+ localNameWithNS: `${ns === 'html' ? '' : `${ns}:`}${name}`,
15
+ localName: name,
16
+ namespace: ns,
17
+ namespaceURI: [
18
+ 'http://www.w3.org/1999/xhtml',
19
+ 'http://www.w3.org/2000/svg',
20
+ 'http://www.w3.org/1998/Math/MathML',
21
+ ].find(ns => namespaceURI) || 'http://www.w3.org/1999/xhtml',
22
+ };
23
+ cache.set(localName + namespaceURI, result);
24
+ return result;
25
+ }
26
+ exports.resolveNamespace = resolveNamespace;
@@ -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 cofigure 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
+ };
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.schemaToSpec = void 0;
4
+ const merge_array_1 = require("../utils/merge-array");
5
+ /**
6
+ * Merging HTML-spec schema and extended spec schemas
7
+ *
8
+ * Ex: `@markuplint/html-spec` + `{ specs: ["@markuplint/vue-spec"] }` in cofigure files.
9
+ *
10
+ * @param schemas `MLDocument.schemas`
11
+ */
12
+ function schemaToSpec(schemas) {
13
+ var _a, _b, _c;
14
+ const [main, ...extendedSpecs] = schemas;
15
+ const result = { ...main };
16
+ for (const extendedSpec of extendedSpecs) {
17
+ if (extendedSpec.cites) {
18
+ result.cites = [...result.cites, ...extendedSpec.cites];
19
+ }
20
+ if (extendedSpec.def) {
21
+ if ((_a = extendedSpec.def['#globalAttrs']) === null || _a === void 0 ? void 0 : _a['#extends']) {
22
+ result.def['#globalAttrs']['#HTMLGlobalAttrs'] = {
23
+ ...(((_b = result.def['#globalAttrs']) === null || _b === void 0 ? void 0 : _b['#HTMLGlobalAttrs']) || {}),
24
+ ...(((_c = extendedSpec.def['#globalAttrs']) === null || _c === void 0 ? void 0 : _c['#extends']) || {}),
25
+ };
26
+ }
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
+ };
40
+ }
41
+ if (extendedSpec.def['#contentModels']) {
42
+ const keys = new Set([
43
+ ...Object.keys(result.def['#contentModels']),
44
+ ...Object.keys(extendedSpec.def['#contentModels']),
45
+ ]);
46
+ for (const modelName of keys) {
47
+ const mainModel = result.def['#contentModels'][modelName];
48
+ const exModel = extendedSpec.def['#contentModels'][modelName];
49
+ result.def['#contentModels'][modelName] = [...(mainModel || []), ...(exModel || [])];
50
+ }
51
+ }
52
+ }
53
+ if (extendedSpec.specs) {
54
+ const exSpecs = extendedSpec.specs.slice();
55
+ const specs = [];
56
+ for (const elSpec of result.specs) {
57
+ const tagName = elSpec.name.toLowerCase();
58
+ const index = exSpecs.findIndex(spec => spec.name.toLowerCase() === tagName);
59
+ if (index === -1) {
60
+ specs.push(elSpec);
61
+ continue;
62
+ }
63
+ const exSpec = exSpecs.splice(index, 1)[0];
64
+ specs.push({
65
+ ...elSpec,
66
+ ...exSpec,
67
+ globalAttrs: {
68
+ ...elSpec.globalAttrs,
69
+ ...exSpec.globalAttrs,
70
+ },
71
+ attributes: mergeAttrSpec(elSpec.attributes, exSpec.attributes),
72
+ categories: (0, merge_array_1.mergeArray)(elSpec.categories, exSpec.categories),
73
+ });
74
+ }
75
+ result.specs = specs;
76
+ }
77
+ }
78
+ return result;
79
+ }
80
+ exports.schemaToSpec = schemaToSpec;
81
+ function mergeAttrSpec(std, ex = {}) {
82
+ const result = {};
83
+ const keys = Array.from(new Set([...Object.keys(std), ...Object.keys(ex)]));
84
+ for (const key of keys) {
85
+ const _std = std[key];
86
+ const _ex = ex[key];
87
+ result[key] = {
88
+ ..._std,
89
+ ..._ex,
90
+ };
91
+ }
92
+ return result;
93
+ }