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