@markuplint/types 4.0.0-dev.28 → 4.0.0-rc.1
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/css-syntax.js +5 -2
- package/lib/defs.d.ts +1 -0
- package/lib/defs.js +102 -49
- package/lib/token/token.js +2 -2
- package/lib/whatwg/is-custom-element-name.d.ts +9 -4
- package/lib/whatwg/is-custom-element-name.js +21 -33
- package/package.json +12 -8
package/LICENSE
CHANGED
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
|
@@ -88,12 +88,14 @@ export const types = {
|
|
|
88
88
|
},
|
|
89
89
|
],
|
|
90
90
|
is: value => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const name =
|
|
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;
|
|
97
99
|
return name.test(value) ? matched() : unmatched(value, 'unexpected-token');
|
|
98
100
|
},
|
|
99
101
|
},
|
|
@@ -403,51 +405,81 @@ export const types = {
|
|
|
403
405
|
},
|
|
404
406
|
Srcset: {
|
|
405
407
|
ref: 'https://html.spec.whatwg.org/multipage/images.html#srcset-attributes',
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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
|
+
}
|
|
418
440
|
break;
|
|
419
441
|
}
|
|
420
|
-
|
|
421
|
-
|
|
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
|
-
|
|
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
|
+
}
|
|
447
469
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
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();
|
|
451
483
|
},
|
|
452
484
|
},
|
|
453
485
|
SourceSizeList: {
|
|
@@ -750,7 +782,7 @@ export const types = {
|
|
|
750
782
|
syntax: {
|
|
751
783
|
apply: '<view-box>',
|
|
752
784
|
def: {
|
|
753
|
-
'view-box': '<min-x> [,]? <min-y> [,]? <width> [,]? <height>',
|
|
785
|
+
'view-box': '<min-x> [,]? <min-y> [,]? <width> [,]? <height>', // As '[<min-x>,? <min-y>,? <width>,? <height>]',
|
|
754
786
|
'min-x': '<number>',
|
|
755
787
|
'min-y': '<number>',
|
|
756
788
|
width: '<number>',
|
|
@@ -813,6 +845,27 @@ export const types = {
|
|
|
813
845
|
},
|
|
814
846
|
},
|
|
815
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
|
+
};
|
|
816
869
|
export const tokenizers = {
|
|
817
870
|
// RFC
|
|
818
871
|
// https://tools.ietf.org/rfc/bcp/bcp47.html
|
package/lib/token/token.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export class Token {
|
|
2
2
|
static getCol(value, offset) {
|
|
3
|
-
const lines = value.slice(0, offset).split(/\n/
|
|
3
|
+
const lines = value.slice(0, offset).split(/\n/);
|
|
4
4
|
return (lines.at(-1) ?? '').length + 1;
|
|
5
5
|
}
|
|
6
6
|
static getLine(value, offset) {
|
|
7
|
-
return value.slice(0, offset).split(/\n/
|
|
7
|
+
return value.slice(0, offset).split(/\n/).length;
|
|
8
8
|
}
|
|
9
9
|
static getType(value, separators) {
|
|
10
10
|
if (Token.whitespace.includes(value[0] ?? '')) {
|
|
@@ -2,7 +2,14 @@ import type { FormattedPrimitiveTypeCreator } from '../types.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* valid name of custom element
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* > PotentialCustomElementName ::=
|
|
6
|
+
* > [a-z] (PCENChar)* '-' (PCENChar)*
|
|
7
|
+
* > PCENChar ::=
|
|
8
|
+
* > "-" | "." | [0-9] | "_" | [a-z] | #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] |
|
|
9
|
+
* > [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
|
|
10
|
+
* > This uses the EBNF notation from the XML specification. [XML]
|
|
11
|
+
*
|
|
12
|
+
* > They start with an ASCII lower alpha, ensuring that the HTML parser will treat them as tags instead of as text.
|
|
6
13
|
*
|
|
7
14
|
* > - name must match the [PotentialCustomElementName](https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname) production
|
|
8
15
|
* > - name must not be any of the following:
|
|
@@ -15,8 +22,6 @@ import type { FormattedPrimitiveTypeCreator } from '../types.js';
|
|
|
15
22
|
* > - `<font-face-name>`
|
|
16
23
|
* > - `<missing-glyph>`
|
|
17
24
|
*
|
|
18
|
-
*
|
|
19
|
-
* Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser.
|
|
20
|
-
*
|
|
25
|
+
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
21
26
|
*/
|
|
22
27
|
export declare const isCustomElementName: FormattedPrimitiveTypeCreator;
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* PCENChar
|
|
3
3
|
*
|
|
4
|
+
* > PCENChar ::=
|
|
5
|
+
* > "-" | "." | [0-9] | "_" | [a-z] | #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] |
|
|
6
|
+
* > [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
|
|
4
7
|
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname
|
|
5
8
|
*
|
|
9
|
+
*/
|
|
10
|
+
const onlyPCENChar =
|
|
11
|
+
// eslint-disable-next-line no-misleading-character-class
|
|
12
|
+
/^[-.\d_a-z\u00B7\u00C0-\u00D6[\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C\u200D\u203F\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]*$/u;
|
|
13
|
+
/**
|
|
14
|
+
* valid name of custom element
|
|
15
|
+
*
|
|
6
16
|
* > PotentialCustomElementName ::=
|
|
7
17
|
* > [a-z] (PCENChar)* '-' (PCENChar)*
|
|
8
18
|
* > PCENChar ::=
|
|
@@ -10,34 +20,7 @@
|
|
|
10
20
|
* > [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
|
|
11
21
|
* > This uses the EBNF notation from the XML specification. [XML]
|
|
12
22
|
*
|
|
13
|
-
* ASCII
|
|
14
|
-
* Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser.
|
|
15
|
-
*/
|
|
16
|
-
const rePCENChar = [
|
|
17
|
-
'\\-',
|
|
18
|
-
'\\.',
|
|
19
|
-
'[0-9]',
|
|
20
|
-
'_',
|
|
21
|
-
'[a-z]',
|
|
22
|
-
'\u00B7',
|
|
23
|
-
'[\u00C0-\u00D6]',
|
|
24
|
-
'[\u00D8-\u00F6]',
|
|
25
|
-
'[\u00F8-\u037D]',
|
|
26
|
-
'[\u037F-\u1FFF]',
|
|
27
|
-
'[\u200C-\u200D]',
|
|
28
|
-
'[\u203F-\u2040]',
|
|
29
|
-
'[\u2070-\u218F]',
|
|
30
|
-
'[\u2C00-\u2FEF]',
|
|
31
|
-
'[\u3001-\uD7FF]',
|
|
32
|
-
'[\uF900-\uFDCF]',
|
|
33
|
-
'[\uFDF0-\uFFFD]',
|
|
34
|
-
'[\uD800-\uDBFF][\uDC00-\uDFFF]',
|
|
35
|
-
].join('|');
|
|
36
|
-
const rePCEN = new RegExp(`^[a-z](?:${rePCENChar})*\\-(?:${rePCENChar})*$`, 'i');
|
|
37
|
-
/**
|
|
38
|
-
* valid name of custom element
|
|
39
|
-
*
|
|
40
|
-
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
23
|
+
* > They start with an ASCII lower alpha, ensuring that the HTML parser will treat them as tags instead of as text.
|
|
41
24
|
*
|
|
42
25
|
* > - name must match the [PotentialCustomElementName](https://html.spec.whatwg.org/multipage/custom-elements.html#prod-potentialcustomelementname) production
|
|
43
26
|
* > - name must not be any of the following:
|
|
@@ -50,9 +33,7 @@ const rePCEN = new RegExp(`^[a-z](?:${rePCENChar})*\\-(?:${rePCENChar})*$`, 'i')
|
|
|
50
33
|
* > - `<font-face-name>`
|
|
51
34
|
* > - `<missing-glyph>`
|
|
52
35
|
*
|
|
53
|
-
*
|
|
54
|
-
* Originally, it is not possible to define a name including ASCII upper alphas in the custom element, but it is not treated as illegal by the HTML parser.
|
|
55
|
-
*
|
|
36
|
+
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
56
37
|
*/
|
|
57
38
|
export const isCustomElementName = () => {
|
|
58
39
|
return tagName => {
|
|
@@ -68,6 +49,13 @@ export const isCustomElementName = () => {
|
|
|
68
49
|
return false;
|
|
69
50
|
}
|
|
70
51
|
}
|
|
71
|
-
|
|
52
|
+
// First char must be ASCII lowercase alpha.
|
|
53
|
+
if (!/^[a-z]/.test(tagName)) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (!tagName.includes('-')) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return onlyPCENChar.test(tagName);
|
|
72
60
|
};
|
|
73
61
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/types",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-rc.1",
|
|
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,18 +22,22 @@
|
|
|
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
|
-
"@types/css-tree": "^2.3.
|
|
29
|
-
"@types/debug": "^4.1.
|
|
30
|
-
"@types/whatwg-mimetype": "3.0.
|
|
32
|
+
"@types/css-tree": "^2.3.4",
|
|
33
|
+
"@types/debug": "^4.1.12",
|
|
34
|
+
"@types/whatwg-mimetype": "3.0.2",
|
|
31
35
|
"bcp-47": "^2.1.0",
|
|
32
36
|
"css-tree": "^2.3.1",
|
|
33
37
|
"debug": "^4.3.4",
|
|
34
38
|
"leven": "^4.0.0",
|
|
35
|
-
"type-fest": "^4.
|
|
36
|
-
"whatwg-mimetype": "^
|
|
39
|
+
"type-fest": "^4.10.2",
|
|
40
|
+
"whatwg-mimetype": "^4.0.0"
|
|
37
41
|
},
|
|
38
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "3a9dbbf4c3c05de66d402802919ee94a46a5eb67"
|
|
39
43
|
}
|