Skip to content

Commit 217caf1

Browse files
committed
Refine docs
1 parent cf3e46c commit 217caf1

File tree

1 file changed

+34
-50
lines changed

1 file changed

+34
-50
lines changed

β€Ždocs-intro/why-tokenscript.mdβ€Ž

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TokenScript is a domain-specific language for design tokens that brings logic, t
1212

1313
## The Problem: Static Tokens Aren't Enough
1414

15-
### Design tokens started simple...
15+
### Design tokens started simple…
1616

1717
<TokenScriptCodeBlock mode="json" showResult={false}>
1818
{`{
@@ -32,7 +32,7 @@ But real design systems need more:
3232

3333
### The current workarounds
3434

35-
**Option 1: Manual maintenance** 😫
35+
**Option 1: Manual maintenance**
3636

3737
<TokenScriptCodeBlock mode="json" showResult={false}>
3838
{`{
@@ -44,12 +44,14 @@ But real design systems need more:
4444
</TokenScriptCodeBlock>
4545

4646
**Problems:**
47+
4748
- ❌ Error-prone manual updates
4849
- ❌ No single source of truth
4950
- ❌ Scales poorly (100+ tokens = chaos)
5051
- ❌ Hard to maintain consistency
5152

52-
**Option 2: Build-time scripts** 🀷
53+
**Option 2: Build-time scripts**
54+
5355
```javascript
5456
// tokens-build.js
5557
const tokens = require('./tokens.json');
@@ -58,33 +60,33 @@ tokens['spacing.large'] = parseInt(tokens['spacing.base']) * 2 + 'px';
5860
```
5961

6062
**Problems:**
63+
6164
- ❌ Custom code for every project
6265
- ❌ No type safety (easy to break)
63-
- ❌ Hard to share/reuse
66+
- ❌ Hard to share & reuse
6467
- ❌ Debugging is painful
6568
- ❌ No standard format
6669

67-
**Option 3: CSS/SCSS variables** 🎨
68-
```scss
69-
$spacing-base: 8px;
70-
$spacing-large: $spacing-base * 2;
70+
**Option 3: CSS variables**
71+
72+
```css
73+
--spacing-base: 8px;
74+
--spacing-large: calc(var(--spacing-base) * 2);
7175
```
7276

7377
**Problems:**
78+
7479
- ❌ Limited to CSS/SCSS ecosystems
75-
- ❌ Can't use in JavaScript, native apps, etc.
7680
- ❌ No color space conversions
7781
- ❌ Poor tooling for design tokens
7882

79-
---
80-
8183
## The Solution: TokenScript
8284

8385
TokenScript is a **type-safe language for design token logic** that integrates seamlessly with token files.
8486

8587
### What makes TokenScript different?
8688

87-
#### 1. **Design-Native Types** 🎨
89+
#### 1. **Design-Native Types**
8890

8991
Colors, units, and design concepts are first-class citizens:
9092

@@ -105,7 +107,7 @@ output;
105107

106108
No string parsing. No unit confusion. Just works.
107109

108-
#### 2. **Type Safety** βœ…
110+
#### 2. **Type Safety**
109111

110112
Catch errors before they break your design:
111113

@@ -117,7 +119,7 @@ variable result: NumberWithUnit = base * scale; // βœ… Works! Result: 12px
117119
variable broken: NumberWithUnit = base + "hello"; // ❌ Error at evaluation!`}
118120
</TokenScriptCodeBlock>
119121

120-
#### 3. **Powerful Color Management** 🌈
122+
#### 3. **Powerful Color Management**
121123

122124
Work in any color space with automatic conversions:
123125

@@ -128,7 +130,7 @@ return lighter.to.oklch();
128130
`}
129131
</TokenScriptCodeBlock>
130132

131-
#### 4. **Standards-Based** πŸ“‹
133+
#### 4. **Standards-Based**
132134

133135
<TokenScriptCodeBlock mode="json">
134136
{`{
@@ -143,15 +145,15 @@ return lighter.to.oklch();
143145
}`}
144146
</TokenScriptCodeBlock>
145147

146-
## Real-World Use Cases
148+
## Use Cases
147149

148-
### Use Case 1: Automated Theme Generation
150+
### Automated Theme Generation
149151

150152
**Problem:** Manually maintaining light and dark themes is error-prone.
151153

152154
**Solution:** Generate dark theme from light theme automatically:
153155

154-
<TokenScriptCodeBlock mode="script" showResult={false}>
156+
<TokenScriptCodeBlock mode="script">
155157
{`// Light theme (source of truth)
156158
variable lightBg: Color = #FFFFFF;
157159
variable lightText: Color = #000000;
@@ -166,26 +168,34 @@ if (contrast(darkText, darkBg) < 4.5) [
166168
]`}
167169
</TokenScriptCodeBlock>
168170

169-
### Use Case 2: Responsive Spacing Scale
171+
### Responsive Spacing Scale
170172

171173
**Problem:** Spacing needs to scale proportionally across breakpoints.
172174

173175
**Solution:** Define once, compute everywhere:
174176

175-
<TokenScriptCodeBlock mode="script" showResult={false}>
177+
<TokenScriptCodeBlock mode="script" lines={{ end: 8 }}>
176178
{`variable baseSpacing: NumberWithUnit = 4px;
177179
variable scale: Number = 1.5;
178180

179181
variable xs: NumberWithUnit = baseSpacing;
180182
variable sm: NumberWithUnit = baseSpacing * scale;
181183
variable md: NumberWithUnit = sm * scale;
182184
variable lg: NumberWithUnit = md * scale;
183-
variable xl: NumberWithUnit = lg * scale;`}
185+
variable xl: NumberWithUnit = lg * scale;
186+
187+
variable output: Dictionary;
188+
output.set("xs", xs);
189+
output.set("sm", sm);
190+
output.set("md", md);
191+
output.set("lg", lg);
192+
output.set("xl", xl);
193+
return output;`}
184194
</TokenScriptCodeBlock>
185195

186196
Change `baseSpacing` once β†’ entire scale updates automatically.
187197

188-
### Use Case 3: Color Ramps
198+
### Color Ramps
189199

190200
**Problem:** Need 9 shades of each color, consistently.
191201

@@ -203,7 +213,7 @@ variable brand900: Color = darken(brand, 40);`}
203213

204214
Update brand color once β†’ all shades regenerate.
205215

206-
### Use Case 4: Unit Conversion for Multi-Platform
216+
### Unit Conversion for Multi-Platform
207217

208218
**Problem:** iOS needs `pt`, Android needs `dp`, web needs `px`.
209219

@@ -222,22 +232,6 @@ variable androidSpacing: NumberWithUnit = baseSpacing; // 16dp
222232
variable remSpacing: NumberWithUnit = baseSpacing.convertTo("rem", 16); // 1rem`}
223233
</TokenScriptCodeBlock>
224234

225-
---
226-
227-
## TokenScript vs. Alternatives
228-
229-
| Feature | TokenScript | Style Dictionary | Theo | CSS Variables | Custom Scripts |
230-
|----------------------|------------------|------------------|---------------|---------------|------------------|
231-
| **Type Safety** | βœ… Built-in | ❌ No | ❌ No | ❌ No | 🟑 DIY |
232-
| **Color Spaces** | βœ… Oklch, P3+ | 🟑 Basic | 🟑 Basic | 🟑 Limited | 🟑 DIY |
233-
| **JSON** | βœ… Native | 🟑 Plugin | ❌ No | N/A | 🟑 DIY |
234-
| **Logic/Conditions** | βœ… Full language | 🟑 Transforms | 🟑 Limited | ❌ No | βœ… Yes (custom) |
235-
| **Embeddable** | βœ… CLI + API | 🟑 CLI mainly | 🟑 CLI mainly | N/A | 🟑 DIY |
236-
| **Learning Curve** | 🟑 Moderate | 🟑 Moderate | 🟒 Easy | 🟒 Easy | πŸ”΄ High (custom) |
237-
| **Extensibility** | βœ… JSON schemas | 🟑 Transforms | 🟑 Limited | ❌ No | βœ… Full (custom) |
238-
239-
---
240-
241235
## What Can You Build With TokenScript?
242236

243237
- **Design token resolvers** - Turn JSON into platform-specific formats
@@ -249,15 +243,13 @@ variable remSpacing: NumberWithUnit = baseSpacing.convertTo("rem", 16); // 1rem
249243
- **CLI tools** - Automate token workflows
250244
- **Token documentation** - Auto-generate docs from tokens
251245

252-
---
253-
254246
## Getting Started
255247

256248
Ready to try TokenScript? Here's how:
257249

258250
### 1. **Quick Start (5 minutes)**
259251
```bash
260-
npm install @tokens-studio/tokenscript-interpreter
252+
npm install --save @tokens-studio/tokenscript-interpreter
261253
```
262254
[Follow the Quick Start Guide](/intro/quick-start)
263255

@@ -277,12 +269,4 @@ Embed the interpreter in your build pipeline.
277269
<a href="/intro/quick-start" class="button button--primary button--lg">
278270
Try the 5-Minute Quick Start
279271
</a>
280-
<a href="/intro/installation" class="button button--secondary button--lg">
281-
Installation Guide
282-
</a>
283272
</div>
284-
285-
---
286-
287-
**TokenScript**: Turn your design tokens into a living, type-safe system. πŸš€
288-

0 commit comments

Comments
Β (0)