@tenphi/glaze 0.0.0-snapshot.63c08ea → 0.0.0-snapshot.6b78fce
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +158 -0
- package/README.md +108 -34
- package/dist/index.cjs +2812 -1274
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +605 -138
- package/dist/index.d.mts +605 -138
- package/dist/index.mjs +2807 -1275
- package/dist/index.mjs.map +1 -1
- package/docs/contrast.mdx +726 -0
- package/docs/exporting.mdx +628 -0
- package/docs/getting-started.mdx +486 -0
- package/docs/methodology.mdx +972 -0
- package/docs/migration.md +286 -345
- package/docs/mixes.mdx +271 -0
- package/docs/okhst.mdx +604 -0
- package/docs/reference/color-definitions.md +498 -0
- package/docs/reference/color-tokens.md +398 -0
- package/docs/reference/configuration.md +456 -0
- package/docs/reference/contrast.md +276 -0
- package/docs/reference/index.md +218 -0
- package/docs/reference/output.md +607 -0
- package/docs/reference/palette.md +395 -0
- package/docs/reference/theme.md +326 -0
- package/docs/reference/utilities.md +532 -0
- package/docs/schemes.mdx +550 -0
- package/docs/shadows-and-glows.mdx +509 -0
- package/package.json +12 -3
- package/docs/api.md +0 -1506
- package/docs/methodology.md +0 -561
- package/docs/okhst.md +0 -308
package/dist/index.d.mts
CHANGED
|
@@ -62,6 +62,24 @@ declare function resolveMinContrast(value: MinContrast$1): number;
|
|
|
62
62
|
* selected spec rather than an outer pair).
|
|
63
63
|
*/
|
|
64
64
|
declare function resolveContrastForMode(spec: ContrastSpec, isHighContrast: boolean, polarity?: 'fg' | 'bg', outerExplicitHC?: boolean): ResolvedContrast;
|
|
65
|
+
/**
|
|
66
|
+
* Resolve a `contrast` spec — including its outer `[normal, highContrast]`
|
|
67
|
+
* pair — at a manual contrast `level` (0–100), by resolving both ends and
|
|
68
|
+
* interpolating the numeric target.
|
|
69
|
+
*
|
|
70
|
+
* Level 0 / 100 delegate verbatim to {@link resolveContrastForMode}, so the
|
|
71
|
+
* endpoints are bit-identical to classic normal / high-contrast resolution.
|
|
72
|
+
* Resolving each end fully first also means every rule that governs the
|
|
73
|
+
* escalation still applies at both ends for free: preset mapping, the
|
|
74
|
+
* `APCA_MAX_LC` clamp, and the explicit-HC suppression that cancels the
|
|
75
|
+
* `AA → AAA` promotion and the `+15 Lc` enhancement.
|
|
76
|
+
*
|
|
77
|
+
* Throws when the two ends measure in different metrics — a WCAG ratio and an
|
|
78
|
+
* APCA Lc live on different scales, so there is no target between them. Such a
|
|
79
|
+
* pair is rejected at authoring time by `validateColorDefs`; this is the guard
|
|
80
|
+
* for direct callers.
|
|
81
|
+
*/
|
|
82
|
+
declare function resolveContrastForLevel(spec: HCPair<ContrastSpec>, level: number, polarity?: 'fg' | 'bg'): ResolvedContrast;
|
|
65
83
|
/**
|
|
66
84
|
* APCA lightness contrast (Lc), signed: positive for dark text on light bg,
|
|
67
85
|
* negative for light text on dark bg. Inputs are screen luminances (0–1).
|
|
@@ -84,10 +102,31 @@ interface FindToneForContrastOptions {
|
|
|
84
102
|
epsilon?: number;
|
|
85
103
|
/** Maximum binary-search iterations per branch. Default: 18. */
|
|
86
104
|
maxIterations?: number;
|
|
87
|
-
/**
|
|
105
|
+
/**
|
|
106
|
+
* Preferred search direction before auto-flip is considered. Default: the
|
|
107
|
+
* side whose bound scores higher (the only open side when `preferredTone`
|
|
108
|
+
* sits on a bound); a tie within float noise starts `'darker'`.
|
|
109
|
+
*/
|
|
88
110
|
initialDirection?: 'lighter' | 'darker';
|
|
89
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* Also search the opposite direction. Default: false. When both directions
|
|
113
|
+
* meet the target, the result nearer `preferredTone` wins; a gap within
|
|
114
|
+
* twice the search resolution is a tie and keeps `initialDirection`.
|
|
115
|
+
*/
|
|
90
116
|
flip?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* When `flip` is on and *both* directions meet the target, keep
|
|
119
|
+
* `initialDirection` instead of taking whichever result lands nearer the
|
|
120
|
+
* preferred tone. Default: false (nearest wins).
|
|
121
|
+
*
|
|
122
|
+
* The nearest-wins tie-break is unstable along a ramp of targets: which side
|
|
123
|
+
* is nearer shifts as the target grows, so a color can swap sides between two
|
|
124
|
+
* adjacent targets. Set this when a caller needs the side to be a property of
|
|
125
|
+
* the color rather than of the target — the manual contrast level does. The
|
|
126
|
+
* flip itself is unaffected: an initial direction that cannot reach the
|
|
127
|
+
* target still falls back to the opposite side.
|
|
128
|
+
*/
|
|
129
|
+
preferInitial?: boolean;
|
|
91
130
|
/** Use the hue-independent "safe" chroma boundary. Default: false. */
|
|
92
131
|
pastel?: boolean;
|
|
93
132
|
}
|
|
@@ -98,26 +137,37 @@ interface FindToneForContrastResult {
|
|
|
98
137
|
contrast: number;
|
|
99
138
|
/** Whether the target was reached. */
|
|
100
139
|
met: boolean;
|
|
101
|
-
/**
|
|
140
|
+
/**
|
|
141
|
+
* The side the result was found on. The two sides meet at `preferredTone`,
|
|
142
|
+
* so a met result sits on that side of the base too. `'preferred'` when the
|
|
143
|
+
* result is `preferredTone` itself: it already cleared the overshooting
|
|
144
|
+
* search target, or no searched side met the floor while it clears the bare
|
|
145
|
+
* target (or there was no room to search).
|
|
146
|
+
*/
|
|
102
147
|
branch: 'lighter' | 'darker' | 'preferred';
|
|
103
148
|
/** Whether the result auto-flipped to the opposite direction. */
|
|
104
149
|
flipped?: boolean;
|
|
105
150
|
}
|
|
106
151
|
/**
|
|
107
152
|
* Find the tone that satisfies a contrast floor against a base color,
|
|
108
|
-
* staying as close to `preferredTone` as possible.
|
|
153
|
+
* staying as close to `preferredTone` as possible. A searched result keeps the
|
|
154
|
+
* overshoot (1% for WCAG, 0.5 Lc for APCA). When no searched side reaches the
|
|
155
|
+
* floor, the result pins to the initial direction's extreme, unmet — unless
|
|
156
|
+
* `preferredTone` itself clears the bare target, which is then kept as met.
|
|
109
157
|
*/
|
|
110
158
|
declare function findToneForContrast(options: FindToneForContrastOptions): FindToneForContrastResult;
|
|
111
159
|
interface FindValueForMixContrastOptions {
|
|
112
160
|
/** Preferred mix parameter (0–1). */
|
|
113
161
|
preferredValue: number;
|
|
114
|
-
/** Base color as linear sRGB. */
|
|
162
|
+
/** Base color as linear sRGB — the color the mix is measured against. */
|
|
115
163
|
baseLinearRgb: LinearRgb;
|
|
116
|
-
/** Target color as linear sRGB. */
|
|
117
|
-
targetLinearRgb: LinearRgb;
|
|
118
164
|
/** Resolved contrast floor (metric + target). */
|
|
119
165
|
contrast: ResolvedContrast;
|
|
120
|
-
/**
|
|
166
|
+
/**
|
|
167
|
+
* Luminance of the mixed color at parameter t, in the metric's basis
|
|
168
|
+
* ({@link metricLuminance}). This closure is the only view the solver has of
|
|
169
|
+
* the mix's target color, blend, and color space.
|
|
170
|
+
*/
|
|
121
171
|
luminanceAtValue: (t: number) => number;
|
|
122
172
|
/** Convergence threshold. Default: 1e-4. */
|
|
123
173
|
epsilon?: number;
|
|
@@ -135,6 +185,9 @@ interface FindValueForMixContrastResult {
|
|
|
135
185
|
/**
|
|
136
186
|
* Find the mix parameter (ratio or opacity) that satisfies a contrast floor
|
|
137
187
|
* against a base color, staying as close to `preferredValue` as possible.
|
|
188
|
+
* Misses pin to the initial direction's end like the tone solver, and a
|
|
189
|
+
* `preferredValue` that clears the bare target is kept as met when no searched
|
|
190
|
+
* side reaches the floor (a value of 1 has no room toward the target).
|
|
138
191
|
*/
|
|
139
192
|
declare function findValueForMixContrast(options: FindValueForMixContrastOptions): FindValueForMixContrastResult;
|
|
140
193
|
//#endregion
|
|
@@ -200,7 +253,15 @@ type GlazeColorFormat = 'okhsl' | 'okhst' | 'rgb' | 'hsl' | 'oklch';
|
|
|
200
253
|
interface GlazeOutputModes {
|
|
201
254
|
/** Include dark scheme variants. Default: true. */
|
|
202
255
|
dark?: boolean;
|
|
203
|
-
/**
|
|
256
|
+
/**
|
|
257
|
+
* Include high-contrast variants (both light-HC and dark-HC). Default: false.
|
|
258
|
+
*
|
|
259
|
+
* Independent of `contrastLevel` — the level positions the normal variants
|
|
260
|
+
* while these stay the true high-contrast resolution, so the two compose. The
|
|
261
|
+
* exception is a global level of 100, where the normal variants already *are*
|
|
262
|
+
* the high-contrast ones: the tier would duplicate them and is dropped.
|
|
263
|
+
* @see GlazeConfig.contrastLevel
|
|
264
|
+
*/
|
|
204
265
|
highContrast?: boolean;
|
|
205
266
|
}
|
|
206
267
|
/** Hex color string for DX hints. Runtime validation in `parseHex()`. */
|
|
@@ -234,13 +295,43 @@ interface OklchColor {
|
|
|
234
295
|
}
|
|
235
296
|
interface RegularColorDef {
|
|
236
297
|
/**
|
|
237
|
-
*
|
|
298
|
+
* Seed this color from a literal color instead of from the theme.
|
|
299
|
+
*
|
|
300
|
+
* Accepts the same values as `glaze.color()` — hex, `rgb()`, `hsl()`,
|
|
301
|
+
* `okhsl()`, `okhst()`, `oklch()`, or a value object. It supplies three
|
|
302
|
+
* things at once: `hue`, `tone`, and — unlike every other color in a theme —
|
|
303
|
+
* an **absolute saturation** rather than a factor of the seed. That last
|
|
304
|
+
* part is the point: a color can now be more saturated than its theme, so
|
|
305
|
+
* honoring a brand color no longer means re-seeding the whole theme to reach
|
|
306
|
+
* it.
|
|
307
|
+
*
|
|
308
|
+
* The **light, normal-contrast** variant reproduces the value exactly
|
|
309
|
+
* (a local `lightTone: false`, matching the value-shorthand form of
|
|
310
|
+
* `glaze.color()`). Dark and high-contrast variants adapt as usual — they
|
|
311
|
+
* are where readability outranks fidelity, and a color pinned across every
|
|
312
|
+
* scheme would defeat both. A `contrast` floor still applies everywhere and
|
|
313
|
+
* still only moves the color when the authored value misses it.
|
|
314
|
+
*
|
|
315
|
+
* Sibling fields override what the value supplied, so
|
|
316
|
+
* `{ from: '#2F5BFF', hue: 300 }` keeps its saturation and tone but rotates
|
|
317
|
+
* the hue.
|
|
318
|
+
*/
|
|
319
|
+
from?: GlazeColorValue;
|
|
320
|
+
/**
|
|
321
|
+
* Tone value (0–100, contrast-uniform — see `docs/okhst.mdx`).
|
|
238
322
|
* - Number: absolute tone.
|
|
239
323
|
* - String ('+N' / '-N'): relative to base color's tone (requires `base`).
|
|
240
324
|
* - `'max'` / `'min'`: force to the scheme's tone extreme (no base needed).
|
|
325
|
+
*
|
|
326
|
+
* Defaults to the tone of `from` when that is set.
|
|
241
327
|
*/
|
|
242
328
|
tone?: HCPair<ToneValue>;
|
|
243
|
-
/**
|
|
329
|
+
/**
|
|
330
|
+
* Saturation factor applied to the seed saturation (0–1, default: 1).
|
|
331
|
+
*
|
|
332
|
+
* With `from`, an explicit value here is still a factor of the seed and
|
|
333
|
+
* overrides the absolute saturation the color carried.
|
|
334
|
+
*/
|
|
244
335
|
saturation?: number;
|
|
245
336
|
/**
|
|
246
337
|
* Hue override for this color.
|
|
@@ -248,6 +339,26 @@ interface RegularColorDef {
|
|
|
248
339
|
* - String ('+N' / '-N'): relative to the theme seed hue.
|
|
249
340
|
*/
|
|
250
341
|
hue?: number | RelativeValue;
|
|
342
|
+
/**
|
|
343
|
+
* Dark-scheme hue override. Applies to the `dark` and `darkContrast`
|
|
344
|
+
* variants; falls back to `hue` when omitted.
|
|
345
|
+
* - Number: absolute hue (0–360).
|
|
346
|
+
* - String ('+N' / '-N'): relative to the theme's **dark** seed hue
|
|
347
|
+
* (`GlazeTheme.darkHue`, itself defaulting to the light seed hue).
|
|
348
|
+
*
|
|
349
|
+
* Ignored under `mode: 'static'`, which pins one value across all schemes.
|
|
350
|
+
*/
|
|
351
|
+
darkHue?: number | RelativeValue;
|
|
352
|
+
/**
|
|
353
|
+
* Dark-scheme saturation factor (0–1) applied to the dark seed
|
|
354
|
+
* saturation. Applies to the `dark` and `darkContrast` variants; falls
|
|
355
|
+
* back to `saturation` when omitted.
|
|
356
|
+
*
|
|
357
|
+
* When set, the global `darkDesaturation` reduction is **not** applied on
|
|
358
|
+
* top — the resulting saturation is taken literally. Ignored under
|
|
359
|
+
* `mode: 'static'`.
|
|
360
|
+
*/
|
|
361
|
+
darkSaturation?: number;
|
|
251
362
|
/** Name of another color in the same theme (dependent color). */
|
|
252
363
|
base?: string;
|
|
253
364
|
/**
|
|
@@ -261,7 +372,8 @@ interface RegularColorDef {
|
|
|
261
372
|
* Whether to flip out-of-bounds results to the opposite side instead of
|
|
262
373
|
* clamping to the extreme. Affects both:
|
|
263
374
|
* - relative `tone`: when `base ± delta` exceeds `[0, 100]`, mirror the
|
|
264
|
-
* delta to the other side of the base.
|
|
375
|
+
* delta to the other side of the base. If the mirrored target is also
|
|
376
|
+
* out of range, keep the original delta and clamp on the authored side.
|
|
265
377
|
* - `contrast`: when the requested direction can't meet the floor, try the
|
|
266
378
|
* opposite side (same as the global `autoFlip`).
|
|
267
379
|
*
|
|
@@ -280,8 +392,8 @@ interface RegularColorDef {
|
|
|
280
392
|
/**
|
|
281
393
|
* Per-color override for the hue-independent "safe" chroma limit used in
|
|
282
394
|
* OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
|
|
283
|
-
* Falls through to the
|
|
284
|
-
* @see
|
|
395
|
+
* Falls through to the per-theme / per-token `pastel` override when omitted.
|
|
396
|
+
* @see GlazeConfigOverride.pastel
|
|
285
397
|
*/
|
|
286
398
|
pastel?: boolean;
|
|
287
399
|
/**
|
|
@@ -300,44 +412,63 @@ interface RegularColorDef {
|
|
|
300
412
|
*/
|
|
301
413
|
inherit?: boolean;
|
|
302
414
|
}
|
|
303
|
-
/**
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
415
|
+
/**
|
|
416
|
+
* Tuning shared by `shadow` and `glow`. Global defaults come from
|
|
417
|
+
* `shadowTuning` / `glowTuning`; a per-color `tuning` merges over them field
|
|
418
|
+
* by field.
|
|
419
|
+
*/
|
|
420
|
+
interface LightingTuning {
|
|
421
|
+
/**
|
|
422
|
+
* β — how strongly the object (`fg`) scales the step. The step is
|
|
423
|
+
* `intensity × k` with `k = max(0, 1 + β · d · (t_bg − t_fg) / 100)`,
|
|
424
|
+
* `d = +1` for a shadow and `−1` for a glow: a darker object deepens its
|
|
425
|
+
* shadow, a lighter one strengthens its glow. An object at the surface's
|
|
426
|
+
* own tone (or no `fg`) gives exactly `intensity`. `0` ignores the object.
|
|
427
|
+
* Default: 0.5.
|
|
428
|
+
*/
|
|
429
|
+
objectInfluence?: number;
|
|
430
|
+
/**
|
|
431
|
+
* Pigment saturation (0–1) in the surface's hue. Default: 0 (neutral black /
|
|
432
|
+
* white). Shows only with `reach` below 1 — pure black and white have no hue.
|
|
433
|
+
*/
|
|
434
|
+
tint?: number;
|
|
313
435
|
/**
|
|
314
|
-
*
|
|
315
|
-
* Default:
|
|
436
|
+
* Where the pigment sits (0–1): the fraction of the way from the surface's
|
|
437
|
+
* tone to black (shadow) / white (glow). Default: 1 (pure black / white),
|
|
438
|
+
* the most reach. Lower values let a `tint` show at the cost of reach.
|
|
316
439
|
*/
|
|
317
|
-
|
|
318
|
-
/** Max alpha (0-1). Reached at intensity=100 with max contrast. Default: 1.0. */
|
|
319
|
-
alphaMax?: number;
|
|
440
|
+
reach?: number;
|
|
320
441
|
/**
|
|
321
|
-
*
|
|
322
|
-
* 0
|
|
442
|
+
* Pull (0–1) of the pigment hue from the surface's hue toward the object's
|
|
443
|
+
* (`fg`) hue. Default: 0. Needs `fg`, a `tint`, and `reach` below 1 to show.
|
|
323
444
|
*/
|
|
324
|
-
|
|
445
|
+
hueBleed?: number;
|
|
325
446
|
}
|
|
447
|
+
/** Tuning for `shadow` colors. Same shape as {@link GlowTuning}. */
|
|
448
|
+
type ShadowTuning = LightingTuning;
|
|
449
|
+
/** Tuning for `glow` colors. Same shape as {@link ShadowTuning}. */
|
|
450
|
+
type GlowTuning = LightingTuning;
|
|
451
|
+
/**
|
|
452
|
+
* A translucent dark overlay that lands the surface (`bg`) exactly
|
|
453
|
+
* `intensity` tones darker in every scheme — a shade for state layers and
|
|
454
|
+
* scrims, or, with `fg`, an object-aware drop shadow.
|
|
455
|
+
*/
|
|
326
456
|
interface ShadowColorDef {
|
|
327
457
|
type: 'shadow';
|
|
328
458
|
/**
|
|
329
|
-
*
|
|
330
|
-
*
|
|
459
|
+
* The surface the shadow falls on. Must reference a color that is not a
|
|
460
|
+
* shadow or glow.
|
|
331
461
|
*/
|
|
332
462
|
bg: string;
|
|
333
463
|
/**
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
* Omit for
|
|
464
|
+
* The object casting the shadow (e.g. the card). A darker object casts a
|
|
465
|
+
* deeper shadow, a lighter one a softer shadow — see
|
|
466
|
+
* `LightingTuning.objectInfluence`. Omit for an exact shade of `intensity`
|
|
467
|
+
* tones. Must reference a color that is not a shadow or glow.
|
|
337
468
|
*/
|
|
338
469
|
fg?: string;
|
|
339
470
|
/**
|
|
340
|
-
*
|
|
471
|
+
* Tone step, 0–100: how many tones darker than `bg` the composite lands.
|
|
341
472
|
* Supports [normal, highContrast] pair.
|
|
342
473
|
*/
|
|
343
474
|
intensity: HCPair<number>;
|
|
@@ -346,8 +477,46 @@ interface ShadowColorDef {
|
|
|
346
477
|
/**
|
|
347
478
|
* Per-color override for the hue-independent "safe" chroma limit used in
|
|
348
479
|
* OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
|
|
349
|
-
* Falls through to the
|
|
350
|
-
* @see
|
|
480
|
+
* Falls through to the per-theme / per-token `pastel` override when omitted.
|
|
481
|
+
* @see GlazeConfigOverride.pastel
|
|
482
|
+
*/
|
|
483
|
+
pastel?: boolean;
|
|
484
|
+
/**
|
|
485
|
+
* Whether this color is inherited by child themes created via `extend()`.
|
|
486
|
+
* Default: true. Set to false to make this color local to the current theme.
|
|
487
|
+
*/
|
|
488
|
+
inherit?: boolean;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* The mirror of {@link ShadowColorDef}: a translucent light overlay that lands
|
|
492
|
+
* the surface (`bg`) exactly `intensity` tones lighter in every scheme — for
|
|
493
|
+
* dark-mode elevation, edge highlights, and lightening state layers.
|
|
494
|
+
*/
|
|
495
|
+
interface GlowColorDef {
|
|
496
|
+
type: 'glow';
|
|
497
|
+
/**
|
|
498
|
+
* The surface the glow falls on. Must reference a color that is not a
|
|
499
|
+
* shadow or glow.
|
|
500
|
+
*/
|
|
501
|
+
bg: string;
|
|
502
|
+
/**
|
|
503
|
+
* The object emitting the glow. A lighter object glows stronger, a darker
|
|
504
|
+
* one weaker — see `LightingTuning.objectInfluence`. Omit for an exact tint
|
|
505
|
+
* of `intensity` tones. Must reference a color that is not a shadow or glow.
|
|
506
|
+
*/
|
|
507
|
+
fg?: string;
|
|
508
|
+
/**
|
|
509
|
+
* Tone step, 0–100: how many tones lighter than `bg` the composite lands.
|
|
510
|
+
* Supports [normal, highContrast] pair.
|
|
511
|
+
*/
|
|
512
|
+
intensity: HCPair<number>;
|
|
513
|
+
/** Override default tuning. Merged field-by-field with global `glowTuning`. */
|
|
514
|
+
tuning?: GlowTuning;
|
|
515
|
+
/**
|
|
516
|
+
* Per-color override for the hue-independent "safe" chroma limit used in
|
|
517
|
+
* OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
|
|
518
|
+
* Falls through to the per-theme / per-token `pastel` override when omitted.
|
|
519
|
+
* @see GlazeConfigOverride.pastel
|
|
351
520
|
*/
|
|
352
521
|
pastel?: boolean;
|
|
353
522
|
/**
|
|
@@ -377,9 +546,12 @@ interface MixColorDef {
|
|
|
377
546
|
/**
|
|
378
547
|
* Interpolation color space for opaque blending. Default: 'okhsl'.
|
|
379
548
|
* - 'okhsl': perceptually uniform, consistent with Glaze's internal model.
|
|
380
|
-
* - 'srgb': linear sRGB interpolation
|
|
549
|
+
* - 'srgb': linear-light sRGB interpolation (like CSS
|
|
550
|
+
* `color-mix(in srgb-linear, …)`).
|
|
381
551
|
*
|
|
382
|
-
* Ignored for 'transparent' blend
|
|
552
|
+
* Ignored for 'transparent' blend: the browser composites that one, and
|
|
553
|
+
* its contrast solve models the browser (`source-over` on gamma-encoded
|
|
554
|
+
* sRGB).
|
|
383
555
|
*/
|
|
384
556
|
space?: 'okhsl' | 'srgb';
|
|
385
557
|
/**
|
|
@@ -393,8 +565,8 @@ interface MixColorDef {
|
|
|
393
565
|
/**
|
|
394
566
|
* Per-color override for the hue-independent "safe" chroma limit used in
|
|
395
567
|
* OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
|
|
396
|
-
* Falls through to the
|
|
397
|
-
* @see
|
|
568
|
+
* Falls through to the per-theme / per-token `pastel` override when omitted.
|
|
569
|
+
* @see GlazeConfigOverride.pastel
|
|
398
570
|
*/
|
|
399
571
|
pastel?: boolean;
|
|
400
572
|
/**
|
|
@@ -409,7 +581,7 @@ interface MixColorDef {
|
|
|
409
581
|
*/
|
|
410
582
|
inherit?: boolean;
|
|
411
583
|
}
|
|
412
|
-
type ColorDef = RegularColorDef | ShadowColorDef | MixColorDef;
|
|
584
|
+
type ColorDef = RegularColorDef | ShadowColorDef | GlowColorDef | MixColorDef;
|
|
413
585
|
type ColorMap = Record<string, ColorDef>;
|
|
414
586
|
/**
|
|
415
587
|
* Resolved color for a single scheme variant.
|
|
@@ -441,7 +613,7 @@ interface ResolvedColor {
|
|
|
441
613
|
dark: ResolvedColorVariant;
|
|
442
614
|
lightContrast: ResolvedColorVariant;
|
|
443
615
|
darkContrast: ResolvedColorVariant;
|
|
444
|
-
/** Adaptation mode
|
|
616
|
+
/** Adaptation mode of a regular color; `undefined` for shadow / glow / mix. */
|
|
445
617
|
mode?: AdaptationMode;
|
|
446
618
|
}
|
|
447
619
|
/**
|
|
@@ -474,10 +646,40 @@ interface GlazeConfig {
|
|
|
474
646
|
dark?: string;
|
|
475
647
|
highContrast?: string;
|
|
476
648
|
};
|
|
477
|
-
/**
|
|
649
|
+
/**
|
|
650
|
+
* Which scheme variants to include in exports. Defaults: `dark: true`,
|
|
651
|
+
* `highContrast: false`.
|
|
652
|
+
*/
|
|
478
653
|
modes?: GlazeOutputModes;
|
|
479
654
|
/** Default tuning for all shadow colors. Per-color tuning merges field-by-field. */
|
|
480
655
|
shadowTuning?: ShadowTuning;
|
|
656
|
+
/** Default tuning for all glow colors. Per-color tuning merges field-by-field. */
|
|
657
|
+
glowTuning?: GlowTuning;
|
|
658
|
+
/**
|
|
659
|
+
* Manual contrast level — a 0–100 slider from normal contrast (`0`) to high
|
|
660
|
+
* contrast (`100`), or `'auto'` (the default) to take the authored normal
|
|
661
|
+
* entries as-is.
|
|
662
|
+
*
|
|
663
|
+
* With a number, Glaze resolves the `light` / `dark` variants *at* that level.
|
|
664
|
+
* That is all it does: `lightContrast` / `darkContrast` stay the true
|
|
665
|
+
* high-contrast resolution at every level, and `modes.highContrast` alone
|
|
666
|
+
* decides whether they are emitted. Level `0` therefore reproduces `'auto'`
|
|
667
|
+
* bit for bit. At `100` the normal variants *are* the high-contrast ones, so a
|
|
668
|
+
* separate tier would duplicate them and a global level of 100 drops it.
|
|
669
|
+
*
|
|
670
|
+
* The level interpolates all three things that make high contrast differ:
|
|
671
|
+
* authored `[normal, highContrast]` pairs, the tone-window widening, and
|
|
672
|
+
* the `AA → AAA` / APCA `+15 Lc` escalation. Contrast floors are re-solved
|
|
673
|
+
* at the interpolated target, so every level is a solution rather than an
|
|
674
|
+
* approximation, and a color keeps to one side of its base as the level moves.
|
|
675
|
+
*
|
|
676
|
+
* Pass `'auto'` to leave manual mode; `configure()` never clears a field by
|
|
677
|
+
* omission. See `docs/reference/contrast.md` for the ramp's edge cases (un-interpolable
|
|
678
|
+
* pairs, side changes) and the export-freeze rule.
|
|
679
|
+
*
|
|
680
|
+
* @default 'auto'
|
|
681
|
+
*/
|
|
682
|
+
contrastLevel?: number | 'auto';
|
|
481
683
|
/**
|
|
482
684
|
* Automatically flip tone direction when contrast can't be met.
|
|
483
685
|
*
|
|
@@ -493,13 +695,6 @@ interface GlazeConfig {
|
|
|
493
695
|
* falls back to the originally requested tone).
|
|
494
696
|
*/
|
|
495
697
|
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
698
|
/**
|
|
504
699
|
* If true (default), infer a color's `role` from its name when no explicit
|
|
505
700
|
* `role` is set. Set to `false` to opt out of name-based inference (the
|
|
@@ -518,14 +713,27 @@ interface GlazeConfigResolved {
|
|
|
518
713
|
};
|
|
519
714
|
modes: Required<GlazeOutputModes>;
|
|
520
715
|
shadowTuning?: ShadowTuning;
|
|
716
|
+
glowTuning?: GlowTuning;
|
|
521
717
|
autoFlip: boolean;
|
|
718
|
+
/**
|
|
719
|
+
* Manual contrast level (0–100) for the normal variants, or `'auto'` to take
|
|
720
|
+
* the authored normal entries as-is.
|
|
721
|
+
* @see GlazeConfig.contrastLevel
|
|
722
|
+
*/
|
|
723
|
+
contrastLevel: number | 'auto';
|
|
724
|
+
/**
|
|
725
|
+
* Instance-level pastel default (`def.pastel ?? config.pastel`).
|
|
726
|
+
* Not set via `glaze.configure()` — only via per-theme / per-token
|
|
727
|
+
* `GlazeConfigOverride` (default `false`).
|
|
728
|
+
*/
|
|
522
729
|
pastel: boolean;
|
|
523
730
|
inferRole: boolean;
|
|
524
731
|
}
|
|
525
732
|
/**
|
|
526
733
|
* Per-instance config override for `glaze.color()` and `glaze()` themes.
|
|
527
734
|
* 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
|
|
735
|
+
* that are omitted fall through to the live global at resolve time
|
|
736
|
+
* (`pastel` is instance-only and defaults to `false` when omitted).
|
|
529
737
|
*
|
|
530
738
|
* `false` for a tone window disables clamping (full range at reference eps).
|
|
531
739
|
*/
|
|
@@ -539,9 +747,22 @@ interface GlazeConfigOverride {
|
|
|
539
747
|
/** Whether to auto-flip tone when contrast can't be met. */
|
|
540
748
|
autoFlip?: boolean;
|
|
541
749
|
/**
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
750
|
+
* Manual contrast level (0–100) for this instance, or `'auto'` to opt out of a
|
|
751
|
+
* global level and take the authored normal entries as-is. Either way the
|
|
752
|
+
* instance keeps its high-contrast tier; a per-instance level never changes
|
|
753
|
+
* which modes are emitted.
|
|
754
|
+
*
|
|
755
|
+
* Only an instance-authored level is frozen into `.export()` snapshots — a
|
|
756
|
+
* level inherited from the global config is treated as a live preference and
|
|
757
|
+
* re-read at restore time.
|
|
758
|
+
*
|
|
759
|
+
* @see GlazeConfig.contrastLevel
|
|
760
|
+
*/
|
|
761
|
+
contrastLevel?: number | 'auto';
|
|
762
|
+
/**
|
|
763
|
+
* Instance-level pastel default for colors that omit per-color `pastel`.
|
|
764
|
+
* Not available on `glaze.configure()` — set here or per-color.
|
|
765
|
+
* @default false
|
|
545
766
|
*/
|
|
546
767
|
pastel?: boolean;
|
|
547
768
|
/**
|
|
@@ -554,39 +775,81 @@ interface GlazeConfigOverride {
|
|
|
554
775
|
* standalone color tokens.
|
|
555
776
|
*/
|
|
556
777
|
shadowTuning?: ShadowTuning;
|
|
778
|
+
/**
|
|
779
|
+
* Glow tuning defaults. Only meaningful for themes; harmless on
|
|
780
|
+
* standalone color tokens.
|
|
781
|
+
*/
|
|
782
|
+
glowTuning?: GlowTuning;
|
|
557
783
|
}
|
|
784
|
+
/**
|
|
785
|
+
* Current authoring-export schema version. Bump when the export shape
|
|
786
|
+
* changes in a non-compatible way. Written on every `.export()` snapshot.
|
|
787
|
+
*
|
|
788
|
+
* - `1` — Glaze 2.x.
|
|
789
|
+
* - `2` — Glaze 3: `shadow` `intensity` / `fg` / `tuning` changed meaning and
|
|
790
|
+
* `glow` was added. Version-1 theme snapshots that carry shadow defs or a
|
|
791
|
+
* `shadowTuning` are rejected on restore.
|
|
792
|
+
*/
|
|
793
|
+
declare const GLAZE_EXPORT_VERSION: 2;
|
|
794
|
+
/** Literal type of {@link GLAZE_EXPORT_VERSION}. */
|
|
795
|
+
type GlazeExportVersion = typeof GLAZE_EXPORT_VERSION;
|
|
796
|
+
/** Discriminator for authoring export snapshots. */
|
|
797
|
+
type GlazeExportKind = 'theme' | 'color' | 'palette';
|
|
558
798
|
/** Serialized theme configuration (no resolved values). */
|
|
559
799
|
interface GlazeThemeExport {
|
|
800
|
+
/** Snapshot kind. Always written by `theme.export()`; optional on legacy hand-written configs. */
|
|
801
|
+
kind?: 'theme';
|
|
802
|
+
/** Schema version. Always written by `theme.export()`; optional on legacy configs. */
|
|
803
|
+
version?: number;
|
|
560
804
|
hue: number;
|
|
561
805
|
saturation: number;
|
|
806
|
+
/** Dark-scheme seed hue (0–360). Omitted when the theme reuses `hue`. */
|
|
807
|
+
darkHue?: number;
|
|
808
|
+
/** Dark-scheme seed saturation (0–100). Omitted when the theme reuses `saturation`. */
|
|
809
|
+
darkSaturation?: number;
|
|
562
810
|
colors: ColorMap;
|
|
563
|
-
/**
|
|
811
|
+
/**
|
|
812
|
+
* Effective config freeze from `.export()` —
|
|
813
|
+
* `getConfig() ∪ instance local ∪ exportArg`. May be sparse on legacy
|
|
814
|
+
* snapshots (omitted fields fall through to the live global at restore).
|
|
815
|
+
*/
|
|
564
816
|
config?: GlazeConfigOverride;
|
|
565
817
|
}
|
|
566
|
-
/** Input for `glaze.shadow()` standalone
|
|
567
|
-
interface
|
|
818
|
+
/** Input for the `glaze.shadow()` and `glaze.glow()` standalone factories. */
|
|
819
|
+
interface GlazeLightingInput {
|
|
568
820
|
/**
|
|
569
|
-
*
|
|
570
|
-
* (`#rgb` / `#rrggbb` / `#rrggbbaa`), `rgb()` / `hsl()` /
|
|
571
|
-
* / `oklch()` strings, or literal objects
|
|
572
|
-
* `{
|
|
821
|
+
* The surface — accepts any `GlazeColorValue` form: hex
|
|
822
|
+
* (`#rgb` / `#rgba` / `#rrggbb` / `#rrggbbaa`), `rgb()` / `hsl()` /
|
|
823
|
+
* `okhsl()` / `okhst()` / `oklch()` strings, or literal objects
|
|
824
|
+
* (`{ r, g, b }`, `{ h, s, l }`, `{ h, s, t }`, `{ l, c, h }`). Alpha
|
|
825
|
+
* components are dropped with a warning.
|
|
573
826
|
*/
|
|
574
827
|
bg: GlazeColorValue;
|
|
575
|
-
/**
|
|
576
|
-
* Foreground color for tinting + intensity modulation. Accepts the
|
|
577
|
-
* same forms as `bg`.
|
|
578
|
-
*/
|
|
828
|
+
/** The object casting the shadow / emitting the glow. Same forms as `bg`. */
|
|
579
829
|
fg?: GlazeColorValue;
|
|
580
|
-
/**
|
|
830
|
+
/** Tone step, 0–100. */
|
|
581
831
|
intensity: number;
|
|
582
|
-
tuning?:
|
|
832
|
+
tuning?: LightingTuning;
|
|
583
833
|
}
|
|
834
|
+
/** Input for `glaze.shadow()`. */
|
|
835
|
+
type GlazeShadowInput = GlazeLightingInput;
|
|
836
|
+
/** Input for `glaze.glow()`. */
|
|
837
|
+
type GlazeGlowInput = GlazeLightingInput;
|
|
584
838
|
/** Input for the structured `glaze.color()` overload. */
|
|
585
839
|
interface GlazeColorInput {
|
|
586
840
|
hue: number;
|
|
587
841
|
saturation: number;
|
|
588
842
|
tone: HCPair<number | ExtremeValue>;
|
|
589
843
|
saturationFactor?: number;
|
|
844
|
+
/**
|
|
845
|
+
* Dark-scheme hue. Number is absolute (0–360); `'+N'`/`'-N'` is relative
|
|
846
|
+
* to the dark seed hue, which defaults to `hue`. Falls back to `hue`.
|
|
847
|
+
*/
|
|
848
|
+
darkHue?: number | RelativeValue;
|
|
849
|
+
/** Dark-scheme seed saturation (0–100). Defaults to `saturation`. */
|
|
850
|
+
darkSaturation?: number;
|
|
851
|
+
/** Dark-scheme multiplier on the dark seed (0–1). Defaults to `saturationFactor`. */
|
|
852
|
+
darkSaturationFactor?: number;
|
|
590
853
|
mode?: AdaptationMode;
|
|
591
854
|
/** Flip out-of-bounds results instead of clamping. Default: global `autoFlip`. */
|
|
592
855
|
autoFlip?: boolean;
|
|
@@ -603,29 +866,33 @@ interface GlazeColorInput {
|
|
|
603
866
|
*/
|
|
604
867
|
base?: GlazeColorToken | GlazeColorValue;
|
|
605
868
|
/**
|
|
606
|
-
* Contrast floor
|
|
869
|
+
* Contrast floor. Without `base`, solved against the token's own input
|
|
870
|
+
* color (`hue`, `saturation`, normal `tone`), held fixed in every scheme;
|
|
871
|
+
* with `base`, against the base's resolved variant per scheme. A bare
|
|
607
872
|
* number/preset is WCAG; use `{ wcag }` / `{ apca }` to pick the metric.
|
|
608
873
|
*/
|
|
609
874
|
contrast?: HCPair<ContrastSpec>;
|
|
610
875
|
/**
|
|
611
876
|
* Optional human-readable name for the token. Used in error and
|
|
612
877
|
* warning messages (otherwise an internal name like `"value"` is
|
|
613
|
-
* used).
|
|
878
|
+
* used) and as `resolve().name`. A debug label only: it does not
|
|
879
|
+
* affect output keys or the token's `role`.
|
|
614
880
|
*/
|
|
615
881
|
name?: string;
|
|
616
882
|
/**
|
|
617
883
|
* Per-color override for the hue-independent "safe" chroma limit used in
|
|
618
884
|
* OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
|
|
619
|
-
* Falls through to the
|
|
620
|
-
* @see
|
|
885
|
+
* Falls through to the per-theme / per-token `pastel` override when omitted.
|
|
886
|
+
* @see GlazeConfigOverride.pastel
|
|
621
887
|
*/
|
|
622
888
|
pastel?: boolean;
|
|
623
889
|
/**
|
|
624
|
-
* Semantic role against
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
*
|
|
628
|
-
*
|
|
890
|
+
* Semantic role against the token's anchor (`base`, or its own input
|
|
891
|
+
* color when `contrast` is set without one): how this token is used.
|
|
892
|
+
* Fixes APCA contrast polarity; WCAG ignores it. Defaults to `'text'` —
|
|
893
|
+
* the token is the foreground and the anchor the background, with or
|
|
894
|
+
* without `base`. Unlike a theme color, a token never infers its role
|
|
895
|
+
* from `name`, so `inferRole` has no effect on it.
|
|
629
896
|
*/
|
|
630
897
|
role?: RoleInput;
|
|
631
898
|
}
|
|
@@ -633,17 +900,35 @@ interface GlazeColorInput {
|
|
|
633
900
|
* Any single-color input form accepted by the value-shorthand
|
|
634
901
|
* overload of `glaze.color()`.
|
|
635
902
|
*
|
|
636
|
-
* Strings cover hex (`#rgb` / `#
|
|
637
|
-
*
|
|
638
|
-
* `
|
|
639
|
-
*
|
|
903
|
+
* Strings cover hex with a leading `#` (`#rgb` / `#rgba` / `#rrggbb` /
|
|
904
|
+
* `#rrggbbaa`) and the five color functions Glaze itself emits: `rgb()`,
|
|
905
|
+
* `hsl()`, `okhsl()`, `okhst()`, `oklch()`, plus the `rgba()` / `hsla()`
|
|
906
|
+
* aliases. Function names are case-insensitive; components are numbers or
|
|
907
|
+
* percentages, separated by spaces or commas. Their scales:
|
|
908
|
+
* - `rgb()` — channels 0–255, or percentages (`100%` is 255).
|
|
909
|
+
* - `hsl()` / `okhsl()` / `okhst()` — saturation, lightness and tone are
|
|
910
|
+
* percentages or bare 0–1 fractions: `hsl(120 50% 50%)` or
|
|
911
|
+
* `hsl(120 0.5 0.5)`. Unlike CSS, a bare `hsl(120 50 50)` does not mean
|
|
912
|
+
* 50%; it is out of range and resolves to white without a warning.
|
|
913
|
+
* - `oklch()` — L 0–1 or a percentage; C bare, or a percentage where
|
|
914
|
+
* `100%` is 0.4.
|
|
915
|
+
* - Hue is in degrees, bare or with `deg`. Other angle units (`turn`,
|
|
916
|
+
* `rad`, `grad`) are misread as degrees rather than rejected.
|
|
917
|
+
*
|
|
918
|
+
* An alpha component (hex alpha, `/ A`, or any fourth component) is
|
|
919
|
+
* dropped with a warning. Named colors, other color functions, and
|
|
920
|
+
* relative color syntax throw.
|
|
640
921
|
*
|
|
641
|
-
* Literal object forms:
|
|
642
|
-
* - `{ h, s, l }` — OKHSL (h: 0–360, s/l: 0–1). Passing 0–100 for `s`/`l`
|
|
643
|
-
* throws with a hint to use the structured form.
|
|
644
|
-
* - `{ h, s, t }` — OKHST (h: 0–360, s/t: 0–1). Tone in 0–1.
|
|
922
|
+
* Literal object forms, told apart by their keys:
|
|
645
923
|
* - `{ r, g, b }` — sRGB 0–255.
|
|
646
924
|
* - `{ l, c, h }` — OKLCh (L/C: 0–1, H: degrees), same as `oklch()` strings.
|
|
925
|
+
* - `{ h, s, t }` — OKHST (h: 0–360, s/t: 0–1). Tone in 0–1, so `t: 0.7` is
|
|
926
|
+
* tone 70.
|
|
927
|
+
* - `{ h, s, l }` — OKHSL (h: 0–360, s/l: 0–1).
|
|
928
|
+
*
|
|
929
|
+
* An object `s`, `l`, `t` or `c` above 1.5 throws, which catches 0–100
|
|
930
|
+
* input; the OKHSL / OKHST errors point to the structured form. String
|
|
931
|
+
* components have no such check.
|
|
647
932
|
*/
|
|
648
933
|
type GlazeColorValue = string | OkhslColor | OkhstColor | RgbColor | OklchColor;
|
|
649
934
|
/** Color overrides for the `from` and value-shorthand inputs. */
|
|
@@ -656,6 +941,23 @@ interface GlazeColorOverrides {
|
|
|
656
941
|
hue?: number | RelativeValue;
|
|
657
942
|
/** Override seed saturation (0–100). Default: extracted from value. */
|
|
658
943
|
saturation?: number;
|
|
944
|
+
/**
|
|
945
|
+
* Dark-scheme hue. Number is absolute (0–360); `'+N'`/`'-N'` is relative
|
|
946
|
+
* to the dark seed hue, which defaults to the (possibly overridden) seed
|
|
947
|
+
* hue. Falls back to `hue` when omitted.
|
|
948
|
+
*/
|
|
949
|
+
darkHue?: number | RelativeValue;
|
|
950
|
+
/**
|
|
951
|
+
* Dark-scheme seed saturation (0–100). Defaults to `saturation`. When set,
|
|
952
|
+
* the global `darkDesaturation` reduction is not applied on top.
|
|
953
|
+
*/
|
|
954
|
+
darkSaturation?: number;
|
|
955
|
+
/**
|
|
956
|
+
* Dark-scheme multiplier on the dark seed (0–1). Defaults to
|
|
957
|
+
* `saturationFactor`. When set, the global `darkDesaturation` reduction is
|
|
958
|
+
* not applied on top.
|
|
959
|
+
*/
|
|
960
|
+
darkSaturationFactor?: number;
|
|
659
961
|
/**
|
|
660
962
|
* Override tone. Number is absolute (0–100, contrast-uniform); `'+N'`/`'-N'`
|
|
661
963
|
* is relative to the literal seed (the value passed to `glaze.color()`);
|
|
@@ -668,11 +970,11 @@ interface GlazeColorOverrides {
|
|
|
668
970
|
/**
|
|
669
971
|
* Adaptation mode. Defaults to `'auto'` for every input form, so
|
|
670
972
|
* colors automatically adapt between light and dark like an ordinary
|
|
671
|
-
* theme color.
|
|
672
|
-
* preserve light tone
|
|
673
|
-
*
|
|
674
|
-
* `{ hue, saturation, tone }` form also
|
|
675
|
-
*
|
|
973
|
+
* theme color. Value-shorthand inputs (strings and literal objects)
|
|
974
|
+
* preserve light tone via a local `lightTone: false` default; other
|
|
975
|
+
* omitted config fields fall through to the live global at resolve
|
|
976
|
+
* time. Structured `{ hue, saturation, tone }` form also falls
|
|
977
|
+
* through for both tone windows unless overridden.
|
|
676
978
|
*
|
|
677
979
|
* Pass `'fixed'` explicitly to opt back into the linear, non-
|
|
678
980
|
* inverting mapping; pass `'static'` to pin the same tone
|
|
@@ -725,20 +1027,24 @@ interface GlazeColorOverrides {
|
|
|
725
1027
|
/**
|
|
726
1028
|
* Optional human-readable name for the token. Used in error and
|
|
727
1029
|
* warning messages (otherwise an internal name like `"value"` is
|
|
728
|
-
* used).
|
|
1030
|
+
* used) and as `resolve().name`. A debug label only: it does not
|
|
1031
|
+
* affect output keys or the token's `role`.
|
|
729
1032
|
*/
|
|
730
1033
|
name?: string;
|
|
731
1034
|
/**
|
|
732
1035
|
* Per-color override for the hue-independent "safe" chroma limit used in
|
|
733
1036
|
* OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
|
|
734
|
-
* Falls through to the
|
|
735
|
-
* @see
|
|
1037
|
+
* Falls through to the per-theme / per-token `pastel` override when omitted.
|
|
1038
|
+
* @see GlazeConfigOverride.pastel
|
|
736
1039
|
*/
|
|
737
1040
|
pastel?: boolean;
|
|
738
1041
|
/**
|
|
739
|
-
* Semantic role against `base
|
|
740
|
-
*
|
|
741
|
-
*
|
|
1042
|
+
* Semantic role against the token's anchor (`base`, or the literal seed
|
|
1043
|
+
* when `contrast` / a relative `tone` is set without one): how this token
|
|
1044
|
+
* is used. Fixes APCA contrast polarity; WCAG ignores it. Defaults to
|
|
1045
|
+
* `'text'` — the token is the foreground and the anchor the background,
|
|
1046
|
+
* with or without `base`. Unlike a theme color, a token never infers its
|
|
1047
|
+
* role from `name`, so `inferRole` has no effect on it.
|
|
742
1048
|
*/
|
|
743
1049
|
role?: RoleInput;
|
|
744
1050
|
}
|
|
@@ -771,8 +1077,9 @@ interface GlazeColorCssOptions {
|
|
|
771
1077
|
*/
|
|
772
1078
|
suffix?: string;
|
|
773
1079
|
/**
|
|
774
|
-
* Emit hue as a separate custom property, referenced via
|
|
775
|
-
* Requires `format: 'oklch'`
|
|
1080
|
+
* Emit hue as a separate `--{name}-hue` custom property, referenced via
|
|
1081
|
+
* `var()`. Requires `format: 'oklch'` (any other format throws) and a
|
|
1082
|
+
* pastel token.
|
|
776
1083
|
*/
|
|
777
1084
|
splitHue?: boolean;
|
|
778
1085
|
}
|
|
@@ -815,14 +1122,19 @@ interface GlazeColorToken {
|
|
|
815
1122
|
* Serialize the token as a JSON-safe object. Captures the original
|
|
816
1123
|
* input value, overrides, and config so it can be rehydrated via
|
|
817
1124
|
* `glaze.colorFrom(...)`. `base` is recursively serialized.
|
|
1125
|
+
* Optional `override` is merged over the instance local at export time.
|
|
818
1126
|
*/
|
|
819
|
-
export(): GlazeColorTokenExport;
|
|
1127
|
+
export(override?: GlazeConfigOverride): GlazeColorTokenExport;
|
|
820
1128
|
}
|
|
821
1129
|
/**
|
|
822
1130
|
* JSON-safe serialization of a `glaze.color()` token. Pass to
|
|
823
1131
|
* `glaze.colorFrom(...)` to rehydrate.
|
|
824
1132
|
*/
|
|
825
1133
|
interface GlazeColorTokenExport {
|
|
1134
|
+
/** Snapshot kind. Always written by `token.export()`; optional on legacy snapshots. */
|
|
1135
|
+
kind?: 'color';
|
|
1136
|
+
/** Schema version. Always written by `token.export()`; optional on legacy snapshots. */
|
|
1137
|
+
version?: number;
|
|
826
1138
|
/**
|
|
827
1139
|
* Discriminator for the source overload that created the token.
|
|
828
1140
|
* - `'value'`: created via `glaze.color(value)` or `glaze.color({ from, ...overrides })`.
|
|
@@ -837,14 +1149,26 @@ interface GlazeColorTokenExport {
|
|
|
837
1149
|
*/
|
|
838
1150
|
overrides?: GlazeColorOverridesExport;
|
|
839
1151
|
/**
|
|
840
|
-
* Effective config
|
|
841
|
-
*
|
|
842
|
-
*
|
|
843
|
-
* post-merge defaults are present. Used by `glaze.colorFrom()` to
|
|
844
|
-
* reproduce deterministic behavior across `configure()` calls.
|
|
1152
|
+
* Effective config freeze from `.export()` — `getConfig() ∪ local ∪
|
|
1153
|
+
* exportArg` at call time. Used by `glaze.colorFrom()` to pin
|
|
1154
|
+
* deterministic behavior across later `configure()` calls.
|
|
845
1155
|
*/
|
|
846
1156
|
config?: GlazeConfigOverride;
|
|
847
1157
|
}
|
|
1158
|
+
/**
|
|
1159
|
+
* JSON-safe serialization of a `glaze.palette()` composition.
|
|
1160
|
+
* Pass to `glaze.paletteFrom(...)` to rehydrate.
|
|
1161
|
+
*/
|
|
1162
|
+
interface GlazePaletteExport {
|
|
1163
|
+
/** Snapshot kind. Always written by `palette.export()`. */
|
|
1164
|
+
kind?: 'palette';
|
|
1165
|
+
/** Schema version. Always written by `palette.export()`. */
|
|
1166
|
+
version?: number;
|
|
1167
|
+
/** Per-theme authoring snapshots keyed by theme name. */
|
|
1168
|
+
themes: Record<string, GlazeThemeExport>;
|
|
1169
|
+
/** Primary theme name, if set on the palette. */
|
|
1170
|
+
primary?: string;
|
|
1171
|
+
}
|
|
848
1172
|
/**
|
|
849
1173
|
* Serializable shape of a structured `glaze.color({...})` input.
|
|
850
1174
|
* Differs from `GlazeColorInput` only in that `base` is replaced by an
|
|
@@ -855,6 +1179,9 @@ interface GlazeColorInputExport {
|
|
|
855
1179
|
saturation: number;
|
|
856
1180
|
tone: HCPair<number | ExtremeValue>;
|
|
857
1181
|
saturationFactor?: number;
|
|
1182
|
+
darkHue?: number | RelativeValue;
|
|
1183
|
+
darkSaturation?: number;
|
|
1184
|
+
darkSaturationFactor?: number;
|
|
858
1185
|
mode?: AdaptationMode;
|
|
859
1186
|
autoFlip?: boolean;
|
|
860
1187
|
opacity?: number;
|
|
@@ -871,6 +1198,9 @@ interface GlazeColorInputExport {
|
|
|
871
1198
|
interface GlazeColorOverridesExport {
|
|
872
1199
|
hue?: number | RelativeValue;
|
|
873
1200
|
saturation?: number;
|
|
1201
|
+
darkHue?: number | RelativeValue;
|
|
1202
|
+
darkSaturation?: number;
|
|
1203
|
+
darkSaturationFactor?: number;
|
|
874
1204
|
tone?: HCPair<ToneValue>;
|
|
875
1205
|
saturationFactor?: number;
|
|
876
1206
|
mode?: AdaptationMode;
|
|
@@ -882,11 +1212,33 @@ interface GlazeColorOverridesExport {
|
|
|
882
1212
|
pastel?: boolean;
|
|
883
1213
|
role?: RoleInput;
|
|
884
1214
|
}
|
|
1215
|
+
/**
|
|
1216
|
+
* The hue/saturation seed pair a theme resolves against.
|
|
1217
|
+
*
|
|
1218
|
+
* `darkHue` / `darkSaturation` are a separate seed for the `dark` and
|
|
1219
|
+
* `darkContrast` variants; each falls back to its light counterpart. Setting
|
|
1220
|
+
* `darkSaturation` opts the theme out of the global `darkDesaturation`
|
|
1221
|
+
* reduction — the authored value is used literally.
|
|
1222
|
+
*/
|
|
1223
|
+
interface GlazeThemeSeed {
|
|
1224
|
+
/** Light-scheme hue seed (0–360). */
|
|
1225
|
+
hue: number;
|
|
1226
|
+
/** Light-scheme saturation seed (0–100). */
|
|
1227
|
+
saturation: number;
|
|
1228
|
+
/** Dark-scheme hue seed (0–360). Defaults to `hue`. */
|
|
1229
|
+
darkHue?: number;
|
|
1230
|
+
/** Dark-scheme saturation seed (0–100). Defaults to `saturation`. */
|
|
1231
|
+
darkSaturation?: number;
|
|
1232
|
+
}
|
|
885
1233
|
interface GlazeTheme {
|
|
886
1234
|
/** The hue seed (0–360). */
|
|
887
1235
|
readonly hue: number;
|
|
888
1236
|
/** The saturation seed (0–100). */
|
|
889
1237
|
readonly saturation: number;
|
|
1238
|
+
/** The dark-scheme hue seed (0–360), or `undefined` when `hue` is reused. */
|
|
1239
|
+
readonly darkHue: number | undefined;
|
|
1240
|
+
/** The dark-scheme saturation seed (0–100), or `undefined` when `saturation` is reused. */
|
|
1241
|
+
readonly darkSaturation: number | undefined;
|
|
890
1242
|
/** The effective config for this theme. */
|
|
891
1243
|
getConfig(): GlazeConfigResolved;
|
|
892
1244
|
/** Add/replace colors (additive merge with existing definitions). */
|
|
@@ -904,7 +1256,7 @@ interface GlazeTheme {
|
|
|
904
1256
|
/** Clear all color definitions. */
|
|
905
1257
|
reset(): void;
|
|
906
1258
|
/** Export the theme configuration as a JSON-safe object. */
|
|
907
|
-
export(): GlazeThemeExport;
|
|
1259
|
+
export(override?: GlazeConfigOverride): GlazeThemeExport;
|
|
908
1260
|
/** Create a child theme inheriting all color definitions. */
|
|
909
1261
|
extend(options: GlazeExtendOptions): GlazeTheme;
|
|
910
1262
|
/** Resolve all colors and return the result map. */
|
|
@@ -924,7 +1276,7 @@ interface GlazeTheme {
|
|
|
924
1276
|
* Spread into component styles or register as a recipe via `configure({ recipes })`.
|
|
925
1277
|
* @see https://tasty.style/docs
|
|
926
1278
|
*/
|
|
927
|
-
tasty(options?:
|
|
1279
|
+
tasty(options?: GlazeTastyOptions): Record<string, Record<string, string>>;
|
|
928
1280
|
/** Export as plain JSON. */
|
|
929
1281
|
json(options?: GlazeJsonOptions): Record<string, Record<string, string>>;
|
|
930
1282
|
/** Export as CSS custom property declarations. */
|
|
@@ -954,13 +1306,19 @@ interface GlazeTheme {
|
|
|
954
1306
|
interface GlazeExtendOptions {
|
|
955
1307
|
hue?: number;
|
|
956
1308
|
saturation?: number;
|
|
1309
|
+
/** Replace the dark-scheme hue seed (0–360). Defaults to the parent's. */
|
|
1310
|
+
darkHue?: number;
|
|
1311
|
+
/** Replace the dark-scheme saturation seed (0–100). Defaults to the parent's. */
|
|
1312
|
+
darkSaturation?: number;
|
|
957
1313
|
colors?: ColorMap;
|
|
958
1314
|
/** Config override for the child theme. Merged with the parent's override. */
|
|
959
1315
|
config?: GlazeConfigOverride;
|
|
960
1316
|
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Options for `token.token()` / `token.tasty()`, and the base of the theme and
|
|
1319
|
+
* palette `tasty()` options: output format, scheme variants, state aliases.
|
|
1320
|
+
*/
|
|
961
1321
|
interface GlazeTokenOptions {
|
|
962
|
-
/** Prefix mode. `true` uses "<themeName>-", or provide a custom map. */
|
|
963
|
-
prefix?: boolean | Record<string, string>;
|
|
964
1322
|
/** Override state aliases for this export. */
|
|
965
1323
|
states?: {
|
|
966
1324
|
dark?: string;
|
|
@@ -970,23 +1328,29 @@ interface GlazeTokenOptions {
|
|
|
970
1328
|
modes?: GlazeOutputModes;
|
|
971
1329
|
/** Output color format. Default: 'oklch'. */
|
|
972
1330
|
format?: GlazeColorFormat;
|
|
1331
|
+
}
|
|
1332
|
+
/** Options for `theme.tasty()`. */
|
|
1333
|
+
interface GlazeTastyOptions extends GlazeTokenOptions {
|
|
973
1334
|
/**
|
|
974
1335
|
* Emit hue as a separate custom property, referenced via `var()`.
|
|
975
|
-
* Requires `format: 'oklch'` and every color to
|
|
1336
|
+
* Requires `format: 'oklch'` (any other format throws) and every color to
|
|
1337
|
+
* be pastel.
|
|
976
1338
|
*/
|
|
977
1339
|
splitHue?: boolean;
|
|
978
1340
|
/**
|
|
979
1341
|
* Base name for the theme-level hue var (`--{name}-hue`). Default: `'theme'`.
|
|
980
|
-
*
|
|
1342
|
+
* Must not equal the name of a color that sets its own hue (throws).
|
|
981
1343
|
*/
|
|
982
1344
|
name?: string;
|
|
983
1345
|
}
|
|
1346
|
+
/** Options for `theme.tokens()` / `theme.json()` and their palette and token counterparts. */
|
|
984
1347
|
interface GlazeJsonOptions {
|
|
985
1348
|
/** Override which scheme variants to include. */
|
|
986
1349
|
modes?: GlazeOutputModes;
|
|
987
1350
|
/** Output color format. Default: 'oklch'. */
|
|
988
1351
|
format?: GlazeColorFormat;
|
|
989
1352
|
}
|
|
1353
|
+
/** Options for `theme.css()`. */
|
|
990
1354
|
interface GlazeCssOptions {
|
|
991
1355
|
/** Output color format. Default: 'oklch'. */
|
|
992
1356
|
format?: GlazeColorFormat;
|
|
@@ -994,12 +1358,13 @@ interface GlazeCssOptions {
|
|
|
994
1358
|
suffix?: string;
|
|
995
1359
|
/**
|
|
996
1360
|
* Emit hue as a separate custom property, referenced via `var()`.
|
|
997
|
-
* Requires `format: 'oklch'` and every color to
|
|
1361
|
+
* Requires `format: 'oklch'` (any other format throws) and every color to
|
|
1362
|
+
* be pastel.
|
|
998
1363
|
*/
|
|
999
1364
|
splitHue?: boolean;
|
|
1000
1365
|
/**
|
|
1001
1366
|
* Base name for the theme-level hue var (`--{name}-hue`). Default: `'theme'`.
|
|
1002
|
-
*
|
|
1367
|
+
* Must not equal the name of a color that sets its own hue (throws).
|
|
1003
1368
|
*/
|
|
1004
1369
|
name?: string;
|
|
1005
1370
|
}
|
|
@@ -1202,7 +1567,10 @@ interface GlazePaletteOptions {
|
|
|
1202
1567
|
*/
|
|
1203
1568
|
primary?: string;
|
|
1204
1569
|
}
|
|
1205
|
-
/**
|
|
1570
|
+
/**
|
|
1571
|
+
* Options shared by every palette export except `json()`: `tokens()`,
|
|
1572
|
+
* `tasty()`, `css()`, `dtcg()`, `dtcgResolver()`, and `tailwind()`.
|
|
1573
|
+
*/
|
|
1206
1574
|
interface GlazePaletteExportOptions {
|
|
1207
1575
|
/**
|
|
1208
1576
|
* Prefix mode. `true` uses `"<themeName>-"`, or provide a custom map.
|
|
@@ -1217,13 +1585,54 @@ interface GlazePaletteExportOptions {
|
|
|
1217
1585
|
* When omitted, inherits the palette-level `primary`.
|
|
1218
1586
|
*/
|
|
1219
1587
|
primary?: string | false;
|
|
1588
|
+
}
|
|
1589
|
+
/**
|
|
1590
|
+
* Options for `palette.tasty()`. There is no `name`: each theme's hue var is
|
|
1591
|
+
* named after the theme.
|
|
1592
|
+
*/
|
|
1593
|
+
interface GlazePaletteTastyOptions extends GlazeTokenOptions, GlazePaletteExportOptions {
|
|
1220
1594
|
/**
|
|
1221
1595
|
* Emit hue as a separate custom property, referenced via `var()`.
|
|
1222
|
-
* Requires `format: 'oklch'` and every color to
|
|
1596
|
+
* Requires `format: 'oklch'` (any other format throws) and every color to
|
|
1597
|
+
* be pastel. The theme-level hue var is `--{themeName}-hue`.
|
|
1598
|
+
*/
|
|
1599
|
+
splitHue?: boolean;
|
|
1600
|
+
}
|
|
1601
|
+
/**
|
|
1602
|
+
* Options for `palette.css()`. There is no `name`: each theme's hue var is
|
|
1603
|
+
* named after the theme.
|
|
1604
|
+
*/
|
|
1605
|
+
interface GlazePaletteCssOptions extends GlazePaletteExportOptions {
|
|
1606
|
+
/** Output color format. Default: 'oklch'. */
|
|
1607
|
+
format?: GlazeColorFormat;
|
|
1608
|
+
/** Suffix appended to each CSS custom property name. Default: '-color'. */
|
|
1609
|
+
suffix?: string;
|
|
1610
|
+
/**
|
|
1611
|
+
* Emit hue as a separate custom property, referenced via `var()`.
|
|
1612
|
+
* Requires `format: 'oklch'` (any other format throws) and every color to
|
|
1613
|
+
* be pastel. The theme-level hue var is `--{themeName}-hue`.
|
|
1223
1614
|
*/
|
|
1224
1615
|
splitHue?: boolean;
|
|
1225
1616
|
}
|
|
1226
1617
|
interface GlazePalette {
|
|
1618
|
+
/** Theme names in insertion order. */
|
|
1619
|
+
list(): string[];
|
|
1620
|
+
/** Primary theme name, if set at palette creation. */
|
|
1621
|
+
readonly primary: string | undefined;
|
|
1622
|
+
/** Get a theme by name. Returns the live instance held by the palette. */
|
|
1623
|
+
theme(name: string): GlazeTheme | undefined;
|
|
1624
|
+
/**
|
|
1625
|
+
* Shallow copy of the theme map (same instances the palette holds).
|
|
1626
|
+
* Mutating a returned theme affects subsequent palette exports.
|
|
1627
|
+
*/
|
|
1628
|
+
themes(): Record<string, GlazeTheme>;
|
|
1629
|
+
/**
|
|
1630
|
+
* Export the palette authoring configuration as a JSON-safe object.
|
|
1631
|
+
* Restorable via `glaze.paletteFrom(...)`. Distinct from `json()`, which
|
|
1632
|
+
* emits resolved color strings. Optional `override` is forwarded to each
|
|
1633
|
+
* nested `theme.export(override)`.
|
|
1634
|
+
*/
|
|
1635
|
+
export(override?: GlazeConfigOverride): GlazePaletteExport;
|
|
1227
1636
|
/**
|
|
1228
1637
|
* Export all themes as a flat token map grouped by scheme variant.
|
|
1229
1638
|
* Prefix defaults to `true` — all tokens are prefixed with the theme name.
|
|
@@ -1242,13 +1651,14 @@ interface GlazePalette {
|
|
|
1242
1651
|
* Prefix defaults to `true`. Inherits the palette-level `primary`.
|
|
1243
1652
|
* @see https://tasty.style/docs
|
|
1244
1653
|
*/
|
|
1245
|
-
tasty(options?:
|
|
1246
|
-
/**
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1654
|
+
tasty(options?: GlazePaletteTastyOptions): Record<string, Record<string, string>>;
|
|
1655
|
+
/**
|
|
1656
|
+
* Export all themes as plain JSON grouped by theme name. No prefix, primary
|
|
1657
|
+
* alias, or collision handling: each theme keeps its own key.
|
|
1658
|
+
*/
|
|
1659
|
+
json(options?: GlazeJsonOptions): Record<string, Record<string, Record<string, string>>>;
|
|
1250
1660
|
/** Export all themes as CSS custom property declarations. */
|
|
1251
|
-
css(options?:
|
|
1661
|
+
css(options?: GlazePaletteCssOptions): GlazeCssResult;
|
|
1252
1662
|
/**
|
|
1253
1663
|
* Export all themes as W3C DTCG documents, one per scheme variant.
|
|
1254
1664
|
* Prefix defaults to `true`. Inherits the palette-level `primary`.
|
|
@@ -1270,6 +1680,14 @@ interface GlazePalette {
|
|
|
1270
1680
|
tailwind(options?: GlazeTailwindOptions & GlazePaletteExportOptions): string;
|
|
1271
1681
|
}
|
|
1272
1682
|
//#endregion
|
|
1683
|
+
//#region src/serialize.d.ts
|
|
1684
|
+
/** Type guard for theme authoring snapshots (prefers `kind`, falls back to shape). */
|
|
1685
|
+
declare function isThemeExport(data: unknown): data is GlazeThemeExport;
|
|
1686
|
+
/** Type guard for color-token authoring snapshots. */
|
|
1687
|
+
declare function isColorTokenExport(data: unknown): data is GlazeColorTokenExport;
|
|
1688
|
+
/** Type guard for palette authoring snapshots. */
|
|
1689
|
+
declare function isPaletteExport(data: unknown): data is GlazePaletteExport;
|
|
1690
|
+
//#endregion
|
|
1273
1691
|
//#region src/glaze.d.ts
|
|
1274
1692
|
type PaletteInput = Record<string, GlazeTheme>;
|
|
1275
1693
|
/**
|
|
@@ -1281,29 +1699,43 @@ type PaletteInput = Record<string, GlazeTheme>;
|
|
|
1281
1699
|
* the theme still reacts to later `configure()` calls for fields it
|
|
1282
1700
|
* didn't override.
|
|
1283
1701
|
*
|
|
1702
|
+
* The object form also accepts `darkHue` / `darkSaturation` — a separate
|
|
1703
|
+
* seed pair for the dark and dark-high-contrast schemes. Both default to
|
|
1704
|
+
* their light counterparts, and an explicit `darkSaturation` opts the theme
|
|
1705
|
+
* out of the global `darkDesaturation` reduction.
|
|
1706
|
+
*
|
|
1284
1707
|
* @example
|
|
1285
1708
|
* ```ts
|
|
1286
1709
|
* const primary = glaze(280, 80);
|
|
1287
1710
|
* // or shorthand:
|
|
1288
1711
|
* const primary = glaze({ hue: 280, saturation: 80 });
|
|
1712
|
+
* // with a retuned dark seed:
|
|
1713
|
+
* const primary = glaze({ hue: 280, saturation: 80, darkHue: 268, darkSaturation: 65 });
|
|
1289
1714
|
* // with config override:
|
|
1290
1715
|
* const raw = glaze(280, 80, { lightTone: false });
|
|
1716
|
+
* const rawSeed = glaze({ hue: 280, saturation: 80 }, { lightTone: false });
|
|
1291
1717
|
* ```
|
|
1292
1718
|
*/
|
|
1293
|
-
declare function glaze(
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1719
|
+
declare function glaze(hue: number, saturation?: number, config?: GlazeConfigOverride): GlazeTheme;
|
|
1720
|
+
declare function glaze(seed: GlazeThemeSeed, config?: GlazeConfigOverride): GlazeTheme;
|
|
1721
|
+
/** @deprecated Pass the config second: `glaze(seed, config)`. */
|
|
1722
|
+
declare function glaze(seed: GlazeThemeSeed, saturation: undefined, config?: GlazeConfigOverride): GlazeTheme;
|
|
1297
1723
|
declare namespace glaze {
|
|
1298
1724
|
var configure: (config: GlazeConfig) => void;
|
|
1299
1725
|
var palette: (themes: PaletteInput, options?: GlazePaletteOptions) => GlazePalette;
|
|
1726
|
+
var themeFrom: (data: GlazeThemeExport) => GlazeTheme;
|
|
1300
1727
|
var from: (data: GlazeThemeExport) => GlazeTheme;
|
|
1301
1728
|
var color: (input: GlazeFromInput | GlazeColorInput | GlazeColorValue, config?: GlazeConfigOverride) => GlazeColorToken;
|
|
1302
1729
|
var shadow: (input: GlazeShadowInput) => ResolvedColorVariant;
|
|
1730
|
+
var glow: (input: GlazeGlowInput) => ResolvedColorVariant;
|
|
1303
1731
|
var format: (variant: ResolvedColorVariant, colorFormat?: GlazeColorFormat, pastel?: boolean) => string;
|
|
1304
1732
|
var fromHex: (hex: string) => GlazeTheme;
|
|
1305
1733
|
var fromRgb: (r: number, g: number, b: number) => GlazeTheme;
|
|
1306
1734
|
var colorFrom: (data: GlazeColorTokenExport) => GlazeColorToken;
|
|
1735
|
+
var paletteFrom: (data: GlazePaletteExport) => GlazePalette;
|
|
1736
|
+
var isThemeExport: typeof isThemeExport;
|
|
1737
|
+
var isColorTokenExport: typeof isColorTokenExport;
|
|
1738
|
+
var isPaletteExport: typeof isPaletteExport;
|
|
1307
1739
|
var getConfig: () => GlazeConfigResolved;
|
|
1308
1740
|
var resetConfig: () => void;
|
|
1309
1741
|
}
|
|
@@ -1316,13 +1748,18 @@ interface HueDeclaration {
|
|
|
1316
1748
|
interface HuePlan {
|
|
1317
1749
|
/** CSS `var()` reference spliced into `oklch(L C <hueVar>)`. */
|
|
1318
1750
|
hueVar: string;
|
|
1319
|
-
/** When true, emit a full inline color (shadow/mix/achromatic). */
|
|
1751
|
+
/** When true, emit a full inline color (shadow/glow/mix/achromatic). */
|
|
1320
1752
|
inline: boolean;
|
|
1321
1753
|
/** Scheme-independent `--*-hue` declarations for this color. */
|
|
1322
1754
|
declarations: HueDeclaration[];
|
|
1323
1755
|
}
|
|
1324
1756
|
interface ChannelCtx {
|
|
1325
1757
|
seedHue: number;
|
|
1758
|
+
/**
|
|
1759
|
+
* Dark-scheme seed hue, when the theme authored one. Drives the dark
|
|
1760
|
+
* `--{baseName}-hue` value; falls back to `seedHue`.
|
|
1761
|
+
*/
|
|
1762
|
+
darkSeedHue?: number;
|
|
1326
1763
|
/** Theme-level hue var base name (without `--` / `-hue`). */
|
|
1327
1764
|
baseName: string;
|
|
1328
1765
|
/** Token / custom-property name prefix used for hue var naming (`brand-` etc.). */
|
|
@@ -1426,7 +1863,11 @@ declare function okhslToOkhst(c: {
|
|
|
1426
1863
|
};
|
|
1427
1864
|
/**
|
|
1428
1865
|
* Edge adapter: a resolved variant stores canonical tone `t` (0–1). Convert
|
|
1429
|
-
* it to the OKHSL `{ h, s, l }` the formatters and luminance pipeline expect
|
|
1866
|
+
* it to the OKHSL `{ h, s, l }` the formatters and luminance pipeline expect —
|
|
1867
|
+
* `s` and `l` on the same 0–1 factor scale, so `const { h, s, l } =
|
|
1868
|
+
* variantToOkhsl(v)` destructures straight into `formatOkhsl` / `formatRgb` /
|
|
1869
|
+
* `okhslToLinearSrgb` with no rescaling. `alpha` stays on the variant; use
|
|
1870
|
+
* `glaze.format(v, format)` for a string that carries it.
|
|
1430
1871
|
*/
|
|
1431
1872
|
declare function variantToOkhsl(v: {
|
|
1432
1873
|
h: number;
|
|
@@ -1444,7 +1885,9 @@ declare function variantToOkhsl(v: {
|
|
|
1444
1885
|
*
|
|
1445
1886
|
* Provides bidirectional OKHSL ↔ sRGB conversion, luminance computation
|
|
1446
1887
|
* for both contrast metrics (WCAG 2 relative luminance and APCA screen
|
|
1447
|
-
* luminance `Ys`
|
|
1888
|
+
* luminance `Ys` — both the exact functions the contrast solver uses, and
|
|
1889
|
+
* both public), strict hex parsing (`parseHex` / `parseHexAlpha` check every
|
|
1890
|
+
* digit), and multi-format output (okhsl, rgb, hsl, oklch).
|
|
1448
1891
|
*/
|
|
1449
1892
|
type Vec3 = [number, number, number];
|
|
1450
1893
|
/**
|
|
@@ -1481,6 +1924,7 @@ declare function relativeLuminanceFromLinearRgb(rgb: [number, number, number]):
|
|
|
1481
1924
|
declare function contrastRatioFromLuminance(yA: number, yB: number): number;
|
|
1482
1925
|
/**
|
|
1483
1926
|
* Convert OKHSL to gamma-encoded sRGB (clamped to 0–1).
|
|
1927
|
+
* h: 0–360, s: 0–1, l: 0–1. Returns [r, g, b] with each channel 0–1.
|
|
1484
1928
|
*/
|
|
1485
1929
|
declare function okhslToSrgb(h: number, s: number, l: number, pastel?: boolean): [number, number, number];
|
|
1486
1930
|
/**
|
|
@@ -1489,6 +1933,22 @@ declare function okhslToSrgb(h: number, s: number, l: number, pastel?: boolean):
|
|
|
1489
1933
|
* This avoids over/under-estimating luminance for out-of-gamut OKHSL colors.
|
|
1490
1934
|
*/
|
|
1491
1935
|
declare function gamutClampedLuminance(linearRgb: [number, number, number]): number;
|
|
1936
|
+
/**
|
|
1937
|
+
* Compute APCA screen luminance (`Ys`) from linear sRGB.
|
|
1938
|
+
*
|
|
1939
|
+
* APCA does not use the WCAG piecewise sRGB EOTF; it defines its own
|
|
1940
|
+
* luminance as `0.2126·R^2.4 + 0.7152·G^2.4 + 0.0722·B^2.4` over the
|
|
1941
|
+
* gamma-encoded (display) channels with a simple 2.4 exponent. The APCA
|
|
1942
|
+
* soft-clamp threshold in `apcaContrast` is calibrated against this basis,
|
|
1943
|
+
* so the solver must feed it `Ys`, not WCAG relative luminance. Channels
|
|
1944
|
+
* are gamut-clamped to [0, 1] first, matching `gamutClampedLuminance`.
|
|
1945
|
+
*
|
|
1946
|
+
* This is exactly the luminance Glaze's contrast solver (and its drift
|
|
1947
|
+
* check) feeds `apcaContrast`, so
|
|
1948
|
+
* `apcaContrast(apcaLuminanceFromLinearRgb(text), apcaLuminanceFromLinearRgb(bg))`
|
|
1949
|
+
* reproduces the solver's Lc for a resolved pair.
|
|
1950
|
+
*/
|
|
1951
|
+
declare function apcaLuminanceFromLinearRgb(linearRgb: [number, number, number]): number;
|
|
1492
1952
|
/**
|
|
1493
1953
|
* Convert OKLab to OKHSL.
|
|
1494
1954
|
* Input: [L, a, b] where L: 0–1, a/b: roughly -0.5 to 0.5.
|
|
@@ -1510,7 +1970,9 @@ declare function srgbToOkhsl(rgb: [number, number, number], pastel?: boolean): [
|
|
|
1510
1970
|
declare function hslToSrgb(h: number, s: number, l: number): [number, number, number];
|
|
1511
1971
|
/**
|
|
1512
1972
|
* Parse a hex color string (#rgb or #rrggbb) to sRGB [r, g, b] in 0–1 range.
|
|
1513
|
-
* Returns null if the string is not a valid hex
|
|
1973
|
+
* The leading `#` is optional. Returns null if the string is not a valid hex
|
|
1974
|
+
* color: a wrong length, any character outside `0-9a-f` (case-insensitive),
|
|
1975
|
+
* or a form with alpha.
|
|
1514
1976
|
*
|
|
1515
1977
|
* For 8-digit hex (`#rrggbbaa`) and 4-digit hex (`#rgba`) with alpha,
|
|
1516
1978
|
* use {@link parseHexAlpha}.
|
|
@@ -1519,7 +1981,12 @@ declare function parseHex(hex: string): [number, number, number] | null;
|
|
|
1519
1981
|
/**
|
|
1520
1982
|
* Parse a hex color string (#rgb, #rrggbb, #rgba, or #rrggbbaa) to
|
|
1521
1983
|
* sRGB [r, g, b] in 0–1 range plus an optional alpha (0–1).
|
|
1522
|
-
* Returns null if the string is not a valid hex
|
|
1984
|
+
* The leading `#` is optional. Returns null if the string is not a valid hex
|
|
1985
|
+
* color: a wrong length or any character outside `0-9a-f`
|
|
1986
|
+
* (case-insensitive).
|
|
1987
|
+
*
|
|
1988
|
+
* Every digit is checked up front: `parseInt` alone stops at the first bad
|
|
1989
|
+
* character, so `'#1z2z3z'` would otherwise read as `#010203`.
|
|
1523
1990
|
*/
|
|
1524
1991
|
declare function parseHexAlpha(hex: string): {
|
|
1525
1992
|
rgb: [number, number, number];
|
|
@@ -1527,12 +1994,12 @@ declare function parseHexAlpha(hex: string): {
|
|
|
1527
1994
|
} | null;
|
|
1528
1995
|
/**
|
|
1529
1996
|
* Format OKHSL values as a CSS `okhsl(H S% L%)` string.
|
|
1530
|
-
* h: 0–360, s: 0–
|
|
1997
|
+
* h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
|
|
1531
1998
|
*/
|
|
1532
1999
|
declare function formatOkhsl(h: number, s: number, l: number, pastel?: boolean): string;
|
|
1533
2000
|
/**
|
|
1534
2001
|
* Format OKHST values as a CSS `okhst(H S% T%)` string.
|
|
1535
|
-
* h: 0–360, s: 0–
|
|
2002
|
+
* h: 0–360, s: 0–1, t: 0–1 (factor scale, matching `ResolvedColorVariant`).
|
|
1536
2003
|
*
|
|
1537
2004
|
* Pastel recompute matches `formatOkhsl`: convert via OKLab so external
|
|
1538
2005
|
* parsers that only understand non-pastel OKHST render identically.
|
|
@@ -1541,17 +2008,17 @@ declare function formatOkhst(h: number, s: number, t: number, pastel?: boolean):
|
|
|
1541
2008
|
/**
|
|
1542
2009
|
* Format OKHSL values as a CSS `rgb(R G B)` string.
|
|
1543
2010
|
* Uses 2 decimal places to avoid 8-bit quantization contrast loss.
|
|
1544
|
-
* h: 0–360, s: 0–
|
|
2011
|
+
* h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
|
|
1545
2012
|
*/
|
|
1546
2013
|
declare function formatRgb(h: number, s: number, l: number, pastel?: boolean): string;
|
|
1547
2014
|
/**
|
|
1548
2015
|
* Format OKHSL values as a CSS `hsl(H S% L%)` string.
|
|
1549
|
-
* h: 0–360, s: 0–
|
|
2016
|
+
* h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
|
|
1550
2017
|
*/
|
|
1551
2018
|
declare function formatHsl(h: number, s: number, l: number, pastel?: boolean): string;
|
|
1552
2019
|
/**
|
|
1553
2020
|
* Format OKHSL values as a CSS `oklch(L C H)` string.
|
|
1554
|
-
* h: 0–360, s: 0–
|
|
2021
|
+
* h: 0–360, s: 0–1, l: 0–1 (factor scale, as returned by every converter).
|
|
1555
2022
|
*/
|
|
1556
2023
|
declare function formatOklch(h: number, s: number, l: number, pastel?: boolean): string;
|
|
1557
2024
|
/**
|
|
@@ -1567,5 +2034,5 @@ declare function srgbToHex(rgb: [number, number, number]): `#${string}`;
|
|
|
1567
2034
|
*/
|
|
1568
2035
|
declare function okhslToOklch(h: number, s: number, l: number, pastel?: boolean): [number, number, number];
|
|
1569
2036
|
//#endregion
|
|
1570
|
-
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, 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 GlazeExtendOptions, type GlazeFromInput, type GlazeJsonOptions, type GlazeOutputModes, type GlazePalette, 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, normalizeRole, okhslToLinearSrgb, okhslToOkhst, okhslToOklab, okhslToOklch, okhslToSrgb, okhstToOkhsl, oklabToOkhsl, oppositeRole, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveApcaTarget, resolveContrastForMode, resolveMinContrast, roleToPolarity, srgbToHex, srgbToOkhsl, toTone, toneFromY, variantToOkhsl, yFromTone };
|
|
2037
|
+
export { APCA_HC_ENHANCEMENT, APCA_MAX_LC, APCA_PRESETS, type AdaptationMode, type ApcaPreset, type ChannelCtx, type ColorDef, type ColorMap, type ContrastPreset, type ContrastSpec, type DtcgColorSpace, type DtcgColorToken, type DtcgColorValue, type DtcgDocument, type DtcgOklchColorValue, type DtcgResolverModifier, type DtcgResolverRef, type DtcgResolverSet, type DtcgSrgbColorValue, type DtcgTokenTree, type ExtremeValue, type FindToneForContrastOptions, type FindToneForContrastResult, type FindValueForMixContrastOptions, type FindValueForMixContrastResult, GLAZE_EXPORT_VERSION, type GlazeColorCssOptions, type GlazeColorDtcgResolverOptions, type GlazeColorDtcgResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorInputExport, type GlazeColorOverrides, type GlazeColorOverridesExport, type GlazeColorTailwindOptions, type GlazeColorToken, type GlazeColorTokenExport, type GlazeColorValue, type GlazeConfig, type GlazeConfigOverride, type GlazeConfigResolved, type GlazeCssOptions, type GlazeCssResult, type GlazeDtcgOptions, type GlazeDtcgResolverContextNames, type GlazeDtcgResolverDocument, type GlazeDtcgResolverOptions, type GlazeDtcgResult, type GlazeExportKind, type GlazeExportVersion, type GlazeExtendOptions, type GlazeFromInput, type GlazeGlowInput, type GlazeJsonOptions, type GlazeLightingInput, type GlazeOutputModes, type GlazePalette, type GlazePaletteCssOptions, type GlazePaletteExport, type GlazePaletteExportOptions, type GlazePaletteOptions, type GlazePaletteTastyOptions, type GlazeShadowInput, type GlazeTailwindOptions, type GlazeTastyOptions, type GlazeTheme, type GlazeThemeExport, type GlazeThemeSeed, type GlazeTokenOptions, type GlowColorDef, type GlowTuning, type HCPair, type HexColor, type HueDeclaration, type HuePlan, type LightingTuning, type MinContrast, type MixColorDef, type OkhslColor, type OkhstColor, type OklchColor, type Polarity, REF_EPS, type RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type ResolvedContrast, type RgbColor, type Role, type RoleInput, type ShadowColorDef, type ShadowTuning, type ToneValue, type ToneWindow, apcaContrast, apcaLuminanceFromLinearRgb, assertAllPastel, assertNativeFormat, contrastRatioFromLuminance, cuspLightness, findToneForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOkhst, formatOklch, formatRgb, fromTone, gamutClampedLuminance, glaze, hslToSrgb, inferRoleFromName, isColorTokenExport, isPaletteExport, isThemeExport, normalizeRole, okhslToLinearSrgb, okhslToOkhst, okhslToOklab, okhslToOklch, okhslToSrgb, okhstToOkhsl, oklabToOkhsl, oppositeRole, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveApcaTarget, resolveContrastForLevel, resolveContrastForMode, resolveMinContrast, roleToPolarity, srgbToHex, srgbToOkhsl, toTone, toneFromY, variantToOkhsl, yFromTone };
|
|
1571
2038
|
//# sourceMappingURL=index.d.mts.map
|