@tenphi/glaze 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -1390
- package/dist/index.cjs +861 -672
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +115 -41
- package/dist/index.d.mts +115 -41
- package/dist/index.mjs +861 -672
- package/dist/index.mjs.map +1 -1
- package/docs/api.md +1080 -0
- package/docs/methodology.md +336 -0
- package/docs/migration.md +237 -0
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -26,6 +26,30 @@ interface FindLightnessForContrastOptions {
|
|
|
26
26
|
epsilon?: number;
|
|
27
27
|
/** Maximum binary-search iterations per branch. Default: 14. */
|
|
28
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;
|
|
29
53
|
}
|
|
30
54
|
interface FindLightnessForContrastResult {
|
|
31
55
|
/** Chosen lightness in 0–1. */
|
|
@@ -36,6 +60,12 @@ interface FindLightnessForContrastResult {
|
|
|
36
60
|
met: boolean;
|
|
37
61
|
/** Which branch was selected. */
|
|
38
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;
|
|
39
69
|
}
|
|
40
70
|
declare function resolveMinContrast(value: MinContrast$1): number;
|
|
41
71
|
/**
|
|
@@ -62,6 +92,22 @@ interface FindValueForMixContrastOptions {
|
|
|
62
92
|
epsilon?: number;
|
|
63
93
|
/** Maximum binary-search iterations per branch. Default: 20. */
|
|
64
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;
|
|
65
111
|
}
|
|
66
112
|
interface FindValueForMixContrastResult {
|
|
67
113
|
/** Chosen mix parameter (0–1). */
|
|
@@ -70,6 +116,12 @@ interface FindValueForMixContrastResult {
|
|
|
70
116
|
contrast: number;
|
|
71
117
|
/** Whether the target was reached. */
|
|
72
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;
|
|
73
125
|
}
|
|
74
126
|
/**
|
|
75
127
|
* Find the mix parameter (ratio or opacity) that satisfies a WCAG 2 contrast
|
|
@@ -104,6 +156,18 @@ interface OkhslColor {
|
|
|
104
156
|
s: number;
|
|
105
157
|
l: number;
|
|
106
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
|
+
}
|
|
107
171
|
interface RegularColorDef {
|
|
108
172
|
/**
|
|
109
173
|
* Lightness value (0–100).
|
|
@@ -273,6 +337,21 @@ interface GlazeConfig {
|
|
|
273
337
|
modes?: GlazeOutputModes;
|
|
274
338
|
/** Default tuning for all shadow colors. Per-color tuning merges field-by-field. */
|
|
275
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;
|
|
276
355
|
}
|
|
277
356
|
interface GlazeConfigResolved {
|
|
278
357
|
lightLightness: [number, number];
|
|
@@ -285,6 +364,7 @@ interface GlazeConfigResolved {
|
|
|
285
364
|
};
|
|
286
365
|
modes: Required<GlazeOutputModes>;
|
|
287
366
|
shadowTuning?: ShadowTuning;
|
|
367
|
+
autoFlip: boolean;
|
|
288
368
|
}
|
|
289
369
|
/** Serialized theme configuration (no resolved values). */
|
|
290
370
|
interface GlazeThemeExport {
|
|
@@ -297,8 +377,8 @@ interface GlazeShadowInput {
|
|
|
297
377
|
/**
|
|
298
378
|
* Background color — accepts any `GlazeColorValue` form: hex
|
|
299
379
|
* (`#rgb` / `#rrggbb` / `#rrggbbaa`), `rgb()` / `hsl()` / `okhsl()`
|
|
300
|
-
* / `oklch()` strings,
|
|
301
|
-
*
|
|
380
|
+
* / `oklch()` strings, or literal objects (`{ r, g, b }`, `{ h, s, l }`,
|
|
381
|
+
* `{ l, c, h }`). Alpha components are dropped with a warning.
|
|
302
382
|
*/
|
|
303
383
|
bg: GlazeColorValue;
|
|
304
384
|
/**
|
|
@@ -349,14 +429,13 @@ interface GlazeColorInput {
|
|
|
349
429
|
* `rgb()`, `hsl()`, `okhsl()`, `oklch()` (alpha components also dropped
|
|
350
430
|
* with a warning).
|
|
351
431
|
*
|
|
352
|
-
*
|
|
353
|
-
* (h: 0–360, s/l: 0–1). Passing 0–100
|
|
354
|
-
* a hint to use the structured
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
* range. Out-of-range or non-finite components throw.
|
|
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.
|
|
358
437
|
*/
|
|
359
|
-
type GlazeColorValue = string | OkhslColor |
|
|
438
|
+
type GlazeColorValue = string | OkhslColor | RgbColor | OklchColor;
|
|
360
439
|
/** Optional overrides for `glaze.color(value, overrides?)`. */
|
|
361
440
|
interface GlazeColorOverrides {
|
|
362
441
|
/**
|
|
@@ -378,11 +457,11 @@ interface GlazeColorOverrides {
|
|
|
378
457
|
/**
|
|
379
458
|
* Adaptation mode. Defaults to `'auto'` for every input form, so
|
|
380
459
|
* colors automatically adapt between light and dark like an ordinary
|
|
381
|
-
* theme color.
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
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`.
|
|
386
465
|
*
|
|
387
466
|
* Pass `'fixed'` explicitly to opt back into the legacy linear, non-
|
|
388
467
|
* inverting mapping; pass `'static'` to pin the same lightness
|
|
@@ -398,7 +477,7 @@ interface GlazeColorOverrides {
|
|
|
398
477
|
/**
|
|
399
478
|
* Optional dependency on another color. Accepts either a
|
|
400
479
|
* `GlazeColorToken` (returned by another `glaze.color()`) or a raw
|
|
401
|
-
* `GlazeColorValue` (hex /
|
|
480
|
+
* `GlazeColorValue` (hex / CSS strings / `{ r, g, b }` / `{ h, s, l }` / …),
|
|
402
481
|
* which is automatically wrapped in `glaze.color(value)`.
|
|
403
482
|
*
|
|
404
483
|
* When set:
|
|
@@ -436,17 +515,14 @@ interface GlazeColorOverrides {
|
|
|
436
515
|
* `glaze.configure()` calls don't retroactively change already-created
|
|
437
516
|
* tokens (and `token.export()` round-trips byte-for-byte):
|
|
438
517
|
*
|
|
439
|
-
* - **
|
|
518
|
+
* - **Value-shorthand** (hex / `rgb()` / `hsl()` / `okhsl()` / `oklch()`
|
|
519
|
+
* strings, `{ r, g, b }`, `{ h, s, l }`, `{ l, c, h }`):
|
|
440
520
|
* - `lightLightness: false` — preserve input exactly.
|
|
441
|
-
* - `darkLightness:
|
|
442
|
-
* dark window so the auto-mode dark variant can Möbius-invert all
|
|
443
|
-
* the way up to white.
|
|
521
|
+
* - `darkLightness: globalConfig.darkLightness` — snapshotted at create time.
|
|
444
522
|
*
|
|
445
|
-
* -
|
|
446
|
-
* - `lightLightness: globalConfig.lightLightness` —
|
|
447
|
-
*
|
|
448
|
-
* - `darkLightness: globalConfig.darkLightness` — same dark window
|
|
449
|
-
* theme colors use, snapshotted at create time.
|
|
523
|
+
* - **Structured inputs** (`{ hue, saturation, lightness, ... }`):
|
|
524
|
+
* - `lightLightness: globalConfig.lightLightness` — theme light window.
|
|
525
|
+
* - `darkLightness: globalConfig.darkLightness` — theme dark window.
|
|
450
526
|
*
|
|
451
527
|
* Passing this object replaces both fields at once. To keep one
|
|
452
528
|
* field's default while overriding the other, restate the default
|
|
@@ -454,18 +530,16 @@ interface GlazeColorOverrides {
|
|
|
454
530
|
*/
|
|
455
531
|
interface GlazeColorScaling {
|
|
456
532
|
/**
|
|
457
|
-
* Light-mode lightness window. Snapshotted
|
|
458
|
-
*
|
|
459
|
-
* `globalConfig.lightLightness` for
|
|
460
|
-
*
|
|
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.
|
|
461
537
|
*/
|
|
462
538
|
lightLightness?: false | [number, number];
|
|
463
539
|
/**
|
|
464
540
|
* Dark-mode lightness window. Snapshotted from `globalConfig` at
|
|
465
|
-
* create time
|
|
466
|
-
*
|
|
467
|
-
* tuple / structured inputs. Pass `false` to preserve input
|
|
468
|
-
* lightness in dark mode too.
|
|
541
|
+
* create time for value-shorthand and structured inputs. Pass `false`
|
|
542
|
+
* to preserve input lightness in dark mode too.
|
|
469
543
|
*/
|
|
470
544
|
darkLightness?: false | [number, number];
|
|
471
545
|
}
|
|
@@ -528,6 +602,13 @@ interface GlazeColorTokenExport {
|
|
|
528
602
|
overrides?: GlazeColorOverridesExport;
|
|
529
603
|
/** Lightness scaling override, if any. */
|
|
530
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;
|
|
531
612
|
}
|
|
532
613
|
/**
|
|
533
614
|
* Serializable shape of a structured `glaze.color({...})` input.
|
|
@@ -721,14 +802,7 @@ declare function glaze(hueOrOptions: number | {
|
|
|
721
802
|
}, saturation?: number): GlazeTheme;
|
|
722
803
|
declare namespace glaze {
|
|
723
804
|
var configure: (config: GlazeConfig) => void;
|
|
724
|
-
var palette: (themes: PaletteInput, options?: GlazePaletteOptions) =>
|
|
725
|
-
tokens(options?: GlazeJsonOptions & GlazePaletteExportOptions): Record<string, Record<string, string>>;
|
|
726
|
-
tasty(options?: GlazeTokenOptions & GlazePaletteExportOptions): Record<string, Record<string, string>>;
|
|
727
|
-
json(options?: GlazeJsonOptions & {
|
|
728
|
-
prefix?: boolean | Record<string, string>;
|
|
729
|
-
}): Record<string, Record<string, Record<string, string>>>;
|
|
730
|
-
css(options?: GlazeCssOptions & GlazePaletteExportOptions): GlazeCssResult;
|
|
731
|
-
};
|
|
805
|
+
var palette: (themes: PaletteInput, options?: GlazePaletteOptions) => GlazePalette;
|
|
732
806
|
var from: (data: GlazeThemeExport) => GlazeTheme;
|
|
733
807
|
var color: {
|
|
734
808
|
(input: GlazeColorInput, scaling?: GlazeColorScaling): GlazeColorToken;
|
|
@@ -838,5 +912,5 @@ declare function formatHsl(h: number, s: number, l: number): string;
|
|
|
838
912
|
*/
|
|
839
913
|
declare function formatOklch(h: number, s: number, l: number): string;
|
|
840
914
|
//#endregion
|
|
841
|
-
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 RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type ShadowColorDef, type ShadowTuning, contrastRatioFromLuminance, findLightnessForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOklch, formatRgb, gamutClampedLuminance, glaze, hslToSrgb, okhslToLinearSrgb, okhslToOklab, okhslToSrgb, oklabToOkhsl, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveMinContrast, srgbToOkhsl };
|
|
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 };
|
|
842
916
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -26,6 +26,30 @@ interface FindLightnessForContrastOptions {
|
|
|
26
26
|
epsilon?: number;
|
|
27
27
|
/** Maximum binary-search iterations per branch. Default: 14. */
|
|
28
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;
|
|
29
53
|
}
|
|
30
54
|
interface FindLightnessForContrastResult {
|
|
31
55
|
/** Chosen lightness in 0–1. */
|
|
@@ -36,6 +60,12 @@ interface FindLightnessForContrastResult {
|
|
|
36
60
|
met: boolean;
|
|
37
61
|
/** Which branch was selected. */
|
|
38
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;
|
|
39
69
|
}
|
|
40
70
|
declare function resolveMinContrast(value: MinContrast$1): number;
|
|
41
71
|
/**
|
|
@@ -62,6 +92,22 @@ interface FindValueForMixContrastOptions {
|
|
|
62
92
|
epsilon?: number;
|
|
63
93
|
/** Maximum binary-search iterations per branch. Default: 20. */
|
|
64
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;
|
|
65
111
|
}
|
|
66
112
|
interface FindValueForMixContrastResult {
|
|
67
113
|
/** Chosen mix parameter (0–1). */
|
|
@@ -70,6 +116,12 @@ interface FindValueForMixContrastResult {
|
|
|
70
116
|
contrast: number;
|
|
71
117
|
/** Whether the target was reached. */
|
|
72
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;
|
|
73
125
|
}
|
|
74
126
|
/**
|
|
75
127
|
* Find the mix parameter (ratio or opacity) that satisfies a WCAG 2 contrast
|
|
@@ -104,6 +156,18 @@ interface OkhslColor {
|
|
|
104
156
|
s: number;
|
|
105
157
|
l: number;
|
|
106
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
|
+
}
|
|
107
171
|
interface RegularColorDef {
|
|
108
172
|
/**
|
|
109
173
|
* Lightness value (0–100).
|
|
@@ -273,6 +337,21 @@ interface GlazeConfig {
|
|
|
273
337
|
modes?: GlazeOutputModes;
|
|
274
338
|
/** Default tuning for all shadow colors. Per-color tuning merges field-by-field. */
|
|
275
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;
|
|
276
355
|
}
|
|
277
356
|
interface GlazeConfigResolved {
|
|
278
357
|
lightLightness: [number, number];
|
|
@@ -285,6 +364,7 @@ interface GlazeConfigResolved {
|
|
|
285
364
|
};
|
|
286
365
|
modes: Required<GlazeOutputModes>;
|
|
287
366
|
shadowTuning?: ShadowTuning;
|
|
367
|
+
autoFlip: boolean;
|
|
288
368
|
}
|
|
289
369
|
/** Serialized theme configuration (no resolved values). */
|
|
290
370
|
interface GlazeThemeExport {
|
|
@@ -297,8 +377,8 @@ interface GlazeShadowInput {
|
|
|
297
377
|
/**
|
|
298
378
|
* Background color — accepts any `GlazeColorValue` form: hex
|
|
299
379
|
* (`#rgb` / `#rrggbb` / `#rrggbbaa`), `rgb()` / `hsl()` / `okhsl()`
|
|
300
|
-
* / `oklch()` strings,
|
|
301
|
-
*
|
|
380
|
+
* / `oklch()` strings, or literal objects (`{ r, g, b }`, `{ h, s, l }`,
|
|
381
|
+
* `{ l, c, h }`). Alpha components are dropped with a warning.
|
|
302
382
|
*/
|
|
303
383
|
bg: GlazeColorValue;
|
|
304
384
|
/**
|
|
@@ -349,14 +429,13 @@ interface GlazeColorInput {
|
|
|
349
429
|
* `rgb()`, `hsl()`, `okhsl()`, `oklch()` (alpha components also dropped
|
|
350
430
|
* with a warning).
|
|
351
431
|
*
|
|
352
|
-
*
|
|
353
|
-
* (h: 0–360, s/l: 0–1). Passing 0–100
|
|
354
|
-
* a hint to use the structured
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
* range. Out-of-range or non-finite components throw.
|
|
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.
|
|
358
437
|
*/
|
|
359
|
-
type GlazeColorValue = string | OkhslColor |
|
|
438
|
+
type GlazeColorValue = string | OkhslColor | RgbColor | OklchColor;
|
|
360
439
|
/** Optional overrides for `glaze.color(value, overrides?)`. */
|
|
361
440
|
interface GlazeColorOverrides {
|
|
362
441
|
/**
|
|
@@ -378,11 +457,11 @@ interface GlazeColorOverrides {
|
|
|
378
457
|
/**
|
|
379
458
|
* Adaptation mode. Defaults to `'auto'` for every input form, so
|
|
380
459
|
* colors automatically adapt between light and dark like an ordinary
|
|
381
|
-
* theme color.
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
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`.
|
|
386
465
|
*
|
|
387
466
|
* Pass `'fixed'` explicitly to opt back into the legacy linear, non-
|
|
388
467
|
* inverting mapping; pass `'static'` to pin the same lightness
|
|
@@ -398,7 +477,7 @@ interface GlazeColorOverrides {
|
|
|
398
477
|
/**
|
|
399
478
|
* Optional dependency on another color. Accepts either a
|
|
400
479
|
* `GlazeColorToken` (returned by another `glaze.color()`) or a raw
|
|
401
|
-
* `GlazeColorValue` (hex /
|
|
480
|
+
* `GlazeColorValue` (hex / CSS strings / `{ r, g, b }` / `{ h, s, l }` / …),
|
|
402
481
|
* which is automatically wrapped in `glaze.color(value)`.
|
|
403
482
|
*
|
|
404
483
|
* When set:
|
|
@@ -436,17 +515,14 @@ interface GlazeColorOverrides {
|
|
|
436
515
|
* `glaze.configure()` calls don't retroactively change already-created
|
|
437
516
|
* tokens (and `token.export()` round-trips byte-for-byte):
|
|
438
517
|
*
|
|
439
|
-
* - **
|
|
518
|
+
* - **Value-shorthand** (hex / `rgb()` / `hsl()` / `okhsl()` / `oklch()`
|
|
519
|
+
* strings, `{ r, g, b }`, `{ h, s, l }`, `{ l, c, h }`):
|
|
440
520
|
* - `lightLightness: false` — preserve input exactly.
|
|
441
|
-
* - `darkLightness:
|
|
442
|
-
* dark window so the auto-mode dark variant can Möbius-invert all
|
|
443
|
-
* the way up to white.
|
|
521
|
+
* - `darkLightness: globalConfig.darkLightness` — snapshotted at create time.
|
|
444
522
|
*
|
|
445
|
-
* -
|
|
446
|
-
* - `lightLightness: globalConfig.lightLightness` —
|
|
447
|
-
*
|
|
448
|
-
* - `darkLightness: globalConfig.darkLightness` — same dark window
|
|
449
|
-
* theme colors use, snapshotted at create time.
|
|
523
|
+
* - **Structured inputs** (`{ hue, saturation, lightness, ... }`):
|
|
524
|
+
* - `lightLightness: globalConfig.lightLightness` — theme light window.
|
|
525
|
+
* - `darkLightness: globalConfig.darkLightness` — theme dark window.
|
|
450
526
|
*
|
|
451
527
|
* Passing this object replaces both fields at once. To keep one
|
|
452
528
|
* field's default while overriding the other, restate the default
|
|
@@ -454,18 +530,16 @@ interface GlazeColorOverrides {
|
|
|
454
530
|
*/
|
|
455
531
|
interface GlazeColorScaling {
|
|
456
532
|
/**
|
|
457
|
-
* Light-mode lightness window. Snapshotted
|
|
458
|
-
*
|
|
459
|
-
* `globalConfig.lightLightness` for
|
|
460
|
-
*
|
|
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.
|
|
461
537
|
*/
|
|
462
538
|
lightLightness?: false | [number, number];
|
|
463
539
|
/**
|
|
464
540
|
* Dark-mode lightness window. Snapshotted from `globalConfig` at
|
|
465
|
-
* create time
|
|
466
|
-
*
|
|
467
|
-
* tuple / structured inputs. Pass `false` to preserve input
|
|
468
|
-
* lightness in dark mode too.
|
|
541
|
+
* create time for value-shorthand and structured inputs. Pass `false`
|
|
542
|
+
* to preserve input lightness in dark mode too.
|
|
469
543
|
*/
|
|
470
544
|
darkLightness?: false | [number, number];
|
|
471
545
|
}
|
|
@@ -528,6 +602,13 @@ interface GlazeColorTokenExport {
|
|
|
528
602
|
overrides?: GlazeColorOverridesExport;
|
|
529
603
|
/** Lightness scaling override, if any. */
|
|
530
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;
|
|
531
612
|
}
|
|
532
613
|
/**
|
|
533
614
|
* Serializable shape of a structured `glaze.color({...})` input.
|
|
@@ -721,14 +802,7 @@ declare function glaze(hueOrOptions: number | {
|
|
|
721
802
|
}, saturation?: number): GlazeTheme;
|
|
722
803
|
declare namespace glaze {
|
|
723
804
|
var configure: (config: GlazeConfig) => void;
|
|
724
|
-
var palette: (themes: PaletteInput, options?: GlazePaletteOptions) =>
|
|
725
|
-
tokens(options?: GlazeJsonOptions & GlazePaletteExportOptions): Record<string, Record<string, string>>;
|
|
726
|
-
tasty(options?: GlazeTokenOptions & GlazePaletteExportOptions): Record<string, Record<string, string>>;
|
|
727
|
-
json(options?: GlazeJsonOptions & {
|
|
728
|
-
prefix?: boolean | Record<string, string>;
|
|
729
|
-
}): Record<string, Record<string, Record<string, string>>>;
|
|
730
|
-
css(options?: GlazeCssOptions & GlazePaletteExportOptions): GlazeCssResult;
|
|
731
|
-
};
|
|
805
|
+
var palette: (themes: PaletteInput, options?: GlazePaletteOptions) => GlazePalette;
|
|
732
806
|
var from: (data: GlazeThemeExport) => GlazeTheme;
|
|
733
807
|
var color: {
|
|
734
808
|
(input: GlazeColorInput, scaling?: GlazeColorScaling): GlazeColorToken;
|
|
@@ -838,5 +912,5 @@ declare function formatHsl(h: number, s: number, l: number): string;
|
|
|
838
912
|
*/
|
|
839
913
|
declare function formatOklch(h: number, s: number, l: number): string;
|
|
840
914
|
//#endregion
|
|
841
|
-
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 RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type ShadowColorDef, type ShadowTuning, contrastRatioFromLuminance, findLightnessForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOklch, formatRgb, gamutClampedLuminance, glaze, hslToSrgb, okhslToLinearSrgb, okhslToOklab, okhslToSrgb, oklabToOkhsl, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveMinContrast, srgbToOkhsl };
|
|
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 };
|
|
842
916
|
//# sourceMappingURL=index.d.mts.map
|