@@ -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
5557const 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
8385TokenScript 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
8991Colors, units, and design concepts are first-class citizens:
9092
@@ -105,7 +107,7 @@ output;
105107
106108No string parsing. No unit confusion. Just works.
107109
108- #### 2. ** Type Safety** β
110+ #### 2. ** Type Safety**
109111
110112Catch errors before they break your design:
111113
@@ -117,7 +119,7 @@ variable result: NumberWithUnit = base * scale; // β
Works! Result: 12px
117119variable broken: NumberWithUnit = base + "hello"; // β Error at evaluation!`}
118120</TokenScriptCodeBlock >
119121
120- #### 3. ** Powerful Color Management** π
122+ #### 3. ** Powerful Color Management**
121123
122124Work 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)
156158variable lightBg: Color = #FFFFFF;
157159variable 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;
177179variable scale: Number = 1.5;
178180
179181variable xs: NumberWithUnit = baseSpacing;
180182variable sm: NumberWithUnit = baseSpacing * scale;
181183variable md: NumberWithUnit = sm * scale;
182184variable 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
186196Change ` 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
204214Update 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
222232variable 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
256248Ready 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