import assert from 'node:assert/strict'; import { test } from 'node:test'; import { characterTheme, characterSyntax, SYNTAX_ROLES } from '../src/lib/theme/characterThemes.ts'; const rgb = (color: string) => color.slice(1).match(/../g)!.map(value => parseInt(value, 16) / 255); function luminance(color: string) { return rgb(color).map(value => value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4) .reduce((sum, value, index) => sum + value * [0.2126, 0.7152, 0.0722][index], 0); } function contrast(foreground: string, background: string) { const values = [luminance(foreground), luminance(background)].sort((a, b) => b - a); return (values[0] + 0.05) / (values[1] + 0.05); } test('Harvest Moon text and syntax stay readable on editor, panel, and selected surfaces', () => { const palette = characterTheme('harvest-moon')!; const [background, elevated, active, , dim, text, strong, accent, selection] = palette.surfaces; for (const foreground of [dim, text, strong, accent, palette.secondary]) { for (const surface of [background, elevated, active, selection]) { assert(contrast(foreground, surface) >= 4.5, `${foreground} on ${surface} needs 4.5:1 contrast`); } } for (const [index, foreground] of palette.syntax.entries()) { for (const surface of [background, elevated, selection]) { assert(contrast(foreground, surface) >= 4.5, `${SYNTAX_ROLES[index]} on ${surface} needs 4.5:1 contrast`); } } }); test('Harvest Moon uses the warm character colors for all palette roles', () => { const palette = characterTheme('harvest-moon')!; for (const color of [...palette.surfaces, palette.secondary, ...palette.syntax]) { assert.match(color, /^#[0-9a-f]{6}$/i); const [red, green, blue] = rgb(color); assert(red >= green && green >= blue, `${color} must follow the copper, amber, red, or cream palette`); } assert.equal(palette.mode, 'dark'); assert.equal(Object.keys(characterSyntax('harvest-moon')).length, SYNTAX_ROLES.length); assert.deepEqual(characterSyntax('unknown'), {}); });