@webstudio-is/css-engine 0.36.0 → 0.41.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.
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,10 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
19
  var __accessCheck = (obj, member, msg) => {
26
20
  if (!member.has(obj))
@@ -48,8 +42,8 @@ __export(rules_exports, {
48
42
  StyleRule: () => StyleRule
49
43
  });
50
44
  module.exports = __toCommonJS(rules_exports);
51
- var import_hyphenate_style_name = __toESM(require("hyphenate-style-name"), 1);
52
45
  var import_to_value = require("./to-value");
46
+ var import_to_property = require("./to-property");
53
47
  var _styleMap, _isDirty, _string, _onChange, _mediaType;
54
48
  class StylePropertyMap {
55
49
  constructor() {
@@ -87,7 +81,7 @@ class StylePropertyMap {
87
81
  if (value === void 0) {
88
82
  continue;
89
83
  }
90
- block.push(`${(0, import_hyphenate_style_name.default)(property)}: ${(0, import_to_value.toValue)(value)}`);
84
+ block.push(`${(0, import_to_property.toProperty)(property)}: ${(0, import_to_value.toValue)(value)}`);
91
85
  }
92
86
  __privateSet(this, _string, block.join("; "));
93
87
  __privateSet(this, _isDirty, false);
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var to_property_exports = {};
26
+ __export(to_property_exports, {
27
+ toProperty: () => toProperty
28
+ });
29
+ module.exports = __toCommonJS(to_property_exports);
30
+ var import_hyphenate_style_name = __toESM(require("hyphenate-style-name"), 1);
31
+ const toProperty = (property) => {
32
+ if (property === "backgroundClip") {
33
+ return "-webkit-background-clip";
34
+ }
35
+ return (0, import_hyphenate_style_name.default)(property);
36
+ };
@@ -67,13 +67,14 @@ const toValue = (value, options = defaultOptions) => {
67
67
  return `rgba(${value.r}, ${value.g}, ${value.b}, ${value.alpha})`;
68
68
  }
69
69
  if (value.type === "image") {
70
- return value.value.map(
71
- (imageAsset) => `url(${imageAsset.value.path}) /* id=${imageAsset.value.id} */`
72
- ).join(", ");
70
+ return `url(${value.value.value.path}) /* id=${value.value.value.id} */`;
73
71
  }
74
72
  if (value.type === "unparsed") {
75
73
  return value.value;
76
74
  }
75
+ if (value.type === "layers") {
76
+ return value.value.map((v) => toValue(v, options)).join(",");
77
+ }
77
78
  assertUnreachable(value, `Unknown value type`);
78
79
  throw new Error("Unknown value type");
79
80
  };
package/lib/core/rules.js CHANGED
@@ -17,8 +17,8 @@ var __privateSet = (obj, member, value, setter) => {
17
17
  return value;
18
18
  };
19
19
  var _styleMap, _isDirty, _string, _onChange, _mediaType;
20
- import hyphenate from "hyphenate-style-name";
21
20
  import { toValue } from "./to-value";
21
+ import { toProperty } from "./to-property";
22
22
  class StylePropertyMap {
23
23
  constructor() {
24
24
  __privateAdd(this, _styleMap, /* @__PURE__ */ new Map());
@@ -55,7 +55,7 @@ class StylePropertyMap {
55
55
  if (value === void 0) {
56
56
  continue;
57
57
  }
58
- block.push(`${hyphenate(property)}: ${toValue(value)}`);
58
+ block.push(`${toProperty(property)}: ${toValue(value)}`);
59
59
  }
60
60
  __privateSet(this, _string, block.join("; "));
61
61
  __privateSet(this, _isDirty, false);
@@ -0,0 +1,10 @@
1
+ import hyphenate from "hyphenate-style-name";
2
+ const toProperty = (property) => {
3
+ if (property === "backgroundClip") {
4
+ return "-webkit-background-clip";
5
+ }
6
+ return hyphenate(property);
7
+ };
8
+ export {
9
+ toProperty
10
+ };
@@ -44,13 +44,14 @@ const toValue = (value, options = defaultOptions) => {
44
44
  return `rgba(${value.r}, ${value.g}, ${value.b}, ${value.alpha})`;
45
45
  }
46
46
  if (value.type === "image") {
47
- return value.value.map(
48
- (imageAsset) => `url(${imageAsset.value.path}) /* id=${imageAsset.value.id} */`
49
- ).join(", ");
47
+ return `url(${value.value.value.path}) /* id=${value.value.value.id} */`;
50
48
  }
51
49
  if (value.type === "unparsed") {
52
50
  return value.value;
53
51
  }
52
+ if (value.type === "layers") {
53
+ return value.value.map((v) => toValue(v, options)).join(",");
54
+ }
54
55
  assertUnreachable(value, `Unknown value type`);
55
56
  throw new Error("Unknown value type");
56
57
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/css-engine",
3
- "version": "0.36.0",
3
+ "version": "0.41.0",
4
4
  "description": "CSS Renderer for Webstudio",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -9,7 +9,7 @@
9
9
  "hyphenate-style-name": "^1.0.4",
10
10
  "react": "^17.0.2",
11
11
  "react-dom": "^17.0.2",
12
- "@webstudio-is/fonts": "^0.36.0"
12
+ "@webstudio-is/fonts": "^0.41.0"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@jest/globals": "^29.3.1",
@@ -21,7 +21,7 @@
21
21
  "@types/react-dom": "^17.0.9",
22
22
  "jest": "^29.3.1",
23
23
  "typescript": "4.9.5",
24
- "@webstudio-is/css-data": "^0.36.0",
24
+ "@webstudio-is/css-data": "^0.41.0",
25
25
  "@webstudio-is/jest-config": "^1.0.2",
26
26
  "@webstudio-is/scripts": "^0.0.0",
27
27
  "@webstudio-is/storybook-config": "^0.0.0",
package/src/core/rules.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Style, StyleProperty, StyleValue } from "@webstudio-is/css-data";
2
- import hyphenate from "hyphenate-style-name";
3
2
  import { toValue } from "./to-value";
3
+ import { toProperty } from "./to-property";
4
4
 
5
5
  class StylePropertyMap {
6
6
  #styleMap: Map<StyleProperty, StyleValue | undefined> = new Map();
@@ -37,7 +37,7 @@ class StylePropertyMap {
37
37
  if (value === undefined) {
38
38
  continue;
39
39
  }
40
- block.push(`${hyphenate(property)}: ${toValue(value)}`);
40
+ block.push(`${toProperty(property)}: ${toValue(value)}`);
41
41
  }
42
42
  this.#string = block.join("; ");
43
43
  this.#isDirty = false;
@@ -0,0 +1,11 @@
1
+ import { describe, test } from "@jest/globals";
2
+ import { toProperty } from "./to-property";
3
+
4
+ describe("toProperty", () => {
5
+ test("boxSizing", () => {
6
+ expect(toProperty("boxSizing")).toBe("box-sizing");
7
+ });
8
+ test("backgroundClip", () => {
9
+ expect(toProperty("backgroundClip")).toBe("-webkit-background-clip");
10
+ });
11
+ });
@@ -0,0 +1,12 @@
1
+ import type { StyleProperty } from "@webstudio-is/css-data";
2
+ import hyphenate from "hyphenate-style-name";
3
+
4
+ export const toProperty = (property: StyleProperty) => {
5
+ // Currently its a non-standard property and is only officially supported via -webkit- prefix.
6
+ // Safari illegally supports it without the prefix.
7
+ // https://caniuse.com/background-clip-text
8
+ if (property === "backgroundClip") {
9
+ return "-webkit-background-clip";
10
+ }
11
+ return hyphenate(property);
12
+ };
@@ -64,4 +64,40 @@ describe("Convert WS CSS Values to native CSS strings", () => {
64
64
  );
65
65
  expect(value).toBe("Courier New");
66
66
  });
67
+
68
+ test("array", () => {
69
+ const value = toValue({
70
+ type: "layers",
71
+ value: [
72
+ {
73
+ type: "keyword",
74
+ value: "auto",
75
+ },
76
+ { type: "unit", value: 10, unit: "px" },
77
+ { type: "unparsed", value: "calc(10px)" },
78
+ {
79
+ type: "image",
80
+ value: {
81
+ type: "asset",
82
+ value: {
83
+ type: "image",
84
+ path: "foo.png",
85
+
86
+ id: "1234567890",
87
+ projectId: "",
88
+ format: "",
89
+ size: 1212,
90
+ name: "img",
91
+ description: "",
92
+ location: "REMOTE",
93
+ createdAt: "",
94
+ meta: { width: 1, height: 2 },
95
+ },
96
+ },
97
+ },
98
+ ],
99
+ });
100
+
101
+ expect(value).toBe("auto,10px,calc(10px),url(foo.png) /* id=1234567890 */");
102
+ });
67
103
  });
@@ -63,18 +63,17 @@ export const toValue = (
63
63
 
64
64
  if (value.type === "image") {
65
65
  // @todo image-set
66
- return value.value
67
- .map(
68
- (imageAsset) =>
69
- `url(${imageAsset.value.path}) /* id=${imageAsset.value.id} */`
70
- )
71
- .join(", ");
66
+ return `url(${value.value.value.path}) /* id=${value.value.value.id} */`;
72
67
  }
73
68
 
74
69
  if (value.type === "unparsed") {
75
70
  return value.value;
76
71
  }
77
72
 
73
+ if (value.type === "layers") {
74
+ return value.value.map((v) => toValue(v, options)).join(",");
75
+ }
76
+
78
77
  // Will give ts error in case of missing type
79
78
  assertUnreachable(value, `Unknown value type`);
80
79