@tenphi/glaze 0.0.0-snapshot.7f7cab2 → 0.0.0-snapshot.84edd5e
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 +86 -1094
- package/dist/index.cjs +3700 -1015
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1375 -111
- package/dist/index.d.mts +1375 -111
- package/dist/index.mjs +3668 -1015
- package/dist/index.mjs.map +1 -1
- package/docs/api.md +1969 -0
- package/docs/methodology.md +684 -0
- package/docs/migration.md +315 -0
- package/docs/okhst.md +203 -0
- package/package.json +9 -9
package/dist/index.d.mts
CHANGED
|
@@ -1,48 +1,144 @@
|
|
|
1
1
|
//#region src/contrast-solver.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* OKHSL Contrast Solver
|
|
4
|
-
*
|
|
5
|
-
* Finds the closest OKHSL lightness that satisfies a WCAG 2 contrast target
|
|
6
|
-
* against a base color. Used by glaze when resolving dependent colors
|
|
7
|
-
* with `contrast`.
|
|
8
|
-
*/
|
|
9
2
|
type LinearRgb = [number, number, number];
|
|
10
3
|
type ContrastPreset = 'AA' | 'AAA' | 'AA-large' | 'AAA-large';
|
|
11
4
|
type MinContrast$1 = number | ContrastPreset;
|
|
12
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Named APCA Lc floor presets (APCA Bronze Simple Mode conformance levels),
|
|
7
|
+
* independent of role. Use them anywhere an APCA target is accepted.
|
|
8
|
+
*
|
|
9
|
+
* | Preset | Lc | Use case |
|
|
10
|
+
* | ------------- | --- | ---------------------------------------------------- |
|
|
11
|
+
* | `'preferred'` | 90 | Preferred body / column text |
|
|
12
|
+
* | `'body'` | 75 | Minimum body / column text |
|
|
13
|
+
* | `'content'` | 60 | Readable non-body content (~WCAG AA 4.5:1) |
|
|
14
|
+
* | `'large'` | 45 | Large/bold headlines; fine icons/outlines (~3:1) |
|
|
15
|
+
* | `'non-text'` | 30 | Solid icons/controls; placeholder/disabled text |
|
|
16
|
+
* | `'min'` | 15 | Dividers/decorative; APCA "point of invisibility" |
|
|
17
|
+
*/
|
|
18
|
+
type ApcaPreset = 'preferred' | 'body' | 'content' | 'large' | 'non-text' | 'min';
|
|
19
|
+
declare const APCA_PRESETS: Record<ApcaPreset, number>;
|
|
20
|
+
/**
|
|
21
|
+
* APCA-W3 "Enhanced Level" delta added to a bare APCA target in high-contrast
|
|
22
|
+
* mode when no explicit HC value is provided (analogous to WCAG AAA over AA).
|
|
23
|
+
* Only applied when neither the outer `contrast` pair nor the inner `apca`
|
|
24
|
+
* pair carries an explicit HC entry.
|
|
25
|
+
*/
|
|
26
|
+
declare const APCA_HC_ENHANCEMENT = 15;
|
|
27
|
+
/** Upper bound for an APCA Lc target after HC enhancement. */
|
|
28
|
+
declare const APCA_MAX_LC = 106;
|
|
29
|
+
/**
|
|
30
|
+
* Resolve an APCA target — a raw Lc number (kept as-is) or an `ApcaPreset`
|
|
31
|
+
* keyword mapped to its Lc value. The magnitude is forced non-negative.
|
|
32
|
+
*/
|
|
33
|
+
declare function resolveApcaTarget(value: number | ApcaPreset): number;
|
|
34
|
+
/** Metric + numeric target after resolving a `ContrastSpec` for a mode. */
|
|
35
|
+
interface ResolvedContrast {
|
|
36
|
+
metric: 'wcag' | 'apca';
|
|
37
|
+
/** WCAG ratio (>= 1) or APCA Lc magnitude (0–106). */
|
|
38
|
+
target: number;
|
|
39
|
+
/**
|
|
40
|
+
* APCA argument order: which side the resolved (candidate) color plays
|
|
41
|
+
* against the base. `'fg'` (default) → `apcaContrast(yCandidate, yBase)`;
|
|
42
|
+
* `'bg'` → `apcaContrast(yBase, yCandidate)`. Always `'fg'` for WCAG
|
|
43
|
+
* (symmetric, ignored).
|
|
44
|
+
*/
|
|
45
|
+
polarity?: 'fg' | 'bg';
|
|
46
|
+
}
|
|
47
|
+
declare function resolveMinContrast(value: MinContrast$1): number;
|
|
48
|
+
/**
|
|
49
|
+
* Resolve a `ContrastSpec` (already selected from any outer HC pair) for a
|
|
50
|
+
* given mode into `{ metric, target }`. Handles the inner metric HC pair and
|
|
51
|
+
* preset resolution. `polarity` is passed through to the result for the APCA
|
|
52
|
+
* branch (it controls argument order in the solver); WCAG ignores it.
|
|
53
|
+
*
|
|
54
|
+
* `outerExplicitHC` indicates whether the caller selected this `spec` from an
|
|
55
|
+
* explicit high-contrast entry of the outer `contrast` pair. Together with the
|
|
56
|
+
* inner metric pair, it decides whether the HC auto-enhancement fires:
|
|
57
|
+
* - APCA: +15 Lc "Enhanced Level" boost when neither level is explicit.
|
|
58
|
+
* - WCAG: AA → AAA / AA-large → AAA-large promotion (SC 1.4.3 → 1.4.6) when
|
|
59
|
+
* neither level is explicit. AAA-family presets and bare numbers are left
|
|
60
|
+
* unchanged (AAA is the top WCAG tier).
|
|
61
|
+
* Defaults to `false` (correct for direct callers, which pass a single
|
|
62
|
+
* selected spec rather than an outer pair).
|
|
63
|
+
*/
|
|
64
|
+
declare function resolveContrastForMode(spec: ContrastSpec, isHighContrast: boolean, polarity?: 'fg' | 'bg', outerExplicitHC?: boolean): ResolvedContrast;
|
|
65
|
+
/**
|
|
66
|
+
* Resolve a `contrast` spec — including its outer `[normal, highContrast]`
|
|
67
|
+
* pair — at a manual contrast `level` (0–100), by resolving both ends and
|
|
68
|
+
* interpolating the numeric target.
|
|
69
|
+
*
|
|
70
|
+
* Level 0 / 100 delegate verbatim to {@link resolveContrastForMode}, so the
|
|
71
|
+
* endpoints are bit-identical to classic normal / high-contrast resolution.
|
|
72
|
+
* Resolving each end fully first also means every rule that governs the
|
|
73
|
+
* escalation still applies at both ends for free: preset mapping, the
|
|
74
|
+
* `APCA_MAX_LC` clamp, and the explicit-HC suppression that cancels the
|
|
75
|
+
* `AA → AAA` promotion and the `+15 Lc` enhancement.
|
|
76
|
+
*
|
|
77
|
+
* Throws when the two ends measure in different metrics — a WCAG ratio and an
|
|
78
|
+
* APCA Lc live on different scales, so there is no target between them. Such a
|
|
79
|
+
* pair is rejected at authoring time by `validateColorDefs`; this is the guard
|
|
80
|
+
* for direct callers.
|
|
81
|
+
*/
|
|
82
|
+
declare function resolveContrastForLevel(spec: HCPair<ContrastSpec>, level: number, polarity?: 'fg' | 'bg'): ResolvedContrast;
|
|
83
|
+
/**
|
|
84
|
+
* APCA lightness contrast (Lc), signed: positive for dark text on light bg,
|
|
85
|
+
* negative for light text on dark bg. Inputs are screen luminances (0–1).
|
|
86
|
+
*/
|
|
87
|
+
declare function apcaContrast(yText: number, yBg: number): number;
|
|
88
|
+
interface FindToneForContrastOptions {
|
|
13
89
|
/** Hue of the candidate color (0–360). */
|
|
14
90
|
hue: number;
|
|
15
91
|
/** Saturation of the candidate color (0–1). */
|
|
16
92
|
saturation: number;
|
|
17
|
-
/** Preferred
|
|
18
|
-
|
|
19
|
-
/** Base/reference color as linear sRGB
|
|
20
|
-
baseLinearRgb:
|
|
21
|
-
/**
|
|
22
|
-
contrast:
|
|
23
|
-
/** Search bounds for
|
|
24
|
-
|
|
93
|
+
/** Preferred tone of the candidate (0–1). */
|
|
94
|
+
preferredTone: number;
|
|
95
|
+
/** Base/reference color as linear sRGB. */
|
|
96
|
+
baseLinearRgb: LinearRgb;
|
|
97
|
+
/** Resolved contrast floor (metric + target). */
|
|
98
|
+
contrast: ResolvedContrast;
|
|
99
|
+
/** Search bounds for tone. Default: [0, 1]. */
|
|
100
|
+
toneRange?: [number, number];
|
|
25
101
|
/** Convergence threshold. Default: 1e-4. */
|
|
26
102
|
epsilon?: number;
|
|
27
|
-
/** Maximum binary-search iterations per branch. Default:
|
|
103
|
+
/** Maximum binary-search iterations per branch. Default: 18. */
|
|
28
104
|
maxIterations?: number;
|
|
105
|
+
/** Preferred search direction before auto-flip is considered. */
|
|
106
|
+
initialDirection?: 'lighter' | 'darker';
|
|
107
|
+
/** Auto-flip tone direction when contrast can't be met. Default: false. */
|
|
108
|
+
flip?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* When `flip` is on and *both* directions meet the target, keep
|
|
111
|
+
* `initialDirection` instead of taking whichever result lands nearer the
|
|
112
|
+
* preferred tone. Default: false (nearest wins).
|
|
113
|
+
*
|
|
114
|
+
* The nearest-wins tie-break is unstable along a ramp of targets: which side
|
|
115
|
+
* is nearer shifts as the target grows, so a color can swap sides between two
|
|
116
|
+
* adjacent targets. Set this when a caller needs the side to be a property of
|
|
117
|
+
* the color rather than of the target — the manual contrast level does. The
|
|
118
|
+
* flip itself is unaffected: an initial direction that cannot reach the
|
|
119
|
+
* target still falls back to the opposite side.
|
|
120
|
+
*/
|
|
121
|
+
preferInitial?: boolean;
|
|
122
|
+
/** Use the hue-independent "safe" chroma boundary. Default: false. */
|
|
123
|
+
pastel?: boolean;
|
|
29
124
|
}
|
|
30
|
-
interface
|
|
31
|
-
/** Chosen
|
|
32
|
-
|
|
33
|
-
/** Achieved WCAG
|
|
125
|
+
interface FindToneForContrastResult {
|
|
126
|
+
/** Chosen tone in 0–1. */
|
|
127
|
+
tone: number;
|
|
128
|
+
/** Achieved score (WCAG ratio or APCA Lc magnitude). */
|
|
34
129
|
contrast: number;
|
|
35
130
|
/** Whether the target was reached. */
|
|
36
131
|
met: boolean;
|
|
37
132
|
/** Which branch was selected. */
|
|
38
133
|
branch: 'lighter' | 'darker' | 'preferred';
|
|
134
|
+
/** Whether the result auto-flipped to the opposite direction. */
|
|
135
|
+
flipped?: boolean;
|
|
39
136
|
}
|
|
40
|
-
declare function resolveMinContrast(value: MinContrast$1): number;
|
|
41
137
|
/**
|
|
42
|
-
* Find the
|
|
43
|
-
*
|
|
138
|
+
* Find the tone that satisfies a contrast floor against a base color,
|
|
139
|
+
* staying as close to `preferredTone` as possible.
|
|
44
140
|
*/
|
|
45
|
-
declare function
|
|
141
|
+
declare function findToneForContrast(options: FindToneForContrastOptions): FindToneForContrastResult;
|
|
46
142
|
interface FindValueForMixContrastOptions {
|
|
47
143
|
/** Preferred mix parameter (0–1). */
|
|
48
144
|
preferredValue: number;
|
|
@@ -50,42 +146,84 @@ interface FindValueForMixContrastOptions {
|
|
|
50
146
|
baseLinearRgb: LinearRgb;
|
|
51
147
|
/** Target color as linear sRGB. */
|
|
52
148
|
targetLinearRgb: LinearRgb;
|
|
53
|
-
/**
|
|
54
|
-
contrast:
|
|
55
|
-
/**
|
|
56
|
-
* Compute the luminance of the mixed color at parameter t.
|
|
57
|
-
* For opaque: luminance of OKHSL-interpolated color.
|
|
58
|
-
* For transparent: luminance of alpha-composited color over base.
|
|
59
|
-
*/
|
|
149
|
+
/** Resolved contrast floor (metric + target). */
|
|
150
|
+
contrast: ResolvedContrast;
|
|
151
|
+
/** Compute the luminance of the mixed color at parameter t. */
|
|
60
152
|
luminanceAtValue: (t: number) => number;
|
|
61
153
|
/** Convergence threshold. Default: 1e-4. */
|
|
62
154
|
epsilon?: number;
|
|
63
155
|
/** Maximum binary-search iterations per branch. Default: 20. */
|
|
64
156
|
maxIterations?: number;
|
|
157
|
+
/** Auto-flip mix direction when contrast can't be met. Default: false. */
|
|
158
|
+
flip?: boolean;
|
|
65
159
|
}
|
|
66
160
|
interface FindValueForMixContrastResult {
|
|
67
|
-
/** Chosen mix parameter (0–1). */
|
|
68
161
|
value: number;
|
|
69
|
-
/** Achieved WCAG contrast ratio. */
|
|
70
162
|
contrast: number;
|
|
71
|
-
/** Whether the target was reached. */
|
|
72
163
|
met: boolean;
|
|
164
|
+
flipped?: boolean;
|
|
73
165
|
}
|
|
74
166
|
/**
|
|
75
|
-
* Find the mix parameter (ratio or opacity) that satisfies a
|
|
76
|
-
*
|
|
167
|
+
* Find the mix parameter (ratio or opacity) that satisfies a contrast floor
|
|
168
|
+
* against a base color, staying as close to `preferredValue` as possible.
|
|
77
169
|
*/
|
|
78
170
|
declare function findValueForMixContrast(options: FindValueForMixContrastOptions): FindValueForMixContrastResult;
|
|
79
171
|
//#endregion
|
|
80
172
|
//#region src/types.d.ts
|
|
81
173
|
/** A value or [normal, high-contrast] pair. */
|
|
82
174
|
type HCPair<T> = T | [T, T];
|
|
175
|
+
/** Bare WCAG contrast target: a ratio number or a named preset. */
|
|
83
176
|
type MinContrast = number | ContrastPreset;
|
|
177
|
+
/**
|
|
178
|
+
* A contrast floor with a pluggable metric.
|
|
179
|
+
*
|
|
180
|
+
* - `number` / `ContrastPreset`: a WCAG ratio (bare form).
|
|
181
|
+
* - `{ wcag }`: WCAG ratio or preset, optionally an HC pair.
|
|
182
|
+
* - `{ apca }`: APCA Lc target (absolute value or preset), optionally an HC pair.
|
|
183
|
+
*
|
|
184
|
+
* The `[normal, highContrast]` pair may live at the outer level
|
|
185
|
+
* (`[4.5, 7]`, `[{ wcag: 4.5 }, { wcag: 7 }]`) or inside the metric
|
|
186
|
+
* (`{ wcag: [4.5, 7] }`, `{ apca: [45, 60] }`, `{ apca: ['content', 'body'] }`).
|
|
187
|
+
*/
|
|
188
|
+
type ContrastSpec = number | ContrastPreset | {
|
|
189
|
+
wcag: HCPair<number | ContrastPreset>;
|
|
190
|
+
} | {
|
|
191
|
+
apca: HCPair<number | ApcaPreset>;
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* The semantic role a color plays against its base, used to fix APCA contrast
|
|
195
|
+
* polarity (which side is the foreground vs the background). WCAG is
|
|
196
|
+
* symmetric, so role never changes WCAG results.
|
|
197
|
+
*/
|
|
198
|
+
type Role = 'text' | 'surface' | 'border';
|
|
199
|
+
/**
|
|
200
|
+
* Any string accepted as a `role`. Canonical values plus aliases normalized by
|
|
201
|
+
* `normalizeRole` (see `roles.ts`): `surface` (bg/background/fill/canvas/
|
|
202
|
+
* paper/layer), `text` (fg/foreground/content/ink/label/stroke), `border`
|
|
203
|
+
* (divider/outline/separator/hairline/rule).
|
|
204
|
+
*/
|
|
205
|
+
type RoleInput = Role | 'bg' | 'background' | 'fill' | 'canvas' | 'paper' | 'layer' | 'fg' | 'foreground' | 'content' | 'ink' | 'label' | 'stroke' | 'divider' | 'outline' | 'separator' | 'hairline' | 'rule';
|
|
84
206
|
type AdaptationMode = 'auto' | 'fixed' | 'static';
|
|
85
207
|
/** A signed relative offset string, e.g. '+20' or '-15.5'. */
|
|
86
208
|
type RelativeValue = `+${number}` | `-${number}`;
|
|
209
|
+
/**
|
|
210
|
+
* Force a color to a tone extreme:
|
|
211
|
+
* - `'max'`: the highest tone in the active scheme range/window.
|
|
212
|
+
* - `'min'`: the lowest tone.
|
|
213
|
+
*
|
|
214
|
+
* Under `mode: 'auto'` the extreme inverts in the dark scheme (so `'max'`
|
|
215
|
+
* tracks the inversion and becomes the darkest tone). No `base` required.
|
|
216
|
+
*/
|
|
217
|
+
type ExtremeValue = 'max' | 'min';
|
|
218
|
+
/**
|
|
219
|
+
* A tone value as authored on a color.
|
|
220
|
+
* - Number: absolute tone (0–100).
|
|
221
|
+
* - `'+N'` / `'-N'`: relative to the base's tone (requires `base`).
|
|
222
|
+
* - `'max'` / `'min'`: forced to the scheme's tone extreme (no base needed).
|
|
223
|
+
*/
|
|
224
|
+
type ToneValue = number | RelativeValue | ExtremeValue;
|
|
87
225
|
/** Color format for output. */
|
|
88
|
-
type GlazeColorFormat = 'okhsl' | 'rgb' | 'hsl' | 'oklch';
|
|
226
|
+
type GlazeColorFormat = 'okhsl' | 'okhst' | 'rgb' | 'hsl' | 'oklch';
|
|
89
227
|
/**
|
|
90
228
|
* Controls which scheme variants are generated in the export.
|
|
91
229
|
* Light is always included (it's the default).
|
|
@@ -93,7 +231,14 @@ type GlazeColorFormat = 'okhsl' | 'rgb' | 'hsl' | 'oklch';
|
|
|
93
231
|
interface GlazeOutputModes {
|
|
94
232
|
/** Include dark scheme variants. Default: true. */
|
|
95
233
|
dark?: boolean;
|
|
96
|
-
/**
|
|
234
|
+
/**
|
|
235
|
+
* Include high-contrast variants (both light-HC and dark-HC). Default: false.
|
|
236
|
+
*
|
|
237
|
+
* Inert while a global `contrastLevel` is set: a manual level has no separate
|
|
238
|
+
* high-contrast tier, so this reads as "emit high-contrast variants when
|
|
239
|
+
* contrast is automatic".
|
|
240
|
+
* @see GlazeConfig.contrastLevel
|
|
241
|
+
*/
|
|
97
242
|
highContrast?: boolean;
|
|
98
243
|
}
|
|
99
244
|
/** Hex color string for DX hints. Runtime validation in `parseHex()`. */
|
|
@@ -104,14 +249,66 @@ interface OkhslColor {
|
|
|
104
249
|
s: number;
|
|
105
250
|
l: number;
|
|
106
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Direct OKHST color input — OKHSL with the lightness axis replaced by the
|
|
254
|
+
* contrast-uniform tone axis. `h`: 0–360, `s`: 0–1, `t`: 0–1 (tone).
|
|
255
|
+
*/
|
|
256
|
+
interface OkhstColor {
|
|
257
|
+
h: number;
|
|
258
|
+
s: number;
|
|
259
|
+
t: number;
|
|
260
|
+
}
|
|
261
|
+
/** sRGB components in 0–255 (value-shorthand object form). */
|
|
262
|
+
interface RgbColor {
|
|
263
|
+
r: number;
|
|
264
|
+
g: number;
|
|
265
|
+
b: number;
|
|
266
|
+
}
|
|
267
|
+
/** OKLCh components matching CSS `oklch(L C H)` (L/C: 0–1, H: degrees). */
|
|
268
|
+
interface OklchColor {
|
|
269
|
+
l: number;
|
|
270
|
+
c: number;
|
|
271
|
+
h: number;
|
|
272
|
+
}
|
|
107
273
|
interface RegularColorDef {
|
|
108
274
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
275
|
+
* Seed this color from a literal color instead of from the theme.
|
|
276
|
+
*
|
|
277
|
+
* Accepts the same values as `glaze.color()` — hex, `rgb()`, `hsl()`,
|
|
278
|
+
* `okhsl()`, `okhst()`, `oklch()`, or a value object. It supplies three
|
|
279
|
+
* things at once: `hue`, `tone`, and — unlike every other color in a theme —
|
|
280
|
+
* an **absolute saturation** rather than a factor of the seed. That last
|
|
281
|
+
* part is the point: a color can now be more saturated than its theme, so
|
|
282
|
+
* honoring a brand color no longer means re-seeding the whole theme to reach
|
|
283
|
+
* it.
|
|
284
|
+
*
|
|
285
|
+
* The **light, normal-contrast** variant reproduces the value exactly
|
|
286
|
+
* (a local `lightTone: false`, matching the value-shorthand form of
|
|
287
|
+
* `glaze.color()`). Dark and high-contrast variants adapt as usual — they
|
|
288
|
+
* are where readability outranks fidelity, and a color pinned across every
|
|
289
|
+
* scheme would defeat both. A `contrast` floor still applies everywhere and
|
|
290
|
+
* still only moves the color when the authored value misses it.
|
|
291
|
+
*
|
|
292
|
+
* Sibling fields override what the value supplied, so
|
|
293
|
+
* `{ from: '#2F5BFF', hue: 300 }` keeps its saturation and tone but rotates
|
|
294
|
+
* the hue.
|
|
295
|
+
*/
|
|
296
|
+
from?: GlazeColorValue;
|
|
297
|
+
/**
|
|
298
|
+
* Tone value (0–100, contrast-uniform — see `docs/okhst.md`).
|
|
299
|
+
* - Number: absolute tone.
|
|
300
|
+
* - String ('+N' / '-N'): relative to base color's tone (requires `base`).
|
|
301
|
+
* - `'max'` / `'min'`: force to the scheme's tone extreme (no base needed).
|
|
302
|
+
*
|
|
303
|
+
* Defaults to the tone of `from` when that is set.
|
|
304
|
+
*/
|
|
305
|
+
tone?: HCPair<ToneValue>;
|
|
306
|
+
/**
|
|
307
|
+
* Saturation factor applied to the seed saturation (0–1, default: 1).
|
|
308
|
+
*
|
|
309
|
+
* With `from`, an explicit value here is still a factor of the seed and
|
|
310
|
+
* overrides the absolute saturation the color carried.
|
|
112
311
|
*/
|
|
113
|
-
lightness?: HCPair<number | RelativeValue>;
|
|
114
|
-
/** Saturation factor applied to the seed saturation (0–1, default: 1). */
|
|
115
312
|
saturation?: number;
|
|
116
313
|
/**
|
|
117
314
|
* Hue override for this color.
|
|
@@ -119,20 +316,73 @@ interface RegularColorDef {
|
|
|
119
316
|
* - String ('+N' / '-N'): relative to the theme seed hue.
|
|
120
317
|
*/
|
|
121
318
|
hue?: number | RelativeValue;
|
|
319
|
+
/**
|
|
320
|
+
* Dark-scheme hue override. Applies to the `dark` and `darkContrast`
|
|
321
|
+
* variants; falls back to `hue` when omitted.
|
|
322
|
+
* - Number: absolute hue (0–360).
|
|
323
|
+
* - String ('+N' / '-N'): relative to the theme's **dark** seed hue
|
|
324
|
+
* (`GlazeTheme.darkHue`, itself defaulting to the light seed hue).
|
|
325
|
+
*
|
|
326
|
+
* Ignored under `mode: 'static'`, which pins one value across all schemes.
|
|
327
|
+
*/
|
|
328
|
+
darkHue?: number | RelativeValue;
|
|
329
|
+
/**
|
|
330
|
+
* Dark-scheme saturation factor (0–1) applied to the dark seed
|
|
331
|
+
* saturation. Applies to the `dark` and `darkContrast` variants; falls
|
|
332
|
+
* back to `saturation` when omitted.
|
|
333
|
+
*
|
|
334
|
+
* When set, the global `darkDesaturation` reduction is **not** applied on
|
|
335
|
+
* top — the resulting saturation is taken literally. Ignored under
|
|
336
|
+
* `mode: 'static'`.
|
|
337
|
+
*/
|
|
338
|
+
darkSaturation?: number;
|
|
122
339
|
/** Name of another color in the same theme (dependent color). */
|
|
123
340
|
base?: string;
|
|
124
|
-
/**
|
|
125
|
-
|
|
341
|
+
/**
|
|
342
|
+
* Contrast floor against the base color. A bare number/preset is WCAG;
|
|
343
|
+
* use `{ wcag }` / `{ apca }` to pick the metric. Accepts an HC pair.
|
|
344
|
+
*/
|
|
345
|
+
contrast?: HCPair<ContrastSpec>;
|
|
126
346
|
/** Adaptation mode. Default: 'auto'. */
|
|
127
347
|
mode?: AdaptationMode;
|
|
348
|
+
/**
|
|
349
|
+
* Whether to flip out-of-bounds results to the opposite side instead of
|
|
350
|
+
* clamping to the extreme. Affects both:
|
|
351
|
+
* - relative `tone`: when `base ± delta` exceeds `[0, 100]`, mirror the
|
|
352
|
+
* delta to the other side of the base. If the mirrored target is also
|
|
353
|
+
* out of range, keep the original delta and clamp on the authored side.
|
|
354
|
+
* - `contrast`: when the requested direction can't meet the floor, try the
|
|
355
|
+
* opposite side (same as the global `autoFlip`).
|
|
356
|
+
*
|
|
357
|
+
* Defaults to the global `autoFlip` config (default `true`). Set `false`
|
|
358
|
+
* to clamp instead.
|
|
359
|
+
*/
|
|
360
|
+
autoFlip?: boolean;
|
|
128
361
|
/**
|
|
129
362
|
* Fixed opacity (0–1).
|
|
130
363
|
* Output includes alpha in the CSS value.
|
|
131
364
|
* Does not affect contrast resolution — a semi-transparent color
|
|
132
|
-
* has no fixed perceived
|
|
365
|
+
* has no fixed perceived tone, so `contrast` and `opacity`
|
|
133
366
|
* should not be combined (a console.warn is emitted).
|
|
134
367
|
*/
|
|
135
368
|
opacity?: number;
|
|
369
|
+
/**
|
|
370
|
+
* Per-color override for the hue-independent "safe" chroma limit used in
|
|
371
|
+
* OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
|
|
372
|
+
* Falls through to the per-theme / per-token `pastel` override when omitted.
|
|
373
|
+
* @see GlazeConfigOverride.pastel
|
|
374
|
+
*/
|
|
375
|
+
pastel?: boolean;
|
|
376
|
+
/**
|
|
377
|
+
* Semantic role against `base`: how this color is used. Fixes APCA contrast
|
|
378
|
+
* polarity (the argument order in `apcaContrast`). WCAG is symmetric so it
|
|
379
|
+
* never affects WCAG results.
|
|
380
|
+
*
|
|
381
|
+
* Resolution: explicit `role` wins; else inferred from the color name when
|
|
382
|
+
* `inferRole` is enabled (default); else the opposite of the base's role;
|
|
383
|
+
* else defaults to `'text'` (foreground).
|
|
384
|
+
*/
|
|
385
|
+
role?: RoleInput;
|
|
136
386
|
/**
|
|
137
387
|
* Whether this color is inherited by child themes created via `extend()`.
|
|
138
388
|
* Default: true. Set to false to make this color local to the current theme.
|
|
@@ -182,6 +432,13 @@ interface ShadowColorDef {
|
|
|
182
432
|
intensity: HCPair<number>;
|
|
183
433
|
/** Override default tuning. Merged field-by-field with global `shadowTuning`. */
|
|
184
434
|
tuning?: ShadowTuning;
|
|
435
|
+
/**
|
|
436
|
+
* Per-color override for the hue-independent "safe" chroma limit used in
|
|
437
|
+
* OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
|
|
438
|
+
* Falls through to the per-theme / per-token `pastel` override when omitted.
|
|
439
|
+
* @see GlazeConfigOverride.pastel
|
|
440
|
+
*/
|
|
441
|
+
pastel?: boolean;
|
|
185
442
|
/**
|
|
186
443
|
* Whether this color is inherited by child themes created via `extend()`.
|
|
187
444
|
* Default: true. Set to false to make this color local to the current theme.
|
|
@@ -215,12 +472,26 @@ interface MixColorDef {
|
|
|
215
472
|
*/
|
|
216
473
|
space?: 'okhsl' | 'srgb';
|
|
217
474
|
/**
|
|
218
|
-
* Minimum
|
|
475
|
+
* Minimum contrast between the base and the resulting color.
|
|
219
476
|
* In 'opaque' mode, adjusts the mix ratio to meet contrast.
|
|
220
477
|
* In 'transparent' mode, adjusts opacity to meet contrast against the composite.
|
|
221
|
-
*
|
|
478
|
+
* A bare number/preset is WCAG; use `{ wcag }` / `{ apca }` to pick the
|
|
479
|
+
* metric. Supports [normal, highContrast] pair.
|
|
222
480
|
*/
|
|
223
|
-
contrast?: HCPair<
|
|
481
|
+
contrast?: HCPair<ContrastSpec>;
|
|
482
|
+
/**
|
|
483
|
+
* Per-color override for the hue-independent "safe" chroma limit used in
|
|
484
|
+
* OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
|
|
485
|
+
* Falls through to the per-theme / per-token `pastel` override when omitted.
|
|
486
|
+
* @see GlazeConfigOverride.pastel
|
|
487
|
+
*/
|
|
488
|
+
pastel?: boolean;
|
|
489
|
+
/**
|
|
490
|
+
* Semantic role of the mixed result against `base`. Same semantics as
|
|
491
|
+
* `RegularColorDef.role` (fixes APCA polarity). Resolution and defaults
|
|
492
|
+
* are identical.
|
|
493
|
+
*/
|
|
494
|
+
role?: RoleInput;
|
|
224
495
|
/**
|
|
225
496
|
* Whether this color is inherited by child themes created via `extend()`.
|
|
226
497
|
* Default: true. Set to false to make this color local to the current theme.
|
|
@@ -229,16 +500,28 @@ interface MixColorDef {
|
|
|
229
500
|
}
|
|
230
501
|
type ColorDef = RegularColorDef | ShadowColorDef | MixColorDef;
|
|
231
502
|
type ColorMap = Record<string, ColorDef>;
|
|
232
|
-
/**
|
|
503
|
+
/**
|
|
504
|
+
* Resolved color for a single scheme variant.
|
|
505
|
+
*
|
|
506
|
+
* Stored in OKHST: `h` / `s` are OKHSL hue/saturation, `t` is the canonical
|
|
507
|
+
* contrast-uniform tone (0–1, reference eps). Convert to OKHSL lightness via
|
|
508
|
+
* `variantToOkhsl` at the rendering / luminance edges.
|
|
509
|
+
*/
|
|
233
510
|
interface ResolvedColorVariant {
|
|
234
511
|
/** OKHSL hue (0–360). */
|
|
235
512
|
h: number;
|
|
236
513
|
/** OKHSL saturation (0–1). */
|
|
237
514
|
s: number;
|
|
238
|
-
/**
|
|
239
|
-
|
|
515
|
+
/** Canonical tone (0–1, reference eps). */
|
|
516
|
+
t: number;
|
|
240
517
|
/** Opacity (0–1). Default: 1. */
|
|
241
518
|
alpha: number;
|
|
519
|
+
/**
|
|
520
|
+
* Effective `pastel` flag used while resolving this variant (author def or
|
|
521
|
+
* config fallback). Carried on the variant so output formatting matches the
|
|
522
|
+
* gamut mapping applied during resolution.
|
|
523
|
+
*/
|
|
524
|
+
pastel?: boolean;
|
|
242
525
|
}
|
|
243
526
|
/** Fully resolved color across all scheme variants. */
|
|
244
527
|
interface ResolvedColor {
|
|
@@ -250,65 +533,428 @@ interface ResolvedColor {
|
|
|
250
533
|
/** Adaptation mode. Present only for regular colors, omitted for shadows. */
|
|
251
534
|
mode?: AdaptationMode;
|
|
252
535
|
}
|
|
536
|
+
/**
|
|
537
|
+
* A scheme tone window.
|
|
538
|
+
* - `[lo, hi]`: OKHSL-lightness endpoints (0–100) the authored tone is
|
|
539
|
+
* remapped into, using the reference eps `0.05`. The common form.
|
|
540
|
+
* - `{ lo, hi, eps }`: same, with an explicit render curvature `eps`
|
|
541
|
+
* (advanced — most palettes never need this).
|
|
542
|
+
* - `false`: disable clamping (full range `[0, 100]` at the reference eps).
|
|
543
|
+
* This removes the *boundaries*, not the tone curve.
|
|
544
|
+
*/
|
|
545
|
+
type ToneWindow = false | [number, number] | {
|
|
546
|
+
lo: number;
|
|
547
|
+
hi: number;
|
|
548
|
+
eps: number;
|
|
549
|
+
};
|
|
253
550
|
interface GlazeConfig {
|
|
254
|
-
/** Light scheme
|
|
255
|
-
|
|
256
|
-
/** Dark scheme
|
|
257
|
-
|
|
551
|
+
/** Light scheme tone window — `[lo, hi]` (default `[10, 100]`), `{ lo, hi, eps }` for advanced eps tuning, or `false` to disable clamping. */
|
|
552
|
+
lightTone?: ToneWindow;
|
|
553
|
+
/** Dark scheme tone window — `[lo, hi]` (default `[15, 95]`), `{ lo, hi, eps }`, or `false` to disable clamping. */
|
|
554
|
+
darkTone?: ToneWindow;
|
|
258
555
|
/** Saturation reduction factor for dark scheme (0–1). Default: 0.1. */
|
|
259
556
|
darkDesaturation?: number;
|
|
260
557
|
/**
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
* Accepts [normal, highContrast] pair for separate HC tuning.
|
|
558
|
+
* State alias names for Tasty token export. Default to media-query states
|
|
559
|
+
* (`'@media(prefers-color-scheme: dark)'` / `'@media(prefers-contrast: more)'`)
|
|
560
|
+
* so tokens react to the OS preference without registering custom states.
|
|
265
561
|
*/
|
|
266
|
-
darkCurve?: HCPair<number>;
|
|
267
|
-
/** State alias names for token export. */
|
|
268
562
|
states?: {
|
|
269
563
|
dark?: string;
|
|
270
564
|
highContrast?: string;
|
|
271
565
|
};
|
|
272
|
-
/**
|
|
566
|
+
/**
|
|
567
|
+
* Which scheme variants to include in exports. Defaults: `dark: true`,
|
|
568
|
+
* `highContrast: false`.
|
|
569
|
+
*/
|
|
273
570
|
modes?: GlazeOutputModes;
|
|
274
571
|
/** Default tuning for all shadow colors. Per-color tuning merges field-by-field. */
|
|
275
572
|
shadowTuning?: ShadowTuning;
|
|
573
|
+
/**
|
|
574
|
+
* Manual contrast level — a 0–100 slider from normal contrast (`0`) to high
|
|
575
|
+
* contrast (`100`), or `'auto'` (the default) to keep the two-tier
|
|
576
|
+
* normal + high-contrast model.
|
|
577
|
+
*
|
|
578
|
+
* With a number, Glaze resolves the `light` / `dark` variants *at* that
|
|
579
|
+
* level and stops emitting a separate high-contrast tier:
|
|
580
|
+
* `lightContrast` / `darkContrast` mirror their normal counterparts and
|
|
581
|
+
* `modes.highContrast` defaults to `false`. Level `0` is therefore "normal
|
|
582
|
+
* contrast, no high-contrast tier"; `100` is "the high-contrast scheme as
|
|
583
|
+
* the only scheme".
|
|
584
|
+
*
|
|
585
|
+
* The level interpolates all three things that make high contrast differ:
|
|
586
|
+
* authored `[normal, highContrast]` pairs, the tone-window widening, and
|
|
587
|
+
* the `AA → AAA` / APCA `+15 Lc` escalation. Contrast floors are re-solved
|
|
588
|
+
* at the interpolated target, so every level is a solution rather than an
|
|
589
|
+
* approximation, and a color keeps to one side of its base as the level moves.
|
|
590
|
+
*
|
|
591
|
+
* Pass `'auto'` to leave manual mode; `configure()` never clears a field by
|
|
592
|
+
* omission. See `docs/api.md` for the ramp's edge cases (un-interpolable
|
|
593
|
+
* pairs, side changes) and the export-freeze rule.
|
|
594
|
+
*
|
|
595
|
+
* @default 'auto'
|
|
596
|
+
*/
|
|
597
|
+
contrastLevel?: number | 'auto';
|
|
598
|
+
/**
|
|
599
|
+
* Automatically flip tone direction when contrast can't be met.
|
|
600
|
+
*
|
|
601
|
+
* When enabled (default `true`), the solver searches the requested
|
|
602
|
+
* tone direction first. If that direction can't reach the target,
|
|
603
|
+
* it tries the opposite direction and uses it when it passes. If neither
|
|
604
|
+
* side passes, the tone is pinned to the requested-direction
|
|
605
|
+
* extreme and a warning is emitted.
|
|
606
|
+
*
|
|
607
|
+
* Set to `false` for strict "no flip" behavior. The opposite
|
|
608
|
+
* direction is never considered: if the requested direction can't
|
|
609
|
+
* meet the target, the tone is pinned to its extreme (never
|
|
610
|
+
* falls back to the originally requested tone).
|
|
611
|
+
*/
|
|
612
|
+
autoFlip?: boolean;
|
|
613
|
+
/**
|
|
614
|
+
* If true (default), infer a color's `role` from its name when no explicit
|
|
615
|
+
* `role` is set. Set to `false` to opt out of name-based inference (the
|
|
616
|
+
* base-opposite and default-foreground fallbacks still apply).
|
|
617
|
+
* @default true
|
|
618
|
+
*/
|
|
619
|
+
inferRole?: boolean;
|
|
276
620
|
}
|
|
277
621
|
interface GlazeConfigResolved {
|
|
278
|
-
|
|
279
|
-
|
|
622
|
+
lightTone: ToneWindow;
|
|
623
|
+
darkTone: ToneWindow;
|
|
280
624
|
darkDesaturation: number;
|
|
281
|
-
darkCurve: HCPair<number>;
|
|
282
625
|
states: {
|
|
283
626
|
dark: string;
|
|
284
627
|
highContrast: string;
|
|
285
628
|
};
|
|
286
629
|
modes: Required<GlazeOutputModes>;
|
|
287
630
|
shadowTuning?: ShadowTuning;
|
|
631
|
+
autoFlip: boolean;
|
|
632
|
+
/**
|
|
633
|
+
* Manual contrast level (0–100), or `'auto'` for the two-tier
|
|
634
|
+
* normal + high-contrast model.
|
|
635
|
+
* @see GlazeConfig.contrastLevel
|
|
636
|
+
*/
|
|
637
|
+
contrastLevel: number | 'auto';
|
|
638
|
+
/**
|
|
639
|
+
* Instance-level pastel default (`def.pastel ?? config.pastel`).
|
|
640
|
+
* Not set via `glaze.configure()` — only via per-theme / per-token
|
|
641
|
+
* `GlazeConfigOverride` (default `false`).
|
|
642
|
+
*/
|
|
643
|
+
pastel: boolean;
|
|
644
|
+
inferRole: boolean;
|
|
288
645
|
}
|
|
646
|
+
/**
|
|
647
|
+
* Per-instance config override for `glaze.color()` and `glaze()` themes.
|
|
648
|
+
* Fields that are set take priority over the live global config. Fields
|
|
649
|
+
* that are omitted fall through to the live global at resolve time
|
|
650
|
+
* (`pastel` is instance-only and defaults to `false` when omitted).
|
|
651
|
+
*
|
|
652
|
+
* `false` for a tone window disables clamping (full range at reference eps).
|
|
653
|
+
*/
|
|
654
|
+
interface GlazeConfigOverride {
|
|
655
|
+
/** Light scheme tone window, or `false` to disable clamping. */
|
|
656
|
+
lightTone?: ToneWindow;
|
|
657
|
+
/** Dark scheme tone window, or `false` to disable clamping. */
|
|
658
|
+
darkTone?: ToneWindow;
|
|
659
|
+
/** Saturation reduction factor for dark scheme (0–1). */
|
|
660
|
+
darkDesaturation?: number;
|
|
661
|
+
/** Whether to auto-flip tone when contrast can't be met. */
|
|
662
|
+
autoFlip?: boolean;
|
|
663
|
+
/**
|
|
664
|
+
* Manual contrast level (0–100) for this instance, or `'auto'` to opt out
|
|
665
|
+
* of a global level and keep the two-tier normal + high-contrast model.
|
|
666
|
+
*
|
|
667
|
+
* Only an instance-authored level is frozen into `.export()` snapshots — a
|
|
668
|
+
* level inherited from the global config is treated as a live preference and
|
|
669
|
+
* re-read at restore time.
|
|
670
|
+
*
|
|
671
|
+
* @see GlazeConfig.contrastLevel
|
|
672
|
+
*/
|
|
673
|
+
contrastLevel?: number | 'auto';
|
|
674
|
+
/**
|
|
675
|
+
* Instance-level pastel default for colors that omit per-color `pastel`.
|
|
676
|
+
* Not available on `glaze.configure()` — set here or per-color.
|
|
677
|
+
* @default false
|
|
678
|
+
*/
|
|
679
|
+
pastel?: boolean;
|
|
680
|
+
/**
|
|
681
|
+
* If true, infer a color's `role` from its name when no explicit `role` is
|
|
682
|
+
* set. Falls through to the live global at resolve time when omitted.
|
|
683
|
+
*/
|
|
684
|
+
inferRole?: boolean;
|
|
685
|
+
/**
|
|
686
|
+
* Shadow tuning defaults. Only meaningful for themes; harmless on
|
|
687
|
+
* standalone color tokens.
|
|
688
|
+
*/
|
|
689
|
+
shadowTuning?: ShadowTuning;
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Current authoring-export schema version. Bump when the export shape
|
|
693
|
+
* changes in a non-compatible way. Written on every `.export()` snapshot.
|
|
694
|
+
*/
|
|
695
|
+
declare const GLAZE_EXPORT_VERSION: 1;
|
|
696
|
+
/** Literal type of {@link GLAZE_EXPORT_VERSION}. */
|
|
697
|
+
type GlazeExportVersion = typeof GLAZE_EXPORT_VERSION;
|
|
698
|
+
/** Discriminator for authoring export snapshots. */
|
|
699
|
+
type GlazeExportKind = 'theme' | 'color' | 'palette';
|
|
289
700
|
/** Serialized theme configuration (no resolved values). */
|
|
290
701
|
interface GlazeThemeExport {
|
|
702
|
+
/** Snapshot kind. Always written by `theme.export()`; optional on legacy hand-written configs. */
|
|
703
|
+
kind?: 'theme';
|
|
704
|
+
/** Schema version. Always written by `theme.export()`; optional on legacy configs. */
|
|
705
|
+
version?: number;
|
|
291
706
|
hue: number;
|
|
292
707
|
saturation: number;
|
|
708
|
+
/** Dark-scheme seed hue (0–360). Omitted when the theme reuses `hue`. */
|
|
709
|
+
darkHue?: number;
|
|
710
|
+
/** Dark-scheme seed saturation (0–100). Omitted when the theme reuses `saturation`. */
|
|
711
|
+
darkSaturation?: number;
|
|
293
712
|
colors: ColorMap;
|
|
713
|
+
/**
|
|
714
|
+
* Effective config freeze from `.export()` —
|
|
715
|
+
* `getConfig() ∪ instance local ∪ exportArg`. May be sparse on legacy
|
|
716
|
+
* snapshots (omitted fields fall through to the live global at restore).
|
|
717
|
+
*/
|
|
718
|
+
config?: GlazeConfigOverride;
|
|
294
719
|
}
|
|
295
720
|
/** Input for `glaze.shadow()` standalone factory. */
|
|
296
721
|
interface GlazeShadowInput {
|
|
297
|
-
/**
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
722
|
+
/**
|
|
723
|
+
* Background color — accepts any `GlazeColorValue` form: hex
|
|
724
|
+
* (`#rgb` / `#rrggbb` / `#rrggbbaa`), `rgb()` / `hsl()` / `okhsl()`
|
|
725
|
+
* / `oklch()` strings, or literal objects (`{ r, g, b }`, `{ h, s, l }`,
|
|
726
|
+
* `{ l, c, h }`). Alpha components are dropped with a warning.
|
|
727
|
+
*/
|
|
728
|
+
bg: GlazeColorValue;
|
|
729
|
+
/**
|
|
730
|
+
* Foreground color for tinting + intensity modulation. Accepts the
|
|
731
|
+
* same forms as `bg`.
|
|
732
|
+
*/
|
|
733
|
+
fg?: GlazeColorValue;
|
|
301
734
|
/** Intensity 0-100. */
|
|
302
735
|
intensity: number;
|
|
303
736
|
tuning?: ShadowTuning;
|
|
304
737
|
}
|
|
305
|
-
/** Input for `glaze.color()`
|
|
738
|
+
/** Input for the structured `glaze.color()` overload. */
|
|
306
739
|
interface GlazeColorInput {
|
|
307
740
|
hue: number;
|
|
308
741
|
saturation: number;
|
|
309
|
-
|
|
742
|
+
tone: HCPair<number | ExtremeValue>;
|
|
743
|
+
saturationFactor?: number;
|
|
744
|
+
/**
|
|
745
|
+
* Dark-scheme hue. Number is absolute (0–360); `'+N'`/`'-N'` is relative
|
|
746
|
+
* to the dark seed hue, which defaults to `hue`. Falls back to `hue`.
|
|
747
|
+
*/
|
|
748
|
+
darkHue?: number | RelativeValue;
|
|
749
|
+
/** Dark-scheme seed saturation (0–100). Defaults to `saturation`. */
|
|
750
|
+
darkSaturation?: number;
|
|
751
|
+
/** Dark-scheme multiplier on the dark seed (0–1). Defaults to `saturationFactor`. */
|
|
752
|
+
darkSaturationFactor?: number;
|
|
753
|
+
mode?: AdaptationMode;
|
|
754
|
+
/** Flip out-of-bounds results instead of clamping. Default: global `autoFlip`. */
|
|
755
|
+
autoFlip?: boolean;
|
|
756
|
+
/**
|
|
757
|
+
* Fixed opacity (0–1). Output includes alpha in the CSS value.
|
|
758
|
+
* Combining with `contrast` is not recommended (perceived tone
|
|
759
|
+
* becomes unpredictable) — a `console.warn` is emitted in that case.
|
|
760
|
+
*/
|
|
761
|
+
opacity?: number;
|
|
762
|
+
/**
|
|
763
|
+
* Optional dependency on another color. Same semantics as
|
|
764
|
+
* `GlazeColorOverrides.base` — `contrast` and relative `tone`
|
|
765
|
+
* anchor to the base per scheme.
|
|
766
|
+
*/
|
|
767
|
+
base?: GlazeColorToken | GlazeColorValue;
|
|
768
|
+
/**
|
|
769
|
+
* Contrast floor against `base`. Requires `base` to be set. A bare
|
|
770
|
+
* number/preset is WCAG; use `{ wcag }` / `{ apca }` to pick the metric.
|
|
771
|
+
*/
|
|
772
|
+
contrast?: HCPair<ContrastSpec>;
|
|
773
|
+
/**
|
|
774
|
+
* Optional human-readable name for the token. Used in error and
|
|
775
|
+
* warning messages (otherwise an internal name like `"value"` is
|
|
776
|
+
* used). Does not affect output keys.
|
|
777
|
+
*/
|
|
778
|
+
name?: string;
|
|
779
|
+
/**
|
|
780
|
+
* Per-color override for the hue-independent "safe" chroma limit used in
|
|
781
|
+
* OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
|
|
782
|
+
* Falls through to the per-theme / per-token `pastel` override when omitted.
|
|
783
|
+
* @see GlazeConfigOverride.pastel
|
|
784
|
+
*/
|
|
785
|
+
pastel?: boolean;
|
|
786
|
+
/**
|
|
787
|
+
* Semantic role against `base` / the literal seed: how this token is used.
|
|
788
|
+
* Fixes APCA contrast polarity. Same resolution chain as
|
|
789
|
+
* `RegularColorDef.role` (explicit → name inference → opposite of base →
|
|
790
|
+
* `'text'`). For standalone tokens the name is internal, so set `role`
|
|
791
|
+
* explicitly or rely on the base-opposite / foreground default.
|
|
792
|
+
*/
|
|
793
|
+
role?: RoleInput;
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Any single-color input form accepted by the value-shorthand
|
|
797
|
+
* overload of `glaze.color()`.
|
|
798
|
+
*
|
|
799
|
+
* Strings cover hex (`#rgb` / `#rrggbb` / `#rrggbbaa`, alpha dropped
|
|
800
|
+
* with a warning) and the four CSS color functions Glaze itself emits:
|
|
801
|
+
* `rgb()`, `hsl()`, `okhsl()`, `oklch()` (alpha components also dropped
|
|
802
|
+
* with a warning).
|
|
803
|
+
*
|
|
804
|
+
* Literal object forms:
|
|
805
|
+
* - `{ h, s, l }` — OKHSL (h: 0–360, s/l: 0–1). Passing 0–100 for `s`/`l`
|
|
806
|
+
* throws with a hint to use the structured form.
|
|
807
|
+
* - `{ h, s, t }` — OKHST (h: 0–360, s/t: 0–1). Tone in 0–1.
|
|
808
|
+
* - `{ r, g, b }` — sRGB 0–255.
|
|
809
|
+
* - `{ l, c, h }` — OKLCh (L/C: 0–1, H: degrees), same as `oklch()` strings.
|
|
810
|
+
*/
|
|
811
|
+
type GlazeColorValue = string | OkhslColor | OkhstColor | RgbColor | OklchColor;
|
|
812
|
+
/** Color overrides for the `from` and value-shorthand inputs. */
|
|
813
|
+
interface GlazeColorOverrides {
|
|
814
|
+
/**
|
|
815
|
+
* Override hue. Number is absolute (0–360); `'+N'`/`'-N'` is relative
|
|
816
|
+
* to the extracted (or overridden) seed hue — same semantics as
|
|
817
|
+
* `RegularColorDef.hue`.
|
|
818
|
+
*/
|
|
819
|
+
hue?: number | RelativeValue;
|
|
820
|
+
/** Override seed saturation (0–100). Default: extracted from value. */
|
|
821
|
+
saturation?: number;
|
|
822
|
+
/**
|
|
823
|
+
* Dark-scheme hue. Number is absolute (0–360); `'+N'`/`'-N'` is relative
|
|
824
|
+
* to the dark seed hue, which defaults to the (possibly overridden) seed
|
|
825
|
+
* hue. Falls back to `hue` when omitted.
|
|
826
|
+
*/
|
|
827
|
+
darkHue?: number | RelativeValue;
|
|
828
|
+
/**
|
|
829
|
+
* Dark-scheme seed saturation (0–100). Defaults to `saturation`. When set,
|
|
830
|
+
* the global `darkDesaturation` reduction is not applied on top.
|
|
831
|
+
*/
|
|
832
|
+
darkSaturation?: number;
|
|
833
|
+
/**
|
|
834
|
+
* Dark-scheme multiplier on the dark seed (0–1). Defaults to
|
|
835
|
+
* `saturationFactor`. When set, the global `darkDesaturation` reduction is
|
|
836
|
+
* not applied on top.
|
|
837
|
+
*/
|
|
838
|
+
darkSaturationFactor?: number;
|
|
839
|
+
/**
|
|
840
|
+
* Override tone. Number is absolute (0–100, contrast-uniform); `'+N'`/`'-N'`
|
|
841
|
+
* is relative to the literal seed (the value passed to `glaze.color()`);
|
|
842
|
+
* `'max'` / `'min'` force to the scheme's tone extreme.
|
|
843
|
+
* Supports HCPair for high-contrast.
|
|
844
|
+
*/
|
|
845
|
+
tone?: HCPair<ToneValue>;
|
|
846
|
+
/** Saturation multiplier on the seed (0–1). Default: 1. */
|
|
310
847
|
saturationFactor?: number;
|
|
848
|
+
/**
|
|
849
|
+
* Adaptation mode. Defaults to `'auto'` for every input form, so
|
|
850
|
+
* colors automatically adapt between light and dark like an ordinary
|
|
851
|
+
* theme color. Value-shorthand inputs (strings and literal objects)
|
|
852
|
+
* preserve light tone via a local `lightTone: false` default; other
|
|
853
|
+
* omitted config fields fall through to the live global at resolve
|
|
854
|
+
* time. Structured `{ hue, saturation, tone }` form also falls
|
|
855
|
+
* through for both tone windows unless overridden.
|
|
856
|
+
*
|
|
857
|
+
* Pass `'fixed'` explicitly to opt back into the linear, non-
|
|
858
|
+
* inverting mapping; pass `'static'` to pin the same tone
|
|
859
|
+
* across every variant.
|
|
860
|
+
*/
|
|
311
861
|
mode?: AdaptationMode;
|
|
862
|
+
/**
|
|
863
|
+
* Flip out-of-bounds results (relative `tone` overshoot / unmet
|
|
864
|
+
* `contrast`) to the opposite side instead of clamping. Defaults to
|
|
865
|
+
* the global `autoFlip`.
|
|
866
|
+
*/
|
|
867
|
+
autoFlip?: boolean;
|
|
868
|
+
/**
|
|
869
|
+
* Contrast floor. By default solved against the literal seed
|
|
870
|
+
* (the value itself); when `base` is set, solved against the base's
|
|
871
|
+
* resolved variant per scheme. Same shape as `RegularColorDef.contrast`
|
|
872
|
+
* (bare number/preset = WCAG; `{ wcag }` / `{ apca }` to pick the metric).
|
|
873
|
+
*/
|
|
874
|
+
contrast?: HCPair<ContrastSpec>;
|
|
875
|
+
/**
|
|
876
|
+
* Optional dependency on another color. Accepts either a
|
|
877
|
+
* `GlazeColorToken` (returned by another `glaze.color()`) or a raw
|
|
878
|
+
* `GlazeColorValue` (hex / CSS strings / `{ r, g, b }` / `{ h, s, l }` / …),
|
|
879
|
+
* which is automatically wrapped in `glaze.color(value)`.
|
|
880
|
+
*
|
|
881
|
+
* When set:
|
|
882
|
+
* - `contrast` is solved against the base's resolved variant
|
|
883
|
+
* per-scheme (light / dark / lightContrast / darkContrast).
|
|
884
|
+
* - Relative `tone: '+N'` / `'-N'` is anchored to the base's
|
|
885
|
+
* tone per-scheme (matches theme behavior for dependent colors).
|
|
886
|
+
* - Relative `hue: '+N'` / `'-N'` still anchors to the seed (the
|
|
887
|
+
* value passed to `glaze.color()`), not the base.
|
|
888
|
+
* - When the base was created via the structured form (with explicit
|
|
889
|
+
* `hue`/`saturation`/`tone`), it is resolved at full range
|
|
890
|
+
* (`lightTone: false`) for the linking math — ensuring the
|
|
891
|
+
* contrast/tone anchor matches the input tone, not the
|
|
892
|
+
* windowed output. The base's own `.resolve()` output is unaffected.
|
|
893
|
+
*
|
|
894
|
+
* The base token's `.resolve()` is called lazily on first resolve and
|
|
895
|
+
* its result is captured by reference; later mutations to the base's
|
|
896
|
+
* defining call don't apply (matches existing token snapshot semantics).
|
|
897
|
+
*/
|
|
898
|
+
base?: GlazeColorToken | GlazeColorValue;
|
|
899
|
+
/**
|
|
900
|
+
* Fixed opacity (0–1). Output includes alpha in the CSS value.
|
|
901
|
+
* Combining with `contrast` is not recommended (perceived tone
|
|
902
|
+
* becomes unpredictable) — a `console.warn` is emitted in that case.
|
|
903
|
+
*/
|
|
904
|
+
opacity?: number;
|
|
905
|
+
/**
|
|
906
|
+
* Optional human-readable name for the token. Used in error and
|
|
907
|
+
* warning messages (otherwise an internal name like `"value"` is
|
|
908
|
+
* used). Does not affect output keys.
|
|
909
|
+
*/
|
|
910
|
+
name?: string;
|
|
911
|
+
/**
|
|
912
|
+
* Per-color override for the hue-independent "safe" chroma limit used in
|
|
913
|
+
* OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
|
|
914
|
+
* Falls through to the per-theme / per-token `pastel` override when omitted.
|
|
915
|
+
* @see GlazeConfigOverride.pastel
|
|
916
|
+
*/
|
|
917
|
+
pastel?: boolean;
|
|
918
|
+
/**
|
|
919
|
+
* Semantic role against `base` / the literal seed: how this token is used.
|
|
920
|
+
* Fixes APCA contrast polarity. Same resolution chain as
|
|
921
|
+
* `RegularColorDef.role`.
|
|
922
|
+
*/
|
|
923
|
+
role?: RoleInput;
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Object input for `glaze.color()` that carries a raw color value plus
|
|
927
|
+
* optional color overrides in the same object.
|
|
928
|
+
*
|
|
929
|
+
* ```ts
|
|
930
|
+
* glaze.color({ from: '#1a1a2e', base: bg, contrast: 'AA' })
|
|
931
|
+
* glaze.color({ from: { r: 38, g: 252, b: 178 }, tone: '+10' })
|
|
932
|
+
* ```
|
|
933
|
+
*/
|
|
934
|
+
interface GlazeFromInput extends GlazeColorOverrides {
|
|
935
|
+
/** The source color value. Accepts the same forms as a bare `GlazeColorValue`. */
|
|
936
|
+
from: GlazeColorValue;
|
|
937
|
+
}
|
|
938
|
+
/** Options for `GlazeColorToken.css()`. */
|
|
939
|
+
interface GlazeColorCssOptions {
|
|
940
|
+
/**
|
|
941
|
+
* Custom property base name (without leading `--`). Required.
|
|
942
|
+
* Becomes the variable identifier in the output, e.g.
|
|
943
|
+
* `name: 'brand'` → `--brand-color: …`.
|
|
944
|
+
*/
|
|
945
|
+
name: string;
|
|
946
|
+
/** Output color format. Default: 'oklch'. */
|
|
947
|
+
format?: GlazeColorFormat;
|
|
948
|
+
/**
|
|
949
|
+
* Suffix appended to the name. Default: '-color' (matches
|
|
950
|
+
* `theme.css` default).
|
|
951
|
+
*/
|
|
952
|
+
suffix?: string;
|
|
953
|
+
/**
|
|
954
|
+
* Emit hue as a separate custom property, referenced via `var()`.
|
|
955
|
+
* Requires `format: 'oklch'` and a pastel token. oklch + all-pastel only.
|
|
956
|
+
*/
|
|
957
|
+
splitHue?: boolean;
|
|
312
958
|
}
|
|
313
959
|
/** Return type for `glaze.color()`. */
|
|
314
960
|
interface GlazeColorToken {
|
|
@@ -318,18 +964,156 @@ interface GlazeColorToken {
|
|
|
318
964
|
token(options?: GlazeTokenOptions): Record<string, string>;
|
|
319
965
|
/**
|
|
320
966
|
* Export as a tasty style-to-state binding (no color name key).
|
|
321
|
-
* Uses `#name` keys and state aliases (`''`,
|
|
322
|
-
* @see https://
|
|
967
|
+
* Uses `#name` keys and state aliases (`''`, `'@media(prefers-color-scheme: dark)'`, etc.).
|
|
968
|
+
* @see https://tasty.style/docs
|
|
323
969
|
*/
|
|
324
970
|
tasty(options?: GlazeTokenOptions): Record<string, string>;
|
|
325
971
|
/** Export as a flat JSON map (no color name key). */
|
|
326
972
|
json(options?: GlazeJsonOptions): Record<string, string>;
|
|
973
|
+
/** Export as CSS custom property declarations grouped by scheme variant. */
|
|
974
|
+
css(options: GlazeColorCssOptions): GlazeCssResult;
|
|
975
|
+
/**
|
|
976
|
+
* Export as W3C DTCG color tokens (one per scheme variant, no color name
|
|
977
|
+
* key). Each entry is a full `{ $type: 'color', $value }` token.
|
|
978
|
+
* @see https://www.designtokens.org/
|
|
979
|
+
*/
|
|
980
|
+
dtcg(options?: GlazeDtcgOptions): GlazeColorDtcgResult;
|
|
981
|
+
/**
|
|
982
|
+
* Export as a single W3C DTCG Resolver-Module document for this color,
|
|
983
|
+
* keyed by `name` across all scheme variants. `name` is required.
|
|
984
|
+
* @see https://www.designtokens.org/
|
|
985
|
+
*/
|
|
986
|
+
dtcgResolver(options: GlazeColorDtcgResolverOptions): GlazeDtcgResolverDocument;
|
|
987
|
+
/**
|
|
988
|
+
* Export as a Tailwind CSS v4 `@theme` block (light baseline) plus dark /
|
|
989
|
+
* high-contrast overrides. Returns a single ready-to-paste CSS string.
|
|
990
|
+
* `name` is required (forms `--color-<name>`).
|
|
991
|
+
* @see https://tailwindcss.com/docs/theme
|
|
992
|
+
*/
|
|
993
|
+
tailwind(options: GlazeColorTailwindOptions): string;
|
|
994
|
+
/**
|
|
995
|
+
* Serialize the token as a JSON-safe object. Captures the original
|
|
996
|
+
* input value, overrides, and config so it can be rehydrated via
|
|
997
|
+
* `glaze.colorFrom(...)`. `base` is recursively serialized.
|
|
998
|
+
* Optional `override` is merged over the instance local at export time.
|
|
999
|
+
*/
|
|
1000
|
+
export(override?: GlazeConfigOverride): GlazeColorTokenExport;
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* JSON-safe serialization of a `glaze.color()` token. Pass to
|
|
1004
|
+
* `glaze.colorFrom(...)` to rehydrate.
|
|
1005
|
+
*/
|
|
1006
|
+
interface GlazeColorTokenExport {
|
|
1007
|
+
/** Snapshot kind. Always written by `token.export()`; optional on legacy snapshots. */
|
|
1008
|
+
kind?: 'color';
|
|
1009
|
+
/** Schema version. Always written by `token.export()`; optional on legacy snapshots. */
|
|
1010
|
+
version?: number;
|
|
1011
|
+
/**
|
|
1012
|
+
* Discriminator for the source overload that created the token.
|
|
1013
|
+
* - `'value'`: created via `glaze.color(value)` or `glaze.color({ from, ...overrides })`.
|
|
1014
|
+
* - `'structured'`: created via `glaze.color({ hue, saturation, ... })`.
|
|
1015
|
+
*/
|
|
1016
|
+
form: 'value' | 'structured';
|
|
1017
|
+
/** Original input. For `form: 'value'` this is the raw `GlazeColorValue`; for `form: 'structured'` this is the structured input. */
|
|
1018
|
+
input: GlazeColorValue | GlazeColorInputExport;
|
|
1019
|
+
/**
|
|
1020
|
+
* Overrides recorded at creation time. `base` is recursively
|
|
1021
|
+
* serialized. Only present for `form: 'value'`.
|
|
1022
|
+
*/
|
|
1023
|
+
overrides?: GlazeColorOverridesExport;
|
|
1024
|
+
/**
|
|
1025
|
+
* Effective config freeze from `.export()` — `getConfig() ∪ local ∪
|
|
1026
|
+
* exportArg` at call time. Used by `glaze.colorFrom()` to pin
|
|
1027
|
+
* deterministic behavior across later `configure()` calls.
|
|
1028
|
+
*/
|
|
1029
|
+
config?: GlazeConfigOverride;
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* JSON-safe serialization of a `glaze.palette()` composition.
|
|
1033
|
+
* Pass to `glaze.paletteFrom(...)` to rehydrate.
|
|
1034
|
+
*/
|
|
1035
|
+
interface GlazePaletteExport {
|
|
1036
|
+
/** Snapshot kind. Always written by `palette.export()`. */
|
|
1037
|
+
kind?: 'palette';
|
|
1038
|
+
/** Schema version. Always written by `palette.export()`. */
|
|
1039
|
+
version?: number;
|
|
1040
|
+
/** Per-theme authoring snapshots keyed by theme name. */
|
|
1041
|
+
themes: Record<string, GlazeThemeExport>;
|
|
1042
|
+
/** Primary theme name, if set on the palette. */
|
|
1043
|
+
primary?: string;
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Serializable shape of a structured `glaze.color({...})` input.
|
|
1047
|
+
* Differs from `GlazeColorInput` only in that `base` is replaced by an
|
|
1048
|
+
* `export` instead of a token reference.
|
|
1049
|
+
*/
|
|
1050
|
+
interface GlazeColorInputExport {
|
|
1051
|
+
hue: number;
|
|
1052
|
+
saturation: number;
|
|
1053
|
+
tone: HCPair<number | ExtremeValue>;
|
|
1054
|
+
saturationFactor?: number;
|
|
1055
|
+
darkHue?: number | RelativeValue;
|
|
1056
|
+
darkSaturation?: number;
|
|
1057
|
+
darkSaturationFactor?: number;
|
|
1058
|
+
mode?: AdaptationMode;
|
|
1059
|
+
autoFlip?: boolean;
|
|
1060
|
+
opacity?: number;
|
|
1061
|
+
base?: GlazeColorTokenExport | GlazeColorValue;
|
|
1062
|
+
contrast?: HCPair<ContrastSpec>;
|
|
1063
|
+
name?: string;
|
|
1064
|
+
pastel?: boolean;
|
|
1065
|
+
role?: RoleInput;
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* Serializable shape of `GlazeColorOverrides`. `base` is replaced by
|
|
1069
|
+
* its export (or left as a `GlazeColorValue` if it was originally a value).
|
|
1070
|
+
*/
|
|
1071
|
+
interface GlazeColorOverridesExport {
|
|
1072
|
+
hue?: number | RelativeValue;
|
|
1073
|
+
saturation?: number;
|
|
1074
|
+
darkHue?: number | RelativeValue;
|
|
1075
|
+
darkSaturation?: number;
|
|
1076
|
+
darkSaturationFactor?: number;
|
|
1077
|
+
tone?: HCPair<ToneValue>;
|
|
1078
|
+
saturationFactor?: number;
|
|
1079
|
+
mode?: AdaptationMode;
|
|
1080
|
+
autoFlip?: boolean;
|
|
1081
|
+
contrast?: HCPair<ContrastSpec>;
|
|
1082
|
+
base?: GlazeColorTokenExport | GlazeColorValue;
|
|
1083
|
+
opacity?: number;
|
|
1084
|
+
name?: string;
|
|
1085
|
+
pastel?: boolean;
|
|
1086
|
+
role?: RoleInput;
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* The hue/saturation seed pair a theme resolves against.
|
|
1090
|
+
*
|
|
1091
|
+
* `darkHue` / `darkSaturation` are a separate seed for the `dark` and
|
|
1092
|
+
* `darkContrast` variants; each falls back to its light counterpart. Setting
|
|
1093
|
+
* `darkSaturation` opts the theme out of the global `darkDesaturation`
|
|
1094
|
+
* reduction — the authored value is used literally.
|
|
1095
|
+
*/
|
|
1096
|
+
interface GlazeThemeSeed {
|
|
1097
|
+
/** Light-scheme hue seed (0–360). */
|
|
1098
|
+
hue: number;
|
|
1099
|
+
/** Light-scheme saturation seed (0–100). */
|
|
1100
|
+
saturation: number;
|
|
1101
|
+
/** Dark-scheme hue seed (0–360). Defaults to `hue`. */
|
|
1102
|
+
darkHue?: number;
|
|
1103
|
+
/** Dark-scheme saturation seed (0–100). Defaults to `saturation`. */
|
|
1104
|
+
darkSaturation?: number;
|
|
327
1105
|
}
|
|
328
1106
|
interface GlazeTheme {
|
|
329
1107
|
/** The hue seed (0–360). */
|
|
330
1108
|
readonly hue: number;
|
|
331
1109
|
/** The saturation seed (0–100). */
|
|
332
1110
|
readonly saturation: number;
|
|
1111
|
+
/** The dark-scheme hue seed (0–360), or `undefined` when `hue` is reused. */
|
|
1112
|
+
readonly darkHue: number | undefined;
|
|
1113
|
+
/** The dark-scheme saturation seed (0–100), or `undefined` when `saturation` is reused. */
|
|
1114
|
+
readonly darkSaturation: number | undefined;
|
|
1115
|
+
/** The effective config for this theme. */
|
|
1116
|
+
getConfig(): GlazeConfigResolved;
|
|
333
1117
|
/** Add/replace colors (additive merge with existing definitions). */
|
|
334
1118
|
colors(defs: ColorMap): void;
|
|
335
1119
|
/** Get a color definition by name. */
|
|
@@ -345,7 +1129,7 @@ interface GlazeTheme {
|
|
|
345
1129
|
/** Clear all color definitions. */
|
|
346
1130
|
reset(): void;
|
|
347
1131
|
/** Export the theme configuration as a JSON-safe object. */
|
|
348
|
-
export(): GlazeThemeExport;
|
|
1132
|
+
export(override?: GlazeConfigOverride): GlazeThemeExport;
|
|
349
1133
|
/** Create a child theme inheriting all color definitions. */
|
|
350
1134
|
extend(options: GlazeExtendOptions): GlazeTheme;
|
|
351
1135
|
/** Resolve all colors and return the result map. */
|
|
@@ -361,20 +1145,47 @@ interface GlazeTheme {
|
|
|
361
1145
|
tokens(options?: GlazeJsonOptions): Record<string, Record<string, string>>;
|
|
362
1146
|
/**
|
|
363
1147
|
* Export as tasty style-to-state bindings.
|
|
364
|
-
* Uses `#name` color token keys and state aliases (`''`,
|
|
1148
|
+
* Uses `#name` color token keys and state aliases (`''`, `'@media(prefers-color-scheme: dark)'`, etc.).
|
|
365
1149
|
* Spread into component styles or register as a recipe via `configure({ recipes })`.
|
|
366
|
-
* @see https://
|
|
1150
|
+
* @see https://tasty.style/docs
|
|
367
1151
|
*/
|
|
368
1152
|
tasty(options?: GlazeTokenOptions): Record<string, Record<string, string>>;
|
|
369
1153
|
/** Export as plain JSON. */
|
|
370
1154
|
json(options?: GlazeJsonOptions): Record<string, Record<string, string>>;
|
|
371
1155
|
/** Export as CSS custom property declarations. */
|
|
372
1156
|
css(options?: GlazeCssOptions): GlazeCssResult;
|
|
1157
|
+
/**
|
|
1158
|
+
* Export as W3C Design Tokens Format Module (2025.10) documents, one per
|
|
1159
|
+
* scheme variant. Consumable by Figma, Tokens Studio, Style Dictionary,
|
|
1160
|
+
* Terrazzo, and any DTCG-compatible tool.
|
|
1161
|
+
* @see https://www.designtokens.org/
|
|
1162
|
+
*/
|
|
1163
|
+
dtcg(options?: GlazeDtcgOptions): GlazeDtcgResult;
|
|
1164
|
+
/**
|
|
1165
|
+
* Export as a single W3C DTCG Resolver-Module document describing every
|
|
1166
|
+
* scheme variant as one `sets` entry plus a single `scheme` modifier with a
|
|
1167
|
+
* context per variant. Consumable by resolver tools such as Dispersa.
|
|
1168
|
+
* @see https://www.designtokens.org/
|
|
1169
|
+
*/
|
|
1170
|
+
dtcgResolver(options?: GlazeDtcgResolverOptions): GlazeDtcgResolverDocument;
|
|
1171
|
+
/**
|
|
1172
|
+
* Export as a Tailwind CSS v4 `@theme` block (light baseline) plus dark /
|
|
1173
|
+
* high-contrast overrides under configurable selectors. Returns a single
|
|
1174
|
+
* ready-to-paste CSS string.
|
|
1175
|
+
* @see https://tailwindcss.com/docs/theme
|
|
1176
|
+
*/
|
|
1177
|
+
tailwind(options?: GlazeTailwindOptions): string;
|
|
373
1178
|
}
|
|
374
1179
|
interface GlazeExtendOptions {
|
|
375
1180
|
hue?: number;
|
|
376
1181
|
saturation?: number;
|
|
1182
|
+
/** Replace the dark-scheme hue seed (0–360). Defaults to the parent's. */
|
|
1183
|
+
darkHue?: number;
|
|
1184
|
+
/** Replace the dark-scheme saturation seed (0–100). Defaults to the parent's. */
|
|
1185
|
+
darkSaturation?: number;
|
|
377
1186
|
colors?: ColorMap;
|
|
1187
|
+
/** Config override for the child theme. Merged with the parent's override. */
|
|
1188
|
+
config?: GlazeConfigOverride;
|
|
378
1189
|
}
|
|
379
1190
|
interface GlazeTokenOptions {
|
|
380
1191
|
/** Prefix mode. `true` uses "<themeName>-", or provide a custom map. */
|
|
@@ -386,20 +1197,40 @@ interface GlazeTokenOptions {
|
|
|
386
1197
|
};
|
|
387
1198
|
/** Override which scheme variants to include. */
|
|
388
1199
|
modes?: GlazeOutputModes;
|
|
389
|
-
/** Output color format. Default: '
|
|
1200
|
+
/** Output color format. Default: 'oklch'. */
|
|
390
1201
|
format?: GlazeColorFormat;
|
|
1202
|
+
/**
|
|
1203
|
+
* Emit hue as a separate custom property, referenced via `var()`.
|
|
1204
|
+
* Requires `format: 'oklch'` and every color to be pastel.
|
|
1205
|
+
*/
|
|
1206
|
+
splitHue?: boolean;
|
|
1207
|
+
/**
|
|
1208
|
+
* Base name for the theme-level hue var (`--{name}-hue`). Default: `'theme'`.
|
|
1209
|
+
* Palette export auto-derives this from the theme name.
|
|
1210
|
+
*/
|
|
1211
|
+
name?: string;
|
|
391
1212
|
}
|
|
392
1213
|
interface GlazeJsonOptions {
|
|
393
1214
|
/** Override which scheme variants to include. */
|
|
394
1215
|
modes?: GlazeOutputModes;
|
|
395
|
-
/** Output color format. Default: '
|
|
1216
|
+
/** Output color format. Default: 'oklch'. */
|
|
396
1217
|
format?: GlazeColorFormat;
|
|
397
1218
|
}
|
|
398
1219
|
interface GlazeCssOptions {
|
|
399
|
-
/** Output color format. Default: '
|
|
1220
|
+
/** Output color format. Default: 'oklch'. */
|
|
400
1221
|
format?: GlazeColorFormat;
|
|
401
1222
|
/** Suffix appended to each CSS custom property name. Default: '-color'. */
|
|
402
1223
|
suffix?: string;
|
|
1224
|
+
/**
|
|
1225
|
+
* Emit hue as a separate custom property, referenced via `var()`.
|
|
1226
|
+
* Requires `format: 'oklch'` and every color to be pastel.
|
|
1227
|
+
*/
|
|
1228
|
+
splitHue?: boolean;
|
|
1229
|
+
/**
|
|
1230
|
+
* Base name for the theme-level hue var (`--{name}-hue`). Default: `'theme'`.
|
|
1231
|
+
* Palette export auto-derives this from the theme name.
|
|
1232
|
+
*/
|
|
1233
|
+
name?: string;
|
|
403
1234
|
}
|
|
404
1235
|
/** CSS custom property declarations grouped by scheme variant. */
|
|
405
1236
|
interface GlazeCssResult {
|
|
@@ -408,6 +1239,182 @@ interface GlazeCssResult {
|
|
|
408
1239
|
lightContrast: string;
|
|
409
1240
|
darkContrast: string;
|
|
410
1241
|
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Color space used for DTCG `$value` color objects.
|
|
1244
|
+
* @see https://www.designtokens.org/
|
|
1245
|
+
*/
|
|
1246
|
+
type DtcgColorSpace = 'srgb' | 'oklch';
|
|
1247
|
+
/**
|
|
1248
|
+
* A DTCG color `$value` in the sRGB color space: gamma sRGB components in
|
|
1249
|
+
* 0–1 plus a 6-digit `hex` hint. Universally understood by Figma, Tokens
|
|
1250
|
+
* Studio, Style Dictionary, and every DTCG reader.
|
|
1251
|
+
*/
|
|
1252
|
+
interface DtcgSrgbColorValue {
|
|
1253
|
+
colorSpace: 'srgb';
|
|
1254
|
+
components: [number, number, number];
|
|
1255
|
+
hex: HexColor;
|
|
1256
|
+
/** Opacity 0–1. Omitted when fully opaque (alpha = 1). */
|
|
1257
|
+
alpha?: number;
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* A DTCG color `$value` in the OKLCH color space: `[L, C, H]` components
|
|
1261
|
+
* (L/C: 0–1, H: degrees). Wide-gamut and Glaze-native; no `hex` is emitted.
|
|
1262
|
+
*/
|
|
1263
|
+
interface DtcgOklchColorValue {
|
|
1264
|
+
colorSpace: 'oklch';
|
|
1265
|
+
components: [number, number, number];
|
|
1266
|
+
/** Opacity 0–1. Omitted when fully opaque (alpha = 1). */
|
|
1267
|
+
alpha?: number;
|
|
1268
|
+
}
|
|
1269
|
+
/** A DTCG `$value` for a color token, in either supported color space. */
|
|
1270
|
+
type DtcgColorValue = DtcgSrgbColorValue | DtcgOklchColorValue;
|
|
1271
|
+
/**
|
|
1272
|
+
* A single W3C DTCG color token: `{ $type: 'color', $value }`.
|
|
1273
|
+
* `$description` is optional and not populated by Glaze today.
|
|
1274
|
+
*/
|
|
1275
|
+
interface DtcgColorToken {
|
|
1276
|
+
$type: 'color';
|
|
1277
|
+
$value: DtcgColorValue;
|
|
1278
|
+
$description?: string;
|
|
1279
|
+
}
|
|
1280
|
+
/**
|
|
1281
|
+
* A W3C Design Tokens Format Module (2025.10) token tree for one scheme.
|
|
1282
|
+
* Glaze emits one document per scheme variant — the most tool-compatible
|
|
1283
|
+
* convention (one file per Style Dictionary theme / Tokens Studio set /
|
|
1284
|
+
* Figma variable mode).
|
|
1285
|
+
*/
|
|
1286
|
+
type DtcgDocument = Record<string, DtcgColorToken>;
|
|
1287
|
+
/** DTCG token documents grouped by scheme variant. Light is always present. */
|
|
1288
|
+
interface GlazeDtcgResult {
|
|
1289
|
+
light: DtcgDocument;
|
|
1290
|
+
dark?: DtcgDocument;
|
|
1291
|
+
lightContrast?: DtcgDocument;
|
|
1292
|
+
darkContrast?: DtcgDocument;
|
|
1293
|
+
}
|
|
1294
|
+
/** A single DTCG color token grouped by scheme variant (standalone tokens). */
|
|
1295
|
+
interface GlazeColorDtcgResult {
|
|
1296
|
+
light: DtcgColorToken;
|
|
1297
|
+
dark?: DtcgColorToken;
|
|
1298
|
+
lightContrast?: DtcgColorToken;
|
|
1299
|
+
darkContrast?: DtcgColorToken;
|
|
1300
|
+
}
|
|
1301
|
+
/** Options for `theme.dtcg()` / `palette.dtcg()`. */
|
|
1302
|
+
interface GlazeDtcgOptions {
|
|
1303
|
+
/** Override which scheme variants to include. */
|
|
1304
|
+
modes?: GlazeOutputModes;
|
|
1305
|
+
/**
|
|
1306
|
+
* DTCG color space. `'srgb'` (default) emits sRGB components plus a `hex`
|
|
1307
|
+
* hint — universally understood (Figma, Tokens Studio). `'oklch'` emits
|
|
1308
|
+
* OKLCH components with no hex — Glaze-native, wide-gamut.
|
|
1309
|
+
*/
|
|
1310
|
+
colorSpace?: DtcgColorSpace;
|
|
1311
|
+
}
|
|
1312
|
+
/**
|
|
1313
|
+
* A node in a DTCG Resolver-Module token tree: either a leaf color token or a
|
|
1314
|
+
* nested group. A flat `DtcgDocument` (top-level color-name keys) is a valid
|
|
1315
|
+
* shallow tree, so Glaze's per-scheme documents slot directly into
|
|
1316
|
+
* `sets.<name>.sources` and `modifiers.<name>.contexts.<ctx>` entries.
|
|
1317
|
+
*/
|
|
1318
|
+
interface DtcgTokenTree {
|
|
1319
|
+
[key: string]: DtcgColorToken | DtcgTokenTree;
|
|
1320
|
+
}
|
|
1321
|
+
/** A named set in a resolver document: a list of token-tree sources. */
|
|
1322
|
+
interface DtcgResolverSet {
|
|
1323
|
+
sources: DtcgTokenTree[];
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* A named modifier (an axis such as `scheme`) in a resolver document.
|
|
1327
|
+
* `default` names the context applied when no override is selected; `contexts`
|
|
1328
|
+
* maps each context name to the token-tree overrides applied for it.
|
|
1329
|
+
*/
|
|
1330
|
+
interface DtcgResolverModifier {
|
|
1331
|
+
default: string;
|
|
1332
|
+
contexts: Record<string, DtcgTokenTree[]>;
|
|
1333
|
+
}
|
|
1334
|
+
/** A JSON-pointer `$ref` entry in a resolver document's `resolutionOrder`. */
|
|
1335
|
+
interface DtcgResolverRef {
|
|
1336
|
+
$ref: string;
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* A W3C DTCG Resolver-Module document. Describes every scheme variant in a
|
|
1340
|
+
* single file as `sets` (base token sources) plus `modifiers` (per-context
|
|
1341
|
+
* overrides) composed in `resolutionOrder`. Consumable by resolver tools such
|
|
1342
|
+
* as Dispersa.
|
|
1343
|
+
* @see https://www.designtokens.org/
|
|
1344
|
+
*/
|
|
1345
|
+
interface GlazeDtcgResolverDocument {
|
|
1346
|
+
version: string;
|
|
1347
|
+
sets: Record<string, DtcgResolverSet>;
|
|
1348
|
+
modifiers: Record<string, DtcgResolverModifier>;
|
|
1349
|
+
resolutionOrder: DtcgResolverRef[];
|
|
1350
|
+
}
|
|
1351
|
+
/** Renaming of the four scheme variants as resolver-modifier context names. */
|
|
1352
|
+
interface GlazeDtcgResolverContextNames {
|
|
1353
|
+
light?: string;
|
|
1354
|
+
dark?: string;
|
|
1355
|
+
lightContrast?: string;
|
|
1356
|
+
darkContrast?: string;
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Options for `theme.dtcgResolver()` / `palette.dtcgResolver()`. Extends
|
|
1360
|
+
* `GlazeDtcgOptions` so `modes` + `colorSpace` pass through to the underlying
|
|
1361
|
+
* per-scheme `dtcg()` build.
|
|
1362
|
+
*/
|
|
1363
|
+
interface GlazeDtcgResolverOptions extends GlazeDtcgOptions {
|
|
1364
|
+
/** Name of the single set holding the default (light) token tree. Default `'base'`. */
|
|
1365
|
+
setName?: string;
|
|
1366
|
+
/**
|
|
1367
|
+
* Name of the modifier describing the scheme axis. Default `'scheme'`
|
|
1368
|
+
* (Glaze's term for the light / dark / high-contrast axis).
|
|
1369
|
+
*/
|
|
1370
|
+
modifierName?: string;
|
|
1371
|
+
/**
|
|
1372
|
+
* Override the four context names emitted on the modifier. Defaults to the
|
|
1373
|
+
* Glaze variant keys: `light` / `dark` / `lightContrast` / `darkContrast`.
|
|
1374
|
+
*/
|
|
1375
|
+
contextNames?: GlazeDtcgResolverContextNames;
|
|
1376
|
+
/** Resolver document version. Default `'2025.10'`. */
|
|
1377
|
+
version?: string;
|
|
1378
|
+
}
|
|
1379
|
+
/** Options for `glaze.color().dtcgResolver()`. `name` is required. */
|
|
1380
|
+
interface GlazeColorDtcgResolverOptions extends GlazeDtcgResolverOptions {
|
|
1381
|
+
/** Token name keying the color within each token tree. Required. */
|
|
1382
|
+
name: string;
|
|
1383
|
+
}
|
|
1384
|
+
/** Options for `theme.tailwind()` / `palette.tailwind()`. */
|
|
1385
|
+
interface GlazeTailwindOptions {
|
|
1386
|
+
/** Override which scheme variants to include. */
|
|
1387
|
+
modes?: GlazeOutputModes;
|
|
1388
|
+
/** Output color format. Default: 'oklch'. */
|
|
1389
|
+
format?: GlazeColorFormat;
|
|
1390
|
+
/**
|
|
1391
|
+
* CSS custom property namespace, forming `--<namespace><name>`.
|
|
1392
|
+
* Default: `'color-'` → `--color-surface`. (Tailwind v4's `--color-*`
|
|
1393
|
+
* convention, which auto-generates `bg-*` / `text-*` / `border-*`.)
|
|
1394
|
+
*
|
|
1395
|
+
* Named `namespace` rather than `prefix` to avoid clashing with the
|
|
1396
|
+
* palette theme-prefix option on `palette.tailwind()`.
|
|
1397
|
+
*/
|
|
1398
|
+
namespace?: string;
|
|
1399
|
+
/**
|
|
1400
|
+
* Selector wrapping the dark-scheme overrides. Default: `'.dark'`.
|
|
1401
|
+
* Pass a media query such as `'@media (prefers-color-scheme: dark)'` to
|
|
1402
|
+
* drive dark mode from the OS preference instead of a class.
|
|
1403
|
+
*/
|
|
1404
|
+
darkSelector?: string;
|
|
1405
|
+
/**
|
|
1406
|
+
* Selector wrapping the light high-contrast overrides. Default:
|
|
1407
|
+
* `'.high-contrast'`. The combined dark + high-contrast overrides are
|
|
1408
|
+
* emitted under `${darkSelector}${highContrastSelector}` (e.g.
|
|
1409
|
+
* `.dark.high-contrast`).
|
|
1410
|
+
*/
|
|
1411
|
+
highContrastSelector?: string;
|
|
1412
|
+
}
|
|
1413
|
+
/** Options for `glaze.color().tailwind()`. `name` is required. */
|
|
1414
|
+
interface GlazeColorTailwindOptions extends GlazeTailwindOptions {
|
|
1415
|
+
/** Custom property base name (without leading `--`). Required. */
|
|
1416
|
+
name: string;
|
|
1417
|
+
}
|
|
411
1418
|
/** Options for `glaze.palette()` creation. */
|
|
412
1419
|
interface GlazePaletteOptions {
|
|
413
1420
|
/**
|
|
@@ -439,8 +1446,31 @@ interface GlazePaletteExportOptions {
|
|
|
439
1446
|
* When omitted, inherits the palette-level `primary`.
|
|
440
1447
|
*/
|
|
441
1448
|
primary?: string | false;
|
|
1449
|
+
/**
|
|
1450
|
+
* Emit hue as a separate custom property, referenced via `var()`.
|
|
1451
|
+
* Requires `format: 'oklch'` and every color to be pastel.
|
|
1452
|
+
*/
|
|
1453
|
+
splitHue?: boolean;
|
|
442
1454
|
}
|
|
443
1455
|
interface GlazePalette {
|
|
1456
|
+
/** Theme names in insertion order. */
|
|
1457
|
+
list(): string[];
|
|
1458
|
+
/** Primary theme name, if set at palette creation. */
|
|
1459
|
+
readonly primary: string | undefined;
|
|
1460
|
+
/** Get a theme by name. Returns the live instance held by the palette. */
|
|
1461
|
+
theme(name: string): GlazeTheme | undefined;
|
|
1462
|
+
/**
|
|
1463
|
+
* Shallow copy of the theme map (same instances the palette holds).
|
|
1464
|
+
* Mutating a returned theme affects subsequent palette exports.
|
|
1465
|
+
*/
|
|
1466
|
+
themes(): Record<string, GlazeTheme>;
|
|
1467
|
+
/**
|
|
1468
|
+
* Export the palette authoring configuration as a JSON-safe object.
|
|
1469
|
+
* Restorable via `glaze.paletteFrom(...)`. Distinct from `json()`, which
|
|
1470
|
+
* emits resolved color strings. Optional `override` is forwarded to each
|
|
1471
|
+
* nested `theme.export(override)`.
|
|
1472
|
+
*/
|
|
1473
|
+
export(override?: GlazeConfigOverride): GlazePaletteExport;
|
|
444
1474
|
/**
|
|
445
1475
|
* Export all themes as a flat token map grouped by scheme variant.
|
|
446
1476
|
* Prefix defaults to `true` — all tokens are prefixed with the theme name.
|
|
@@ -455,9 +1485,9 @@ interface GlazePalette {
|
|
|
455
1485
|
tokens(options?: GlazeJsonOptions & GlazePaletteExportOptions): Record<string, Record<string, string>>;
|
|
456
1486
|
/**
|
|
457
1487
|
* Export all themes as tasty style-to-state bindings.
|
|
458
|
-
* Uses `#name` color token keys and state aliases (`''`,
|
|
1488
|
+
* Uses `#name` color token keys and state aliases (`''`, `'@media(prefers-color-scheme: dark)'`, etc.).
|
|
459
1489
|
* Prefix defaults to `true`. Inherits the palette-level `primary`.
|
|
460
|
-
* @see https://
|
|
1490
|
+
* @see https://tasty.style/docs
|
|
461
1491
|
*/
|
|
462
1492
|
tasty(options?: GlazeTokenOptions & GlazePaletteExportOptions): Record<string, Record<string, string>>;
|
|
463
1493
|
/** Export all themes as plain JSON grouped by theme name. */
|
|
@@ -466,61 +1496,249 @@ interface GlazePalette {
|
|
|
466
1496
|
}): Record<string, Record<string, Record<string, string>>>;
|
|
467
1497
|
/** Export all themes as CSS custom property declarations. */
|
|
468
1498
|
css(options?: GlazeCssOptions & GlazePaletteExportOptions): GlazeCssResult;
|
|
1499
|
+
/**
|
|
1500
|
+
* Export all themes as W3C DTCG documents, one per scheme variant.
|
|
1501
|
+
* Prefix defaults to `true`. Inherits the palette-level `primary`.
|
|
1502
|
+
* @see https://www.designtokens.org/
|
|
1503
|
+
*/
|
|
1504
|
+
dtcg(options?: GlazeDtcgOptions & GlazePaletteExportOptions): GlazeDtcgResult;
|
|
1505
|
+
/**
|
|
1506
|
+
* Export all themes as a single W3C DTCG Resolver-Module document. Prefix
|
|
1507
|
+
* defaults to `true`. Inherits the palette-level `primary`.
|
|
1508
|
+
* @see https://www.designtokens.org/
|
|
1509
|
+
*/
|
|
1510
|
+
dtcgResolver(options?: GlazeDtcgResolverOptions & GlazePaletteExportOptions): GlazeDtcgResolverDocument;
|
|
1511
|
+
/**
|
|
1512
|
+
* Export all themes as a Tailwind CSS v4 `@theme` block plus dark /
|
|
1513
|
+
* high-contrast overrides. Returns a single ready-to-paste CSS string.
|
|
1514
|
+
* Prefix defaults to `true`.
|
|
1515
|
+
* @see https://tailwindcss.com/docs/theme
|
|
1516
|
+
*/
|
|
1517
|
+
tailwind(options?: GlazeTailwindOptions & GlazePaletteExportOptions): string;
|
|
469
1518
|
}
|
|
470
1519
|
//#endregion
|
|
1520
|
+
//#region src/serialize.d.ts
|
|
1521
|
+
/** Type guard for theme authoring snapshots (prefers `kind`, falls back to shape). */
|
|
1522
|
+
declare function isThemeExport(data: unknown): data is GlazeThemeExport;
|
|
1523
|
+
/** Type guard for color-token authoring snapshots. */
|
|
1524
|
+
declare function isColorTokenExport(data: unknown): data is GlazeColorTokenExport;
|
|
1525
|
+
/** Type guard for palette authoring snapshots. */
|
|
1526
|
+
declare function isPaletteExport(data: unknown): data is GlazePaletteExport;
|
|
1527
|
+
//#endregion
|
|
471
1528
|
//#region src/glaze.d.ts
|
|
472
1529
|
type PaletteInput = Record<string, GlazeTheme>;
|
|
473
1530
|
/**
|
|
474
1531
|
* Create a single-hue glaze theme.
|
|
475
1532
|
*
|
|
1533
|
+
* An optional `config` override can be supplied to customize the resolve
|
|
1534
|
+
* behavior for this theme (tone windows, etc.). The
|
|
1535
|
+
* override is **merged over the live global config at resolve time** —
|
|
1536
|
+
* the theme still reacts to later `configure()` calls for fields it
|
|
1537
|
+
* didn't override.
|
|
1538
|
+
*
|
|
1539
|
+
* The object form also accepts `darkHue` / `darkSaturation` — a separate
|
|
1540
|
+
* seed pair for the dark and dark-high-contrast schemes. Both default to
|
|
1541
|
+
* their light counterparts, and an explicit `darkSaturation` opts the theme
|
|
1542
|
+
* out of the global `darkDesaturation` reduction.
|
|
1543
|
+
*
|
|
476
1544
|
* @example
|
|
477
1545
|
* ```ts
|
|
478
|
-
* const primary = glaze({ hue: 280, saturation: 80 });
|
|
479
|
-
* // or shorthand:
|
|
480
1546
|
* const primary = glaze(280, 80);
|
|
1547
|
+
* // or shorthand:
|
|
1548
|
+
* const primary = glaze({ hue: 280, saturation: 80 });
|
|
1549
|
+
* // with a retuned dark seed:
|
|
1550
|
+
* const primary = glaze({ hue: 280, saturation: 80, darkHue: 268, darkSaturation: 65 });
|
|
1551
|
+
* // with config override:
|
|
1552
|
+
* const raw = glaze(280, 80, { lightTone: false });
|
|
481
1553
|
* ```
|
|
482
1554
|
*/
|
|
483
|
-
declare function glaze(hueOrOptions: number |
|
|
484
|
-
hue: number;
|
|
485
|
-
saturation: number;
|
|
486
|
-
}, saturation?: number): GlazeTheme;
|
|
1555
|
+
declare function glaze(hueOrOptions: number | GlazeThemeSeed, saturation?: number, config?: GlazeConfigOverride): GlazeTheme;
|
|
487
1556
|
declare namespace glaze {
|
|
488
1557
|
var configure: (config: GlazeConfig) => void;
|
|
489
|
-
var palette: (themes: PaletteInput, options?: GlazePaletteOptions) =>
|
|
490
|
-
|
|
491
|
-
tasty(options?: GlazeTokenOptions & GlazePaletteExportOptions): Record<string, Record<string, string>>;
|
|
492
|
-
json(options?: GlazeJsonOptions & {
|
|
493
|
-
prefix?: boolean | Record<string, string>;
|
|
494
|
-
}): Record<string, Record<string, Record<string, string>>>;
|
|
495
|
-
css(options?: GlazeCssOptions & GlazePaletteExportOptions): GlazeCssResult;
|
|
496
|
-
};
|
|
1558
|
+
var palette: (themes: PaletteInput, options?: GlazePaletteOptions) => GlazePalette;
|
|
1559
|
+
var themeFrom: (data: GlazeThemeExport) => GlazeTheme;
|
|
497
1560
|
var from: (data: GlazeThemeExport) => GlazeTheme;
|
|
498
|
-
var color: (input: GlazeColorInput) => GlazeColorToken;
|
|
1561
|
+
var color: (input: GlazeFromInput | GlazeColorInput | GlazeColorValue, config?: GlazeConfigOverride) => GlazeColorToken;
|
|
499
1562
|
var shadow: (input: GlazeShadowInput) => ResolvedColorVariant;
|
|
500
|
-
var format: (variant: ResolvedColorVariant, colorFormat?: GlazeColorFormat) => string;
|
|
1563
|
+
var format: (variant: ResolvedColorVariant, colorFormat?: GlazeColorFormat, pastel?: boolean) => string;
|
|
501
1564
|
var fromHex: (hex: string) => GlazeTheme;
|
|
502
1565
|
var fromRgb: (r: number, g: number, b: number) => GlazeTheme;
|
|
1566
|
+
var colorFrom: (data: GlazeColorTokenExport) => GlazeColorToken;
|
|
1567
|
+
var paletteFrom: (data: GlazePaletteExport) => GlazePalette;
|
|
1568
|
+
var isThemeExport: typeof isThemeExport;
|
|
1569
|
+
var isColorTokenExport: typeof isColorTokenExport;
|
|
1570
|
+
var isPaletteExport: typeof isPaletteExport;
|
|
503
1571
|
var getConfig: () => GlazeConfigResolved;
|
|
504
1572
|
var resetConfig: () => void;
|
|
505
1573
|
}
|
|
506
1574
|
//#endregion
|
|
1575
|
+
//#region src/channels.d.ts
|
|
1576
|
+
interface HueDeclaration {
|
|
1577
|
+
prop: string;
|
|
1578
|
+
value: string;
|
|
1579
|
+
}
|
|
1580
|
+
interface HuePlan {
|
|
1581
|
+
/** CSS `var()` reference spliced into `oklch(L C <hueVar>)`. */
|
|
1582
|
+
hueVar: string;
|
|
1583
|
+
/** When true, emit a full inline color (shadow/mix/achromatic). */
|
|
1584
|
+
inline: boolean;
|
|
1585
|
+
/** Scheme-independent `--*-hue` declarations for this color. */
|
|
1586
|
+
declarations: HueDeclaration[];
|
|
1587
|
+
}
|
|
1588
|
+
interface ChannelCtx {
|
|
1589
|
+
seedHue: number;
|
|
1590
|
+
/**
|
|
1591
|
+
* Dark-scheme seed hue, when the theme authored one. Drives the dark
|
|
1592
|
+
* `--{baseName}-hue` value; falls back to `seedHue`.
|
|
1593
|
+
*/
|
|
1594
|
+
darkSeedHue?: number;
|
|
1595
|
+
/** Theme-level hue var base name (without `--` / `-hue`). */
|
|
1596
|
+
baseName: string;
|
|
1597
|
+
/** Token / custom-property name prefix used for hue var naming (`brand-` etc.). */
|
|
1598
|
+
prefix: string;
|
|
1599
|
+
defs: ColorMap;
|
|
1600
|
+
mode: 'theme' | 'standalone';
|
|
1601
|
+
/** Standalone: resolved hue from the primary variant (scheme-independent). */
|
|
1602
|
+
resolvedHue?: number;
|
|
1603
|
+
/**
|
|
1604
|
+
* When false, hue declarations are not emitted (the pass only references
|
|
1605
|
+
* hue vars already declared by a sibling pass). Used by palette primary
|
|
1606
|
+
* unprefixed aliases so they reference the themed `--{themeName}-*-hue`
|
|
1607
|
+
* vars without re-declaring (and colliding with) other themes' base vars.
|
|
1608
|
+
* Defaults to true.
|
|
1609
|
+
*/
|
|
1610
|
+
emitDeclarations?: boolean;
|
|
1611
|
+
}
|
|
1612
|
+
//#endregion
|
|
1613
|
+
//#region src/format-guard.d.ts
|
|
1614
|
+
/**
|
|
1615
|
+
* Throw when a non-native Glaze color space is requested for an export that
|
|
1616
|
+
* emits raw CSS or non-Tasty token maps.
|
|
1617
|
+
*/
|
|
1618
|
+
declare function assertNativeFormat(format: GlazeColorFormat | undefined, method: string): void;
|
|
1619
|
+
/**
|
|
1620
|
+
* Throw when `splitHue` is enabled but any exported color is not pastel.
|
|
1621
|
+
* Hue rotation is only clip-free when chroma is bounded by the hue-independent
|
|
1622
|
+
* safe chroma (`computeSafeChromaOKLCH`).
|
|
1623
|
+
*/
|
|
1624
|
+
declare function assertAllPastel(resolved: Map<string, ResolvedColor>, modes: Required<GlazeOutputModes>): void;
|
|
1625
|
+
//#endregion
|
|
1626
|
+
//#region src/roles.d.ts
|
|
1627
|
+
/**
|
|
1628
|
+
* Normalize a `RoleInput` (canonical value or alias) into a canonical `Role`.
|
|
1629
|
+
* Returns `undefined` for unrecognized strings so callers can fall through to
|
|
1630
|
+
* the next step of the resolution chain.
|
|
1631
|
+
*/
|
|
1632
|
+
declare function normalizeRole(input: RoleInput | undefined): Role | undefined;
|
|
1633
|
+
/**
|
|
1634
|
+
* Infer a `Role` from a color name by matching its tokens against the role
|
|
1635
|
+
* keyword sets. When multiple tokens match, the **last** recognized token
|
|
1636
|
+
* wins (so `button-text` → `text`, `input-bg` → `surface`, `card-border` →
|
|
1637
|
+
* `border`). Returns `undefined` when no token matches.
|
|
1638
|
+
*/
|
|
1639
|
+
declare function inferRoleFromName(name: string): Role | undefined;
|
|
1640
|
+
/** APCA argument order: which side the resolved color plays. */
|
|
1641
|
+
type Polarity = 'fg' | 'bg';
|
|
1642
|
+
/**
|
|
1643
|
+
* Map a role to its APCA polarity. `text` and `border` are foreground spots
|
|
1644
|
+
* against their base (the candidate is the text argument); `surface` is the
|
|
1645
|
+
* background (the base is the text argument).
|
|
1646
|
+
*/
|
|
1647
|
+
declare function roleToPolarity(role: Role): Polarity;
|
|
1648
|
+
/**
|
|
1649
|
+
* The opposite role of `role`, used when a color with no explicit role and no
|
|
1650
|
+
* inferable name depends on a base: the dependent color plays the opposite
|
|
1651
|
+
* role of its base. `surface` ↔ `text`; `border` is treated as a foreground
|
|
1652
|
+
* spot, so its opposite is `surface`.
|
|
1653
|
+
*/
|
|
1654
|
+
declare function oppositeRole(role: Role): Role;
|
|
1655
|
+
//#endregion
|
|
1656
|
+
//#region src/okhst.d.ts
|
|
1657
|
+
/**
|
|
1658
|
+
* Reference eps for the OKHST color space. WCAG 2 contrast is
|
|
1659
|
+
* `(Y_hi + 0.05) / (Y_lo + 0.05)`, so an eps of `0.05` makes equal tone
|
|
1660
|
+
* steps yield equal WCAG contrast. This is the canonical eps used by
|
|
1661
|
+
* `okhst()` input, `{ h, s, t }` input, stored `ResolvedColorVariant.t`,
|
|
1662
|
+
* relative `tone` offsets, and the contrast solver.
|
|
1663
|
+
*/
|
|
1664
|
+
declare const REF_EPS = 0.05;
|
|
1665
|
+
/**
|
|
1666
|
+
* Map a luminance `Y` (0–1) to tone (0–100) at the given eps.
|
|
1667
|
+
* `toneFromY(0) === 0` and `toneFromY(1) === 100` for any eps.
|
|
1668
|
+
*/
|
|
1669
|
+
declare function toneFromY(y: number, eps?: number): number;
|
|
1670
|
+
/** Map a tone (0–100) back to luminance (0–1). Inverse of {@link toneFromY}. */
|
|
1671
|
+
declare function yFromTone(t: number, eps?: number): number;
|
|
1672
|
+
/** OKHSL lightness (0–1) -> tone (0–100). */
|
|
1673
|
+
declare function toTone(l: number, eps?: number): number;
|
|
1674
|
+
/** Tone (0–100) -> OKHSL lightness (0–1). Inverse of {@link toTone}. */
|
|
1675
|
+
declare function fromTone(t: number, eps?: number): number;
|
|
1676
|
+
/** Convert OKHST `{ h, s, t }` (t in 0–1) to OKHSL `{ h, s, l }`. */
|
|
1677
|
+
declare function okhstToOkhsl(c: {
|
|
1678
|
+
h: number;
|
|
1679
|
+
s: number;
|
|
1680
|
+
t: number;
|
|
1681
|
+
}): {
|
|
1682
|
+
h: number;
|
|
1683
|
+
s: number;
|
|
1684
|
+
l: number;
|
|
1685
|
+
};
|
|
1686
|
+
/** Convert OKHSL `{ h, s, l }` to OKHST `{ h, s, t }` (t in 0–1). */
|
|
1687
|
+
declare function okhslToOkhst(c: {
|
|
1688
|
+
h: number;
|
|
1689
|
+
s: number;
|
|
1690
|
+
l: number;
|
|
1691
|
+
}): {
|
|
1692
|
+
h: number;
|
|
1693
|
+
s: number;
|
|
1694
|
+
t: number;
|
|
1695
|
+
};
|
|
1696
|
+
/**
|
|
1697
|
+
* Edge adapter: a resolved variant stores canonical tone `t` (0–1). Convert
|
|
1698
|
+
* it to the OKHSL `{ h, s, l }` the formatters and luminance pipeline expect.
|
|
1699
|
+
*/
|
|
1700
|
+
declare function variantToOkhsl(v: {
|
|
1701
|
+
h: number;
|
|
1702
|
+
s: number;
|
|
1703
|
+
t: number;
|
|
1704
|
+
}): {
|
|
1705
|
+
h: number;
|
|
1706
|
+
s: number;
|
|
1707
|
+
l: number;
|
|
1708
|
+
};
|
|
1709
|
+
//#endregion
|
|
507
1710
|
//#region src/okhsl-color-math.d.ts
|
|
508
1711
|
/**
|
|
509
1712
|
* OKHSL color math primitives for the glaze theme generator.
|
|
510
1713
|
*
|
|
511
|
-
* Provides bidirectional OKHSL ↔ sRGB conversion,
|
|
512
|
-
*
|
|
513
|
-
* (okhsl, rgb, hsl, oklch).
|
|
1714
|
+
* Provides bidirectional OKHSL ↔ sRGB conversion, luminance computation
|
|
1715
|
+
* for both contrast metrics (WCAG 2 relative luminance and APCA screen
|
|
1716
|
+
* luminance `Ys`), and multi-format output (okhsl, rgb, hsl, oklch).
|
|
514
1717
|
*/
|
|
1718
|
+
type Vec3 = [number, number, number];
|
|
1719
|
+
/**
|
|
1720
|
+
* OKHSL toe function: maps OKLab lightness L to perceptual lightness l.
|
|
1721
|
+
* Exported for the OKHST tone transfers in `okhst.ts`.
|
|
1722
|
+
*/
|
|
1723
|
+
/**
|
|
1724
|
+
* OKHSL lightness of the gamut cusp for a hue — the lightness where the
|
|
1725
|
+
* realizable chroma peaks. Reuses the same `find_cusp` OKHSL already runs for
|
|
1726
|
+
* its `s` normalization (no new color math); the OKLab cusp lightness is run
|
|
1727
|
+
* through the OKHSL `toe` and clamped to `[0.001, 0.999]` so divisions that
|
|
1728
|
+
* key off it stay safe. Cached per (rounded) hue.
|
|
1729
|
+
*
|
|
1730
|
+
* @param h Hue, 0–360.
|
|
1731
|
+
*/
|
|
1732
|
+
declare function cuspLightness(h: number): number;
|
|
515
1733
|
/**
|
|
516
1734
|
* Convert OKHSL (h: 0–360, s: 0–1, l: 0–1) to OKLab [L, a, b].
|
|
517
1735
|
*/
|
|
518
|
-
declare function okhslToOklab(h: number, s: number, l: number): [number, number, number];
|
|
1736
|
+
declare function okhslToOklab(h: number, s: number, l: number, pastel?: boolean): [number, number, number];
|
|
519
1737
|
/**
|
|
520
1738
|
* Convert OKHSL (h: 0–360, s: 0–1, l: 0–1) to linear sRGB.
|
|
521
1739
|
* Channels may exceed [0, 1] near gamut boundaries — caller must clamp if needed.
|
|
522
1740
|
*/
|
|
523
|
-
declare function okhslToLinearSrgb(h: number, s: number, l: number): [number, number, number];
|
|
1741
|
+
declare function okhslToLinearSrgb(h: number, s: number, l: number, pastel?: boolean): [number, number, number];
|
|
524
1742
|
/**
|
|
525
1743
|
* Compute relative luminance Y from linear sRGB channels.
|
|
526
1744
|
* Per WCAG 2: Y = 0.2126·R + 0.7152·G + 0.0722·B
|
|
@@ -533,44 +1751,90 @@ declare function contrastRatioFromLuminance(yA: number, yB: number): number;
|
|
|
533
1751
|
/**
|
|
534
1752
|
* Convert OKHSL to gamma-encoded sRGB (clamped to 0–1).
|
|
535
1753
|
*/
|
|
536
|
-
declare function okhslToSrgb(h: number, s: number, l: number): [number, number, number];
|
|
1754
|
+
declare function okhslToSrgb(h: number, s: number, l: number, pastel?: boolean): [number, number, number];
|
|
537
1755
|
/**
|
|
538
1756
|
* Compute WCAG 2 relative luminance from linear sRGB, matching the browser
|
|
539
1757
|
* rendering pipeline: gamma-encode, clamp to sRGB gamut [0,1], then linearize.
|
|
540
1758
|
* This avoids over/under-estimating luminance for out-of-gamut OKHSL colors.
|
|
541
1759
|
*/
|
|
542
1760
|
declare function gamutClampedLuminance(linearRgb: [number, number, number]): number;
|
|
1761
|
+
/**
|
|
1762
|
+
* Convert OKLab to OKHSL.
|
|
1763
|
+
* Input: [L, a, b] where L: 0–1, a/b: roughly -0.5 to 0.5.
|
|
1764
|
+
* Returns [h, s, l] where h: 0–360, s: 0–1, l: 0–1.
|
|
1765
|
+
*/
|
|
1766
|
+
declare const oklabToOkhsl: (lab: Vec3, pastel?: boolean) => Vec3;
|
|
543
1767
|
/**
|
|
544
1768
|
* Convert gamma-encoded sRGB (0–1 per channel) to OKHSL.
|
|
545
1769
|
* Returns [h, s, l] where h: 0–360, s: 0–1, l: 0–1.
|
|
546
1770
|
*/
|
|
547
|
-
declare function srgbToOkhsl(rgb: [number, number, number]): [number, number, number];
|
|
1771
|
+
declare function srgbToOkhsl(rgb: [number, number, number], pastel?: boolean): [number, number, number];
|
|
1772
|
+
/**
|
|
1773
|
+
* Convert CSS HSL (sRGB-based) to gamma-encoded sRGB [r, g, b] in 0–1 range.
|
|
1774
|
+
* h: 0–360, s: 0–1, l: 0–1.
|
|
1775
|
+
*
|
|
1776
|
+
* Note: CSS HSL is not the same as OKHSL — it's HSL in the sRGB color space.
|
|
1777
|
+
* Use this when parsing `hsl(...)` strings before passing to `srgbToOkhsl`.
|
|
1778
|
+
*/
|
|
1779
|
+
declare function hslToSrgb(h: number, s: number, l: number): [number, number, number];
|
|
548
1780
|
/**
|
|
549
1781
|
* Parse a hex color string (#rgb or #rrggbb) to sRGB [r, g, b] in 0–1 range.
|
|
550
1782
|
* Returns null if the string is not a valid hex color.
|
|
1783
|
+
*
|
|
1784
|
+
* For 8-digit hex (`#rrggbbaa`) and 4-digit hex (`#rgba`) with alpha,
|
|
1785
|
+
* use {@link parseHexAlpha}.
|
|
551
1786
|
*/
|
|
552
1787
|
declare function parseHex(hex: string): [number, number, number] | null;
|
|
1788
|
+
/**
|
|
1789
|
+
* Parse a hex color string (#rgb, #rrggbb, #rgba, or #rrggbbaa) to
|
|
1790
|
+
* sRGB [r, g, b] in 0–1 range plus an optional alpha (0–1).
|
|
1791
|
+
* Returns null if the string is not a valid hex color.
|
|
1792
|
+
*/
|
|
1793
|
+
declare function parseHexAlpha(hex: string): {
|
|
1794
|
+
rgb: [number, number, number];
|
|
1795
|
+
alpha?: number;
|
|
1796
|
+
} | null;
|
|
553
1797
|
/**
|
|
554
1798
|
* Format OKHSL values as a CSS `okhsl(H S% L%)` string.
|
|
555
1799
|
* h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
|
|
556
1800
|
*/
|
|
557
|
-
declare function formatOkhsl(h: number, s: number, l: number): string;
|
|
1801
|
+
declare function formatOkhsl(h: number, s: number, l: number, pastel?: boolean): string;
|
|
1802
|
+
/**
|
|
1803
|
+
* Format OKHST values as a CSS `okhst(H S% T%)` string.
|
|
1804
|
+
* h: 0–360, s: 0–100, t: 0–100 (percentage scale for s and t).
|
|
1805
|
+
*
|
|
1806
|
+
* Pastel recompute matches `formatOkhsl`: convert via OKLab so external
|
|
1807
|
+
* parsers that only understand non-pastel OKHST render identically.
|
|
1808
|
+
*/
|
|
1809
|
+
declare function formatOkhst(h: number, s: number, t: number, pastel?: boolean): string;
|
|
558
1810
|
/**
|
|
559
1811
|
* Format OKHSL values as a CSS `rgb(R G B)` string.
|
|
560
1812
|
* Uses 2 decimal places to avoid 8-bit quantization contrast loss.
|
|
561
1813
|
* h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
|
|
562
1814
|
*/
|
|
563
|
-
declare function formatRgb(h: number, s: number, l: number): string;
|
|
1815
|
+
declare function formatRgb(h: number, s: number, l: number, pastel?: boolean): string;
|
|
564
1816
|
/**
|
|
565
1817
|
* Format OKHSL values as a CSS `hsl(H S% L%)` string.
|
|
566
1818
|
* h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
|
|
567
1819
|
*/
|
|
568
|
-
declare function formatHsl(h: number, s: number, l: number): string;
|
|
1820
|
+
declare function formatHsl(h: number, s: number, l: number, pastel?: boolean): string;
|
|
569
1821
|
/**
|
|
570
1822
|
* Format OKHSL values as a CSS `oklch(L C H)` string.
|
|
571
1823
|
* h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
|
|
572
1824
|
*/
|
|
573
|
-
declare function formatOklch(h: number, s: number, l: number): string;
|
|
1825
|
+
declare function formatOklch(h: number, s: number, l: number, pastel?: boolean): string;
|
|
1826
|
+
/**
|
|
1827
|
+
* Convert gamma-encoded sRGB channels (0–1) to a 6-digit lowercase hex
|
|
1828
|
+
* string (`#rrggbb`). Channels are clamped to [0,1] and rounded to 8-bit.
|
|
1829
|
+
* Alpha is not encoded here — DTCG carries it as a separate `alpha` field.
|
|
1830
|
+
*/
|
|
1831
|
+
declare function srgbToHex(rgb: [number, number, number]): `#${string}`;
|
|
1832
|
+
/**
|
|
1833
|
+
* Convert OKHSL (h: 0–360, s: 0–1, l: 0–1) to OKLCH components `[L, C, H]`.
|
|
1834
|
+
* L: 0–1, C: 0–~0.4 (chroma), H: 0–360 (hue). Shared by `formatOklch` and
|
|
1835
|
+
* the DTCG `oklch` colorSpace exporter so the two never drift apart.
|
|
1836
|
+
*/
|
|
1837
|
+
declare function okhslToOklch(h: number, s: number, l: number, pastel?: boolean): [number, number, number];
|
|
574
1838
|
//#endregion
|
|
575
|
-
export { type AdaptationMode, type ColorDef, type ColorMap, type ContrastPreset, type
|
|
1839
|
+
export { APCA_HC_ENHANCEMENT, APCA_MAX_LC, APCA_PRESETS, type AdaptationMode, type ApcaPreset, type ChannelCtx, type ColorDef, type ColorMap, type ContrastPreset, type ContrastSpec, type DtcgColorSpace, type DtcgColorToken, type DtcgColorValue, type DtcgDocument, type DtcgOklchColorValue, type DtcgResolverModifier, type DtcgResolverRef, type DtcgResolverSet, type DtcgSrgbColorValue, type DtcgTokenTree, type ExtremeValue, type FindToneForContrastOptions, type FindToneForContrastResult, type FindValueForMixContrastOptions, type FindValueForMixContrastResult, GLAZE_EXPORT_VERSION, type GlazeColorCssOptions, type GlazeColorDtcgResolverOptions, type GlazeColorDtcgResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorInputExport, type GlazeColorOverrides, type GlazeColorOverridesExport, type GlazeColorTailwindOptions, type GlazeColorToken, type GlazeColorTokenExport, type GlazeColorValue, type GlazeConfig, type GlazeConfigOverride, type GlazeConfigResolved, type GlazeCssOptions, type GlazeCssResult, type GlazeDtcgOptions, type GlazeDtcgResolverContextNames, type GlazeDtcgResolverDocument, type GlazeDtcgResolverOptions, type GlazeDtcgResult, type GlazeExportKind, type GlazeExportVersion, type GlazeExtendOptions, type GlazeFromInput, type GlazeJsonOptions, type GlazeOutputModes, type GlazePalette, type GlazePaletteExport, type GlazePaletteExportOptions, type GlazePaletteOptions, type GlazeShadowInput, type GlazeTailwindOptions, type GlazeTheme, type GlazeThemeExport, type GlazeThemeSeed, type GlazeTokenOptions, type HCPair, type HexColor, type HueDeclaration, type HuePlan, type MinContrast, type MixColorDef, type OkhslColor, type OkhstColor, type OklchColor, type Polarity, REF_EPS, type RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type ResolvedContrast, type RgbColor, type Role, type RoleInput, type ShadowColorDef, type ShadowTuning, type ToneValue, type ToneWindow, apcaContrast, assertAllPastel, assertNativeFormat, contrastRatioFromLuminance, cuspLightness, findToneForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOkhst, formatOklch, formatRgb, fromTone, gamutClampedLuminance, glaze, hslToSrgb, inferRoleFromName, isColorTokenExport, isPaletteExport, isThemeExport, normalizeRole, okhslToLinearSrgb, okhslToOkhst, okhslToOklab, okhslToOklch, okhslToSrgb, okhstToOkhsl, oklabToOkhsl, oppositeRole, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveApcaTarget, resolveContrastForLevel, resolveContrastForMode, resolveMinContrast, roleToPolarity, srgbToHex, srgbToOkhsl, toTone, toneFromY, variantToOkhsl, yFromTone };
|
|
576
1840
|
//# sourceMappingURL=index.d.mts.map
|