@markuplint/ml-spec 2.1.0 → 3.0.0-alpha.82

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 (122) 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 +182 -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 +69 -0
  23. package/lib/index.d.ts +16 -6
  24. package/lib/index.js +16 -6
  25. package/lib/specs/aria-spec.d.ts +5 -0
  26. package/lib/specs/aria-spec.js +12 -0
  27. package/lib/specs/aria-specs.d.ts +6 -0
  28. package/lib/specs/aria-specs.js +8 -0
  29. package/lib/specs/content-model-category-to-tag-names.d.ts +3 -0
  30. package/lib/specs/content-model-category-to-tag-names.js +15 -0
  31. package/lib/specs/get-aria.d.ts +3 -0
  32. package/lib/specs/get-aria.js +71 -0
  33. package/lib/specs/get-attr-specs.d.ts +8 -0
  34. package/lib/{get-attr-specs.js → specs/get-attr-specs.js} +8 -6
  35. package/lib/specs/get-implicit-role.d.ts +2 -0
  36. package/lib/specs/get-implicit-role.js +12 -0
  37. package/lib/specs/get-permitted-roles.d.ts +12 -0
  38. package/lib/specs/get-permitted-roles.js +61 -0
  39. package/lib/specs/get-role-spec.d.ts +5 -0
  40. package/lib/specs/get-role-spec.js +52 -0
  41. package/lib/specs/get-selectors-by-content-model-category.d.ts +3 -0
  42. package/lib/specs/get-selectors-by-content-model-category.js +8 -0
  43. package/lib/specs/get-spec-by-tag-name.d.ts +2 -0
  44. package/lib/specs/get-spec-by-tag-name.js +16 -0
  45. package/lib/{get-spec.d.ts → specs/get-spec.d.ts} +4 -4
  46. package/lib/{get-spec.js → specs/get-spec.js} +1 -1
  47. package/lib/specs/html-spec.d.ts +6 -0
  48. package/lib/specs/html-spec.js +16 -0
  49. package/lib/specs/is-presentational.d.ts +1 -0
  50. package/lib/specs/is-presentational.js +10 -0
  51. package/lib/specs/resolve-namespace.d.ts +9 -0
  52. package/lib/specs/resolve-namespace.js +26 -0
  53. package/lib/specs/resolve-version.d.ts +3 -0
  54. package/lib/specs/resolve-version.js +21 -0
  55. package/lib/specs/schema-to-spec.d.ts +13 -0
  56. package/lib/specs/schema-to-spec.js +93 -0
  57. package/lib/types/aria.d.ts +130 -0
  58. package/lib/{attributes.js → types/aria.js} +0 -0
  59. package/lib/{attributes.d.ts → types/attributes.d.ts} +2 -10
  60. package/lib/{permitted-structres.js → types/attributes.js} +0 -0
  61. package/lib/{types.d.ts → types/index.d.ts} +49 -64
  62. package/lib/{types.js → types/index.js} +0 -0
  63. package/lib/{permitted-structres.d.ts → types/permitted-structres.d.ts} +14 -23
  64. package/lib/types/permitted-structres.js +8 -0
  65. package/lib/utils/get-ns.d.ts +1 -0
  66. package/lib/{get-ns.js → utils/get-ns.js} +0 -0
  67. package/lib/utils/merge-array.d.ts +5 -0
  68. package/lib/utils/merge-array.js +36 -0
  69. package/lib/utils/resolve-namespace.d.ts +9 -0
  70. package/lib/utils/resolve-namespace.js +26 -0
  71. package/lib/utils.d.ts +6 -3
  72. package/lib/utils.js +15 -1
  73. package/package.json +9 -5
  74. package/schemas/aria.schema.json +258 -0
  75. package/schemas/attributes.schema.json +3 -22
  76. package/schemas/{permitted-structures.schema.json → content-models.schema.json} +52 -81
  77. package/schemas/element.schema.json +11 -0
  78. package/src/dom-traverse/accname-computation.spec.ts +69 -0
  79. package/src/dom-traverse/accname-computation.ts +5 -0
  80. package/src/dom-traverse/get-attr-specs.ts +8 -0
  81. package/src/dom-traverse/get-computed-role.spec.ts +134 -0
  82. package/src/dom-traverse/get-computed-role.ts +193 -0
  83. package/src/dom-traverse/get-explicit-role.ts +112 -0
  84. package/src/dom-traverse/get-implicit-role.ts +36 -0
  85. package/src/dom-traverse/get-non-presentational-ancestor.ts +20 -0
  86. package/src/dom-traverse/get-permitted-roles.ts +7 -0
  87. package/src/dom-traverse/get-spec.ts +7 -0
  88. package/src/dom-traverse/has-required-owned-elements.spec.ts +36 -0
  89. package/src/dom-traverse/has-required-owned-elements.ts +72 -0
  90. package/src/index.ts +16 -6
  91. package/src/specs/aria-specs.ts +6 -0
  92. package/src/specs/content-model-category-to-tag-names.ts +15 -0
  93. package/src/specs/get-aria.ts +85 -0
  94. package/src/{get-attr-specs.spec.ts → specs/get-attr-specs.spec.ts} +4 -7
  95. package/src/{get-attr-specs.ts → specs/get-attr-specs.ts} +12 -7
  96. package/src/specs/get-implicit-role.spec.ts +81 -0
  97. package/src/specs/get-implicit-role.ts +17 -0
  98. package/src/specs/get-permitted-roles.spec.ts +420 -0
  99. package/src/specs/get-permitted-roles.ts +87 -0
  100. package/src/specs/get-role-spec.spec.ts +67 -0
  101. package/src/specs/get-role-spec.ts +72 -0
  102. package/src/specs/get-selectors-by-content-model-category.ts +10 -0
  103. package/src/specs/get-spec-by-tag-name.spec.ts +68 -0
  104. package/src/specs/get-spec-by-tag-name.ts +16 -0
  105. package/src/specs/is-presentational.ts +6 -0
  106. package/src/specs/resolve-version.ts +20 -0
  107. package/src/{get-spec.spec.ts → specs/schema-to-spec.spec.ts} +2 -2
  108. package/src/{get-spec.ts → specs/schema-to-spec.ts} +22 -8
  109. package/src/types/aria.ts +147 -0
  110. package/src/{attributes.ts → types/attributes.ts} +2 -12
  111. package/src/{types.ts → types/index.ts} +69 -68
  112. package/src/{permitted-structres.ts → types/permitted-structres.ts} +15 -25
  113. package/src/{get-ns.ts → utils/get-ns.ts} +1 -1
  114. package/src/{utils.ts → utils/merge-array.ts} +0 -0
  115. package/src/utils/resolve-namespace.ts +36 -0
  116. package/tsconfig.tsbuildinfo +1 -1
  117. package/lib/get-attr-specs.d.ts +0 -7
  118. package/lib/get-ns.d.ts +0 -1
  119. package/lib/get-spec-by-tag-name.d.ts +0 -2
  120. package/lib/get-spec-by-tag-name.js +0 -31
  121. package/schemas/wai-aria.schema.json +0 -87
  122. package/src/get-spec-by-tag-name.ts +0 -32
@@ -1,6 +1,7 @@
1
- import type { AttributeJSON } from '.';
2
- import type { AttributeType, GlobalAttributes } from './attributes';
3
- import type { ContentModel, PermittedStructuresSchema } from './permitted-structres';
1
+ import type { ARIA } from './aria';
2
+ import type { AttributeJSON, AttributeType, GlobalAttributes } from './attributes';
3
+ import type { ContentModel, Category } from './permitted-structres';
4
+ import type { NamespaceURI } from '@markuplint/ml-ast';
4
5
 
5
6
  /**
6
7
  * markuplit Markup-language spec
@@ -33,9 +34,17 @@ export type SpecDefs = {
33
34
  '#HTMLGlobalAttrs': Record<string, Partial<Attribute>>;
34
35
  [OtherGlobalAttrs: string]: Record<string, Partial<Attribute>>;
35
36
  }>;
36
- '#ariaAttrs': ARIAAttribute[];
37
- '#roles': ARIRRoleAttribute[];
38
- '#contentModels': { [model in ContentModel]?: string[] };
37
+ '#aria': {
38
+ '1.2': ARIASpec;
39
+ '1.1': ARIASpec;
40
+ };
41
+ '#contentModels': { [model in Category]?: string[] };
42
+ };
43
+
44
+ type ARIASpec = {
45
+ roles: ARIARoleInSchema[];
46
+ graphicsRoles: ARIARoleInSchema[];
47
+ props: ARIAProperty[];
39
48
  };
40
49
 
41
50
  /**
@@ -51,7 +60,7 @@ export type ElementSpec = {
51
60
  * Namespaces in XML
52
61
  * @see https://www.w3.org/TR/xml-names/
53
62
  */
54
- namespace?: 'http://www.w3.org/1999/xhtml' | 'http://www.w3.org/2000/svg' | 'http://www.w3.org/1998/Math/MathML';
63
+ namespace?: NamespaceURI;
55
64
 
56
65
  /**
57
66
  * Reference URL
@@ -90,36 +99,12 @@ export type ElementSpec = {
90
99
  /**
91
100
  * Element cateogries
92
101
  */
93
- categories: ContentModel[];
102
+ categories: Category[];
94
103
 
95
104
  /**
96
105
  * Permitted contents and permitted parents
97
106
  */
98
- permittedStructures: PermittedStructuresSchema;
99
-
100
- /**
101
- * Permitted ARIA roles
102
- */
103
- permittedRoles: {
104
- summary: string;
105
- roles: PermittedRoles;
106
- conditions?: {
107
- condition: string;
108
- roles: PermittedRoles;
109
- }[];
110
- };
111
-
112
- /**
113
- * Implicit ARIA role
114
- */
115
- implicitRole: {
116
- summary: string;
117
- role: ImplicitRole;
118
- conditions?: {
119
- condition: string;
120
- role: ImplicitRole;
121
- }[];
122
- };
107
+ contentModel: ContentModel;
123
108
 
124
109
  /**
125
110
  * Tag omittion
@@ -136,6 +121,11 @@ export type ElementSpec = {
136
121
  */
137
122
  attributes: Record<string, Attribute>;
138
123
 
124
+ /**
125
+ * WAI-ARIA role and properies
126
+ */
127
+ aria: ARIA;
128
+
139
129
  /**
140
130
  * If true, it is possible to add any properties as attributes,
141
131
  * for example, when using a template engine or a view language.
@@ -147,17 +137,6 @@ export type ElementSpec = {
147
137
  possibleToAddProperties?: true;
148
138
  };
149
139
 
150
- /**
151
- * If `false`, this mean is "No corresponding role".
152
- */
153
- type ImplicitRole = string | false;
154
-
155
- /**
156
- * If `true`, this mean is "Any".
157
- * If `false`, this mean is "No".
158
- */
159
- export type PermittedRoles = string[] | boolean;
160
-
161
140
  type ElementSpecOmittion = false | ElementSpecOmittionTags;
162
141
 
163
142
  type ElementSpecOmittionTags = {
@@ -180,31 +159,39 @@ export type Attribute = {
180
159
  nonStandard?: true;
181
160
  } & ExtendableAttributeSpec;
182
161
 
183
- type ExtendableAttributeSpec = Omit<AttributeJSON, 'ref' | '_TODO_' | 'type'>;
162
+ type ExtendableAttributeSpec = Omit<AttributeJSON, 'type'>;
184
163
 
185
- export type ARIRRoleAttribute = {
164
+ export type ARIARole = {
186
165
  name: string;
187
- description: string;
188
- isAbstract?: true;
189
- generalization: string[];
190
- requiredContextRole?: string[];
166
+ isAbstract: boolean;
167
+ requiredContextRole: string[];
168
+ requiredOwnedElements: string[];
191
169
  accessibleNameRequired: boolean;
170
+ accessibleNameFromAuthor: boolean;
192
171
  accessibleNameFromContent: boolean;
193
172
  accessibleNameProhibited: boolean;
194
- ownedAttribute: ARIARoleOwnedPropOrState[];
195
- childrenPresentational?: boolean;
173
+ childrenPresentational: boolean;
174
+ ownedProperties: ARIARoleOwnedProperties[];
175
+ prohibitedProperties: string[];
196
176
  };
197
177
 
198
- export type ARIARoleOwnedPropOrState = {
178
+ export type ARIARoleInSchema = Partial<
179
+ ARIARole & {
180
+ description: string;
181
+ generalization: string[];
182
+ }
183
+ > & {
184
+ name: string;
185
+ };
186
+
187
+ export type ARIARoleOwnedProperties = {
199
188
  name: string;
200
189
  inherited?: true;
201
190
  required?: true;
202
191
  deprecated?: true;
203
- prohibited?: true;
204
- defaultValue?: boolean | string | number;
205
192
  };
206
193
 
207
- export type ARIAAttribute = {
194
+ export type ARIAProperty = {
208
195
  name: string;
209
196
  type: 'property' | 'state';
210
197
  deprecated?: true;
@@ -233,22 +220,36 @@ export type ARIAAttributeValue =
233
220
  | 'token list'
234
221
  | 'URI';
235
222
 
223
+ export type ARIAVersion = '1.1' | '1.2';
224
+
236
225
  export type EquivalentHtmlAttr = {
237
226
  htmlAttrName: string;
238
227
  isNotStrictEquivalent?: true;
239
228
  value: string | null;
240
229
  };
241
230
 
242
- export interface SpecOM {
243
- [tagName: string]: MLDOMElementSpec;
244
- }
231
+ export type Matches = (selector: string) => boolean;
232
+
233
+ export type ComputedRole = {
234
+ el: Element;
235
+ role:
236
+ | (ARIARole & {
237
+ superClassRoles: ARIARoleInSchema[];
238
+ isImplicit?: boolean;
239
+ })
240
+ | null;
241
+ errorType?: RoleComputationError;
242
+ };
245
243
 
246
- export interface MLDOMElementSpec {
247
- experimental: boolean;
248
- obsolete: boolean | string;
249
- deprecated: boolean;
250
- nonStandard: boolean;
251
- categories: ContentModel[];
252
- permittedStructures: PermittedStructuresSchema;
253
- attributes: Attribute[];
254
- }
244
+ export type RoleComputationError =
245
+ | 'ABSTRACT'
246
+ | 'GLOBAL_PROP_MUST_NOT_BE_PRESENTATIONAL'
247
+ | 'IMPLICIT_ROLE_NAMESPACE_ERROR'
248
+ | 'INTERACTIVE_ELEMENT_MUST_NOT_BE_PRESENTATIONAL'
249
+ | 'INVALID_LANDMARK'
250
+ | 'INVALID_REQUIRED_CONTEXT_ROLE'
251
+ | 'NO_EXPLICIT'
252
+ | 'NO_OWNER'
253
+ | 'NO_PERMITTED'
254
+ | 'REQUIRED_OWNED_ELEMENT_MUST_NOT_BE_PRESENTATIONAL'
255
+ | 'ROLE_NO_EXISTS';
@@ -12,9 +12,10 @@ export type PermittedContent =
12
12
  | PermittedContentZeroOrMore
13
13
  | PermittedContentChoice
14
14
  | PermittedContentInterleave;
15
- export type Target = Node | Node[];
16
- export type Node = string | '#text' | ContentModel;
17
- export type ContentModel =
15
+ export type Target = ContentType | ContentType[];
16
+ export type ContentType = string | Category;
17
+ export type Category =
18
+ | '#text'
18
19
  | '#phrasing'
19
20
  | '#flow'
20
21
  | '#interactive'
@@ -47,32 +48,21 @@ export type ContentModel =
47
48
  | '#SVGOtherXMLNamespace';
48
49
  export type PermittedContentSpec = PermittedContent[];
49
50
 
50
- export interface PermittedStructuresSchema {
51
- summary?: string;
52
- tag: string;
51
+ export interface ContentModelsSchema {
52
+ __contentModel?: ContentModel;
53
+ }
54
+ export interface ContentModel {
55
+ contents: PermittedContentSpec | boolean;
56
+ descendantOf?: string;
53
57
  conditional?: {
54
- condition:
55
- | {
56
- hasAttr: string;
57
- }
58
- | {
59
- parent: string;
60
- /**
61
- * Not support yet
62
- */
63
- hasNotAttr?: string;
64
- _TODO_?: string;
65
- _parent?: string;
66
- };
58
+ condition: string;
67
59
  contents: PermittedContentSpec | boolean;
68
60
  }[];
69
- contents: PermittedContentSpec | boolean;
70
- ancestor?: Node;
71
61
  }
72
62
  export interface PermittedContentRequire {
73
63
  require: Target;
74
64
  ignore?: Target;
75
- notAllowedDescendants?: Node[];
65
+ notAllowedDescendants?: ContentType[];
76
66
  max?: number;
77
67
  min?: number;
78
68
  _TODO_?: string;
@@ -80,21 +70,21 @@ export interface PermittedContentRequire {
80
70
  export interface PermittedContentOptional {
81
71
  optional: Target;
82
72
  ignore?: Target;
83
- notAllowedDescendants?: Node[];
73
+ notAllowedDescendants?: ContentType[];
84
74
  max?: number;
85
75
  _TODO_?: string;
86
76
  }
87
77
  export interface PermittedContentOneOrMore {
88
78
  oneOrMore: Target | PermittedContentSpec;
89
79
  ignore?: Target;
90
- notAllowedDescendants?: Node[];
80
+ notAllowedDescendants?: ContentType[];
91
81
  max?: number;
92
82
  _TODO_?: string;
93
83
  }
94
84
  export interface PermittedContentZeroOrMore {
95
85
  zeroOrMore: Target | PermittedContentSpec;
96
86
  ignore?: Target;
97
- notAllowedDescendants?: Node[];
87
+ notAllowedDescendants?: ContentType[];
98
88
  max?: number;
99
89
  _TODO_?: string;
100
90
  }
@@ -1,4 +1,4 @@
1
- export function getNS(namespaceURI: string) {
1
+ export function getNS(namespaceURI: string | null) {
2
2
  switch (namespaceURI) {
3
3
  case 'http://www.w3.org/2000/svg': {
4
4
  return 'svg';
File without changes
@@ -0,0 +1,36 @@
1
+ import type { NamespaceURI } from '@markuplint/ml-ast';
2
+
3
+ import { getNS } from './get-ns';
4
+
5
+ const cache = new Map<string, NamespacedElementName>();
6
+
7
+ type NamespacedElementName = {
8
+ localNameWithNS: string;
9
+ localName: string;
10
+ namespace: 'html' | 'svg' | 'mml';
11
+ namespaceURI: NamespaceURI;
12
+ };
13
+
14
+ export function resolveNamespace(localName: string, namespaceURI: string | null = 'http://www.w3.org/1999/xhtml') {
15
+ const cached = cache.get(localName + namespaceURI);
16
+ if (cached) {
17
+ return cached;
18
+ }
19
+ const name = localName.split(':')[1] || localName;
20
+ const ns = getNS(namespaceURI || null);
21
+ const result: NamespacedElementName = {
22
+ localNameWithNS: `${ns === 'html' ? '' : `${ns}:`}${name}`,
23
+ localName: name,
24
+ namespace: ns,
25
+ namespaceURI:
26
+ (
27
+ [
28
+ 'http://www.w3.org/1999/xhtml',
29
+ 'http://www.w3.org/2000/svg',
30
+ 'http://www.w3.org/1998/Math/MathML',
31
+ ] as const
32
+ ).find(ns => ns === namespaceURI) || 'http://www.w3.org/1999/xhtml',
33
+ };
34
+ cache.set(localName + namespaceURI, result);
35
+ return result;
36
+ }