@designtools/tokens 0.1.5 → 0.1.7

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/dist/index.d.ts CHANGED
@@ -169,6 +169,17 @@ interface GenerationOptions {
169
169
  contrastAlgorithm: ContrastAlgorithm;
170
170
  contrastTarget: ContrastTarget;
171
171
  lightnessStrategy: LightnessStrategy;
172
+ /**
173
+ * Which step the seed colour lands on. Default: 500.
174
+ * Brand colours arrive as whatever they are — deep navies and pale tints are
175
+ * common — and forcing them all onto 500 wrecks the ramp either side.
176
+ */
177
+ seedShade?: ShadeNumber;
178
+ /**
179
+ * Which steps to emit. Default: all twelve (25–950).
180
+ * Tokens naming a dropped step are snapped to the nearest emitted one.
181
+ */
182
+ shades?: ShadeNumber[];
172
183
  shadeOverrides: SemanticShadeOverrides;
173
184
  surfaceShadeOverrides?: {
174
185
  light?: Partial<SurfaceShadeOverrides>;
@@ -196,6 +207,8 @@ type CVDType = "none" | "protanopia" | "deuteranopia" | "tritanopia";
196
207
  interface SavedConfig {
197
208
  primaryColor: string;
198
209
  neutralColor: string;
210
+ seedShade?: ShadeNumber;
211
+ shades?: ShadeNumber[];
199
212
  additionalColors: {
200
213
  name: string;
201
214
  color: string;
@@ -219,6 +232,86 @@ interface SavedConfig {
219
232
  */
220
233
  declare function generateTokens(brandColors: BrandColors, options?: Partial<GenerationOptions>): TokenSystem;
221
234
 
235
+ /**
236
+ * OKLCH color utilities using culori
237
+ * OKLCH provides perceptually uniform color manipulation
238
+ */
239
+
240
+ /**
241
+ * Convert any color format to OKLCH
242
+ */
243
+ declare function parseToOklch(color: string): Oklch;
244
+ /**
245
+ * Convert OKLCH to hex
246
+ */
247
+ declare function oklchToHex(color: Oklch): string;
248
+ /** Per-shade options shared by both lightness strategies */
249
+ interface ScaleOptions {
250
+ /** Which step the input colour lands on. Default: 500 */
251
+ seedShade?: ShadeNumber;
252
+ /** Which steps to emit. Default: all twelve */
253
+ shades?: readonly ShadeNumber[];
254
+ }
255
+ declare function generateColorScale(baseColor: string, options?: ScaleOptions): ColorScale;
256
+ declare function generateColorScaleAPCA(baseColor: string, options?: ScaleOptions): ColorScale;
257
+ /**
258
+ * Adjust the lightness of a color
259
+ */
260
+ declare function adjustLightness(color: string, lightness: number): string;
261
+ /**
262
+ * Adjust the chroma (saturation) of a color
263
+ */
264
+ declare function adjustChroma(color: string, chroma: number): string;
265
+ /**
266
+ * Get the relative luminance of a color (for contrast calculations)
267
+ * Using WCAG formula
268
+ */
269
+ declare function getRelativeLuminance(color: string): number;
270
+ /**
271
+ * Calculate contrast ratio between two colors (WCAG formula)
272
+ */
273
+ declare function getContrastRatio(color1: string, color2: string): number;
274
+ /**
275
+ * Check if contrast ratio meets WCAG AA standard
276
+ */
277
+ declare function meetsWCAG_AA(ratio: number, isLargeText?: boolean): boolean;
278
+ /**
279
+ * Check if contrast ratio meets WCAG AAA standard
280
+ */
281
+ declare function meetsWCAG_AAA(ratio: number, isLargeText?: boolean): boolean;
282
+ /**
283
+ * Calculate APCA contrast (Lc value) between foreground and background.
284
+ * Returns the absolute Lc value.
285
+ */
286
+ declare function getAPCAContrast(foreground: string, background: string): number;
287
+ /**
288
+ * Find contrasting color using APCA algorithm.
289
+ * Targets Lc >= 60 for body text readability.
290
+ */
291
+ declare function findContrastingColorAPCA(background: string, lightColor: string, darkColor: string): string;
292
+ /**
293
+ * Simulate how a colour appears under a given colour vision deficiency.
294
+ * Returns the original colour string if cvd is "none".
295
+ */
296
+ declare function simulateCVD(color: string, cvd: CVDType): string;
297
+ /**
298
+ * Classify an APCA Lc value into a readability level.
299
+ */
300
+ declare function classifyAPCALevel(lcValue: number): APCAContrastResult["level"];
301
+ /**
302
+ * Format a color value as a short string (no function wrapper).
303
+ * e.g. "54.32% 0.1827 264.05" instead of "oklch(54.32% 0.1827 264.05)"
304
+ */
305
+ declare function formatColorShort(color: string, format: ColorFormat): string;
306
+ /**
307
+ * Get OKLCH values as a readable string
308
+ */
309
+ declare function getOklchString(color: string): string;
310
+ /**
311
+ * Convert a color to the specified format
312
+ */
313
+ declare function formatColorAs(color: string, format: ColorFormat): string;
314
+
222
315
  /**
223
316
  * Primitive color palette generation using OKLCH
224
317
  */
@@ -237,7 +330,7 @@ declare const DEFAULT_NEUTRAL_COLOR = "#747474";
237
330
  * Requires primary and neutral - other semantic colors are derived from primary
238
331
  * Additional colors can be provided to generate custom scales
239
332
  */
240
- declare function generatePrimitivePalette(brandColors: BrandColors, lightnessStrategy?: LightnessStrategy): PrimitivePalette;
333
+ declare function generatePrimitivePalette(brandColors: BrandColors, lightnessStrategy?: LightnessStrategy, scaleOptions?: ScaleOptions): PrimitivePalette;
241
334
  /**
242
335
  * Get a specific shade from a color scale
243
336
  */
@@ -256,11 +349,11 @@ declare function generateSemanticTokens(palette: PrimitivePalette, mode: "light"
256
349
  /**
257
350
  * Generate surface tokens (canvas / surface / overlay depth system) from neutral palette
258
351
  */
259
- declare function generateSurfaceTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<SurfaceShadeOverrides>): SurfaceTokens;
352
+ declare function generateSurfaceTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<SurfaceShadeOverrides>, shades?: readonly ShadeNumber[]): SurfaceTokens;
260
353
  /**
261
354
  * Generate utility tokens for borders, rings, inputs, shadow
262
355
  */
263
- declare function generateUtilityTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<UtilityShadeOverrides>): UtilityTokens;
356
+ declare function generateUtilityTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<UtilityShadeOverrides>, shades?: readonly ShadeNumber[]): UtilityTokens;
264
357
  /**
265
358
  * Check contrast compliance for all semantic colors
266
359
  */
@@ -292,11 +385,29 @@ declare function computeAccessibilityScore(tokens: SemanticTokens, algorithm: Co
292
385
  /**
293
386
  * Export tokens as CSS custom properties
294
387
  */
295
- declare function exportToCss(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, compat?: boolean): string;
388
+ declare function exportToCss(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, sections?: TokenSection[], shades?: readonly ShadeNumber[]): string;
389
+ /**
390
+ * Emittable slices of the token system.
391
+ *
392
+ * `ramp` is the twelve-step colour ramps alone; `primitives` is those plus
393
+ * black and white. The two are separated because "hand me a colour, hand me
394
+ * back scales" is a different job from "emit the primitive layer of a system".
395
+ *
396
+ * Note there is no non-colour section: the TokenSystem carries spacing, type,
397
+ * radii and shadow defaults, but they are not yet serialised to CSS.
398
+ */
399
+ declare const TOKEN_SECTIONS: readonly ["primitives", "ramp", "semantic", "surface", "utility"];
400
+ type TokenSection = (typeof TOKEN_SECTIONS)[number];
296
401
  /**
297
- * Export tokens as Tailwind v4 CSS
402
+ * Export tokens as Tailwind v4 CSS.
403
+ *
404
+ * Primitives carry real values directly in the theme block: they are
405
+ * mode-invariant, and this keeps their names identical to the plain-CSS export
406
+ * so the two formats stay interchangeable. Semantics vary by mode, and @theme
407
+ * emits once to :root and cannot vary by selector, so they are var()
408
+ * indirections registered in @theme and re-bound in each mode block.
298
409
  */
299
- declare function exportToTailwindV4(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, compat?: boolean): string;
410
+ declare function exportToTailwindV4(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, replacePalette?: boolean, sections?: TokenSection[], shades?: readonly ShadeNumber[]): string;
300
411
  /**
301
412
  * Export tokens as Tailwind v3 config
302
413
  */
@@ -306,134 +417,31 @@ declare function exportToTailwindV3(tokens: TokenSystem, colorFormat?: ColorForm
306
417
  * @see https://tr.designtokens.org/format/
307
418
  */
308
419
  declare function exportToDtcg(tokens: TokenSystem): string;
309
- /**
310
- * Export tokens as a Lovable-compatible theme (shadcn/ui globals.css)
311
- * Lovable uses standard shadcn/ui + Tailwind v4 theming via CSS custom properties
312
- */
313
- declare function exportToLovable(tokens: TokenSystem, colorFormat?: ColorFormat): string;
314
- type ExportFormat = "css" | "tailwind-v3" | "tailwind-v4" | "dtcg" | "lovable";
420
+ type ExportFormat = "css" | "tailwind-v3" | "tailwind-v4" | "dtcg";
315
421
  /** Options for token export */
316
422
  interface ExportOptions {
317
423
  colorFormat?: ColorFormat;
318
424
  shadeOverrides?: SemanticShadeOverrides;
319
425
  /**
320
- * Include shadcn/ui compatibility aliases (--background, --card, --secondary,
321
- * --sidebar-*) in css and tailwind-v4 exports. Set false for vanilla-CSS
322
- * projects that only want the native token names. Default: true.
426
+ * Clear Tailwind's stock colour palette in the tailwind-v4 export, so any
427
+ * colour class the generator does not define fails to compile rather than
428
+ * compiling off-brand. Default: false.
323
429
  */
324
- compat?: boolean;
430
+ replacePalette?: boolean;
431
+ /**
432
+ * Restrict output to these slices of the token system. Omit for everything.
433
+ * Only the CSS-shaped formats can honour this; see SECTIONED_FORMATS.
434
+ */
435
+ sections?: TokenSection[];
436
+ /**
437
+ * Which ramp steps the token system was generated with. Shade references are
438
+ * snapped onto this set, so a dropped step never leaves a dangling var().
439
+ */
440
+ shades?: readonly ShadeNumber[];
325
441
  }
326
442
  /**
327
443
  * Export tokens in the specified format
328
444
  */
329
445
  declare function exportTokens(tokens: TokenSystem, format: ExportFormat, options?: ExportOptions): string;
330
446
 
331
- /**
332
- * OKLCH color utilities using culori
333
- * OKLCH provides perceptually uniform color manipulation
334
- */
335
-
336
- /**
337
- * Convert any color format to OKLCH
338
- */
339
- declare function parseToOklch(color: string): Oklch;
340
- /**
341
- * Convert OKLCH to hex
342
- */
343
- declare function oklchToHex(color: Oklch): string;
344
- /**
345
- * Generate a color scale from a base color using OKLCH
346
- * Creates 12 shades (25,50,100,200,...,900,950) with perceptually uniform lightness
347
- * Shade 500 exactly matches the baseColor
348
- *
349
- * Algorithm inspired by Radix Colors methodology:
350
- *
351
- * Lightness Distribution:
352
- * - Uses easing curves for smooth perceptual transitions
353
- * - Light shades (25-400): Gradual steps optimized for UI backgrounds and subtle states
354
- * - Dark shades (600-950): Larger jumps for text contrast and accessibility
355
- * - Adaptive scaling based on available headroom above/below base color
356
- *
357
- * Chroma Distribution:
358
- * - Progressive easing from desaturated light tints (8% at shade 25)
359
- * - Smooth transitions through mid-range (reaching 100% by shade 400)
360
- * - Peak chroma maintained through interactive range (shades 400-900)
361
- * - Minimal reduction only at darkest shade (950)
362
- *
363
- * Hue:
364
- * - Constant throughout entire scale (no Bezold-Brücke shift)
365
- * - Ensures brand color consistency across all shades
366
- */
367
- declare function generateColorScale(baseColor: string): ColorScale;
368
- /**
369
- * Adjust the lightness of a color
370
- */
371
- declare function adjustLightness(color: string, lightness: number): string;
372
- /**
373
- * Adjust the chroma (saturation) of a color
374
- */
375
- declare function adjustChroma(color: string, chroma: number): string;
376
- /**
377
- * Get the relative luminance of a color (for contrast calculations)
378
- * Using WCAG formula
379
- */
380
- declare function getRelativeLuminance(color: string): number;
381
- /**
382
- * Calculate contrast ratio between two colors (WCAG formula)
383
- */
384
- declare function getContrastRatio(color1: string, color2: string): number;
385
- /**
386
- * Check if contrast ratio meets WCAG AA standard
387
- */
388
- declare function meetsWCAG_AA(ratio: number, isLargeText?: boolean): boolean;
389
- /**
390
- * Check if contrast ratio meets WCAG AAA standard
391
- */
392
- declare function meetsWCAG_AAA(ratio: number, isLargeText?: boolean): boolean;
393
- /**
394
- * Calculate APCA contrast (Lc value) between foreground and background.
395
- * Returns the absolute Lc value.
396
- */
397
- declare function getAPCAContrast(foreground: string, background: string): number;
398
- /**
399
- * Find contrasting color using APCA algorithm.
400
- * Targets Lc >= 60 for body text readability.
401
- */
402
- declare function findContrastingColorAPCA(background: string, lightColor: string, darkColor: string): string;
403
- /**
404
- * Simulate how a colour appears under a given colour vision deficiency.
405
- * Returns the original colour string if cvd is "none".
406
- */
407
- declare function simulateCVD(color: string, cvd: CVDType): string;
408
- /**
409
- * Classify an APCA Lc value into a readability level.
410
- */
411
- declare function classifyAPCALevel(lcValue: number): APCAContrastResult["level"];
412
- /**
413
- * Generate a color scale using APCA-informed perceptual lightness distribution.
414
- * Uses the same headroom approach as generateColorScale but with spacing ratios
415
- * tuned to produce more perceptually even contrast steps under APCA.
416
- *
417
- * Key differences from "fixed":
418
- * - Light shades (25-400) use tighter spacing to create smoother transitions
419
- * where APCA perceives larger contrast differences
420
- * - Dark shades (600-950) use wider spacing since APCA is more forgiving
421
- * in the dark range
422
- * - Chroma preserved more aggressively in light shades to avoid grayness
423
- */
424
- declare function generateColorScaleAPCA(baseColor: string): ColorScale;
425
- /**
426
- * Format a color value as a short string (no function wrapper).
427
- * e.g. "54.32% 0.1827 264.05" instead of "oklch(54.32% 0.1827 264.05)"
428
- */
429
- declare function formatColorShort(color: string, format: ColorFormat): string;
430
- /**
431
- * Get OKLCH values as a readable string
432
- */
433
- declare function getOklchString(color: string): string;
434
- /**
435
- * Convert a color to the specified format
436
- */
437
- declare function formatColorAs(color: string, format: ColorFormat): string;
438
-
439
- export { type APCAContrastResult, type BrandColors, type CVDType, type ColorFormat, type ColorScale, type ContrastAlgorithm, type ContrastTarget, DEFAULT_NEUTRAL_COLOR, type ExportFormat, type ExportOptions, type ExtendedSemanticColor, type ForegroundRef, type GenerationOptions, type LightnessStrategy, type PrimitivePalette, type SavedConfig, type SemanticColorPair, type SemanticShadeOverrides, type SemanticTokens, type ShadeNumber, type SurfaceRef, type SurfaceShadeOverrides, type SurfaceTokens, type TokenSystem, type UtilityShadeOverrides, type UtilityTokens, VALID_SHADES, type VariantShadeOverrides, type WCAGContrastResult, adjustChroma, adjustLightness, checkSemanticContrast, checkSemanticContrastAPCA, classifyAPCALevel, computeAccessibilityScore, exportToCss, exportToDtcg, exportToLovable, exportToTailwindV3, exportToTailwindV4, exportTokens, findContrastingColorAPCA, formatColorAs, formatColorShort, generateColorScale, generateColorScaleAPCA, generatePrimitivePalette, generateSemanticTokens, generateSurfaceTokens, generateTokens, generateUtilityTokens, getAPCAContrast, getContrastRatio, getOklchString, getRelativeLuminance, getShade, meetsWCAG_AA, meetsWCAG_AAA, oklchToHex, parseToOklch, simulateCVD };
447
+ export { type APCAContrastResult, type BrandColors, type CVDType, type ColorFormat, type ColorScale, type ContrastAlgorithm, type ContrastTarget, DEFAULT_NEUTRAL_COLOR, type ExportFormat, type ExportOptions, type ExtendedSemanticColor, type ForegroundRef, type GenerationOptions, type LightnessStrategy, type PrimitivePalette, type SavedConfig, type SemanticColorPair, type SemanticShadeOverrides, type SemanticTokens, type ShadeNumber, type SurfaceRef, type SurfaceShadeOverrides, type SurfaceTokens, type TokenSystem, type UtilityShadeOverrides, type UtilityTokens, VALID_SHADES, type VariantShadeOverrides, type WCAGContrastResult, adjustChroma, adjustLightness, checkSemanticContrast, checkSemanticContrastAPCA, classifyAPCALevel, computeAccessibilityScore, exportToCss, exportToDtcg, exportToTailwindV3, exportToTailwindV4, exportTokens, findContrastingColorAPCA, formatColorAs, formatColorShort, generateColorScale, generateColorScaleAPCA, generatePrimitivePalette, generateSemanticTokens, generateSurfaceTokens, generateTokens, generateUtilityTokens, getAPCAContrast, getContrastRatio, getOklchString, getRelativeLuminance, getShade, meetsWCAG_AA, meetsWCAG_AAA, oklchToHex, parseToOklch, simulateCVD };
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  DEFAULT_NEUTRAL_COLOR,
3
+ VALID_SHADES,
3
4
  adjustChroma,
4
5
  adjustLightness,
5
6
  checkSemanticContrast,
@@ -8,7 +9,6 @@ import {
8
9
  computeAccessibilityScore,
9
10
  exportToCss,
10
11
  exportToDtcg,
11
- exportToLovable,
12
12
  exportToTailwindV3,
13
13
  exportToTailwindV4,
14
14
  exportTokens,
@@ -32,10 +32,7 @@ import {
32
32
  oklchToHex,
33
33
  parseToOklch,
34
34
  simulateCVD
35
- } from "./chunk-G6P25B5W.js";
36
-
37
- // src/types.ts
38
- var VALID_SHADES = [25, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
35
+ } from "./chunk-T62MMGGQ.js";
39
36
  export {
40
37
  DEFAULT_NEUTRAL_COLOR,
41
38
  VALID_SHADES,
@@ -47,7 +44,6 @@ export {
47
44
  computeAccessibilityScore,
48
45
  exportToCss,
49
46
  exportToDtcg,
50
- exportToLovable,
51
47
  exportToTailwindV3,
52
48
  exportToTailwindV4,
53
49
  exportTokens,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@designtools/tokens",
3
- "version": "0.1.5",
4
- "description": "Headless colour token generation from brand colours: OKLCH primitive scales, contrast-checked semantic intents, light/dark modes, and serialisers for CSS custom properties (lead), Tailwind v3/v4, DTCG, and Lovable. Pure TypeScript, deterministic.",
3
+ "version": "0.1.7",
4
+ "description": "Headless colour token generation from brand colours: OKLCH primitive scales, contrast-checked semantic intents, light/dark modes, and serialisers for CSS custom properties (lead), Tailwind v4 (@theme static) and v3, and DTCG. Pure TypeScript, deterministic.",
5
5
  "type": "module",
6
6
  "license": "CC-BY-NC-4.0",
7
7
  "repository": {