From caf1fc43755c1cfa328127a30491af6d521d8a92 Mon Sep 17 00:00:00 2001
From: vince
Date: Mon, 15 Jul 2024 23:22:00 +0800
Subject: [PATCH] perf: optimize interface color matching
---
internal/tailwind-config/src/index.ts | 197 ++++++++++--------
package.json | 1 -
.../@core/forward/preferences/src/config.ts | 2 +-
.../forward/preferences/src/constants.ts | 4 +-
.../preferences/src/preferences.test.ts | 2 +-
.../design/src/design-tokens/dark/index.css | 26 ++-
.../src/design-tokens/default/index.css | 54 +++--
packages/@core/shared/toolkit/package.json | 4 +-
.../shared/toolkit/src/colorful/generator.ts | 30 ++-
.../src/components/layout-content.vue | 2 +-
.../src/components/layout-footer.vue | 13 +-
.../src/components/layout-header.vue | 12 +-
.../src/components/layout-sidebar.vue | 2 +-
.../src/components/layout-tabbar.vue | 20 +-
.../ui-kit/layout-ui/src/vben-layout.vue | 6 +-
.../ui/context-menu/ContextMenu.vue | 4 +-
.../ui/dropdown-menu/DropdownMenu.vue | 4 +-
.../src/components/tabs-chrome/tabs.vue | 30 +--
.../tabs-ui/src/components/tabs/tabs.vue | 22 +-
.../src/components/widgets/tool-more.vue | 2 +-
.../src/components/widgets/tool-screen.vue | 2 +-
.../src/authentication/authentication.vue | 44 ++--
.../{from-view.vue => form.vue} | 6 +-
.../layouts/src/authentication/toolbar.vue | 2 +-
.../widgets/global-search/global-search.vue | 2 +-
.../widgets/preferences/preferences-sheet.vue | 4 +-
pnpm-lock.yaml | 22 +-
27 files changed, 270 insertions(+), 249 deletions(-)
rename packages/effects/layouts/src/authentication/{from-view.vue => form.vue} (83%)
diff --git a/internal/tailwind-config/src/index.ts b/internal/tailwind-config/src/index.ts
index 59396133..247d518d 100644
--- a/internal/tailwind-config/src/index.ts
+++ b/internal/tailwind-config/src/index.ts
@@ -24,30 +24,86 @@ packages.forEach((pkg) => {
}
});
-function createColorsPattern(name: string) {
- return {
- 100: `hsl(var(--${name}-100))`,
- 200: `hsl(var(--${name}-200))`,
- 300: `hsl(var(--${name}-300))`,
- 400: `hsl(var(--${name}-400))`,
- 500: `hsl(var(--${name}-500))`,
- 600: `hsl(var(--${name}-600))`,
- 700: `hsl(var(--${name}-700))`,
- 800: `hsl(var(--${name}-800))`,
- 900: `hsl(var(--${name}-900))`,
- 1000: `hsl(var(--${name}-1000))`,
- active: `hsl(var(--${name}-700))`,
- background: `hsl(var(--${name}-100))`,
- 'background-hover': `hsl(var(--${name}-200))`,
- border: `hsl(var(--${name}-300))`,
- 'border-hover': `hsl(var(--${name}-400))`,
- foreground: `hsl(var(--${name}-foreground))`,
- hover: `hsl(var(--${name}-500))`,
- text: `hsl(var(--${name}-900))`,
- 'text-active': `hsl(var(--${name}-1000))`,
- 'text-hover': `hsl(var(--${name}-800))`,
- };
-}
+const shadcnUiColors = {
+ accent: {
+ DEFAULT: 'hsl(var(--accent))',
+ foreground: 'hsl(var(--accent-foreground))',
+ hover: 'hsl(var(--accent-hover))',
+ },
+ background: {
+ DEFAULT: 'hsl(var(--background))',
+ content: 'hsl(var(--background-content))',
+ },
+ border: 'hsl(var(--border))',
+ card: {
+ DEFAULT: 'hsl(var(--card))',
+ foreground: 'hsl(var(--card-foreground))',
+ },
+ destructive: {
+ ...createColorsPattern('destructive'),
+ DEFAULT: 'hsl(var(--destructive))',
+ },
+
+ foreground: 'hsl(var(--foreground))',
+
+ input: {
+ DEFAULT: 'hsl(var(--input))',
+ background: 'hsl(var(--input-background))',
+ },
+ muted: {
+ DEFAULT: 'hsl(var(--muted))',
+ foreground: 'hsl(var(--muted-foreground))',
+ },
+ popover: {
+ DEFAULT: 'hsl(var(--popover))',
+ foreground: 'hsl(var(--popover-foreground))',
+ },
+ primary: {
+ ...createColorsPattern('primary'),
+ DEFAULT: 'hsl(var(--primary))',
+ },
+
+ ring: 'hsl(var(--ring))',
+ secondary: {
+ DEFAULT: 'hsl(var(--secondary))',
+ desc: 'hsl(var(--secondary-desc))',
+ foreground: 'hsl(var(--secondary-foreground))',
+ },
+};
+
+const customColors = {
+ authentication: {
+ DEFAULT: 'hsl(var(--authentication))',
+ },
+ green: {
+ ...createColorsPattern('green'),
+ foreground: 'hsl(var(--success-foreground))',
+ },
+ heavy: {
+ DEFAULT: 'hsl(var(--heavy))',
+ foreground: 'hsl(var(--heavy-foreground))',
+ },
+ main: {
+ DEFAULT: 'hsl(var(--main))',
+ },
+ overlay: 'hsl(var(--overlay))',
+ red: {
+ ...createColorsPattern('red'),
+ foreground: 'hsl(var(--destructive-foreground))',
+ },
+ success: {
+ ...createColorsPattern('success'),
+ DEFAULT: 'hsl(var(--success))',
+ },
+ warning: {
+ ...createColorsPattern('warning'),
+ DEFAULT: 'hsl(var(--warning))',
+ },
+ yellow: {
+ ...createColorsPattern('yellow'),
+ foreground: 'hsl(var(--warning-foreground))',
+ },
+};
export default {
content: [
@@ -93,71 +149,8 @@ export default {
xl: 'calc(var(--radius) + 4px)',
},
colors: {
- accent: {
- DEFAULT: 'hsl(var(--accent))',
- foreground: 'hsl(var(--accent-foreground))',
- hover: 'hsl(var(--accent-hover))',
- },
- authentication: 'hsl(var(--authentication))',
- background: 'hsl(var(--background))',
- border: 'hsl(var(--border))',
- card: {
- DEFAULT: 'hsl(var(--card))',
- foreground: 'hsl(var(--card-foreground))',
- },
- destructive: {
- ...createColorsPattern('destructive'),
- DEFAULT: 'hsl(var(--destructive))',
- },
-
- foreground: 'hsl(var(--foreground))',
- green: {
- ...createColorsPattern('green'),
- foreground: 'hsl(var(--success-foreground))',
- },
- heavy: {
- DEFAULT: 'hsl(var(--heavy))',
- foreground: 'hsl(var(--heavy-foreground))',
- },
- input: {
- DEFAULT: 'hsl(var(--input))',
- background: 'hsl(var(--input-background))',
- },
- muted: {
- DEFAULT: 'hsl(var(--muted))',
- foreground: 'hsl(var(--muted-foreground))',
- },
- overlay: 'hsl(var(--overlay))',
- popover: {
- DEFAULT: 'hsl(var(--popover))',
- foreground: 'hsl(var(--popover-foreground))',
- },
- primary: {
- ...createColorsPattern('primary'),
- DEFAULT: 'hsl(var(--primary))',
- },
- red: {
- ...createColorsPattern('red'),
- foreground: 'hsl(var(--destructive-foreground))',
- },
- ring: 'hsl(var(--ring))',
- secondary: {
- DEFAULT: 'hsl(var(--secondary))',
- desc: 'hsl(var(--secondary-desc))',
- foreground: 'hsl(var(--secondary-foreground))',
- },
- success: {
- ...createColorsPattern('success'),
- DEFAULT: 'hsl(var(--success))',
- },
- warning: {
- ...createColorsPattern('warning'),
- DEFAULT: 'hsl(var(--warning))',
- },
- yellow: {
- ...createColorsPattern('yellow'),
- foreground: 'hsl(var(--warning-foreground))',
- },
+ ...customColors,
+ ...shadcnUiColors,
},
fontFamily: {
sans: [
@@ -195,3 +188,29 @@ export default {
},
},
} as Config;
+
+function createColorsPattern(name: string) {
+ return {
+ 50: `hsl(var(--${name}-50))`,
+ 100: `hsl(var(--${name}-100))`,
+ 200: `hsl(var(--${name}-200))`,
+ 300: `hsl(var(--${name}-300))`,
+ 400: `hsl(var(--${name}-400))`,
+ 500: `hsl(var(--${name}-500))`,
+ 600: `hsl(var(--${name}-600))`,
+ 700: `hsl(var(--${name}-700))`,
+ 800: `hsl(var(--${name}-800))`,
+ 900: `hsl(var(--${name}-900))`,
+ 950: `hsl(var(--${name}-950))`,
+ active: `hsl(var(--${name}-600))`,
+ background: `hsl(var(--${name}-50))`,
+ 'background-hover': `hsl(var(--${name}-100))`,
+ border: `hsl(var(--${name}-200))`,
+ 'border-hover': `hsl(var(--${name}-300))`,
+ foreground: `hsl(var(--${name}-foreground))`,
+ hover: `hsl(var(--${name}-400))`,
+ text: `hsl(var(--${name}-800))`,
+ 'text-active': `hsl(var(--${name}-900))`,
+ 'text-hover': `hsl(var(--${name}-700))`,
+ };
+}
diff --git a/package.json b/package.json
index ca031024..1c9222cd 100644
--- a/package.json
+++ b/package.json
@@ -84,7 +84,6 @@
"packageManager": "pnpm@9.5.0",
"pnpm": {
"overrides": {
- "@ant-design/colors": "^7.1.0",
"@ctrl/tinycolor": "^4.1.0",
"clsx": "^2.1.1",
"eslint": "^8.57.0",
diff --git a/packages/@core/forward/preferences/src/config.ts b/packages/@core/forward/preferences/src/config.ts
index ed02ce48..f6766fff 100644
--- a/packages/@core/forward/preferences/src/config.ts
+++ b/packages/@core/forward/preferences/src/config.ts
@@ -79,7 +79,7 @@ const defaultPreferences: Preferences = {
theme: {
builtinType: 'default',
colorDestructive: 'hsl(348 100% 61%)',
- colorPrimary: 'hsl(245 82% 67%)',
+ colorPrimary: 'hsl(231 98% 65%)',
colorSuccess: 'hsl(144 57% 58%)',
colorWarning: 'hsl(42 84% 61%)',
mode: 'dark',
diff --git a/packages/@core/forward/preferences/src/constants.ts b/packages/@core/forward/preferences/src/constants.ts
index 7a638aba..5a510000 100644
--- a/packages/@core/forward/preferences/src/constants.ts
+++ b/packages/@core/forward/preferences/src/constants.ts
@@ -31,11 +31,11 @@ const SUPPORT_LANGUAGES: Language[] = [
const BUILT_IN_THEME_PRESETS: BuiltinThemePreset[] = [
{
- color: 'hsl(245 82% 67%)',
+ color: 'hsl(231 98% 65%)',
type: 'default',
},
{
- color: 'hsl(231 98% 65%)',
+ color: 'hsl(245 82% 67%)',
type: 'violet',
},
{
diff --git a/packages/@core/forward/preferences/src/preferences.test.ts b/packages/@core/forward/preferences/src/preferences.test.ts
index 5b003dca..83050f4f 100644
--- a/packages/@core/forward/preferences/src/preferences.test.ts
+++ b/packages/@core/forward/preferences/src/preferences.test.ts
@@ -25,7 +25,7 @@ describe('preferences', () => {
});
it('initPreferences should initialize preferences with overrides and namespace', async () => {
- const overrides = { theme: { colorPrimary: 'hsl(245 82% 67%)' } };
+ const overrides = { theme: { colorPrimary: 'hsl(231 98% 65%)' } };
const namespace = 'testNamespace';
await preferenceManager.initPreferences({ namespace, overrides });
diff --git a/packages/@core/shared/design/src/design-tokens/dark/index.css b/packages/@core/shared/design/src/design-tokens/dark/index.css
index 968987f0..0e7735be 100644
--- a/packages/@core/shared/design/src/design-tokens/dark/index.css
+++ b/packages/@core/shared/design/src/design-tokens/dark/index.css
@@ -2,17 +2,20 @@
:root.dark[data-theme='custom'],
:root.dark[data-theme='default'] {
/* Default background color of ...etc */
- --background: 220deg 13.04% 8%;
+ --background: 222.34deg 10.43% 12.27%;
+
+ /* 主体区域背景色 */
+ --background-content: 220deg 13.06% 9%;
--foreground: 220 13% 91%;
/* Background color for */
- --card: 222.86deg 8.43% 16.27%;
+ --card: 222.34deg 10.43% 12.27%;
/* --card: 222.2 84% 4.9%; */
--card-foreground: 210 40% 98%;
/* Background color for popovers such as , , */
- --popover: 222.86deg 8.43% 16.27%;
+ --popover: 222.82deg 8.43% 16.27%;
--popover-foreground: 210 40% 98%;
/* Muted backgrounds such as , and */
@@ -53,7 +56,7 @@
--heavy-foreground: var(--accent-foreground);
/* Default border color */
- --border: 0deg 0% 100% / 10%;
+ --border: 215 27.9% 16.9%;
/* Border color for inputs such as , , */
--input: 0deg 0% 100% / 10%;
@@ -63,20 +66,25 @@
/* Used for focus ring */
--ring: 222.2 84% 4.9%;
+ /* 基本圆角大小 */
+ --radius: 0.5rem;
+
+ /* ============= Custom ============= */
+
/* 遮罩颜色 */
--overlay: 0deg 0% 0% / 40%;
/* 基本文字大小 */
--font-size-base: 16px;
- /* 基本圆角大小 */
- --radius: 0.5rem;
+ /* 主体内容背景色 */
+ --content: 240 11% 96%;
+
+ /* 登录背景色 */
+ --authentication: 220deg 13.06% 3.04%;
/* =============component & UI============= */
- /* authentication */
- --authentication: 240deg 11% 2%;
-
color-scheme: dark;
}
diff --git a/packages/@core/shared/design/src/design-tokens/default/index.css b/packages/@core/shared/design/src/design-tokens/default/index.css
index 8bcf1892..2fe917af 100644
--- a/packages/@core/shared/design/src/design-tokens/default/index.css
+++ b/packages/@core/shared/design/src/design-tokens/default/index.css
@@ -5,7 +5,10 @@
'Segoe UI Symbol';
/* Default background color of