@markuplint/types 3.12.0 → 4.0.0-alpha.10

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 (101) hide show
  1. package/LICENSE +1 -1
  2. package/lib/check-multi-types.d.ts +2 -5
  3. package/lib/check-multi-types.js +9 -14
  4. package/lib/check.d.ts +1 -1
  5. package/lib/check.js +20 -30
  6. package/lib/css-syntax.d.ts +1 -1
  7. package/lib/css-syntax.js +33 -33
  8. package/lib/debug.js +2 -6
  9. package/lib/defs.d.ts +2 -1
  10. package/lib/defs.js +188 -138
  11. package/lib/enum.d.ts +2 -2
  12. package/lib/enum.js +7 -12
  13. package/lib/get-candidate.d.ts +1 -4
  14. package/lib/get-candidate.js +5 -10
  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 +20 -25
  19. package/lib/list.d.ts +2 -2
  20. package/lib/list.js +9 -14
  21. package/lib/match-result.d.ts +8 -21
  22. package/lib/match-result.js +6 -13
  23. package/lib/number.d.ts +3 -3
  24. package/lib/number.js +13 -17
  25. package/lib/primitive/index.d.ts +7 -7
  26. package/lib/primitive/index.js +7 -17
  27. package/lib/primitive/is-float.js +2 -6
  28. package/lib/primitive/is-int.js +2 -6
  29. package/lib/primitive/is-non-zero-uint.js +2 -6
  30. package/lib/primitive/is-quantity.d.ts +1 -5
  31. package/lib/primitive/is-quantity.js +9 -13
  32. package/lib/primitive/is-uint.d.ts +3 -6
  33. package/lib/primitive/is-uint.js +4 -8
  34. package/lib/primitive/range.js +3 -7
  35. package/lib/primitive/split-unit.d.ts +2 -2
  36. package/lib/primitive/split-unit.js +4 -8
  37. package/lib/rfc/is-bcp-47.d.ts +1 -1
  38. package/lib/rfc/is-bcp-47.js +3 -7
  39. package/lib/token/index.d.ts +2 -2
  40. package/lib/token/index.js +2 -7
  41. package/lib/token/token-collection.d.ts +58 -70
  42. package/lib/token/token-collection.js +47 -56
  43. package/lib/token/token.d.ts +54 -59
  44. package/lib/token/token.js +14 -20
  45. package/lib/token/types.js +1 -2
  46. package/lib/types.d.ts +58 -82
  47. package/lib/types.js +1 -2
  48. package/lib/types.schema.d.ts +31 -1087
  49. package/lib/types.schema.js +1 -2
  50. package/lib/w3c/check-serialized-permissions-policy.d.ts +1 -1
  51. package/lib/w3c/check-serialized-permissions-policy.js +21 -25
  52. package/lib/whatwg/check-autocomplete.d.ts +1 -1
  53. package/lib/whatwg/check-autocomplete.js +34 -41
  54. package/lib/whatwg/check-datetime/date-string.d.ts +1 -1
  55. package/lib/whatwg/check-datetime/date-string.js +12 -16
  56. package/lib/whatwg/check-datetime/datetime-tokens.d.ts +2 -22
  57. package/lib/whatwg/check-datetime/datetime-tokens.js +58 -64
  58. package/lib/whatwg/check-datetime/duration-string.d.ts +1 -1
  59. package/lib/whatwg/check-datetime/duration-string.js +64 -69
  60. package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +1 -1
  61. package/lib/whatwg/check-datetime/global-date-and-time-string.js +24 -28
  62. package/lib/whatwg/check-datetime/index.d.ts +1 -1
  63. package/lib/whatwg/check-datetime/index.js +25 -29
  64. package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +1 -1
  65. package/lib/whatwg/check-datetime/local-date-and-time-string.js +37 -41
  66. package/lib/whatwg/check-datetime/month-string.d.ts +1 -1
  67. package/lib/whatwg/check-datetime/month-string.js +9 -13
  68. package/lib/whatwg/check-datetime/time-string.d.ts +1 -1
  69. package/lib/whatwg/check-datetime/time-string.js +13 -17
  70. package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +3 -3
  71. package/lib/whatwg/check-datetime/time-zone-offset-string.js +22 -28
  72. package/lib/whatwg/check-datetime/week-string.d.ts +1 -1
  73. package/lib/whatwg/check-datetime/week-string.js +11 -15
  74. package/lib/whatwg/check-datetime/year-string.d.ts +1 -1
  75. package/lib/whatwg/check-datetime/year-string.js +9 -13
  76. package/lib/whatwg/check-datetime/yearless-date-string.d.ts +1 -1
  77. package/lib/whatwg/check-datetime/yearless-date-string.js +11 -15
  78. package/lib/whatwg/check-mime-type.d.ts +5 -5
  79. package/lib/whatwg/check-mime-type.js +11 -17
  80. package/lib/whatwg/is-abs-url.d.ts +1 -1
  81. package/lib/whatwg/is-abs-url.js +8 -12
  82. package/lib/whatwg/is-browser-context-name.d.ts +1 -1
  83. package/lib/whatwg/is-browser-context-name.js +1 -5
  84. package/lib/whatwg/is-custom-element-name.d.ts +10 -5
  85. package/lib/whatwg/is-custom-element-name.js +22 -38
  86. package/lib/whatwg/is-itemprop-name.d.ts +1 -1
  87. package/lib/whatwg/is-itemprop-name.js +1 -5
  88. package/lib/whatwg/is-navigable-target-name.d.ts +1 -1
  89. package/lib/whatwg/is-navigable-target-name.js +1 -5
  90. package/package.json +17 -9
  91. package/test/check.spec.js +0 -89
  92. package/test/css-syntax.spec.js +0 -170
  93. package/test/list.spec.js +0 -133
  94. package/test/primitive/index.spec.js +0 -65
  95. package/test/rfc/is-bcp-47.spec.js +0 -23
  96. package/test/token/token-collection.spec.js +0 -146
  97. package/test/w3c/check-serialized-permissions-policy.spec.js +0 -36
  98. package/test/whatwg/check-autocomplete.spec.js +0 -387
  99. package/test/whatwg/check-datetime/index.spec.js +0 -336
  100. package/test/whatwg/check-mime-type.spec.js +0 -59
  101. package/test/whatwg/is-abs-url.spec.js +0 -8
package/lib/defs.js CHANGED
@@ -1,34 +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
- const is_navigable_target_name_1 = require("./whatwg/is-navigable-target-name");
19
- 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 = {
20
17
  Any: {
21
18
  ref: '',
22
- is: () => (0, match_result_1.matched)(),
19
+ is: () => matched(),
23
20
  },
24
21
  NoEmptyAny: {
25
22
  ref: '',
26
- is: value => (0 < value.length ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'empty-token')),
23
+ is: value => (value.length > 0 ? matched() : unmatched(value, 'empty-token')),
27
24
  },
28
25
  OneLineAny: {
29
26
  ref: '',
30
27
  is: value => {
31
- const tokens = new token_1.TokenCollection(value);
28
+ const tokens = new TokenCollection(value);
32
29
  /**
33
30
  * @see https://infra.spec.whatwg.org/#ascii-tab-or-newline
34
31
  */
@@ -39,7 +36,7 @@ exports.types = {
39
36
  reason: 'unexpected-newline',
40
37
  });
41
38
  }
42
- return (0, match_result_1.matched)();
39
+ return matched();
43
40
  },
44
41
  },
45
42
  Zero: {
@@ -50,7 +47,7 @@ exports.types = {
50
47
  value: 'zero',
51
48
  },
52
49
  ],
53
- 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')),
54
51
  },
55
52
  Number: {
56
53
  ref: '',
@@ -60,7 +57,7 @@ exports.types = {
60
57
  value: 'number',
61
58
  },
62
59
  ],
63
- 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')),
64
61
  },
65
62
  Int: {
66
63
  ref: '',
@@ -70,7 +67,7 @@ exports.types = {
70
67
  value: 'integer',
71
68
  },
72
69
  ],
73
- 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')),
74
71
  },
75
72
  Uint: {
76
73
  ref: '',
@@ -80,7 +77,7 @@ exports.types = {
80
77
  value: 'non-negative integer',
81
78
  },
82
79
  ],
83
- 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')),
84
81
  },
85
82
  XMLName: {
86
83
  ref: 'https://www.w3.org/TR/xml/#NT-Name',
@@ -91,13 +88,15 @@ exports.types = {
91
88
  },
92
89
  ],
93
90
  is: value => {
94
- // NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
95
- const nameStartChar = /[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]/u;
96
- // NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
97
- const nameCharTail = /-|[.0-9\u00B7]|[\u0300-\u036F\u203F-\u2040]/;
98
- // Name ::= NameStartChar (NameChar)*
99
- const name = RegExp(`(?:${nameStartChar.source})(?:${nameCharTail})*`, 'u');
100
- return name.test(value) ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token');
91
+ /**
92
+ * NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
93
+ * NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
94
+ * Name ::= NameStartChar (NameChar)*
95
+ */
96
+ const name =
97
+ // eslint-disable-next-line no-misleading-character-class
98
+ /[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}][\d.\u00B7\u0300-\u036F\u203F\u2040-]*/u;
99
+ return name.test(value) ? matched() : unmatched(value, 'unexpected-token');
101
100
  },
102
101
  },
103
102
  DOMID: {
@@ -109,17 +108,17 @@ exports.types = {
109
108
  },
110
109
  ],
111
110
  is: value => {
112
- const tokens = new token_1.TokenCollection(value);
113
- const ws = tokens.search(token_1.Token.WhiteSpace);
111
+ const tokens = new TokenCollection(value);
112
+ const ws = tokens.search(Token.WhiteSpace);
114
113
  if (ws) {
115
114
  return ws.unmatched({
116
115
  reason: 'unexpected-space',
117
116
  });
118
117
  }
119
118
  if (tokens.length === 0) {
120
- return (0, match_result_1.unmatched)(value, 'empty-token');
119
+ return unmatched(value, 'empty-token');
121
120
  }
122
- return (0, match_result_1.matched)();
121
+ return matched();
123
122
  },
124
123
  },
125
124
  FunctionBody: {
@@ -131,7 +130,7 @@ exports.types = {
131
130
  },
132
131
  ],
133
132
  // **NO IMPLEMENT PLAN NOW**
134
- is: () => (0, match_result_1.matched)(),
133
+ is: () => matched(),
135
134
  },
136
135
  Pattern: {
137
136
  ref: 'https://html.spec.whatwg.org/multipage/input.html#compiled-pattern-regular-expression',
@@ -146,9 +145,9 @@ exports.types = {
146
145
  new RegExp(`^(?:${value})$`);
147
146
  }
148
147
  catch {
149
- return (0, match_result_1.unmatched)(value);
148
+ return unmatched(value);
150
149
  }
151
- return (0, match_result_1.matched)();
150
+ return matched();
152
151
  },
153
152
  },
154
153
  DateTime: {
@@ -159,7 +158,7 @@ exports.types = {
159
158
  value: 'date time',
160
159
  },
161
160
  ],
162
- is: (0, check_datetime_1.checkDateTime)(),
161
+ is: checkDateTime(),
163
162
  },
164
163
  /**
165
164
  * It doesn't check the meaningless number less than -1
@@ -182,7 +181,7 @@ exports.types = {
182
181
  },
183
182
  ],
184
183
  ref: 'https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex',
185
- is: (0, match_result_1.matches)(value => (0, primitive_1.isInt)(value)),
184
+ is: matches(value => isInt(value)),
186
185
  },
187
186
  BCP47: {
188
187
  expects: [
@@ -192,7 +191,7 @@ exports.types = {
192
191
  },
193
192
  ],
194
193
  ref: 'https://tools.ietf.org/rfc/bcp/bcp47.html',
195
- is: (0, match_result_1.matches)((0, is_bcp_47_1.isBCP47)(), { reason: 'unexpected-token' }),
194
+ is: matches(isBCP47(), { reason: 'unexpected-token' }),
196
195
  },
197
196
  /**
198
197
  * **NO IMPLEMENT NEVER**
@@ -209,7 +208,7 @@ exports.types = {
209
208
  */
210
209
  URL: {
211
210
  ref: 'https://html.spec.whatwg.org/multipage/urls-and-fetching.html#valid-url-potentially-surrounded-by-spaces',
212
- is: () => (0, match_result_1.matched)(),
211
+ is: () => matched(),
213
212
  },
214
213
  /**
215
214
  * Fail if it inclides "data" or "javascript" scheme.
@@ -225,14 +224,14 @@ exports.types = {
225
224
  is(value) {
226
225
  value = value.toLowerCase().trim();
227
226
  if (value.startsWith('data:') || value.startsWith('javascript:')) {
228
- return (0, match_result_1.unmatched)(value, 'unexpected-token');
227
+ return unmatched(value, 'unexpected-token');
229
228
  }
230
- return (0, match_result_1.matched)();
229
+ return matched();
231
230
  },
232
231
  },
233
232
  AbsoluteURL: {
234
233
  ref: 'https://url.spec.whatwg.org/#syntax-url-absolute',
235
- is: (0, match_result_1.matches)((0, is_abs_url_1.isAbsURL)()),
234
+ is: matches(isAbsURL()),
236
235
  },
237
236
  HashName: {
238
237
  ref: 'https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-hash-name-reference',
@@ -242,7 +241,7 @@ exports.types = {
242
241
  value: 'hash name',
243
242
  },
244
243
  ],
245
- is: value => (value[0] === '#' ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token')),
244
+ is: value => (value[0] === '#' ? matched() : unmatched(value, 'unexpected-token')),
246
245
  },
247
246
  OneCodePointChar: {
248
247
  ref: 'https://html.spec.whatwg.org/multipage/interaction.html#the-accesskey-attribute',
@@ -252,7 +251,7 @@ exports.types = {
252
251
  value: 'one code point character',
253
252
  },
254
253
  ],
255
- is: value => (value.length === 1 ? (0, match_result_1.matched)() : (0, match_result_1.unmatched)(value, 'unexpected-token')),
254
+ is: value => (value.length === 1 ? matched() : unmatched(value, 'unexpected-token')),
256
255
  },
257
256
  CustomElementName: {
258
257
  ref: 'https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name',
@@ -262,7 +261,7 @@ exports.types = {
262
261
  value: 'custom element name',
263
262
  },
264
263
  ],
265
- is: (0, match_result_1.matches)((0, is_custom_element_name_1.isCustomElementName)()),
264
+ is: matches(isCustomElementName()),
266
265
  },
267
266
  NavigableTargetName: {
268
267
  ref: 'https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name',
@@ -273,7 +272,7 @@ exports.types = {
273
272
  },
274
273
  ],
275
274
  // <iframe name="[HERE]">
276
- is: (0, match_result_1.matches)((0, is_navigable_target_name_1.isNavigableTargetName)()),
275
+ is: matches(isNavigableTargetName()),
277
276
  },
278
277
  /**
279
278
  * @deprecated Use {@link types.NavigableTargetName} instead.
@@ -286,7 +285,7 @@ exports.types = {
286
285
  value: 'browsing context name',
287
286
  },
288
287
  ],
289
- is: (0, match_result_1.matches)((0, is_browser_context_name_1.isBrowserContextName)()),
288
+ is: matches(isBrowserContextName()),
290
289
  },
291
290
  NavigableTargetNameOrKeyword: {
292
291
  ref: 'https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name-or-keyword',
@@ -305,17 +304,17 @@ exports.types = {
305
304
  value = value.toLowerCase();
306
305
  const keywords = ['_blank', '_self', '_parent', '_top'];
307
306
  if (keywords.includes(value)) {
308
- return (0, match_result_1.matched)();
307
+ return matched();
309
308
  }
310
309
  if (value[0] === '_') {
311
- const candidate = (0, get_candidate_1.getCandidate)(value, keywords);
312
- return (0, match_result_1.unmatched)(value, 'unexpected-token', { candidate });
310
+ const candidate = getCandidate(value, keywords);
311
+ return unmatched(value, 'unexpected-token', { candidate });
313
312
  }
314
- const res = (0, match_result_1.matches)((0, is_navigable_target_name_1.isNavigableTargetName)())(value);
313
+ const res = matches(isNavigableTargetName())(value);
315
314
  if (!res.matched) {
316
315
  // @see https://html.spec.whatwg.org/multipage/semantics.html#get-an-element's-target
317
316
  // > If target is not null, and contains an ASCII tab or newline and a U+003C (<), then set target to "_blank".
318
- return (0, match_result_1.unmatched)(value, 'unexpected-token', { fallbackTo: '_blank' });
317
+ return unmatched(value, 'unexpected-token', { fallbackTo: '_blank' });
319
318
  }
320
319
  return res;
321
320
  },
@@ -339,13 +338,13 @@ exports.types = {
339
338
  value = value.toLowerCase();
340
339
  const keywords = ['_blank', '_self', '_parent', '_top'];
341
340
  if (keywords.includes(value)) {
342
- return (0, match_result_1.matched)();
341
+ return matched();
343
342
  }
344
343
  if (value[0] === '_') {
345
- const candidate = (0, get_candidate_1.getCandidate)(value, keywords);
346
- return (0, match_result_1.unmatched)(value, 'unexpected-token', { candidate });
344
+ const candidate = getCandidate(value, keywords);
345
+ return unmatched(value, 'unexpected-token', { candidate });
347
346
  }
348
- return (0, match_result_1.matches)((0, is_browser_context_name_1.isBrowserContextName)())(value);
347
+ return matches(isBrowserContextName())(value);
349
348
  },
350
349
  },
351
350
  HTTPSchemaURL: {
@@ -357,13 +356,13 @@ exports.types = {
357
356
  },
358
357
  ],
359
358
  is(value) {
360
- if ((0, is_abs_url_1.isAbsURL)()(value)) {
361
- return (0, match_result_1.unmatched)(value, 'unexpected-token');
359
+ if (isAbsURL()(value)) {
360
+ return unmatched(value, 'unexpected-token');
362
361
  }
363
362
  if (/^https?/i.test(value)) {
364
- return (0, match_result_1.matched)();
363
+ return matched();
365
364
  }
366
- return (0, match_result_1.unmatched)(value, 'unexpected-token', {
365
+ return unmatched(value, 'unexpected-token', {
367
366
  expects: [
368
367
  {
369
368
  type: 'format',
@@ -381,7 +380,7 @@ exports.types = {
381
380
  value: 'MIME Type',
382
381
  },
383
382
  ],
384
- is: (0, check_mime_type_1.checkMIMEType)(),
383
+ is: checkMIMEType(),
385
384
  },
386
385
  ItemProp: {
387
386
  ref: 'https://html.spec.whatwg.org/multipage/microdata.html#names:-the-itemprop-attribute',
@@ -396,61 +395,91 @@ exports.types = {
396
395
  },
397
396
  ],
398
397
  is(value) {
399
- const _matched = (0, match_result_1.matched)();
400
- const _unmatched = (0, match_result_1.unmatched)(value, 'unexpected-token');
401
- return (0, check_multi_types_1.checkMultiTypes)(value, [
402
- value => ((0, is_abs_url_1.isAbsURL)()(value) ? _matched : _unmatched),
403
- value => ((0, is_itemprop_name_1.isItempropName)()(value) ? _matched : _unmatched),
398
+ const _matched = matched();
399
+ const _unmatched = unmatched(value, 'unexpected-token');
400
+ return checkMultiTypes(value, [
401
+ value => (isAbsURL()(value) ? _matched : _unmatched),
402
+ value => (isItempropName()(value) ? _matched : _unmatched),
404
403
  ]);
405
404
  },
406
405
  },
407
406
  Srcset: {
408
407
  ref: 'https://html.spec.whatwg.org/multipage/images.html#srcset-attributes',
409
- syntax: {
410
- apply: '<srcset>',
411
- def: {
412
- srcset: '<image-candidate-strings> [, <image-candidate-strings>]*',
413
- 'image-candidate-strings': '<valid-non-empty-url> [ <width-descriptor> | <pixel-density-descriptor> ]?',
414
- 'valid-non-empty-url'(token, getNextToken) {
415
- if (!token) {
416
- return 0;
417
- }
418
- let willAdoptTokenLength = 0;
419
- do {
420
- if (token.type === 13) {
408
+ is(value) {
409
+ const images = value.split(',');
410
+ for (const image of images) {
411
+ // image candidate string
412
+ const [url, , descriptor, ...tail] = new TokenCollection(image.trim(), {
413
+ disallowToSurroundBySpaces: true,
414
+ separator: 'space',
415
+ });
416
+ if (!url) {
417
+ return unmatched(value, 'unexpected-token', {
418
+ expects: [
419
+ {
420
+ type: 'format',
421
+ value: 'valid non-empty URL',
422
+ },
423
+ ],
424
+ });
425
+ }
426
+ if (descriptor) {
427
+ const { num, unit } = splitUnit(descriptor.value);
428
+ switch (unit) {
429
+ case 'w': {
430
+ if (!isUint(num)) {
431
+ return unmatched(value, 'unexpected-token', {
432
+ expects: [
433
+ {
434
+ type: 'format',
435
+ value: 'width descriptor',
436
+ },
437
+ ],
438
+ });
439
+ }
421
440
  break;
422
441
  }
423
- willAdoptTokenLength++;
424
- } while ((token = getNextToken(willAdoptTokenLength)));
425
- return willAdoptTokenLength;
426
- },
427
- 'width-descriptor'(token) {
428
- if (!token) {
429
- return 0;
430
- }
431
- const { num, unit } = (0, primitive_1.splitUnit)(token.value);
432
- if (unit !== 'w') {
433
- return 0;
434
- }
435
- if (!(0, primitive_1.isUint)(num)) {
436
- return 0;
437
- }
438
- return 1;
439
- },
440
- 'pixel-density-descriptor'(token) {
441
- if (!token) {
442
- return 0;
443
- }
444
- const { num, unit } = (0, primitive_1.splitUnit)(token.value);
445
- if (unit !== 'x') {
446
- return 0;
447
- }
448
- if (!(0, primitive_1.isFloat)(num)) {
449
- return 0;
442
+ case 'x': {
443
+ if (!isFloat(num)) {
444
+ return unmatched(value, 'unexpected-token', {
445
+ expects: [
446
+ {
447
+ type: 'format',
448
+ value: 'pixel density descriptor',
449
+ },
450
+ ],
451
+ });
452
+ }
453
+ break;
454
+ }
455
+ default: {
456
+ return unmatched(value, 'unexpected-token', {
457
+ expects: [
458
+ {
459
+ type: 'format',
460
+ value: 'width descriptor',
461
+ },
462
+ {
463
+ type: 'format',
464
+ value: 'pixel density descriptor',
465
+ },
466
+ ],
467
+ });
468
+ }
450
469
  }
451
- return 1;
452
- },
453
- },
470
+ }
471
+ if (tail[0]) {
472
+ return unmatched(value, 'unexpected-token', {
473
+ expects: [
474
+ {
475
+ type: 'syntax',
476
+ value: 'image candidate string',
477
+ },
478
+ ],
479
+ });
480
+ }
481
+ }
482
+ return matched();
454
483
  },
455
484
  },
456
485
  SourceSizeList: {
@@ -493,12 +522,12 @@ exports.types = {
493
522
  is(value) {
494
523
  value = value.toLowerCase();
495
524
  if (value === 'any') {
496
- return (0, match_result_1.matched)();
525
+ return matched();
497
526
  }
498
- const tokens = new token_1.TokenCollection(value, { specificSeparator: 'x' });
527
+ const tokens = new TokenCollection(value, { specificSeparator: 'x' });
499
528
  const [width, sep, height, ...tail] = tokens;
500
529
  if (!width) {
501
- return (0, match_result_1.unmatched)(value, 'unexpected-token');
530
+ return unmatched(value, 'unexpected-token');
502
531
  }
503
532
  if (!sep) {
504
533
  return width.unmatched({ reason: 'unexpected-token' });
@@ -509,7 +538,7 @@ exports.types = {
509
538
  if (tail[0]) {
510
539
  return tail[0].unmatched({ reason: 'extra-token' });
511
540
  }
512
- if (!(0, primitive_1.isUint)(width.value)) {
541
+ if (!isUint(width.value)) {
513
542
  return width.unmatched({ reason: 'unexpected-token' });
514
543
  }
515
544
  if (width.value === '0') {
@@ -518,18 +547,18 @@ exports.types = {
518
547
  if (sep.value !== 'x') {
519
548
  return sep.unmatched({ reason: 'out-of-range' });
520
549
  }
521
- if (!(0, primitive_1.isUint)(height.value)) {
550
+ if (!isUint(height.value)) {
522
551
  return height.unmatched({ reason: 'unexpected-token' });
523
552
  }
524
553
  if (height.value === '0') {
525
554
  return height.unmatched({ reason: 'out-of-range' });
526
555
  }
527
- return (0, match_result_1.matched)();
556
+ return matched();
528
557
  },
529
558
  },
530
559
  AutoComplete: {
531
560
  ref: 'https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete',
532
- is: (0, check_autocomplete_1.checkAutoComplete)(),
561
+ is: checkAutoComplete(),
533
562
  },
534
563
  Accept: {
535
564
  ref: 'https://html.spec.whatwg.org/multipage/input.html#attr-input-accept',
@@ -559,18 +588,18 @@ exports.types = {
559
588
  is(value) {
560
589
  const extMap = ['audio/*', 'video/*', 'image/*'];
561
590
  if (extMap.includes(value))
562
- return (0, match_result_1.matched)();
591
+ return matched();
563
592
  // A valid MIME type string with no parameters
564
- const mimeMatched = (0, check_mime_type_1.checkMIMEType)({ withoutParameters: true })(value);
593
+ const mimeMatched = checkMIMEType({ withoutParameters: true })(value);
565
594
  if (mimeMatched.matched)
566
- return (0, match_result_1.matched)();
595
+ return matched();
567
596
  // A string whose first character is a U+002E FULL STOP character (.)
568
- return value[0] === '.' && value[1] ? (0, match_result_1.matched)() : mimeMatched;
597
+ return value[0] === '.' && value[1] ? matched() : mimeMatched;
569
598
  },
570
599
  },
571
600
  SerializedPermissionsPolicy: {
572
601
  ref: 'https://w3c.github.io/webappsec-permissions-policy/#serialized-permissions-policy',
573
- is: (0, check_serialized_permissions_policy_1.checkSerializedPermissionsPolicy)(),
602
+ is: checkSerializedPermissionsPolicy(),
574
603
  },
575
604
  '<css-declaration-list>': {
576
605
  ref: 'https://drafts.csswg.org/css-style-attr/#syntax',
@@ -594,52 +623,52 @@ exports.types = {
594
623
  '<svg-font-size>': {
595
624
  ref: 'https://drafts.csswg.org/css-fonts-5/#descdef-font-face-font-size',
596
625
  // TODO:
597
- is: () => (0, match_result_1.matched)(),
626
+ is: () => matched(),
598
627
  },
599
628
  '<svg-font-size-adjust>': {
600
629
  ref: 'https://drafts.csswg.org/css-fonts-5/#propdef-font-size-adjust',
601
630
  // TODO:
602
- is: () => (0, match_result_1.matched)(),
631
+ is: () => matched(),
603
632
  },
604
633
  "<'color-profile'>": {
605
634
  ref: 'https://www.w3.org/TR/SVG11/color.html#ColorProfileProperty',
606
635
  // TODO:
607
- is: () => (0, match_result_1.matched)(),
636
+ is: () => matched(),
608
637
  },
609
638
  "<'color-rendering'>": {
610
639
  ref: 'https://www.w3.org/TR/SVG11/painting.html#ColorRenderingProperty',
611
640
  // TODO:
612
- is: () => (0, match_result_1.matched)(),
641
+ is: () => matched(),
613
642
  },
614
643
  "<'enable-background'>": {
615
644
  ref: 'https://www.w3.org/TR/SVG11/filters.html#EnableBackgroundProperty',
616
645
  // TODO:
617
- is: () => (0, match_result_1.matched)(),
646
+ is: () => matched(),
618
647
  },
619
648
  '<list-of-svg-feature-string>': {
620
649
  ref: 'https://www.w3.org/TR/SVG11/feature.html',
621
650
  // TODO:
622
- is: () => (0, match_result_1.matched)(),
651
+ is: () => matched(),
623
652
  },
624
653
  '<animatable-value>': {
625
654
  ref: 'https://svgwg.org/specs/animations/#FromAttribute',
626
655
  // TODO:
627
- is: () => (0, match_result_1.matched)(),
656
+ is: () => matched(),
628
657
  },
629
658
  '<begin-value-list>': {
630
659
  ref: 'https://svgwg.org/specs/animations/#BeginValueListSyntax',
631
660
  // TODO:
632
- is: () => (0, match_result_1.matched)(),
661
+ is: () => matched(),
633
662
  },
634
663
  '<end-value-list>': {
635
664
  ref: 'https://svgwg.org/specs/animations/#EndValueListSyntax',
636
665
  // TODO:
637
- is: () => (0, match_result_1.matched)(),
666
+ is: () => matched(),
638
667
  },
639
668
  '<list-of-value>': {
640
669
  ref: 'https://svgwg.org/specs/animations/#ValuesAttribute',
641
670
  // TODO:
642
- is: () => (0, match_result_1.matched)(),
671
+ is: () => matched(),
643
672
  },
644
673
  '<clock-value>': {
645
674
  ref: 'https://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-ClockValueSyntax',
@@ -816,13 +845,34 @@ exports.types = {
816
845
  },
817
846
  },
818
847
  };
819
- exports.tokenizers = {
848
+ export const overrides = {
849
+ // Alias
850
+ 'legacy-length-percentage': '<length> | <percentage> | <svg-length>',
851
+ 'legacy-angle': '<angle> | <zero> | <number>',
852
+ /**
853
+ * @see https://www.w3.org/TR/css-transforms-1/#funcdef-transform-translate
854
+ */
855
+ 'translate()': 'translate( <legacy-length-percentage> , <legacy-length-percentage>? ) | translate( <legacy-length-percentage> <legacy-length-percentage>? )',
856
+ /**
857
+ * @see https://www.w3.org/TR/css-transforms-1/#funcdef-transform-scale
858
+ */
859
+ 'scale()': 'scale( [ <number> | <percentage> ]#{1,2} )',
860
+ /**
861
+ * @see https://www.w3.org/TR/css-transforms-1/#funcdef-transform-rotate
862
+ */
863
+ 'rotate()': 'rotate( <legacy-angle> )',
864
+ /**
865
+ * @see https://www.w3.org/TR/css-transforms-1/#funcdef-transform-skew
866
+ */
867
+ 'skew()': 'skew( <legacy-angle> , <legacy-angle>? ) | skew( <legacy-angle> <legacy-angle>? )',
868
+ };
869
+ export const tokenizers = {
820
870
  // RFC
821
871
  // https://tools.ietf.org/rfc/bcp/bcp47.html
822
872
  'bcp-47'(token) {
823
873
  if (!token) {
824
874
  return 0;
825
875
  }
826
- return (0, is_bcp_47_1.isBCP47)()(token.value) ? 1 : 0;
876
+ return isBCP47()(token.value) ? 1 : 0;
827
877
  },
828
878
  };
package/lib/enum.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Result } from './types';
2
- import type { Enum } from './types.schema';
1
+ import type { Result } from './types.js';
2
+ import type { Enum } from './types.schema.js';
3
3
  import type { ReadonlyDeep } from 'type-fest';
4
4
  export declare function checkEnum(value: string, type: ReadonlyDeep<Enum>, ref?: string): Result;