Switch to BiomeJS (#306)

This commit is contained in:
Gregory Schier
2025-11-23 08:38:13 -08:00
committed by GitHub
parent 2bac610efe
commit ec3e2e16a9
332 changed files with 3007 additions and 4097 deletions

View File

@@ -139,7 +139,7 @@ function bannerColorVariables(color: YaakColor | null): Partial<CSSVariables> {
function buttonSolidColorVariables(
color: YaakColor | null,
isDefault: boolean = false,
isDefault = false,
): Partial<CSSVariables> {
if (color == null) return {};
@@ -161,7 +161,7 @@ function buttonSolidColorVariables(
function buttonBorderColorVariables(
color: YaakColor | null,
isDefault: boolean = false,
isDefault = false,
): Partial<CSSVariables> {
if (color == null) return {};
@@ -268,6 +268,7 @@ export function getThemeCSS(theme: Theme): string {
theme.components.toast = theme.components.toast ?? theme.components.menu ?? {};
const { components, id, label } = theme;
const colors = Object.keys(theme.base).reduce((prev, key) => {
// biome-ignore lint/performance/noAccumulatingSpread: none
return { ...prev, [key]: theme.base[key as YaakColorKey] };
}, {}) as ThemeComponentColors;
@@ -278,11 +279,11 @@ export function getThemeCSS(theme: Theme): string {
baseCss,
...Object.keys(components ?? {}).map((key) => componentCSS(theme, key as ComponentName)),
variablesToCSS(
`.x-theme-button--solid--default`,
'.x-theme-button--solid--default',
buttonSolidColorVariables(yc(theme, theme.base.surface), true),
),
variablesToCSS(
`.x-theme-button--border--default`,
'.x-theme-button--border--default',
buttonBorderColorVariables(yc(theme, theme.base.surface), true),
),
...Object.keys(colors ?? {}).map((key) =>
@@ -312,7 +313,7 @@ export function addThemeStylesToDocument(rawTheme: Theme | null) {
}
const theme = completeTheme(rawTheme);
let styleEl = document.head.querySelector(`style[data-theme]`);
let styleEl = document.head.querySelector('style[data-theme]');
if (!styleEl) {
styleEl = document.createElement('style');
document.head.appendChild(styleEl);

View File

@@ -3,10 +3,10 @@ import parseColor from 'parse-color';
export class YaakColor {
private readonly appearance: 'dark' | 'light' = 'light';
private hue: number = 0;
private saturation: number = 0;
private lightness: number = 0;
private alpha: number = 1;
private hue = 0;
private saturation = 0;
private lightness = 0;
private alpha = 1;
constructor(cssColor: string, appearance: 'dark' | 'light' = 'light') {
try {
@@ -30,11 +30,12 @@ export class YaakColor {
}
set(cssColor: string): YaakColor {
let fixedCssColor = cssColor;
if (cssColor.startsWith('#') && cssColor.length === 9) {
const [r, g, b, a] = hexToRgba(cssColor);
cssColor = `rgba(${r},${g},${b},${a})`;
fixedCssColor = `rgba(${r},${g},${b},${a})`;
}
const { hsla } = parseColor(cssColor);
const { hsla } = parseColor(fixedCssColor);
this.hue = hsla[0];
this.saturation = hsla[1];
this.lightness = hsla[2];
@@ -131,7 +132,7 @@ function rgbaToHex(r: number, g: number, b: number, a: number): string {
const hex = Number(Math.round(n)).toString(16);
return hex.length === 1 ? `0${hex}` : hex;
};
return '#' + [toHex(r), toHex(g), toHex(b), toHex(a * 255)].join('').toUpperCase();
return `#${[toHex(r), toHex(g), toHex(b), toHex(a * 255)].join('').toUpperCase()}`;
}
function rgbaToHexNoAlpha(r: number, g: number, b: number): string {
@@ -139,7 +140,7 @@ function rgbaToHexNoAlpha(r: number, g: number, b: number): string {
const hex = Number(Math.round(n)).toString(16);
return hex.length === 1 ? `0${hex}` : hex;
};
return '#' + [toHex(r), toHex(g), toHex(b)].join('').toUpperCase();
return `#${[toHex(r), toHex(g), toHex(b)].join('').toUpperCase()}`;
}
function hexToRgba(hex: string): [number, number, number, number] {