@webstudio-is/css-data 0.72.0 → 0.74.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/cjs/index.js CHANGED
@@ -29,17 +29,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
30
  var src_exports = {};
31
31
  __export(src_exports, {
32
+ declarationDescriptions: () => import_property_value_descriptions.declarations,
32
33
  html: () => html,
33
- properties: () => properties
34
+ properties: () => properties2,
35
+ propertyDescriptions: () => import_property_value_descriptions.properties
34
36
  });
35
37
  module.exports = __toCommonJS(src_exports);
36
38
  var exportedHtml = __toESM(require("./html"), 1);
37
39
  __reExport(src_exports, require("./__generated__/keyword-values"), module.exports);
38
40
  __reExport(src_exports, require("./__generated__/units"), module.exports);
41
+ var import_property_value_descriptions = require("./__generated__/property-value-descriptions");
39
42
  __reExport(src_exports, require("./schema"), module.exports);
40
43
  __reExport(src_exports, require("./property-parsers/index"), module.exports);
41
44
  __reExport(src_exports, require("./parse-css-value"), module.exports);
42
45
  __reExport(src_exports, require("./parse-css"), module.exports);
43
46
  var import_properties = require("./__generated__/properties");
44
47
  const html = exportedHtml;
45
- const properties = import_properties.properties;
48
+ const properties2 = import_properties.properties;
@@ -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/index.js CHANGED
@@ -2,13 +2,19 @@ import * as exportedHtml from "./html";
2
2
  const html = exportedHtml;
3
3
  export * from "./__generated__/keyword-values";
4
4
  export * from "./__generated__/units";
5
+ import {
6
+ properties,
7
+ declarations
8
+ } from "./__generated__/property-value-descriptions";
5
9
  export * from "./schema";
6
10
  export * from "./property-parsers/index";
7
11
  export * from "./parse-css-value";
8
12
  export * from "./parse-css";
9
13
  import { properties as generatedProperties } from "./__generated__/properties";
10
- const properties = generatedProperties;
14
+ const properties2 = generatedProperties;
11
15
  export {
16
+ declarations as declarationDescriptions,
12
17
  html,
13
- properties
18
+ properties2 as properties,
19
+ properties as propertyDescriptions
14
20
  };
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 {};