@synapsly/tokens 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +221 -0
- package/README.zh-CN.md +221 -0
- package/dist/dark.json +662 -0
- package/dist/figma.dark.tokens.json +3088 -0
- package/dist/figma.light.tokens.json +3088 -0
- package/dist/figma.tokens.json +2886 -0
- package/dist/index.cjs +1375 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +1220 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.cts +6674 -0
- package/dist/index.d.ts +6674 -0
- package/dist/index.js +1344 -0
- package/dist/index.js.map +1 -0
- package/dist/light.json +662 -0
- package/dist/primitive.json +263 -0
- package/dist/references.dark.json +662 -0
- package/dist/references.json +662 -0
- package/dist/references.light.json +662 -0
- package/dist/resolved.json +662 -0
- package/dist/semantic.dark.json +397 -0
- package/dist/semantic.json +397 -0
- package/dist/semantic.light.json +397 -0
- package/dist/tokens.json +662 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# @synapsly/tokens
|
|
2
|
+
|
|
3
|
+
[简体中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
Company design tokens for Synapsly products.
|
|
6
|
+
|
|
7
|
+
The package has two distinct layers:
|
|
8
|
+
|
|
9
|
+
- `primitive`: fixed company materials. These are defined by this package and are not part of project theme overrides.
|
|
10
|
+
- `semantic`: theme decisions grouped by usage, such as `color.bg.canvas`, `color.fg.primary`, and `color.action.primary.bg`.
|
|
11
|
+
|
|
12
|
+
Components and product styles should prefer `vars`. Theme authors can point semantic values at `primitiveVars`.
|
|
13
|
+
|
|
14
|
+
## Use the Default Themes
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import "@synapsly/tokens/styles.css";
|
|
18
|
+
import { themeNames } from "@synapsly/tokens";
|
|
19
|
+
|
|
20
|
+
<html data-theme={themeNames.light} />
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Dark theme uses the same attribute:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import "@synapsly/tokens/styles.css";
|
|
27
|
+
import { themeNames } from "@synapsly/tokens";
|
|
28
|
+
|
|
29
|
+
<html data-theme={themeNames.dark} />
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Theme classes are also exported when a class-based host app needs them:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { defaultDarkThemeClass, defaultLightThemeClass } from "@synapsly/tokens";
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { style } from "@vanilla-extract/css";
|
|
40
|
+
import { vars } from "@synapsly/tokens";
|
|
41
|
+
|
|
42
|
+
export const page = style({
|
|
43
|
+
background: vars.color.bg.canvas,
|
|
44
|
+
color: vars.color.fg.primary
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Override Semantic Tokens
|
|
49
|
+
|
|
50
|
+
Project themes override semantic decisions only. Primitive tokens remain fixed. Create custom themes in a vanilla-extract file such as `theme.css.ts`.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// theme.css.ts
|
|
54
|
+
import { createTheme, primitiveVars } from "@synapsly/tokens";
|
|
55
|
+
|
|
56
|
+
export const appTheme = createTheme({
|
|
57
|
+
name: "acme",
|
|
58
|
+
overrides: {
|
|
59
|
+
color: {
|
|
60
|
+
action: {
|
|
61
|
+
primary: {
|
|
62
|
+
bg: primitiveVars.color.green[600],
|
|
63
|
+
bgHover: primitiveVars.color.green[700],
|
|
64
|
+
bgActive: primitiveVars.color.green[800]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Attach the generated attributes in the app shell:
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { appTheme } from "./theme.css";
|
|
76
|
+
|
|
77
|
+
<html data-theme={appTheme.name} />;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Switching between multiple custom themes is just switching the theme name:
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
import { useState } from "react";
|
|
84
|
+
import { themeNames, type ThemeName } from "@synapsly/tokens";
|
|
85
|
+
import { appTheme } from "./theme.css";
|
|
86
|
+
|
|
87
|
+
type AppThemeName = ThemeName | typeof appTheme.name;
|
|
88
|
+
|
|
89
|
+
export function AppShell({ children }: { children: React.ReactNode }) {
|
|
90
|
+
const [theme, setTheme] = useState<AppThemeName>(themeNames.light);
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<div data-theme={theme}>
|
|
94
|
+
<button onClick={() => setTheme(themeNames.light)}>Light</button>
|
|
95
|
+
<button onClick={() => setTheme(themeNames.dark)}>Dark</button>
|
|
96
|
+
<button onClick={() => setTheme(appTheme.name)}>Acme</button>
|
|
97
|
+
{children}
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Derive from Existing Semantic Tokens
|
|
104
|
+
|
|
105
|
+
Use `createThemeTokens` when a theme should build on another semantic theme before creating a class.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
// theme.css.ts
|
|
109
|
+
import {
|
|
110
|
+
createTheme,
|
|
111
|
+
createThemeTokens,
|
|
112
|
+
defaultSemanticTokens,
|
|
113
|
+
primitiveVars
|
|
114
|
+
} from "@synapsly/tokens";
|
|
115
|
+
|
|
116
|
+
const brandTokens = createThemeTokens(defaultSemanticTokens, {
|
|
117
|
+
color: {
|
|
118
|
+
fg: {
|
|
119
|
+
brand: primitiveVars.color.brand[700]
|
|
120
|
+
},
|
|
121
|
+
action: {
|
|
122
|
+
primary: {
|
|
123
|
+
bg: primitiveVars.color.brand[500],
|
|
124
|
+
bgHover: primitiveVars.color.brand[600],
|
|
125
|
+
bgActive: primitiveVars.color.brand[700]
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
export const brandTheme = createTheme({
|
|
132
|
+
name: "brand",
|
|
133
|
+
tokens: brandTokens
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## API
|
|
138
|
+
|
|
139
|
+
- `primitiveTokens`: fixed primitive token values as a TypeScript object.
|
|
140
|
+
- `primitiveVars`: fixed primitive CSS variable references.
|
|
141
|
+
- `vars`: semantic CSS variable references for components and product styles.
|
|
142
|
+
- `semanticVars`: alias of `vars`.
|
|
143
|
+
- `themeNames`: built-in theme names, currently `light` and `dark`.
|
|
144
|
+
- `themeAttribute`: the theme attribute name, currently `data-theme`.
|
|
145
|
+
- `getThemeSelector(name)`: returns a selector such as `[data-theme="dark"]`.
|
|
146
|
+
- `createTheme({ name, tokens?, overrides?, selector? })`: creates a named vanilla-extract theme with `data-theme` attributes and a compatibility class.
|
|
147
|
+
- `createThemeTokens(base, overrides?)`: returns complete semantic tokens by deeply merging overrides into an existing semantic token object.
|
|
148
|
+
- `defaultLightTheme`: named light theme definition.
|
|
149
|
+
- `defaultDarkTheme`: named dark theme definition.
|
|
150
|
+
- `defaultLightThemeClass`: reference light theme class.
|
|
151
|
+
- `defaultDarkThemeClass`: reference dark theme class.
|
|
152
|
+
- `defaultThemeClass`: alias of `defaultLightThemeClass`.
|
|
153
|
+
- `defaultLightSemanticTokens`: default light semantic runtime tokens.
|
|
154
|
+
- `defaultDarkSemanticTokens`: default dark semantic runtime tokens.
|
|
155
|
+
- `defaultSemanticTokens`: alias of `defaultLightSemanticTokens`.
|
|
156
|
+
- `defaultResolvedLightSemanticTokens`: light semantic values resolved to concrete primitive values.
|
|
157
|
+
- `defaultResolvedDarkSemanticTokens`: dark semantic values resolved to concrete primitive values.
|
|
158
|
+
- `defaultResolvedSemanticTokens`: alias of `defaultResolvedLightSemanticTokens`.
|
|
159
|
+
- `defaultLightTokens`: publication snapshot for light.
|
|
160
|
+
- `defaultDarkTokens`: publication snapshot for dark.
|
|
161
|
+
- `defaultTokens`: alias of `defaultLightTokens`.
|
|
162
|
+
- `defaultLightTokenReferences`: primitive values plus light semantic reference strings.
|
|
163
|
+
- `defaultDarkTokenReferences`: primitive values plus dark semantic reference strings.
|
|
164
|
+
- `defaultTokenReferences`: alias of `defaultLightTokenReferences`.
|
|
165
|
+
- `SemanticTokens`: complete semantic token value type.
|
|
166
|
+
- `SemanticTokenOverrides`: partial semantic token override type.
|
|
167
|
+
|
|
168
|
+
## Semantic Coverage
|
|
169
|
+
|
|
170
|
+
Semantic tokens cover foundation usage plus common product UI decisions:
|
|
171
|
+
|
|
172
|
+
- `color.state`: shared interaction states such as hover, pressed, selected, focus, loading, visited, and readonly.
|
|
173
|
+
- `color.form`: form control surfaces, borders, placeholder, caret, invalid, disabled, and readonly states.
|
|
174
|
+
- `typography.text`: reusable text styles for display, headings, body, labels, captions, and code.
|
|
175
|
+
- `size.control` and `size.iconButton`: standard interactive control heights.
|
|
176
|
+
- `padding.control`, `gap`, and `layout`: control padding, common composition gaps, page gutters, containers, and sidebar widths.
|
|
177
|
+
|
|
178
|
+
## Primitive Scales
|
|
179
|
+
|
|
180
|
+
Spacing uses a 4px-based scale:
|
|
181
|
+
|
|
182
|
+
```text
|
|
183
|
+
0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32, 64
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Shadow uses a numeric elevation scale plus special-purpose values:
|
|
187
|
+
|
|
188
|
+
```text
|
|
189
|
+
0, 1, 2, 3, 4, 5, inner, focus
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## JSON Exports
|
|
193
|
+
|
|
194
|
+
- `@synapsly/tokens/tokens.json`: publication snapshot with primitive and resolved semantic tokens.
|
|
195
|
+
- `@synapsly/tokens/resolved.json`: same resolved publication snapshot.
|
|
196
|
+
- `@synapsly/tokens/light.json`: light publication snapshot.
|
|
197
|
+
- `@synapsly/tokens/dark.json`: dark publication snapshot.
|
|
198
|
+
- `@synapsly/tokens/primitive.json`: fixed primitive token values.
|
|
199
|
+
- `@synapsly/tokens/semantic.json`: resolved default semantic token values.
|
|
200
|
+
- `@synapsly/tokens/semantic.light.json`: resolved light semantic token values.
|
|
201
|
+
- `@synapsly/tokens/semantic.dark.json`: resolved dark semantic token values.
|
|
202
|
+
- `@synapsly/tokens/references.json`: default semantic references such as `{primitive.color.brand.500}`.
|
|
203
|
+
- `@synapsly/tokens/references.light.json`: light semantic references.
|
|
204
|
+
- `@synapsly/tokens/references.dark.json`: dark semantic references.
|
|
205
|
+
|
|
206
|
+
## Figma Exports
|
|
207
|
+
|
|
208
|
+
Two formats are emitted so teams can match their Figma workflow.
|
|
209
|
+
|
|
210
|
+
- `@synapsly/tokens/figma.tokens.json`: [Tokens Studio for Figma](https://tokens.studio) format with `global`, `light`, and `dark` token sets. Import it through the Tokens Studio plugin and configure `light` and `dark` as two modes of one collection. Shadow and typography tokens are fully preserved.
|
|
211
|
+
- `@synapsly/tokens/figma.light.tokens.json` and `@synapsly/tokens/figma.dark.tokens.json`: Figma-native DTCG (W3C) files for drag-and-drop import without a plugin. On a paid plan, drag both files into one new collection and Figma creates a mode per file. On the free plan (one mode per collection), import each file as its own collection. Only `color`, `dimension`, `fontFamily`, `duration`, `number`, and `string` tokens become variables; `shadow` and typography composite tokens are retained in the file but skipped by Figma's importer.
|
|
212
|
+
|
|
213
|
+
Dimensions are emitted as `px` (with `1rem = 16px`), durations as `s`, and font families as a single name. See [Modes for variables](https://help.figma.com/hc/en-us/articles/15343816063383) for import details.
|
|
214
|
+
|
|
215
|
+
## Versioning
|
|
216
|
+
|
|
217
|
+
This package follows semver.
|
|
218
|
+
|
|
219
|
+
- Patch: fix token values without changing meaning.
|
|
220
|
+
- Minor: add new tokens or add non-breaking exports.
|
|
221
|
+
- Major: remove, rename, or change the semantic meaning of an existing token.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# @synapsly/tokens
|
|
2
|
+
|
|
3
|
+
[English](./README.md)
|
|
4
|
+
|
|
5
|
+
Synapsly 产品的公司级设计 token。
|
|
6
|
+
|
|
7
|
+
这个包严格分为两层:
|
|
8
|
+
|
|
9
|
+
- `primitive`:固定的公司设计材料。它们由本包定义,不可被项目主题覆盖。
|
|
10
|
+
- `semantic`:按使用意图组织的主题决策,例如 `color.bg.canvas`、`color.fg.primary` 和 `color.action.primary.bg`。
|
|
11
|
+
|
|
12
|
+
组件和产品样式应该优先使用 `vars`。主题作者可以把 semantic 值指向 `primitiveVars`。
|
|
13
|
+
|
|
14
|
+
## 使用默认主题
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import "@synapsly/tokens/styles.css";
|
|
18
|
+
import { themeNames } from "@synapsly/tokens";
|
|
19
|
+
|
|
20
|
+
<html data-theme={themeNames.light} />;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
深色主题使用同一个属性:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import "@synapsly/tokens/styles.css";
|
|
27
|
+
import { themeNames } from "@synapsly/tokens";
|
|
28
|
+
|
|
29
|
+
<html data-theme={themeNames.dark} />;
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
当宿主应用需要 class 形式主题时,也可以使用导出的主题 class:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { defaultDarkThemeClass, defaultLightThemeClass } from "@synapsly/tokens";
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { style } from "@vanilla-extract/css";
|
|
40
|
+
import { vars } from "@synapsly/tokens";
|
|
41
|
+
|
|
42
|
+
export const page = style({
|
|
43
|
+
background: vars.color.bg.canvas,
|
|
44
|
+
color: vars.color.fg.primary
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 覆盖 Semantic Token
|
|
49
|
+
|
|
50
|
+
项目主题只覆盖 semantic 决策。Primitive token 保持固定。在 `theme.css.ts` 这类 vanilla-extract 文件中创建自定义主题。
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// theme.css.ts
|
|
54
|
+
import { createTheme, primitiveVars } from "@synapsly/tokens";
|
|
55
|
+
|
|
56
|
+
export const appTheme = createTheme({
|
|
57
|
+
name: "acme",
|
|
58
|
+
overrides: {
|
|
59
|
+
color: {
|
|
60
|
+
action: {
|
|
61
|
+
primary: {
|
|
62
|
+
bg: primitiveVars.color.green[600],
|
|
63
|
+
bgHover: primitiveVars.color.green[700],
|
|
64
|
+
bgActive: primitiveVars.color.green[800]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
在应用壳层挂载生成的属性:
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import { appTheme } from "./theme.css";
|
|
76
|
+
|
|
77
|
+
<html data-theme={appTheme.name} />;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
在多个自定义主题之间切换时,只需要切换主题名:
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
import { useState } from "react";
|
|
84
|
+
import { themeNames, type ThemeName } from "@synapsly/tokens";
|
|
85
|
+
import { appTheme } from "./theme.css";
|
|
86
|
+
|
|
87
|
+
type AppThemeName = ThemeName | typeof appTheme.name;
|
|
88
|
+
|
|
89
|
+
export function AppShell({ children }: { children: React.ReactNode }) {
|
|
90
|
+
const [theme, setTheme] = useState<AppThemeName>(themeNames.light);
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<div data-theme={theme}>
|
|
94
|
+
<button onClick={() => setTheme(themeNames.light)}>Light</button>
|
|
95
|
+
<button onClick={() => setTheme(themeNames.dark)}>Dark</button>
|
|
96
|
+
<button onClick={() => setTheme(appTheme.name)}>Acme</button>
|
|
97
|
+
{children}
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## 从现有 Semantic Token 派生
|
|
104
|
+
|
|
105
|
+
当一个主题需要先基于已有 semantic 主题再创建 class 时,使用 `createThemeTokens`。
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
// theme.css.ts
|
|
109
|
+
import {
|
|
110
|
+
createTheme,
|
|
111
|
+
createThemeTokens,
|
|
112
|
+
defaultSemanticTokens,
|
|
113
|
+
primitiveVars
|
|
114
|
+
} from "@synapsly/tokens";
|
|
115
|
+
|
|
116
|
+
const brandTokens = createThemeTokens(defaultSemanticTokens, {
|
|
117
|
+
color: {
|
|
118
|
+
fg: {
|
|
119
|
+
brand: primitiveVars.color.brand[700]
|
|
120
|
+
},
|
|
121
|
+
action: {
|
|
122
|
+
primary: {
|
|
123
|
+
bg: primitiveVars.color.brand[500],
|
|
124
|
+
bgHover: primitiveVars.color.brand[600],
|
|
125
|
+
bgActive: primitiveVars.color.brand[700]
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
export const brandTheme = createTheme({
|
|
132
|
+
name: "brand",
|
|
133
|
+
tokens: brandTokens
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## API
|
|
138
|
+
|
|
139
|
+
- `primitiveTokens`:固定 primitive token 值的 TypeScript 对象。
|
|
140
|
+
- `primitiveVars`:固定 primitive CSS 变量引用。
|
|
141
|
+
- `vars`:供组件和产品样式使用的 semantic CSS 变量引用。
|
|
142
|
+
- `semanticVars`:`vars` 的别名。
|
|
143
|
+
- `themeNames`:内置主题名,目前是 `light` 和 `dark`。
|
|
144
|
+
- `themeAttribute`:主题属性名,目前是 `data-theme`。
|
|
145
|
+
- `getThemeSelector(name)`:返回类似 `[data-theme="dark"]` 的选择器。
|
|
146
|
+
- `createTheme({ name, tokens?, overrides?, selector? })`:用 `data-theme` 属性和兼容 class 创建命名 vanilla-extract 主题。
|
|
147
|
+
- `createThemeTokens(base, overrides?)`:把 overrides 深合并到已有 semantic token 对象,返回完整 semantic tokens。
|
|
148
|
+
- `defaultLightTheme`:命名浅色主题定义。
|
|
149
|
+
- `defaultDarkTheme`:命名深色主题定义。
|
|
150
|
+
- `defaultLightThemeClass`:参考浅色主题 class。
|
|
151
|
+
- `defaultDarkThemeClass`:参考深色主题 class。
|
|
152
|
+
- `defaultThemeClass`:`defaultLightThemeClass` 的别名。
|
|
153
|
+
- `defaultLightSemanticTokens`:默认浅色 semantic runtime tokens。
|
|
154
|
+
- `defaultDarkSemanticTokens`:默认深色 semantic runtime tokens。
|
|
155
|
+
- `defaultSemanticTokens`:`defaultLightSemanticTokens` 的别名。
|
|
156
|
+
- `defaultResolvedLightSemanticTokens`:解析为具体 primitive 值的浅色 semantic 值。
|
|
157
|
+
- `defaultResolvedDarkSemanticTokens`:解析为具体 primitive 值的深色 semantic 值。
|
|
158
|
+
- `defaultResolvedSemanticTokens`:`defaultResolvedLightSemanticTokens` 的别名。
|
|
159
|
+
- `defaultLightTokens`:浅色发布快照。
|
|
160
|
+
- `defaultDarkTokens`:深色发布快照。
|
|
161
|
+
- `defaultTokens`:`defaultLightTokens` 的别名。
|
|
162
|
+
- `defaultLightTokenReferences`:primitive 值和浅色 semantic 引用字符串。
|
|
163
|
+
- `defaultDarkTokenReferences`:primitive 值和深色 semantic 引用字符串。
|
|
164
|
+
- `defaultTokenReferences`:`defaultLightTokenReferences` 的别名。
|
|
165
|
+
- `SemanticTokens`:完整 semantic token 值类型。
|
|
166
|
+
- `SemanticTokenOverrides`:局部 semantic token 覆盖类型。
|
|
167
|
+
|
|
168
|
+
## Semantic 覆盖范围
|
|
169
|
+
|
|
170
|
+
Semantic tokens 覆盖基础使用场景和常见产品 UI 决策:
|
|
171
|
+
|
|
172
|
+
- `color.state`:hover、pressed、selected、focus、loading、visited、readonly 等共享交互状态。
|
|
173
|
+
- `color.form`:表单控件表面、边框、placeholder、caret、invalid、disabled 和 readonly 状态。
|
|
174
|
+
- `typography.text`:display、heading、body、label、caption 和 code 的可复用文本样式。
|
|
175
|
+
- `size.control` 和 `size.iconButton`:标准交互控件高度。
|
|
176
|
+
- `padding.control`、`gap` 和 `layout`:控件 padding、常用组合间距、页面 gutter、容器和侧边栏宽度。
|
|
177
|
+
|
|
178
|
+
## Primitive 尺度
|
|
179
|
+
|
|
180
|
+
Spacing 使用基于 4px 的尺度:
|
|
181
|
+
|
|
182
|
+
```text
|
|
183
|
+
0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32, 64
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Shadow 使用数字 elevation 尺度和特殊用途值:
|
|
187
|
+
|
|
188
|
+
```text
|
|
189
|
+
0, 1, 2, 3, 4, 5, inner, focus
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## JSON 导出
|
|
193
|
+
|
|
194
|
+
- `@synapsly/tokens/tokens.json`:包含 primitive 和已解析 semantic tokens 的发布快照。
|
|
195
|
+
- `@synapsly/tokens/resolved.json`:同样的已解析发布快照。
|
|
196
|
+
- `@synapsly/tokens/light.json`:浅色发布快照。
|
|
197
|
+
- `@synapsly/tokens/dark.json`:深色发布快照。
|
|
198
|
+
- `@synapsly/tokens/primitive.json`:固定 primitive token 值。
|
|
199
|
+
- `@synapsly/tokens/semantic.json`:已解析的默认 semantic token 值。
|
|
200
|
+
- `@synapsly/tokens/semantic.light.json`:已解析的浅色 semantic token 值。
|
|
201
|
+
- `@synapsly/tokens/semantic.dark.json`:已解析的深色 semantic token 值。
|
|
202
|
+
- `@synapsly/tokens/references.json`:默认 semantic 引用,例如 `{primitive.color.brand.500}`。
|
|
203
|
+
- `@synapsly/tokens/references.light.json`:浅色 semantic 引用。
|
|
204
|
+
- `@synapsly/tokens/references.dark.json`:深色 semantic 引用。
|
|
205
|
+
|
|
206
|
+
## Figma 导出
|
|
207
|
+
|
|
208
|
+
提供两种格式,团队可按自己的 Figma 工作流选择。
|
|
209
|
+
|
|
210
|
+
- `@synapsly/tokens/figma.tokens.json`:[Tokens Studio for Figma](https://tokens.studio) 格式,含 `global`、`light`、`dark` 三个 token 集合。通过 Tokens Studio 插件导入,再把 `light` 和 `dark` 配为同一个集合的两个 mode。shadow 和 typography token 完整保留。
|
|
211
|
+
- `@synapsly/tokens/figma.light.tokens.json` 与 `@synapsly/tokens/figma.dark.tokens.json`:Figma 原生 DTCG(W3C)格式,无需插件,直接拖入导入。付费版可把两个文件拖进同一个新集合,Figma 会为每个文件创建一个 mode。免费版每个集合只能有一个 mode,需把两个文件分别导入为各自的单 mode 集合。只有 `color`、`dimension`、`fontFamily`、`duration`、`number`、`string` 这几种 token 会成为变量;`shadow` 和 typography 复合 token 会保留在文件中,但被 Figma 导入器跳过。
|
|
212
|
+
|
|
213
|
+
间距以 `px` 输出(按 `1rem = 16px` 换算),时长以 `s` 输出,字体族只取首个名字。导入机制参见 [Modes for variables](https://help.figma.com/hc/en-us/articles/15343816063383)。
|
|
214
|
+
|
|
215
|
+
## 版本策略
|
|
216
|
+
|
|
217
|
+
这个包遵循 semver。
|
|
218
|
+
|
|
219
|
+
- Patch:修复 token 值,但不改变语义。
|
|
220
|
+
- Minor:新增 token 或新增非破坏性导出。
|
|
221
|
+
- Major:删除、重命名或改变已有 token 的 semantic 含义。
|