Skip to content

Commit faa1d31

Browse files
committed
feat: parse additional color spaces
1 parent 4a2c805 commit faa1d31

File tree

14 files changed

+364
-76
lines changed

14 files changed

+364
-76
lines changed

.config/cspell.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"xcworkspace"
1111
],
1212
"words": [
13+
"colorjs",
1314
"prebuild"
1415
]
15-
}
16+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
"!**/__mocks__"
112112
],
113113
"dependencies": {
114+
"colorjs.io": "^0.5.2",
114115
"comment-json": "^4.2.5",
115116
"debug": "^4.4.1"
116117
},

src/compiler/__tests__/compiler.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
import { compile } from "../compiler";
22

3+
test("reads global CSS variables", () => {
4+
const compiled = compile(`
5+
@react-native {
6+
preserve-variables: true
7+
}
8+
9+
@layer theme {
10+
:root, :host {
11+
--color-red-500: oklch(63.7% 0.237 25.331);
12+
}
13+
}`);
14+
15+
expect(compiled).toStrictEqual({
16+
vr: [["color-red-500", "oklch(63.7% 0.237 25.331)"]],
17+
});
18+
});
19+
320
test.skip("test compiler", () => {
421
const compiled = compile(`
522
.test {

src/compiler/compiler.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ export function compile(
105105
filename: "style.css", // This is ignored, but required
106106
code: typeof code === "string" ? new TextEncoder().encode(code) : code,
107107
visitor: {
108+
Rule(rule) {
109+
if (isReactNativeAtRule(rule)) {
110+
extractReactNativeOptions(rule, collection);
111+
}
112+
},
108113
Declaration(decl) {
109114
// Track variable usage, we remove any unused variables
110115
if (decl.property !== "unparsed" && decl.property !== "custom") return;
@@ -125,7 +130,6 @@ export function compile(
125130
},
126131
customAtRules: {
127132
"react-native": {
128-
prelude: "<custom-ident>+",
129133
body: "declaration-list",
130134
},
131135
},
@@ -220,11 +224,33 @@ function extractRule(
220224
}
221225
break;
222226
}
223-
case "custom": {
224-
if (isReactNativeAtRule(rule)) {
225-
extractReactNativeOptions(rule, collection);
227+
case "layer-block":
228+
for (const layerRule of rule.value.rules) {
229+
extractRule(layerRule, collection, partialStyle);
226230
}
227-
}
231+
break;
232+
case "custom":
233+
case "font-face":
234+
case "font-palette-values":
235+
case "font-feature-values":
236+
case "namespace":
237+
case "layer-statement":
238+
case "property":
239+
case "view-transition":
240+
case "ignored":
241+
case "unknown":
242+
case "import":
243+
case "page":
244+
case "supports":
245+
case "counter-style":
246+
case "moz-document":
247+
case "nesting":
248+
case "nested-declarations":
249+
case "viewport":
250+
case "custom-media":
251+
case "scope":
252+
case "starting-style":
253+
break;
228254
}
229255
}
230256

0 commit comments

Comments
 (0)