@phcdevworks/spectre-tokens 2.1.2 → 2.3.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
@@ -27,6 +27,27 @@ translate those contracts for specific frameworks and runtimes.
27
27
  - Keeps visual meaning centralized so downstream consumers do not redefine token
28
28
  contracts
29
29
 
30
+ ## What this package owns
31
+
32
+ - Visual language expressed as token data in `tokens/`
33
+ - Semantic roles and token contracts consumed downstream
34
+ - Generated token outputs for JavaScript, TypeScript, CSS variables, and
35
+ Tailwind theme exports
36
+ - Theme and mode definitions used by downstream consumers
37
+
38
+ This package is the correct place to define token meaning.
39
+
40
+ ## What this package does not own
41
+
42
+ - Component structure or composition That belongs in downstream UI packages such
43
+ as [`@phcdevworks/spectre-ui`](https://github.com/phcdevworks/spectre-ui).
44
+ - Framework-specific delivery Adapter packages translate Spectre contracts for
45
+ specific frameworks and runtimes.
46
+ - Local redefinition of token meaning Downstream consumers should consume these
47
+ contracts rather than recreate them independently.
48
+ - Example app architecture The `example/` directory documents token usage; it is
49
+ not the contract source and should not become a downstream UI layer.
50
+
30
51
  ## Installation
31
52
 
32
53
  ```bash
@@ -72,17 +93,103 @@ export default {
72
93
  }
73
94
  ```
74
95
 
75
- Prefer semantic tokens such as `surface`, `text`, `component`, `buttons`, and
76
- `forms` for application UI. Raw palette values remain available when fixed color
77
- access is appropriate.
96
+ ## Consumer usage
78
97
 
79
- ## What this package owns
98
+ ### Source of truth
80
99
 
81
- - Visual language expressed as token data in `tokens/`
82
- - Semantic roles and token contracts consumed downstream
83
- - Generated token outputs for JavaScript, TypeScript, CSS variables, and
84
- Tailwind theme exports
85
- - Theme and mode definitions used by downstream consumers
100
+ - Change token data in `tokens/`.
101
+ - Treat generated outputs as derived artifacts.
102
+ - Treat `contract.manifest.json` as the machine-readable contract authority for
103
+ public namespaces and required outputs.
104
+
105
+ ### JavaScript and TypeScript tokens
106
+
107
+ Use the runtime token object when a consumer needs token values directly in
108
+ code.
109
+
110
+ ```ts
111
+ import tokens from '@phcdevworks/spectre-tokens'
112
+
113
+ const card = {
114
+ background: tokens.surface.card,
115
+ color: tokens.text.onSurface.default,
116
+ borderColor: tokens.component.iconBox.border,
117
+ padding: tokens.space['16']
118
+ }
119
+ ```
120
+
121
+ Use named exports when you need generated helpers or Tailwind integration:
122
+
123
+ ```ts
124
+ import tokens, {
125
+ generateCssVariables,
126
+ tailwindPreset,
127
+ tailwindTheme
128
+ } from '@phcdevworks/spectre-tokens'
129
+
130
+ const css = generateCssVariables(tokens)
131
+ ```
132
+
133
+ ### Generated CSS variables
134
+
135
+ Import `index.css` when a downstream package or app wants the generated Spectre
136
+ CSS variable contract.
137
+
138
+ ```css
139
+ @import '@phcdevworks/spectre-tokens/index.css';
140
+
141
+ .card {
142
+ background: var(--sp-surface-card);
143
+ color: var(--sp-text-on-surface-default);
144
+ }
145
+ ```
146
+
147
+ The CSS entry point is intended for consumers that want the token contract as
148
+ variables rather than reading values in JavaScript.
149
+
150
+ ### Tailwind preset
151
+
152
+ Use the Tailwind preset when a consumer wants Tailwind theme values derived from
153
+ the same token contract.
154
+
155
+ ```ts
156
+ import { tailwindPreset } from '@phcdevworks/spectre-tokens'
157
+
158
+ export default {
159
+ presets: [tailwindPreset]
160
+ }
161
+ ```
162
+
163
+ Use `tailwindTheme` directly only when a consumer needs the generated theme
164
+ object outside the preset shape.
165
+
166
+ ### Semantic tokens first
167
+
168
+ Prefer semantic namespaces for downstream UI work:
169
+
170
+ - `surface`
171
+ - `text`
172
+ - `component`
173
+ - `buttons`
174
+ - `forms`
175
+ - `modes`
176
+
177
+ These namespaces are the main consumer-facing contract because they express UI
178
+ meaning rather than raw color selection.
179
+
180
+ ### When raw palette access is acceptable
181
+
182
+ Raw palette access through `colors` is acceptable when a consumer deliberately
183
+ needs fixed palette values.
184
+
185
+ Typical cases:
186
+
187
+ - data visualization or non-semantic decorative use
188
+ - compatibility layers that need a specific raw ramp
189
+ - tooling that inspects or serializes palette data directly
190
+
191
+ Raw palette access should not replace semantic token usage for normal UI
192
+ surfaces, text, buttons, forms, or mode-aware styling.
86
193
 
87
194
  ### Token model
88
195
 
@@ -100,6 +207,8 @@ The generated token object includes these namespaces:
100
207
  - `transitions`
101
208
  - `animations`
102
209
  - `opacity`
210
+ - `aspectRatios`
211
+ - `icons`
103
212
  - `border`
104
213
  - `accessibility`
105
214
  - `buttons`
@@ -109,23 +218,78 @@ The generated token object includes these namespaces:
109
218
  - `component`
110
219
  - `modes`
111
220
 
221
+ The exported runtime token object is a flattened string-based tree generated
222
+ from `tokens/`. Source-only wrapper fields such as `value` and `metadata` are
223
+ internal generation details and are not part of the public package contract.
224
+
225
+ ## Public contract guarantees
226
+
227
+ `contract.manifest.json` is the machine-readable contract authority for this
228
+ package.
229
+
230
+ It defines:
231
+
232
+ - public namespaces
233
+ - required output surfaces for JavaScript, CSS, and Tailwind
234
+ - protected semantic groups
235
+
236
+ Every contract-facing surface in this repository must match that manifest.
237
+ Validation fails fast on token overwrite across files, undocumented namespaces,
238
+ output drift, and README mismatch with the contract authority.
239
+
112
240
  ### Themes and modes
113
241
 
114
242
  The package includes mode-aware semantic tokens under `modes`, with `default`
115
243
  and `dark` mode definitions in the generated output.
116
244
 
117
- Raw palette tokens are stable values. Semantic tokens are the preferred
118
- interface for theme-aware usage because they can map across modes without
119
- changing consumer code.
245
+ Use semantic mode-aware values when the consumer needs light/dark or
246
+ mode-specific behavior without branching on raw palette values.
120
247
 
121
- ## What this package does not own
248
+ ```ts
249
+ import tokens from '@phcdevworks/spectre-tokens'
122
250
 
123
- - Component structure or composition That belongs in downstream UI packages such
124
- as [`@phcdevworks/spectre-ui`](https://github.com/phcdevworks/spectre-ui).
125
- - Framework-specific delivery Adapter packages translate Spectre contracts for
126
- specific frameworks and runtimes.
127
- - Local redefinition of token meaning Downstream consumers should consume these
128
- contracts rather than recreate them independently.
251
+ const darkPage = tokens.modes.dark.surface.page
252
+ const darkText = tokens.modes.dark.text.onPage.default
253
+ ```
254
+
255
+ Guidance:
256
+
257
+ - Prefer semantic tokens for theme-aware UI.
258
+ - Prefer `modes` when a consumer explicitly needs mode-specific values.
259
+ - Do not invent local light/dark token contracts when this package already
260
+ provides the semantic path.
261
+
262
+ ## Downstream boundaries
263
+
264
+ Downstream packages should never redefine locally:
265
+
266
+ - the meaning of `surface`, `text`, `component`, `buttons`, `forms`, or `modes`
267
+ - protected semantic groups such as `success`, `warning`, `danger`, or CTA /
268
+ brand-action semantics
269
+ - public namespace shape that this package already exports
270
+
271
+ Downstream packages may:
272
+
273
+ - compose UI structure on top of this contract
274
+ - map these tokens into framework-specific delivery
275
+ - use raw palette values when the usage is intentionally non-semantic
276
+
277
+ ## Upgrade expectations for consumers
278
+
279
+ Consumers should treat this package as a SemVer-governed contract.
280
+
281
+ Practical guidance:
282
+
283
+ - additive token paths are intended to be safe for existing consumers
284
+ - semantic shifts may keep the same path but still affect visual meaning
285
+ - renames and removals are breaking
286
+ - generated JS, TS, CSS, and Tailwind outputs are expected to stay aligned
287
+
288
+ If a downstream package depends on specific token paths or semantic meaning:
289
+
290
+ - read `CHANGELOG.md` for contract change classification
291
+ - read `TOKEN_CONTRACT.md` for contract rules
292
+ - prefer documented public namespaces over undocumented internal assumptions
129
293
 
130
294
  ## Package exports / API surface
131
295
 
@@ -136,7 +300,7 @@ changing consumer code.
136
300
  - `default` / `tokens`
137
301
  - `tailwindTheme`
138
302
  - `tailwindPreset`
139
- - `generateCssVariables()`
303
+ - `generateCssVariables`
140
304
  - TypeScript types including `SpectreTokens`, `TailwindTheme`,
141
305
  `SpectreModeTokens`, and `SpectreModeName`
142
306
 
@@ -173,6 +337,18 @@ Spectre keeps responsibilities separate:
173
337
  That separation keeps token meaning centralized while letting the package system
174
338
  expand by responsibility.
175
339
 
340
+ ## Consumer checklist
341
+
342
+ For downstream packages and compatible apps:
343
+
344
+ - import tokens from the package root when you need runtime values
345
+ - import `index.css` when you need generated CSS variables
346
+ - use `tailwindPreset` when you need Tailwind theme integration
347
+ - prefer semantic namespaces for UI behavior
348
+ - use raw palette values only when fixed palette access is intentional
349
+ - treat `tokens/` as source of truth and generated outputs as derived
350
+ - do not redefine Spectre semantic contracts locally
351
+
176
352
  ## Development
177
353
 
178
354
  Regenerate package outputs:
@@ -195,9 +371,9 @@ Key source areas:
195
371
  - `scripts/` for build and validation scripts
196
372
  - `example/` for usage examples
197
373
 
198
- The files in `example/` are illustrative token demos only. They help explain
199
- the token contract, but they are not the package contract itself and should not
200
- be treated as downstream UI primitives.
374
+ The files in `example/` are illustrative token demos only. They help explain the
375
+ token contract, but they are not the package contract itself and should not be
376
+ treated as downstream UI primitives.
201
377
 
202
378
  ## Contributing
203
379
 
@@ -211,6 +387,7 @@ When contributing:
211
387
  - run `npm run build` to regenerate outputs when sources change
212
388
  - run `npm run check` as the full validation gate before opening a pull request
213
389
  - do not modify locked semantic color families without explicit approval
390
+ - keep `README.md`, generated outputs, and `contract.manifest.json` aligned
214
391
 
215
392
  See [CONTRIBUTING.md](CONTRIBUTING.md) for the full workflow.
216
393