@markuplint/types 4.0.0-alpha.4 → 4.0.0-alpha.6
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/defs.js +9 -7
- 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 +7 -7
package/LICENSE
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
|
},
|
|
@@ -750,7 +752,7 @@ export const types = {
|
|
|
750
752
|
syntax: {
|
|
751
753
|
apply: '<view-box>',
|
|
752
754
|
def: {
|
|
753
|
-
'view-box': '<min-x> [,]? <min-y> [,]? <width> [,]? <height>',
|
|
755
|
+
'view-box': '<min-x> [,]? <min-y> [,]? <width> [,]? <height>', // As '[<min-x>,? <min-y>,? <width>,? <height>]',
|
|
754
756
|
'min-x': '<number>',
|
|
755
757
|
'min-y': '<number>',
|
|
756
758
|
width: '<number>',
|
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-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.6",
|
|
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>",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
"schema": "ts-node './gen/types.ts'; json2ts './types.schema.json' > './src/types.schema.ts'; prettier './src/types.schema.ts' './types.schema.json' --write; eslint './src/types.schema.ts' --fix; tsc;"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@types/css-tree": "^2.3.
|
|
29
|
-
"@types/debug": "^4.1.
|
|
30
|
-
"@types/whatwg-mimetype": "3.0.
|
|
28
|
+
"@types/css-tree": "^2.3.4",
|
|
29
|
+
"@types/debug": "^4.1.12",
|
|
30
|
+
"@types/whatwg-mimetype": "3.0.2",
|
|
31
31
|
"bcp-47": "^2.1.0",
|
|
32
32
|
"css-tree": "^2.3.1",
|
|
33
33
|
"debug": "^4.3.4",
|
|
34
34
|
"leven": "^4.0.0",
|
|
35
|
-
"type-fest": "^4.
|
|
36
|
-
"whatwg-mimetype": "^
|
|
35
|
+
"type-fest": "^4.8.2",
|
|
36
|
+
"whatwg-mimetype": "^4.0.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "06e1242d274c72cf08a10a572b06ac35d1b924a4"
|
|
39
39
|
}
|