@webstudio-is/css-engine 0.3.0 → 0.4.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.
Files changed (52) hide show
  1. package/lib/cjs/core/create-css-engine.cjs +27 -0
  2. package/lib/cjs/core/css-engine.cjs +132 -0
  3. package/lib/cjs/core/index.cjs +27 -0
  4. package/lib/cjs/core/rules.cjs +163 -0
  5. package/lib/cjs/core/style-element.cjs +69 -0
  6. package/lib/cjs/core/style-sheet.cjs +57 -0
  7. package/lib/cjs/core/to-value.cjs +54 -0
  8. package/lib/cjs/index.cjs +18 -0
  9. package/lib/core/create-css-engine.js +5 -2
  10. package/lib/core/css-engine.js +106 -86
  11. package/lib/core/index.js +4 -1
  12. package/lib/core/rules.js +123 -98
  13. package/lib/core/style-element.js +43 -33
  14. package/lib/core/style-sheet.js +33 -22
  15. package/lib/core/to-value.js +27 -24
  16. package/package.json +7 -14
  17. package/src/core/create-css-engine.ts +5 -0
  18. package/src/core/css-engine.stories.tsx +48 -0
  19. package/src/core/css-engine.test.ts +206 -0
  20. package/src/core/css-engine.ts +94 -0
  21. package/src/core/index.ts +10 -0
  22. package/src/core/rules.ts +122 -0
  23. package/src/core/style-element.ts +24 -0
  24. package/src/core/style-sheet.ts +15 -0
  25. package/src/core/to-value.test.ts +66 -0
  26. package/src/core/to-value.ts +41 -0
  27. package/src/index.ts +1 -0
  28. package/lib/core/create-css-engine.d.ts +0 -3
  29. package/lib/core/create-css-engine.d.ts.map +0 -1
  30. package/lib/core/css-engine.d.ts +0 -15
  31. package/lib/core/css-engine.d.ts.map +0 -1
  32. package/lib/core/css-engine.stories.d.ts +0 -7
  33. package/lib/core/css-engine.stories.d.ts.map +0 -1
  34. package/lib/core/css-engine.stories.js +0 -31
  35. package/lib/core/css-engine.test.d.ts +0 -2
  36. package/lib/core/css-engine.test.d.ts.map +0 -1
  37. package/lib/core/css-engine.test.js +0 -182
  38. package/lib/core/index.d.ts +0 -5
  39. package/lib/core/index.d.ts.map +0 -1
  40. package/lib/core/rules.d.ts +0 -48
  41. package/lib/core/rules.d.ts.map +0 -1
  42. package/lib/core/style-element.d.ts +0 -8
  43. package/lib/core/style-element.d.ts.map +0 -1
  44. package/lib/core/style-sheet.d.ts +0 -7
  45. package/lib/core/style-sheet.d.ts.map +0 -1
  46. package/lib/core/to-value.d.ts +0 -7
  47. package/lib/core/to-value.d.ts.map +0 -1
  48. package/lib/core/to-value.test.d.ts +0 -2
  49. package/lib/core/to-value.test.d.ts.map +0 -1
  50. package/lib/core/to-value.test.js +0 -55
  51. package/lib/index.d.ts +0 -2
  52. package/lib/index.d.ts.map +0 -1
@@ -0,0 +1,66 @@
1
+ import { toValue } from "./to-value";
2
+
3
+ describe("Convert WS CSS Values to native CSS strings", () => {
4
+ test("keyword", () => {
5
+ const value = toValue({ type: "keyword", value: "red" });
6
+ expect(value).toBe("red");
7
+ });
8
+
9
+ test("unit", () => {
10
+ const value = toValue({ type: "unit", value: 10, unit: "px" });
11
+ expect(value).toBe("10px");
12
+ });
13
+
14
+ test("invalid", () => {
15
+ const value = toValue({ type: "invalid", value: "bad" });
16
+ expect(value).toBe("bad");
17
+ });
18
+
19
+ test("unset", () => {
20
+ const value = toValue({ type: "unset", value: "" });
21
+ expect(value).toBe("");
22
+ });
23
+
24
+ test("var", () => {
25
+ const value = toValue({ type: "var", value: "namespace", fallbacks: [] });
26
+ expect(value).toBe("var(--namespace)");
27
+ });
28
+
29
+ test("var with fallbacks", () => {
30
+ const value = toValue({
31
+ type: "var",
32
+ value: "namespace",
33
+ fallbacks: [
34
+ {
35
+ type: "keyword",
36
+ value: "normal",
37
+ },
38
+ {
39
+ type: "unit",
40
+ value: 10,
41
+ unit: "px",
42
+ },
43
+ ],
44
+ });
45
+ expect(value).toBe("var(--namespace, normal, 10px)");
46
+ });
47
+
48
+ test("fontFamily", () => {
49
+ const value = toValue({
50
+ type: "fontFamily",
51
+ value: ["Courier New"],
52
+ });
53
+ expect(value).toBe("Courier New, monospace");
54
+ });
55
+
56
+ test("withFallback=false", () => {
57
+ const value = toValue(
58
+ {
59
+ type: "fontFamily",
60
+ value: ["Courier New"],
61
+ },
62
+ { withFallback: false }
63
+ );
64
+ expect(value).toBe("Courier New");
65
+ });
66
+ });
@@ -0,0 +1,41 @@
1
+ import type { StyleValue } from "@webstudio-is/css-data";
2
+ import { DEFAULT_FONT_FALLBACK, SYSTEM_FONTS } from "@webstudio-is/fonts";
3
+
4
+ type ToCssOptions = {
5
+ withFallback: boolean;
6
+ };
7
+
8
+ const defaultOptions = {
9
+ withFallback: true,
10
+ };
11
+
12
+ export const toValue = (
13
+ value?: StyleValue,
14
+ options: ToCssOptions = defaultOptions
15
+ ): string => {
16
+ if (value === undefined) return "";
17
+ if (value.type === "unit") {
18
+ return value.value + (value.unit === "number" ? "" : value.unit);
19
+ }
20
+ if (value.type === "fontFamily") {
21
+ if (options.withFallback === false) {
22
+ return value.value[0];
23
+ }
24
+ const family = value.value[0];
25
+ const fallbacks = SYSTEM_FONTS.get(family);
26
+ if (Array.isArray(fallbacks)) {
27
+ return [...value.value, ...fallbacks].join(", ");
28
+ }
29
+ return [...value.value, DEFAULT_FONT_FALLBACK].join(", ");
30
+ }
31
+ if (value.type === "var") {
32
+ const fallbacks = [];
33
+ for (const fallback of value.fallbacks) {
34
+ fallbacks.push(toValue(fallback, options));
35
+ }
36
+ const fallbacksString =
37
+ fallbacks.length > 0 ? `, ${fallbacks.join(", ")}` : "";
38
+ return `var(--${value.value}${fallbacksString})`;
39
+ }
40
+ return value.value;
41
+ };
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./core";
@@ -1,3 +0,0 @@
1
- import { CssEngine } from "./css-engine";
2
- export declare const createCssEngine: () => CssEngine;
3
- //# sourceMappingURL=create-css-engine.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-css-engine.d.ts","sourceRoot":"","sources":["../../src/core/create-css-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,eAAO,MAAM,eAAe,iBAE3B,CAAC"}
@@ -1,15 +0,0 @@
1
- import type { CssRule } from "@webstudio-is/css-data";
2
- import { MediaRule, PlaintextRule, StyleRule, type FontFaceOptions, type MediaRuleOptions } from "./rules";
3
- export declare class CssEngine {
4
- #private;
5
- constructor();
6
- addMediaRule(id: string, options?: MediaRuleOptions): MediaRule;
7
- addStyleRule(selectorText: string, rule: CssRule): StyleRule;
8
- addPlaintextRule(cssText: string): PlaintextRule | Map<string, PlaintextRule>;
9
- addFontFaceRule(options: FontFaceOptions): number;
10
- clear(): void;
11
- render(): void;
12
- unmount(): void;
13
- get cssText(): string;
14
- }
15
- //# sourceMappingURL=css-engine.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"css-engine.d.ts","sourceRoot":"","sources":["../../src/core/css-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAEL,SAAS,EACT,aAAa,EACb,SAAS,EACT,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,SAAS,CAAC;AAMjB,qBAAa,SAAS;;;IAYpB,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB;IASnD,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;IAYhD,gBAAgB,CAAC,OAAO,EAAE,MAAM;IAMhC,eAAe,CAAC,OAAO,EAAE,eAAe;IAIxC,KAAK;IAML,MAAM;IAKN,OAAO;IAGP,IAAI,OAAO,WAiBV;CAKF"}
@@ -1,7 +0,0 @@
1
- /// <reference types="react" />
2
- declare const _default: {
3
- component: string;
4
- };
5
- export default _default;
6
- export declare const Basic: () => JSX.Element;
7
- //# sourceMappingURL=css-engine.stories.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"css-engine.stories.d.ts","sourceRoot":"","sources":["../../src/core/css-engine.stories.tsx"],"names":[],"mappings":";;;;AAEA,wBAEE;AASF,eAAO,MAAM,KAAK,mBAkCjB,CAAC"}
@@ -1,31 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CssEngine } from "./css-engine";
3
- export default {
4
- component: "CssEngine",
5
- };
6
- const style0 = {
7
- color: { type: "keyword", value: "red" },
8
- };
9
- const mediaRuleOptions0 = { minWidth: 0 };
10
- const mediaId = "0";
11
- export const Basic = () => {
12
- const engine = new CssEngine();
13
- engine.addMediaRule(mediaId, mediaRuleOptions0);
14
- const rule = engine.addStyleRule(".test", {
15
- style: style0,
16
- breakpoint: "0",
17
- });
18
- engine.render();
19
- return (_jsxs(_Fragment, { children: [_jsx("div", { className: "test", children: "Should be red" }), _jsx("button", { onClick: () => {
20
- rule.styleMap.set("color", { type: "keyword", value: "green" });
21
- engine.render();
22
- }, children: "Make it green" }), _jsx("button", { onClick: () => {
23
- engine.addStyleRule(".test", {
24
- style: {
25
- background: { type: "keyword", value: "yellow" },
26
- },
27
- breakpoint: "0",
28
- });
29
- engine.render();
30
- }, children: "Add rule with yellow background" })] }));
31
- };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=css-engine.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"css-engine.test.d.ts","sourceRoot":"","sources":["../../src/core/css-engine.test.ts"],"names":[],"mappings":""}
@@ -1,182 +0,0 @@
1
- import { CssEngine } from "./css-engine";
2
- const style0 = {
3
- display: { type: "keyword", value: "block" },
4
- };
5
- const mediaRuleOptions0 = { minWidth: 0 };
6
- const mediaId = "0";
7
- describe("CssEngine", () => {
8
- let engine;
9
- beforeEach(() => {
10
- engine = new CssEngine();
11
- });
12
- test("use default media rule when there is no matching one registrered", () => {
13
- engine.addStyleRule(".c", {
14
- style: style0,
15
- breakpoint: "x",
16
- });
17
- expect(engine.cssText).toMatchInlineSnapshot(`
18
- "@media all {
19
- .c { display: block }
20
- }"
21
- `);
22
- engine.addStyleRule(".c1", {
23
- style: { color: { type: "keyword", value: "red" } },
24
- breakpoint: "x",
25
- });
26
- expect(engine.cssText).toMatchInlineSnapshot(`
27
- "@media all {
28
- .c { display: block }
29
- .c1 { color: red }
30
- }"
31
- `);
32
- engine.addMediaRule(mediaId, mediaRuleOptions0);
33
- engine.addStyleRule(".c1", {
34
- style: { color: { type: "keyword", value: "blue" } },
35
- breakpoint: mediaId,
36
- });
37
- // Default media query should allways be the first to have the lowest source order specificity
38
- expect(engine.cssText).toMatchInlineSnapshot(`
39
- "@media all {
40
- .c { display: block }
41
- .c1 { color: red }
42
- }
43
- @media all and (min-width: 0px) {
44
- .c1 { color: blue }
45
- }"
46
- `);
47
- });
48
- test("rule with multiple properties", () => {
49
- engine.addMediaRule(mediaId, mediaRuleOptions0);
50
- engine.addStyleRule(".c", {
51
- style: {
52
- ...style0,
53
- color: { type: "keyword", value: "red" },
54
- },
55
- breakpoint: "0",
56
- });
57
- expect(engine.cssText).toMatchInlineSnapshot(`
58
- "@media all and (min-width: 0px) {
59
- .c { display: block; color: red }
60
- }"
61
- `);
62
- });
63
- test("hyphenate property", () => {
64
- engine.addMediaRule(mediaId, mediaRuleOptions0);
65
- engine.addStyleRule(".c", {
66
- style: {
67
- backgroundColor: { type: "keyword", value: "red" },
68
- },
69
- breakpoint: "0",
70
- });
71
- expect(engine.cssText).toMatchInlineSnapshot(`
72
- "@media all and (min-width: 0px) {
73
- .c { background-color: red }
74
- }"
75
- `);
76
- });
77
- test("add rule", () => {
78
- engine.addMediaRule(mediaId, mediaRuleOptions0);
79
- const rule1 = engine.addStyleRule(".c", {
80
- style: {
81
- ...style0,
82
- color: { type: "keyword", value: "red" },
83
- },
84
- breakpoint: "0",
85
- });
86
- expect(engine.cssText).toMatchInlineSnapshot(`
87
- "@media all and (min-width: 0px) {
88
- .c { display: block; color: red }
89
- }"
90
- `);
91
- expect(rule1.cssText).toMatchInlineSnapshot(`".c { display: block; color: red }"`);
92
- engine.addStyleRule(".c2", {
93
- style: {
94
- ...style0,
95
- color: { type: "keyword", value: "green" },
96
- },
97
- breakpoint: "0",
98
- });
99
- expect(engine.cssText).toMatchInlineSnapshot(`
100
- "@media all and (min-width: 0px) {
101
- .c { display: block; color: red }
102
- .c2 { display: block; color: green }
103
- }"
104
- `);
105
- });
106
- test("update rule", () => {
107
- engine.addMediaRule(mediaId, mediaRuleOptions0);
108
- const rule = engine.addStyleRule(".c", {
109
- style: {
110
- ...style0,
111
- color: { type: "keyword", value: "red" },
112
- },
113
- breakpoint: "0",
114
- });
115
- expect(engine.cssText).toMatchInlineSnapshot(`
116
- "@media all and (min-width: 0px) {
117
- .c { display: block; color: red }
118
- }"
119
- `);
120
- expect(rule.cssText).toMatchInlineSnapshot(`".c { display: block; color: red }"`);
121
- rule.styleMap.set("color", { type: "keyword", value: "green" });
122
- expect(rule.cssText).toMatchInlineSnapshot(`".c { display: block; color: green }"`);
123
- expect(engine.cssText).toMatchInlineSnapshot(`
124
- "@media all and (min-width: 0px) {
125
- .c { display: block; color: green }
126
- }"
127
- `);
128
- });
129
- test("don't override media queries", () => {
130
- engine.addMediaRule(mediaId, mediaRuleOptions0);
131
- engine.addStyleRule(".c", {
132
- style: style0,
133
- breakpoint: "0",
134
- });
135
- expect(engine.cssText).toMatchInlineSnapshot(`
136
- "@media all and (min-width: 0px) {
137
- .c { display: block }
138
- }"
139
- `);
140
- engine.addMediaRule(mediaId, mediaRuleOptions0);
141
- expect(engine.cssText).toMatchInlineSnapshot(`
142
- "@media all and (min-width: 0px) {
143
- .c { display: block }
144
- }"
145
- `);
146
- });
147
- test("plaintext rule", () => {
148
- engine.addPlaintextRule(".c { color: red }");
149
- expect(engine.cssText).toMatchInlineSnapshot(`".c { color: red }"`);
150
- });
151
- test("plaintext - no duplicates", () => {
152
- engine.addPlaintextRule(".c { color: red }");
153
- engine.addPlaintextRule(".c { color: red }");
154
- engine.addPlaintextRule(".c { color: green }");
155
- expect(engine.cssText).toMatchInlineSnapshot(`
156
- ".c { color: red }
157
- .c { color: green }"
158
- `);
159
- });
160
- test("font family rule", () => {
161
- engine.addFontFaceRule({
162
- fontFamily: "Roboto",
163
- fontStyle: "normal",
164
- fontWeight: 400,
165
- fontDisplay: "swap",
166
- src: "url(/src)",
167
- });
168
- expect(engine.cssText).toMatchInlineSnapshot(`
169
- "@font-face {
170
- font-family: Roboto; font-style: normal; font-weight: 400; font-display: swap; src: url(/src);
171
- }"
172
- `);
173
- });
174
- test("clear", () => {
175
- engine.addStyleRule(".c", {
176
- style: style0,
177
- breakpoint: "0",
178
- });
179
- engine.clear();
180
- expect(engine.cssText).toMatchInlineSnapshot(`""`);
181
- });
182
- });
@@ -1,5 +0,0 @@
1
- export { CssEngine } from "./css-engine";
2
- export type { AnyRule, StyleRule, MediaRule, PlaintextRule, FontFaceRule, } from "./rules";
3
- export * from "./create-css-engine";
4
- export * from "./to-value";
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,YAAY,EACV,OAAO,EACP,SAAS,EACT,SAAS,EACT,aAAa,EACb,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC"}
@@ -1,48 +0,0 @@
1
- import type { Style, StyleProperty, StyleValue } from "@webstudio-is/css-data";
2
- declare class StylePropertyMap {
3
- #private;
4
- onChange?: () => void;
5
- set(property: StyleProperty, value?: StyleValue): void;
6
- clear(): void;
7
- toString(): string;
8
- }
9
- export declare class StyleRule {
10
- #private;
11
- styleMap: StylePropertyMap;
12
- selectorText: string;
13
- onChange?: () => void;
14
- constructor(selectorText: string, style: Style);
15
- get cssText(): string;
16
- }
17
- export declare type MediaRuleOptions = {
18
- minWidth?: number;
19
- maxWidth?: number;
20
- mediaType?: "all" | "screen" | "print";
21
- };
22
- export declare class MediaRule {
23
- #private;
24
- rules: Array<StyleRule | PlaintextRule>;
25
- constructor(options?: MediaRuleOptions);
26
- insertRule(rule: StyleRule | PlaintextRule): StyleRule | PlaintextRule;
27
- get cssText(): string;
28
- }
29
- export declare class PlaintextRule {
30
- cssText: string;
31
- styleMap: Map<any, any>;
32
- constructor(cssText: string);
33
- }
34
- export declare type FontFaceOptions = {
35
- fontFamily: string;
36
- fontStyle: "normal" | "italic" | "oblique";
37
- fontWeight: number;
38
- fontDisplay: "swap" | "auto" | "block" | "fallback" | "optional";
39
- src: string;
40
- };
41
- export declare class FontFaceRule {
42
- #private;
43
- constructor(options: FontFaceOptions);
44
- get cssText(): string;
45
- }
46
- export declare type AnyRule = StyleRule | MediaRule | PlaintextRule | FontFaceRule;
47
- export {};
48
- //# sourceMappingURL=rules.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/core/rules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAI/E,cAAM,gBAAgB;;IAIpB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,GAAG,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,CAAC,EAAE,UAAU;IAK/C,KAAK;IAKL,QAAQ;CAaT;AAED,qBAAa,SAAS;;IACpB,QAAQ,mBAAC;IACT,YAAY,SAAC;IACb,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;gBACV,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;IAY9C,IAAI,OAAO,WAEV;CACF;AAED,oBAAY,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;CACxC,CAAC;AAEF,qBAAa,SAAS;;IAEpB,KAAK,EAAE,KAAK,CAAC,SAAS,GAAG,aAAa,CAAC,CAAM;gBAEjC,OAAO,GAAE,gBAAqB;IAI1C,UAAU,CAAC,IAAI,EAAE,SAAS,GAAG,aAAa;IAI1C,IAAI,OAAO,WAcV;CACF;AAED,qBAAa,aAAa;IACxB,OAAO,SAAC;IACR,QAAQ,gBAAa;gBACT,OAAO,EAAE,MAAM;CAG5B;AAED,oBAAY,eAAe,GAAG;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC;IACjE,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,qBAAa,YAAY;;gBAEX,OAAO,EAAE,eAAe;IAGpC,IAAI,OAAO,WAIV;CACF;AAED,oBAAY,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,aAAa,GAAG,YAAY,CAAC"}
@@ -1,8 +0,0 @@
1
- export declare class StyleElement {
2
- #private;
3
- get isMounted(): boolean;
4
- mount(): void;
5
- unmount(): void;
6
- render(cssText: string): void;
7
- }
8
- //# sourceMappingURL=style-element.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"style-element.d.ts","sourceRoot":"","sources":["../../src/core/style-element.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAY;;IAEvB,IAAI,SAAS,YAEZ;IACD,KAAK;IAOL,OAAO;IAMP,MAAM,CAAC,OAAO,EAAE,MAAM;CAKvB"}
@@ -1,7 +0,0 @@
1
- import { StyleElement } from "./style-element";
2
- export declare class StyleSheet {
3
- #private;
4
- constructor(element: StyleElement);
5
- replaceSync(cssText: string): void;
6
- }
7
- //# sourceMappingURL=style-sheet.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"style-sheet.d.ts","sourceRoot":"","sources":["../../src/core/style-sheet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,qBAAa,UAAU;;gBAGT,OAAO,EAAE,YAAY;IAGjC,WAAW,CAAC,OAAO,EAAE,MAAM;CAM5B"}
@@ -1,7 +0,0 @@
1
- import type { StyleValue } from "@webstudio-is/css-data";
2
- declare type ToCssOptions = {
3
- withFallback: boolean;
4
- };
5
- export declare const toValue: (value?: StyleValue, options?: ToCssOptions) => string;
6
- export {};
7
- //# sourceMappingURL=to-value.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"to-value.d.ts","sourceRoot":"","sources":["../../src/core/to-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD,aAAK,YAAY,GAAG;IAClB,YAAY,EAAE,OAAO,CAAC;CACvB,CAAC;AAMF,eAAO,MAAM,OAAO,WACV,UAAU,YACT,YAAY,KACpB,MA0BF,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=to-value.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"to-value.test.d.ts","sourceRoot":"","sources":["../../src/core/to-value.test.ts"],"names":[],"mappings":""}
@@ -1,55 +0,0 @@
1
- import { toValue } from "./to-value";
2
- describe("Convert WS CSS Values to native CSS strings", () => {
3
- test("keyword", () => {
4
- const value = toValue({ type: "keyword", value: "red" });
5
- expect(value).toBe("red");
6
- });
7
- test("unit", () => {
8
- const value = toValue({ type: "unit", value: 10, unit: "px" });
9
- expect(value).toBe("10px");
10
- });
11
- test("invalid", () => {
12
- const value = toValue({ type: "invalid", value: "bad" });
13
- expect(value).toBe("bad");
14
- });
15
- test("unset", () => {
16
- const value = toValue({ type: "unset", value: "" });
17
- expect(value).toBe("");
18
- });
19
- test("var", () => {
20
- const value = toValue({ type: "var", value: "namespace", fallbacks: [] });
21
- expect(value).toBe("var(--namespace)");
22
- });
23
- test("var with fallbacks", () => {
24
- const value = toValue({
25
- type: "var",
26
- value: "namespace",
27
- fallbacks: [
28
- {
29
- type: "keyword",
30
- value: "normal",
31
- },
32
- {
33
- type: "unit",
34
- value: 10,
35
- unit: "px",
36
- },
37
- ],
38
- });
39
- expect(value).toBe("var(--namespace, normal, 10px)");
40
- });
41
- test("fontFamily", () => {
42
- const value = toValue({
43
- type: "fontFamily",
44
- value: ["Courier New"],
45
- });
46
- expect(value).toBe("Courier New, monospace");
47
- });
48
- test("withFallback=false", () => {
49
- const value = toValue({
50
- type: "fontFamily",
51
- value: ["Courier New"],
52
- }, { withFallback: false });
53
- expect(value).toBe("Courier New");
54
- });
55
- });
package/lib/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./core";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}