@phcdevworks/spectre-tokens 0.0.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/LICENSE +21 -0
- package/README.md +298 -0
- package/dist/index.cjs +501 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +226 -0
- package/dist/index.d.cts +96 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.js +469 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
- package/tokens/core.json +330 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 PHCDevworks
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# Spectre Tokens
|
|
2
|
+
|
|
3
|
+
**Spectre Tokens** is the foundational design layer of the **Spectre Suite** — a token-driven design system that powers consistent styling across all Spectre projects.
|
|
4
|
+
|
|
5
|
+
It defines Spectre's visual identity through design tokens (colors, typography, spacing, radii, shadows, breakpoints, z-index, transitions) consumed by **Spectre UI**, **Spectre Blocks** (WordPress), **Spectre Astro**, **Spectre 11ty**, and future Spectre tools.
|
|
6
|
+
|
|
7
|
+
> One token system. Many frameworks. Full consistency.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Spectre Tokens provides a centralized source of truth for design decisions across the entire Spectre ecosystem. Whether you're building WordPress blocks, static sites with Astro or 11ty, or future Spectre integrations, Spectre Tokens ensures your design language remains consistent and maintainable.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- **Token-Driven Design**: Centralized design tokens for colors, typography, spacing, and more
|
|
18
|
+
- **Cross-Platform**: Powers styling across WordPress, Astro, 11ty, and beyond
|
|
19
|
+
- **Multiple Formats**: Export tokens as CSS variables, JSON, JavaScript, and more
|
|
20
|
+
- **Type-Safe**: TypeScript definitions for all design tokens
|
|
21
|
+
- **Themeable**: Easy customization and theming support
|
|
22
|
+
- **Semantic Colors**: Built-in success, warning, error, and info color scales
|
|
23
|
+
- **Responsive Design**: Consistent breakpoint tokens for all screen sizes
|
|
24
|
+
- **Motion Design**: Transition duration and easing tokens for animations
|
|
25
|
+
- **Z-Index Scale**: Organized layering system for consistent stacking
|
|
26
|
+
- **CRO-Optimized**: Button variants, form states, and micro-interactions for higher conversions
|
|
27
|
+
- **Accessibility First**: WCAG-compliant focus states and touch target guidelines
|
|
28
|
+
- **Interaction States**: Opacity and state tokens for hover, active, disabled, and more
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @phcdevworks/spectre-tokens
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
Import Spectre Tokens into your project:
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
import tokens from "@phcdevworks/spectre-tokens";
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Or use CSS variables directly:
|
|
45
|
+
|
|
46
|
+
```css
|
|
47
|
+
@import "@phcdevworks/spectre-tokens/css/tokens.css";
|
|
48
|
+
|
|
49
|
+
.my-component {
|
|
50
|
+
color: var(--spectre-color-primary);
|
|
51
|
+
padding: var(--spectre-spacing-4);
|
|
52
|
+
border-radius: var(--spectre-radius-md);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## CRO & Accessibility Features
|
|
57
|
+
|
|
58
|
+
### Button Variants (Conversion-Optimized)
|
|
59
|
+
|
|
60
|
+
Spectre Tokens includes pre-designed button variants optimized for conversion rate optimization:
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
// Available button variants
|
|
64
|
+
tokens.buttons.primary; // High-contrast primary CTA
|
|
65
|
+
tokens.buttons.secondary; // Outlined secondary action
|
|
66
|
+
tokens.buttons.ghost; // Minimal tertiary action
|
|
67
|
+
tokens.buttons.danger; // Destructive actions
|
|
68
|
+
tokens.buttons.success; // Positive confirmation
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Each variant includes full state coverage:
|
|
72
|
+
|
|
73
|
+
- `bg`, `bgHover`, `bgActive`, `bgDisabled`
|
|
74
|
+
- `text`, `textDisabled`
|
|
75
|
+
- `border`, `borderDisabled` (for outlined variants)
|
|
76
|
+
|
|
77
|
+
**CSS Usage:**
|
|
78
|
+
|
|
79
|
+
```css
|
|
80
|
+
.cta-button {
|
|
81
|
+
background: var(--sp-button-primary-bg);
|
|
82
|
+
color: var(--sp-button-primary-text);
|
|
83
|
+
}
|
|
84
|
+
.cta-button:hover {
|
|
85
|
+
background: var(--sp-button-primary-bg-hover);
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Form States (Validation & Feedback)
|
|
90
|
+
|
|
91
|
+
Complete form state tokens for clear user feedback:
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
tokens.forms.default; // Initial state
|
|
95
|
+
tokens.forms.hover; // Mouse hover
|
|
96
|
+
tokens.forms.focus; // Keyboard focus
|
|
97
|
+
tokens.forms.valid; // Successful validation
|
|
98
|
+
tokens.forms.invalid; // Error state
|
|
99
|
+
tokens.forms.disabled; // Non-interactive
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**CSS Usage:**
|
|
103
|
+
|
|
104
|
+
```css
|
|
105
|
+
.input {
|
|
106
|
+
background: var(--sp-form-default-bg);
|
|
107
|
+
border: 1px solid var(--sp-form-default-border);
|
|
108
|
+
}
|
|
109
|
+
.input:focus {
|
|
110
|
+
border-color: var(--sp-form-focus-border);
|
|
111
|
+
outline: var(--sp-focus-ring-width) var(--sp-focus-ring-style) var(--sp-form-focus-ring);
|
|
112
|
+
}
|
|
113
|
+
.input.error {
|
|
114
|
+
border-color: var(--sp-form-invalid-border);
|
|
115
|
+
background: var(--sp-form-invalid-bg);
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Accessibility Standards
|
|
120
|
+
|
|
121
|
+
Built-in WCAG compliance helpers:
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
tokens.accessibility.focusRing.width; // 2px
|
|
125
|
+
tokens.accessibility.focusRing.offset; // 2px
|
|
126
|
+
tokens.accessibility.minTouchTarget; // 44px (WCAG 2.5.5)
|
|
127
|
+
tokens.accessibility.minTextSize; // 16px
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Focus Colors:**
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
tokens.colors.focus.primary; // Brand-aligned focus ring
|
|
134
|
+
tokens.colors.focus.error; // Error state focus
|
|
135
|
+
tokens.colors.focus.info; // Info state focus
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Micro-Interactions & Animations
|
|
139
|
+
|
|
140
|
+
Pre-configured animations for engagement:
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
tokens.animations.fadeIn; // Subtle entrance
|
|
144
|
+
tokens.animations.slideDown; // Dropdown reveal
|
|
145
|
+
tokens.animations.scaleIn; // Modal/tooltip appearance
|
|
146
|
+
tokens.animations.bounce; // Success feedback
|
|
147
|
+
tokens.animations.shake; // Error feedback
|
|
148
|
+
tokens.animations.pulse; // Loading state
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**CSS Usage:**
|
|
152
|
+
|
|
153
|
+
```css
|
|
154
|
+
@keyframes fade-in {
|
|
155
|
+
from {
|
|
156
|
+
opacity: 0;
|
|
157
|
+
}
|
|
158
|
+
to {
|
|
159
|
+
opacity: 1;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
.modal {
|
|
163
|
+
animation: fade-in var(--sp-animation-fade-in-duration) var(
|
|
164
|
+
--sp-animation-fade-in-easing
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Opacity Tokens
|
|
170
|
+
|
|
171
|
+
Consistent interaction opacity:
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
tokens.opacity.hover; // 0.92 - Subtle hover
|
|
175
|
+
tokens.opacity.active; // 0.84 - Active press
|
|
176
|
+
tokens.opacity.disabled; // 0.38 - Disabled state (WCAG compliant)
|
|
177
|
+
tokens.opacity.overlay; // 0.5 - Modal overlays
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### WCAG Contrast Guidelines
|
|
181
|
+
|
|
182
|
+
**Primary Colors:**
|
|
183
|
+
|
|
184
|
+
- Brand 500 on white: ✅ AAA (contrast ratio 4.8:1)
|
|
185
|
+
- Success 600 on white: ✅ AAA (contrast ratio 4.7:1)
|
|
186
|
+
- Error 600 on white: ✅ AAA (contrast ratio 5.2:1)
|
|
187
|
+
|
|
188
|
+
**Text Colors:**
|
|
189
|
+
|
|
190
|
+
- Neutral 900 on white: ✅ AAA (contrast ratio 16.1:1)
|
|
191
|
+
- Neutral 700 on white: ✅ AA (contrast ratio 8.4:1)
|
|
192
|
+
|
|
193
|
+
**Focus Indicators:**
|
|
194
|
+
|
|
195
|
+
- All focus rings meet WCAG 2.4.7 (2px solid, high contrast)
|
|
196
|
+
|
|
197
|
+
> **Note:** Always test final implementations with contrast checking tools like [WebAIM Contrast Checker](https://webaim.org/resources/contrastchecker/).
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Part of the Spectre Suite
|
|
202
|
+
|
|
203
|
+
- **Spectre Tokens**: Design token foundation (this package)
|
|
204
|
+
- **Spectre UI**: Core styling layer
|
|
205
|
+
- **Spectre Blocks**: WordPress block library
|
|
206
|
+
- **Spectre Astro**: Astro integration
|
|
207
|
+
- **Spectre 11ty**: Eleventy integration
|
|
208
|
+
|
|
209
|
+
## License
|
|
210
|
+
|
|
211
|
+
MIT
|
|
212
|
+
|
|
213
|
+
## Contributing
|
|
214
|
+
|
|
215
|
+
Contributions are welcome! Please open an issue or submit a pull request.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Repository layout
|
|
220
|
+
|
|
221
|
+
| Folder | Responsibility |
|
|
222
|
+
| ---------- | ------------------------------------------------------------------------------------------------------------- |
|
|
223
|
+
| `tokens/` | Raw JSON tokens owned by design. `core.json` holds colors, spacing, radii, typography scale, and shadows. |
|
|
224
|
+
| `src/` | TypeScript source that turns JSON into reusable formats (JS/TS objects, Tailwind theme, CSS helpers). |
|
|
225
|
+
| `scripts/` | Build utilities. `build-css.js` consumes the compiled library and writes `dist/index.css`. |
|
|
226
|
+
| `dist/` | Generated artifacts: `index.js`, `index.cjs`, `index.d.ts`, and `index.css`. Regenerated via `npm run build`. |
|
|
227
|
+
|
|
228
|
+
Designers only edit `tokens/`. Engineering evolves `src/` + `scripts/` when structure changes.
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## Consuming the tokens
|
|
233
|
+
|
|
234
|
+
### Programmatic access (JS/TS)
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
import tokens, {
|
|
238
|
+
tailwindTheme,
|
|
239
|
+
tailwindPreset,
|
|
240
|
+
generateCssVariables,
|
|
241
|
+
} from "@phcdevworks/spectre-tokens";
|
|
242
|
+
|
|
243
|
+
// Raw structured tokens (colors, spacing, radii, typography, shadows)
|
|
244
|
+
console.log(tokens.colors.brand["500"]);
|
|
245
|
+
|
|
246
|
+
// Tailwind-ready theme or preset drop-in
|
|
247
|
+
export default {
|
|
248
|
+
theme: tailwindTheme,
|
|
249
|
+
presets: [tailwindPreset],
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// Generic CSS variable string if you want custom selectors or prefixes
|
|
253
|
+
const css = generateCssVariables(tokens, {
|
|
254
|
+
selector: ".spectre-scope",
|
|
255
|
+
prefix: "sp",
|
|
256
|
+
});
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### CSS variables
|
|
260
|
+
|
|
261
|
+
Include the generated CSS file to get `--sp-*` variables anywhere:
|
|
262
|
+
|
|
263
|
+
```css
|
|
264
|
+
@import "@phcdevworks/spectre-tokens/index.css";
|
|
265
|
+
|
|
266
|
+
.button {
|
|
267
|
+
color: var(--sp-color-brand-500);
|
|
268
|
+
padding-inline: var(--sp-space-md);
|
|
269
|
+
border-radius: var(--sp-radius-pill);
|
|
270
|
+
box-shadow: var(--sp-shadow-md);
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Tailwind compatibility
|
|
277
|
+
|
|
278
|
+
This package exposes a Tailwind-style theme object and a preset wrapper built with the classic Tailwind config shape (`theme.extend` with colors, spacing, font families, etc.). Tailwind CSS v4 introduces the Oxide engine and optional token-centric workflows, but it still supports the traditional `tailwind.config.(js|cjs|mjs|ts)` file, theme configuration, and presets. You can continue to consume `tailwindPreset` or spread `tailwindTheme` in both Tailwind 3 and Tailwind 4 projects without changes.
|
|
279
|
+
|
|
280
|
+
When Tailwind’s new token-first features stabilize, we may add an additional export that serializes `tokens/core.json` into whatever public token schema Tailwind ships. Until then, treat this library as a conventional Tailwind theme/preset provider that uses the stable config-based API.
|
|
281
|
+
|
|
282
|
+
Engineering guidance:
|
|
283
|
+
|
|
284
|
+
- Primary integration: keep exporting `tailwindTheme` (Spectre theme contents) and `tailwindPreset` (for `presets: []`).
|
|
285
|
+
- Support Tailwind 3.x and 4.x via the classic config API; avoid depending on v4-specific internals or JSON token formats.
|
|
286
|
+
- Future (optional): layer on a token-native export once Tailwind’s token workflows are documented and stable, without removing the preset interface.
|
|
287
|
+
|
|
288
|
+
Public messaging across Spectre projects should stay simple: “Works with Tailwind 3 and 4 via the standard config-based API. We export a theme and preset; plug it in like any other Tailwind preset. When Tailwind’s token workflow is ready, we’ll offer an additional integration.”
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## Build & release
|
|
293
|
+
|
|
294
|
+
```
|
|
295
|
+
npm run build
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
This command bundles the TypeScript library with `tsup` (ESM + CJS + `.d.ts`) and then calls `scripts/build-css.js` to emit `dist/index.css`. Because `dist/` is fully generated, publishing is reproducible from `tokens/` + `src/`.
|