@webstudio-is/css-engine 0.15.0 → 0.17.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.
@@ -65,6 +65,14 @@ class StylePropertyMap {
65
65
  has(property) {
66
66
  return __privateGet(this, _styleMap).has(property);
67
67
  }
68
+ keys() {
69
+ return __privateGet(this, _styleMap).keys();
70
+ }
71
+ delete(property) {
72
+ __privateGet(this, _styleMap).delete(property);
73
+ __privateSet(this, _isDirty, true);
74
+ this.onChange?.();
75
+ }
68
76
  clear() {
69
77
  __privateGet(this, _styleMap).clear();
70
78
  __privateSet(this, _isDirty, true);
package/lib/core/rules.js CHANGED
@@ -33,6 +33,14 @@ class StylePropertyMap {
33
33
  has(property) {
34
34
  return __privateGet(this, _styleMap).has(property);
35
35
  }
36
+ keys() {
37
+ return __privateGet(this, _styleMap).keys();
38
+ }
39
+ delete(property) {
40
+ __privateGet(this, _styleMap).delete(property);
41
+ __privateSet(this, _isDirty, true);
42
+ this.onChange?.();
43
+ }
36
44
  clear() {
37
45
  __privateGet(this, _styleMap).clear();
38
46
  __privateSet(this, _isDirty, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/css-engine",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "description": "CSS Renderer for Webstudio",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -11,6 +11,11 @@ const style1 = {
11
11
  display: { type: "keyword", value: "flex" },
12
12
  } as const;
13
13
 
14
+ const style2 = {
15
+ display: { type: "keyword", value: "block" },
16
+ color: { type: "keyword", value: "black" },
17
+ } as const;
18
+
14
19
  const mediaRuleOptions1 = { minWidth: 300 } as const;
15
20
  const mediaId1 = "1";
16
21
 
@@ -278,4 +283,30 @@ describe("CssEngine", () => {
278
283
  engine.clear();
279
284
  expect(engine.cssText).toMatchInlineSnapshot(`""`);
280
285
  });
286
+
287
+ test("get all rule style keys", () => {
288
+ const rule = engine.addStyleRule(".c", {
289
+ style: style2,
290
+ breakpoint: "0",
291
+ });
292
+ expect(Array.from(rule.styleMap.keys())).toMatchInlineSnapshot(`
293
+ [
294
+ "display",
295
+ "color",
296
+ ]
297
+ `);
298
+ });
299
+
300
+ test("delete style from rule", () => {
301
+ const rule = engine.addStyleRule(".c", {
302
+ style: style2,
303
+ breakpoint: "0",
304
+ });
305
+ rule.styleMap.delete("display");
306
+ expect(engine.cssText).toMatchInlineSnapshot(`
307
+ "@media all {
308
+ .c { color: black }
309
+ }"
310
+ `);
311
+ });
281
312
  });
package/src/core/rules.ts CHANGED
@@ -15,6 +15,14 @@ class StylePropertyMap {
15
15
  has(property: StyleProperty) {
16
16
  return this.#styleMap.has(property);
17
17
  }
18
+ keys() {
19
+ return this.#styleMap.keys();
20
+ }
21
+ delete(property: StyleProperty) {
22
+ this.#styleMap.delete(property);
23
+ this.#isDirty = true;
24
+ this.onChange?.();
25
+ }
18
26
  clear() {
19
27
  this.#styleMap.clear();
20
28
  this.#isDirty = true;