feat: theme colors (#1195)
This commit is contained in:
parent
2e79f3aa37
commit
8753a94aae
19 changed files with 298 additions and 35 deletions
31
scripts/generate-themes.ts
Normal file
31
scripts/generate-themes.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import chroma from 'chroma-js'
|
||||
import type { ThemeColors } from '~/composables/settings'
|
||||
|
||||
// #cc7d24 -> hcl(67.14,62.19,59.56)
|
||||
export const themesColor = Array.from(
|
||||
{ length: 9 },
|
||||
(_, i) => chroma.hcl((67.14 + i * 40) % 360, 62.19, 59.56).hex(),
|
||||
)
|
||||
|
||||
export function getThemeColors(primary: string): ThemeColors {
|
||||
const c = chroma(primary)
|
||||
const dc = c.brighten(0.1)
|
||||
|
||||
return {
|
||||
'--theme-color-name': primary,
|
||||
|
||||
'--c-primary': 'rgb(var(--rgb-primary))',
|
||||
'--c-primary-active': c.darken(0.5).hex(),
|
||||
'--c-primary-light': c.alpha(0.5).hex(),
|
||||
'--c-primary-fade': c.darken(0.1).alpha(0.1).hex(),
|
||||
'--rgb-primary': c.rgb().join(', '),
|
||||
|
||||
'--c-dark-primary': 'rgb(var(--rgb-dark-primary))',
|
||||
'--c-dark-primary-active': dc.darken(0.5).hex(),
|
||||
'--c-dark-primary-light': dc.alpha(0.5).hex(),
|
||||
'--c-dark-primary-fade': dc.darken(0.1).alpha(0.1).hex(),
|
||||
'--rgb-dark-primary': c.rgb().join(', '),
|
||||
}
|
||||
}
|
||||
|
||||
export const colorsMap = themesColor.map(color => [color, getThemeColors(color)])
|
|
@ -1,12 +1,16 @@
|
|||
import { copy } from 'fs-extra'
|
||||
import fs from 'fs-extra'
|
||||
import { emojiPrefix, iconifyEmojiPackage } from '../config/emojis'
|
||||
import { colorsMap } from './generate-themes'
|
||||
|
||||
const dereference = process.platform === 'win32' ? true : undefined
|
||||
|
||||
await copy('node_modules/shiki-es/dist/assets', 'public/shiki/', {
|
||||
await fs.copy('node_modules/shiki-es/dist/assets', 'public/shiki/', {
|
||||
dereference,
|
||||
filter: src => src === 'node_modules/shiki/' || src.includes('languages') || src.includes('dist'),
|
||||
})
|
||||
await copy('node_modules/theme-vitesse/themes', 'public/shiki/themes', { dereference })
|
||||
await copy('node_modules/theme-vitesse/themes', 'node_modules/shiki/themes', { overwrite: true, dereference })
|
||||
await copy(`node_modules/${iconifyEmojiPackage}/icons`, `public/emojis/${emojiPrefix}`, { overwrite: true, dereference })
|
||||
await fs.copy('node_modules/theme-vitesse/themes', 'public/shiki/themes', { dereference })
|
||||
await fs.copy('node_modules/theme-vitesse/themes', 'node_modules/shiki/themes', { overwrite: true, dereference })
|
||||
await fs.copy(`node_modules/${iconifyEmojiPackage}/icons`, `public/emojis/${emojiPrefix}`, { overwrite: true, dereference })
|
||||
|
||||
await fs.writeJSON('constants/themes.json', colorsMap, { spaces: 2, EOL: '\n' })
|
||||
await fs.writeFile('styles/default-theme.css', `:root {\n${Object.entries(colorsMap[0][1]).map(([k, v]) => ` ${k}: ${v};`).join('\n')}\n}\n`, { encoding: 'utf-8' })
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue