@webstudio-is/css-engine 0.16.0 → 0.18.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/core/rules.cjs +8 -0
- package/lib/core/rules.js +8 -0
- package/package.json +13 -14
- package/src/core/css-engine.test.ts +32 -0
- package/src/core/rules.ts +8 -0
- package/src/core/to-value.test.ts +1 -0
package/lib/cjs/core/rules.cjs
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "CSS Renderer for Webstudio",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -17,27 +17,26 @@
|
|
|
17
17
|
"publish-to-npm": "bash ../../bin/publish-to-npm.sh"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@webstudio-is/fonts": "*",
|
|
20
21
|
"hyphenate-style-name": "^1.0.4",
|
|
21
22
|
"react": "^17.0.2",
|
|
22
|
-
"react-dom": "^17.0.2"
|
|
23
|
-
"@webstudio-is/fonts": "*"
|
|
23
|
+
"react-dom": "^17.0.2"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@
|
|
27
|
-
"@storybook/addon-essentials": "^6.5.6",
|
|
28
|
-
"@storybook/addon-interactions": "^6.5.12",
|
|
29
|
-
"@storybook/addon-links": "^6.5.6",
|
|
30
|
-
"@storybook/builder-webpack4": "^6.5.6",
|
|
26
|
+
"@jest/globals": "^29.3.1",
|
|
31
27
|
"@storybook/jest": "^0.0.10",
|
|
32
|
-
"@storybook/
|
|
33
|
-
"@storybook/react": "^6.5.6",
|
|
28
|
+
"@storybook/react": "^6.5.14",
|
|
34
29
|
"@storybook/testing-library": "^0.0.13",
|
|
35
|
-
"@
|
|
30
|
+
"@types/hyphenate-style-name": "^1.0.0",
|
|
31
|
+
"@types/react": "^17.0.24",
|
|
32
|
+
"@types/react-dom": "^17.0.9",
|
|
36
33
|
"@webstudio-is/css-data": "*",
|
|
34
|
+
"@webstudio-is/jest-config": "*",
|
|
37
35
|
"@webstudio-is/scripts": "*",
|
|
38
|
-
"
|
|
39
|
-
"@
|
|
40
|
-
"
|
|
36
|
+
"@webstudio-is/storybook-config": "*",
|
|
37
|
+
"@webstudio-is/tsconfig": "*",
|
|
38
|
+
"jest": "^29.3.1",
|
|
39
|
+
"typescript": "4.7.4"
|
|
41
40
|
},
|
|
42
41
|
"exports": "./lib/index.js",
|
|
43
42
|
"types": "src/index.ts",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describe, beforeEach, test, expect } from "@jest/globals";
|
|
1
2
|
import { CssEngine } from "./css-engine";
|
|
2
3
|
|
|
3
4
|
const style0 = {
|
|
@@ -11,6 +12,11 @@ const style1 = {
|
|
|
11
12
|
display: { type: "keyword", value: "flex" },
|
|
12
13
|
} as const;
|
|
13
14
|
|
|
15
|
+
const style2 = {
|
|
16
|
+
display: { type: "keyword", value: "block" },
|
|
17
|
+
color: { type: "keyword", value: "black" },
|
|
18
|
+
} as const;
|
|
19
|
+
|
|
14
20
|
const mediaRuleOptions1 = { minWidth: 300 } as const;
|
|
15
21
|
const mediaId1 = "1";
|
|
16
22
|
|
|
@@ -278,4 +284,30 @@ describe("CssEngine", () => {
|
|
|
278
284
|
engine.clear();
|
|
279
285
|
expect(engine.cssText).toMatchInlineSnapshot(`""`);
|
|
280
286
|
});
|
|
287
|
+
|
|
288
|
+
test("get all rule style keys", () => {
|
|
289
|
+
const rule = engine.addStyleRule(".c", {
|
|
290
|
+
style: style2,
|
|
291
|
+
breakpoint: "0",
|
|
292
|
+
});
|
|
293
|
+
expect(Array.from(rule.styleMap.keys())).toMatchInlineSnapshot(`
|
|
294
|
+
[
|
|
295
|
+
"display",
|
|
296
|
+
"color",
|
|
297
|
+
]
|
|
298
|
+
`);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
test("delete style from rule", () => {
|
|
302
|
+
const rule = engine.addStyleRule(".c", {
|
|
303
|
+
style: style2,
|
|
304
|
+
breakpoint: "0",
|
|
305
|
+
});
|
|
306
|
+
rule.styleMap.delete("display");
|
|
307
|
+
expect(engine.cssText).toMatchInlineSnapshot(`
|
|
308
|
+
"@media all {
|
|
309
|
+
.c { color: black }
|
|
310
|
+
}"
|
|
311
|
+
`);
|
|
312
|
+
});
|
|
281
313
|
});
|
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;
|