@webstudio-is/css-data 0.72.0 → 0.73.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.
@@ -69,10 +69,21 @@ const parseCssValue = function parseCssValue2(property, value) {
69
69
  [property]: (0, import_parse_css_value.parseCssValue)(property, value)
70
70
  };
71
71
  };
72
+ const cssTreeTryParse = (input) => {
73
+ try {
74
+ const ast = csstree.parse(input);
75
+ return ast;
76
+ } catch {
77
+ return void 0;
78
+ }
79
+ };
72
80
  const parseCss = function cssToWS(css) {
73
- const ast = csstree.parse(css);
81
+ const ast = cssTreeTryParse(css);
74
82
  let selectors = [];
75
83
  const styles = {};
84
+ if (ast === void 0) {
85
+ return styles;
86
+ }
76
87
  csstree.walk(ast, (node, item) => {
77
88
  if (node.type === "SelectorList") {
78
89
  selectors = [];
@@ -52,6 +52,14 @@ const parseBackground = (background) => {
52
52
  backgroundColor: backgroundColor && backgroundColor.type === "rgb" ? backgroundColor : void 0
53
53
  };
54
54
  };
55
+ const cssTreeTryParseValue = (input) => {
56
+ try {
57
+ const ast = csstree.parse(input, { context: "value" });
58
+ return ast;
59
+ } catch {
60
+ return void 0;
61
+ }
62
+ };
55
63
  const backgroundToLonghand = (background) => {
56
64
  const layers = [];
57
65
  let tokenStream = background.trim();
@@ -60,7 +68,13 @@ const backgroundToLonghand = (background) => {
60
68
  for (const cleanupKeyword of cleanupKeywords) {
61
69
  tokenStream = tokenStream.startsWith(cleanupKeyword) ? tokenStream.slice(cleanupKeyword.length).trim() : tokenStream;
62
70
  }
63
- const cssAst = csstree.parse(tokenStream, { context: "value" });
71
+ const cssAst = cssTreeTryParseValue(tokenStream);
72
+ if (cssAst === void 0) {
73
+ return {
74
+ backgroundImage: [],
75
+ backgroundColor: void 0
76
+ };
77
+ }
64
78
  let backgroundColorRaw;
65
79
  let nestingLevel = 0;
66
80
  csstree.walk(cssAst, {
package/lib/parse-css.js CHANGED
@@ -36,10 +36,21 @@ const parseCssValue = function parseCssValue2(property, value) {
36
36
  [property]: parseCssValueLonghand(property, value)
37
37
  };
38
38
  };
39
+ const cssTreeTryParse = (input) => {
40
+ try {
41
+ const ast = csstree.parse(input);
42
+ return ast;
43
+ } catch {
44
+ return void 0;
45
+ }
46
+ };
39
47
  const parseCss = function cssToWS(css) {
40
- const ast = csstree.parse(css);
48
+ const ast = cssTreeTryParse(css);
41
49
  let selectors = [];
42
50
  const styles = {};
51
+ if (ast === void 0) {
52
+ return styles;
53
+ }
43
54
  csstree.walk(ast, (node, item) => {
44
55
  if (node.type === "SelectorList") {
45
56
  selectors = [];
@@ -16,6 +16,14 @@ const parseBackground = (background) => {
16
16
  backgroundColor: backgroundColor && backgroundColor.type === "rgb" ? backgroundColor : void 0
17
17
  };
18
18
  };
19
+ const cssTreeTryParseValue = (input) => {
20
+ try {
21
+ const ast = csstree.parse(input, { context: "value" });
22
+ return ast;
23
+ } catch {
24
+ return void 0;
25
+ }
26
+ };
19
27
  const backgroundToLonghand = (background) => {
20
28
  const layers = [];
21
29
  let tokenStream = background.trim();
@@ -24,7 +32,13 @@ const backgroundToLonghand = (background) => {
24
32
  for (const cleanupKeyword of cleanupKeywords) {
25
33
  tokenStream = tokenStream.startsWith(cleanupKeyword) ? tokenStream.slice(cleanupKeyword.length).trim() : tokenStream;
26
34
  }
27
- const cssAst = csstree.parse(tokenStream, { context: "value" });
35
+ const cssAst = cssTreeTryParseValue(tokenStream);
36
+ if (cssAst === void 0) {
37
+ return {
38
+ backgroundImage: [],
39
+ backgroundColor: void 0
40
+ };
41
+ }
28
42
  let backgroundColorRaw;
29
43
  let nestingLevel = 0;
30
44
  csstree.walk(cssAst, {
@@ -0,0 +1 @@
1
+ export {};