@markuplint/ml-spec 3.0.0-alpha.2 → 3.0.0-alpha.27

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 (74) hide show
  1. package/README.md +8 -3
  2. package/lib/dom-traverse/get-computed-aria-props.d.ts +12 -0
  3. package/lib/dom-traverse/get-computed-aria-props.js +106 -0
  4. package/lib/dom-traverse/get-explicit-role.js +1 -1
  5. package/lib/dom-traverse/is-exposed.d.ts +11 -0
  6. package/lib/dom-traverse/is-exposed.js +181 -0
  7. package/lib/index.d.ts +5 -0
  8. package/lib/index.js +5 -0
  9. package/lib/specs/get-attr-specs.d.ts +1 -1
  10. package/lib/specs/is-nothing-content-model.d.ts +5 -0
  11. package/lib/specs/is-nothing-content-model.js +12 -0
  12. package/lib/specs/is-palpable-elements.d.ts +5 -0
  13. package/lib/specs/is-palpable-elements.js +47 -0
  14. package/lib/specs/is-void-element.d.ts +1 -0
  15. package/lib/specs/is-void-element.js +25 -0
  16. package/lib/specs/schema-to-spec.d.ts +1 -1
  17. package/lib/specs/schema-to-spec.js +1 -1
  18. package/lib/types/aria.d.ts +3 -3
  19. package/lib/types/attributes.d.ts +2 -2
  20. package/lib/types/index.d.ts +21 -21
  21. package/lib/types/permitted-structres.d.ts +4 -4
  22. package/lib/types/permitted-structures.d.ts +4 -4
  23. package/lib/utils/merge-array.d.ts +1 -1
  24. package/lib/utils/resolve-namespace.d.ts +1 -1
  25. package/package.json +6 -6
  26. package/schemas/aria.schema.json +0 -258
  27. package/schemas/attributes.schema.json +0 -204
  28. package/schemas/content-models.schema.json +0 -200
  29. package/schemas/element.schema.json +0 -11
  30. package/schemas/global-attributes.schema.json +0 -761
  31. package/src/dom-traverse/accname-computation.spec.ts +0 -69
  32. package/src/dom-traverse/accname-computation.ts +0 -5
  33. package/src/dom-traverse/get-attr-specs.ts +0 -8
  34. package/src/dom-traverse/get-computed-role.spec.ts +0 -134
  35. package/src/dom-traverse/get-computed-role.ts +0 -181
  36. package/src/dom-traverse/get-content-model.ts +0 -32
  37. package/src/dom-traverse/get-explicit-role.ts +0 -112
  38. package/src/dom-traverse/get-implicit-role.ts +0 -36
  39. package/src/dom-traverse/get-non-presentational-ancestor.ts +0 -20
  40. package/src/dom-traverse/get-permitted-roles.ts +0 -7
  41. package/src/dom-traverse/get-spec.ts +0 -7
  42. package/src/dom-traverse/has-required-owned-elements.spec.ts +0 -36
  43. package/src/dom-traverse/has-required-owned-elements.ts +0 -85
  44. package/src/dom-traverse/may-be-focusable.ts +0 -21
  45. package/src/index.ts +0 -19
  46. package/src/specs/aria-specs.ts +0 -6
  47. package/src/specs/content-model-category-to-tag-names.ts +0 -15
  48. package/src/specs/get-aria.ts +0 -85
  49. package/src/specs/get-attr-specs.spec.ts +0 -47
  50. package/src/specs/get-attr-specs.ts +0 -116
  51. package/src/specs/get-implicit-role.spec.ts +0 -81
  52. package/src/specs/get-implicit-role.ts +0 -17
  53. package/src/specs/get-permitted-roles.spec.ts +0 -420
  54. package/src/specs/get-permitted-roles.ts +0 -87
  55. package/src/specs/get-role-spec.spec.ts +0 -67
  56. package/src/specs/get-role-spec.ts +0 -72
  57. package/src/specs/get-selectors-by-content-model-category.ts +0 -10
  58. package/src/specs/get-spec-by-tag-name.spec.ts +0 -68
  59. package/src/specs/get-spec-by-tag-name.ts +0 -20
  60. package/src/specs/is-presentational.ts +0 -6
  61. package/src/specs/resolve-version.ts +0 -20
  62. package/src/specs/schema-to-spec.spec.ts +0 -39
  63. package/src/specs/schema-to-spec.ts +0 -103
  64. package/src/types/aria.ts +0 -153
  65. package/src/types/attributes.ts +0 -1473
  66. package/src/types/index.ts +0 -255
  67. package/src/types/permitted-structres.ts +0 -101
  68. package/src/types/permitted-structures.ts +0 -97
  69. package/src/utils/get-ns.ts +0 -18
  70. package/src/utils/merge-array.ts +0 -35
  71. package/src/utils/resolve-namespace.spec.ts +0 -37
  72. package/src/utils/resolve-namespace.ts +0 -40
  73. package/tsconfig.test.json +0 -3
  74. package/tsconfig.tsbuildinfo +0 -1
@@ -1,85 +0,0 @@
1
- import type { ARIAVersion, ComputedRole, MLMLSpec } from '../types';
2
-
3
- import { isPresentational } from '../specs/is-presentational';
4
-
5
- import { getComputedRole } from './get-computed-role';
6
- import { getExplicitRole } from './get-explicit-role';
7
- import { getImplicitRole } from './get-implicit-role';
8
-
9
- export function hasRequiredOwnedElement(el: Element, specs: Readonly<MLMLSpec>, version: ARIAVersion): boolean {
10
- /**
11
- * The element has aria-owns which means it may have owned elements.
12
- *
13
- * THIS CONDITION IS PARTIAL SUPPORT.
14
- */
15
- if (el.hasAttribute('aria-owns')) {
16
- // FIXME
17
- return true;
18
- }
19
-
20
- /**
21
- * Otherwise, traverses descendants to find owned elements.
22
- */
23
- const computed = getComputedRole(specs, el, version);
24
- if (!computed.role || computed.role.requiredOwnedElements.length === 0) {
25
- return true;
26
- }
27
- for (const expectRole of computed.role.requiredOwnedElements) {
28
- for (const owned of getClosestNonPresentationalDescendants(el, specs, version)) {
29
- if (isRequiredOwnedElement(owned, expectRole, specs, version)) {
30
- return true;
31
- }
32
- }
33
- }
34
-
35
- return false;
36
- }
37
-
38
- export function isRequiredOwnedElement(owned: ComputedRole, query: string, specs: MLMLSpec, version: ARIAVersion) {
39
- const [baseRole, owningRole] = query.split(' > ') as [string, string | undefined];
40
- if (owned.role?.name !== baseRole) {
41
- return false;
42
- }
43
-
44
- if (!owningRole) {
45
- return true;
46
- }
47
-
48
- for (const owning of getClosestNonPresentationalDescendants(owned.el, specs, version)) {
49
- if (owning.role?.name === owningRole) {
50
- return true;
51
- }
52
- }
53
-
54
- return false;
55
- }
56
-
57
- /**
58
- * Gets the list of closest non-presentational descendants.
59
- * ⚠ THE SPECIFICATION HAS AN ISSUE
60
- * that has not decided whether the owned element is a child or a descendant.
61
- *
62
- * @see https://github.com/w3c/aria/issues/1033
63
- * @see https://github.com/w3c/aria/issues/748
64
- * @see https://github.com/w3c/aria/pull/1162
65
- * @see https://github.com/w3c/aria/pull/1213
66
- *
67
- * Currently, this process interprets that as A CHILD
68
- * because it wants to be near to HTML semantics.
69
- * However, the presentational role behaves transparently
70
- * according to the sample code in WAI-ARIA specification.
71
- */
72
- function getClosestNonPresentationalDescendants(el: Element, specs: MLMLSpec, version: ARIAVersion): ComputedRole[] {
73
- const owned: ComputedRole[] = [];
74
- for (const child of Array.from(el.children)) {
75
- const implicitRole = getImplicitRole(specs, child, version);
76
- const explicitRole = getExplicitRole(specs, child, version);
77
- const computed = explicitRole.role ? explicitRole : implicitRole;
78
- if (isPresentational(computed.role?.name)) {
79
- owned.push(...getClosestNonPresentationalDescendants(child, specs, version));
80
- continue;
81
- }
82
- owned.push({ ...computed, el: child });
83
- }
84
- return owned;
85
- }
@@ -1,21 +0,0 @@
1
- import type { MLMLSpec } from '../types';
2
-
3
- import { getSelectorsByContentModelCategory } from '../specs/get-selectors-by-content-model-category';
4
-
5
- export function mayBeFocusable(el: Element, specs: Readonly<MLMLSpec>): boolean {
6
- return [
7
- /**
8
- * Interactive content
9
- *
10
- * @see https://html.spec.whatwg.org/multipage/dom.html#interactive-content
11
- */
12
- ...getSelectorsByContentModelCategory(specs, '#interactive'),
13
- /**
14
- * Interaction
15
- *
16
- * @see https://html.spec.whatwg.org/multipage/interaction.html
17
- */
18
- '[tabindex]',
19
- '[contenteditable]:not([contenteditable="false" i])',
20
- ].some(selector => el.matches(selector));
21
- }
package/src/index.ts DELETED
@@ -1,19 +0,0 @@
1
- export * from './dom-traverse/accname-computation';
2
- export * from './dom-traverse/get-attr-specs';
3
- export * from './dom-traverse/get-computed-role';
4
- export * from './dom-traverse/get-content-model';
5
- export * from './dom-traverse/get-implicit-role';
6
- export * from './dom-traverse/get-permitted-roles';
7
- export * from './dom-traverse/get-spec';
8
- export * from './dom-traverse/has-required-owned-elements';
9
- export * from './dom-traverse/may-be-focusable';
10
- export * from './specs/aria-specs';
11
- export * from './specs/content-model-category-to-tag-names';
12
- export * from './specs/get-role-spec';
13
- export * from './specs/get-spec-by-tag-name';
14
- export * from './specs/schema-to-spec';
15
- export * from './types';
16
- export * from './types/aria';
17
- export * from './types/attributes';
18
- export * from './types/permitted-structures';
19
- export * from './utils/resolve-namespace';
@@ -1,6 +0,0 @@
1
- import type { ARIAVersion, MLMLSpec } from '../types';
2
-
3
- export function ariaSpecs(specs: Readonly<MLMLSpec>, version: ARIAVersion) {
4
- const aria = specs.def['#aria'];
5
- return aria[version];
6
- }
@@ -1,15 +0,0 @@
1
- import type { MLMLSpec } from '../types';
2
- import type { Category } from '../types/permitted-structures';
3
-
4
- const cache = new Map<Category, ReadonlyArray<string>>();
5
-
6
- export function contentModelCategoryToTagNames(contentModel: Category, def: MLMLSpec['def']): ReadonlyArray<string> {
7
- const cached = cache.get(contentModel);
8
- if (cached) {
9
- return cached;
10
- }
11
- const tags: string[] | undefined = def['#contentModels'][contentModel];
12
- const sortedTag = Object.freeze(tags && Array.isArray(tags) ? tags.sort() : []);
13
- cache.set(contentModel, sortedTag);
14
- return sortedTag;
15
- }
@@ -1,85 +0,0 @@
1
- import type { ARIAVersion, Matches, MLMLSpec } from '../types';
2
- import type { ARIA, PermittedRoles } from '../types/aria';
3
-
4
- import { getSpecByTagName } from './get-spec-by-tag-name';
5
- import { resolveVersion } from './resolve-version';
6
-
7
- const cache = new Map<string, Omit<ARIA, ARIAVersion> | null>();
8
-
9
- export function getARIA(
10
- specs: Readonly<MLMLSpec>,
11
- localName: string,
12
- namespace: string | null,
13
- version: ARIAVersion,
14
- matches: Matches,
15
- ): Omit<ARIA, ARIAVersion | 'conditions'> | null {
16
- const aria = getVersionResolvedARIA(specs, localName, namespace, version);
17
- if (!aria) {
18
- return null;
19
- }
20
- const conditions = aria.conditions;
21
- if (!conditions) {
22
- return aria;
23
- }
24
- const conditionKeys = Object.keys(conditions);
25
- let { implicitRole, permittedRoles, implicitProperties, properties, namingProhibited } = aria;
26
- for (const cond of conditionKeys) {
27
- if (!matches(cond)) {
28
- continue;
29
- }
30
- const condARIA = conditions[cond];
31
- implicitRole = condARIA.implicitRole ?? implicitRole;
32
- permittedRoles = condARIA.permittedRoles ?? permittedRoles;
33
- implicitProperties = condARIA.implicitProperties ?? implicitProperties;
34
- properties = condARIA.properties ?? properties;
35
- namingProhibited = condARIA.namingProhibited ?? namingProhibited;
36
- }
37
- return {
38
- implicitRole,
39
- permittedRoles,
40
- implicitProperties,
41
- properties,
42
- namingProhibited,
43
- };
44
- }
45
-
46
- function getVersionResolvedARIA(
47
- specs: Readonly<MLMLSpec>,
48
- localName: string,
49
- namespace: string | null,
50
- version: ARIAVersion,
51
- ) {
52
- const key = localName + namespace + version;
53
- let aria = cache.get(key);
54
- if (aria !== undefined) {
55
- return aria;
56
- }
57
- const spec = getSpecByTagName(specs.specs, localName, namespace)?.aria;
58
- if (!spec) {
59
- cache.set(key, null);
60
- return null;
61
- }
62
- aria = resolveVersion(spec, version);
63
- if (aria.permittedRoles) {
64
- aria.permittedRoles = optimizePermittedRoles(aria.permittedRoles);
65
- }
66
- cache.set(key, aria);
67
- return aria;
68
- }
69
-
70
- function optimizePermittedRoles(permittedRoles: PermittedRoles) {
71
- if (!Array.isArray(permittedRoles)) {
72
- return permittedRoles;
73
- }
74
- const unique = new Set(permittedRoles);
75
-
76
- // https://www.w3.org/TR/wai-aria-1.2/#note-regarding-the-aria-1-1-none-role
77
- if (unique.has('presentation')) {
78
- unique.add('none');
79
- }
80
- if (unique.has('none')) {
81
- unique.add('presentation');
82
- }
83
-
84
- return Array.from(unique).sort();
85
- }
@@ -1,47 +0,0 @@
1
- import htmlSpec from '@markuplint/html-spec';
2
-
3
- import { getAttrSpecs } from './get-attr-specs';
4
-
5
- describe('getSpec', () => {
6
- test('svg:image[x]', () => {
7
- const specs = getAttrSpecs('image', 'http://www.w3.org/2000/svg', htmlSpec);
8
- const x = specs?.find(spec => spec.name === 'x');
9
- expect(x).toStrictEqual({
10
- defaultValue: '0',
11
- name: 'x',
12
- type: ['<svg-length>', '<percentage>'],
13
- animatable: true,
14
- });
15
- });
16
-
17
- test('svg:foreignObject[x]', () => {
18
- const specs = getAttrSpecs('foreignObject', 'http://www.w3.org/2000/svg', htmlSpec);
19
- const x = specs?.find(spec => spec.name === 'x');
20
- expect(x).toStrictEqual({
21
- defaultValue: '0',
22
- description:
23
- 'The x coordinate of the foreignObject. Value type: <length>|<percentage> ; Default value: 0; Animatable: yes',
24
- name: 'x',
25
- type: ['<svg-length>', '<percentage>'],
26
- animatable: true,
27
- });
28
- });
29
-
30
- test('svg:linearGradient[xlink:href]', () => {
31
- const specs = getAttrSpecs('linearGradient', 'http://www.w3.org/2000/svg', htmlSpec);
32
- const x = specs?.find(spec => spec.name === 'xlink:href');
33
- expect(x).toStrictEqual({
34
- description:
35
- 'Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.An <IRI> reference to another <linearGradient> element that will be used as a template. Value type: <IRI> ; Default value: none; Animatable: yes',
36
- name: 'xlink:href',
37
- type: 'URL',
38
- deprecated: true,
39
- });
40
- });
41
-
42
- test('img[fetchpriority] (experimental spec)', () => {
43
- const attrs = getAttrSpecs('img', null, htmlSpec);
44
- const fetchpriority = attrs?.find(attr => attr.name === 'fetchpriority');
45
- expect(fetchpriority?.experimental).toBe(true);
46
- });
47
- });
@@ -1,116 +0,0 @@
1
- import type { MLMLSpec, Attribute } from '../types';
2
- import type { NamespaceURI } from '@markuplint/ml-ast';
3
-
4
- import { resolveNamespace } from '../utils/resolve-namespace';
5
-
6
- const cacheMap = new Map<string, Attribute[] | null>();
7
- const schemaCache = new WeakSet<MLMLSpec>();
8
-
9
- export function getAttrSpecs(localName: string, namespace: NamespaceURI | null, schema: MLMLSpec) {
10
- if (!schemaCache.has(schema)) {
11
- cacheMap.clear();
12
- }
13
-
14
- const { localNameWithNS } = resolveNamespace(localName, namespace || undefined);
15
-
16
- const cache = cacheMap.get(localNameWithNS);
17
-
18
- if (cache !== undefined) {
19
- return cache;
20
- }
21
-
22
- schemaCache.add(schema);
23
-
24
- const elSpec = schema.specs.find(spec => spec.name === localNameWithNS);
25
- if (!elSpec) {
26
- cacheMap.set(localNameWithNS, null);
27
- return null;
28
- }
29
-
30
- const globalAttrs = schema.def['#globalAttrs'];
31
- let attrs: Record<string, Partial<Attribute>> = {};
32
-
33
- for (const catName in elSpec.globalAttrs) {
34
- // @ts-ignore
35
- const catAttrs: boolean | string[] = elSpec.globalAttrs[catName];
36
- if (!catAttrs) {
37
- continue;
38
- }
39
- if (typeof catAttrs === 'boolean') {
40
- const global = globalAttrs[catName];
41
- attrs = {
42
- ...attrs,
43
- ...global,
44
- };
45
- continue;
46
- }
47
- if (Array.isArray(catAttrs)) {
48
- const global = globalAttrs[catName];
49
- if (!global) {
50
- continue;
51
- }
52
- catAttrs.forEach(selectedName => {
53
- const selected = global[selectedName];
54
- attrs[selectedName] = {
55
- ...attrs[selectedName],
56
- ...selected,
57
- };
58
- });
59
- continue;
60
- }
61
- }
62
-
63
- for (const attrName in elSpec.attributes) {
64
- const attr = elSpec.attributes[attrName];
65
- if (!attr) {
66
- continue;
67
- }
68
-
69
- const current = attrs[attrName] as Omit<Attribute, 'name'> | undefined;
70
-
71
- attrs[attrName] = {
72
- description: '',
73
- ...current,
74
- ...attr,
75
- };
76
- }
77
-
78
- const attrList: Attribute[] = Object.keys(attrs).map<Attribute>(name => {
79
- const attr = attrs[name];
80
- return { name, type: 'Any', ...attr };
81
- });
82
-
83
- for (const attr of attrList) {
84
- if (!attr.type) {
85
- throw new Error(
86
- `The type is empty in the ${attr.name} attribute of the ${localName} element,
87
- 'packages',
88
- '@markuplint',
89
- 'html-spec',
90
- 'src',
91
- 'attributes',
92
- nameWithNS.replace(':', '_') + '.json',
93
- )})`,
94
- );
95
- }
96
- }
97
-
98
- attrList.sort(nameCompare);
99
-
100
- cacheMap.set(localNameWithNS, attrList);
101
- return attrList;
102
- }
103
-
104
- type HasName = { name: string };
105
-
106
- export function nameCompare(a: HasName | string, b: HasName | string) {
107
- const nameA = typeof a === 'string' ? a : a.name.toUpperCase();
108
- const nameB = typeof b === 'string' ? b : b.name.toUpperCase();
109
- if (nameA < nameB) {
110
- return -1;
111
- }
112
- if (nameA > nameB) {
113
- return 1;
114
- }
115
- return 0;
116
- }
@@ -1,81 +0,0 @@
1
- import type { ARIAVersion } from '../types';
2
-
3
- import specs from '@markuplint/html-spec';
4
- import { createSelector } from '@markuplint/selector';
5
- import { createJSDOMElement } from '@markuplint/test-tools';
6
-
7
- import { getImplicitRole } from './get-implicit-role';
8
-
9
- function c(html: string, version: ARIAVersion) {
10
- const el = createJSDOMElement(html);
11
- return getImplicitRole(
12
- specs,
13
- el.localName,
14
- el.namespaceURI,
15
- version,
16
- selector => !!createSelector(selector, specs).match(el),
17
- );
18
- }
19
-
20
- describe('getImplicitRole', () => {
21
- test('the a element', () => {
22
- expect(c('<a></a>', '1.2')).toBe(false);
23
- expect(c('<a name="foo"></a>', '1.2')).toBe(false);
24
- expect(c('<a href></a>', '1.2')).toBe('link');
25
- expect(c('<a href=""></a>', '1.2')).toBe('link');
26
- expect(c('<a href="path/to"></a>', '1.2')).toBe('link');
27
- });
28
-
29
- test('the area element', () => {
30
- expect(c('<area />', '1.2')).toBe(false);
31
- expect(c('<area shape="rect" />', '1.2')).toBe(false);
32
- expect(c('<area href />', '1.2')).toBe('link');
33
- expect(c('<area href="" />', '1.2')).toBe('link');
34
- expect(c('<area href="path/to" />', '1.2')).toBe('link');
35
- });
36
-
37
- test('the article element', () => {
38
- expect(c('<article></article>', '1.2')).toBe('article');
39
- });
40
-
41
- test('the aside element', () => {
42
- expect(c('<aside></aside>', '1.2')).toBe('complementary');
43
- });
44
-
45
- test('the audio element', () => {
46
- expect(c('<audio></audio>', '1.2')).toBe(false);
47
- });
48
-
49
- test('the h1 element', () => {
50
- expect(c('<h1></h1>', '1.2')).toBe('heading');
51
- });
52
-
53
- test('the header element', () => {
54
- expect(c('<header></header>', '1.2')).toBe('banner');
55
- expect(c('<header><article></article></header>', '1.2')).toBe('generic');
56
- expect(c('<header><article></article></header>', '1.1')).toBe(false);
57
- expect(c('<header><div></div></header>', '1.2')).toBe('banner');
58
- expect(c('<header><div role="article"></div></header>', '1.2')).toBe('generic');
59
- expect(c('<header><div role="article"></div></header>', '1.1')).toBe(false);
60
- });
61
-
62
- test('the img element', () => {
63
- expect(c('<img />', '1.2')).toBe('img');
64
- expect(c('<img alt />', '1.2')).toBe('presentation');
65
- expect(c('<img alt="" />', '1.2')).toBe('presentation');
66
- expect(c('<img alt="foo" />', '1.2')).toBe('img');
67
- expect(c('<img aria-label="foo" />', '1.2')).toBe('img');
68
- });
69
-
70
- test('the form element', () => {
71
- expect(c('<form></form>', '1.2')).toBe('form');
72
- expect(c('<form></form>', '1.1')).toBe(false);
73
- expect(c('<form aria-label="foo"></form>', '1.2')).toBe('form');
74
- expect(c('<form aria-label="foo"></form>', '1.1')).toBe('form');
75
- });
76
-
77
- test('the section element', () => {
78
- expect(c('<section></section>', '1.2')).toBe(false);
79
- expect(c('<section aria-label="foo"></section>', '1.2')).toBe('region');
80
- });
81
- });
@@ -1,17 +0,0 @@
1
- import type { ARIAVersion, Matches, MLMLSpec } from '../types';
2
-
3
- import { getARIA } from './get-aria';
4
-
5
- export function getImplicitRole(
6
- specs: Readonly<MLMLSpec>,
7
- localName: string,
8
- namespace: string | null,
9
- version: ARIAVersion,
10
- matches: Matches,
11
- ) {
12
- const aria = getARIA(specs, localName, namespace, version, matches);
13
- if (!aria) {
14
- return false;
15
- }
16
- return aria.implicitRole;
17
- }