@markuplint/types 4.0.0-dev.0 → 4.0.0-dev.12
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/LICENSE +1 -1
- package/lib/check-multi-types.d.ts +1 -1
- package/lib/css-syntax.js +5 -2
- package/lib/defs.d.ts +1 -0
- package/lib/defs.js +93 -42
- package/lib/match-result.d.ts +1 -1
- package/lib/token/token-collection.d.ts +1 -1
- package/lib/token/token.d.ts +1 -1
- package/package.json +8 -4
package/LICENSE
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { CustomSyntaxCheck, UnmatchedResult } from './types.js';
|
|
2
|
-
export declare function checkMultiTypes(value: string, checks: readonly CustomSyntaxCheck[]): import("./types.js").MatchedResult
|
|
2
|
+
export declare function checkMultiTypes(value: string, checks: readonly CustomSyntaxCheck[]): UnmatchedResult | import("./types.js").MatchedResult;
|
package/lib/css-syntax.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fork } from 'css-tree';
|
|
2
2
|
import { log } from './debug.js';
|
|
3
|
-
import { tokenizers } from './defs.js';
|
|
3
|
+
import { tokenizers, overrides } from './defs.js';
|
|
4
4
|
import { matched } from './match-result.js';
|
|
5
5
|
const MIMIC_TAG_L = 'mimiccases---';
|
|
6
6
|
const MIMIC_TAG_R = '---mimiccases';
|
|
@@ -52,7 +52,10 @@ export function cssSyntaxMatch(value, type) {
|
|
|
52
52
|
}
|
|
53
53
|
// @ts-ignore
|
|
54
54
|
const lexer = fork({
|
|
55
|
-
types:
|
|
55
|
+
types: {
|
|
56
|
+
...overrides,
|
|
57
|
+
...typesExtended,
|
|
58
|
+
},
|
|
56
59
|
properties: propsExtended,
|
|
57
60
|
}).lexer;
|
|
58
61
|
for (const key of Object.keys(typesCheckers)) {
|
package/lib/defs.d.ts
CHANGED
package/lib/defs.js
CHANGED
|
@@ -405,51 +405,81 @@ export const types = {
|
|
|
405
405
|
},
|
|
406
406
|
Srcset: {
|
|
407
407
|
ref: 'https://html.spec.whatwg.org/multipage/images.html#srcset-attributes',
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
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
|
+
}
|
|
420
440
|
break;
|
|
421
441
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
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
|
+
}
|
|
449
469
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
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();
|
|
453
483
|
},
|
|
454
484
|
},
|
|
455
485
|
SourceSizeList: {
|
|
@@ -815,6 +845,27 @@ export const types = {
|
|
|
815
845
|
},
|
|
816
846
|
},
|
|
817
847
|
};
|
|
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
|
+
};
|
|
818
869
|
export const tokenizers = {
|
|
819
870
|
// RFC
|
|
820
871
|
// https://tools.ietf.org/rfc/bcp/bcp47.html
|
package/lib/match-result.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { FormattedPrimitiveTypeCheck, MatchedResult, UnmatchedResult, Unmat
|
|
|
2
2
|
export declare function matches(checker: FormattedPrimitiveTypeCheck, options?: UnmatchedResultOptions & {
|
|
3
3
|
readonly ref?: string;
|
|
4
4
|
readonly reason?: UnmatchedResultReason;
|
|
5
|
-
}): (value: string) =>
|
|
5
|
+
}): (value: string) => UnmatchedResult | MatchedResult;
|
|
6
6
|
export declare function matched(): MatchedResult;
|
|
7
7
|
export declare function unmatched(value: string, reason?: UnmatchedResultReason, options?: UnmatchedResultOptions & {
|
|
8
8
|
readonly ref?: string;
|
|
@@ -24,7 +24,7 @@ export declare class TokenCollection extends Array<Token> {
|
|
|
24
24
|
expects?: Expect[];
|
|
25
25
|
ref?: string;
|
|
26
26
|
cache?: boolean;
|
|
27
|
-
}): import("../types.js").MatchedResult
|
|
27
|
+
}): UnmatchedResult | import("../types.js").MatchedResult;
|
|
28
28
|
chunk(split: number): TokenCollection[];
|
|
29
29
|
compareTokens(callback: (prev: Readonly<Token>, current: Readonly<Token>) => Readonly<Token> | null | void): Readonly<Token> | null | undefined;
|
|
30
30
|
divide(position: number): readonly [TokenCollection, TokenCollection];
|
package/lib/token/token.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare class Token {
|
|
|
20
20
|
static readonly whitespace: ReadonlyArray<string>;
|
|
21
21
|
static getCol(value: string, offset: number): number;
|
|
22
22
|
static getLine(value: string, offset: number): number;
|
|
23
|
-
static getType(value: string, separators?: readonly string[]): 1 |
|
|
23
|
+
static getType(value: string, separators?: readonly string[]): 1 | 18 | 13;
|
|
24
24
|
static shiftLocation(token: Readonly<Token>, offset: number): {
|
|
25
25
|
offset: number;
|
|
26
26
|
line: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/types",
|
|
3
|
-
"version": "4.0.0-dev.
|
|
3
|
+
"version": "4.0.0-dev.12+2275fbeb0",
|
|
4
4
|
"description": "Type declaration and value checker",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -22,7 +22,11 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "tsc",
|
|
24
24
|
"clean": "tsc --build --clean",
|
|
25
|
-
"schema": "
|
|
25
|
+
"schema": "run-s schema:types schema:schema build schema:prettier schema:eslint schema:prettier",
|
|
26
|
+
"schema:types": "node --loader ts-node/esm \"./gen/types.ts\"",
|
|
27
|
+
"schema:schema": "json2ts \"./types.schema.json\" > \"./src/types.schema.ts\"",
|
|
28
|
+
"schema:eslint": "eslint --fix \"./src/types.schema.ts\"",
|
|
29
|
+
"schema:prettier": "prettier --write \"./src/types.schema.ts\" \"./types.schema.json\" --log-level warn"
|
|
26
30
|
},
|
|
27
31
|
"dependencies": {
|
|
28
32
|
"@types/css-tree": "^2.3.4",
|
|
@@ -32,8 +36,8 @@
|
|
|
32
36
|
"css-tree": "^2.3.1",
|
|
33
37
|
"debug": "^4.3.4",
|
|
34
38
|
"leven": "^4.0.0",
|
|
35
|
-
"type-fest": "^4.
|
|
39
|
+
"type-fest": "^4.9.0",
|
|
36
40
|
"whatwg-mimetype": "^4.0.0"
|
|
37
41
|
},
|
|
38
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "2275fbeb053605b636f080f4fafd7cd4fc57a9a3"
|
|
39
43
|
}
|