主题与样式
Deskset 的视觉系统让你的小组件自动融入每一种桌面外观:浅色/深色毛玻璃卡片以及无边框极简模式。优先使用语义颜色令牌,避免写死纯黑或纯白。




1. 语义颜色令牌(Semantic Tokens)#
任何接受颜色的属性(color、background、borderColor、trackColor、fill、stroke)都可以传入十六进制色值(如 "#0EA5E9"、"#0EA5E933")、"clear",或以下语义令牌(左圆点为浅色模式、右圆点为深色模式):
theme.ink
主文字与主图标色,极简模式下自动根据壁纸亮暗翻转。
theme.secondary
次要文字、副标题与标签。
theme.tertiary
弱化辅助文字与占位符。
theme.accent
组件强调色(继承 deskpack.json 的 accentColor 或用户选择)。
theme.card
卡片标准底色(仅用于 background,自动联动当前材质)。
theme.faint
轻底块、图标徽章与内嵌子卡片填充色。
theme.raised
凸起层级底色,适合按钮或分组胶囊。
theme.track
进度条、圆环与滑块未完成轨道色。
theme.divider
精细分割线与边框描边色。
theme.surface
次级面板背景色。
theme.danger
警告、错误或破坏性操作强调色。
theme.success
完成、在线与正向趋势强调色。
theme.warning
注意提示与中等负载强调色。
theme.blue
系统标准蓝色。
theme.purple
系统标准紫色。
2. 玻璃卡片与极简无边框模式适配#
在 deskpack.json 中声明 "styles": ["glass", "minimal"] 后,用户即可在右键 编辑小组件 与工坊预览中把小组件切到 极简无边框模式(theme.isPure === true)。推荐在每个组件根容器上复用下面这组标准样式,一次兼顾卡片与透明悬浮两种状态:
TSX
const { theme } = useWidget();
const card = {
maxWidth: true,
maxHeight: true,
background: theme.isPure ? "clear" : "theme.card",
cornerRadius: theme.isPure ? 0 : theme.corner,
clip: !theme.isPure,
} as const;
return (
<VStack {...card} padding={16} spacing={8}>
<Text fontSize={18} fontWeight="bold" color="theme.ink">Hello</Text>
</VStack>
);
3. WidgetTheme 主题对象#
通过 const { theme } = useWidget() 获取,提供当前材质、明暗和系统地区偏好:
stylestring只读- 当前桌面外观风格,固定为
"modern"。 materialstring只读- 当前生效的卡片材质:
"glass"、"graphite"或"pure"(极简无边框)。 isDarkboolean只读- 当前是否为深色外观。
isPureboolean只读- 是否处于极简无边框(透明背景)模式。
accentstring只读- 解析后的强调色十六进制字符串。
inkstring只读- 解析后的主文字颜色。
secondarystring只读- 解析后的次要文字颜色。
surfacestring只读- 解析后的次级表面颜色。
cornernumber只读- 当前桌面卡片的标准圆角半径(pt)。
wallpaperTonestring可选- 小组件正下方桌面壁纸的明暗度:
"light"或"dark"(可探测时提供)。 use24Hourboolean可选- macOS 系统是否开启 24 小时制。
firstWeekdaynumber可选- macOS 系统周起始日(
1= 周日 …7= 周六)。 tempUnitstring可选- macOS 系统温度单位偏好:
"C"或"F"。 timeZonestring可选- 当前系统 IANA 时区标识(如
"Asia/Shanghai")。 utcOffsetSecondsnumber可选- 当前系统时区相对 UTC 的偏移秒数。
4. StyleProps 通用样式属性#
Deskset 中所有 23 个原生组件都继承同一套 StyleProps,类似 SwiftUI 修饰符,直接作为 JSX 属性书写:
尺寸、间距与对齐#
paddingnumber | EdgeInsets可选- 内边距(pt),可传单数字或对象
{ top, bottom, leading, trailing, horizontal, vertical }。 spacingnumber可选- 子节点之间的间距(pt),适用于
VStack/HStack。 alignmentAlignment可选- 对齐方式:
"leading"、"center"、"trailing"、"top"、"bottom"、"topLeading"、"topTrailing"、"bottomLeading"、"bottomTrailing"、"firstTextBaseline"、"lastTextBaseline"。 widthnumber可选- 固定逻辑宽度(pt)。
heightnumber可选- 固定逻辑高度(pt)。
minWidthnumber可选- 最小宽度(pt)。
minHeightnumber可选- 最小高度(pt)。
maxWidthboolean | number可选- 传
true横向撑满父容器,或传具体最大宽度(pt)。 maxHeightboolean | number可选- 传
true纵向撑满父容器,或传具体最大高度(pt)。 fullBleedboolean可选- 忽略默认安全边距贴边绘制(也可直接使用
FullBleed容器)。
背景、材质、边框与阴影#
backgroundstring可选- 背景色:语义令牌、十六进制色值或
"clear"。 materialMaterialKind可选- 原生毛玻璃材质:
"ultraThin"、"thin"、"regular"、"thick"、"pill"、"glass"。 gradientGradientSpec可选- 渐变背景
{ colors: string[], start?: string, end?: string, kind?: "linear" | "radial" | "angular" }。 cornerRadiusnumber可选- 连续曲率圆角半径(pt)。
clipboolean可选- 是否按
cornerRadius裁剪超出边界的子节点。 borderColorstring可选- 描边颜色(配合
borderWidth使用)。 borderWidthnumber可选- 描边粗细(pt)。
shadowboolean | ShadowSpec可选- 传
true使用默认柔和阴影,或传{ color?, radius?, x?, y? }精确控制。 opacitynumber可选- 不透明度(
0–1)。 blurRadiusnumber可选- 高斯模糊半径(pt)。
变换、动画与交互事件#
offsetXnumber可选- 水平位移(pt)。
offsetYnumber可选- 垂直位移(pt)。
zIndexnumber可选- 层叠顺序(数值越大越靠前)。
rotationnumber可选- 顺时针旋转角度(度)。
scalenumber可选- 缩放倍率(
0–8,1为原始大小)。 animationAnimationKind可选- 属性变化自动补间动画:
"none"、"spring"、"easeInOut"、"easeIn"、"easeOut"、"linear"。系统开启「减少动态效果」时自动关闭。 animationDurationnumber可选- 动画时长(秒,
0.05–2,默认0.35)。 onClickfunction可选- 点击回调
() => void。 onClickAtfunction可选- 带本地坐标的点击回调
({ x, y, width, height }) => void(单位 pt)。 onHoverfunction可选- 鼠标悬停进入/离开回调
(hovered: boolean) => void。