@webstudio-is/css-data 0.91.0 → 0.266.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/lib/index.js +17534 -15
- package/lib/types/__generated__/animatable-properties.d.ts +1 -0
- package/lib/types/__generated__/html.d.ts +2 -0
- package/lib/types/__generated__/keyword-values.d.ts +4 -358
- package/lib/types/__generated__/properties.d.ts +10 -3674
- package/lib/types/__generated__/property-value-descriptions.d.ts +7 -5446
- package/lib/types/__generated__/pseudo-classes.d.ts +1 -0
- package/lib/types/__generated__/pseudo-elements.d.ts +1 -0
- package/lib/types/__generated__/pseudo-selector-descriptions.d.ts +2 -0
- package/lib/types/__generated__/shorthand-properties.d.ts +1 -0
- package/lib/types/css-tree.d.ts +772 -0
- package/lib/types/index.d.ts +18 -3680
- package/lib/types/media-condition-simulator.d.ts +7 -0
- package/lib/types/parse-css-value.d.ts +8 -3
- package/lib/types/parse-css.d.ts +75 -6
- package/lib/types/property-parsers/conic-gradient.d.ts +3 -0
- package/lib/types/property-parsers/gradient-utils.d.ts +20 -0
- package/lib/types/property-parsers/grid-template-areas.d.ts +21 -0
- package/lib/types/property-parsers/grid-template-tracks.d.ts +128 -0
- package/lib/types/property-parsers/index.d.ts +6 -2
- package/lib/types/property-parsers/linear-gradient.d.ts +4 -0
- package/lib/types/property-parsers/radial-gradient.d.ts +3 -0
- package/lib/types/property-parsers/types.d.ts +28 -0
- package/lib/types/selector-validation.d.ts +13 -0
- package/lib/types/shorthands.d.ts +2 -0
- package/package.json +29 -33
- package/lib/__generated__/keyword-values.js +0 -5255
- package/lib/__generated__/properties.js +0 -3697
- package/lib/__generated__/property-value-descriptions.js +0 -2740
- package/lib/__generated__/units.js +0 -65
- package/lib/cjs/__generated__/keyword-values.js +0 -5275
- package/lib/cjs/__generated__/properties.js +0 -3717
- package/lib/cjs/__generated__/property-value-descriptions.js +0 -2760
- package/lib/cjs/__generated__/units.js +0 -85
- package/lib/cjs/custom-data.js +0 -64
- package/lib/cjs/html-check.js +0 -25
- package/lib/cjs/html.js +0 -581
- package/lib/cjs/index.js +0 -48
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/parse-css-value.js +0 -152
- package/lib/cjs/parse-css.js +0 -136
- package/lib/cjs/popularity-index.js +0 -4633
- package/lib/cjs/property-parsers/background.js +0 -119
- package/lib/cjs/property-parsers/box-shadow.js +0 -129
- package/lib/cjs/property-parsers/index.js +0 -19
- package/lib/cjs/property-parsers/parsers.js +0 -26
- package/lib/cjs/property-parsers/to-longhand.js +0 -24
- package/lib/cjs/schema.js +0 -135
- package/lib/custom-data.js +0 -44
- package/lib/html-check.js +0 -2
- package/lib/html.js +0 -561
- package/lib/parse-css-value.js +0 -122
- package/lib/parse-css.js +0 -106
- package/lib/popularity-index.js +0 -4613
- package/lib/property-parsers/background.js +0 -89
- package/lib/property-parsers/box-shadow.js +0 -99
- package/lib/property-parsers/index.js +0 -2
- package/lib/property-parsers/parsers.js +0 -6
- package/lib/property-parsers/to-longhand.js +0 -4
- package/lib/schema.js +0 -115
- package/lib/types/custom-data.d.ts +0 -15
- package/lib/types/html-check.d.ts +0 -1
- package/lib/types/html.d.ts +0 -62
- package/lib/types/parse-css-value.test.d.ts +0 -1
- package/lib/types/parse-css.test.d.ts +0 -1
- package/lib/types/popularity-index.d.ts +0 -6
- package/lib/types/property-parsers/background.d.ts +0 -11
- package/lib/types/property-parsers/background.test.d.ts +0 -1
- package/lib/types/property-parsers/box-shadow.d.ts +0 -3
- package/lib/types/property-parsers/box-shadow.test.d.ts +0 -1
- package/lib/types/property-parsers/parsers.d.ts +0 -2
- package/lib/types/property-parsers/to-longhand.d.ts +0 -1
- package/lib/types/schema.d.ts +0 -3243
- package/src/__generated__/keyword-values.ts +0 -5253
- package/src/__generated__/properties.ts +0 -3696
- package/src/__generated__/property-value-descriptions.ts +0 -4008
- package/src/__generated__/units.ts +0 -63
- package/src/custom-data.ts +0 -57
- package/src/html-check.ts +0 -8
- package/src/html.ts +0 -617
- package/src/index.ts +0 -25
- package/src/parse-css-value.test.ts +0 -136
- package/src/parse-css-value.ts +0 -157
- package/src/parse-css.test.ts +0 -101
- package/src/parse-css.ts +0 -137
- package/src/popularity-index.ts +0 -4611
- package/src/property-parsers/README.md +0 -11
- package/src/property-parsers/background.test.ts +0 -184
- package/src/property-parsers/background.ts +0 -147
- package/src/property-parsers/box-shadow.test.ts +0 -294
- package/src/property-parsers/box-shadow.ts +0 -130
- package/src/property-parsers/index.ts +0 -2
- package/src/property-parsers/parsers.ts +0 -5
- package/src/property-parsers/to-longhand.ts +0 -4
- package/src/schema.ts +0 -193
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
## Properties Parsers
|
|
2
|
-
|
|
3
|
-
This folder contains:
|
|
4
|
-
|
|
5
|
-
- `parsers.ts` individual properties parses
|
|
6
|
-
- `to-longhand.ts` shorthand forms unwrappers
|
|
7
|
-
|
|
8
|
-
The idea is that these two modules export a number of utilities whose name match the property that they parse or unwrap e.g.:
|
|
9
|
-
|
|
10
|
-
- `backgroundImage` is a property parser
|
|
11
|
-
- `background` is a "to-longhand" unwrapper
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "@jest/globals";
|
|
2
|
-
|
|
3
|
-
import { parseBackground } from "./background";
|
|
4
|
-
|
|
5
|
-
describe("parseBackground", () => {
|
|
6
|
-
test("parse background from figma", () => {
|
|
7
|
-
expect(
|
|
8
|
-
parseBackground(
|
|
9
|
-
"linear-gradient(180deg, #11181C 0%, rgba(17, 24, 28, 0) 36.09%), none, linear-gradient(180deg, rgba(230, 60, 254, 0.33) 0%, rgba(255, 174, 60, 0) 100%), radial-gradient(54.1% 95.83% at 100% 100%, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%), linear-gradient(122.33deg, rgba(74, 78, 250, 0.2) 0%, rgba(0, 0, 0, 0) 69.38%), radial-gradient(92.26% 201.29% at 98.6% 10.65%, rgba(255, 174, 60, 0.3) 0%, rgba(227, 53, 255, 0) 100%) /* warning: gradient uses a rotation that is not supported by CSS and may not behave as expected */, radial-gradient(84.64% 267.51% at 10.07% 81.45%, rgba(53, 255, 182, 0.2) 0%, rgba(74, 78, 250, 0.2) 100%) /* warning: gradient uses a rotation that is not supported by CSS and may not behave as expected */, #EBFFFC;"
|
|
10
|
-
)
|
|
11
|
-
).toMatchInlineSnapshot(`
|
|
12
|
-
{
|
|
13
|
-
"backgroundColor": {
|
|
14
|
-
"alpha": 1,
|
|
15
|
-
"b": 252,
|
|
16
|
-
"g": 255,
|
|
17
|
-
"r": 235,
|
|
18
|
-
"type": "rgb",
|
|
19
|
-
},
|
|
20
|
-
"backgroundImage": {
|
|
21
|
-
"type": "layers",
|
|
22
|
-
"value": [
|
|
23
|
-
{
|
|
24
|
-
"type": "unparsed",
|
|
25
|
-
"value": "linear-gradient(180deg,#11181C 0%,rgba(17,24,28,0) 36.09%)",
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"type": "unparsed",
|
|
29
|
-
"value": "linear-gradient(180deg,rgba(230,60,254,0.33) 0%,rgba(255,174,60,0) 100%)",
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"type": "unparsed",
|
|
33
|
-
"value": "radial-gradient(54.1% 95.83%at 100% 100%,#FFFFFF 0%,rgba(255,255,255,0) 100%)",
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
"type": "unparsed",
|
|
37
|
-
"value": "linear-gradient(122.33deg,rgba(74,78,250,0.2) 0%,rgba(0,0,0,0) 69.38%)",
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
"type": "unparsed",
|
|
41
|
-
"value": "radial-gradient(92.26% 201.29%at 98.6% 10.65%,rgba(255,174,60,0.3) 0%,rgba(227,53,255,0) 100%)",
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
"type": "unparsed",
|
|
45
|
-
"value": "radial-gradient(84.64% 267.51%at 10.07% 81.45%,rgba(53,255,182,0.2) 0%,rgba(74,78,250,0.2) 100%)",
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
}
|
|
50
|
-
`);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test("parse background from figma without backgroundColor", () => {
|
|
54
|
-
expect(
|
|
55
|
-
parseBackground(
|
|
56
|
-
"linear-gradient(180deg, #11181C 0%, rgba(17, 24, 28, 0) 36.09%), linear-gradient(180deg, rgba(230, 60, 254, 0.33) 0%, rgba(255, 174, 60, 0) 100%), radial-gradient(54.1% 95.83% at 100% 100%, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%), linear-gradient(122.33deg, rgba(74, 78, 250, 0.2) 0%, rgba(0, 0, 0, 0) 69.38%), radial-gradient(92.26% 201.29% at 98.6% 10.65%, rgba(255, 174, 60, 0.3) 0%, rgba(227, 53, 255, 0) 100%) /* warning: gradient uses a rotation that is not supported by CSS and may not behave as expected */, radial-gradient(84.64% 267.51% at 10.07% 81.45%, rgba(53, 255, 182, 0.2) 0%, rgba(74, 78, 250, 0.2) 100%) /* warning: gradient uses a rotation that is not supported by CSS and may not behave as expected */"
|
|
57
|
-
)
|
|
58
|
-
).toMatchInlineSnapshot(`
|
|
59
|
-
{
|
|
60
|
-
"backgroundColor": undefined,
|
|
61
|
-
"backgroundImage": {
|
|
62
|
-
"type": "layers",
|
|
63
|
-
"value": [
|
|
64
|
-
{
|
|
65
|
-
"type": "unparsed",
|
|
66
|
-
"value": "linear-gradient(180deg,#11181C 0%,rgba(17,24,28,0) 36.09%)",
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
"type": "unparsed",
|
|
70
|
-
"value": "linear-gradient(180deg,rgba(230,60,254,0.33) 0%,rgba(255,174,60,0) 100%)",
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
"type": "unparsed",
|
|
74
|
-
"value": "radial-gradient(54.1% 95.83%at 100% 100%,#FFFFFF 0%,rgba(255,255,255,0) 100%)",
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
"type": "unparsed",
|
|
78
|
-
"value": "linear-gradient(122.33deg,rgba(74,78,250,0.2) 0%,rgba(0,0,0,0) 69.38%)",
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
"type": "unparsed",
|
|
82
|
-
"value": "radial-gradient(92.26% 201.29%at 98.6% 10.65%,rgba(255,174,60,0.3) 0%,rgba(227,53,255,0) 100%)",
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
"type": "unparsed",
|
|
86
|
-
"value": "radial-gradient(84.64% 267.51%at 10.07% 81.45%,rgba(53,255,182,0.2) 0%,rgba(74,78,250,0.2) 100%)",
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
},
|
|
90
|
-
}
|
|
91
|
-
`);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
test("parse background and skips url background", () => {
|
|
95
|
-
expect(
|
|
96
|
-
parseBackground(
|
|
97
|
-
"url(https://hello.world/some-image), linear-gradient(180deg, rgba(230, 60, 254, 0.33) 0%, rgba(255, 174, 60, 0) 100%), radial-gradient(54.1% 95.83% at 100% 100%, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%), linear-gradient(122.33deg, rgba(74, 78, 250, 0.2) 0%, rgba(0, 0, 0, 0) 69.38%), radial-gradient(92.26% 201.29% at 98.6% 10.65%, rgba(255, 174, 60, 0.3) 0%, rgba(227, 53, 255, 0) 100%) /* warning: gradient uses a rotation that is not supported by CSS and may not behave as expected */, radial-gradient(84.64% 267.51% at 10.07% 81.45%, rgba(53, 255, 182, 0.2) 0%, rgba(74, 78, 250, 0.2) 100%) /* warning: gradient uses a rotation that is not supported by CSS and may not behave as expected */"
|
|
98
|
-
)
|
|
99
|
-
).toMatchInlineSnapshot(`
|
|
100
|
-
{
|
|
101
|
-
"backgroundColor": undefined,
|
|
102
|
-
"backgroundImage": {
|
|
103
|
-
"type": "layers",
|
|
104
|
-
"value": [
|
|
105
|
-
{
|
|
106
|
-
"type": "unparsed",
|
|
107
|
-
"value": "linear-gradient(180deg,rgba(230,60,254,0.33) 0%,rgba(255,174,60,0) 100%)",
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
"type": "unparsed",
|
|
111
|
-
"value": "radial-gradient(54.1% 95.83%at 100% 100%,#FFFFFF 0%,rgba(255,255,255,0) 100%)",
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
"type": "unparsed",
|
|
115
|
-
"value": "linear-gradient(122.33deg,rgba(74,78,250,0.2) 0%,rgba(0,0,0,0) 69.38%)",
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
"type": "unparsed",
|
|
119
|
-
"value": "radial-gradient(92.26% 201.29%at 98.6% 10.65%,rgba(255,174,60,0.3) 0%,rgba(227,53,255,0) 100%)",
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
"type": "unparsed",
|
|
123
|
-
"value": "radial-gradient(84.64% 267.51%at 10.07% 81.45%,rgba(53,255,182,0.2) 0%,rgba(74,78,250,0.2) 100%)",
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
},
|
|
127
|
-
}
|
|
128
|
-
`);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test("parse background partially copied background", () => {
|
|
132
|
-
expect(
|
|
133
|
-
parseBackground(
|
|
134
|
-
"linear-gradient(180deg, #11181C 0%, rgba(17, 24, 28, 0) 36.09%), linear-gradient(180deg, "
|
|
135
|
-
)
|
|
136
|
-
).toMatchInlineSnapshot(`
|
|
137
|
-
{
|
|
138
|
-
"backgroundColor": undefined,
|
|
139
|
-
"backgroundImage": {
|
|
140
|
-
"type": "layers",
|
|
141
|
-
"value": [
|
|
142
|
-
{
|
|
143
|
-
"type": "unparsed",
|
|
144
|
-
"value": "linear-gradient(180deg,#11181C 0%,rgba(17,24,28,0) 36.09%)",
|
|
145
|
-
},
|
|
146
|
-
],
|
|
147
|
-
},
|
|
148
|
-
}
|
|
149
|
-
`);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
test("parse background partially commented", () => {
|
|
153
|
-
expect(
|
|
154
|
-
parseBackground(
|
|
155
|
-
"linear-gradient(180deg, rgba(230, 60, 254, 0.33) 0%, rgba(255, 174, 60, 0) 100%), /* radial-gradient(54.1% 95.83% at 100% 100%, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%) */"
|
|
156
|
-
)
|
|
157
|
-
).toMatchInlineSnapshot(`
|
|
158
|
-
{
|
|
159
|
-
"backgroundColor": undefined,
|
|
160
|
-
"backgroundImage": {
|
|
161
|
-
"type": "layers",
|
|
162
|
-
"value": [
|
|
163
|
-
{
|
|
164
|
-
"type": "unparsed",
|
|
165
|
-
"value": "linear-gradient(180deg,rgba(230,60,254,0.33) 0%,rgba(255,174,60,0) 100%)",
|
|
166
|
-
},
|
|
167
|
-
],
|
|
168
|
-
},
|
|
169
|
-
}
|
|
170
|
-
`);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
test("parse bad background", () => {
|
|
174
|
-
expect(parseBackground("linear-gradient(180deg,")).toMatchInlineSnapshot(`
|
|
175
|
-
{
|
|
176
|
-
"backgroundColor": undefined,
|
|
177
|
-
"backgroundImage": {
|
|
178
|
-
"type": "invalid",
|
|
179
|
-
"value": "linear-gradient(180deg,)",
|
|
180
|
-
},
|
|
181
|
-
}
|
|
182
|
-
`);
|
|
183
|
-
});
|
|
184
|
-
});
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import * as csstree from "css-tree";
|
|
2
|
-
import { parseCssValue } from "../parse-css-value";
|
|
3
|
-
import type {
|
|
4
|
-
InvalidValue,
|
|
5
|
-
LayersValue,
|
|
6
|
-
RgbValue,
|
|
7
|
-
UnparsedValue,
|
|
8
|
-
} from "../schema";
|
|
9
|
-
|
|
10
|
-
export const gradientNames = [
|
|
11
|
-
"conic-gradient",
|
|
12
|
-
"linear-gradient",
|
|
13
|
-
"radial-gradient",
|
|
14
|
-
"repeating-conic-gradient",
|
|
15
|
-
"repeating-linear-gradient",
|
|
16
|
-
"repeating-radial-gradient",
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
export const parseBackground = (
|
|
20
|
-
background: string
|
|
21
|
-
): {
|
|
22
|
-
backgroundImage: LayersValue | InvalidValue;
|
|
23
|
-
backgroundColor: RgbValue | undefined;
|
|
24
|
-
} => {
|
|
25
|
-
const { backgroundImage, backgroundColor: backgroundColorRaw } =
|
|
26
|
-
backgroundToLonghand(background);
|
|
27
|
-
|
|
28
|
-
const backgroundColor = backgroundColorRaw
|
|
29
|
-
? (parseCssValue("backgroundColor", backgroundColorRaw) as RgbValue)
|
|
30
|
-
: undefined;
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
backgroundImage: parseBackgroundImage(backgroundImage),
|
|
34
|
-
backgroundColor:
|
|
35
|
-
backgroundColor && backgroundColor.type === "rgb"
|
|
36
|
-
? backgroundColor
|
|
37
|
-
: undefined,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const cssTreeTryParseValue = (input: string) => {
|
|
42
|
-
try {
|
|
43
|
-
const ast = csstree.parse(input, { context: "value" });
|
|
44
|
-
return ast;
|
|
45
|
-
} catch {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export const backgroundToLonghand = (
|
|
51
|
-
background: string
|
|
52
|
-
): {
|
|
53
|
-
backgroundImage: string[];
|
|
54
|
-
backgroundColor: string | undefined;
|
|
55
|
-
} => {
|
|
56
|
-
const layers: string[] = [];
|
|
57
|
-
let tokenStream = background.trim();
|
|
58
|
-
|
|
59
|
-
tokenStream = tokenStream.endsWith(";")
|
|
60
|
-
? tokenStream.slice(0, -1)
|
|
61
|
-
: tokenStream;
|
|
62
|
-
|
|
63
|
-
// The user can copy the whole style together with the name of the property from figma or any other tool.
|
|
64
|
-
// We need to remove the property name from the string.
|
|
65
|
-
const cleanupKeywords = ["background:", "background-image:"];
|
|
66
|
-
|
|
67
|
-
for (const cleanupKeyword of cleanupKeywords) {
|
|
68
|
-
tokenStream = tokenStream.startsWith(cleanupKeyword)
|
|
69
|
-
? tokenStream.slice(cleanupKeyword.length).trim()
|
|
70
|
-
: tokenStream;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const cssAst = cssTreeTryParseValue(tokenStream);
|
|
74
|
-
|
|
75
|
-
if (cssAst === undefined) {
|
|
76
|
-
return {
|
|
77
|
-
backgroundImage: [],
|
|
78
|
-
backgroundColor: undefined,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let backgroundColorRaw: string | undefined;
|
|
83
|
-
|
|
84
|
-
let nestingLevel = 0;
|
|
85
|
-
|
|
86
|
-
csstree.walk(cssAst, {
|
|
87
|
-
enter: (node, item, list) => {
|
|
88
|
-
if (node.type === "Function") {
|
|
89
|
-
if (gradientNames.includes(node.name)) {
|
|
90
|
-
layers.push(csstree.generate(node));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// If the depth is at level 0 and the next item is null, it's likely that the backgroundColor
|
|
94
|
-
// is written as rgba(x,y,z,a) or similar format.
|
|
95
|
-
// nestingLevel is used as a fast way to check existance of parent Function node
|
|
96
|
-
if (item.next === null && nestingLevel === 0) {
|
|
97
|
-
backgroundColorRaw = csstree.generate(node);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
nestingLevel++;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (node.type === "Hash" && item.next === null && nestingLevel === 0) {
|
|
104
|
-
// If the depth is at level 0 and the next item is null, it's likely that the backgroundColor
|
|
105
|
-
// is written as hex #XYZFGH
|
|
106
|
-
backgroundColorRaw = csstree.generate(node);
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
leave: (node, item, list) => {
|
|
110
|
-
if (node.type === "Function") {
|
|
111
|
-
nestingLevel--;
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
backgroundImage: layers,
|
|
118
|
-
backgroundColor: backgroundColorRaw,
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
export const parseBackgroundImage = (
|
|
123
|
-
layers: string[]
|
|
124
|
-
): LayersValue | InvalidValue => {
|
|
125
|
-
const backgroundImages: UnparsedValue[] = [];
|
|
126
|
-
|
|
127
|
-
for (const layer of layers) {
|
|
128
|
-
if (
|
|
129
|
-
gradientNames.some((gradientName) => layer.startsWith(gradientName)) ===
|
|
130
|
-
false
|
|
131
|
-
) {
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const layerStyle = parseCssValue("backgroundImage", layer);
|
|
136
|
-
|
|
137
|
-
if (layerStyle.type !== "unparsed") {
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
backgroundImages.push(layerStyle);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return backgroundImages.length > 0
|
|
145
|
-
? { type: "layers", value: backgroundImages }
|
|
146
|
-
: { type: "invalid", value: layers.join(",") };
|
|
147
|
-
};
|
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "@jest/globals";
|
|
2
|
-
|
|
3
|
-
import { parseBoxShadow } from "./box-shadow";
|
|
4
|
-
|
|
5
|
-
describe("parseBoxShadow", () => {
|
|
6
|
-
test("parses value and returns invalid when used a invalid color", () => {
|
|
7
|
-
expect(parseBoxShadow(`10px 10px 5px foo`)).toMatchInlineSnapshot(`
|
|
8
|
-
{
|
|
9
|
-
"type": "invalid",
|
|
10
|
-
"value": "10px 10px 5px foo",
|
|
11
|
-
}
|
|
12
|
-
`);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test("throws error when passed a value without a unit", () => {
|
|
16
|
-
expect(parseBoxShadow(`10 10px 5px red`)).toMatchInlineSnapshot(`
|
|
17
|
-
{
|
|
18
|
-
"type": "invalid",
|
|
19
|
-
"value": "10 10px 5px red",
|
|
20
|
-
}
|
|
21
|
-
`);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("inset and color values can be interchanged", () => {
|
|
25
|
-
expect(parseBoxShadow(`inset 10px 10px 5px black;`)).toMatchInlineSnapshot(`
|
|
26
|
-
{
|
|
27
|
-
"type": "layers",
|
|
28
|
-
"value": [
|
|
29
|
-
{
|
|
30
|
-
"type": "tuple",
|
|
31
|
-
"value": [
|
|
32
|
-
{
|
|
33
|
-
"type": "keyword",
|
|
34
|
-
"value": "inset",
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"type": "unit",
|
|
38
|
-
"unit": "px",
|
|
39
|
-
"value": 10,
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"type": "unit",
|
|
43
|
-
"unit": "px",
|
|
44
|
-
"value": 10,
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
"type": "unit",
|
|
48
|
-
"unit": "px",
|
|
49
|
-
"value": 5,
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
"type": "keyword",
|
|
53
|
-
"value": "black",
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
}
|
|
59
|
-
`);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("parses value when inset is used but missing blur-radius", () => {
|
|
63
|
-
expect(parseBoxShadow(`box-shadow: inset 5em 1em gold`))
|
|
64
|
-
.toMatchInlineSnapshot(`
|
|
65
|
-
{
|
|
66
|
-
"type": "layers",
|
|
67
|
-
"value": [
|
|
68
|
-
{
|
|
69
|
-
"type": "tuple",
|
|
70
|
-
"value": [
|
|
71
|
-
{
|
|
72
|
-
"type": "keyword",
|
|
73
|
-
"value": "inset",
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
"type": "unit",
|
|
77
|
-
"unit": "em",
|
|
78
|
-
"value": 5,
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
"type": "unit",
|
|
82
|
-
"unit": "em",
|
|
83
|
-
"value": 1,
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
"type": "keyword",
|
|
87
|
-
"value": "gold",
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
}
|
|
93
|
-
`);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test("parses value when offsetX and offsetY are used", () => {
|
|
97
|
-
expect(parseBoxShadow(`box-shadow: 60px -16px teal;`))
|
|
98
|
-
.toMatchInlineSnapshot(`
|
|
99
|
-
{
|
|
100
|
-
"type": "layers",
|
|
101
|
-
"value": [
|
|
102
|
-
{
|
|
103
|
-
"type": "tuple",
|
|
104
|
-
"value": [
|
|
105
|
-
{
|
|
106
|
-
"type": "unit",
|
|
107
|
-
"unit": "px",
|
|
108
|
-
"value": 60,
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
"type": "unit",
|
|
112
|
-
"unit": "px",
|
|
113
|
-
"value": -16,
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
"type": "keyword",
|
|
117
|
-
"value": "teal",
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
},
|
|
121
|
-
],
|
|
122
|
-
}
|
|
123
|
-
`);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test("parses value from figma", () => {
|
|
127
|
-
expect(
|
|
128
|
-
parseBoxShadow(
|
|
129
|
-
"box-shadow: 0 60px 80px rgba(0,0,0,0.60), 0 45px 26px rgba(0,0,0,0.14);"
|
|
130
|
-
)
|
|
131
|
-
).toMatchInlineSnapshot(`
|
|
132
|
-
{
|
|
133
|
-
"type": "layers",
|
|
134
|
-
"value": [
|
|
135
|
-
{
|
|
136
|
-
"type": "tuple",
|
|
137
|
-
"value": [
|
|
138
|
-
{
|
|
139
|
-
"type": "unit",
|
|
140
|
-
"unit": "number",
|
|
141
|
-
"value": 0,
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
"type": "unit",
|
|
145
|
-
"unit": "px",
|
|
146
|
-
"value": 60,
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
"type": "unit",
|
|
150
|
-
"unit": "px",
|
|
151
|
-
"value": 80,
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
"alpha": 0.6,
|
|
155
|
-
"b": 0,
|
|
156
|
-
"g": 0,
|
|
157
|
-
"r": 0,
|
|
158
|
-
"type": "rgb",
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
"type": "tuple",
|
|
164
|
-
"value": [
|
|
165
|
-
{
|
|
166
|
-
"type": "unit",
|
|
167
|
-
"unit": "number",
|
|
168
|
-
"value": 0,
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
"type": "unit",
|
|
172
|
-
"unit": "px",
|
|
173
|
-
"value": 45,
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
"type": "unit",
|
|
177
|
-
"unit": "px",
|
|
178
|
-
"value": 26,
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
"alpha": 0.14,
|
|
182
|
-
"b": 0,
|
|
183
|
-
"g": 0,
|
|
184
|
-
"r": 0,
|
|
185
|
-
"type": "rgb",
|
|
186
|
-
},
|
|
187
|
-
],
|
|
188
|
-
},
|
|
189
|
-
],
|
|
190
|
-
}
|
|
191
|
-
`);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test(`parses multiple layers of box-shadow property`, () => {
|
|
195
|
-
expect(
|
|
196
|
-
parseBoxShadow(`box-shadow:
|
|
197
|
-
0 0 5px rgba(0, 0, 0, 0.2),
|
|
198
|
-
inset 0 0 10px rgba(0, 0, 0, 0.3),
|
|
199
|
-
0 0 15px rgba(0, 0, 0, 0.4);
|
|
200
|
-
`)
|
|
201
|
-
).toMatchInlineSnapshot(`
|
|
202
|
-
{
|
|
203
|
-
"type": "layers",
|
|
204
|
-
"value": [
|
|
205
|
-
{
|
|
206
|
-
"type": "tuple",
|
|
207
|
-
"value": [
|
|
208
|
-
{
|
|
209
|
-
"type": "unit",
|
|
210
|
-
"unit": "number",
|
|
211
|
-
"value": 0,
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
"type": "unit",
|
|
215
|
-
"unit": "number",
|
|
216
|
-
"value": 0,
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
"type": "unit",
|
|
220
|
-
"unit": "px",
|
|
221
|
-
"value": 5,
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
"alpha": 0.2,
|
|
225
|
-
"b": 0,
|
|
226
|
-
"g": 0,
|
|
227
|
-
"r": 0,
|
|
228
|
-
"type": "rgb",
|
|
229
|
-
},
|
|
230
|
-
],
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
"type": "tuple",
|
|
234
|
-
"value": [
|
|
235
|
-
{
|
|
236
|
-
"type": "keyword",
|
|
237
|
-
"value": "inset",
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
"type": "unit",
|
|
241
|
-
"unit": "number",
|
|
242
|
-
"value": 0,
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
"type": "unit",
|
|
246
|
-
"unit": "number",
|
|
247
|
-
"value": 0,
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
"type": "unit",
|
|
251
|
-
"unit": "px",
|
|
252
|
-
"value": 10,
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
"alpha": 0.3,
|
|
256
|
-
"b": 0,
|
|
257
|
-
"g": 0,
|
|
258
|
-
"r": 0,
|
|
259
|
-
"type": "rgb",
|
|
260
|
-
},
|
|
261
|
-
],
|
|
262
|
-
},
|
|
263
|
-
{
|
|
264
|
-
"type": "tuple",
|
|
265
|
-
"value": [
|
|
266
|
-
{
|
|
267
|
-
"type": "unit",
|
|
268
|
-
"unit": "number",
|
|
269
|
-
"value": 0,
|
|
270
|
-
},
|
|
271
|
-
{
|
|
272
|
-
"type": "unit",
|
|
273
|
-
"unit": "number",
|
|
274
|
-
"value": 0,
|
|
275
|
-
},
|
|
276
|
-
{
|
|
277
|
-
"type": "unit",
|
|
278
|
-
"unit": "px",
|
|
279
|
-
"value": 15,
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
"alpha": 0.4,
|
|
283
|
-
"b": 0,
|
|
284
|
-
"g": 0,
|
|
285
|
-
"r": 0,
|
|
286
|
-
"type": "rgb",
|
|
287
|
-
},
|
|
288
|
-
],
|
|
289
|
-
},
|
|
290
|
-
],
|
|
291
|
-
}
|
|
292
|
-
`);
|
|
293
|
-
});
|
|
294
|
-
});
|