mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 21:08:17 +00:00
test: Count Derived Scrim Tokens as Theme-Owned (#16512)
The stylesheet-ownership check added in #16480 required every declared color token to be a theme key of its own, so the scrim tokens from #16492, which compose the surface-overlay role with a scrim opacity role, failed it once both landed on canary. A token is now owned when a variable its value reads is one a theme can set.
This commit is contained in:
parent
364bf27210
commit
75bb1899fc
1 changed files with 11 additions and 5 deletions
|
|
@ -11,11 +11,15 @@ globalThis.structuredClone ??= <T>(value: T): T => deserialize(serialize(value))
|
|||
|
||||
const tokensPath = path.resolve(__dirname, 'tokens.css');
|
||||
const tokens = fs.readFileSync(tokensPath, 'utf8');
|
||||
const declared = new Set(
|
||||
Array.from(tokens.matchAll(/--color-([\w-]+):/g), (match) => match[1]).filter(
|
||||
(name) => !name.endsWith('*'),
|
||||
),
|
||||
/** Each declared color token, mapped to the custom properties its value reads. */
|
||||
const declarations = new Map(
|
||||
Array.from(
|
||||
tokens.matchAll(/--color-([\w-]+):([^;]+);/g),
|
||||
([, name, value]) =>
|
||||
[name, Array.from(value.matchAll(/var\(--([\w-]+)/g), (match) => match[1])] as const,
|
||||
).filter(([name]) => !name.endsWith('*')),
|
||||
);
|
||||
const declared = new Set(declarations.keys());
|
||||
|
||||
/**
|
||||
* Theme properties consumed by stylesheets rather than by utilities: the shimmer animation and
|
||||
|
|
@ -70,7 +74,9 @@ describe('theme color tokens', () => {
|
|||
|
||||
it('lets a theme set every color token the stylesheet declares', () => {
|
||||
const registered = new Set(Object.keys(defaultTheme).map((key) => key.replace(/^rgb-/, '')));
|
||||
const unowned = [...declared].filter((token) => !registered.has(token));
|
||||
const unowned = [...declarations]
|
||||
.filter(([, reads]) => !reads.some((property) => registered.has(property)))
|
||||
.map(([token]) => token);
|
||||
|
||||
expect(unowned).toEqual([]);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue