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