@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.
- package/lib/dom-traverse/accname-computation.d.ts +1 -0
- package/lib/dom-traverse/accname-computation.js +8 -0
- package/lib/dom-traverse/focusability-computation.d.ts +1 -0
- package/lib/dom-traverse/focusability-computation.js +8 -0
- package/lib/dom-traverse/get-aria.d.ts +9 -0
- package/lib/dom-traverse/get-aria.js +54 -0
- package/lib/dom-traverse/get-attr-specs.d.ts +2 -0
- package/lib/dom-traverse/get-attr-specs.js +8 -0
- package/lib/dom-traverse/get-computed-role.d.ts +2 -0
- package/lib/dom-traverse/get-computed-role.js +182 -0
- package/lib/dom-traverse/get-explicit-role.d.ts +2 -0
- package/lib/dom-traverse/get-explicit-role.js +102 -0
- package/lib/dom-traverse/get-implicit-role.d.ts +3 -0
- package/lib/dom-traverse/get-implicit-role.js +37 -0
- package/lib/dom-traverse/get-non-presentational-ancestor.d.ts +5 -0
- package/lib/dom-traverse/get-non-presentational-ancestor.js +21 -0
- package/lib/dom-traverse/get-permitted-roles.d.ts +5 -0
- package/lib/dom-traverse/get-permitted-roles.js +8 -0
- package/lib/dom-traverse/get-spec.d.ts +2 -0
- package/lib/dom-traverse/get-spec.js +8 -0
- package/lib/dom-traverse/has-required-owned-elements.d.ts +3 -0
- package/lib/dom-traverse/has-required-owned-elements.js +69 -0
- package/lib/index.d.ts +16 -6
- package/lib/index.js +16 -6
- package/lib/specs/aria-spec.d.ts +5 -0
- package/lib/specs/aria-spec.js +12 -0
- package/lib/specs/aria-specs.d.ts +6 -0
- package/lib/specs/aria-specs.js +8 -0
- package/lib/specs/content-model-category-to-tag-names.d.ts +3 -0
- package/lib/specs/content-model-category-to-tag-names.js +15 -0
- package/lib/specs/get-aria.d.ts +3 -0
- package/lib/specs/get-aria.js +71 -0
- package/lib/specs/get-attr-specs.d.ts +8 -0
- package/lib/{get-attr-specs.js → specs/get-attr-specs.js} +8 -6
- package/lib/specs/get-implicit-role.d.ts +2 -0
- package/lib/specs/get-implicit-role.js +12 -0
- package/lib/specs/get-permitted-roles.d.ts +12 -0
- package/lib/specs/get-permitted-roles.js +61 -0
- package/lib/specs/get-role-spec.d.ts +5 -0
- package/lib/specs/get-role-spec.js +52 -0
- package/lib/specs/get-selectors-by-content-model-category.d.ts +3 -0
- package/lib/specs/get-selectors-by-content-model-category.js +8 -0
- package/lib/specs/get-spec-by-tag-name.d.ts +2 -0
- package/lib/specs/get-spec-by-tag-name.js +16 -0
- package/lib/{get-spec.d.ts → specs/get-spec.d.ts} +4 -4
- package/lib/{get-spec.js → specs/get-spec.js} +1 -1
- package/lib/specs/html-spec.d.ts +6 -0
- package/lib/specs/html-spec.js +16 -0
- package/lib/specs/is-presentational.d.ts +1 -0
- package/lib/specs/is-presentational.js +10 -0
- package/lib/specs/resolve-namespace.d.ts +9 -0
- package/lib/specs/resolve-namespace.js +26 -0
- package/lib/specs/resolve-version.d.ts +3 -0
- package/lib/specs/resolve-version.js +21 -0
- package/lib/specs/schema-to-spec.d.ts +13 -0
- package/lib/specs/schema-to-spec.js +93 -0
- package/lib/types/aria.d.ts +130 -0
- package/lib/{attributes.js → types/aria.js} +0 -0
- package/lib/{attributes.d.ts → types/attributes.d.ts} +2 -10
- package/lib/{permitted-structres.js → types/attributes.js} +0 -0
- package/lib/{types.d.ts → types/index.d.ts} +49 -64
- package/lib/{types.js → types/index.js} +0 -0
- package/lib/{permitted-structres.d.ts → types/permitted-structres.d.ts} +14 -23
- package/lib/types/permitted-structres.js +8 -0
- package/lib/utils/get-ns.d.ts +1 -0
- package/lib/{get-ns.js → utils/get-ns.js} +0 -0
- package/lib/utils/merge-array.d.ts +5 -0
- package/lib/utils/merge-array.js +36 -0
- package/lib/utils/resolve-namespace.d.ts +9 -0
- package/lib/utils/resolve-namespace.js +26 -0
- package/lib/utils.d.ts +6 -3
- package/lib/utils.js +15 -1
- package/package.json +9 -5
- package/schemas/aria.schema.json +258 -0
- package/schemas/attributes.schema.json +3 -22
- package/schemas/{permitted-structures.schema.json → content-models.schema.json} +52 -81
- package/schemas/element.schema.json +11 -0
- package/src/dom-traverse/accname-computation.spec.ts +69 -0
- package/src/dom-traverse/accname-computation.ts +5 -0
- package/src/dom-traverse/get-attr-specs.ts +8 -0
- package/src/dom-traverse/get-computed-role.spec.ts +134 -0
- package/src/dom-traverse/get-computed-role.ts +193 -0
- package/src/dom-traverse/get-explicit-role.ts +112 -0
- package/src/dom-traverse/get-implicit-role.ts +36 -0
- package/src/dom-traverse/get-non-presentational-ancestor.ts +20 -0
- package/src/dom-traverse/get-permitted-roles.ts +7 -0
- package/src/dom-traverse/get-spec.ts +7 -0
- package/src/dom-traverse/has-required-owned-elements.spec.ts +36 -0
- package/src/dom-traverse/has-required-owned-elements.ts +72 -0
- package/src/index.ts +16 -6
- package/src/specs/aria-specs.ts +6 -0
- package/src/specs/content-model-category-to-tag-names.ts +15 -0
- package/src/specs/get-aria.ts +85 -0
- package/src/{get-attr-specs.spec.ts → specs/get-attr-specs.spec.ts} +4 -7
- package/src/{get-attr-specs.ts → specs/get-attr-specs.ts} +12 -7
- package/src/specs/get-implicit-role.spec.ts +81 -0
- package/src/specs/get-implicit-role.ts +17 -0
- package/src/specs/get-permitted-roles.spec.ts +420 -0
- package/src/specs/get-permitted-roles.ts +87 -0
- package/src/specs/get-role-spec.spec.ts +67 -0
- package/src/specs/get-role-spec.ts +72 -0
- package/src/specs/get-selectors-by-content-model-category.ts +10 -0
- package/src/specs/get-spec-by-tag-name.spec.ts +68 -0
- package/src/specs/get-spec-by-tag-name.ts +16 -0
- package/src/specs/is-presentational.ts +6 -0
- package/src/specs/resolve-version.ts +20 -0
- package/src/{get-spec.spec.ts → specs/schema-to-spec.spec.ts} +2 -2
- package/src/{get-spec.ts → specs/schema-to-spec.ts} +22 -8
- package/src/types/aria.ts +147 -0
- package/src/{attributes.ts → types/attributes.ts} +2 -12
- package/src/{types.ts → types/index.ts} +69 -68
- package/src/{permitted-structres.ts → types/permitted-structres.ts} +15 -25
- package/src/{get-ns.ts → utils/get-ns.ts} +1 -1
- package/src/{utils.ts → utils/merge-array.ts} +0 -0
- package/src/utils/resolve-namespace.ts +36 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/get-attr-specs.d.ts +0 -7
- package/lib/get-ns.d.ts +0 -1
- package/lib/get-spec-by-tag-name.d.ts +0 -2
- package/lib/get-spec-by-tag-name.js +0 -31
- package/schemas/wai-aria.schema.json +0 -87
- package/src/get-spec-by-tag-name.ts +0 -32
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AttributeType, GlobalAttributes } from './attributes';
|
|
3
|
-
import type { ContentModel,
|
|
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
|
-
'#
|
|
37
|
-
|
|
38
|
-
|
|
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?:
|
|
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:
|
|
102
|
+
categories: Category[];
|
|
94
103
|
|
|
95
104
|
/**
|
|
96
105
|
* Permitted contents and permitted parents
|
|
97
106
|
*/
|
|
98
|
-
|
|
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, '
|
|
162
|
+
type ExtendableAttributeSpec = Omit<AttributeJSON, 'type'>;
|
|
184
163
|
|
|
185
|
-
export type
|
|
164
|
+
export type ARIARole = {
|
|
186
165
|
name: string;
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
195
|
-
|
|
173
|
+
childrenPresentational: boolean;
|
|
174
|
+
ownedProperties: ARIARoleOwnedProperties[];
|
|
175
|
+
prohibitedProperties: string[];
|
|
196
176
|
};
|
|
197
177
|
|
|
198
|
-
export type
|
|
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
|
|
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
|
|
243
|
-
|
|
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
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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 =
|
|
16
|
-
export type
|
|
17
|
-
export type
|
|
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
|
|
51
|
-
|
|
52
|
-
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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?:
|
|
87
|
+
notAllowedDescendants?: ContentType[];
|
|
98
88
|
max?: number;
|
|
99
89
|
_TODO_?: string;
|
|
100
90
|
}
|
|
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
|
+
}
|