Skip to content

Commit 1df1f2d

Browse files
authored
fix: update reserved keywords (#7)
1 parent 2ef2bb1 commit 1df1f2d

File tree

6 files changed

+139
-26
lines changed

6 files changed

+139
-26
lines changed

.changeset/orange-pianos-open.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hebilicious/cssforge": patch
3+
---
4+
5+
fix: update reserved keywords

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
## Why
1111

1212
CSS forge is library that leverages modern CSS features and conventions to help you
13-
generate CSS custom properties (css variables). At the core of CSSforge is the schema : A
14-
serializable configuration object. CSSforge has 0 runtime and generate at build time raw
15-
CSS, Typescript or JSON. This intentionally keeps things simple and flexible, and allows
16-
you to integrate it with any framework or CSS workflow. CSSforge will try to integrate
17-
with design tools such as Figma, cooors etc in the future.
13+
generate CSS custom properties (css variables).
14+
15+
At the core of CSSforge is the schema : A serializable configuration object.
16+
17+
CSSforge has 0 runtime and generate at build time raw CSS, Typescript or JSON.
18+
19+
This intentionally keeps things simple and flexible, and allows you to integrate it with
20+
any framework or CSS workflow.
21+
22+
In the future, CSSforge will try to integrate with popular design tools such as Figma.
1823

1924
## Features
2025

@@ -871,15 +876,18 @@ const css = generateCSS(config);
871876

872877
Check out our examples:
873878

874-
- [Basic Setup](./examples/basic)
875-
- [] Tailwind
879+
- [Basic Setup](./example/basic)
880+
- [ ] Tailwind
876881

877882
## TODO
878883

879-
- [] Custom Media Queries https://www.w3.org/TR/mediaqueries-5/#at-ruledef-custom-media
880-
- [] Line Height
881-
- [] Bundlers Plugin (Vite, Rollup, Webpack ...)
882-
- [] Nuxt Module
884+
- [ ] Module:
885+
[Custom Media Queries](https://www.w3.org/TR/mediaqueries-5/#at-ruledef-custom-media)
886+
- [ ] Typography : Line Height
887+
- [ ] Stable schema spec
888+
- [ ] VSCode Extension
889+
- [ ] Bundlers Plugin (Vite, Rollup, Webpack ...)
890+
- [ ] Nuxt Module
883891

884892
## License
885893

src/helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const reservedKeyWords = [
44
"typography",
55
"typography_fluid",
66
"theme",
7-
"color",
7+
"gradients",
8+
"palette",
89
];
910
/**
1011
* Validates a name to ensure it doesn't contain invalid characters.

tests/colors.test.ts

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Deno.test("processColors - converts hex to oklch", () => {
1616
},
1717
});
1818

19-
const { css } = processColors(config.colors);
19+
const { css, resolveMap } = processColors(config.colors);
2020
const lines = getLines(css);
2121
assertEquals(
2222
lines[1].trim(),
@@ -26,6 +26,10 @@ Deno.test("processColors - converts hex to oklch", () => {
2626
lines[2].trim(),
2727
"--palette-coral-200: oklch(69.622% 0.19552 32.32143);",
2828
);
29+
assertEquals(Array.from(resolveMap.keys()), [
30+
"palette.value.coral.100",
31+
"palette.value.coral.200",
32+
]);
2933
});
3034

3135
Deno.test("processColors - handles different color formats", () => {
@@ -45,7 +49,7 @@ Deno.test("processColors - handles different color formats", () => {
4549
},
4650
} as const,
4751
);
48-
const { css } = processColors(config.colors);
52+
const { css, resolveMap } = processColors(config.colors);
4953
const lines = getLines(css);
5054

5155
assertEquals(
@@ -61,6 +65,13 @@ Deno.test("processColors - handles different color formats", () => {
6165
lines[4].trim(),
6266
"--palette-brand-default: oklch(62.796% 0.25768 29.23388);",
6367
);
68+
69+
assertEquals(Array.from(resolveMap.keys()), [
70+
"palette.value.brand.200",
71+
"palette.value.brand.300",
72+
"palette.value.brand.400",
73+
"palette.value.brand.default",
74+
]);
6475
});
6576

6677
Deno.test("processColors - handles string values", () => {
@@ -76,7 +87,7 @@ Deno.test("processColors - handles string values", () => {
7687
},
7788
},
7889
});
79-
const { css } = processColors(config.colors);
90+
const { css, resolveMap } = processColors(config.colors);
8091
const lines = getLines(css);
8192
assertEquals(
8293
lines[1].trim(),
@@ -86,6 +97,10 @@ Deno.test("processColors - handles string values", () => {
8697
lines[2].trim(),
8798
"--palette-simple-black: oklch(0% 0 0);",
8899
);
100+
assertEquals(Array.from(resolveMap.keys()), [
101+
"palette.value.simple.white",
102+
"palette.value.simple.black",
103+
]);
89104
});
90105

91106
Deno.test("processColors - handles themes", () => {
@@ -117,7 +132,7 @@ Deno.test("processColors - handles themes", () => {
117132
},
118133
},
119134
});
120-
const { css } = processColors(config.colors);
135+
const { css, resolveMap } = processColors(config.colors);
121136
const lines = getLines(css);
122137
assertEquals(
123138
lines[5].trim(),
@@ -127,6 +142,12 @@ Deno.test("processColors - handles themes", () => {
127142
lines[6].trim(),
128143
"--theme-light-background-secondary: var(--palette-simple-black);",
129144
);
145+
assertEquals(Array.from(resolveMap.keys()), [
146+
"palette.value.simple.white",
147+
"palette.value.simple.black",
148+
"theme.value.light.background.primary",
149+
"theme.value.light.background.secondary",
150+
]);
130151
});
131152

132153
Deno.test("processColors - handles transparency", () => {
@@ -142,7 +163,7 @@ Deno.test("processColors - handles transparency", () => {
142163
},
143164
},
144165
});
145-
const { css } = processColors(config.colors);
166+
const { css, resolveMap } = processColors(config.colors);
146167
const lines = getLines(css);
147168
assertEquals(
148169
lines[1],
@@ -152,6 +173,10 @@ Deno.test("processColors - handles transparency", () => {
152173
lines[2],
153174
"--palette-alpha-softGray2: oklch(14.48% 0 0 / 24%);",
154175
);
176+
assertEquals(Array.from(resolveMap.keys()), [
177+
"palette.value.alpha.softGray1",
178+
"palette.value.alpha.softGray2",
179+
]);
155180
});
156181

157182
Deno.test("processColors - generates gradient with color variables", () => {
@@ -197,6 +222,13 @@ Deno.test("processColors - generates gradient with color variables", () => {
197222
].join("\n");
198223

199224
assertEquals(lines.at(-1), expected);
225+
assertEquals(Array.from(result.resolveMap.keys()), [
226+
"palette.value.coral.50",
227+
"palette.value.coral.90",
228+
"palette.value.coral.100",
229+
"palette.value.indigo.100",
230+
"gradients.value.orangeGradient.primary",
231+
]);
200232
});
201233

202234
Deno.test("processColors - handles themes referencing gradients", () => {
@@ -241,11 +273,16 @@ Deno.test("processColors - handles themes referencing gradients", () => {
241273
},
242274
});
243275

244-
const { css } = processColors(config.colors);
276+
const { css, resolveMap } = processColors(config.colors);
245277
const lines = getLines(css);
246278
const lastLine = lines.pop();
247279
assertEquals(
248280
lastLine,
249281
"--theme-light-background-primary: var(--gradients-orangeGradient-primary);",
250282
);
283+
assertEquals(Array.from(resolveMap.keys()), [
284+
"palette.value.coral.50",
285+
"gradients.value.orangeGradient.primary",
286+
"theme.value.light.background.primary",
287+
]);
251288
});

tests/spacing.test.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ Deno.test("processSpacing - generates correct spacing scale", () => {
2121
"--spacing-size-s: 1rem;",
2222
].join("\n");
2323
assertEquals(result.css, expected);
24+
25+
assertEquals(Array.from(result.resolveMap.keys()), [
26+
"spacing.custom.size.value.1",
27+
"spacing.custom.size.value.2",
28+
"spacing.custom.size.value.3",
29+
"spacing.custom.size.value.s",
30+
]);
2431
});
2532

2633
// Test with string keys
@@ -49,6 +56,13 @@ Deno.test("processSpacing - handles settings", () => {
4956
].join("\n");
5057

5158
assertEquals(result.css, expected);
59+
60+
assertEquals(Array.from(result.resolveMap.keys()), [
61+
"spacing.custom.size.value.1",
62+
"spacing.custom.size.value.2",
63+
"spacing.custom.scale.value.md",
64+
"spacing.custom.scale.value.lg",
65+
]);
5266
});
5367

5468
Deno.test("processSpacing - generates fluid spacing (prefix)", () => {
@@ -71,7 +85,7 @@ Deno.test("processSpacing - generates fluid spacing (prefix)", () => {
7185
},
7286
});
7387

74-
const { css } = processSpacing(config.spacing);
88+
const { css, resolveMap } = processSpacing(config.spacing);
7589
const expected = [
7690
"--spacing_fluid-base-foo-xs: clamp(0rem, 0rem + 0vw, 0rem);",
7791
"--spacing_fluid-base-foo-s: clamp(0.25rem, -0.1667rem + 2.0833vw, 1.5rem);",
@@ -83,6 +97,17 @@ Deno.test("processSpacing - generates fluid spacing (prefix)", () => {
8397
"--spacing_fluid-base-foo-m-l: clamp(0.25rem, -0.6667rem + 4.5833vw, 3rem);",
8498
].join("\n");
8599
assertEquals(css, expected);
100+
101+
assertEquals(Array.from(resolveMap.keys()), [
102+
"spacing_fluid.base@xs",
103+
"spacing_fluid.base@s",
104+
"spacing_fluid.base@m",
105+
"spacing_fluid.base@l",
106+
"spacing_fluid.base@xs-l",
107+
"spacing_fluid.base@xs-s",
108+
"spacing_fluid.base@s-m",
109+
"spacing_fluid.base@m-l",
110+
]);
86111
});
87112

88113
Deno.test("processSpacing - fluid without prefix falls back to scale name", () => {
@@ -102,7 +127,7 @@ Deno.test("processSpacing - fluid without prefix falls back to scale name", () =
102127
},
103128
},
104129
});
105-
const { css } = processSpacing(config.spacing);
130+
const { css, resolveMap } = processSpacing(config.spacing);
106131
const expected = [
107132
"--spacing_fluid-rhythm-xs: clamp(0rem, 0rem + 0vw, 0rem);",
108133
"--spacing_fluid-rhythm-s: clamp(0.125rem, -0.25rem + 1.875vw, 1.25rem);",
@@ -111,6 +136,14 @@ Deno.test("processSpacing - fluid without prefix falls back to scale name", () =
111136
"--spacing_fluid-rhythm-s-m: clamp(0.125rem, -0.25rem + 1.875vw, 1.25rem);",
112137
].join("\n");
113138
assertEquals(css, expected);
139+
140+
assertEquals(Array.from(resolveMap.keys()), [
141+
"spacing_fluid.rhythm@xs",
142+
"spacing_fluid.rhythm@s",
143+
"spacing_fluid.rhythm@m",
144+
"spacing_fluid.rhythm@xs-s",
145+
"spacing_fluid.rhythm@s-m",
146+
]);
114147
});
115148

116149
Deno.test("processSpacing - combines fluid and custom spacing", () => {
@@ -137,7 +170,7 @@ Deno.test("processSpacing - combines fluid and custom spacing", () => {
137170
},
138171
},
139172
});
140-
const { css } = processSpacing(config.spacing!);
173+
const { css, resolveMap } = processSpacing(config.spacing!);
141174
const expected = [
142175
"--spacing_fluid-base-flux-xs: clamp(0rem, 0rem + 0vw, 0rem);",
143176
"--spacing_fluid-base-flux-s: clamp(0.25rem, -0.1667rem + 2.0833vw, 1.5rem);",
@@ -148,4 +181,13 @@ Deno.test("processSpacing - combines fluid and custom spacing", () => {
148181
"--spacing-gap-2: 8px;",
149182
].join("\n");
150183
assertEquals(css, expected);
184+
assertEquals(Array.from(resolveMap.keys()), [
185+
"spacing_fluid.base@xs",
186+
"spacing_fluid.base@s",
187+
"spacing_fluid.base@m",
188+
"spacing_fluid.base@xs-s",
189+
"spacing_fluid.base@s-m",
190+
"spacing.custom.gap.value.1",
191+
"spacing.custom.gap.value.2",
192+
]);
151193
});

tests/typography.test.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ Deno.test("processTypography - generates correct CSS variables", () => {
4444
"--typography_fluid-arial-xl: clamp(1.3672rem, 1.3111rem + 0.2803vw, 1.5625rem);",
4545
);
4646

47+
assertEquals(
48+
Array.from(result.resolveMap.keys()),
49+
expectedSizes.map((size) => `typography_fluid.arial@${size}`),
50+
);
51+
4752
// Test that we have all the expected size variables
4853
expectedSizes.forEach((size) => {
4954
const hasSize = lines.some((line) =>
@@ -107,10 +112,15 @@ Deno.test("typography - can handle custom labels and prefixes", () => {
107112
// Test a specific value for precision
108113
const xlLine = lines.find((line) => line.includes("--typography_fluid-arial-text-xl:"));
109114
assertEquals(
110-
xlLine?.trim(),
115+
xlLine,
111116
"--typography_fluid-arial-text-xl: clamp(1.3672rem, 1.3111rem + 0.2803vw, 1.5625rem);",
112117
);
113118

119+
assertEquals(
120+
Array.from(result.resolveMap.keys()),
121+
expectedSizes.toReversed().map((size) => `typography_fluid.arial@${size}`),
122+
);
123+
114124
// Test that we have all the expected size variables
115125
expectedSizes.forEach((size) => {
116126
const hasSize = lines.some((line) =>
@@ -149,12 +159,22 @@ Deno.test("processTypography - can process weights", () => {
149159
const lines = getLines(result.css);
150160
assertEquals(lines.length, positiveSteps + negativeSteps + 1 + 1); // 1 for base size and 1 for weight
151161

162+
assertEquals(
163+
Array.from(result.resolveMap.keys()),
164+
[
165+
"typography_fluid.arial@2xl",
166+
"typography_fluid.arial@xl",
167+
"typography_fluid.arial@l",
168+
"typography_fluid.arial@m",
169+
"typography_fluid.arial@s",
170+
"typography_fluid.arial@xs",
171+
"typography_fluid.arial@2xs",
172+
"typography.weight.arial.value.regular",
173+
],
174+
);
152175
// Test that we have the weight variable
153176
const xlLine = lines.find((line) =>
154177
line.includes("--typography-weight-arial-regular:")
155178
);
156-
assertEquals(
157-
xlLine?.trim(),
158-
"--typography-weight-arial-regular: 500;",
159-
);
179+
assertEquals(xlLine, "--typography-weight-arial-regular: 500;");
160180
});

0 commit comments

Comments
 (0)