@tenphi/glaze 0.9.3 → 0.10.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 +307 -10
- package/dist/index.cjs +678 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +266 -7
- package/dist/index.d.mts +266 -7
- package/dist/index.mjs +676 -83
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -294,21 +294,189 @@ interface GlazeThemeExport {
|
|
|
294
294
|
}
|
|
295
295
|
/** Input for `glaze.shadow()` standalone factory. */
|
|
296
296
|
interface GlazeShadowInput {
|
|
297
|
-
/**
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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;
|
|
301
309
|
/** Intensity 0-100. */
|
|
302
310
|
intensity: number;
|
|
303
311
|
tuning?: ShadowTuning;
|
|
304
312
|
}
|
|
305
|
-
/** Input for `glaze.color()`
|
|
313
|
+
/** Input for the structured `glaze.color()` overload. */
|
|
306
314
|
interface GlazeColorInput {
|
|
307
315
|
hue: number;
|
|
308
316
|
saturation: number;
|
|
309
317
|
lightness: HCPair<number>;
|
|
310
318
|
saturationFactor?: number;
|
|
311
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 vary by input form:
|
|
380
|
+
* - String inputs (`'#1a1a1a'`, `'rgb(...)'`, etc.): `'auto'` (Möbius
|
|
381
|
+
* curve — pairs with the extended dark window to invert
|
|
382
|
+
* `#000` ↔ `#fff` between light and dark).
|
|
383
|
+
* - `OkhslColor` and `[r, g, b]` tuple inputs: `'fixed'` (linear,
|
|
384
|
+
* preserves light lightness exactly).
|
|
385
|
+
*
|
|
386
|
+
* Pass `'fixed'` explicitly to opt a string input back into the
|
|
387
|
+
* linear, non-inverting mapping; pass `'static'` to pin the same
|
|
388
|
+
* lightness across every variant.
|
|
389
|
+
*/
|
|
390
|
+
mode?: AdaptationMode;
|
|
391
|
+
/**
|
|
392
|
+
* WCAG contrast floor. By default solved against the literal seed
|
|
393
|
+
* (the value itself); when `base` is set, solved against the base's
|
|
394
|
+
* resolved variant per scheme. Same shape as `RegularColorDef.contrast`.
|
|
395
|
+
*/
|
|
396
|
+
contrast?: HCPair<MinContrast>;
|
|
397
|
+
/**
|
|
398
|
+
* Optional dependency on another color. Accepts either a
|
|
399
|
+
* `GlazeColorToken` (returned by another `glaze.color()`) or a raw
|
|
400
|
+
* `GlazeColorValue` (hex / `rgb()` / `OkhslColor` / `[r, g, b]`),
|
|
401
|
+
* which is automatically wrapped in `glaze.color(value)`.
|
|
402
|
+
*
|
|
403
|
+
* When set:
|
|
404
|
+
* - `contrast` is solved against the base's resolved variant
|
|
405
|
+
* per-scheme (light / dark / lightContrast / darkContrast).
|
|
406
|
+
* - Relative `lightness: '+N'` / `'-N'` is anchored to the base's
|
|
407
|
+
* lightness per-scheme (matches theme behavior for dependent colors).
|
|
408
|
+
* - Relative `hue: '+N'` / `'-N'` still anchors to the seed (the
|
|
409
|
+
* value passed to `glaze.color()`), not the base.
|
|
410
|
+
*
|
|
411
|
+
* The base token's `.resolve()` is called lazily on first resolve and
|
|
412
|
+
* its result is captured by reference; later mutations to the base's
|
|
413
|
+
* defining call don't apply (matches existing token snapshot semantics).
|
|
414
|
+
*/
|
|
415
|
+
base?: GlazeColorToken | GlazeColorValue;
|
|
416
|
+
/**
|
|
417
|
+
* Fixed opacity (0–1). Output includes alpha in the CSS value.
|
|
418
|
+
* Combining with `contrast` is not recommended (perceived lightness
|
|
419
|
+
* becomes unpredictable) — a `console.warn` is emitted in that case.
|
|
420
|
+
*/
|
|
421
|
+
opacity?: number;
|
|
422
|
+
/**
|
|
423
|
+
* Optional human-readable name for the token. Used in error and
|
|
424
|
+
* warning messages (otherwise an internal name like `"value"` is
|
|
425
|
+
* used). Does not affect output keys.
|
|
426
|
+
*/
|
|
427
|
+
name?: string;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Per-call lightness-window overrides for `glaze.color()`. Mirrors
|
|
431
|
+
* the field names from `GlazeConfig`.
|
|
432
|
+
*
|
|
433
|
+
* Defaults for `glaze.color()` vary by input form, and both fields are
|
|
434
|
+
* snapshotted from `globalConfig` at color-creation time so later
|
|
435
|
+
* `glaze.configure()` calls don't retroactively change already-created
|
|
436
|
+
* tokens (and `token.export()` round-trips byte-for-byte):
|
|
437
|
+
*
|
|
438
|
+
* - **String inputs** (`'#1a1a1a'`, `'rgb(...)'`, `'okhsl(...)'`, ...):
|
|
439
|
+
* - `lightLightness: false` — preserve input exactly.
|
|
440
|
+
* - `darkLightness: [globalConfig.darkLightness[0], 100]` — extended
|
|
441
|
+
* dark window so the auto-mode dark variant can Möbius-invert all
|
|
442
|
+
* the way up to white.
|
|
443
|
+
*
|
|
444
|
+
* - **`OkhslColor` / `[r, g, b]` tuple / structured inputs**:
|
|
445
|
+
* - `lightLightness: false` — preserve input exactly.
|
|
446
|
+
* - `darkLightness: globalConfig.darkLightness` — same window
|
|
447
|
+
* theme colors use, snapshotted at create time.
|
|
448
|
+
*
|
|
449
|
+
* Passing this object replaces both fields at once. To keep one
|
|
450
|
+
* field's default while overriding the other, restate the default
|
|
451
|
+
* explicitly.
|
|
452
|
+
*/
|
|
453
|
+
interface GlazeColorScaling {
|
|
454
|
+
/** Light-mode lightness window. `false` (default) preserves input. */
|
|
455
|
+
lightLightness?: false | [number, number];
|
|
456
|
+
/**
|
|
457
|
+
* Dark-mode lightness window. Snapshotted from `globalConfig` at
|
|
458
|
+
* create time: extended `[globalConfig.darkLightness[0], 100]` for
|
|
459
|
+
* string inputs, plain `globalConfig.darkLightness` for object /
|
|
460
|
+
* tuple / structured inputs. Pass `false` to preserve input
|
|
461
|
+
* lightness in dark mode too.
|
|
462
|
+
*/
|
|
463
|
+
darkLightness?: false | [number, number];
|
|
464
|
+
}
|
|
465
|
+
/** Options for `GlazeColorToken.css()`. */
|
|
466
|
+
interface GlazeColorCssOptions {
|
|
467
|
+
/**
|
|
468
|
+
* Custom property base name (without leading `--`). Required.
|
|
469
|
+
* Becomes the variable identifier in the output, e.g.
|
|
470
|
+
* `name: 'brand'` → `--brand-color: …`.
|
|
471
|
+
*/
|
|
472
|
+
name: string;
|
|
473
|
+
/** Output color format. Default: 'rgb' (matches `theme.css` default). */
|
|
474
|
+
format?: GlazeColorFormat;
|
|
475
|
+
/**
|
|
476
|
+
* Suffix appended to the name. Default: '-color' (matches
|
|
477
|
+
* `theme.css` default).
|
|
478
|
+
*/
|
|
479
|
+
suffix?: string;
|
|
312
480
|
}
|
|
313
481
|
/** Return type for `glaze.color()`. */
|
|
314
482
|
interface GlazeColorToken {
|
|
@@ -324,6 +492,66 @@ interface GlazeColorToken {
|
|
|
324
492
|
tasty(options?: GlazeTokenOptions): Record<string, string>;
|
|
325
493
|
/** Export as a flat JSON map (no color name key). */
|
|
326
494
|
json(options?: GlazeJsonOptions): Record<string, string>;
|
|
495
|
+
/** Export as CSS custom property declarations grouped by scheme variant. */
|
|
496
|
+
css(options: GlazeColorCssOptions): GlazeCssResult;
|
|
497
|
+
/**
|
|
498
|
+
* Serialize the token as a JSON-safe object. Captures the original
|
|
499
|
+
* input value, overrides, and scaling so it can be rehydrated via
|
|
500
|
+
* `glaze.colorFrom(...)`. `base` is recursively serialized.
|
|
501
|
+
*/
|
|
502
|
+
export(): GlazeColorTokenExport;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* JSON-safe serialization of a `glaze.color()` token. Pass to
|
|
506
|
+
* `glaze.colorFrom(...)` to rehydrate.
|
|
507
|
+
*/
|
|
508
|
+
interface GlazeColorTokenExport {
|
|
509
|
+
/**
|
|
510
|
+
* Discriminator for the source overload that created the token.
|
|
511
|
+
* - `'value'`: created via `glaze.color(value, overrides?, scaling?)`.
|
|
512
|
+
* - `'structured'`: created via `glaze.color({ hue, saturation, ... }, scaling?)`.
|
|
513
|
+
*/
|
|
514
|
+
form: 'value' | 'structured';
|
|
515
|
+
/** Original input. For `form: 'value'` this is the raw `GlazeColorValue`; for `form: 'structured'` this is the structured input. */
|
|
516
|
+
input: GlazeColorValue | GlazeColorInputExport;
|
|
517
|
+
/**
|
|
518
|
+
* Overrides recorded at creation time. `base` is recursively
|
|
519
|
+
* serialized. Only present for `form: 'value'`.
|
|
520
|
+
*/
|
|
521
|
+
overrides?: GlazeColorOverridesExport;
|
|
522
|
+
/** Lightness scaling override, if any. */
|
|
523
|
+
scaling?: GlazeColorScaling;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Serializable shape of a structured `glaze.color({...})` input.
|
|
527
|
+
* Differs from `GlazeColorInput` only in that `base` is replaced by an
|
|
528
|
+
* `export` instead of a token reference.
|
|
529
|
+
*/
|
|
530
|
+
interface GlazeColorInputExport {
|
|
531
|
+
hue: number;
|
|
532
|
+
saturation: number;
|
|
533
|
+
lightness: HCPair<number>;
|
|
534
|
+
saturationFactor?: number;
|
|
535
|
+
mode?: AdaptationMode;
|
|
536
|
+
opacity?: number;
|
|
537
|
+
base?: GlazeColorTokenExport | GlazeColorValue;
|
|
538
|
+
contrast?: HCPair<MinContrast>;
|
|
539
|
+
name?: string;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Serializable shape of `GlazeColorOverrides`. `base` is replaced by
|
|
543
|
+
* its export (or left as a `GlazeColorValue` if it was originally a value).
|
|
544
|
+
*/
|
|
545
|
+
interface GlazeColorOverridesExport {
|
|
546
|
+
hue?: number | RelativeValue;
|
|
547
|
+
saturation?: number;
|
|
548
|
+
lightness?: HCPair<number | RelativeValue>;
|
|
549
|
+
saturationFactor?: number;
|
|
550
|
+
mode?: AdaptationMode;
|
|
551
|
+
contrast?: HCPair<MinContrast>;
|
|
552
|
+
base?: GlazeColorTokenExport | GlazeColorValue;
|
|
553
|
+
opacity?: number;
|
|
554
|
+
name?: string;
|
|
327
555
|
}
|
|
328
556
|
interface GlazeTheme {
|
|
329
557
|
/** The hue seed (0–360). */
|
|
@@ -495,11 +723,15 @@ declare namespace glaze {
|
|
|
495
723
|
css(options?: GlazeCssOptions & GlazePaletteExportOptions): GlazeCssResult;
|
|
496
724
|
};
|
|
497
725
|
var from: (data: GlazeThemeExport) => GlazeTheme;
|
|
498
|
-
var color:
|
|
726
|
+
var color: {
|
|
727
|
+
(input: GlazeColorInput, scaling?: GlazeColorScaling): GlazeColorToken;
|
|
728
|
+
(value: GlazeColorValue, overrides?: GlazeColorOverrides, scaling?: GlazeColorScaling): GlazeColorToken;
|
|
729
|
+
};
|
|
499
730
|
var shadow: (input: GlazeShadowInput) => ResolvedColorVariant;
|
|
500
731
|
var format: (variant: ResolvedColorVariant, colorFormat?: GlazeColorFormat) => string;
|
|
501
732
|
var fromHex: (hex: string) => GlazeTheme;
|
|
502
733
|
var fromRgb: (r: number, g: number, b: number) => GlazeTheme;
|
|
734
|
+
var colorFrom: (data: GlazeColorTokenExport) => GlazeColorToken;
|
|
503
735
|
var getConfig: () => GlazeConfigResolved;
|
|
504
736
|
var resetConfig: () => void;
|
|
505
737
|
}
|
|
@@ -512,6 +744,7 @@ declare namespace glaze {
|
|
|
512
744
|
* computation for WCAG 2 contrast calculations, and multi-format output
|
|
513
745
|
* (okhsl, rgb, hsl, oklch).
|
|
514
746
|
*/
|
|
747
|
+
type Vec3 = [number, number, number];
|
|
515
748
|
/**
|
|
516
749
|
* Convert OKHSL (h: 0–360, s: 0–1, l: 0–1) to OKLab [L, a, b].
|
|
517
750
|
*/
|
|
@@ -540,16 +773,42 @@ declare function okhslToSrgb(h: number, s: number, l: number): [number, number,
|
|
|
540
773
|
* This avoids over/under-estimating luminance for out-of-gamut OKHSL colors.
|
|
541
774
|
*/
|
|
542
775
|
declare function gamutClampedLuminance(linearRgb: [number, number, number]): number;
|
|
776
|
+
/**
|
|
777
|
+
* Convert OKLab to OKHSL.
|
|
778
|
+
* Input: [L, a, b] where L: 0–1, a/b: roughly -0.5 to 0.5.
|
|
779
|
+
* Returns [h, s, l] where h: 0–360, s: 0–1, l: 0–1.
|
|
780
|
+
*/
|
|
781
|
+
declare const oklabToOkhsl: (lab: Vec3) => Vec3;
|
|
543
782
|
/**
|
|
544
783
|
* Convert gamma-encoded sRGB (0–1 per channel) to OKHSL.
|
|
545
784
|
* Returns [h, s, l] where h: 0–360, s: 0–1, l: 0–1.
|
|
546
785
|
*/
|
|
547
786
|
declare function srgbToOkhsl(rgb: [number, number, number]): [number, number, number];
|
|
787
|
+
/**
|
|
788
|
+
* Convert CSS HSL (sRGB-based) to gamma-encoded sRGB [r, g, b] in 0–1 range.
|
|
789
|
+
* h: 0–360, s: 0–1, l: 0–1.
|
|
790
|
+
*
|
|
791
|
+
* Note: CSS HSL is not the same as OKHSL — it's HSL in the sRGB color space.
|
|
792
|
+
* Use this when parsing `hsl(...)` strings before passing to `srgbToOkhsl`.
|
|
793
|
+
*/
|
|
794
|
+
declare function hslToSrgb(h: number, s: number, l: number): [number, number, number];
|
|
548
795
|
/**
|
|
549
796
|
* Parse a hex color string (#rgb or #rrggbb) to sRGB [r, g, b] in 0–1 range.
|
|
550
797
|
* Returns null if the string is not a valid hex color.
|
|
798
|
+
*
|
|
799
|
+
* For 8-digit hex (`#rrggbbaa`) and 4-digit hex (`#rgba`) with alpha,
|
|
800
|
+
* use {@link parseHexAlpha}.
|
|
551
801
|
*/
|
|
552
802
|
declare function parseHex(hex: string): [number, number, number] | null;
|
|
803
|
+
/**
|
|
804
|
+
* Parse a hex color string (#rgb, #rrggbb, #rgba, or #rrggbbaa) to
|
|
805
|
+
* sRGB [r, g, b] in 0–1 range plus an optional alpha (0–1).
|
|
806
|
+
* Returns null if the string is not a valid hex color.
|
|
807
|
+
*/
|
|
808
|
+
declare function parseHexAlpha(hex: string): {
|
|
809
|
+
rgb: [number, number, number];
|
|
810
|
+
alpha?: number;
|
|
811
|
+
} | null;
|
|
553
812
|
/**
|
|
554
813
|
* Format OKHSL values as a CSS `okhsl(H S% L%)` string.
|
|
555
814
|
* h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
|
|
@@ -572,5 +831,5 @@ declare function formatHsl(h: number, s: number, l: number): string;
|
|
|
572
831
|
*/
|
|
573
832
|
declare function formatOklch(h: number, s: number, l: number): string;
|
|
574
833
|
//#endregion
|
|
575
|
-
export { type AdaptationMode, type ColorDef, type ColorMap, type ContrastPreset, type FindLightnessForContrastOptions, type FindLightnessForContrastResult, type FindValueForMixContrastOptions, type FindValueForMixContrastResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorToken, 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, okhslToLinearSrgb, okhslToOklab, okhslToSrgb, parseHex, relativeLuminanceFromLinearRgb, resolveMinContrast, srgbToOkhsl };
|
|
834
|
+
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 };
|
|
576
835
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -294,21 +294,189 @@ interface GlazeThemeExport {
|
|
|
294
294
|
}
|
|
295
295
|
/** Input for `glaze.shadow()` standalone factory. */
|
|
296
296
|
interface GlazeShadowInput {
|
|
297
|
-
/**
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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;
|
|
301
309
|
/** Intensity 0-100. */
|
|
302
310
|
intensity: number;
|
|
303
311
|
tuning?: ShadowTuning;
|
|
304
312
|
}
|
|
305
|
-
/** Input for `glaze.color()`
|
|
313
|
+
/** Input for the structured `glaze.color()` overload. */
|
|
306
314
|
interface GlazeColorInput {
|
|
307
315
|
hue: number;
|
|
308
316
|
saturation: number;
|
|
309
317
|
lightness: HCPair<number>;
|
|
310
318
|
saturationFactor?: number;
|
|
311
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 vary by input form:
|
|
380
|
+
* - String inputs (`'#1a1a1a'`, `'rgb(...)'`, etc.): `'auto'` (Möbius
|
|
381
|
+
* curve — pairs with the extended dark window to invert
|
|
382
|
+
* `#000` ↔ `#fff` between light and dark).
|
|
383
|
+
* - `OkhslColor` and `[r, g, b]` tuple inputs: `'fixed'` (linear,
|
|
384
|
+
* preserves light lightness exactly).
|
|
385
|
+
*
|
|
386
|
+
* Pass `'fixed'` explicitly to opt a string input back into the
|
|
387
|
+
* linear, non-inverting mapping; pass `'static'` to pin the same
|
|
388
|
+
* lightness across every variant.
|
|
389
|
+
*/
|
|
390
|
+
mode?: AdaptationMode;
|
|
391
|
+
/**
|
|
392
|
+
* WCAG contrast floor. By default solved against the literal seed
|
|
393
|
+
* (the value itself); when `base` is set, solved against the base's
|
|
394
|
+
* resolved variant per scheme. Same shape as `RegularColorDef.contrast`.
|
|
395
|
+
*/
|
|
396
|
+
contrast?: HCPair<MinContrast>;
|
|
397
|
+
/**
|
|
398
|
+
* Optional dependency on another color. Accepts either a
|
|
399
|
+
* `GlazeColorToken` (returned by another `glaze.color()`) or a raw
|
|
400
|
+
* `GlazeColorValue` (hex / `rgb()` / `OkhslColor` / `[r, g, b]`),
|
|
401
|
+
* which is automatically wrapped in `glaze.color(value)`.
|
|
402
|
+
*
|
|
403
|
+
* When set:
|
|
404
|
+
* - `contrast` is solved against the base's resolved variant
|
|
405
|
+
* per-scheme (light / dark / lightContrast / darkContrast).
|
|
406
|
+
* - Relative `lightness: '+N'` / `'-N'` is anchored to the base's
|
|
407
|
+
* lightness per-scheme (matches theme behavior for dependent colors).
|
|
408
|
+
* - Relative `hue: '+N'` / `'-N'` still anchors to the seed (the
|
|
409
|
+
* value passed to `glaze.color()`), not the base.
|
|
410
|
+
*
|
|
411
|
+
* The base token's `.resolve()` is called lazily on first resolve and
|
|
412
|
+
* its result is captured by reference; later mutations to the base's
|
|
413
|
+
* defining call don't apply (matches existing token snapshot semantics).
|
|
414
|
+
*/
|
|
415
|
+
base?: GlazeColorToken | GlazeColorValue;
|
|
416
|
+
/**
|
|
417
|
+
* Fixed opacity (0–1). Output includes alpha in the CSS value.
|
|
418
|
+
* Combining with `contrast` is not recommended (perceived lightness
|
|
419
|
+
* becomes unpredictable) — a `console.warn` is emitted in that case.
|
|
420
|
+
*/
|
|
421
|
+
opacity?: number;
|
|
422
|
+
/**
|
|
423
|
+
* Optional human-readable name for the token. Used in error and
|
|
424
|
+
* warning messages (otherwise an internal name like `"value"` is
|
|
425
|
+
* used). Does not affect output keys.
|
|
426
|
+
*/
|
|
427
|
+
name?: string;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Per-call lightness-window overrides for `glaze.color()`. Mirrors
|
|
431
|
+
* the field names from `GlazeConfig`.
|
|
432
|
+
*
|
|
433
|
+
* Defaults for `glaze.color()` vary by input form, and both fields are
|
|
434
|
+
* snapshotted from `globalConfig` at color-creation time so later
|
|
435
|
+
* `glaze.configure()` calls don't retroactively change already-created
|
|
436
|
+
* tokens (and `token.export()` round-trips byte-for-byte):
|
|
437
|
+
*
|
|
438
|
+
* - **String inputs** (`'#1a1a1a'`, `'rgb(...)'`, `'okhsl(...)'`, ...):
|
|
439
|
+
* - `lightLightness: false` — preserve input exactly.
|
|
440
|
+
* - `darkLightness: [globalConfig.darkLightness[0], 100]` — extended
|
|
441
|
+
* dark window so the auto-mode dark variant can Möbius-invert all
|
|
442
|
+
* the way up to white.
|
|
443
|
+
*
|
|
444
|
+
* - **`OkhslColor` / `[r, g, b]` tuple / structured inputs**:
|
|
445
|
+
* - `lightLightness: false` — preserve input exactly.
|
|
446
|
+
* - `darkLightness: globalConfig.darkLightness` — same window
|
|
447
|
+
* theme colors use, snapshotted at create time.
|
|
448
|
+
*
|
|
449
|
+
* Passing this object replaces both fields at once. To keep one
|
|
450
|
+
* field's default while overriding the other, restate the default
|
|
451
|
+
* explicitly.
|
|
452
|
+
*/
|
|
453
|
+
interface GlazeColorScaling {
|
|
454
|
+
/** Light-mode lightness window. `false` (default) preserves input. */
|
|
455
|
+
lightLightness?: false | [number, number];
|
|
456
|
+
/**
|
|
457
|
+
* Dark-mode lightness window. Snapshotted from `globalConfig` at
|
|
458
|
+
* create time: extended `[globalConfig.darkLightness[0], 100]` for
|
|
459
|
+
* string inputs, plain `globalConfig.darkLightness` for object /
|
|
460
|
+
* tuple / structured inputs. Pass `false` to preserve input
|
|
461
|
+
* lightness in dark mode too.
|
|
462
|
+
*/
|
|
463
|
+
darkLightness?: false | [number, number];
|
|
464
|
+
}
|
|
465
|
+
/** Options for `GlazeColorToken.css()`. */
|
|
466
|
+
interface GlazeColorCssOptions {
|
|
467
|
+
/**
|
|
468
|
+
* Custom property base name (without leading `--`). Required.
|
|
469
|
+
* Becomes the variable identifier in the output, e.g.
|
|
470
|
+
* `name: 'brand'` → `--brand-color: …`.
|
|
471
|
+
*/
|
|
472
|
+
name: string;
|
|
473
|
+
/** Output color format. Default: 'rgb' (matches `theme.css` default). */
|
|
474
|
+
format?: GlazeColorFormat;
|
|
475
|
+
/**
|
|
476
|
+
* Suffix appended to the name. Default: '-color' (matches
|
|
477
|
+
* `theme.css` default).
|
|
478
|
+
*/
|
|
479
|
+
suffix?: string;
|
|
312
480
|
}
|
|
313
481
|
/** Return type for `glaze.color()`. */
|
|
314
482
|
interface GlazeColorToken {
|
|
@@ -324,6 +492,66 @@ interface GlazeColorToken {
|
|
|
324
492
|
tasty(options?: GlazeTokenOptions): Record<string, string>;
|
|
325
493
|
/** Export as a flat JSON map (no color name key). */
|
|
326
494
|
json(options?: GlazeJsonOptions): Record<string, string>;
|
|
495
|
+
/** Export as CSS custom property declarations grouped by scheme variant. */
|
|
496
|
+
css(options: GlazeColorCssOptions): GlazeCssResult;
|
|
497
|
+
/**
|
|
498
|
+
* Serialize the token as a JSON-safe object. Captures the original
|
|
499
|
+
* input value, overrides, and scaling so it can be rehydrated via
|
|
500
|
+
* `glaze.colorFrom(...)`. `base` is recursively serialized.
|
|
501
|
+
*/
|
|
502
|
+
export(): GlazeColorTokenExport;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* JSON-safe serialization of a `glaze.color()` token. Pass to
|
|
506
|
+
* `glaze.colorFrom(...)` to rehydrate.
|
|
507
|
+
*/
|
|
508
|
+
interface GlazeColorTokenExport {
|
|
509
|
+
/**
|
|
510
|
+
* Discriminator for the source overload that created the token.
|
|
511
|
+
* - `'value'`: created via `glaze.color(value, overrides?, scaling?)`.
|
|
512
|
+
* - `'structured'`: created via `glaze.color({ hue, saturation, ... }, scaling?)`.
|
|
513
|
+
*/
|
|
514
|
+
form: 'value' | 'structured';
|
|
515
|
+
/** Original input. For `form: 'value'` this is the raw `GlazeColorValue`; for `form: 'structured'` this is the structured input. */
|
|
516
|
+
input: GlazeColorValue | GlazeColorInputExport;
|
|
517
|
+
/**
|
|
518
|
+
* Overrides recorded at creation time. `base` is recursively
|
|
519
|
+
* serialized. Only present for `form: 'value'`.
|
|
520
|
+
*/
|
|
521
|
+
overrides?: GlazeColorOverridesExport;
|
|
522
|
+
/** Lightness scaling override, if any. */
|
|
523
|
+
scaling?: GlazeColorScaling;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Serializable shape of a structured `glaze.color({...})` input.
|
|
527
|
+
* Differs from `GlazeColorInput` only in that `base` is replaced by an
|
|
528
|
+
* `export` instead of a token reference.
|
|
529
|
+
*/
|
|
530
|
+
interface GlazeColorInputExport {
|
|
531
|
+
hue: number;
|
|
532
|
+
saturation: number;
|
|
533
|
+
lightness: HCPair<number>;
|
|
534
|
+
saturationFactor?: number;
|
|
535
|
+
mode?: AdaptationMode;
|
|
536
|
+
opacity?: number;
|
|
537
|
+
base?: GlazeColorTokenExport | GlazeColorValue;
|
|
538
|
+
contrast?: HCPair<MinContrast>;
|
|
539
|
+
name?: string;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Serializable shape of `GlazeColorOverrides`. `base` is replaced by
|
|
543
|
+
* its export (or left as a `GlazeColorValue` if it was originally a value).
|
|
544
|
+
*/
|
|
545
|
+
interface GlazeColorOverridesExport {
|
|
546
|
+
hue?: number | RelativeValue;
|
|
547
|
+
saturation?: number;
|
|
548
|
+
lightness?: HCPair<number | RelativeValue>;
|
|
549
|
+
saturationFactor?: number;
|
|
550
|
+
mode?: AdaptationMode;
|
|
551
|
+
contrast?: HCPair<MinContrast>;
|
|
552
|
+
base?: GlazeColorTokenExport | GlazeColorValue;
|
|
553
|
+
opacity?: number;
|
|
554
|
+
name?: string;
|
|
327
555
|
}
|
|
328
556
|
interface GlazeTheme {
|
|
329
557
|
/** The hue seed (0–360). */
|
|
@@ -495,11 +723,15 @@ declare namespace glaze {
|
|
|
495
723
|
css(options?: GlazeCssOptions & GlazePaletteExportOptions): GlazeCssResult;
|
|
496
724
|
};
|
|
497
725
|
var from: (data: GlazeThemeExport) => GlazeTheme;
|
|
498
|
-
var color:
|
|
726
|
+
var color: {
|
|
727
|
+
(input: GlazeColorInput, scaling?: GlazeColorScaling): GlazeColorToken;
|
|
728
|
+
(value: GlazeColorValue, overrides?: GlazeColorOverrides, scaling?: GlazeColorScaling): GlazeColorToken;
|
|
729
|
+
};
|
|
499
730
|
var shadow: (input: GlazeShadowInput) => ResolvedColorVariant;
|
|
500
731
|
var format: (variant: ResolvedColorVariant, colorFormat?: GlazeColorFormat) => string;
|
|
501
732
|
var fromHex: (hex: string) => GlazeTheme;
|
|
502
733
|
var fromRgb: (r: number, g: number, b: number) => GlazeTheme;
|
|
734
|
+
var colorFrom: (data: GlazeColorTokenExport) => GlazeColorToken;
|
|
503
735
|
var getConfig: () => GlazeConfigResolved;
|
|
504
736
|
var resetConfig: () => void;
|
|
505
737
|
}
|
|
@@ -512,6 +744,7 @@ declare namespace glaze {
|
|
|
512
744
|
* computation for WCAG 2 contrast calculations, and multi-format output
|
|
513
745
|
* (okhsl, rgb, hsl, oklch).
|
|
514
746
|
*/
|
|
747
|
+
type Vec3 = [number, number, number];
|
|
515
748
|
/**
|
|
516
749
|
* Convert OKHSL (h: 0–360, s: 0–1, l: 0–1) to OKLab [L, a, b].
|
|
517
750
|
*/
|
|
@@ -540,16 +773,42 @@ declare function okhslToSrgb(h: number, s: number, l: number): [number, number,
|
|
|
540
773
|
* This avoids over/under-estimating luminance for out-of-gamut OKHSL colors.
|
|
541
774
|
*/
|
|
542
775
|
declare function gamutClampedLuminance(linearRgb: [number, number, number]): number;
|
|
776
|
+
/**
|
|
777
|
+
* Convert OKLab to OKHSL.
|
|
778
|
+
* Input: [L, a, b] where L: 0–1, a/b: roughly -0.5 to 0.5.
|
|
779
|
+
* Returns [h, s, l] where h: 0–360, s: 0–1, l: 0–1.
|
|
780
|
+
*/
|
|
781
|
+
declare const oklabToOkhsl: (lab: Vec3) => Vec3;
|
|
543
782
|
/**
|
|
544
783
|
* Convert gamma-encoded sRGB (0–1 per channel) to OKHSL.
|
|
545
784
|
* Returns [h, s, l] where h: 0–360, s: 0–1, l: 0–1.
|
|
546
785
|
*/
|
|
547
786
|
declare function srgbToOkhsl(rgb: [number, number, number]): [number, number, number];
|
|
787
|
+
/**
|
|
788
|
+
* Convert CSS HSL (sRGB-based) to gamma-encoded sRGB [r, g, b] in 0–1 range.
|
|
789
|
+
* h: 0–360, s: 0–1, l: 0–1.
|
|
790
|
+
*
|
|
791
|
+
* Note: CSS HSL is not the same as OKHSL — it's HSL in the sRGB color space.
|
|
792
|
+
* Use this when parsing `hsl(...)` strings before passing to `srgbToOkhsl`.
|
|
793
|
+
*/
|
|
794
|
+
declare function hslToSrgb(h: number, s: number, l: number): [number, number, number];
|
|
548
795
|
/**
|
|
549
796
|
* Parse a hex color string (#rgb or #rrggbb) to sRGB [r, g, b] in 0–1 range.
|
|
550
797
|
* Returns null if the string is not a valid hex color.
|
|
798
|
+
*
|
|
799
|
+
* For 8-digit hex (`#rrggbbaa`) and 4-digit hex (`#rgba`) with alpha,
|
|
800
|
+
* use {@link parseHexAlpha}.
|
|
551
801
|
*/
|
|
552
802
|
declare function parseHex(hex: string): [number, number, number] | null;
|
|
803
|
+
/**
|
|
804
|
+
* Parse a hex color string (#rgb, #rrggbb, #rgba, or #rrggbbaa) to
|
|
805
|
+
* sRGB [r, g, b] in 0–1 range plus an optional alpha (0–1).
|
|
806
|
+
* Returns null if the string is not a valid hex color.
|
|
807
|
+
*/
|
|
808
|
+
declare function parseHexAlpha(hex: string): {
|
|
809
|
+
rgb: [number, number, number];
|
|
810
|
+
alpha?: number;
|
|
811
|
+
} | null;
|
|
553
812
|
/**
|
|
554
813
|
* Format OKHSL values as a CSS `okhsl(H S% L%)` string.
|
|
555
814
|
* h: 0–360, s: 0–100, l: 0–100 (percentage scale for s and l).
|
|
@@ -572,5 +831,5 @@ declare function formatHsl(h: number, s: number, l: number): string;
|
|
|
572
831
|
*/
|
|
573
832
|
declare function formatOklch(h: number, s: number, l: number): string;
|
|
574
833
|
//#endregion
|
|
575
|
-
export { type AdaptationMode, type ColorDef, type ColorMap, type ContrastPreset, type FindLightnessForContrastOptions, type FindLightnessForContrastResult, type FindValueForMixContrastOptions, type FindValueForMixContrastResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorToken, 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, okhslToLinearSrgb, okhslToOklab, okhslToSrgb, parseHex, relativeLuminanceFromLinearRgb, resolveMinContrast, srgbToOkhsl };
|
|
834
|
+
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 };
|
|
576
835
|
//# sourceMappingURL=index.d.mts.map
|