@markuplint/types 5.0.0-rc.2 → 5.0.0-rc.5
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.
- package/CHANGELOG.md +38 -0
- package/README.md +83 -75
- package/lib/check-multi-types.d.ts +2 -9
- package/lib/check-multi-types.js +2 -9
- package/lib/css-defs.d.ts +0 -8
- package/lib/css-defs.js +0 -8
- package/lib/css-overrides.d.ts +2 -5
- package/lib/css-overrides.js +2 -5
- package/lib/css-syntax.d.ts +0 -11
- package/lib/css-syntax.js +6 -18
- package/lib/css-tokenizers.d.ts +0 -6
- package/lib/css-tokenizers.js +0 -6
- package/lib/debug.d.ts +0 -3
- package/lib/debug.js +0 -3
- package/lib/defs.d.ts +0 -8
- package/lib/defs.js +308 -37
- package/lib/directive.d.ts +0 -14
- package/lib/directive.js +0 -14
- package/lib/enum.d.ts +0 -11
- package/lib/enum.js +0 -11
- package/lib/keyword-type.d.ts +0 -13
- package/lib/keyword-type.js +0 -13
- package/lib/list.d.ts +0 -13
- package/lib/list.js +0 -13
- package/lib/match-result.d.ts +0 -21
- package/lib/match-result.js +0 -21
- package/lib/number.d.ts +0 -12
- package/lib/number.js +0 -12
- package/lib/primitive/is-float.d.ts +3 -4
- package/lib/primitive/is-float.js +3 -4
- package/lib/primitive/is-int.d.ts +0 -5
- package/lib/primitive/is-int.js +0 -5
- package/lib/primitive/is-non-zero-uint.d.ts +0 -6
- package/lib/primitive/is-non-zero-uint.js +0 -6
- package/lib/primitive/is-quantity.d.ts +0 -8
- package/lib/primitive/is-quantity.js +0 -8
- package/lib/primitive/is-uint.d.ts +0 -6
- package/lib/primitive/is-uint.js +0 -6
- package/lib/primitive/range.d.ts +0 -8
- package/lib/primitive/range.js +0 -8
- package/lib/primitive/split-unit.d.ts +0 -6
- package/lib/primitive/split-unit.js +0 -6
- package/lib/rfc/is-bcp-47.d.ts +24 -1
- package/lib/rfc/is-bcp-47.js +88 -3
- package/lib/token/token-collection.d.ts +1 -111
- package/lib/token/token-collection.js +0 -108
- package/lib/token/token.d.ts +1 -73
- package/lib/token/token.js +0 -72
- package/lib/token/types.d.ts +0 -9
- package/lib/types.schema.d.ts +1 -1
- package/lib/w3c/check-content-security-policy.d.ts +18 -0
- package/lib/w3c/check-content-security-policy.js +363 -0
- package/lib/w3c/check-serialized-permissions-policy.d.ts +0 -2
- package/lib/w3c/check-serialized-permissions-policy.js +0 -2
- package/lib/whatwg/check-autocomplete.d.ts +26 -9
- package/lib/whatwg/check-autocomplete.js +42 -15
- package/lib/whatwg/check-datetime/date-string-with-optional-time.d.ts +11 -0
- package/lib/whatwg/check-datetime/date-string-with-optional-time.js +16 -0
- package/lib/whatwg/check-datetime/date-string.d.ts +0 -2
- package/lib/whatwg/check-datetime/date-string.js +0 -2
- package/lib/whatwg/check-datetime/datetime-tokens.d.ts +0 -13
- package/lib/whatwg/check-datetime/datetime-tokens.js +0 -16
- package/lib/whatwg/check-datetime/duration-string.d.ts +0 -4
- package/lib/whatwg/check-datetime/duration-string.js +0 -4
- package/lib/whatwg/check-datetime/global-date-and-time-string.d.ts +0 -2
- package/lib/whatwg/check-datetime/global-date-and-time-string.js +4 -4
- package/lib/whatwg/check-datetime/index.d.ts +0 -5
- package/lib/whatwg/check-datetime/index.js +0 -5
- package/lib/whatwg/check-datetime/local-date-and-time-string.d.ts +0 -4
- package/lib/whatwg/check-datetime/local-date-and-time-string.js +0 -4
- package/lib/whatwg/check-datetime/month-string.d.ts +0 -2
- package/lib/whatwg/check-datetime/month-string.js +0 -2
- package/lib/whatwg/check-datetime/time-string.d.ts +0 -2
- package/lib/whatwg/check-datetime/time-string.js +0 -2
- package/lib/whatwg/check-datetime/time-zone-offset-string.d.ts +0 -8
- package/lib/whatwg/check-datetime/time-zone-offset-string.js +0 -8
- package/lib/whatwg/check-datetime/week-string.d.ts +0 -2
- package/lib/whatwg/check-datetime/week-string.js +0 -2
- package/lib/whatwg/check-datetime/year-string.d.ts +0 -2
- package/lib/whatwg/check-datetime/year-string.js +0 -2
- package/lib/whatwg/check-datetime/yearless-date-string.d.ts +0 -2
- package/lib/whatwg/check-datetime/yearless-date-string.js +0 -2
- package/lib/whatwg/check-email.js +0 -2
- package/lib/whatwg/check-http-equiv-content-type.d.ts +12 -0
- package/lib/whatwg/check-http-equiv-content-type.js +32 -0
- package/lib/whatwg/check-http-equiv-refresh.d.ts +21 -0
- package/lib/whatwg/check-http-equiv-refresh.js +106 -0
- package/lib/whatwg/check-media-query-list.d.ts +61 -0
- package/lib/whatwg/check-media-query-list.js +484 -0
- package/lib/whatwg/check-mime-type.d.ts +0 -4
- package/lib/whatwg/check-mime-type.js +55 -3
- package/lib/whatwg/check-simple-color.d.ts +2 -4
- package/lib/whatwg/check-simple-color.js +2 -4
- package/lib/whatwg/check-url.d.ts +15 -7
- package/lib/whatwg/check-url.js +333 -25
- package/lib/whatwg/is-abs-url.d.ts +0 -2
- package/lib/whatwg/is-abs-url.js +0 -2
- package/lib/whatwg/is-browser-context-name.d.ts +0 -2
- package/lib/whatwg/is-browser-context-name.js +0 -2
- package/lib/whatwg/is-itemprop-name.d.ts +0 -2
- package/lib/whatwg/is-itemprop-name.js +0 -2
- package/lib/whatwg/is-navigable-target-name.d.ts +0 -2
- package/lib/whatwg/is-navigable-target-name.js +0 -2
- package/package.json +6 -5
- package/types.schema.json +9 -0
- package/ARCHITECTURE.ja.md +0 -256
- package/ARCHITECTURE.md +0 -256
- package/SKILL.md +0 -100
- package/docs/check-pipeline.ja.md +0 -494
- package/docs/check-pipeline.md +0 -494
- package/docs/token-system.ja.md +0 -584
- package/docs/token-system.md +0 -584
- package/docs/type-system.ja.md +0 -623
- package/docs/type-system.md +0 -623
- package/docs/validators.ja.md +0 -536
- package/docs/validators.md +0 -536
|
@@ -1,21 +1,6 @@
|
|
|
1
1
|
import { matched, unmatched } from '../match-result.js';
|
|
2
2
|
import { Token } from './token.js';
|
|
3
|
-
/**
|
|
4
|
-
* An ordered collection of tokens parsed from a string value.
|
|
5
|
-
*
|
|
6
|
-
* Extends `Array<Token>` with parsing, validation, and query capabilities.
|
|
7
|
-
* Supports configurable separators (space, comma, or custom), uniqueness
|
|
8
|
-
* constraints, ordering checks, and case sensitivity options.
|
|
9
|
-
*/
|
|
10
3
|
export class TokenCollection extends Array {
|
|
11
|
-
/**
|
|
12
|
-
* Creates a TokenCollection by matching a value against a sequence of regex patterns.
|
|
13
|
-
*
|
|
14
|
-
* @param value - The source token or string to parse
|
|
15
|
-
* @param patterns - The regex patterns to match sequentially
|
|
16
|
-
* @param typeOptions - Optional collection configuration
|
|
17
|
-
* @returns A new TokenCollection containing the matched tokens
|
|
18
|
-
*/
|
|
19
4
|
static fromPatterns(value, patterns,
|
|
20
5
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
21
6
|
typeOptions) {
|
|
@@ -136,23 +121,10 @@ export class TokenCollection extends Array {
|
|
|
136
121
|
offset += v.length;
|
|
137
122
|
}
|
|
138
123
|
}
|
|
139
|
-
/**
|
|
140
|
-
* The concatenated string value of all tokens in this collection.
|
|
141
|
-
*/
|
|
142
124
|
get value() {
|
|
143
125
|
const value = this.map(t => t.value).join('');
|
|
144
126
|
return value;
|
|
145
127
|
}
|
|
146
|
-
/**
|
|
147
|
-
* Validates the token collection structure against its configuration.
|
|
148
|
-
*
|
|
149
|
-
* Checks for unexpected spaces, consecutive commas, empty tokens,
|
|
150
|
-
* and duplicate values based on the collection's separator, allowEmpty,
|
|
151
|
-
* and unique settings.
|
|
152
|
-
*
|
|
153
|
-
* @param options - Optional validation settings including expected values and reference URL
|
|
154
|
-
* @returns The validation result
|
|
155
|
-
*/
|
|
156
128
|
check(options = {}) {
|
|
157
129
|
const { expects, ref } = options;
|
|
158
130
|
if (this.separator !== 'space' && this.disallowToSurroundBySpaces) {
|
|
@@ -229,12 +201,6 @@ export class TokenCollection extends Array {
|
|
|
229
201
|
}
|
|
230
202
|
return matched();
|
|
231
203
|
}
|
|
232
|
-
/**
|
|
233
|
-
* Splits this collection into chunks of the specified size.
|
|
234
|
-
*
|
|
235
|
-
* @param split - The number of tokens per chunk
|
|
236
|
-
* @returns An array of TokenCollection chunks
|
|
237
|
-
*/
|
|
238
204
|
chunk(split) {
|
|
239
205
|
const chunks = [];
|
|
240
206
|
const tokens = this.slice();
|
|
@@ -245,12 +211,6 @@ export class TokenCollection extends Array {
|
|
|
245
211
|
}
|
|
246
212
|
return chunks;
|
|
247
213
|
}
|
|
248
|
-
/**
|
|
249
|
-
* Iterates over consecutive token pairs, calling the callback for each pair.
|
|
250
|
-
*
|
|
251
|
-
* @param callback - A function receiving the previous and current token; return a token to stop iteration
|
|
252
|
-
* @returns The token returned by the callback, or `null` if iteration completes
|
|
253
|
-
*/
|
|
254
214
|
compareTokens(callback) {
|
|
255
215
|
const _tokens = this.slice();
|
|
256
216
|
let prev = _tokens.shift();
|
|
@@ -267,12 +227,6 @@ export class TokenCollection extends Array {
|
|
|
267
227
|
}
|
|
268
228
|
return null;
|
|
269
229
|
}
|
|
270
|
-
/**
|
|
271
|
-
* Splits this collection into two at the given position.
|
|
272
|
-
*
|
|
273
|
-
* @param position - The index at which to split
|
|
274
|
-
* @returns A tuple of two TokenCollections: before and after the position
|
|
275
|
-
*/
|
|
276
230
|
divide(position) {
|
|
277
231
|
const _a = this.slice(0, position);
|
|
278
232
|
const _b = this.slice(position);
|
|
@@ -280,15 +234,6 @@ export class TokenCollection extends Array {
|
|
|
280
234
|
const b = TokenCollection.#new(_b, this);
|
|
281
235
|
return [a, b];
|
|
282
236
|
}
|
|
283
|
-
/**
|
|
284
|
-
* Applies a sequence of check callbacks to consecutive tokens.
|
|
285
|
-
*
|
|
286
|
-
* Each callback receives the current head token and remaining tail.
|
|
287
|
-
* Tracks pass count and cumulative offset for error reporting.
|
|
288
|
-
*
|
|
289
|
-
* @param callbacks - The check functions to apply sequentially
|
|
290
|
-
* @returns The validation result
|
|
291
|
-
*/
|
|
292
237
|
eachCheck(...callbacks) {
|
|
293
238
|
let headAndTail = this.headAndTail();
|
|
294
239
|
let head = headAndTail.head;
|
|
@@ -355,21 +300,9 @@ export class TokenCollection extends Array {
|
|
|
355
300
|
}
|
|
356
301
|
return matched();
|
|
357
302
|
}
|
|
358
|
-
/**
|
|
359
|
-
* Creates a new TokenCollection containing only tokens that pass the test.
|
|
360
|
-
*
|
|
361
|
-
* @param callback - The filter predicate function
|
|
362
|
-
* @returns A new TokenCollection with the filtered tokens
|
|
363
|
-
*/
|
|
364
303
|
filter(callback) {
|
|
365
304
|
return TokenCollection.#new(super.filter(callback), this);
|
|
366
305
|
}
|
|
367
|
-
/**
|
|
368
|
-
* Finds the first occurrence of two consecutive tokens of the same type.
|
|
369
|
-
*
|
|
370
|
-
* @param tokenType - The token type number to check for consecutive occurrences
|
|
371
|
-
* @returns The second consecutive token, or `null` if none found
|
|
372
|
-
*/
|
|
373
306
|
getConsecutiveToken(tokenType) {
|
|
374
307
|
const resultToken = this.compareTokens((prev, current) => {
|
|
375
308
|
if (prev.type === tokenType && current.type === tokenType) {
|
|
@@ -378,13 +311,6 @@ export class TokenCollection extends Array {
|
|
|
378
311
|
});
|
|
379
312
|
return resultToken ?? null;
|
|
380
313
|
}
|
|
381
|
-
/**
|
|
382
|
-
* Finds the first duplicated token in this collection.
|
|
383
|
-
*
|
|
384
|
-
* Comparison respects the `caseInsensitive` setting of this collection.
|
|
385
|
-
*
|
|
386
|
-
* @returns The duplicated token, or `null` if all tokens are unique
|
|
387
|
-
*/
|
|
388
314
|
getDuplicated() {
|
|
389
315
|
const aList = this.slice();
|
|
390
316
|
const bList = this.slice();
|
|
@@ -406,28 +332,12 @@ export class TokenCollection extends Array {
|
|
|
406
332
|
}
|
|
407
333
|
return null;
|
|
408
334
|
}
|
|
409
|
-
/**
|
|
410
|
-
* Returns only the identifier tokens, excluding whitespace and separators.
|
|
411
|
-
*
|
|
412
|
-
* @returns A new TokenCollection containing only Ident-type tokens
|
|
413
|
-
*/
|
|
414
335
|
getIdentTokens() {
|
|
415
336
|
return this.filter(token => token.type === Token.Ident);
|
|
416
337
|
}
|
|
417
|
-
/**
|
|
418
|
-
* Checks whether any token in this collection matches the given value.
|
|
419
|
-
*
|
|
420
|
-
* @param value - The token value, type number, regex, or array to check against
|
|
421
|
-
* @returns Whether any token matches
|
|
422
|
-
*/
|
|
423
338
|
has(value) {
|
|
424
339
|
return this.some(t => t.matches(value));
|
|
425
340
|
}
|
|
426
|
-
/**
|
|
427
|
-
* Splits this collection into a head token and a tail collection.
|
|
428
|
-
*
|
|
429
|
-
* @returns An object with `head` (first token or null) and `tail` (remaining tokens)
|
|
430
|
-
*/
|
|
431
341
|
headAndTail() {
|
|
432
342
|
const copy = this.slice();
|
|
433
343
|
const head = copy.shift();
|
|
@@ -437,12 +347,6 @@ export class TokenCollection extends Array {
|
|
|
437
347
|
const tail = TokenCollection.#new(copy, this);
|
|
438
348
|
return { head, tail };
|
|
439
349
|
}
|
|
440
|
-
/**
|
|
441
|
-
* Searches for the first token that includes the given value.
|
|
442
|
-
*
|
|
443
|
-
* @param value - The token value, type number, regex, or array to search for
|
|
444
|
-
* @returns The first matching token, or `null` if not found
|
|
445
|
-
*/
|
|
446
350
|
search(value) {
|
|
447
351
|
for (const token of this) {
|
|
448
352
|
if (token.includes(value)) {
|
|
@@ -451,13 +355,6 @@ export class TokenCollection extends Array {
|
|
|
451
355
|
}
|
|
452
356
|
return null;
|
|
453
357
|
}
|
|
454
|
-
/**
|
|
455
|
-
* Verifies that tokens alternate between the specified types in order.
|
|
456
|
-
*
|
|
457
|
-
* @param tokenNumbers - The expected repeating pattern of token types
|
|
458
|
-
* @param lastTokenNumber - Optional expected type for the last token
|
|
459
|
-
* @returns An error object if the pattern is violated, or `null` if valid
|
|
460
|
-
*/
|
|
461
358
|
takeTurns(tokenNumbers, lastTokenNumber) {
|
|
462
359
|
const tokens = this.slice();
|
|
463
360
|
for (let i = 0; i < tokens.length; i++) {
|
|
@@ -483,11 +380,6 @@ export class TokenCollection extends Array {
|
|
|
483
380
|
}
|
|
484
381
|
return null;
|
|
485
382
|
}
|
|
486
|
-
/**
|
|
487
|
-
* Converts all tokens in this collection to plain JSON-serializable objects.
|
|
488
|
-
*
|
|
489
|
-
* @returns An array of plain token objects
|
|
490
|
-
*/
|
|
491
383
|
toJSON() {
|
|
492
384
|
return this.map(t => t.toJSON());
|
|
493
385
|
}
|
package/lib/token/token.d.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import type { TokenValue } from './types.js';
|
|
2
2
|
import type { UnmatchedResult, UnmatchedResultOptions, UnmatchedResultReason } from '../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Represents a single token within a parsed string value.
|
|
5
|
-
*
|
|
6
|
-
* Tracks the token's value, type (whitespace, comma, or identifier),
|
|
7
|
-
* offset position within the original string, and provides methods
|
|
8
|
-
* for matching and comparison operations.
|
|
9
|
-
*/
|
|
10
3
|
export declare class Token {
|
|
11
4
|
/**
|
|
12
5
|
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
@@ -25,32 +18,11 @@ export declare class Token {
|
|
|
25
18
|
* @see https://infra.spec.whatwg.org/#ascii-whitespace
|
|
26
19
|
*/
|
|
27
20
|
static readonly whitespace: ReadonlyArray<string>;
|
|
28
|
-
/**
|
|
29
|
-
* Calculates the line and column position at the given offset within a string.
|
|
30
|
-
*
|
|
31
|
-
* @param value - The source string
|
|
32
|
-
* @param offset - The character offset to calculate the position for
|
|
33
|
-
* @returns The line number (1-based) and column number (1-based)
|
|
34
|
-
*/
|
|
35
21
|
static getPosition(value: string, offset: number): {
|
|
36
22
|
line: number;
|
|
37
23
|
column: number;
|
|
38
24
|
};
|
|
39
|
-
|
|
40
|
-
* Determines the token type based on the first character.
|
|
41
|
-
*
|
|
42
|
-
* @param value - The token string value
|
|
43
|
-
* @param separators - Optional separator characters to detect
|
|
44
|
-
* @returns The token type number (WhiteSpace, Comma, or Ident)
|
|
45
|
-
*/
|
|
46
|
-
static getType(value: string, separators?: readonly string[]): 1 | 18 | 13;
|
|
47
|
-
/**
|
|
48
|
-
* Calculates a new position by shifting from a token's offset.
|
|
49
|
-
*
|
|
50
|
-
* @param token - The base token to shift from
|
|
51
|
-
* @param offset - The additional offset to apply
|
|
52
|
-
* @returns The shifted offset, line, and column
|
|
53
|
-
*/
|
|
25
|
+
static getType(value: string, separators?: readonly string[]): 1 | 13 | 18;
|
|
54
26
|
static shiftLocation(token: Readonly<Token>, offset: number): {
|
|
55
27
|
offset: number;
|
|
56
28
|
line: number;
|
|
@@ -60,61 +32,17 @@ export declare class Token {
|
|
|
60
32
|
readonly originalValue: string;
|
|
61
33
|
readonly type: number;
|
|
62
34
|
readonly value: string;
|
|
63
|
-
/**
|
|
64
|
-
* @param value - The token string value
|
|
65
|
-
* @param offset - The offset position within the original string
|
|
66
|
-
* @param originalValue - The complete original string this token was parsed from
|
|
67
|
-
* @param separators - Optional separator characters used for type detection
|
|
68
|
-
*/
|
|
69
35
|
constructor(value: string, offset: number, originalValue: string, separators?: readonly string[]);
|
|
70
|
-
/**
|
|
71
|
-
* The character length of the token value.
|
|
72
|
-
*/
|
|
73
36
|
get length(): number;
|
|
74
|
-
/**
|
|
75
|
-
* Creates a copy of this token.
|
|
76
|
-
*
|
|
77
|
-
* @returns A new Token instance with the same value, offset, and original value
|
|
78
|
-
*/
|
|
79
37
|
clone(): Token;
|
|
80
|
-
/**
|
|
81
|
-
* Checks whether this token's value contains the given value.
|
|
82
|
-
*
|
|
83
|
-
* @param value - The token value, type number, regex, or array to check against
|
|
84
|
-
* @param caseInsensitive - Whether to perform case-insensitive comparison
|
|
85
|
-
* @returns Whether this token includes the given value
|
|
86
|
-
*/
|
|
87
38
|
includes(value: TokenValue, caseInsensitive?: boolean): boolean;
|
|
88
|
-
/**
|
|
89
|
-
* Checks whether this token exactly matches the given value.
|
|
90
|
-
*
|
|
91
|
-
* @param value - The token value, type number, regex, or array to match against
|
|
92
|
-
* @param caseInsensitive - Whether to perform case-insensitive comparison
|
|
93
|
-
* @returns Whether this token matches the given value
|
|
94
|
-
*/
|
|
95
39
|
matches(value: TokenValue, caseInsensitive?: boolean): boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Converts this token to a plain JSON-serializable object.
|
|
98
|
-
*
|
|
99
|
-
* @returns An object with type, value, and offset properties
|
|
100
|
-
*/
|
|
101
40
|
toJSON(): {
|
|
102
41
|
type: number;
|
|
103
42
|
value: string;
|
|
104
43
|
offset: number;
|
|
105
44
|
};
|
|
106
|
-
/**
|
|
107
|
-
* Parses the token value as a floating-point number.
|
|
108
|
-
*
|
|
109
|
-
* @returns The parsed number, or 0 if parsing fails
|
|
110
|
-
*/
|
|
111
45
|
toNumber(): number;
|
|
112
|
-
/**
|
|
113
|
-
* Creates an unmatched result positioned at this token's location.
|
|
114
|
-
*
|
|
115
|
-
* @param options - Optional settings including ref, reason, and expected values
|
|
116
|
-
* @returns An unmatched result with this token's position information
|
|
117
|
-
*/
|
|
118
46
|
unmatched(options?: UnmatchedResultOptions & {
|
|
119
47
|
readonly ref?: string;
|
|
120
48
|
readonly reason?: UnmatchedResultReason;
|
package/lib/token/token.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a single token within a parsed string value.
|
|
3
|
-
*
|
|
4
|
-
* Tracks the token's value, type (whitespace, comma, or identifier),
|
|
5
|
-
* offset position within the original string, and provides methods
|
|
6
|
-
* for matching and comparison operations.
|
|
7
|
-
*/
|
|
8
1
|
export class Token {
|
|
9
2
|
/**
|
|
10
3
|
* @see https://github.com/csstree/csstree/blob/master/lib/tokenizer/types.js
|
|
@@ -23,26 +16,12 @@ export class Token {
|
|
|
23
16
|
* @see https://infra.spec.whatwg.org/#ascii-whitespace
|
|
24
17
|
*/
|
|
25
18
|
static whitespace = ['\u0009', '\u000A', '\u000C', '\u000D', '\u0020'];
|
|
26
|
-
/**
|
|
27
|
-
* Calculates the line and column position at the given offset within a string.
|
|
28
|
-
*
|
|
29
|
-
* @param value - The source string
|
|
30
|
-
* @param offset - The character offset to calculate the position for
|
|
31
|
-
* @returns The line number (1-based) and column number (1-based)
|
|
32
|
-
*/
|
|
33
19
|
static getPosition(value, offset) {
|
|
34
20
|
const lines = value.slice(0, offset).split(/\n/);
|
|
35
21
|
const line = lines.length;
|
|
36
22
|
const column = (lines.at(-1) ?? '').length + 1;
|
|
37
23
|
return { line, column };
|
|
38
24
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Determines the token type based on the first character.
|
|
41
|
-
*
|
|
42
|
-
* @param value - The token string value
|
|
43
|
-
* @param separators - Optional separator characters to detect
|
|
44
|
-
* @returns The token type number (WhiteSpace, Comma, or Ident)
|
|
45
|
-
*/
|
|
46
25
|
static getType(value, separators) {
|
|
47
26
|
if (Token.whitespace.includes(value[0] ?? '')) {
|
|
48
27
|
return Token.WhiteSpace;
|
|
@@ -56,13 +35,6 @@ export class Token {
|
|
|
56
35
|
}
|
|
57
36
|
return Token.Ident;
|
|
58
37
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Calculates a new position by shifting from a token's offset.
|
|
61
|
-
*
|
|
62
|
-
* @param token - The base token to shift from
|
|
63
|
-
* @param offset - The additional offset to apply
|
|
64
|
-
* @returns The shifted offset, line, and column
|
|
65
|
-
*/
|
|
66
38
|
static shiftLocation(token, offset) {
|
|
67
39
|
const shifted = token.offset + offset;
|
|
68
40
|
const { line, column } = Token.getPosition(token.originalValue, shifted);
|
|
@@ -76,39 +48,18 @@ export class Token {
|
|
|
76
48
|
originalValue;
|
|
77
49
|
type;
|
|
78
50
|
value;
|
|
79
|
-
/**
|
|
80
|
-
* @param value - The token string value
|
|
81
|
-
* @param offset - The offset position within the original string
|
|
82
|
-
* @param originalValue - The complete original string this token was parsed from
|
|
83
|
-
* @param separators - Optional separator characters used for type detection
|
|
84
|
-
*/
|
|
85
51
|
constructor(value, offset, originalValue, separators) {
|
|
86
52
|
this.type = Token.getType(value, separators);
|
|
87
53
|
this.value = value;
|
|
88
54
|
this.offset = offset;
|
|
89
55
|
this.originalValue = originalValue;
|
|
90
56
|
}
|
|
91
|
-
/**
|
|
92
|
-
* The character length of the token value.
|
|
93
|
-
*/
|
|
94
57
|
get length() {
|
|
95
58
|
return this.value.length;
|
|
96
59
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Creates a copy of this token.
|
|
99
|
-
*
|
|
100
|
-
* @returns A new Token instance with the same value, offset, and original value
|
|
101
|
-
*/
|
|
102
60
|
clone() {
|
|
103
61
|
return new Token(this.value, this.offset, this.originalValue);
|
|
104
62
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Checks whether this token's value contains the given value.
|
|
107
|
-
*
|
|
108
|
-
* @param value - The token value, type number, regex, or array to check against
|
|
109
|
-
* @param caseInsensitive - Whether to perform case-insensitive comparison
|
|
110
|
-
* @returns Whether this token includes the given value
|
|
111
|
-
*/
|
|
112
63
|
includes(value, caseInsensitive) {
|
|
113
64
|
if (Array.isArray(value)) {
|
|
114
65
|
return value.some(v => this.includes(v, caseInsensitive));
|
|
@@ -124,13 +75,6 @@ export class Token {
|
|
|
124
75
|
}
|
|
125
76
|
return this.type === value;
|
|
126
77
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Checks whether this token exactly matches the given value.
|
|
129
|
-
*
|
|
130
|
-
* @param value - The token value, type number, regex, or array to match against
|
|
131
|
-
* @param caseInsensitive - Whether to perform case-insensitive comparison
|
|
132
|
-
* @returns Whether this token matches the given value
|
|
133
|
-
*/
|
|
134
78
|
matches(value, caseInsensitive) {
|
|
135
79
|
if (Array.isArray(value)) {
|
|
136
80
|
return value.some(v => this.matches(v, caseInsensitive));
|
|
@@ -146,11 +90,6 @@ export class Token {
|
|
|
146
90
|
}
|
|
147
91
|
return this.type === value;
|
|
148
92
|
}
|
|
149
|
-
/**
|
|
150
|
-
* Converts this token to a plain JSON-serializable object.
|
|
151
|
-
*
|
|
152
|
-
* @returns An object with type, value, and offset properties
|
|
153
|
-
*/
|
|
154
93
|
toJSON() {
|
|
155
94
|
return {
|
|
156
95
|
type: this.type,
|
|
@@ -158,21 +97,10 @@ export class Token {
|
|
|
158
97
|
offset: this.offset,
|
|
159
98
|
};
|
|
160
99
|
}
|
|
161
|
-
/**
|
|
162
|
-
* Parses the token value as a floating-point number.
|
|
163
|
-
*
|
|
164
|
-
* @returns The parsed number, or 0 if parsing fails
|
|
165
|
-
*/
|
|
166
100
|
toNumber() {
|
|
167
101
|
const num = Number.parseFloat(this.value);
|
|
168
102
|
return Number.isNaN(num) ? 0 : num;
|
|
169
103
|
}
|
|
170
|
-
/**
|
|
171
|
-
* Creates an unmatched result positioned at this token's location.
|
|
172
|
-
*
|
|
173
|
-
* @param options - Optional settings including ref, reason, and expected values
|
|
174
|
-
* @returns An unmatched result with this token's position information
|
|
175
|
-
*/
|
|
176
104
|
unmatched(options) {
|
|
177
105
|
const { line, column } = Token.getPosition(this.originalValue, this.offset);
|
|
178
106
|
return {
|
package/lib/token/types.d.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A single token value: a literal string, a regular expression pattern, or a token type number.
|
|
3
|
-
*/
|
|
4
1
|
export type TokenValueScalar = string | Readonly<RegExp> | number;
|
|
5
|
-
/**
|
|
6
|
-
* An array of token values for matching against multiple patterns.
|
|
7
|
-
*/
|
|
8
2
|
export type TokenValueArray = readonly TokenValue[];
|
|
9
|
-
/**
|
|
10
|
-
* A token value used for matching: either a scalar or an array of token values.
|
|
11
|
-
*/
|
|
12
3
|
export type TokenValue = TokenValueScalar | TokenValueArray;
|
package/lib/types.schema.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
export type Type = KeywordDefinedType | List | Enum | Number | Directive | Pattern;
|
|
7
7
|
export type KeywordDefinedType = CssSyntax | ExtendedType | HtmlAttrRequirement;
|
|
8
8
|
export type CssSyntax = "<'--*'>" | "<'-moz-appearance'>" | "<'-moz-background-clip'>" | "<'-moz-binding'>" | "<'-moz-border-bottom-colors'>" | "<'-moz-border-left-colors'>" | "<'-moz-border-radius-bottomleft'>" | "<'-moz-border-radius-bottomright'>" | "<'-moz-border-radius-topleft'>" | "<'-moz-border-radius-topright'>" | "<'-moz-border-right-colors'>" | "<'-moz-border-top-colors'>" | "<'-moz-context-properties'>" | "<'-moz-control-character-visibility'>" | "<'-moz-float-edge'>" | "<'-moz-force-broken-image-icon'>" | "<'-moz-orient'>" | "<'-moz-osx-font-smoothing'>" | "<'-moz-outline-radius'>" | "<'-moz-outline-radius-bottomleft'>" | "<'-moz-outline-radius-bottomright'>" | "<'-moz-outline-radius-topleft'>" | "<'-moz-outline-radius-topright'>" | "<'-moz-stack-sizing'>" | "<'-moz-text-blink'>" | "<'-moz-user-focus'>" | "<'-moz-user-input'>" | "<'-moz-user-modify'>" | "<'-moz-user-select'>" | "<'-moz-window-dragging'>" | "<'-moz-window-shadow'>" | "<'-ms-accelerator'>" | "<'-ms-block-progression'>" | "<'-ms-content-zoom-chaining'>" | "<'-ms-content-zoom-limit'>" | "<'-ms-content-zoom-limit-max'>" | "<'-ms-content-zoom-limit-min'>" | "<'-ms-content-zoom-snap'>" | "<'-ms-content-zoom-snap-points'>" | "<'-ms-content-zoom-snap-type'>" | "<'-ms-content-zooming'>" | "<'-ms-filter'>" | "<'-ms-flex-align'>" | "<'-ms-flex-item-align'>" | "<'-ms-flex-line-pack'>" | "<'-ms-flex-negative'>" | "<'-ms-flex-order'>" | "<'-ms-flex-pack'>" | "<'-ms-flex-positive'>" | "<'-ms-flex-preferred-size'>" | "<'-ms-flow-from'>" | "<'-ms-flow-into'>" | "<'-ms-grid-column-align'>" | "<'-ms-grid-columns'>" | "<'-ms-grid-row-align'>" | "<'-ms-grid-rows'>" | "<'-ms-high-contrast-adjust'>" | "<'-ms-hyphenate-limit-chars'>" | "<'-ms-hyphenate-limit-last'>" | "<'-ms-hyphenate-limit-lines'>" | "<'-ms-hyphenate-limit-zone'>" | "<'-ms-ime-align'>" | "<'-ms-interpolation-mode'>" | "<'-ms-overflow-style'>" | "<'-ms-scroll-chaining'>" | "<'-ms-scroll-limit'>" | "<'-ms-scroll-limit-x-max'>" | "<'-ms-scroll-limit-x-min'>" | "<'-ms-scroll-limit-y-max'>" | "<'-ms-scroll-limit-y-min'>" | "<'-ms-scroll-rails'>" | "<'-ms-scroll-snap-points-x'>" | "<'-ms-scroll-snap-points-y'>" | "<'-ms-scroll-snap-type'>" | "<'-ms-scroll-snap-x'>" | "<'-ms-scroll-snap-y'>" | "<'-ms-scroll-translation'>" | "<'-ms-scrollbar-3dlight-color'>" | "<'-ms-scrollbar-arrow-color'>" | "<'-ms-scrollbar-base-color'>" | "<'-ms-scrollbar-darkshadow-color'>" | "<'-ms-scrollbar-face-color'>" | "<'-ms-scrollbar-highlight-color'>" | "<'-ms-scrollbar-shadow-color'>" | "<'-ms-scrollbar-track-color'>" | "<'-ms-text-autospace'>" | "<'-ms-touch-select'>" | "<'-ms-user-select'>" | "<'-ms-wrap-flow'>" | "<'-ms-wrap-margin'>" | "<'-ms-wrap-through'>" | "<'-webkit-appearance'>" | "<'-webkit-background-clip'>" | "<'-webkit-border-before'>" | "<'-webkit-border-before-color'>" | "<'-webkit-border-before-style'>" | "<'-webkit-border-before-width'>" | "<'-webkit-box-reflect'>" | "<'-webkit-column-break-after'>" | "<'-webkit-column-break-before'>" | "<'-webkit-column-break-inside'>" | "<'-webkit-font-smoothing'>" | "<'-webkit-line-clamp'>" | "<'-webkit-mask'>" | "<'-webkit-mask-attachment'>" | "<'-webkit-mask-box-image'>" | "<'-webkit-mask-clip'>" | "<'-webkit-mask-composite'>" | "<'-webkit-mask-image'>" | "<'-webkit-mask-origin'>" | "<'-webkit-mask-position'>" | "<'-webkit-mask-position-x'>" | "<'-webkit-mask-position-y'>" | "<'-webkit-mask-repeat'>" | "<'-webkit-mask-repeat-x'>" | "<'-webkit-mask-repeat-y'>" | "<'-webkit-mask-size'>" | "<'-webkit-overflow-scrolling'>" | "<'-webkit-print-color-adjust'>" | "<'-webkit-tap-highlight-color'>" | "<'-webkit-text-fill-color'>" | "<'-webkit-text-security'>" | "<'-webkit-text-stroke'>" | "<'-webkit-text-stroke-color'>" | "<'-webkit-text-stroke-width'>" | "<'-webkit-touch-callout'>" | "<'-webkit-user-drag'>" | "<'-webkit-user-modify'>" | "<'-webkit-user-select'>" | "<'accent-color'>" | "<'align-content'>" | "<'align-items'>" | "<'align-self'>" | "<'align-tracks'>" | "<'alignment-baseline'>" | "<'all'>" | "<'anchor-name'>" | "<'anchor-scope'>" | "<'animation'>" | "<'animation-composition'>" | "<'animation-delay'>" | "<'animation-direction'>" | "<'animation-duration'>" | "<'animation-fill-mode'>" | "<'animation-iteration-count'>" | "<'animation-name'>" | "<'animation-play-state'>" | "<'animation-range'>" | "<'animation-range-end'>" | "<'animation-range-start'>" | "<'animation-timeline'>" | "<'animation-timing-function'>" | "<'animation-trigger'>" | "<'appearance'>" | "<'aspect-ratio'>" | "<'backdrop-filter'>" | "<'backface-visibility'>" | "<'background'>" | "<'background-attachment'>" | "<'background-blend-mode'>" | "<'background-clip'>" | "<'background-color'>" | "<'background-image'>" | "<'background-origin'>" | "<'background-position'>" | "<'background-position-x'>" | "<'background-position-y'>" | "<'background-repeat'>" | "<'background-size'>" | "<'baseline-shift'>" | "<'baseline-source'>" | "<'behavior'>" | "<'block-size'>" | "<'border'>" | "<'border-block'>" | "<'border-block-color'>" | "<'border-block-end'>" | "<'border-block-end-color'>" | "<'border-block-end-style'>" | "<'border-block-end-width'>" | "<'border-block-start'>" | "<'border-block-start-color'>" | "<'border-block-start-style'>" | "<'border-block-start-width'>" | "<'border-block-style'>" | "<'border-block-width'>" | "<'border-bottom'>" | "<'border-bottom-color'>" | "<'border-bottom-left-radius'>" | "<'border-bottom-right-radius'>" | "<'border-bottom-style'>" | "<'border-bottom-width'>" | "<'border-collapse'>" | "<'border-color'>" | "<'border-end-end-radius'>" | "<'border-end-start-radius'>" | "<'border-image'>" | "<'border-image-outset'>" | "<'border-image-repeat'>" | "<'border-image-slice'>" | "<'border-image-source'>" | "<'border-image-width'>" | "<'border-inline'>" | "<'border-inline-color'>" | "<'border-inline-end'>" | "<'border-inline-end-color'>" | "<'border-inline-end-style'>" | "<'border-inline-end-width'>" | "<'border-inline-start'>" | "<'border-inline-start-color'>" | "<'border-inline-start-style'>" | "<'border-inline-start-width'>" | "<'border-inline-style'>" | "<'border-inline-width'>" | "<'border-left'>" | "<'border-left-color'>" | "<'border-left-style'>" | "<'border-left-width'>" | "<'border-radius'>" | "<'border-right'>" | "<'border-right-color'>" | "<'border-right-style'>" | "<'border-right-width'>" | "<'border-spacing'>" | "<'border-start-end-radius'>" | "<'border-start-start-radius'>" | "<'border-style'>" | "<'border-top'>" | "<'border-top-color'>" | "<'border-top-left-radius'>" | "<'border-top-right-radius'>" | "<'border-top-style'>" | "<'border-top-width'>" | "<'border-width'>" | "<'bottom'>" | "<'box-align'>" | "<'box-decoration-break'>" | "<'box-direction'>" | "<'box-flex'>" | "<'box-flex-group'>" | "<'box-lines'>" | "<'box-ordinal-group'>" | "<'box-orient'>" | "<'box-pack'>" | "<'box-shadow'>" | "<'box-sizing'>" | "<'break-after'>" | "<'break-before'>" | "<'break-inside'>" | "<'caption-side'>" | "<'caret'>" | "<'caret-animation'>" | "<'caret-color'>" | "<'caret-shape'>" | "<'clear'>" | "<'clip'>" | "<'clip-path'>" | "<'clip-rule'>" | "<'color'>" | "<'color-interpolation-filters'>" | "<'color-scheme'>" | "<'column-count'>" | "<'column-fill'>" | "<'column-gap'>" | "<'column-height'>" | "<'column-rule'>" | "<'column-rule-color'>" | "<'column-rule-style'>" | "<'column-rule-width'>" | "<'column-span'>" | "<'column-width'>" | "<'column-wrap'>" | "<'columns'>" | "<'contain'>" | "<'contain-intrinsic-block-size'>" | "<'contain-intrinsic-height'>" | "<'contain-intrinsic-inline-size'>" | "<'contain-intrinsic-size'>" | "<'contain-intrinsic-width'>" | "<'container'>" | "<'container-name'>" | "<'container-type'>" | "<'content'>" | "<'content-visibility'>" | "<'corner-block-end-shape'>" | "<'corner-block-start-shape'>" | "<'corner-bottom-left-shape'>" | "<'corner-bottom-right-shape'>" | "<'corner-bottom-shape'>" | "<'corner-end-end-shape'>" | "<'corner-end-start-shape'>" | "<'corner-inline-end-shape'>" | "<'corner-inline-start-shape'>" | "<'corner-left-shape'>" | "<'corner-right-shape'>" | "<'corner-shape'>" | "<'corner-start-end-shape'>" | "<'corner-start-start-shape'>" | "<'corner-top-left-shape'>" | "<'corner-top-right-shape'>" | "<'corner-top-shape'>" | "<'counter-increment'>" | "<'counter-reset'>" | "<'counter-set'>" | "<'cue'>" | "<'cue-after'>" | "<'cue-before'>" | "<'cursor'>" | "<'cx'>" | "<'cy'>" | "<'d'>" | "<'direction'>" | "<'display'>" | "<'dominant-baseline'>" | "<'dynamic-range-limit'>" | "<'empty-cells'>" | "<'field-sizing'>" | "<'fill'>" | "<'fill-opacity'>" | "<'fill-rule'>" | "<'filter'>" | "<'flex'>" | "<'flex-basis'>" | "<'flex-direction'>" | "<'flex-flow'>" | "<'flex-grow'>" | "<'flex-shrink'>" | "<'flex-wrap'>" | "<'float'>" | "<'flood-color'>" | "<'flood-opacity'>" | "<'font'>" | "<'font-family'>" | "<'font-feature-settings'>" | "<'font-kerning'>" | "<'font-language-override'>" | "<'font-optical-sizing'>" | "<'font-palette'>" | "<'font-size'>" | "<'font-size-adjust'>" | "<'font-smooth'>" | "<'font-stretch'>" | "<'font-style'>" | "<'font-synthesis'>" | "<'font-synthesis-position'>" | "<'font-synthesis-small-caps'>" | "<'font-synthesis-style'>" | "<'font-synthesis-weight'>" | "<'font-variant'>" | "<'font-variant-alternates'>" | "<'font-variant-caps'>" | "<'font-variant-east-asian'>" | "<'font-variant-emoji'>" | "<'font-variant-ligatures'>" | "<'font-variant-numeric'>" | "<'font-variant-position'>" | "<'font-variation-settings'>" | "<'font-weight'>" | "<'font-width'>" | "<'forced-color-adjust'>" | "<'gap'>" | "<'glyph-orientation-horizontal'>" | "<'glyph-orientation-vertical'>" | "<'grid'>" | "<'grid-area'>" | "<'grid-auto-columns'>" | "<'grid-auto-flow'>" | "<'grid-auto-rows'>" | "<'grid-column'>" | "<'grid-column-end'>" | "<'grid-column-gap'>" | "<'grid-column-start'>" | "<'grid-gap'>" | "<'grid-row'>" | "<'grid-row-end'>" | "<'grid-row-gap'>" | "<'grid-row-start'>" | "<'grid-template'>" | "<'grid-template-areas'>" | "<'grid-template-columns'>" | "<'grid-template-rows'>" | "<'hanging-punctuation'>" | "<'height'>" | "<'hyphenate-character'>" | "<'hyphenate-limit-chars'>" | "<'hyphens'>" | "<'image-orientation'>" | "<'image-rendering'>" | "<'image-resolution'>" | "<'ime-mode'>" | "<'initial-letter'>" | "<'initial-letter-align'>" | "<'inline-size'>" | "<'inset'>" | "<'inset-block'>" | "<'inset-block-end'>" | "<'inset-block-start'>" | "<'inset-inline'>" | "<'inset-inline-end'>" | "<'inset-inline-start'>" | "<'interactivity'>" | "<'interest-delay'>" | "<'interest-delay-end'>" | "<'interest-delay-start'>" | "<'interpolate-size'>" | "<'isolation'>" | "<'justify-content'>" | "<'justify-items'>" | "<'justify-self'>" | "<'justify-tracks'>" | "<'kerning'>" | "<'left'>" | "<'letter-spacing'>" | "<'lighting-color'>" | "<'line-break'>" | "<'line-clamp'>" | "<'line-height'>" | "<'line-height-step'>" | "<'list-style'>" | "<'list-style-image'>" | "<'list-style-position'>" | "<'list-style-type'>" | "<'margin'>" | "<'margin-block'>" | "<'margin-block-end'>" | "<'margin-block-start'>" | "<'margin-bottom'>" | "<'margin-inline'>" | "<'margin-inline-end'>" | "<'margin-inline-start'>" | "<'margin-left'>" | "<'margin-right'>" | "<'margin-top'>" | "<'margin-trim'>" | "<'marker'>" | "<'marker-end'>" | "<'marker-mid'>" | "<'marker-start'>" | "<'mask'>" | "<'mask-border'>" | "<'mask-border-mode'>" | "<'mask-border-outset'>" | "<'mask-border-repeat'>" | "<'mask-border-slice'>" | "<'mask-border-source'>" | "<'mask-border-width'>" | "<'mask-clip'>" | "<'mask-composite'>" | "<'mask-image'>" | "<'mask-mode'>" | "<'mask-origin'>" | "<'mask-position'>" | "<'mask-repeat'>" | "<'mask-size'>" | "<'mask-type'>" | "<'masonry-auto-flow'>" | "<'math-depth'>" | "<'math-shift'>" | "<'math-style'>" | "<'max-block-size'>" | "<'max-height'>" | "<'max-inline-size'>" | "<'max-lines'>" | "<'max-width'>" | "<'min-block-size'>" | "<'min-height'>" | "<'min-inline-size'>" | "<'min-width'>" | "<'mix-blend-mode'>" | "<'object-fit'>" | "<'object-position'>" | "<'object-view-box'>" | "<'offset'>" | "<'offset-anchor'>" | "<'offset-distance'>" | "<'offset-path'>" | "<'offset-position'>" | "<'offset-rotate'>" | "<'opacity'>" | "<'order'>" | "<'orphans'>" | "<'outline'>" | "<'outline-color'>" | "<'outline-offset'>" | "<'outline-style'>" | "<'outline-width'>" | "<'overflow'>" | "<'overflow-anchor'>" | "<'overflow-block'>" | "<'overflow-clip-box'>" | "<'overflow-clip-margin'>" | "<'overflow-inline'>" | "<'overflow-wrap'>" | "<'overflow-x'>" | "<'overflow-y'>" | "<'overlay'>" | "<'overscroll-behavior'>" | "<'overscroll-behavior-block'>" | "<'overscroll-behavior-inline'>" | "<'overscroll-behavior-x'>" | "<'overscroll-behavior-y'>" | "<'padding'>" | "<'padding-block'>" | "<'padding-block-end'>" | "<'padding-block-start'>" | "<'padding-bottom'>" | "<'padding-inline'>" | "<'padding-inline-end'>" | "<'padding-inline-start'>" | "<'padding-left'>" | "<'padding-right'>" | "<'padding-top'>" | "<'page'>" | "<'page-break-after'>" | "<'page-break-before'>" | "<'page-break-inside'>" | "<'paint-order'>" | "<'pause'>" | "<'pause-after'>" | "<'pause-before'>" | "<'perspective'>" | "<'perspective-origin'>" | "<'place-content'>" | "<'place-items'>" | "<'place-self'>" | "<'pointer-events'>" | "<'position'>" | "<'position-anchor'>" | "<'position-area'>" | "<'position-try'>" | "<'position-try-fallbacks'>" | "<'position-try-options'>" | "<'position-try-order'>" | "<'position-visibility'>" | "<'print-color-adjust'>" | "<'quotes'>" | "<'r'>" | "<'reading-flow'>" | "<'reading-order'>" | "<'resize'>" | "<'rest'>" | "<'rest-after'>" | "<'rest-before'>" | "<'right'>" | "<'rotate'>" | "<'row-gap'>" | "<'ruby-align'>" | "<'ruby-merge'>" | "<'ruby-overhang'>" | "<'ruby-position'>" | "<'rx'>" | "<'ry'>" | "<'scale'>" | "<'scroll-behavior'>" | "<'scroll-initial-target'>" | "<'scroll-margin'>" | "<'scroll-margin-block'>" | "<'scroll-margin-block-end'>" | "<'scroll-margin-block-start'>" | "<'scroll-margin-bottom'>" | "<'scroll-margin-inline'>" | "<'scroll-margin-inline-end'>" | "<'scroll-margin-inline-start'>" | "<'scroll-margin-left'>" | "<'scroll-margin-right'>" | "<'scroll-margin-top'>" | "<'scroll-marker-group'>" | "<'scroll-padding'>" | "<'scroll-padding-block'>" | "<'scroll-padding-block-end'>" | "<'scroll-padding-block-start'>" | "<'scroll-padding-bottom'>" | "<'scroll-padding-inline'>" | "<'scroll-padding-inline-end'>" | "<'scroll-padding-inline-start'>" | "<'scroll-padding-left'>" | "<'scroll-padding-right'>" | "<'scroll-padding-top'>" | "<'scroll-snap-align'>" | "<'scroll-snap-coordinate'>" | "<'scroll-snap-destination'>" | "<'scroll-snap-points-x'>" | "<'scroll-snap-points-y'>" | "<'scroll-snap-stop'>" | "<'scroll-snap-type'>" | "<'scroll-snap-type-x'>" | "<'scroll-snap-type-y'>" | "<'scroll-target-group'>" | "<'scroll-timeline'>" | "<'scroll-timeline-axis'>" | "<'scroll-timeline-name'>" | "<'scrollbar-color'>" | "<'scrollbar-gutter'>" | "<'scrollbar-width'>" | "<'shape-image-threshold'>" | "<'shape-margin'>" | "<'shape-outside'>" | "<'shape-rendering'>" | "<'speak'>" | "<'speak-as'>" | "<'stop-color'>" | "<'stop-opacity'>" | "<'stroke'>" | "<'stroke-color'>" | "<'stroke-dasharray'>" | "<'stroke-dashoffset'>" | "<'stroke-linecap'>" | "<'stroke-linejoin'>" | "<'stroke-miterlimit'>" | "<'stroke-opacity'>" | "<'stroke-width'>" | "<'tab-size'>" | "<'table-layout'>" | "<'text-align'>" | "<'text-align-last'>" | "<'text-anchor'>" | "<'text-autospace'>" | "<'text-box'>" | "<'text-box-edge'>" | "<'text-box-trim'>" | "<'text-combine-upright'>" | "<'text-decoration'>" | "<'text-decoration-color'>" | "<'text-decoration-inset'>" | "<'text-decoration-line'>" | "<'text-decoration-skip'>" | "<'text-decoration-skip-ink'>" | "<'text-decoration-style'>" | "<'text-decoration-thickness'>" | "<'text-emphasis'>" | "<'text-emphasis-color'>" | "<'text-emphasis-position'>" | "<'text-emphasis-style'>" | "<'text-indent'>" | "<'text-justify'>" | "<'text-orientation'>" | "<'text-overflow'>" | "<'text-rendering'>" | "<'text-shadow'>" | "<'text-size-adjust'>" | "<'text-spacing-trim'>" | "<'text-transform'>" | "<'text-underline-offset'>" | "<'text-underline-position'>" | "<'text-wrap'>" | "<'text-wrap-mode'>" | "<'text-wrap-style'>" | "<'timeline-scope'>" | "<'timeline-trigger'>" | "<'timeline-trigger-exit-range'>" | "<'timeline-trigger-exit-range-end'>" | "<'timeline-trigger-exit-range-start'>" | "<'timeline-trigger-name'>" | "<'timeline-trigger-range'>" | "<'timeline-trigger-range-end'>" | "<'timeline-trigger-range-start'>" | "<'timeline-trigger-source'>" | "<'top'>" | "<'touch-action'>" | "<'transform'>" | "<'transform-box'>" | "<'transform-origin'>" | "<'transform-style'>" | "<'transition'>" | "<'transition-behavior'>" | "<'transition-delay'>" | "<'transition-duration'>" | "<'transition-property'>" | "<'transition-timing-function'>" | "<'translate'>" | "<'trigger-scope'>" | "<'unicode-bidi'>" | "<'user-select'>" | "<'vector-effect'>" | "<'vertical-align'>" | "<'view-timeline'>" | "<'view-timeline-axis'>" | "<'view-timeline-inset'>" | "<'view-timeline-name'>" | "<'view-transition-class'>" | "<'view-transition-name'>" | "<'visibility'>" | "<'voice-balance'>" | "<'voice-duration'>" | "<'voice-family'>" | "<'voice-pitch'>" | "<'voice-range'>" | "<'voice-rate'>" | "<'voice-stress'>" | "<'voice-volume'>" | "<'white-space'>" | "<'white-space-collapse'>" | "<'white-space-trim'>" | "<'widows'>" | "<'width'>" | "<'will-change'>" | "<'word-break'>" | "<'word-spacing'>" | "<'word-wrap'>" | "<'writing-mode'>" | "<'x'>" | "<'y'>" | "<'z-index'>" | "<'zoom'>" | "<(-token>" | "<)-token>" | "<-legacy-gradient>" | "<-legacy-linear-gradient-arguments>" | "<-legacy-linear-gradient>" | "<-legacy-radial-gradient-arguments>" | "<-legacy-radial-gradient-shape>" | "<-legacy-radial-gradient-size>" | "<-legacy-radial-gradient>" | "<-legacy-repeating-linear-gradient>" | "<-legacy-repeating-radial-gradient>" | "<-ms-filter-function-legacy>" | "<-ms-filter-function-list>" | "<-ms-filter-function-progid>" | "<-ms-filter-function>" | "<-non-standard-color>" | "<-non-standard-display>" | "<-non-standard-font>" | "<-non-standard-generic-family>" | "<-non-standard-image-rendering>" | "<-non-standard-overflow>" | "<-non-standard-size>" | "<-webkit-gradient()>" | "<-webkit-gradient-color-stop>" | "<-webkit-gradient-point>" | "<-webkit-gradient-radius>" | "<-webkit-gradient-type>" | "<-webkit-mask-box-repeat>" | "<CDC-token>" | "<CDO-token>" | "<[-token>" | "<]-token>" | "<abs()>" | "<absolute-size>" | "<acos()>" | "<age>" | "<alpha-value>" | "<an+b>" | "<an-plus-b>" | "<anchor()>" | "<anchor-name>" | "<anchor-side>" | "<anchor-size()>" | "<anchor-size>" | "<angle-percentage>" | "<angle>" | "<angular-color-hint>" | "<angular-color-stop-list>" | "<angular-color-stop>" | "<animateable-feature>" | "<animation-action>" | "<any-value>" | "<asin()>" | "<at-keyword-token>" | "<atan()>" | "<atan2()>" | "<attachment>" | "<attr()>" | "<attr-fallback>" | "<attr-matcher>" | "<attr-modifier>" | "<attr-name>" | "<attr-type>" | "<attr-unit>" | "<attribute-selector>" | "<auto-repeat>" | "<auto-track-list>" | "<autospace>" | "<axis>" | "<bad-string-token>" | "<bad-url-token>" | "<baseline-position>" | "<basic-shape-rect>" | "<basic-shape>" | "<bcp-47>" | "<bg-clip>" | "<bg-image>" | "<bg-layer>" | "<bg-position>" | "<bg-size>" | "<blend-mode>" | "<blur()>" | "<bottom>" | "<brightness()>" | "<calc()>" | "<calc-constant>" | "<calc-product>" | "<calc-size()>" | "<calc-size-basis>" | "<calc-sum>" | "<calc-value>" | "<cf-final-image>" | "<cf-mixing-image>" | "<circle()>" | "<clamp()>" | "<class-selector>" | "<clip-source>" | "<cmyk-component>" | "<colon-token>" | "<color()>" | "<color-base>" | "<color-function>" | "<color-interpolation-method>" | "<color-mix()>" | "<color-space>" | "<color-stop-angle>" | "<color-stop-length>" | "<color-stop-list>" | "<color-stop>" | "<color>" | "<colorspace-params>" | "<combinator>" | "<comma-token>" | "<common-lig-values>" | "<compat-auto>" | "<compat-special>" | "<complex-real-selector-list>" | "<complex-real-selector>" | "<complex-selector-list>" | "<complex-selector-unit>" | "<complex-selector>" | "<composite-style>" | "<compositing-operator>" | "<compound-selector-list>" | "<compound-selector>" | "<conic-gradient()>" | "<conic-gradient-syntax>" | "<container-condition>" | "<container-name>" | "<container-query>" | "<content-distribution>" | "<content-list>" | "<content-position>" | "<content-replacement>" | "<contextual-alt-values>" | "<contrast()>" | "<coord-box>" | "<corner-shape-value>" | "<cos()>" | "<counter()>" | "<counter-name>" | "<counter-style-name>" | "<counter-style>" | "<counter>" | "<counters()>" | "<cross-fade()>" | "<cubic-bezier()>" | "<cubic-bezier-easing-function>" | "<cursor-predefined>" | "<custom-color-space>" | "<custom-ident>" | "<custom-params>" | "<custom-property-name>" | "<dasharray>" | "<dashed-ident>" | "<dashndashdigit-ident>" | "<decibel>" | "<declaration-list>" | "<declaration-value>" | "<declaration>" | "<delim-token>" | "<deprecated-system-color>" | "<device-cmyk()>" | "<dimension-token>" | "<dimension>" | "<discretionary-lig-values>" | "<display-box>" | "<display-inside>" | "<display-internal>" | "<display-legacy>" | "<display-listitem>" | "<display-outside>" | "<drop-shadow()>" | "<dynamic-range-limit-mix()>" | "<easing-function>" | "<east-asian-variant-values>" | "<east-asian-width-values>" | "<element()>" | "<ellipse()>" | "<env()>" | "<exp()>" | "<explicit-track-list>" | "<family-name>" | "<feature-tag-value>" | "<feature-type>" | "<feature-value-block-list>" | "<feature-value-block>" | "<feature-value-declaration-list>" | "<feature-value-declaration>" | "<feature-value-name>" | "<filter-function>" | "<filter-value-list>" | "<final-bg-layer>" | "<fit-content()>" | "<fixed-breadth>" | "<fixed-repeat>" | "<fixed-size>" | "<flex>" | "<font-stretch-absolute>" | "<font-variant-css2>" | "<font-weight-absolute>" | "<font-width-css3>" | "<forgiving-relative-selector-list>" | "<forgiving-selector-list>" | "<form-control-identifier>" | "<frequency-percentage>" | "<frequency>" | "<function-token>" | "<gender>" | "<general-enclosed>" | "<generic-complete>" | "<generic-family>" | "<generic-incomplete>" | "<generic-script-specific>" | "<generic-voice>" | "<geometry-box>" | "<gradient>" | "<grayscale()>" | "<grid-line>" | "<hash-token>" | "<hex-color>" | "<historical-lig-values>" | "<hsl()>" | "<hsla()>" | "<hue-interpolation-method>" | "<hue-rotate()>" | "<hue>" | "<hwb()>" | "<hypot()>" | "<id-selector>" | "<ident-token>" | "<ident>" | "<image()>" | "<image-set()>" | "<image-set-option>" | "<image-src>" | "<image-tags>" | "<image>" | "<inflexible-breadth>" | "<inset()>" | "<inset-area>" | "<integer>" | "<intrinsic-size-keyword>" | "<invert()>" | "<keyframe-block>" | "<keyframe-selector>" | "<keyframes-name>" | "<lab()>" | "<layer()>" | "<layer-name>" | "<lch()>" | "<leader()>" | "<leader-type>" | "<left>" | "<legacy-device-cmyk-syntax>" | "<legacy-pseudo-element-selector>" | "<length-percentage>" | "<length>" | "<light-dark()>" | "<line-name-list>" | "<line-names>" | "<line-style>" | "<line-width>" | "<linear()>" | "<linear-color-hint>" | "<linear-color-stop>" | "<linear-easing-function>" | "<linear-gradient()>" | "<linear-gradient-syntax>" | "<log()>" | "<mask-layer>" | "<mask-position>" | "<mask-reference>" | "<mask-source>" | "<masking-mode>" | "<matrix()>" | "<matrix3d()>" | "<max()>" | "<media-and>" | "<media-condition-without-or>" | "<media-condition>" | "<media-feature>" | "<media-in-parens>" | "<media-not>" | "<media-or>" | "<media-query-list>" | "<media-query>" | "<media-type>" | "<mf-boolean>" | "<mf-name>" | "<mf-plain>" | "<mf-range>" | "<mf-value>" | "<min()>" | "<minmax()>" | "<mod()>" | "<modern-device-cmyk-syntax>" | "<n-dimension>" | "<name-repeat>" | "<named-color>" | "<namespace-prefix>" | "<ndash-dimension>" | "<ndashdigit-dimension>" | "<ndashdigit-ident>" | "<ns-prefix>" | "<number-one-or-greater>" | "<number-percentage>" | "<number-token>" | "<number-zero-one>" | "<number>" | "<numeric-figure-values>" | "<numeric-fraction-values>" | "<numeric-spacing-values>" | "<offset-path>" | "<oklab()>" | "<oklch()>" | "<opacity()>" | "<opacity-value>" | "<outline-line-style>" | "<outline-radius>" | "<overflow-position>" | "<page-body>" | "<page-margin-box-type>" | "<page-margin-box>" | "<page-selector-list>" | "<page-selector>" | "<page-size>" | "<paint()>" | "<paint-box>" | "<paint>" | "<palette-identifier>" | "<palette-mix()>" | "<path()>" | "<percentage-token>" | "<percentage>" | "<perspective()>" | "<polar-color-space>" | "<polygon()>" | "<position-area>" | "<position>" | "<pow()>" | "<predefined-rgb-params>" | "<predefined-rgb>" | "<pseudo-class-selector>" | "<pseudo-compound-selector>" | "<pseudo-element-selector>" | "<pseudo-page>" | "<query-in-parens>" | "<quote>" | "<radial-extent>" | "<radial-gradient()>" | "<radial-gradient-syntax>" | "<radial-shape>" | "<radial-size>" | "<ratio>" | "<ray()>" | "<ray-size>" | "<rect()>" | "<rectangular-color-space>" | "<relative-real-selector-list>" | "<relative-real-selector>" | "<relative-selector-list>" | "<relative-selector>" | "<relative-size>" | "<rem()>" | "<repeat-style>" | "<repeating-conic-gradient()>" | "<repeating-linear-gradient()>" | "<repeating-radial-gradient()>" | "<resolution>" | "<reversed-counter-name>" | "<rgb()>" | "<rgba()>" | "<right>" | "<rotate()>" | "<rotate3d()>" | "<rotateX()>" | "<rotateY()>" | "<rotateZ()>" | "<round()>" | "<rounding-strategy>" | "<saturate()>" | "<scale()>" | "<scale3d()>" | "<scaleX()>" | "<scaleY()>" | "<scaleZ()>" | "<scope-end>" | "<scope-start>" | "<scroll()>" | "<scroll-state-feature>" | "<scroll-state-in-parens>" | "<scroll-state-query>" | "<scroller>" | "<selector-list>" | "<self-position>" | "<semicolon-token>" | "<semitones>" | "<sepia()>" | "<shadow-t>" | "<shadow>" | "<shape-box>" | "<shape>" | "<side-or-corner>" | "<sign()>" | "<signed-integer>" | "<signless-integer>" | "<simple-selector-list>" | "<simple-selector>" | "<sin()>" | "<single-animation-composition>" | "<single-animation-direction>" | "<single-animation-fill-mode>" | "<single-animation-iteration-count>" | "<single-animation-play-state>" | "<single-animation-timeline>" | "<single-animation>" | "<single-transition-property>" | "<single-transition>" | "<size-feature>" | "<size>" | "<skew()>" | "<skewX()>" | "<skewY()>" | "<sqrt()>" | "<step-easing-function>" | "<step-position>" | "<steps()>" | "<string-token>" | "<string>" | "<style-condition>" | "<style-feature>" | "<style-in-parens>" | "<style-query>" | "<subclass-selector>" | "<superellipse()>" | "<supports-condition>" | "<supports-decl>" | "<supports-feature>" | "<supports-in-parens>" | "<supports-selector-fn>" | "<svg-length>" | "<svg-writing-mode>" | "<symbol>" | "<symbols()>" | "<symbols-type>" | "<syntax-combinator>" | "<syntax-component>" | "<syntax-multiplier>" | "<syntax-single-component>" | "<syntax-string>" | "<syntax-type-name>" | "<syntax>" | "<system-color>" | "<system-family-name>" | "<tan()>" | "<target-counter()>" | "<target-counters()>" | "<target-text()>" | "<target>" | "<text-edge>" | "<time-percentage>" | "<time>" | "<timeline-range-name>" | "<top>" | "<track-breadth>" | "<track-list>" | "<track-repeat>" | "<track-size>" | "<transform-function>" | "<transform-list>" | "<transition-behavior-value>" | "<translate()>" | "<translate3d()>" | "<translateX()>" | "<translateY()>" | "<translateZ()>" | "<try-size>" | "<try-tactic>" | "<type-or-unit>" | "<type-selector>" | "<urange>" | "<url-modifier>" | "<url-token>" | "<url>" | "<var()>" | "<view()>" | "<viewport-length>" | "<visual-box>" | "<whitespace-token>" | "<wq-name>" | "<x>" | "<xywh()>" | "<xyz-params>" | "<xyz-space>" | "<xyz>" | "<y>" | "<zero>" | "<{-token>" | "<}-token>";
|
|
9
|
-
export type ExtendedType = "<'color-profile'>" | "<'color-rendering'>" | "<'enable-background'>" | "<animatable-value>" | "<begin-value-list>" | "<class-list>" | "<clock-value>" | "<color-matrix>" | "<css-declaration-list>" | "<dasharray>" | "<end-value-list>" | "<key-points>" | "<key-splines>" | "<key-times>" | "<list-of-lengths>" | "<list-of-numbers>" | "<list-of-percentages>" | "<list-of-svg-feature-string>" | "<list-of-value>" | "<number-optional-number>" | "<origin>" | "<points>" | "<preserve-aspect-ratio>" | "<rotate>" | "<svg-font-size-adjust>" | "<svg-font-size>" | "<svg-path>" | "<system-language>" | "<text-coordinate>" | "<view-box>" | "AbsoluteURL" | "Accept" | "Any" | "AutoComplete" | "BCP47" | "BaseURL" | "BrowsingContextName" | "BrowsingContextNameOrKeyword" | "CustomElementName" | "DOMID" | "DateString" | "DateTime" | "Email" | "FunctionBody" | "HTTPSchemaURL" | "HashName" | "IconSize" | "Int" | "ItemProp" | "JSON" | "LinkTypeForAnchorAndAreaElement" | "LinkTypeForFormElement" | "LinkTypeForLinkElement" | "LinkTypeForLinkElementInBody" | "LocalDateTimeString" | "MIMEType" | "MonthString" | "NavigableTargetName" | "NavigableTargetNameOrKeyword" | "NoEmptyAny" | "Number" | "OneCodePointChar" | "OneLineAny" | "Pattern" | "SRIHash" | "SerializedPermissionsPolicy" | "SimpleColor" | "SourceSizeList" | "Srcset" | "TabIndex" | "TimeString" | "URL" | "Uint" | "ValidCustomCommand" | "WeekString" | "XMLName" | "Zero";
|
|
9
|
+
export type ExtendedType = "<'color-profile'>" | "<'color-rendering'>" | "<'enable-background'>" | "<animatable-value>" | "<begin-value-list>" | "<class-list>" | "<clock-value>" | "<color-matrix>" | "<css-declaration-list>" | "<dasharray>" | "<end-value-list>" | "<key-points>" | "<key-splines>" | "<key-times>" | "<list-of-lengths>" | "<list-of-numbers>" | "<list-of-percentages>" | "<list-of-svg-feature-string>" | "<list-of-value>" | "<number-optional-number>" | "<origin>" | "<points>" | "<preserve-aspect-ratio>" | "<rotate>" | "<svg-font-size-adjust>" | "<svg-font-size>" | "<svg-path>" | "<system-language>" | "<text-coordinate>" | "<view-box>" | "AbsoluteURL" | "AbsoluteURLOrEmpty" | "Accept" | "Any" | "AutoComplete" | "AutoCompleteAnchorMantle" | "AutoCompleteNoWebauthn" | "BCP47" | "BaseURL" | "BrowsingContextName" | "BrowsingContextNameOrKeyword" | "ContentSecurityPolicy" | "CustomElementName" | "DOMID" | "DateString" | "DateStringWithOptionalTime" | "DateTime" | "Email" | "FunctionBody" | "HTTPEquivContentType" | "HTTPEquivRefresh" | "HTTPSchemaURL" | "HashName" | "IconSize" | "Int" | "ItemProp" | "JSON" | "LinkTypeForAnchorAndAreaElement" | "LinkTypeForFormElement" | "LinkTypeForLinkElement" | "LinkTypeForLinkElementInBody" | "LocalDateTimeString" | "MIMEType" | "MediaQueryList" | "MonthString" | "NavigableTargetName" | "NavigableTargetNameOrKeyword" | "NoEmptyAny" | "NonEmptyURL" | "Number" | "OneCodePointChar" | "OneLineAny" | "Pattern" | "SRIHash" | "SerializedPermissionsPolicy" | "SimpleColor" | "SourceSizeList" | "Srcset" | "TabIndex" | "TimeString" | "URL" | "Uint" | "ValidCustomCommand" | "WeekString" | "XMLName" | "Zero";
|
|
10
10
|
export type HtmlAttrRequirement = "Boolean";
|
|
11
11
|
export interface TypesSchema {
|
|
12
12
|
type?: Type;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CustomSyntaxChecker } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validates the `content` attribute value of
|
|
4
|
+
* `<meta http-equiv="content-security-policy">` against the Content
|
|
5
|
+
* Security Policy Level 3 `serialized-policy` grammar.
|
|
6
|
+
*
|
|
7
|
+
* Directive-value-specific grammars are only enforced for the directives
|
|
8
|
+
* exercised by the nu-validator bench corpus (fetch directives + `base-uri`
|
|
9
|
+
* / `form-action` / `frame-ancestors`, `sandbox`, `require-trusted-types-for`,
|
|
10
|
+
* `trusted-types`, `upgrade-insecure-requests`); `report-uri` / `report-to` /
|
|
11
|
+
* `webrtc` are recognized as registered directive names but their values are
|
|
12
|
+
* not further validated.
|
|
13
|
+
*
|
|
14
|
+
* @see https://www.w3.org/TR/CSP3/#framework-policy
|
|
15
|
+
* @see https://www.w3.org/TR/CSP3/#framework-directives
|
|
16
|
+
* @see https://www.w3.org/TR/CSP3/#meta-element
|
|
17
|
+
*/
|
|
18
|
+
export declare const checkContentSecurityPolicy: CustomSyntaxChecker;
|