@yelbolt/engine-ui-color-palette 1.10.2
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 +430 -0
- package/dist/color-DTr3No_G.js +540 -0
- package/dist/color-DTr3No_G.js.map +1 -0
- package/dist/formats/primitives/makeCompose.d.ts +4 -0
- package/dist/formats/primitives/makeCompose.d.ts.map +1 -0
- package/dist/formats/primitives/makeCssCustomProps.d.ts +5 -0
- package/dist/formats/primitives/makeCssCustomProps.d.ts.map +1 -0
- package/dist/formats/primitives/makeCsv.d.ts +13 -0
- package/dist/formats/primitives/makeCsv.d.ts.map +1 -0
- package/dist/formats/primitives/makeDtcgTokens.d.ts +5 -0
- package/dist/formats/primitives/makeDtcgTokens.d.ts.map +1 -0
- package/dist/formats/primitives/makeLessVariables.d.ts +5 -0
- package/dist/formats/primitives/makeLessVariables.d.ts.map +1 -0
- package/dist/formats/primitives/makeNativeTokens.d.ts +4 -0
- package/dist/formats/primitives/makeNativeTokens.d.ts.map +1 -0
- package/dist/formats/primitives/makeResources.d.ts +4 -0
- package/dist/formats/primitives/makeResources.d.ts.map +1 -0
- package/dist/formats/primitives/makeScssVariables.d.ts +5 -0
- package/dist/formats/primitives/makeScssVariables.d.ts.map +1 -0
- package/dist/formats/primitives/makeStyleDictionaryV3Tokens.d.ts +4 -0
- package/dist/formats/primitives/makeStyleDictionaryV3Tokens.d.ts.map +1 -0
- package/dist/formats/primitives/makeSwiftUI.d.ts +4 -0
- package/dist/formats/primitives/makeSwiftUI.d.ts.map +1 -0
- package/dist/formats/primitives/makeTailwindV3Config.d.ts +4 -0
- package/dist/formats/primitives/makeTailwindV3Config.d.ts.map +1 -0
- package/dist/formats/primitives/makeTailwindV4Config.d.ts +4 -0
- package/dist/formats/primitives/makeTailwindV4Config.d.ts.map +1 -0
- package/dist/formats/primitives/makeUIKit.d.ts +4 -0
- package/dist/formats/primitives/makeUIKit.d.ts.map +1 -0
- package/dist/formats/primitives/makeUniversalTokens.d.ts +4 -0
- package/dist/formats/primitives/makeUniversalTokens.d.ts.map +1 -0
- package/dist/formats/semantics/_helpers.d.ts +26 -0
- package/dist/formats/semantics/_helpers.d.ts.map +1 -0
- package/dist/formats/semantics/makeComposeSemantics.d.ts +5 -0
- package/dist/formats/semantics/makeComposeSemantics.d.ts.map +1 -0
- package/dist/formats/semantics/makeCssSemantics.d.ts +5 -0
- package/dist/formats/semantics/makeCssSemantics.d.ts.map +1 -0
- package/dist/formats/semantics/makeCsvSemantics.d.ts +5 -0
- package/dist/formats/semantics/makeCsvSemantics.d.ts.map +1 -0
- package/dist/formats/semantics/makeDtcgSemantics.d.ts +5 -0
- package/dist/formats/semantics/makeDtcgSemantics.d.ts.map +1 -0
- package/dist/formats/semantics/makeLessSemantics.d.ts +5 -0
- package/dist/formats/semantics/makeLessSemantics.d.ts.map +1 -0
- package/dist/formats/semantics/makeNativeSemantics.d.ts +5 -0
- package/dist/formats/semantics/makeNativeSemantics.d.ts.map +1 -0
- package/dist/formats/semantics/makeResourcesSemantics.d.ts +5 -0
- package/dist/formats/semantics/makeResourcesSemantics.d.ts.map +1 -0
- package/dist/formats/semantics/makeScssSemantics.d.ts +5 -0
- package/dist/formats/semantics/makeScssSemantics.d.ts.map +1 -0
- package/dist/formats/semantics/makeStyleDictionaryV3Semantics.d.ts +5 -0
- package/dist/formats/semantics/makeStyleDictionaryV3Semantics.d.ts.map +1 -0
- package/dist/formats/semantics/makeSwiftUISemantics.d.ts +5 -0
- package/dist/formats/semantics/makeSwiftUISemantics.d.ts.map +1 -0
- package/dist/formats/semantics/makeTailwindV3Semantics.d.ts +5 -0
- package/dist/formats/semantics/makeTailwindV3Semantics.d.ts.map +1 -0
- package/dist/formats/semantics/makeTailwindV4Semantics.d.ts +5 -0
- package/dist/formats/semantics/makeTailwindV4Semantics.d.ts.map +1 -0
- package/dist/formats/semantics/makeUIKitSemantics.d.ts +5 -0
- package/dist/formats/semantics/makeUIKitSemantics.d.ts.map +1 -0
- package/dist/formats/semantics/makeUniversalSemantics.d.ts +5 -0
- package/dist/formats/semantics/makeUniversalSemantics.d.ts.map +1 -0
- package/dist/index-Beb8qoyd.js +1403 -0
- package/dist/index-Beb8qoyd.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/code/code.d.ts +28 -0
- package/dist/modules/code/code.d.ts.map +1 -0
- package/dist/modules/code/code.js +1312 -0
- package/dist/modules/code/code.js.map +1 -0
- package/dist/modules/color/color.d.ts +49 -0
- package/dist/modules/color/color.d.ts.map +1 -0
- package/dist/modules/color/color.js +6 -0
- package/dist/modules/color/color.js.map +1 -0
- package/dist/modules/color-harmony/color-harmony.d.ts +25 -0
- package/dist/modules/color-harmony/color-harmony.d.ts.map +1 -0
- package/dist/modules/color-harmony/color-harmony.js +147 -0
- package/dist/modules/color-harmony/color-harmony.js.map +1 -0
- package/dist/modules/contrast/contrast.d.ts +19 -0
- package/dist/modules/contrast/contrast.d.ts.map +1 -0
- package/dist/modules/contrast/contrast.js +187 -0
- package/dist/modules/contrast/contrast.js.map +1 -0
- package/dist/modules/data/data.d.ts +17 -0
- package/dist/modules/data/data.d.ts.map +1 -0
- package/dist/modules/data/data.js +461 -0
- package/dist/modules/data/data.js.map +1 -0
- package/dist/modules/dominant-colors/dominant-colors.d.ts +39 -0
- package/dist/modules/dominant-colors/dominant-colors.d.ts.map +1 -0
- package/dist/modules/dominant-colors/dominant-colors.js +198 -0
- package/dist/modules/dominant-colors/dominant-colors.js.map +1 -0
- package/dist/modules/system/system.d.ts +17 -0
- package/dist/modules/system/system.d.ts.map +1 -0
- package/dist/modules/system/system.js +78 -0
- package/dist/modules/system/system.js.map +1 -0
- package/dist/types/code.types.d.ts +6 -0
- package/dist/types/code.types.d.ts.map +1 -0
- package/dist/types/color.types.d.ts +45 -0
- package/dist/types/color.types.d.ts.map +1 -0
- package/dist/types/configuration.types.d.ts +154 -0
- package/dist/types/configuration.types.d.ts.map +1 -0
- package/dist/types/data.types.d.ts +135 -0
- package/dist/types/data.types.d.ts.map +1 -0
- package/dist/types/model.types.d.ts +3 -0
- package/dist/types/model.types.d.ts.map +1 -0
- package/dist/types/system.types.d.ts +40 -0
- package/dist/types/system.types.d.ts.map +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Aurélien Grimaud
|
|
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,430 @@
|
|
|
1
|
+
  
|
|
2
|
+

|
|
3
|
+
|
|
4
|
+
# UI Color Palette Engine
|
|
5
|
+
|
|
6
|
+
Core utilities library for UI Color Palette - a color management plugin for design tools. This library provides the foundational color manipulation, contrast calculation, and palette generation features used in the plugin.
|
|
7
|
+
|
|
8
|
+
## Design Tools Compatibility
|
|
9
|
+
|
|
10
|
+
UI Color Palette is available for:
|
|
11
|
+
|
|
12
|
+
- Figma - Create and manage color primitives directly in your Figma designs
|
|
13
|
+
- FigJam - Collaborate on color decisions with your team
|
|
14
|
+
- Penpot - Open-source design tool alternative with full color management support
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- **Color Contrast Tools**:
|
|
19
|
+
|
|
20
|
+
- APCA contrast calculations
|
|
21
|
+
- WCAG 2.1 compliance checking
|
|
22
|
+
- Contrast ratio calculations between colors
|
|
23
|
+
- Pre-computed text contrast scores (light/dark) per shade
|
|
24
|
+
|
|
25
|
+
- **Color Manipulation**:
|
|
26
|
+
|
|
27
|
+
- Color space conversions (RGB, HSL, HSLuv, LAB)
|
|
28
|
+
- Color mixing and blending
|
|
29
|
+
- Brightness and saturation adjustments
|
|
30
|
+
|
|
31
|
+
- **Dominant Colors Extraction**:
|
|
32
|
+
|
|
33
|
+
- Extract dominant colors from images using K-means clustering
|
|
34
|
+
- Configurable number of colors to extract
|
|
35
|
+
- Automatic color frequency calculation
|
|
36
|
+
- Support for transparent pixel filtering
|
|
37
|
+
|
|
38
|
+
- **Color Harmony Generation**:
|
|
39
|
+
|
|
40
|
+
- Generate analogous, complementary, triadic, tetradic, square, and compound color harmonies
|
|
41
|
+
- Configurable analogous spread angle
|
|
42
|
+
- Automatic color relationship calculations
|
|
43
|
+
- Support for all major color harmony types
|
|
44
|
+
|
|
45
|
+
- **Color System & Semantic Tokens**:
|
|
46
|
+
|
|
47
|
+
- Build a semantic color system from a taxonomy schema and palette data
|
|
48
|
+
- Bind semantic tokens to primitive shades with optional per-theme overrides
|
|
49
|
+
- Exclude specific tokens from code generation via the `isExcluded` flag
|
|
50
|
+
- Generate semantic token files for CSS, SCSS, LESS, DTCG, Tailwind v3/v4, SwiftUI, UIKit, Compose, Native, Universal, CSV, Android Resources, and Style Dictionary v3
|
|
51
|
+
|
|
52
|
+
- **Palette Generation**:
|
|
53
|
+
- Create harmonious color schemes
|
|
54
|
+
- Generate accessible color combinations
|
|
55
|
+
- Scale generation for design systems
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm install @yelbolt/engine-ui-color-palette
|
|
61
|
+
# or
|
|
62
|
+
yarn add @yelbolt/engine-ui-color-palette
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import {
|
|
69
|
+
Color,
|
|
70
|
+
Contrast,
|
|
71
|
+
Data,
|
|
72
|
+
DominantColors,
|
|
73
|
+
ColorHarmony,
|
|
74
|
+
} from '@yelbolt/engine-ui-color-palette'
|
|
75
|
+
|
|
76
|
+
// Use Color class for color manipulation
|
|
77
|
+
const color = new Color({
|
|
78
|
+
sourceColor: [255, 0, 0], // RGB values
|
|
79
|
+
lightness: 50,
|
|
80
|
+
hueShifting: 0,
|
|
81
|
+
chromaShifting: 100,
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
// Use Contrast class for accessibility checks
|
|
85
|
+
const contrast = new Contrast({
|
|
86
|
+
backgroundColor: [255, 255, 255],
|
|
87
|
+
textColor: '#000000',
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
// Use Data class for palette generation
|
|
91
|
+
const data = new Data({
|
|
92
|
+
base: baseConfig,
|
|
93
|
+
themes: themesConfig,
|
|
94
|
+
meta: metaConfig,
|
|
95
|
+
})
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Examples
|
|
99
|
+
|
|
100
|
+
### Color Manipulation
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import { Color } from '@yelbolt/engine-ui-color-palette'
|
|
104
|
+
|
|
105
|
+
// Create a color instance
|
|
106
|
+
const color = new Color({
|
|
107
|
+
sourceColor: [255, 0, 0], // Red in RGB
|
|
108
|
+
lightness: 50,
|
|
109
|
+
chromaShifting: 100,
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
// Convert to different color spaces
|
|
113
|
+
const lchColor = color.lch() // Returns LCH color
|
|
114
|
+
const oklchColor = color.oklch() // Returns OKLCH color
|
|
115
|
+
const hslColor = color.hsl() // Returns HSL color
|
|
116
|
+
const labColor = color.lab() // Returns LAB color
|
|
117
|
+
|
|
118
|
+
// Mix colors
|
|
119
|
+
const mixedRgb = color.mixColorsRgb(
|
|
120
|
+
[255, 0, 0, 0.5], // Semi-transparent red
|
|
121
|
+
[0, 0, 255, 1] // Solid blue
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
const mixedHex = color.mixColorsHex('#FF0000', '#0000FF')
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Contrast Calculations
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { Contrast } from '@yelbolt/engine-ui-color-palette'
|
|
131
|
+
|
|
132
|
+
// Create a contrast checker instance
|
|
133
|
+
const contrast = new Contrast({
|
|
134
|
+
backgroundColor: [255, 255, 255], // White background
|
|
135
|
+
textColor: '#000000', // Black text
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
// Get contrast values
|
|
139
|
+
const wcagContrast = contrast.getWCAGContrast() // WCAG 2.1 contrast ratio
|
|
140
|
+
const apcaContrast = contrast.getAPCAContrast() // APCA contrast value
|
|
141
|
+
const wcagScore = contrast.getWCAGScore() // Returns: 'AAA', 'AA', or 'A'
|
|
142
|
+
|
|
143
|
+
// Get accessibility recommendations
|
|
144
|
+
const usage = contrast.getRecommendedUsage() // Returns usage recommendation
|
|
145
|
+
const minSizes = contrast.getMinFontSizes() // Returns minimum font sizes
|
|
146
|
+
|
|
147
|
+
// Find specific contrast values
|
|
148
|
+
const lightness = contrast.getLightnessForContrastRatio(4.5) // For WCAG AA
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Dominant Colors Extraction
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
import { DominantColors } from '@yelbolt/engine-ui-color-palette'
|
|
155
|
+
|
|
156
|
+
// Prepare your image data (from canvas, file, etc.)
|
|
157
|
+
const canvas = document.createElement('canvas')
|
|
158
|
+
const ctx = canvas.getContext('2d')
|
|
159
|
+
// ... load your image into the canvas
|
|
160
|
+
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height)
|
|
161
|
+
|
|
162
|
+
// Create a dominant colors extractor
|
|
163
|
+
const dominantColors = new DominantColors({
|
|
164
|
+
imageData: imageData,
|
|
165
|
+
colorCount: 5, // Extract top 5 colors
|
|
166
|
+
maxIterations: 50, // K-means algorithm iterations
|
|
167
|
+
tolerance: 0.01, // Convergence tolerance
|
|
168
|
+
skipTransparent: true, // Skip transparent pixels
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
// Extract the dominant colors
|
|
172
|
+
const colors = dominantColors.extractDominantColors()
|
|
173
|
+
|
|
174
|
+
// Results array contains:
|
|
175
|
+
colors.forEach((result) => {
|
|
176
|
+
console.log({
|
|
177
|
+
color: result.color, // RGB array: [r, g, b]
|
|
178
|
+
hex: result.hex, // Hex string: "#ff0000"
|
|
179
|
+
percentage: result.percentage, // Percentage of image: 25.5
|
|
180
|
+
count: result.count, // Number of pixels: 1000
|
|
181
|
+
})
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
// Update settings dynamically
|
|
185
|
+
dominantColors.setColorCount(8) // Change to 8 colors
|
|
186
|
+
dominantColors.updateOptions({
|
|
187
|
+
maxIterations: 100,
|
|
188
|
+
tolerance: 0.005,
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
// Get current configuration
|
|
192
|
+
const options = dominantColors.getOptions()
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
#### Working with File Uploads (ArrayBuffer)
|
|
196
|
+
|
|
197
|
+
For modern web applications that need to extract colors from uploaded image files:
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
import { DominantColors } from '@yelbolt/engine-ui-color-palette'
|
|
201
|
+
|
|
202
|
+
// Handle file upload from user input
|
|
203
|
+
const handleImageUpload = async (event: Event) => {
|
|
204
|
+
const file = (event.target as HTMLInputElement).files?.[0]
|
|
205
|
+
if (!file) return
|
|
206
|
+
|
|
207
|
+
// Convert file to ArrayBuffer
|
|
208
|
+
const arrayBuffer = await file.arrayBuffer()
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
// Simple usage: extract 5 dominant colors
|
|
212
|
+
const colors = await DominantColors.extract(arrayBuffer, 5)
|
|
213
|
+
|
|
214
|
+
console.log('Extracted colors:', colors)
|
|
215
|
+
// Each color object contains: { color, hex, percentage, count }
|
|
216
|
+
} catch (error) {
|
|
217
|
+
console.error('Error extracting colors:', error)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Advanced usage with custom options
|
|
222
|
+
const extractColorsAdvanced = async (arrayBuffer: ArrayBuffer) => {
|
|
223
|
+
const colors = await DominantColors.fromArrayBuffer(arrayBuffer, {
|
|
224
|
+
colorCount: 8,
|
|
225
|
+
maxIterations: 100,
|
|
226
|
+
tolerance: 0.005,
|
|
227
|
+
skipTransparent: true,
|
|
228
|
+
maxImageSize: 300, // Resize large images for faster processing
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
return colors
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// HTML file input example
|
|
235
|
+
// <input type="file" accept="image/*" onChange={handleImageUpload} />
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**Note**: ArrayBuffer extraction requires a browser environment with Canvas API support.
|
|
239
|
+
|
|
240
|
+
### Color Harmony Generation
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
import { ColorHarmony } from '@yelbolt/engine-ui-color-palette'
|
|
244
|
+
|
|
245
|
+
// Create a color harmony generator
|
|
246
|
+
const colorHarmony = new ColorHarmony({
|
|
247
|
+
baseColor: [255, 0, 0], // Red base color
|
|
248
|
+
analogousSpread: 30, // 30 degrees for analogous colors
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
// Generate specific harmony types
|
|
252
|
+
const analogous = colorHarmony.generateAnalogous()
|
|
253
|
+
const complementary = colorHarmony.generateComplementary()
|
|
254
|
+
const triadic = colorHarmony.generateTriadic()
|
|
255
|
+
const tetradic = colorHarmony.generateTetradic()
|
|
256
|
+
const square = colorHarmony.generateSquare()
|
|
257
|
+
const compound = colorHarmony.generateCompound()
|
|
258
|
+
|
|
259
|
+
// Generate harmony by type
|
|
260
|
+
const harmony = colorHarmony.generateHarmony('TRIADIC')
|
|
261
|
+
|
|
262
|
+
// Generate all harmonies at once (now includes 6 harmonies)
|
|
263
|
+
const allHarmonies = colorHarmony.getAllHarmonies()
|
|
264
|
+
|
|
265
|
+
// Results contain both RGB and hex values
|
|
266
|
+
console.log(triadic.colors) // [[255, 0, 0], [0, 255, 0], [0, 0, 255]]
|
|
267
|
+
console.log(triadic.hexColors) // ['#ff0000', '#00ff00', '#0000ff']
|
|
268
|
+
|
|
269
|
+
// Update settings
|
|
270
|
+
colorHarmony.setBaseColor([0, 128, 255])
|
|
271
|
+
colorHarmony.setAnalogousSpread(45)
|
|
272
|
+
colorHarmony.updateOptions({
|
|
273
|
+
analogousSpread: 60,
|
|
274
|
+
returnFormat: 'hex',
|
|
275
|
+
})
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Palette Generation
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
import { Data } from '@yelbolt/engine-ui-color-palette'
|
|
282
|
+
|
|
283
|
+
// Configure your palette
|
|
284
|
+
const config = {
|
|
285
|
+
base: {
|
|
286
|
+
name: 'My Palette',
|
|
287
|
+
colors: [
|
|
288
|
+
/* your colors */
|
|
289
|
+
],
|
|
290
|
+
colorSpace: 'LAB',
|
|
291
|
+
algorithmVersion: 'v3',
|
|
292
|
+
},
|
|
293
|
+
themes: [
|
|
294
|
+
{
|
|
295
|
+
id: 'light',
|
|
296
|
+
name: 'Light Theme',
|
|
297
|
+
scale: {
|
|
298
|
+
/* lightness values */
|
|
299
|
+
},
|
|
300
|
+
visionSimulationMode: 'NONE',
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
meta: {
|
|
304
|
+
/* metadata */
|
|
305
|
+
},
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Create a data instance
|
|
309
|
+
const data = new Data(config)
|
|
310
|
+
|
|
311
|
+
// Generate palette data
|
|
312
|
+
const paletteData = data.makePaletteData()
|
|
313
|
+
const fullData = data.makePaletteFullData()
|
|
314
|
+
|
|
315
|
+
// Access pre-computed text contrast scores
|
|
316
|
+
paletteData.themes[0].colors[0].shades.forEach((shade) => {
|
|
317
|
+
if (shade.textContrast) {
|
|
318
|
+
// WCAG scores for light/dark text on this shade
|
|
319
|
+
console.log(shade.textContrast.wcag.light) // { ratio: 4.5, score: 'AA' }
|
|
320
|
+
console.log(shade.textContrast.wcag.dark) // { ratio: 12.6, score: 'AAA' }
|
|
321
|
+
|
|
322
|
+
// APCA scores for light/dark text on this shade
|
|
323
|
+
console.log(shade.textContrast.apca.light) // { lc: -60.2, recommendedUsage: 'BODY_TEXT' }
|
|
324
|
+
console.log(shade.textContrast.apca.dark) // { lc: 85.1, recommendedUsage: 'FLUENT_TEXT' }
|
|
325
|
+
}
|
|
326
|
+
})
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### Color System & Semantic Tokens
|
|
330
|
+
|
|
331
|
+
```typescript
|
|
332
|
+
import { System, Code } from '@yelbolt/engine-ui-color-palette'
|
|
333
|
+
|
|
334
|
+
// Define a taxonomy schema (groups of semantic dimensions)
|
|
335
|
+
const system = new System({
|
|
336
|
+
paletteData,
|
|
337
|
+
system: {
|
|
338
|
+
schema: {
|
|
339
|
+
groups: [
|
|
340
|
+
{
|
|
341
|
+
id: 'role',
|
|
342
|
+
name: 'Role',
|
|
343
|
+
members: [
|
|
344
|
+
{ id: 'brand', name: 'Brand' },
|
|
345
|
+
{ id: 'neutral', name: 'Neutral' },
|
|
346
|
+
],
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
id: 'prominence',
|
|
350
|
+
name: 'Prominence',
|
|
351
|
+
members: [
|
|
352
|
+
{ id: 'default', name: 'Default' },
|
|
353
|
+
{ id: 'subtle', name: 'Subtle' },
|
|
354
|
+
],
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
},
|
|
358
|
+
bindings: [
|
|
359
|
+
{
|
|
360
|
+
path: ['brand', 'default'],
|
|
361
|
+
description: 'Primary brand color',
|
|
362
|
+
ref: 'blue:500',
|
|
363
|
+
overrides: { dark: 'blue:400' }, // per-theme override
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
path: ['neutral', 'subtle'],
|
|
367
|
+
ref: 'gray:200',
|
|
368
|
+
isExcluded: true, // skip this token in code generation
|
|
369
|
+
},
|
|
370
|
+
],
|
|
371
|
+
},
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
// Resolve the system data (tokens + refs)
|
|
375
|
+
const systemData = system.makeSystemData()
|
|
376
|
+
|
|
377
|
+
// Generate semantic token files alongside primitives
|
|
378
|
+
const code = new Code({ paletteData, systemData })
|
|
379
|
+
const files = code.makeCssFiles()
|
|
380
|
+
// files[0].content includes both --color-blue-500 primitives
|
|
381
|
+
// and --brand-default / --neutral-default semantic custom properties
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
## Testing
|
|
385
|
+
|
|
386
|
+
```bash
|
|
387
|
+
npm test
|
|
388
|
+
# or
|
|
389
|
+
yarn test
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## Code Coverage
|
|
393
|
+
|
|
394
|
+
Current test coverage results:
|
|
395
|
+
|
|
396
|
+
| File | % Stmts | % Branch | % Funcs | % Lines |
|
|
397
|
+
| --------------- | --------- | --------- | --------- | --------- |
|
|
398
|
+
| **All files** | **91.61** | **87.27** | **91.59** | **91.61** |
|
|
399
|
+
| code | 100 | 100 | 100 | 100 |
|
|
400
|
+
| color | 93.54 | 77.51 | 83.33 | 93.54 |
|
|
401
|
+
| color-harmony | 100 | 96.66 | 100 | 100 |
|
|
402
|
+
| contrast | 89 | 93.33 | 100 | 89 |
|
|
403
|
+
| data | 93.48 | 89.74 | 100 | 93.48 |
|
|
404
|
+
| dominant-colors | 77.58 | 89.06 | 90.47 | 77.58 |
|
|
405
|
+
|
|
406
|
+
To run coverage tests:
|
|
407
|
+
|
|
408
|
+
```bash
|
|
409
|
+
npm run test:coverage
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## Credits
|
|
413
|
+
|
|
414
|
+
This project relies on several excellent open source packages:
|
|
415
|
+
|
|
416
|
+
### Color Processing
|
|
417
|
+
|
|
418
|
+
- [chroma.js](https://gka.github.io/chroma.js/) - A powerful library for color manipulations and conversions
|
|
419
|
+
- Author: Gregor Aisch
|
|
420
|
+
- License: BSD-3-Clause
|
|
421
|
+
|
|
422
|
+
### Contrast Calculation
|
|
423
|
+
|
|
424
|
+
- [APCA-W3](https://github.com/Myndex/SAPC-APCA) - Advanced Perceptual Contrast Algorithm
|
|
425
|
+
- Author: Andrew Somers
|
|
426
|
+
- License: W3C Software and Document Notice and License
|
|
427
|
+
|
|
428
|
+
## License
|
|
429
|
+
|
|
430
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.
|