@tenphi/glaze 0.0.0-snapshot.02f3ca5

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.
@@ -0,0 +1,916 @@
1
+ //#region src/contrast-solver.d.ts
2
+ /**
3
+ * OKHSL Contrast Solver
4
+ *
5
+ * Finds the closest OKHSL lightness that satisfies a WCAG 2 contrast target
6
+ * against a base color. Used by glaze when resolving dependent colors
7
+ * with `contrast`.
8
+ */
9
+ type LinearRgb = [number, number, number];
10
+ type ContrastPreset = 'AA' | 'AAA' | 'AA-large' | 'AAA-large';
11
+ type MinContrast$1 = number | ContrastPreset;
12
+ interface FindLightnessForContrastOptions {
13
+ /** Hue of the candidate color (0–360). */
14
+ hue: number;
15
+ /** Saturation of the candidate color (0–1). */
16
+ saturation: number;
17
+ /** Preferred lightness of the candidate (0–1). */
18
+ preferredLightness: number;
19
+ /** Base/reference color as linear sRGB (channels may be outside 0–1 before clamp). */
20
+ baseLinearRgb: [number, number, number];
21
+ /** WCAG contrast ratio target floor. */
22
+ contrast: MinContrast$1;
23
+ /** Search bounds for lightness. Default: [0, 1]. */
24
+ lightnessRange?: [number, number];
25
+ /** Convergence threshold. Default: 1e-4. */
26
+ epsilon?: number;
27
+ /** Maximum binary-search iterations per branch. Default: 14. */
28
+ maxIterations?: number;
29
+ /**
30
+ * Preferred search direction before auto-flip is considered.
31
+ *
32
+ * Theme resolution sets this from the requested lightness relative to
33
+ * the base color so `autoFlip: false` preserves the authored direction.
34
+ * When omitted, the solver falls back to the side whose extreme has
35
+ * higher contrast against the base.
36
+ */
37
+ initialDirection?: 'lighter' | 'darker';
38
+ /**
39
+ * Auto-flip lightness direction when contrast can't be met.
40
+ *
41
+ * When `true`, the solver searches the initial direction first. If that side
42
+ * doesn't reach the target, it tries the opposite direction and
43
+ * uses it when it passes. If neither side passes, it returns the
44
+ * extreme lightness of the initial direction.
45
+ *
46
+ * When `false`, only the initial direction is considered. If it
47
+ * doesn't reach the target, the result is pinned to the initial
48
+ * direction's extreme — never to the original preferred lightness.
49
+ *
50
+ * Default: false.
51
+ */
52
+ flip?: boolean;
53
+ }
54
+ interface FindLightnessForContrastResult {
55
+ /** Chosen lightness in 0–1. */
56
+ lightness: number;
57
+ /** Achieved WCAG contrast ratio. */
58
+ contrast: number;
59
+ /** Whether the target was reached. */
60
+ met: boolean;
61
+ /** Which branch was selected. */
62
+ branch: 'lighter' | 'darker' | 'preferred';
63
+ /**
64
+ * Whether the result was auto-flipped to the opposite direction.
65
+ * Only set when the initial direction failed and the opposite
66
+ * direction satisfied the target.
67
+ */
68
+ flipped?: boolean;
69
+ }
70
+ declare function resolveMinContrast(value: MinContrast$1): number;
71
+ /**
72
+ * Find the OKHSL lightness that satisfies a WCAG 2 contrast target
73
+ * against a base color, staying as close to `preferredLightness` as possible.
74
+ */
75
+ declare function findLightnessForContrast(options: FindLightnessForContrastOptions): FindLightnessForContrastResult;
76
+ interface FindValueForMixContrastOptions {
77
+ /** Preferred mix parameter (0–1). */
78
+ preferredValue: number;
79
+ /** Base color as linear sRGB. */
80
+ baseLinearRgb: LinearRgb;
81
+ /** Target color as linear sRGB. */
82
+ targetLinearRgb: LinearRgb;
83
+ /** WCAG contrast target. */
84
+ contrast: MinContrast$1;
85
+ /**
86
+ * Compute the luminance of the mixed color at parameter t.
87
+ * For opaque: luminance of OKHSL-interpolated color.
88
+ * For transparent: luminance of alpha-composited color over base.
89
+ */
90
+ luminanceAtValue: (t: number) => number;
91
+ /** Convergence threshold. Default: 1e-4. */
92
+ epsilon?: number;
93
+ /** Maximum binary-search iterations per branch. Default: 20. */
94
+ maxIterations?: number;
95
+ /**
96
+ * Auto-flip mix direction when contrast can't be met.
97
+ *
98
+ * When `true`, the solver searches the initial direction first
99
+ * (the side whose extreme has higher contrast against the base).
100
+ * If that side doesn't reach the target, it tries the opposite
101
+ * direction and uses it when it passes. If neither side passes,
102
+ * it returns the extreme mix value of the initial direction.
103
+ *
104
+ * When `false`, only the initial direction is considered. If it
105
+ * doesn't reach the target, the result is pinned to the initial
106
+ * direction's extreme — never to the original preferred value.
107
+ *
108
+ * Default: false.
109
+ */
110
+ flip?: boolean;
111
+ }
112
+ interface FindValueForMixContrastResult {
113
+ /** Chosen mix parameter (0–1). */
114
+ value: number;
115
+ /** Achieved WCAG contrast ratio. */
116
+ contrast: number;
117
+ /** Whether the target was reached. */
118
+ met: boolean;
119
+ /**
120
+ * Whether the result was auto-flipped to the opposite direction.
121
+ * Only set when the initial direction failed and the opposite
122
+ * direction satisfied the target.
123
+ */
124
+ flipped?: boolean;
125
+ }
126
+ /**
127
+ * Find the mix parameter (ratio or opacity) that satisfies a WCAG 2 contrast
128
+ * target against a base color, staying as close to `preferredValue` as possible.
129
+ */
130
+ declare function findValueForMixContrast(options: FindValueForMixContrastOptions): FindValueForMixContrastResult;
131
+ //#endregion
132
+ //#region src/types.d.ts
133
+ /** A value or [normal, high-contrast] pair. */
134
+ type HCPair<T> = T | [T, T];
135
+ type MinContrast = number | ContrastPreset;
136
+ type AdaptationMode = 'auto' | 'fixed' | 'static';
137
+ /** A signed relative offset string, e.g. '+20' or '-15.5'. */
138
+ type RelativeValue = `+${number}` | `-${number}`;
139
+ /** Color format for output. */
140
+ type GlazeColorFormat = 'okhsl' | 'rgb' | 'hsl' | 'oklch';
141
+ /**
142
+ * Controls which scheme variants are generated in the export.
143
+ * Light is always included (it's the default).
144
+ */
145
+ interface GlazeOutputModes {
146
+ /** Include dark scheme variants. Default: true. */
147
+ dark?: boolean;
148
+ /** Include high-contrast variants (both light-HC and dark-HC). Default: false. */
149
+ highContrast?: boolean;
150
+ }
151
+ /** Hex color string for DX hints. Runtime validation in `parseHex()`. */
152
+ type HexColor = `#${string}`;
153
+ /** Direct OKHSL color input. */
154
+ interface OkhslColor {
155
+ h: number;
156
+ s: number;
157
+ l: number;
158
+ }
159
+ /** sRGB components in 0–255 (value-shorthand object form). */
160
+ interface RgbColor {
161
+ r: number;
162
+ g: number;
163
+ b: number;
164
+ }
165
+ /** OKLCh components matching CSS `oklch(L C H)` (L/C: 0–1, H: degrees). */
166
+ interface OklchColor {
167
+ l: number;
168
+ c: number;
169
+ h: number;
170
+ }
171
+ interface RegularColorDef {
172
+ /**
173
+ * Lightness value (0–100).
174
+ * - Number: absolute lightness.
175
+ * - String ('+N' / '-N'): relative to base color's lightness (requires `base`).
176
+ */
177
+ lightness?: HCPair<number | RelativeValue>;
178
+ /** Saturation factor applied to the seed saturation (0–1, default: 1). */
179
+ saturation?: number;
180
+ /**
181
+ * Hue override for this color.
182
+ * - Number: absolute hue (0–360).
183
+ * - String ('+N' / '-N'): relative to the theme seed hue.
184
+ */
185
+ hue?: number | RelativeValue;
186
+ /** Name of another color in the same theme (dependent color). */
187
+ base?: string;
188
+ /** WCAG contrast ratio floor against the base color. */
189
+ contrast?: HCPair<MinContrast>;
190
+ /** Adaptation mode. Default: 'auto'. */
191
+ mode?: AdaptationMode;
192
+ /**
193
+ * Fixed opacity (0–1).
194
+ * Output includes alpha in the CSS value.
195
+ * Does not affect contrast resolution — a semi-transparent color
196
+ * has no fixed perceived lightness, so `contrast` and `opacity`
197
+ * should not be combined (a console.warn is emitted).
198
+ */
199
+ opacity?: number;
200
+ /**
201
+ * Whether this color is inherited by child themes created via `extend()`.
202
+ * Default: true. Set to false to make this color local to the current theme.
203
+ */
204
+ inherit?: boolean;
205
+ }
206
+ /** Shadow tuning knobs. All values use the 0–1 scale (OKHSL). */
207
+ interface ShadowTuning {
208
+ /** Fraction of fg saturation kept in pigment (0-1). Default: 0.18. */
209
+ saturationFactor?: number;
210
+ /** Upper clamp on pigment saturation (0-1). Default: 0.25. */
211
+ maxSaturation?: number;
212
+ /** Multiplier for bg lightness → pigment lightness. Default: 0.25. */
213
+ lightnessFactor?: number;
214
+ /** [min, max] clamp for pigment lightness (0-1). Default: [0.05, 0.20]. */
215
+ lightnessBounds?: [number, number];
216
+ /**
217
+ * Target minimum gap between pigment lightness and bg lightness (0-1).
218
+ * Default: 0.05.
219
+ */
220
+ minGapTarget?: number;
221
+ /** Max alpha (0-1). Reached at intensity=100 with max contrast. Default: 1.0. */
222
+ alphaMax?: number;
223
+ /**
224
+ * Blend weight (0-1) pulling pigment hue toward bg hue.
225
+ * 0 = pure fg hue, 1 = pure bg hue. Default: 0.2.
226
+ */
227
+ bgHueBlend?: number;
228
+ }
229
+ interface ShadowColorDef {
230
+ type: 'shadow';
231
+ /**
232
+ * Background color name — the surface the shadow sits on.
233
+ * Must reference a non-shadow color in the same theme.
234
+ */
235
+ bg: string;
236
+ /**
237
+ * Foreground color name for tinting and intensity modulation.
238
+ * Must reference a non-shadow color in the same theme.
239
+ * Omit for achromatic shadow at full user-specified intensity.
240
+ */
241
+ fg?: string;
242
+ /**
243
+ * Shadow intensity, 0-100.
244
+ * Supports [normal, highContrast] pair.
245
+ */
246
+ intensity: HCPair<number>;
247
+ /** Override default tuning. Merged field-by-field with global `shadowTuning`. */
248
+ tuning?: ShadowTuning;
249
+ /**
250
+ * Whether this color is inherited by child themes created via `extend()`.
251
+ * Default: true. Set to false to make this color local to the current theme.
252
+ */
253
+ inherit?: boolean;
254
+ }
255
+ interface MixColorDef {
256
+ type: 'mix';
257
+ /** Background/base color name — the "from" color. */
258
+ base: string;
259
+ /** Target color name — the "to" color to mix toward. */
260
+ target: string;
261
+ /**
262
+ * Mix ratio 0–100 (0 = pure base, 100 = pure target).
263
+ * In 'transparent' blend mode, this controls the opacity of the target.
264
+ * Supports [normal, highContrast] pair.
265
+ */
266
+ value: HCPair<number>;
267
+ /**
268
+ * Blending mode. Default: 'opaque'.
269
+ * - 'opaque': produces a solid color by interpolating base and target.
270
+ * - 'transparent': produces the target color with alpha = value/100.
271
+ */
272
+ blend?: 'opaque' | 'transparent';
273
+ /**
274
+ * Interpolation color space for opaque blending. Default: 'okhsl'.
275
+ * - 'okhsl': perceptually uniform, consistent with Glaze's internal model.
276
+ * - 'srgb': linear sRGB interpolation, matches browser compositing.
277
+ *
278
+ * Ignored for 'transparent' blend (always composites in linear sRGB).
279
+ */
280
+ space?: 'okhsl' | 'srgb';
281
+ /**
282
+ * Minimum WCAG contrast between the base and the resulting color.
283
+ * In 'opaque' mode, adjusts the mix ratio to meet contrast.
284
+ * In 'transparent' mode, adjusts opacity to meet contrast against the composite.
285
+ * Supports [normal, highContrast] pair.
286
+ */
287
+ contrast?: HCPair<MinContrast>;
288
+ /**
289
+ * Whether this color is inherited by child themes created via `extend()`.
290
+ * Default: true. Set to false to make this color local to the current theme.
291
+ */
292
+ inherit?: boolean;
293
+ }
294
+ type ColorDef = RegularColorDef | ShadowColorDef | MixColorDef;
295
+ type ColorMap = Record<string, ColorDef>;
296
+ /** Resolved color for a single scheme variant. */
297
+ interface ResolvedColorVariant {
298
+ /** OKHSL hue (0–360). */
299
+ h: number;
300
+ /** OKHSL saturation (0–1). */
301
+ s: number;
302
+ /** OKHSL lightness (0–1). */
303
+ l: number;
304
+ /** Opacity (0–1). Default: 1. */
305
+ alpha: number;
306
+ }
307
+ /** Fully resolved color across all scheme variants. */
308
+ interface ResolvedColor {
309
+ name: string;
310
+ light: ResolvedColorVariant;
311
+ dark: ResolvedColorVariant;
312
+ lightContrast: ResolvedColorVariant;
313
+ darkContrast: ResolvedColorVariant;
314
+ /** Adaptation mode. Present only for regular colors, omitted for shadows. */
315
+ mode?: AdaptationMode;
316
+ }
317
+ interface GlazeConfig {
318
+ /** Light scheme lightness window [lo, hi]. Default: [10, 100]. */
319
+ lightLightness?: [number, number];
320
+ /** Dark scheme lightness window [lo, hi]. Default: [15, 95]. */
321
+ darkLightness?: [number, number];
322
+ /** Saturation reduction factor for dark scheme (0–1). Default: 0.1. */
323
+ darkDesaturation?: number;
324
+ /**
325
+ * Möbius beta for dark auto-inversion (0–1).
326
+ * Lower values expand subtle near-white distinctions in dark mode.
327
+ * Set to 1 for linear (legacy) behavior. Default: 0.5.
328
+ * Accepts [normal, highContrast] pair for separate HC tuning.
329
+ */
330
+ darkCurve?: HCPair<number>;
331
+ /** State alias names for token export. */
332
+ states?: {
333
+ dark?: string;
334
+ highContrast?: string;
335
+ };
336
+ /** Which scheme variants to include in exports. Default: both true. */
337
+ modes?: GlazeOutputModes;
338
+ /** Default tuning for all shadow colors. Per-color tuning merges field-by-field. */
339
+ shadowTuning?: ShadowTuning;
340
+ /**
341
+ * Automatically flip lightness direction when contrast can't be met.
342
+ *
343
+ * When enabled (default `true`), the solver searches the requested
344
+ * lightness direction first. If that direction can't reach the target,
345
+ * it tries the opposite direction and uses it when it passes. If neither
346
+ * side passes, the lightness is pinned to the requested-direction
347
+ * extreme and a warning is emitted.
348
+ *
349
+ * Set to `false` for strict "no flip" behavior. The opposite
350
+ * direction is never considered: if the requested direction can't
351
+ * meet the target, the lightness is pinned to its extreme (never
352
+ * falls back to the originally requested lightness).
353
+ */
354
+ autoFlip?: boolean;
355
+ }
356
+ interface GlazeConfigResolved {
357
+ lightLightness: [number, number];
358
+ darkLightness: [number, number];
359
+ darkDesaturation: number;
360
+ darkCurve: HCPair<number>;
361
+ states: {
362
+ dark: string;
363
+ highContrast: string;
364
+ };
365
+ modes: Required<GlazeOutputModes>;
366
+ shadowTuning?: ShadowTuning;
367
+ autoFlip: boolean;
368
+ }
369
+ /** Serialized theme configuration (no resolved values). */
370
+ interface GlazeThemeExport {
371
+ hue: number;
372
+ saturation: number;
373
+ colors: ColorMap;
374
+ }
375
+ /** Input for `glaze.shadow()` standalone factory. */
376
+ interface GlazeShadowInput {
377
+ /**
378
+ * Background color — accepts any `GlazeColorValue` form: hex
379
+ * (`#rgb` / `#rrggbb` / `#rrggbbaa`), `rgb()` / `hsl()` / `okhsl()`
380
+ * / `oklch()` strings, or literal objects (`{ r, g, b }`, `{ h, s, l }`,
381
+ * `{ l, c, h }`). Alpha components are dropped with a warning.
382
+ */
383
+ bg: GlazeColorValue;
384
+ /**
385
+ * Foreground color for tinting + intensity modulation. Accepts the
386
+ * same forms as `bg`.
387
+ */
388
+ fg?: GlazeColorValue;
389
+ /** Intensity 0-100. */
390
+ intensity: number;
391
+ tuning?: ShadowTuning;
392
+ }
393
+ /** Input for the structured `glaze.color()` overload. */
394
+ interface GlazeColorInput {
395
+ hue: number;
396
+ saturation: number;
397
+ lightness: HCPair<number>;
398
+ saturationFactor?: number;
399
+ mode?: AdaptationMode;
400
+ /**
401
+ * Fixed opacity (0–1). Output includes alpha in the CSS value.
402
+ * Combining with `contrast` is not recommended (perceived lightness
403
+ * becomes unpredictable) — a `console.warn` is emitted in that case.
404
+ */
405
+ opacity?: number;
406
+ /**
407
+ * Optional dependency on another color. Same semantics as
408
+ * `GlazeColorOverrides.base` — `contrast` and relative `lightness`
409
+ * anchor to the base per scheme.
410
+ */
411
+ base?: GlazeColorToken | GlazeColorValue;
412
+ /**
413
+ * WCAG contrast floor against `base`. Requires `base` to be set.
414
+ */
415
+ contrast?: HCPair<MinContrast>;
416
+ /**
417
+ * Optional human-readable name for the token. Used in error and
418
+ * warning messages (otherwise an internal name like `"value"` is
419
+ * used). Does not affect output keys.
420
+ */
421
+ name?: string;
422
+ }
423
+ /**
424
+ * Any single-color input form accepted by the value-shorthand
425
+ * overload of `glaze.color()`.
426
+ *
427
+ * Strings cover hex (`#rgb` / `#rrggbb` / `#rrggbbaa`, alpha dropped
428
+ * with a warning) and the four CSS color functions Glaze itself emits:
429
+ * `rgb()`, `hsl()`, `okhsl()`, `oklch()` (alpha components also dropped
430
+ * with a warning).
431
+ *
432
+ * Literal object forms:
433
+ * - `{ h, s, l }` — OKHSL (h: 0–360, s/l: 0–1). Passing 0–100 for `s`/`l`
434
+ * throws with a hint to use the structured form.
435
+ * - `{ r, g, b }` — sRGB 0–255.
436
+ * - `{ l, c, h }` — OKLCh (L/C: 0–1, H: degrees), same as `oklch()` strings.
437
+ */
438
+ type GlazeColorValue = string | OkhslColor | RgbColor | OklchColor;
439
+ /** Optional overrides for `glaze.color(value, overrides?)`. */
440
+ interface GlazeColorOverrides {
441
+ /**
442
+ * Override hue. Number is absolute (0–360); `'+N'`/`'-N'` is relative
443
+ * to the extracted (or overridden) seed hue — same semantics as
444
+ * `RegularColorDef.hue`.
445
+ */
446
+ hue?: number | RelativeValue;
447
+ /** Override seed saturation (0–100). Default: extracted from value. */
448
+ saturation?: number;
449
+ /**
450
+ * Override lightness. Number is absolute (0–100); `'+N'`/`'-N'` is
451
+ * relative to the literal seed (the value passed to `glaze.color()`).
452
+ * Supports HCPair for high-contrast.
453
+ */
454
+ lightness?: HCPair<number | RelativeValue>;
455
+ /** Saturation multiplier on the seed (0–1). Default: 1. */
456
+ saturationFactor?: number;
457
+ /**
458
+ * Adaptation mode. Defaults to `'auto'` for every input form, so
459
+ * colors automatically adapt between light and dark like an ordinary
460
+ * theme color. All value-shorthand inputs (strings and literal objects)
461
+ * preserve light lightness (`lightLightness: false`) and snapshot
462
+ * `globalConfig.darkLightness` on the dark side. Only the structured
463
+ * `{ hue, saturation, lightness }` form also snapshots
464
+ * `globalConfig.lightLightness`.
465
+ *
466
+ * Pass `'fixed'` explicitly to opt back into the legacy linear, non-
467
+ * inverting mapping; pass `'static'` to pin the same lightness
468
+ * across every variant.
469
+ */
470
+ mode?: AdaptationMode;
471
+ /**
472
+ * WCAG contrast floor. By default solved against the literal seed
473
+ * (the value itself); when `base` is set, solved against the base's
474
+ * resolved variant per scheme. Same shape as `RegularColorDef.contrast`.
475
+ */
476
+ contrast?: HCPair<MinContrast>;
477
+ /**
478
+ * Optional dependency on another color. Accepts either a
479
+ * `GlazeColorToken` (returned by another `glaze.color()`) or a raw
480
+ * `GlazeColorValue` (hex / CSS strings / `{ r, g, b }` / `{ h, s, l }` / …),
481
+ * which is automatically wrapped in `glaze.color(value)`.
482
+ *
483
+ * When set:
484
+ * - `contrast` is solved against the base's resolved variant
485
+ * per-scheme (light / dark / lightContrast / darkContrast).
486
+ * - Relative `lightness: '+N'` / `'-N'` is anchored to the base's
487
+ * lightness per-scheme (matches theme behavior for dependent colors).
488
+ * - Relative `hue: '+N'` / `'-N'` still anchors to the seed (the
489
+ * value passed to `glaze.color()`), not the base.
490
+ *
491
+ * The base token's `.resolve()` is called lazily on first resolve and
492
+ * its result is captured by reference; later mutations to the base's
493
+ * defining call don't apply (matches existing token snapshot semantics).
494
+ */
495
+ base?: GlazeColorToken | GlazeColorValue;
496
+ /**
497
+ * Fixed opacity (0–1). Output includes alpha in the CSS value.
498
+ * Combining with `contrast` is not recommended (perceived lightness
499
+ * becomes unpredictable) — a `console.warn` is emitted in that case.
500
+ */
501
+ opacity?: number;
502
+ /**
503
+ * Optional human-readable name for the token. Used in error and
504
+ * warning messages (otherwise an internal name like `"value"` is
505
+ * used). Does not affect output keys.
506
+ */
507
+ name?: string;
508
+ }
509
+ /**
510
+ * Per-call lightness-window overrides for `glaze.color()`. Mirrors
511
+ * the field names from `GlazeConfig`.
512
+ *
513
+ * Defaults for `glaze.color()` vary by input form, and both fields are
514
+ * snapshotted from `globalConfig` at color-creation time so later
515
+ * `glaze.configure()` calls don't retroactively change already-created
516
+ * tokens (and `token.export()` round-trips byte-for-byte):
517
+ *
518
+ * - **Value-shorthand** (hex / `rgb()` / `hsl()` / `okhsl()` / `oklch()`
519
+ * strings, `{ r, g, b }`, `{ h, s, l }`, `{ l, c, h }`):
520
+ * - `lightLightness: false` — preserve input exactly.
521
+ * - `darkLightness: globalConfig.darkLightness` — snapshotted at create time.
522
+ *
523
+ * - **Structured inputs** (`{ hue, saturation, lightness, ... }`):
524
+ * - `lightLightness: globalConfig.lightLightness` — theme light window.
525
+ * - `darkLightness: globalConfig.darkLightness` — theme dark window.
526
+ *
527
+ * Passing this object replaces both fields at once. To keep one
528
+ * field's default while overriding the other, restate the default
529
+ * explicitly.
530
+ */
531
+ interface GlazeColorScaling {
532
+ /**
533
+ * Light-mode lightness window. Snapshotted at create time: `false`
534
+ * (preserve input) for value-shorthand inputs; plain
535
+ * `globalConfig.lightLightness` for structured inputs only. Pass
536
+ * `false` to preserve input lightness in light mode.
537
+ */
538
+ lightLightness?: false | [number, number];
539
+ /**
540
+ * Dark-mode lightness window. Snapshotted from `globalConfig` at
541
+ * create time for value-shorthand and structured inputs. Pass `false`
542
+ * to preserve input lightness in dark mode too.
543
+ */
544
+ darkLightness?: false | [number, number];
545
+ }
546
+ /** Options for `GlazeColorToken.css()`. */
547
+ interface GlazeColorCssOptions {
548
+ /**
549
+ * Custom property base name (without leading `--`). Required.
550
+ * Becomes the variable identifier in the output, e.g.
551
+ * `name: 'brand'` → `--brand-color: …`.
552
+ */
553
+ name: string;
554
+ /** Output color format. Default: 'rgb' (matches `theme.css` default). */
555
+ format?: GlazeColorFormat;
556
+ /**
557
+ * Suffix appended to the name. Default: '-color' (matches
558
+ * `theme.css` default).
559
+ */
560
+ suffix?: string;
561
+ }
562
+ /** Return type for `glaze.color()`. */
563
+ interface GlazeColorToken {
564
+ /** Resolve the color across all scheme variants. */
565
+ resolve(): ResolvedColor;
566
+ /** Export as a flat token map (no color name key). */
567
+ token(options?: GlazeTokenOptions): Record<string, string>;
568
+ /**
569
+ * Export as a tasty style-to-state binding (no color name key).
570
+ * Uses `#name` keys and state aliases (`''`, `@dark`, etc.).
571
+ * @see https://tasty.style/docs
572
+ */
573
+ tasty(options?: GlazeTokenOptions): Record<string, string>;
574
+ /** Export as a flat JSON map (no color name key). */
575
+ json(options?: GlazeJsonOptions): Record<string, string>;
576
+ /** Export as CSS custom property declarations grouped by scheme variant. */
577
+ css(options: GlazeColorCssOptions): GlazeCssResult;
578
+ /**
579
+ * Serialize the token as a JSON-safe object. Captures the original
580
+ * input value, overrides, and scaling so it can be rehydrated via
581
+ * `glaze.colorFrom(...)`. `base` is recursively serialized.
582
+ */
583
+ export(): GlazeColorTokenExport;
584
+ }
585
+ /**
586
+ * JSON-safe serialization of a `glaze.color()` token. Pass to
587
+ * `glaze.colorFrom(...)` to rehydrate.
588
+ */
589
+ interface GlazeColorTokenExport {
590
+ /**
591
+ * Discriminator for the source overload that created the token.
592
+ * - `'value'`: created via `glaze.color(value, overrides?, scaling?)`.
593
+ * - `'structured'`: created via `glaze.color({ hue, saturation, ... }, scaling?)`.
594
+ */
595
+ form: 'value' | 'structured';
596
+ /** Original input. For `form: 'value'` this is the raw `GlazeColorValue`; for `form: 'structured'` this is the structured input. */
597
+ input: GlazeColorValue | GlazeColorInputExport;
598
+ /**
599
+ * Overrides recorded at creation time. `base` is recursively
600
+ * serialized. Only present for `form: 'value'`.
601
+ */
602
+ overrides?: GlazeColorOverridesExport;
603
+ /** Lightness scaling override, if any. */
604
+ scaling?: GlazeColorScaling;
605
+ /**
606
+ * Auto-flip setting snapshotted at creation time from
607
+ * `globalConfig.autoFlip`. Only present when it differs from the
608
+ * global default (`true`). Rehydrated tokens use this value instead
609
+ * of whatever is current in `globalConfig`.
610
+ */
611
+ autoFlip?: boolean;
612
+ }
613
+ /**
614
+ * Serializable shape of a structured `glaze.color({...})` input.
615
+ * Differs from `GlazeColorInput` only in that `base` is replaced by an
616
+ * `export` instead of a token reference.
617
+ */
618
+ interface GlazeColorInputExport {
619
+ hue: number;
620
+ saturation: number;
621
+ lightness: HCPair<number>;
622
+ saturationFactor?: number;
623
+ mode?: AdaptationMode;
624
+ opacity?: number;
625
+ base?: GlazeColorTokenExport | GlazeColorValue;
626
+ contrast?: HCPair<MinContrast>;
627
+ name?: string;
628
+ }
629
+ /**
630
+ * Serializable shape of `GlazeColorOverrides`. `base` is replaced by
631
+ * its export (or left as a `GlazeColorValue` if it was originally a value).
632
+ */
633
+ interface GlazeColorOverridesExport {
634
+ hue?: number | RelativeValue;
635
+ saturation?: number;
636
+ lightness?: HCPair<number | RelativeValue>;
637
+ saturationFactor?: number;
638
+ mode?: AdaptationMode;
639
+ contrast?: HCPair<MinContrast>;
640
+ base?: GlazeColorTokenExport | GlazeColorValue;
641
+ opacity?: number;
642
+ name?: string;
643
+ }
644
+ interface GlazeTheme {
645
+ /** The hue seed (0–360). */
646
+ readonly hue: number;
647
+ /** The saturation seed (0–100). */
648
+ readonly saturation: number;
649
+ /** Add/replace colors (additive merge with existing definitions). */
650
+ colors(defs: ColorMap): void;
651
+ /** Get a color definition by name. */
652
+ color(name: string): ColorDef | undefined;
653
+ /** Set a single color definition. */
654
+ color(name: string, def: ColorDef): void;
655
+ /** Remove one or more color definitions. */
656
+ remove(names: string | string[]): void;
657
+ /** Check if a color is defined. */
658
+ has(name: string): boolean;
659
+ /** List all defined color names. */
660
+ list(): string[];
661
+ /** Clear all color definitions. */
662
+ reset(): void;
663
+ /** Export the theme configuration as a JSON-safe object. */
664
+ export(): GlazeThemeExport;
665
+ /** Create a child theme inheriting all color definitions. */
666
+ extend(options: GlazeExtendOptions): GlazeTheme;
667
+ /** Resolve all colors and return the result map. */
668
+ resolve(): Map<string, ResolvedColor>;
669
+ /**
670
+ * Export as a flat token map grouped by scheme variant.
671
+ *
672
+ * ```ts
673
+ * theme.tokens()
674
+ * // → { light: { surface: 'okhsl(...)' }, dark: { surface: 'okhsl(...)' } }
675
+ * ```
676
+ */
677
+ tokens(options?: GlazeJsonOptions): Record<string, Record<string, string>>;
678
+ /**
679
+ * Export as tasty style-to-state bindings.
680
+ * Uses `#name` color token keys and state aliases (`''`, `@dark`, etc.).
681
+ * Spread into component styles or register as a recipe via `configure({ recipes })`.
682
+ * @see https://tasty.style/docs
683
+ */
684
+ tasty(options?: GlazeTokenOptions): Record<string, Record<string, string>>;
685
+ /** Export as plain JSON. */
686
+ json(options?: GlazeJsonOptions): Record<string, Record<string, string>>;
687
+ /** Export as CSS custom property declarations. */
688
+ css(options?: GlazeCssOptions): GlazeCssResult;
689
+ }
690
+ interface GlazeExtendOptions {
691
+ hue?: number;
692
+ saturation?: number;
693
+ colors?: ColorMap;
694
+ }
695
+ interface GlazeTokenOptions {
696
+ /** Prefix mode. `true` uses "<themeName>-", or provide a custom map. */
697
+ prefix?: boolean | Record<string, string>;
698
+ /** Override state aliases for this export. */
699
+ states?: {
700
+ dark?: string;
701
+ highContrast?: string;
702
+ };
703
+ /** Override which scheme variants to include. */
704
+ modes?: GlazeOutputModes;
705
+ /** Output color format. Default: 'okhsl'. */
706
+ format?: GlazeColorFormat;
707
+ }
708
+ interface GlazeJsonOptions {
709
+ /** Override which scheme variants to include. */
710
+ modes?: GlazeOutputModes;
711
+ /** Output color format. Default: 'okhsl'. */
712
+ format?: GlazeColorFormat;
713
+ }
714
+ interface GlazeCssOptions {
715
+ /** Output color format. Default: 'rgb'. */
716
+ format?: GlazeColorFormat;
717
+ /** Suffix appended to each CSS custom property name. Default: '-color'. */
718
+ suffix?: string;
719
+ }
720
+ /** CSS custom property declarations grouped by scheme variant. */
721
+ interface GlazeCssResult {
722
+ light: string;
723
+ dark: string;
724
+ lightContrast: string;
725
+ darkContrast: string;
726
+ }
727
+ /** Options for `glaze.palette()` creation. */
728
+ interface GlazePaletteOptions {
729
+ /**
730
+ * Name of the primary theme. The primary theme's tokens are duplicated
731
+ * without prefix in all exports, providing convenient short aliases
732
+ * alongside the prefixed versions. Can be overridden per-export.
733
+ *
734
+ * @example
735
+ * ```ts
736
+ * const palette = glaze.palette({ brand, accent }, { primary: 'brand' });
737
+ * palette.tokens()
738
+ * // → { light: { 'brand-surface': '...', 'surface': '...', 'accent-surface': '...' } }
739
+ * ```
740
+ */
741
+ primary?: string;
742
+ }
743
+ /** Options shared by palette `tokens()`, `tasty()`, and `css()` exports. */
744
+ interface GlazePaletteExportOptions {
745
+ /**
746
+ * Prefix mode. `true` uses `"<themeName>-"`, or provide a custom map.
747
+ * Defaults to `true` for palette export methods.
748
+ * Set to `false` explicitly to disable prefixing. Colliding keys
749
+ * produce a console.warn and the first-written value wins.
750
+ */
751
+ prefix?: boolean | Record<string, string>;
752
+ /**
753
+ * Override the palette-level primary theme for this export.
754
+ * Pass a theme name to set/change the primary, or `false` to disable it.
755
+ * When omitted, inherits the palette-level `primary`.
756
+ */
757
+ primary?: string | false;
758
+ }
759
+ interface GlazePalette {
760
+ /**
761
+ * Export all themes as a flat token map grouped by scheme variant.
762
+ * Prefix defaults to `true` — all tokens are prefixed with the theme name.
763
+ * Inherits the palette-level `primary`; override per-call or pass `false` to disable.
764
+ *
765
+ * ```ts
766
+ * const palette = glaze.palette({ brand, accent }, { primary: 'brand' });
767
+ * palette.tokens()
768
+ * // → { light: { 'brand-surface': '...', 'surface': '...', 'accent-surface': '...' } }
769
+ * ```
770
+ */
771
+ tokens(options?: GlazeJsonOptions & GlazePaletteExportOptions): Record<string, Record<string, string>>;
772
+ /**
773
+ * Export all themes as tasty style-to-state bindings.
774
+ * Uses `#name` color token keys and state aliases (`''`, `@dark`, etc.).
775
+ * Prefix defaults to `true`. Inherits the palette-level `primary`.
776
+ * @see https://tasty.style/docs
777
+ */
778
+ tasty(options?: GlazeTokenOptions & GlazePaletteExportOptions): Record<string, Record<string, string>>;
779
+ /** Export all themes as plain JSON grouped by theme name. */
780
+ json(options?: GlazeJsonOptions & {
781
+ prefix?: boolean | Record<string, string>;
782
+ }): Record<string, Record<string, Record<string, string>>>;
783
+ /** Export all themes as CSS custom property declarations. */
784
+ css(options?: GlazeCssOptions & GlazePaletteExportOptions): GlazeCssResult;
785
+ }
786
+ //#endregion
787
+ //#region src/glaze.d.ts
788
+ type PaletteInput = Record<string, GlazeTheme>;
789
+ /**
790
+ * Create a single-hue glaze theme.
791
+ *
792
+ * @example
793
+ * ```ts
794
+ * const primary = glaze({ hue: 280, saturation: 80 });
795
+ * // or shorthand:
796
+ * const primary = glaze(280, 80);
797
+ * ```
798
+ */
799
+ declare function glaze(hueOrOptions: number | {
800
+ hue: number;
801
+ saturation: number;
802
+ }, saturation?: number): GlazeTheme;
803
+ declare namespace glaze {
804
+ var configure: (config: GlazeConfig) => void;
805
+ var palette: (themes: PaletteInput, options?: GlazePaletteOptions) => GlazePalette;
806
+ var from: (data: GlazeThemeExport) => GlazeTheme;
807
+ var color: {
808
+ (input: GlazeColorInput, scaling?: GlazeColorScaling): GlazeColorToken;
809
+ (value: GlazeColorValue, overrides?: GlazeColorOverrides, scaling?: GlazeColorScaling): GlazeColorToken;
810
+ };
811
+ var shadow: (input: GlazeShadowInput) => ResolvedColorVariant;
812
+ var format: (variant: ResolvedColorVariant, colorFormat?: GlazeColorFormat) => string;
813
+ var fromHex: (hex: string) => GlazeTheme;
814
+ var fromRgb: (r: number, g: number, b: number) => GlazeTheme;
815
+ var colorFrom: (data: GlazeColorTokenExport) => GlazeColorToken;
816
+ var getConfig: () => GlazeConfigResolved;
817
+ var resetConfig: () => void;
818
+ }
819
+ //#endregion
820
+ //#region src/okhsl-color-math.d.ts
821
+ /**
822
+ * OKHSL color math primitives for the glaze theme generator.
823
+ *
824
+ * Provides bidirectional OKHSL ↔ sRGB conversion, relative luminance
825
+ * computation for WCAG 2 contrast calculations, and multi-format output
826
+ * (okhsl, rgb, hsl, oklch).
827
+ */
828
+ type Vec3 = [number, number, number];
829
+ /**
830
+ * Convert OKHSL (h: 0–360, s: 0–1, l: 0–1) to OKLab [L, a, b].
831
+ */
832
+ declare function okhslToOklab(h: number, s: number, l: number): [number, number, number];
833
+ /**
834
+ * Convert OKHSL (h: 0–360, s: 0–1, l: 0–1) to linear sRGB.
835
+ * Channels may exceed [0, 1] near gamut boundaries — caller must clamp if needed.
836
+ */
837
+ declare function okhslToLinearSrgb(h: number, s: number, l: number): [number, number, number];
838
+ /**
839
+ * Compute relative luminance Y from linear sRGB channels.
840
+ * Per WCAG 2: Y = 0.2126·R + 0.7152·G + 0.0722·B
841
+ */
842
+ declare function relativeLuminanceFromLinearRgb(rgb: [number, number, number]): number;
843
+ /**
844
+ * WCAG 2 contrast ratio from two luminance values.
845
+ */
846
+ declare function contrastRatioFromLuminance(yA: number, yB: number): number;
847
+ /**
848
+ * Convert OKHSL to gamma-encoded sRGB (clamped to 0–1).
849
+ */
850
+ declare function okhslToSrgb(h: number, s: number, l: number): [number, number, number];
851
+ /**
852
+ * Compute WCAG 2 relative luminance from linear sRGB, matching the browser
853
+ * rendering pipeline: gamma-encode, clamp to sRGB gamut [0,1], then linearize.
854
+ * This avoids over/under-estimating luminance for out-of-gamut OKHSL colors.
855
+ */
856
+ declare function gamutClampedLuminance(linearRgb: [number, number, number]): number;
857
+ /**
858
+ * Convert OKLab to OKHSL.
859
+ * Input: [L, a, b] where L: 0–1, a/b: roughly -0.5 to 0.5.
860
+ * Returns [h, s, l] where h: 0–360, s: 0–1, l: 0–1.
861
+ */
862
+ declare const oklabToOkhsl: (lab: Vec3) => Vec3;
863
+ /**
864
+ * Convert gamma-encoded sRGB (0–1 per channel) to OKHSL.
865
+ * Returns [h, s, l] where h: 0–360, s: 0–1, l: 0–1.
866
+ */
867
+ declare function srgbToOkhsl(rgb: [number, number, number]): [number, number, number];
868
+ /**
869
+ * Convert CSS HSL (sRGB-based) to gamma-encoded sRGB [r, g, b] in 0–1 range.
870
+ * h: 0–360, s: 0–1, l: 0–1.
871
+ *
872
+ * Note: CSS HSL is not the same as OKHSL — it's HSL in the sRGB color space.
873
+ * Use this when parsing `hsl(...)` strings before passing to `srgbToOkhsl`.
874
+ */
875
+ declare function hslToSrgb(h: number, s: number, l: number): [number, number, number];
876
+ /**
877
+ * Parse a hex color string (#rgb or #rrggbb) to sRGB [r, g, b] in 0–1 range.
878
+ * Returns null if the string is not a valid hex color.
879
+ *
880
+ * For 8-digit hex (`#rrggbbaa`) and 4-digit hex (`#rgba`) with alpha,
881
+ * use {@link parseHexAlpha}.
882
+ */
883
+ declare function parseHex(hex: string): [number, number, number] | null;
884
+ /**
885
+ * Parse a hex color string (#rgb, #rrggbb, #rgba, or #rrggbbaa) to
886
+ * sRGB [r, g, b] in 0–1 range plus an optional alpha (0–1).
887
+ * Returns null if the string is not a valid hex color.
888
+ */
889
+ declare function parseHexAlpha(hex: string): {
890
+ rgb: [number, number, number];
891
+ alpha?: number;
892
+ } | null;
893
+ /**
894
+ * Format OKHSL values as a CSS `okhsl(H S% L%)` string.
895
+ * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
896
+ */
897
+ declare function formatOkhsl(h: number, s: number, l: number): string;
898
+ /**
899
+ * Format OKHSL values as a CSS `rgb(R G B)` string.
900
+ * Uses 2 decimal places to avoid 8-bit quantization contrast loss.
901
+ * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
902
+ */
903
+ declare function formatRgb(h: number, s: number, l: number): string;
904
+ /**
905
+ * Format OKHSL values as a CSS `hsl(H S% L%)` string.
906
+ * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
907
+ */
908
+ declare function formatHsl(h: number, s: number, l: number): string;
909
+ /**
910
+ * Format OKHSL values as a CSS `oklch(L C H)` string.
911
+ * h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
912
+ */
913
+ declare function formatOklch(h: number, s: number, l: number): string;
914
+ //#endregion
915
+ export { type AdaptationMode, type ColorDef, type ColorMap, type ContrastPreset, type FindLightnessForContrastOptions, type FindLightnessForContrastResult, type FindValueForMixContrastOptions, type FindValueForMixContrastResult, type GlazeColorCssOptions, type GlazeColorFormat, type GlazeColorInput, type GlazeColorInputExport, type GlazeColorOverrides, type GlazeColorOverridesExport, type GlazeColorScaling, type GlazeColorToken, type GlazeColorTokenExport, type GlazeColorValue, type GlazeConfig, type GlazeCssOptions, type GlazeCssResult, type GlazeExtendOptions, 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 OklchColor, type RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type RgbColor, type ShadowColorDef, type ShadowTuning, contrastRatioFromLuminance, findLightnessForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOklch, formatRgb, gamutClampedLuminance, glaze, hslToSrgb, okhslToLinearSrgb, okhslToOklab, okhslToSrgb, oklabToOkhsl, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveMinContrast, srgbToOkhsl };
916
+ //# sourceMappingURL=index.d.cts.map