@tenphi/glaze 0.0.0-snapshot.4c063ef → 0.0.0-snapshot.4e8eab7
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 +587 -51
- package/dist/index.cjs +1064 -137
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +424 -33
- package/dist/index.d.mts +424 -33
- package/dist/index.mjs +1060 -138
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -7
package/dist/index.d.cts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* against a base color. Used by glaze when resolving dependent colors
|
|
7
7
|
* with `contrast`.
|
|
8
8
|
*/
|
|
9
|
+
type LinearRgb = [number, number, number];
|
|
9
10
|
type ContrastPreset = 'AA' | 'AAA' | 'AA-large' | 'AAA-large';
|
|
10
11
|
type MinContrast$1 = number | ContrastPreset;
|
|
11
12
|
interface FindLightnessForContrastOptions {
|
|
@@ -42,6 +43,39 @@ declare function resolveMinContrast(value: MinContrast$1): number;
|
|
|
42
43
|
* against a base color, staying as close to `preferredLightness` as possible.
|
|
43
44
|
*/
|
|
44
45
|
declare function findLightnessForContrast(options: FindLightnessForContrastOptions): FindLightnessForContrastResult;
|
|
46
|
+
interface FindValueForMixContrastOptions {
|
|
47
|
+
/** Preferred mix parameter (0–1). */
|
|
48
|
+
preferredValue: number;
|
|
49
|
+
/** Base color as linear sRGB. */
|
|
50
|
+
baseLinearRgb: LinearRgb;
|
|
51
|
+
/** Target color as linear sRGB. */
|
|
52
|
+
targetLinearRgb: LinearRgb;
|
|
53
|
+
/** WCAG contrast target. */
|
|
54
|
+
contrast: MinContrast$1;
|
|
55
|
+
/**
|
|
56
|
+
* Compute the luminance of the mixed color at parameter t.
|
|
57
|
+
* For opaque: luminance of OKHSL-interpolated color.
|
|
58
|
+
* For transparent: luminance of alpha-composited color over base.
|
|
59
|
+
*/
|
|
60
|
+
luminanceAtValue: (t: number) => number;
|
|
61
|
+
/** Convergence threshold. Default: 1e-4. */
|
|
62
|
+
epsilon?: number;
|
|
63
|
+
/** Maximum binary-search iterations per branch. Default: 20. */
|
|
64
|
+
maxIterations?: number;
|
|
65
|
+
}
|
|
66
|
+
interface FindValueForMixContrastResult {
|
|
67
|
+
/** Chosen mix parameter (0–1). */
|
|
68
|
+
value: number;
|
|
69
|
+
/** Achieved WCAG contrast ratio. */
|
|
70
|
+
contrast: number;
|
|
71
|
+
/** Whether the target was reached. */
|
|
72
|
+
met: boolean;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Find the mix parameter (ratio or opacity) that satisfies a WCAG 2 contrast
|
|
76
|
+
* target against a base color, staying as close to `preferredValue` as possible.
|
|
77
|
+
*/
|
|
78
|
+
declare function findValueForMixContrast(options: FindValueForMixContrastOptions): FindValueForMixContrastResult;
|
|
45
79
|
//#endregion
|
|
46
80
|
//#region src/types.d.ts
|
|
47
81
|
/** A value or [normal, high-contrast] pair. */
|
|
@@ -99,6 +133,11 @@ interface RegularColorDef {
|
|
|
99
133
|
* should not be combined (a console.warn is emitted).
|
|
100
134
|
*/
|
|
101
135
|
opacity?: number;
|
|
136
|
+
/**
|
|
137
|
+
* Whether this color is inherited by child themes created via `extend()`.
|
|
138
|
+
* Default: true. Set to false to make this color local to the current theme.
|
|
139
|
+
*/
|
|
140
|
+
inherit?: boolean;
|
|
102
141
|
}
|
|
103
142
|
/** Shadow tuning knobs. All values use the 0–1 scale (OKHSL). */
|
|
104
143
|
interface ShadowTuning {
|
|
@@ -143,8 +182,52 @@ interface ShadowColorDef {
|
|
|
143
182
|
intensity: HCPair<number>;
|
|
144
183
|
/** Override default tuning. Merged field-by-field with global `shadowTuning`. */
|
|
145
184
|
tuning?: ShadowTuning;
|
|
185
|
+
/**
|
|
186
|
+
* Whether this color is inherited by child themes created via `extend()`.
|
|
187
|
+
* Default: true. Set to false to make this color local to the current theme.
|
|
188
|
+
*/
|
|
189
|
+
inherit?: boolean;
|
|
146
190
|
}
|
|
147
|
-
|
|
191
|
+
interface MixColorDef {
|
|
192
|
+
type: 'mix';
|
|
193
|
+
/** Background/base color name — the "from" color. */
|
|
194
|
+
base: string;
|
|
195
|
+
/** Target color name — the "to" color to mix toward. */
|
|
196
|
+
target: string;
|
|
197
|
+
/**
|
|
198
|
+
* Mix ratio 0–100 (0 = pure base, 100 = pure target).
|
|
199
|
+
* In 'transparent' blend mode, this controls the opacity of the target.
|
|
200
|
+
* Supports [normal, highContrast] pair.
|
|
201
|
+
*/
|
|
202
|
+
value: HCPair<number>;
|
|
203
|
+
/**
|
|
204
|
+
* Blending mode. Default: 'opaque'.
|
|
205
|
+
* - 'opaque': produces a solid color by interpolating base and target.
|
|
206
|
+
* - 'transparent': produces the target color with alpha = value/100.
|
|
207
|
+
*/
|
|
208
|
+
blend?: 'opaque' | 'transparent';
|
|
209
|
+
/**
|
|
210
|
+
* Interpolation color space for opaque blending. Default: 'okhsl'.
|
|
211
|
+
* - 'okhsl': perceptually uniform, consistent with Glaze's internal model.
|
|
212
|
+
* - 'srgb': linear sRGB interpolation, matches browser compositing.
|
|
213
|
+
*
|
|
214
|
+
* Ignored for 'transparent' blend (always composites in linear sRGB).
|
|
215
|
+
*/
|
|
216
|
+
space?: 'okhsl' | 'srgb';
|
|
217
|
+
/**
|
|
218
|
+
* Minimum WCAG contrast between the base and the resulting color.
|
|
219
|
+
* In 'opaque' mode, adjusts the mix ratio to meet contrast.
|
|
220
|
+
* In 'transparent' mode, adjusts opacity to meet contrast against the composite.
|
|
221
|
+
* Supports [normal, highContrast] pair.
|
|
222
|
+
*/
|
|
223
|
+
contrast?: HCPair<MinContrast>;
|
|
224
|
+
/**
|
|
225
|
+
* Whether this color is inherited by child themes created via `extend()`.
|
|
226
|
+
* Default: true. Set to false to make this color local to the current theme.
|
|
227
|
+
*/
|
|
228
|
+
inherit?: boolean;
|
|
229
|
+
}
|
|
230
|
+
type ColorDef = RegularColorDef | ShadowColorDef | MixColorDef;
|
|
148
231
|
type ColorMap = Record<string, ColorDef>;
|
|
149
232
|
/** Resolved color for a single scheme variant. */
|
|
150
233
|
interface ResolvedColorVariant {
|
|
@@ -174,6 +257,13 @@ interface GlazeConfig {
|
|
|
174
257
|
darkLightness?: [number, number];
|
|
175
258
|
/** Saturation reduction factor for dark scheme (0–1). Default: 0.1. */
|
|
176
259
|
darkDesaturation?: number;
|
|
260
|
+
/**
|
|
261
|
+
* Möbius beta for dark auto-inversion (0–1).
|
|
262
|
+
* Lower values expand subtle near-white distinctions in dark mode.
|
|
263
|
+
* Set to 1 for linear (legacy) behavior. Default: 0.5.
|
|
264
|
+
* Accepts [normal, highContrast] pair for separate HC tuning.
|
|
265
|
+
*/
|
|
266
|
+
darkCurve?: HCPair<number>;
|
|
177
267
|
/** State alias names for token export. */
|
|
178
268
|
states?: {
|
|
179
269
|
dark?: string;
|
|
@@ -188,6 +278,7 @@ interface GlazeConfigResolved {
|
|
|
188
278
|
lightLightness: [number, number];
|
|
189
279
|
darkLightness: [number, number];
|
|
190
280
|
darkDesaturation: number;
|
|
281
|
+
darkCurve: HCPair<number>;
|
|
191
282
|
states: {
|
|
192
283
|
dark: string;
|
|
193
284
|
highContrast: string;
|
|
@@ -203,21 +294,196 @@ interface GlazeThemeExport {
|
|
|
203
294
|
}
|
|
204
295
|
/** Input for `glaze.shadow()` standalone factory. */
|
|
205
296
|
interface GlazeShadowInput {
|
|
206
|
-
/**
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
297
|
+
/**
|
|
298
|
+
* Background color — accepts any `GlazeColorValue` form: hex
|
|
299
|
+
* (`#rgb` / `#rrggbb` / `#rrggbbaa`), `rgb()` / `hsl()` / `okhsl()`
|
|
300
|
+
* / `oklch()` strings, an `OkhslColor` object, or an `[r, g, b]`
|
|
301
|
+
* (0–255) tuple. Alpha components are dropped with a warning.
|
|
302
|
+
*/
|
|
303
|
+
bg: GlazeColorValue;
|
|
304
|
+
/**
|
|
305
|
+
* Foreground color for tinting + intensity modulation. Accepts the
|
|
306
|
+
* same forms as `bg`.
|
|
307
|
+
*/
|
|
308
|
+
fg?: GlazeColorValue;
|
|
210
309
|
/** Intensity 0-100. */
|
|
211
310
|
intensity: number;
|
|
212
311
|
tuning?: ShadowTuning;
|
|
213
312
|
}
|
|
214
|
-
/** Input for `glaze.color()`
|
|
313
|
+
/** Input for the structured `glaze.color()` overload. */
|
|
215
314
|
interface GlazeColorInput {
|
|
216
315
|
hue: number;
|
|
217
316
|
saturation: number;
|
|
218
317
|
lightness: HCPair<number>;
|
|
219
318
|
saturationFactor?: number;
|
|
220
319
|
mode?: AdaptationMode;
|
|
320
|
+
/**
|
|
321
|
+
* Fixed opacity (0–1). Output includes alpha in the CSS value.
|
|
322
|
+
* Combining with `contrast` is not recommended (perceived lightness
|
|
323
|
+
* becomes unpredictable) — a `console.warn` is emitted in that case.
|
|
324
|
+
*/
|
|
325
|
+
opacity?: number;
|
|
326
|
+
/**
|
|
327
|
+
* Optional dependency on another color. Same semantics as
|
|
328
|
+
* `GlazeColorOverrides.base` — `contrast` and relative `lightness`
|
|
329
|
+
* anchor to the base per scheme.
|
|
330
|
+
*/
|
|
331
|
+
base?: GlazeColorToken | GlazeColorValue;
|
|
332
|
+
/**
|
|
333
|
+
* WCAG contrast floor against `base`. Requires `base` to be set.
|
|
334
|
+
*/
|
|
335
|
+
contrast?: HCPair<MinContrast>;
|
|
336
|
+
/**
|
|
337
|
+
* Optional human-readable name for the token. Used in error and
|
|
338
|
+
* warning messages (otherwise an internal name like `"value"` is
|
|
339
|
+
* used). Does not affect output keys.
|
|
340
|
+
*/
|
|
341
|
+
name?: string;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Any single-color input form accepted by the value-shorthand
|
|
345
|
+
* overload of `glaze.color()`.
|
|
346
|
+
*
|
|
347
|
+
* Strings cover hex (`#rgb` / `#rrggbb` / `#rrggbbaa`, alpha dropped
|
|
348
|
+
* with a warning) and the four CSS color functions Glaze itself emits:
|
|
349
|
+
* `rgb()`, `hsl()`, `okhsl()`, `oklch()` (alpha components also dropped
|
|
350
|
+
* with a warning).
|
|
351
|
+
*
|
|
352
|
+
* The OKHSL object form `{ h, s, l }` matches Glaze's native shape
|
|
353
|
+
* (h: 0–360, s/l: 0–1). Passing 0–100 values for `s`/`l` throws with
|
|
354
|
+
* a hint to use the structured `{ hue, saturation, lightness }` form.
|
|
355
|
+
*
|
|
356
|
+
* The tuple form is `[r, g, b]` in 0–255, matching `glaze.fromRgb`'s
|
|
357
|
+
* range. Out-of-range or non-finite components throw.
|
|
358
|
+
*/
|
|
359
|
+
type GlazeColorValue = string | OkhslColor | readonly [number, number, number];
|
|
360
|
+
/** Optional overrides for `glaze.color(value, overrides?)`. */
|
|
361
|
+
interface GlazeColorOverrides {
|
|
362
|
+
/**
|
|
363
|
+
* Override hue. Number is absolute (0–360); `'+N'`/`'-N'` is relative
|
|
364
|
+
* to the extracted (or overridden) seed hue — same semantics as
|
|
365
|
+
* `RegularColorDef.hue`.
|
|
366
|
+
*/
|
|
367
|
+
hue?: number | RelativeValue;
|
|
368
|
+
/** Override seed saturation (0–100). Default: extracted from value. */
|
|
369
|
+
saturation?: number;
|
|
370
|
+
/**
|
|
371
|
+
* Override lightness. Number is absolute (0–100); `'+N'`/`'-N'` is
|
|
372
|
+
* relative to the literal seed (the value passed to `glaze.color()`).
|
|
373
|
+
* Supports HCPair for high-contrast.
|
|
374
|
+
*/
|
|
375
|
+
lightness?: HCPair<number | RelativeValue>;
|
|
376
|
+
/** Saturation multiplier on the seed (0–1). Default: 1. */
|
|
377
|
+
saturationFactor?: number;
|
|
378
|
+
/**
|
|
379
|
+
* Adaptation mode. Defaults to `'auto'` for every input form, so
|
|
380
|
+
* colors automatically adapt between light and dark like an ordinary
|
|
381
|
+
* theme color. The default *scaling* snapshot differs by input form:
|
|
382
|
+
* string inputs preserve their light lightness and extend the dark
|
|
383
|
+
* window to `[lo, 100]` (`#000` ↔ `#fff` flip), while `OkhslColor`
|
|
384
|
+
* and `[r, g, b]` tuple inputs snapshot the full `globalConfig.
|
|
385
|
+
* lightLightness` / `globalConfig.darkLightness` windows.
|
|
386
|
+
*
|
|
387
|
+
* Pass `'fixed'` explicitly to opt back into the legacy linear, non-
|
|
388
|
+
* inverting mapping; pass `'static'` to pin the same lightness
|
|
389
|
+
* across every variant.
|
|
390
|
+
*/
|
|
391
|
+
mode?: AdaptationMode;
|
|
392
|
+
/**
|
|
393
|
+
* WCAG contrast floor. By default solved against the literal seed
|
|
394
|
+
* (the value itself); when `base` is set, solved against the base's
|
|
395
|
+
* resolved variant per scheme. Same shape as `RegularColorDef.contrast`.
|
|
396
|
+
*/
|
|
397
|
+
contrast?: HCPair<MinContrast>;
|
|
398
|
+
/**
|
|
399
|
+
* Optional dependency on another color. Accepts either a
|
|
400
|
+
* `GlazeColorToken` (returned by another `glaze.color()`) or a raw
|
|
401
|
+
* `GlazeColorValue` (hex / `rgb()` / `OkhslColor` / `[r, g, b]`),
|
|
402
|
+
* which is automatically wrapped in `glaze.color(value)`.
|
|
403
|
+
*
|
|
404
|
+
* When set:
|
|
405
|
+
* - `contrast` is solved against the base's resolved variant
|
|
406
|
+
* per-scheme (light / dark / lightContrast / darkContrast).
|
|
407
|
+
* - Relative `lightness: '+N'` / `'-N'` is anchored to the base's
|
|
408
|
+
* lightness per-scheme (matches theme behavior for dependent colors).
|
|
409
|
+
* - Relative `hue: '+N'` / `'-N'` still anchors to the seed (the
|
|
410
|
+
* value passed to `glaze.color()`), not the base.
|
|
411
|
+
*
|
|
412
|
+
* The base token's `.resolve()` is called lazily on first resolve and
|
|
413
|
+
* its result is captured by reference; later mutations to the base's
|
|
414
|
+
* defining call don't apply (matches existing token snapshot semantics).
|
|
415
|
+
*/
|
|
416
|
+
base?: GlazeColorToken | GlazeColorValue;
|
|
417
|
+
/**
|
|
418
|
+
* Fixed opacity (0–1). Output includes alpha in the CSS value.
|
|
419
|
+
* Combining with `contrast` is not recommended (perceived lightness
|
|
420
|
+
* becomes unpredictable) — a `console.warn` is emitted in that case.
|
|
421
|
+
*/
|
|
422
|
+
opacity?: number;
|
|
423
|
+
/**
|
|
424
|
+
* Optional human-readable name for the token. Used in error and
|
|
425
|
+
* warning messages (otherwise an internal name like `"value"` is
|
|
426
|
+
* used). Does not affect output keys.
|
|
427
|
+
*/
|
|
428
|
+
name?: string;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Per-call lightness-window overrides for `glaze.color()`. Mirrors
|
|
432
|
+
* the field names from `GlazeConfig`.
|
|
433
|
+
*
|
|
434
|
+
* Defaults for `glaze.color()` vary by input form, and both fields are
|
|
435
|
+
* snapshotted from `globalConfig` at color-creation time so later
|
|
436
|
+
* `glaze.configure()` calls don't retroactively change already-created
|
|
437
|
+
* tokens (and `token.export()` round-trips byte-for-byte):
|
|
438
|
+
*
|
|
439
|
+
* - **String inputs** (`'#1a1a1a'`, `'rgb(...)'`, `'okhsl(...)'`, ...):
|
|
440
|
+
* - `lightLightness: false` — preserve input exactly.
|
|
441
|
+
* - `darkLightness: [globalConfig.darkLightness[0], 100]` — extended
|
|
442
|
+
* dark window so the auto-mode dark variant can Möbius-invert all
|
|
443
|
+
* the way up to white.
|
|
444
|
+
*
|
|
445
|
+
* - **`OkhslColor` / `[r, g, b]` tuple / structured inputs**:
|
|
446
|
+
* - `lightLightness: globalConfig.lightLightness` — same light window
|
|
447
|
+
* theme colors use, snapshotted at create time.
|
|
448
|
+
* - `darkLightness: globalConfig.darkLightness` — same dark window
|
|
449
|
+
* theme colors use, snapshotted at create time.
|
|
450
|
+
*
|
|
451
|
+
* Passing this object replaces both fields at once. To keep one
|
|
452
|
+
* field's default while overriding the other, restate the default
|
|
453
|
+
* explicitly.
|
|
454
|
+
*/
|
|
455
|
+
interface GlazeColorScaling {
|
|
456
|
+
/**
|
|
457
|
+
* Light-mode lightness window. Snapshotted from `globalConfig` at
|
|
458
|
+
* create time: `false` (preserve input) for string inputs, plain
|
|
459
|
+
* `globalConfig.lightLightness` for object / tuple / structured
|
|
460
|
+
* inputs. Pass `false` to preserve input lightness in light mode.
|
|
461
|
+
*/
|
|
462
|
+
lightLightness?: false | [number, number];
|
|
463
|
+
/**
|
|
464
|
+
* Dark-mode lightness window. Snapshotted from `globalConfig` at
|
|
465
|
+
* create time: extended `[globalConfig.darkLightness[0], 100]` for
|
|
466
|
+
* string inputs, plain `globalConfig.darkLightness` for object /
|
|
467
|
+
* tuple / structured inputs. Pass `false` to preserve input
|
|
468
|
+
* lightness in dark mode too.
|
|
469
|
+
*/
|
|
470
|
+
darkLightness?: false | [number, number];
|
|
471
|
+
}
|
|
472
|
+
/** Options for `GlazeColorToken.css()`. */
|
|
473
|
+
interface GlazeColorCssOptions {
|
|
474
|
+
/**
|
|
475
|
+
* Custom property base name (without leading `--`). Required.
|
|
476
|
+
* Becomes the variable identifier in the output, e.g.
|
|
477
|
+
* `name: 'brand'` → `--brand-color: …`.
|
|
478
|
+
*/
|
|
479
|
+
name: string;
|
|
480
|
+
/** Output color format. Default: 'rgb' (matches `theme.css` default). */
|
|
481
|
+
format?: GlazeColorFormat;
|
|
482
|
+
/**
|
|
483
|
+
* Suffix appended to the name. Default: '-color' (matches
|
|
484
|
+
* `theme.css` default).
|
|
485
|
+
*/
|
|
486
|
+
suffix?: string;
|
|
221
487
|
}
|
|
222
488
|
/** Return type for `glaze.color()`. */
|
|
223
489
|
interface GlazeColorToken {
|
|
@@ -228,11 +494,71 @@ interface GlazeColorToken {
|
|
|
228
494
|
/**
|
|
229
495
|
* Export as a tasty style-to-state binding (no color name key).
|
|
230
496
|
* Uses `#name` keys and state aliases (`''`, `@dark`, etc.).
|
|
231
|
-
* @see https://
|
|
497
|
+
* @see https://tasty.style/docs
|
|
232
498
|
*/
|
|
233
499
|
tasty(options?: GlazeTokenOptions): Record<string, string>;
|
|
234
500
|
/** Export as a flat JSON map (no color name key). */
|
|
235
501
|
json(options?: GlazeJsonOptions): Record<string, string>;
|
|
502
|
+
/** Export as CSS custom property declarations grouped by scheme variant. */
|
|
503
|
+
css(options: GlazeColorCssOptions): GlazeCssResult;
|
|
504
|
+
/**
|
|
505
|
+
* Serialize the token as a JSON-safe object. Captures the original
|
|
506
|
+
* input value, overrides, and scaling so it can be rehydrated via
|
|
507
|
+
* `glaze.colorFrom(...)`. `base` is recursively serialized.
|
|
508
|
+
*/
|
|
509
|
+
export(): GlazeColorTokenExport;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* JSON-safe serialization of a `glaze.color()` token. Pass to
|
|
513
|
+
* `glaze.colorFrom(...)` to rehydrate.
|
|
514
|
+
*/
|
|
515
|
+
interface GlazeColorTokenExport {
|
|
516
|
+
/**
|
|
517
|
+
* Discriminator for the source overload that created the token.
|
|
518
|
+
* - `'value'`: created via `glaze.color(value, overrides?, scaling?)`.
|
|
519
|
+
* - `'structured'`: created via `glaze.color({ hue, saturation, ... }, scaling?)`.
|
|
520
|
+
*/
|
|
521
|
+
form: 'value' | 'structured';
|
|
522
|
+
/** Original input. For `form: 'value'` this is the raw `GlazeColorValue`; for `form: 'structured'` this is the structured input. */
|
|
523
|
+
input: GlazeColorValue | GlazeColorInputExport;
|
|
524
|
+
/**
|
|
525
|
+
* Overrides recorded at creation time. `base` is recursively
|
|
526
|
+
* serialized. Only present for `form: 'value'`.
|
|
527
|
+
*/
|
|
528
|
+
overrides?: GlazeColorOverridesExport;
|
|
529
|
+
/** Lightness scaling override, if any. */
|
|
530
|
+
scaling?: GlazeColorScaling;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Serializable shape of a structured `glaze.color({...})` input.
|
|
534
|
+
* Differs from `GlazeColorInput` only in that `base` is replaced by an
|
|
535
|
+
* `export` instead of a token reference.
|
|
536
|
+
*/
|
|
537
|
+
interface GlazeColorInputExport {
|
|
538
|
+
hue: number;
|
|
539
|
+
saturation: number;
|
|
540
|
+
lightness: HCPair<number>;
|
|
541
|
+
saturationFactor?: number;
|
|
542
|
+
mode?: AdaptationMode;
|
|
543
|
+
opacity?: number;
|
|
544
|
+
base?: GlazeColorTokenExport | GlazeColorValue;
|
|
545
|
+
contrast?: HCPair<MinContrast>;
|
|
546
|
+
name?: string;
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Serializable shape of `GlazeColorOverrides`. `base` is replaced by
|
|
550
|
+
* its export (or left as a `GlazeColorValue` if it was originally a value).
|
|
551
|
+
*/
|
|
552
|
+
interface GlazeColorOverridesExport {
|
|
553
|
+
hue?: number | RelativeValue;
|
|
554
|
+
saturation?: number;
|
|
555
|
+
lightness?: HCPair<number | RelativeValue>;
|
|
556
|
+
saturationFactor?: number;
|
|
557
|
+
mode?: AdaptationMode;
|
|
558
|
+
contrast?: HCPair<MinContrast>;
|
|
559
|
+
base?: GlazeColorTokenExport | GlazeColorValue;
|
|
560
|
+
opacity?: number;
|
|
561
|
+
name?: string;
|
|
236
562
|
}
|
|
237
563
|
interface GlazeTheme {
|
|
238
564
|
/** The hue seed (0–360). */
|
|
@@ -272,7 +598,7 @@ interface GlazeTheme {
|
|
|
272
598
|
* Export as tasty style-to-state bindings.
|
|
273
599
|
* Uses `#name` color token keys and state aliases (`''`, `@dark`, etc.).
|
|
274
600
|
* Spread into component styles or register as a recipe via `configure({ recipes })`.
|
|
275
|
-
* @see https://
|
|
601
|
+
* @see https://tasty.style/docs
|
|
276
602
|
*/
|
|
277
603
|
tasty(options?: GlazeTokenOptions): Record<string, Record<string, string>>;
|
|
278
604
|
/** Export as plain JSON. */
|
|
@@ -317,33 +643,64 @@ interface GlazeCssResult {
|
|
|
317
643
|
lightContrast: string;
|
|
318
644
|
darkContrast: string;
|
|
319
645
|
}
|
|
646
|
+
/** Options for `glaze.palette()` creation. */
|
|
647
|
+
interface GlazePaletteOptions {
|
|
648
|
+
/**
|
|
649
|
+
* Name of the primary theme. The primary theme's tokens are duplicated
|
|
650
|
+
* without prefix in all exports, providing convenient short aliases
|
|
651
|
+
* alongside the prefixed versions. Can be overridden per-export.
|
|
652
|
+
*
|
|
653
|
+
* @example
|
|
654
|
+
* ```ts
|
|
655
|
+
* const palette = glaze.palette({ brand, accent }, { primary: 'brand' });
|
|
656
|
+
* palette.tokens()
|
|
657
|
+
* // → { light: { 'brand-surface': '...', 'surface': '...', 'accent-surface': '...' } }
|
|
658
|
+
* ```
|
|
659
|
+
*/
|
|
660
|
+
primary?: string;
|
|
661
|
+
}
|
|
662
|
+
/** Options shared by palette `tokens()`, `tasty()`, and `css()` exports. */
|
|
663
|
+
interface GlazePaletteExportOptions {
|
|
664
|
+
/**
|
|
665
|
+
* Prefix mode. `true` uses `"<themeName>-"`, or provide a custom map.
|
|
666
|
+
* Defaults to `true` for palette export methods.
|
|
667
|
+
* Set to `false` explicitly to disable prefixing. Colliding keys
|
|
668
|
+
* produce a console.warn and the first-written value wins.
|
|
669
|
+
*/
|
|
670
|
+
prefix?: boolean | Record<string, string>;
|
|
671
|
+
/**
|
|
672
|
+
* Override the palette-level primary theme for this export.
|
|
673
|
+
* Pass a theme name to set/change the primary, or `false` to disable it.
|
|
674
|
+
* When omitted, inherits the palette-level `primary`.
|
|
675
|
+
*/
|
|
676
|
+
primary?: string | false;
|
|
677
|
+
}
|
|
320
678
|
interface GlazePalette {
|
|
321
679
|
/**
|
|
322
680
|
* Export all themes as a flat token map grouped by scheme variant.
|
|
681
|
+
* Prefix defaults to `true` — all tokens are prefixed with the theme name.
|
|
682
|
+
* Inherits the palette-level `primary`; override per-call or pass `false` to disable.
|
|
323
683
|
*
|
|
324
684
|
* ```ts
|
|
325
|
-
* palette.
|
|
326
|
-
*
|
|
685
|
+
* const palette = glaze.palette({ brand, accent }, { primary: 'brand' });
|
|
686
|
+
* palette.tokens()
|
|
687
|
+
* // → { light: { 'brand-surface': '...', 'surface': '...', 'accent-surface': '...' } }
|
|
327
688
|
* ```
|
|
328
689
|
*/
|
|
329
|
-
tokens(options?: GlazeJsonOptions &
|
|
330
|
-
prefix?: boolean | Record<string, string>;
|
|
331
|
-
}): Record<string, Record<string, string>>;
|
|
690
|
+
tokens(options?: GlazeJsonOptions & GlazePaletteExportOptions): Record<string, Record<string, string>>;
|
|
332
691
|
/**
|
|
333
692
|
* Export all themes as tasty style-to-state bindings.
|
|
334
693
|
* Uses `#name` color token keys and state aliases (`''`, `@dark`, etc.).
|
|
335
|
-
*
|
|
336
|
-
* @see https://
|
|
694
|
+
* Prefix defaults to `true`. Inherits the palette-level `primary`.
|
|
695
|
+
* @see https://tasty.style/docs
|
|
337
696
|
*/
|
|
338
|
-
tasty(options?: GlazeTokenOptions): Record<string, Record<string, string>>;
|
|
339
|
-
/** Export all themes as plain JSON. */
|
|
697
|
+
tasty(options?: GlazeTokenOptions & GlazePaletteExportOptions): Record<string, Record<string, string>>;
|
|
698
|
+
/** Export all themes as plain JSON grouped by theme name. */
|
|
340
699
|
json(options?: GlazeJsonOptions & {
|
|
341
700
|
prefix?: boolean | Record<string, string>;
|
|
342
701
|
}): Record<string, Record<string, Record<string, string>>>;
|
|
343
702
|
/** Export all themes as CSS custom property declarations. */
|
|
344
|
-
css(options?: GlazeCssOptions &
|
|
345
|
-
prefix?: boolean | Record<string, string>;
|
|
346
|
-
}): GlazeCssResult;
|
|
703
|
+
css(options?: GlazeCssOptions & GlazePaletteExportOptions): GlazeCssResult;
|
|
347
704
|
}
|
|
348
705
|
//#endregion
|
|
349
706
|
//#region src/glaze.d.ts
|
|
@@ -364,24 +721,24 @@ declare function glaze(hueOrOptions: number | {
|
|
|
364
721
|
}, saturation?: number): GlazeTheme;
|
|
365
722
|
declare namespace glaze {
|
|
366
723
|
var configure: (config: GlazeConfig) => void;
|
|
367
|
-
var palette: (themes: PaletteInput) => {
|
|
368
|
-
tokens(options?: GlazeJsonOptions &
|
|
369
|
-
|
|
370
|
-
}): Record<string, Record<string, string>>;
|
|
371
|
-
tasty(options?: GlazeTokenOptions): Record<string, Record<string, string>>;
|
|
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>>;
|
|
372
727
|
json(options?: GlazeJsonOptions & {
|
|
373
728
|
prefix?: boolean | Record<string, string>;
|
|
374
729
|
}): Record<string, Record<string, Record<string, string>>>;
|
|
375
|
-
css(options?: GlazeCssOptions &
|
|
376
|
-
prefix?: boolean | Record<string, string>;
|
|
377
|
-
}): GlazeCssResult;
|
|
730
|
+
css(options?: GlazeCssOptions & GlazePaletteExportOptions): GlazeCssResult;
|
|
378
731
|
};
|
|
379
732
|
var from: (data: GlazeThemeExport) => GlazeTheme;
|
|
380
|
-
var color:
|
|
733
|
+
var color: {
|
|
734
|
+
(input: GlazeColorInput, scaling?: GlazeColorScaling): GlazeColorToken;
|
|
735
|
+
(value: GlazeColorValue, overrides?: GlazeColorOverrides, scaling?: GlazeColorScaling): GlazeColorToken;
|
|
736
|
+
};
|
|
381
737
|
var shadow: (input: GlazeShadowInput) => ResolvedColorVariant;
|
|
382
738
|
var format: (variant: ResolvedColorVariant, colorFormat?: GlazeColorFormat) => string;
|
|
383
739
|
var fromHex: (hex: string) => GlazeTheme;
|
|
384
740
|
var fromRgb: (r: number, g: number, b: number) => GlazeTheme;
|
|
741
|
+
var colorFrom: (data: GlazeColorTokenExport) => GlazeColorToken;
|
|
385
742
|
var getConfig: () => GlazeConfigResolved;
|
|
386
743
|
var resetConfig: () => void;
|
|
387
744
|
}
|
|
@@ -394,6 +751,11 @@ declare namespace glaze {
|
|
|
394
751
|
* computation for WCAG 2 contrast calculations, and multi-format output
|
|
395
752
|
* (okhsl, rgb, hsl, oklch).
|
|
396
753
|
*/
|
|
754
|
+
type Vec3 = [number, number, number];
|
|
755
|
+
/**
|
|
756
|
+
* Convert OKHSL (h: 0–360, s: 0–1, l: 0–1) to OKLab [L, a, b].
|
|
757
|
+
*/
|
|
758
|
+
declare function okhslToOklab(h: number, s: number, l: number): [number, number, number];
|
|
397
759
|
/**
|
|
398
760
|
* Convert OKHSL (h: 0–360, s: 0–1, l: 0–1) to linear sRGB.
|
|
399
761
|
* Channels may exceed [0, 1] near gamut boundaries — caller must clamp if needed.
|
|
@@ -413,26 +775,55 @@ declare function contrastRatioFromLuminance(yA: number, yB: number): number;
|
|
|
413
775
|
*/
|
|
414
776
|
declare function okhslToSrgb(h: number, s: number, l: number): [number, number, number];
|
|
415
777
|
/**
|
|
416
|
-
*
|
|
778
|
+
* Compute WCAG 2 relative luminance from linear sRGB, matching the browser
|
|
779
|
+
* rendering pipeline: gamma-encode, clamp to sRGB gamut [0,1], then linearize.
|
|
780
|
+
* This avoids over/under-estimating luminance for out-of-gamut OKHSL colors.
|
|
417
781
|
*/
|
|
418
|
-
declare function
|
|
782
|
+
declare function gamutClampedLuminance(linearRgb: [number, number, number]): number;
|
|
783
|
+
/**
|
|
784
|
+
* Convert OKLab to OKHSL.
|
|
785
|
+
* Input: [L, a, b] where L: 0–1, a/b: roughly -0.5 to 0.5.
|
|
786
|
+
* Returns [h, s, l] where h: 0–360, s: 0–1, l: 0–1.
|
|
787
|
+
*/
|
|
788
|
+
declare const oklabToOkhsl: (lab: Vec3) => Vec3;
|
|
419
789
|
/**
|
|
420
790
|
* Convert gamma-encoded sRGB (0–1 per channel) to OKHSL.
|
|
421
791
|
* Returns [h, s, l] where h: 0–360, s: 0–1, l: 0–1.
|
|
422
792
|
*/
|
|
423
793
|
declare function srgbToOkhsl(rgb: [number, number, number]): [number, number, number];
|
|
794
|
+
/**
|
|
795
|
+
* Convert CSS HSL (sRGB-based) to gamma-encoded sRGB [r, g, b] in 0–1 range.
|
|
796
|
+
* h: 0–360, s: 0–1, l: 0–1.
|
|
797
|
+
*
|
|
798
|
+
* Note: CSS HSL is not the same as OKHSL — it's HSL in the sRGB color space.
|
|
799
|
+
* Use this when parsing `hsl(...)` strings before passing to `srgbToOkhsl`.
|
|
800
|
+
*/
|
|
801
|
+
declare function hslToSrgb(h: number, s: number, l: number): [number, number, number];
|
|
424
802
|
/**
|
|
425
803
|
* Parse a hex color string (#rgb or #rrggbb) to sRGB [r, g, b] in 0–1 range.
|
|
426
804
|
* Returns null if the string is not a valid hex color.
|
|
805
|
+
*
|
|
806
|
+
* For 8-digit hex (`#rrggbbaa`) and 4-digit hex (`#rgba`) with alpha,
|
|
807
|
+
* use {@link parseHexAlpha}.
|
|
427
808
|
*/
|
|
428
809
|
declare function parseHex(hex: string): [number, number, number] | null;
|
|
810
|
+
/**
|
|
811
|
+
* Parse a hex color string (#rgb, #rrggbb, #rgba, or #rrggbbaa) to
|
|
812
|
+
* sRGB [r, g, b] in 0–1 range plus an optional alpha (0–1).
|
|
813
|
+
* Returns null if the string is not a valid hex color.
|
|
814
|
+
*/
|
|
815
|
+
declare function parseHexAlpha(hex: string): {
|
|
816
|
+
rgb: [number, number, number];
|
|
817
|
+
alpha?: number;
|
|
818
|
+
} | null;
|
|
429
819
|
/**
|
|
430
820
|
* Format OKHSL values as a CSS `okhsl(H S% L%)` string.
|
|
431
821
|
* h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
|
|
432
822
|
*/
|
|
433
823
|
declare function formatOkhsl(h: number, s: number, l: number): string;
|
|
434
824
|
/**
|
|
435
|
-
* Format OKHSL values as a CSS `rgb(R G B)` string
|
|
825
|
+
* Format OKHSL values as a CSS `rgb(R G B)` string.
|
|
826
|
+
* Uses 2 decimal places to avoid 8-bit quantization contrast loss.
|
|
436
827
|
* h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
|
|
437
828
|
*/
|
|
438
829
|
declare function formatRgb(h: number, s: number, l: number): string;
|
|
@@ -447,5 +838,5 @@ declare function formatHsl(h: number, s: number, l: number): string;
|
|
|
447
838
|
*/
|
|
448
839
|
declare function formatOklch(h: number, s: number, l: number): string;
|
|
449
840
|
//#endregion
|
|
450
|
-
export { type AdaptationMode, type ColorDef, type ColorMap, type ContrastPreset, type FindLightnessForContrastOptions, type FindLightnessForContrastResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorToken, type GlazeConfig, type GlazeCssOptions, type GlazeCssResult, type GlazeExtendOptions, type GlazeJsonOptions, type GlazeOutputModes, type GlazePalette, type GlazeShadowInput, type GlazeTheme, type GlazeThemeExport, type GlazeTokenOptions, type HCPair, type HexColor, type MinContrast, type OkhslColor, type RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type ShadowColorDef, type ShadowTuning, contrastRatioFromLuminance, findLightnessForContrast, formatHsl, formatOkhsl, formatOklch, formatRgb, glaze, okhslToLinearSrgb, okhslToOklab, okhslToSrgb, parseHex, relativeLuminanceFromLinearRgb, resolveMinContrast, srgbToOkhsl };
|
|
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 };
|
|
451
842
|
//# sourceMappingURL=index.d.cts.map
|