@markuplint/ml-spec 3.0.0-dev.25 → 3.0.0-dev.290

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 (131) hide show
  1. package/lib/constant/aria-version.d.ts +2 -0
  2. package/lib/constant/aria-version.js +2 -0
  3. package/lib/dom-traverse/accname-computation.js +6 -7
  4. package/lib/dom-traverse/get-attr-specs.d.ts +2 -2
  5. package/lib/dom-traverse/get-attr-specs.js +5 -7
  6. package/lib/dom-traverse/get-computed-aria-props.d.ts +2 -2
  7. package/lib/dom-traverse/get-computed-aria-props.js +10 -13
  8. package/lib/dom-traverse/get-computed-role.d.ts +2 -2
  9. package/lib/dom-traverse/get-computed-role.js +104 -31
  10. package/lib/dom-traverse/get-content-model.d.ts +4 -3
  11. package/lib/dom-traverse/get-content-model.js +8 -11
  12. package/lib/dom-traverse/get-explicit-role.d.ts +1 -1
  13. package/lib/dom-traverse/get-explicit-role.js +14 -14
  14. package/lib/dom-traverse/get-implicit-role.d.ts +3 -3
  15. package/lib/dom-traverse/get-implicit-role.js +12 -13
  16. package/lib/dom-traverse/get-non-presentational-ancestor.d.ts +2 -2
  17. package/lib/dom-traverse/get-non-presentational-ancestor.js +13 -10
  18. package/lib/dom-traverse/get-permitted-roles.d.ts +4 -4
  19. package/lib/dom-traverse/get-permitted-roles.js +5 -7
  20. package/lib/dom-traverse/get-spec.d.ts +2 -2
  21. package/lib/dom-traverse/get-spec.js +5 -7
  22. package/lib/dom-traverse/has-required-owned-elements.d.ts +3 -3
  23. package/lib/dom-traverse/has-required-owned-elements.js +21 -22
  24. package/lib/dom-traverse/is-exposed.d.ts +2 -2
  25. package/lib/dom-traverse/is-exposed.js +47 -18
  26. package/lib/dom-traverse/matches-context-role.d.ts +2 -0
  27. package/lib/dom-traverse/matches-context-role.js +23 -0
  28. package/lib/dom-traverse/may-be-focusable.d.ts +2 -2
  29. package/lib/dom-traverse/may-be-focusable.js +5 -7
  30. package/lib/index.d.ts +28 -24
  31. package/lib/index.js +28 -27
  32. package/lib/specs/aria-specs.d.ts +5 -5
  33. package/lib/specs/aria-specs.js +1 -5
  34. package/lib/specs/content-model-category-to-tag-names.d.ts +2 -2
  35. package/lib/specs/content-model-category-to-tag-names.js +1 -5
  36. package/lib/specs/get-aria.d.ts +4 -3
  37. package/lib/specs/get-aria.js +18 -18
  38. package/lib/specs/get-attr-specs.d.ts +3 -3
  39. package/lib/specs/get-attr-specs.js +5 -22
  40. package/lib/specs/get-implicit-role.d.ts +2 -2
  41. package/lib/specs/get-implicit-role.js +3 -7
  42. package/lib/specs/get-permitted-roles.d.ts +4 -4
  43. package/lib/specs/get-permitted-roles.js +29 -28
  44. package/lib/specs/get-role-spec.d.ts +2 -2
  45. package/lib/specs/get-role-spec.js +10 -14
  46. package/lib/specs/get-selectors-by-content-model-category.d.ts +3 -3
  47. package/lib/specs/get-selectors-by-content-model-category.js +2 -6
  48. package/lib/specs/get-spec-by-tag-name.d.ts +2 -2
  49. package/lib/specs/get-spec-by-tag-name.js +4 -8
  50. package/lib/specs/is-nothing-content-model.js +5 -7
  51. package/lib/specs/is-palpable-elements.d.ts +4 -4
  52. package/lib/specs/is-palpable-elements.js +7 -10
  53. package/lib/specs/is-presentational.js +1 -5
  54. package/lib/specs/is-void-element.js +3 -5
  55. package/lib/specs/resolve-version.d.ts +4 -3
  56. package/lib/specs/resolve-version.js +7 -12
  57. package/lib/specs/schema-to-spec.d.ts +4 -4
  58. package/lib/specs/schema-to-spec.js +30 -24
  59. package/lib/types/aria.d.ts +25 -4
  60. package/lib/types/aria.js +1 -3
  61. package/lib/types/attributes.d.ts +3 -4
  62. package/lib/types/attributes.js +1 -3
  63. package/lib/types/index.d.ts +93 -92
  64. package/lib/types/index.js +1 -2
  65. package/lib/types/permitted-structures.d.ts +6 -2
  66. package/lib/types/permitted-structures.js +1 -3
  67. package/lib/utils/get-ns.js +1 -5
  68. package/lib/utils/merge-array.d.ts +2 -2
  69. package/lib/utils/merge-array.js +1 -5
  70. package/lib/utils/resolve-namespace.js +4 -8
  71. package/lib/utils/validateAriaVersion.d.ts +2 -0
  72. package/lib/utils/validateAriaVersion.js +4 -0
  73. package/package.json +20 -10
  74. package/lib/types/permitted-structres.d.ts +0 -58
  75. package/lib/types/permitted-structres.js +0 -8
  76. package/schemas/aria.schema.json +0 -258
  77. package/schemas/attributes.schema.json +0 -204
  78. package/schemas/content-models.schema.json +0 -199
  79. package/schemas/element.schema.json +0 -11
  80. package/schemas/global-attributes.schema.json +0 -761
  81. package/src/dom-traverse/accname-computation.spec.ts +0 -69
  82. package/src/dom-traverse/accname-computation.ts +0 -5
  83. package/src/dom-traverse/get-attr-specs.ts +0 -8
  84. package/src/dom-traverse/get-computed-aria-props.spec.ts +0 -368
  85. package/src/dom-traverse/get-computed-aria-props.ts +0 -130
  86. package/src/dom-traverse/get-computed-role.spec.ts +0 -134
  87. package/src/dom-traverse/get-computed-role.ts +0 -181
  88. package/src/dom-traverse/get-content-model.ts +0 -32
  89. package/src/dom-traverse/get-explicit-role.ts +0 -112
  90. package/src/dom-traverse/get-implicit-role.ts +0 -36
  91. package/src/dom-traverse/get-non-presentational-ancestor.ts +0 -20
  92. package/src/dom-traverse/get-permitted-roles.ts +0 -7
  93. package/src/dom-traverse/get-spec.ts +0 -7
  94. package/src/dom-traverse/has-required-owned-elements.spec.ts +0 -36
  95. package/src/dom-traverse/has-required-owned-elements.ts +0 -85
  96. package/src/dom-traverse/is-exposed.spec.ts +0 -50
  97. package/src/dom-traverse/is-exposed.ts +0 -196
  98. package/src/dom-traverse/may-be-focusable.ts +0 -21
  99. package/src/index.ts +0 -24
  100. package/src/specs/aria-specs.ts +0 -6
  101. package/src/specs/content-model-category-to-tag-names.ts +0 -15
  102. package/src/specs/get-aria.ts +0 -85
  103. package/src/specs/get-attr-specs.spec.ts +0 -47
  104. package/src/specs/get-attr-specs.ts +0 -116
  105. package/src/specs/get-implicit-role.spec.ts +0 -81
  106. package/src/specs/get-implicit-role.ts +0 -17
  107. package/src/specs/get-permitted-roles.spec.ts +0 -420
  108. package/src/specs/get-permitted-roles.ts +0 -87
  109. package/src/specs/get-role-spec.spec.ts +0 -67
  110. package/src/specs/get-role-spec.ts +0 -72
  111. package/src/specs/get-selectors-by-content-model-category.ts +0 -10
  112. package/src/specs/get-spec-by-tag-name.spec.ts +0 -68
  113. package/src/specs/get-spec-by-tag-name.ts +0 -20
  114. package/src/specs/is-nothing-content-model.ts +0 -9
  115. package/src/specs/is-palpable-elements.ts +0 -55
  116. package/src/specs/is-presentational.ts +0 -6
  117. package/src/specs/is-void-element.ts +0 -22
  118. package/src/specs/resolve-version.ts +0 -20
  119. package/src/specs/schema-to-spec.spec.ts +0 -39
  120. package/src/specs/schema-to-spec.ts +0 -103
  121. package/src/types/aria.ts +0 -153
  122. package/src/types/attributes.ts +0 -1524
  123. package/src/types/index.ts +0 -255
  124. package/src/types/permitted-structres.ts +0 -100
  125. package/src/types/permitted-structures.ts +0 -96
  126. package/src/utils/get-ns.ts +0 -18
  127. package/src/utils/merge-array.ts +0 -35
  128. package/src/utils/resolve-namespace.spec.ts +0 -37
  129. package/src/utils/resolve-namespace.ts +0 -40
  130. package/tsconfig.test.json +0 -3
  131. package/tsconfig.tsbuildinfo +0 -1
@@ -1,255 +0,0 @@
1
- import type { ARIA } from './aria';
2
- import type { AttributeJSON, AttributeType, GlobalAttributes } from './attributes';
3
- import type { ContentModel, Category } from './permitted-structures';
4
- import type { NamespaceURI } from '@markuplint/ml-ast';
5
-
6
- /**
7
- * markuplint Markup-language spec
8
- */
9
- export interface MLMLSpec {
10
- cites: Cites;
11
- def: SpecDefs;
12
- specs: ElementSpec[];
13
- }
14
-
15
- export type ExtendedElementSpec = Partial<Omit<ElementSpec, 'name' | 'attributes'>> & {
16
- name: ElementSpec['name'];
17
- attributes?: Record<string, Partial<Attribute>>;
18
- };
19
-
20
- export type ExtendedSpec = {
21
- cites?: Cites;
22
- def?: Partial<SpecDefs>;
23
- specs?: ExtendedElementSpec[];
24
- };
25
-
26
- /**
27
- * Reference URLs
28
- */
29
- export type Cites = string[];
30
-
31
- export type SpecDefs = {
32
- '#globalAttrs': Partial<{
33
- '#extends': Record<string, Partial<Attribute>>;
34
- '#HTMLGlobalAttrs': Record<string, Partial<Attribute>>;
35
- [OtherGlobalAttrs: string]: Record<string, Partial<Attribute>>;
36
- }>;
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[];
48
- };
49
-
50
- /**
51
- * Element spec
52
- */
53
- export type ElementSpec = {
54
- /**
55
- * Tag name
56
- */
57
- name: string;
58
-
59
- /**
60
- * Namespaces in XML
61
- * @see https://www.w3.org/TR/xml-names/
62
- */
63
- namespace?: NamespaceURI;
64
-
65
- /**
66
- * Reference URL
67
- */
68
- cite: string;
69
-
70
- /**
71
- * Description
72
- */
73
- description?: string;
74
-
75
- /**
76
- * Experimental technology
77
- */
78
- experimental?: true;
79
-
80
- /**
81
- * Obsolete or alternative elements
82
- */
83
- obsolete?:
84
- | true
85
- | {
86
- alt: string;
87
- };
88
-
89
- /**
90
- * Deprecated
91
- */
92
- deprecated?: true;
93
-
94
- /**
95
- * Non-standard
96
- */
97
- nonStandard?: true;
98
-
99
- /**
100
- * Element categories
101
- */
102
- categories: Category[];
103
-
104
- /**
105
- * Permitted contents and permitted parents
106
- */
107
- contentModel: ContentModel;
108
-
109
- /**
110
- * Tag omission
111
- */
112
- omission: ElementSpecOmission;
113
-
114
- /**
115
- * Global Attributes
116
- */
117
- globalAttrs: GlobalAttributes;
118
-
119
- /**
120
- * Attributes
121
- */
122
- attributes: Record<string, Attribute>;
123
-
124
- /**
125
- * WAI-ARIA role and properties
126
- */
127
- aria: ARIA;
128
-
129
- /**
130
- * If true, it is possible to add any properties as attributes,
131
- * for example, when using a template engine or a view language.
132
- *
133
- * @see https://v2.vuejs.org/v2/guide/components-slots.html#Scoped-Slots
134
- *
135
- * **It assumes to specify it on the parser plugin.**
136
- */
137
- possibleToAddProperties?: true;
138
- };
139
-
140
- type ElementSpecOmission = false | ElementSpecOmissionTags;
141
-
142
- type ElementSpecOmissionTags = {
143
- startTag: boolean | ElementCondition;
144
- endTag: boolean | ElementCondition;
145
- };
146
-
147
- type ElementCondition = {
148
- __WIP__: 'WORK_IN_PROGRESS';
149
- };
150
-
151
- export type Attribute = {
152
- name: string;
153
- type: AttributeType | AttributeType[];
154
- description?: string;
155
- caseSensitive?: true;
156
- experimental?: boolean;
157
- obsolete?: true;
158
- deprecated?: boolean;
159
- nonStandard?: true;
160
- } & ExtendableAttributeSpec;
161
-
162
- type ExtendableAttributeSpec = Omit<AttributeJSON, 'type'>;
163
-
164
- export type ARIARole = {
165
- name: string;
166
- isAbstract: boolean;
167
- requiredContextRole: string[];
168
- requiredOwnedElements: string[];
169
- accessibleNameRequired: boolean;
170
- accessibleNameFromAuthor: boolean;
171
- accessibleNameFromContent: boolean;
172
- accessibleNameProhibited: boolean;
173
- childrenPresentational: boolean;
174
- ownedProperties: ARIARoleOwnedProperties[];
175
- prohibitedProperties: string[];
176
- };
177
-
178
- export type ARIARoleInSchema = Partial<
179
- ARIARole & {
180
- description: string;
181
- generalization: string[];
182
- }
183
- > & {
184
- name: string;
185
- };
186
-
187
- export type ARIARoleOwnedProperties = {
188
- name: string;
189
- inherited?: true;
190
- required?: true;
191
- deprecated?: true;
192
- };
193
-
194
- export type ARIAProperty = {
195
- name: string;
196
- type: 'property' | 'state';
197
- deprecated?: true;
198
- isGlobal?: true;
199
- value: ARIAAttributeValue;
200
- conditionalValue?: {
201
- role: string[];
202
- value: ARIAAttributeValue;
203
- }[];
204
- enum: string[];
205
- defaultValue?: string;
206
- equivalentHtmlAttrs?: EquivalentHtmlAttr[];
207
- valueDescriptions?: Record<string, string>;
208
- };
209
-
210
- export type ARIAAttributeValue =
211
- | 'true/false'
212
- | 'tristate'
213
- | 'true/false/undefined'
214
- | 'ID reference'
215
- | 'ID reference list'
216
- | 'integer'
217
- | 'number'
218
- | 'string'
219
- | 'token'
220
- | 'token list'
221
- | 'URI';
222
-
223
- export type ARIAVersion = '1.1' | '1.2';
224
-
225
- export type EquivalentHtmlAttr = {
226
- htmlAttrName: string;
227
- isNotStrictEquivalent?: true;
228
- value: string | null;
229
- };
230
-
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
- };
243
-
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';
@@ -1,100 +0,0 @@
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
- /**
82
- * @minItems 2
83
- * @maxItems 5
84
- */
85
- choice:
86
- | [PermittedContentPattern[], PermittedContentPattern[]]
87
- | [PermittedContentPattern[], PermittedContentPattern[], PermittedContentPattern[]]
88
- | [PermittedContentPattern[], PermittedContentPattern[], PermittedContentPattern[], PermittedContentPattern[]]
89
- | [
90
- PermittedContentPattern[],
91
- PermittedContentPattern[],
92
- PermittedContentPattern[],
93
- PermittedContentPattern[],
94
- PermittedContentPattern[],
95
- ];
96
- _TODO_?: string;
97
- }
98
- export interface PermittedContentTransparent {
99
- transparent: string;
100
- }
@@ -1,96 +0,0 @@
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,18 +0,0 @@
1
- import type { Namespace } from '@markuplint/ml-ast';
2
-
3
- export function getNS(namespaceURI: string | null): Namespace {
4
- switch (namespaceURI) {
5
- case 'http://www.w3.org/2000/svg': {
6
- return 'svg';
7
- }
8
- case 'http://www.w3.org/1998/Math/MathML': {
9
- return 'mml';
10
- }
11
- case 'http://www.w3.org/1999/xlink': {
12
- return 'xlink';
13
- }
14
- default: {
15
- return 'html';
16
- }
17
- }
18
- }
@@ -1,35 +0,0 @@
1
- type NamedDefinition = string | { name: string };
2
-
3
- export function mergeArray<T extends NamedDefinition>(a: T[], b: T[] | null | undefined): T[] {
4
- if (!b) {
5
- return a;
6
- }
7
- const result: T[] = a.slice();
8
- for (const bItem of b) {
9
- const bName = getName(bItem);
10
- const aIndex = result.findIndex(item => getName(item) === bName);
11
- if (aIndex === -1) {
12
- result.push(bItem);
13
- continue;
14
- }
15
- const aItem = result.splice(aIndex, 1)[0];
16
- if (typeof bItem === 'string') {
17
- continue;
18
- }
19
- if (typeof aItem === 'string') {
20
- result.push(bItem);
21
- continue;
22
- }
23
- const exItem = {
24
- ...(aItem as { name: string }),
25
- ...(bItem as { name: string }),
26
- };
27
- result.push(exItem as T);
28
- }
29
- return result;
30
- }
31
-
32
- function getName(def: NamedDefinition): string {
33
- const result = typeof def === 'string' ? def : def.name;
34
- return result.toLowerCase().trim();
35
- }
@@ -1,37 +0,0 @@
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,40 +0,0 @@
1
- import type { NamespaceURI, Namespace } 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: Namespace;
11
- namespaceURI: NamespaceURI;
12
- };
13
-
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);
23
- if (cached) {
24
- return cached;
25
- }
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';
32
- const result: NamespacedElementName = {
33
- localNameWithNS: `${namespace === 'html' ? '' : `${namespace}:`}${localName}`,
34
- localName,
35
- namespace,
36
- namespaceURI: namespaceURIMap[namespace],
37
- };
38
- cache.set(name + namespaceURI, result);
39
- return result;
40
- }
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.json"
3
- }