@phcdevworks/spectre-tokens 2.2.0 → 2.4.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 +196 -23
- package/dist/index.cjs +68 -236
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +19 -25
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +68 -236
- package/dist/index.js.map +1 -1
- package/package.json +18 -11
- package/tokens/components.json +23 -17
- package/tokens/modes.json +20 -20
- package/tokens/primitives.json +3 -3
- package/tokens/typography.json +2 -1
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
|
-
|
|
76
|
-
`forms` for application UI. Raw palette values remain available when fixed color
|
|
77
|
-
access is appropriate.
|
|
96
|
+
## Consumer usage
|
|
78
97
|
|
|
79
|
-
|
|
98
|
+
### Source of truth
|
|
80
99
|
|
|
81
|
-
-
|
|
82
|
-
-
|
|
83
|
-
-
|
|
84
|
-
|
|
85
|
-
|
|
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`
|
|
@@ -113,23 +222,74 @@ The exported runtime token object is a flattened string-based tree generated
|
|
|
113
222
|
from `tokens/`. Source-only wrapper fields such as `value` and `metadata` are
|
|
114
223
|
internal generation details and are not part of the public package contract.
|
|
115
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
|
+
|
|
116
240
|
### Themes and modes
|
|
117
241
|
|
|
118
242
|
The package includes mode-aware semantic tokens under `modes`, with `default`
|
|
119
243
|
and `dark` mode definitions in the generated output.
|
|
120
244
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
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.
|
|
124
247
|
|
|
125
|
-
|
|
248
|
+
```ts
|
|
249
|
+
import tokens from '@phcdevworks/spectre-tokens'
|
|
126
250
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
|
133
293
|
|
|
134
294
|
## Package exports / API surface
|
|
135
295
|
|
|
@@ -140,7 +300,7 @@ changing consumer code.
|
|
|
140
300
|
- `default` / `tokens`
|
|
141
301
|
- `tailwindTheme`
|
|
142
302
|
- `tailwindPreset`
|
|
143
|
-
- `generateCssVariables
|
|
303
|
+
- `generateCssVariables`
|
|
144
304
|
- TypeScript types including `SpectreTokens`, `TailwindTheme`,
|
|
145
305
|
`SpectreModeTokens`, and `SpectreModeName`
|
|
146
306
|
|
|
@@ -177,6 +337,18 @@ Spectre keeps responsibilities separate:
|
|
|
177
337
|
That separation keeps token meaning centralized while letting the package system
|
|
178
338
|
expand by responsibility.
|
|
179
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
|
+
|
|
180
352
|
## Development
|
|
181
353
|
|
|
182
354
|
Regenerate package outputs:
|
|
@@ -199,9 +371,9 @@ Key source areas:
|
|
|
199
371
|
- `scripts/` for build and validation scripts
|
|
200
372
|
- `example/` for usage examples
|
|
201
373
|
|
|
202
|
-
The files in `example/` are illustrative token demos only. They help explain
|
|
203
|
-
|
|
204
|
-
|
|
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.
|
|
205
377
|
|
|
206
378
|
## Contributing
|
|
207
379
|
|
|
@@ -215,6 +387,7 @@ When contributing:
|
|
|
215
387
|
- run `npm run build` to regenerate outputs when sources change
|
|
216
388
|
- run `npm run check` as the full validation gate before opening a pull request
|
|
217
389
|
- do not modify locked semantic color families without explicit approval
|
|
390
|
+
- keep `README.md`, generated outputs, and `contract.manifest.json` aligned
|
|
218
391
|
|
|
219
392
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for the full workflow.
|
|
220
393
|
|