feat: @bchen/ui v0.1.0 — dark-mode token palette and 16px base rule #2
@@ -8,9 +8,4 @@ describe('base.css', () => {
|
|||||||
expect(css).toMatch(/input\s*,\s*textarea\s*,\s*select\s*\{[^}]*font-size\s*:\s*16px/);
|
expect(css).toMatch(/input\s*,\s*textarea\s*,\s*select\s*\{[^}]*font-size\s*:\s*16px/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('covers all three form control selectors in one rule', () => {
|
|
||||||
expect(css).toMatch(/input/);
|
|
||||||
expect(css).toMatch(/textarea/);
|
|
||||||
expect(css).toMatch(/select/);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,17 +5,11 @@ const css = readFileSync(new URL('../dist/tokens.css', import.meta.url), 'utf-8'
|
|||||||
|
|
||||||
// ---- CSS parser helpers ----
|
// ---- CSS parser helpers ----
|
||||||
|
|
||||||
function extractRootBlock(src: string): string {
|
function extractBlock(src: string): string {
|
||||||
const m = src.match(/:root\s*\{([^}]+)\}/);
|
const m = src.match(/:root\s*\{([^}]+)\}/);
|
||||||
return m?.[1] ?? '';
|
return m?.[1] ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractDarkBlock(src: string): string {
|
|
||||||
const afterMedia = src.split('@media (prefers-color-scheme: dark)')[1] ?? '';
|
|
||||||
const m = afterMedia.match(/:root\s*\{([^}]+)\}/);
|
|
||||||
return m?.[1] ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseProps(block: string): Map<string, string> {
|
function parseProps(block: string): Map<string, string> {
|
||||||
const map = new Map<string, string>();
|
const map = new Map<string, string>();
|
||||||
const re = /--([\w-]+)\s*:\s*([^;]+);/g;
|
const re = /--([\w-]+)\s*:\s*([^;]+);/g;
|
||||||
@@ -63,8 +57,8 @@ function contrast(hex1: string, hex2: string): number {
|
|||||||
|
|
||||||
// ---- Fixtures ----
|
// ---- Fixtures ----
|
||||||
|
|
||||||
const rootProps = parseProps(extractRootBlock(css));
|
const rootProps = parseProps(extractBlock(css));
|
||||||
const darkProps = parseProps(extractDarkBlock(css));
|
const darkProps = parseProps(extractBlock(css.split('@media (prefers-color-scheme: dark)')[1] ?? ''));
|
||||||
// Merged: dark overrides on top of light primitives so var() refs resolve correctly.
|
// Merged: dark overrides on top of light primitives so var() refs resolve correctly.
|
||||||
const mergedDark = new Map([...rootProps, ...darkProps]);
|
const mergedDark = new Map([...rootProps, ...darkProps]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user