@markuplint/ml-spec 3.0.0-alpha.82 → 3.0.0-dev.24

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 (91) 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-computed-role.js +13 -25
  5. package/lib/dom-traverse/get-content-model.d.ts +3 -0
  6. package/lib/dom-traverse/get-content-model.js +28 -0
  7. package/lib/dom-traverse/get-explicit-role.js +1 -1
  8. package/lib/dom-traverse/get-spec.d.ts +2 -2
  9. package/lib/dom-traverse/get-spec.js +2 -2
  10. package/lib/dom-traverse/has-required-owned-elements.js +12 -0
  11. package/lib/dom-traverse/is-exposed.d.ts +11 -0
  12. package/lib/dom-traverse/is-exposed.js +181 -0
  13. package/lib/dom-traverse/may-be-focusable.d.ts +2 -0
  14. package/lib/dom-traverse/may-be-focusable.js +22 -0
  15. package/lib/index.d.ts +8 -1
  16. package/lib/index.js +8 -1
  17. package/lib/specs/content-model-category-to-tag-names.d.ts +2 -2
  18. package/lib/specs/content-model-category-to-tag-names.js +2 -2
  19. package/lib/specs/get-aria.js +3 -3
  20. package/lib/specs/get-attr-specs.d.ts +1 -1
  21. package/lib/specs/get-selectors-by-content-model-category.d.ts +1 -1
  22. package/lib/specs/get-spec-by-tag-name.d.ts +2 -2
  23. package/lib/specs/get-spec-by-tag-name.js +1 -1
  24. package/lib/specs/is-nothing-content-model.d.ts +5 -0
  25. package/lib/specs/is-nothing-content-model.js +12 -0
  26. package/lib/specs/is-palpable-elements.d.ts +5 -0
  27. package/lib/specs/is-palpable-elements.js +47 -0
  28. package/lib/specs/is-void-element.d.ts +1 -0
  29. package/lib/specs/is-void-element.js +25 -0
  30. package/lib/specs/schema-to-spec.d.ts +1 -1
  31. package/lib/specs/schema-to-spec.js +1 -1
  32. package/lib/types/aria.d.ts +10 -4
  33. package/lib/types/attributes.d.ts +94 -39
  34. package/lib/types/index.d.ts +27 -27
  35. package/lib/types/permitted-structres.d.ts +22 -28
  36. package/lib/types/permitted-structures.d.ts +54 -0
  37. package/lib/types/permitted-structures.js +8 -0
  38. package/lib/utils/get-ns.d.ts +2 -1
  39. package/lib/utils/get-ns.js +3 -0
  40. package/lib/utils/merge-array.d.ts +1 -1
  41. package/lib/utils/resolve-namespace.d.ts +4 -4
  42. package/lib/utils/resolve-namespace.js +18 -13
  43. package/package.json +7 -7
  44. package/schema.json +6 -6
  45. package/schemas/aria.schema.json +1 -1
  46. package/schemas/content-models.schema.json +33 -49
  47. package/src/dom-traverse/accname-computation.spec.ts +6 -6
  48. package/src/dom-traverse/get-computed-aria-props.spec.ts +368 -0
  49. package/src/dom-traverse/get-computed-aria-props.ts +130 -0
  50. package/src/dom-traverse/get-computed-role.spec.ts +1 -1
  51. package/src/dom-traverse/get-computed-role.ts +13 -25
  52. package/src/dom-traverse/get-content-model.ts +32 -0
  53. package/src/dom-traverse/get-explicit-role.ts +1 -1
  54. package/src/dom-traverse/get-spec.ts +3 -3
  55. package/src/dom-traverse/has-required-owned-elements.ts +13 -0
  56. package/src/dom-traverse/is-exposed.spec.ts +50 -0
  57. package/src/dom-traverse/is-exposed.ts +196 -0
  58. package/src/dom-traverse/may-be-focusable.ts +21 -0
  59. package/src/index.ts +8 -1
  60. package/src/specs/content-model-category-to-tag-names.ts +3 -3
  61. package/src/specs/get-aria.ts +3 -3
  62. package/src/specs/get-selectors-by-content-model-category.ts +1 -1
  63. package/src/specs/get-spec-by-tag-name.spec.ts +10 -10
  64. package/src/specs/get-spec-by-tag-name.ts +9 -5
  65. package/src/specs/is-nothing-content-model.ts +9 -0
  66. package/src/specs/is-palpable-elements.ts +55 -0
  67. package/src/specs/is-void-element.ts +22 -0
  68. package/src/specs/schema-to-spec.ts +1 -1
  69. package/src/types/aria.ts +7 -1
  70. package/src/types/attributes.ts +227 -121
  71. package/src/types/index.ts +8 -8
  72. package/src/types/permitted-structres.ts +24 -32
  73. package/src/types/permitted-structures.ts +96 -0
  74. package/src/utils/get-ns.ts +6 -1
  75. package/src/utils/resolve-namespace.spec.ts +37 -0
  76. package/src/utils/resolve-namespace.ts +22 -18
  77. package/tsconfig.tsbuildinfo +1 -1
  78. package/lib/dom-traverse/focusability-computation.d.ts +0 -1
  79. package/lib/dom-traverse/focusability-computation.js +0 -8
  80. package/lib/dom-traverse/get-aria.d.ts +0 -9
  81. package/lib/dom-traverse/get-aria.js +0 -54
  82. package/lib/specs/aria-spec.d.ts +0 -5
  83. package/lib/specs/aria-spec.js +0 -12
  84. package/lib/specs/get-spec.d.ts +0 -13
  85. package/lib/specs/get-spec.js +0 -85
  86. package/lib/specs/html-spec.d.ts +0 -6
  87. package/lib/specs/html-spec.js +0 -16
  88. package/lib/specs/resolve-namespace.d.ts +0 -9
  89. package/lib/specs/resolve-namespace.js +0 -26
  90. package/lib/utils.d.ts +0 -8
  91. package/lib/utils.js +0 -50
@@ -1,10 +1,10 @@
1
1
  import type { ARIA } from './aria';
2
2
  import type { AttributeJSON, AttributeType, GlobalAttributes } from './attributes';
3
- import type { ContentModel, Category } from './permitted-structres';
3
+ import type { ContentModel, Category } from './permitted-structures';
4
4
  import type { NamespaceURI } from '@markuplint/ml-ast';
5
5
 
6
6
  /**
7
- * markuplit Markup-language spec
7
+ * markuplint Markup-language spec
8
8
  */
9
9
  export interface MLMLSpec {
10
10
  cites: Cites;
@@ -97,7 +97,7 @@ export type ElementSpec = {
97
97
  nonStandard?: true;
98
98
 
99
99
  /**
100
- * Element cateogries
100
+ * Element categories
101
101
  */
102
102
  categories: Category[];
103
103
 
@@ -107,9 +107,9 @@ export type ElementSpec = {
107
107
  contentModel: ContentModel;
108
108
 
109
109
  /**
110
- * Tag omittion
110
+ * Tag omission
111
111
  */
112
- omittion: ElementSpecOmittion;
112
+ omission: ElementSpecOmission;
113
113
 
114
114
  /**
115
115
  * Global Attributes
@@ -122,7 +122,7 @@ export type ElementSpec = {
122
122
  attributes: Record<string, Attribute>;
123
123
 
124
124
  /**
125
- * WAI-ARIA role and properies
125
+ * WAI-ARIA role and properties
126
126
  */
127
127
  aria: ARIA;
128
128
 
@@ -137,9 +137,9 @@ export type ElementSpec = {
137
137
  possibleToAddProperties?: true;
138
138
  };
139
139
 
140
- type ElementSpecOmittion = false | ElementSpecOmittionTags;
140
+ type ElementSpecOmission = false | ElementSpecOmissionTags;
141
141
 
142
- type ElementSpecOmittionTags = {
142
+ type ElementSpecOmissionTags = {
143
143
  startTag: boolean | ElementCondition;
144
144
  endTag: boolean | ElementCondition;
145
145
  };
@@ -5,14 +5,14 @@
5
5
  * and run json-schema-to-typescript to regenerate this file.
6
6
  */
7
7
 
8
- export type PermittedContent =
8
+ export type PermittedContentPattern =
9
9
  | PermittedContentRequire
10
10
  | PermittedContentOptional
11
11
  | PermittedContentOneOrMore
12
12
  | PermittedContentZeroOrMore
13
13
  | PermittedContentChoice
14
- | PermittedContentInterleave;
15
- export type Target = ContentType | ContentType[];
14
+ | PermittedContentTransparent;
15
+ export type Model = ContentType | ContentType[];
16
16
  export type ContentType = string | Category;
17
17
  export type Category =
18
18
  | '#text'
@@ -22,7 +22,6 @@ export type Category =
22
22
  | '#heading'
23
23
  | '#sectioning'
24
24
  | '#metadata'
25
- | '#transparent'
26
25
  | '#embedded'
27
26
  | '#palpable'
28
27
  | '#script-supporting'
@@ -44,65 +43,58 @@ export type Category =
44
43
  | '#SVGStructural'
45
44
  | '#SVGStructurallyExternal'
46
45
  | '#SVGTextContent'
47
- | '#SVGTextContentChild'
48
- | '#SVGOtherXMLNamespace';
49
- export type PermittedContentSpec = PermittedContent[];
46
+ | '#SVGTextContentChild';
50
47
 
51
48
  export interface ContentModelsSchema {
52
49
  __contentModel?: ContentModel;
53
50
  }
54
51
  export interface ContentModel {
55
- contents: PermittedContentSpec | boolean;
52
+ contents: PermittedContentPattern[] | boolean;
56
53
  descendantOf?: string;
57
54
  conditional?: {
58
55
  condition: string;
59
- contents: PermittedContentSpec | boolean;
56
+ contents: PermittedContentPattern[] | boolean;
60
57
  }[];
61
58
  }
62
59
  export interface PermittedContentRequire {
63
- require: Target;
64
- ignore?: Target;
65
- notAllowedDescendants?: ContentType[];
60
+ require: Model;
66
61
  max?: number;
67
62
  min?: number;
68
63
  _TODO_?: string;
69
64
  }
70
65
  export interface PermittedContentOptional {
71
- optional: Target;
72
- ignore?: Target;
73
- notAllowedDescendants?: ContentType[];
66
+ optional: Model;
74
67
  max?: number;
75
68
  _TODO_?: string;
76
69
  }
77
70
  export interface PermittedContentOneOrMore {
78
- oneOrMore: Target | PermittedContentSpec;
79
- ignore?: Target;
80
- notAllowedDescendants?: ContentType[];
71
+ oneOrMore: Model | PermittedContentPattern[];
81
72
  max?: number;
82
73
  _TODO_?: string;
83
74
  }
84
75
  export interface PermittedContentZeroOrMore {
85
- zeroOrMore: Target | PermittedContentSpec;
86
- ignore?: Target;
87
- notAllowedDescendants?: ContentType[];
76
+ zeroOrMore: Model | PermittedContentPattern[];
88
77
  max?: number;
89
78
  _TODO_?: string;
90
79
  }
91
80
  export interface PermittedContentChoice {
81
+ /**
82
+ * @minItems 2
83
+ * @maxItems 5
84
+ */
92
85
  choice:
93
- | [PermittedContentSpec, PermittedContentSpec]
94
- | [PermittedContentSpec, PermittedContentSpec, PermittedContentSpec]
95
- | [PermittedContentSpec, PermittedContentSpec, PermittedContentSpec, PermittedContentSpec]
86
+ | [PermittedContentPattern[], PermittedContentPattern[]]
87
+ | [PermittedContentPattern[], PermittedContentPattern[], PermittedContentPattern[]]
88
+ | [PermittedContentPattern[], PermittedContentPattern[], PermittedContentPattern[], PermittedContentPattern[]]
96
89
  | [
97
- PermittedContentSpec,
98
- PermittedContentSpec,
99
- PermittedContentSpec,
100
- PermittedContentSpec,
101
- PermittedContentSpec,
90
+ PermittedContentPattern[],
91
+ PermittedContentPattern[],
92
+ PermittedContentPattern[],
93
+ PermittedContentPattern[],
94
+ PermittedContentPattern[],
102
95
  ];
103
96
  _TODO_?: string;
104
97
  }
105
- export interface PermittedContentInterleave {
106
- interleave: [PermittedContentSpec, PermittedContentSpec, ...PermittedContentSpec[]];
107
- _TODO_?: string;
98
+ export interface PermittedContentTransparent {
99
+ transparent: string;
108
100
  }
@@ -0,0 +1,96 @@
1
+ /* tslint:disable */
2
+ /**
3
+ * This file was automatically generated by json-schema-to-typescript.
4
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5
+ * and run json-schema-to-typescript to regenerate this file.
6
+ */
7
+
8
+ export type PermittedContentPattern =
9
+ | PermittedContentRequire
10
+ | PermittedContentOptional
11
+ | PermittedContentOneOrMore
12
+ | PermittedContentZeroOrMore
13
+ | PermittedContentChoice
14
+ | PermittedContentTransparent;
15
+ export type Model = ContentType | ContentType[];
16
+ export type ContentType = string | Category;
17
+ export type Category =
18
+ | '#text'
19
+ | '#phrasing'
20
+ | '#flow'
21
+ | '#interactive'
22
+ | '#heading'
23
+ | '#sectioning'
24
+ | '#metadata'
25
+ | '#embedded'
26
+ | '#palpable'
27
+ | '#script-supporting'
28
+ | '#SVGAnimation'
29
+ | '#SVGBasicShapes'
30
+ | '#SVGContainer'
31
+ | '#SVGDescriptive'
32
+ | '#SVGFilterPrimitive'
33
+ | '#SVGFont'
34
+ | '#SVGGradient'
35
+ | '#SVGGraphics'
36
+ | '#SVGGraphicsReferencing'
37
+ | '#SVGLightSource'
38
+ | '#SVGNeverRendered'
39
+ | '#SVGNone'
40
+ | '#SVGPaintServer'
41
+ | '#SVGRenderable'
42
+ | '#SVGShape'
43
+ | '#SVGStructural'
44
+ | '#SVGStructurallyExternal'
45
+ | '#SVGTextContent'
46
+ | '#SVGTextContentChild';
47
+
48
+ export interface ContentModelsSchema {
49
+ __contentModel?: ContentModel;
50
+ }
51
+ export interface ContentModel {
52
+ contents: PermittedContentPattern[] | boolean;
53
+ descendantOf?: string;
54
+ conditional?: {
55
+ condition: string;
56
+ contents: PermittedContentPattern[] | boolean;
57
+ }[];
58
+ }
59
+ export interface PermittedContentRequire {
60
+ require: Model;
61
+ max?: number;
62
+ min?: number;
63
+ _TODO_?: string;
64
+ }
65
+ export interface PermittedContentOptional {
66
+ optional: Model;
67
+ max?: number;
68
+ _TODO_?: string;
69
+ }
70
+ export interface PermittedContentOneOrMore {
71
+ oneOrMore: Model | PermittedContentPattern[];
72
+ max?: number;
73
+ _TODO_?: string;
74
+ }
75
+ export interface PermittedContentZeroOrMore {
76
+ zeroOrMore: Model | PermittedContentPattern[];
77
+ max?: number;
78
+ _TODO_?: string;
79
+ }
80
+ export interface PermittedContentChoice {
81
+ choice:
82
+ | [PermittedContentPattern[], PermittedContentPattern[]]
83
+ | [PermittedContentPattern[], PermittedContentPattern[], PermittedContentPattern[]]
84
+ | [PermittedContentPattern[], PermittedContentPattern[], PermittedContentPattern[], PermittedContentPattern[]]
85
+ | [
86
+ PermittedContentPattern[],
87
+ PermittedContentPattern[],
88
+ PermittedContentPattern[],
89
+ PermittedContentPattern[],
90
+ PermittedContentPattern[],
91
+ ];
92
+ _TODO_?: string;
93
+ }
94
+ export interface PermittedContentTransparent {
95
+ transparent: string;
96
+ }
@@ -1,4 +1,6 @@
1
- export function getNS(namespaceURI: string | null) {
1
+ import type { Namespace } from '@markuplint/ml-ast';
2
+
3
+ export function getNS(namespaceURI: string | null): Namespace {
2
4
  switch (namespaceURI) {
3
5
  case 'http://www.w3.org/2000/svg': {
4
6
  return 'svg';
@@ -6,6 +8,9 @@ export function getNS(namespaceURI: string | null) {
6
8
  case 'http://www.w3.org/1998/Math/MathML': {
7
9
  return 'mml';
8
10
  }
11
+ case 'http://www.w3.org/1999/xlink': {
12
+ return 'xlink';
13
+ }
9
14
  default: {
10
15
  return 'html';
11
16
  }
@@ -0,0 +1,37 @@
1
+ import { resolveNamespace } from './resolve-namespace';
2
+
3
+ test('tag', () => {
4
+ expect(resolveNamespace('a')).toStrictEqual({
5
+ localName: 'a',
6
+ localNameWithNS: 'a',
7
+ namespace: 'html',
8
+ namespaceURI: 'http://www.w3.org/1999/xhtml',
9
+ });
10
+ expect(resolveNamespace('svg:a')).toStrictEqual({
11
+ localName: 'a',
12
+ localNameWithNS: 'svg:a',
13
+ namespace: 'svg',
14
+ namespaceURI: 'http://www.w3.org/2000/svg',
15
+ });
16
+ });
17
+
18
+ test('attr', () => {
19
+ expect(resolveNamespace('href', 'http://www.w3.org/1999/xhtml')).toStrictEqual({
20
+ localName: 'href',
21
+ localNameWithNS: 'href',
22
+ namespace: 'html',
23
+ namespaceURI: 'http://www.w3.org/1999/xhtml',
24
+ });
25
+ expect(resolveNamespace('href', 'http://www.w3.org/2000/svg')).toStrictEqual({
26
+ localName: 'href',
27
+ localNameWithNS: 'svg:href',
28
+ namespace: 'svg',
29
+ namespaceURI: 'http://www.w3.org/2000/svg',
30
+ });
31
+ expect(resolveNamespace('xlink:href', 'http://www.w3.org/2000/svg')).toStrictEqual({
32
+ localName: 'href',
33
+ localNameWithNS: 'xlink:href',
34
+ namespace: 'xlink',
35
+ namespaceURI: 'http://www.w3.org/1999/xlink',
36
+ });
37
+ });
@@ -1,4 +1,4 @@
1
- import type { NamespaceURI } from '@markuplint/ml-ast';
1
+ import type { NamespaceURI, Namespace } from '@markuplint/ml-ast';
2
2
 
3
3
  import { getNS } from './get-ns';
4
4
 
@@ -7,30 +7,34 @@ const cache = new Map<string, NamespacedElementName>();
7
7
  type NamespacedElementName = {
8
8
  localNameWithNS: string;
9
9
  localName: string;
10
- namespace: 'html' | 'svg' | 'mml';
10
+ namespace: Namespace;
11
11
  namespaceURI: NamespaceURI;
12
12
  };
13
13
 
14
- export function resolveNamespace(localName: string, namespaceURI: string | null = 'http://www.w3.org/1999/xhtml') {
15
- const cached = cache.get(localName + namespaceURI);
14
+ const namespaceURIMap: Record<Namespace, NamespaceURI> = {
15
+ html: 'http://www.w3.org/1999/xhtml',
16
+ svg: 'http://www.w3.org/2000/svg',
17
+ mml: 'http://www.w3.org/1998/Math/MathML',
18
+ xlink: 'http://www.w3.org/1999/xlink',
19
+ };
20
+
21
+ export function resolveNamespace(name: string, namespaceURI: string | null = 'http://www.w3.org/1999/xhtml') {
22
+ const cached = cache.get(name + namespaceURI);
16
23
  if (cached) {
17
24
  return cached;
18
25
  }
19
- const name = localName.split(':')[1] || localName;
20
- const ns = getNS(namespaceURI || null);
26
+ const [_explicitNS, _localName] = name.split(':');
27
+ const explicitNS = _localName ? _explicitNS : null;
28
+ const localName = _localName ?? _explicitNS;
29
+ const namespace =
30
+ (['html', 'svg', 'mml', 'xlink'] as const).find(_ns => _ns === (explicitNS || getNS(namespaceURI || null))) ||
31
+ 'html';
21
32
  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
+ localNameWithNS: `${namespace === 'html' ? '' : `${namespace}:`}${localName}`,
34
+ localName,
35
+ namespace,
36
+ namespaceURI: namespaceURIMap[namespace],
33
37
  };
34
- cache.set(localName + namespaceURI, result);
38
+ cache.set(name + namespaceURI, result);
35
39
  return result;
36
40
  }