@markuplint/types 4.7.7 → 4.8.0

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 CHANGED
@@ -3,6 +3,24 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [4.8.0](https://github.com/markuplint/markuplint/compare/@markuplint/types@4.7.7...@markuplint/types@4.8.0) (2025-08-24)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **types:** adjust type checking for css-tree update ([7fff913](https://github.com/markuplint/markuplint/commit/7fff913f4630eab6017861934142636d3c267336))
12
+ * **types:** fix bug that spaces are invalid even if separator is 'space' when disallowToSurroundBySpaces is enabled ([3b81c3b](https://github.com/markuplint/markuplint/commit/3b81c3b525cd406275936236f8b793efed8864d7))
13
+
14
+
15
+ ### Features
16
+
17
+ * **types:** add link type definitions for specific HTML elements ([7199a8e](https://github.com/markuplint/markuplint/commit/7199a8eb4eaf334855ba78064c4340e040d8614c))
18
+ * **types:** add link type validation for HTML elements ([ed7cc6c](https://github.com/markuplint/markuplint/commit/ed7cc6c2b703e14b8572087eb07c63a97d864187))
19
+
20
+
21
+
22
+
23
+
6
24
  ## [4.7.7](https://github.com/markuplint/markuplint/compare/@markuplint/types@4.7.6...@markuplint/types@4.7.7) (2025-08-13)
7
25
 
8
26
  ### Bug Fixes
package/README.md CHANGED
@@ -33,70 +33,74 @@ check('2020-02-30', 'DateTime');
33
33
 
34
34
  ## Type Identifiers
35
35
 
36
- | Identifier | Use on | Spec | Supported |
37
- | ---------------------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | --------- |
38
- | `Any` | Some attributes | | ✅ |
39
- | `NoEmptyAny` | Some attributes | | ✅ |
40
- | `OneLineAny` | Some attributes | | ✅ |
41
- | `Zero` | Some attributes | | ✅ |
42
- | `Number` | Some attributes | | ✅ |
43
- | `Uint` | Some attributes | | ✅ |
44
- | `JSON` | Attributes on some frameworks etc. | | ✅ |
45
- | `XMLName` | `svg\|[attributeName]` and more | [XML](https://www.w3.org/TR/xml/#d0e804) | ✅ |
46
- | `DOMID` | The `id` attribute and more | [WHATWG](https://html.spec.whatwg.org/multipage/dom.html#global-attributes:concept-id) | ✅ |
47
- | `FunctionBody` | Event handler attributes | | 🚧 |
48
- | `Pattern` | `input[pattern]` | [WHATWG](https://html.spec.whatwg.org/multipage/input.html#compiled-pattern-regular-expression) | ✅ |
49
- | `DateTime` | `time[datetime]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/text-level-semantics.html#datetime-value) | ✅ |
50
- | `TabIndex` | The `tabindex` attribute | [WHATWG](https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex) | ✅ |
51
- | `BCP47` | The `lang` attribute and more | [RFC](https://tools.ietf.org/rfc/bcp/bcp47.html) | ✅ |
52
- | `URL` | Some attributes | [WHATWG](https://html.spec.whatwg.org/multipage/urls-and-fetching.html#valid-url-potentially-surrounded-by-spaces) | ✅ |
53
- | `AbsoluteURL` | The `itemtype` attribute (as list) | [WHATWG](https://url.spec.whatwg.org/#syntax-url-absolute) | ✅ |
54
- | `HashName` | `img[usemap]` | [WHATWG](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-hash-name-reference) | ✅ |
55
- | `OneCodePointChar` | The `accesskey` attribute (as list) | [WHATWG](https://html.spec.whatwg.org/multipage/interaction.html#the-accesskey-attribute) | ✅ |
56
- | `CustomElementName` | The `is` attribute | [WHATWG](https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name) | ✅ |
57
- | ~~`BrowsingContextName`~~ | Use `NavigableTargetName` instead. | **Obsolated** | ✅ |
58
- | ~~`BrowsingContextNameOrKeyword`~~ | Use `NavigableTargetNameOrKeyword` instead. | **Obsolated** | ✅ |
59
- | `NavigableTargetName` | `iframe[name]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name) | ✅ |
60
- | `NavigableTargetNameOrKeyword` | `a[target]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name-or-keyword) | ✅ |
61
- | `HTTPSchemaURL` | `a[ping]` (as list) and more | [WHATWG](https://html.spec.whatwg.org/multipage/links.html#ping) | ✅ |
62
- | `MIMEType` | `embed[type]` and more | [WHATWG](https://mimesniff.spec.whatwg.org/#valid-mime-type) | ✅ |
63
- | `ItemProp` | The `itemprop` attribute (as list) | [WHATWG](https://html.spec.whatwg.org/multipage/microdata.html#names:-the-itemprop-attribute) | ✅ |
64
- | `Srcset` | `img[srcset]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/images.html#srcset-attributes) | ✅ |
65
- | `SourceSizeList` | `img[sizes]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/images.html#sizes-attributes) | ✅ |
66
- | `IconSize` | `link[sizes]` (as list) | [WHATWG](https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes) | ✅ |
67
- | `AutoComplete` | `input[autocomplete]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete) | ✅ |
68
- | `Accept` | `input[accept]` | [WHATWG](https://html.spec.whatwg.org/multipage/input.html#attr-input-accept) | ✅ |
69
- | `SerializedPermissionsPolicy` | `iframe[allow]` | [W3C](https://w3c.github.io/webappsec-permissions-policy/#serialized-permissions-policy) | ✅ |
70
- | `<css-declaration-list>` | The `style` attribute | [CSS](https://drafts.csswg.org/css-style-attr/#syntax) | ✅ |
71
- | `<class-list>` | The `class` attribute | [SVG](https://www.w3.org/TR/SVG/styling.html#ClassAttribute) | ✅ |
72
- | `<svg-font-size>` | Some attributes for SVG | [CSS](https://drafts.csswg.org/css-fonts-5/#descdef-font-face-font-size) | 🚧 |
73
- | `<svg-font-size-adjust>` | Some attributes for SVG | [CSS](https://drafts.csswg.org/css-fonts-5/#propdef-font-size-adjust) | 🚧 |
74
- | `<'color-profile'>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/color.html#ColorProfileProperty) | 🚧 |
75
- | `<'color-rendering'>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/painting.html#ColorRenderingProperty) | 🚧 |
76
- | `<'enable-background'>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/filters.html#EnableBackgroundProperty) | 🚧 |
77
- | `<list-of-svg-feature-string>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/feature.html) | 🚧 |
78
- | `<animatable-value>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#FromAttribute) | 🚧 |
79
- | `<begin-value-list>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#BeginValueListSyntax) | 🚧 |
80
- | `<end-value-list>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#EndValueListSyntax) | 🚧 |
81
- | `<list-of-value>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#ValuesAttribute) | 🚧 |
82
- | `<clock-value>` | Some attributes for SVG | [SMIL](https://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-ClockValueSyntax) | 🚧 |
83
- | `<color-matrix>` | Some attributes for SVG | [W3C](https://drafts.fxtf.org/filter-effects/#element-attrdef-fecolormatrix-values) | |
84
- | `<dasharray>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/painting.html#StrokeDasharrayProperty) | |
85
- | `<key-points>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#KeyPointsAttribute) | |
86
- | `<key-splines>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#KeyTimesAttribute) | |
87
- | `<key-times>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#KeyTimesAttribute) | ✅ |
88
- | `<system-language>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/struct.html#SystemLanguageAttribute) | ✅ |
89
- | `<origin>` | Some attributes for SVG | [SMIL](https://www.w3.org/TR/2001/REC-smil-animation-20010904/#MotionOriginAttribute) | ✅ |
90
- | `<svg-path>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/paths.html#PathDataBNF) | 🚧 |
91
- | `<points>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/shapes.html#DataTypePoints) | ✅ |
92
- | `<preserve-aspect-ratio>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/coords.html#PreserveAspectRatioAttribute) | ✅ |
93
- | `<view-box>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/coords.html#ViewBoxAttribute) | ✅ |
94
- | `<rotate>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#RotateAttribute) | |
95
- | `<text-coordinate>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/text.html#TSpanAttributes) | ✅ |
96
- | `<list-of-lengths>` | Some attributes for SVG | | ✅ |
97
- | `<list-of-numbers>` | Some attributes for SVG | | ✅ |
98
- | `<list-of-percentages>` | Some attributes for SVG | | ✅ |
99
- | `<number-optional-number>` | Some attributes for SVG | | ✅ |
36
+ | Identifier | Use on | Spec | Supported |
37
+ | ---------------------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------- |
38
+ | `Any` | Some attributes | | ✅ |
39
+ | `NoEmptyAny` | Some attributes | | ✅ |
40
+ | `OneLineAny` | Some attributes | | ✅ |
41
+ | `Zero` | Some attributes | | ✅ |
42
+ | `Number` | Some attributes | | ✅ |
43
+ | `Uint` | Some attributes | | ✅ |
44
+ | `JSON` | Attributes on some frameworks etc. | | ✅ |
45
+ | `XMLName` | `svg\|[attributeName]` and more | [XML](https://www.w3.org/TR/xml/#d0e804) | ✅ |
46
+ | `DOMID` | The `id` attribute and more | [WHATWG](https://html.spec.whatwg.org/multipage/dom.html#global-attributes:concept-id) | ✅ |
47
+ | `FunctionBody` | Event handler attributes | | 🚧 |
48
+ | `Pattern` | `input[pattern]` | [WHATWG](https://html.spec.whatwg.org/multipage/input.html#compiled-pattern-regular-expression) | ✅ |
49
+ | `DateTime` | `time[datetime]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/text-level-semantics.html#datetime-value) | ✅ |
50
+ | `TabIndex` | The `tabindex` attribute | [WHATWG](https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex) | ✅ |
51
+ | `BCP47` | The `lang` attribute and more | [RFC](https://tools.ietf.org/rfc/bcp/bcp47.html) | ✅ |
52
+ | `URL` | Some attributes | [WHATWG](https://html.spec.whatwg.org/multipage/urls-and-fetching.html#valid-url-potentially-surrounded-by-spaces) | ✅ |
53
+ | `AbsoluteURL` | The `itemtype` attribute (as list) | [WHATWG](https://url.spec.whatwg.org/#syntax-url-absolute) | ✅ |
54
+ | `HashName` | `img[usemap]` | [WHATWG](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-hash-name-reference) | ✅ |
55
+ | `OneCodePointChar` | The `accesskey` attribute (as list) | [WHATWG](https://html.spec.whatwg.org/multipage/interaction.html#the-accesskey-attribute) | ✅ |
56
+ | `CustomElementName` | The `is` attribute | [WHATWG](https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name) | ✅ |
57
+ | ~~`BrowsingContextName`~~ | Use `NavigableTargetName` instead. | **Obsolated** | ✅ |
58
+ | ~~`BrowsingContextNameOrKeyword`~~ | Use `NavigableTargetNameOrKeyword` instead. | **Obsolated** | ✅ |
59
+ | `NavigableTargetName` | `iframe[name]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name) | ✅ |
60
+ | `NavigableTargetNameOrKeyword` | `a[target]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name-or-keyword) | ✅ |
61
+ | `HTTPSchemaURL` | `a[ping]` (as list) and more | [WHATWG](https://html.spec.whatwg.org/multipage/links.html#ping) | ✅ |
62
+ | `MIMEType` | `embed[type]` and more | [WHATWG](https://mimesniff.spec.whatwg.org/#valid-mime-type) | ✅ |
63
+ | `ItemProp` | The `itemprop` attribute (as list) | [WHATWG](https://html.spec.whatwg.org/multipage/microdata.html#names:-the-itemprop-attribute) | ✅ |
64
+ | `Srcset` | `img[srcset]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/images.html#srcset-attributes) | ✅ |
65
+ | `SourceSizeList` | `img[sizes]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/images.html#sizes-attributes) | ✅ |
66
+ | `IconSize` | `link[sizes]` (as list) | [WHATWG](https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes) | ✅ |
67
+ | `AutoComplete` | `input[autocomplete]` and more | [WHATWG](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete) | ✅ |
68
+ | `Accept` | `input[accept]` | [WHATWG](https://html.spec.whatwg.org/multipage/input.html#attr-input-accept) | ✅ |
69
+ | `SerializedPermissionsPolicy` | `iframe[allow]` | [W3C](https://w3c.github.io/webappsec-permissions-policy/#serialized-permissions-policy) | ✅ |
70
+ | `LinkTypeForLinkElement` | `link[rel]` | [WHATWG](https://html.spec.whatwg.org/multipage/links.html#linkTypes) [microformats](https://microformats.org/wiki/existing-rel-values) | ✅ |
71
+ | `LinkTypeForLinkElementInBody` | `link[rel]` in `<body>` | [WHATWG](https://html.spec.whatwg.org/multipage/links.html#body-ok) [microformats](https://microformats.org/wiki/existing-rel-values#HTML5_link_type_extensions) | ✅ |
72
+ | `LinkTypeForAnchorAndAreaElement` | `a[rel]`, `area[rel]` | [WHATWG](https://html.spec.whatwg.org/multipage/links.html#linkTypes) [microformats](https://microformats.org/wiki/existing-rel-values#HTML5_link_type_extensions) | |
73
+ | `LinkTypeForFormElement` | `form[rel]` | [WHATWG](https://html.spec.whatwg.org/multipage/links.html#linkTypes) [microformats](https://microformats.org/wiki/existing-rel-values#HTML5_link_type_extensions) | |
74
+ | `<css-declaration-list>` | The `style` attribute | [CSS](https://drafts.csswg.org/css-style-attr/#syntax) | |
75
+ | `<class-list>` | The `class` attribute | [SVG](https://www.w3.org/TR/SVG/styling.html#ClassAttribute) | |
76
+ | `<svg-font-size>` | Some attributes for SVG | [CSS](https://drafts.csswg.org/css-fonts-5/#descdef-font-face-font-size) | 🚧 |
77
+ | `<svg-font-size-adjust>` | Some attributes for SVG | [CSS](https://drafts.csswg.org/css-fonts-5/#propdef-font-size-adjust) | 🚧 |
78
+ | `<'color-profile'>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/color.html#ColorProfileProperty) | 🚧 |
79
+ | `<'color-rendering'>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/painting.html#ColorRenderingProperty) | 🚧 |
80
+ | `<'enable-background'>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/filters.html#EnableBackgroundProperty) | 🚧 |
81
+ | `<list-of-svg-feature-string>` | Some attributes for SVG | [SVG](https://www.w3.org/TR/SVG11/feature.html) | 🚧 |
82
+ | `<animatable-value>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#FromAttribute) | 🚧 |
83
+ | `<begin-value-list>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#BeginValueListSyntax) | 🚧 |
84
+ | `<end-value-list>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#EndValueListSyntax) | 🚧 |
85
+ | `<list-of-value>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#ValuesAttribute) | 🚧 |
86
+ | `<clock-value>` | Some attributes for SVG | [SMIL](https://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-ClockValueSyntax) | 🚧 |
87
+ | `<color-matrix>` | Some attributes for SVG | [W3C](https://drafts.fxtf.org/filter-effects/#element-attrdef-fecolormatrix-values) | ✅ |
88
+ | `<dasharray>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/painting.html#StrokeDasharrayProperty) | ✅ |
89
+ | `<key-points>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#KeyPointsAttribute) | ✅ |
90
+ | `<key-splines>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#KeyTimesAttribute) | |
91
+ | `<key-times>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#KeyTimesAttribute) | ✅ |
92
+ | `<system-language>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/struct.html#SystemLanguageAttribute) | ✅ |
93
+ | `<origin>` | Some attributes for SVG | [SMIL](https://www.w3.org/TR/2001/REC-smil-animation-20010904/#MotionOriginAttribute) | ✅ |
94
+ | `<svg-path>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/paths.html#PathDataBNF) | 🚧 |
95
+ | `<points>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/shapes.html#DataTypePoints) | ✅ |
96
+ | `<preserve-aspect-ratio>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/coords.html#PreserveAspectRatioAttribute) | ✅ |
97
+ | `<view-box>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/coords.html#ViewBoxAttribute) | ✅ |
98
+ | `<rotate>` | Some attributes for SVG | [SVG](https://svgwg.org/specs/animations/#RotateAttribute) | ✅ |
99
+ | `<text-coordinate>` | Some attributes for SVG | [SVG](https://svgwg.org/svg2-draft/text.html#TSpanAttributes) | ✅ |
100
+ | `<list-of-lengths>` | Some attributes for SVG | | ✅ |
101
+ | `<list-of-numbers>` | Some attributes for SVG | | ✅ |
102
+ | `<list-of-percentages>` | Some attributes for SVG | | ✅ |
103
+ | `<number-optional-number>` | Some attributes for SVG | | ✅ |
100
104
 
101
105
  In addition, you can use types **[CSSTree](https://github.com/csstree/csstree)** defined.
102
106
 
@@ -0,0 +1,10 @@
1
+ import type { Type, Result, List, CustomSyntax, CustomCssSyntax, Enum, KeywordDefinedType, Number, Directive, Defs } from './types.js';
2
+ import type { ReadonlyDeep } from 'type-fest';
3
+ export declare function checkBase(value: string, type: ReadonlyDeep<Type>, defs: Defs, ref?: string, cache?: boolean): Result;
4
+ export declare function isKeyword(type: ReadonlyDeep<Type>): type is ReadonlyDeep<KeywordDefinedType>;
5
+ export declare function isList(type: ReadonlyDeep<Type>): type is ReadonlyDeep<List>;
6
+ export declare function isEnum(type: ReadonlyDeep<Type>): type is ReadonlyDeep<Enum>;
7
+ export declare function isNumber(type: ReadonlyDeep<Type>): type is ReadonlyDeep<Number>;
8
+ export declare function isDirective(type: ReadonlyDeep<Type>): type is ReadonlyDeep<Directive>;
9
+ export declare function isCSSSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomCssSyntax;
10
+ export declare function isCustomSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomSyntax;
@@ -0,0 +1,50 @@
1
+ import { log } from './debug.js';
2
+ import { checkDirective } from './directive.js';
3
+ import { checkEnum } from './enum.js';
4
+ import { checkKeywordType } from './keyword-type.js';
5
+ import { checkList } from './list.js';
6
+ import { checkNumber } from './number.js';
7
+ export function checkBase(value, type, defs, ref, cache = true) {
8
+ if (isKeyword(type)) {
9
+ log('Check keyword: %s', type);
10
+ return checkKeywordType(value, type, defs, cache);
11
+ }
12
+ if (isList(type)) {
13
+ log('Check list: %O', type);
14
+ return checkList(value, type, defs, ref, cache);
15
+ }
16
+ if (isEnum(type)) {
17
+ log('Check enum: %O', type);
18
+ return checkEnum(value, type, ref);
19
+ }
20
+ if (isNumber(type)) {
21
+ log('Check number: %O', type);
22
+ return checkNumber(value, type, ref);
23
+ }
24
+ if (isDirective(type)) {
25
+ log('Check directive: %O', type);
26
+ return checkDirective(value, type, defs, ref, cache);
27
+ }
28
+ throw new Error('Unknown type');
29
+ }
30
+ export function isKeyword(type) {
31
+ return typeof type === 'string';
32
+ }
33
+ export function isList(type) {
34
+ return typeof type !== 'string' && 'separator' in type;
35
+ }
36
+ export function isEnum(type) {
37
+ return typeof type !== 'string' && 'enum' in type;
38
+ }
39
+ export function isNumber(type) {
40
+ return typeof type !== 'string' && 'type' in type && (type.type === 'float' || type.type === 'integer');
41
+ }
42
+ export function isDirective(type) {
43
+ return typeof type !== 'string' && 'directive' in type;
44
+ }
45
+ export function isCSSSyntax(type) {
46
+ return typeof type === 'string' || 'syntax' in type;
47
+ }
48
+ export function isCustomSyntax(type) {
49
+ return !isCSSSyntax(type);
50
+ }
package/lib/check.d.ts CHANGED
@@ -1,10 +1,3 @@
1
- import type { Type, Result, List, CustomSyntax, CustomCssSyntax, Enum, KeywordDefinedType, Number, Directive } from './types.js';
1
+ import type { Type, Result } from './types.js';
2
2
  import type { ReadonlyDeep } from 'type-fest';
3
3
  export declare function check(value: string, type: ReadonlyDeep<Type>, ref?: string, cache?: boolean): Result;
4
- export declare function isKeyword(type: ReadonlyDeep<Type>): type is ReadonlyDeep<KeywordDefinedType>;
5
- export declare function isList(type: ReadonlyDeep<Type>): type is ReadonlyDeep<List>;
6
- export declare function isEnum(type: ReadonlyDeep<Type>): type is ReadonlyDeep<Enum>;
7
- export declare function isNumber(type: ReadonlyDeep<Type>): type is ReadonlyDeep<Number>;
8
- export declare function isDirective(type: ReadonlyDeep<Type>): type is ReadonlyDeep<Directive>;
9
- export declare function isCSSSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomCssSyntax;
10
- export declare function isCustomSyntax(type: CustomSyntax | CustomCssSyntax): type is CustomSyntax;
package/lib/check.js CHANGED
@@ -1,50 +1,6 @@
1
- import { log } from './debug.js';
2
- import { checkDirective } from './directive.js';
3
- import { checkEnum } from './enum.js';
4
- import { checkKeywordType } from './keyword-type.js';
5
- import { checkList } from './list.js';
6
- import { checkNumber } from './number.js';
1
+ import { checkBase } from './check-base.js';
2
+ import { defs } from './defs.js';
3
+ import { cssDefs } from './css-defs.js';
7
4
  export function check(value, type, ref, cache = true) {
8
- if (isKeyword(type)) {
9
- log('Check keyword: %s', type);
10
- return checkKeywordType(value, type, cache);
11
- }
12
- if (isList(type)) {
13
- log('Check list: %O', type);
14
- return checkList(value, type, ref, cache);
15
- }
16
- if (isEnum(type)) {
17
- log('Check enum: %O', type);
18
- return checkEnum(value, type, ref);
19
- }
20
- if (isNumber(type)) {
21
- log('Check number: %O', type);
22
- return checkNumber(value, type, ref);
23
- }
24
- if (isDirective(type)) {
25
- log('Check directive: %O', type);
26
- return checkDirective(value, type, ref);
27
- }
28
- throw new Error('Unknown type');
29
- }
30
- export function isKeyword(type) {
31
- return typeof type === 'string';
32
- }
33
- export function isList(type) {
34
- return typeof type !== 'string' && 'separator' in type;
35
- }
36
- export function isEnum(type) {
37
- return typeof type !== 'string' && 'enum' in type;
38
- }
39
- export function isNumber(type) {
40
- return typeof type !== 'string' && 'type' in type && (type.type === 'float' || type.type === 'integer');
41
- }
42
- export function isDirective(type) {
43
- return typeof type !== 'string' && 'directive' in type;
44
- }
45
- export function isCSSSyntax(type) {
46
- return typeof type === 'string' || 'syntax' in type;
47
- }
48
- export function isCustomSyntax(type) {
49
- return !isCSSSyntax(type);
5
+ return checkBase(value, type, { ...defs, ...cssDefs }, ref, cache);
50
6
  }
@@ -0,0 +1,2 @@
1
+ import type { Defs } from './types.js';
2
+ export declare const cssDefs: Defs;
@@ -0,0 +1,246 @@
1
+ import { matched } from './match-result.js';
2
+ export const cssDefs = {
3
+ '<css-declaration-list>': {
4
+ ref: 'https://drafts.csswg.org/css-style-attr/#syntax',
5
+ syntax: {
6
+ apply: '<css-declaration-list>',
7
+ def: {
8
+ 'css-declaration-list': '<declaration-list>',
9
+ },
10
+ },
11
+ },
12
+ // DO NOT USE: Issue #564
13
+ '<class-list>': {
14
+ ref: 'https://www.w3.org/TR/SVG/styling.html#ClassAttribute',
15
+ syntax: {
16
+ apply: '<class-list>',
17
+ def: {
18
+ 'class-list': '<ident-token>*',
19
+ },
20
+ },
21
+ },
22
+ '<svg-font-size>': {
23
+ ref: 'https://drafts.csswg.org/css-fonts-5/#descdef-font-face-font-size',
24
+ // TODO:
25
+ is: () => matched(),
26
+ },
27
+ '<svg-font-size-adjust>': {
28
+ ref: 'https://drafts.csswg.org/css-fonts-5/#propdef-font-size-adjust',
29
+ // TODO:
30
+ is: () => matched(),
31
+ },
32
+ "<'color-profile'>": {
33
+ ref: 'https://www.w3.org/TR/SVG11/color.html#ColorProfileProperty',
34
+ // TODO:
35
+ is: () => matched(),
36
+ },
37
+ "<'color-rendering'>": {
38
+ ref: 'https://www.w3.org/TR/SVG11/painting.html#ColorRenderingProperty',
39
+ // TODO:
40
+ is: () => matched(),
41
+ },
42
+ "<'enable-background'>": {
43
+ ref: 'https://www.w3.org/TR/SVG11/filters.html#EnableBackgroundProperty',
44
+ // TODO:
45
+ is: () => matched(),
46
+ },
47
+ '<list-of-svg-feature-string>': {
48
+ ref: 'https://www.w3.org/TR/SVG11/feature.html',
49
+ // TODO:
50
+ is: () => matched(),
51
+ },
52
+ '<animatable-value>': {
53
+ ref: 'https://svgwg.org/specs/animations/#FromAttribute',
54
+ // TODO:
55
+ is: () => matched(),
56
+ },
57
+ '<begin-value-list>': {
58
+ ref: 'https://svgwg.org/specs/animations/#BeginValueListSyntax',
59
+ // TODO:
60
+ is: () => matched(),
61
+ },
62
+ '<end-value-list>': {
63
+ ref: 'https://svgwg.org/specs/animations/#EndValueListSyntax',
64
+ // TODO:
65
+ is: () => matched(),
66
+ },
67
+ '<list-of-value>': {
68
+ ref: 'https://svgwg.org/specs/animations/#ValuesAttribute',
69
+ // TODO:
70
+ is: () => matched(),
71
+ },
72
+ '<clock-value>': {
73
+ ref: 'https://www.w3.org/TR/2001/REC-smil-animation-20010904/#Timing-ClockValueSyntax',
74
+ syntax: {
75
+ // TODO:
76
+ apply: '<clock-value>',
77
+ def: {
78
+ 'clock-value': '<any-value>',
79
+ },
80
+ },
81
+ },
82
+ '<color-matrix>': {
83
+ ref: 'https://drafts.fxtf.org/filter-effects/#element-attrdef-fecolormatrix-values',
84
+ syntax: {
85
+ apply: '<color-matrix>',
86
+ def: {
87
+ 'color-matrix': '[ <number-zero-one> [,]? ]{19} <number-zero-one>',
88
+ },
89
+ },
90
+ },
91
+ '<dasharray>': {
92
+ ref: 'https://svgwg.org/svg2-draft/painting.html#StrokeDasharrayProperty',
93
+ syntax: {
94
+ apply: '<dasharray>',
95
+ def: {
96
+ dasharray: '[ [ <svg-length> | <percentage> | <number> ]+ ]#',
97
+ },
98
+ },
99
+ },
100
+ '<key-points>': {
101
+ ref: 'https://svgwg.org/specs/animations/#KeyPointsAttribute',
102
+ syntax: {
103
+ apply: '<key-points>',
104
+ def: {
105
+ 'key-points': '<number> [; <number>]* [;]?',
106
+ },
107
+ },
108
+ },
109
+ '<key-splines>': {
110
+ ref: 'https://svgwg.org/specs/animations/#KeyTimesAttribute',
111
+ syntax: {
112
+ apply: '<key-splines>',
113
+ def: {
114
+ 'key-splines': '<control-point> [; <control-point>]* [;]?',
115
+ 'control-point': '<number> [,]? <number> [,]? <number> [,]? <number>',
116
+ },
117
+ },
118
+ },
119
+ '<key-times>': {
120
+ ref: 'https://svgwg.org/specs/animations/#KeyTimesAttribute',
121
+ syntax: {
122
+ apply: '<key-times>',
123
+ def: {
124
+ 'key-times': '<number> [; <number>]* [;]?',
125
+ },
126
+ },
127
+ },
128
+ '<system-language>': {
129
+ ref: 'https://svgwg.org/svg2-draft/struct.html#SystemLanguageAttribute',
130
+ syntax: {
131
+ apply: '<system-language>',
132
+ def: {
133
+ 'system-language': '<bcp-47>#',
134
+ },
135
+ },
136
+ },
137
+ '<origin>': {
138
+ ref: 'https://www.w3.org/TR/2001/REC-smil-animation-20010904/#MotionOriginAttribute',
139
+ syntax: {
140
+ apply: '<origin>',
141
+ def: {
142
+ origin: 'default',
143
+ },
144
+ },
145
+ },
146
+ '<svg-path>': {
147
+ ref: 'https://svgwg.org/svg2-draft/paths.html#PathDataBNF',
148
+ syntax: {
149
+ apply: '<svg-path>',
150
+ // TODO:
151
+ def: {
152
+ 'svg-path': '<any-value>',
153
+ },
154
+ },
155
+ },
156
+ '<points>': {
157
+ ref: 'https://svgwg.org/svg2-draft/shapes.html#DataTypePoints',
158
+ syntax: {
159
+ apply: '<points>',
160
+ def: {
161
+ points: '[ <number>+ ]#',
162
+ },
163
+ },
164
+ },
165
+ '<preserve-aspect-ratio>': {
166
+ ref: 'https://svgwg.org/svg2-draft/coords.html#PreserveAspectRatioAttribute',
167
+ syntax: {
168
+ apply: '<preserve-aspect-ratio>',
169
+ def: {
170
+ 'preserve-aspect-ratio': '<align> <meet-or-slice>?',
171
+ align: 'none | xMinYMin | xMidYMin | xMaxYMin | xMinYMid | xMidYMid | xMaxYMid| xMinYMax | xMidYMax | xMaxYMax',
172
+ 'meet-or-slice': 'meet | slice',
173
+ },
174
+ // A new spec
175
+ // @see https://drafts.fxtf.org/filter-effects/#element-attrdef-feimage-preserveaspectratio
176
+ // > preserveAspectRatio = "[defer] <align> [<meetOrSlice>]"
177
+ },
178
+ },
179
+ '<view-box>': {
180
+ ref: 'https://svgwg.org/svg2-draft/coords.html#ViewBoxAttribute',
181
+ syntax: {
182
+ apply: '<view-box>',
183
+ def: {
184
+ 'view-box': '<min-x> [,]? <min-y> [,]? <width> [,]? <height>', // As '[<min-x>,? <min-y>,? <width>,? <height>]',
185
+ 'min-x': '<number>',
186
+ 'min-y': '<number>',
187
+ width: '<number>',
188
+ height: '<number>',
189
+ },
190
+ },
191
+ },
192
+ '<rotate>': {
193
+ ref: 'https://svgwg.org/specs/animations/#RotateAttribute',
194
+ syntax: {
195
+ apply: '<rotate>',
196
+ def: {
197
+ rotate: '<number> | auto | auto-reverse',
198
+ },
199
+ },
200
+ },
201
+ '<text-coordinate>': {
202
+ ref: 'https://svgwg.org/svg2-draft/text.html#TSpanAttributes',
203
+ syntax: {
204
+ apply: '<text-coordinate>',
205
+ def: {
206
+ 'text-coordinate': '[ [ <svg-length> | <percentage> | <number> ]+ ]#',
207
+ },
208
+ },
209
+ },
210
+ '<list-of-lengths>': {
211
+ ref: 'https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#list-of-ts',
212
+ syntax: {
213
+ apply: '<list-of-lengths>',
214
+ def: {
215
+ 'list-of-lengths': '[ <svg-length> [,]? ]* <svg-length>',
216
+ },
217
+ },
218
+ },
219
+ '<list-of-numbers>': {
220
+ ref: 'https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#list-of-ts',
221
+ syntax: {
222
+ apply: '<list-of-numbers>',
223
+ def: {
224
+ 'list-of-numbers': '[ <number> [,]? ]* <number>',
225
+ },
226
+ },
227
+ },
228
+ '<list-of-percentages>': {
229
+ ref: 'https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#percentage',
230
+ syntax: {
231
+ apply: '<list-of-percentages>',
232
+ def: {
233
+ 'list-of-percentages': '[ <percentage> [,]? ]* <percentage>',
234
+ },
235
+ },
236
+ },
237
+ '<number-optional-number>': {
238
+ ref: 'https://developer.mozilla.org/en-US/docs/Web/SVG/Content_type#number-optional-number',
239
+ syntax: {
240
+ apply: '<number-optional-number>',
241
+ def: {
242
+ 'number-optional-number': '<number> | <number> , <number>',
243
+ },
244
+ },
245
+ },
246
+ };
@@ -0,0 +1 @@
1
+ export declare const cssOverrides: Record<string, string>;
@@ -0,0 +1,21 @@
1
+ export const cssOverrides = {
2
+ // Alias
3
+ 'legacy-length-percentage': '<length> | <percentage> | <svg-length>',
4
+ 'legacy-angle': '<angle> | <zero> | <number>',
5
+ /**
6
+ * @see https://www.w3.org/TR/css-transforms-1/#funcdef-transform-translate
7
+ */
8
+ 'translate()': 'translate( <legacy-length-percentage> , <legacy-length-percentage>? ) | translate( <legacy-length-percentage> <legacy-length-percentage>? )',
9
+ /**
10
+ * @see https://www.w3.org/TR/css-transforms-1/#funcdef-transform-scale
11
+ */
12
+ 'scale()': 'scale( [ <number> | <percentage> ]#{1,2} )',
13
+ /**
14
+ * @see https://www.w3.org/TR/css-transforms-1/#funcdef-transform-rotate
15
+ */
16
+ 'rotate()': 'rotate( <legacy-angle> )',
17
+ /**
18
+ * @see https://www.w3.org/TR/css-transforms-1/#funcdef-transform-skew
19
+ */
20
+ 'skew()': 'skew( <legacy-angle> , <legacy-angle>? ) | skew( <legacy-angle> <legacy-angle>? )',
21
+ };