feat(desktop): 完善灵动岛设计令牌与外观配置
发布官网与文档站 / build (push) Waiting to run

This commit is contained in:
LoveChengke committed 2026-11-17 18:57:32 +08:00
1 parent 195ee3b90a
commit 4449fbd0a1
37 files changed
+1656 -356

No files matched your search

+232 -2
View File
@@ -261,14 +261,236 @@ export const WEEK_PARITY_VALUES: readonly ('ALL' | 'ODD' | 'EVEN')[] = ['ALL', '
/** 一个学期按多少周为一个单双周循环(ClassIsland WeekCountDivTotal 的默认值) */
export const WEEK_PARITY_CYCLE = 2;
/**
* ClassIsland 岛层设计 token 的 TypeScript 单一来源。
*
* CSS 变量在 `packages/ui/src/tokens.css` 中按 `--ci-*` 一一映射;窗口几何、
* 主进程安全区与设置页范围直接复用本对象,避免 TypeScript 与 CSS 各写一套。
* 应用外壳仍使用 `--ch-*` / `--ch-ui-*`,本对象只服务于岛与课程信息层。
*/
export const CLASSISLAND_TOKENS = {
colors: {
light: {
primaryColor: '#00BFFF',
secondaryColor: '#7FFFD4',
accentFallback: '#1E90FF',
accentPaletteFallback: '#1E90FF',
/** ClassIsland 原值 #E4000000(AARRGGBB),CSS 写作 RRGGBBAA。 */
text1: '#000000E4',
/** ClassIsland 浅色主题对 InformativeSecondary 的覆盖值。 */
text2: '#000000C0',
text3: '#00000072',
text4: '#0000005C',
text5: '#0000002E',
textOnAccent: '#FFFFFFFF',
bgBase: '#F3F3F3',
bgSecondary: '#EEEEEE',
bgTertiary: '#F9F9F9',
fillSecondary: '#0000000A',
smoke: '#00000066',
islandBgCustom: '#000000',
strokeIsland: '#00000014',
strokeControl: '#00000024',
strokeDivider: '#00000014',
strokeFlyout: '#0000001B',
fillStrong: '#00000072',
strokeCard: '#00000016',
strokeDrag: '#1E90FF',
strokeTutorial: '#1E90FF',
aqi1: '#228B22',
aqi2: '#CCCC00',
aqi3: '#FF8C00',
aqi4: '#CD5C5C',
aqi5: '#8B0000',
aqi6: '#800080',
weatherRain: '#0000FF',
glowClass: '#FFFF00',
danger: '#CD5C5C',
warningCritical: '#C42B1C',
warningCaution: '#9D5D00',
warningCautionBackground: '#FFF4CE',
},
dark: {
primaryColor: '#00BFFF',
secondaryColor: '#7FFFD4',
accentFallback: '#1E90FF',
accentPaletteFallback: '#1E90FF',
text1: '#FFFFFFFF',
/** ClassIsland 深色主题对 InformativeSecondary 的覆盖值。 */
text2: '#FFFFFFDA',
text3: '#FFFFFFC5',
text4: '#FFFFFF87',
text5: '#FFFFFF5D',
textOnAccent: '#FFFFFFFF',
bgBase: '#202020',
bgSecondary: '#1C1C1C',
bgTertiary: '#282828',
fillSecondary: '#FFFFFF14',
smoke: '#00000066',
islandBgCustom: '#000000',
strokeIsland: '#FFFFFF26',
strokeControl: '#FFFFFF3D',
strokeDivider: '#FFFFFF26',
strokeFlyout: '#FFFFFF33',
fillStrong: '#FFFFFF8A',
strokeCard: '#FFFFFF26',
strokeDrag: '#00BFFF',
strokeTutorial: '#00BFFF',
aqi1: '#3CB371',
aqi2: '#FFFF00',
aqi3: '#FFA500',
aqi4: '#CD5C5C',
aqi5: '#8B0000',
aqi6: '#9370DB',
weatherRain: '#00BFFF',
glowClass: '#FFFF00',
danger: '#CD5C5C',
warningCritical: '#FF99A4',
warningCaution: '#FCE100',
warningCautionBackground: '#433519',
},
},
fonts: {
app: "'HarmonyOS Sans SC', 'Microsoft YaHei UI', 'Noto Sans CJK SC', 'Noto Sans SC', 'PingFang SC', 'Source Han Sans SC', SimHei, 'WenQuanYi Micro Hei', sans-serif",
island:
"'HarmonyOS Sans SC', 'Microsoft YaHei UI', 'Noto Sans CJK SC', 'Noto Sans SC', 'PingFang SC', 'Source Han Sans SC', SimHei, 'WenQuanYi Micro Hei', sans-serif",
harmonyOsSans: "'HarmonyOS Sans SC', 'Microsoft YaHei UI', SimHei",
backend: "'Microsoft YaHei UI'",
iconFluent: "'FluentSystemIcons-Resizable'",
iconLucide: "'lucide'",
iconSf: "'SF-Symbols'",
},
fontWeights: {
thin: 100,
extraLight: 200,
light: 300,
normal: 400,
medium: 500,
semiBold: 600,
bold: 700,
extraBold: 800,
black: 900,
},
fontSizes: {
secondary: 14,
body: 16,
emphasized: 18,
large: 20,
version: 9,
caption: 12,
controlBase: 13,
label: 14,
title: 16,
rolling: 17,
oobeBody: 18,
brand: 20,
weather: 22,
oobeTitle: 32,
inputMin: 1,
inputMax: 40,
inputStep: 0.5,
},
radii: {
island: 8,
islandLocal: 0,
islandMax: 20,
islandStep: 0.5,
popup: 6,
card: 4,
control: 4,
drawer: '8px 8px 0 0',
pill: 999,
iconButton: 14,
oobeButton: 24,
},
spacing: {
islandHeight: 40,
islandPadX: 12,
islandMinWidth: 20,
componentGap: 12,
lineGap: 5,
settingsMaxWidth: 960,
popupPad: 12,
progressHeight: 3,
editbarBottom: 64,
splashWidth: 400,
splashHeight: 100,
},
shadows: {
island: '0 4px 8px 2px #00000048',
mask: '0 8px 32px 0 #00000066',
drawer: '0 8px 32px 0 #00000066',
drawerX: '0 0 8px #00000033',
classicMask: '0 0 8px #000000',
adorn: '0 0 8px #00000066',
},
opacity: {
islandBackground: 0.5,
line: 1,
pointerFaded: 0.05,
maskFrom: 0,
maskTo: 1,
},
layers: {
windowBottom: 0,
windowTop: 1,
content: 0,
mask: 1,
drag: 1,
drawer: 10,
timelineAdorn: 9999,
guide: 10000,
/** 原值 33550336;Web 层用浏览器最大安全整数哨兵表达同一语义。 */
sentinel: 2147483647,
},
dpi: {
/** ClassIsland 的所有视觉值都以 96 DPI 的 CSS px 为基准。 */
basis: 96,
scale: 1,
scaleMin: 0.75,
scaleMax: 2.5,
scaleStep: 0.05,
verticalSafeArea: 20,
tutorialSafeArea: 150,
effectScale: 1,
},
misc: {
rippleStroke: 200,
maskFade: 'linear-gradient(to bottom, #FFFFFF00, #FFFFFF00 65%, #FFFFFFFF)',
scrimTutorial: '#00000099',
debugBackground: '#22222277',
splashBackground: '#11111188',
brandGradientA: '#0C0E1F',
brandGradientB: '#0D1111',
brandDark: '#0D1111',
},
} as const;
/** ClassIsland `IntToFontWeightConverter` 的逐值映射;其他值回落 Normal。 */
export function classislandFontWeight(value: unknown): number {
if (
typeof value === 'number' &&
value >= CLASSISLAND_TOKENS.fontWeights.thin &&
value <= CLASSISLAND_TOKENS.fontWeights.black &&
value % 100 === 0
) {
return value;
}
return CLASSISLAND_TOKENS.fontWeights.normal;
}
/** 灵动岛默认外观(设置页个性化项的初始值,也是区间校验的单一来源) */
export const DEFAULT_ISLAND_APPEARANCE = {
height: 44,
width: 268,
radius: 20,
opacity: 1,
/** 默认强调色采用 Apple 系统蓝(与 WinIsland 的系统色体系一致) */
accent: '#0a84ff',
/** 默认强调色与 ClassIsland 的 PrimaryColor 对齐。 */
accent: CLASSISLAND_TOKENS.colors.light.primaryColor,
/** 0=自定义,1=壁纸主题色,2=跟随系统,3=屏幕主题色;未知值回落兜底色。 */
accentSource: 0,
accentPalette: [CLASSISLAND_TOKENS.colors.light.primaryColor] as string[],
accentPaletteIndex: 0,
fontSize: 13,
animations: true,
speed: 1,
@@ -320,6 +542,14 @@ export const ISLAND_POSITION_LABELS: Record<(typeof ISLAND_POSITIONS)[number], s
'bottom-right': '右下角',
};
/** ClassIsland `ColorSource` 的显示顺序与中文说明。 */
export const ISLAND_ACCENT_SOURCES = [
{ value: 0, label: '自定义颜色' },
{ value: 1, label: '壁纸主题色' },
{ value: 2, label: '跟随系统' },
{ value: 3, label: '屏幕主题色' },
] as const;
/** 视觉风格可选值(参考 WinIsland 的 island_style) */
export const ISLAND_STYLES = ['black', 'glass', 'tinted'] as const;
+170 -42
View File
@@ -1,4 +1,5 @@
import { isDayKey } from './utils.js';
import { CLASSISLAND_TOKENS, classislandFontWeight } from './constants.js';
export const ISLAND_COMPONENTS = [
'date',
@@ -18,21 +19,21 @@ export const ISLAND_COMPONENTS = [
] as const;
/** ClassIsland master:MainWindowLine 与 Models/Settings.cs(2026-10-17 核对)。 */
export const CLASSISLAND_ISLAND_METRICS = {
rowHeight: 40,
horizontalPadding: 12,
radius: 8,
opacity: 0.5,
scale: 1,
scaleMin: 0.75,
scaleMax: 2.5,
radiusMax: 20,
rowHeight: CLASSISLAND_TOKENS.spacing.islandHeight,
horizontalPadding: CLASSISLAND_TOKENS.spacing.islandPadX,
radius: CLASSISLAND_TOKENS.radii.island,
opacity: CLASSISLAND_TOKENS.opacity.islandBackground,
scale: CLASSISLAND_TOKENS.dpi.scale,
scaleMin: CLASSISLAND_TOKENS.dpi.scaleMin,
scaleMax: CLASSISLAND_TOKENS.dpi.scaleMax,
radiusMax: CLASSISLAND_TOKENS.radii.islandMax,
rowSpacingMax: 150,
secondaryFontSize: 14,
bodyFontSize: 16,
emphasizedFontSize: 18,
largeFontSize: 20,
rowSpacing: 5,
fadedOpacity: 0.05,
secondaryFontSize: CLASSISLAND_TOKENS.fontSizes.secondary,
bodyFontSize: CLASSISLAND_TOKENS.fontSizes.body,
emphasizedFontSize: CLASSISLAND_TOKENS.fontSizes.emphasized,
largeFontSize: CLASSISLAND_TOKENS.fontSizes.large,
rowSpacing: CLASSISLAND_TOKENS.spacing.lineGap,
fadedOpacity: CLASSISLAND_TOKENS.opacity.pointerFaded,
} as const;
export type IslandComponentKind = (typeof ISLAND_COMPONENTS)[number];
export interface IslandWeather {
@@ -74,6 +75,13 @@ export interface ComponentAppearance {
cornerRadius: number;
opacity: number;
}
/** 四档核心字号;组件与行级覆盖共用同一字段名。 */
export interface IslandFontSizes {
secondaryFontSize: number;
bodyFontSize: number;
emphasizedFontSize: number;
largeFontSize: number;
}
export interface IslandComponentNode {
id: string;
kind: IslandComponentKind;
@@ -112,6 +120,14 @@ export interface IslandLayoutRow {
main: boolean;
allowNotifications: boolean;
gap: number;
/** 整行透明度,默认 1;不再与背景 alpha 相乘。 */
opacity: number;
/** 是否把四档字号写到这一行根元素,只影响本行。 */
fontOverridesEnabled: boolean;
secondaryFontSize: number;
bodyFontSize: number;
emphasizedFontSize: number;
largeFontSize: number;
nodes: IslandComponentNode[];
}
export interface IslandLayoutScheme {
@@ -123,8 +139,17 @@ export interface IslandLayoutScheme {
scale: number;
color: string;
foreground: string;
/** false 时回落当前亮/暗主题背景。 */
customBackgroundEnabled: boolean;
/** false 时回落当前亮/暗主题的 5 级前景色。 */
customForegroundEnabled: boolean;
opacity: number;
radius: number;
fontWeight: number;
secondaryFontSize: number;
bodyFontSize: number;
emphasizedFontSize: number;
largeFontSize: number;
separated: boolean;
spacing: number;
}
@@ -166,10 +191,21 @@ function defaultExpandedRows(): IslandLayoutRow[] {
main: true,
allowNotifications: false,
gap: 12,
opacity: CLASSISLAND_TOKENS.opacity.line,
fontOverridesEnabled: false,
...defaultCoreFontSizes(),
nodes: [islandNode('date', 'expanded-date'), course],
},
];
}
function defaultCoreFontSizes(): IslandFontSizes {
return {
secondaryFontSize: CLASSISLAND_TOKENS.fontSizes.secondary,
bodyFontSize: CLASSISLAND_TOKENS.fontSizes.body,
emphasizedFontSize: CLASSISLAND_TOKENS.fontSizes.emphasized,
largeFontSize: CLASSISLAND_TOKENS.fontSizes.large,
};
}
export function islandNode(kind: IslandComponentKind, id: string): IslandComponentNode {
return {
id,
@@ -197,19 +233,16 @@ export function islandNode(kind: IslandComponentKind, id: string): IslandCompone
},
appearance: {
resourceOverridingEnabled: false,
secondaryFontSize: 14,
bodyFontSize: 16,
emphasizedFontSize: 18,
largeFontSize: 20,
...defaultCoreFontSizes(),
customForegroundEnabled: false,
foreground: '#ffffff',
foreground: CLASSISLAND_TOKENS.colors.light.textOnAccent,
customBackgroundEnabled: false,
background: '#202024',
background: CLASSISLAND_TOKENS.colors.light.islandBgCustom,
customBackgroundOpacityEnabled: false,
backgroundOpacity: 0.5,
backgroundOpacity: CLASSISLAND_TOKENS.opacity.islandBackground,
customCornerRadiusEnabled: false,
cornerRadius: 16,
opacity: 1,
cornerRadius: CLASSISLAND_TOKENS.radii.island,
opacity: CLASSISLAND_TOKENS.opacity.line,
},
advanced: { hideRules: [], align: 'stretch', width: 0, maxWidth: 0 },
};
@@ -234,6 +267,9 @@ export function defaultIslandLayouts(): IslandLayoutSettings {
main: true,
allowNotifications: true,
gap: 12,
opacity: CLASSISLAND_TOKENS.opacity.line,
fontOverridesEnabled: false,
...defaultCoreFontSizes(),
nodes: [
islandNode('date', 'date'),
islandNode('clock', 'clock'),
@@ -243,12 +279,16 @@ export function defaultIslandLayouts(): IslandLayoutSettings {
},
],
scale: 1,
color: '#000000',
foreground: '#ffffff',
opacity: 0.5,
radius: 8,
color: CLASSISLAND_TOKENS.colors.light.islandBgCustom,
foreground: CLASSISLAND_TOKENS.colors.light.textOnAccent,
customBackgroundEnabled: true,
customForegroundEnabled: true,
opacity: CLASSISLAND_TOKENS.opacity.islandBackground,
radius: CLASSISLAND_TOKENS.radii.island,
fontWeight: CLASSISLAND_TOKENS.fontWeights.medium,
...defaultCoreFontSizes(),
separated: false,
spacing: 5,
spacing: CLASSISLAND_TOKENS.spacing.lineGap,
},
],
};
@@ -304,19 +344,44 @@ export function normalizeIslandLayouts(input: unknown): IslandLayoutSettings {
},
appearance: {
resourceOverridingEnabled: a.resourceOverridingEnabled === true,
secondaryFontSize: clamp(a.secondaryFontSize, 8, 96, 14),
bodyFontSize: clamp(a.bodyFontSize, 8, 96, 16),
emphasizedFontSize: clamp(a.emphasizedFontSize, 8, 96, 18),
largeFontSize: clamp(a.largeFontSize, 8, 128, 20),
secondaryFontSize: clamp(
a.secondaryFontSize,
CLASSISLAND_TOKENS.fontSizes.inputMin,
CLASSISLAND_TOKENS.fontSizes.inputMax,
CLASSISLAND_TOKENS.fontSizes.secondary,
),
bodyFontSize: clamp(
a.bodyFontSize,
CLASSISLAND_TOKENS.fontSizes.inputMin,
CLASSISLAND_TOKENS.fontSizes.inputMax,
CLASSISLAND_TOKENS.fontSizes.body,
),
emphasizedFontSize: clamp(
a.emphasizedFontSize,
CLASSISLAND_TOKENS.fontSizes.inputMin,
CLASSISLAND_TOKENS.fontSizes.inputMax,
CLASSISLAND_TOKENS.fontSizes.emphasized,
),
largeFontSize: clamp(
a.largeFontSize,
CLASSISLAND_TOKENS.fontSizes.inputMin,
CLASSISLAND_TOKENS.fontSizes.inputMax,
CLASSISLAND_TOKENS.fontSizes.large,
),
customForegroundEnabled: a.customForegroundEnabled === true,
foreground: color(a.foreground, '#ffffff'),
foreground: color(a.foreground, CLASSISLAND_TOKENS.colors.light.textOnAccent),
customBackgroundEnabled: a.customBackgroundEnabled === true,
background: color(a.background, '#202024'),
background: color(a.background, CLASSISLAND_TOKENS.colors.light.islandBgCustom),
customBackgroundOpacityEnabled: a.customBackgroundOpacityEnabled === true,
backgroundOpacity: clamp(a.backgroundOpacity, 0, 1, 0.5),
backgroundOpacity: clamp(a.backgroundOpacity, 0, 1, CLASSISLAND_TOKENS.opacity.islandBackground),
customCornerRadiusEnabled: a.customCornerRadiusEnabled === true,
cornerRadius: clamp(a.cornerRadius, 0, 100, 16),
opacity: clamp(a.opacity, 0, 1, 1),
cornerRadius: clamp(
a.cornerRadius,
0,
CLASSISLAND_TOKENS.radii.islandMax,
CLASSISLAND_TOKENS.radii.island,
),
opacity: clamp(a.opacity, 0, 1, CLASSISLAND_TOKENS.opacity.line),
},
advanced: {
hideRules: Array.isArray(adv.hideRules)
@@ -341,6 +406,32 @@ export function normalizeIslandLayouts(input: unknown): IslandLayoutSettings {
main: r.main === true,
allowNotifications: r.allowNotifications !== false,
gap: clamp(r.gap, 0, 64, 8),
opacity: clamp(r.opacity, 0, 1, CLASSISLAND_TOKENS.opacity.line),
fontOverridesEnabled: r.fontOverridesEnabled === true,
secondaryFontSize: clamp(
r.secondaryFontSize,
CLASSISLAND_TOKENS.fontSizes.inputMin,
CLASSISLAND_TOKENS.fontSizes.inputMax,
CLASSISLAND_TOKENS.fontSizes.secondary,
),
bodyFontSize: clamp(
r.bodyFontSize,
CLASSISLAND_TOKENS.fontSizes.inputMin,
CLASSISLAND_TOKENS.fontSizes.inputMax,
CLASSISLAND_TOKENS.fontSizes.body,
),
emphasizedFontSize: clamp(
r.emphasizedFontSize,
CLASSISLAND_TOKENS.fontSizes.inputMin,
CLASSISLAND_TOKENS.fontSizes.inputMax,
CLASSISLAND_TOKENS.fontSizes.emphasized,
),
largeFontSize: clamp(
r.largeFontSize,
CLASSISLAND_TOKENS.fontSizes.inputMin,
CLASSISLAND_TOKENS.fontSizes.inputMax,
CLASSISLAND_TOKENS.fontSizes.large,
),
nodes: (Array.isArray(r.nodes) ? r.nodes : [])
.map((n) => node(n, 0))
.filter((n): n is IslandComponentNode => Boolean(n)),
@@ -373,12 +464,49 @@ export function normalizeIslandLayouts(input: unknown): IslandLayoutSettings {
resident ? CLASSISLAND_ISLAND_METRICS.scaleMax : 3,
1,
),
color: color(scheme.color, '#000000'),
foreground: color(scheme.foreground, '#ffffff'),
opacity: clamp(scheme.opacity, resident ? 0 : 0.1, 1, 0.5),
radius: clamp(scheme.radius, 0, resident ? CLASSISLAND_ISLAND_METRICS.radiusMax : 100, 8),
color: color(scheme.color, CLASSISLAND_TOKENS.colors.light.islandBgCustom),
foreground: color(scheme.foreground, CLASSISLAND_TOKENS.colors.light.textOnAccent),
customBackgroundEnabled: scheme.customBackgroundEnabled !== false,
customForegroundEnabled: scheme.customForegroundEnabled !== false,
opacity: clamp(scheme.opacity, resident ? 0 : 0.1, 1, CLASSISLAND_TOKENS.opacity.islandBackground),
radius: clamp(
scheme.radius,
0,
resident ? CLASSISLAND_ISLAND_METRICS.radiusMax : 100,
CLASSISLAND_TOKENS.radii.island,
),
fontWeight: classislandFontWeight(scheme.fontWeight),
secondaryFontSize: clamp(
scheme.secondaryFontSize,
CLASSISLAND_TOKENS.fontSizes.inputMin,
CLASSISLAND_TOKENS.fontSizes.inputMax,
CLASSISLAND_TOKENS.fontSizes.secondary,
),
bodyFontSize: clamp(
scheme.bodyFontSize,
CLASSISLAND_TOKENS.fontSizes.inputMin,
CLASSISLAND_TOKENS.fontSizes.inputMax,
CLASSISLAND_TOKENS.fontSizes.body,
),
emphasizedFontSize: clamp(
scheme.emphasizedFontSize,
CLASSISLAND_TOKENS.fontSizes.inputMin,
CLASSISLAND_TOKENS.fontSizes.inputMax,
CLASSISLAND_TOKENS.fontSizes.emphasized,
),
largeFontSize: clamp(
scheme.largeFontSize,
CLASSISLAND_TOKENS.fontSizes.inputMin,
CLASSISLAND_TOKENS.fontSizes.inputMax,
CLASSISLAND_TOKENS.fontSizes.large,
),
separated: scheme.separated === true,
spacing: clamp(scheme.spacing, 0, resident ? CLASSISLAND_ISLAND_METRICS.rowSpacingMax : 100, 5),
spacing: clamp(
scheme.spacing,
0,
resident ? CLASSISLAND_ISLAND_METRICS.rowSpacingMax : 100,
CLASSISLAND_TOKENS.spacing.lineGap,
),
});
}
return {
+12
View File
@@ -1143,6 +1143,8 @@ export interface IslandNotification {
}
/** 灵动岛外观设置(设置页可调,主进程持久化并按此驱动窗口与渲染进程) */
export type IslandAccentColorSource = 0 | 1 | 2 | 3;
export interface IslandAppearance {
/** 胶囊高度(px,36~72):展开卡高度按比例联动,保证布局不错乱 */
height: number;
@@ -1154,6 +1156,16 @@ export interface IslandAppearance {
opacity: number;
/** 主题色(强调色,用于高亮与按钮) */
accent: string;
/**
* ClassIsland 强调色来源:
* 0=自定义、1=壁纸主题色、2=跟随系统、3=屏幕主题色。
*/
accentSource: IslandAccentColorSource;
/** 壁纸/屏幕主题色候选;来源为 1 或 3 时按索引取色。 */
accentPalette: string[];
accentPaletteIndex: number;
/** 主进程按 accentSource 解析出的只读实际颜色,不参与用户选择。 */
resolvedAccent?: string;
/**
* 基础字号(px,11~20)——参考 WinIsland 的 font_size:
* 岛内**所有文本**都由它乘以各自的排版系数得出,因此改字号会整体等比缩放。