@tenphi/glaze 0.0.0-snapshot.7c1fc7d → 0.0.0-snapshot.7dca259
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 +29 -861
- package/dist/index.cjs +2201 -692
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +680 -85
- package/dist/index.d.mts +680 -85
- package/dist/index.mjs +2186 -692
- package/dist/index.mjs.map +1 -1
- package/docs/api.md +1215 -0
- package/docs/methodology.md +346 -0
- package/docs/migration.md +308 -0
- package/docs/okhst.md +224 -0
- package/package.json +4 -8
package/dist/index.d.cts
CHANGED
|
@@ -1,55 +1,141 @@
|
|
|
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
|
-
*/
|
|
2
|
+
type LinearRgb = [number, number, number];
|
|
9
3
|
type ContrastPreset = 'AA' | 'AAA' | 'AA-large' | 'AAA-large';
|
|
10
4
|
type MinContrast$1 = number | ContrastPreset;
|
|
11
|
-
|
|
5
|
+
/** Metric + numeric target after resolving a `ContrastSpec` for a mode. */
|
|
6
|
+
interface ResolvedContrast {
|
|
7
|
+
metric: 'wcag' | 'apca';
|
|
8
|
+
/** WCAG ratio (>= 1) or APCA Lc magnitude (0–106). */
|
|
9
|
+
target: number;
|
|
10
|
+
}
|
|
11
|
+
declare function resolveMinContrast(value: MinContrast$1): number;
|
|
12
|
+
/**
|
|
13
|
+
* Resolve a `ContrastSpec` (already selected from any outer HC pair) for a
|
|
14
|
+
* given mode into `{ metric, target }`. Handles the inner metric HC pair and
|
|
15
|
+
* preset resolution.
|
|
16
|
+
*/
|
|
17
|
+
declare function resolveContrastForMode(spec: ContrastSpec, isHighContrast: boolean): ResolvedContrast;
|
|
18
|
+
/**
|
|
19
|
+
* APCA lightness contrast (Lc), signed: positive for dark text on light bg,
|
|
20
|
+
* negative for light text on dark bg. Inputs are screen luminances (0–1).
|
|
21
|
+
*/
|
|
22
|
+
declare function apcaContrast(yText: number, yBg: number): number;
|
|
23
|
+
interface FindToneForContrastOptions {
|
|
12
24
|
/** Hue of the candidate color (0–360). */
|
|
13
25
|
hue: number;
|
|
14
26
|
/** Saturation of the candidate color (0–1). */
|
|
15
27
|
saturation: number;
|
|
16
|
-
/** Preferred
|
|
17
|
-
|
|
18
|
-
/** Base/reference color as linear sRGB
|
|
19
|
-
baseLinearRgb:
|
|
20
|
-
/**
|
|
21
|
-
contrast:
|
|
22
|
-
/** Search bounds for
|
|
23
|
-
|
|
28
|
+
/** Preferred tone of the candidate (0–1). */
|
|
29
|
+
preferredTone: number;
|
|
30
|
+
/** Base/reference color as linear sRGB. */
|
|
31
|
+
baseLinearRgb: LinearRgb;
|
|
32
|
+
/** Resolved contrast floor (metric + target). */
|
|
33
|
+
contrast: ResolvedContrast;
|
|
34
|
+
/** Search bounds for tone. Default: [0, 1]. */
|
|
35
|
+
toneRange?: [number, number];
|
|
24
36
|
/** Convergence threshold. Default: 1e-4. */
|
|
25
37
|
epsilon?: number;
|
|
26
|
-
/** Maximum binary-search iterations per branch. Default:
|
|
38
|
+
/** Maximum binary-search iterations per branch. Default: 18. */
|
|
27
39
|
maxIterations?: number;
|
|
40
|
+
/** Preferred search direction before auto-flip is considered. */
|
|
41
|
+
initialDirection?: 'lighter' | 'darker';
|
|
42
|
+
/** Auto-flip tone direction when contrast can't be met. Default: false. */
|
|
43
|
+
flip?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Saturation taper strength (0–1). When set, candidate saturation is rolled
|
|
46
|
+
* off toward the tone extremes via the same envelope the renderer applies,
|
|
47
|
+
* so the solved tone meets the floor with its *rendered* saturation. Default
|
|
48
|
+
* `0` (no taper) for direct/advanced callers.
|
|
49
|
+
*/
|
|
50
|
+
saturationTaper?: number;
|
|
28
51
|
}
|
|
29
|
-
interface
|
|
30
|
-
/** Chosen
|
|
31
|
-
|
|
32
|
-
/** Achieved WCAG
|
|
52
|
+
interface FindToneForContrastResult {
|
|
53
|
+
/** Chosen tone in 0–1. */
|
|
54
|
+
tone: number;
|
|
55
|
+
/** Achieved score (WCAG ratio or APCA Lc magnitude). */
|
|
33
56
|
contrast: number;
|
|
34
57
|
/** Whether the target was reached. */
|
|
35
58
|
met: boolean;
|
|
36
59
|
/** Which branch was selected. */
|
|
37
60
|
branch: 'lighter' | 'darker' | 'preferred';
|
|
61
|
+
/** Whether the result auto-flipped to the opposite direction. */
|
|
62
|
+
flipped?: boolean;
|
|
38
63
|
}
|
|
39
|
-
declare function resolveMinContrast(value: MinContrast$1): number;
|
|
40
64
|
/**
|
|
41
|
-
* Find the
|
|
42
|
-
*
|
|
65
|
+
* Find the tone that satisfies a contrast floor against a base color,
|
|
66
|
+
* staying as close to `preferredTone` as possible.
|
|
43
67
|
*/
|
|
44
|
-
declare function
|
|
68
|
+
declare function findToneForContrast(options: FindToneForContrastOptions): FindToneForContrastResult;
|
|
69
|
+
interface FindValueForMixContrastOptions {
|
|
70
|
+
/** Preferred mix parameter (0–1). */
|
|
71
|
+
preferredValue: number;
|
|
72
|
+
/** Base color as linear sRGB. */
|
|
73
|
+
baseLinearRgb: LinearRgb;
|
|
74
|
+
/** Target color as linear sRGB. */
|
|
75
|
+
targetLinearRgb: LinearRgb;
|
|
76
|
+
/** Resolved contrast floor (metric + target). */
|
|
77
|
+
contrast: ResolvedContrast;
|
|
78
|
+
/** Compute the luminance of the mixed color at parameter t. */
|
|
79
|
+
luminanceAtValue: (t: number) => number;
|
|
80
|
+
/** Convergence threshold. Default: 1e-4. */
|
|
81
|
+
epsilon?: number;
|
|
82
|
+
/** Maximum binary-search iterations per branch. Default: 20. */
|
|
83
|
+
maxIterations?: number;
|
|
84
|
+
/** Auto-flip mix direction when contrast can't be met. Default: false. */
|
|
85
|
+
flip?: boolean;
|
|
86
|
+
}
|
|
87
|
+
interface FindValueForMixContrastResult {
|
|
88
|
+
value: number;
|
|
89
|
+
contrast: number;
|
|
90
|
+
met: boolean;
|
|
91
|
+
flipped?: boolean;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Find the mix parameter (ratio or opacity) that satisfies a contrast floor
|
|
95
|
+
* against a base color, staying as close to `preferredValue` as possible.
|
|
96
|
+
*/
|
|
97
|
+
declare function findValueForMixContrast(options: FindValueForMixContrastOptions): FindValueForMixContrastResult;
|
|
45
98
|
//#endregion
|
|
46
99
|
//#region src/types.d.ts
|
|
47
100
|
/** A value or [normal, high-contrast] pair. */
|
|
48
101
|
type HCPair<T> = T | [T, T];
|
|
102
|
+
/** Bare WCAG contrast target: a ratio number or a named preset. */
|
|
49
103
|
type MinContrast = number | ContrastPreset;
|
|
104
|
+
/**
|
|
105
|
+
* A contrast floor with a pluggable metric.
|
|
106
|
+
*
|
|
107
|
+
* - `number` / `ContrastPreset`: a WCAG ratio (bare form).
|
|
108
|
+
* - `{ wcag }`: WCAG ratio or preset, optionally an HC pair.
|
|
109
|
+
* - `{ apca }`: APCA Lc target (absolute value), optionally an HC pair.
|
|
110
|
+
*
|
|
111
|
+
* The `[normal, highContrast]` pair may live at the outer level
|
|
112
|
+
* (`[4.5, 7]`, `[{ wcag: 4.5 }, { wcag: 7 }]`) or inside the metric
|
|
113
|
+
* (`{ wcag: [4.5, 7] }`, `{ apca: [45, 60] }`).
|
|
114
|
+
*/
|
|
115
|
+
type ContrastSpec = number | ContrastPreset | {
|
|
116
|
+
wcag: HCPair<number | ContrastPreset>;
|
|
117
|
+
} | {
|
|
118
|
+
apca: HCPair<number>;
|
|
119
|
+
};
|
|
50
120
|
type AdaptationMode = 'auto' | 'fixed' | 'static';
|
|
51
121
|
/** A signed relative offset string, e.g. '+20' or '-15.5'. */
|
|
52
122
|
type RelativeValue = `+${number}` | `-${number}`;
|
|
123
|
+
/**
|
|
124
|
+
* Force a color to a tone extreme:
|
|
125
|
+
* - `'max'`: the highest tone in the active scheme range/window.
|
|
126
|
+
* - `'min'`: the lowest tone.
|
|
127
|
+
*
|
|
128
|
+
* Under `mode: 'auto'` the extreme inverts in the dark scheme (so `'max'`
|
|
129
|
+
* tracks the inversion and becomes the darkest tone). No `base` required.
|
|
130
|
+
*/
|
|
131
|
+
type ExtremeValue = 'max' | 'min';
|
|
132
|
+
/**
|
|
133
|
+
* A tone value as authored on a color.
|
|
134
|
+
* - Number: absolute tone (0–100).
|
|
135
|
+
* - `'+N'` / `'-N'`: relative to the base's tone (requires `base`).
|
|
136
|
+
* - `'max'` / `'min'`: forced to the scheme's tone extreme (no base needed).
|
|
137
|
+
*/
|
|
138
|
+
type ToneValue = number | RelativeValue | ExtremeValue;
|
|
53
139
|
/** Color format for output. */
|
|
54
140
|
type GlazeColorFormat = 'okhsl' | 'rgb' | 'hsl' | 'oklch';
|
|
55
141
|
/**
|
|
@@ -70,13 +156,35 @@ interface OkhslColor {
|
|
|
70
156
|
s: number;
|
|
71
157
|
l: number;
|
|
72
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Direct OKHST color input — OKHSL with the lightness axis replaced by the
|
|
161
|
+
* contrast-uniform tone axis. `h`: 0–360, `s`: 0–1, `t`: 0–1 (tone).
|
|
162
|
+
*/
|
|
163
|
+
interface OkhstColor {
|
|
164
|
+
h: number;
|
|
165
|
+
s: number;
|
|
166
|
+
t: number;
|
|
167
|
+
}
|
|
168
|
+
/** sRGB components in 0–255 (value-shorthand object form). */
|
|
169
|
+
interface RgbColor {
|
|
170
|
+
r: number;
|
|
171
|
+
g: number;
|
|
172
|
+
b: number;
|
|
173
|
+
}
|
|
174
|
+
/** OKLCh components matching CSS `oklch(L C H)` (L/C: 0–1, H: degrees). */
|
|
175
|
+
interface OklchColor {
|
|
176
|
+
l: number;
|
|
177
|
+
c: number;
|
|
178
|
+
h: number;
|
|
179
|
+
}
|
|
73
180
|
interface RegularColorDef {
|
|
74
181
|
/**
|
|
75
|
-
*
|
|
76
|
-
* - Number: absolute
|
|
77
|
-
* - String ('+N' / '-N'): relative to base color's
|
|
182
|
+
* Tone value (0–100, contrast-uniform — see `docs/okhst.md`).
|
|
183
|
+
* - Number: absolute tone.
|
|
184
|
+
* - String ('+N' / '-N'): relative to base color's tone (requires `base`).
|
|
185
|
+
* - `'max'` / `'min'`: force to the scheme's tone extreme (no base needed).
|
|
78
186
|
*/
|
|
79
|
-
|
|
187
|
+
tone?: HCPair<ToneValue>;
|
|
80
188
|
/** Saturation factor applied to the seed saturation (0–1, default: 1). */
|
|
81
189
|
saturation?: number;
|
|
82
190
|
/**
|
|
@@ -87,18 +195,38 @@ interface RegularColorDef {
|
|
|
87
195
|
hue?: number | RelativeValue;
|
|
88
196
|
/** Name of another color in the same theme (dependent color). */
|
|
89
197
|
base?: string;
|
|
90
|
-
/**
|
|
91
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Contrast floor against the base color. A bare number/preset is WCAG;
|
|
200
|
+
* use `{ wcag }` / `{ apca }` to pick the metric. Accepts an HC pair.
|
|
201
|
+
*/
|
|
202
|
+
contrast?: HCPair<ContrastSpec>;
|
|
92
203
|
/** Adaptation mode. Default: 'auto'. */
|
|
93
204
|
mode?: AdaptationMode;
|
|
205
|
+
/**
|
|
206
|
+
* Whether to flip out-of-bounds results to the opposite side instead of
|
|
207
|
+
* clamping to the extreme. Affects both:
|
|
208
|
+
* - relative `tone`: when `base ± delta` exceeds `[0, 100]`, mirror the
|
|
209
|
+
* delta to the other side of the base.
|
|
210
|
+
* - `contrast`: when the requested direction can't meet the floor, try the
|
|
211
|
+
* opposite side (same as the global `autoFlip`).
|
|
212
|
+
*
|
|
213
|
+
* Defaults to the global `autoFlip` config (default `true`). Set `false`
|
|
214
|
+
* to clamp instead.
|
|
215
|
+
*/
|
|
216
|
+
flip?: boolean;
|
|
94
217
|
/**
|
|
95
218
|
* Fixed opacity (0–1).
|
|
96
219
|
* Output includes alpha in the CSS value.
|
|
97
220
|
* Does not affect contrast resolution — a semi-transparent color
|
|
98
|
-
* has no fixed perceived
|
|
221
|
+
* has no fixed perceived tone, so `contrast` and `opacity`
|
|
99
222
|
* should not be combined (a console.warn is emitted).
|
|
100
223
|
*/
|
|
101
224
|
opacity?: number;
|
|
225
|
+
/**
|
|
226
|
+
* Whether this color is inherited by child themes created via `extend()`.
|
|
227
|
+
* Default: true. Set to false to make this color local to the current theme.
|
|
228
|
+
*/
|
|
229
|
+
inherit?: boolean;
|
|
102
230
|
}
|
|
103
231
|
/** Shadow tuning knobs. All values use the 0–1 scale (OKHSL). */
|
|
104
232
|
interface ShadowTuning {
|
|
@@ -143,17 +271,68 @@ interface ShadowColorDef {
|
|
|
143
271
|
intensity: HCPair<number>;
|
|
144
272
|
/** Override default tuning. Merged field-by-field with global `shadowTuning`. */
|
|
145
273
|
tuning?: ShadowTuning;
|
|
274
|
+
/**
|
|
275
|
+
* Whether this color is inherited by child themes created via `extend()`.
|
|
276
|
+
* Default: true. Set to false to make this color local to the current theme.
|
|
277
|
+
*/
|
|
278
|
+
inherit?: boolean;
|
|
146
279
|
}
|
|
147
|
-
|
|
280
|
+
interface MixColorDef {
|
|
281
|
+
type: 'mix';
|
|
282
|
+
/** Background/base color name — the "from" color. */
|
|
283
|
+
base: string;
|
|
284
|
+
/** Target color name — the "to" color to mix toward. */
|
|
285
|
+
target: string;
|
|
286
|
+
/**
|
|
287
|
+
* Mix ratio 0–100 (0 = pure base, 100 = pure target).
|
|
288
|
+
* In 'transparent' blend mode, this controls the opacity of the target.
|
|
289
|
+
* Supports [normal, highContrast] pair.
|
|
290
|
+
*/
|
|
291
|
+
value: HCPair<number>;
|
|
292
|
+
/**
|
|
293
|
+
* Blending mode. Default: 'opaque'.
|
|
294
|
+
* - 'opaque': produces a solid color by interpolating base and target.
|
|
295
|
+
* - 'transparent': produces the target color with alpha = value/100.
|
|
296
|
+
*/
|
|
297
|
+
blend?: 'opaque' | 'transparent';
|
|
298
|
+
/**
|
|
299
|
+
* Interpolation color space for opaque blending. Default: 'okhsl'.
|
|
300
|
+
* - 'okhsl': perceptually uniform, consistent with Glaze's internal model.
|
|
301
|
+
* - 'srgb': linear sRGB interpolation, matches browser compositing.
|
|
302
|
+
*
|
|
303
|
+
* Ignored for 'transparent' blend (always composites in linear sRGB).
|
|
304
|
+
*/
|
|
305
|
+
space?: 'okhsl' | 'srgb';
|
|
306
|
+
/**
|
|
307
|
+
* Minimum contrast between the base and the resulting color.
|
|
308
|
+
* In 'opaque' mode, adjusts the mix ratio to meet contrast.
|
|
309
|
+
* In 'transparent' mode, adjusts opacity to meet contrast against the composite.
|
|
310
|
+
* A bare number/preset is WCAG; use `{ wcag }` / `{ apca }` to pick the
|
|
311
|
+
* metric. Supports [normal, highContrast] pair.
|
|
312
|
+
*/
|
|
313
|
+
contrast?: HCPair<ContrastSpec>;
|
|
314
|
+
/**
|
|
315
|
+
* Whether this color is inherited by child themes created via `extend()`.
|
|
316
|
+
* Default: true. Set to false to make this color local to the current theme.
|
|
317
|
+
*/
|
|
318
|
+
inherit?: boolean;
|
|
319
|
+
}
|
|
320
|
+
type ColorDef = RegularColorDef | ShadowColorDef | MixColorDef;
|
|
148
321
|
type ColorMap = Record<string, ColorDef>;
|
|
149
|
-
/**
|
|
322
|
+
/**
|
|
323
|
+
* Resolved color for a single scheme variant.
|
|
324
|
+
*
|
|
325
|
+
* Stored in OKHST: `h` / `s` are OKHSL hue/saturation, `t` is the canonical
|
|
326
|
+
* contrast-uniform tone (0–1, reference eps). Convert to OKHSL lightness via
|
|
327
|
+
* `variantToOkhsl` at the rendering / luminance edges.
|
|
328
|
+
*/
|
|
150
329
|
interface ResolvedColorVariant {
|
|
151
330
|
/** OKHSL hue (0–360). */
|
|
152
331
|
h: number;
|
|
153
332
|
/** OKHSL saturation (0–1). */
|
|
154
333
|
s: number;
|
|
155
|
-
/**
|
|
156
|
-
|
|
334
|
+
/** Canonical tone (0–1, reference eps). */
|
|
335
|
+
t: number;
|
|
157
336
|
/** Opacity (0–1). Default: 1. */
|
|
158
337
|
alpha: number;
|
|
159
338
|
}
|
|
@@ -167,13 +346,33 @@ interface ResolvedColor {
|
|
|
167
346
|
/** Adaptation mode. Present only for regular colors, omitted for shadows. */
|
|
168
347
|
mode?: AdaptationMode;
|
|
169
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* A scheme tone window.
|
|
351
|
+
* - `[lo, hi]`: OKHSL-lightness endpoints (0–100) the authored tone is
|
|
352
|
+
* remapped into, using the reference eps `0.05`. The common form.
|
|
353
|
+
* - `{ lo, hi, eps }`: same, with an explicit render curvature `eps`
|
|
354
|
+
* (advanced — most palettes never need this).
|
|
355
|
+
* - `false`: disable clamping (full range `[0, 100]` at the reference eps).
|
|
356
|
+
* This removes the *boundaries*, not the tone curve.
|
|
357
|
+
*/
|
|
358
|
+
type ToneWindow = false | [number, number] | {
|
|
359
|
+
lo: number;
|
|
360
|
+
hi: number;
|
|
361
|
+
eps: number;
|
|
362
|
+
};
|
|
170
363
|
interface GlazeConfig {
|
|
171
|
-
/** Light scheme
|
|
172
|
-
|
|
173
|
-
/** Dark scheme
|
|
174
|
-
|
|
364
|
+
/** Light scheme tone window — `[lo, hi]` (default `[13, 100]`), `{ lo, hi, eps }` for advanced eps tuning, or `false` to disable clamping. */
|
|
365
|
+
lightTone?: ToneWindow;
|
|
366
|
+
/** Dark scheme tone window — `[lo, hi]` (default `[10, 95]`), `{ lo, hi, eps }`, or `false` to disable clamping. */
|
|
367
|
+
darkTone?: ToneWindow;
|
|
175
368
|
/** Saturation reduction factor for dark scheme (0–1). Default: 0.1. */
|
|
176
369
|
darkDesaturation?: number;
|
|
370
|
+
/**
|
|
371
|
+
* Saturation taper toward the tone extremes (0–1). The fraction of the
|
|
372
|
+
* tone range over which saturation rolls off at each end, where in-gamut
|
|
373
|
+
* chroma collapses. Default: 0.15. Set to 0 to disable.
|
|
374
|
+
*/
|
|
375
|
+
saturationTaper?: number;
|
|
177
376
|
/** State alias names for token export. */
|
|
178
377
|
states?: {
|
|
179
378
|
dark?: string;
|
|
@@ -183,41 +382,246 @@ interface GlazeConfig {
|
|
|
183
382
|
modes?: GlazeOutputModes;
|
|
184
383
|
/** Default tuning for all shadow colors. Per-color tuning merges field-by-field. */
|
|
185
384
|
shadowTuning?: ShadowTuning;
|
|
385
|
+
/**
|
|
386
|
+
* Automatically flip tone direction when contrast can't be met.
|
|
387
|
+
*
|
|
388
|
+
* When enabled (default `true`), the solver searches the requested
|
|
389
|
+
* tone direction first. If that direction can't reach the target,
|
|
390
|
+
* it tries the opposite direction and uses it when it passes. If neither
|
|
391
|
+
* side passes, the tone is pinned to the requested-direction
|
|
392
|
+
* extreme and a warning is emitted.
|
|
393
|
+
*
|
|
394
|
+
* Set to `false` for strict "no flip" behavior. The opposite
|
|
395
|
+
* direction is never considered: if the requested direction can't
|
|
396
|
+
* meet the target, the tone is pinned to its extreme (never
|
|
397
|
+
* falls back to the originally requested tone).
|
|
398
|
+
*/
|
|
399
|
+
autoFlip?: boolean;
|
|
186
400
|
}
|
|
187
401
|
interface GlazeConfigResolved {
|
|
188
|
-
|
|
189
|
-
|
|
402
|
+
lightTone: ToneWindow;
|
|
403
|
+
darkTone: ToneWindow;
|
|
190
404
|
darkDesaturation: number;
|
|
405
|
+
saturationTaper: number;
|
|
191
406
|
states: {
|
|
192
407
|
dark: string;
|
|
193
408
|
highContrast: string;
|
|
194
409
|
};
|
|
195
410
|
modes: Required<GlazeOutputModes>;
|
|
196
411
|
shadowTuning?: ShadowTuning;
|
|
412
|
+
autoFlip: boolean;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Per-instance config override for `glaze.color()` and `glaze()` themes.
|
|
416
|
+
* Fields that are set take priority over the live global config. Fields
|
|
417
|
+
* that are omitted fall through to the live global at resolve time.
|
|
418
|
+
*
|
|
419
|
+
* `false` for a tone window disables clamping (full range at reference eps).
|
|
420
|
+
*/
|
|
421
|
+
interface GlazeConfigOverride {
|
|
422
|
+
/** Light scheme tone window, or `false` to disable clamping. */
|
|
423
|
+
lightTone?: ToneWindow;
|
|
424
|
+
/** Dark scheme tone window, or `false` to disable clamping. */
|
|
425
|
+
darkTone?: ToneWindow;
|
|
426
|
+
/** Saturation reduction factor for dark scheme (0–1). */
|
|
427
|
+
darkDesaturation?: number;
|
|
428
|
+
/** Saturation taper toward the tone extremes (0–1). */
|
|
429
|
+
saturationTaper?: number;
|
|
430
|
+
/** Whether to auto-flip tone when contrast can't be met. */
|
|
431
|
+
autoFlip?: boolean;
|
|
432
|
+
/**
|
|
433
|
+
* Shadow tuning defaults. Only meaningful for themes; harmless on
|
|
434
|
+
* standalone color tokens.
|
|
435
|
+
*/
|
|
436
|
+
shadowTuning?: ShadowTuning;
|
|
197
437
|
}
|
|
198
438
|
/** Serialized theme configuration (no resolved values). */
|
|
199
439
|
interface GlazeThemeExport {
|
|
200
440
|
hue: number;
|
|
201
441
|
saturation: number;
|
|
202
442
|
colors: ColorMap;
|
|
443
|
+
/** Per-theme config override, if any. */
|
|
444
|
+
config?: GlazeConfigOverride;
|
|
203
445
|
}
|
|
204
446
|
/** Input for `glaze.shadow()` standalone factory. */
|
|
205
447
|
interface GlazeShadowInput {
|
|
206
|
-
/**
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
448
|
+
/**
|
|
449
|
+
* Background color — accepts any `GlazeColorValue` form: hex
|
|
450
|
+
* (`#rgb` / `#rrggbb` / `#rrggbbaa`), `rgb()` / `hsl()` / `okhsl()`
|
|
451
|
+
* / `oklch()` strings, or literal objects (`{ r, g, b }`, `{ h, s, l }`,
|
|
452
|
+
* `{ l, c, h }`). Alpha components are dropped with a warning.
|
|
453
|
+
*/
|
|
454
|
+
bg: GlazeColorValue;
|
|
455
|
+
/**
|
|
456
|
+
* Foreground color for tinting + intensity modulation. Accepts the
|
|
457
|
+
* same forms as `bg`.
|
|
458
|
+
*/
|
|
459
|
+
fg?: GlazeColorValue;
|
|
210
460
|
/** Intensity 0-100. */
|
|
211
461
|
intensity: number;
|
|
212
462
|
tuning?: ShadowTuning;
|
|
213
463
|
}
|
|
214
|
-
/** Input for `glaze.color()`
|
|
464
|
+
/** Input for the structured `glaze.color()` overload. */
|
|
215
465
|
interface GlazeColorInput {
|
|
216
466
|
hue: number;
|
|
217
467
|
saturation: number;
|
|
218
|
-
|
|
468
|
+
tone: HCPair<number | ExtremeValue>;
|
|
219
469
|
saturationFactor?: number;
|
|
220
470
|
mode?: AdaptationMode;
|
|
471
|
+
/** Flip out-of-bounds results instead of clamping. Default: global `autoFlip`. */
|
|
472
|
+
flip?: boolean;
|
|
473
|
+
/**
|
|
474
|
+
* Fixed opacity (0–1). Output includes alpha in the CSS value.
|
|
475
|
+
* Combining with `contrast` is not recommended (perceived tone
|
|
476
|
+
* becomes unpredictable) — a `console.warn` is emitted in that case.
|
|
477
|
+
*/
|
|
478
|
+
opacity?: number;
|
|
479
|
+
/**
|
|
480
|
+
* Optional dependency on another color. Same semantics as
|
|
481
|
+
* `GlazeColorOverrides.base` — `contrast` and relative `tone`
|
|
482
|
+
* anchor to the base per scheme.
|
|
483
|
+
*/
|
|
484
|
+
base?: GlazeColorToken | GlazeColorValue;
|
|
485
|
+
/**
|
|
486
|
+
* Contrast floor against `base`. Requires `base` to be set. A bare
|
|
487
|
+
* number/preset is WCAG; use `{ wcag }` / `{ apca }` to pick the metric.
|
|
488
|
+
*/
|
|
489
|
+
contrast?: HCPair<ContrastSpec>;
|
|
490
|
+
/**
|
|
491
|
+
* Optional human-readable name for the token. Used in error and
|
|
492
|
+
* warning messages (otherwise an internal name like `"value"` is
|
|
493
|
+
* used). Does not affect output keys.
|
|
494
|
+
*/
|
|
495
|
+
name?: string;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Any single-color input form accepted by the value-shorthand
|
|
499
|
+
* overload of `glaze.color()`.
|
|
500
|
+
*
|
|
501
|
+
* Strings cover hex (`#rgb` / `#rrggbb` / `#rrggbbaa`, alpha dropped
|
|
502
|
+
* with a warning) and the four CSS color functions Glaze itself emits:
|
|
503
|
+
* `rgb()`, `hsl()`, `okhsl()`, `oklch()` (alpha components also dropped
|
|
504
|
+
* with a warning).
|
|
505
|
+
*
|
|
506
|
+
* Literal object forms:
|
|
507
|
+
* - `{ h, s, l }` — OKHSL (h: 0–360, s/l: 0–1). Passing 0–100 for `s`/`l`
|
|
508
|
+
* throws with a hint to use the structured form.
|
|
509
|
+
* - `{ h, s, t }` — OKHST (h: 0–360, s/t: 0–1). Tone in 0–1.
|
|
510
|
+
* - `{ r, g, b }` — sRGB 0–255.
|
|
511
|
+
* - `{ l, c, h }` — OKLCh (L/C: 0–1, H: degrees), same as `oklch()` strings.
|
|
512
|
+
*/
|
|
513
|
+
type GlazeColorValue = string | OkhslColor | OkhstColor | RgbColor | OklchColor;
|
|
514
|
+
/** Color overrides for the `from` and value-shorthand inputs. */
|
|
515
|
+
interface GlazeColorOverrides {
|
|
516
|
+
/**
|
|
517
|
+
* Override hue. Number is absolute (0–360); `'+N'`/`'-N'` is relative
|
|
518
|
+
* to the extracted (or overridden) seed hue — same semantics as
|
|
519
|
+
* `RegularColorDef.hue`.
|
|
520
|
+
*/
|
|
521
|
+
hue?: number | RelativeValue;
|
|
522
|
+
/** Override seed saturation (0–100). Default: extracted from value. */
|
|
523
|
+
saturation?: number;
|
|
524
|
+
/**
|
|
525
|
+
* Override tone. Number is absolute (0–100, contrast-uniform); `'+N'`/`'-N'`
|
|
526
|
+
* is relative to the literal seed (the value passed to `glaze.color()`);
|
|
527
|
+
* `'max'` / `'min'` force to the scheme's tone extreme.
|
|
528
|
+
* Supports HCPair for high-contrast.
|
|
529
|
+
*/
|
|
530
|
+
tone?: HCPair<ToneValue>;
|
|
531
|
+
/** Saturation multiplier on the seed (0–1). Default: 1. */
|
|
532
|
+
saturationFactor?: number;
|
|
533
|
+
/**
|
|
534
|
+
* Adaptation mode. Defaults to `'auto'` for every input form, so
|
|
535
|
+
* colors automatically adapt between light and dark like an ordinary
|
|
536
|
+
* theme color. All value-shorthand inputs (strings and literal objects)
|
|
537
|
+
* preserve light tone (`lightTone: false`) and snapshot
|
|
538
|
+
* `globalConfig.darkTone` on the dark side. Only the structured
|
|
539
|
+
* `{ hue, saturation, tone }` form also snapshots
|
|
540
|
+
* `globalConfig.lightTone`.
|
|
541
|
+
*
|
|
542
|
+
* Pass `'fixed'` explicitly to opt back into the linear, non-
|
|
543
|
+
* inverting mapping; pass `'static'` to pin the same tone
|
|
544
|
+
* across every variant.
|
|
545
|
+
*/
|
|
546
|
+
mode?: AdaptationMode;
|
|
547
|
+
/**
|
|
548
|
+
* Flip out-of-bounds results (relative `tone` overshoot / unmet
|
|
549
|
+
* `contrast`) to the opposite side instead of clamping. Defaults to
|
|
550
|
+
* the global `autoFlip`.
|
|
551
|
+
*/
|
|
552
|
+
flip?: boolean;
|
|
553
|
+
/**
|
|
554
|
+
* Contrast floor. By default solved against the literal seed
|
|
555
|
+
* (the value itself); when `base` is set, solved against the base's
|
|
556
|
+
* resolved variant per scheme. Same shape as `RegularColorDef.contrast`
|
|
557
|
+
* (bare number/preset = WCAG; `{ wcag }` / `{ apca }` to pick the metric).
|
|
558
|
+
*/
|
|
559
|
+
contrast?: HCPair<ContrastSpec>;
|
|
560
|
+
/**
|
|
561
|
+
* Optional dependency on another color. Accepts either a
|
|
562
|
+
* `GlazeColorToken` (returned by another `glaze.color()`) or a raw
|
|
563
|
+
* `GlazeColorValue` (hex / CSS strings / `{ r, g, b }` / `{ h, s, l }` / …),
|
|
564
|
+
* which is automatically wrapped in `glaze.color(value)`.
|
|
565
|
+
*
|
|
566
|
+
* When set:
|
|
567
|
+
* - `contrast` is solved against the base's resolved variant
|
|
568
|
+
* per-scheme (light / dark / lightContrast / darkContrast).
|
|
569
|
+
* - Relative `tone: '+N'` / `'-N'` is anchored to the base's
|
|
570
|
+
* tone per-scheme (matches theme behavior for dependent colors).
|
|
571
|
+
* - Relative `hue: '+N'` / `'-N'` still anchors to the seed (the
|
|
572
|
+
* value passed to `glaze.color()`), not the base.
|
|
573
|
+
* - When the base was created via the structured form (with explicit
|
|
574
|
+
* `hue`/`saturation`/`tone`), it is resolved at full range
|
|
575
|
+
* (`lightTone: false`) for the linking math — ensuring the
|
|
576
|
+
* contrast/tone anchor matches the input tone, not the
|
|
577
|
+
* windowed output. The base's own `.resolve()` output is unaffected.
|
|
578
|
+
*
|
|
579
|
+
* The base token's `.resolve()` is called lazily on first resolve and
|
|
580
|
+
* its result is captured by reference; later mutations to the base's
|
|
581
|
+
* defining call don't apply (matches existing token snapshot semantics).
|
|
582
|
+
*/
|
|
583
|
+
base?: GlazeColorToken | GlazeColorValue;
|
|
584
|
+
/**
|
|
585
|
+
* Fixed opacity (0–1). Output includes alpha in the CSS value.
|
|
586
|
+
* Combining with `contrast` is not recommended (perceived tone
|
|
587
|
+
* becomes unpredictable) — a `console.warn` is emitted in that case.
|
|
588
|
+
*/
|
|
589
|
+
opacity?: number;
|
|
590
|
+
/**
|
|
591
|
+
* Optional human-readable name for the token. Used in error and
|
|
592
|
+
* warning messages (otherwise an internal name like `"value"` is
|
|
593
|
+
* used). Does not affect output keys.
|
|
594
|
+
*/
|
|
595
|
+
name?: string;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Object input for `glaze.color()` that carries a raw color value plus
|
|
599
|
+
* optional color overrides in the same object.
|
|
600
|
+
*
|
|
601
|
+
* ```ts
|
|
602
|
+
* glaze.color({ from: '#1a1a2e', base: bg, contrast: 'AA' })
|
|
603
|
+
* glaze.color({ from: { r: 38, g: 252, b: 178 }, tone: '+10' })
|
|
604
|
+
* ```
|
|
605
|
+
*/
|
|
606
|
+
interface GlazeFromInput extends GlazeColorOverrides {
|
|
607
|
+
/** The source color value. Accepts the same forms as a bare `GlazeColorValue`. */
|
|
608
|
+
from: GlazeColorValue;
|
|
609
|
+
}
|
|
610
|
+
/** Options for `GlazeColorToken.css()`. */
|
|
611
|
+
interface GlazeColorCssOptions {
|
|
612
|
+
/**
|
|
613
|
+
* Custom property base name (without leading `--`). Required.
|
|
614
|
+
* Becomes the variable identifier in the output, e.g.
|
|
615
|
+
* `name: 'brand'` → `--brand-color: …`.
|
|
616
|
+
*/
|
|
617
|
+
name: string;
|
|
618
|
+
/** Output color format. Default: 'rgb' (matches `theme.css` default). */
|
|
619
|
+
format?: GlazeColorFormat;
|
|
620
|
+
/**
|
|
621
|
+
* Suffix appended to the name. Default: '-color' (matches
|
|
622
|
+
* `theme.css` default).
|
|
623
|
+
*/
|
|
624
|
+
suffix?: string;
|
|
221
625
|
}
|
|
222
626
|
/** Return type for `glaze.color()`. */
|
|
223
627
|
interface GlazeColorToken {
|
|
@@ -228,11 +632,79 @@ interface GlazeColorToken {
|
|
|
228
632
|
/**
|
|
229
633
|
* Export as a tasty style-to-state binding (no color name key).
|
|
230
634
|
* Uses `#name` keys and state aliases (`''`, `@dark`, etc.).
|
|
231
|
-
* @see https://
|
|
635
|
+
* @see https://tasty.style/docs
|
|
232
636
|
*/
|
|
233
637
|
tasty(options?: GlazeTokenOptions): Record<string, string>;
|
|
234
638
|
/** Export as a flat JSON map (no color name key). */
|
|
235
639
|
json(options?: GlazeJsonOptions): Record<string, string>;
|
|
640
|
+
/** Export as CSS custom property declarations grouped by scheme variant. */
|
|
641
|
+
css(options: GlazeColorCssOptions): GlazeCssResult;
|
|
642
|
+
/**
|
|
643
|
+
* Serialize the token as a JSON-safe object. Captures the original
|
|
644
|
+
* input value, overrides, and config so it can be rehydrated via
|
|
645
|
+
* `glaze.colorFrom(...)`. `base` is recursively serialized.
|
|
646
|
+
*/
|
|
647
|
+
export(): GlazeColorTokenExport;
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* JSON-safe serialization of a `glaze.color()` token. Pass to
|
|
651
|
+
* `glaze.colorFrom(...)` to rehydrate.
|
|
652
|
+
*/
|
|
653
|
+
interface GlazeColorTokenExport {
|
|
654
|
+
/**
|
|
655
|
+
* Discriminator for the source overload that created the token.
|
|
656
|
+
* - `'value'`: created via `glaze.color(value)` or `glaze.color({ from, ...overrides })`.
|
|
657
|
+
* - `'structured'`: created via `glaze.color({ hue, saturation, ... })`.
|
|
658
|
+
*/
|
|
659
|
+
form: 'value' | 'structured';
|
|
660
|
+
/** Original input. For `form: 'value'` this is the raw `GlazeColorValue`; for `form: 'structured'` this is the structured input. */
|
|
661
|
+
input: GlazeColorValue | GlazeColorInputExport;
|
|
662
|
+
/**
|
|
663
|
+
* Overrides recorded at creation time. `base` is recursively
|
|
664
|
+
* serialized. Only present for `form: 'value'`.
|
|
665
|
+
*/
|
|
666
|
+
overrides?: GlazeColorOverridesExport;
|
|
667
|
+
/**
|
|
668
|
+
* Effective config snapshot at creation time — captures the merged
|
|
669
|
+
* result of the global config + any per-call override at the moment
|
|
670
|
+
* the token was created. Only fields that differ from their
|
|
671
|
+
* post-merge defaults are present. Used by `glaze.colorFrom()` to
|
|
672
|
+
* reproduce deterministic behavior across `configure()` calls.
|
|
673
|
+
*/
|
|
674
|
+
config?: GlazeConfigOverride;
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Serializable shape of a structured `glaze.color({...})` input.
|
|
678
|
+
* Differs from `GlazeColorInput` only in that `base` is replaced by an
|
|
679
|
+
* `export` instead of a token reference.
|
|
680
|
+
*/
|
|
681
|
+
interface GlazeColorInputExport {
|
|
682
|
+
hue: number;
|
|
683
|
+
saturation: number;
|
|
684
|
+
tone: HCPair<number | ExtremeValue>;
|
|
685
|
+
saturationFactor?: number;
|
|
686
|
+
mode?: AdaptationMode;
|
|
687
|
+
flip?: boolean;
|
|
688
|
+
opacity?: number;
|
|
689
|
+
base?: GlazeColorTokenExport | GlazeColorValue;
|
|
690
|
+
contrast?: HCPair<ContrastSpec>;
|
|
691
|
+
name?: string;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Serializable shape of `GlazeColorOverrides`. `base` is replaced by
|
|
695
|
+
* its export (or left as a `GlazeColorValue` if it was originally a value).
|
|
696
|
+
*/
|
|
697
|
+
interface GlazeColorOverridesExport {
|
|
698
|
+
hue?: number | RelativeValue;
|
|
699
|
+
saturation?: number;
|
|
700
|
+
tone?: HCPair<ToneValue>;
|
|
701
|
+
saturationFactor?: number;
|
|
702
|
+
mode?: AdaptationMode;
|
|
703
|
+
flip?: boolean;
|
|
704
|
+
contrast?: HCPair<ContrastSpec>;
|
|
705
|
+
base?: GlazeColorTokenExport | GlazeColorValue;
|
|
706
|
+
opacity?: number;
|
|
707
|
+
name?: string;
|
|
236
708
|
}
|
|
237
709
|
interface GlazeTheme {
|
|
238
710
|
/** The hue seed (0–360). */
|
|
@@ -272,7 +744,7 @@ interface GlazeTheme {
|
|
|
272
744
|
* Export as tasty style-to-state bindings.
|
|
273
745
|
* Uses `#name` color token keys and state aliases (`''`, `@dark`, etc.).
|
|
274
746
|
* Spread into component styles or register as a recipe via `configure({ recipes })`.
|
|
275
|
-
* @see https://
|
|
747
|
+
* @see https://tasty.style/docs
|
|
276
748
|
*/
|
|
277
749
|
tasty(options?: GlazeTokenOptions): Record<string, Record<string, string>>;
|
|
278
750
|
/** Export as plain JSON. */
|
|
@@ -284,6 +756,8 @@ interface GlazeExtendOptions {
|
|
|
284
756
|
hue?: number;
|
|
285
757
|
saturation?: number;
|
|
286
758
|
colors?: ColorMap;
|
|
759
|
+
/** Config override for the child theme. Merged with the parent's override. */
|
|
760
|
+
config?: GlazeConfigOverride;
|
|
287
761
|
}
|
|
288
762
|
interface GlazeTokenOptions {
|
|
289
763
|
/** Prefix mode. `true` uses "<themeName>-", or provide a custom map. */
|
|
@@ -317,33 +791,64 @@ interface GlazeCssResult {
|
|
|
317
791
|
lightContrast: string;
|
|
318
792
|
darkContrast: string;
|
|
319
793
|
}
|
|
794
|
+
/** Options for `glaze.palette()` creation. */
|
|
795
|
+
interface GlazePaletteOptions {
|
|
796
|
+
/**
|
|
797
|
+
* Name of the primary theme. The primary theme's tokens are duplicated
|
|
798
|
+
* without prefix in all exports, providing convenient short aliases
|
|
799
|
+
* alongside the prefixed versions. Can be overridden per-export.
|
|
800
|
+
*
|
|
801
|
+
* @example
|
|
802
|
+
* ```ts
|
|
803
|
+
* const palette = glaze.palette({ brand, accent }, { primary: 'brand' });
|
|
804
|
+
* palette.tokens()
|
|
805
|
+
* // → { light: { 'brand-surface': '...', 'surface': '...', 'accent-surface': '...' } }
|
|
806
|
+
* ```
|
|
807
|
+
*/
|
|
808
|
+
primary?: string;
|
|
809
|
+
}
|
|
810
|
+
/** Options shared by palette `tokens()`, `tasty()`, and `css()` exports. */
|
|
811
|
+
interface GlazePaletteExportOptions {
|
|
812
|
+
/**
|
|
813
|
+
* Prefix mode. `true` uses `"<themeName>-"`, or provide a custom map.
|
|
814
|
+
* Defaults to `true` for palette export methods.
|
|
815
|
+
* Set to `false` explicitly to disable prefixing. Colliding keys
|
|
816
|
+
* produce a console.warn and the first-written value wins.
|
|
817
|
+
*/
|
|
818
|
+
prefix?: boolean | Record<string, string>;
|
|
819
|
+
/**
|
|
820
|
+
* Override the palette-level primary theme for this export.
|
|
821
|
+
* Pass a theme name to set/change the primary, or `false` to disable it.
|
|
822
|
+
* When omitted, inherits the palette-level `primary`.
|
|
823
|
+
*/
|
|
824
|
+
primary?: string | false;
|
|
825
|
+
}
|
|
320
826
|
interface GlazePalette {
|
|
321
827
|
/**
|
|
322
828
|
* Export all themes as a flat token map grouped by scheme variant.
|
|
829
|
+
* Prefix defaults to `true` — all tokens are prefixed with the theme name.
|
|
830
|
+
* Inherits the palette-level `primary`; override per-call or pass `false` to disable.
|
|
323
831
|
*
|
|
324
832
|
* ```ts
|
|
325
|
-
* palette.
|
|
326
|
-
*
|
|
833
|
+
* const palette = glaze.palette({ brand, accent }, { primary: 'brand' });
|
|
834
|
+
* palette.tokens()
|
|
835
|
+
* // → { light: { 'brand-surface': '...', 'surface': '...', 'accent-surface': '...' } }
|
|
327
836
|
* ```
|
|
328
837
|
*/
|
|
329
|
-
tokens(options?: GlazeJsonOptions &
|
|
330
|
-
prefix?: boolean | Record<string, string>;
|
|
331
|
-
}): Record<string, Record<string, string>>;
|
|
838
|
+
tokens(options?: GlazeJsonOptions & GlazePaletteExportOptions): Record<string, Record<string, string>>;
|
|
332
839
|
/**
|
|
333
840
|
* Export all themes as tasty style-to-state bindings.
|
|
334
841
|
* Uses `#name` color token keys and state aliases (`''`, `@dark`, etc.).
|
|
335
|
-
*
|
|
336
|
-
* @see https://
|
|
842
|
+
* Prefix defaults to `true`. Inherits the palette-level `primary`.
|
|
843
|
+
* @see https://tasty.style/docs
|
|
337
844
|
*/
|
|
338
|
-
tasty(options?: GlazeTokenOptions): Record<string, Record<string, string>>;
|
|
339
|
-
/** Export all themes as plain JSON. */
|
|
845
|
+
tasty(options?: GlazeTokenOptions & GlazePaletteExportOptions): Record<string, Record<string, string>>;
|
|
846
|
+
/** Export all themes as plain JSON grouped by theme name. */
|
|
340
847
|
json(options?: GlazeJsonOptions & {
|
|
341
848
|
prefix?: boolean | Record<string, string>;
|
|
342
849
|
}): Record<string, Record<string, Record<string, string>>>;
|
|
343
850
|
/** Export all themes as CSS custom property declarations. */
|
|
344
|
-
css(options?: GlazeCssOptions &
|
|
345
|
-
prefix?: boolean | Record<string, string>;
|
|
346
|
-
}): GlazeCssResult;
|
|
851
|
+
css(options?: GlazeCssOptions & GlazePaletteExportOptions): GlazeCssResult;
|
|
347
852
|
}
|
|
348
853
|
//#endregion
|
|
349
854
|
//#region src/glaze.d.ts
|
|
@@ -351,49 +856,110 @@ type PaletteInput = Record<string, GlazeTheme>;
|
|
|
351
856
|
/**
|
|
352
857
|
* Create a single-hue glaze theme.
|
|
353
858
|
*
|
|
859
|
+
* An optional `config` override can be supplied to customize the resolve
|
|
860
|
+
* behavior for this theme (tone windows, saturation taper, etc.). The
|
|
861
|
+
* override is **merged over the live global config at resolve time** —
|
|
862
|
+
* the theme still reacts to later `configure()` calls for fields it
|
|
863
|
+
* didn't override.
|
|
864
|
+
*
|
|
354
865
|
* @example
|
|
355
866
|
* ```ts
|
|
356
|
-
* const primary = glaze({ hue: 280, saturation: 80 });
|
|
357
|
-
* // or shorthand:
|
|
358
867
|
* const primary = glaze(280, 80);
|
|
868
|
+
* // or shorthand:
|
|
869
|
+
* const primary = glaze({ hue: 280, saturation: 80 });
|
|
870
|
+
* // with config override:
|
|
871
|
+
* const raw = glaze(280, 80, { lightTone: false });
|
|
359
872
|
* ```
|
|
360
873
|
*/
|
|
361
874
|
declare function glaze(hueOrOptions: number | {
|
|
362
875
|
hue: number;
|
|
363
876
|
saturation: number;
|
|
364
|
-
}, saturation?: number): GlazeTheme;
|
|
877
|
+
}, saturation?: number, config?: GlazeConfigOverride): GlazeTheme;
|
|
365
878
|
declare namespace glaze {
|
|
366
879
|
var configure: (config: GlazeConfig) => void;
|
|
367
|
-
var palette: (themes: PaletteInput) =>
|
|
368
|
-
tokens(options?: GlazeJsonOptions & {
|
|
369
|
-
prefix?: boolean | Record<string, string>;
|
|
370
|
-
}): Record<string, Record<string, string>>;
|
|
371
|
-
tasty(options?: GlazeTokenOptions): Record<string, Record<string, string>>;
|
|
372
|
-
json(options?: GlazeJsonOptions & {
|
|
373
|
-
prefix?: boolean | Record<string, string>;
|
|
374
|
-
}): Record<string, Record<string, Record<string, string>>>;
|
|
375
|
-
css(options?: GlazeCssOptions & {
|
|
376
|
-
prefix?: boolean | Record<string, string>;
|
|
377
|
-
}): GlazeCssResult;
|
|
378
|
-
};
|
|
880
|
+
var palette: (themes: PaletteInput, options?: GlazePaletteOptions) => GlazePalette;
|
|
379
881
|
var from: (data: GlazeThemeExport) => GlazeTheme;
|
|
380
|
-
var color: (input: GlazeColorInput) => GlazeColorToken;
|
|
882
|
+
var color: (input: GlazeFromInput | GlazeColorInput | GlazeColorValue, config?: GlazeConfigOverride) => GlazeColorToken;
|
|
381
883
|
var shadow: (input: GlazeShadowInput) => ResolvedColorVariant;
|
|
382
884
|
var format: (variant: ResolvedColorVariant, colorFormat?: GlazeColorFormat) => string;
|
|
383
885
|
var fromHex: (hex: string) => GlazeTheme;
|
|
384
886
|
var fromRgb: (r: number, g: number, b: number) => GlazeTheme;
|
|
887
|
+
var colorFrom: (data: GlazeColorTokenExport) => GlazeColorToken;
|
|
385
888
|
var getConfig: () => GlazeConfigResolved;
|
|
386
889
|
var resetConfig: () => void;
|
|
387
890
|
}
|
|
388
891
|
//#endregion
|
|
892
|
+
//#region src/okhst.d.ts
|
|
893
|
+
/**
|
|
894
|
+
* Reference eps for the OKHST color space. WCAG 2 contrast is
|
|
895
|
+
* `(Y_hi + 0.05) / (Y_lo + 0.05)`, so an eps of `0.05` makes equal tone
|
|
896
|
+
* steps yield equal WCAG contrast. This is the canonical eps used by
|
|
897
|
+
* `okhst()` input, `{ h, s, t }` input, stored `ResolvedColorVariant.t`,
|
|
898
|
+
* relative `tone` offsets, and the contrast solver.
|
|
899
|
+
*/
|
|
900
|
+
declare const REF_EPS = 0.05;
|
|
901
|
+
/**
|
|
902
|
+
* Map a luminance `Y` (0–1) to tone (0–100) at the given eps.
|
|
903
|
+
* `toneFromY(0) === 0` and `toneFromY(1) === 100` for any eps.
|
|
904
|
+
*/
|
|
905
|
+
declare function toneFromY(y: number, eps?: number): number;
|
|
906
|
+
/** Map a tone (0–100) back to luminance (0–1). Inverse of {@link toneFromY}. */
|
|
907
|
+
declare function yFromTone(t: number, eps?: number): number;
|
|
908
|
+
/** OKHSL lightness (0–1) -> tone (0–100). */
|
|
909
|
+
declare function toTone(l: number, eps?: number): number;
|
|
910
|
+
/** Tone (0–100) -> OKHSL lightness (0–1). Inverse of {@link toTone}. */
|
|
911
|
+
declare function fromTone(t: number, eps?: number): number;
|
|
912
|
+
/** Convert OKHST `{ h, s, t }` (t in 0–1) to OKHSL `{ h, s, l }`. */
|
|
913
|
+
declare function okhstToOkhsl(c: {
|
|
914
|
+
h: number;
|
|
915
|
+
s: number;
|
|
916
|
+
t: number;
|
|
917
|
+
}): {
|
|
918
|
+
h: number;
|
|
919
|
+
s: number;
|
|
920
|
+
l: number;
|
|
921
|
+
};
|
|
922
|
+
/** Convert OKHSL `{ h, s, l }` to OKHST `{ h, s, t }` (t in 0–1). */
|
|
923
|
+
declare function okhslToOkhst(c: {
|
|
924
|
+
h: number;
|
|
925
|
+
s: number;
|
|
926
|
+
l: number;
|
|
927
|
+
}): {
|
|
928
|
+
h: number;
|
|
929
|
+
s: number;
|
|
930
|
+
t: number;
|
|
931
|
+
};
|
|
932
|
+
/**
|
|
933
|
+
* Edge adapter: a resolved variant stores canonical tone `t` (0–1). Convert
|
|
934
|
+
* it to the OKHSL `{ h, s, l }` the formatters and luminance pipeline expect.
|
|
935
|
+
*/
|
|
936
|
+
declare function variantToOkhsl(v: {
|
|
937
|
+
h: number;
|
|
938
|
+
s: number;
|
|
939
|
+
t: number;
|
|
940
|
+
}): {
|
|
941
|
+
h: number;
|
|
942
|
+
s: number;
|
|
943
|
+
l: number;
|
|
944
|
+
};
|
|
945
|
+
//#endregion
|
|
389
946
|
//#region src/okhsl-color-math.d.ts
|
|
390
947
|
/**
|
|
391
948
|
* OKHSL color math primitives for the glaze theme generator.
|
|
392
949
|
*
|
|
393
|
-
* Provides bidirectional OKHSL ↔ sRGB conversion,
|
|
394
|
-
*
|
|
395
|
-
* (okhsl, rgb, hsl, oklch).
|
|
950
|
+
* Provides bidirectional OKHSL ↔ sRGB conversion, luminance computation
|
|
951
|
+
* for both contrast metrics (WCAG 2 relative luminance and APCA screen
|
|
952
|
+
* luminance `Ys`), and multi-format output (okhsl, rgb, hsl, oklch).
|
|
953
|
+
*/
|
|
954
|
+
type Vec3 = [number, number, number];
|
|
955
|
+
/**
|
|
956
|
+
* OKHSL toe function: maps OKLab lightness L to perceptual lightness l.
|
|
957
|
+
* Exported for the OKHST tone transfers in `okhst.ts`.
|
|
958
|
+
*/
|
|
959
|
+
/**
|
|
960
|
+
* Convert OKHSL (h: 0–360, s: 0–1, l: 0–1) to OKLab [L, a, b].
|
|
396
961
|
*/
|
|
962
|
+
declare function okhslToOklab(h: number, s: number, l: number): [number, number, number];
|
|
397
963
|
/**
|
|
398
964
|
* Convert OKHSL (h: 0–360, s: 0–1, l: 0–1) to linear sRGB.
|
|
399
965
|
* Channels may exceed [0, 1] near gamut boundaries — caller must clamp if needed.
|
|
@@ -413,26 +979,55 @@ declare function contrastRatioFromLuminance(yA: number, yB: number): number;
|
|
|
413
979
|
*/
|
|
414
980
|
declare function okhslToSrgb(h: number, s: number, l: number): [number, number, number];
|
|
415
981
|
/**
|
|
416
|
-
*
|
|
982
|
+
* Compute WCAG 2 relative luminance from linear sRGB, matching the browser
|
|
983
|
+
* rendering pipeline: gamma-encode, clamp to sRGB gamut [0,1], then linearize.
|
|
984
|
+
* This avoids over/under-estimating luminance for out-of-gamut OKHSL colors.
|
|
417
985
|
*/
|
|
418
|
-
declare function
|
|
986
|
+
declare function gamutClampedLuminance(linearRgb: [number, number, number]): number;
|
|
987
|
+
/**
|
|
988
|
+
* Convert OKLab to OKHSL.
|
|
989
|
+
* Input: [L, a, b] where L: 0–1, a/b: roughly -0.5 to 0.5.
|
|
990
|
+
* Returns [h, s, l] where h: 0–360, s: 0–1, l: 0–1.
|
|
991
|
+
*/
|
|
992
|
+
declare const oklabToOkhsl: (lab: Vec3) => Vec3;
|
|
419
993
|
/**
|
|
420
994
|
* Convert gamma-encoded sRGB (0–1 per channel) to OKHSL.
|
|
421
995
|
* Returns [h, s, l] where h: 0–360, s: 0–1, l: 0–1.
|
|
422
996
|
*/
|
|
423
997
|
declare function srgbToOkhsl(rgb: [number, number, number]): [number, number, number];
|
|
998
|
+
/**
|
|
999
|
+
* Convert CSS HSL (sRGB-based) to gamma-encoded sRGB [r, g, b] in 0–1 range.
|
|
1000
|
+
* h: 0–360, s: 0–1, l: 0–1.
|
|
1001
|
+
*
|
|
1002
|
+
* Note: CSS HSL is not the same as OKHSL — it's HSL in the sRGB color space.
|
|
1003
|
+
* Use this when parsing `hsl(...)` strings before passing to `srgbToOkhsl`.
|
|
1004
|
+
*/
|
|
1005
|
+
declare function hslToSrgb(h: number, s: number, l: number): [number, number, number];
|
|
424
1006
|
/**
|
|
425
1007
|
* Parse a hex color string (#rgb or #rrggbb) to sRGB [r, g, b] in 0–1 range.
|
|
426
1008
|
* Returns null if the string is not a valid hex color.
|
|
1009
|
+
*
|
|
1010
|
+
* For 8-digit hex (`#rrggbbaa`) and 4-digit hex (`#rgba`) with alpha,
|
|
1011
|
+
* use {@link parseHexAlpha}.
|
|
427
1012
|
*/
|
|
428
1013
|
declare function parseHex(hex: string): [number, number, number] | null;
|
|
1014
|
+
/**
|
|
1015
|
+
* Parse a hex color string (#rgb, #rrggbb, #rgba, or #rrggbbaa) to
|
|
1016
|
+
* sRGB [r, g, b] in 0–1 range plus an optional alpha (0–1).
|
|
1017
|
+
* Returns null if the string is not a valid hex color.
|
|
1018
|
+
*/
|
|
1019
|
+
declare function parseHexAlpha(hex: string): {
|
|
1020
|
+
rgb: [number, number, number];
|
|
1021
|
+
alpha?: number;
|
|
1022
|
+
} | null;
|
|
429
1023
|
/**
|
|
430
1024
|
* Format OKHSL values as a CSS `okhsl(H S% L%)` string.
|
|
431
1025
|
* h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
|
|
432
1026
|
*/
|
|
433
1027
|
declare function formatOkhsl(h: number, s: number, l: number): string;
|
|
434
1028
|
/**
|
|
435
|
-
* Format OKHSL values as a CSS `rgb(R G B)` string
|
|
1029
|
+
* Format OKHSL values as a CSS `rgb(R G B)` string.
|
|
1030
|
+
* Uses 2 decimal places to avoid 8-bit quantization contrast loss.
|
|
436
1031
|
* h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
|
|
437
1032
|
*/
|
|
438
1033
|
declare function formatRgb(h: number, s: number, l: number): string;
|
|
@@ -447,5 +1042,5 @@ declare function formatHsl(h: number, s: number, l: number): string;
|
|
|
447
1042
|
*/
|
|
448
1043
|
declare function formatOklch(h: number, s: number, l: number): string;
|
|
449
1044
|
//#endregion
|
|
450
|
-
export { type AdaptationMode, type ColorDef, type ColorMap, type ContrastPreset, type
|
|
1045
|
+
export { type AdaptationMode, type ColorDef, type ColorMap, type ContrastPreset, type ContrastSpec, type ExtremeValue, type FindToneForContrastOptions, type FindToneForContrastResult, type FindValueForMixContrastOptions, type FindValueForMixContrastResult, type GlazeColorCssOptions, type GlazeColorFormat, type GlazeColorInput, type GlazeColorInputExport, type GlazeColorOverrides, type GlazeColorOverridesExport, type GlazeColorToken, type GlazeColorTokenExport, type GlazeColorValue, type GlazeConfig, type GlazeConfigOverride, type GlazeConfigResolved, type GlazeCssOptions, type GlazeCssResult, type GlazeExtendOptions, type GlazeFromInput, type GlazeJsonOptions, type GlazeOutputModes, type GlazePalette, type GlazePaletteExportOptions, type GlazePaletteOptions, type GlazeShadowInput, type GlazeTheme, type GlazeThemeExport, type GlazeTokenOptions, type HCPair, type HexColor, type MinContrast, type MixColorDef, type OkhslColor, type OkhstColor, type OklchColor, REF_EPS, type RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type ResolvedContrast, type RgbColor, type ShadowColorDef, type ShadowTuning, type ToneValue, type ToneWindow, apcaContrast, contrastRatioFromLuminance, findToneForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOklch, formatRgb, fromTone, gamutClampedLuminance, glaze, hslToSrgb, okhslToLinearSrgb, okhslToOkhst, okhslToOklab, okhslToSrgb, okhstToOkhsl, oklabToOkhsl, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveContrastForMode, resolveMinContrast, srgbToOkhsl, toTone, toneFromY, variantToOkhsl, yFromTone };
|
|
451
1046
|
//# sourceMappingURL=index.d.cts.map
|