@marianmeres/design-tokens 1.0.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/AGENTS.md +85 -0
- package/API.md +271 -0
- package/CLAUDE.md +3 -0
- package/LICENSE +21 -0
- package/README.md +139 -0
- package/dist/colors.d.ts +301 -0
- package/dist/colors.js +301 -0
- package/dist/generate.d.ts +14 -0
- package/dist/generate.js +137 -0
- package/dist/mod.d.ts +13 -0
- package/dist/mod.js +12 -0
- package/dist/reboot-bridge.d.ts +27 -0
- package/dist/reboot-bridge.js +89 -0
- package/dist/themes/blue-orange.d.ts +3 -0
- package/dist/themes/blue-orange.js +117 -0
- package/dist/themes/cyan-red.d.ts +3 -0
- package/dist/themes/cyan-red.js +117 -0
- package/dist/themes/cyan-slate.d.ts +3 -0
- package/dist/themes/cyan-slate.js +117 -0
- package/dist/themes/dds.d.ts +3 -0
- package/dist/themes/dds.js +133 -0
- package/dist/themes/emerald-amber-forest.d.ts +3 -0
- package/dist/themes/emerald-amber-forest.js +117 -0
- package/dist/themes/emerald-pink.d.ts +3 -0
- package/dist/themes/emerald-pink.js +117 -0
- package/dist/themes/fuchsia-emerald.d.ts +3 -0
- package/dist/themes/fuchsia-emerald.js +117 -0
- package/dist/themes/gray.d.ts +3 -0
- package/dist/themes/gray.js +66 -0
- package/dist/themes/indigo-amber.d.ts +3 -0
- package/dist/themes/indigo-amber.js +117 -0
- package/dist/themes/lime-fuchsia-neon.d.ts +3 -0
- package/dist/themes/lime-fuchsia-neon.js +117 -0
- package/dist/themes/mod.d.ts +72 -0
- package/dist/themes/mod.js +71 -0
- package/dist/themes/monokai-cyan.d.ts +3 -0
- package/dist/themes/monokai-cyan.js +119 -0
- package/dist/themes/monokai-green.d.ts +3 -0
- package/dist/themes/monokai-green.js +119 -0
- package/dist/themes/monokai-pink.d.ts +3 -0
- package/dist/themes/monokai-pink.js +119 -0
- package/dist/themes/orange-pink-sunset.d.ts +3 -0
- package/dist/themes/orange-pink-sunset.js +117 -0
- package/dist/themes/pink-emerald.d.ts +3 -0
- package/dist/themes/pink-emerald.js +117 -0
- package/dist/themes/pink-teal.d.ts +3 -0
- package/dist/themes/pink-teal.js +117 -0
- package/dist/themes/purple-yellow.d.ts +3 -0
- package/dist/themes/purple-yellow.js +117 -0
- package/dist/themes/rainbow.d.ts +3 -0
- package/dist/themes/rainbow.js +122 -0
- package/dist/themes/red-blue.d.ts +3 -0
- package/dist/themes/red-blue.js +117 -0
- package/dist/themes/red-cyan.d.ts +3 -0
- package/dist/themes/red-cyan.js +117 -0
- package/dist/themes/red-sky-slate.d.ts +3 -0
- package/dist/themes/red-sky-slate.js +117 -0
- package/dist/themes/red-sky.d.ts +3 -0
- package/dist/themes/red-sky.js +117 -0
- package/dist/themes/rose-teal.d.ts +3 -0
- package/dist/themes/rose-teal.js +117 -0
- package/dist/themes/sky-amber.d.ts +3 -0
- package/dist/themes/sky-amber.js +117 -0
- package/dist/themes/slate-cyan.d.ts +3 -0
- package/dist/themes/slate-cyan.js +117 -0
- package/dist/themes/slate-teal-ocean.d.ts +3 -0
- package/dist/themes/slate-teal-ocean.js +117 -0
- package/dist/themes/stone-orange-earth.d.ts +3 -0
- package/dist/themes/stone-orange-earth.js +117 -0
- package/dist/themes/stone.d.ts +3 -0
- package/dist/themes/stone.js +72 -0
- package/dist/themes/teal-rose.d.ts +3 -0
- package/dist/themes/teal-rose.js +117 -0
- package/dist/themes/violet-lime.d.ts +3 -0
- package/dist/themes/violet-lime.js +117 -0
- package/dist/themes/violet-rose-dusk.d.ts +3 -0
- package/dist/themes/violet-rose-dusk.js +117 -0
- package/dist/themes/zinc.d.ts +3 -0
- package/dist/themes/zinc.js +66 -0
- package/dist/types.d.ts +48 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +28 -0
- package/package.json +23 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# @marianmeres/design-tokens — Agent Guide
|
|
2
|
+
|
|
3
|
+
## Quick Reference
|
|
4
|
+
- **Stack**: Deno / TypeScript
|
|
5
|
+
- **Run**: `deno task test` | **Watch**: `deno task test:watch`
|
|
6
|
+
- **Build (npm)**: `deno task npm:build`
|
|
7
|
+
- **Publish**: `deno task publish` (JSR + npm)
|
|
8
|
+
- **Format**: `deno fmt` (tabs, 90 chars, indent 4)
|
|
9
|
+
|
|
10
|
+
## What This Package Does
|
|
11
|
+
|
|
12
|
+
CSS custom property generator for design token systems. Takes a structured
|
|
13
|
+
`ThemeSchema` (light + optional dark mode) and produces CSS `--custom-property`
|
|
14
|
+
declarations with automatic hover/active state derivation via `color-mix()`.
|
|
15
|
+
|
|
16
|
+
Three entry points:
|
|
17
|
+
- `.` — core generation functions, types, color palette
|
|
18
|
+
- `./reboot` — Bootstrap Reboot `--bs-*` variable bridge
|
|
19
|
+
- `./themes` — 31 pre-built theme definitions
|
|
20
|
+
|
|
21
|
+
## Project Structure
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
/src
|
|
25
|
+
mod.ts — main entry: re-exports functions, types, colors
|
|
26
|
+
types.ts — core type definitions (ThemeSchema, TokenSchema, etc.)
|
|
27
|
+
generate.ts — token generation + CSS output (generateCssTokens, toCssString, generateThemeCss)
|
|
28
|
+
utils.ts — hex color parsing (hexToRgb, hexToRgbTriplet)
|
|
29
|
+
colors.ts — complete Tailwind v3 color palette (hex values)
|
|
30
|
+
reboot-bridge.ts — Bootstrap Reboot --bs-* variable mapping
|
|
31
|
+
/themes
|
|
32
|
+
mod.ts — re-exports all theme definitions
|
|
33
|
+
*.ts — individual theme files (default export: ThemeSchema)
|
|
34
|
+
/tests — test files (deno test --allow-read)
|
|
35
|
+
/scripts — npm build script
|
|
36
|
+
/theme-preview-builder — HTML preview tool
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Public API Surface
|
|
40
|
+
|
|
41
|
+
### Functions (from `./src/mod.ts`)
|
|
42
|
+
| Function | Purpose |
|
|
43
|
+
|----------|---------|
|
|
44
|
+
| `generateCssTokens(schema, prefix, mode?)` | Generate token key-value pairs from a TokenSchema |
|
|
45
|
+
| `toCssString(tokens, selector?)` | Convert tokens to a CSS declaration block |
|
|
46
|
+
| `generateThemeCss(schema, prefix)` | Generate complete CSS for light + optional dark mode |
|
|
47
|
+
| `hexToRgb(hex)` | Parse hex to `[r, g, b]` tuple |
|
|
48
|
+
| `hexToRgbTriplet(hex)` | Convert hex to `"r, g, b"` string |
|
|
49
|
+
|
|
50
|
+
### Functions (from `./reboot`)
|
|
51
|
+
| Function | Purpose |
|
|
52
|
+
|----------|---------|
|
|
53
|
+
| `generateRebootBridge(tokens, prefix)` | Map tokens to `--bs-*` variables |
|
|
54
|
+
| `generateThemedCss(schema, prefix)` | Combined tokens + reboot bridge CSS |
|
|
55
|
+
|
|
56
|
+
### Key Types
|
|
57
|
+
| Type | Purpose |
|
|
58
|
+
|------|---------|
|
|
59
|
+
| `ThemeSchema` | `{ light: TokenSchema; dark?: TokenSchema }` |
|
|
60
|
+
| `TokenSchema` | Intent colors, role paired/single colors |
|
|
61
|
+
| `ColorPair` | `{ DEFAULT, foreground, hover?, active? }` |
|
|
62
|
+
| `ColorValue` | `{ DEFAULT, hover?, active? }` |
|
|
63
|
+
| `SingleColor` | `string \| ColorValue` |
|
|
64
|
+
| `GeneratedTokens` | `Record<string, string>` |
|
|
65
|
+
|
|
66
|
+
### Constants
|
|
67
|
+
| Export | Purpose |
|
|
68
|
+
|--------|---------|
|
|
69
|
+
| `colors` | Complete Tailwind v3 hex palette (`colors.blue[600]`) |
|
|
70
|
+
|
|
71
|
+
## Critical Conventions
|
|
72
|
+
|
|
73
|
+
1. All public functions must have JSDoc and explicit return types (Deno/JSR requirement)
|
|
74
|
+
2. Token naming: `--{prefix}color-{key}`, `--{prefix}color-{key}-hover`, etc.
|
|
75
|
+
3. Hover/active auto-derived via `color-mix(in oklch, ...)` — light darkens with black, dark lightens with white
|
|
76
|
+
4. Surface-intent tokens derived via `color-mix(in srgb, ...)` from intent + background
|
|
77
|
+
5. Theme files use `export default` with `ThemeSchema` type annotation
|
|
78
|
+
6. Formatting: tabs, 90-char line width, 4-space indent width (`deno fmt`)
|
|
79
|
+
|
|
80
|
+
## Before Making Changes
|
|
81
|
+
|
|
82
|
+
- [ ] Read existing patterns in similar files
|
|
83
|
+
- [ ] Run `deno task test` — all 37 tests must pass
|
|
84
|
+
- [ ] Follow `deno fmt` conventions
|
|
85
|
+
- [ ] Ensure new exports have JSDoc + explicit return types
|
package/API.md
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# API
|
|
2
|
+
|
|
3
|
+
## Functions
|
|
4
|
+
|
|
5
|
+
### `generateCssTokens(schema, prefix, mode?)`
|
|
6
|
+
|
|
7
|
+
Generate CSS token key-value pairs from a single-mode token schema.
|
|
8
|
+
|
|
9
|
+
**Parameters:**
|
|
10
|
+
- `schema` (`TokenSchema`) — Color definitions for intent, role paired, and role single colors
|
|
11
|
+
- `prefix` (`string`) — CSS variable prefix (e.g. `"my-"` produces `--my-color-primary`)
|
|
12
|
+
- `mode` (`"light" | "dark"`, optional) — Affects auto-derivation direction. Light darkens with black, dark lightens with white. Default: `"light"`
|
|
13
|
+
|
|
14
|
+
**Returns:** `GeneratedTokens` — Key-value record of token names to CSS values (keys without the `--` prefix)
|
|
15
|
+
|
|
16
|
+
**Example:**
|
|
17
|
+
```typescript
|
|
18
|
+
import { generateCssTokens } from "@marianmeres/design-tokens";
|
|
19
|
+
|
|
20
|
+
const tokens = generateCssTokens(schema.light, "app-", "light");
|
|
21
|
+
// { "app-color-primary": "#2563eb", "app-color-primary-hover": "color-mix(...)", ... }
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
### `toCssString(tokens, selector?)`
|
|
27
|
+
|
|
28
|
+
Convert a tokens record to a formatted CSS declaration block, grouped by base color name.
|
|
29
|
+
|
|
30
|
+
**Parameters:**
|
|
31
|
+
- `tokens` (`GeneratedTokens`) — Key-value token pairs (from `generateCssTokens`)
|
|
32
|
+
- `selector` (`string`, optional) — CSS selector for the block. Default: `":root"`
|
|
33
|
+
|
|
34
|
+
**Returns:** `string` — Formatted CSS string
|
|
35
|
+
|
|
36
|
+
**Example:**
|
|
37
|
+
```typescript
|
|
38
|
+
import { generateCssTokens, toCssString } from "@marianmeres/design-tokens";
|
|
39
|
+
|
|
40
|
+
const css = toCssString(tokens, ":root.dark");
|
|
41
|
+
// :root.dark {
|
|
42
|
+
// --app-color-primary: #2563eb;
|
|
43
|
+
// ...
|
|
44
|
+
// }
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
### `generateThemeCss(schema, prefix)`
|
|
50
|
+
|
|
51
|
+
Generate complete CSS for a theme with light mode and optional dark mode.
|
|
52
|
+
|
|
53
|
+
**Parameters:**
|
|
54
|
+
- `schema` (`ThemeSchema`) — Theme with required `light` and optional `dark` token schemas
|
|
55
|
+
- `prefix` (`string`) — CSS variable prefix
|
|
56
|
+
|
|
57
|
+
**Returns:** `string` — Complete CSS with `:root` for light and `:root.dark` for dark mode
|
|
58
|
+
|
|
59
|
+
**Example:**
|
|
60
|
+
```typescript
|
|
61
|
+
import { generateThemeCss } from "@marianmeres/design-tokens";
|
|
62
|
+
import { zinc } from "@marianmeres/design-tokens/themes";
|
|
63
|
+
|
|
64
|
+
const css = generateThemeCss(zinc, "app-");
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### `hexToRgb(hex)`
|
|
70
|
+
|
|
71
|
+
Parse a hex color string to RGB components. Supports 3-digit (`#abc`) and 6-digit (`#aabbcc`) formats, with or without `#` prefix.
|
|
72
|
+
|
|
73
|
+
**Parameters:**
|
|
74
|
+
- `hex` (`string`) — Hex color string
|
|
75
|
+
|
|
76
|
+
**Returns:** `[number, number, number] | null` — RGB tuple, or `null` if invalid
|
|
77
|
+
|
|
78
|
+
**Example:**
|
|
79
|
+
```typescript
|
|
80
|
+
import { hexToRgb } from "@marianmeres/design-tokens";
|
|
81
|
+
|
|
82
|
+
hexToRgb("#2563eb"); // → [37, 99, 235]
|
|
83
|
+
hexToRgb("fff"); // → [255, 255, 255]
|
|
84
|
+
hexToRgb("nope"); // → null
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
### `hexToRgbTriplet(hex)`
|
|
90
|
+
|
|
91
|
+
Convert a hex color to an `"r, g, b"` triplet string suitable for CSS `rgb()` usage.
|
|
92
|
+
|
|
93
|
+
**Parameters:**
|
|
94
|
+
- `hex` (`string`) — Hex color string
|
|
95
|
+
|
|
96
|
+
**Returns:** `string | null` — Comma-separated RGB triplet, or `null` if invalid
|
|
97
|
+
|
|
98
|
+
**Example:**
|
|
99
|
+
```typescript
|
|
100
|
+
import { hexToRgbTriplet } from "@marianmeres/design-tokens";
|
|
101
|
+
|
|
102
|
+
hexToRgbTriplet("#2563eb"); // → "37, 99, 235"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
### `generateRebootBridge(tokens, prefix)`
|
|
108
|
+
|
|
109
|
+
*Import from `@marianmeres/design-tokens/reboot`*
|
|
110
|
+
|
|
111
|
+
Map design tokens to Bootstrap Reboot `--bs-*` CSS variables. Automatically generates `-rgb` triplet companions for hex color values.
|
|
112
|
+
|
|
113
|
+
**Parameters:**
|
|
114
|
+
- `tokens` (`GeneratedTokens`) — Generated token pairs (from `generateCssTokens`)
|
|
115
|
+
- `prefix` (`string`) — The same prefix used in `generateCssTokens`
|
|
116
|
+
|
|
117
|
+
**Returns:** `GeneratedTokens` — Bootstrap bridge variables (`bs-body-bg`, `bs-link-color`, etc.)
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
### `generateThemedCss(schema, prefix)`
|
|
122
|
+
|
|
123
|
+
*Import from `@marianmeres/design-tokens/reboot`*
|
|
124
|
+
|
|
125
|
+
Generate complete themed CSS including both design tokens AND the Bootstrap Reboot bridge.
|
|
126
|
+
|
|
127
|
+
**Parameters:**
|
|
128
|
+
- `schema` (`ThemeSchema`) — Theme schema with light and optional dark modes
|
|
129
|
+
- `prefix` (`string`) — CSS variable prefix
|
|
130
|
+
|
|
131
|
+
**Returns:** `string` — Combined CSS with token variables and `--bs-*` bridge variables
|
|
132
|
+
|
|
133
|
+
**Example:**
|
|
134
|
+
```typescript
|
|
135
|
+
import { generateThemedCss } from "@marianmeres/design-tokens/reboot";
|
|
136
|
+
import { zinc } from "@marianmeres/design-tokens/themes";
|
|
137
|
+
|
|
138
|
+
const css = generateThemedCss(zinc, "app-");
|
|
139
|
+
// → :root { --app-color-primary: ...; --bs-body-bg: ...; --bs-link-color: ...; }
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Types
|
|
145
|
+
|
|
146
|
+
### `ThemeSchema`
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
type ThemeSchema = {
|
|
150
|
+
light: TokenSchema;
|
|
151
|
+
dark?: TokenSchema;
|
|
152
|
+
};
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Complete theme definition with required light mode and optional dark mode.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
### `TokenSchema`
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
type TokenSchema = {
|
|
163
|
+
colors: {
|
|
164
|
+
intent: WithRequired<IntentColorKey, ColorPair>;
|
|
165
|
+
role: {
|
|
166
|
+
paired: WithRequired<RolePairedKey, ColorPair>;
|
|
167
|
+
single: WithRequired<RoleSingleKey, SingleColor>;
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Single-mode token schema. Intent colors define primary UI actions; role colors define structural UI elements.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
### `ColorPair`
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
type ColorPair = {
|
|
181
|
+
DEFAULT: string;
|
|
182
|
+
foreground: string;
|
|
183
|
+
hover?: string;
|
|
184
|
+
active?: string;
|
|
185
|
+
};
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Color with a foreground companion. Hover/active are auto-derived when omitted.
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
### `ColorValue`
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
type ColorValue = {
|
|
196
|
+
DEFAULT: string;
|
|
197
|
+
hover?: string;
|
|
198
|
+
active?: string;
|
|
199
|
+
};
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Color with optional pseudo states.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
### `SingleColor`
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
type SingleColor = string | ColorValue;
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Either a plain CSS color string or an object with optional hover/active states.
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
### `GeneratedTokens`
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
type GeneratedTokens = Record<string, string>;
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Generated CSS token key-value pairs (keys without the `--` prefix).
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
### `IntentColorKey`
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
type IntentColorKey = "primary" | "accent" | "destructive" | "warning" | "success";
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
### `RolePairedKey`
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
type RolePairedKey = "background" | "muted" | "surface";
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
### `RoleSingleKey`
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
type RoleSingleKey = "foreground" | "border" | "input" | "ring";
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Constants
|
|
251
|
+
|
|
252
|
+
### `colors`
|
|
253
|
+
|
|
254
|
+
Complete Tailwind CSS v3 color palette as hex values. Contains `black`, `white`, and 22 color scales (slate, gray, zinc, neutral, stone, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose) each with shades 50–950.
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
import { colors } from "@marianmeres/design-tokens";
|
|
258
|
+
|
|
259
|
+
colors.blue[600] // → "#2563eb"
|
|
260
|
+
colors.white // → "#ffffff"
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Bundled Themes
|
|
266
|
+
|
|
267
|
+
*Import from `@marianmeres/design-tokens/themes`*
|
|
268
|
+
|
|
269
|
+
31 pre-built `ThemeSchema` definitions, each with light + dark mode:
|
|
270
|
+
|
|
271
|
+
`blueOrange`, `cyanRed`, `cyanSlate`, `emeraldAmberForest`, `emeraldPink`, `fuchsiaEmerald`, `gray`, `indigoAmber`, `limeFuchsiaNeon`, `monokaiCyan`, `monokaiGreen`, `monokaiPink`, `orangePinkSunset`, `pinkEmerald`, `pinkTeal`, `purpleYellow`, `rainbow`, `redBlue`, `redCyan`, `redSky`, `redSkySlate`, `roseTeal`, `skyAmber`, `slateCyan`, `slateTealOcean`, `stone`, `stoneOrangeEarth`, `tealRose`, `violetLime`, `violetRoseDusk`, `zinc`
|
package/CLAUDE.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marian Meres
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# @marianmeres/design-tokens
|
|
2
|
+
|
|
3
|
+
[](https://jsr.io/@marianmeres/design-tokens)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
A standalone CSS custom property generator for design token systems. Takes a structured
|
|
7
|
+
color token schema and produces CSS variables for light and dark modes, with automatic
|
|
8
|
+
hover/active state derivation using `color-mix()`. Ships an optional Bootstrap Reboot
|
|
9
|
+
bridge that maps tokens to `--bs-*` variables. Same mental model as
|
|
10
|
+
[@marianmeres/stuic](https://github.com/marianmeres/stuic)'s token system, but
|
|
11
|
+
framework-agnostic — no Tailwind dependency.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
deno add jsr:@marianmeres/design-tokens
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { generateThemeCss } from "@marianmeres/design-tokens";
|
|
23
|
+
import type { ThemeSchema } from "@marianmeres/design-tokens";
|
|
24
|
+
|
|
25
|
+
const theme: ThemeSchema = {
|
|
26
|
+
light: {
|
|
27
|
+
colors: {
|
|
28
|
+
intent: {
|
|
29
|
+
primary: { DEFAULT: "#2563eb", foreground: "#ffffff" },
|
|
30
|
+
accent: { DEFAULT: "#8b5cf6", foreground: "#ffffff" },
|
|
31
|
+
destructive: { DEFAULT: "#dc2626", foreground: "#ffffff" },
|
|
32
|
+
warning: { DEFAULT: "#f59e0b", foreground: "#000000" },
|
|
33
|
+
success: { DEFAULT: "#16a34a", foreground: "#ffffff" },
|
|
34
|
+
},
|
|
35
|
+
role: {
|
|
36
|
+
paired: {
|
|
37
|
+
background: { DEFAULT: "#ffffff", foreground: "#171717" },
|
|
38
|
+
muted: { DEFAULT: "#f5f5f5", foreground: "#737373" },
|
|
39
|
+
surface: { DEFAULT: "#e5e5e5", foreground: "#171717" },
|
|
40
|
+
},
|
|
41
|
+
single: {
|
|
42
|
+
foreground: "#171717",
|
|
43
|
+
border: { DEFAULT: "#d4d4d4" },
|
|
44
|
+
input: { DEFAULT: "#ffffff" },
|
|
45
|
+
ring: "color-mix(in srgb, #2563eb 25%, transparent)",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const css = generateThemeCss(theme, "my-");
|
|
53
|
+
// → :root { --my-color-primary: #2563eb; ... }
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Creating a custom theme
|
|
57
|
+
|
|
58
|
+
Use the bundled `colors` map (complete Tailwind v3 palette) to avoid looking up hex values:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { colors, generateThemeCss } from "@marianmeres/design-tokens";
|
|
62
|
+
import type { ThemeSchema } from "@marianmeres/design-tokens";
|
|
63
|
+
|
|
64
|
+
const myTheme: ThemeSchema = {
|
|
65
|
+
light: {
|
|
66
|
+
colors: {
|
|
67
|
+
intent: {
|
|
68
|
+
primary: { DEFAULT: colors.blue[600], foreground: colors.white },
|
|
69
|
+
accent: { DEFAULT: colors.violet[500], foreground: colors.white },
|
|
70
|
+
destructive: { DEFAULT: colors.red[600], foreground: colors.white },
|
|
71
|
+
warning: { DEFAULT: colors.amber[500], foreground: colors.black },
|
|
72
|
+
success: { DEFAULT: colors.emerald[600], foreground: colors.white },
|
|
73
|
+
},
|
|
74
|
+
role: {
|
|
75
|
+
paired: {
|
|
76
|
+
background: {
|
|
77
|
+
DEFAULT: colors.slate[50],
|
|
78
|
+
foreground: colors.slate[900],
|
|
79
|
+
},
|
|
80
|
+
muted: {
|
|
81
|
+
DEFAULT: colors.slate[100],
|
|
82
|
+
foreground: colors.slate[500],
|
|
83
|
+
},
|
|
84
|
+
surface: {
|
|
85
|
+
DEFAULT: colors.slate[200],
|
|
86
|
+
foreground: colors.slate[900],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
single: {
|
|
90
|
+
foreground: colors.slate[900],
|
|
91
|
+
border: { DEFAULT: colors.slate[300] },
|
|
92
|
+
input: { DEFAULT: colors.slate[50], hover: colors.slate[100] },
|
|
93
|
+
ring: `color-mix(in srgb, ${colors.blue[600]} 25%, transparent)`,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
// dark: { ... } // optional
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const css = generateThemeCss(myTheme, "my-");
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Hover/active states are auto-derived via `color-mix(in oklch, ...)` when omitted. You can
|
|
105
|
+
provide explicit values to override the derivation.
|
|
106
|
+
|
|
107
|
+
## Bundled themes
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { gray, stone, zinc } from "@marianmeres/design-tokens/themes";
|
|
111
|
+
import { generateThemeCss } from "@marianmeres/design-tokens";
|
|
112
|
+
|
|
113
|
+
const css = generateThemeCss(zinc, "app-");
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Reboot bridge
|
|
117
|
+
|
|
118
|
+
Maps design tokens to Bootstrap Reboot's `--bs-*` CSS variables:
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { generateThemedCss } from "@marianmeres/design-tokens/reboot";
|
|
122
|
+
import { zinc } from "@marianmeres/design-tokens/themes";
|
|
123
|
+
|
|
124
|
+
const css = generateThemedCss(zinc, "app-");
|
|
125
|
+
// → :root { --app-color-primary: ...; --bs-body-bg: ...; --bs-link-color: ...; }
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## API
|
|
129
|
+
|
|
130
|
+
See [API.md](API.md) for the complete API documentation.
|
|
131
|
+
|
|
132
|
+
## Types
|
|
133
|
+
|
|
134
|
+
See [src/types.ts](src/types.ts) for the full type definitions (`TokenSchema`,
|
|
135
|
+
`ThemeSchema`, `ColorPair`, `ColorValue`, etc.).
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
[MIT](LICENSE)
|