@nice2dev/design-tokens 1.0.28

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 ADDED
@@ -0,0 +1,221 @@
1
+ # @nice2dev/design-tokens
2
+
3
+ W3C Design Tokens implementation for Nice2Dev UI library.
4
+
5
+ ## Features
6
+
7
+ - 📋 **W3C Design Tokens Format** - Compliant with [W3C Design Tokens Community Group](https://tr.designtokens.org/format/)
8
+ - 🎨 **Multiple Output Formats** - CSS, SCSS, JS, TypeScript, Tailwind
9
+ - 🌙 **Theme Support** - Light, dark, high-contrast modes
10
+ - 🔗 **Token References** - Reference tokens with `{category.token}` syntax
11
+ - 🧮 **Computed Values** - Auto-resolve references and composite tokens
12
+ - 🛠️ **CLI Tool** - Generate tokens from command line
13
+ - 📦 **Programmatic API** - Use in build scripts
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @nice2dev/design-tokens
19
+ # or
20
+ pnpm add @nice2dev/design-tokens
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ### Using CLI
26
+
27
+ ```bash
28
+ # Initialize a new tokens project
29
+ npx nice-tokens init
30
+
31
+ # Build tokens
32
+ npx nice-tokens build -i ./tokens -o ./dist -f css,scss,ts
33
+
34
+ # Watch mode
35
+ npx nice-tokens build --watch
36
+ ```
37
+
38
+ ### Token Format (W3C)
39
+
40
+ ```json
41
+ {
42
+ "color": {
43
+ "$type": "color",
44
+ "primary": {
45
+ "500": {
46
+ "$value": "#3b82f6",
47
+ "$description": "Primary brand color"
48
+ }
49
+ }
50
+ },
51
+ "spacing": {
52
+ "$type": "dimension",
53
+ "md": {
54
+ "$value": "1rem"
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ ### Using References
61
+
62
+ ```json
63
+ {
64
+ "semantic": {
65
+ "button": {
66
+ "background": {
67
+ "$value": "{color.primary.500}"
68
+ }
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ ## API Usage
75
+
76
+ ```typescript
77
+ import { createGenerator } from '@nice2dev/design-tokens';
78
+
79
+ const generator = createGenerator({
80
+ formats: ['css', 'ts'],
81
+ outputDir: './dist',
82
+ prefix: 'nice',
83
+ });
84
+
85
+ generator.loadDirectory('./tokens');
86
+ await generator.generate();
87
+ ```
88
+
89
+ ## Token Types
90
+
91
+ | Type | Description | Example |
92
+ | ------------- | ---------------- | ------------------------------ |
93
+ | `color` | Color values | `#3b82f6`, `rgb(59, 130, 246)` |
94
+ | `dimension` | Sizes, spacing | `1rem`, `16px` |
95
+ | `fontFamily` | Font stacks | `["Inter", "sans-serif"]` |
96
+ | `fontWeight` | Font weights | `400`, `"bold"` |
97
+ | `duration` | Animation timing | `200ms`, `0.3s` |
98
+ | `cubicBezier` | Easing curves | `[0.4, 0, 0.2, 1]` |
99
+ | `shadow` | Box shadows | Complex object |
100
+ | `typography` | Font shorthand | Complex object |
101
+
102
+ ## Output Formats
103
+
104
+ ### CSS
105
+
106
+ ```css
107
+ :root {
108
+ --nice-color-primary-500: #3b82f6;
109
+ --nice-spacing-md: 1rem;
110
+ }
111
+ ```
112
+
113
+ ### TypeScript
114
+
115
+ ```typescript
116
+ export const tokens = {
117
+ color: {
118
+ primary: {
119
+ '500': '#3b82f6',
120
+ },
121
+ },
122
+ spacing: {
123
+ md: '1rem',
124
+ },
125
+ };
126
+ ```
127
+
128
+ ### Tailwind
129
+
130
+ ```javascript
131
+ module.exports = {
132
+ theme: {
133
+ extend: {
134
+ colors: {
135
+ primary: {
136
+ 500: '#3b82f6',
137
+ },
138
+ },
139
+ },
140
+ },
141
+ };
142
+ ```
143
+
144
+ ## Themes
145
+
146
+ The package supports multiple themes:
147
+
148
+ - `light` - Default light theme
149
+ - `dark` - Dark mode
150
+ - `high-contrast` - WCAG AAA compliant
151
+ - `high-contrast-dark` - High contrast dark mode
152
+ - `dim` - Reduced brightness mode
153
+
154
+ ### Theme Switcher
155
+
156
+ ```html
157
+ <script src="./dist/theme-switcher.js"></script>
158
+ <script>
159
+ // Set theme
160
+ setTheme('dark');
161
+
162
+ // Toggle between light/dark
163
+ toggleTheme();
164
+
165
+ // Use system preference
166
+ useSystemTheme();
167
+ </script>
168
+ ```
169
+
170
+ ### React Theme Provider
171
+
172
+ ```tsx
173
+ import { ThemeProvider, useTheme } from '@nice2dev/design-tokens/ThemeContext';
174
+
175
+ function App() {
176
+ return (
177
+ <ThemeProvider>
178
+ <MyComponent />
179
+ </ThemeProvider>
180
+ );
181
+ }
182
+
183
+ function MyComponent() {
184
+ const { theme, setTheme, toggleTheme } = useTheme();
185
+
186
+ return <button onClick={toggleTheme}>Current: {theme}</button>;
187
+ }
188
+ ```
189
+
190
+ ## CLI Commands
191
+
192
+ ```bash
193
+ # Build tokens
194
+ nice-tokens build [options]
195
+ -i, --input <dir> Input directory (default: ./tokens)
196
+ -o, --output <dir> Output directory (default: ./dist)
197
+ -f, --formats <list> Output formats (css,scss,js,ts,json,tailwind)
198
+ -p, --prefix <str> CSS variable prefix (default: nice)
199
+ --separate Generate separate files by category
200
+ --watch Watch for changes
201
+
202
+ # Initialize project
203
+ nice-tokens init [-d <dir>]
204
+
205
+ # Validate token files
206
+ nice-tokens validate <files...>
207
+ nice-tokens validate -d ./tokens
208
+
209
+ # Convert formats
210
+ nice-tokens convert <input> <output> -f <format>
211
+
212
+ # Show token info
213
+ nice-tokens info <dir>
214
+
215
+ # Compare tokens
216
+ nice-tokens diff <source> <target>
217
+ ```
218
+
219
+ ## License
220
+
221
+ MIT © Nice2Dev