sure
This commit is contained in:
parent
ced0ac56f3
commit
d6a8f898d1
27 changed files with 751 additions and 354 deletions
19
src/vibes.ts
19
src/vibes.ts
|
|
@ -1,9 +1,11 @@
|
|||
import { appConfig, type VibePreset } from './config';
|
||||
import { appConfig, type VibeId, type VibePreset } from './config';
|
||||
import { readBrowserStorage } from './utils/browser-storage';
|
||||
|
||||
export { VibeId } from './config';
|
||||
export type { VibePreset } from './config';
|
||||
|
||||
export const VIBE_PRESETS: Array<VibePreset> = appConfig.vibes.presets;
|
||||
const VIBE_IDS = new Set<VibeId>(VIBE_PRESETS.map((vibe) => vibe.id));
|
||||
|
||||
const HEX_COLOR_PATTERN =
|
||||
/^#?(?<red>[0-9a-f]{2})(?<green>[0-9a-f]{2})(?<blue>[0-9a-f]{2})$/i;
|
||||
|
|
@ -18,11 +20,14 @@ export const hexToRgb = (hex: string): [number, number, number] => {
|
|||
return [parseInt(red, 16) / 255, parseInt(green, 16) / 255, parseInt(blue, 16) / 255];
|
||||
};
|
||||
|
||||
export const isVibeId = (value: unknown): value is VibeId =>
|
||||
typeof value === 'string' && VIBE_IDS.has(value as VibeId);
|
||||
|
||||
export const getInitialVibe = (): VibePreset => {
|
||||
const id = readBrowserStorage(appConfig.storage.vibeKey);
|
||||
return (
|
||||
VIBE_PRESETS.find((vibe) => vibe.id === id) ??
|
||||
VIBE_PRESETS.find((vibe) => vibe.id === appConfig.vibes.defaultVibeId) ??
|
||||
VIBE_PRESETS[0]
|
||||
);
|
||||
const storedVibeId = readBrowserStorage(appConfig.storage.vibeKey);
|
||||
const initialVibeId = isVibeId(storedVibeId)
|
||||
? storedVibeId
|
||||
: appConfig.vibes.defaultVibeId;
|
||||
|
||||
return VIBE_PRESETS.find((vibe) => vibe.id === initialVibeId) ?? VIBE_PRESETS[0];
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue