@markuplint/ml-spec 3.0.0-canary.5 → 3.0.0-dev.176

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 (128) hide show
  1. package/README.md +1 -1
  2. package/lib/constant/aria-version.d.ts +2 -0
  3. package/lib/constant/aria-version.js +5 -0
  4. package/lib/dom-traverse/accname-computation.js +3 -1
  5. package/lib/dom-traverse/get-attr-specs.d.ts +1 -1
  6. package/lib/dom-traverse/get-attr-specs.js +3 -1
  7. package/lib/dom-traverse/get-computed-aria-props.d.ts +6 -6
  8. package/lib/dom-traverse/get-computed-aria-props.js +4 -2
  9. package/lib/dom-traverse/get-computed-role.d.ts +6 -1
  10. package/lib/dom-traverse/get-computed-role.js +41 -10
  11. package/lib/dom-traverse/get-content-model.d.ts +28 -2
  12. package/lib/dom-traverse/get-content-model.js +4 -2
  13. package/lib/dom-traverse/get-explicit-role.js +9 -4
  14. package/lib/dom-traverse/get-implicit-role.d.ts +6 -2
  15. package/lib/dom-traverse/get-implicit-role.js +6 -2
  16. package/lib/dom-traverse/get-non-presentational-ancestor.d.ts +10 -4
  17. package/lib/dom-traverse/get-non-presentational-ancestor.js +10 -2
  18. package/lib/dom-traverse/get-permitted-roles.d.ts +7 -3
  19. package/lib/dom-traverse/get-permitted-roles.js +3 -1
  20. package/lib/dom-traverse/get-spec.d.ts +4 -1
  21. package/lib/dom-traverse/get-spec.js +3 -1
  22. package/lib/dom-traverse/has-required-owned-elements.d.ts +8 -2
  23. package/lib/dom-traverse/has-required-owned-elements.js +14 -8
  24. package/lib/dom-traverse/is-exposed.d.ts +1 -1
  25. package/lib/dom-traverse/is-exposed.js +43 -7
  26. package/lib/dom-traverse/matches-context-role.d.ts +7 -0
  27. package/lib/dom-traverse/matches-context-role.js +27 -0
  28. package/lib/dom-traverse/may-be-focusable.d.ts +1 -1
  29. package/lib/dom-traverse/may-be-focusable.js +3 -1
  30. package/lib/index.d.ts +4 -0
  31. package/lib/index.js +4 -0
  32. package/lib/specs/aria-specs.d.ts +7 -4
  33. package/lib/specs/content-model-category-to-tag-names.d.ts +4 -1
  34. package/lib/specs/get-aria.d.ts +8 -1
  35. package/lib/specs/get-aria.js +8 -2
  36. package/lib/specs/get-attr-specs.d.ts +6 -2
  37. package/lib/specs/get-attr-specs.js +2 -14
  38. package/lib/specs/get-implicit-role.d.ts +7 -1
  39. package/lib/specs/get-permitted-roles.d.ts +9 -3
  40. package/lib/specs/get-permitted-roles.js +19 -15
  41. package/lib/specs/get-role-spec.d.ts +10 -3
  42. package/lib/specs/get-role-spec.js +2 -2
  43. package/lib/specs/get-selectors-by-content-model-category.d.ts +1 -1
  44. package/lib/specs/get-selectors-by-content-model-category.js +1 -1
  45. package/lib/specs/get-spec-by-tag-name.d.ts +5 -1
  46. package/lib/specs/get-spec-by-tag-name.js +3 -2
  47. package/lib/specs/is-nothing-content-model.d.ts +5 -0
  48. package/lib/specs/is-nothing-content-model.js +14 -0
  49. package/lib/specs/is-palpable-elements.d.ts +8 -4
  50. package/lib/specs/is-palpable-elements.js +6 -4
  51. package/lib/specs/is-void-element.js +3 -1
  52. package/lib/specs/resolve-version.d.ts +5 -1
  53. package/lib/specs/resolve-version.js +1 -1
  54. package/lib/specs/schema-to-spec.d.ts +4 -4
  55. package/lib/specs/schema-to-spec.js +29 -18
  56. package/lib/types/aria.d.ts +149 -114
  57. package/lib/types/attributes.d.ts +1490 -111
  58. package/lib/types/index.d.ts +178 -149
  59. package/lib/types/permitted-structures.d.ts +74 -31
  60. package/lib/utils/merge-array.d.ts +9 -4
  61. package/lib/utils/resolve-namespace.d.ts +4 -4
  62. package/lib/utils/resolve-namespace.js +3 -2
  63. package/lib/utils/validateAriaVersion.d.ts +2 -0
  64. package/lib/utils/validateAriaVersion.js +8 -0
  65. package/package.json +13 -8
  66. package/{src/dom-traverse/accname-computation.spec.ts → test/dom-traverse/accname-computation.spec.js} +4 -4
  67. package/test/dom-traverse/get-computed-aria-props.spec.js +758 -0
  68. package/test/dom-traverse/get-computed-role.spec.js +294 -0
  69. package/test/dom-traverse/get-implicit-role.spec.js +40 -0
  70. package/{src/dom-traverse/has-required-owned-elements.spec.ts → test/dom-traverse/has-required-owned-elements.spec.js} +7 -9
  71. package/{src/dom-traverse/is-exposed.spec.ts → test/dom-traverse/is-exposed.spec.js} +29 -9
  72. package/test/dom-traverse/matches-context-role.spec.js +60 -0
  73. package/{src/specs/get-attr-specs.spec.ts → test/specs/get-attr-specs.spec.js} +2 -8
  74. package/{src/specs/get-implicit-role.spec.ts → test/specs/get-implicit-role.spec.js} +9 -11
  75. package/{src/specs/get-permitted-roles.spec.ts → test/specs/get-permitted-roles.spec.js} +8 -10
  76. package/{src/specs/get-role-spec.spec.ts → test/specs/get-role-spec.spec.js} +4 -4
  77. package/{src/specs/get-spec-by-tag-name.spec.ts → test/specs/get-spec-by-tag-name.spec.js} +2 -2
  78. package/test/specs/resolve-version.spec.js +34 -0
  79. package/test/specs/schema-to-spec.spec.js +61 -0
  80. package/{src/utils/resolve-namespace.spec.ts → test/utils/resolve-namespace.spec.js} +1 -1
  81. package/lib/types/permitted-structres.d.ts +0 -58
  82. package/lib/types/permitted-structres.js +0 -8
  83. package/schemas/aria.schema.json +0 -258
  84. package/schemas/attributes.schema.json +0 -204
  85. package/schemas/content-models.schema.json +0 -199
  86. package/schemas/element.schema.json +0 -11
  87. package/schemas/global-attributes.schema.json +0 -761
  88. package/src/dom-traverse/accname-computation.ts +0 -5
  89. package/src/dom-traverse/get-attr-specs.ts +0 -8
  90. package/src/dom-traverse/get-computed-aria-props.spec.ts +0 -368
  91. package/src/dom-traverse/get-computed-aria-props.ts +0 -130
  92. package/src/dom-traverse/get-computed-role.spec.ts +0 -134
  93. package/src/dom-traverse/get-computed-role.ts +0 -181
  94. package/src/dom-traverse/get-content-model.ts +0 -32
  95. package/src/dom-traverse/get-explicit-role.ts +0 -112
  96. package/src/dom-traverse/get-implicit-role.ts +0 -36
  97. package/src/dom-traverse/get-non-presentational-ancestor.ts +0 -20
  98. package/src/dom-traverse/get-permitted-roles.ts +0 -7
  99. package/src/dom-traverse/get-spec.ts +0 -7
  100. package/src/dom-traverse/has-required-owned-elements.ts +0 -85
  101. package/src/dom-traverse/is-exposed.ts +0 -196
  102. package/src/dom-traverse/may-be-focusable.ts +0 -21
  103. package/src/index.ts +0 -23
  104. package/src/specs/aria-specs.ts +0 -6
  105. package/src/specs/content-model-category-to-tag-names.ts +0 -15
  106. package/src/specs/get-aria.ts +0 -85
  107. package/src/specs/get-attr-specs.ts +0 -116
  108. package/src/specs/get-implicit-role.ts +0 -17
  109. package/src/specs/get-permitted-roles.ts +0 -87
  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.ts +0 -20
  113. package/src/specs/is-palpable-elements.ts +0 -55
  114. package/src/specs/is-presentational.ts +0 -6
  115. package/src/specs/is-void-element.ts +0 -22
  116. package/src/specs/resolve-version.ts +0 -20
  117. package/src/specs/schema-to-spec.spec.ts +0 -39
  118. package/src/specs/schema-to-spec.ts +0 -103
  119. package/src/types/aria.ts +0 -153
  120. package/src/types/attributes.ts +0 -1473
  121. package/src/types/index.ts +0 -255
  122. package/src/types/permitted-structres.ts +0 -100
  123. package/src/types/permitted-structures.ts +0 -96
  124. package/src/utils/get-ns.ts +0 -18
  125. package/src/utils/merge-array.ts +0 -35
  126. package/src/utils/resolve-namespace.ts +0 -40
  127. package/tsconfig.test.json +0 -3
  128. 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,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
- }