Update editor, workspace, Git services, appearance, and project guides
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { customThemes } from './customThemes.ts';
|
||||
export const APPEARANCE_KEY = 'runestone.appearance';
|
||||
export const THEMES = ['default', 'claude', 'sakura'] as const;
|
||||
export type ThemeName = typeof THEMES[number] | `custom:${string}`;
|
||||
export type Appearance = { theme: ThemeName; mode: 'light' | 'dark' };
|
||||
export const DEFAULT_APPEARANCE: Appearance = { theme: 'default', mode: 'dark' };
|
||||
export function normalizeAppearance(value: { theme?: unknown; mode?: unknown } | null): Appearance {
|
||||
const theme: ThemeName = typeof value?.theme === 'string' && (/^custom:[a-z][a-z0-9-]{0,63}$/.test(value.theme) || (THEMES as readonly string[]).includes(value.theme)) ? value.theme as ThemeName : 'default';
|
||||
return { theme, mode: theme === 'sakura' || value?.mode === 'light' ? 'light' : 'dark' };
|
||||
}
|
||||
export function parseAppearance(raw: string | null): Appearance {
|
||||
try { return normalizeAppearance(JSON.parse(raw || 'null')); }
|
||||
catch { return { ...DEFAULT_APPEARANCE }; }
|
||||
}
|
||||
const keys = ['bg', 'bg-elevated', 'bg-active', 'border', 'text-dim', 'text', 'text-strong', 'accent', 'selection'] as const;
|
||||
const palettes = {
|
||||
default: {
|
||||
dark: ['#141414','#1c1c1c','#2a2a2a','#2e2e2e','#9a9a9a','#e6e6e6','#f3f3f3','#82aaff','#264f78'],
|
||||
light: ['#f3f3f3','#ffffff','#e8e8e8','#d4d4d4','#626262','#1e1e1e','#111111','#315fb3','#add6ff'],
|
||||
},
|
||||
// Anthropic brand guidelines: https://github.com/anthropics/skills/blob/main/skills/brand-guidelines/SKILL.md
|
||||
claude: {
|
||||
dark: ['#141413','#20201e','#32322e','#5a5952','#b0aea5','#faf9f5','#faf9f5','#d97757','#674435'],
|
||||
light: ['#faf9f5','#faf9f5','#e8e6dc','#b0aea5','#67665f','#141413','#141413','#d97757','#e8e6dc'],
|
||||
},
|
||||
// Palette from pm-image:7968b79c-9d80-40a5-9e9a-696c26aacfb9. Sakura supports light mode only.
|
||||
sakura: {
|
||||
light: ['#fefcfc','#fefcfc','#dbeacb','#f8dbe6','#687788','#513346','#321c2a','#98556c','#ffc9dc'],
|
||||
},
|
||||
};
|
||||
export function applyAppearance(value: Appearance, root = document.documentElement) {
|
||||
const { theme, mode } = normalizeAppearance(value);
|
||||
root.dataset.theme = mode;
|
||||
root.dataset.palette = theme;
|
||||
root.style.colorScheme = mode;
|
||||
const palette = theme === 'sakura' ? palettes.sakura.light : palettes[theme === 'claude' ? 'claude' : 'default'][mode];
|
||||
keys.forEach((key, index) => root.style.setProperty(`--rs-${key}`, palette[index]));
|
||||
root.style.setProperty('--rs-accent-2', theme === 'claude' ? '#6a9bcc' : theme === 'sakura' ? '#607fa9' : 'var(--rs-accent)');
|
||||
root.style.setProperty('--rs-accent-dim', 'color-mix(in srgb, var(--rs-accent) 80%, var(--rs-bg))');
|
||||
root.style.setProperty('--rs-accent-deep', 'color-mix(in srgb, var(--rs-accent) 60%, var(--rs-bg))');
|
||||
const semantic = mode === 'light' ? ['#b42323', '#8a5700', '#806600', '#287b29', '#7740a5']
|
||||
: ['#f44747', '#d68a00', '#cca700', '#89d185', '#c792ea'];
|
||||
if (theme === 'claude') { semantic[3] = '#788c5d'; semantic[4] = '#6a9bcc'; }
|
||||
if (theme === 'sakura') { semantic[3] = '#618c71'; semantic[4] = '#cb6b91'; }
|
||||
['error', 'warn-hot', 'warn', 'ok', 'special'].forEach((key, index) => root.style.setProperty(`--rs-${key}`, semantic[index]));
|
||||
const syntax = theme === 'sakura'
|
||||
? ['#cb6b91', '#98556c', '#618c71', '#69a2bd', '#607fa9', '#687788']
|
||||
: ['var(--rs-special)', 'var(--rs-accent)', 'var(--rs-text)', 'var(--rs-accent-2)', 'var(--rs-accent-2)', 'var(--rs-text-dim)'];
|
||||
['parameter', 'keyword', 'local', 'static', 'instance', 'global'].forEach((key, index) => root.style.setProperty(`--rs-syntax-${key}`, syntax[index]));
|
||||
root.style.setProperty('--rs-danger', 'var(--rs-error)');
|
||||
const custom = theme.startsWith('custom:') ? customThemes().find(item => item.id === theme.slice(7)) : undefined;
|
||||
if (custom) for (const [key, color] of Object.entries(custom[mode])) root.style.setProperty(`--rs-${key}`, color);
|
||||
window.dispatchEvent(new CustomEvent('runestone-theme-changed'));
|
||||
}
|
||||
export function saveAppearance(value: Appearance) {
|
||||
const appearance = normalizeAppearance(value);
|
||||
localStorage.setItem(APPEARANCE_KEY, JSON.stringify(appearance));
|
||||
applyAppearance(appearance);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user