1
- import { parseCommaSeparatedListOfComponentValues } from '@csstools/css-parser-algorithms' ;
2
- import { tokenize } from '@csstools/css-tokenizer' ;
3
1
import { CoreTypes } from '../../core-types' ;
4
2
import { Trace } from '../../trace' ;
5
3
import { Length } from './style-properties' ;
@@ -20,9 +18,14 @@ export function cleanupImportantFlags(value: unknown, propertyName: string) {
20
18
}
21
19
22
20
/**
23
- * Matches whitespace except if the whitespace is contained in parenthesis - ex . rgb(a), hsl color.
21
+ * Matches whitespace except if the whitespace is contained in parenthesis - e.g . rgb(a), hsl color.
24
22
*/
25
- const PARTS_RE = / \s (? ! [ ^ ( ] * \) ) / ;
23
+ const WHITE_SPACE_RE = / \s (? ! [ ^ ( ] * \) ) / ;
24
+
25
+ /**
26
+ * Matches comma except if the comma is contained in parenthesis - e.g. rgb(a, b, c).
27
+ */
28
+ const COMMA_RE = / , (? ! [ ^ ( ] * \) ) / ;
26
29
27
30
/**
28
31
* Matches a Length value with or without a unit
@@ -34,34 +37,22 @@ const LENGTH_RE = /^-?[0-9]+[a-zA-Z%]*?$/;
34
37
*/
35
38
const isLength = ( v ) => v === '0' || LENGTH_RE . test ( v ) ;
36
39
37
- export function parseCSSListOfValues ( value : string ) : string [ ] {
40
+ export function parseCSSCommaSeparatedListOfValues ( value : string ) : string [ ] {
38
41
const values : string [ ] = [ ] ;
39
42
40
43
if ( ! value ) {
41
- return values ;
42
- }
43
-
44
- if ( ! value . includes ( ',' ) ) {
45
- values . push ( value ) ;
46
- return values ;
47
- }
48
-
49
- const tokens = tokenize ( { css : value } ) ;
50
- const componentValueSet = parseCommaSeparatedListOfComponentValues ( tokens ) ;
51
-
52
- for ( const componentValues of componentValueSet ) {
53
- values . push ( componentValues . join ( '' ) ) ;
44
+ return [ ] ;
54
45
}
55
46
56
- return values ;
47
+ return value . split ( COMMA_RE ) ;
57
48
}
58
49
59
50
export function parseCSSShorthand ( value : string ) : {
60
51
values : Array < CoreTypes . LengthType > ;
61
52
color : string ;
62
53
inset : boolean ;
63
54
} {
64
- const parts = value . trim ( ) . split ( PARTS_RE ) ;
55
+ const parts = value . trim ( ) . split ( WHITE_SPACE_RE ) ;
65
56
const first = parts [ 0 ] ;
66
57
67
58
if ( [ '' , 'none' , 'unset' ] . includes ( first ) ) {
0 commit comments