Skip to content

Commit 6baff6b

Browse files
tenphicursoragent
andauthored
fix(glaze): allow absolute lightness with base colors for contrast (#14)
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent b5e79a8 commit 6baff6b

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎.changeset/fix-lightness-base.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tenphi/glaze': patch
3+
---
4+
5+
Fix relative lightness application: allow absolute lightness values when using base colors for contrast solving. Previously, colors with both `base` and absolute `lightness` were incorrectly rejected during validation and topological sorting.

‎.cursor/commands/submit-changes.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type(scope): short description
3737
- Keep the message as short as possible.
3838
- Include the changeset file in the same commit.
3939
- Before 1.0.0 release treat major changes as minor and minor as patches.
40+
- Do not include markdown files that are not in the repo yet and wasn't staged manually by the user.
4041

4142
## 4. Push
4243

‎src/glaze.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ describe('glaze', () => {
151151

152152
expect(() => theme.resolve()).toThrow('must have either');
153153
});
154+
155+
it('resolves colors with absolute lightness and base (for contrast)', () => {
156+
const theme = glaze(280, 80);
157+
theme.colors({
158+
surface: { lightness: 97 },
159+
card: { base: 'surface', lightness: 46 },
160+
});
161+
162+
const resolved = theme.resolve();
163+
const card = resolved.get('card')!;
164+
expect(card.light.l).toBeCloseTo(0.46, 2);
165+
});
154166
});
155167

156168
describe('relative lightness', () => {

‎src/glaze.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ function validateColorDefs(defs: ColorMap): void {
263263
if (def.fg) dfs(def.fg);
264264
} else {
265265
const regDef = def as RegularColorDef;
266-
if (regDef.base && !isAbsoluteLightness(regDef.lightness)) {
266+
if (regDef.base) {
267267
dfs(regDef.base);
268268
}
269269
}
@@ -294,7 +294,7 @@ function topoSort(defs: ColorMap): string[] {
294294
if (def.fg) visit(def.fg);
295295
} else {
296296
const regDef = def as RegularColorDef;
297-
if (regDef.base && !isAbsoluteLightness(regDef.lightness)) {
297+
if (regDef.base) {
298298
visit(regDef.base);
299299
}
300300
}

0 commit comments

Comments
 (0)