@tenphi/glaze 0.19.0 → 1.1.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/dist/index.d.cts CHANGED
@@ -280,8 +280,8 @@ interface RegularColorDef {
280
280
  /**
281
281
  * Per-color override for the hue-independent "safe" chroma limit used in
282
282
  * OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
283
- * Falls through to the global / per-theme `pastel` config when omitted.
284
- * @see GlazeConfig.pastel
283
+ * Falls through to the per-theme / per-token `pastel` override when omitted.
284
+ * @see GlazeConfigOverride.pastel
285
285
  */
286
286
  pastel?: boolean;
287
287
  /**
@@ -346,8 +346,8 @@ interface ShadowColorDef {
346
346
  /**
347
347
  * Per-color override for the hue-independent "safe" chroma limit used in
348
348
  * OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
349
- * Falls through to the global / per-theme `pastel` config when omitted.
350
- * @see GlazeConfig.pastel
349
+ * Falls through to the per-theme / per-token `pastel` override when omitted.
350
+ * @see GlazeConfigOverride.pastel
351
351
  */
352
352
  pastel?: boolean;
353
353
  /**
@@ -393,8 +393,8 @@ interface MixColorDef {
393
393
  /**
394
394
  * Per-color override for the hue-independent "safe" chroma limit used in
395
395
  * OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
396
- * Falls through to the global / per-theme `pastel` config when omitted.
397
- * @see GlazeConfig.pastel
396
+ * Falls through to the per-theme / per-token `pastel` override when omitted.
397
+ * @see GlazeConfigOverride.pastel
398
398
  */
399
399
  pastel?: boolean;
400
400
  /**
@@ -493,13 +493,6 @@ interface GlazeConfig {
493
493
  * falls back to the originally requested tone).
494
494
  */
495
495
  autoFlip?: boolean;
496
- /**
497
- * If true, uses a hue-independent "safe" chroma limit across all colors
498
- * so that scaling saturation never exceeds the sRGB boundary at any hue
499
- * for the given lightness.
500
- * @default false
501
- */
502
- pastel?: boolean;
503
496
  /**
504
497
  * If true (default), infer a color's `role` from its name when no explicit
505
498
  * `role` is set. Set to `false` to opt out of name-based inference (the
@@ -519,13 +512,19 @@ interface GlazeConfigResolved {
519
512
  modes: Required<GlazeOutputModes>;
520
513
  shadowTuning?: ShadowTuning;
521
514
  autoFlip: boolean;
515
+ /**
516
+ * Instance-level pastel default (`def.pastel ?? config.pastel`).
517
+ * Not set via `glaze.configure()` — only via per-theme / per-token
518
+ * `GlazeConfigOverride` (default `false`).
519
+ */
522
520
  pastel: boolean;
523
521
  inferRole: boolean;
524
522
  }
525
523
  /**
526
524
  * Per-instance config override for `glaze.color()` and `glaze()` themes.
527
525
  * Fields that are set take priority over the live global config. Fields
528
- * that are omitted fall through to the live global at resolve time.
526
+ * that are omitted fall through to the live global at resolve time
527
+ * (`pastel` is instance-only and defaults to `false` when omitted).
529
528
  *
530
529
  * `false` for a tone window disables clamping (full range at reference eps).
531
530
  */
@@ -539,9 +538,9 @@ interface GlazeConfigOverride {
539
538
  /** Whether to auto-flip tone when contrast can't be met. */
540
539
  autoFlip?: boolean;
541
540
  /**
542
- * If true, uses a hue-independent "safe" chroma limit across all colors
543
- * so that scaling saturation never exceeds the sRGB boundary at any hue
544
- * for the given lightness.
541
+ * Instance-level pastel default for colors that omit per-color `pastel`.
542
+ * Not available on `glaze.configure()` set here or per-color.
543
+ * @default false
545
544
  */
546
545
  pastel?: boolean;
547
546
  /**
@@ -555,12 +554,29 @@ interface GlazeConfigOverride {
555
554
  */
556
555
  shadowTuning?: ShadowTuning;
557
556
  }
557
+ /**
558
+ * Current authoring-export schema version. Bump when the export shape
559
+ * changes in a non-compatible way. Written on every `.export()` snapshot.
560
+ */
561
+ declare const GLAZE_EXPORT_VERSION: 1;
562
+ /** Literal type of {@link GLAZE_EXPORT_VERSION}. */
563
+ type GlazeExportVersion = typeof GLAZE_EXPORT_VERSION;
564
+ /** Discriminator for authoring export snapshots. */
565
+ type GlazeExportKind = 'theme' | 'color' | 'palette';
558
566
  /** Serialized theme configuration (no resolved values). */
559
567
  interface GlazeThemeExport {
568
+ /** Snapshot kind. Always written by `theme.export()`; optional on legacy hand-written configs. */
569
+ kind?: 'theme';
570
+ /** Schema version. Always written by `theme.export()`; optional on legacy configs. */
571
+ version?: number;
560
572
  hue: number;
561
573
  saturation: number;
562
574
  colors: ColorMap;
563
- /** Per-theme config override, if any. */
575
+ /**
576
+ * Effective config freeze from `.export()` —
577
+ * `getConfig() ∪ instance local ∪ exportArg`. May be sparse on legacy
578
+ * snapshots (omitted fields fall through to the live global at restore).
579
+ */
564
580
  config?: GlazeConfigOverride;
565
581
  }
566
582
  /** Input for `glaze.shadow()` standalone factory. */
@@ -616,8 +632,8 @@ interface GlazeColorInput {
616
632
  /**
617
633
  * Per-color override for the hue-independent "safe" chroma limit used in
618
634
  * OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
619
- * Falls through to the global / per-theme `pastel` config when omitted.
620
- * @see GlazeConfig.pastel
635
+ * Falls through to the per-theme / per-token `pastel` override when omitted.
636
+ * @see GlazeConfigOverride.pastel
621
637
  */
622
638
  pastel?: boolean;
623
639
  /**
@@ -668,11 +684,11 @@ interface GlazeColorOverrides {
668
684
  /**
669
685
  * Adaptation mode. Defaults to `'auto'` for every input form, so
670
686
  * colors automatically adapt between light and dark like an ordinary
671
- * theme color. All value-shorthand inputs (strings and literal objects)
672
- * preserve light tone (`lightTone: false`) and snapshot
673
- * `globalConfig.darkTone` on the dark side. Only the structured
674
- * `{ hue, saturation, tone }` form also snapshots
675
- * `globalConfig.lightTone`.
687
+ * theme color. Value-shorthand inputs (strings and literal objects)
688
+ * preserve light tone via a local `lightTone: false` default; other
689
+ * omitted config fields fall through to the live global at resolve
690
+ * time. Structured `{ hue, saturation, tone }` form also falls
691
+ * through for both tone windows unless overridden.
676
692
  *
677
693
  * Pass `'fixed'` explicitly to opt back into the linear, non-
678
694
  * inverting mapping; pass `'static'` to pin the same tone
@@ -731,8 +747,8 @@ interface GlazeColorOverrides {
731
747
  /**
732
748
  * Per-color override for the hue-independent "safe" chroma limit used in
733
749
  * OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
734
- * Falls through to the global / per-theme `pastel` config when omitted.
735
- * @see GlazeConfig.pastel
750
+ * Falls through to the per-theme / per-token `pastel` override when omitted.
751
+ * @see GlazeConfigOverride.pastel
736
752
  */
737
753
  pastel?: boolean;
738
754
  /**
@@ -815,14 +831,19 @@ interface GlazeColorToken {
815
831
  * Serialize the token as a JSON-safe object. Captures the original
816
832
  * input value, overrides, and config so it can be rehydrated via
817
833
  * `glaze.colorFrom(...)`. `base` is recursively serialized.
834
+ * Optional `override` is merged over the instance local at export time.
818
835
  */
819
- export(): GlazeColorTokenExport;
836
+ export(override?: GlazeConfigOverride): GlazeColorTokenExport;
820
837
  }
821
838
  /**
822
839
  * JSON-safe serialization of a `glaze.color()` token. Pass to
823
840
  * `glaze.colorFrom(...)` to rehydrate.
824
841
  */
825
842
  interface GlazeColorTokenExport {
843
+ /** Snapshot kind. Always written by `token.export()`; optional on legacy snapshots. */
844
+ kind?: 'color';
845
+ /** Schema version. Always written by `token.export()`; optional on legacy snapshots. */
846
+ version?: number;
826
847
  /**
827
848
  * Discriminator for the source overload that created the token.
828
849
  * - `'value'`: created via `glaze.color(value)` or `glaze.color({ from, ...overrides })`.
@@ -837,14 +858,26 @@ interface GlazeColorTokenExport {
837
858
  */
838
859
  overrides?: GlazeColorOverridesExport;
839
860
  /**
840
- * Effective config snapshot at creation time captures the merged
841
- * result of the global config + any per-call override at the moment
842
- * the token was created. Only fields that differ from their
843
- * post-merge defaults are present. Used by `glaze.colorFrom()` to
844
- * reproduce deterministic behavior across `configure()` calls.
861
+ * Effective config freeze from `.export()``getConfig() local ∪
862
+ * exportArg` at call time. Used by `glaze.colorFrom()` to pin
863
+ * deterministic behavior across later `configure()` calls.
845
864
  */
846
865
  config?: GlazeConfigOverride;
847
866
  }
867
+ /**
868
+ * JSON-safe serialization of a `glaze.palette()` composition.
869
+ * Pass to `glaze.paletteFrom(...)` to rehydrate.
870
+ */
871
+ interface GlazePaletteExport {
872
+ /** Snapshot kind. Always written by `palette.export()`. */
873
+ kind?: 'palette';
874
+ /** Schema version. Always written by `palette.export()`. */
875
+ version?: number;
876
+ /** Per-theme authoring snapshots keyed by theme name. */
877
+ themes: Record<string, GlazeThemeExport>;
878
+ /** Primary theme name, if set on the palette. */
879
+ primary?: string;
880
+ }
848
881
  /**
849
882
  * Serializable shape of a structured `glaze.color({...})` input.
850
883
  * Differs from `GlazeColorInput` only in that `base` is replaced by an
@@ -904,7 +937,7 @@ interface GlazeTheme {
904
937
  /** Clear all color definitions. */
905
938
  reset(): void;
906
939
  /** Export the theme configuration as a JSON-safe object. */
907
- export(): GlazeThemeExport;
940
+ export(override?: GlazeConfigOverride): GlazeThemeExport;
908
941
  /** Create a child theme inheriting all color definitions. */
909
942
  extend(options: GlazeExtendOptions): GlazeTheme;
910
943
  /** Resolve all colors and return the result map. */
@@ -1224,6 +1257,24 @@ interface GlazePaletteExportOptions {
1224
1257
  splitHue?: boolean;
1225
1258
  }
1226
1259
  interface GlazePalette {
1260
+ /** Theme names in insertion order. */
1261
+ list(): string[];
1262
+ /** Primary theme name, if set at palette creation. */
1263
+ readonly primary: string | undefined;
1264
+ /** Get a theme by name. Returns the live instance held by the palette. */
1265
+ theme(name: string): GlazeTheme | undefined;
1266
+ /**
1267
+ * Shallow copy of the theme map (same instances the palette holds).
1268
+ * Mutating a returned theme affects subsequent palette exports.
1269
+ */
1270
+ themes(): Record<string, GlazeTheme>;
1271
+ /**
1272
+ * Export the palette authoring configuration as a JSON-safe object.
1273
+ * Restorable via `glaze.paletteFrom(...)`. Distinct from `json()`, which
1274
+ * emits resolved color strings. Optional `override` is forwarded to each
1275
+ * nested `theme.export(override)`.
1276
+ */
1277
+ export(override?: GlazeConfigOverride): GlazePaletteExport;
1227
1278
  /**
1228
1279
  * Export all themes as a flat token map grouped by scheme variant.
1229
1280
  * Prefix defaults to `true` — all tokens are prefixed with the theme name.
@@ -1270,6 +1321,14 @@ interface GlazePalette {
1270
1321
  tailwind(options?: GlazeTailwindOptions & GlazePaletteExportOptions): string;
1271
1322
  }
1272
1323
  //#endregion
1324
+ //#region src/serialize.d.ts
1325
+ /** Type guard for theme authoring snapshots (prefers `kind`, falls back to shape). */
1326
+ declare function isThemeExport(data: unknown): data is GlazeThemeExport;
1327
+ /** Type guard for color-token authoring snapshots. */
1328
+ declare function isColorTokenExport(data: unknown): data is GlazeColorTokenExport;
1329
+ /** Type guard for palette authoring snapshots. */
1330
+ declare function isPaletteExport(data: unknown): data is GlazePaletteExport;
1331
+ //#endregion
1273
1332
  //#region src/glaze.d.ts
1274
1333
  type PaletteInput = Record<string, GlazeTheme>;
1275
1334
  /**
@@ -1297,6 +1356,7 @@ declare function glaze(hueOrOptions: number | {
1297
1356
  declare namespace glaze {
1298
1357
  var configure: (config: GlazeConfig) => void;
1299
1358
  var palette: (themes: PaletteInput, options?: GlazePaletteOptions) => GlazePalette;
1359
+ var themeFrom: (data: GlazeThemeExport) => GlazeTheme;
1300
1360
  var from: (data: GlazeThemeExport) => GlazeTheme;
1301
1361
  var color: (input: GlazeFromInput | GlazeColorInput | GlazeColorValue, config?: GlazeConfigOverride) => GlazeColorToken;
1302
1362
  var shadow: (input: GlazeShadowInput) => ResolvedColorVariant;
@@ -1304,6 +1364,10 @@ declare namespace glaze {
1304
1364
  var fromHex: (hex: string) => GlazeTheme;
1305
1365
  var fromRgb: (r: number, g: number, b: number) => GlazeTheme;
1306
1366
  var colorFrom: (data: GlazeColorTokenExport) => GlazeColorToken;
1367
+ var paletteFrom: (data: GlazePaletteExport) => GlazePalette;
1368
+ var isThemeExport: typeof isThemeExport;
1369
+ var isColorTokenExport: typeof isColorTokenExport;
1370
+ var isPaletteExport: typeof isPaletteExport;
1307
1371
  var getConfig: () => GlazeConfigResolved;
1308
1372
  var resetConfig: () => void;
1309
1373
  }
@@ -1567,5 +1631,5 @@ declare function srgbToHex(rgb: [number, number, number]): `#${string}`;
1567
1631
  */
1568
1632
  declare function okhslToOklch(h: number, s: number, l: number, pastel?: boolean): [number, number, number];
1569
1633
  //#endregion
1570
- export { APCA_HC_ENHANCEMENT, APCA_MAX_LC, APCA_PRESETS, type AdaptationMode, type ApcaPreset, type ChannelCtx, type ColorDef, type ColorMap, type ContrastPreset, type ContrastSpec, type DtcgColorSpace, type DtcgColorToken, type DtcgColorValue, type DtcgDocument, type DtcgOklchColorValue, type DtcgResolverModifier, type DtcgResolverRef, type DtcgResolverSet, type DtcgSrgbColorValue, type DtcgTokenTree, type ExtremeValue, type FindToneForContrastOptions, type FindToneForContrastResult, type FindValueForMixContrastOptions, type FindValueForMixContrastResult, type GlazeColorCssOptions, type GlazeColorDtcgResolverOptions, type GlazeColorDtcgResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorInputExport, type GlazeColorOverrides, type GlazeColorOverridesExport, type GlazeColorTailwindOptions, type GlazeColorToken, type GlazeColorTokenExport, type GlazeColorValue, type GlazeConfig, type GlazeConfigOverride, type GlazeConfigResolved, type GlazeCssOptions, type GlazeCssResult, type GlazeDtcgOptions, type GlazeDtcgResolverContextNames, type GlazeDtcgResolverDocument, type GlazeDtcgResolverOptions, type GlazeDtcgResult, type GlazeExtendOptions, type GlazeFromInput, type GlazeJsonOptions, type GlazeOutputModes, type GlazePalette, type GlazePaletteExportOptions, type GlazePaletteOptions, type GlazeShadowInput, type GlazeTailwindOptions, type GlazeTheme, type GlazeThemeExport, type GlazeTokenOptions, type HCPair, type HexColor, type HueDeclaration, type HuePlan, type MinContrast, type MixColorDef, type OkhslColor, type OkhstColor, type OklchColor, type Polarity, REF_EPS, type RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type ResolvedContrast, type RgbColor, type Role, type RoleInput, type ShadowColorDef, type ShadowTuning, type ToneValue, type ToneWindow, apcaContrast, assertAllPastel, assertNativeFormat, contrastRatioFromLuminance, cuspLightness, findToneForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOkhst, formatOklch, formatRgb, fromTone, gamutClampedLuminance, glaze, hslToSrgb, inferRoleFromName, normalizeRole, okhslToLinearSrgb, okhslToOkhst, okhslToOklab, okhslToOklch, okhslToSrgb, okhstToOkhsl, oklabToOkhsl, oppositeRole, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveApcaTarget, resolveContrastForMode, resolveMinContrast, roleToPolarity, srgbToHex, srgbToOkhsl, toTone, toneFromY, variantToOkhsl, yFromTone };
1634
+ export { APCA_HC_ENHANCEMENT, APCA_MAX_LC, APCA_PRESETS, type AdaptationMode, type ApcaPreset, type ChannelCtx, type ColorDef, type ColorMap, type ContrastPreset, type ContrastSpec, type DtcgColorSpace, type DtcgColorToken, type DtcgColorValue, type DtcgDocument, type DtcgOklchColorValue, type DtcgResolverModifier, type DtcgResolverRef, type DtcgResolverSet, type DtcgSrgbColorValue, type DtcgTokenTree, type ExtremeValue, type FindToneForContrastOptions, type FindToneForContrastResult, type FindValueForMixContrastOptions, type FindValueForMixContrastResult, GLAZE_EXPORT_VERSION, type GlazeColorCssOptions, type GlazeColorDtcgResolverOptions, type GlazeColorDtcgResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorInputExport, type GlazeColorOverrides, type GlazeColorOverridesExport, type GlazeColorTailwindOptions, type GlazeColorToken, type GlazeColorTokenExport, type GlazeColorValue, type GlazeConfig, type GlazeConfigOverride, type GlazeConfigResolved, type GlazeCssOptions, type GlazeCssResult, type GlazeDtcgOptions, type GlazeDtcgResolverContextNames, type GlazeDtcgResolverDocument, type GlazeDtcgResolverOptions, type GlazeDtcgResult, type GlazeExportKind, type GlazeExportVersion, type GlazeExtendOptions, type GlazeFromInput, type GlazeJsonOptions, type GlazeOutputModes, type GlazePalette, type GlazePaletteExport, type GlazePaletteExportOptions, type GlazePaletteOptions, type GlazeShadowInput, type GlazeTailwindOptions, type GlazeTheme, type GlazeThemeExport, type GlazeTokenOptions, type HCPair, type HexColor, type HueDeclaration, type HuePlan, type MinContrast, type MixColorDef, type OkhslColor, type OkhstColor, type OklchColor, type Polarity, REF_EPS, type RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type ResolvedContrast, type RgbColor, type Role, type RoleInput, type ShadowColorDef, type ShadowTuning, type ToneValue, type ToneWindow, apcaContrast, assertAllPastel, assertNativeFormat, contrastRatioFromLuminance, cuspLightness, findToneForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOkhst, formatOklch, formatRgb, fromTone, gamutClampedLuminance, glaze, hslToSrgb, inferRoleFromName, isColorTokenExport, isPaletteExport, isThemeExport, normalizeRole, okhslToLinearSrgb, okhslToOkhst, okhslToOklab, okhslToOklch, okhslToSrgb, okhstToOkhsl, oklabToOkhsl, oppositeRole, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveApcaTarget, resolveContrastForMode, resolveMinContrast, roleToPolarity, srgbToHex, srgbToOkhsl, toTone, toneFromY, variantToOkhsl, yFromTone };
1571
1635
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.mts CHANGED
@@ -280,8 +280,8 @@ interface RegularColorDef {
280
280
  /**
281
281
  * Per-color override for the hue-independent "safe" chroma limit used in
282
282
  * OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
283
- * Falls through to the global / per-theme `pastel` config when omitted.
284
- * @see GlazeConfig.pastel
283
+ * Falls through to the per-theme / per-token `pastel` override when omitted.
284
+ * @see GlazeConfigOverride.pastel
285
285
  */
286
286
  pastel?: boolean;
287
287
  /**
@@ -346,8 +346,8 @@ interface ShadowColorDef {
346
346
  /**
347
347
  * Per-color override for the hue-independent "safe" chroma limit used in
348
348
  * OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
349
- * Falls through to the global / per-theme `pastel` config when omitted.
350
- * @see GlazeConfig.pastel
349
+ * Falls through to the per-theme / per-token `pastel` override when omitted.
350
+ * @see GlazeConfigOverride.pastel
351
351
  */
352
352
  pastel?: boolean;
353
353
  /**
@@ -393,8 +393,8 @@ interface MixColorDef {
393
393
  /**
394
394
  * Per-color override for the hue-independent "safe" chroma limit used in
395
395
  * OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
396
- * Falls through to the global / per-theme `pastel` config when omitted.
397
- * @see GlazeConfig.pastel
396
+ * Falls through to the per-theme / per-token `pastel` override when omitted.
397
+ * @see GlazeConfigOverride.pastel
398
398
  */
399
399
  pastel?: boolean;
400
400
  /**
@@ -493,13 +493,6 @@ interface GlazeConfig {
493
493
  * falls back to the originally requested tone).
494
494
  */
495
495
  autoFlip?: boolean;
496
- /**
497
- * If true, uses a hue-independent "safe" chroma limit across all colors
498
- * so that scaling saturation never exceeds the sRGB boundary at any hue
499
- * for the given lightness.
500
- * @default false
501
- */
502
- pastel?: boolean;
503
496
  /**
504
497
  * If true (default), infer a color's `role` from its name when no explicit
505
498
  * `role` is set. Set to `false` to opt out of name-based inference (the
@@ -519,13 +512,19 @@ interface GlazeConfigResolved {
519
512
  modes: Required<GlazeOutputModes>;
520
513
  shadowTuning?: ShadowTuning;
521
514
  autoFlip: boolean;
515
+ /**
516
+ * Instance-level pastel default (`def.pastel ?? config.pastel`).
517
+ * Not set via `glaze.configure()` — only via per-theme / per-token
518
+ * `GlazeConfigOverride` (default `false`).
519
+ */
522
520
  pastel: boolean;
523
521
  inferRole: boolean;
524
522
  }
525
523
  /**
526
524
  * Per-instance config override for `glaze.color()` and `glaze()` themes.
527
525
  * Fields that are set take priority over the live global config. Fields
528
- * that are omitted fall through to the live global at resolve time.
526
+ * that are omitted fall through to the live global at resolve time
527
+ * (`pastel` is instance-only and defaults to `false` when omitted).
529
528
  *
530
529
  * `false` for a tone window disables clamping (full range at reference eps).
531
530
  */
@@ -539,9 +538,9 @@ interface GlazeConfigOverride {
539
538
  /** Whether to auto-flip tone when contrast can't be met. */
540
539
  autoFlip?: boolean;
541
540
  /**
542
- * If true, uses a hue-independent "safe" chroma limit across all colors
543
- * so that scaling saturation never exceeds the sRGB boundary at any hue
544
- * for the given lightness.
541
+ * Instance-level pastel default for colors that omit per-color `pastel`.
542
+ * Not available on `glaze.configure()` set here or per-color.
543
+ * @default false
545
544
  */
546
545
  pastel?: boolean;
547
546
  /**
@@ -555,12 +554,29 @@ interface GlazeConfigOverride {
555
554
  */
556
555
  shadowTuning?: ShadowTuning;
557
556
  }
557
+ /**
558
+ * Current authoring-export schema version. Bump when the export shape
559
+ * changes in a non-compatible way. Written on every `.export()` snapshot.
560
+ */
561
+ declare const GLAZE_EXPORT_VERSION: 1;
562
+ /** Literal type of {@link GLAZE_EXPORT_VERSION}. */
563
+ type GlazeExportVersion = typeof GLAZE_EXPORT_VERSION;
564
+ /** Discriminator for authoring export snapshots. */
565
+ type GlazeExportKind = 'theme' | 'color' | 'palette';
558
566
  /** Serialized theme configuration (no resolved values). */
559
567
  interface GlazeThemeExport {
568
+ /** Snapshot kind. Always written by `theme.export()`; optional on legacy hand-written configs. */
569
+ kind?: 'theme';
570
+ /** Schema version. Always written by `theme.export()`; optional on legacy configs. */
571
+ version?: number;
560
572
  hue: number;
561
573
  saturation: number;
562
574
  colors: ColorMap;
563
- /** Per-theme config override, if any. */
575
+ /**
576
+ * Effective config freeze from `.export()` —
577
+ * `getConfig() ∪ instance local ∪ exportArg`. May be sparse on legacy
578
+ * snapshots (omitted fields fall through to the live global at restore).
579
+ */
564
580
  config?: GlazeConfigOverride;
565
581
  }
566
582
  /** Input for `glaze.shadow()` standalone factory. */
@@ -616,8 +632,8 @@ interface GlazeColorInput {
616
632
  /**
617
633
  * Per-color override for the hue-independent "safe" chroma limit used in
618
634
  * OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
619
- * Falls through to the global / per-theme `pastel` config when omitted.
620
- * @see GlazeConfig.pastel
635
+ * Falls through to the per-theme / per-token `pastel` override when omitted.
636
+ * @see GlazeConfigOverride.pastel
621
637
  */
622
638
  pastel?: boolean;
623
639
  /**
@@ -668,11 +684,11 @@ interface GlazeColorOverrides {
668
684
  /**
669
685
  * Adaptation mode. Defaults to `'auto'` for every input form, so
670
686
  * colors automatically adapt between light and dark like an ordinary
671
- * theme color. All value-shorthand inputs (strings and literal objects)
672
- * preserve light tone (`lightTone: false`) and snapshot
673
- * `globalConfig.darkTone` on the dark side. Only the structured
674
- * `{ hue, saturation, tone }` form also snapshots
675
- * `globalConfig.lightTone`.
687
+ * theme color. Value-shorthand inputs (strings and literal objects)
688
+ * preserve light tone via a local `lightTone: false` default; other
689
+ * omitted config fields fall through to the live global at resolve
690
+ * time. Structured `{ hue, saturation, tone }` form also falls
691
+ * through for both tone windows unless overridden.
676
692
  *
677
693
  * Pass `'fixed'` explicitly to opt back into the linear, non-
678
694
  * inverting mapping; pass `'static'` to pin the same tone
@@ -731,8 +747,8 @@ interface GlazeColorOverrides {
731
747
  /**
732
748
  * Per-color override for the hue-independent "safe" chroma limit used in
733
749
  * OKHSL↔sRGB conversions (luminance, contrast solving, output formatting).
734
- * Falls through to the global / per-theme `pastel` config when omitted.
735
- * @see GlazeConfig.pastel
750
+ * Falls through to the per-theme / per-token `pastel` override when omitted.
751
+ * @see GlazeConfigOverride.pastel
736
752
  */
737
753
  pastel?: boolean;
738
754
  /**
@@ -815,14 +831,19 @@ interface GlazeColorToken {
815
831
  * Serialize the token as a JSON-safe object. Captures the original
816
832
  * input value, overrides, and config so it can be rehydrated via
817
833
  * `glaze.colorFrom(...)`. `base` is recursively serialized.
834
+ * Optional `override` is merged over the instance local at export time.
818
835
  */
819
- export(): GlazeColorTokenExport;
836
+ export(override?: GlazeConfigOverride): GlazeColorTokenExport;
820
837
  }
821
838
  /**
822
839
  * JSON-safe serialization of a `glaze.color()` token. Pass to
823
840
  * `glaze.colorFrom(...)` to rehydrate.
824
841
  */
825
842
  interface GlazeColorTokenExport {
843
+ /** Snapshot kind. Always written by `token.export()`; optional on legacy snapshots. */
844
+ kind?: 'color';
845
+ /** Schema version. Always written by `token.export()`; optional on legacy snapshots. */
846
+ version?: number;
826
847
  /**
827
848
  * Discriminator for the source overload that created the token.
828
849
  * - `'value'`: created via `glaze.color(value)` or `glaze.color({ from, ...overrides })`.
@@ -837,14 +858,26 @@ interface GlazeColorTokenExport {
837
858
  */
838
859
  overrides?: GlazeColorOverridesExport;
839
860
  /**
840
- * Effective config snapshot at creation time captures the merged
841
- * result of the global config + any per-call override at the moment
842
- * the token was created. Only fields that differ from their
843
- * post-merge defaults are present. Used by `glaze.colorFrom()` to
844
- * reproduce deterministic behavior across `configure()` calls.
861
+ * Effective config freeze from `.export()``getConfig() local ∪
862
+ * exportArg` at call time. Used by `glaze.colorFrom()` to pin
863
+ * deterministic behavior across later `configure()` calls.
845
864
  */
846
865
  config?: GlazeConfigOverride;
847
866
  }
867
+ /**
868
+ * JSON-safe serialization of a `glaze.palette()` composition.
869
+ * Pass to `glaze.paletteFrom(...)` to rehydrate.
870
+ */
871
+ interface GlazePaletteExport {
872
+ /** Snapshot kind. Always written by `palette.export()`. */
873
+ kind?: 'palette';
874
+ /** Schema version. Always written by `palette.export()`. */
875
+ version?: number;
876
+ /** Per-theme authoring snapshots keyed by theme name. */
877
+ themes: Record<string, GlazeThemeExport>;
878
+ /** Primary theme name, if set on the palette. */
879
+ primary?: string;
880
+ }
848
881
  /**
849
882
  * Serializable shape of a structured `glaze.color({...})` input.
850
883
  * Differs from `GlazeColorInput` only in that `base` is replaced by an
@@ -904,7 +937,7 @@ interface GlazeTheme {
904
937
  /** Clear all color definitions. */
905
938
  reset(): void;
906
939
  /** Export the theme configuration as a JSON-safe object. */
907
- export(): GlazeThemeExport;
940
+ export(override?: GlazeConfigOverride): GlazeThemeExport;
908
941
  /** Create a child theme inheriting all color definitions. */
909
942
  extend(options: GlazeExtendOptions): GlazeTheme;
910
943
  /** Resolve all colors and return the result map. */
@@ -1224,6 +1257,24 @@ interface GlazePaletteExportOptions {
1224
1257
  splitHue?: boolean;
1225
1258
  }
1226
1259
  interface GlazePalette {
1260
+ /** Theme names in insertion order. */
1261
+ list(): string[];
1262
+ /** Primary theme name, if set at palette creation. */
1263
+ readonly primary: string | undefined;
1264
+ /** Get a theme by name. Returns the live instance held by the palette. */
1265
+ theme(name: string): GlazeTheme | undefined;
1266
+ /**
1267
+ * Shallow copy of the theme map (same instances the palette holds).
1268
+ * Mutating a returned theme affects subsequent palette exports.
1269
+ */
1270
+ themes(): Record<string, GlazeTheme>;
1271
+ /**
1272
+ * Export the palette authoring configuration as a JSON-safe object.
1273
+ * Restorable via `glaze.paletteFrom(...)`. Distinct from `json()`, which
1274
+ * emits resolved color strings. Optional `override` is forwarded to each
1275
+ * nested `theme.export(override)`.
1276
+ */
1277
+ export(override?: GlazeConfigOverride): GlazePaletteExport;
1227
1278
  /**
1228
1279
  * Export all themes as a flat token map grouped by scheme variant.
1229
1280
  * Prefix defaults to `true` — all tokens are prefixed with the theme name.
@@ -1270,6 +1321,14 @@ interface GlazePalette {
1270
1321
  tailwind(options?: GlazeTailwindOptions & GlazePaletteExportOptions): string;
1271
1322
  }
1272
1323
  //#endregion
1324
+ //#region src/serialize.d.ts
1325
+ /** Type guard for theme authoring snapshots (prefers `kind`, falls back to shape). */
1326
+ declare function isThemeExport(data: unknown): data is GlazeThemeExport;
1327
+ /** Type guard for color-token authoring snapshots. */
1328
+ declare function isColorTokenExport(data: unknown): data is GlazeColorTokenExport;
1329
+ /** Type guard for palette authoring snapshots. */
1330
+ declare function isPaletteExport(data: unknown): data is GlazePaletteExport;
1331
+ //#endregion
1273
1332
  //#region src/glaze.d.ts
1274
1333
  type PaletteInput = Record<string, GlazeTheme>;
1275
1334
  /**
@@ -1297,6 +1356,7 @@ declare function glaze(hueOrOptions: number | {
1297
1356
  declare namespace glaze {
1298
1357
  var configure: (config: GlazeConfig) => void;
1299
1358
  var palette: (themes: PaletteInput, options?: GlazePaletteOptions) => GlazePalette;
1359
+ var themeFrom: (data: GlazeThemeExport) => GlazeTheme;
1300
1360
  var from: (data: GlazeThemeExport) => GlazeTheme;
1301
1361
  var color: (input: GlazeFromInput | GlazeColorInput | GlazeColorValue, config?: GlazeConfigOverride) => GlazeColorToken;
1302
1362
  var shadow: (input: GlazeShadowInput) => ResolvedColorVariant;
@@ -1304,6 +1364,10 @@ declare namespace glaze {
1304
1364
  var fromHex: (hex: string) => GlazeTheme;
1305
1365
  var fromRgb: (r: number, g: number, b: number) => GlazeTheme;
1306
1366
  var colorFrom: (data: GlazeColorTokenExport) => GlazeColorToken;
1367
+ var paletteFrom: (data: GlazePaletteExport) => GlazePalette;
1368
+ var isThemeExport: typeof isThemeExport;
1369
+ var isColorTokenExport: typeof isColorTokenExport;
1370
+ var isPaletteExport: typeof isPaletteExport;
1307
1371
  var getConfig: () => GlazeConfigResolved;
1308
1372
  var resetConfig: () => void;
1309
1373
  }
@@ -1567,5 +1631,5 @@ declare function srgbToHex(rgb: [number, number, number]): `#${string}`;
1567
1631
  */
1568
1632
  declare function okhslToOklch(h: number, s: number, l: number, pastel?: boolean): [number, number, number];
1569
1633
  //#endregion
1570
- export { APCA_HC_ENHANCEMENT, APCA_MAX_LC, APCA_PRESETS, type AdaptationMode, type ApcaPreset, type ChannelCtx, type ColorDef, type ColorMap, type ContrastPreset, type ContrastSpec, type DtcgColorSpace, type DtcgColorToken, type DtcgColorValue, type DtcgDocument, type DtcgOklchColorValue, type DtcgResolverModifier, type DtcgResolverRef, type DtcgResolverSet, type DtcgSrgbColorValue, type DtcgTokenTree, type ExtremeValue, type FindToneForContrastOptions, type FindToneForContrastResult, type FindValueForMixContrastOptions, type FindValueForMixContrastResult, type GlazeColorCssOptions, type GlazeColorDtcgResolverOptions, type GlazeColorDtcgResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorInputExport, type GlazeColorOverrides, type GlazeColorOverridesExport, type GlazeColorTailwindOptions, type GlazeColorToken, type GlazeColorTokenExport, type GlazeColorValue, type GlazeConfig, type GlazeConfigOverride, type GlazeConfigResolved, type GlazeCssOptions, type GlazeCssResult, type GlazeDtcgOptions, type GlazeDtcgResolverContextNames, type GlazeDtcgResolverDocument, type GlazeDtcgResolverOptions, type GlazeDtcgResult, type GlazeExtendOptions, type GlazeFromInput, type GlazeJsonOptions, type GlazeOutputModes, type GlazePalette, type GlazePaletteExportOptions, type GlazePaletteOptions, type GlazeShadowInput, type GlazeTailwindOptions, type GlazeTheme, type GlazeThemeExport, type GlazeTokenOptions, type HCPair, type HexColor, type HueDeclaration, type HuePlan, type MinContrast, type MixColorDef, type OkhslColor, type OkhstColor, type OklchColor, type Polarity, REF_EPS, type RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type ResolvedContrast, type RgbColor, type Role, type RoleInput, type ShadowColorDef, type ShadowTuning, type ToneValue, type ToneWindow, apcaContrast, assertAllPastel, assertNativeFormat, contrastRatioFromLuminance, cuspLightness, findToneForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOkhst, formatOklch, formatRgb, fromTone, gamutClampedLuminance, glaze, hslToSrgb, inferRoleFromName, normalizeRole, okhslToLinearSrgb, okhslToOkhst, okhslToOklab, okhslToOklch, okhslToSrgb, okhstToOkhsl, oklabToOkhsl, oppositeRole, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveApcaTarget, resolveContrastForMode, resolveMinContrast, roleToPolarity, srgbToHex, srgbToOkhsl, toTone, toneFromY, variantToOkhsl, yFromTone };
1634
+ export { APCA_HC_ENHANCEMENT, APCA_MAX_LC, APCA_PRESETS, type AdaptationMode, type ApcaPreset, type ChannelCtx, type ColorDef, type ColorMap, type ContrastPreset, type ContrastSpec, type DtcgColorSpace, type DtcgColorToken, type DtcgColorValue, type DtcgDocument, type DtcgOklchColorValue, type DtcgResolverModifier, type DtcgResolverRef, type DtcgResolverSet, type DtcgSrgbColorValue, type DtcgTokenTree, type ExtremeValue, type FindToneForContrastOptions, type FindToneForContrastResult, type FindValueForMixContrastOptions, type FindValueForMixContrastResult, GLAZE_EXPORT_VERSION, type GlazeColorCssOptions, type GlazeColorDtcgResolverOptions, type GlazeColorDtcgResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorInputExport, type GlazeColorOverrides, type GlazeColorOverridesExport, type GlazeColorTailwindOptions, type GlazeColorToken, type GlazeColorTokenExport, type GlazeColorValue, type GlazeConfig, type GlazeConfigOverride, type GlazeConfigResolved, type GlazeCssOptions, type GlazeCssResult, type GlazeDtcgOptions, type GlazeDtcgResolverContextNames, type GlazeDtcgResolverDocument, type GlazeDtcgResolverOptions, type GlazeDtcgResult, type GlazeExportKind, type GlazeExportVersion, type GlazeExtendOptions, type GlazeFromInput, type GlazeJsonOptions, type GlazeOutputModes, type GlazePalette, type GlazePaletteExport, type GlazePaletteExportOptions, type GlazePaletteOptions, type GlazeShadowInput, type GlazeTailwindOptions, type GlazeTheme, type GlazeThemeExport, type GlazeTokenOptions, type HCPair, type HexColor, type HueDeclaration, type HuePlan, type MinContrast, type MixColorDef, type OkhslColor, type OkhstColor, type OklchColor, type Polarity, REF_EPS, type RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type ResolvedContrast, type RgbColor, type Role, type RoleInput, type ShadowColorDef, type ShadowTuning, type ToneValue, type ToneWindow, apcaContrast, assertAllPastel, assertNativeFormat, contrastRatioFromLuminance, cuspLightness, findToneForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOkhst, formatOklch, formatRgb, fromTone, gamutClampedLuminance, glaze, hslToSrgb, inferRoleFromName, isColorTokenExport, isPaletteExport, isThemeExport, normalizeRole, okhslToLinearSrgb, okhslToOkhst, okhslToOklab, okhslToOklch, okhslToSrgb, okhstToOkhsl, oklabToOkhsl, oppositeRole, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveApcaTarget, resolveContrastForMode, resolveMinContrast, roleToPolarity, srgbToHex, srgbToOkhsl, toTone, toneFromY, variantToOkhsl, yFromTone };
1571
1635
  //# sourceMappingURL=index.d.mts.map