@designtools/tokens 0.1.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/README.md +57 -0
- package/dist/chunk-G6P25B5W.js +1500 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +173 -0
- package/dist/index.d.ts +439 -0
- package/dist/index.js +74 -0
- package/package.json +46 -0
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_NEUTRAL_COLOR,
|
|
4
|
+
exportTokens,
|
|
5
|
+
generateTokens,
|
|
6
|
+
parseToOklch
|
|
7
|
+
} from "./chunk-G6P25B5W.js";
|
|
8
|
+
|
|
9
|
+
// src/cli.ts
|
|
10
|
+
import { parseArgs } from "util";
|
|
11
|
+
import { mkdirSync, writeFileSync, readFileSync, statSync } from "fs";
|
|
12
|
+
import { join } from "path";
|
|
13
|
+
var HELP = `generate-tokens \u2014 brand colour in, design tokens out
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
generate-tokens --primary <colour> [options]
|
|
17
|
+
|
|
18
|
+
Seeds:
|
|
19
|
+
--primary <colour> Brand colour (hex, rgb(), hsl(), oklch(), named). Required.
|
|
20
|
+
--neutral <colour> Neutral seed. Default: ${DEFAULT_NEUTRAL_COLOR}
|
|
21
|
+
--color <name>=<colour> Additional brand colour scale. Repeatable.
|
|
22
|
+
|
|
23
|
+
Generation options:
|
|
24
|
+
--contrast <wcag|apca> Contrast algorithm for foreground selection. Default: wcag
|
|
25
|
+
--target <aa-large|aa|aaa> Contrast target level. Default: aa
|
|
26
|
+
--lightness <fixed|perceptual> Lightness distribution strategy. Default: fixed
|
|
27
|
+
--overrides <file.json> JSON file with { shadeOverrides, surfaceShadeOverrides,
|
|
28
|
+
utilityShadeOverrides } (same shape as the web tool).
|
|
29
|
+
|
|
30
|
+
Output:
|
|
31
|
+
--format <fmt> css | tailwind-v4 | tailwind-v3 | dtcg | lovable | json | all
|
|
32
|
+
Default: css (CSS custom properties, the lead format)
|
|
33
|
+
--color-format <fmt> oklch | hex | rgb | hsl \u2014 how literal colour values are printed.
|
|
34
|
+
Default: oklch
|
|
35
|
+
--out <path> File to write (or directory when --format all).
|
|
36
|
+
Omit to print to stdout.
|
|
37
|
+
--vanilla Omit the shadcn/ui compatibility aliases (--background,
|
|
38
|
+
--card, --secondary, --sidebar-*) from css and tailwind-v4.
|
|
39
|
+
Use for Base UI / vanilla-CSS projects. Default: aliases on.
|
|
40
|
+
--help Show this help.
|
|
41
|
+
`;
|
|
42
|
+
var FILE_NAMES = {
|
|
43
|
+
css: "tokens.css",
|
|
44
|
+
"tailwind-v4": "tailwind.css",
|
|
45
|
+
"tailwind-v3": "tailwind.config.js",
|
|
46
|
+
dtcg: "tokens.dtcg.json",
|
|
47
|
+
lovable: "lovable.css",
|
|
48
|
+
json: "tokens.json"
|
|
49
|
+
};
|
|
50
|
+
function fail(message) {
|
|
51
|
+
process.stderr.write(`generate-tokens: ${message}
|
|
52
|
+
`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
var values;
|
|
56
|
+
try {
|
|
57
|
+
({ values } = parseArgs({
|
|
58
|
+
options: {
|
|
59
|
+
primary: { type: "string" },
|
|
60
|
+
neutral: { type: "string" },
|
|
61
|
+
color: { type: "string", multiple: true },
|
|
62
|
+
contrast: { type: "string" },
|
|
63
|
+
target: { type: "string" },
|
|
64
|
+
lightness: { type: "string" },
|
|
65
|
+
overrides: { type: "string" },
|
|
66
|
+
format: { type: "string" },
|
|
67
|
+
"color-format": { type: "string" },
|
|
68
|
+
out: { type: "string" },
|
|
69
|
+
vanilla: { type: "boolean" },
|
|
70
|
+
help: { type: "boolean" }
|
|
71
|
+
}
|
|
72
|
+
}));
|
|
73
|
+
} catch (err) {
|
|
74
|
+
fail(err instanceof Error ? err.message : String(err));
|
|
75
|
+
}
|
|
76
|
+
if (values.help) {
|
|
77
|
+
process.stdout.write(HELP);
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}
|
|
80
|
+
if (!values.primary) fail("--primary is required (try --help)");
|
|
81
|
+
function validateChoice(name, value, choices, fallback) {
|
|
82
|
+
if (value === void 0) return fallback;
|
|
83
|
+
if (!choices.includes(value)) {
|
|
84
|
+
fail(`--${name} must be one of: ${choices.join(", ")} (got "${value}")`);
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
function validateColor(name, value) {
|
|
89
|
+
try {
|
|
90
|
+
parseToOklch(value);
|
|
91
|
+
} catch {
|
|
92
|
+
fail(`--${name} is not a parseable colour: "${value}"`);
|
|
93
|
+
}
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
var primary = validateColor("primary", values.primary);
|
|
97
|
+
var neutral = validateColor("neutral", values.neutral ?? DEFAULT_NEUTRAL_COLOR);
|
|
98
|
+
var additionalColors = {};
|
|
99
|
+
for (const entry of values.color ?? []) {
|
|
100
|
+
const eq = entry.indexOf("=");
|
|
101
|
+
if (eq === -1) fail(`--color expects name=colour (got "${entry}")`);
|
|
102
|
+
const name = entry.slice(0, eq).trim();
|
|
103
|
+
const colour = entry.slice(eq + 1).trim();
|
|
104
|
+
if (!/^[a-z][a-z0-9-]*$/i.test(name)) {
|
|
105
|
+
fail(`--color name must be alphanumeric/kebab-case (got "${name}")`);
|
|
106
|
+
}
|
|
107
|
+
additionalColors[name] = validateColor(`color ${name}`, colour);
|
|
108
|
+
}
|
|
109
|
+
var contrastAlgorithm = validateChoice("contrast", values.contrast, ["wcag", "apca"], "wcag");
|
|
110
|
+
var contrastTarget = validateChoice("target", values.target, ["aa-large", "aa", "aaa"], "aa");
|
|
111
|
+
var lightnessStrategy = validateChoice("lightness", values.lightness, ["fixed", "perceptual"], "fixed");
|
|
112
|
+
var format = validateChoice(
|
|
113
|
+
"format",
|
|
114
|
+
values.format,
|
|
115
|
+
["css", "tailwind-v4", "tailwind-v3", "dtcg", "lovable", "json", "all"],
|
|
116
|
+
"css"
|
|
117
|
+
);
|
|
118
|
+
var colorFormat = validateChoice("color-format", values["color-format"], ["oklch", "hex", "rgb", "hsl"], "oklch");
|
|
119
|
+
var overrides = {};
|
|
120
|
+
if (values.overrides) {
|
|
121
|
+
try {
|
|
122
|
+
overrides = JSON.parse(readFileSync(values.overrides, "utf8"));
|
|
123
|
+
} catch (err) {
|
|
124
|
+
fail(`could not read --overrides file: ${err instanceof Error ? err.message : String(err)}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
var brandColors = {
|
|
128
|
+
primary,
|
|
129
|
+
neutral,
|
|
130
|
+
...Object.keys(additionalColors).length > 0 ? { additionalColors } : {}
|
|
131
|
+
};
|
|
132
|
+
var options = {
|
|
133
|
+
contrastAlgorithm,
|
|
134
|
+
contrastTarget,
|
|
135
|
+
lightnessStrategy,
|
|
136
|
+
shadeOverrides: overrides.shadeOverrides ?? {},
|
|
137
|
+
surfaceShadeOverrides: overrides.surfaceShadeOverrides,
|
|
138
|
+
utilityShadeOverrides: overrides.utilityShadeOverrides
|
|
139
|
+
};
|
|
140
|
+
var tokens = generateTokens(brandColors, options);
|
|
141
|
+
var compat = !values.vanilla;
|
|
142
|
+
function serialise(fmt) {
|
|
143
|
+
if (fmt === "json") return JSON.stringify(tokens, null, 2);
|
|
144
|
+
return exportTokens(tokens, fmt, {
|
|
145
|
+
colorFormat,
|
|
146
|
+
shadeOverrides: options.shadeOverrides,
|
|
147
|
+
compat
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if (format === "all") {
|
|
151
|
+
const dir = values.out ?? ".";
|
|
152
|
+
mkdirSync(dir, { recursive: true });
|
|
153
|
+
for (const fmt of Object.keys(FILE_NAMES)) {
|
|
154
|
+
const target = join(dir, FILE_NAMES[fmt]);
|
|
155
|
+
writeFileSync(target, serialise(fmt) + "\n");
|
|
156
|
+
process.stderr.write(`wrote ${target}
|
|
157
|
+
`);
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
const output = serialise(format) + "\n";
|
|
161
|
+
if (values.out) {
|
|
162
|
+
let target = values.out;
|
|
163
|
+
try {
|
|
164
|
+
if (statSync(target).isDirectory()) target = join(target, FILE_NAMES[format]);
|
|
165
|
+
} catch {
|
|
166
|
+
}
|
|
167
|
+
writeFileSync(target, output);
|
|
168
|
+
process.stderr.write(`wrote ${target}
|
|
169
|
+
`);
|
|
170
|
+
} else {
|
|
171
|
+
process.stdout.write(output);
|
|
172
|
+
}
|
|
173
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import { Oklch } from 'culori';
|
|
2
|
+
|
|
3
|
+
interface BrandColors {
|
|
4
|
+
primary: string;
|
|
5
|
+
neutral: string;
|
|
6
|
+
additionalColors?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
interface ColorScale {
|
|
9
|
+
25: string;
|
|
10
|
+
50: string;
|
|
11
|
+
100: string;
|
|
12
|
+
200: string;
|
|
13
|
+
300: string;
|
|
14
|
+
400: string;
|
|
15
|
+
500: string;
|
|
16
|
+
600: string;
|
|
17
|
+
700: string;
|
|
18
|
+
800: string;
|
|
19
|
+
900: string;
|
|
20
|
+
950: string;
|
|
21
|
+
}
|
|
22
|
+
type ColorFormat = "oklch" | "rgb" | "hsl" | "hex";
|
|
23
|
+
interface SemanticTokens {
|
|
24
|
+
primary: ExtendedSemanticColor;
|
|
25
|
+
neutral: ExtendedSemanticColor;
|
|
26
|
+
success: ExtendedSemanticColor;
|
|
27
|
+
destructive: ExtendedSemanticColor;
|
|
28
|
+
warning: ExtendedSemanticColor;
|
|
29
|
+
muted: SemanticColorPair;
|
|
30
|
+
[key: string]: ExtendedSemanticColor | SemanticColorPair;
|
|
31
|
+
}
|
|
32
|
+
interface ExtendedSemanticColor {
|
|
33
|
+
DEFAULT: string;
|
|
34
|
+
foreground: string;
|
|
35
|
+
subdued: string;
|
|
36
|
+
"subdued-foreground": string;
|
|
37
|
+
highlight: string;
|
|
38
|
+
"highlight-foreground": string;
|
|
39
|
+
/** Primitive references for foreground values (used by export layer) */
|
|
40
|
+
_refs?: {
|
|
41
|
+
foreground: ForegroundRef;
|
|
42
|
+
"subdued-foreground": ForegroundRef;
|
|
43
|
+
"highlight-foreground": ForegroundRef;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
interface SemanticColorPair {
|
|
47
|
+
DEFAULT: string;
|
|
48
|
+
foreground: string;
|
|
49
|
+
}
|
|
50
|
+
/** Tracks which neutral primitive a surface value references */
|
|
51
|
+
type SurfaceRef = {
|
|
52
|
+
type: "shade";
|
|
53
|
+
shade: ShadeNumber;
|
|
54
|
+
} | {
|
|
55
|
+
type: "white";
|
|
56
|
+
} | {
|
|
57
|
+
type: "black";
|
|
58
|
+
};
|
|
59
|
+
interface SurfaceTokens {
|
|
60
|
+
canvas: string;
|
|
61
|
+
"canvas-foreground": string;
|
|
62
|
+
surface: string;
|
|
63
|
+
"surface-foreground": string;
|
|
64
|
+
overlay: string;
|
|
65
|
+
"overlay-foreground": string;
|
|
66
|
+
/** Primitive references for surface values (used by export layer) */
|
|
67
|
+
_refs?: {
|
|
68
|
+
canvas: SurfaceRef;
|
|
69
|
+
"canvas-foreground": SurfaceRef;
|
|
70
|
+
surface: SurfaceRef;
|
|
71
|
+
"surface-foreground": SurfaceRef;
|
|
72
|
+
overlay: SurfaceRef;
|
|
73
|
+
"overlay-foreground": SurfaceRef;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
interface UtilityTokens {
|
|
77
|
+
border: string;
|
|
78
|
+
ring: string;
|
|
79
|
+
input: string;
|
|
80
|
+
shadow: string;
|
|
81
|
+
}
|
|
82
|
+
interface TokenSystem {
|
|
83
|
+
primitives: {
|
|
84
|
+
black: string;
|
|
85
|
+
white: string;
|
|
86
|
+
[colorName: string]: ColorScale | string;
|
|
87
|
+
};
|
|
88
|
+
semantic: {
|
|
89
|
+
light: SemanticTokens;
|
|
90
|
+
dark: SemanticTokens;
|
|
91
|
+
};
|
|
92
|
+
surface: {
|
|
93
|
+
light: SurfaceTokens;
|
|
94
|
+
dark: SurfaceTokens;
|
|
95
|
+
};
|
|
96
|
+
utility: {
|
|
97
|
+
light: UtilityTokens;
|
|
98
|
+
dark: UtilityTokens;
|
|
99
|
+
};
|
|
100
|
+
spacing: Record<string, string>;
|
|
101
|
+
typography: {
|
|
102
|
+
fontSize: Record<string, string>;
|
|
103
|
+
fontWeight: Record<string, number>;
|
|
104
|
+
tracking: Record<string, string>;
|
|
105
|
+
leading: Record<string, number>;
|
|
106
|
+
};
|
|
107
|
+
radii: Record<string, string>;
|
|
108
|
+
borderWidth?: string;
|
|
109
|
+
shadows: {
|
|
110
|
+
light: Record<string, string>;
|
|
111
|
+
dark: Record<string, string>;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** Contrast algorithm choice */
|
|
115
|
+
type ContrastAlgorithm = "wcag" | "apca";
|
|
116
|
+
/** Contrast target level — controls minimum threshold for foreground selection */
|
|
117
|
+
type ContrastTarget = "aa-large" | "aa" | "aaa";
|
|
118
|
+
/** Lightness distribution strategy */
|
|
119
|
+
type LightnessStrategy = "fixed" | "perceptual";
|
|
120
|
+
/** Valid shade numbers in a ColorScale */
|
|
121
|
+
declare const VALID_SHADES: readonly [25, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
122
|
+
type ShadeNumber = (typeof VALID_SHADES)[number];
|
|
123
|
+
/** Tracks which primitive a foreground value references */
|
|
124
|
+
type ForegroundRef = {
|
|
125
|
+
type: "shade";
|
|
126
|
+
colorName: string;
|
|
127
|
+
shade: ShadeNumber;
|
|
128
|
+
} | {
|
|
129
|
+
type: "white";
|
|
130
|
+
} | {
|
|
131
|
+
type: "black";
|
|
132
|
+
};
|
|
133
|
+
/** Per-variant shade overrides: background shade + optional foreground ("on") shade */
|
|
134
|
+
interface VariantShadeOverrides {
|
|
135
|
+
DEFAULT?: ShadeNumber;
|
|
136
|
+
subdued?: ShadeNumber;
|
|
137
|
+
highlight?: ShadeNumber;
|
|
138
|
+
"on-DEFAULT"?: ShadeNumber;
|
|
139
|
+
"on-subdued"?: ShadeNumber;
|
|
140
|
+
"on-highlight"?: ShadeNumber;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Per-semantic-color shade overrides.
|
|
144
|
+
* Keys are semantic color names (e.g. "primary", "destructive").
|
|
145
|
+
* Values specify which shade index to use for each variant.
|
|
146
|
+
*/
|
|
147
|
+
type SemanticShadeOverrides = Record<string, {
|
|
148
|
+
light?: Partial<VariantShadeOverrides>;
|
|
149
|
+
dark?: Partial<VariantShadeOverrides>;
|
|
150
|
+
}>;
|
|
151
|
+
/** Per-surface-token shade overrides */
|
|
152
|
+
interface SurfaceShadeOverrides {
|
|
153
|
+
canvas?: ShadeNumber | "white" | "black";
|
|
154
|
+
"canvas-foreground"?: ShadeNumber | "white" | "black";
|
|
155
|
+
surface?: ShadeNumber | "white" | "black";
|
|
156
|
+
"surface-foreground"?: ShadeNumber | "white" | "black";
|
|
157
|
+
overlay?: ShadeNumber | "white" | "black";
|
|
158
|
+
"overlay-foreground"?: ShadeNumber | "white" | "black";
|
|
159
|
+
}
|
|
160
|
+
/** Per-utility-token shade overrides */
|
|
161
|
+
interface UtilityShadeOverrides {
|
|
162
|
+
border?: ShadeNumber;
|
|
163
|
+
input?: ShadeNumber;
|
|
164
|
+
ring?: ShadeNumber;
|
|
165
|
+
shadow?: ShadeNumber;
|
|
166
|
+
}
|
|
167
|
+
/** Generation options passed through the pipeline */
|
|
168
|
+
interface GenerationOptions {
|
|
169
|
+
contrastAlgorithm: ContrastAlgorithm;
|
|
170
|
+
contrastTarget: ContrastTarget;
|
|
171
|
+
lightnessStrategy: LightnessStrategy;
|
|
172
|
+
shadeOverrides: SemanticShadeOverrides;
|
|
173
|
+
surfaceShadeOverrides?: {
|
|
174
|
+
light?: Partial<SurfaceShadeOverrides>;
|
|
175
|
+
dark?: Partial<SurfaceShadeOverrides>;
|
|
176
|
+
};
|
|
177
|
+
utilityShadeOverrides?: {
|
|
178
|
+
light?: Partial<UtilityShadeOverrides>;
|
|
179
|
+
dark?: Partial<UtilityShadeOverrides>;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/** APCA contrast result for a single pairing */
|
|
183
|
+
interface APCAContrastResult {
|
|
184
|
+
lcValue: number;
|
|
185
|
+
level: "Fail" | "Minimum" | "Large text" | "Body text" | "Fluent";
|
|
186
|
+
}
|
|
187
|
+
/** WCAG contrast result for a single pairing */
|
|
188
|
+
interface WCAGContrastResult {
|
|
189
|
+
ratio: number;
|
|
190
|
+
passesAA: boolean;
|
|
191
|
+
passesAAA: boolean;
|
|
192
|
+
}
|
|
193
|
+
/** Colour vision deficiency simulation */
|
|
194
|
+
type CVDType = "none" | "protanopia" | "deuteranopia" | "tritanopia";
|
|
195
|
+
/** Saved configuration for localStorage persistence */
|
|
196
|
+
interface SavedConfig {
|
|
197
|
+
primaryColor: string;
|
|
198
|
+
neutralColor: string;
|
|
199
|
+
additionalColors: {
|
|
200
|
+
name: string;
|
|
201
|
+
color: string;
|
|
202
|
+
}[];
|
|
203
|
+
colorFormat: ColorFormat;
|
|
204
|
+
contrastAlgorithm: ContrastAlgorithm;
|
|
205
|
+
contrastTarget: ContrastTarget;
|
|
206
|
+
lightnessStrategy: LightnessStrategy;
|
|
207
|
+
shadeOverrides: SemanticShadeOverrides;
|
|
208
|
+
surfaceShadeOverrides?: GenerationOptions["surfaceShadeOverrides"];
|
|
209
|
+
utilityShadeOverrides?: GenerationOptions["utilityShadeOverrides"];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Simplified token generation - color-only
|
|
214
|
+
* Hardcodes defaults for non-color tokens (spacing, typography, shadows, etc.)
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Generate a complete token system from brand colors (color-focused)
|
|
219
|
+
*/
|
|
220
|
+
declare function generateTokens(brandColors: BrandColors, options?: Partial<GenerationOptions>): TokenSystem;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Primitive color palette generation using OKLCH
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
type PrimitivePalette = {
|
|
227
|
+
black: string;
|
|
228
|
+
white: string;
|
|
229
|
+
[colorName: string]: ColorScale | string;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Default neutral color - a balanced gray
|
|
233
|
+
*/
|
|
234
|
+
declare const DEFAULT_NEUTRAL_COLOR = "#747474";
|
|
235
|
+
/**
|
|
236
|
+
* Generate a complete primitive palette from brand colors
|
|
237
|
+
* Requires primary and neutral - other semantic colors are derived from primary
|
|
238
|
+
* Additional colors can be provided to generate custom scales
|
|
239
|
+
*/
|
|
240
|
+
declare function generatePrimitivePalette(brandColors: BrandColors, lightnessStrategy?: LightnessStrategy): PrimitivePalette;
|
|
241
|
+
/**
|
|
242
|
+
* Get a specific shade from a color scale
|
|
243
|
+
*/
|
|
244
|
+
declare function getShade(palette: PrimitivePalette, colorName: string, shade: keyof ColorScale): string;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Semantic token generation
|
|
248
|
+
* Maps primitive colors to meaningful semantic roles
|
|
249
|
+
*/
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Generate semantic tokens for a specific mode
|
|
253
|
+
* Supports additional custom colors beyond the core semantic colors
|
|
254
|
+
*/
|
|
255
|
+
declare function generateSemanticTokens(palette: PrimitivePalette, mode: "light" | "dark", options?: Partial<GenerationOptions>): SemanticTokens;
|
|
256
|
+
/**
|
|
257
|
+
* Generate surface tokens (canvas / surface / overlay depth system) from neutral palette
|
|
258
|
+
*/
|
|
259
|
+
declare function generateSurfaceTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<SurfaceShadeOverrides>): SurfaceTokens;
|
|
260
|
+
/**
|
|
261
|
+
* Generate utility tokens for borders, rings, inputs, shadow
|
|
262
|
+
*/
|
|
263
|
+
declare function generateUtilityTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<UtilityShadeOverrides>): UtilityTokens;
|
|
264
|
+
/**
|
|
265
|
+
* Check contrast compliance for all semantic colors
|
|
266
|
+
*/
|
|
267
|
+
declare function checkSemanticContrast(tokens: SemanticTokens): Record<string, {
|
|
268
|
+
ratio: number;
|
|
269
|
+
passesAA: boolean;
|
|
270
|
+
passesAAA: boolean;
|
|
271
|
+
}>;
|
|
272
|
+
/**
|
|
273
|
+
* Check APCA contrast compliance for all semantic colors
|
|
274
|
+
*/
|
|
275
|
+
declare function checkSemanticContrastAPCA(tokens: SemanticTokens): Record<string, APCAContrastResult>;
|
|
276
|
+
/**
|
|
277
|
+
* Compute an overall accessibility score for the token system.
|
|
278
|
+
* Only counts pairings that are shown in the semantic preview
|
|
279
|
+
* (excludes neutral, muted). Simple pass/fail counting.
|
|
280
|
+
*/
|
|
281
|
+
declare function computeAccessibilityScore(tokens: SemanticTokens, algorithm: ContrastAlgorithm, contrastTarget?: ContrastTarget): {
|
|
282
|
+
score: number;
|
|
283
|
+
passed: number;
|
|
284
|
+
total: number;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Export utilities for design tokens
|
|
289
|
+
* Converts token system to CSS variables, Tailwind config, etc.
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Export tokens as CSS custom properties
|
|
294
|
+
*/
|
|
295
|
+
declare function exportToCss(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, compat?: boolean): string;
|
|
296
|
+
/**
|
|
297
|
+
* Export tokens as Tailwind v4 CSS
|
|
298
|
+
*/
|
|
299
|
+
declare function exportToTailwindV4(tokens: TokenSystem, colorFormat?: ColorFormat, shadeOverrides?: SemanticShadeOverrides, compat?: boolean): string;
|
|
300
|
+
/**
|
|
301
|
+
* Export tokens as Tailwind v3 config
|
|
302
|
+
*/
|
|
303
|
+
declare function exportToTailwindV3(tokens: TokenSystem, colorFormat?: ColorFormat): string;
|
|
304
|
+
/**
|
|
305
|
+
* Export tokens in W3C Design Token Community Group (DTCG) format
|
|
306
|
+
* @see https://tr.designtokens.org/format/
|
|
307
|
+
*/
|
|
308
|
+
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";
|
|
315
|
+
/** Options for token export */
|
|
316
|
+
interface ExportOptions {
|
|
317
|
+
colorFormat?: ColorFormat;
|
|
318
|
+
shadeOverrides?: SemanticShadeOverrides;
|
|
319
|
+
/**
|
|
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.
|
|
323
|
+
*/
|
|
324
|
+
compat?: boolean;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Export tokens in the specified format
|
|
328
|
+
*/
|
|
329
|
+
declare function exportTokens(tokens: TokenSystem, format: ExportFormat, options?: ExportOptions): string;
|
|
330
|
+
|
|
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 };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_NEUTRAL_COLOR,
|
|
3
|
+
adjustChroma,
|
|
4
|
+
adjustLightness,
|
|
5
|
+
checkSemanticContrast,
|
|
6
|
+
checkSemanticContrastAPCA,
|
|
7
|
+
classifyAPCALevel,
|
|
8
|
+
computeAccessibilityScore,
|
|
9
|
+
exportToCss,
|
|
10
|
+
exportToDtcg,
|
|
11
|
+
exportToLovable,
|
|
12
|
+
exportToTailwindV3,
|
|
13
|
+
exportToTailwindV4,
|
|
14
|
+
exportTokens,
|
|
15
|
+
findContrastingColorAPCA,
|
|
16
|
+
formatColorAs,
|
|
17
|
+
formatColorShort,
|
|
18
|
+
generateColorScale,
|
|
19
|
+
generateColorScaleAPCA,
|
|
20
|
+
generatePrimitivePalette,
|
|
21
|
+
generateSemanticTokens,
|
|
22
|
+
generateSurfaceTokens,
|
|
23
|
+
generateTokens,
|
|
24
|
+
generateUtilityTokens,
|
|
25
|
+
getAPCAContrast,
|
|
26
|
+
getContrastRatio,
|
|
27
|
+
getOklchString,
|
|
28
|
+
getRelativeLuminance,
|
|
29
|
+
getShade,
|
|
30
|
+
meetsWCAG_AA,
|
|
31
|
+
meetsWCAG_AAA,
|
|
32
|
+
oklchToHex,
|
|
33
|
+
parseToOklch,
|
|
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];
|
|
39
|
+
export {
|
|
40
|
+
DEFAULT_NEUTRAL_COLOR,
|
|
41
|
+
VALID_SHADES,
|
|
42
|
+
adjustChroma,
|
|
43
|
+
adjustLightness,
|
|
44
|
+
checkSemanticContrast,
|
|
45
|
+
checkSemanticContrastAPCA,
|
|
46
|
+
classifyAPCALevel,
|
|
47
|
+
computeAccessibilityScore,
|
|
48
|
+
exportToCss,
|
|
49
|
+
exportToDtcg,
|
|
50
|
+
exportToLovable,
|
|
51
|
+
exportToTailwindV3,
|
|
52
|
+
exportToTailwindV4,
|
|
53
|
+
exportTokens,
|
|
54
|
+
findContrastingColorAPCA,
|
|
55
|
+
formatColorAs,
|
|
56
|
+
formatColorShort,
|
|
57
|
+
generateColorScale,
|
|
58
|
+
generateColorScaleAPCA,
|
|
59
|
+
generatePrimitivePalette,
|
|
60
|
+
generateSemanticTokens,
|
|
61
|
+
generateSurfaceTokens,
|
|
62
|
+
generateTokens,
|
|
63
|
+
generateUtilityTokens,
|
|
64
|
+
getAPCAContrast,
|
|
65
|
+
getContrastRatio,
|
|
66
|
+
getOklchString,
|
|
67
|
+
getRelativeLuminance,
|
|
68
|
+
getShade,
|
|
69
|
+
meetsWCAG_AA,
|
|
70
|
+
meetsWCAG_AAA,
|
|
71
|
+
oklchToHex,
|
|
72
|
+
parseToOklch,
|
|
73
|
+
simulateCVD
|
|
74
|
+
};
|