更新变量注释和颜色分类

This commit is contained in:
lutinglt
2025-06-28 16:32:16 +08:00
parent 59497be05e
commit 94c7f81bbf
7 changed files with 52 additions and 27 deletions

View File

@@ -1,52 +1,78 @@
import { rgba } from "polished"; import { rgba } from "polished";
import { scaleColorLight } from "src/functions"; import { scaleColorLight } from "src/functions";
import type { Ansi, Based, Console, Diff, Message, Named, Primary, Secondary } from "src/types"; import type { Ansi, Other, Console, Diff, Message, Named, Primary, Secondary } from "src/types";
import { themeVars } from "src/types/vars"; import { themeVars } from "src/types/vars";
import type { Theme } from "./theme"; import type { Theme } from "./theme";
interface ColorTheme { interface ColorTheme {
/** 用于标识当前是否为暗色主题: `true` 暗色 `false` 亮色 */
isDarkTheme: boolean; isDarkTheme: boolean;
/** 主色调 */
primary: string; primary: string;
/** 主色调的对比色, 一般用于 `color` 属性, primary 用于 `background-color` */
primaryContrast: string; primaryContrast: string;
/** 副色调 */
secondary: string; secondary: string;
/** 红色 */
red: string; red: string;
/** 橙色 */
orange: string; orange: string;
/** 黄色 */
yellow: string; yellow: string;
/** 黄绿色/橄榄色 */
olive: string; olive: string;
/** 绿色 */
green: string; green: string;
/** 青色/蓝绿色 */
teal: string; teal: string;
/** 蓝色 */
blue: string; blue: string;
/** 蓝紫色/紫罗兰色 */
violet: string; violet: string;
/** 紫色 */
purple: string; purple: string;
/** 粉红色 */
pink: string; pink: string;
/** 棕色 */
brown: string; brown: string;
/** 黑色 */
black: string; black: string;
/** 灰色 */
grey: string; grey: string;
/** 金色 */
gold: string; gold: string;
/** 白色 */
white: string; white: string;
/** Action 日志 */
console: Console; console: Console;
/** 提交代码对比 */
diff: Diff; diff: Diff;
based: Based; /** 其他 */
other: Other;
} }
/** 定义颜色, 用于生成颜色主题 /** 定义颜色, 用于生成颜色主题
* @example * @example
* 文件名: `color-dark.css.ts` * 文件名: "dark.css.tsx"
* import type { Primary } from "src/types"; * import type { Console, Diff, Other } from "src/types";
* import { defineTheme, themeVars } from "src"; * import { defineTheme, themeVars } from "src";
* *
* const primary: Primary = { * const console: Console = {
* self: "#ffffff", * fg: {
* contrast: themeVars.color.white, * self: "#f0f6fc", // self 表示本身等于 --color-console-fg: #f0f6fc, 所有键名为 self 的都将被忽略
* subtle: themeVars.color.body, // 引用别的CSS变量等于 --color-console-fg-subtle: var(--color-body)
* num1: "rgb(125, 133, 144)", // 由于纯数字无法在 TS 中使用点调用, 采用 num 前缀等于 --color-console-fg-1: rgb(125, 133, 144)
* },
* ... * ...
* } * }
* * ...
* export default defineTheme({ * export default defineTheme({
* isDarkTheme: "true", * isDarkTheme: true,
* color: { * primary: "#0969da",
* primary,
* ... * ...
* } * console,
* diff,
* other,
* }) * })
*/ */
export function defineTheme(theme: ColorTheme): Theme { export function defineTheme(theme: ColorTheme): Theme {
@@ -267,22 +293,22 @@ export function defineTheme(theme: ColorTheme): Theme {
active: rgba(theme.red, 0.5), active: rgba(theme.red, 0.5),
hover: rgba(theme.red, 0.3), hover: rgba(theme.red, 0.3),
}, },
border: scaleColorLight(theme.red, 30 * lighten), border: scaleColorLight(theme.red, 20 * lighten),
text: theme.red, text: theme.red,
}, },
success: { success: {
bg: rgba(theme.green, 0.1), bg: rgba(theme.green, 0.1),
border: scaleColorLight(theme.green, 30 * lighten), border: scaleColorLight(theme.green, 20 * lighten),
text: theme.green, text: theme.green,
}, },
warning: { warning: {
bg: rgba(theme.yellow, 0.1), bg: rgba(theme.yellow, 0.1),
border: scaleColorLight(theme.yellow, 30 * lighten), border: scaleColorLight(theme.yellow, 20 * lighten),
text: theme.yellow, text: theme.yellow,
}, },
info: { info: {
bg: rgba(theme.blue, 0.1), bg: rgba(theme.blue, 0.1),
border: scaleColorLight(theme.blue, 30 * lighten), border: scaleColorLight(theme.blue, 20 * lighten),
text: theme.blue, text: theme.blue,
}, },
}; };
@@ -318,7 +344,7 @@ export function defineTheme(theme: ColorTheme): Theme {
console: theme.console, console: theme.console,
diff: theme.diff, diff: theme.diff,
...message, ...message,
...theme.based, ...theme.other,
}, },
}; };
} }

View File

@@ -1,4 +1,4 @@
export { css } from "@linaria/core"; export { css } from "@linaria/core";
export { defineTheme } from "./core/color"; export { defineTheme } from "./core/color";
export type { Based, Console, Diff } from "./types"; export type { Other, Console, Diff } from "./types";
export { themeVars } from "./types/vars"; export { themeVars } from "./types/vars";

View File

@@ -1,4 +1,4 @@
export { based } from "./based"; export { other } from "./other";
export { ansi, console } from "./console"; export { ansi, console } from "./console";
export { diff } from "./diff"; export { diff } from "./diff";
export { primary, secondary } from "./main"; export { primary, secondary } from "./main";

View File

@@ -1,4 +1,4 @@
export const based = { export const other = {
/** 未知 */ /** 未知 */
git: null, git: null,
/** 主要背景色 */ /** 主要背景色 */

View File

@@ -8,4 +8,4 @@ export type Message = MapLeafNodes<typeof color.message, string>;
export type Ansi = MapLeafNodes<typeof color.ansi, string>; export type Ansi = MapLeafNodes<typeof color.ansi, string>;
export type Console = MapLeafNodes<typeof color.console, string>; export type Console = MapLeafNodes<typeof color.console, string>;
export type Diff = MapLeafNodes<typeof color.diff, string>; export type Diff = MapLeafNodes<typeof color.diff, string>;
export type Based = MapLeafNodes<typeof color.based, string>; export type Other = MapLeafNodes<typeof color.other, string>;

View File

@@ -11,11 +11,10 @@ export function varMapper(value: string | null, path: string[]) {
} }
const vars = { const vars = {
/** 用于标识当前是否为暗色主题: `"true"` 暗色 `"false"` 亮色 */
isDarkTheme: "is-dark-theme", isDarkTheme: "is-dark-theme",
color: { color: {
...color.other,
...color.message, ...color.message,
...color.based,
...color.named, ...color.named,
primary: color.primary, primary: color.primary,
secondary: color.secondary, secondary: color.secondary,

View File

@@ -1,4 +1,4 @@
import type { Based, Console, Diff } from "src"; import type { Other, Console, Diff } from "src";
import { defineTheme, themeVars } from "src"; import { defineTheme, themeVars } from "src";
const console: Console = { const console: Console = {
@@ -50,7 +50,7 @@ const diff: Diff = {
inactive: "#353846", inactive: "#353846",
}; };
const based: Based = { const other: Other = {
git: "#f05133", git: "#f05133",
body: "#0d1117", body: "#0d1117",
box: { box: {
@@ -164,5 +164,5 @@ export default defineTheme({
white: "#ffffff", white: "#ffffff",
console, console,
diff, diff,
based, other,
}); });