Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions e2e/testcafe-devextreme/tests/common/accentColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ import { isFluentNext, testScreenshot } from '../../helpers/themeUtils';

const STEPS = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180];

const DESIGNED_PALETTE_TOLERANCE = 4;
const DESIGNED_PALETTE_TOLERANCE = 1.5;
const HUE_TOLERANCE = 0.01;

const NORMALIZED_ACCENT_LIGHTNESS: Record<string, number> = {
'#000080': 0.45,
'#ffff00': 0.6,
'oklch(0.3 0.016 200)': 0.465,
'oklch(0.7 0.016 40)': 0.585,
black: 0.525,
white: 0.525,
'#808080': 0.525,
};

interface Oklch {
l: number;
c: number;
Expand Down Expand Up @@ -75,21 +85,12 @@ const measurePalette = ClientFunction((accent: string | null, steps: number[]) =
return { step, resolved, oklch: asOklch(resolved) };
};

const setting = (name: string): number => +getComputedStyle(root).getPropertyValue(name).trim();
const measured = steps.map(read);
const source = accent ? asOklch(accent) : null;

probe.remove();

return {
measured,
source,
settings: {
lightnessMax: setting('--dx-accent-lightness-max'),
lightnessMin: setting('--dx-accent-lightness-min'),
chromaMin: setting('--dx-accent-chroma-min'),
},
};
return { measured, source };
});

const PALETTE_STRIP = 'accent-palette';
Expand Down Expand Up @@ -257,17 +258,13 @@ fixture`Custom accent color`
.eql([]);
});

(isFluentNext() ? test : test.skip)('an arbitrary accent keeps hue, order and clamps', async (t) => {
(isFluentNext() ? test : test.skip)('an arbitrary accent keeps hue and order', async (t) => {
const arbitraryAccent = '#a703ff';
const { measured, source, settings } = await measurePalette(arbitraryAccent, STEPS);
const { measured, source } = await measurePalette(arbitraryAccent, STEPS);
const steps = measured;
const lightest = stepOf(steps, 10);
const darkest = stepOf(steps, 180);
const accentItself = stepOf(steps, 100);

await t.expect({
lightest: { l: rounded(lightest.l), c: rounded(lightest.c) },
darkest: { l: rounded(darkest.l), c: rounded(darkest.c) },
accentItself: { l: rounded(accentItself.l), c: rounded(accentItself.c) },
lighteningSteps: steps
.filter((entry, index) => index > 0 && entry.oklch!.l >= steps[index - 1].oklch!.l)
Expand All @@ -276,14 +273,29 @@ fixture`Custom accent color`
.filter((entry) => Math.abs(entry.oklch!.h - source!.h) > HUE_TOLERANCE)
.map((entry) => entry.step),
}).eql({
lightest: { l: settings.lightnessMax, c: settings.chromaMin },
darkest: { l: settings.lightnessMin, c: settings.chromaMin },
accentItself: { l: rounded(source!.l), c: rounded(source!.c) },
lighteningSteps: [],
stepsOffHue: [],
});
});

(isFluentNext() ? test : test.skip)('an accent too dark, too light, short of chroma or achromatic is normalized, keeping its chroma and hue', async (t) => {
const normalized: Record<string, Oklch> = {};
const expected: Record<string, Oklch> = {};

for (const [accent, lightness] of Object.entries(NORMALIZED_ACCENT_LIGHTNESS)) {
const { measured, source } = await measurePalette(accent, [100]);
const accentItself = stepOf(measured, 100);

normalized[accent] = {
l: rounded(accentItself.l), c: rounded(accentItself.c), h: rounded(accentItself.h),
};
expected[accent] = { l: lightness, c: rounded(source!.c), h: rounded(source!.h) };
}

await t.expect(normalized).eql(expected);
});

(isFluentNext() ? test : test.skip)('the derived palette is drawn as designed', async (t) => {
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);

Expand Down Expand Up @@ -383,9 +395,9 @@ fixture`Custom accent color`
});

(isFluentNext() ? test : test.skip)('themes.customAccentColor takes an accent written by name', async (t) => {
const namedAccent = 'rebeccapurple';
const namedAccent = 'slateblue';
const applied = await accentThroughApi(namedAccent);

await t.expect(applied.seed).eql('#663399', 'the palette is built from the color the name stands for');
await t.expect(applied.seed).eql('#6a5acd', 'the palette is built from the color the name stands for');
await t.expect(applied.reported).eql(namedAccent, 'the accent is reported back as it was written, not as a hex');
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
// sync between Blazor and DevExtreme (plus vNext and WPF in the future)
@supports (color: oklch(from red l c h)) {
:root {
--dx-accent-color-source: var(--dx-accent-color);
--dx-accent-lightness-max: 0.975;
--dx-accent-lightness-min: 0.15;
--dx-accent-chroma-min: 0.02;
--dx-accent-color-10: oklch(from var(--dx-accent-color-source) max(l, var(--dx-accent-lightness-max)) min(c, var(--dx-accent-chroma-min)) h / 1);
--dx-accent-color-20: oklch(from var(--dx-accent-color-source) calc(l + 8 * (var(--dx-accent-lightness-max) - min(l, var(--dx-accent-lightness-max))) / 9) calc(c - 8 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 9) h / 1);
--dx-accent-color-30: oklch(from var(--dx-accent-color-source) calc(l + 7 * (var(--dx-accent-lightness-max) - min(l, var(--dx-accent-lightness-max))) / 9) calc(c - 7 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 9) h / 1);
--dx-accent-color-40: oklch(from var(--dx-accent-color-source) calc(l + 6 * (var(--dx-accent-lightness-max) - min(l, var(--dx-accent-lightness-max))) / 9) calc(c - 6 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 9) h / 1);
--dx-accent-color-50: oklch(from var(--dx-accent-color-source) calc(l + 5 * (var(--dx-accent-lightness-max) - min(l, var(--dx-accent-lightness-max))) / 9) calc(c - 5 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 9) h / 1);
--dx-accent-color-60: oklch(from var(--dx-accent-color-source) calc(l + 4 * (var(--dx-accent-lightness-max) - min(l, var(--dx-accent-lightness-max))) / 9) calc(c - 4 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 9) h / 1);
--dx-accent-color-70: oklch(from var(--dx-accent-color-source) calc(l + 3 * (var(--dx-accent-lightness-max) - min(l, var(--dx-accent-lightness-max))) / 9) calc(c - 3 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 9) h / 1);
--dx-accent-color-80: oklch(from var(--dx-accent-color-source) calc(l + 2 * (var(--dx-accent-lightness-max) - min(l, var(--dx-accent-lightness-max))) / 9) calc(c - 2 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 9) h / 1);
--dx-accent-color-90: oklch(from var(--dx-accent-color-source) calc(l + 1 * (var(--dx-accent-lightness-max) - min(l, var(--dx-accent-lightness-max))) / 9) calc(c - 1 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 9) h / 1);
--dx-accent-color-100: oklch(from var(--dx-accent-color-source) l c h / 1);
--dx-accent-color-110: oklch(from var(--dx-accent-color-source) calc(l - 1 * (max(l, var(--dx-accent-lightness-min)) - var(--dx-accent-lightness-min)) / 8) calc(c - 1 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 8) h / 1);
--dx-accent-color-120: oklch(from var(--dx-accent-color-source) calc(l - 2 * (max(l, var(--dx-accent-lightness-min)) - var(--dx-accent-lightness-min)) / 8) calc(c - 2 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 8) h / 1);
--dx-accent-color-130: oklch(from var(--dx-accent-color-source) calc(l - 3 * (max(l, var(--dx-accent-lightness-min)) - var(--dx-accent-lightness-min)) / 8) calc(c - 3 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 8) h / 1);
--dx-accent-color-140: oklch(from var(--dx-accent-color-source) calc(l - 4 * (max(l, var(--dx-accent-lightness-min)) - var(--dx-accent-lightness-min)) / 8) calc(c - 4 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 8) h / 1);
--dx-accent-color-150: oklch(from var(--dx-accent-color-source) calc(l - 5 * (max(l, var(--dx-accent-lightness-min)) - var(--dx-accent-lightness-min)) / 8) calc(c - 5 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 8) h / 1);
--dx-accent-color-160: oklch(from var(--dx-accent-color-source) calc(l - 6 * (max(l, var(--dx-accent-lightness-min)) - var(--dx-accent-lightness-min)) / 8) calc(c - 6 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 8) h / 1);
--dx-accent-color-170: oklch(from var(--dx-accent-color-source) calc(l - 7 * (max(l, var(--dx-accent-lightness-min)) - var(--dx-accent-lightness-min)) / 8) calc(c - 7 * (max(c, var(--dx-accent-chroma-min)) - var(--dx-accent-chroma-min)) / 8) h / 1);
--dx-accent-color-180: oklch(from var(--dx-accent-color-source) min(l, var(--dx-accent-lightness-min)) min(c, var(--dx-accent-chroma-min)) h / 1);
/* Normalizes the accent: lightness clamped to 45–60%, achromatic accents (white, black, grays) use 52.5% lightness, alpha forced to 100% */
--dx-accent-color-base: oklch(from var(--dx-accent-color) calc(0.525 + (clamp(0.45, l, 0.6) - 0.525) * min(1, c / 0.02)) c h / 1);
--dx-accent-color-10: oklch(from var(--dx-accent-color-base) 98% calc(c * (0.98 - 0.12 * 8)) h);
--dx-accent-color-20: oklch(from var(--dx-accent-color-base) 95% calc(c * (0.98 - 0.12 * 7)) h);
--dx-accent-color-30: oklch(from var(--dx-accent-color-base) 90% calc(c * (0.98 - 0.12 * 6)) h);
--dx-accent-color-40: oklch(from var(--dx-accent-color-base) 85% calc(c * (0.98 - 0.12 * 5)) h);
--dx-accent-color-50: oklch(from var(--dx-accent-color-base) 80% calc(c * (0.98 - 0.12 * 4)) h);
--dx-accent-color-60: oklch(from var(--dx-accent-color-base) 75% calc(c * (0.98 - 0.12 * 3)) h);
--dx-accent-color-70: oklch(from var(--dx-accent-color-base) calc(0.75 + (l - 0.75) / 4 * 1) calc(c * (0.98 - 0.12 * 2)) h);
--dx-accent-color-80: oklch(from var(--dx-accent-color-base) calc(0.75 + (l - 0.75) / 4 * 2) calc(c * (0.98 - 0.12 * 1)) h);
--dx-accent-color-90: oklch(from var(--dx-accent-color-base) calc(0.75 + (l - 0.75) / 4 * 3) calc(c * (0.98 - 0.12 * 0)) h);
--dx-accent-color-100: oklch(from var(--dx-accent-color-base) l c h);
--dx-accent-color-110: oklch(from var(--dx-accent-color-base) calc(l + (0.35 - l) / 4 * 1) calc(c * (0.95 - 0.1 * 0)) h);
--dx-accent-color-120: oklch(from var(--dx-accent-color-base) calc(l + (0.35 - l) / 4 * 2) calc(c * (0.95 - 0.1 * 1)) h);
--dx-accent-color-130: oklch(from var(--dx-accent-color-base) calc(l + (0.35 - l) / 4 * 3) calc(c * (0.95 - 0.1 * 2)) h);
--dx-accent-color-140: oklch(from var(--dx-accent-color-base) 35% calc(c * (0.95 - 0.1 * 3)) h);
--dx-accent-color-150: oklch(from var(--dx-accent-color-base) 30% calc(c * (0.95 - 0.1 * 4)) h);
--dx-accent-color-160: oklch(from var(--dx-accent-color-base) 25% calc(c * (0.95 - 0.1 * 5)) h);
--dx-accent-color-170: oklch(from var(--dx-accent-color-base) 20% calc(c * (0.95 - 0.1 * 6)) h);
--dx-accent-color-180: oklch(from var(--dx-accent-color-base) 15% calc(c * (0.95 - 0.1 * 7)) h);
}
}
42 changes: 9 additions & 33 deletions packages/devextreme-scss/tests/accent-palette.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ test('the stylesheet declares exactly what the contract names', () => {
const declared = [...stylesheet().matchAll(/(--dx-accent[a-z0-9-]*):/g)].map((match) => match[1]);

expect(declared).toEqual([
contract.source.name,
...contract.settings.map(({ name }) => name),
contract.base.name,
...contractSteps.map(stepName),
]);
expect(stylesheet()).toContain(`var(${contract.input.name})`);
Expand Down Expand Up @@ -76,38 +75,15 @@ test('the palettes read back exactly the steps the contract fixes', () => {
expect(readBack).toEqual(paletteNames.map((palette) => [palette, contractSteps]));
});

test('no step multiplies and divides by the same number — Chrome 145 folds that term to zero', () => {
const degenerateFactors = (expression: string): string[] => {
const offenders: string[] = [];
const multiplier = /(\d+) \* \(/g;
let match = multiplier.exec(expression);
while (match) {
let depth = 1;
let index = match.index + match[0].length;
while (depth > 0 && index < expression.length) {
if (expression[index] === '(') depth += 1;
if (expression[index] === ')') depth -= 1;
index += 1;
}
const divisor = /^ \/ (\d+)/.exec(expression.slice(index));
if (divisor?.[1] === match[1]) offenders.push(`${match[1]} * (…) / ${divisor[1]}`);
match = multiplier.exec(expression);
}
return offenders;
};

const offenders = [...stylesheet().matchAll(/--dx-accent-color-(\d+): (.+);/g)]
.flatMap(([, step, value]) => degenerateFactors(value).map((shape) => `step ${step}: ${shape}`));
test('the base pins the alpha and every step is built from it, so a translucent accent does not fade the whole scale', () => {
const declarations = new Map([...stylesheet().matchAll(/(--dx-accent-color-[a-z0-9]+): (.+);/g)]
.map(([, name, expression]) => [name, expression]));

expect(offenders).toEqual([]);
});

test('every step pins the alpha, so a translucent accent does not fade the whole scale', () => {
const offenders = [...stylesheet().matchAll(/--dx-accent-color-(\d+): (.+);/g)]
.filter(([, , expression]) => !expression.endsWith('h / 1)'))
.map(([, step]) => `step ${step} inherits the alpha of the accent`);

expect(offenders).toEqual([]);
expect(declarations.get(contract.base.name))
.toMatch(new RegExp(`^oklch\\(from var\\(${contract.input.name}\\) .+ h / 1\\)$`));
expect(contractSteps.filter((step) => declarations.get(stepName(step))
?.startsWith(`oklch(from var(${contract.base.name}) `)))
.toEqual(contractSteps);
});

test('the built bundles carry both halves of the accent', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/devextreme-scss/tests/calc-budget.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"dx.fluent-next.blue.dark.compact.css": {
"calcOccurrences": 389,
"calcOccurrences": 383,
"declarationsWithDeepCalc": 5
},
"dx.fluent-next.blue.dark.css": {
"calcOccurrences": 390,
"calcOccurrences": 384,
"declarationsWithDeepCalc": 5
},
"dx.fluent-next.blue.light.compact.css": {
"calcOccurrences": 389,
"calcOccurrences": 383,
"declarationsWithDeepCalc": 5
},
"dx.fluent-next.blue.light.css": {
"calcOccurrences": 390,
"calcOccurrences": 384,
"declarationsWithDeepCalc": 5
}
}
3 changes: 1 addition & 2 deletions packages/devextreme-scss/tests/fluent-next-naming.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ const isAccentContractFile = (file: string): boolean => file.endsWith(
);
const ACCENT_CONTRACT = new Set([
accentContract.input.name,
accentContract.source.name,
...accentContract.settings.map(({ name }) => name),
accentContract.base.name,
...accentContract.steps.values.map((step) => `${accentContract.steps.prefix}${step}`),
]);

Expand Down
5 changes: 1 addition & 4 deletions packages/devextreme-scss/tests/public-surface.baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"fluent-next"
],
"names": [
"--dx-accent-chroma-min",
"--dx-accent-color-10",
"--dx-accent-color-100",
"--dx-accent-color-110",
Expand All @@ -71,9 +70,7 @@
"--dx-accent-color-70",
"--dx-accent-color-80",
"--dx-accent-color-90",
"--dx-accent-color-source",
"--dx-accent-lightness-max",
"--dx-accent-lightness-min",
"--dx-accent-color-base",
"--dx-accordion-bg",
"--dx-accordion-body-padding",
"--dx-accordion-content",
Expand Down
3 changes: 1 addition & 2 deletions packages/devextreme-scss/tests/runtime-reads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ test('no other place in the runtime reads a --dx-* name', () => {
...written.variables.map(({ name }) => name),
...painted.variables.map(({ name }) => name),
accent.input.name,
accent.source.name,
...accent.settings.map(({ name }) => name),
accent.base.name,
...accent.steps.values.map((step) => `${accent.steps.prefix}${step}`),
]);
const unlisted = walk(runtimeRoot, ['.ts', '.tsx'])
Expand Down
24 changes: 5 additions & 19 deletions packages/devextreme-scss/tools/naming/accent-contract.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
{
"comment": "The application -> CSS contract of the custom accent, the mirror image of runtime-contract.json's JS -> CSS one: an application writes ONE colour into --dx-accent-color, through themes.customAccentColor or by hand, and scss/widgets/fluent-next/_accent-color.scss derives the whole primary scale from it with relative colour syntax. These names are not part of the component tier - `accent` is neither a component nor a registered system concern - and fluent-next is the only theme that derives a palette, so tests/fluent-next-naming.test.ts excludes them from the public-surface checks. tests/accent-palette.test.ts holds the stylesheet, the generated palettes and the built bundles to this file.",
"comment": "The application -> CSS contract of the custom accent, the mirror image of runtime-contract.json's JS -> CSS one: an application writes ONE colour into --dx-accent-color, through themes.customAccentColor or by hand, and scss/widgets/fluent-next/_accent-color.scss derives the whole primary scale from it with relative colour syntax, by the same formula as the Blazor Fluent theme; the two copies are kept in sync by hand. These names are not part of the component tier - `accent` is neither a component nor a registered system concern - and fluent-next is the only theme that derives a palette, so tests/fluent-next-naming.test.ts excludes them from the public-surface checks. tests/accent-palette.test.ts holds the stylesheet, the generated palettes and the built bundles to this file.",
"declaredIn": "fluent-next/_accent-color.scss",
"input": {
"name": "--dx-accent-color",
"setBy": "themes.customAccentColor(color), the documented entry point, or the application itself writing the property on the root element",
"acceptedForms": "any colour the browser parses, including var(--custom-property) pointing at one; a value that resolves to no colour, or to another element's colour such as currentColor or inherit, is refused with W0024",
"whenUnset": "every derived step is invalid at computed-value time, so each generated palette keeps the designed colour through var(--dx-accent-color-<step>, <designed value>)"
},
"source": {
"name": "--dx-accent-color-source",
"purpose": "the single read of the application's name, so the 18 step expressions do not each carry it"
"base": {
"name": "--dx-accent-color-base",
"purpose": "the accent normalized once: lightness clamped to 0.45-0.6 and pulled towards 0.525 as chroma falls under 0.02, so white, black and grays come out at about 0.525; alpha forced to 1. Every step is built from it, and step 100 is this normalized accent rather than the colour the application wrote"
},
"settings": [
{
"name": "--dx-accent-lightness-max",
"purpose": "the lightness the light end of the scale arrives at"
},
{
"name": "--dx-accent-lightness-min",
"purpose": "the lightness the dark end of the scale arrives at"
},
{
"name": "--dx-accent-chroma-min",
"purpose": "the chroma both ends fade to"
}
],
"steps": {
"prefix": "--dx-accent-color-",
"values": [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180],
"readIn": "_design-system/fluent/accents/*.scss",
"alpha": "every step ends in `/ 1`: relative colour syntax hands the alpha of the origin colour down, so an accent written with one would otherwise fade the whole scale",
"alpha": "the base ends in `/ 1`: relative colour syntax hands the alpha of the origin colour down, so an accent written with one would otherwise fade the whole scale; every step is built from the base and inherits its alpha",
"fallback": "the designed value of the step, so an unset accent leaves the theme exactly as drawn"
}
}
Loading