@markuplint/ml-spec 2.1.0 → 3.0.0-alpha.0

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/lib/dom-traverse/accname-computation.d.ts +1 -0
  2. package/lib/dom-traverse/accname-computation.js +8 -0
  3. package/lib/dom-traverse/focusability-computation.d.ts +1 -0
  4. package/lib/dom-traverse/focusability-computation.js +8 -0
  5. package/lib/dom-traverse/get-aria.d.ts +9 -0
  6. package/lib/dom-traverse/get-aria.js +54 -0
  7. package/lib/dom-traverse/get-attr-specs.d.ts +2 -0
  8. package/lib/dom-traverse/get-attr-specs.js +8 -0
  9. package/lib/dom-traverse/get-computed-role.d.ts +2 -0
  10. package/lib/dom-traverse/get-computed-role.js +170 -0
  11. package/lib/dom-traverse/get-explicit-role.d.ts +2 -0
  12. package/lib/dom-traverse/get-explicit-role.js +102 -0
  13. package/lib/dom-traverse/get-implicit-role.d.ts +3 -0
  14. package/lib/dom-traverse/get-implicit-role.js +37 -0
  15. package/lib/dom-traverse/get-non-presentational-ancestor.d.ts +5 -0
  16. package/lib/dom-traverse/get-non-presentational-ancestor.js +21 -0
  17. package/lib/dom-traverse/get-permitted-roles.d.ts +5 -0
  18. package/lib/dom-traverse/get-permitted-roles.js +8 -0
  19. package/lib/dom-traverse/get-spec.d.ts +2 -0
  20. package/lib/dom-traverse/get-spec.js +8 -0
  21. package/lib/dom-traverse/has-required-owned-elements.d.ts +3 -0
  22. package/lib/dom-traverse/has-required-owned-elements.js +81 -0
  23. package/lib/dom-traverse/may-be-focusable.d.ts +2 -0
  24. package/lib/dom-traverse/may-be-focusable.js +22 -0
  25. package/lib/index.d.ts +17 -6
  26. package/lib/index.js +17 -6
  27. package/lib/specs/aria-spec.d.ts +5 -0
  28. package/lib/specs/aria-spec.js +12 -0
  29. package/lib/specs/aria-specs.d.ts +6 -0
  30. package/lib/specs/aria-specs.js +8 -0
  31. package/lib/specs/content-model-category-to-tag-names.d.ts +3 -0
  32. package/lib/specs/content-model-category-to-tag-names.js +15 -0
  33. package/lib/specs/get-aria.d.ts +3 -0
  34. package/lib/specs/get-aria.js +71 -0
  35. package/lib/specs/get-attr-specs.d.ts +8 -0
  36. package/lib/{get-attr-specs.js → specs/get-attr-specs.js} +8 -6
  37. package/lib/specs/get-implicit-role.d.ts +2 -0
  38. package/lib/specs/get-implicit-role.js +12 -0
  39. package/lib/specs/get-permitted-roles.d.ts +12 -0
  40. package/lib/specs/get-permitted-roles.js +61 -0
  41. package/lib/specs/get-role-spec.d.ts +5 -0
  42. package/lib/specs/get-role-spec.js +52 -0
  43. package/lib/specs/get-selectors-by-content-model-category.d.ts +3 -0
  44. package/lib/specs/get-selectors-by-content-model-category.js +8 -0
  45. package/lib/specs/get-spec-by-tag-name.d.ts +2 -0
  46. package/lib/specs/get-spec-by-tag-name.js +16 -0
  47. package/lib/{get-spec.d.ts → specs/get-spec.d.ts} +4 -4
  48. package/lib/{get-spec.js → specs/get-spec.js} +1 -1
  49. package/lib/specs/html-spec.d.ts +6 -0
  50. package/lib/specs/html-spec.js +16 -0
  51. package/lib/specs/is-presentational.d.ts +1 -0
  52. package/lib/specs/is-presentational.js +10 -0
  53. package/lib/specs/resolve-namespace.d.ts +9 -0
  54. package/lib/specs/resolve-namespace.js +26 -0
  55. package/lib/specs/resolve-version.d.ts +3 -0
  56. package/lib/specs/resolve-version.js +21 -0
  57. package/lib/specs/schema-to-spec.d.ts +13 -0
  58. package/lib/specs/schema-to-spec.js +93 -0
  59. package/lib/types/aria.d.ts +130 -0
  60. package/lib/{attributes.js → types/aria.js} +0 -0
  61. package/lib/{attributes.d.ts → types/attributes.d.ts} +2 -10
  62. package/lib/{permitted-structres.js → types/attributes.js} +0 -0
  63. package/lib/{types.d.ts → types/index.d.ts} +49 -64
  64. package/lib/{types.js → types/index.js} +0 -0
  65. package/lib/{permitted-structres.d.ts → types/permitted-structres.d.ts} +14 -23
  66. package/lib/types/permitted-structres.js +8 -0
  67. package/lib/utils/cache.d.ts +10 -0
  68. package/lib/utils/cache.js +42 -0
  69. package/lib/utils/get-ns.d.ts +2 -0
  70. package/lib/{get-ns.js → utils/get-ns.js} +3 -0
  71. package/lib/utils/merge-array.d.ts +5 -0
  72. package/lib/utils/merge-array.js +36 -0
  73. package/lib/utils/resolve-namespace.d.ts +9 -0
  74. package/lib/utils/resolve-namespace.js +31 -0
  75. package/lib/utils.d.ts +6 -3
  76. package/lib/utils.js +15 -1
  77. package/package.json +10 -6
  78. package/schemas/aria.schema.json +258 -0
  79. package/schemas/attributes.schema.json +3 -22
  80. package/schemas/{permitted-structures.schema.json → content-models.schema.json} +52 -81
  81. package/schemas/element.schema.json +11 -0
  82. package/src/dom-traverse/accname-computation.spec.ts +69 -0
  83. package/src/dom-traverse/accname-computation.ts +5 -0
  84. package/src/dom-traverse/get-attr-specs.ts +8 -0
  85. package/src/dom-traverse/get-computed-role.spec.ts +134 -0
  86. package/src/dom-traverse/get-computed-role.ts +181 -0
  87. package/src/dom-traverse/get-explicit-role.ts +112 -0
  88. package/src/dom-traverse/get-implicit-role.ts +36 -0
  89. package/src/dom-traverse/get-non-presentational-ancestor.ts +20 -0
  90. package/src/dom-traverse/get-permitted-roles.ts +7 -0
  91. package/src/dom-traverse/get-spec.ts +7 -0
  92. package/src/dom-traverse/has-required-owned-elements.spec.ts +36 -0
  93. package/src/dom-traverse/has-required-owned-elements.ts +85 -0
  94. package/src/dom-traverse/may-be-focusable.ts +21 -0
  95. package/src/index.ts +17 -6
  96. package/src/specs/aria-specs.ts +6 -0
  97. package/src/specs/content-model-category-to-tag-names.ts +15 -0
  98. package/src/specs/get-aria.ts +85 -0
  99. package/src/{get-attr-specs.spec.ts → specs/get-attr-specs.spec.ts} +4 -7
  100. package/src/{get-attr-specs.ts → specs/get-attr-specs.ts} +12 -7
  101. package/src/specs/get-implicit-role.spec.ts +81 -0
  102. package/src/specs/get-implicit-role.ts +17 -0
  103. package/src/specs/get-permitted-roles.spec.ts +420 -0
  104. package/src/specs/get-permitted-roles.ts +87 -0
  105. package/src/specs/get-role-spec.spec.ts +67 -0
  106. package/src/specs/get-role-spec.ts +72 -0
  107. package/src/specs/get-selectors-by-content-model-category.ts +10 -0
  108. package/src/specs/get-spec-by-tag-name.spec.ts +68 -0
  109. package/src/specs/get-spec-by-tag-name.ts +16 -0
  110. package/src/specs/is-presentational.ts +6 -0
  111. package/src/specs/resolve-version.ts +20 -0
  112. package/src/{get-spec.spec.ts → specs/schema-to-spec.spec.ts} +2 -2
  113. package/src/{get-spec.ts → specs/schema-to-spec.ts} +22 -8
  114. package/src/types/aria.ts +147 -0
  115. package/src/{attributes.ts → types/attributes.ts} +2 -12
  116. package/src/{types.ts → types/index.ts} +69 -68
  117. package/src/{permitted-structres.ts → types/permitted-structres.ts} +15 -25
  118. package/src/{get-ns.ts → utils/get-ns.ts} +6 -1
  119. package/src/{utils.ts → utils/merge-array.ts} +0 -0
  120. package/src/utils/resolve-namespace.spec.ts +37 -0
  121. package/src/utils/resolve-namespace.ts +40 -0
  122. package/tsconfig.tsbuildinfo +1 -1
  123. package/lib/get-attr-specs.d.ts +0 -7
  124. package/lib/get-ns.d.ts +0 -1
  125. package/lib/get-spec-by-tag-name.d.ts +0 -2
  126. package/lib/get-spec-by-tag-name.js +0 -31
  127. package/schemas/wai-aria.schema.json +0 -87
  128. package/src/get-spec-by-tag-name.ts +0 -32
@@ -0,0 +1,130 @@
1
+ /**
2
+ * This file was automatically generated by json-schema-to-typescript.
3
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4
+ * and run json-schema-to-typescript to regenerate this file.
5
+ */
6
+ /**
7
+ * If `false`, this mean is "No corresponding role".
8
+ */
9
+ export declare type ImplicitRole = false | string;
10
+ /**
11
+ * If `true`, this mean is "Any". If `false`, this mean is "No".
12
+ */
13
+ export declare type PermittedRoles = boolean | (string | {
14
+ name: string;
15
+ deprecated?: true;
16
+ [k: string]: unknown;
17
+ })[] | {
18
+ 'core-aam'?: true;
19
+ 'graphics-aam'?: true;
20
+ };
21
+ /**
22
+ * If set false:
23
+ * > No role or aria-* attributes
24
+ */
25
+ export declare type PermittedARIAProperties = false | {
26
+ global?: true;
27
+ /**
28
+ * Set true if the spec says "and any aria-* attributes applicable to the allowed roles."
29
+ */
30
+ role?: true | string | [string, ...string[]];
31
+ only?: [
32
+ (string | {
33
+ name: string;
34
+ value?: string;
35
+ }),
36
+ ...(string | {
37
+ name: string;
38
+ value?: string;
39
+ })[]
40
+ ];
41
+ whithout?: [
42
+ {
43
+ type: 'not-recommended' | 'should-not' | 'must-not';
44
+ name: string;
45
+ value?: string;
46
+ alt?: {
47
+ method: 'remove-attr' | 'set-attr';
48
+ target: string;
49
+ };
50
+ },
51
+ ...{
52
+ type: 'not-recommended' | 'should-not' | 'must-not';
53
+ name: string;
54
+ value?: string;
55
+ alt?: {
56
+ method: 'remove-attr' | 'set-attr';
57
+ target: string;
58
+ };
59
+ }[]
60
+ ];
61
+ };
62
+ export interface AriaSchema {
63
+ _?: ARIA;
64
+ [k: string]: unknown;
65
+ }
66
+ export interface ARIA {
67
+ implicitRole: ImplicitRole;
68
+ permittedRoles: PermittedRoles;
69
+ namingProhibited?: true;
70
+ implicitProperties?: ImplicitProperties;
71
+ properties?: PermittedARIAProperties;
72
+ conditions?: {
73
+ /**
74
+ * This interface was referenced by `undefined`'s JSON-Schema definition
75
+ * via the `patternProperty` ".+".
76
+ */
77
+ [k: string]: {
78
+ implicitRole?: ImplicitRole;
79
+ permittedRoles?: PermittedRoles;
80
+ namingProhibited?: true;
81
+ implicitProperties?: ImplicitProperties;
82
+ properties?: PermittedARIAProperties;
83
+ };
84
+ };
85
+ '1.2'?: {
86
+ implicitRole?: ImplicitRole;
87
+ permittedRoles?: PermittedRoles;
88
+ namingProhibited?: true;
89
+ implicitProperties?: ImplicitProperties;
90
+ properties?: PermittedARIAProperties;
91
+ conditions?: {
92
+ /**
93
+ * This interface was referenced by `undefined`'s JSON-Schema definition
94
+ * via the `patternProperty` ".+".
95
+ */
96
+ [k: string]: {
97
+ implicitRole?: ImplicitRole;
98
+ permittedRoles?: PermittedRoles;
99
+ namingProhibited?: true;
100
+ implicitProperties?: ImplicitProperties;
101
+ properties?: PermittedARIAProperties;
102
+ };
103
+ };
104
+ };
105
+ '1.1'?: {
106
+ implicitRole?: ImplicitRole;
107
+ permittedRoles?: PermittedRoles;
108
+ implicitProperties?: ImplicitProperties;
109
+ properties?: PermittedARIAProperties;
110
+ conditions?: {
111
+ /**
112
+ * This interface was referenced by `undefined`'s JSON-Schema definition
113
+ * via the `patternProperty` ".+".
114
+ */
115
+ [k: string]: {
116
+ implicitRole?: ImplicitRole;
117
+ permittedRoles?: PermittedRoles;
118
+ implicitProperties?: ImplicitProperties;
119
+ properties?: PermittedARIAProperties;
120
+ };
121
+ };
122
+ };
123
+ }
124
+ export interface ImplicitProperties {
125
+ /**
126
+ * This interface was referenced by `ImplicitProperties`'s JSON-Schema definition
127
+ * via the `patternProperty` "^aria-.+".
128
+ */
129
+ [k: string]: string;
130
+ }
File without changes
@@ -41,15 +41,9 @@ export declare type AttributeType = (("<'--*'>" | "<'-ms-accelerator'>" | "<'-ms
41
41
  lte?: number;
42
42
  clampable?: boolean;
43
43
  };
44
- export declare type AttributeCondition = {
45
- ancestor: Selectors;
46
- } | {
47
- self: Selectors;
48
- };
49
- export declare type Selectors = string | [string, string, ...string[]];
44
+ export declare type AttributeCondition = string | [string, string, ...string[]];
50
45
  export interface AttributesSchema {
51
46
  tag: string;
52
- ref: string;
53
47
  global?: GlobalAttributes;
54
48
  attributes: Attributes;
55
49
  }
@@ -83,8 +77,6 @@ export interface Attributes {
83
77
  * via the `patternProperty` ".*".
84
78
  */
85
79
  export interface AttributeJSON {
86
- _TODO_?: string;
87
- ref: string;
88
80
  type?: AttributeType | [AttributeType, ...AttributeType[]];
89
81
  defaultValue?: string;
90
82
  deprecated?: boolean;
@@ -92,7 +84,7 @@ export interface AttributeJSON {
92
84
  requiredEither?: string[];
93
85
  noUse?: boolean;
94
86
  condition?: AttributeCondition;
95
- ineffective?: Selectors;
87
+ ineffective?: AttributeCondition;
96
88
  animatable?: boolean;
97
89
  experimental?: boolean;
98
90
  }
@@ -1,6 +1,7 @@
1
- import type { AttributeJSON } from '.';
2
- import type { AttributeType, GlobalAttributes } from './attributes';
3
- import type { ContentModel, PermittedStructuresSchema } from './permitted-structres';
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
  * markuplit Markup-language spec
6
7
  */
@@ -28,12 +29,19 @@ export declare type SpecDefs = {
28
29
  '#HTMLGlobalAttrs': Record<string, Partial<Attribute>>;
29
30
  [OtherGlobalAttrs: string]: Record<string, Partial<Attribute>>;
30
31
  }>;
31
- '#ariaAttrs': ARIAAttribute[];
32
- '#roles': ARIRRoleAttribute[];
32
+ '#aria': {
33
+ '1.2': ARIASpec;
34
+ '1.1': ARIASpec;
35
+ };
33
36
  '#contentModels': {
34
- [model in ContentModel]?: string[];
37
+ [model in Category]?: string[];
35
38
  };
36
39
  };
40
+ declare type ARIASpec = {
41
+ roles: ARIARoleInSchema[];
42
+ graphicsRoles: ARIARoleInSchema[];
43
+ props: ARIAProperty[];
44
+ };
37
45
  /**
38
46
  * Element spec
39
47
  */
@@ -46,7 +54,7 @@ export declare type ElementSpec = {
46
54
  * Namespaces in XML
47
55
  * @see https://www.w3.org/TR/xml-names/
48
56
  */
49
- namespace?: 'http://www.w3.org/1999/xhtml' | 'http://www.w3.org/2000/svg' | 'http://www.w3.org/1998/Math/MathML';
57
+ namespace?: NamespaceURI;
50
58
  /**
51
59
  * Reference URL
52
60
  */
@@ -76,33 +84,11 @@ export declare type ElementSpec = {
76
84
  /**
77
85
  * Element cateogries
78
86
  */
79
- categories: ContentModel[];
87
+ categories: Category[];
80
88
  /**
81
89
  * Permitted contents and permitted parents
82
90
  */
83
- permittedStructures: PermittedStructuresSchema;
84
- /**
85
- * Permitted ARIA roles
86
- */
87
- permittedRoles: {
88
- summary: string;
89
- roles: PermittedRoles;
90
- conditions?: {
91
- condition: string;
92
- roles: PermittedRoles;
93
- }[];
94
- };
95
- /**
96
- * Implicit ARIA role
97
- */
98
- implicitRole: {
99
- summary: string;
100
- role: ImplicitRole;
101
- conditions?: {
102
- condition: string;
103
- role: ImplicitRole;
104
- }[];
105
- };
91
+ contentModel: ContentModel;
106
92
  /**
107
93
  * Tag omittion
108
94
  */
@@ -115,6 +101,10 @@ export declare type ElementSpec = {
115
101
  * Attributes
116
102
  */
117
103
  attributes: Record<string, Attribute>;
104
+ /**
105
+ * WAI-ARIA role and properies
106
+ */
107
+ aria: ARIA;
118
108
  /**
119
109
  * If true, it is possible to add any properties as attributes,
120
110
  * for example, when using a template engine or a view language.
@@ -125,15 +115,6 @@ export declare type ElementSpec = {
125
115
  */
126
116
  possibleToAddProperties?: true;
127
117
  };
128
- /**
129
- * If `false`, this mean is "No corresponding role".
130
- */
131
- declare type ImplicitRole = string | false;
132
- /**
133
- * If `true`, this mean is "Any".
134
- * If `false`, this mean is "No".
135
- */
136
- export declare type PermittedRoles = string[] | boolean;
137
118
  declare type ElementSpecOmittion = false | ElementSpecOmittionTags;
138
119
  declare type ElementSpecOmittionTags = {
139
120
  startTag: boolean | ElementCondition;
@@ -152,28 +133,33 @@ export declare type Attribute = {
152
133
  deprecated?: boolean;
153
134
  nonStandard?: true;
154
135
  } & ExtendableAttributeSpec;
155
- declare type ExtendableAttributeSpec = Omit<AttributeJSON, 'ref' | '_TODO_' | 'type'>;
156
- export declare type ARIRRoleAttribute = {
136
+ declare type ExtendableAttributeSpec = Omit<AttributeJSON, 'type'>;
137
+ export declare type ARIARole = {
157
138
  name: string;
158
- description: string;
159
- isAbstract?: true;
160
- generalization: string[];
161
- requiredContextRole?: string[];
139
+ isAbstract: boolean;
140
+ requiredContextRole: string[];
141
+ requiredOwnedElements: string[];
162
142
  accessibleNameRequired: boolean;
143
+ accessibleNameFromAuthor: boolean;
163
144
  accessibleNameFromContent: boolean;
164
145
  accessibleNameProhibited: boolean;
165
- ownedAttribute: ARIARoleOwnedPropOrState[];
166
- childrenPresentational?: boolean;
146
+ childrenPresentational: boolean;
147
+ ownedProperties: ARIARoleOwnedProperties[];
148
+ prohibitedProperties: string[];
167
149
  };
168
- export declare type ARIARoleOwnedPropOrState = {
150
+ export declare type ARIARoleInSchema = Partial<ARIARole & {
151
+ description: string;
152
+ generalization: string[];
153
+ }> & {
154
+ name: string;
155
+ };
156
+ export declare type ARIARoleOwnedProperties = {
169
157
  name: string;
170
158
  inherited?: true;
171
159
  required?: true;
172
160
  deprecated?: true;
173
- prohibited?: true;
174
- defaultValue?: boolean | string | number;
175
161
  };
176
- export declare type ARIAAttribute = {
162
+ export declare type ARIAProperty = {
177
163
  name: string;
178
164
  type: 'property' | 'state';
179
165
  deprecated?: true;
@@ -189,21 +175,20 @@ export declare type ARIAAttribute = {
189
175
  valueDescriptions?: Record<string, string>;
190
176
  };
191
177
  export declare type ARIAAttributeValue = 'true/false' | 'tristate' | 'true/false/undefined' | 'ID reference' | 'ID reference list' | 'integer' | 'number' | 'string' | 'token' | 'token list' | 'URI';
178
+ export declare type ARIAVersion = '1.1' | '1.2';
192
179
  export declare type EquivalentHtmlAttr = {
193
180
  htmlAttrName: string;
194
181
  isNotStrictEquivalent?: true;
195
182
  value: string | null;
196
183
  };
197
- export interface SpecOM {
198
- [tagName: string]: MLDOMElementSpec;
199
- }
200
- export interface MLDOMElementSpec {
201
- experimental: boolean;
202
- obsolete: boolean | string;
203
- deprecated: boolean;
204
- nonStandard: boolean;
205
- categories: ContentModel[];
206
- permittedStructures: PermittedStructuresSchema;
207
- attributes: Attribute[];
208
- }
184
+ export declare type Matches = (selector: string) => boolean;
185
+ export declare type ComputedRole = {
186
+ el: Element;
187
+ role: (ARIARole & {
188
+ superClassRoles: ARIARoleInSchema[];
189
+ isImplicit?: boolean;
190
+ }) | null;
191
+ errorType?: RoleComputationError;
192
+ };
193
+ export declare type RoleComputationError = 'ABSTRACT' | 'GLOBAL_PROP_MUST_NOT_BE_PRESENTATIONAL' | 'IMPLICIT_ROLE_NAMESPACE_ERROR' | 'INTERACTIVE_ELEMENT_MUST_NOT_BE_PRESENTATIONAL' | 'INVALID_LANDMARK' | 'INVALID_REQUIRED_CONTEXT_ROLE' | 'NO_EXPLICIT' | 'NO_OWNER' | 'NO_PERMITTED' | 'REQUIRED_OWNED_ELEMENT_MUST_NOT_BE_PRESENTATIONAL' | 'ROLE_NO_EXISTS';
209
194
  export {};
File without changes
@@ -4,34 +4,25 @@
4
4
  * and run json-schema-to-typescript to regenerate this file.
5
5
  */
6
6
  export declare type PermittedContent = PermittedContentRequire | PermittedContentOptional | PermittedContentOneOrMore | PermittedContentZeroOrMore | PermittedContentChoice | PermittedContentInterleave;
7
- export declare type Target = Node | Node[];
8
- export declare type Node = string | '#text' | ContentModel;
9
- export declare type ContentModel = '#phrasing' | '#flow' | '#interactive' | '#heading' | '#sectioning' | '#metadata' | '#transparent' | '#embedded' | '#palpable' | '#script-supporting' | '#SVGAnimation' | '#SVGBasicShapes' | '#SVGContainer' | '#SVGDescriptive' | '#SVGFilterPrimitive' | '#SVGFont' | '#SVGGradient' | '#SVGGraphics' | '#SVGGraphicsReferencing' | '#SVGLightSource' | '#SVGNeverRendered' | '#SVGNone' | '#SVGPaintServer' | '#SVGRenderable' | '#SVGShape' | '#SVGStructural' | '#SVGStructurallyExternal' | '#SVGTextContent' | '#SVGTextContentChild' | '#SVGOtherXMLNamespace';
7
+ export declare type Target = ContentType | ContentType[];
8
+ export declare type ContentType = string | Category;
9
+ export declare type Category = '#text' | '#phrasing' | '#flow' | '#interactive' | '#heading' | '#sectioning' | '#metadata' | '#transparent' | '#embedded' | '#palpable' | '#script-supporting' | '#SVGAnimation' | '#SVGBasicShapes' | '#SVGContainer' | '#SVGDescriptive' | '#SVGFilterPrimitive' | '#SVGFont' | '#SVGGradient' | '#SVGGraphics' | '#SVGGraphicsReferencing' | '#SVGLightSource' | '#SVGNeverRendered' | '#SVGNone' | '#SVGPaintServer' | '#SVGRenderable' | '#SVGShape' | '#SVGStructural' | '#SVGStructurallyExternal' | '#SVGTextContent' | '#SVGTextContentChild' | '#SVGOtherXMLNamespace';
10
10
  export declare type PermittedContentSpec = PermittedContent[];
11
- export interface PermittedStructuresSchema {
12
- summary?: string;
13
- tag: string;
11
+ export interface ContentModelsSchema {
12
+ __contentModel?: ContentModel;
13
+ }
14
+ export interface ContentModel {
15
+ contents: PermittedContentSpec | boolean;
16
+ descendantOf?: string;
14
17
  conditional?: {
15
- condition: {
16
- hasAttr: string;
17
- } | {
18
- parent: string;
19
- /**
20
- * Not support yet
21
- */
22
- hasNotAttr?: string;
23
- _TODO_?: string;
24
- _parent?: string;
25
- };
18
+ condition: string;
26
19
  contents: PermittedContentSpec | boolean;
27
20
  }[];
28
- contents: PermittedContentSpec | boolean;
29
- ancestor?: Node;
30
21
  }
31
22
  export interface PermittedContentRequire {
32
23
  require: Target;
33
24
  ignore?: Target;
34
- notAllowedDescendants?: Node[];
25
+ notAllowedDescendants?: ContentType[];
35
26
  max?: number;
36
27
  min?: number;
37
28
  _TODO_?: string;
@@ -39,21 +30,21 @@ export interface PermittedContentRequire {
39
30
  export interface PermittedContentOptional {
40
31
  optional: Target;
41
32
  ignore?: Target;
42
- notAllowedDescendants?: Node[];
33
+ notAllowedDescendants?: ContentType[];
43
34
  max?: number;
44
35
  _TODO_?: string;
45
36
  }
46
37
  export interface PermittedContentOneOrMore {
47
38
  oneOrMore: Target | PermittedContentSpec;
48
39
  ignore?: Target;
49
- notAllowedDescendants?: Node[];
40
+ notAllowedDescendants?: ContentType[];
50
41
  max?: number;
51
42
  _TODO_?: string;
52
43
  }
53
44
  export interface PermittedContentZeroOrMore {
54
45
  zeroOrMore: Target | PermittedContentSpec;
55
46
  ignore?: Target;
56
- notAllowedDescendants?: Node[];
47
+ notAllowedDescendants?: ContentType[];
57
48
  max?: number;
58
49
  _TODO_?: string;
59
50
  }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /* tslint:disable */
3
+ /**
4
+ * This file was automatically generated by json-schema-to-typescript.
5
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
6
+ * and run json-schema-to-typescript to regenerate this file.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ declare type CacheKeys<K1, K2 = undefined, K3 = undefined, K4 = undefined, K5 = undefined, K6 = undefined> = K2 extends undefined ? [K1] : K3 extends undefined ? [K1, K2] : K4 extends undefined ? [K1, K2, K3] : K5 extends undefined ? [K1, K2, K3, K4] : K6 extends undefined ? [K1, K2, K3, K4, K5] : [K1, K2, K3, K4, K5, K6];
2
+ export declare class Cache<V, K1, K2 = undefined, K3 = undefined, K4 = undefined, K5 = undefined, K6 = undefined, K = CacheKeys<K1, K2, K3, K4, K5, K6>> {
3
+ #private;
4
+ constructor();
5
+ set(keys: K, value: V): this;
6
+ get(keys: K): V | undefined;
7
+ createKey(keys: K): string;
8
+ clear(): void;
9
+ }
10
+ export {};
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var _Cache_i, _Cache_m, _Cache_o;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Cache = void 0;
5
+ const tslib_1 = require("tslib");
6
+ class Cache {
7
+ constructor() {
8
+ _Cache_i.set(this, 0);
9
+ _Cache_m.set(this, new Map());
10
+ _Cache_o.set(this, new Map());
11
+ }
12
+ set(keys, value) {
13
+ const _keys = this.createKey(keys);
14
+ tslib_1.__classPrivateFieldGet(this, _Cache_m, "f").set(_keys, value);
15
+ return this;
16
+ }
17
+ get(keys) {
18
+ const _keys = this.createKey(keys);
19
+ return tslib_1.__classPrivateFieldGet(this, _Cache_m, "f").get(_keys);
20
+ }
21
+ createKey(keys) {
22
+ const _keys = keys
23
+ // @ts-ignore
24
+ .map(o => {
25
+ if (tslib_1.__classPrivateFieldGet(this, _Cache_o, "f").has(o)) {
26
+ return tslib_1.__classPrivateFieldGet(this, _Cache_o, "f").get(o);
27
+ }
28
+ const i = tslib_1.__classPrivateFieldGet(this, _Cache_i, "f") + 1;
29
+ tslib_1.__classPrivateFieldSet(this, _Cache_i, i, "f");
30
+ tslib_1.__classPrivateFieldGet(this, _Cache_o, "f").set(o, i);
31
+ return i;
32
+ })
33
+ .join('_');
34
+ return _keys;
35
+ }
36
+ clear() {
37
+ tslib_1.__classPrivateFieldGet(this, _Cache_m, "f").clear();
38
+ tslib_1.__classPrivateFieldGet(this, _Cache_o, "f").clear();
39
+ }
40
+ }
41
+ exports.Cache = Cache;
42
+ _Cache_i = new WeakMap(), _Cache_m = new WeakMap(), _Cache_o = new WeakMap();
@@ -0,0 +1,2 @@
1
+ import type { Namespace } from '@markuplint/ml-ast';
2
+ export declare function getNS(namespaceURI: string | null): Namespace;
@@ -9,6 +9,9 @@ function getNS(namespaceURI) {
9
9
  case 'http://www.w3.org/1998/Math/MathML': {
10
10
  return 'mml';
11
11
  }
12
+ case 'http://www.w3.org/1999/xlink': {
13
+ return 'xlink';
14
+ }
12
15
  default: {
13
16
  return 'html';
14
17
  }
@@ -0,0 +1,5 @@
1
+ declare type NamedDefinition = string | {
2
+ name: string;
3
+ };
4
+ export declare function mergeArray<T extends NamedDefinition>(a: T[], b: T[] | null | undefined): T[];
5
+ export {};
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeArray = void 0;
4
+ function mergeArray(a, b) {
5
+ if (!b) {
6
+ return a;
7
+ }
8
+ const result = a.slice();
9
+ for (const bItem of b) {
10
+ const bName = getName(bItem);
11
+ const aIndex = result.findIndex(item => getName(item) === bName);
12
+ if (aIndex === -1) {
13
+ result.push(bItem);
14
+ continue;
15
+ }
16
+ const aItem = result.splice(aIndex, 1)[0];
17
+ if (typeof bItem === 'string') {
18
+ continue;
19
+ }
20
+ if (typeof aItem === 'string') {
21
+ result.push(bItem);
22
+ continue;
23
+ }
24
+ const exItem = {
25
+ ...aItem,
26
+ ...bItem,
27
+ };
28
+ result.push(exItem);
29
+ }
30
+ return result;
31
+ }
32
+ exports.mergeArray = mergeArray;
33
+ function getName(def) {
34
+ const result = typeof def === 'string' ? def : def.name;
35
+ return result.toLowerCase().trim();
36
+ }
@@ -0,0 +1,9 @@
1
+ import type { NamespaceURI, Namespace } from '@markuplint/ml-ast';
2
+ declare type NamespacedElementName = {
3
+ localNameWithNS: string;
4
+ localName: string;
5
+ namespace: Namespace;
6
+ namespaceURI: NamespaceURI;
7
+ };
8
+ export declare function resolveNamespace(name: string, namespaceURI?: string | null): NamespacedElementName;
9
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveNamespace = void 0;
4
+ const get_ns_1 = require("./get-ns");
5
+ const cache = new Map();
6
+ const namespaceURIMap = {
7
+ html: 'http://www.w3.org/1999/xhtml',
8
+ svg: 'http://www.w3.org/2000/svg',
9
+ mml: 'http://www.w3.org/1998/Math/MathML',
10
+ xlink: 'http://www.w3.org/1999/xlink',
11
+ };
12
+ function resolveNamespace(name, namespaceURI = 'http://www.w3.org/1999/xhtml') {
13
+ const cached = cache.get(name + namespaceURI);
14
+ if (cached) {
15
+ return cached;
16
+ }
17
+ const [_explicitNS, _localName] = name.split(':');
18
+ const explicitNS = _localName ? _explicitNS : null;
19
+ const localName = _localName !== null && _localName !== void 0 ? _localName : _explicitNS;
20
+ const namespace = ['html', 'svg', 'mml', 'xlink'].find(_ns => _ns === (explicitNS || (0, get_ns_1.getNS)(namespaceURI || null))) ||
21
+ 'html';
22
+ const result = {
23
+ localNameWithNS: `${namespace === 'html' ? '' : `${namespace}:`}${localName}`,
24
+ localName,
25
+ namespace,
26
+ namespaceURI: namespaceURIMap[namespace],
27
+ };
28
+ cache.set(name + namespaceURI, result);
29
+ return result;
30
+ }
31
+ exports.resolveNamespace = resolveNamespace;
package/lib/utils.d.ts CHANGED
@@ -1,5 +1,8 @@
1
- declare type NamedDefinition = string | {
2
- name: string;
3
- };
1
+ declare type NamedDefinition =
2
+ | string
3
+ | {
4
+ name: string;
5
+ };
6
+ export declare function getNS(namespaceURI: string | null): 'svg' | 'mml' | 'html';
4
7
  export declare function mergeArray<T extends NamedDefinition>(a: T[], b: T[] | null | undefined): T[];
5
8
  export {};
package/lib/utils.js CHANGED
@@ -1,6 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeArray = void 0;
3
+ exports.mergeArray = exports.getNS = void 0;
4
+ function getNS(namespaceURI) {
5
+ switch (namespaceURI) {
6
+ case 'http://www.w3.org/2000/svg': {
7
+ return 'svg';
8
+ }
9
+ case 'http://www.w3.org/1998/Math/MathML': {
10
+ return 'mml';
11
+ }
12
+ default: {
13
+ return 'html';
14
+ }
15
+ }
16
+ }
17
+ exports.getNS = getNS;
4
18
  function mergeArray(a, b) {
5
19
  if (!b) {
6
20
  return a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-spec",
3
- "version": "2.1.0",
3
+ "version": "3.0.0-alpha.0",
4
4
  "description": "Types and schema that specs of the Markup languages for markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -16,16 +16,20 @@
16
16
  "dev": "tsc --build --watch",
17
17
  "clean": "tsc --build --clean",
18
18
  "schema:gen": "ts-node ./gen/gen.ts; prettier --write './schemas/*.json';",
19
- "schema:structures": "json2ts ./schemas/permitted-structures.schema.json > ./src/permitted-structres.ts; prettier --write ./src/permitted-structres.ts; eslint --fix --config ../../../.eslintrc ./src/permitted-structres.ts",
20
- "schema:attributes": "json2ts ./schemas/attributes.schema.json --cwd ./schemas > ./src/attributes.ts; prettier --write ./src/attributes.ts; eslint --fix --config ../../../.eslintrc ./src/attributes.ts",
21
- "schema": "yarn schema:gen; yarn schema:structures; yarn schema:attributes; tsc;"
19
+ "schema:content-models": "json2ts ./schemas/content-models.schema.json > ./src/types/permitted-structres.ts; prettier --write ./src/types/permitted-structres.ts; eslint --fix --config ../../../.eslintrc ./src/types/permitted-structres.ts",
20
+ "schema:attributes": "json2ts ./schemas/attributes.schema.json --cwd ./schemas > ./src/types/attributes.ts; prettier --write ./src/types/attributes.ts; eslint --fix --config ../../../.eslintrc ./src/types/attributes.ts",
21
+ "schema:aria": "json2ts ./schemas/aria.schema.json --cwd ./schemas > ./src/types/aria.ts; prettier --write ./src/types/aria.ts; eslint --fix --config ../../../.eslintrc ./src/types/aria.ts",
22
+ "schema": "run-s schema:*"
22
23
  },
23
24
  "dependencies": {
25
+ "@markuplint/ml-ast": "3.0.0-alpha.0",
26
+ "dom-accessibility-api": "^0.5.14",
24
27
  "tslib": "^2.3.1"
25
28
  },
26
29
  "devDependencies": {
27
- "@markuplint/types": "2.1.0",
30
+ "@markuplint/test-tools": "3.0.0-alpha.0",
31
+ "@markuplint/types": "3.0.0-alpha.0",
28
32
  "json-schema-to-typescript": "^10.1.5"
29
33
  },
30
- "gitHead": "0321513e36cc74929c41e06e1f58c43ff7602556"
34
+ "gitHead": "d32c522e016888e20bcbb5f09352c006b964f193"
31
35
  }