@markuplint/types 3.0.0-dev.25 → 3.0.0-dev.300

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 (173) hide show
  1. package/README.md +63 -61
  2. package/lib/check-multi-types.d.ts +2 -2
  3. package/lib/check-multi-types.js +9 -13
  4. package/lib/check.d.ts +7 -6
  5. package/lib/check.js +20 -30
  6. package/lib/css-syntax.d.ts +1 -1
  7. package/lib/css-syntax.js +60 -63
  8. package/lib/debug.js +2 -6
  9. package/lib/defs.d.ts +1 -1
  10. package/lib/defs.js +163 -91
  11. package/lib/enum.d.ts +4 -3
  12. package/lib/enum.js +7 -12
  13. package/lib/get-candidate.d.ts +1 -1
  14. package/lib/get-candidate.js +3 -8
  15. package/lib/index.d.ts +3 -3
  16. package/lib/index.js +3 -6
  17. package/lib/keyword-type.d.ts +2 -2
  18. package/lib/keyword-type.js +17 -21
  19. package/lib/list.d.ts +4 -3
  20. package/lib/list.js +9 -13
  21. package/lib/match-result.d.ts +4 -4
  22. package/lib/match-result.js +6 -12
  23. package/lib/number.d.ts +3 -3
  24. package/lib/number.js +11 -15
  25. package/lib/primitive/index.d.ts +7 -7
  26. package/lib/primitive/index.js +7 -17
  27. package/lib/primitive/is-float.js +1 -5
  28. package/lib/primitive/is-int.js +1 -5
  29. package/lib/primitive/is-non-zero-uint.js +1 -5
  30. package/lib/primitive/is-quantity.d.ts +1 -1
  31. package/lib/primitive/is-quantity.js +9 -13
  32. package/lib/primitive/is-uint.d.ts +1 -1
  33. package/lib/primitive/is-uint.js +1 -5
  34. package/lib/primitive/range.js +1 -5
  35. package/lib/primitive/split-unit.js +3 -7
  36. package/lib/rfc/is-bcp-47.d.ts +1 -1
  37. package/lib/rfc/is-bcp-47.js +3 -7
  38. package/lib/token/index.d.ts +2 -2
  39. package/lib/token/index.js +2 -7
  40. package/lib/token/token-collection.d.ts +13 -13
  41. package/lib/token/token-collection.js +55 -50
  42. package/lib/token/token.d.ts +11 -10
  43. package/lib/token/token.js +16 -24
  44. package/lib/token/types.d.ts +3 -0
  45. package/lib/types.d.ts +47 -46
  46. package/lib/types.js +1 -2
  47. package/lib/types.schema.d.ts +2 -2
  48. package/lib/types.schema.js +1 -3
  49. package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
  50. package/lib/w3c/check-serialized-permissions-policy.js +16 -20
  51. package/lib/whatwg/check-autocomplete.d.ts +1 -1
  52. package/lib/whatwg/check-autocomplete.js +28 -32
  53. package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
  54. package/lib/whatwg/check-datetime/date-string.js +9 -13
  55. package/lib/whatwg/check-datetime/datetime-tokens.d.ts +1 -1
  56. package/lib/whatwg/check-datetime/datetime-tokens.js +43 -46
  57. package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
  58. package/lib/whatwg/check-datetime/duration-string.js +48 -44
  59. package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +1 -1
  60. package/lib/whatwg/check-datetime/global-date-and-time-string.js +17 -21
  61. package/lib/whatwg/check-datetime/index.d.ts +1 -1
  62. package/lib/whatwg/check-datetime/index.js +25 -29
  63. package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +1 -1
  64. package/lib/whatwg/check-datetime/local-date-and-time-string.js +25 -26
  65. package/lib/whatwg/check-datetime/month-string.d.ts +1 -1
  66. package/lib/whatwg/check-datetime/month-string.js +9 -13
  67. package/lib/whatwg/check-datetime/time-string.d.ts +1 -1
  68. package/lib/whatwg/check-datetime/time-string.js +9 -13
  69. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
  70. package/lib/whatwg/check-datetime/time-zone-offset-string.js +16 -21
  71. package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
  72. package/lib/whatwg/check-datetime/week-string.js +9 -13
  73. package/lib/whatwg/check-datetime/year-string.d.ts +1 -1
  74. package/lib/whatwg/check-datetime/year-string.js +9 -13
  75. package/lib/whatwg/check-datetime/yearless-date-string.d.ts +1 -1
  76. package/lib/whatwg/check-datetime/yearless-date-string.js +9 -13
  77. package/lib/whatwg/check-mime-type.d.ts +1 -1
  78. package/lib/whatwg/check-mime-type.js +12 -18
  79. package/lib/whatwg/is-abs-url.d.ts +1 -1
  80. package/lib/whatwg/is-abs-url.js +1 -5
  81. package/lib/whatwg/is-browser-context-name.d.ts +3 -1
  82. package/lib/whatwg/is-browser-context-name.js +3 -5
  83. package/lib/whatwg/is-custom-element-name.d.ts +1 -1
  84. package/lib/whatwg/is-custom-element-name.js +1 -5
  85. package/lib/whatwg/is-itemprop-name.d.ts +1 -1
  86. package/lib/whatwg/is-itemprop-name.js +2 -6
  87. package/lib/whatwg/is-navigable-target-name.d.ts +11 -0
  88. package/lib/whatwg/is-navigable-target-name.js +20 -0
  89. package/package.json +19 -14
  90. package/types.schema.json +314 -311
  91. package/gen/specific-schema.json +0 -98
  92. package/gen/types.ts +0 -66
  93. package/lib/check.spec.js +0 -76
  94. package/lib/css-syntax.spec.d.ts +0 -1
  95. package/lib/css-syntax.spec.js +0 -157
  96. package/lib/list.spec.d.ts +0 -1
  97. package/lib/list.spec.js +0 -129
  98. package/lib/primitive/index.spec.d.ts +0 -1
  99. package/lib/primitive/index.spec.js +0 -62
  100. package/lib/rfc/is-bcp-47.spec.d.ts +0 -1
  101. package/lib/rfc/is-bcp-47.spec.js +0 -19
  102. package/lib/token/token-collection.spec.d.ts +0 -1
  103. package/lib/token/token-collection.spec.js +0 -144
  104. package/lib/w3c/check-serialized-permissions-policy.spec.d.ts +0 -1
  105. package/lib/w3c/check-serialized-permissions-policy.spec.js +0 -34
  106. package/lib/whatwg/check-autocomplete.spec.d.ts +0 -1
  107. package/lib/whatwg/check-autocomplete.spec.js +0 -379
  108. package/lib/whatwg/check-datetime/index.spec.d.ts +0 -1
  109. package/lib/whatwg/check-datetime/index.spec.js +0 -318
  110. package/lib/whatwg/check-mime-type.spec.d.ts +0 -1
  111. package/lib/whatwg/check-mime-type.spec.js +0 -58
  112. package/lib/whatwg/is-abs-url.spec.d.ts +0 -1
  113. package/lib/whatwg/is-abs-url.spec.js +0 -8
  114. package/patches/css-tree+2.3.1.patch +0 -23
  115. package/src/check-multi-types.ts +0 -35
  116. package/src/check.spec.ts +0 -83
  117. package/src/check.ts +0 -48
  118. package/src/css-syntax.spec.ts +0 -167
  119. package/src/css-syntax.ts +0 -188
  120. package/src/debug.ts +0 -3
  121. package/src/defs.ts +0 -811
  122. package/src/enum.ts +0 -25
  123. package/src/get-candidate.ts +0 -24
  124. package/src/index.ts +0 -3
  125. package/src/keyword-type.ts +0 -64
  126. package/src/list.spec.ts +0 -133
  127. package/src/list.ts +0 -34
  128. package/src/match-result.ts +0 -49
  129. package/src/number.ts +0 -46
  130. package/src/primitive/index.spec.ts +0 -65
  131. package/src/primitive/index.ts +0 -7
  132. package/src/primitive/is-float.ts +0 -8
  133. package/src/primitive/is-int.ts +0 -8
  134. package/src/primitive/is-non-zero-uint.ts +0 -8
  135. package/src/primitive/is-quantity.ts +0 -38
  136. package/src/primitive/is-uint.ts +0 -15
  137. package/src/primitive/range.ts +0 -14
  138. package/src/primitive/split-unit.ts +0 -20
  139. package/src/rfc/is-bcp-47.spec.ts +0 -23
  140. package/src/rfc/is-bcp-47.ts +0 -13
  141. package/src/token/index.ts +0 -2
  142. package/src/token/token-collection.spec.ts +0 -147
  143. package/src/token/token-collection.ts +0 -444
  144. package/src/token/token.ts +0 -144
  145. package/src/types.schema.ts +0 -1113
  146. package/src/types.ts +0 -118
  147. package/src/w3c/check-serialized-permissions-policy.spec.ts +0 -38
  148. package/src/w3c/check-serialized-permissions-policy.ts +0 -303
  149. package/src/whatwg/check-autocomplete.spec.ts +0 -387
  150. package/src/whatwg/check-autocomplete.ts +0 -380
  151. package/src/whatwg/check-datetime/date-string.ts +0 -44
  152. package/src/whatwg/check-datetime/datetime-tokens.ts +0 -600
  153. package/src/whatwg/check-datetime/duration-string.ts +0 -399
  154. package/src/whatwg/check-datetime/global-date-and-time-string.ts +0 -96
  155. package/src/whatwg/check-datetime/index.spec.ts +0 -333
  156. package/src/whatwg/check-datetime/index.ts +0 -36
  157. package/src/whatwg/check-datetime/local-date-and-time-string.ts +0 -163
  158. package/src/whatwg/check-datetime/month-string.ts +0 -31
  159. package/src/whatwg/check-datetime/time-string.ts +0 -49
  160. package/src/whatwg/check-datetime/time-zone-offset-string.ts +0 -93
  161. package/src/whatwg/check-datetime/week-string.ts +0 -41
  162. package/src/whatwg/check-datetime/year-string.ts +0 -26
  163. package/src/whatwg/check-datetime/yearless-date-string.ts +0 -38
  164. package/src/whatwg/check-mime-type.spec.ts +0 -59
  165. package/src/whatwg/check-mime-type.ts +0 -46
  166. package/src/whatwg/is-abs-url.spec.ts +0 -8
  167. package/src/whatwg/is-abs-url.ts +0 -31
  168. package/src/whatwg/is-browser-context-name.ts +0 -16
  169. package/src/whatwg/is-custom-element-name.ts +0 -76
  170. package/src/whatwg/is-itemprop-name.ts +0 -17
  171. package/tsconfig.test.json +0 -3
  172. package/tsconfig.tsbuildinfo +0 -1
  173. /package/lib/{check.spec.d.ts → token/types.js} +0 -0
package/lib/defs.js CHANGED
@@ -1,33 +1,31 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tokenizers = exports.types = void 0;
4
- const check_multi_types_1 = require("./check-multi-types");
5
- const get_candidate_1 = require("./get-candidate");
6
- const match_result_1 = require("./match-result");
7
- const primitive_1 = require("./primitive");
8
- const is_bcp_47_1 = require("./rfc/is-bcp-47");
9
- const token_1 = require("./token");
10
- const check_serialized_permissions_policy_1 = require("./w3c/check-serialized-permissions-policy");
11
- const check_autocomplete_1 = require("./whatwg/check-autocomplete");
12
- const check_datetime_1 = require("./whatwg/check-datetime");
13
- const check_mime_type_1 = require("./whatwg/check-mime-type");
14
- const is_abs_url_1 = require("./whatwg/is-abs-url");
15
- const is_browser_context_name_1 = require("./whatwg/is-browser-context-name");
16
- const is_custom_element_name_1 = require("./whatwg/is-custom-element-name");
17
- const is_itemprop_name_1 = require("./whatwg/is-itemprop-name");
18
- exports.types = {
1
+ import { checkMultiTypes } from './check-multi-types.js';
2
+ import { getCandidate } from './get-candidate.js';
3
+ import { matched, matches, unmatched } from './match-result.js';
4
+ import { splitUnit, isFloat, isUint, isInt } from './primitive/index.js';
5
+ import { isBCP47 } from './rfc/is-bcp-47.js';
6
+ import { Token, TokenCollection } from './token/index.js';
7
+ import { checkSerializedPermissionsPolicy } from './w3c/check-serialized-permissions-policy.js';
8
+ import { checkAutoComplete } from './whatwg/check-autocomplete.js';
9
+ import { checkDateTime } from './whatwg/check-datetime/index.js';
10
+ import { checkMIMEType } from './whatwg/check-mime-type.js';
11
+ import { isAbsURL } from './whatwg/is-abs-url.js';
12
+ import { isBrowserContextName } from './whatwg/is-browser-context-name.js';
13
+ import { isCustomElementName } from './whatwg/is-custom-element-name.js';
14
+ import { isItempropName } from './whatwg/is-itemprop-name.js';
15
+ import { isNavigableTargetName } from './whatwg/is-navigable-target-name.js';
16
+ export const types = {
19
17
  Any: {
20
18
  ref: '',
21
- is: () => (0, match_result_1.matched)(),
19
+ is: () => matched(),
22
20
  },
23
21
  NoEmptyAny: {
24
22
  ref: '',
25
- is: value => (0 < value.length ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'empty-token')),
23
+ is: value => (0 < value.length ? matched() : unmatched(value, 'empty-token')),
26
24
  },
27
25
  OneLineAny: {
28
26
  ref: '',
29
27
  is: value => {
30
- const tokens = new token_1.TokenCollection(value);
28
+ const tokens = new TokenCollection(value);
31
29
  /**
32
30
  * @see https://infra.spec.whatwg.org/#ascii-tab-or-newline
33
31
  */
@@ -38,7 +36,7 @@ exports.types = {
38
36
  reason: 'unexpected-newline',
39
37
  });
40
38
  }
41
- return (0, match_result_1.matched)();
39
+ return matched();
42
40
  },
43
41
  },
44
42
  Zero: {
@@ -49,7 +47,7 @@ exports.types = {
49
47
  value: 'zero',
50
48
  },
51
49
  ],
52
- is: value => (value === '0' ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'syntax-error')),
50
+ is: value => (value === '0' ? matched() : unmatched(value, 'syntax-error')),
53
51
  },
54
52
  Number: {
55
53
  ref: '',
@@ -59,7 +57,7 @@ exports.types = {
59
57
  value: 'number',
60
58
  },
61
59
  ],
62
- is: value => ((0, primitive_1.isFloat)(value) ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token')),
60
+ is: value => (isFloat(value) ? matched() : unmatched(value, 'unexpected-token')),
63
61
  },
64
62
  Int: {
65
63
  ref: '',
@@ -69,7 +67,7 @@ exports.types = {
69
67
  value: 'integer',
70
68
  },
71
69
  ],
72
- is: value => ((0, primitive_1.isInt)(value) ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token')),
70
+ is: value => (isInt(value) ? matched() : unmatched(value, 'unexpected-token')),
73
71
  },
74
72
  Uint: {
75
73
  ref: '',
@@ -79,7 +77,7 @@ exports.types = {
79
77
  value: 'non-negative integer',
80
78
  },
81
79
  ],
82
- is: value => ((0, primitive_1.isUint)(value) ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token')),
80
+ is: value => (isUint(value) ? matched() : unmatched(value, 'unexpected-token')),
83
81
  },
84
82
  XMLName: {
85
83
  ref: 'https://www.w3.org/TR/xml/#NT-Name',
@@ -96,7 +94,7 @@ exports.types = {
96
94
  const nameCharTail = /-|[.0-9\u00B7]|[\u0300-\u036F\u203F-\u2040]/;
97
95
  // Name ::= NameStartChar (NameChar)*
98
96
  const name = RegExp(`(?:${nameStartChar.source})(?:${nameCharTail})*`, 'u');
99
- return name.test(value) ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token');
97
+ return name.test(value) ? matched() : unmatched(value, 'unexpected-token');
100
98
  },
101
99
  },
102
100
  DOMID: {
@@ -108,17 +106,17 @@ exports.types = {
108
106
  },
109
107
  ],
110
108
  is: value => {
111
- const tokens = new token_1.TokenCollection(value);
112
- const ws = tokens.search(token_1.Token.WhiteSpace);
109
+ const tokens = new TokenCollection(value);
110
+ const ws = tokens.search(Token.WhiteSpace);
113
111
  if (ws) {
114
112
  return ws.unmatched({
115
113
  reason: 'unexpected-space',
116
114
  });
117
115
  }
118
- if (!tokens.length) {
119
- return (0, match_result_1.unmatched)(value, 'empty-token');
116
+ if (tokens.length === 0) {
117
+ return unmatched(value, 'empty-token');
120
118
  }
121
- return (0, match_result_1.matched)();
119
+ return matched();
122
120
  },
123
121
  },
124
122
  FunctionBody: {
@@ -130,7 +128,7 @@ exports.types = {
130
128
  },
131
129
  ],
132
130
  // **NO IMPLEMENT PLAN NOW**
133
- is: () => (0, match_result_1.matched)(),
131
+ is: () => matched(),
134
132
  },
135
133
  Pattern: {
136
134
  ref: 'https://html.spec.whatwg.org/multipage/input.html#compiled-pattern-regular-expression',
@@ -145,9 +143,9 @@ exports.types = {
145
143
  new RegExp(`^(?:${value})$`);
146
144
  }
147
145
  catch {
148
- return (0, match_result_1.unmatched)(value);
146
+ return unmatched(value);
149
147
  }
150
- return (0, match_result_1.matched)();
148
+ return matched();
151
149
  },
152
150
  },
153
151
  DateTime: {
@@ -158,7 +156,7 @@ exports.types = {
158
156
  value: 'date time',
159
157
  },
160
158
  ],
161
- is: (0, check_datetime_1.checkDateTime)(),
159
+ is: checkDateTime(),
162
160
  },
163
161
  /**
164
162
  * It doesn't check the meaningless number less than -1
@@ -181,7 +179,7 @@ exports.types = {
181
179
  },
182
180
  ],
183
181
  ref: 'https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex',
184
- is: (0, match_result_1.matches)(value => (0, primitive_1.isInt)(value)),
182
+ is: matches(value => isInt(value)),
185
183
  },
186
184
  BCP47: {
187
185
  expects: [
@@ -191,7 +189,7 @@ exports.types = {
191
189
  },
192
190
  ],
193
191
  ref: 'https://tools.ietf.org/rfc/bcp/bcp47.html',
194
- is: (0, match_result_1.matches)((0, is_bcp_47_1.isBCP47)(), { reason: 'unexpected-token' }),
192
+ is: matches(isBCP47(), { reason: 'unexpected-token' }),
195
193
  },
196
194
  /**
197
195
  * **NO IMPLEMENT NEVER**
@@ -208,11 +206,30 @@ exports.types = {
208
206
  */
209
207
  URL: {
210
208
  ref: 'https://html.spec.whatwg.org/multipage/urls-and-fetching.html#valid-url-potentially-surrounded-by-spaces',
211
- is: () => (0, match_result_1.matched)(),
209
+ is: () => matched(),
210
+ },
211
+ /**
212
+ * Fail if it inclides "data" or "javascript" scheme.
213
+ *
214
+ * > If any of the following are true:
215
+ * > urlRecord is failure;
216
+ * > urlRecord's scheme is "data" or "javascript"; or
217
+ * > running Is base allowed for Document? on urlRecord and document returns "Blocked",
218
+ * > then set element's frozen base URL to document's fallback base URL and return.
219
+ */
220
+ BaseURL: {
221
+ ref: 'https://html.spec.whatwg.org/multipage/semantics.html#set-the-frozen-base-url',
222
+ is(value) {
223
+ value = value.toLowerCase().trim();
224
+ if (value.startsWith('data:') || value.startsWith('javascript:')) {
225
+ return unmatched(value, 'unexpected-token');
226
+ }
227
+ return matched();
228
+ },
212
229
  },
213
230
  AbsoluteURL: {
214
231
  ref: 'https://url.spec.whatwg.org/#syntax-url-absolute',
215
- is: (0, match_result_1.matches)((0, is_abs_url_1.isAbsURL)()),
232
+ is: matches(isAbsURL()),
216
233
  },
217
234
  HashName: {
218
235
  ref: 'https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-hash-name-reference',
@@ -222,7 +239,7 @@ exports.types = {
222
239
  value: 'hash name',
223
240
  },
224
241
  ],
225
- is: value => (value[0] === '#' ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token')),
242
+ is: value => (value[0] === '#' ? matched() : unmatched(value, 'unexpected-token')),
226
243
  },
227
244
  OneCodePointChar: {
228
245
  ref: 'https://html.spec.whatwg.org/multipage/interaction.html#the-accesskey-attribute',
@@ -232,7 +249,7 @@ exports.types = {
232
249
  value: 'one code point character',
233
250
  },
234
251
  ],
235
- is: value => (value.length === 1 ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token')),
252
+ is: value => (value.length === 1 ? matched() : unmatched(value, 'unexpected-token')),
236
253
  },
237
254
  CustomElementName: {
238
255
  ref: 'https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name',
@@ -242,8 +259,22 @@ exports.types = {
242
259
  value: 'custom element name',
243
260
  },
244
261
  ],
245
- is: (0, match_result_1.matches)((0, is_custom_element_name_1.isCustomElementName)()),
262
+ is: matches(isCustomElementName()),
263
+ },
264
+ NavigableTargetName: {
265
+ ref: 'https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name',
266
+ expects: [
267
+ {
268
+ type: 'common',
269
+ value: 'navigable target name',
270
+ },
271
+ ],
272
+ // <iframe name="[HERE]">
273
+ is: matches(isNavigableTargetName()),
246
274
  },
275
+ /**
276
+ * @deprecated Use {@link types.NavigableTargetName} instead.
277
+ */
247
278
  BrowsingContextName: {
248
279
  ref: 'https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-names',
249
280
  expects: [
@@ -252,9 +283,43 @@ exports.types = {
252
283
  value: 'browsing context name',
253
284
  },
254
285
  ],
255
- // <iframe name="[HERE]">
256
- is: (0, match_result_1.matches)((0, is_browser_context_name_1.isBrowserContextName)()),
286
+ is: matches(isBrowserContextName()),
287
+ },
288
+ NavigableTargetNameOrKeyword: {
289
+ ref: 'https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name-or-keyword',
290
+ expects: [
291
+ { type: 'const', value: '_blank' },
292
+ { type: 'const', value: '_self' },
293
+ { type: 'const', value: '_parent' },
294
+ { type: 'const', value: '_top' },
295
+ {
296
+ type: 'common',
297
+ value: 'navigable target name',
298
+ },
299
+ ],
300
+ // <a target="[HERE]">
301
+ is(value) {
302
+ value = value.toLowerCase();
303
+ const keywords = ['_blank', '_self', '_parent', '_top'];
304
+ if (keywords.includes(value)) {
305
+ return matched();
306
+ }
307
+ if (value[0] === '_') {
308
+ const candidate = getCandidate(value, keywords);
309
+ return unmatched(value, 'unexpected-token', { candidate });
310
+ }
311
+ const res = matches(isNavigableTargetName())(value);
312
+ if (!res.matched) {
313
+ // @see https://html.spec.whatwg.org/multipage/semantics.html#get-an-element's-target
314
+ // > If target is not null, and contains an ASCII tab or newline and a U+003C (<), then set target to "_blank".
315
+ return unmatched(value, 'unexpected-token', { fallbackTo: '_blank' });
316
+ }
317
+ return res;
318
+ },
257
319
  },
320
+ /**
321
+ * @deprecated Use {@link types.NavigableTargetNameOrKeyword} instead.
322
+ */
258
323
  BrowsingContextNameOrKeyword: {
259
324
  ref: 'https://html.spec.whatwg.org/multipage/browsers.html#valid-browsing-context-name-or-keyword',
260
325
  expects: [
@@ -267,18 +332,17 @@ exports.types = {
267
332
  value: 'browsing context name',
268
333
  },
269
334
  ],
270
- // <a target="[HERE]">
271
335
  is(value) {
272
336
  value = value.toLowerCase();
273
337
  const keywords = ['_blank', '_self', '_parent', '_top'];
274
338
  if (keywords.includes(value)) {
275
- return (0, match_result_1.matched)();
339
+ return matched();
276
340
  }
277
341
  if (value[0] === '_') {
278
- const candidate = (0, get_candidate_1.getCandidate)(value, keywords);
279
- return (0, match_result_1.unmatched)(value, 'unexpected-token', { candidate });
342
+ const candidate = getCandidate(value, keywords);
343
+ return unmatched(value, 'unexpected-token', { candidate });
280
344
  }
281
- return (0, match_result_1.matches)((0, is_browser_context_name_1.isBrowserContextName)())(value);
345
+ return matches(isBrowserContextName())(value);
282
346
  },
283
347
  },
284
348
  HTTPSchemaURL: {
@@ -290,13 +354,13 @@ exports.types = {
290
354
  },
291
355
  ],
292
356
  is(value) {
293
- if ((0, is_abs_url_1.isAbsURL)()(value)) {
294
- return (0, match_result_1.unmatched)(value, 'unexpected-token');
357
+ if (isAbsURL()(value)) {
358
+ return unmatched(value, 'unexpected-token');
295
359
  }
296
360
  if (/^https?/i.test(value)) {
297
- return (0, match_result_1.matched)();
361
+ return matched();
298
362
  }
299
- return (0, match_result_1.unmatched)(value, 'unexpected-token', {
363
+ return unmatched(value, 'unexpected-token', {
300
364
  expects: [
301
365
  {
302
366
  type: 'format',
@@ -314,7 +378,7 @@ exports.types = {
314
378
  value: 'MIME Type',
315
379
  },
316
380
  ],
317
- is: (0, check_mime_type_1.checkMIMEType)(),
381
+ is: checkMIMEType(),
318
382
  },
319
383
  ItemProp: {
320
384
  ref: 'https://html.spec.whatwg.org/multipage/microdata.html#names:-the-itemprop-attribute',
@@ -329,11 +393,11 @@ exports.types = {
329
393
  },
330
394
  ],
331
395
  is(value) {
332
- const _matched = (0, match_result_1.matched)();
333
- const _unmatched = (0, match_result_1.unmatched)(value, 'unexpected-token');
334
- return (0, check_multi_types_1.checkMultiTypes)(value, [
335
- value => ((0, is_abs_url_1.isAbsURL)()(value) ? _matched : _unmatched),
336
- value => ((0, is_itemprop_name_1.isItempropName)()(value) ? _matched : _unmatched),
396
+ const _matched = matched();
397
+ const _unmatched = unmatched(value, 'unexpected-token');
398
+ return checkMultiTypes(value, [
399
+ value => (isAbsURL()(value) ? _matched : _unmatched),
400
+ value => (isItempropName()(value) ? _matched : _unmatched),
337
401
  ]);
338
402
  },
339
403
  },
@@ -361,11 +425,11 @@ exports.types = {
361
425
  if (!token) {
362
426
  return 0;
363
427
  }
364
- const { num, unit } = (0, primitive_1.splitUnit)(token.value);
428
+ const { num, unit } = splitUnit(token.value);
365
429
  if (unit !== 'w') {
366
430
  return 0;
367
431
  }
368
- if (!(0, primitive_1.isUint)(num)) {
432
+ if (!isUint(num)) {
369
433
  return 0;
370
434
  }
371
435
  return 1;
@@ -374,11 +438,11 @@ exports.types = {
374
438
  if (!token) {
375
439
  return 0;
376
440
  }
377
- const { num, unit } = (0, primitive_1.splitUnit)(token.value);
441
+ const { num, unit } = splitUnit(token.value);
378
442
  if (unit !== 'x') {
379
443
  return 0;
380
444
  }
381
- if (!(0, primitive_1.isFloat)(num)) {
445
+ if (!isFloat(num)) {
382
446
  return 0;
383
447
  }
384
448
  return 1;
@@ -398,8 +462,16 @@ exports.types = {
398
462
  apply: '<source-size-list>',
399
463
  def: {
400
464
  'source-size-list': '[ <source-size># , ]? <source-size-value>',
401
- 'source-size': '<media-condition> <source-size-value>',
402
- 'source-size-value': '<length>',
465
+ 'source-size': '<media-condition> <source-size-value> | auto',
466
+ /**
467
+ * > Percentages are not allowed in a `<source-size-value>`,
468
+ * > to avoid confusion about what it would be relative to.
469
+ * > The 'vw' unit can be used for sizes relative to the viewport width.
470
+ *
471
+ * `<length>` doesn't allow percentages.
472
+ * @see https://csstree.github.io/docs/syntax/#Type:length
473
+ */
474
+ 'source-size-value': '<length> | auto',
403
475
  },
404
476
  },
405
477
  },
@@ -418,12 +490,12 @@ exports.types = {
418
490
  is(value) {
419
491
  value = value.toLowerCase();
420
492
  if (value === 'any') {
421
- return (0, match_result_1.matched)();
493
+ return matched();
422
494
  }
423
- const tokens = new token_1.TokenCollection(value, { specificSeparator: 'x' });
495
+ const tokens = new TokenCollection(value, { specificSeparator: 'x' });
424
496
  const [width, sep, height, ...tail] = tokens;
425
497
  if (!width) {
426
- return (0, match_result_1.unmatched)(value, 'unexpected-token');
498
+ return unmatched(value, 'unexpected-token');
427
499
  }
428
500
  if (!sep) {
429
501
  return width.unmatched({ reason: 'unexpected-token' });
@@ -431,10 +503,10 @@ exports.types = {
431
503
  if (!height) {
432
504
  return sep.unmatched({ reason: 'unexpected-token' });
433
505
  }
434
- if (tail && tail.length) {
506
+ if (tail[0]) {
435
507
  return tail[0].unmatched({ reason: 'extra-token' });
436
508
  }
437
- if (!(0, primitive_1.isUint)(width.value)) {
509
+ if (!isUint(width.value)) {
438
510
  return width.unmatched({ reason: 'unexpected-token' });
439
511
  }
440
512
  if (width.value === '0') {
@@ -443,18 +515,18 @@ exports.types = {
443
515
  if (sep.value !== 'x') {
444
516
  return sep.unmatched({ reason: 'out-of-range' });
445
517
  }
446
- if (!(0, primitive_1.isUint)(height.value)) {
518
+ if (!isUint(height.value)) {
447
519
  return height.unmatched({ reason: 'unexpected-token' });
448
520
  }
449
521
  if (height.value === '0') {
450
522
  return height.unmatched({ reason: 'out-of-range' });
451
523
  }
452
- return (0, match_result_1.matched)();
524
+ return matched();
453
525
  },
454
526
  },
455
527
  AutoComplete: {
456
528
  ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete',
457
- is: (0, check_autocomplete_1.checkAutoComplete)(),
529
+ is: checkAutoComplete(),
458
530
  },
459
531
  Accept: {
460
532
  ref: 'https://html.spec.whatwg.org/multipage/input.html#attr-input-accept',
@@ -484,18 +556,18 @@ exports.types = {
484
556
  is(value) {
485
557
  const extMap = ['audio/*', 'video/*', 'image/*'];
486
558
  if (extMap.includes(value))
487
- return (0, match_result_1.matched)();
559
+ return matched();
488
560
  // A valid MIME type string with no parameters
489
- const mimeMatched = (0, check_mime_type_1.checkMIMEType)({ withoutParameters: true })(value);
561
+ const mimeMatched = checkMIMEType({ withoutParameters: true })(value);
490
562
  if (mimeMatched.matched)
491
- return (0, match_result_1.matched)();
563
+ return matched();
492
564
  // A string whose first character is a U+002E FULL STOP character (.)
493
- return value[0] === '.' && value[1] ? (0, match_result_1.matched)() : mimeMatched;
565
+ return value[0] === '.' && value[1] ? matched() : mimeMatched;
494
566
  },
495
567
  },
496
568
  SerializedPermissionsPolicy: {
497
569
  ref: 'https://w3c.github.io/webappsec-permissions-policy/#serialized-permissions-policy',
498
- is: (0, check_serialized_permissions_policy_1.checkSerializedPermissionsPolicy)(),
570
+ is: checkSerializedPermissionsPolicy(),
499
571
  },
500
572
  '<css-declaration-list>': {
501
573
  ref: 'https://drafts.csswg.org/css-style-attr/#syntax',
@@ -519,52 +591,52 @@ exports.types = {
519
591
  '<svg-font-size>': {
520
592
  ref: 'https://drafts.csswg.org/css-fonts-5/#descdef-font-face-font-size',
521
593
  // TODO:
522
- is: () => (0, match_result_1.matched)(),
594
+ is: () => matched(),
523
595
  },
524
596
  '<svg-font-size-adjust>': {
525
597
  ref: 'https://drafts.csswg.org/css-fonts-5/#propdef-font-size-adjust',
526
598
  // TODO:
527
- is: () => (0, match_result_1.matched)(),
599
+ is: () => matched(),
528
600
  },
529
601
  "<'color-profile'>": {
530
602
  ref: 'https://www.w3.org/TR/SVG11/color.html#ColorProfileProperty',
531
603
  // TODO:
532
- is: () => (0, match_result_1.matched)(),
604
+ is: () => matched(),
533
605
  },
534
606
  "<'color-rendering'>": {
535
607
  ref: 'https://www.w3.org/TR/SVG11/painting.html#ColorRenderingProperty',
536
608
  // TODO:
537
- is: () => (0, match_result_1.matched)(),
609
+ is: () => matched(),
538
610
  },
539
611
  "<'enable-background'>": {
540
612
  ref: 'https://www.w3.org/TR/SVG11/filters.html#EnableBackgroundProperty',
541
613
  // TODO:
542
- is: () => (0, match_result_1.matched)(),
614
+ is: () => matched(),
543
615
  },
544
616
  '<list-of-svg-feature-string>': {
545
617
  ref: 'https://www.w3.org/TR/SVG11/feature.html',
546
618
  // TODO:
547
- is: () => (0, match_result_1.matched)(),
619
+ is: () => matched(),
548
620
  },
549
621
  '<animatable-value>': {
550
622
  ref: 'https://svgwg.org/specs/animations/#FromAttribute',
551
623
  // TODO:
552
- is: () => (0, match_result_1.matched)(),
624
+ is: () => matched(),
553
625
  },
554
626
  '<begin-value-list>': {
555
627
  ref: 'https://svgwg.org/specs/animations/#BeginValueListSyntax',
556
628
  // TODO:
557
- is: () => (0, match_result_1.matched)(),
629
+ is: () => matched(),
558
630
  },
559
631
  '<end-value-list>': {
560
632
  ref: 'https://svgwg.org/specs/animations/#EndValueListSyntax',
561
633
  // TODO:
562
- is: () => (0, match_result_1.matched)(),
634
+ is: () => matched(),
563
635
  },
564
636
  '<list-of-value>': {
565
637
  ref: 'https://svgwg.org/specs/animations/#ValuesAttribute',
566
638
  // TODO:
567
- is: () => (0, match_result_1.matched)(),
639
+ is: () => matched(),
568
640
  },
569
641
  '<clock-value>': {
570
642
  ref: 'https://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-ClockValueSyntax',
@@ -741,13 +813,13 @@ exports.types = {
741
813
  },
742
814
  },
743
815
  };
744
- exports.tokenizers = {
816
+ export const tokenizers = {
745
817
  // RFC
746
818
  // https://tools.ietf.org/rfc/bcp/bcp47.html
747
819
  'bcp-47'(token) {
748
820
  if (!token) {
749
821
  return 0;
750
822
  }
751
- return (0, is_bcp_47_1.isBCP47)()(token.value) ? 1 : 0;
823
+ return isBCP47()(token.value) ? 1 : 0;
752
824
  },
753
825
  };
package/lib/enum.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import type { Result } from './types';
2
- import type { Enum } from './types.schema';
3
- export declare function checkEnum(value: string, type: Enum, ref?: string): Result;
1
+ import type { Result } from './types.js';
2
+ import type { Enum } from './types.schema.js';
3
+ import type { ReadonlyDeep } from 'type-fest';
4
+ export declare function checkEnum(value: string, type: ReadonlyDeep<Enum>, ref?: string): Result;
package/lib/enum.js CHANGED
@@ -1,26 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkEnum = void 0;
4
- const match_result_1 = require("./match-result");
5
- function checkEnum(value, type, ref) {
6
- var _a, _b;
7
- const disallowToSurroundBySpaces = (_a = type.disallowToSurroundBySpaces) !== null && _a !== void 0 ? _a : true;
8
- const caseInsensitive = (_b = type.caseInsensitive) !== null && _b !== void 0 ? _b : true;
1
+ import { matched, unmatched } from './match-result.js';
2
+ export function checkEnum(value, type, ref) {
3
+ const disallowToSurroundBySpaces = type.disallowToSurroundBySpaces ?? true;
4
+ const caseInsensitive = type.caseInsensitive ?? true;
9
5
  if (!disallowToSurroundBySpaces) {
10
6
  value = value.trim();
11
7
  }
12
- let values = type.enum;
8
+ let values = type.enum.slice();
13
9
  if (caseInsensitive) {
14
10
  value = value.toLowerCase();
15
11
  values = type.enum.map(v => v.toLowerCase());
16
12
  }
17
13
  const res = values.includes(value);
18
14
  if (res) {
19
- return (0, match_result_1.matched)();
15
+ return matched();
20
16
  }
21
- return (0, match_result_1.unmatched)(value, 'doesnt-exist-in-enum', {
17
+ return unmatched(value, 'doesnt-exist-in-enum', {
22
18
  ref,
23
19
  expects: type.enum.map(value => ({ type: 'const', value })),
24
20
  });
25
21
  }
26
- exports.checkEnum = checkEnum;
@@ -1,3 +1,3 @@
1
1
  type NullableString = string | null | undefined;
2
- export declare function getCandidate(value: NullableString, ...candidates: (NullableString | NullableString[])[]): string | undefined;
2
+ export declare function getCandidate(value: NullableString, ...candidates: readonly (NullableString | readonly NullableString[])[]): string | undefined;
3
3
  export {};
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCandidate = void 0;
4
- const tslib_1 = require("tslib");
5
- const leven_1 = tslib_1.__importDefault(require("leven"));
6
- function getCandidate(value, ...candidates) {
1
+ import leven from 'leven';
2
+ export function getCandidate(value, ...candidates) {
7
3
  if (!value) {
8
4
  return;
9
5
  }
@@ -11,7 +7,7 @@ function getCandidate(value, ...candidates) {
11
7
  let candidate;
12
8
  let maxRatio = 0;
13
9
  list.forEach(word => {
14
- const dist = (0, leven_1.default)(value.trim().toLowerCase(), word.trim().toLowerCase());
10
+ const dist = leven(value.trim().toLowerCase(), word.trim().toLowerCase());
15
11
  const ratio = 1 - dist / word.length;
16
12
  if (0.5 <= ratio && maxRatio < ratio) {
17
13
  candidate = word;
@@ -23,4 +19,3 @@ function getCandidate(value, ...candidates) {
23
19
  }
24
20
  return candidate;
25
21
  }
26
- exports.getCandidate = getCandidate;
package/lib/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './whatwg/is-custom-element-name';
2
- export * from './check';
3
- export * from './types';
1
+ export * from './whatwg/is-custom-element-name.js';
2
+ export * from './check.js';
3
+ export * from './types.js';
package/lib/index.js CHANGED
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./whatwg/is-custom-element-name"), exports);
5
- tslib_1.__exportStar(require("./check"), exports);
6
- tslib_1.__exportStar(require("./types"), exports);
1
+ export * from './whatwg/is-custom-element-name.js';
2
+ export * from './check.js';
3
+ export * from './types.js';
@@ -1,3 +1,3 @@
1
- import type { Result } from './types';
2
- import type { KeywordDefinedType } from './types.schema';
1
+ import type { Result } from './types.js';
2
+ import type { KeywordDefinedType } from './types.schema.js';
3
3
  export declare function checkKeywordType(value: string, type: KeywordDefinedType, cache?: boolean): Result;