@styleframe/transpiler 1.0.0 → 1.0.2
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/.tsbuildinfo +1 -1
- package/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/package.json +8 -4
- package/src/consume/at-rule.test.ts +2 -2
- package/src/consume/consume.test.ts +21 -21
- package/src/consume/consume.ts +36 -15
- package/src/consume/container.test.ts +2 -2
- package/src/consume/css.test.ts +21 -18
- package/src/consume/css.ts +1 -1
- package/src/consume/declarations.test.ts +2 -2
- package/src/consume/primitive.test.ts +2 -2
- package/src/consume/ref.test.ts +2 -2
- package/src/consume/root.test.ts +2 -2
- package/src/consume/selector.test.ts +2 -2
- package/src/consume/theme.test.ts +2 -2
- package/src/consume/utility.test.ts +2 -2
- package/src/consume/variable.test.ts +2 -2
- package/src/transpile.test.ts +7 -3
- package/src/transpile.ts +18 -5
- package/src/types.ts +8 -0
- package/tsconfig.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @styleframe/transpiler
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#30](https://github.com/styleframe-dev/styleframe/pull/30) [`68cd004`](https://github.com/styleframe-dev/styleframe/commit/68cd004b04395797876b5e805c0b910d6b665f35) Thanks [@alexgrozav](https://github.com/alexgrozav)! - feat: Add support for custom transpile functions
|
|
8
|
+
refactor: Separate CSS and TS transpilation
|
|
9
|
+
|
|
10
|
+
## 1.0.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Update README.md
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
- @styleframe/core@1.0.1
|
|
17
|
+
|
|
3
18
|
## 1.0.0
|
|
4
19
|
|
|
5
20
|
### Major Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alex Grozav
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@styleframe/transpiler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/transpiler.d.ts",
|
|
6
6
|
"module": "./dist/transpiler.js",
|
|
@@ -14,15 +14,16 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"scule": "^1.3.0",
|
|
17
|
-
"@styleframe/core": "^1.0.
|
|
17
|
+
"@styleframe/core": "^1.0.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
20
21
|
"typescript": "^5.8.3",
|
|
21
22
|
"vite": "^7.0.6",
|
|
22
23
|
"vite-plugin-dts": "^4.5.4",
|
|
23
24
|
"vitest": "^3.2.4",
|
|
24
|
-
"@styleframe/config-
|
|
25
|
-
"@styleframe/config-
|
|
25
|
+
"@styleframe/config-typescript": "^1.0.1",
|
|
26
|
+
"@styleframe/config-vite": "^1.0.1"
|
|
26
27
|
},
|
|
27
28
|
"homepage": "https://github.com/styleframe-dev/styleframe#readme",
|
|
28
29
|
"bugs": {
|
|
@@ -33,6 +34,9 @@
|
|
|
33
34
|
"url": "git+https://github.com/styleframe-dev/styleframe.git"
|
|
34
35
|
},
|
|
35
36
|
"author": "Alex Grozav <alex@styleframe.dev>",
|
|
37
|
+
"overrides": {
|
|
38
|
+
"vite": "npm:rolldown-vite@latest"
|
|
39
|
+
},
|
|
36
40
|
"scripts": {
|
|
37
41
|
"dev": "vite build --watch",
|
|
38
42
|
"build": "pnpm typecheck && vite build",
|
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
createRoot,
|
|
6
6
|
} from "@styleframe/core";
|
|
7
7
|
import { createAtRuleConsumer } from "./at-rule";
|
|
8
|
-
import {
|
|
8
|
+
import { consumeCSS } from "./consume";
|
|
9
9
|
|
|
10
10
|
describe("createAtRuleConsumer", () => {
|
|
11
11
|
let root: Root;
|
|
12
12
|
let atRule: ReturnType<typeof createAtRuleFunction>;
|
|
13
13
|
let ref: ReturnType<typeof createRefFunction>;
|
|
14
14
|
|
|
15
|
-
const consumeAtRule = createAtRuleConsumer(
|
|
15
|
+
const consumeAtRule = createAtRuleConsumer(consumeCSS);
|
|
16
16
|
const options: StyleframeOptions = {};
|
|
17
17
|
|
|
18
18
|
beforeEach(() => {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
createVariableFunction,
|
|
11
11
|
isUtility,
|
|
12
12
|
} from "@styleframe/core";
|
|
13
|
-
import {
|
|
13
|
+
import { consumeCSS } from "./consume";
|
|
14
14
|
|
|
15
15
|
describe("consume", () => {
|
|
16
16
|
let root: Root;
|
|
@@ -37,21 +37,21 @@ describe("consume", () => {
|
|
|
37
37
|
|
|
38
38
|
it("should consume a variable instance", () => {
|
|
39
39
|
const colorVar = variable("primary-color", "#006cff");
|
|
40
|
-
const result =
|
|
40
|
+
const result = consumeCSS(colorVar, options);
|
|
41
41
|
|
|
42
42
|
expect(result).toBe("--primary-color: #006cff;");
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
it("should consume a reference instance", () => {
|
|
46
46
|
const colorRef = ref("primary-color");
|
|
47
|
-
const result =
|
|
47
|
+
const result = consumeCSS(colorRef, options);
|
|
48
48
|
|
|
49
49
|
expect(result).toBe("var(--primary-color)");
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
it("should consume a CSS instance", () => {
|
|
53
53
|
const cssValue = css`16px solid #000`;
|
|
54
|
-
const result =
|
|
54
|
+
const result = consumeCSS(cssValue, options);
|
|
55
55
|
|
|
56
56
|
expect(result).toBe("16px solid #000");
|
|
57
57
|
});
|
|
@@ -62,7 +62,7 @@ describe("consume", () => {
|
|
|
62
62
|
backgroundColor: "#006cff",
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
const result =
|
|
65
|
+
const result = consumeCSS(buttonSelector, options);
|
|
66
66
|
|
|
67
67
|
expect(result).toEqual(`.button {
|
|
68
68
|
\tpadding: 0.5rem 1rem;
|
|
@@ -76,7 +76,7 @@ describe("consume", () => {
|
|
|
76
76
|
v("text-color", "#000000");
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
const result =
|
|
79
|
+
const result = consumeCSS(lightTheme, options);
|
|
80
80
|
|
|
81
81
|
expect(result).toEqual(`[data-theme="light"] {
|
|
82
82
|
\t--background-color: #ffffff;
|
|
@@ -89,7 +89,7 @@ describe("consume", () => {
|
|
|
89
89
|
fontSize: "18px",
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
-
const result =
|
|
92
|
+
const result = consumeCSS(mediaRule, options);
|
|
93
93
|
|
|
94
94
|
expect(result).toEqual(`@media (min-width: 768px) {
|
|
95
95
|
\tfont-size: 18px;
|
|
@@ -109,7 +109,7 @@ describe("consume", () => {
|
|
|
109
109
|
const marginUtility = root.children.find(
|
|
110
110
|
(u) => isUtility(u) && u.name === "margin",
|
|
111
111
|
);
|
|
112
|
-
const result =
|
|
112
|
+
const result = consumeCSS(marginUtility, options);
|
|
113
113
|
|
|
114
114
|
expect(result).toEqual(`._margin\\:sm {
|
|
115
115
|
\tmargin: 8px;
|
|
@@ -117,12 +117,12 @@ describe("consume", () => {
|
|
|
117
117
|
});
|
|
118
118
|
|
|
119
119
|
it("should consume primitive values", () => {
|
|
120
|
-
expect(
|
|
121
|
-
expect(
|
|
122
|
-
expect(
|
|
123
|
-
expect(
|
|
124
|
-
expect(
|
|
125
|
-
expect(
|
|
120
|
+
expect(consumeCSS("test string", options)).toBe("test string");
|
|
121
|
+
expect(consumeCSS(42, options)).toBe("42");
|
|
122
|
+
expect(consumeCSS(true, options)).toBe("true");
|
|
123
|
+
expect(consumeCSS(false, options)).toBe("false");
|
|
124
|
+
expect(consumeCSS(null, options)).toBe("");
|
|
125
|
+
expect(consumeCSS(undefined, options)).toBe("");
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
it("should consume complex nested structures", () => {
|
|
@@ -163,7 +163,7 @@ describe("consume", () => {
|
|
|
163
163
|
});
|
|
164
164
|
});
|
|
165
165
|
|
|
166
|
-
const result =
|
|
166
|
+
const result = consumeCSS(root, options);
|
|
167
167
|
const expected = `:root {
|
|
168
168
|
\t--card-bg: #ffffff;
|
|
169
169
|
\t--card-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
@@ -220,9 +220,9 @@ describe("consume", () => {
|
|
|
220
220
|
});
|
|
221
221
|
});
|
|
222
222
|
|
|
223
|
-
const selectorResult =
|
|
224
|
-
const cssResult =
|
|
225
|
-
const themeResult =
|
|
223
|
+
const selectorResult = consumeCSS(buttonSelector, options);
|
|
224
|
+
const cssResult = consumeCSS(borderStyle, options);
|
|
225
|
+
const themeResult = consumeCSS(brandTheme, options);
|
|
226
226
|
|
|
227
227
|
expect(selectorResult).toEqual(`.button {
|
|
228
228
|
\tbackground-color: var(--brand-color);
|
|
@@ -245,9 +245,9 @@ describe("consume", () => {
|
|
|
245
245
|
color: colorRef,
|
|
246
246
|
});
|
|
247
247
|
|
|
248
|
-
const varResult =
|
|
249
|
-
const refResult =
|
|
250
|
-
const selectorResult =
|
|
248
|
+
const varResult = consumeCSS(colorVar, prefixOptions);
|
|
249
|
+
const refResult = consumeCSS(colorRef, prefixOptions);
|
|
250
|
+
const selectorResult = consumeCSS(buttonSelector, prefixOptions);
|
|
251
251
|
|
|
252
252
|
expect(varResult).toBe("--app-primary: #006cff;");
|
|
253
253
|
expect(refResult).toBe("var(--app-secondary)");
|
package/src/consume/consume.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
isVariable,
|
|
11
11
|
} from "@styleframe/core";
|
|
12
12
|
import { createAtRuleConsumer } from "./at-rule";
|
|
13
|
-
import {
|
|
13
|
+
import { createCSSTemplateLiteralConsumer } from "./css";
|
|
14
14
|
import { createPrimitiveConsumer } from "./primitive";
|
|
15
15
|
import { createRefConsumer } from "./ref";
|
|
16
16
|
import { createRootConsumer } from "./root";
|
|
@@ -22,17 +22,21 @@ import { createVariableConsumer } from "./variable";
|
|
|
22
22
|
/**
|
|
23
23
|
* Consumes any token instance and returns the CSS string representation
|
|
24
24
|
*/
|
|
25
|
-
export function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
25
|
+
export function consumeCSS(
|
|
26
|
+
instance: unknown,
|
|
27
|
+
options: StyleframeOptions,
|
|
28
|
+
): string {
|
|
29
|
+
const consumeRoot = createRootConsumer(consumeCSS);
|
|
30
|
+
const consumeSelector = createSelectorConsumer(consumeCSS);
|
|
31
|
+
const consumeUtility = createUtilityConsumer(consumeCSS);
|
|
32
|
+
const consumeAtRule = createAtRuleConsumer(consumeCSS);
|
|
30
33
|
// const consumeRecipe = createRecipeConsumer(consume);
|
|
31
|
-
const consumeTheme = createThemeConsumer(
|
|
32
|
-
const consumeVariable = createVariableConsumer(
|
|
33
|
-
const consumeRef = createRefConsumer(
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
const consumeTheme = createThemeConsumer(consumeCSS);
|
|
35
|
+
const consumeVariable = createVariableConsumer(consumeCSS);
|
|
36
|
+
const consumeRef = createRefConsumer(consumeCSS);
|
|
37
|
+
const consumeCSSTemplateLiteral =
|
|
38
|
+
createCSSTemplateLiteralConsumer(consumeCSS);
|
|
39
|
+
const consumePrimitive = createPrimitiveConsumer(consumeCSS);
|
|
36
40
|
|
|
37
41
|
switch (true) {
|
|
38
42
|
case isSelector(instance):
|
|
@@ -41,9 +45,6 @@ export function consume(instance: unknown, options: StyleframeOptions): string {
|
|
|
41
45
|
return consumeUtility(instance, options);
|
|
42
46
|
case isAtRule(instance):
|
|
43
47
|
return consumeAtRule(instance, options);
|
|
44
|
-
// case isRecipe(instance):
|
|
45
|
-
// return consumeRecipe(instance, options);
|
|
46
|
-
// break;
|
|
47
48
|
case isRoot(instance):
|
|
48
49
|
return consumeRoot(instance, options);
|
|
49
50
|
case isTheme(instance):
|
|
@@ -53,8 +54,28 @@ export function consume(instance: unknown, options: StyleframeOptions): string {
|
|
|
53
54
|
case isRef(instance):
|
|
54
55
|
return consumeRef(instance, options);
|
|
55
56
|
case isCSS(instance):
|
|
56
|
-
return
|
|
57
|
+
return consumeCSSTemplateLiteral(instance, options);
|
|
57
58
|
default:
|
|
58
59
|
return consumePrimitive(instance, options);
|
|
59
60
|
}
|
|
60
61
|
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Consumes any token instance and returns the TS string representation
|
|
65
|
+
*/
|
|
66
|
+
export function consumeTS(
|
|
67
|
+
instance: unknown,
|
|
68
|
+
options: StyleframeOptions,
|
|
69
|
+
): string {
|
|
70
|
+
// const consumeRecipe = createRecipeConsumer(consumeTS);
|
|
71
|
+
|
|
72
|
+
switch (true) {
|
|
73
|
+
case Array.isArray(instance):
|
|
74
|
+
return instance.map((item) => consumeTS(item, options)).join("\n");
|
|
75
|
+
// case isRecipe(instance):
|
|
76
|
+
// return consumeRecipe(instance, options);
|
|
77
|
+
// break;
|
|
78
|
+
default:
|
|
79
|
+
return "";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
createVariableFunction,
|
|
11
11
|
} from "@styleframe/core";
|
|
12
12
|
import { createContainerConsumer } from "./container";
|
|
13
|
-
import {
|
|
13
|
+
import { consumeCSS } from "./consume";
|
|
14
14
|
|
|
15
15
|
describe("createContainerConsumer", () => {
|
|
16
16
|
let root: Root;
|
|
@@ -18,7 +18,7 @@ describe("createContainerConsumer", () => {
|
|
|
18
18
|
let ref: ReturnType<typeof createRefFunction>;
|
|
19
19
|
let selector: ReturnType<typeof createSelectorFunction>;
|
|
20
20
|
|
|
21
|
-
const consumeContainer = createContainerConsumer(
|
|
21
|
+
const consumeContainer = createContainerConsumer(consumeCSS);
|
|
22
22
|
const options: StyleframeOptions = {};
|
|
23
23
|
|
|
24
24
|
beforeEach(() => {
|
package/src/consume/css.test.ts
CHANGED
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
createRoot,
|
|
6
6
|
createVariableFunction,
|
|
7
7
|
} from "@styleframe/core";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { createCSSTemplateLiteralConsumer } from "./css";
|
|
9
|
+
import { consumeCSS } from "./consume";
|
|
10
10
|
|
|
11
11
|
describe("createCSSConsumer", () => {
|
|
12
12
|
let root: Root;
|
|
@@ -14,7 +14,8 @@ describe("createCSSConsumer", () => {
|
|
|
14
14
|
let variable: ReturnType<typeof createVariableFunction>;
|
|
15
15
|
let ref: ReturnType<typeof createRefFunction>;
|
|
16
16
|
|
|
17
|
-
const
|
|
17
|
+
const consumeCSSTemplateLiteral =
|
|
18
|
+
createCSSTemplateLiteralConsumer(consumeCSS);
|
|
18
19
|
const options: StyleframeOptions = {};
|
|
19
20
|
|
|
20
21
|
beforeEach(() => {
|
|
@@ -26,7 +27,7 @@ describe("createCSSConsumer", () => {
|
|
|
26
27
|
|
|
27
28
|
it("should process a simple CSS value", () => {
|
|
28
29
|
const cssValue = css`16px`;
|
|
29
|
-
expect(
|
|
30
|
+
expect(consumeCSSTemplateLiteral(cssValue, options)).toBe("16px");
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
it("should handle CSS values with variable references", () => {
|
|
@@ -35,14 +36,14 @@ describe("createCSSConsumer", () => {
|
|
|
35
36
|
${ref(spacingVar)} calc(${ref(spacingVar)} * 2)
|
|
36
37
|
`;
|
|
37
38
|
|
|
38
|
-
expect(
|
|
39
|
+
expect(consumeCSSTemplateLiteral(paddingValue, options)).toBe(
|
|
39
40
|
"var(--spacing-md) calc(var(--spacing-md) * 2)",
|
|
40
41
|
);
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
it("should handle empty CSS values", () => {
|
|
44
45
|
const emptyCss = css``;
|
|
45
|
-
expect(
|
|
46
|
+
expect(consumeCSSTemplateLiteral(emptyCss, options)).toBe("");
|
|
46
47
|
});
|
|
47
48
|
|
|
48
49
|
it("should respect prefix in options if provided", () => {
|
|
@@ -57,7 +58,7 @@ describe("createCSSConsumer", () => {
|
|
|
57
58
|
${ref(colorVar)}
|
|
58
59
|
`;
|
|
59
60
|
|
|
60
|
-
expect(
|
|
61
|
+
expect(consumeCSSTemplateLiteral(colorValue, prefixOptions)).toBe(
|
|
61
62
|
"var(--sf-color-primary)",
|
|
62
63
|
);
|
|
63
64
|
});
|
|
@@ -68,7 +69,7 @@ describe("createCSSConsumer", () => {
|
|
|
68
69
|
${zIndex}
|
|
69
70
|
`;
|
|
70
71
|
|
|
71
|
-
expect(
|
|
72
|
+
expect(consumeCSSTemplateLiteral(zIndexValue, options)).toBe("100");
|
|
72
73
|
});
|
|
73
74
|
|
|
74
75
|
it("should handle CSS values with string interpolations", () => {
|
|
@@ -79,14 +80,16 @@ describe("createCSSConsumer", () => {
|
|
|
79
80
|
${borderWidth} ${borderStyle} ${borderColor}
|
|
80
81
|
`;
|
|
81
82
|
|
|
82
|
-
expect(
|
|
83
|
+
expect(consumeCSSTemplateLiteral(borderValue, options)).toBe(
|
|
84
|
+
"2px solid #000",
|
|
85
|
+
);
|
|
83
86
|
});
|
|
84
87
|
|
|
85
88
|
it("should handle CSS values with array interpolations", () => {
|
|
86
89
|
const gridAreas = ["header", "main", "footer"];
|
|
87
90
|
const gridTemplateValue = css`"${gridAreas[0]}" "${gridAreas[1]}" "${gridAreas[2]}"`;
|
|
88
91
|
|
|
89
|
-
expect(
|
|
92
|
+
expect(consumeCSSTemplateLiteral(gridTemplateValue, options)).toBe(
|
|
90
93
|
'"header" "main" "footer"',
|
|
91
94
|
);
|
|
92
95
|
});
|
|
@@ -100,7 +103,7 @@ describe("createCSSConsumer", () => {
|
|
|
100
103
|
${ref(fontSize)}/${ref(lineHeight)} ${ref(fontFamily)}
|
|
101
104
|
`;
|
|
102
105
|
|
|
103
|
-
expect(
|
|
106
|
+
expect(consumeCSSTemplateLiteral(fontValue, options)).toBe(
|
|
104
107
|
"var(--font-size-base)/var(--line-height-normal) var(--font-family-sans)",
|
|
105
108
|
);
|
|
106
109
|
});
|
|
@@ -109,7 +112,7 @@ describe("createCSSConsumer", () => {
|
|
|
109
112
|
const spacing = variable("spacing", "8px");
|
|
110
113
|
const calcValue = css`calc(100% - ${ref(spacing)} * 2)`;
|
|
111
114
|
|
|
112
|
-
expect(
|
|
115
|
+
expect(consumeCSSTemplateLiteral(calcValue, options)).toBe(
|
|
113
116
|
"calc(100% - var(--spacing) * 2)",
|
|
114
117
|
);
|
|
115
118
|
});
|
|
@@ -118,7 +121,7 @@ describe("createCSSConsumer", () => {
|
|
|
118
121
|
const primaryColor = variable("color-primary", "#006cff");
|
|
119
122
|
const colorValue = css`rgba(${ref(primaryColor)}, 0.5)`;
|
|
120
123
|
|
|
121
|
-
expect(
|
|
124
|
+
expect(consumeCSSTemplateLiteral(colorValue, options)).toBe(
|
|
122
125
|
"rgba(var(--color-primary), 0.5)",
|
|
123
126
|
);
|
|
124
127
|
});
|
|
@@ -129,7 +132,7 @@ describe("createCSSConsumer", () => {
|
|
|
129
132
|
|
|
130
133
|
const gradientValue = css`linear-gradient(135deg, ${ref(primaryColor)} 0%, ${ref(secondaryColor)} 100%)`;
|
|
131
134
|
|
|
132
|
-
expect(
|
|
135
|
+
expect(consumeCSSTemplateLiteral(gradientValue, options)).toBe(
|
|
133
136
|
"linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%)",
|
|
134
137
|
);
|
|
135
138
|
});
|
|
@@ -140,7 +143,7 @@ describe("createCSSConsumer", () => {
|
|
|
140
143
|
${isLarge ? "2rem" : "1rem"}
|
|
141
144
|
`;
|
|
142
145
|
|
|
143
|
-
expect(
|
|
146
|
+
expect(consumeCSSTemplateLiteral(conditionalValue, options)).toBe("2rem");
|
|
144
147
|
});
|
|
145
148
|
|
|
146
149
|
it("should handle CSS values with fallback references", () => {
|
|
@@ -148,7 +151,7 @@ describe("createCSSConsumer", () => {
|
|
|
148
151
|
${ref("custom-spacing", "16px")}
|
|
149
152
|
`;
|
|
150
153
|
|
|
151
|
-
expect(
|
|
154
|
+
expect(consumeCSSTemplateLiteral(spacingValue, options)).toBe(
|
|
152
155
|
"var(--custom-spacing, 16px)",
|
|
153
156
|
);
|
|
154
157
|
});
|
|
@@ -164,7 +167,7 @@ describe("createCSSConsumer", () => {
|
|
|
164
167
|
`;
|
|
165
168
|
|
|
166
169
|
// The function might normalize whitespace
|
|
167
|
-
const result =
|
|
170
|
+
const result = consumeCSSTemplateLiteral(complexValue, options);
|
|
168
171
|
expect(result).toContain("var(--spacing) solid var(--color-primary)");
|
|
169
172
|
expect(result).toContain(
|
|
170
173
|
"calc(var(--spacing) * 2) dashed var(--color-secondary)",
|
|
@@ -177,7 +180,7 @@ describe("createCSSConsumer", () => {
|
|
|
177
180
|
|
|
178
181
|
const nestedValue = css`calc(${ref(baseSize)} * ${multiplier})`;
|
|
179
182
|
|
|
180
|
-
expect(
|
|
183
|
+
expect(consumeCSSTemplateLiteral(nestedValue, options)).toBe(
|
|
181
184
|
"calc(var(--size-base) * 1.5)",
|
|
182
185
|
);
|
|
183
186
|
});
|
package/src/consume/css.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { ConsumeFunction } from "../types";
|
|
|
4
4
|
/**
|
|
5
5
|
* Consumes a CSS value, equivalent to the string body of a selector
|
|
6
6
|
*/
|
|
7
|
-
export function
|
|
7
|
+
export function createCSSTemplateLiteralConsumer(consume: ConsumeFunction) {
|
|
8
8
|
return function consumeCSS(
|
|
9
9
|
instance: CSS,
|
|
10
10
|
options: StyleframeOptions,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
createRoot,
|
|
6
6
|
createVariableFunction,
|
|
7
7
|
} from "@styleframe/core";
|
|
8
|
-
import {
|
|
8
|
+
import { consumeCSS } from "./consume";
|
|
9
9
|
import { createDeclarationsConsumer } from "./declarations";
|
|
10
10
|
|
|
11
11
|
describe("createDeclarationsConsumer", () => {
|
|
@@ -14,7 +14,7 @@ describe("createDeclarationsConsumer", () => {
|
|
|
14
14
|
let variable: ReturnType<typeof createVariableFunction>;
|
|
15
15
|
let css: ReturnType<typeof createCssFunction>;
|
|
16
16
|
|
|
17
|
-
const consumeDeclarations = createDeclarationsConsumer(
|
|
17
|
+
const consumeDeclarations = createDeclarationsConsumer(consumeCSS);
|
|
18
18
|
const options: StyleframeOptions = {};
|
|
19
19
|
|
|
20
20
|
beforeEach(() => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { StyleframeOptions } from "@styleframe/core";
|
|
2
2
|
import { createPrimitiveConsumer } from "./primitive";
|
|
3
|
-
import {
|
|
3
|
+
import { consumeCSS } from "./consume";
|
|
4
4
|
|
|
5
5
|
describe("createPrimitiveConsumer", () => {
|
|
6
|
-
const consumePrimitive = createPrimitiveConsumer(
|
|
6
|
+
const consumePrimitive = createPrimitiveConsumer(consumeCSS);
|
|
7
7
|
const options: StyleframeOptions = {};
|
|
8
8
|
|
|
9
9
|
it("should return a string representation of a number", () => {
|
package/src/consume/ref.test.ts
CHANGED
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
createVariableFunction,
|
|
6
6
|
} from "@styleframe/core";
|
|
7
7
|
import { createRefConsumer } from "./ref";
|
|
8
|
-
import {
|
|
8
|
+
import { consumeCSS } from "./consume";
|
|
9
9
|
|
|
10
10
|
describe("createRefConsumer", () => {
|
|
11
11
|
let root: Root;
|
|
12
12
|
let ref: ReturnType<typeof createRefFunction>;
|
|
13
13
|
let variable: ReturnType<typeof createVariableFunction>;
|
|
14
14
|
|
|
15
|
-
const consumeRef = createRefConsumer(
|
|
15
|
+
const consumeRef = createRefConsumer(consumeCSS);
|
|
16
16
|
const options: StyleframeOptions = {};
|
|
17
17
|
|
|
18
18
|
beforeEach(() => {
|
package/src/consume/root.test.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
createSelectorFunction,
|
|
6
6
|
createVariableFunction,
|
|
7
7
|
} from "@styleframe/core";
|
|
8
|
-
import {
|
|
8
|
+
import { consumeCSS } from "./consume";
|
|
9
9
|
import { createRootConsumer } from "./root";
|
|
10
10
|
|
|
11
11
|
describe("createRootConsumer", () => {
|
|
@@ -14,7 +14,7 @@ describe("createRootConsumer", () => {
|
|
|
14
14
|
let ref: ReturnType<typeof createRefFunction>;
|
|
15
15
|
let selector: ReturnType<typeof createSelectorFunction>;
|
|
16
16
|
|
|
17
|
-
const consumeRoot = createRootConsumer(
|
|
17
|
+
const consumeRoot = createRootConsumer(consumeCSS);
|
|
18
18
|
const options: StyleframeOptions = {};
|
|
19
19
|
|
|
20
20
|
beforeEach(() => {
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
isSelector,
|
|
9
9
|
} from "@styleframe/core";
|
|
10
10
|
import { createSelectorConsumer } from "./selector";
|
|
11
|
-
import {
|
|
11
|
+
import { consumeCSS } from "./consume";
|
|
12
12
|
|
|
13
13
|
describe("createSelectorConsumer", () => {
|
|
14
14
|
let root: Root;
|
|
@@ -17,7 +17,7 @@ describe("createSelectorConsumer", () => {
|
|
|
17
17
|
let selector: ReturnType<typeof createSelectorFunction>;
|
|
18
18
|
let css: ReturnType<typeof createCssFunction>;
|
|
19
19
|
|
|
20
|
-
const consumeSelector = createSelectorConsumer(
|
|
20
|
+
const consumeSelector = createSelectorConsumer(consumeCSS);
|
|
21
21
|
const options: StyleframeOptions = {};
|
|
22
22
|
|
|
23
23
|
beforeEach(() => {
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
createThemeFunction,
|
|
7
7
|
createVariableFunction,
|
|
8
8
|
} from "@styleframe/core";
|
|
9
|
-
import {
|
|
9
|
+
import { consumeCSS } from "./consume";
|
|
10
10
|
import { createThemeConsumer } from "./theme";
|
|
11
11
|
|
|
12
12
|
describe("createThemeConsumer", () => {
|
|
@@ -16,7 +16,7 @@ describe("createThemeConsumer", () => {
|
|
|
16
16
|
let ref: ReturnType<typeof createRefFunction>;
|
|
17
17
|
let css: ReturnType<typeof createCssFunction>;
|
|
18
18
|
|
|
19
|
-
const consumeTheme = createThemeConsumer(
|
|
19
|
+
const consumeTheme = createThemeConsumer(consumeCSS);
|
|
20
20
|
const options: StyleframeOptions = {};
|
|
21
21
|
|
|
22
22
|
beforeEach(() => {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
createUtilityFunction,
|
|
11
11
|
isUtility,
|
|
12
12
|
} from "@styleframe/core";
|
|
13
|
-
import {
|
|
13
|
+
import { consumeCSS } from "./consume";
|
|
14
14
|
import { createUtilityConsumer } from "./utility";
|
|
15
15
|
|
|
16
16
|
describe("createUtilityConsumer", () => {
|
|
@@ -19,7 +19,7 @@ describe("createUtilityConsumer", () => {
|
|
|
19
19
|
let utility: ReturnType<typeof createUtilityFunction>;
|
|
20
20
|
let modifier: ReturnType<typeof createModifierFunction>;
|
|
21
21
|
|
|
22
|
-
const consumeUtility = createUtilityConsumer(
|
|
22
|
+
const consumeUtility = createUtilityConsumer(consumeCSS);
|
|
23
23
|
const options: StyleframeOptions = {};
|
|
24
24
|
|
|
25
25
|
beforeEach(() => {
|
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
createVariableFunction,
|
|
6
6
|
} from "@styleframe/core";
|
|
7
7
|
import { createVariableConsumer } from "./variable";
|
|
8
|
-
import {
|
|
8
|
+
import { consumeCSS } from "./consume";
|
|
9
9
|
|
|
10
10
|
describe("createVariableConsumer", () => {
|
|
11
11
|
let root: Root;
|
|
12
12
|
let variable: ReturnType<typeof createVariableFunction>;
|
|
13
13
|
let ref: ReturnType<typeof createRefFunction>;
|
|
14
14
|
|
|
15
|
-
const consumeVariable = createVariableConsumer(
|
|
15
|
+
const consumeVariable = createVariableConsumer(consumeCSS);
|
|
16
16
|
const options: StyleframeOptions = {};
|
|
17
17
|
|
|
18
18
|
beforeEach(() => {
|
package/src/transpile.test.ts
CHANGED
|
@@ -62,9 +62,11 @@ describe("transpile", () => {
|
|
|
62
62
|
it("should transpile an empty Styleframe instance", () => {
|
|
63
63
|
const output = transpile(instance);
|
|
64
64
|
|
|
65
|
-
expect(output.files).toHaveLength(
|
|
65
|
+
expect(output.files).toHaveLength(2);
|
|
66
66
|
expect(output.files[0]!.name).toBe("index.css");
|
|
67
67
|
expect(output.files[0]!.content).toEqual("");
|
|
68
|
+
expect(output.files[1]!.name).toBe("index.ts");
|
|
69
|
+
expect(output.files[1]!.content).toEqual("");
|
|
68
70
|
});
|
|
69
71
|
|
|
70
72
|
it("should transpile a simple variable", () => {
|
|
@@ -72,11 +74,13 @@ describe("transpile", () => {
|
|
|
72
74
|
|
|
73
75
|
const output = transpile(instance);
|
|
74
76
|
|
|
75
|
-
expect(output.files).toHaveLength(
|
|
77
|
+
expect(output.files).toHaveLength(2);
|
|
76
78
|
expect(output.files[0]!.name).toBe("index.css");
|
|
77
79
|
expect(output.files[0]!.content).toEqual(`:root {
|
|
78
80
|
\t--primary-color: #006cff;
|
|
79
81
|
}`);
|
|
82
|
+
expect(output.files[1]!.name).toBe("index.ts");
|
|
83
|
+
expect(output.files[1]!.content).toEqual("");
|
|
80
84
|
});
|
|
81
85
|
|
|
82
86
|
it("should transpile multiple variables", () => {
|
|
@@ -522,7 +526,7 @@ describe("transpile", () => {
|
|
|
522
526
|
// Transpile the complex scenario
|
|
523
527
|
const output = transpile(instance);
|
|
524
528
|
|
|
525
|
-
expect(output.files).toHaveLength(
|
|
529
|
+
expect(output.files).toHaveLength(2);
|
|
526
530
|
expect(output.files[0]!.name).toBe("index.css");
|
|
527
531
|
|
|
528
532
|
const content = output.files[0]!.content;
|