@webstudio-is/css-engine 0.4.0 → 0.4.1

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.
@@ -81,8 +81,9 @@ class CssEngine {
81
81
  }
82
82
  addPlaintextRule(cssText) {
83
83
  const rule = __privateGet(this, _plainRules).get(cssText);
84
- if (rule !== void 0)
84
+ if (rule !== void 0) {
85
85
  return rule;
86
+ }
86
87
  __privateSet(this, _isDirty, true);
87
88
  return __privateGet(this, _plainRules).set(cssText, new import_rules.PlaintextRule(cssText));
88
89
  }
@@ -115,8 +116,9 @@ class CssEngine {
115
116
  }
116
117
  for (const mediaRule of __privateGet(this, _mediaRules).values()) {
117
118
  const { cssText } = mediaRule;
118
- if (cssText !== "")
119
+ if (cssText !== "") {
119
120
  css.push(cssText);
121
+ }
120
122
  }
121
123
  __privateSet(this, _cssText, css.join("\n"));
122
124
  return __privateGet(this, _cssText);
@@ -76,8 +76,9 @@ class StylePropertyMap {
76
76
  }
77
77
  const block = [];
78
78
  for (const [property, value] of __privateGet(this, _styleMap)) {
79
- if (value === void 0)
79
+ if (value === void 0) {
80
80
  continue;
81
+ }
81
82
  block.push(`${(0, import_hyphenate_style_name.default)(property)}: ${(0, import_to_value.toValue)(value)}`);
82
83
  }
83
84
  __privateSet(this, _string, block.join("; "));
@@ -119,20 +120,24 @@ class MediaRule {
119
120
  return rule;
120
121
  }
121
122
  get cssText() {
122
- if (this.rules.length === 0)
123
+ if (this.rules.length === 0) {
123
124
  return "";
125
+ }
124
126
  const rules = [];
125
127
  for (const rule of this.rules) {
126
128
  rules.push(` ${rule.cssText}`);
127
129
  }
128
130
  let conditionText = "";
129
131
  const { minWidth, maxWidth } = __privateGet(this, _options);
130
- if (minWidth !== void 0)
132
+ if (minWidth !== void 0) {
131
133
  conditionText = `min-width: ${minWidth}px`;
132
- if (maxWidth !== void 0)
134
+ }
135
+ if (maxWidth !== void 0) {
133
136
  conditionText = `max-width: ${maxWidth}px`;
134
- if (conditionText)
137
+ }
138
+ if (conditionText) {
135
139
  conditionText = `and (${conditionText}) `;
140
+ }
136
141
  return `@media ${__privateGet(this, _mediaType)} ${conditionText}{
137
142
  ${rules.join(
138
143
  "\n"
@@ -26,8 +26,9 @@ const defaultOptions = {
26
26
  withFallback: true
27
27
  };
28
28
  const toValue = (value, options = defaultOptions) => {
29
- if (value === void 0)
29
+ if (value === void 0) {
30
30
  return "";
31
+ }
31
32
  if (value.type === "unit") {
32
33
  return value.value + (value.unit === "number" ? "" : value.unit);
33
34
  }
@@ -63,8 +63,9 @@ class CssEngine {
63
63
  }
64
64
  addPlaintextRule(cssText) {
65
65
  const rule = __privateGet(this, _plainRules).get(cssText);
66
- if (rule !== void 0)
66
+ if (rule !== void 0) {
67
67
  return rule;
68
+ }
68
69
  __privateSet(this, _isDirty, true);
69
70
  return __privateGet(this, _plainRules).set(cssText, new PlaintextRule(cssText));
70
71
  }
@@ -97,8 +98,9 @@ class CssEngine {
97
98
  }
98
99
  for (const mediaRule of __privateGet(this, _mediaRules).values()) {
99
100
  const { cssText } = mediaRule;
100
- if (cssText !== "")
101
+ if (cssText !== "") {
101
102
  css.push(cssText);
103
+ }
102
104
  }
103
105
  __privateSet(this, _cssText, css.join("\n"));
104
106
  return __privateGet(this, _cssText);
package/lib/core/rules.js CHANGED
@@ -44,8 +44,9 @@ class StylePropertyMap {
44
44
  }
45
45
  const block = [];
46
46
  for (const [property, value] of __privateGet(this, _styleMap)) {
47
- if (value === void 0)
47
+ if (value === void 0) {
48
48
  continue;
49
+ }
49
50
  block.push(`${hyphenate(property)}: ${toValue(value)}`);
50
51
  }
51
52
  __privateSet(this, _string, block.join("; "));
@@ -87,20 +88,24 @@ class MediaRule {
87
88
  return rule;
88
89
  }
89
90
  get cssText() {
90
- if (this.rules.length === 0)
91
+ if (this.rules.length === 0) {
91
92
  return "";
93
+ }
92
94
  const rules = [];
93
95
  for (const rule of this.rules) {
94
96
  rules.push(` ${rule.cssText}`);
95
97
  }
96
98
  let conditionText = "";
97
99
  const { minWidth, maxWidth } = __privateGet(this, _options);
98
- if (minWidth !== void 0)
100
+ if (minWidth !== void 0) {
99
101
  conditionText = `min-width: ${minWidth}px`;
100
- if (maxWidth !== void 0)
102
+ }
103
+ if (maxWidth !== void 0) {
101
104
  conditionText = `max-width: ${maxWidth}px`;
102
- if (conditionText)
105
+ }
106
+ if (conditionText) {
103
107
  conditionText = `and (${conditionText}) `;
108
+ }
104
109
  return `@media ${__privateGet(this, _mediaType)} ${conditionText}{
105
110
  ${rules.join(
106
111
  "\n"
@@ -3,8 +3,9 @@ const defaultOptions = {
3
3
  withFallback: true
4
4
  };
5
5
  const toValue = (value, options = defaultOptions) => {
6
- if (value === void 0)
6
+ if (value === void 0) {
7
7
  return "";
8
+ }
8
9
  if (value.type === "unit") {
9
10
  return value.value + (value.unit === "number" ? "" : value.unit);
10
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/css-engine",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "CSS Renderer for Webstudio",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -47,7 +47,9 @@ export class CssEngine {
47
47
  }
48
48
  addPlaintextRule(cssText: string) {
49
49
  const rule = this.#plainRules.get(cssText);
50
- if (rule !== undefined) return rule;
50
+ if (rule !== undefined) {
51
+ return rule;
52
+ }
51
53
  this.#isDirty = true;
52
54
  return this.#plainRules.set(cssText, new PlaintextRule(cssText));
53
55
  }
@@ -82,7 +84,9 @@ export class CssEngine {
82
84
  }
83
85
  for (const mediaRule of this.#mediaRules.values()) {
84
86
  const { cssText } = mediaRule;
85
- if (cssText !== "") css.push(cssText);
87
+ if (cssText !== "") {
88
+ css.push(cssText);
89
+ }
86
90
  }
87
91
  this.#cssText = css.join("\n");
88
92
  return this.#cssText;
package/src/core/rules.ts CHANGED
@@ -26,7 +26,9 @@ class StylePropertyMap {
26
26
  }
27
27
  const block: Array<string> = [];
28
28
  for (const [property, value] of this.#styleMap) {
29
- if (value === undefined) continue;
29
+ if (value === undefined) {
30
+ continue;
31
+ }
30
32
  block.push(`${hyphenate(property)}: ${toValue(value)}`);
31
33
  }
32
34
  this.#string = block.join("; ");
@@ -75,16 +77,24 @@ export class MediaRule {
75
77
  return rule;
76
78
  }
77
79
  get cssText() {
78
- if (this.rules.length === 0) return "";
80
+ if (this.rules.length === 0) {
81
+ return "";
82
+ }
79
83
  const rules = [];
80
84
  for (const rule of this.rules) {
81
85
  rules.push(` ${rule.cssText}`);
82
86
  }
83
87
  let conditionText = "";
84
88
  const { minWidth, maxWidth } = this.#options;
85
- if (minWidth !== undefined) conditionText = `min-width: ${minWidth}px`;
86
- if (maxWidth !== undefined) conditionText = `max-width: ${maxWidth}px`;
87
- if (conditionText) conditionText = `and (${conditionText}) `;
89
+ if (minWidth !== undefined) {
90
+ conditionText = `min-width: ${minWidth}px`;
91
+ }
92
+ if (maxWidth !== undefined) {
93
+ conditionText = `max-width: ${maxWidth}px`;
94
+ }
95
+ if (conditionText) {
96
+ conditionText = `and (${conditionText}) `;
97
+ }
88
98
  return `@media ${this.#mediaType} ${conditionText}{\n${rules.join(
89
99
  "\n"
90
100
  )}\n}`;
@@ -13,7 +13,9 @@ export const toValue = (
13
13
  value?: StyleValue,
14
14
  options: ToCssOptions = defaultOptions
15
15
  ): string => {
16
- if (value === undefined) return "";
16
+ if (value === undefined) {
17
+ return "";
18
+ }
17
19
  if (value.type === "unit") {
18
20
  return value.value + (value.unit === "number" ? "" : value.unit);
19
21
  }