@dazl/shorthands-opener 4.2.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/README.md +3 -0
- package/dist/compounds/compound-css-data.d.ts +22 -0
- package/dist/compounds/compound-css-data.d.ts.map +1 -0
- package/dist/compounds/compound-css-data.js +2 -0
- package/dist/compounds/compound-css-data.js.map +1 -0
- package/dist/compounds/compound-mapper.d.ts +4 -0
- package/dist/compounds/compound-mapper.d.ts.map +1 -0
- package/dist/compounds/compound-mapper.js +10 -0
- package/dist/compounds/compound-mapper.js.map +1 -0
- package/dist/compounds/compound-parser-utils.d.ts +3 -0
- package/dist/compounds/compound-parser-utils.d.ts.map +1 -0
- package/dist/compounds/compound-parser-utils.js +33 -0
- package/dist/compounds/compound-parser-utils.js.map +1 -0
- package/dist/compounds/compound-types.d.ts +26 -0
- package/dist/compounds/compound-types.d.ts.map +1 -0
- package/dist/compounds/compound-types.js +2 -0
- package/dist/compounds/compound-types.js.map +1 -0
- package/dist/compounds/compound-value-parsers.d.ts +6 -0
- package/dist/compounds/compound-value-parsers.d.ts.map +1 -0
- package/dist/compounds/compound-value-parsers.js +5 -0
- package/dist/compounds/compound-value-parsers.js.map +1 -0
- package/dist/compounds/index.d.ts +6 -0
- package/dist/compounds/index.d.ts.map +1 -0
- package/dist/compounds/index.js +6 -0
- package/dist/compounds/index.js.map +1 -0
- package/dist/compounds/parsers/index.d.ts +2 -0
- package/dist/compounds/parsers/index.d.ts.map +1 -0
- package/dist/compounds/parsers/index.js +2 -0
- package/dist/compounds/parsers/index.js.map +1 -0
- package/dist/compounds/parsers/shadow-compound.d.ts +5 -0
- package/dist/compounds/parsers/shadow-compound.d.ts.map +1 -0
- package/dist/compounds/parsers/shadow-compound.js +39 -0
- package/dist/compounds/parsers/shadow-compound.js.map +1 -0
- package/dist/css-data-types/data-types-consts.d.ts +212 -0
- package/dist/css-data-types/data-types-consts.d.ts.map +1 -0
- package/dist/css-data-types/data-types-consts.js +790 -0
- package/dist/css-data-types/data-types-consts.js.map +1 -0
- package/dist/css-data-types/data-types-predicates.d.ts +32 -0
- package/dist/css-data-types/data-types-predicates.d.ts.map +1 -0
- package/dist/css-data-types/data-types-predicates.js +353 -0
- package/dist/css-data-types/data-types-predicates.js.map +1 -0
- package/dist/css-data-types/data-types-state-machines.d.ts +14 -0
- package/dist/css-data-types/data-types-state-machines.d.ts.map +1 -0
- package/dist/css-data-types/data-types-state-machines.js +129 -0
- package/dist/css-data-types/data-types-state-machines.js.map +1 -0
- package/dist/css-data-types/data-types-types.d.ts +26 -0
- package/dist/css-data-types/data-types-types.d.ts.map +1 -0
- package/dist/css-data-types/data-types-types.js +2 -0
- package/dist/css-data-types/data-types-types.js.map +1 -0
- package/dist/css-data-types/data-types-utils.d.ts +31 -0
- package/dist/css-data-types/data-types-utils.d.ts.map +1 -0
- package/dist/css-data-types/data-types-utils.js +176 -0
- package/dist/css-data-types/data-types-utils.js.map +1 -0
- package/dist/css-data-types/data-types.d.ts +64 -0
- package/dist/css-data-types/data-types.d.ts.map +1 -0
- package/dist/css-data-types/data-types.js +304 -0
- package/dist/css-data-types/data-types.js.map +1 -0
- package/dist/css-data-types/index.d.ts +7 -0
- package/dist/css-data-types/index.d.ts.map +1 -0
- package/dist/css-data-types/index.js +7 -0
- package/dist/css-data-types/index.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/shorthands/index.d.ts +8 -0
- package/dist/shorthands/index.d.ts.map +1 -0
- package/dist/shorthands/index.js +8 -0
- package/dist/shorthands/index.js.map +1 -0
- package/dist/shorthands/openers/background-position-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/background-position-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/background-position-shorthand.js +173 -0
- package/dist/shorthands/openers/background-position-shorthand.js.map +1 -0
- package/dist/shorthands/openers/background-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/background-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/background-shorthand.js +88 -0
- package/dist/shorthands/openers/background-shorthand.js.map +1 -0
- package/dist/shorthands/openers/border-image-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/border-image-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/border-image-shorthand.js +16 -0
- package/dist/shorthands/openers/border-image-shorthand.js.map +1 -0
- package/dist/shorthands/openers/border-radius-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/border-radius-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/border-radius-shorthand.js +61 -0
- package/dist/shorthands/openers/border-radius-shorthand.js.map +1 -0
- package/dist/shorthands/openers/border-shorthand.d.ts +20 -0
- package/dist/shorthands/openers/border-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/border-shorthand.js +90 -0
- package/dist/shorthands/openers/border-shorthand.js.map +1 -0
- package/dist/shorthands/openers/flex-flow-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/flex-flow-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/flex-flow-shorthand.js +13 -0
- package/dist/shorthands/openers/flex-flow-shorthand.js.map +1 -0
- package/dist/shorthands/openers/flex-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/flex-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/flex-shorthand.js +55 -0
- package/dist/shorthands/openers/flex-shorthand.js.map +1 -0
- package/dist/shorthands/openers/font-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/font-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/font-shorthand.js +60 -0
- package/dist/shorthands/openers/font-shorthand.js.map +1 -0
- package/dist/shorthands/openers/gap-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/gap-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/gap-shorthand.js +28 -0
- package/dist/shorthands/openers/gap-shorthand.js.map +1 -0
- package/dist/shorthands/openers/grid-axis-shorthand.d.ts +6 -0
- package/dist/shorthands/openers/grid-axis-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/grid-axis-shorthand.js +36 -0
- package/dist/shorthands/openers/grid-axis-shorthand.js.map +1 -0
- package/dist/shorthands/openers/grid-gap-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/grid-gap-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/grid-gap-shorthand.js +21 -0
- package/dist/shorthands/openers/grid-gap-shorthand.js.map +1 -0
- package/dist/shorthands/openers/grid-shorthand.d.ts +8 -0
- package/dist/shorthands/openers/grid-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/grid-shorthand.js +145 -0
- package/dist/shorthands/openers/grid-shorthand.js.map +1 -0
- package/dist/shorthands/openers/grid-template-shorthand.d.ts +10 -0
- package/dist/shorthands/openers/grid-template-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/grid-template-shorthand.js +113 -0
- package/dist/shorthands/openers/grid-template-shorthand.js.map +1 -0
- package/dist/shorthands/openers/index.d.ts +22 -0
- package/dist/shorthands/openers/index.d.ts.map +1 -0
- package/dist/shorthands/openers/index.js +22 -0
- package/dist/shorthands/openers/index.js.map +1 -0
- package/dist/shorthands/openers/list-style-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/list-style-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/list-style-shorthand.js +15 -0
- package/dist/shorthands/openers/list-style-shorthand.js.map +1 -0
- package/dist/shorthands/openers/margin-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/margin-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/margin-shorthand.js +11 -0
- package/dist/shorthands/openers/margin-shorthand.js.map +1 -0
- package/dist/shorthands/openers/outline-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/outline-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/outline-shorthand.js +14 -0
- package/dist/shorthands/openers/outline-shorthand.js.map +1 -0
- package/dist/shorthands/openers/overflow-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/overflow-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/overflow-shorthand.js +21 -0
- package/dist/shorthands/openers/overflow-shorthand.js.map +1 -0
- package/dist/shorthands/openers/padding-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/padding-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/padding-shorthand.js +11 -0
- package/dist/shorthands/openers/padding-shorthand.js.map +1 -0
- package/dist/shorthands/openers/place-content-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/place-content-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/place-content-shorthand.js +29 -0
- package/dist/shorthands/openers/place-content-shorthand.js.map +1 -0
- package/dist/shorthands/openers/place-items-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/place-items-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/place-items-shorthand.js +23 -0
- package/dist/shorthands/openers/place-items-shorthand.js.map +1 -0
- package/dist/shorthands/openers/text-decoration-shorthand.d.ts +5 -0
- package/dist/shorthands/openers/text-decoration-shorthand.d.ts.map +1 -0
- package/dist/shorthands/openers/text-decoration-shorthand.js +14 -0
- package/dist/shorthands/openers/text-decoration-shorthand.js.map +1 -0
- package/dist/shorthands/shorthand-css-data.d.ts +120 -0
- package/dist/shorthands/shorthand-css-data.d.ts.map +1 -0
- package/dist/shorthands/shorthand-css-data.js +48 -0
- package/dist/shorthands/shorthand-css-data.js.map +1 -0
- package/dist/shorthands/shorthand-mapper.d.ts +6 -0
- package/dist/shorthands/shorthand-mapper.d.ts.map +1 -0
- package/dist/shorthands/shorthand-mapper.js +72 -0
- package/dist/shorthands/shorthand-mapper.js.map +1 -0
- package/dist/shorthands/shorthand-parser-errors.d.ts +25 -0
- package/dist/shorthands/shorthand-parser-errors.d.ts.map +1 -0
- package/dist/shorthands/shorthand-parser-errors.js +41 -0
- package/dist/shorthands/shorthand-parser-errors.js.map +1 -0
- package/dist/shorthands/shorthand-parser-utils.d.ts +24 -0
- package/dist/shorthands/shorthand-parser-utils.d.ts.map +1 -0
- package/dist/shorthands/shorthand-parser-utils.js +398 -0
- package/dist/shorthands/shorthand-parser-utils.js.map +1 -0
- package/dist/shorthands/shorthand-types.d.ts +64 -0
- package/dist/shorthands/shorthand-types.d.ts.map +1 -0
- package/dist/shorthands/shorthand-types.js +2 -0
- package/dist/shorthands/shorthand-types.js.map +1 -0
- package/dist/shorthands/shorthands-ast-evaluation.d.ts +5 -0
- package/dist/shorthands/shorthands-ast-evaluation.d.ts.map +1 -0
- package/dist/shorthands/shorthands-ast-evaluation.js +19 -0
- package/dist/shorthands/shorthands-ast-evaluation.js.map +1 -0
- package/dist/tokenizers/css-value-tokenizer.d.ts +43 -0
- package/dist/tokenizers/css-value-tokenizer.d.ts.map +1 -0
- package/dist/tokenizers/css-value-tokenizer.js +154 -0
- package/dist/tokenizers/css-value-tokenizer.js.map +1 -0
- package/dist/tokenizers/index.d.ts +2 -0
- package/dist/tokenizers/index.d.ts.map +1 -0
- package/dist/tokenizers/index.js +2 -0
- package/dist/tokenizers/index.js.map +1 -0
- package/package.json +54 -0
- package/src/compounds/compound-css-data.ts +24 -0
- package/src/compounds/compound-mapper.ts +21 -0
- package/src/compounds/compound-parser-utils.ts +47 -0
- package/src/compounds/compound-types.ts +35 -0
- package/src/compounds/compound-value-parsers.ts +12 -0
- package/src/compounds/index.ts +5 -0
- package/src/compounds/parsers/index.ts +1 -0
- package/src/compounds/parsers/shadow-compound.ts +56 -0
- package/src/css-data-types/data-types-consts.ts +877 -0
- package/src/css-data-types/data-types-predicates.ts +477 -0
- package/src/css-data-types/data-types-state-machines.ts +169 -0
- package/src/css-data-types/data-types-types.ts +43 -0
- package/src/css-data-types/data-types-utils.ts +258 -0
- package/src/css-data-types/data-types.ts +435 -0
- package/src/css-data-types/index.ts +6 -0
- package/src/index.ts +4 -0
- package/src/shorthands/index.ts +7 -0
- package/src/shorthands/openers/background-position-shorthand.ts +180 -0
- package/src/shorthands/openers/background-shorthand.ts +161 -0
- package/src/shorthands/openers/border-image-shorthand.ts +35 -0
- package/src/shorthands/openers/border-radius-shorthand.ts +93 -0
- package/src/shorthands/openers/border-shorthand.ts +198 -0
- package/src/shorthands/openers/flex-flow-shorthand.ts +24 -0
- package/src/shorthands/openers/flex-shorthand.ts +79 -0
- package/src/shorthands/openers/font-shorthand.ts +85 -0
- package/src/shorthands/openers/gap-shorthand.ts +47 -0
- package/src/shorthands/openers/grid-axis-shorthand.ts +61 -0
- package/src/shorthands/openers/grid-gap-shorthand.ts +40 -0
- package/src/shorthands/openers/grid-shorthand.ts +260 -0
- package/src/shorthands/openers/grid-template-shorthand.ts +176 -0
- package/src/shorthands/openers/index.ts +21 -0
- package/src/shorthands/openers/list-style-shorthand.ts +33 -0
- package/src/shorthands/openers/margin-shorthand.ts +20 -0
- package/src/shorthands/openers/outline-shorthand.ts +27 -0
- package/src/shorthands/openers/overflow-shorthand.ts +40 -0
- package/src/shorthands/openers/padding-shorthand.ts +21 -0
- package/src/shorthands/openers/place-content-shorthand.ts +49 -0
- package/src/shorthands/openers/place-items-shorthand.ts +43 -0
- package/src/shorthands/openers/text-decoration-shorthand.ts +27 -0
- package/src/shorthands/shorthand-css-data.ts +210 -0
- package/src/shorthands/shorthand-mapper.ts +157 -0
- package/src/shorthands/shorthand-parser-errors.ts +47 -0
- package/src/shorthands/shorthand-parser-utils.ts +602 -0
- package/src/shorthands/shorthand-types.ts +107 -0
- package/src/shorthands/shorthands-ast-evaluation.ts +38 -0
- package/src/tokenizers/css-value-tokenizer.ts +220 -0
- package/src/tokenizers/index.ts +1 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import type { Descriptors, Delimiters } from '../tokenizers/index.js';
|
|
2
|
+
import type {
|
|
3
|
+
AstItem,
|
|
4
|
+
PredicateMatch,
|
|
5
|
+
PredicateIndexMatch,
|
|
6
|
+
DataTypePredicate,
|
|
7
|
+
PredicatePrefix,
|
|
8
|
+
DataType,
|
|
9
|
+
} from './data-types-types.js';
|
|
10
|
+
import {
|
|
11
|
+
DataTypeType,
|
|
12
|
+
type KeywordsMap,
|
|
13
|
+
INTERNAL_VALUE_SEPERATOR,
|
|
14
|
+
DATA_TYPES_MAP,
|
|
15
|
+
getInitialValue,
|
|
16
|
+
} from './data-types-consts.js';
|
|
17
|
+
|
|
18
|
+
export interface Dimension {
|
|
19
|
+
number: number;
|
|
20
|
+
unit: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface DimensionPredicateOptions {
|
|
24
|
+
units?: string | KeywordsMap;
|
|
25
|
+
min?: number;
|
|
26
|
+
max?: number;
|
|
27
|
+
nonZero?: boolean;
|
|
28
|
+
integer?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const DIMENSION_REGEX = /^[+-]?(\d+|\d*\.\d+|\d*\.?\d+[eE][+-]?\d+)(\D*$)/;
|
|
32
|
+
const DIMENSION_REGEX_UNIT_INDEX = 2;
|
|
33
|
+
// TODO: support unicode and escaped characters
|
|
34
|
+
const IDENTIFIER_REGEX = /^-?[A-Za-z_]([A-Za-z0-9_-])*/;
|
|
35
|
+
const HEX_COLOR_REGEX = /^#([a-fA-F\d]{3,4}|[a-fA-F\d]{6}|[a-fA-F\d]{8})$/;
|
|
36
|
+
const EMPTY_UNIT = '';
|
|
37
|
+
export const EMPTY_DIMENSION: Dimension = { number: 0, unit: EMPTY_UNIT };
|
|
38
|
+
|
|
39
|
+
/** Checks if map has a key in a case-insensitive manner using `toLowerCase()`. */
|
|
40
|
+
function mapHasKeyCaseInsensitive(map: Map<string, unknown>, key: string) {
|
|
41
|
+
return [...map.keys()].map((key) => key.toLowerCase()).includes(key.toLowerCase());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const parseDimension = (text: string): Dimension | undefined => {
|
|
45
|
+
const number = parseFloat(text);
|
|
46
|
+
if (!isNaN(number)) {
|
|
47
|
+
const dimensionMatch = DIMENSION_REGEX.exec(text);
|
|
48
|
+
return dimensionMatch ? { number, unit: dimensionMatch[DIMENSION_REGEX_UNIT_INDEX] || EMPTY_UNIT } : undefined;
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const unorderedListPredicate =
|
|
54
|
+
(keywords: string | KeywordsMap): DataTypePredicate =>
|
|
55
|
+
(ast) =>
|
|
56
|
+
ast.type === 'text' &&
|
|
57
|
+
(typeof keywords === 'string'
|
|
58
|
+
? ast.text.toLowerCase() === keywords.toLowerCase()
|
|
59
|
+
: mapHasKeyCaseInsensitive(keywords, ast.text));
|
|
60
|
+
|
|
61
|
+
export const functionPredicate =
|
|
62
|
+
(functions: string | KeywordsMap): DataTypePredicate =>
|
|
63
|
+
(ast) =>
|
|
64
|
+
ast.type === 'call' &&
|
|
65
|
+
(typeof functions === 'string'
|
|
66
|
+
? ast.name.toLowerCase() === functions.toLowerCase()
|
|
67
|
+
: mapHasKeyCaseInsensitive(functions, ast.name));
|
|
68
|
+
|
|
69
|
+
// <hex-color>
|
|
70
|
+
export const hexColorPredicate = (): DataTypePredicate => (ast) =>
|
|
71
|
+
ast.type === 'text' && HEX_COLOR_REGEX.test(ast.text);
|
|
72
|
+
|
|
73
|
+
// <string>
|
|
74
|
+
export const stringPredicate = (): DataTypePredicate => (ast) => ast.type === 'string';
|
|
75
|
+
|
|
76
|
+
export const dimensionPredicate =
|
|
77
|
+
({ units, min, max, nonZero = false, integer = false }: DimensionPredicateOptions = {}): DataTypePredicate =>
|
|
78
|
+
(ast) => {
|
|
79
|
+
if (ast.type === 'text') {
|
|
80
|
+
const dimension = parseDimension(ast.text);
|
|
81
|
+
if (
|
|
82
|
+
!dimension ||
|
|
83
|
+
(min !== undefined && dimension.number < min) ||
|
|
84
|
+
(max !== undefined && dimension.number > max)
|
|
85
|
+
) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
if (nonZero && dimension.number === 0) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
if (integer) {
|
|
92
|
+
return dimension.number % 1 === 0;
|
|
93
|
+
}
|
|
94
|
+
if (min === undefined && max === undefined && dimension.number === 0) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
if (typeof units === 'string') {
|
|
98
|
+
return dimension.unit.toLowerCase() === units.toLowerCase();
|
|
99
|
+
}
|
|
100
|
+
return units ? mapHasKeyCaseInsensitive(units, dimension.unit) : !dimension.unit;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return false;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const customIdentPredicate =
|
|
107
|
+
(forbiddenKeywords?: string | KeywordsMap): DataTypePredicate =>
|
|
108
|
+
(ast) =>
|
|
109
|
+
ast.type === 'text' &&
|
|
110
|
+
!(forbiddenKeywords && unorderedListPredicate(forbiddenKeywords)(ast)) &&
|
|
111
|
+
IDENTIFIER_REGEX.test(ast.text);
|
|
112
|
+
|
|
113
|
+
export const typePredicate =
|
|
114
|
+
(typeList: Array<'string' | 'call' | 'text' | ',' | '/'>): DataTypePredicate =>
|
|
115
|
+
(ast, index, items) => {
|
|
116
|
+
const startIndex = index ?? 0;
|
|
117
|
+
const astItems = items ?? [{ value: ast }];
|
|
118
|
+
|
|
119
|
+
let item: AstItem | undefined;
|
|
120
|
+
let i = startIndex;
|
|
121
|
+
let matchAmount = 0;
|
|
122
|
+
while ((item = astItems[i++])) {
|
|
123
|
+
const itemType = item.value.type;
|
|
124
|
+
if (typeList.every((typeItem) => itemType !== typeItem)) {
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
matchAmount++;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return matchAmount;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const curlyBracesPredicate =
|
|
134
|
+
(predicates: DataTypePredicate[], min: number, max: number): DataTypePredicate =>
|
|
135
|
+
(ast, index, items) => {
|
|
136
|
+
const startIndex = index ?? 0;
|
|
137
|
+
const astItems = items ?? [{ value: ast }];
|
|
138
|
+
|
|
139
|
+
let item: AstItem | undefined;
|
|
140
|
+
let i = startIndex;
|
|
141
|
+
let matchAmount = 0;
|
|
142
|
+
while ((item = astItems[i++])) {
|
|
143
|
+
let match: PredicateMatch | undefined = undefined;
|
|
144
|
+
for (const predicate of predicates) {
|
|
145
|
+
const predicateMatch = predicate(item.value, i - 1, items);
|
|
146
|
+
if (predicateMatch) {
|
|
147
|
+
match = predicateMatch;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!match || ++matchAmount === max) {
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return matchAmount >= min ? matchAmount : false;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const asteriskPredicate =
|
|
160
|
+
(predicate: DataTypePredicate): DataTypePredicate =>
|
|
161
|
+
(ast, index, items) => {
|
|
162
|
+
const startIndex = index ?? 0;
|
|
163
|
+
const astItems = items ?? [{ value: ast }];
|
|
164
|
+
|
|
165
|
+
let item: AstItem | undefined;
|
|
166
|
+
let i = startIndex;
|
|
167
|
+
let matchAmount = 0;
|
|
168
|
+
while ((item = astItems[i])) {
|
|
169
|
+
if (!predicate(item.value, i++, astItems)) {
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
matchAmount++;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return matchAmount;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export const seperatorPredicate = (): DataTypePredicate => (ast) =>
|
|
179
|
+
ast.type === '/' && ast.text === INTERNAL_VALUE_SEPERATOR;
|
|
180
|
+
|
|
181
|
+
export const seperatorPrefix = (dataType: DataTypeType): PredicatePrefix => ({
|
|
182
|
+
dataType,
|
|
183
|
+
prefixChar: INTERNAL_VALUE_SEPERATOR,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
export const predicateUnion =
|
|
187
|
+
(predicates: DataTypePredicate[]): DataTypePredicate =>
|
|
188
|
+
(ast, index, items, prev) => {
|
|
189
|
+
for (const predicate of predicates) {
|
|
190
|
+
const predicateMatch = predicate(ast, index, items, prev);
|
|
191
|
+
if (predicateMatch) {
|
|
192
|
+
return predicateMatch;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return false;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export const findPredicateIndexMatch = (
|
|
199
|
+
items: AstItem[],
|
|
200
|
+
predicate: DataTypePredicate,
|
|
201
|
+
): PredicateIndexMatch | undefined => {
|
|
202
|
+
let item: AstItem | undefined;
|
|
203
|
+
let i = 0;
|
|
204
|
+
while ((item = items[i])) {
|
|
205
|
+
const predicateMatch = predicate(item.value, i, items);
|
|
206
|
+
if (predicateMatch) {
|
|
207
|
+
return { index: i, length: Number(predicateMatch) };
|
|
208
|
+
}
|
|
209
|
+
i++;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return undefined;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export const createDataType = (dataType: DataTypeType, predicates: DataTypePredicate[]): DataType => {
|
|
216
|
+
const dataTypeData = DATA_TYPES_MAP.get(dataType);
|
|
217
|
+
const prefix = dataTypeData?.prefix ? seperatorPrefix(dataTypeData.prefix) : undefined;
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
dataType,
|
|
221
|
+
initial: getInitialValue(dataType),
|
|
222
|
+
prefix,
|
|
223
|
+
predicate: (ast, index, items, prev) => {
|
|
224
|
+
let predicateAst = ast;
|
|
225
|
+
let predicateIndex = index;
|
|
226
|
+
if (prefix) {
|
|
227
|
+
if (index === undefined || !items || prev !== prefix.dataType) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
const prefixType: Descriptors | Delimiters =
|
|
231
|
+
prefix.prefixChar === INTERNAL_VALUE_SEPERATOR ? '/' : 'text';
|
|
232
|
+
if (ast.type !== prefixType || ast.text !== prefix.prefixChar) {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
predicateIndex = index + 1;
|
|
236
|
+
if (!items[predicateIndex]) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
predicateAst = items[predicateIndex]!.value;
|
|
240
|
+
}
|
|
241
|
+
const predicateMatch = predicateUnion(predicates)(predicateAst, predicateIndex, items, prev);
|
|
242
|
+
if (predicateMatch) {
|
|
243
|
+
return !prefix ? predicateMatch : Number(predicateMatch) + 1;
|
|
244
|
+
}
|
|
245
|
+
return false;
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
export const createUnorderedListDataType = (dataType: DataTypeType): DataType => {
|
|
251
|
+
const dataTypeData = DATA_TYPES_MAP.get(dataType);
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
dataType,
|
|
255
|
+
initial: getInitialValue(dataType),
|
|
256
|
+
predicate: dataTypeData?.keywords ? unorderedListPredicate(dataTypeData.keywords) : () => false,
|
|
257
|
+
};
|
|
258
|
+
};
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import type { DataType } from './data-types-types.js';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
DataTypeType,
|
|
5
|
+
DEFAULT_DIMENSION,
|
|
6
|
+
LINE_WIDTH_KEYWORDS,
|
|
7
|
+
COLOR_FUNCTIONS,
|
|
8
|
+
INITIAL_BACKGROUND_COLOR,
|
|
9
|
+
OUTLINE_COLOR_INVERT_KEYWORD,
|
|
10
|
+
BORDER_IMAGE_REPEAT_MULTIPLE_KEYWORDS,
|
|
11
|
+
GRADIENT_FUNCTIONS,
|
|
12
|
+
IMAGE_FUNCTIONS,
|
|
13
|
+
IMAGE_SOURCE_NONE_KEYWORD,
|
|
14
|
+
BG_SIZE_KEYWORDS,
|
|
15
|
+
REPEAT_STYLE_SINGLE_KEYWORDS,
|
|
16
|
+
REPEAT_STYLE_MULTIPLE_KEYWORDS,
|
|
17
|
+
INITIAL_BACKGROUND_ORIGIN,
|
|
18
|
+
INITIAL_BACKGROUND_CLIP,
|
|
19
|
+
FONT_STYLE_KEYWORDS,
|
|
20
|
+
FONT_WEIGHT_KEYWORDS,
|
|
21
|
+
FONT_WEIGHT_NUMBER_RANGE_MIN,
|
|
22
|
+
FONT_WEIGHT_NUMBER_RANGE_MAX,
|
|
23
|
+
FONT_SIZE_KEYWORDS,
|
|
24
|
+
LINE_HEIGHT_KEYWORD,
|
|
25
|
+
CONTENT_DISTRIBUTION_KEYWORDS,
|
|
26
|
+
CONTENT_POSITION_KEYWORDS,
|
|
27
|
+
ALIGN_CONTENT_KEYWORDS,
|
|
28
|
+
JUSTIFY_CONTENT_KEYWORDS,
|
|
29
|
+
SELF_POSITION_KEYWORDS,
|
|
30
|
+
ALIGN_ITEMS_KEYWORDS,
|
|
31
|
+
JUSTIFY_ITEMS_KEYWORDS,
|
|
32
|
+
FLEX_BASIS_KEYWORDS,
|
|
33
|
+
GRID_LINE_AUTO_KEYWORD,
|
|
34
|
+
GRID_TEMPLATE_AXIS_NONE_KEYWORD,
|
|
35
|
+
INITIAL_GRID_TEMPLATE_AREAS,
|
|
36
|
+
TEXT_DECORATION_LINE_NONE_KEYWORD,
|
|
37
|
+
LIST_STYLE_TYPE_KEYWORDS,
|
|
38
|
+
CURRENT_COLOR_KEYWORD,
|
|
39
|
+
SYSTEM_COLOR_KEYWORDS,
|
|
40
|
+
TRANSPARENT_COLOR_KEYWORD,
|
|
41
|
+
NAMED_COLOR_KEYWORDS,
|
|
42
|
+
} from './data-types-consts.js';
|
|
43
|
+
import {
|
|
44
|
+
unorderedListPredicate,
|
|
45
|
+
functionPredicate,
|
|
46
|
+
hexColorPredicate,
|
|
47
|
+
stringPredicate,
|
|
48
|
+
dimensionPredicate,
|
|
49
|
+
curlyBracesPredicate,
|
|
50
|
+
asteriskPredicate,
|
|
51
|
+
createDataType,
|
|
52
|
+
createUnorderedListDataType,
|
|
53
|
+
} from './data-types-utils.js';
|
|
54
|
+
import {
|
|
55
|
+
numberPredicate,
|
|
56
|
+
lengthPredicate,
|
|
57
|
+
lengthPercentagePredicate,
|
|
58
|
+
autoKeywordPredicate,
|
|
59
|
+
fontStylePredicate,
|
|
60
|
+
fontFamilyStringPredicate,
|
|
61
|
+
textDecorationLinePredicate,
|
|
62
|
+
borderImageSlicePredicate,
|
|
63
|
+
gridLinePredicate,
|
|
64
|
+
trackSizePredicate,
|
|
65
|
+
trackListPredicate,
|
|
66
|
+
explicitTrackListPredicate,
|
|
67
|
+
autoTrackListPredicate,
|
|
68
|
+
gridTemplateAreasStringPredicate,
|
|
69
|
+
gridAutoFlowPredicate,
|
|
70
|
+
basicMathFunctionPredicate,
|
|
71
|
+
} from './data-types-predicates.js';
|
|
72
|
+
import { stateMachineDataTypeMatch, bgPositionStateMachine } from './data-types-state-machines.js';
|
|
73
|
+
|
|
74
|
+
export const ALWAYS_DATA_TYPE: DataType = {
|
|
75
|
+
dataType: DataTypeType.Unknown,
|
|
76
|
+
predicate: () => true,
|
|
77
|
+
initial: DEFAULT_DIMENSION,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// <universal>
|
|
81
|
+
// syntax: inherit | initial | unset | revert
|
|
82
|
+
export const universalDataType = createUnorderedListDataType(DataTypeType.Universal);
|
|
83
|
+
|
|
84
|
+
// <length>
|
|
85
|
+
export const lengthDataType = createDataType(DataTypeType.Length, [lengthPredicate, basicMathFunctionPredicate]);
|
|
86
|
+
|
|
87
|
+
// <length-percentage>
|
|
88
|
+
export const lengthPercentageDataType = createDataType(DataTypeType.LengthPercentage, [
|
|
89
|
+
lengthPercentagePredicate,
|
|
90
|
+
basicMathFunctionPredicate,
|
|
91
|
+
]);
|
|
92
|
+
|
|
93
|
+
// <width>
|
|
94
|
+
export const widthDataType = createDataType(DataTypeType.Width, [
|
|
95
|
+
lengthPercentageDataType.predicate,
|
|
96
|
+
autoKeywordPredicate,
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
// <line-style>
|
|
100
|
+
// syntax: none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset
|
|
101
|
+
export const lineStyleDataType = createUnorderedListDataType(DataTypeType.LineStyle);
|
|
102
|
+
|
|
103
|
+
// <'outline-style'>
|
|
104
|
+
// syntax: auto | <'border-style'>
|
|
105
|
+
export const outlineStyleDataType = createDataType(DataTypeType.OutlineStyle, [
|
|
106
|
+
autoKeywordPredicate,
|
|
107
|
+
lineStyleDataType.predicate,
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
// <line-width>
|
|
111
|
+
// syntax: <length> | thin | medium | thick
|
|
112
|
+
export const lineWidthDataType = createDataType(DataTypeType.LineWidth, [
|
|
113
|
+
lengthDataType.predicate,
|
|
114
|
+
unorderedListPredicate(LINE_WIDTH_KEYWORDS),
|
|
115
|
+
]);
|
|
116
|
+
|
|
117
|
+
// <color-base>
|
|
118
|
+
const colorBasePredicates = [
|
|
119
|
+
hexColorPredicate(),
|
|
120
|
+
functionPredicate(COLOR_FUNCTIONS),
|
|
121
|
+
unorderedListPredicate(NAMED_COLOR_KEYWORDS),
|
|
122
|
+
functionPredicate('color-mix'),
|
|
123
|
+
unorderedListPredicate(TRANSPARENT_COLOR_KEYWORD),
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
// <color>
|
|
127
|
+
export const colorDataType = createDataType(DataTypeType.Color, [
|
|
128
|
+
...colorBasePredicates,
|
|
129
|
+
unorderedListPredicate(CURRENT_COLOR_KEYWORD),
|
|
130
|
+
unorderedListPredicate(SYSTEM_COLOR_KEYWORDS),
|
|
131
|
+
functionPredicate('contrast-color'),
|
|
132
|
+
functionPredicate('device-cmyk'),
|
|
133
|
+
functionPredicate('light-dark'),
|
|
134
|
+
]);
|
|
135
|
+
|
|
136
|
+
export const backgroundColorDataType: DataType = {
|
|
137
|
+
...colorDataType,
|
|
138
|
+
initial: INITIAL_BACKGROUND_COLOR,
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// <'outline-color'>
|
|
142
|
+
// syntax: <color> | invert
|
|
143
|
+
export const outlineColorDataType = createDataType(DataTypeType.OutlineColor, [
|
|
144
|
+
colorDataType.predicate,
|
|
145
|
+
unorderedListPredicate(OUTLINE_COLOR_INVERT_KEYWORD),
|
|
146
|
+
]);
|
|
147
|
+
|
|
148
|
+
// <border-image-slice>
|
|
149
|
+
// syntax: <number-percentage>{1,4} && fill?
|
|
150
|
+
export const borderImageSliceDataType = createDataType(DataTypeType.BorderImageSlice, [borderImageSlicePredicate]);
|
|
151
|
+
|
|
152
|
+
// <border-image-outset>
|
|
153
|
+
// syntax: [ <length> | <number> ]{1,4}
|
|
154
|
+
export const borderImageOutsetDataType = createDataType(DataTypeType.BorderImageOutset, [
|
|
155
|
+
curlyBracesPredicate([lengthDataType.predicate, numberPredicate], 1, 4),
|
|
156
|
+
]);
|
|
157
|
+
|
|
158
|
+
// <border-image-repeat>
|
|
159
|
+
// syntax: [ stretch | repeat | round | space ]{1,2}
|
|
160
|
+
export const borderImageRepeatDataType = createDataType(DataTypeType.BorderImageRepeat, [
|
|
161
|
+
curlyBracesPredicate([unorderedListPredicate(BORDER_IMAGE_REPEAT_MULTIPLE_KEYWORDS)], 1, 2),
|
|
162
|
+
]);
|
|
163
|
+
|
|
164
|
+
// <border-image-width>
|
|
165
|
+
// syntax: [ <length-percentage> | <number> | auto ]{1,4}
|
|
166
|
+
export const borderImageWidthDataType = createDataType(DataTypeType.BorderImageWidth, [
|
|
167
|
+
curlyBracesPredicate([lengthPercentageDataType.predicate, numberPredicate, autoKeywordPredicate], 1, 4),
|
|
168
|
+
]);
|
|
169
|
+
|
|
170
|
+
// <gradient>
|
|
171
|
+
// syntax: <linear-gradient()> | <repeating-linear-gradient()> | <radial-gradient()> | <repeating-radial-gradient()> | <conic-gradient()> | <repeating-conic-gradient()>
|
|
172
|
+
export const gradientDataType = createDataType(DataTypeType.Gradient, [functionPredicate(GRADIENT_FUNCTIONS)]);
|
|
173
|
+
|
|
174
|
+
// <image>
|
|
175
|
+
// syntax: <url> | <image()> | <image-set()> | <element()> | <paint()> | <cross-fade()> | <gradient>
|
|
176
|
+
export const imageDataType = createDataType(DataTypeType.Image, [
|
|
177
|
+
functionPredicate(IMAGE_FUNCTIONS),
|
|
178
|
+
gradientDataType.predicate,
|
|
179
|
+
]);
|
|
180
|
+
|
|
181
|
+
// <image-source>
|
|
182
|
+
// syntax: none | <image>
|
|
183
|
+
export const imageSourceDataType = createDataType(DataTypeType.ImageSource, [
|
|
184
|
+
unorderedListPredicate(IMAGE_SOURCE_NONE_KEYWORD),
|
|
185
|
+
imageDataType.predicate,
|
|
186
|
+
]);
|
|
187
|
+
|
|
188
|
+
// <bg-position>
|
|
189
|
+
/*
|
|
190
|
+
syntax: [
|
|
191
|
+
[ left | center | right | top | bottom | <length-percentage> ] |
|
|
192
|
+
[ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ] |
|
|
193
|
+
[ center | [ left | right ] <length-percentage>? ]
|
|
194
|
+
&& [ center | [ top | bottom] <length-percentage>? ]
|
|
195
|
+
]
|
|
196
|
+
*/
|
|
197
|
+
export const bgPositionDataType = createDataType(DataTypeType.BgPosition, [
|
|
198
|
+
(ast, index, items) => {
|
|
199
|
+
if (ast.type !== 'text' || index === undefined || !items) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return stateMachineDataTypeMatch(items, index, bgPositionStateMachine(lengthPercentageDataType.predicate));
|
|
204
|
+
},
|
|
205
|
+
]);
|
|
206
|
+
|
|
207
|
+
// <bg-size>
|
|
208
|
+
// syntax: [ <length-percentage> | auto ]{1,2} | cover | contain
|
|
209
|
+
export const bgSizeDataType = createDataType(DataTypeType.BgSize, [
|
|
210
|
+
curlyBracesPredicate([lengthPercentageDataType.predicate, autoKeywordPredicate], 1, 2),
|
|
211
|
+
unorderedListPredicate(BG_SIZE_KEYWORDS),
|
|
212
|
+
]);
|
|
213
|
+
|
|
214
|
+
// <repeat-style>
|
|
215
|
+
// syntax: repeat-x | repeat-y | [ repeat | space | round | no-repeat ]{1,2}
|
|
216
|
+
export const repeatStyleDataType = createDataType(DataTypeType.RepeatStyle, [
|
|
217
|
+
unorderedListPredicate(REPEAT_STYLE_SINGLE_KEYWORDS),
|
|
218
|
+
curlyBracesPredicate([unorderedListPredicate(REPEAT_STYLE_MULTIPLE_KEYWORDS)], 1, 2),
|
|
219
|
+
]);
|
|
220
|
+
|
|
221
|
+
// <attachment>
|
|
222
|
+
// syntax: scroll | fixed | local
|
|
223
|
+
export const attachmentDataType = createUnorderedListDataType(DataTypeType.Attachment);
|
|
224
|
+
|
|
225
|
+
// <box>
|
|
226
|
+
// syntax: border-box | padding-box | content-box
|
|
227
|
+
export const boxDataType = createUnorderedListDataType(DataTypeType.Box);
|
|
228
|
+
|
|
229
|
+
export const backgroundOriginDataType: DataType = {
|
|
230
|
+
...boxDataType,
|
|
231
|
+
initial: INITIAL_BACKGROUND_ORIGIN,
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
export const backgroundClipDataType: DataType = {
|
|
235
|
+
...boxDataType,
|
|
236
|
+
initial: INITIAL_BACKGROUND_CLIP,
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// <font>
|
|
240
|
+
// syntax: caption | icon | menu | message-box | small-caption | status-bar
|
|
241
|
+
export const fontSingleValueDataType = createUnorderedListDataType(DataTypeType.Font);
|
|
242
|
+
|
|
243
|
+
// <font-style>
|
|
244
|
+
// syntax: normal | italic | oblique <angle>?
|
|
245
|
+
export const fontStyleDataType = createDataType(DataTypeType.FontStyle, [
|
|
246
|
+
unorderedListPredicate(FONT_STYLE_KEYWORDS),
|
|
247
|
+
fontStylePredicate,
|
|
248
|
+
]);
|
|
249
|
+
|
|
250
|
+
// <font-variant>
|
|
251
|
+
// syntax: normal | small-caps
|
|
252
|
+
export const fontVariantDataType = createUnorderedListDataType(DataTypeType.FontVariant);
|
|
253
|
+
|
|
254
|
+
// <font-weight>
|
|
255
|
+
// syntax: <font-weight-absolute> | <font-weight-relative> | [1,1000]
|
|
256
|
+
export const fontWeightDataType = createDataType(DataTypeType.FontWeight, [
|
|
257
|
+
unorderedListPredicate(FONT_WEIGHT_KEYWORDS),
|
|
258
|
+
dimensionPredicate({
|
|
259
|
+
min: FONT_WEIGHT_NUMBER_RANGE_MIN,
|
|
260
|
+
max: FONT_WEIGHT_NUMBER_RANGE_MAX,
|
|
261
|
+
}),
|
|
262
|
+
]);
|
|
263
|
+
|
|
264
|
+
// <font-stretch>
|
|
265
|
+
// syntax: normal | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded
|
|
266
|
+
export const fontStretchDataType = createUnorderedListDataType(DataTypeType.FontStretch);
|
|
267
|
+
|
|
268
|
+
// <font-size>
|
|
269
|
+
// syntax: <length-percentage> | <absolute-size> | <relative-size>
|
|
270
|
+
export const fontSizeDataType = createDataType(DataTypeType.FontSize, [
|
|
271
|
+
lengthPercentageDataType.predicate,
|
|
272
|
+
unorderedListPredicate(FONT_SIZE_KEYWORDS),
|
|
273
|
+
]);
|
|
274
|
+
|
|
275
|
+
// <line-height>
|
|
276
|
+
// syntax: <number> | <length-percentage> | normal
|
|
277
|
+
export const lineHeightDataType = createDataType(DataTypeType.LineHeight, [
|
|
278
|
+
numberPredicate,
|
|
279
|
+
lengthPercentageDataType.predicate,
|
|
280
|
+
unorderedListPredicate(LINE_HEIGHT_KEYWORD),
|
|
281
|
+
]);
|
|
282
|
+
|
|
283
|
+
// <font-family>
|
|
284
|
+
export const fontFamilyDataType = createDataType(DataTypeType.FontFamily, [fontFamilyStringPredicate]);
|
|
285
|
+
|
|
286
|
+
// <align-content>
|
|
287
|
+
// syntax: normal | baseline | <content-distribution> | <content-position>
|
|
288
|
+
export const alignContentDataType = createDataType(DataTypeType.AlignContent, [
|
|
289
|
+
unorderedListPredicate(ALIGN_CONTENT_KEYWORDS),
|
|
290
|
+
unorderedListPredicate(CONTENT_DISTRIBUTION_KEYWORDS),
|
|
291
|
+
unorderedListPredicate(CONTENT_POSITION_KEYWORDS),
|
|
292
|
+
]);
|
|
293
|
+
|
|
294
|
+
// <justify-content>
|
|
295
|
+
// syntax: normal | <content-distribution> | <content-position> | left | right
|
|
296
|
+
export const justifyContentDataType = createDataType(DataTypeType.JustifyContent, [
|
|
297
|
+
unorderedListPredicate(JUSTIFY_CONTENT_KEYWORDS),
|
|
298
|
+
unorderedListPredicate(CONTENT_DISTRIBUTION_KEYWORDS),
|
|
299
|
+
unorderedListPredicate(CONTENT_POSITION_KEYWORDS),
|
|
300
|
+
]);
|
|
301
|
+
|
|
302
|
+
// <align-items>
|
|
303
|
+
// syntax: normal | stretch | baseline | <self-position>
|
|
304
|
+
export const alignItemsDataType = createDataType(DataTypeType.AlignItems, [
|
|
305
|
+
unorderedListPredicate(ALIGN_ITEMS_KEYWORDS),
|
|
306
|
+
unorderedListPredicate(SELF_POSITION_KEYWORDS),
|
|
307
|
+
]);
|
|
308
|
+
|
|
309
|
+
// justify-items
|
|
310
|
+
// syntax: normal | stretch | baseline | <self-position> | legacy | left | right | center
|
|
311
|
+
export const justifyItemsDataType = createDataType(DataTypeType.JustifyItems, [
|
|
312
|
+
alignItemsDataType.predicate,
|
|
313
|
+
unorderedListPredicate(JUSTIFY_ITEMS_KEYWORDS),
|
|
314
|
+
]);
|
|
315
|
+
|
|
316
|
+
// <'flex'>
|
|
317
|
+
// syntax: initial | auto | none
|
|
318
|
+
export const flexSingleValueDataType = createUnorderedListDataType(DataTypeType.Flex);
|
|
319
|
+
|
|
320
|
+
// <flex-grow>
|
|
321
|
+
// syntax: <number>
|
|
322
|
+
export const flexGrowDataType = createDataType(DataTypeType.FlexGrow, [numberPredicate]);
|
|
323
|
+
|
|
324
|
+
// <flex-shrink>
|
|
325
|
+
// syntax: <number>
|
|
326
|
+
export const flexShrinkDataType = createDataType(DataTypeType.FlexShrink, [numberPredicate]);
|
|
327
|
+
|
|
328
|
+
// <flex-basis>
|
|
329
|
+
// syntax: <width> | content | fill | max-content | min-content | fit-content
|
|
330
|
+
export const flexBasisDataType = createDataType(DataTypeType.FlexBasis, [
|
|
331
|
+
widthDataType.predicate,
|
|
332
|
+
unorderedListPredicate(FLEX_BASIS_KEYWORDS),
|
|
333
|
+
]);
|
|
334
|
+
|
|
335
|
+
// <flex-direction>
|
|
336
|
+
// syntax: row | row-reverse | column | column-reverse
|
|
337
|
+
export const flexDirectionDataType = createUnorderedListDataType(DataTypeType.FlexDirection);
|
|
338
|
+
|
|
339
|
+
// <flex-wrap>
|
|
340
|
+
// syntax: nowrap | wrap | wrap-reverse
|
|
341
|
+
export const flexWrapDataType = createUnorderedListDataType(DataTypeType.FlexWrap);
|
|
342
|
+
|
|
343
|
+
// <grid-line>
|
|
344
|
+
// syntax: auto | <custom-ident> | [ <integer> && <custom-ident>? ] | [ span && [ <integer> || <custom-ident> ] ]
|
|
345
|
+
export const gridLineDataType = createDataType(DataTypeType.GridLine, [
|
|
346
|
+
unorderedListPredicate(GRID_LINE_AUTO_KEYWORD),
|
|
347
|
+
gridLinePredicate,
|
|
348
|
+
]);
|
|
349
|
+
|
|
350
|
+
// <grid-line-end>
|
|
351
|
+
// syntax: <grid-line> [ / <grid-line> ]?
|
|
352
|
+
export const gridLineEndDataType = createDataType(DataTypeType.GridLineEnd, [gridLineDataType.predicate]);
|
|
353
|
+
|
|
354
|
+
// <grid-template-areas>
|
|
355
|
+
// syntax: none | <string>+
|
|
356
|
+
export const gridTemplateAreasDataType = createDataType(DataTypeType.GridTemplateAreas, [
|
|
357
|
+
unorderedListPredicate(INITIAL_GRID_TEMPLATE_AREAS),
|
|
358
|
+
gridTemplateAreasStringPredicate,
|
|
359
|
+
]);
|
|
360
|
+
|
|
361
|
+
// <grid-template-rows>
|
|
362
|
+
// syntax: none | <track-list> | <auto-track-list>
|
|
363
|
+
export const gridTemplateRowsDataType = createDataType(DataTypeType.GridTemplateRows, [
|
|
364
|
+
unorderedListPredicate(GRID_TEMPLATE_AXIS_NONE_KEYWORD),
|
|
365
|
+
autoTrackListPredicate,
|
|
366
|
+
trackListPredicate,
|
|
367
|
+
]);
|
|
368
|
+
|
|
369
|
+
// <grid-template-columns>
|
|
370
|
+
// syntax: none | <track-list> | <auto-track-list>
|
|
371
|
+
export const gridTemplateColumnsDataType = createDataType(DataTypeType.GridTemplateColumns, [
|
|
372
|
+
gridTemplateRowsDataType.predicate,
|
|
373
|
+
]);
|
|
374
|
+
|
|
375
|
+
// <explicit-track-list>
|
|
376
|
+
// syntax: [ <line-names>? <track-size> ]+ <line-names>?
|
|
377
|
+
export const explicitTrackListDataType = createDataType(DataTypeType.ExplicitTrackList, [explicitTrackListPredicate]);
|
|
378
|
+
|
|
379
|
+
// <grid-template>
|
|
380
|
+
// syntax: none
|
|
381
|
+
export const gridTemplateSingleValueDataType = createUnorderedListDataType(DataTypeType.GridTemplate);
|
|
382
|
+
|
|
383
|
+
// <grid-auto-flow>
|
|
384
|
+
// syntax: auto-flow && dense?
|
|
385
|
+
export const gridAutoFlowDataType = createDataType(DataTypeType.GridAutoFlow, [gridAutoFlowPredicate]);
|
|
386
|
+
|
|
387
|
+
// <grid-auto-rows>
|
|
388
|
+
// syntax: <track-size>+
|
|
389
|
+
export const gridAutoRowsDataType = createDataType(DataTypeType.GridAutoRows, [asteriskPredicate(trackSizePredicate)]);
|
|
390
|
+
|
|
391
|
+
// <grid-auto-columns>
|
|
392
|
+
// syntax: <track-size>+
|
|
393
|
+
export const gridAutoColumnsDataType = createDataType(DataTypeType.GridAutoColumns, [gridAutoRowsDataType.predicate]);
|
|
394
|
+
|
|
395
|
+
// <grid>
|
|
396
|
+
// syntax: none
|
|
397
|
+
export const gridSingleValueDataType = createUnorderedListDataType(DataTypeType.Grid);
|
|
398
|
+
|
|
399
|
+
// <overflow>
|
|
400
|
+
// syntax: visible | hidden | clip | scroll | auto
|
|
401
|
+
export const overflowDataType = createUnorderedListDataType(DataTypeType.Overflow);
|
|
402
|
+
|
|
403
|
+
// <text-decoration-line>
|
|
404
|
+
// syntax: none | [ underline || overline || line-through ]
|
|
405
|
+
export const textDecorationLineDataType = createDataType(DataTypeType.TextDecorationLine, [
|
|
406
|
+
unorderedListPredicate(TEXT_DECORATION_LINE_NONE_KEYWORD),
|
|
407
|
+
textDecorationLinePredicate,
|
|
408
|
+
]);
|
|
409
|
+
|
|
410
|
+
// <text-decoration-style>
|
|
411
|
+
// syntax: solid | double | dotted | dashed | wavy
|
|
412
|
+
export const textDecorationStyleDataType = createUnorderedListDataType(DataTypeType.TextDecorationStyle);
|
|
413
|
+
|
|
414
|
+
// <list-style>
|
|
415
|
+
// syntax: none
|
|
416
|
+
export const listStyleSingleValueDataType = createUnorderedListDataType(DataTypeType.ListStyle);
|
|
417
|
+
|
|
418
|
+
// <list-style-position>
|
|
419
|
+
// syntax: inside | outside
|
|
420
|
+
export const listStylePositionDataType = createUnorderedListDataType(DataTypeType.ListStylePosition);
|
|
421
|
+
|
|
422
|
+
// <list-style-type>
|
|
423
|
+
// syntax: <counter-style> | <string> | none
|
|
424
|
+
export const listStyleTypeDataType = createDataType(DataTypeType.ListStyleType, [
|
|
425
|
+
unorderedListPredicate(LIST_STYLE_TYPE_KEYWORDS),
|
|
426
|
+
stringPredicate(),
|
|
427
|
+
]);
|
|
428
|
+
|
|
429
|
+
// <inset>
|
|
430
|
+
// syntax: inset
|
|
431
|
+
export const insetDataType = createUnorderedListDataType(DataTypeType.Inset);
|
|
432
|
+
|
|
433
|
+
// <shadow>
|
|
434
|
+
// syntax: none
|
|
435
|
+
export const shadowSingleValueDataType = createUnorderedListDataType(DataTypeType.Shadow);
|
package/src/index.ts
ADDED