@phcdevworks/spectre-tokens 2.5.0 → 2.7.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/README.md CHANGED
@@ -1,32 +1,40 @@
1
1
  # @phcdevworks/spectre-tokens
2
2
 
3
- [![GitHub issues](https://img.shields.io/github/issues/phcdevworks/spectre-tokens)](https://github.com/phcdevworks/spectre-tokens/issues)
4
- [![GitHub pulls](https://img.shields.io/github/issues-pr/phcdevworks/spectre-tokens)](https://github.com/phcdevworks/spectre-tokens/pulls)
5
- [![License](https://img.shields.io/github/license/phcdevworks/spectre-tokens)](LICENSE)
3
+ [![npm version](https://img.shields.io/npm/v/@phcdevworks/spectre-tokens)](https://www.npmjs.com/package/@phcdevworks/spectre-tokens)
4
+ [![CI](https://github.com/phcdevworks/spectre-tokens/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/phcdevworks/spectre-tokens/actions/workflows/ci.yml)
5
+ [![License](https://img.shields.io/npm/l/@phcdevworks/spectre-tokens)](LICENSE)
6
+ [![Node](https://img.shields.io/node/v/@phcdevworks/spectre-tokens)](https://nodejs.org)
6
7
 
7
- `@phcdevworks/spectre-tokens` is the design-token package of the Spectre system
8
- for downstream Spectre packages and compatible applications.
8
+ `@phcdevworks/spectre-tokens` is the design-token package of the Spectre system.
9
+ It provides a complete, UI-ready token surface for downstream Spectre packages
10
+ and compatible applications.
9
11
 
10
12
  Maintained by PHCDevworks, it defines the visual language, semantic roles, and
11
- token contracts consumed downstream. It keeps visual meaning centralized in
12
- token data while downstream UI packages define structure and adapter packages
13
- translate those contracts for specific frameworks and runtimes.
14
-
15
- [Contributing](CONTRIBUTING.md) | [Changelog](CHANGELOG.md) |
16
- [Token Contract](TOKEN_CONTRACT.md) | [Roadmap](ROADMAP.md) |
17
- [Security Policy](SECURITY.md)
18
-
19
- ## Key capabilities
20
-
21
- - Uses `tokens/` as the source of truth for design-token data
22
- - Generates JavaScript, TypeScript, CSS, and Tailwind theme exports from shared
23
- token sources
24
- - Defines semantic token contracts for surfaces, text, components, buttons,
25
- forms, and modes
26
- - Exposes primitives and semantic roles for downstream packages and compatible
27
- applications
28
- - Keeps visual meaning centralized so downstream consumers do not redefine token
29
- contracts
13
+ token contracts that downstream consumers can rely on without filling gaps with
14
+ raw palette values or local token inventions. Downstream UI packages define
15
+ structure; adapter packages translate Spectre contracts for specific frameworks
16
+ and runtimes.
17
+
18
+ [Contributing](CONTRIBUTING.md) | [Code of Conduct](CODE_OF_CONDUCT.md) |
19
+ [Changelog](CHANGELOG.md) | [Token Contract](TOKEN_CONTRACT.md) |
20
+ [Roadmap](ROADMAP.md) | [Security Policy](SECURITY.md)
21
+
22
+ ## Source of truth
23
+
24
+ `tokens/` is the source of truth. `contract.manifest.json` is the
25
+ machine-readable contract authority. Everything else is derived from them or
26
+ validated against them.
27
+
28
+ | Layer | Path | Rule |
29
+ |---|---|---|
30
+ | Source token data | `tokens/*.json` | All token value changes start here — never anywhere else |
31
+ | Contract authority | `contract.manifest.json` | Governs public namespaces and required output surfaces |
32
+ | Public entry points | `src/index.ts` · `src/types.ts` · `src/css.ts` | Contract-authority files — changes require changelog classification |
33
+ | Generated TypeScript | `src/generated/tokens.ts` | **Never edit directly** — regenerated by `npm run build` |
34
+ | Generated dist | `dist/` | **Never edit directly** — regenerated by `npm run build` |
35
+
36
+ After any source change: run `npm run build` to regenerate outputs, then
37
+ `npm run check` to validate the full contract.
30
38
 
31
39
  ## What this package owns
32
40
 
@@ -40,14 +48,30 @@ This package is the correct place to define token meaning.
40
48
 
41
49
  ## What this package does not own
42
50
 
43
- - Component structure or composition That belongs in downstream UI packages such
44
- as [`@phcdevworks/spectre-ui`](https://github.com/phcdevworks/spectre-ui).
45
- - Framework-specific delivery Adapter packages translate Spectre contracts for
51
+ - Component structure or composition. That belongs in downstream UI packages
52
+ such as
53
+ [`@phcdevworks/spectre-ui`](https://github.com/phcdevworks/spectre-ui).
54
+ - Framework-specific delivery. Adapter packages translate Spectre contracts for
46
55
  specific frameworks and runtimes.
47
- - Local redefinition of token meaning Downstream consumers should consume these
56
+ - Local redefinition of token meaning. Downstream consumers should consume these
48
57
  contracts rather than recreate them independently.
49
- - Example app architecture The `example/` directory documents token usage; it is
50
- not the contract source and should not become a downstream UI layer.
58
+ - Example app architecture. The `example/` directory documents token usage; it
59
+ is not the contract source and should not become a downstream UI layer.
60
+
61
+ ## When to use this package
62
+
63
+ - You are building a Spectre ecosystem package and need the visual language contract.
64
+ - You need design token values in JavaScript, TypeScript, CSS variables, or a Tailwind theme.
65
+ - You want a single source of truth for semantic roles: `surface`, `text`, `component`, `buttons`, `forms`, `modes`.
66
+ - You are consuming tokens as named values, not inventing new token meaning.
67
+
68
+ ## When not to use this package
69
+
70
+ - You need UI components or component structure — use
71
+ [`@phcdevworks/spectre-ui`](https://github.com/phcdevworks/spectre-ui).
72
+ - You need framework-specific component delivery — use the appropriate adapter package.
73
+ - You want to define your own token meaning or override Spectre semantics locally —
74
+ this package is the authority; downstream consumers should consume, not redefine.
51
75
 
52
76
  ## Installation
53
77
 
@@ -94,14 +118,56 @@ export default {
94
118
  }
95
119
  ```
96
120
 
97
- ## Consumer usage
121
+ ## Semantic tokens vs raw palette tokens
122
+
123
+ Semantic tokens express UI meaning. Raw palette tokens expose the fixed color
124
+ ramp. Always prefer semantic tokens for UI surfaces, text, buttons, forms, and
125
+ mode-aware styling.
126
+
127
+ ### Semantic namespaces (prefer for all UI work)
128
+
129
+ | Namespace | What it expresses |
130
+ |---|---|
131
+ | `surface` | Background roles: page, card, overlay, sidebar |
132
+ | `text` | Foreground roles: default, muted, subtle, meta, on-surface, on-page |
133
+ | `component` | Role-specific tokens for icon boxes, badges, ratings, testimonials, pricing cards |
134
+ | `buttons` | Button state tokens: default, hover, active, disabled, CTA |
135
+ | `forms` | Form state tokens: default, focused, error, disabled |
136
+ | `modes` | Mode-aware overrides under `modes.default` and `modes.dark` |
137
+
138
+ ```ts
139
+ import tokens from '@phcdevworks/spectre-tokens'
140
+
141
+ // Semantic — always prefer this for UI
142
+ const card = {
143
+ background: tokens.surface.card,
144
+ color: tokens.text.onSurface.default,
145
+ }
146
+
147
+ // Mode-aware semantic
148
+ const dark = {
149
+ background: tokens.modes.dark.surface.page,
150
+ color: tokens.modes.dark.text.onPage.default,
151
+ }
152
+ ```
153
+
154
+ ### Raw palette (use sparingly)
155
+
156
+ The `colors` namespace exposes the raw palette ramp. Use it only when fixed
157
+ color access is intentional — data visualization, compatibility layers, or
158
+ tooling that inspects palette data directly.
159
+
160
+ ```ts
161
+ // Raw palette — only when fixed color access is deliberate
162
+ const chart = {
163
+ series1: tokens.colors.brand[500],
164
+ series2: tokens.colors.neutral[300],
165
+ }
166
+ ```
98
167
 
99
- ### Source of truth
168
+ Do not use `colors` as a substitute for semantic tokens in normal UI surfaces.
100
169
 
101
- - Change token data in `tokens/`.
102
- - Treat generated outputs as derived artifacts.
103
- - Treat `contract.manifest.json` as the machine-readable contract authority for
104
- public namespaces and required outputs.
170
+ ## Consumer usage
105
171
 
106
172
  ### JavaScript and TypeScript tokens
107
173
 
@@ -164,34 +230,6 @@ export default {
164
230
  Use `tailwindTheme` directly only when a consumer needs the generated theme
165
231
  object outside the preset shape.
166
232
 
167
- ### Semantic tokens first
168
-
169
- Prefer semantic namespaces for downstream UI work:
170
-
171
- - `surface`
172
- - `text`
173
- - `component`
174
- - `buttons`
175
- - `forms`
176
- - `modes`
177
-
178
- These namespaces are the main consumer-facing contract because they express UI
179
- meaning rather than raw color selection.
180
-
181
- ### When raw palette access is acceptable
182
-
183
- Raw palette access through `colors` is acceptable when a consumer deliberately
184
- needs fixed palette values.
185
-
186
- Typical cases:
187
-
188
- - data visualization or non-semantic decorative use
189
- - compatibility layers that need a specific raw ramp
190
- - tooling that inspects or serializes palette data directly
191
-
192
- Raw palette access should not replace semantic token usage for normal UI
193
- surfaces, text, buttons, forms, or mode-aware styling.
194
-
195
233
  ### Token model
196
234
 
197
235
  The generated token object includes these namespaces:
@@ -260,6 +298,23 @@ Guidance:
260
298
  - Do not invent local light/dark token contracts when this package already
261
299
  provides the semantic path.
262
300
 
301
+ ## Protected token families
302
+
303
+ The following semantic groups are locked. Their values must not change without
304
+ explicit approval from Bradley Potts. This applies to all contributors and all
305
+ AI agents — apparent visual improvements still require human sign-off.
306
+
307
+ | Protected group | Backed by | Guarded by |
308
+ |---|---|---|
309
+ | `success` | `colors.success` palette | `check:locked` + `check:contrast` |
310
+ | `warning` | `colors.warning` palette | `check:locked` + `check:contrast` |
311
+ | `danger` semantic roles | `colors.error` palette | `check:locked` + `check:contrast` |
312
+ | CTA / primary action / brand-action | `colors.brand` + `buttons.cta` | `check:locked` + `check:contrast` |
313
+
314
+ `check:locked` fails immediately if any protected value changes from the
315
+ recorded baseline. An intentional change requires updating the baseline as part
316
+ of an approved, classified release.
317
+
263
318
  ## Downstream boundaries
264
319
 
265
320
  Downstream packages should never redefine locally:
@@ -292,6 +347,19 @@ If a downstream package depends on specific token paths or semantic meaning:
292
347
  - read `TOKEN_CONTRACT.md` for contract rules
293
348
  - prefer documented public namespaces over undocumented internal assumptions
294
349
 
350
+ ### Change classification
351
+
352
+ Every contract-affecting change is classified in `CHANGELOG.md [Unreleased]`
353
+ with a `Contract change type:` line before release.
354
+
355
+ | Classification | When to use | Examples |
356
+ |---|---|---|
357
+ | `additive` | New tokens, new paths, new CSS variables — existing consumers unaffected | Adding a namespace, adding a token inside an existing family |
358
+ | `semantic change` | Path stays the same but meaning, intent, or visual output shifts | Adjusting the role of an existing surface or text token |
359
+ | `breaking` | Existing consumers may need code changes | Renaming a token path, removing a namespace, changing mode names |
360
+
361
+ Renames and removals are always breaking regardless of perceived scope.
362
+
295
363
  ## Package exports / API surface
296
364
 
297
365
  ### Root package
@@ -352,30 +420,71 @@ For downstream packages and compatible apps:
352
420
 
353
421
  ## Development
354
422
 
355
- Regenerate package outputs:
423
+ Install dependencies, then run the package verification flow:
356
424
 
357
425
  ```bash
358
- npm run build
426
+ npm install
427
+ npm run check
359
428
  ```
360
429
 
361
- Run the full validation and release gate:
430
+ This project expects Node.js `^22.12.0 || >=24.0.0` and npm `11.14.1`.
362
431
 
363
- ```bash
364
- npm run check
365
- ```
432
+ ### Common commands
433
+
434
+ | Command | What it does |
435
+ |---|---|
436
+ | `npm run build` | Regenerate all outputs — run after any token source change |
437
+ | `npm run check` | Full validation gate — all 14 steps must pass before commit |
438
+ | `npm run lint` | Run ESLint against all source files |
439
+ | `npm run format` | Apply Prettier formatting to all files |
440
+ | `npm run generate` | Regenerate `src/generated/tokens.ts` from token sources only |
441
+ | `npm run check:manifest` | Validate public namespaces against `contract.manifest.json` |
442
+ | `npm run check:docs` | Validate README and TOKEN_CONTRACT headings against manifest |
443
+ | `npm run check:locked` | Confirm protected color families are unchanged |
444
+ | `npm run check:contrast` | Confirm all paired tokens meet WCAG AA |
445
+ | `npm run check:dist` | Confirm `dist/` artifacts are in sync with source |
366
446
 
367
- Key source areas:
447
+ ### Key source areas
368
448
 
369
- - `tokens/` for source token data
370
- - `src/generated/` for generated token output
371
- - `src/` for package entry points, CSS generation, and types
372
- - `scripts/` for build and validation scripts
373
- - `example/` for usage examples
449
+ - `tokens/` source token data (source of truth)
450
+ - `src/` package entry points, CSS generation, and public types
451
+ - `src/generated/` auto-generated output (do not edit directly)
452
+ - `scripts/` build and validation scripts
453
+ - `example/` usage examples and smoke consumer
374
454
 
375
455
  The files in `example/` are illustrative token demos only. They help explain the
376
456
  token contract, but they are not the package contract itself and should not be
377
457
  treated as downstream UI primitives.
378
458
 
459
+ ## Troubleshooting
460
+
461
+ | Failure | Cause | Fix |
462
+ |---|---|---|
463
+ | `check:regression` fails | A token value changed vs the recorded baseline | Revert the unintended change, or update the baseline if the change was intentional |
464
+ | `check:locked` fails | A protected color family was modified | Revert unless Bradley Potts has explicitly approved the change |
465
+ | `check:contrast` fails | A text/background token pair does not meet WCAG AA | Adjust the token value or the `metadata.pair` reference in the source JSON |
466
+ | `check:dist` fails | Generated dist is out of sync | Run `npm run build` then re-run `npm run check` |
467
+ | `check:manifest` fails | A namespace exists in outputs but is not declared in `contract.manifest.json` | Add the namespace to the manifest or remove it from the source |
468
+ | `check:docs` fails | README or TOKEN_CONTRACT.md has drifted from the manifest | Update the doc to match the current contract |
469
+ | `check:classification` fails | A contract-authority file changed without a classification entry | Add `Contract change type: additive`, `semantic change`, or `breaking` to `CHANGELOG.md [Unreleased]` |
470
+
471
+ ## AI and automation boundaries
472
+
473
+ Claude Code (`claude-sonnet-4-6`) is the primary development agent for this
474
+ repository. Codex handles releases and production stabilization. Jules handles
475
+ small automated fixes and generated-output sync. GitHub Copilot provides
476
+ development support.
477
+
478
+ Claude Code does not create git commits. All Claude Code changes are prepared
479
+ and validated, then handed off to Bradley Potts for human review and commit.
480
+ Jules commits bounded automated maintenance tasks autonomously when all
481
+ validation gates pass.
482
+
483
+ **Protected from automated change:** locked color families (`success`,
484
+ `warning`, `danger`, CTA/brand-action), `contract.manifest.json`, and
485
+ `src/generated/tokens.ts`. See [AGENTS.md](AGENTS.md) for full agent
486
+ governance and boundary rules.
487
+
379
488
  ## Contributing
380
489
 
381
490
  PHCDevworks maintains this package as part of the Spectre system.