@phcdevworks/spectre-tokens is the design-token package of the Spectre system
for downstream Spectre packages and compatible applications.
Maintained by PHCDevworks, it defines the visual language, semantic roles, and token contracts consumed downstream. It keeps visual meaning centralized in token data while downstream UI packages define structure and adapter packages translate those contracts for specific frameworks and runtimes.
Contributing | Changelog | Security Policy
- Uses
tokens/as the source of truth for design-token data - Generates JavaScript, TypeScript, CSS, and Tailwind theme exports from shared token sources
- Defines semantic token contracts for surfaces, text, components, buttons, forms, and modes
- Exposes primitives and semantic roles for downstream packages and compatible applications
- Keeps visual meaning centralized so downstream consumers do not redefine token contracts
- Visual language expressed as token data in
tokens/ - Semantic roles and token contracts consumed downstream
- Generated token outputs for JavaScript, TypeScript, CSS variables, and Tailwind theme exports
- Theme and mode definitions used by downstream consumers
This package is the correct place to define token meaning.
- Component structure or composition That belongs in downstream UI packages such
as
@phcdevworks/spectre-ui. - Framework-specific delivery Adapter packages translate Spectre contracts for specific frameworks and runtimes.
- Local redefinition of token meaning Downstream consumers should consume these contracts rather than recreate them independently.
- Example app architecture The
example/directory documents token usage; it is not the contract source and should not become a downstream UI layer.
npm install @phcdevworks/spectre-tokensImport the generated CSS variables:
@import '@phcdevworks/spectre-tokens/index.css';Load the token object in JavaScript or TypeScript:
import tokens from '@phcdevworks/spectre-tokens'
const card = {
background: tokens.surface.page,
color: tokens.text.onPage.default,
padding: tokens.space['16'],
borderRadius: tokens.radii.md
}Use the generated Tailwind preset when you want the package to populate theme values from the token contract:
// tailwind.config.ts
import { tailwindPreset } from '@phcdevworks/spectre-tokens'
export default {
presets: [tailwindPreset]
}- Change token data in
tokens/. - Treat generated outputs as derived artifacts.
- Treat
contract.manifest.jsonas the machine-readable contract authority for public namespaces and required outputs.
Use the runtime token object when a consumer needs token values directly in code.
import tokens from '@phcdevworks/spectre-tokens'
const card = {
background: tokens.surface.card,
color: tokens.text.onSurface.default,
borderColor: tokens.component.iconBox.border,
padding: tokens.space['16']
}Use named exports when you need generated helpers or Tailwind integration:
import tokens, {
generateCssVariables,
tailwindPreset,
tailwindTheme
} from '@phcdevworks/spectre-tokens'
const css = generateCssVariables(tokens)Import index.css when a downstream package or app wants the generated Spectre
CSS variable contract.
@import '@phcdevworks/spectre-tokens/index.css';
.card {
background: var(--sp-surface-card);
color: var(--sp-text-on-surface-default);
}The CSS entry point is intended for consumers that want the token contract as variables rather than reading values in JavaScript.
Use the Tailwind preset when a consumer wants Tailwind theme values derived from the same token contract.
import { tailwindPreset } from '@phcdevworks/spectre-tokens'
export default {
presets: [tailwindPreset]
}Use tailwindTheme directly only when a consumer needs the generated theme
object outside the preset shape.
Prefer semantic namespaces for downstream UI work:
surfacetextcomponentbuttonsformsmodes
These namespaces are the main consumer-facing contract because they express UI meaning rather than raw color selection.
Raw palette access through colors is acceptable when a consumer deliberately
needs fixed palette values.
Typical cases:
- data visualization or non-semantic decorative use
- compatibility layers that need a specific raw ramp
- tooling that inspects or serializes palette data directly
Raw palette access should not replace semantic token usage for normal UI surfaces, text, buttons, forms, or mode-aware styling.
The generated token object includes these namespaces:
colorsspacelayoutradiitypographyfontshadowsbreakpointszIndextransitionsanimationsopacityaspectRatiosiconsborderaccessibilitybuttonsformssurfacetextcomponentmodes
The exported runtime token object is a flattened string-based tree generated
from tokens/. Source-only wrapper fields such as value and metadata are
internal generation details and are not part of the public package contract.
contract.manifest.json is the machine-readable contract authority for this
package.
It defines:
- public namespaces
- required output surfaces for JavaScript, CSS, and Tailwind
- protected semantic groups
Every contract-facing surface in this repository must match that manifest. Validation fails fast on token overwrite across files, undocumented namespaces, output drift, and README mismatch with the contract authority.
The package includes mode-aware semantic tokens under modes, with default
and dark mode definitions in the generated output.
Use semantic mode-aware values when the consumer needs light/dark or mode-specific behavior without branching on raw palette values.
import tokens from '@phcdevworks/spectre-tokens'
const darkPage = tokens.modes.dark.surface.page
const darkText = tokens.modes.dark.text.onPage.defaultGuidance:
- Prefer semantic tokens for theme-aware UI.
- Prefer
modeswhen a consumer explicitly needs mode-specific values. - Do not invent local light/dark token contracts when this package already provides the semantic path.
Downstream packages should never redefine locally:
- the meaning of
surface,text,component,buttons,forms, ormodes - protected semantic groups such as
success,warning,danger, or CTA / brand-action semantics - public namespace shape that this package already exports
Downstream packages may:
- compose UI structure on top of this contract
- map these tokens into framework-specific delivery
- use raw palette values when the usage is intentionally non-semantic
Consumers should treat this package as a SemVer-governed contract.
Practical guidance:
- additive token paths are intended to be safe for existing consumers
- semantic shifts may keep the same path but still affect visual meaning
- renames and removals are breaking
- generated JS, TS, CSS, and Tailwind outputs are expected to stay aligned
If a downstream package depends on specific token paths or semantic meaning:
- read
CHANGELOG.mdfor contract change classification - read
TOKEN_CONTRACT.mdfor contract rules - prefer documented public namespaces over undocumented internal assumptions
@phcdevworks/spectre-tokens exports:
default/tokenstailwindThemetailwindPresetgenerateCssVariables- TypeScript types including
SpectreTokens,TailwindTheme,SpectreModeTokens, andSpectreModeName
Example:
import tokens, {
generateCssVariables,
tailwindPreset,
tailwindTheme
} from '@phcdevworks/spectre-tokens'
const css = generateCssVariables(tokens, {
selector: ':root',
prefix: 'sp'
})@phcdevworks/spectre-tokens/index.css
Spectre keeps responsibilities separate:
@phcdevworks/spectre-tokensdefines visual language, semantic roles, and token contracts@phcdevworks/spectre-uiturns those contracts into reusable CSS, Tailwind tooling, and shared styling behavior- Adapter packages translate Spectre contracts for framework-specific delivery
That separation keeps token meaning centralized while letting the package system expand by responsibility.
For downstream packages and compatible apps:
- import tokens from the package root when you need runtime values
- import
index.csswhen you need generated CSS variables - use
tailwindPresetwhen you need Tailwind theme integration - prefer semantic namespaces for UI behavior
- use raw palette values only when fixed palette access is intentional
- treat
tokens/as source of truth and generated outputs as derived - do not redefine Spectre semantic contracts locally
Regenerate package outputs:
npm run buildRun the full validation and release gate:
npm run checkKey source areas:
tokens/for source token datasrc/generated/for generated token outputsrc/for package entry points, CSS generation, and typesscripts/for build and validation scriptsexample/for usage examples
The files in example/ are illustrative token demos only. They help explain the
token contract, but they are not the package contract itself and should not be
treated as downstream UI primitives.
PHCDevworks maintains this package as part of the Spectre system.
When contributing:
- treat
tokens/as the source of truth - keep generated outputs derived from source data
- avoid breaking token contracts without an intentional major-version change
- run
npm run buildto regenerate outputs when sources change - run
npm run checkas the full validation gate before opening a pull request - do not modify locked semantic color families without explicit approval
- keep
README.md, generated outputs, andcontract.manifest.jsonaligned
See CONTRIBUTING.md for the full workflow.
MIT © PHCDevworks. See LICENSE.