|
|
@@ -5,7 +5,16 @@
|
|
|
import ModeSwitch from '$lib/modeSwitch/ModeSwitch.svelte';
|
|
|
import { currentColorStore } from '../../../store';
|
|
|
import themes, { type ThemeItem } from '../../../data/themes';
|
|
|
- import { generatePalette, generateThemeBlack, generateThemeWhite, colorConvertFunc, throttle, hexToRgb } from '../../../utils';
|
|
|
+ import {
|
|
|
+ generatePalette,
|
|
|
+ generateThemeBlack,
|
|
|
+ generateThemeWhite,
|
|
|
+ colorConvertFunc,
|
|
|
+ throttle,
|
|
|
+ hexToRgb,
|
|
|
+ getOklchFunc,
|
|
|
+ getHexFunc
|
|
|
+ } from '../../../utils';
|
|
|
import colorList from '../../../data/color';
|
|
|
import GeneratorPreview from './GeneratorPreview.svelte';
|
|
|
import hljs from 'highlight.js';
|
|
|
@@ -26,7 +35,7 @@
|
|
|
let extendListStr = ' {';
|
|
|
extendList.forEach((item) => {
|
|
|
extendListStr += `
|
|
|
- color: '${hexToRgb(item.color)}', // ${item.color} ${colorConvertFunc(item.color).hsl}
|
|
|
+ color: '${colorConvertFunc(item.color).oklch}', // ${item.color} ${colorConvertFunc(item.color).hsl}
|
|
|
alias: "${item.alias}",
|
|
|
},`;
|
|
|
extendListStr += `
|
|
|
@@ -34,29 +43,28 @@
|
|
|
});
|
|
|
// 如果 extendListStr 最后一个是换行符,则删除换行
|
|
|
extendListStr = extendListStr.slice(0, extendListStr.lastIndexOf('\n'));
|
|
|
- // extendListStr = extendListStr.slice(0, extendListStr.lastIndexOf(',') + 1);
|
|
|
return extendListStr;
|
|
|
};
|
|
|
// 使用 extendList 返回 extendListStr2
|
|
|
const extendListStrFunc2 = (extendList: { color: string; alias: string }[]) => {
|
|
|
let extendListStr = '';
|
|
|
extendList.forEach((item, index) => {
|
|
|
- extendListStr += `--theme-color-extend${index}: ${hexToRgb(item.color)};
|
|
|
+ extendListStr += ` --color-extend${index}: ${getOklchFunc(item.color)};
|
|
|
+ --color-${item.alias}: ${getOklchFunc(item.color)};
|
|
|
`;
|
|
|
});
|
|
|
// 如果 extendListStr 最后一个是换行符,则删除换行
|
|
|
extendListStr = extendListStr.slice(0, extendListStr.lastIndexOf('\n'));
|
|
|
- // extendListStr = extendListStr.slice(0, extendListStr.lastIndexOf(',') + 1);
|
|
|
return extendListStr;
|
|
|
};
|
|
|
const numbers = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
|
let colors = $state([
|
|
|
- { type: 'primary', color: initTheme.theme.color.primary.default },
|
|
|
- { type: 'dark', color: initTheme.theme.color.dark.default },
|
|
|
- { type: 'success', color: initTheme.theme.color.functional.success },
|
|
|
- { type: 'warning', color: initTheme.theme.color.functional.warning },
|
|
|
- { type: 'error', color: initTheme.theme.color.functional.error },
|
|
|
- { type: 'info', color: initTheme.theme.color.functional.info }
|
|
|
+ { type: 'primary', color: initTheme.theme.color.primary.default, hex: getHexFunc(initTheme.theme.color.primary.default) },
|
|
|
+ { type: 'dark', color: initTheme.theme.color.dark.default, hex: getHexFunc(initTheme.theme.color.dark.default) },
|
|
|
+ { type: 'success', color: initTheme.theme.color.functional.success, hex: getHexFunc(initTheme.theme.color.functional.success) },
|
|
|
+ { type: 'warning', color: initTheme.theme.color.functional.warning, hex: getHexFunc(initTheme.theme.color.functional.warning) },
|
|
|
+ { type: 'error', color: initTheme.theme.color.functional.error, hex: getHexFunc(initTheme.theme.color.functional.error) },
|
|
|
+ { type: 'info', color: initTheme.theme.color.functional.info, hex: getHexFunc(initTheme.theme.color.functional.info) }
|
|
|
]);
|
|
|
let currentColorObj = {
|
|
|
name: '',
|
|
|
@@ -67,25 +75,24 @@
|
|
|
extend: [{ color: '', alias: '' }]
|
|
|
}
|
|
|
};
|
|
|
- let primaryColors: { hex: string; hsl: string; n: number; rgb: string }[] = $state([]);
|
|
|
- let darkColors: { hex: string; hsl: string; n: number; rgb: string }[] = $state([]);
|
|
|
+ let primaryColors: { hex: string; hsl: string; n: number; rgb: string; oklch: string }[] = $state([]);
|
|
|
+ let darkColors: { hex: string; hsl: string; n: number; rgb: string; oklch: string }[] = $state([]);
|
|
|
let themeBlack = $state({
|
|
|
- primary: { hex: '', hsl: '', rgb: '' },
|
|
|
- dark: { hex: '', hsl: '', rgb: '' }
|
|
|
+ primary: { hex: '', hsl: '', rgb: '', oklch: '' },
|
|
|
+ dark: { hex: '', hsl: '', rgb: '', oklch: '' }
|
|
|
});
|
|
|
let themeWhite = $state({
|
|
|
- primary: { hex: '', hsl: '', rgb: '' },
|
|
|
- dark: { hex: '', hsl: '', rgb: '' }
|
|
|
+ primary: { hex: '', hsl: '', rgb: '', oklch: '' },
|
|
|
+ dark: { hex: '', hsl: '', rgb: '', oklch: '' }
|
|
|
});
|
|
|
let stateColor = $state({ success: '', warning: '', error: '', info: '' });
|
|
|
- let extendList: { color: string; alias: string }[] = $state(initTheme.theme.color.extend);
|
|
|
+ let extendList: { color: string; alias: string; hex: string }[] = $state(initTheme.theme.color.extend);
|
|
|
+
|
|
|
let name = $state(initTheme.name);
|
|
|
let showCopyTip = $state(false);
|
|
|
let showCopyTip2 = $state(false);
|
|
|
- let extendListStr;
|
|
|
- $effect(() => {
|
|
|
- extendListStr = extendListStrFunc(extendList);
|
|
|
- });
|
|
|
+ let extendListStr = $derived(extendListStrFunc(extendList));
|
|
|
+
|
|
|
let extendListStr2 = $derived(extendListStrFunc2(extendList));
|
|
|
|
|
|
let configStr = $derived(
|
|
|
@@ -94,40 +101,40 @@
|
|
|
name: '${name}',
|
|
|
color: {
|
|
|
primary: {
|
|
|
- 50: '${hexToRgb(primaryColors[0].hex)}', // ${primaryColors[0].hex} ${primaryColors[0].hsl}
|
|
|
- 100: '${hexToRgb(primaryColors[1].hex)}', // ${primaryColors[1].hex} ${primaryColors[1].hsl}
|
|
|
- 200: '${hexToRgb(primaryColors[2].hex)}', // ${primaryColors[2].hex} ${primaryColors[2].hsl}
|
|
|
- 300: '${hexToRgb(primaryColors[3].hex)}', // ${primaryColors[3].hex} ${primaryColors[3].hsl}
|
|
|
- 400: '${hexToRgb(primaryColors[4].hex)}', // ${primaryColors[4].hex} ${primaryColors[4].hsl}
|
|
|
- 500: '${hexToRgb(primaryColors[5].hex)}', // ${primaryColors[5].hex} ${primaryColors[5].hsl}
|
|
|
- default: '${hexToRgb(primaryColors[6].hex)}', // ${primaryColors[6].hex} ${primaryColors[6].hsl}
|
|
|
- 700: '${hexToRgb(primaryColors[7].hex)}', // ${primaryColors[7].hex} ${primaryColors[7].hsl}
|
|
|
- 800: '${hexToRgb(primaryColors[8].hex)}', // ${primaryColors[8].hex} ${primaryColors[8].hsl}
|
|
|
- 900: '${hexToRgb(primaryColors[9].hex)}', // ${primaryColors[9].hex} ${primaryColors[9].hsl}
|
|
|
- 950: '${hexToRgb(primaryColors[10].hex)}', // ${primaryColors[10].hex} ${primaryColors[10].hsl}
|
|
|
+ 50: '${primaryColors[0].oklch}', // ${primaryColors[0].hex} ${primaryColors[0].hsl}
|
|
|
+ 100: '${primaryColors[1].oklch}', // ${primaryColors[1].hex} ${primaryColors[1].hsl}
|
|
|
+ 200: '${primaryColors[2].oklch}', // ${primaryColors[2].hex} ${primaryColors[2].hsl}
|
|
|
+ 300: '${primaryColors[3].oklch}', // ${primaryColors[3].hex} ${primaryColors[3].hsl}
|
|
|
+ 400: '${primaryColors[4].oklch}', // ${primaryColors[4].hex} ${primaryColors[4].hsl}
|
|
|
+ 500: '${primaryColors[5].oklch}', // ${primaryColors[5].hex} ${primaryColors[5].hsl}
|
|
|
+ default: '${primaryColors[6].oklch}', // ${primaryColors[6].hex} ${primaryColors[6].hsl}
|
|
|
+ 700: '${primaryColors[7].oklch}', // ${primaryColors[7].hex} ${primaryColors[7].hsl}
|
|
|
+ 800: '${primaryColors[8].oklch}', // ${primaryColors[8].hex} ${primaryColors[8].hsl}
|
|
|
+ 900: '${primaryColors[9].oklch}', // ${primaryColors[9].hex} ${primaryColors[9].hsl}
|
|
|
+ 950: '${primaryColors[10].oklch}', // ${primaryColors[10].hex} ${primaryColors[10].hsl}
|
|
|
},
|
|
|
dark: {
|
|
|
- 50: '${hexToRgb(darkColors[0].hex)}', // ${darkColors[0].hex} ${darkColors[0].hsl}
|
|
|
- 100: '${hexToRgb(darkColors[1].hex)}', // ${darkColors[1].hex} ${darkColors[1].hsl}
|
|
|
- 200: '${hexToRgb(darkColors[2].hex)}', // ${darkColors[2].hex} ${darkColors[2].hsl}
|
|
|
- 300: '${hexToRgb(darkColors[3].hex)}', // ${darkColors[3].hex} ${darkColors[3].hsl}
|
|
|
- 400: '${hexToRgb(darkColors[4].hex)}', // ${darkColors[4].hex} ${darkColors[4].hsl}
|
|
|
- 500: '${hexToRgb(darkColors[5].hex)}', // ${darkColors[5].hex} ${darkColors[5].hsl}
|
|
|
- default: '${hexToRgb(darkColors[6].hex)}', // ${darkColors[6].hex} ${darkColors[6].hsl}
|
|
|
- 700: '${hexToRgb(darkColors[7].hex)}', // ${darkColors[7].hex} ${darkColors[7].hsl}
|
|
|
- 800: '${hexToRgb(darkColors[8].hex)}', // ${darkColors[8].hex} ${darkColors[8].hsl}
|
|
|
- 900: '${hexToRgb(darkColors[9].hex)}', // ${darkColors[9].hex} ${darkColors[9].hsl}
|
|
|
- 950: '${hexToRgb(darkColors[10].hex)}', // ${darkColors[10].hex} ${darkColors[10].hsl}
|
|
|
+ 50: '${darkColors[0].oklch}', // ${darkColors[0].hex} ${darkColors[0].hsl}
|
|
|
+ 100: '${darkColors[1].oklch}', // ${darkColors[1].hex} ${darkColors[1].hsl}
|
|
|
+ 200: '${darkColors[2].oklch}', // ${darkColors[2].hex} ${darkColors[2].hsl}
|
|
|
+ 300: '${darkColors[3].oklch}', // ${darkColors[3].hex} ${darkColors[3].hsl}
|
|
|
+ 400: '${darkColors[4].oklch}', // ${darkColors[4].hex} ${darkColors[4].hsl}
|
|
|
+ 500: '${darkColors[5].oklch}', // ${darkColors[5].hex} ${darkColors[5].hsl}
|
|
|
+ default: '${darkColors[6].oklch}', // ${darkColors[6].hex} ${darkColors[6].hsl}
|
|
|
+ 700: '${darkColors[7].oklch}', // ${darkColors[7].hex} ${darkColors[7].hsl}
|
|
|
+ 800: '${darkColors[8].oklch}', // ${darkColors[8].hex} ${darkColors[8].hsl}
|
|
|
+ 900: '${darkColors[9].oklch}', // ${darkColors[9].hex} ${darkColors[9].hsl}
|
|
|
+ 950: '${darkColors[10].oklch}', // ${darkColors[10].hex} ${darkColors[10].hsl}
|
|
|
},
|
|
|
- primaryBlack: '${hexToRgb(themeBlack.primary.hex)}', // ${themeBlack.primary.hex} ${themeBlack.primary.hsl}
|
|
|
- primaryWhite: '${hexToRgb(themeWhite.primary.hex)}', // ${themeWhite.primary.hex} ${themeWhite.primary.hsl}
|
|
|
- darkBlack: '${hexToRgb(themeBlack.dark.hex)}', // ${themeBlack.dark.hex} ${themeBlack.dark.hsl}
|
|
|
- darkWhite: '${hexToRgb(themeWhite.dark.hex)}', // ${themeWhite.dark.hex} ${themeWhite.dark.hsl}
|
|
|
+ primaryBlack: '${getOklchFunc(themeBlack.primary.hex)}', // ${themeBlack.primary.hex} ${themeBlack.primary.hsl}
|
|
|
+ primaryWhite: '${getOklchFunc(themeWhite.primary.hex)}', // ${themeWhite.primary.hex} ${themeWhite.primary.hsl}
|
|
|
+ darkBlack: '${getOklchFunc(themeBlack.dark.hex)}', // ${themeBlack.dark.hex} ${themeBlack.dark.hsl}
|
|
|
+ darkWhite: '${getOklchFunc(themeWhite.dark.hex)}', // ${themeWhite.dark.hex} ${themeWhite.dark.hsl}
|
|
|
functional: {
|
|
|
- success: '${hexToRgb(stateColor.success)}', // ${stateColor.success} ${colorConvertFunc(stateColor.success).hsl}
|
|
|
- warning: '${hexToRgb(stateColor.warning)}', // ${stateColor.warning} ${colorConvertFunc(stateColor.warning).hsl}
|
|
|
- error: '${hexToRgb(stateColor.error)}', // ${stateColor.error} ${colorConvertFunc(stateColor.error).hsl}
|
|
|
- info: '${hexToRgb(stateColor.info)}', // ${stateColor.info} ${colorConvertFunc(stateColor.info).hsl}
|
|
|
+ success: '${getOklchFunc(stateColor.success)}', // ${stateColor.success} ${colorConvertFunc(stateColor.success).hsl}
|
|
|
+ warning: '${getOklchFunc(stateColor.warning)}', // ${stateColor.warning} ${colorConvertFunc(stateColor.warning).hsl}
|
|
|
+ error: '${getOklchFunc(stateColor.error)}', // ${stateColor.error} ${colorConvertFunc(stateColor.error).hsl}
|
|
|
+ info: '${getOklchFunc(stateColor.info)}', // ${stateColor.info} ${colorConvertFunc(stateColor.info).hsl}
|
|
|
},
|
|
|
extend: [
|
|
|
${extendListStr}
|
|
|
@@ -139,38 +146,60 @@ color: {
|
|
|
|
|
|
let configStr2 = $derived(
|
|
|
hljs.highlight(
|
|
|
- `/* ${isZh ? '初始 CSS 变量' : 'Initial CSS variables'} */
|
|
|
---theme-color-primary-50: ${hexToRgb(primaryColors[0].hex)};
|
|
|
---theme-color-primary-100: ${hexToRgb(primaryColors[1].hex)};
|
|
|
---theme-color-primary-200: ${hexToRgb(primaryColors[2].hex)};
|
|
|
---theme-color-primary-300: ${hexToRgb(primaryColors[3].hex)};
|
|
|
---theme-color-primary-400: ${hexToRgb(primaryColors[4].hex)};
|
|
|
---theme-color-primary-500: ${hexToRgb(primaryColors[5].hex)};
|
|
|
---theme-color-primary: ${hexToRgb(primaryColors[6].hex)};
|
|
|
---theme-color-primary-700: ${hexToRgb(primaryColors[7].hex)};
|
|
|
---theme-color-primary-800: ${hexToRgb(primaryColors[8].hex)};
|
|
|
---theme-color-primary-900: ${hexToRgb(primaryColors[9].hex)};
|
|
|
---theme-color-primary-950: ${hexToRgb(primaryColors[10].hex)};
|
|
|
---theme-color-dark-50: ${hexToRgb(darkColors[0].hex)};
|
|
|
---theme-color-dark-100: ${hexToRgb(darkColors[1].hex)};
|
|
|
---theme-color-dark-200: ${hexToRgb(darkColors[2].hex)};
|
|
|
---theme-color-dark-300: ${hexToRgb(darkColors[3].hex)};
|
|
|
---theme-color-dark-400: ${hexToRgb(darkColors[4].hex)};
|
|
|
---theme-color-dark-500: ${hexToRgb(darkColors[5].hex)};
|
|
|
---theme-color-dark: ${hexToRgb(darkColors[6].hex)};
|
|
|
---theme-color-dark-700: ${hexToRgb(darkColors[7].hex)};
|
|
|
---theme-color-dark-800: ${hexToRgb(darkColors[8].hex)};
|
|
|
---theme-color-dark-900: ${hexToRgb(darkColors[9].hex)};
|
|
|
---theme-color-dark-950: ${hexToRgb(darkColors[10].hex)};
|
|
|
---theme-color-primaryBlack: ${hexToRgb(themeBlack.primary.hex)};
|
|
|
---theme-color-primaryWhite: ${hexToRgb(themeWhite.primary.hex)};
|
|
|
---theme-color-darkBlack: ${hexToRgb(themeBlack.dark.hex)};
|
|
|
---theme-color-darkWhite: ${hexToRgb(themeWhite.dark.hex)};
|
|
|
---theme-color-functional-success: ${hexToRgb(stateColor.success)};
|
|
|
---theme-color-functional-warning: ${hexToRgb(stateColor.warning)};
|
|
|
---theme-color-functional-error: ${hexToRgb(stateColor.error)};
|
|
|
---theme-color-functional-info: ${hexToRgb(stateColor.info)};
|
|
|
-${extendListStr2}`,
|
|
|
+ `/* ${isZh ? '初始主题 CSS 变量' : 'Initial theme CSS variables'} */
|
|
|
+@theme {
|
|
|
+ --color-primary-50: ${primaryColors[0].oklch};
|
|
|
+ --color-primary-100: ${primaryColors[1].oklch};
|
|
|
+ --color-primary-200: ${primaryColors[2].oklch};
|
|
|
+ --color-primary-300: ${primaryColors[3].oklch};
|
|
|
+ --color-primary-400: ${primaryColors[4].oklch};
|
|
|
+ --color-primary-500: ${primaryColors[5].oklch};
|
|
|
+ --color-primary: ${primaryColors[6].oklch};
|
|
|
+ --color-primary-700: ${primaryColors[7].oklch};
|
|
|
+ --color-primary-800: ${primaryColors[8].oklch};
|
|
|
+ --color-primary-900: ${primaryColors[9].oklch};
|
|
|
+ --color-primary-950: ${primaryColors[10].oklch};
|
|
|
+
|
|
|
+ --color-dark-50: ${darkColors[0].oklch};
|
|
|
+ --color-dark-100: ${darkColors[1].oklch};
|
|
|
+ --color-dark-200: ${darkColors[2].oklch};
|
|
|
+ --color-dark-300: ${darkColors[3].oklch};
|
|
|
+ --color-dark-400: ${darkColors[4].oklch};
|
|
|
+ --color-dark-500: ${darkColors[5].oklch};
|
|
|
+ --color-dark: ${darkColors[6].oklch};
|
|
|
+ --color-dark-700: ${darkColors[7].oklch};
|
|
|
+ --color-dark-800: ${darkColors[8].oklch};
|
|
|
+ --color-dark-900: ${darkColors[9].oklch};
|
|
|
+ --color-dark-950: ${darkColors[10].oklch};
|
|
|
+
|
|
|
+ --color-primaryBlack: ${getOklchFunc(themeBlack.primary.hex)};
|
|
|
+ --color-primaryWhite: ${getOklchFunc(themeWhite.primary.hex)};
|
|
|
+ --color-darkBlack: ${getOklchFunc(themeBlack.dark.hex)};
|
|
|
+ --color-darkWhite: ${getOklchFunc(themeWhite.dark.hex)};
|
|
|
+
|
|
|
+ --color-success: ${getOklchFunc(stateColor.success)};
|
|
|
+ --color-warning: ${getOklchFunc(stateColor.warning)};
|
|
|
+ --color-error: ${getOklchFunc(stateColor.error)};
|
|
|
+ --color-info: ${getOklchFunc(stateColor.info)};
|
|
|
+
|
|
|
+${extendListStr2}
|
|
|
+
|
|
|
+ --color-black: oklch(0 0 0);
|
|
|
+ --color-white: oklch(1 0 0);
|
|
|
+ --color-gray-50: oklch(0.961 0 0);
|
|
|
+ --color-gray-100: oklch(0.925 0 0);
|
|
|
+ --color-gray-200: oklch(0.845 0 0);
|
|
|
+ --color-gray-300: oklch(0.767 0 0);
|
|
|
+ --color-gray-400: oklch(0.683 0 0);
|
|
|
+ --color-gray-500: oklch(0.6 0 0);
|
|
|
+ --color-gray-600: oklch(0.51 0 0);
|
|
|
+ --color-gray-700: oklch(0.42 0 0);
|
|
|
+ --color-gray-800: oklch(0.321 0 0);
|
|
|
+ --color-gray-900: oklch(0.218 0 0);
|
|
|
+ --color-gray-950: oklch(0.159 0 0);
|
|
|
+ --color-transparent: transparent;
|
|
|
+}
|
|
|
+`,
|
|
|
{ language: 'css', ignoreIllegals: true }
|
|
|
).value
|
|
|
);
|
|
|
@@ -183,35 +212,33 @@ ${extendListStr2}`,
|
|
|
console.error('颜色列表长度必须为 11');
|
|
|
return;
|
|
|
}
|
|
|
- const colorArr: { hex: string; hsl: string; n: number; rgb: string }[] = [];
|
|
|
+ const colorArr: { hex: string; hsl: string; n: number; rgb: string; oklch: string }[] = [];
|
|
|
colorList.forEach((item, index) => {
|
|
|
// 第 0 项和最后一项的 key 为 50 和 950,其他项为 100-900,颜色有 hex、rgb、hsl 三种格式,注意 hsl 保留整数
|
|
|
- let colorObj: { hex: string; hsl: string; n: number; rgb: string } = {
|
|
|
- hex: '',
|
|
|
- hsl: '',
|
|
|
- n: 0,
|
|
|
- rgb: ''
|
|
|
- };
|
|
|
+ let colorObj: { hex: string; hsl: string; n: number; rgb: string; oklch: string } = { hex: '', hsl: '', n: 0, rgb: '', oklch: '' };
|
|
|
if (index === 0) {
|
|
|
colorObj = {
|
|
|
n: 50,
|
|
|
hex: item,
|
|
|
rgb: colorConvertFunc(item).rgb,
|
|
|
- hsl: colorConvertFunc(item).hsl
|
|
|
+ hsl: colorConvertFunc(item).hsl,
|
|
|
+ oklch: colorConvertFunc(item).oklch
|
|
|
};
|
|
|
} else if (index === 10) {
|
|
|
colorObj = {
|
|
|
n: 950,
|
|
|
hex: item,
|
|
|
rgb: colorConvertFunc(item).rgb,
|
|
|
- hsl: colorConvertFunc(item).hsl
|
|
|
+ hsl: colorConvertFunc(item).hsl,
|
|
|
+ oklch: colorConvertFunc(item).oklch
|
|
|
};
|
|
|
} else {
|
|
|
colorObj = {
|
|
|
n: 100 * index,
|
|
|
hex: item,
|
|
|
rgb: colorConvertFunc(item).rgb,
|
|
|
- hsl: colorConvertFunc(item).hsl
|
|
|
+ hsl: colorConvertFunc(item).hsl,
|
|
|
+ oklch: colorConvertFunc(item).oklch
|
|
|
};
|
|
|
}
|
|
|
colorArr.push(colorObj);
|
|
|
@@ -225,6 +252,7 @@ ${extendListStr2}`,
|
|
|
hsl: string;
|
|
|
n: number;
|
|
|
rgb: string;
|
|
|
+ oklch: string;
|
|
|
}[];
|
|
|
|
|
|
darkColors = createTWColorFunc(darkColorList) as {
|
|
|
@@ -232,6 +260,7 @@ ${extendListStr2}`,
|
|
|
hsl: string;
|
|
|
n: number;
|
|
|
rgb: string;
|
|
|
+ oklch: string;
|
|
|
}[];
|
|
|
|
|
|
// 根据主题色生成主题黑和白
|
|
|
@@ -275,7 +304,8 @@ ${extendListStr2}`,
|
|
|
const newColors = [...colors];
|
|
|
const item = newColors.find((item) => item.type === type);
|
|
|
if (item) {
|
|
|
- item.color = colorValue;
|
|
|
+ item.color = colorValue.indexOf('#') === 0 ? colorValue : getOklchFunc(colorValue);
|
|
|
+ item.hex = colorValue.indexOf('#') === 0 ? colorValue : getHexFunc(colorValue);
|
|
|
}
|
|
|
colors = newColors;
|
|
|
if (type === 'primary') {
|
|
|
@@ -323,18 +353,21 @@ ${extendListStr2}`,
|
|
|
newColors.forEach((item) => {
|
|
|
if (item.type === 'primary') {
|
|
|
item.color = currentColorObj.color.primary.default;
|
|
|
+ item.hex = getHexFunc(currentColorObj.color.primary.default);
|
|
|
} else if (item.type === 'dark') {
|
|
|
item.color = currentColorObj.color.dark.default;
|
|
|
+ item.hex = getHexFunc(currentColorObj.color.dark.default);
|
|
|
} else {
|
|
|
// 确保 item.type 是 functional 对象中的有效键
|
|
|
if (item.type in currentColorObj.color.functional) {
|
|
|
item.color = currentColorObj.color.functional[item.type as keyof typeof currentColorObj.color.functional];
|
|
|
+ item.hex = getHexFunc(currentColorObj.color.functional[item.type as keyof typeof currentColorObj.color.functional]);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
colors = newColors;
|
|
|
name = currentColorObj.name;
|
|
|
- extendList = currentColorObj.color.extend;
|
|
|
+ extendList = currentColorObj.color.extend.map((item) => ({ ...item, hex: getHexFunc(item.color) }));
|
|
|
});
|
|
|
// svelte 组件销毁时取消订阅
|
|
|
onDestroy(() => {
|
|
|
@@ -351,6 +384,8 @@ ${extendListStr2}`,
|
|
|
];
|
|
|
name = `${randomDarkColor.name}/${randomLightColor.name}`;
|
|
|
// 根据随机颜色生成主题
|
|
|
+ console.log(111, randomDarkColor);
|
|
|
+
|
|
|
changeFunc('primary', null, randomDarkColor.hex);
|
|
|
changeFunc('dark', null, randomLightColor.hex);
|
|
|
// 获取当前 extendList 的长度
|
|
|
@@ -362,10 +397,9 @@ ${extendListStr2}`,
|
|
|
.slice(0, extendListLength);
|
|
|
let newExtendList = [];
|
|
|
newExtendList = randomExtendList.map((item) => {
|
|
|
- return { color: item.hex, alias: item.name };
|
|
|
+ return { color: item.hex, alias: item.name, hex: getHexFunc(item.hex) };
|
|
|
});
|
|
|
extendList = newExtendList;
|
|
|
- extendListStr = extendListStrFunc(extendList);
|
|
|
};
|
|
|
// 重置事件
|
|
|
const resetFunc = () => {
|
|
|
@@ -377,7 +411,6 @@ ${extendListStr2}`,
|
|
|
let newExtendList = [...extendList];
|
|
|
newExtendList.splice(i, 1);
|
|
|
extendList = newExtendList;
|
|
|
- extendListStr = extendListStrFunc(extendList);
|
|
|
};
|
|
|
// 选择 extendList 的颜色
|
|
|
const changeExtendFunc = (e: Event, i: number) => {
|
|
|
@@ -385,7 +418,6 @@ ${extendListStr2}`,
|
|
|
let newExtendList = [...extendList];
|
|
|
newExtendList[i].color = colorValue;
|
|
|
extendList = newExtendList;
|
|
|
- extendListStr = extendListStrFunc(extendList);
|
|
|
};
|
|
|
// 输入 extendList 的别名
|
|
|
const inputExtendFunc = (e: Event, i: number) => {
|
|
|
@@ -393,14 +425,12 @@ ${extendListStr2}`,
|
|
|
let newExtendList = [...extendList];
|
|
|
newExtendList[i].alias = aliasValue;
|
|
|
extendList = newExtendList;
|
|
|
- extendListStr = extendListStrFunc(extendList);
|
|
|
};
|
|
|
// 新增扩展色
|
|
|
const addExtendFunc = () => {
|
|
|
let newExtendList = [...extendList];
|
|
|
- newExtendList.push({ color: '#000000', alias: '' });
|
|
|
+ newExtendList.push({ color: '#000000', alias: '', hex: getHexFunc('#000000') });
|
|
|
extendList = newExtendList;
|
|
|
- extendListStr = extendListStrFunc(extendList);
|
|
|
};
|
|
|
// 监听窗口变化
|
|
|
const windowResizeFun = () => {
|
|
|
@@ -457,7 +487,7 @@ ${extendListStr2}`,
|
|
|
<div class="text-left">{isZh ? '主题名称' : 'Theme name'}</div>
|
|
|
<div class="flex-1">
|
|
|
<input
|
|
|
- class="w-full rounded-sm bg-transparent px-1 py-1 text-sm outline outline-1 outline-black/10 focus:outline-none focus:outline-primary dark:outline-white/20 dark:focus:outline-dark"
|
|
|
+ class="focus:outline-primary dark:focus:outline-dark rounded-xs focus:outline-hidden w-full bg-transparent px-1 py-1 text-sm outline outline-black/10 dark:outline-white/20"
|
|
|
type="text"
|
|
|
bind:value={name}
|
|
|
placeholder={isZh ? '请输入主题名称' : 'Please enter theme name'}
|
|
|
@@ -466,44 +496,45 @@ ${extendListStr2}`,
|
|
|
</div>
|
|
|
<div class="mt-4 flex gap-2">
|
|
|
<div class="flex flex-col gap-4 text-center">
|
|
|
- <!-- 输入框 -->
|
|
|
+ <!-- 输入框 主题色与功能色 -->
|
|
|
{#each colors as item, i}
|
|
|
- <div class="flex justify-end gap-2 {i === 2 ? 'mt-6' : 'mt-0'} relative">
|
|
|
- <div class="flex-1 text-right">{item.type}</div>
|
|
|
- <input
|
|
|
- type="color"
|
|
|
- bind:value={item.color}
|
|
|
- oninput={(e) => throttle(() => changeFunc(item.type, e, item.color), 100)()}
|
|
|
- class="h-6 w-6 flex-none cursor-pointer"
|
|
|
- style="background-color: {item.color};"
|
|
|
- onclick={() => (showTip = false)}
|
|
|
- />
|
|
|
- <div class="w-20 flex-none overflow-hidden text-left text-sm leading-6">
|
|
|
- {item.color}
|
|
|
+ <div class="{i === 2 ? 'mt-6' : 'mt-0'} relative">
|
|
|
+ <!-- <div class="mb-1 text-left text-xs">{getOklchFunc(item.color)}</div> -->
|
|
|
+ <div class="flex items-center gap-2">
|
|
|
+ <input
|
|
|
+ type="color"
|
|
|
+ bind:value={item.hex}
|
|
|
+ oninput={(e) => throttle(() => changeFunc(item.type, e, item.color), 100)()}
|
|
|
+ class="h-6 w-6 flex-none cursor-pointer"
|
|
|
+ style="background-color: {item.color};"
|
|
|
+ onclick={() => (showTip = false)}
|
|
|
+ />
|
|
|
+ <span>{item.type}</span>
|
|
|
</div>
|
|
|
{#if i === 0 && showTip}
|
|
|
- <div class="pointer-events-none absolute right-[4.4rem] rotate-[135deg]">
|
|
|
+ <div class="pointer-events-none absolute left-2 top-0 rotate-[135deg]">
|
|
|
<div class="animate-bounce text-3xl">👇</div>
|
|
|
</div>
|
|
|
{/if}
|
|
|
</div>
|
|
|
{/each}
|
|
|
- <div class="mt-6 flex flex-col gap-4 overflow-y-auto p-1" style="height: {windowHeight - 480}px;">
|
|
|
+ <!-- 扩展色 -->
|
|
|
+ <div class="mt-6 flex flex-col gap-4 overflow-y-auto" style="height: {windowHeight - 480}px;">
|
|
|
{#each extendList as item, i}
|
|
|
<div class="flex flex-col gap-2">
|
|
|
- <div class="flex justify-end gap-2">
|
|
|
- <div class="flex-1 text-right">extend{i}</div>
|
|
|
+ <div class="flex gap-2">
|
|
|
<input
|
|
|
type="color"
|
|
|
- bind:value={item.color}
|
|
|
- class="h-6 w-6 flex-none"
|
|
|
+ bind:value={item.hex}
|
|
|
+ class="h-6 w-6"
|
|
|
style="background-color: {item.color};"
|
|
|
- oninput={(e) => throttle(() => changeExtendFunc(e, i))}
|
|
|
+ oninput={(e) => throttle(() => changeExtendFunc(e, i), 100)()}
|
|
|
/>
|
|
|
- <div class="w-16 flex-none overflow-hidden text-left text-sm leading-6">
|
|
|
+ <div>extend{i}</div>
|
|
|
+ <!-- <div class="w-16 flex-none overflow-hidden text-left text-sm leading-6">
|
|
|
{item.color}
|
|
|
- </div>
|
|
|
- <button aria-label="delete" class="rounded bg-black/5 px-1 dark:bg-white/10" onclick={() => deleteFunc(i)}>
|
|
|
+ </div> -->
|
|
|
+ <button aria-label="delete" class="rounded-sm bg-black/5 px-1 dark:bg-white/10" onclick={() => deleteFunc(i)}>
|
|
|
<svg class="h-4 w-6 transition-all hover:scale-90" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
|
|
<path
|
|
|
class="fill-error"
|
|
|
@@ -513,9 +544,9 @@ ${extendListStr2}`,
|
|
|
</svg>
|
|
|
</button>
|
|
|
</div>
|
|
|
- <div class="flex">
|
|
|
+ <div class="flex px-0.5">
|
|
|
<input
|
|
|
- class="h-6 w-full rounded-sm bg-transparent px-1 py-1 text-xs outline outline-1 outline-black/10 focus:outline-none focus:outline-primary dark:outline-white/20 dark:focus:outline-dark"
|
|
|
+ class="focus:outline-primary dark:focus:outline-dark rounded-xs focus:outline-hidden h-6 w-full bg-transparent px-1 py-1 text-xs outline outline-black/10 dark:outline-white/20"
|
|
|
type="text"
|
|
|
bind:value={item.alias}
|
|
|
placeholder={isZh ? `请输入 extend${i} 别名` : `Please enter extend${i} alias`}
|
|
|
@@ -526,7 +557,7 @@ ${extendListStr2}`,
|
|
|
{/each}
|
|
|
<div>
|
|
|
<button
|
|
|
- class="items-centers flex w-full justify-center gap-2 rounded border border-primary py-1.5 text-sm text-black dark:border-dark dark:text-white"
|
|
|
+ class="items-centers border-primary dark:border-dark flex w-full justify-center gap-2 rounded-sm border py-1.5 text-sm text-black dark:text-white"
|
|
|
onclick={addExtendFunc}
|
|
|
>
|
|
|
<span>
|
|
|
@@ -547,8 +578,8 @@ ${extendListStr2}`,
|
|
|
<div class="mb-1 flex flex-1 justify-between gap-1">
|
|
|
{#each primaryColors as color, index}
|
|
|
<div
|
|
|
- class="h-12 rounded {index >= 5 ? 'text-primaryWhite' : 'text-primaryBlack'}"
|
|
|
- style="background-color: {color.hex};flex: {index === 6 ? '2' : '1'}"
|
|
|
+ class="h-12 rounded-sm {index >= 5 ? 'text-primaryWhite' : 'text-primaryBlack'}"
|
|
|
+ style="background-color: {color.oklch};flex: {index === 6 ? '2' : '1'}"
|
|
|
>
|
|
|
<div class="flex flex-col items-center justify-between">
|
|
|
<div class="flex-1 leading-10 mt-1{index === 6 ? ' text-xl font-bold' : ''}">
|
|
|
@@ -561,8 +592,8 @@ ${extendListStr2}`,
|
|
|
<div class="flex flex-1 justify-between gap-1">
|
|
|
{#each darkColors as color, index}
|
|
|
<div
|
|
|
- class="h-12 rounded {index <= 6 ? 'text-darkBlack' : 'text-darkWhite'}"
|
|
|
- style="background-color: {color.hex};flex: {index === 6 ? '2' : '1'};"
|
|
|
+ class="h-12 rounded-sm {index <= 6 ? 'text-darkBlack' : 'text-darkWhite'}"
|
|
|
+ style="background-color: {color.oklch};flex: {index === 6 ? '2' : '1'};"
|
|
|
>
|
|
|
<div class="flex items-center justify-between">
|
|
|
<div class="flex-1 leading-10 mt-1{index === 6 ? ' text-xl font-bold' : ''}">
|
|
|
@@ -576,8 +607,8 @@ ${extendListStr2}`,
|
|
|
<div class="mt-1 flex justify-between gap-1 px-4 text-center text-xs">
|
|
|
{#each [themeBlack.primary, themeBlack.dark, themeWhite.primary, themeWhite.dark] as item, i}
|
|
|
<div
|
|
|
- class="h-12 flex-1 rounded border pt-4 {i === 0 || i === 1 ? 'border-gray-700 text-white' : 'border-gray-300 text-black'}"
|
|
|
- style="background-color: {item.hex};"
|
|
|
+ class="h-12 flex-1 rounded-sm border pt-4 {i === 0 || i === 1 ? 'border-gray-700 text-white' : 'border-gray-300 text-black'}"
|
|
|
+ style="background-color: {item.oklch};"
|
|
|
>
|
|
|
<div>
|
|
|
{i === 0 ? 'primaryBlack' : i === 1 ? 'darkBlack' : i === 2 ? 'primaryWhite' : 'darkWhite'}
|
|
|
@@ -587,16 +618,16 @@ ${extendListStr2}`,
|
|
|
</div>
|
|
|
<!-- 功能色 -->
|
|
|
<div class="mt-1 flex justify-between gap-1 px-4 text-center text-xs text-white">
|
|
|
- <div class="h-12 flex-1 rounded pt-4" style="background-color: {stateColor.success};">success</div>
|
|
|
- <div class="h-12 flex-1 rounded pt-4" style="background-color: {stateColor.warning};">warning</div>
|
|
|
- <div class="h-12 flex-1 rounded pt-4" style="background-color: {stateColor.error};">error</div>
|
|
|
- <div class="h-12 flex-1 rounded pt-4" style="background-color: {stateColor.info};">info</div>
|
|
|
+ <div class="h-12 flex-1 rounded-sm pt-4" style="background-color: {stateColor.success};">success</div>
|
|
|
+ <div class="h-12 flex-1 rounded-sm pt-4" style="background-color: {stateColor.warning};">warning</div>
|
|
|
+ <div class="h-12 flex-1 rounded-sm pt-4" style="background-color: {stateColor.error};">error</div>
|
|
|
+ <div class="h-12 flex-1 rounded-sm pt-4" style="background-color: {stateColor.info};">info</div>
|
|
|
</div>
|
|
|
<!-- 扩展色 -->
|
|
|
<div class="mt-1 flex h-12 justify-between gap-1 px-4 text-center text-xs text-white">
|
|
|
{#if extendList}
|
|
|
{#each extendList as item, i}
|
|
|
- <div class="flex h-12 flex-1 flex-col justify-center gap-1 rounded py-1" style="background-color: {item.color};">
|
|
|
+ <div class="flex h-12 flex-1 flex-col justify-center gap-1 rounded-sm py-1" style="background-color: {item.color};">
|
|
|
<div class="text-xs">extend{i}</div>
|
|
|
<div>{item.alias}</div>
|
|
|
</div>
|
|
|
@@ -604,17 +635,17 @@ ${extendListStr2}`,
|
|
|
{/if}
|
|
|
</div>
|
|
|
<!-- 配置文件 -->
|
|
|
- <div class="mx-4 mt-1 flex" style="height:{windowHeight - 388}px;width:{windowWidth - 858}px">
|
|
|
+ <div class="mx-4 mt-1 flex" style="height:{windowHeight - 388}px;width:{windowWidth - 858 + 46}px">
|
|
|
<div class="bg-codeLight dark:bg-codeDark relative mr-1 grow">
|
|
|
- <div class="overflow-auto rounded" style="height:{windowHeight - 388}px;width:{((windowWidth - 858) / 5) * 3 - 6}px">
|
|
|
- <article class="prose max-w-none text-xs dark:prose-invert">
|
|
|
+ <div class="overflow-auto rounded-sm" style="height:{windowHeight - 388}px;width:{((windowWidth - 858) / 5) * 3 - 6 + 46}px">
|
|
|
+ <article class="prose dark:prose-invert max-w-none text-xs">
|
|
|
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
|
|
|
<pre><code class="hljs" id="myCodeBlock">{@html configStr}</code></pre>
|
|
|
</article>
|
|
|
</div>
|
|
|
<button
|
|
|
aria-label="copy"
|
|
|
- class="absolute right-0 top-0 rounded-bl bg-black/5 px-3 py-2 text-sm hover:opacity-80 dark:bg-white/10"
|
|
|
+ class="absolute right-0 top-0 rounded-bl-sm bg-black/5 px-3 py-2 text-sm hover:opacity-80 dark:bg-white/10"
|
|
|
id="copyButton"
|
|
|
>
|
|
|
<svg class="h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
|
|
@@ -631,15 +662,15 @@ ${extendListStr2}`,
|
|
|
{/if}
|
|
|
</div>
|
|
|
<div class="bg-codeLight dark:bg-codeDark relative grow">
|
|
|
- <div class="overflow-auto rounded" style="height:{windowHeight - 388}px;width:{((windowWidth - 858) / 5) * 2 + 4}px">
|
|
|
- <article class="prose max-w-none text-xs dark:prose-invert">
|
|
|
+ <div class="overflow-auto rounded-sm" style="height:{windowHeight - 388}px;width:{((windowWidth - 858) / 5) * 2 + 4}px">
|
|
|
+ <article class="prose dark:prose-invert max-w-none text-xs">
|
|
|
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
|
|
|
<pre><code class="hljs" id="myCodeBlock2">{@html configStr2}</code></pre>
|
|
|
</article>
|
|
|
</div>
|
|
|
<button
|
|
|
aria-label="copy"
|
|
|
- class="absolute right-0 top-0 rounded-bl bg-black/5 px-3 py-2 text-sm hover:opacity-80 dark:bg-white/10"
|
|
|
+ class="absolute right-0 top-0 rounded-bl-sm bg-black/5 px-3 py-2 text-sm hover:opacity-80 dark:bg-white/10"
|
|
|
id="copyButton2"
|
|
|
>
|
|
|
<svg class="h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
|
|
@@ -662,13 +693,13 @@ ${extendListStr2}`,
|
|
|
<div class="flex w-full justify-between pb-2">
|
|
|
<div>
|
|
|
<button
|
|
|
- class="rounded bg-primary px-4 py-2 text-xs text-white hover:opacity-90 dark:bg-dark dark:text-black"
|
|
|
+ class="bg-primary dark:bg-dark rounded-sm px-4 py-2 text-xs text-white hover:opacity-90 dark:text-black"
|
|
|
onclick={randomFunc}
|
|
|
>
|
|
|
{isZh ? '随机主题' : 'Random theme'}
|
|
|
</button>
|
|
|
<button
|
|
|
- class="ml-2 rounded border border-primary px-4 py-2 text-xs text-black hover:opacity-90 dark:border-dark dark:text-white"
|
|
|
+ class="border-primary dark:border-dark ml-2 rounded-sm border px-4 py-2 text-xs text-black hover:opacity-90 dark:text-white"
|
|
|
onclick={resetFunc}
|
|
|
>
|
|
|
{isZh ? '重置' : 'Reset'}
|
|
|
@@ -679,7 +710,7 @@ ${extendListStr2}`,
|
|
|
</div>
|
|
|
</div>
|
|
|
<div
|
|
|
- class="h-96 w-[392px] overflow-auto border border-primary/20 bg-primaryWhite dark:border-dark/20 dark:border-gray-700 dark:bg-darkBlack"
|
|
|
+ class="border-primary/20 bg-primaryWhite dark:border-dark/20 dark:bg-darkBlack h-96 w-[392px] overflow-auto border dark:border-gray-700"
|
|
|
style="height:{windowHeight - 130}px"
|
|
|
>
|
|
|
<GeneratorPreview />
|