themeClass 的定义一直在 tokens、消费 barrel 却在 themes,跨目录反向 导入不自洽。迁到 src/themes/theme.css.ts 后 themes 目录自有定义, themes/index.ts 改 './theme.css' 直连;包内 10 处 import 与 README 两处路径同步更新。
This commit is contained in:
13 files changed
+14
-14
No files matched your search
@@ -7,13 +7,13 @@
|
||||
颜色分两层(`design/colors` 规范的机器可执行形式),各自由 `createThemeContract` + `createTheme` 定义,靠挂在 `html` 上的主题类生效(`paletteClass`/`themeClass`/`siteClass` 从 `@idealjs/stack-ui-kit/themes` 导出,`mount.ts` 挂类、ssg 烘进静态 html):
|
||||
|
||||
- **颜色描述层(primitive,`src/tokens/palette.css.ts`)**——`--palette-coral/teal/mustard/violet/pink/blue/green/black/cream/sand/clay/graphite`,描述「这是什么颜色」,是色值的唯一事实源。**theme switch 只切这层**:换一套 palette 映射(撞色对轮转、暗色纸等),全站观感随动。
|
||||
- **语义描述层(semantic,`src/tokens/theme.css.ts`)**——`--color-clash1a…3b`(撞色对槽位:对 1 a=coral、对 1 b=teal……)、`--color-ink/paper/paper-deep/mute/body`(中性角色:描边墨/纸面/深纸/弱字/正文)、`--shadow-ink(-lift)`、`--drop-shadow-ink(-lift)`、`--text-content/t3/t2/t1/small`(含 `--line-height` 伴生)。描述「这个颜色在系统里干什么」,**组件组成只准消费这层**,值全部 `var(--palette-*)` 引用。业务站主题(`src/tokens/site.css.ts`)同构:章节色 `--color-ch1..7` 映射 palette 槽位,`--page-flip-spring` 翻页动效曲线。
|
||||
- **语义描述层(semantic,`src/themes/theme.css.ts`)**——`--color-clash1a…3b`(撞色对槽位:对 1 a=coral、对 1 b=teal……)、`--color-ink/paper/paper-deep/mute/body`(中性角色:描边墨/纸面/深纸/弱字/正文)、`--shadow-ink(-lift)`、`--drop-shadow-ink(-lift)`、`--text-content/t3/t2/t1/small`(含 `--line-height` 伴生)。描述「这个颜色在系统里干什么」,**组件组成只准消费这层**,值全部 `var(--palette-*)` 引用。业务站主题(`src/tokens/site.css.ts`)同构:章节色 `--color-ch1..7` 映射 palette 槽位,`--page-flip-spring` 翻页动效曲线。
|
||||
|
||||
semantic 层以**原名**输出:ve 主题类产出的是带作用域哈希的契约变量(`--color-ink__…`),stack 插件在 `__shared/ui-kit.css` 末尾追加 `:root` 桥接块,把原名 `--color-ink` 指向契约变量。learning.css、app 手写 css 与全部 inline `var()` 都按 `--color-*` 原名消费——改名即断,动前先全库 grep。
|
||||
|
||||
## 组件 css.ts 如何消费 token
|
||||
|
||||
- ui-kit 包内:直接用契约 `themeVars`(`import { themeVars } from '../tokens/theme.css'`)。
|
||||
- ui-kit 包内:直接用契约 `themeVars`(`import { themeVars } from '../themes/theme.css'`)。
|
||||
- 其它包(如 `@idealjs/stack-site-ui-kit`):只能 `import { theme } from '@idealjs/stack-ui-kit/tokens'`——纯 TS 常量,值为 `var(--color-*)` 原名字符串,不是 ve theme 机制。
|
||||
|
||||
**其它包不得 import ui-kit 的 `.css.ts` token 模块**:ve 的文件作用域按「编译根 + 文件路径」计算,跨包 import 会让同一个 token 模块被编译进第二个作用域,而主题类只挂其中一套,引用全部悬空。插件发现同一原名对应两个作用域会在构建期直接报错。
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { style } from '@vanilla-extract/css'
|
||||
import { themeVars } from '../tokens/theme.css'
|
||||
import { themeVars } from '../themes/theme.css'
|
||||
|
||||
export const mockup = style({
|
||||
overflow: 'hidden',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { style } from '@vanilla-extract/css'
|
||||
import { themeVars } from '../tokens/theme.css'
|
||||
import { themeVars } from '../themes/theme.css'
|
||||
|
||||
export const buttonHost = style({
|
||||
display: 'inline-block',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { style } from '@vanilla-extract/css'
|
||||
import { themeVars } from '../../tokens/theme.css'
|
||||
import { themeVars } from '../../themes/theme.css'
|
||||
|
||||
export const dropdownTriggerHost = style({
|
||||
display: 'inline-flex',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { style } from '@vanilla-extract/css'
|
||||
import { themeVars } from '../tokens/theme.css'
|
||||
import { themeVars } from '../themes/theme.css'
|
||||
import { hoverHost } from './hoverHost.css.ts'
|
||||
|
||||
const ink = themeVars.color.ink
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { style } from '@vanilla-extract/css'
|
||||
import { themeVars } from '../tokens/theme.css'
|
||||
import { themeVars } from '../themes/theme.css'
|
||||
|
||||
export const shadowButtonBase = style({
|
||||
display: 'inline-flex',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { style } from '@vanilla-extract/css'
|
||||
import { themeVars } from '../tokens/theme.css'
|
||||
import { themeVars } from '../themes/theme.css'
|
||||
|
||||
export const shadowCardHost = style({
|
||||
display: 'block',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { style } from '@vanilla-extract/css'
|
||||
import { themeVars } from '../tokens/theme.css'
|
||||
import { themeVars } from '../themes/theme.css'
|
||||
|
||||
export const mark = style({
|
||||
rotate: '-1deg',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { style } from '@vanilla-extract/css'
|
||||
import { themeVars } from '../tokens/theme.css'
|
||||
import { themeVars } from '../themes/theme.css'
|
||||
|
||||
export const ticketHost = style({
|
||||
display: 'block',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { style } from '@vanilla-extract/css'
|
||||
import { themeVars } from '../tokens/theme.css'
|
||||
import { themeVars } from '../themes/theme.css'
|
||||
|
||||
const alpha = (color: string, ratio: string): string =>
|
||||
`color-mix(in oklab, ${color} ${ratio}, transparent)`
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export { paletteClass } from '../tokens/palette.css'
|
||||
export { themeClass } from '../tokens/theme.css'
|
||||
export { themeClass } from './theme.css'
|
||||
export { siteClass } from '../tokens/site.css'
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { createTheme, createThemeContract } from '@vanilla-extract/css'
|
||||
import { paletteVars } from './palette.css'
|
||||
import { paletteVars } from '../tokens/palette.css'
|
||||
|
||||
export const themeVars = createThemeContract({
|
||||
color: {
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { themeVars } from './theme.css'
|
||||
import type { themeVars } from '../themes/theme.css'
|
||||
|
||||
type Refs<T> = { readonly [K in keyof T]: T[K] extends string ? string : Refs<T[K]> }
|
||||
|
||||
|
||||
Reference in new issue
Block a user