@phcdevworks/spectre-tokens 0.1.0 → 0.2.1

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 CHANGED
@@ -1,17 +1,19 @@
1
1
  # @phcdevworks/spectre-tokens
2
2
 
3
- Design-token source of truth that powers Spectre UI, Spectre Blocks, Spectre Astro, Spectre 11ty, and every future Spectre surface.
3
+ JSON-first design tokens that power Spectre UI, Spectre Blocks, Spectre Astro, Spectre 11ty, and every future Spectre surface.
4
4
 
5
- > 📋 **[View Roadmap](ROADMAP.md)** | 🤝 **[Contributing Guide](CONTRIBUTING.md)** | 📝 **[Changelog](CHANGELOG.md)**
5
+ 🤝 **[Contributing Guide](CONTRIBUTING.md)** | 📝 **[Changelog](CHANGELOG.md)**
6
6
 
7
7
  ## Overview
8
8
 
9
- `@phcdevworks/spectre-tokens` defines Spectre's visual language—colors, typography, spacing, radii, shadows, breakpoints, z-index scales, transitions, and CRO-focused interaction states. The package turns the raw JSON tokens in `tokens/` into multiple consumption modes (JS, TS, Tailwind, CSS variables) so that teams can stay in sync regardless of framework. One token system runs the entire Spectre Suite; every other package simply consumes these values.
9
+ `@phcdevworks/spectre-tokens` defines Spectre's visual language—colors, typography, space, radii, shadows, breakpoints, z-index scales, transitions, and CRO-focused interaction states. The package turns the raw JSON tokens in `tokens/` into multiple consumption modes (JS, TS, Tailwind, CSS variables) so teams can stay in sync regardless of framework.
10
+
11
+ **Single source of truth:** JSON is the source. Everything else is generated.
10
12
 
11
13
  - ✅ Centralized token definitions and semantic naming
12
14
  - ✅ JS/TS objects, Tailwind theme + preset, and CSS variable outputs
13
- - ✅ CRO-focused surfaces (buttons, forms, states) and WCAG-first accessibility tokens
14
- - ✅ Format-agnostic helpers for scoped CSS variable generation
15
+ - ✅ CRO-focused surfaces (buttons, forms, states) and accessibility-first tokens
16
+ - ✅ Helpers for scoped CSS variable generation
15
17
  - ✅ Type-safe outputs with bundled `.d.ts` files
16
18
 
17
19
  ## Installation
@@ -20,6 +22,70 @@ Design-token source of truth that powers Spectre UI, Spectre Blocks, Spectre Ast
20
22
  npm install @phcdevworks/spectre-tokens
21
23
  ```
22
24
 
25
+ ## Quick Start
26
+
27
+ ### Option 1: CSS Variables (fastest)
28
+
29
+ **Recommended (bundlers):**
30
+
31
+ If you’re not using a bundler, copy `dist/index.css` into your app and link it.
32
+
33
+ ```css
34
+ @import "@phcdevworks/spectre-tokens/dist/index.css";
35
+ ```
36
+
37
+ or:
38
+
39
+ ```ts
40
+ import "@phcdevworks/spectre-tokens/dist/index.css";
41
+ ```
42
+
43
+ **Use semantic tokens (recommended):**
44
+
45
+ ```css
46
+ .my-button {
47
+ background: var(--sp-button-primary-bg);
48
+ color: var(--sp-button-primary-text);
49
+ padding: var(--sp-space-12) var(--sp-space-24);
50
+ border-radius: var(--sp-radius-md);
51
+ }
52
+ ```
53
+
54
+ > Note: Raw palette tokens like `--sp-color-brand-500` are stable utilities, but they do not adapt across modes by themselves. Prefer semantic tokens (`surface.*`, `text.*`, `component.*`, `buttons.*`, `forms.*`) for theme-aware UI.
55
+
56
+ ### Option 2: JavaScript/TypeScript
57
+
58
+ ```ts
59
+ import tokens from "@phcdevworks/spectre-tokens";
60
+
61
+ const styles = {
62
+ color: tokens.colors.brand["500"],
63
+ padding: `${tokens.space["12"]} ${tokens.space["24"]}`,
64
+ borderRadius: tokens.radii.md,
65
+ };
66
+ ```
67
+
68
+ ### Option 3: Tailwind CSS
69
+
70
+ ```ts
71
+ // tailwind.config.ts
72
+ import { tailwindPreset } from "@phcdevworks/spectre-tokens";
73
+
74
+ export default {
75
+ presets: [tailwindPreset],
76
+ content: ["./src/**/*.{js,jsx,ts,tsx}"],
77
+ };
78
+ ```
79
+
80
+ ```html
81
+ <!-- Use Spectre tokens via Tailwind utilities -->
82
+ <button class="bg-brand-500 text-white px-6 py-3 rounded-md shadow-md">
83
+ Click me
84
+ </button>
85
+ ```
86
+
87
+ > Tip: Tailwind palette utilities like `bg-brand-500` are stable, but they won’t automatically adapt across modes. For theme-aware UI, prefer semantic CSS variables (`surface.*`, `text.*`, `component.*`) or Spectre UI recipes.
88
+
23
89
  ## Usage
24
90
 
25
91
  ### 1. Import tokens (JS/TS)
@@ -31,13 +97,46 @@ import tokens, {
31
97
  generateCssVariables,
32
98
  } from "@phcdevworks/spectre-tokens";
33
99
 
34
- console.log(tokens.colors.brand["500"]); // Brand palette swatches
100
+ console.log(tokens.colors.brand["500"]); // "#8652ff"
101
+ console.log(tokens.space["16"]); // "1rem"
102
+ console.log(tokens.buttons.primary.bg); // "#8652ff"
35
103
  ```
36
104
 
37
- - `tokens`: Raw structured tokens (colors, spacing, radii, typography, shadows, z-index, transitions, buttons, forms, accessibility, animations, opacity).
38
- - `tailwindTheme`: Ready-to-use Tailwind theme object.
39
- - `tailwindPreset`: Preset for Tailwind config (includes theme).
40
- - `generateCssVariables()`: Generate custom `--sp-*` CSS variable strings with scoped selectors or prefixes.
105
+ **Exports:**
106
+
107
+ - `tokens` (default export): Complete token object with flattened structure for easy access
108
+ - `tailwindTheme`: Ready-to-use Tailwind theme object
109
+ - `tailwindPreset`: Preset for Tailwind config (includes theme)
110
+ - `generateCssVariables()`: Generate custom `--sp-*` CSS variable strings with scoped selectors or prefixes
111
+
112
+ `generateCssVariables()` returns a CSS **string** (e.g. `:root { --sp-... }`) you can write to a file or inject into a page.
113
+
114
+ **Token Structure (high-level namespaces):**
115
+
116
+ The `tokens` object includes:
117
+
118
+ - `colors`: Color palettes (brand, neutral, accent, success, warning, error, info, focus)
119
+ - `space`: Spacing scale (0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 56, 64, 80, 96)
120
+ - `layout`: Semantic layout tokens (section, stack, container padding/gaps)
121
+ - `radii`: Border radius values (none, sm, md, lg, pill)
122
+ - `typography`: Font families and complete typography scale with metadata
123
+ - `font`: Simplified font size/lineHeight/weight tokens for quick access
124
+ - `shadows`: Box shadow tokens (none, sm, md, lg)
125
+ - `breakpoints`: Responsive breakpoints (sm, md, lg, xl, 2xl)
126
+ - `zIndex`: Z-index scale (base, dropdown, sticky, fixed, overlay, modal, popover, tooltip)
127
+ - `transitions`: Duration and easing tokens
128
+ - `animations`: Animation presets with duration, easing, and keyframe references
129
+ - `buttons`: Button state tokens (primary, secondary, ghost, danger, success)
130
+ - `forms`: Form state tokens (default, hover, focus, valid, invalid, disabled)
131
+ - `accessibility`: WCAG compliance tokens (focus ring, touch targets, min text size)
132
+ - `opacity`: Opacity scale (hover, active, disabled, focus, overlay, tooltip)
133
+ - `borders`: Border color tokens
134
+ - `surface`: Semantic surface backgrounds (page, card, input, overlay)
135
+ - `text`: Semantic text colors (onPage, onSurface with default/muted/subtle/meta)
136
+ - `component`: Component-specific tokens (card, input, button, badge, iconBox)
137
+ - `modes`: Theme mode definitions (default/light and dark)
138
+
139
+ > Tokens may exist before UI primitives land in `@phcdevworks/spectre-ui`. Tokens define meaning; UI defines structure.
41
140
 
42
141
  ### 2. CSS variables
43
142
 
@@ -45,8 +144,8 @@ console.log(tokens.colors.brand["500"]); // Brand palette swatches
45
144
  @import "@phcdevworks/spectre-tokens/dist/index.css";
46
145
 
47
146
  .button {
48
- color: var(--sp-color-brand-500);
49
- padding-inline: var(--sp-space-md);
147
+ color: var(--sp-text-on-page-default);
148
+ padding-inline: var(--sp-space-16);
50
149
  border-radius: var(--sp-radius-pill);
51
150
  box-shadow: var(--sp-shadow-md);
52
151
  }
@@ -154,56 +253,498 @@ tokens.animations.pulse;
154
253
  ### Opacity scale
155
254
 
156
255
  ```ts
157
- tokens.opacity.hover; // 0.92
158
- tokens.opacity.active; // 0.84
159
- tokens.opacity.disabled; // 0.38
160
- tokens.opacity.overlay; // 0.5
256
+ tokens.opacity.hover; // "0.92"
257
+ tokens.opacity.active; // "0.84"
258
+ tokens.opacity.disabled; // "0.38"
259
+ tokens.opacity.overlay; // "0.5"
260
+ tokens.opacity.focus; // "1"
261
+ tokens.opacity.tooltip; // "0.95"
262
+ ```
263
+
264
+ ### Typography: Font vs Typography
265
+
266
+ Spectre provides **two ways** to access typography tokens:
267
+
268
+ #### 1. `tokens.font.*` - Simplified Quick Access
269
+
270
+ For simple use cases, use the `font` object which provides direct access to size, line height, and weight:
271
+
272
+ ```ts
273
+ tokens.font.xs; // { size: "0.75rem", lineHeight: "1.25rem", weight: 400 }
274
+ tokens.font.sm; // { size: "0.875rem", lineHeight: "1.5rem", weight: 400 }
275
+ tokens.font.md; // { size: "1rem", lineHeight: "1.75rem", weight: 500 }
276
+ tokens.font.lg; // { size: "1.25rem", lineHeight: "2rem", weight: 500 }
277
+ tokens.font.xl; // { size: "1.5rem", lineHeight: "2.125rem", weight: 600 }
278
+ tokens.font["2xl"]; // { size: "1.875rem", lineHeight: "2.5rem", weight: 600 }
279
+ ```
280
+
281
+ #### 2. `tokens.typography.*` - Complete Typography System
282
+
283
+ For advanced typography with font families and additional properties like letter spacing:
284
+
285
+ ```ts
286
+ // Font families
287
+ tokens.typography.families.sans; // "'Inter', 'Helvetica Neue', Arial, sans-serif"
288
+ tokens.typography.families.serif; // "'Spectre Serif', 'Georgia', serif"
289
+ tokens.typography.families.mono; // "'JetBrains Mono', 'SFMono-Regular', Consolas, monospace"
290
+
291
+ // Typography scale (includes all font properties plus letter spacing)
292
+ tokens.typography.scale.xs; // { fontSize: "0.75rem", lineHeight: "1.25rem", fontWeight: 400, letterSpacing: "0.02em" }
293
+ tokens.typography.scale.sm; // { fontSize: "0.875rem", lineHeight: "1.5rem", fontWeight: 400 }
294
+ tokens.typography.scale.md; // { fontSize: "1rem", lineHeight: "1.75rem", fontWeight: 500 }
295
+ tokens.typography.scale.lg; // { fontSize: "1.25rem", lineHeight: "2rem", fontWeight: 600 }
296
+ tokens.typography.scale.xl; // { fontSize: "1.5rem", lineHeight: "2.125rem", fontWeight: 600 }
297
+ tokens.typography.scale["2xl"]; // { fontSize: "1.875rem", lineHeight: "2.5rem", fontWeight: 700 }
298
+ tokens.typography.scale["3xl"]; // { fontSize: "2.25rem", lineHeight: "2.75rem", fontWeight: 700 }
299
+ ```
300
+
301
+ **When to use which:**
302
+
303
+ - Use `tokens.font.*` for quick, simple typography applications
304
+ - Use `tokens.typography.*` when you need font families or letter spacing
305
+ - Use `tokens.typography.scale.*` for complete typographic control
306
+
307
+ ### Typography CSS Variables
308
+
309
+ All typography tokens are available as CSS variables:
310
+
311
+ ```css
312
+ .heading {
313
+ font-family: var(--sp-typography-family-sans);
314
+ font-size: var(--sp-font-xl-size);
315
+ line-height: var(--sp-font-xl-line-height);
316
+ font-weight: var(--sp-font-xl-weight);
317
+ }
318
+
319
+ .body-text {
320
+ font-size: var(--sp-font-md-size);
321
+ line-height: var(--sp-font-md-line-height);
322
+ font-weight: var(--sp-font-md-weight);
323
+ }
324
+
325
+ .code-block {
326
+ font-family: var(--sp-typography-family-mono);
327
+ font-size: var(--sp-font-sm-size);
328
+ }
329
+ ```
330
+
331
+ ### Badge tokens
332
+
333
+ Badges have background and text colors for five semantic variants:
334
+
335
+ ```ts
336
+ // Access via component namespace
337
+ tokens.component.badge.neutralBg; // "#f1f5f9" (light) / "#334155" (dark)
338
+ tokens.component.badge.neutralText; // "#334155" (light) / "#f1f5f9" (dark)
339
+ tokens.component.badge.infoBg; // "#dbeafe" (light) / "#1e40af" (dark)
340
+ tokens.component.badge.infoText; // "#1d4ed8" (light) / "#dbeafe" (dark)
341
+ tokens.component.badge.successBg; // "#dcfce7" (light) / "#166534" (dark)
342
+ tokens.component.badge.successText; // "#15803d" (light) / "#dcfce7" (dark)
343
+ tokens.component.badge.warningBg; // "#fef3c7" (light) / "#92400e" (dark)
344
+ tokens.component.badge.warningText; // "#b45309" (light) / "#fef3c7" (dark)
345
+ tokens.component.badge.dangerBg; // "#fee2e2" (light) / "#991b1b" (dark)
346
+ tokens.component.badge.dangerText; // "#b91c1c" (light) / "#fee2e2" (dark)
347
+ ```
348
+
349
+ **CSS Variables:**
350
+
351
+ ```css
352
+ .badge {
353
+ background: var(--sp-badge-neutral-bg);
354
+ color: var(--sp-badge-neutral-text);
355
+ padding: 0.25rem 0.5rem;
356
+ border-radius: var(--sp-radius-sm);
357
+ font-size: var(--sp-font-xs-size);
358
+ font-weight: var(--sp-font-xs-weight);
359
+ }
360
+
361
+ .badge--info {
362
+ background: var(--sp-badge-info-bg);
363
+ color: var(--sp-badge-info-text);
364
+ }
365
+
366
+ .badge--success {
367
+ background: var(--sp-badge-success-bg);
368
+ color: var(--sp-badge-success-text);
369
+ }
370
+
371
+ .badge--warning {
372
+ background: var(--sp-badge-warning-bg);
373
+ color: var(--sp-badge-warning-text);
374
+ }
375
+
376
+ .badge--danger {
377
+ background: var(--sp-badge-danger-bg);
378
+ color: var(--sp-badge-danger-text);
379
+ }
380
+ ```
381
+
382
+ ### Icon Box tokens
383
+
384
+ Icon boxes are decorative containers for icons with semantic color states:
385
+
386
+ ```ts
387
+ // Background and border
388
+ tokens.component.iconBox.bg; // "#ffffff" (light) / "#1e293b" (dark)
389
+ tokens.component.iconBox.border; // "#e2e8f0" (light) / "#334155" (dark)
390
+
391
+ // Icon colors for different states
392
+ tokens.component.iconBox.iconDefault; // "#6c32e6" (light) / "#a37aff" (dark)
393
+ tokens.component.iconBox.iconSuccess; // "#16a34a" (light) / "#4ade80" (dark)
394
+ tokens.component.iconBox.iconWarning; // "#d97706" (light) / "#fbbf24" (dark)
395
+ tokens.component.iconBox.iconDanger; // "#dc2626" (light) / "#ef4444" (dark)
396
+ ```
397
+
398
+ **CSS Variables:**
399
+
400
+ ```css
401
+ .icon-box {
402
+ background: var(--sp-icon-box-bg);
403
+ border: 1px solid var(--sp-icon-box-border);
404
+ border-radius: var(--sp-radius-md);
405
+ padding: var(--sp-space-12);
406
+ }
407
+
408
+ .icon-box__icon {
409
+ color: var(--sp-icon-box-icon-default);
410
+ }
411
+
412
+ .icon-box--success .icon-box__icon {
413
+ color: var(--sp-icon-box-icon-success);
414
+ }
415
+
416
+ .icon-box--warning .icon-box__icon {
417
+ color: var(--sp-icon-box-icon-warning);
418
+ }
419
+
420
+ .icon-box--danger .icon-box__icon {
421
+ color: var(--sp-icon-box-icon-danger);
422
+ }
423
+ ```
424
+
425
+ ### Meta text
426
+
427
+ For secondary/metadata text styling:
428
+
429
+ ```ts
430
+ tokens.text.onPage.meta; // Metadata text on page backgrounds
431
+ tokens.text.onSurface.meta; // Metadata text on card/surface backgrounds
432
+ ```
433
+
434
+ ```css
435
+ .timestamp,
436
+ .byline {
437
+ color: var(--sp-text-on-page-meta);
438
+ font-size: var(--sp-font-sm-size);
439
+ }
161
440
  ```
162
441
 
163
442
  ### WCAG targets
164
443
 
165
- - Brand 500 on white AAA (4.8:1)
166
- - Success 600 on white → ✅ AAA (4.7:1)
167
- - Error 600 on white → ✅ AAA (5.2:1)
168
- - Neutral 900 on white → ✅ AAA (16.1:1)
169
- - Neutral 700 on white → ✅ AA (8.4:1)
170
- - Focus rings meet WCAG 2.4.7 (2px solid, high contrast)
444
+ Spectre encodes accessibility constraints (focus rings, touch targets, and contrast-minded semantic roles) at the token level. Always validate final UI implementations with tools like the WebAIM Contrast Checker.
171
445
 
172
446
  Always re-run final UI implementations through tools like [WebAIM Contrast Checker](https://webaim.org/resources/contrastchecker/).
173
447
 
448
+ ## Spacing & Layout Tokens
449
+
450
+ - **8px grid**: `space.*` follows an 8px rhythm with a single 4px micro step for fine-grain alignment. Scale: 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 56, 64, 80, 96 (all in px, emitted as rem).
451
+ - **Semantic layout**: `layout.section.padding.{sm,md,lg}` → `space.24/32/48`; `layout.section.gap.{sm,md,lg}` → `space.16/24/32`; `layout.stack.gap.{sm,md,lg}` → `space.8/12/16`; `layout.container.paddingInline.{sm,md,lg}` → `space.16/24/32`.
452
+ - **Outputs**: CSS vars like `--sp-space-24` and `--sp-layout-section-padding-md`; Tailwind `theme.spacing` is sourced from `space.*`.
453
+ - **Usage**: Use `layout.*` for consistent gutters/padding rather than ad-hoc numbers. Example: `gap: var(--sp-layout-stack-gap-md);` or `padding-inline: var(--sp-layout-container-padding-inline-lg);`.
454
+ - **Responsiveness lives in Spectre UI**: apply breakpoint logic and component behavior in `@phcdevworks/spectre-ui` or consumers; keep tokens meaning-only.
455
+
174
456
  ## Surface & Typography Roles
175
457
 
176
458
  - `surface.page`, `surface.card`, `surface.input`, `surface.overlay`: semantic backgrounds for the app canvas, containers/tiles, form fields, and modal/dropdown layers.
177
459
  - `text.onPage.*` vs `text.onSurface.*`: use `onPage` for copy sitting directly on the page canvas; use `onSurface` for text inside cards, tiles, inputs, overlays, and other elevated surfaces.
178
- - `component.card.text`/`textMuted`, `component.input.text`/`placeholder`, and `component.button.textDefault`/`textOnPrimary` alias the underlying `text.onSurface` roles (with `textOnPrimary` pairing white against the primary button background) to keep component defaults aligned.
460
+ - `text.onPage.default`, `text.onPage.muted`, `text.onPage.subtle`, `text.onPage.meta`
461
+ - `text.onSurface.default`, `text.onSurface.muted`, `text.onSurface.subtle`, `text.onSurface.meta`
462
+ - `component.card.text`/`textMuted`, `component.input.text`/`placeholder`, `component.button.textDefault`/`textOnPrimary`, and `component.badge.*` alias the underlying semantic roles to keep component defaults aligned.
463
+
464
+ ## Modes & Theme Switching
465
+
466
+ Spectre tokens ship with a comprehensive `modes` system for theme support:
467
+
468
+ ```ts
469
+ tokens.modes.default; // Light theme semantic tokens
470
+ tokens.modes.dark; // Dark theme semantic tokens
471
+ ```
179
472
 
180
- ## Modes
473
+ ### Mode Structure
181
474
 
182
- Tokens ship with a `modes` object:
475
+ Each mode contains semantic tokens that adapt to the theme:
183
476
 
184
- - `modes.default` is the light theme.
185
- - `modes.dark` is the dark theme.
477
+ ```ts
478
+ // Light mode (tokens.modes.default)
479
+ {
480
+ surface: {
481
+ page: { value: "#f8fafc" },
482
+ card: { value: "#ffffff" },
483
+ input: { value: "#ffffff" },
484
+ overlay: { value: "rgba(15,23,42,0.6)" }
485
+ },
486
+ text: {
487
+ onPage: {
488
+ default: { value: "#0f172a" },
489
+ muted: { value: "#475569" },
490
+ subtle: { value: "#94a3b8" },
491
+ meta: { value: "#94a3b8" }
492
+ },
493
+ onSurface: { /* ... */ }
494
+ },
495
+ component: {
496
+ card: { text: { value: "#0f172a" }, textMuted: { value: "#6b7280" } },
497
+ input: { text: { value: "#0f172a" }, placeholder: { value: "#94a3b8" } },
498
+ button: { textDefault: { value: "#0f172a" }, textOnPrimary: { value: "#ffffff" } },
499
+ badge: { /* ... */ },
500
+ iconBox: { /* ... */ }
501
+ }
502
+ }
186
503
 
187
- The CSS generator outputs:
504
+ // Dark mode (tokens.modes.dark) - same structure with dark-adapted values
505
+ ```
188
506
 
189
- - `:root { ... }` for `modes.default`
190
- - `:root[data-spectre-theme="dark"] { ... }` for `modes.dark`
507
+ ### Accessing Semantic Tokens
191
508
 
192
- Consumers can toggle themes by setting `data-spectre-theme="dark"` on `:root` or `<html>`.
509
+ The TypeScript library flattens mode tokens to the root level for convenient access:
510
+
511
+ > Note: The JS `tokens.*` values resolve to the default mode. Theme switching happens in CSS via `:root[data-spectre-theme="dark"]` and semantic CSS variables.
512
+
513
+ ```ts
514
+ // These are automatically resolved from modes.default
515
+ tokens.surface.page; // "#f8fafc" in light mode
516
+ tokens.text.onPage.default; // "#0f172a" in light mode
517
+ tokens.component.card.text; // "#0f172a" in light mode
518
+ ```
519
+
520
+ ### CSS Variable Output
521
+
522
+ The CSS generator outputs mode-specific variables:
523
+
524
+ ```css
525
+ /* Default (light) theme */
526
+ :root {
527
+ --sp-surface-page: #f8fafc;
528
+ --sp-surface-card: #ffffff;
529
+ --sp-text-on-page-default: #0f172a;
530
+ /* ... */
531
+ }
532
+
533
+ /* Dark theme */
534
+ :root[data-spectre-theme="dark"] {
535
+ --sp-surface-page: #0f172a;
536
+ --sp-surface-card: #1e293b;
537
+ --sp-text-on-page-default: #f8fafc;
538
+ /* ... */
539
+ }
540
+ ```
541
+
542
+ ### Enabling Dark Mode
543
+
544
+ Toggle themes by setting the `data-spectre-theme` attribute:
545
+
546
+ ```html
547
+ <!-- Light mode (default) -->
548
+ <html>
549
+ <!-- Your content -->
550
+ </html>
551
+
552
+ <!-- Dark mode -->
553
+ <html data-spectre-theme="dark">
554
+ <!-- Your content -->
555
+ </html>
556
+ ```
557
+
558
+ ```js
559
+ function setTheme(theme) {
560
+ const html = document.documentElement;
561
+ if (!theme || theme === "default") html.removeAttribute("data-spectre-theme");
562
+ else html.setAttribute("data-spectre-theme", theme);
563
+ }
564
+
565
+ function toggleTheme() {
566
+ const html = document.documentElement;
567
+ const currentTheme = html.getAttribute("data-spectre-theme");
568
+ setTheme(currentTheme === "dark" ? "default" : "dark");
569
+ }
570
+
571
+ // Set based on user preference
572
+ if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
573
+ setTheme("dark");
574
+ }
575
+ ```
576
+
577
+ ### Semantic Token Benefits
578
+
579
+ - **Automatic theme adaptation**: All semantic tokens (surface, text, component) automatically adapt when switching themes
580
+ - **No manual color management**: Reference semantic tokens instead of raw colors
581
+ - **Consistent UX**: Components using semantic tokens maintain proper contrast in both themes
582
+ - **Type-safe**: TypeScript definitions ensure you only use valid semantic token paths
193
583
 
194
584
  ### Key CSS variables
195
585
 
196
586
  These variables are the contract consumed by `@phcdevworks/spectre-ui`; removing or renaming them will break downstream UI packages.
197
587
 
198
- - Surface: `--sp-surface-page`, `--sp-surface-card`, `--sp-surface-input`, `--sp-surface-overlay`
199
- - Text: `--sp-text-on-page-default`, `--sp-text-on-page-muted`, `--sp-text-on-surface-default`, `--sp-text-on-surface-muted`
200
- - Components/buttons: `--sp-component-card-text`, `--sp-component-card-text-muted`, `--sp-component-input-text`, `--sp-component-input-placeholder`, `--sp-button-primary-bg`, `--sp-button-primary-text`, `--sp-button-secondary-bg`, `--sp-button-secondary-text`, `--sp-button-ghost-bg`, `--sp-button-ghost-text`
588
+ - **Surface**: `--sp-surface-page`, `--sp-surface-card`, `--sp-surface-input`, `--sp-surface-overlay`
589
+ - **Text**: `--sp-text-on-page-default`, `--sp-text-on-page-muted`, `--sp-text-on-page-subtle`, `--sp-text-on-page-meta`, `--sp-text-on-surface-default`, `--sp-text-on-surface-muted`, `--sp-text-on-surface-subtle`, `--sp-text-on-surface-meta`
590
+ - **Components**: `--sp-component-card-text`, `--sp-component-card-text-muted`, `--sp-component-input-text`, `--sp-component-input-placeholder`, `--sp-badge-neutral-bg`, `--sp-badge-neutral-text`
591
+ - **Buttons**: `--sp-button-primary-bg`, `--sp-button-primary-text`, `--sp-button-secondary-bg`, `--sp-button-secondary-text`, `--sp-button-ghost-bg`, `--sp-button-ghost-text`
592
+ - **Typography**: `--sp-font-{xs,sm,md,lg,xl}-size`, `--sp-font-{xs,sm,md,lg,xl}-line-height`, `--sp-font-{xs,sm,md,lg,xl}-weight`
593
+
594
+ ## Complete Token Reference
595
+
596
+ ### Color Tokens
597
+
598
+ ```ts
599
+ // Brand colors (purple)
600
+ tokens.colors.brand["50"]; // "#f5f0ff"
601
+ tokens.colors.brand["500"]; // "#8652ff"
602
+ tokens.colors.brand["900"]; // "#241147"
603
+
604
+ // Neutral grays
605
+ tokens.colors.neutral["50"]; // "#f8fafc"
606
+ tokens.colors.neutral["500"]; // "#64748b"
607
+ tokens.colors.neutral["900"]; // "#0f172a"
608
+
609
+ // Accent (teal/cyan)
610
+ tokens.colors.accent["500"]; // "#03e6b3"
611
+
612
+ // Semantic colors
613
+ tokens.colors.success["500"]; // "#22c55e"
614
+ tokens.colors.warning["500"]; // "#f59e0b"
615
+ tokens.colors.error["500"]; // "#ef4444"
616
+ tokens.colors.info["500"]; // "#3b82f6"
617
+
618
+ // Focus colors
619
+ tokens.colors.focus.primary; // "#8652ff"
620
+ tokens.colors.focus.error; // "#ef4444"
621
+ tokens.colors.focus.info; // "#3b82f6"
622
+ ```
623
+
624
+ ### Spacing Tokens
625
+
626
+ ```ts
627
+ tokens.space["0"]; // "0rem"
628
+ tokens.space["4"]; // "0.25rem" (4px)
629
+ tokens.space["8"]; // "0.5rem" (8px)
630
+ tokens.space["16"]; // "1rem" (16px)
631
+ tokens.space["24"]; // "1.5rem" (24px)
632
+ tokens.space["32"]; // "2rem" (32px)
633
+ tokens.space["48"]; // "3rem" (48px)
634
+ tokens.space["64"]; // "4rem" (64px)
635
+ tokens.space["96"]; // "6rem" (96px)
636
+ ```
637
+
638
+ ### Layout Tokens
639
+
640
+ ```ts
641
+ // Section padding
642
+ tokens.layout.section.padding.sm; // "1.5rem"
643
+ tokens.layout.section.padding.md; // "2rem"
644
+ tokens.layout.section.padding.lg; // "3rem"
645
+
646
+ // Section gaps
647
+ tokens.layout.section.gap.sm; // "1rem"
648
+ tokens.layout.section.gap.md; // "1.5rem"
649
+ tokens.layout.section.gap.lg; // "2rem"
650
+
651
+ // Stack gaps (tighter spacing for related elements)
652
+ tokens.layout.stack.gap.sm; // "0.5rem"
653
+ tokens.layout.stack.gap.md; // "0.75rem"
654
+ tokens.layout.stack.gap.lg; // "1rem"
655
+
656
+ // Container inline padding
657
+ tokens.layout.container.paddingInline.sm; // "1rem"
658
+ tokens.layout.container.paddingInline.md; // "1.5rem"
659
+ tokens.layout.container.paddingInline.lg; // "2rem"
660
+ ```
661
+
662
+ ### Border Radius Tokens
663
+
664
+ ```ts
665
+ tokens.radii.none; // "0"
666
+ tokens.radii.sm; // "2px"
667
+ tokens.radii.md; // "4px"
668
+ tokens.radii.lg; // "8px"
669
+ tokens.radii.pill; // "999px"
670
+ ```
671
+
672
+ ### Shadow Tokens
673
+
674
+ ```ts
675
+ tokens.shadows.none; // "none"
676
+ tokens.shadows.sm; // "0 1px 2px 0 rgba(15, 23, 42, 0.08)"
677
+ tokens.shadows.md; // "0 3px 8px -1px rgba(15, 23, 42, 0.1)"
678
+ tokens.shadows.lg; // "0 8px 20px -4px rgba(15, 23, 42, 0.18)"
679
+ ```
680
+
681
+ ### Breakpoint Tokens
682
+
683
+ ```ts
684
+ tokens.breakpoints.sm; // "640px"
685
+ tokens.breakpoints.md; // "768px"
686
+ tokens.breakpoints.lg; // "1024px"
687
+ tokens.breakpoints.xl; // "1280px"
688
+ tokens.breakpoints["2xl"]; // "1536px"
689
+ ```
690
+
691
+ ### Z-Index Tokens
692
+
693
+ ```ts
694
+ tokens.zIndex.base; // "0"
695
+ tokens.zIndex.dropdown; // "1000"
696
+ tokens.zIndex.sticky; // "1100"
697
+ tokens.zIndex.fixed; // "1200"
698
+ tokens.zIndex.overlay; // "1300"
699
+ tokens.zIndex.modal; // "1400"
700
+ tokens.zIndex.popover; // "1500"
701
+ tokens.zIndex.tooltip; // "1600"
702
+ ```
703
+
704
+ ### Transition Tokens
705
+
706
+ ```ts
707
+ // Duration
708
+ tokens.transitions.duration.instant; // "75ms"
709
+ tokens.transitions.duration.fast; // "150ms"
710
+ tokens.transitions.duration.base; // "200ms"
711
+ tokens.transitions.duration.moderate; // "300ms"
712
+ tokens.transitions.duration.slow; // "500ms"
713
+ tokens.transitions.duration.slower; // "700ms"
714
+
715
+ // Easing
716
+ tokens.transitions.easing.linear; // "linear"
717
+ tokens.transitions.easing.in; // "cubic-bezier(0.4, 0, 1, 1)"
718
+ tokens.transitions.easing.out; // "cubic-bezier(0, 0, 0.2, 1)"
719
+ tokens.transitions.easing.inOut; // "cubic-bezier(0.4, 0, 0.2, 1)"
720
+ tokens.transitions.easing.spring; // "cubic-bezier(0.34, 1.56, 0.64, 1)"
721
+ ```
722
+
723
+ ### Animation Tokens
724
+
725
+ ```ts
726
+ tokens.animations.fadeIn; // { duration: "200ms", easing: "...", keyframes: "fade-in" }
727
+ tokens.animations.fadeOut; // { duration: "150ms", easing: "...", keyframes: "fade-out" }
728
+ tokens.animations.slideUp; // { duration: "300ms", easing: "...", keyframes: "slide-up" }
729
+ tokens.animations.slideDown; // { duration: "300ms", easing: "...", keyframes: "slide-down" }
730
+ tokens.animations.scaleIn; // { duration: "200ms", easing: "...", keyframes: "scale-in" }
731
+ tokens.animations.bounce; // { duration: "500ms", easing: "...", keyframes: "bounce" }
732
+ tokens.animations.shake; // { duration: "400ms", easing: "...", keyframes: "shake" }
733
+ tokens.animations.pulse; // { duration: "1500ms", easing: "...", keyframes: "pulse" }
734
+ ```
735
+
736
+ ### Border Tokens
737
+
738
+ ```ts
739
+ tokens.borders.card; // "#334155"
740
+ tokens.borders.input; // "#cbd5f5"
741
+ ```
201
742
 
202
743
  ## Repository Layout
203
744
 
204
745
  | Folder | Responsibility |
205
746
  | ---------- | ------------------------------------------------------------------------------------------------------------- |
206
- | `tokens/` | Raw JSON tokens owned by design. `core.json` holds colors, spacing, radii, typography scales, and shadows. |
747
+ | `tokens/` | Raw JSON token files owned by design (e.g. `core.json`, modes, component semantics). |
207
748
  | `src/` | TypeScript source that turns JSON into reusable formats (JS/TS exports, Tailwind theme, CSS helpers). |
208
749
  | `scripts/` | Build utilities. `build-css.js` consumes the compiled library and writes `dist/index.css`. |
209
750
  | `dist/` | Generated artifacts: `index.js`, `index.cjs`, `index.d.ts`, and `index.css`. Regenerated via `npm run build`. |
@@ -218,8 +759,141 @@ npm run build
218
759
 
219
760
  `tsup` compiles the TypeScript library (ESM, CJS, `.d.ts`) and `scripts/build-css.js` emits `dist/index.css`. Because `dist/` is generated, releases are reproducible from `tokens/` + `src/`.
220
761
 
762
+ > Do not hand-edit `dist/`. Always regenerate it via the build.
763
+
221
764
  For release history and version notes, see the **[Changelog](CHANGELOG.md)**.
222
765
 
766
+ ## Migration & Comparison Guide
767
+
768
+ ### Migrating from Other Token Systems
769
+
770
+ #### From Style Dictionary / Design Tokens Format
771
+
772
+ ```js
773
+ // Old: Style Dictionary format
774
+ {
775
+ "color": {
776
+ "brand": {
777
+ "primary": { "value": "#8652ff" }
778
+ }
779
+ }
780
+ }
781
+
782
+ // New: Spectre Tokens
783
+ tokens.colors.brand["500"] // "#8652ff"
784
+ ```
785
+
786
+ #### From Tailwind Default Theme
787
+
788
+ ```js
789
+ // Old: Tailwind's theme
790
+ colors.purple[500]; // "#a855f7"
791
+ spacing[4]; // "1rem"
792
+
793
+ // New: Spectre Tokens
794
+ tokens.colors.brand["500"]; // "#8652ff" (custom brand purple)
795
+ tokens.space["16"]; // "1rem"
796
+ ```
797
+
798
+ #### From CSS Custom Properties Only
799
+
800
+ ```css
801
+ /* Old: Manual CSS variables */
802
+ :root {
803
+ --primary-color: #8652ff;
804
+ --spacing-4: 1rem;
805
+ }
806
+
807
+ /* New: Spectre auto-generated */
808
+ :root {
809
+ --sp-color-brand-500: #8652ff;
810
+ --sp-space-16: 1rem;
811
+ /* Plus 300+ more tokens */
812
+ }
813
+ ```
814
+
815
+ ### Key Differences from Other Systems
816
+
817
+ | Feature | Spectre Tokens | Tailwind | Material UI | Chakra UI |
818
+ | ----------------------- | ------------------------- | ------------------- | ------------------- | ----------------- |
819
+ | **Format** | JSON → JS/TS/CSS | JS Config | Theme Object | Theme Object |
820
+ | **CSS Variables** | ✅ Auto-generated | ⚠️ Opt-in (v4+) | ✅ Built-in | ✅ Built-in |
821
+ | **Dark Mode** | ✅ Via `modes` | ✅ Via classes | ✅ Via palette mode | ✅ Via color mode |
822
+ | **Type Safety** | ✅ Full TypeScript | ⚠️ Partial | ✅ Full | ✅ Full |
823
+ | **Framework Agnostic** | ✅ Yes | ⚠️ Tailwind-focused | ❌ React-only | ❌ React-only |
824
+ | **Semantic Tokens** | ✅ surface/text/component | ❌ Utility-first | ✅ Built-in | ✅ Built-in |
825
+ | **Button States** | ✅ CRO-optimized | ❌ DIY | ✅ Built-in | ✅ Built-in |
826
+ | **Form States** | ✅ Validation-aware | ❌ DIY | ✅ Built-in | ✅ Built-in |
827
+ | **Tailwind Compatible** | ✅ Preset provided | N/A | ⚠️ Via plugin | ⚠️ Via plugin |
828
+
829
+ ### Why Choose Spectre Tokens?
830
+
831
+ 1. **True Single Source of Truth**: JSON tokens drive everything - JS, CSS, Tailwind, documentation
832
+ 2. **CRO-First Design**: Button and form states optimized for conversion and UX
833
+ 3. **Framework Agnostic**: Use with React, Vue, Svelte, WordPress, Astro, 11ty, or vanilla JS
834
+ 4. **Semantic + Utility**: Get both semantic tokens (surface, text) and utility tokens (colors, space)
835
+ 5. **WCAG Built-In**: Accessibility constraints enforced at the token level
836
+ 6. **No Lock-In**: Export to CSS variables and use anywhere, or integrate deeply with Tailwind
837
+ 7. **Type-Safe**: Complete TypeScript definitions with autocomplete
838
+
839
+ ## Spectre Design Philosophy
840
+
841
+ Spectre is a **specification-driven design system** built on three strict layers:
842
+
843
+ ### 1. @phcdevworks/spectre-tokens (Foundation)
844
+
845
+ **Purpose**: Single source of truth for design values (colors, surfaces, text roles, space, radii, shadows, etc.)
846
+
847
+ **Exports**: CSS variables (`--sp-*`), TypeScript token object, Tailwind-compatible theme mappings
848
+
849
+ **Rules**:
850
+
851
+ - Tokens define semantic meaning, not UI behavior
852
+ - UI must never invent new colors or values
853
+ - Designers own `tokens/*.json`; engineers maintain `src/` transforms
854
+ - Contrast targets and accessibility constraints are encoded at the token level
855
+
856
+ **Status**: v0.1.0 released with stable semantic roles (`surface.*`, `text.*`, `component.*`) and considered correct/locked
857
+
858
+ ### 2. @phcdevworks/spectre-ui (Framework-Agnostic UI Layer)
859
+
860
+ **Purpose**: Converts tokens into real CSS and class recipes
861
+
862
+ **Ships**:
863
+
864
+ - `index.css` (canonical CSS bundle: tokens + base + components + utilities)
865
+ - `base.css` (resets + globals)
866
+ - `components.css` (`.sp-btn`, `.sp-card`, `.sp-input`, etc.)
867
+ - `utilities.css` (`.sp-stack`, `.sp-container`, etc.)
868
+ - Type-safe recipes: `getButtonClasses`, `getCardClasses`, `getInputClasses`
869
+
870
+ **Rules**:
871
+
872
+ - UI must consume tokens, not redefine design values
873
+ - Literal values in CSS are fallbacks only
874
+ - Every CSS selector has a matching recipe where applicable
875
+ - Tailwind preset is optional and non-authoritative
876
+
877
+ **Status**: v0.1.0 released, hardened and aligned to tokens
878
+
879
+ ### 3. Adapters (WordPress, Astro, etc.)
880
+
881
+ **Purpose**: Thin framework wrappers around spectre-ui; automatically sync and load the Spectre UI CSS bundle
882
+
883
+ **Rules**:
884
+
885
+ - Adapters never define styles, never duplicate CSS, never load tokens directly
886
+ - All design values come from tokens, all CSS comes from spectre-ui
887
+ - Adapters only translate and integrate
888
+
889
+ ### Golden Rule (Non-Negotiable)
890
+
891
+ **Tokens define meaning. UI defines structure. Adapters only translate.**
892
+
893
+ - If it's a design token → belongs in `@phcdevworks/spectre-tokens`
894
+ - If it's a CSS class or style → belongs in `@phcdevworks/spectre-ui`
895
+ - If it's framework integration → belongs in an adapter
896
+
223
897
  ## Design Principles
224
898
 
225
899
  1. **Single source of truth** – Tokens originate in JSON and flow into every runtime surface.
@@ -230,7 +904,7 @@ For release history and version notes, see the **[Changelog](CHANGELOG.md)**.
230
904
 
231
905
  ## TypeScript Support
232
906
 
233
- Type definitions are bundled automatically:
907
+ Type definitions are bundled automatically with comprehensive interfaces for all token types:
234
908
 
235
909
  ```ts
236
910
  import type {
@@ -238,13 +912,168 @@ import type {
238
912
  SpectreTokens,
239
913
  TailwindTheme,
240
914
  ColorScale,
915
+ TokenScale,
241
916
  ButtonStateTokens,
242
917
  FormStateTokens,
918
+ TypographyTokens,
919
+ TypographyScaleEntry,
920
+ FontScaleEntry,
921
+ TransitionTokens,
922
+ AnimationEntry,
923
+ AccessibilityTokens,
924
+ ComponentTokens,
925
+ ComponentBadgeTokens,
926
+ ComponentIconBoxTokens,
927
+ LayoutTokens,
928
+ SpectreModeTokens,
929
+ SpectreModeName,
930
+ SemanticTokenValue,
931
+ CssVariableOptions,
932
+ CssVariableMap,
243
933
  } from "@phcdevworks/spectre-tokens";
244
934
 
245
935
  const allTokens: SpectreTokens = tokens;
246
936
  ```
247
937
 
938
+ ### Key Type Interfaces
939
+
940
+ **Core Token Types:**
941
+
942
+ ```ts
943
+ // Color and token scales
944
+ type ColorScale = Record<string, string>;
945
+ type TokenScale = Record<string, string>;
946
+
947
+ // Typography
948
+ interface TypographyScaleEntry {
949
+ fontSize: string;
950
+ lineHeight: string;
951
+ fontWeight?: number;
952
+ letterSpacing?: string;
953
+ }
954
+
955
+ interface FontScaleEntry {
956
+ size: string;
957
+ lineHeight: string;
958
+ weight: number;
959
+ }
960
+
961
+ // Component states
962
+ interface ButtonStateTokens {
963
+ bg: string;
964
+ bgHover: string;
965
+ bgActive: string;
966
+ bgDisabled: string;
967
+ text: string;
968
+ textDisabled: string;
969
+ border?: string;
970
+ borderDisabled?: string;
971
+ }
972
+
973
+ interface FormStateTokens {
974
+ bg?: string;
975
+ border: string;
976
+ text?: string;
977
+ placeholder?: string;
978
+ ring?: string;
979
+ }
980
+
981
+ // Component tokens
982
+ interface ComponentBadgeTokens<Value = string> {
983
+ neutralBg: Value;
984
+ neutralText: Value;
985
+ infoBg: Value;
986
+ infoText: Value;
987
+ successBg: Value;
988
+ successText: Value;
989
+ warningBg: Value;
990
+ warningText: Value;
991
+ dangerBg: Value;
992
+ dangerText: Value;
993
+ }
994
+
995
+ interface ComponentIconBoxTokens<Value = string> {
996
+ bg: Value;
997
+ border: Value;
998
+ iconDefault: Value;
999
+ iconSuccess: Value;
1000
+ iconWarning: Value;
1001
+ iconDanger: Value;
1002
+ }
1003
+ ```
1004
+
1005
+ **Semantic Token Types:**
1006
+
1007
+ ```ts
1008
+ // Semantic token values can be strings or objects with metadata
1009
+ type SemanticTokenValue = string | { value: string; [key: string]: any };
1010
+
1011
+ // Mode names
1012
+ type SpectreModeName = "default" | "dark";
1013
+
1014
+ // Mode structure
1015
+ interface SpectreModeTokens {
1016
+ surface: {
1017
+ page: SemanticTokenValue;
1018
+ card: SemanticTokenValue;
1019
+ input: SemanticTokenValue;
1020
+ overlay: SemanticTokenValue;
1021
+ };
1022
+ text: {
1023
+ onPage: {
1024
+ default: SemanticTokenValue;
1025
+ muted: SemanticTokenValue;
1026
+ subtle: SemanticTokenValue;
1027
+ meta: SemanticTokenValue;
1028
+ };
1029
+ onSurface: {
1030
+ /* same as onPage */
1031
+ };
1032
+ };
1033
+ component: ComponentTokens<SemanticTokenValue>;
1034
+ }
1035
+ ```
1036
+
1037
+ **CSS Variable Generation:**
1038
+
1039
+ ```ts
1040
+ interface CssVariableOptions {
1041
+ prefix?: string; // Default: "sp"
1042
+ selector?: string; // Default: ":root"
1043
+ }
1044
+
1045
+ type CssVariableMap = Record<string, string>;
1046
+
1047
+ // Usage
1048
+ const css: string = generateCssVariables(tokens, {
1049
+ prefix: "spectre",
1050
+ selector: ".my-theme",
1051
+ });
1052
+ ```
1053
+
1054
+ ### Type-Safe Token Access
1055
+
1056
+ TypeScript provides full autocomplete and type checking:
1057
+
1058
+ ```ts
1059
+ import tokens from "@phcdevworks/spectre-tokens";
1060
+
1061
+ // Autocomplete for all color palettes and shades
1062
+ const brandColor = tokens.colors.brand["500"]; // ✅ Type: string
1063
+
1064
+ // Autocomplete for button states
1065
+ const primaryBg = tokens.buttons.primary.bg; // ✅ Type: string
1066
+ const primaryHover = tokens.buttons.primary.bgHover; // ✅ Type: string
1067
+
1068
+ // Type checking prevents invalid access
1069
+ // tokens.colors.invalid["500"]; // ❌ TypeScript error
1070
+ // tokens.buttons.primary.invalidProp; // ❌ TypeScript error
1071
+
1072
+ // Full type support for component tokens
1073
+ const badgeBg: string = tokens.component.badge.successBg;
1074
+ const iconColor: string = tokens.component.iconBox.iconDanger;
1075
+ ```
1076
+
248
1077
  ## Part of the Spectre Suite
249
1078
 
250
1079
  - **Spectre Tokens** – Design-token foundation (this package)
@@ -253,7 +1082,427 @@ const allTokens: SpectreTokens = tokens;
253
1082
  - **Spectre Astro** – Astro integration
254
1083
  - **Spectre 11ty** – Eleventy integration
255
1084
 
256
- For the project's future direction, see the **[Roadmap](ROADMAP.md)**.
1085
+ ## Practical Examples
1086
+
1087
+ ### Building a Button Component
1088
+
1089
+ ```ts
1090
+ import tokens from "@phcdevworks/spectre-tokens";
1091
+
1092
+ // Create a type-safe button configuration
1093
+ const buttonStyles = {
1094
+ primary: {
1095
+ background: tokens.buttons.primary.bg,
1096
+ color: tokens.buttons.primary.text,
1097
+ borderRadius: tokens.radii.md,
1098
+ padding: `${tokens.space["12"]} ${tokens.space["24"]}`,
1099
+ fontSize: tokens.font.md.size,
1100
+ fontWeight: tokens.font.md.weight,
1101
+ transition: `all ${tokens.transitions.duration.fast} ${tokens.transitions.easing.out}`,
1102
+ "&:hover": {
1103
+ background: tokens.buttons.primary.bgHover,
1104
+ },
1105
+ "&:active": {
1106
+ background: tokens.buttons.primary.bgActive,
1107
+ },
1108
+ "&:disabled": {
1109
+ background: tokens.buttons.primary.bgDisabled,
1110
+ color: tokens.buttons.primary.textDisabled,
1111
+ },
1112
+ },
1113
+ };
1114
+ ```
1115
+
1116
+ ### Creating a Card Layout
1117
+
1118
+ ```css
1119
+ .card {
1120
+ background: var(--sp-surface-card);
1121
+ border: 1px solid var(--sp-borders-card);
1122
+ border-radius: var(--sp-radius-lg);
1123
+ padding: var(--sp-space-24);
1124
+ box-shadow: var(--sp-shadow-md);
1125
+
1126
+ /* Semantic layout spacing */
1127
+ display: flex;
1128
+ flex-direction: column;
1129
+ gap: var(--sp-layout-stack-gap-md);
1130
+ }
1131
+
1132
+ .card__title {
1133
+ color: var(--sp-text-on-surface-default);
1134
+ font-size: var(--sp-font-lg-size);
1135
+ line-height: var(--sp-font-lg-line-height);
1136
+ font-weight: var(--sp-font-lg-weight);
1137
+ }
1138
+
1139
+ .card__description {
1140
+ color: var(--sp-text-on-surface-muted);
1141
+ font-size: var(--sp-font-md-size);
1142
+ line-height: var(--sp-font-md-line-height);
1143
+ }
1144
+
1145
+ .card__meta {
1146
+ color: var(--sp-text-on-surface-meta);
1147
+ font-size: var(--sp-font-sm-size);
1148
+ }
1149
+ ```
1150
+
1151
+ ### Form with Validation States
1152
+
1153
+ ```html
1154
+ <!-- HTML structure -->
1155
+ <div class="form-field">
1156
+ <label class="form-label">Email Address</label>
1157
+ <input type="email" class="form-input" />
1158
+ <span class="form-hint">We'll never share your email.</span>
1159
+ </div>
1160
+
1161
+ <div class="form-field form-field--error">
1162
+ <label class="form-label">Password</label>
1163
+ <input type="password" class="form-input" />
1164
+ <span class="form-error">Password must be at least 8 characters.</span>
1165
+ </div>
1166
+ ```
1167
+
1168
+ ```css
1169
+ /* CSS using Spectre tokens */
1170
+ .form-field {
1171
+ display: flex;
1172
+ flex-direction: column;
1173
+ gap: var(--sp-layout-stack-gap-sm);
1174
+ }
1175
+
1176
+ .form-label {
1177
+ color: var(--sp-text-on-page-default);
1178
+ font-size: var(--sp-font-sm-size);
1179
+ font-weight: var(--sp-font-md-weight);
1180
+ }
1181
+
1182
+ .form-input {
1183
+ background: var(--sp-form-default-bg);
1184
+ border: 1px solid var(--sp-form-default-border);
1185
+ border-radius: var(--sp-radius-md);
1186
+ padding: var(--sp-space-12) var(--sp-space-16);
1187
+ font-size: var(--sp-font-md-size);
1188
+ color: var(--sp-form-default-text);
1189
+ transition: border-color var(--sp-transition-duration-fast) var(
1190
+ --sp-transition-easing-out
1191
+ );
1192
+ min-height: var(--sp-accessibility-min-touch-target);
1193
+ }
1194
+
1195
+ .form-input::placeholder {
1196
+ color: var(--sp-form-default-placeholder);
1197
+ }
1198
+
1199
+ .form-input:hover {
1200
+ border-color: var(--sp-form-hover-border);
1201
+ }
1202
+
1203
+ .form-input:focus {
1204
+ outline: none;
1205
+ border-color: var(--sp-form-focus-border);
1206
+ box-shadow: 0 0 0 var(--sp-accessibility-focus-ring-width) var(
1207
+ --sp-form-focus-ring
1208
+ );
1209
+ }
1210
+
1211
+ .form-field--error .form-input {
1212
+ border-color: var(--sp-form-invalid-border);
1213
+ background: var(--sp-form-invalid-bg);
1214
+ }
1215
+
1216
+ .form-hint {
1217
+ color: var(--sp-text-on-page-subtle);
1218
+ font-size: var(--sp-font-xs-size);
1219
+ }
1220
+
1221
+ .form-error {
1222
+ color: var(--sp-form-invalid-text);
1223
+ font-size: var(--sp-font-xs-size);
1224
+ }
1225
+ ```
1226
+
1227
+ ### Responsive Layout with Breakpoints
1228
+
1229
+ ```ts
1230
+ import { tailwindTheme } from "@phcdevworks/spectre-tokens";
1231
+
1232
+ // Use in CSS-in-JS or styled-components
1233
+ const Container = styled.div`
1234
+ padding-inline: ${tokens.layout.container.paddingInline.sm};
1235
+
1236
+ @media (min-width: ${tokens.breakpoints.md}) {
1237
+ padding-inline: ${tokens.layout.container.paddingInline.md};
1238
+ }
1239
+
1240
+ @media (min-width: ${tokens.breakpoints.lg}) {
1241
+ padding-inline: ${tokens.layout.container.paddingInline.lg};
1242
+ }
1243
+ `;
1244
+ ```
1245
+
1246
+ ### Animated Modal
1247
+
1248
+ ```css
1249
+ .modal {
1250
+ position: fixed;
1251
+ inset: 0;
1252
+ z-index: var(--sp-z-index-modal);
1253
+ display: flex;
1254
+ align-items: center;
1255
+ justify-content: center;
1256
+ background: var(--sp-surface-overlay);
1257
+ animation: fade-in var(--sp-animation-fade-in-duration) var(
1258
+ --sp-animation-fade-in-easing
1259
+ );
1260
+ }
1261
+
1262
+ .modal__content {
1263
+ background: var(--sp-surface-card);
1264
+ border-radius: var(--sp-radius-lg);
1265
+ padding: var(--sp-space-32);
1266
+ box-shadow: var(--sp-shadow-lg);
1267
+ max-width: 32rem;
1268
+ animation: scale-in var(--sp-animation-scale-in-duration) var(
1269
+ --sp-animation-scale-in-easing
1270
+ );
1271
+ }
1272
+
1273
+ @keyframes fade-in {
1274
+ from {
1275
+ opacity: 0;
1276
+ }
1277
+ to {
1278
+ opacity: 1;
1279
+ }
1280
+ }
1281
+
1282
+ @keyframes scale-in {
1283
+ from {
1284
+ opacity: 0;
1285
+ transform: scale(0.95);
1286
+ }
1287
+ to {
1288
+ opacity: 1;
1289
+ transform: scale(1);
1290
+ }
1291
+ }
1292
+ ```
1293
+
1294
+ ### Badge Component System
1295
+
1296
+ ```tsx
1297
+ // React/TypeScript example
1298
+ import tokens from "@phcdevworks/spectre-tokens";
1299
+
1300
+ type BadgeVariant = 'neutral' | 'info' | 'success' | 'warning' | 'danger';
1301
+
1302
+ interface BadgeProps {
1303
+ variant?: BadgeVariant;
1304
+ children: React.ReactNode;
1305
+ }
1306
+
1307
+ const Badge: React.FC<BadgeProps> = ({ variant = 'neutral', children }) => {
1308
+ const styles = {
1309
+ background: tokens.component.badge[`${variant}Bg` as keyof typeof tokens.component.badge],
1310
+ color: tokens.component.badge[`${variant}Text` as keyof typeof tokens.component.badge],
1311
+ padding: `${tokens.space["4"]} ${tokens.space["8"]}`,
1312
+ borderRadius: tokens.radii.sm,
1313
+ fontSize: tokens.font.xs.size,
1314
+ fontWeight: tokens.font.xs.weight,
1315
+ display: 'inline-flex',
1316
+ alignItems: 'center',
1317
+ };
1318
+
1319
+ return <span style={styles}>{children}</span>;
1320
+ };
1321
+
1322
+ // Usage
1323
+ <Badge variant="success">Active</Badge>
1324
+ <Badge variant="warning">Pending</Badge>
1325
+ <Badge variant="danger">Error</Badge>
1326
+ ```
1327
+
1328
+ ### Custom Theme Scope
1329
+
1330
+ ```ts
1331
+ import { generateCssVariables } from "@phcdevworks/spectre-tokens";
1332
+
1333
+ // Generate scoped CSS variables for a specific component
1334
+ const customThemeCSS = generateCssVariables(tokens, {
1335
+ selector: ".custom-widget",
1336
+ prefix: "widget",
1337
+ });
1338
+
1339
+ // Output: Variables scoped to .custom-widget with --widget-* prefix
1340
+ // .custom-widget {
1341
+ // --widget-color-brand-500: #8652ff;
1342
+ // --widget-space-16: 1rem;
1343
+ // ...
1344
+ // }
1345
+ ```
1346
+
1347
+ ## Troubleshooting & FAQ
1348
+
1349
+ ### CSS Variables Not Working
1350
+
1351
+ **Problem:** CSS variables like `var(--sp-color-brand-500)` are not applying.
1352
+
1353
+ **Solution:**
1354
+
1355
+ 1. Ensure you've imported the CSS file:
1356
+ ```css
1357
+ @import "@phcdevworks/spectre-tokens/dist/index.css";
1358
+ ```
1359
+ 2. Check that the file is being served correctly from `node_modules/`
1360
+ 3. Verify CSS import order - token CSS should come before your custom styles
1361
+
1362
+ ### TypeScript Types Not Found
1363
+
1364
+ **Problem:** TypeScript can't find type definitions.
1365
+
1366
+ **Solution:**
1367
+
1368
+ 1. Check that `@phcdevworks/spectre-tokens` is in your dependencies (not devDependencies)
1369
+ 2. Verify `dist/index.d.ts` exists in your `node_modules`
1370
+ 3. Try clearing TypeScript cache: `rm -rf node_modules/.cache`
1371
+ 4. Restart your TypeScript server/IDE
1372
+
1373
+ ### Dark Mode Not Switching
1374
+
1375
+ **Problem:** Setting `data-spectre-theme="dark"` doesn't change colors.
1376
+
1377
+ **Solution:**
1378
+
1379
+ 1. Apply the attribute to the `:root` or `<html>` element:
1380
+ ```js
1381
+ document.documentElement.setAttribute("data-spectre-theme", "dark");
1382
+ ```
1383
+ 2. Ensure you're using semantic tokens (surface, text, component) not raw colors
1384
+ 3. Raw color tokens (e.g., `tokens.colors.brand[500]`) don't change with themes - use semantic tokens instead
1385
+
1386
+ ### Tailwind Integration Issues
1387
+
1388
+ **Problem:** Tailwind utilities not using Spectre tokens.
1389
+
1390
+ **Solution:**
1391
+
1392
+ 1. Verify preset is added to your config:
1393
+
1394
+ ```ts
1395
+ import { tailwindPreset } from "@phcdevworks/spectre-tokens";
1396
+
1397
+ export default {
1398
+ presets: [tailwindPreset], // Must be in presets, not theme.extend
1399
+ };
1400
+ ```
1401
+
1402
+ 2. Clear Tailwind cache: `rm -rf .next/cache` or `rm -rf node_modules/.cache`
1403
+ 3. Rebuild: `npm run build`
1404
+
1405
+ ### Difference Between `font` and `typography`?
1406
+
1407
+ **Question:** When should I use `tokens.font.*` vs `tokens.typography.*`?
1408
+
1409
+ **Answer:**
1410
+
1411
+ - **Use `tokens.font.*`** for quick access to size, line-height, and weight:
1412
+ ```ts
1413
+ tokens.font.md.size; // "1rem"
1414
+ tokens.font.md.lineHeight; // "1.75rem"
1415
+ tokens.font.md.weight; // 500
1416
+ ```
1417
+ - **Use `tokens.typography.*`** when you need:
1418
+ - Font families: `tokens.typography.families.sans`
1419
+ - Letter spacing: `tokens.typography.scale.xs.letterSpacing`
1420
+ - Complete typographic object: `tokens.typography.scale.md`
1421
+
1422
+ ### How to Create Custom Modes?
1423
+
1424
+ **Question:** Can I add my own theme modes beyond default/dark?
1425
+
1426
+ **Answer:**
1427
+ Yes! Extend the `modes` object in your `core.json`:
1428
+
1429
+ ```json
1430
+ {
1431
+ "modes": {
1432
+ "default": {
1433
+ /* ... */
1434
+ },
1435
+ "dark": {
1436
+ /* ... */
1437
+ },
1438
+ "highContrast": {
1439
+ "surface": {
1440
+ "page": { "value": "#ffffff" }
1441
+ }
1442
+ }
1443
+ }
1444
+ }
1445
+ ```
1446
+
1447
+ Then generate CSS with:
1448
+
1449
+ ```css
1450
+ :root[data-spectre-theme="highContrast"] {
1451
+ /* Custom mode variables */
1452
+ }
1453
+ ```
1454
+
1455
+ ### Can I Override Specific Tokens?
1456
+
1457
+ **Question:** How do I override just a few tokens without forking?
1458
+
1459
+ **Answer:**
1460
+ Two approaches:
1461
+
1462
+ 1. **CSS Override** (simplest):
1463
+
1464
+ ```css
1465
+ :root {
1466
+ --sp-color-brand-500: #your-color !important;
1467
+ }
1468
+ ```
1469
+
1470
+ 2. **JavaScript Override**:
1471
+
1472
+ ```ts
1473
+ import tokens from "@phcdevworks/spectre-tokens";
1474
+
1475
+ const customTokens = {
1476
+ ...tokens,
1477
+ colors: {
1478
+ ...tokens.colors,
1479
+ brand: {
1480
+ ...tokens.colors.brand,
1481
+ "500": "#your-color",
1482
+ },
1483
+ },
1484
+ };
1485
+ ```
1486
+
1487
+ ### Accessing Nested Token Values
1488
+
1489
+ **Question:** Some tokens return `{ value: "..." }` instead of strings. Why?
1490
+
1491
+ **Answer:**
1492
+ Semantic tokens in `modes` use the `{ value: "..." }` format for metadata. The TypeScript library automatically resolves these:
1493
+
1494
+ ```ts
1495
+ // In core.json: { "value": "#f8fafc" }
1496
+ tokens.surface.page; // Returns "#f8fafc" (string)
1497
+
1498
+ // The library handles resolution automatically
1499
+ ```
1500
+
1501
+ If you're working with raw JSON, extract the value:
1502
+
1503
+ ```ts
1504
+ const rawValue = tokens.modes.default.surface.page.value;
1505
+ ```
257
1506
 
258
1507
  ## Contributing
259
1508
 
@@ -263,7 +1512,7 @@ For detailed contribution guidelines, see **[CONTRIBUTING.md](CONTRIBUTING.md)**
263
1512
 
264
1513
  ## License
265
1514
 
266
- MIT © PHCDevworks — See **[LICENSE](LICENSE)** for details.
1515
+ See **[LICENSE](LICENSE)** for details.
267
1516
 
268
1517
  ---
269
1518