@sugarcube-org/core 0.0.1-alpha.5 → 0.0.1-alpha.7

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.ts CHANGED
@@ -1,28 +1,29 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  /**
4
- * Supported color formats for CSS output
4
+ * Directional variants for utility properties
5
5
  */
6
- type ColorFormat = "hex" | "rgb" | "rgba" | "hsl" | "hsla" | "oklch" | "p3";
6
+ type DirectionalVariant = "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all";
7
7
  /**
8
- * Configuration for fluid (responsive) values
8
+ * Properties-first utility configuration
9
+ * This is the approach where users configure utilities by CSS property
10
+ * Made it separate in case we want other types of configs later
9
11
  */
12
+ type PropertyUtilityConfig = {
13
+ source: string;
14
+ directions?: DirectionalVariant | DirectionalVariant[];
15
+ prefix?: string;
16
+ stripDuplicates?: boolean;
17
+ collection?: string;
18
+ };
19
+
20
+ type ColorFallbackStrategy = "native" | "polyfill";
10
21
  type FluidConfig = {
11
- /** Minimum viewport width in pixels */
12
22
  min: number;
13
- /** Maximum viewport width in pixels */
14
23
  max: number;
15
24
  };
16
- /**
17
- * A collection of token files with shared namespace.
18
- * Represents either a starter kit or custom token collection.
19
- */
20
25
  type TokenCollection = {
21
- /** Array of source file paths for this collection */
22
26
  source: string[];
23
- /** Whether this is a starter kit or custom collection */
24
- type: "starter-kit" | "custom";
25
- /** Optional theme-specific source files */
26
27
  themes?: Record<string, string[]>;
27
28
  };
28
29
  /**
@@ -30,66 +31,53 @@ type TokenCollection = {
30
31
  * Each key is a collection name (e.g., "base", "ui", "marketing").
31
32
  */
32
33
  type TokenCollections = Record<string, TokenCollection>;
34
+ type UserTransformsConfig = {
35
+ fluid?: FluidConfig;
36
+ colorFallbackStrategy?: ColorFallbackStrategy;
37
+ };
33
38
  /**
34
- * Global options for token processing and output
39
+ * Configuration for transforms applied to tokens during processing (internal config)
35
40
  */
36
- type OptionsConfig = {
37
- /** Configuration for fluid (responsive) values */
38
- fluid?: FluidConfig;
39
- /** Prefix to add to all CSS variable names */
40
- prefix?: string;
41
- /** Default color format for all color tokens */
42
- color?: ColorFormat;
41
+ type TransformsConfig = {
42
+ fluid: FluidConfig;
43
+ colorFallbackStrategy: ColorFallbackStrategy;
43
44
  };
44
45
  /**
45
- * Configuration for output directories
46
+ * Configuration for output directories (user config - optional fields)
46
47
  */
47
- type DirectoriesConfig = {
48
- /** Directory containing token source files */
49
- tokens: string;
50
- /** Optional directory for component files */
48
+ type UserOutputConfig = {
49
+ css?: string;
51
50
  components?: string;
52
- /** Directory where CSS files will be written */
53
- css: string;
51
+ separate?: boolean;
54
52
  };
55
53
  /**
56
- * Configuration for CSS output generation
54
+ * Configuration for output directories (internal config - required fields)
57
55
  */
58
- type CSSOutputConfig = {
59
- /**
60
- * Controls how CSS variables are organized in output files:
61
- * - When false: Generates one file per collection, combining all tokens within each collection
62
- * (e.g., base/tokens.variables.css, ui/tokens.variables.css)
63
- * - When true: Generates separate files by token type within each collection
64
- * (e.g., base/colors.variables.css, base/space.variables.css)
65
- * @default false
66
- */
56
+ type OutputConfig = {
57
+ css: string;
58
+ components?: string;
67
59
  separate: boolean;
68
- /** Whether to generate and manage an index.css file */
69
- manageIndex?: boolean;
70
- /** The format of the output CSS files */
71
- format?: "css" | "scss" | "less";
72
60
  };
73
61
  /**
74
- * Configuration for all output generation
62
+ * Utilities configuration
63
+ * This is the approach where users configure utilities by CSS property
64
+ * Can be a single configuration or an array of configurations
75
65
  */
76
- type OutputConfig = {
77
- /** Directory configuration for all output files */
78
- directories: DirectoriesConfig;
79
- /** CSS-specific output configuration */
80
- css: CSSOutputConfig;
81
- };
66
+ type UtilitiesConfig = Record<string, PropertyUtilityConfig | PropertyUtilityConfig[]>;
67
+ interface UserConfig {
68
+ tokens?: TokenCollection | TokenCollections;
69
+ transforms?: UserTransformsConfig;
70
+ output?: UserOutputConfig;
71
+ utilities?: UtilitiesConfig;
72
+ }
82
73
  /**
83
- * The main configuration type for Sugarcube.
84
- * Defines all settings for token processing and output generation.
74
+ * Internal configuration type - what code uses (complete, required fields)
85
75
  */
86
- interface SugarcubeConfig {
87
- /** Token source configuration, either a single collection or multiple named collections */
88
- tokens: TokenCollection | TokenCollections;
89
- /** Optional global processing options */
90
- options?: OptionsConfig;
91
- /** Output configuration for generated files */
76
+ interface InternalConfig {
77
+ tokens?: TokenCollection | TokenCollections;
78
+ transforms: TransformsConfig;
92
79
  output: OutputConfig;
80
+ utilities?: UtilitiesConfig;
93
81
  }
94
82
 
95
83
  /**
@@ -199,9 +187,20 @@ type StructuralCompositeType = "strokeStyle";
199
187
  type CompositeTokenValue<T extends CompositeTokenType = CompositeTokenType> = T extends "typography" ? Typography : T extends "border" ? Border : T extends "shadow" ? Shadow : T extends "gradient" ? Gradient : T extends "transition" ? Transition : T extends "strokeStyle" ? StrokeStyle : never;
200
188
  /**
201
189
  * A color value in any valid CSS color format.
202
- * This can be any string that is valid in CSS color contexts.
203
- */
204
- type Color = string;
190
+ * This can be either:
191
+ * - A string that is valid in CSS color contexts (legacy format)
192
+ * - A W3C color object with colorSpace, components, and optional alpha/hex
193
+ */
194
+ type Color = string | {
195
+ /** The color space - supports "oklch" and "display-p3" */
196
+ colorSpace: "oklch" | "display-p3";
197
+ /** Array of 3 numbers representing the color components */
198
+ components: [number, number, number];
199
+ /** Optional alpha value between 0 and 1 (defaults to 1 if omitted) */
200
+ alpha?: number;
201
+ /** Optional hex fallback value for compatibility */
202
+ hex?: string;
203
+ };
205
204
  /**
206
205
  * A dimensional value with a numeric value and unit.
207
206
  * Used for measurements like width, height, spacing, etc.
@@ -385,47 +384,159 @@ type TokenTree = {
385
384
  };
386
385
 
387
386
  /**
388
- * A flattened token with its source information and path.
389
- * Represents a token after it has been flattened from a nested structure into a flat key-value map.
387
+ * A resolved token with its final value.
388
+ * Contains both the original token data and its resolved value after reference resolution.
390
389
  * @template T - The type of token (e.g., "color", "dimension", etc.)
391
390
  */
392
- type FlattenedToken<T extends TokenType = TokenType> = NodeMetadata & {
391
+ type ResolvedToken<T extends TokenType = TokenType> = NodeMetadata & {
393
392
  /** The type of the token */
394
393
  $type: T;
395
- /** The value of the token */
396
- $value: TokenValue<T>;
397
- /** The path to this token in the flattened structure */
394
+ /** The original value of the token, which may contain references */
395
+ $value: RawTokenValue<T>;
396
+ /** The path to this token in the token tree */
398
397
  $path: string;
399
398
  /** Information about where this token was loaded from */
400
399
  $source: TokenSource;
401
- /** The original path before flattening */
400
+ /** The original path before any resolution */
402
401
  $originalPath: string;
402
+ /** The final resolved value after all references are resolved */
403
+ $resolvedValue: RawTokenValue<T>;
403
404
  };
404
405
  /**
405
- * A map of flattened tokens and metadata by their lookup path, with an index for quick reference lookups.
406
- * Used to store the flattened state of all tokens in a collection.
407
- * Contains both the token map and a path index for efficient lookups.
406
+ * A map of resolved tokens by their lookup path.
407
+ * Used to store the final resolved state of all tokens in a collection.
408
+ * Keys are token paths, values are either resolved tokens or node metadata.
408
409
  */
409
- type FlattenedTokens = {
410
- /** Map of token paths to their flattened tokens or metadata */
411
- tokens: {
412
- /** Token path as key, flattened token or metadata as value */
413
- [lookupKey: string]: FlattenedToken | NodeMetadata;
414
- };
415
- /** Index mapping original paths to their namespaced keys for quick lookups */
416
- pathIndex: Map<string, string>;
410
+ type ResolvedTokens = {
411
+ /** Token path as key, resolved token or metadata as value */
412
+ [lookupKey: string]: ResolvedToken | NodeMetadata;
417
413
  };
418
414
  /**
419
- * An error that occurred during token flattening.
420
- * Extends the base error type with flattening-specific information.
415
+ * Type of resolution error that occurred.
416
+ * - "circular": A circular reference was detected
417
+ * - "missing": A referenced token could not be found
418
+ * - "type-mismatch": A referenced token's type doesn't match the expected type
421
419
  */
422
- type FlattenError = BaseError & {
423
- /** The path to the token that failed flattening */
420
+ type ResolutionErrorType = "circular" | "missing" | "type-mismatch";
421
+ /**
422
+ * An error that occurred during token resolution.
423
+ * Extends the base error type with resolution-specific information.
424
+ */
425
+ type ResolutionError = BaseError & {
426
+ /** The type of resolution error that occurred */
427
+ type: ResolutionErrorType;
428
+ /** The path to the token that failed resolution */
424
429
  path: string;
425
430
  /** Source information about where the token was loaded from */
426
431
  source: TokenSource;
427
432
  };
428
433
 
434
+ /**
435
+ * A token that has been converted to CSS properties.
436
+ * Extends ResolvedToken with CSS-specific properties.
437
+ * @template T The type of token
438
+ */
439
+ type ConvertedToken<T extends TokenType = TokenType> = ResolvedToken<T> & {
440
+ /** The CSS properties generated from the token */
441
+ $cssProperties: CSSProperties<T>;
442
+ };
443
+ /**
444
+ * A collection of converted tokens.
445
+ * Maps token paths to their converted values or metadata nodes.
446
+ */
447
+ type ConvertedTokens = {
448
+ [lookupKey: string]: ConvertedToken | NodeMetadata;
449
+ };
450
+ /**
451
+ * A collection of converted tokens organized by theme.
452
+ * Each theme contains its own set of converted tokens.
453
+ */
454
+ type ConvertedThemeTokenSet = {
455
+ /** The default theme's tokens */
456
+ default: ConvertedTokens;
457
+ /** Additional theme-specific tokens */
458
+ [theme: string]: ConvertedTokens;
459
+ };
460
+ /**
461
+ * A collection of converted tokens organized by collection and theme.
462
+ * The top-level structure for all converted tokens.
463
+ */
464
+ type NormalizedConvertedTokens = {
465
+ [collection: string]: ConvertedThemeTokenSet;
466
+ };
467
+ /**
468
+ * CSS property types for different token types.
469
+ * Maps token types to their corresponding CSS property structures.
470
+ * @template T The type of token
471
+ */
472
+ type CSSProperties<T extends TokenType> = T extends SimpleTokenType ? SimpleCSSProperties : T extends AlwaysDecomposedType ? AlwaysDecomposedProperties : T extends "border" ? CSSBorderProperties : T extends "shadow" ? CSSShadowProperties : T extends "gradient" ? CSSGradientProperties : T extends "transition" ? CSSTransitionProperties : T extends StructuralCompositeType ? SimpleCSSProperties : never;
473
+ /**
474
+ * Simple CSS properties with a single value.
475
+ * Used for tokens that map to a single CSS property.
476
+ */
477
+ type SimpleCSSProperties = {
478
+ /** The CSS value */
479
+ value: string | number;
480
+ /** Optional feature queries for responsive values */
481
+ featureValues?: Array<{
482
+ query: string;
483
+ value: string;
484
+ }>;
485
+ };
486
+ /**
487
+ * CSS properties that are always broken down into multiple properties.
488
+ * Currently only used for typography tokens.
489
+ */
490
+ type AlwaysDecomposedProperties = CSSTypographyProperties;
491
+ /**
492
+ * CSS properties specific to typography tokens.
493
+ * Maps typography tokens to their corresponding CSS properties.
494
+ */
495
+ type CSSTypographyProperties = {
496
+ /** The font family to use */
497
+ "font-family": string;
498
+ /** The font size */
499
+ "font-size": string;
500
+ /** The font weight */
501
+ "font-weight"?: number | string;
502
+ /** The letter spacing */
503
+ "letter-spacing"?: string;
504
+ /** The line height */
505
+ "line-height"?: number | string;
506
+ };
507
+ /**
508
+ * CSS properties for specific token types.
509
+ * These types represent tokens that map to single CSS properties.
510
+ */
511
+ /**
512
+ * CSS properties for border tokens.
513
+ */
514
+ type CSSBorderProperties = {
515
+ /** The border value */
516
+ value: string;
517
+ };
518
+ /**
519
+ * CSS properties for shadow tokens.
520
+ */
521
+ type CSSShadowProperties = {
522
+ /** The shadow value */
523
+ value: string;
524
+ };
525
+ /**
526
+ * CSS properties for gradient tokens.
527
+ */
528
+ type CSSGradientProperties = {
529
+ /** The gradient value */
530
+ value: string;
531
+ };
532
+ /**
533
+ * CSS properties for transition tokens.
534
+ */
535
+ type CSSTransitionProperties = {
536
+ /** The transition value */
537
+ value: string;
538
+ };
539
+
429
540
  /**
430
541
  * Represents a single CSS file output with its path and content
431
542
  */
@@ -434,12 +545,36 @@ type CSSFile = {
434
545
  path: string;
435
546
  /** The CSS content to write to the file */
436
547
  css: string;
548
+ /** The collection name (e.g., "default", "base", "ui", "marketing") */
549
+ collection: string;
437
550
  };
438
551
  /**
439
552
  * Represents multiple CSS file outputs from generateSeparateFiles or generateSingleFile
440
553
  */
441
554
  type CSSFileOutput = CSSFile[];
442
555
 
556
+ declare function generateCSSVariables(convertedTokens: NormalizedConvertedTokens, config: InternalConfig): Promise<CSSFileOutput>;
557
+
558
+ /**
559
+ * An error that occurred during token flattening.
560
+ * Extends the base error type with flattening-specific information.
561
+ */
562
+ type FlattenError = BaseError & {
563
+ /** The path to the token that failed flattening */
564
+ path: string;
565
+ /** Source information about where the token was loaded from */
566
+ source: TokenSource;
567
+ };
568
+
569
+ /**
570
+ * Result of loading a Sugarcube configuration file
571
+ */
572
+ type LoadedConfig = {
573
+ /** The validated configuration */
574
+ config: InternalConfig;
575
+ /** The path to the config file that was loaded */
576
+ configPath: string;
577
+ };
443
578
  /**
444
579
  * Data structure for loading tokens from memory.
445
580
  * Maps file paths to their token content and metadata.
@@ -462,54 +597,6 @@ type LoadError = BaseError & {
462
597
  file: string;
463
598
  };
464
599
 
465
- /**
466
- * A resolved token with its final value.
467
- * Contains both the original token data and its resolved value after reference resolution.
468
- * @template T - The type of token (e.g., "color", "dimension", etc.)
469
- */
470
- type ResolvedToken<T extends TokenType = TokenType> = NodeMetadata & {
471
- /** The type of the token */
472
- $type: T;
473
- /** The original value of the token, which may contain references */
474
- $value: RawTokenValue<T>;
475
- /** The path to this token in the token tree */
476
- $path: string;
477
- /** Information about where this token was loaded from */
478
- $source: TokenSource;
479
- /** The original path before any resolution */
480
- $originalPath: string;
481
- /** The final resolved value after all references are resolved */
482
- $resolvedValue: RawTokenValue<T>;
483
- };
484
- /**
485
- * A map of resolved tokens by their lookup path.
486
- * Used to store the final resolved state of all tokens in a collection.
487
- * Keys are token paths, values are either resolved tokens or node metadata.
488
- */
489
- type ResolvedTokens = {
490
- /** Token path as key, resolved token or metadata as value */
491
- [lookupKey: string]: ResolvedToken | NodeMetadata;
492
- };
493
- /**
494
- * Type of resolution error that occurred.
495
- * - "circular": A circular reference was detected
496
- * - "missing": A referenced token could not be found
497
- * - "type-mismatch": A referenced token's type doesn't match the expected type
498
- */
499
- type ResolutionErrorType = "circular" | "missing" | "type-mismatch";
500
- /**
501
- * An error that occurred during token resolution.
502
- * Extends the base error type with resolution-specific information.
503
- */
504
- type ResolutionError = BaseError & {
505
- /** The type of resolution error that occurred */
506
- type: ResolutionErrorType;
507
- /** The path to the token that failed resolution */
508
- path: string;
509
- /** Source information about where the token was loaded from */
510
- source: TokenSource;
511
- };
512
-
513
600
  /**
514
601
  * An error that occurred during token validation.
515
602
  * Extends the base error type with token-specific information.
@@ -522,35 +609,16 @@ type ValidationError = BaseError & {
522
609
  };
523
610
 
524
611
  /**
525
- * A warning that occurred during token normalization.
526
- * Provides information about non-critical issues during the normalization process.
527
- */
528
- type NormalizationWarning = {
529
- /** The type of the warning */
530
- type: "warning";
531
- /** A human-readable message describing the warning */
532
- message: string;
533
- /** The file where the warning occurred */
534
- file: string;
535
- /** The collection where the warning occurred */
536
- collection: string;
537
- /** The theme where the warning occurred, if applicable */
538
- theme?: string;
539
- };
540
-
541
- /**
542
- * Result of running the tokens-to-CSS pipeline.
543
- * Contains the generated CSS files, token trees, and any errors or warnings.
612
+ * Result of running any pipeline.
613
+ * Contains the generated output, token trees, and any errors.
544
614
  */
545
- type TokensToCSSPipelineResult = {
546
- /** The generated CSS files */
615
+ type PipelineResult = {
616
+ /** The generated output (e.g. CSS files) */
547
617
  output: CSSFileOutput;
548
618
  /** The loaded token trees */
549
619
  trees: TokenTree[];
550
620
  /** Any errors that occurred during pipeline execution */
551
621
  errors: PipelineErrors;
552
- /** Any warnings that occurred during pipeline execution */
553
- warnings: PipelineWarnings;
554
622
  };
555
623
  /**
556
624
  * Common error types that can occur during pipeline execution.
@@ -567,455 +635,731 @@ type PipelineErrors = {
567
635
  resolution: ResolutionError[];
568
636
  };
569
637
  /**
570
- * Common warning types that can occur during pipeline execution.
571
- * Organizes warnings by the pipeline stage where they occurred.
638
+ * Defines how tokens should be loaded and processed.
639
+ * Either from files using a config, or from memory with token data.
572
640
  */
573
- type PipelineWarnings = {
574
- /** Warnings that occurred during token normalization */
575
- normalization: NormalizationWarning[];
576
- };
577
- /**
578
- * Result of running the validation pipeline.
579
- * Contains the validated token trees, flattened tokens, and resolved tokens.
580
- */
581
- type ValidationPipelineResult = {
582
- /** The loaded token trees */
583
- trees: TokenTree[];
584
- /** The flattened tokens */
585
- flattenedTokens: FlattenedTokens;
586
- /** The resolved tokens */
587
- resolved: ResolvedTokens;
588
- /** Any errors that occurred during pipeline execution */
589
- errors: PipelineErrors;
641
+ type TokenPipelineSource = {
642
+ type: "files";
643
+ config: InternalConfig;
644
+ } | {
645
+ type: "memory";
646
+ data: Record<string, {
647
+ collection: string;
648
+ content: string;
649
+ }>;
650
+ config: InternalConfig;
590
651
  };
591
652
  /**
592
- * Options for loading tokens in the validation pipeline.
653
+ * Options for loading tokens in the pipeline.
593
654
  * Specifies whether to load tokens from files or memory.
594
655
  */
595
656
  type TokenLoader = {
596
657
  type: "files";
597
- paths: SugarcubeConfig;
658
+ paths: InternalConfig;
598
659
  } | {
599
660
  type: "memory";
600
661
  data: TokenMemoryData;
601
662
  };
602
- /**
603
- * Options for configuring the validation pipeline.
604
- * Controls how tokens are loaded and processed.
605
- */
606
- type ValidationPipelineOptions = {
607
- /** The token loader configuration */
608
- loader: TokenLoader;
609
- };
610
- /**
611
- * Result of running the generation pipeline.
612
- * Contains the generated CSS files and any warnings.
613
- */
614
- type GenerationPipelineResult = {
615
- /** The generated CSS files */
616
- output: CSSFileOutput;
617
- /** Any warnings that occurred during pipeline execution */
618
- warnings: PipelineWarnings;
619
- };
620
663
 
621
664
  /**
622
- * The main pipeline that transforms design tokens into CSS output.
665
+ * Core token processing pipeline that handles loading, validation, and resolution of tokens.
666
+ * This is the foundation for all other token processing operations.
623
667
  *
624
- * This pipeline orchestrates the entire token processing flow:
668
+ * This pipeline:
625
669
  * 1. Loads token trees from config or memory
626
- * 2. Flattens trees into a single structure with source information
670
+ * 2. Flattens trees into a single structure
627
671
  * 3. Validates tokens for correctness
628
672
  * 4. Resolves all token references
629
- * 5. Processes trees into collections and themes
630
- * 6. Normalizes tokens into a standard format
631
- * 7. Converts tokens into CSS-ready format
632
- * 8. Generates final CSS output
633
673
  *
634
- * Each stage can produce errors or warnings, which are collected and returned
635
- * in the result. The pipeline stops at validation if any errors are found.
674
+ * Each stage can produce errors which are collected and returned in the result.
636
675
  *
637
- * @param config - The sugarcube configuration
638
- * @param options - Optional pipeline configuration including a custom token loader
639
- * @returns The pipeline result containing CSS output, trees, and any errors/warnings
676
+ * @param source - The source of tokens to process, either from memory or config
677
+ * @returns An object containing the processed trees, resolved tokens, and any errors
640
678
  *
641
679
  * @example
642
- * const result = await tokensToCSSPipeline(config);
680
+ * const result = await loadAndResolveTokens({ type: "config", config });
643
681
  * if (result.errors.validation.length > 0) {
644
682
  * console.error("Validation failed:", result.errors.validation);
645
- * } else {
646
- * // Use the generated CSS
647
- * console.log(result.output);
648
683
  * }
649
684
  */
650
- declare function tokensToCSSPipeline(config: SugarcubeConfig, options?: {
651
- loader?: TokenLoader;
652
- }): Promise<TokensToCSSPipelineResult>;
685
+ declare function loadAndResolveTokens(source: TokenPipelineSource): Promise<{
686
+ trees: TokenTree[];
687
+ resolved: ResolvedTokens;
688
+ errors: PipelineResult["errors"];
689
+ }>;
690
+
691
+ type NamedUtilityValue = {
692
+ kind: "named";
693
+ value: string;
694
+ fraction: string | null;
695
+ };
696
+ type ArbitraryUtilityValue = {
697
+ kind: "arbitrary";
698
+ value: string;
699
+ };
700
+ type UtilityValue = NamedUtilityValue | ArbitraryUtilityValue;
701
+ type StaticVariant = {
702
+ kind: "static";
703
+ root: string;
704
+ };
705
+ type FunctionalVariant = {
706
+ kind: "functional";
707
+ root: string;
708
+ value: UtilityValue;
709
+ };
710
+ type Variant = StaticVariant | FunctionalVariant;
711
+ type StaticCandidate = {
712
+ kind: "static";
713
+ root: string;
714
+ variants: Variant[];
715
+ raw: string;
716
+ };
717
+ type FunctionalCandidate = {
718
+ kind: "functional";
719
+ root: string;
720
+ value: UtilityValue | null;
721
+ variants: Variant[];
722
+ raw: string;
723
+ };
724
+ type Candidate = StaticCandidate | FunctionalCandidate;
725
+ interface StaticUtilityPattern {
726
+ properties: string[];
727
+ validator: (candidate: Candidate) => boolean;
728
+ generator: (candidate: Candidate) => string;
729
+ }
653
730
 
654
731
  /**
655
- * A pipeline that validates design tokens without generating CSS output.
656
- *
657
- * This pipeline performs the initial stages of token processing:
658
- * 1. Loads token trees from config or memory
659
- * 2. Flattens trees into a single structure with source information
660
- * 3. Validates tokens for correctness
661
- * 4. Resolves all token references
732
+ * Processes and converts token trees into CSS-ready format.
733
+ * This pipeline:
734
+ * 1. Processes trees with resolved tokens to create a unified structure
735
+ * 2. Normalizes tokens into a collection-theme organization
736
+ * 3. Converts tokens to their CSS representations with properties
662
737
  *
663
- * Unlike the main pipeline, this one doesn't generate CSS output.
664
- * It's useful for:
665
- * - Validating tokens before full processing
666
- * - Checking token references
667
- * - Debugging token structure issues
668
738
  *
739
+ * @param trees - The token trees to process
740
+ * @param resolved - The resolved tokens for processing
669
741
  * @param config - The sugarcube configuration
670
- * @param options - Pipeline options including the token loader configuration
671
- * @returns The validation result containing trees, tokens, and any errors
742
+ * @param validationErrors - Optional array of validation errors. Tokens with validation errors will be filtered out before conversion.
743
+ * @returns The processed and converted tokens ready for CSS generation
672
744
  *
673
745
  * @example
674
- * const result = await validationPipeline(config, {
675
- * loader: { type: "config" }
676
- * });
677
- *
678
- * if (result.errors.validation.length > 0) {
679
- * console.error("Token validation failed:", result.errors.validation);
680
- * } else {
681
- * console.log("All tokens are valid!");
682
- * }
746
+ * const convertedTokens = await processAndConvertTokens(trees, resolved, config);
747
+ * // convertedTokens = { collection: { theme: { "token.path": { $cssProperties: {...} } } } }
683
748
  */
684
- declare function validationPipeline(config: SugarcubeConfig, options: ValidationPipelineOptions): Promise<ValidationPipelineResult>;
749
+ declare function processAndConvertTokens(trees: TokenTree[], resolved: ResolvedTokens, config: InternalConfig, validationErrors?: ValidationError[]): Promise<NormalizedConvertedTokens>;
750
+
751
+ declare function generateIndex(stylesDir: string, config: InternalConfig): Promise<string>;
752
+ declare function shouldRegenerateIndex(stylesDir: string, config: InternalConfig): Promise<boolean>;
685
753
 
686
754
  /**
687
- * A pipeline that generates CSS from pre-validated tokens.
688
- *
689
- * This pipeline handles the final stages of token processing:
690
- * 1. Processes trees into collections and themes
691
- * 2. Normalizes tokens into a standard format
692
- * 3. Converts tokens into CSS-ready format
693
- * 4. Generates final CSS output
755
+ * Writes CSS files to disk, creating directories as needed.
694
756
  *
695
- * This pipeline exists to support workflows where you want to:
696
- * - Validate tokens, then generate CSS
757
+ * This function:
758
+ * 1. Creates any missing directories in the file path
759
+ * 2. Adds a warning banner to prevent direct edits
760
+ * 3. Only writes files if the content has changed
761
+ * 4. Handles both single and multiple CSS file outputs
697
762
  *
698
- * @param trees - The token trees to process
699
- * @param resolved - The resolved tokens to convert
700
- * @param configState - The sugarcube configuration
701
- * @returns The generation result containing CSS output and any warnings
763
+ * @param output - Array of CSS file outputs to write
764
+ * @returns The original output array
765
+ * @throws Error if file writing fails
702
766
  *
703
767
  * @example
704
- * // First validate tokens once
705
- * const validationResult = await validationPipeline(config, options);
706
- * if (validationResult.errors.validation.length > 0) {
707
- * throw new Error("Tokens failed validation");
708
- * }
768
+ * await writeCSSFilesToDisk([
769
+ * { path: "styles/tokens.css", css: "body { color: red; }" }
770
+ * ]);
771
+ */
772
+ declare function writeCSSVariablesToDisk(output: CSSFileOutput): Promise<CSSFileOutput>;
773
+ /**
774
+ * Writes utility CSS files to disk, creating directories as needed.
709
775
  *
710
- * // Generate CSS with different configs
711
- * const lightThemeConfig = { ...config, options: { color: "hex" } };
712
- * const darkThemeConfig = { ...config, options: { color: "rgb" } };
776
+ * This function:
777
+ * 1. Creates any missing directories in the file path
778
+ * 2. Adds a warning banner specific to utility classes
779
+ * 3. Only writes files if the content has changed
713
780
  *
714
- * const lightResult = await generationPipeline(
715
- * validationResult.trees,
716
- * validationResult.resolved,
717
- * lightThemeConfig
718
- * );
781
+ * @param output - The CSS file output to write
782
+ * @param config - The sugarcube configuration
783
+ * @returns The CSS file output that was written
784
+ * @throws Error if file writing fails
719
785
  *
720
- * const darkResult = await generationPipeline(
721
- * validationResult.trees,
722
- * validationResult.resolved,
723
- * darkThemeConfig
786
+ * @example
787
+ * await writeCSSUtilitiesToDisk(
788
+ * [{ path: "src/styles/utilities/utilities.css", css: ".p-4 { padding: var(--spacing-4); }" }],
789
+ * config
724
790
  * );
725
791
  */
726
- declare function generationPipeline(trees: TokenTree[], resolved: ResolvedTokens, configState: SugarcubeConfig): Promise<GenerationPipelineResult>;
792
+ declare function writeCSSUtilitiesToDisk(output: CSSFileOutput): Promise<CSSFileOutput>;
793
+
794
+ declare function findConfigFile(basePath?: string): string | null;
795
+ declare function configFileExists(basePath?: string): boolean;
796
+ declare function loadTSConfig(configPath: string): Promise<unknown>;
797
+ declare function loadUserConfig(configPath?: string): Promise<{
798
+ config: UserConfig;
799
+ configPath: string;
800
+ }>;
801
+ declare function loadInternalConfig(configPath?: string): Promise<LoadedConfig>;
727
802
 
728
803
  /**
729
- * Loads and validates the sugarcube configuration file from disk.
730
- *
731
- * This function:
732
- * 1. Reads the config file from the specified path
733
- * 2. Parses and validates the configuration
734
- * 3. Returns the validated configuration object
804
+ * Validates a user configuration object against the user schema.
735
805
  *
736
- * @param configPath - Path to the config file (default: "sugarcube.config.json")
737
- * @returns A promise that resolves to the validated configuration
738
- * @throws Error if the config file is not found or invalid
739
- *
740
- * @example
741
- * // Load default config file
742
- * const config = await loadConfig();
806
+ * @param config - The user configuration object to validate
807
+ * @returns The validated user configuration
808
+ * @throws Error if the configuration is invalid
809
+ */
810
+ declare function validateUserConfig(config: Partial<UserConfig>): UserConfig;
811
+ /**
812
+ * Validates an internal configuration object against the internal schema and checks for duplicate filenames.
743
813
  *
744
- * // Load custom config file
745
- * const config = await loadConfig("./config/sugarcube.json");
814
+ * @param config - The internal configuration object to validate
815
+ * @returns The validated internal configuration
816
+ * @throws Error if the configuration is invalid or contains duplicate filenames
746
817
  */
747
- declare function loadConfig(configPath?: string): Promise<SugarcubeConfig>;
748
-
818
+ declare function validateInternalConfig(config: InternalConfig): InternalConfig;
749
819
  /**
750
- * Validates a sugarcube configuration object against the schema.
820
+ * Validates a user configuration object against the schema and fills in defaults.
751
821
  *
752
822
  * This function:
753
- * 1. Validates the configuration structure using the schema
754
- * 2. Checks for duplicate filenames across collections
755
- * 3. Returns the validated configuration if successful
823
+ * 1. Validates the configuration structure using the user schema
824
+ * 2. Fills in default values
825
+ * 3. Validates the complete configuration using the internal schema
826
+ * 4. Checks for duplicate filenames across collections
827
+ * 5. Returns the validated configuration with defaults filled in
756
828
  *
757
- * @param config - The configuration object to validate
758
- * @returns The validated configuration
829
+ * @param config - The user configuration object to validate
830
+ * @returns The validated configuration with defaults filled in
759
831
  * @throws Error if the configuration is invalid or contains duplicate filenames
760
832
  *
761
833
  * @example
762
834
  * const config = {
763
835
  * tokens: {
764
- * source: ["tokens.json"],
765
- * type: "custom"
836
+ * source: ["tokens.json"]
766
837
  * }
767
838
  * };
768
839
  * const validatedConfig = validateConfig(config);
840
+ * // validatedConfig.output.css === "src/styles" (default filled in)
769
841
  */
770
- declare function validateConfig(config: Partial<SugarcubeConfig>): SugarcubeConfig;
842
+ declare function validateConfig(config: Partial<UserConfig>): InternalConfig;
771
843
  /**
772
844
  * Parses and validates a JSON configuration string.
773
845
  *
774
846
  * This function:
775
847
  * 1. Parses the JSON string into a configuration object
776
- * 2. Validates the configuration using validateConfig
777
- * 3. Returns the validated configuration if successful
848
+ * 2. Validates and normalizes the configuration using validateConfig
849
+ * 3. Returns the validated and normalized configuration
778
850
  *
779
851
  * @param configString - The JSON configuration string to parse and validate
780
- * @returns The validated configuration
852
+ * @returns The validated and normalized configuration
781
853
  * @throws Error if the JSON is invalid or the configuration is invalid
782
854
  *
783
855
  * @example
784
856
  * const configString = `{
785
857
  * "tokens": {
786
- * "source": ["tokens.json"],
787
- * "type": "custom"
858
+ * "source": ["tokens.json"]
788
859
  * }
789
860
  * }`;
790
861
  * const config = parseAndValidateConfig(configString);
862
+ * // config.output.css === "src/styles" (default filled in)
791
863
  */
792
- declare function parseAndValidateConfig(configString: string): SugarcubeConfig;
864
+ declare function parseAndValidateConfig(configString: string): InternalConfig;
793
865
 
794
866
  /**
795
- * Gets all token source file paths from the configuration.
796
- *
797
- * This function handles both single and multiple collection configurations:
798
- * - Single collection: Returns the source array directly
799
- * - Multiple collections: Flattens and returns all source paths from all collections
800
- *
801
- * @param config - The sugarcube configuration
802
- * @returns An array of all token source file paths
803
- *
804
- * @example
805
- * // Single collection
806
- * getTokenPathsFromConfig({ tokens: { source: ["tokens.json"] } })
807
- * // Returns: ["tokens.json"]
808
- *
809
- * // Multiple collections
810
- * getTokenPathsFromConfig({
811
- * tokens: {
812
- * base: { source: ["base.json"] },
813
- * ui: { source: ["ui.json"] }
814
- * }
815
- * })
816
- * // Returns: ["base.json", "ui.json"]
817
- */
818
- declare function getTokenPathsFromConfig(config: SugarcubeConfig): string[];
819
- /**
820
- * Writes CSS files to disk, creating directories as needed.
867
+ * Fills in default values for any omitted fields in a user configuration.
821
868
  *
822
- * This function:
823
- * 1. Creates any missing directories in the file path
824
- * 2. Optionally adds a warning banner to prevent direct edits
825
- * 3. Only writes files if the content has changed
826
- * 4. Handles both single and multiple CSS file outputs
869
+ * This function takes a user config (with optional fields) and
870
+ * returns a complete internal config (with all required fields filled in).
827
871
  *
828
- * @param output - Array of CSS file outputs to write
829
- * @param addBanner - Whether to add the warning banner (default: true)
830
- * @param tokenPaths - Optional array of token source paths for the warning banner
831
- * @returns The original output array
832
- * @throws Error if file writing fails
872
+ * @param userConfig - The user configuration with optional fields
873
+ * @returns A complete configuration with all defaults filled in
833
874
  *
834
875
  * @example
835
- * await writeCSSFilesToDisk([
836
- * { path: "styles/tokens.css", css: "body { color: red; }" }
837
- * ]);
876
+ * const userConfig = {
877
+ * tokens: { source: ["tokens/*.json"] }
878
+ * };
879
+ * const completeConfig = fillDefaults(userConfig);
880
+ * // completeConfig.output.css === "src/styles"
881
+ * // completeConfig.output.components === "src/ui/components"
882
+ * // completeConfig.output.separate === false
838
883
  */
839
- declare function writeCSSFilesToDisk(output: CSSFileOutput, addBanner?: boolean, tokenPaths?: string[]): Promise<CSSFileOutput>;
884
+ declare function fillDefaults(userConfig: UserConfig): InternalConfig;
840
885
 
841
- /**
842
- * Manages the CSS index file that imports all CSS files.
843
- * @param options.cssOutputDirectory - Directory where the index.css will be created/updated
844
- * @param options.files - CSS files to include in the index
845
- * @returns Path to the generated index file
846
- */
847
- declare function manageCSSIndex({ cssOutputDirectory, files, }: {
848
- cssOutputDirectory: string;
849
- files: string[];
850
- }): Promise<string>;
886
+ interface CSSImport {
887
+ path: string;
888
+ layer: string;
889
+ relativePath: string;
890
+ }
891
+ declare function discoverAllFiles(stylesDir: string, config: InternalConfig): Promise<CSSImport[]>;
851
892
 
852
- /**
853
- * Schema for configuration
854
- */
855
- declare const configSchema: z.ZodObject<{
856
- tokens: z.ZodUnion<[z.ZodObject<{
893
+ declare function generateIndexContent(files: CSSImport[]): string;
894
+
895
+ declare class Instrumentation implements Disposable {
896
+ #private;
897
+ private defaultFlush;
898
+ constructor(defaultFlush?: (message: string) => undefined);
899
+ hit(label: string): void;
900
+ start(label: string): void;
901
+ end(label: string): void;
902
+ report(flush?: (message: string) => undefined): void;
903
+ [Symbol.dispose](): void;
904
+ }
905
+
906
+ type CSSObject = Record<string, string | number | undefined>;
907
+ declare function convertConfigToUnoRules(utilitiesConfig: UtilitiesConfig, tokens: NormalizedConvertedTokens): Array<[RegExp, (m: RegExpMatchArray) => CSSObject]>;
908
+
909
+ declare const SUGARCUBE_FILE = "_sugarcube.css";
910
+ declare const GLOBAL_DIR = "global";
911
+ declare const UTILITIES_DIR = "utilities";
912
+ declare const VARIABLES_FILE_SUFFIX = ".variables.gen.css";
913
+ declare const DEFAULT_VARIABLES_FILENAME = "tokens";
914
+ declare const DEFAULT_UTILITIES_FILENAME = "utilities.gen.css";
915
+ declare const DEFAULT_STYLES_PATH = "src/styles";
916
+ declare const DEFAULT_DESIGN_TOKENS_PATH = "src/design-tokens";
917
+ declare const SUGARCUBE_CONFIG_FILE = "sugarcube.config.ts";
918
+
919
+ declare const DEFAULT_CONFIG: {
920
+ readonly output: {
921
+ readonly css: "src/styles";
922
+ readonly components: "src/components/ui";
923
+ readonly separate: false;
924
+ };
925
+ readonly transforms: {
926
+ readonly fluid: {
927
+ readonly min: 320;
928
+ readonly max: 1200;
929
+ };
930
+ readonly colorFallbackStrategy: "native";
931
+ };
932
+ };
933
+
934
+ declare const DEFAULT_COLLECTION = "default";
935
+ declare const DEFAULT_THEME = "default";
936
+
937
+ declare const ErrorMessages: {
938
+ readonly LOAD: {
939
+ readonly NO_FILES_FOUND: (pattern: string) => string;
940
+ readonly INVALID_JSON: (path: string, message: string) => string;
941
+ readonly GLOB_ERROR: (pattern: string, error: string) => string;
942
+ };
943
+ readonly FLATTEN: {
944
+ readonly INVALID_TOKEN_NAME: (name: string) => string;
945
+ readonly MISSING_DOLLAR_PREFIX: (path: string) => string;
946
+ readonly INVALID_TOKEN_NESTING: (path: string) => string;
947
+ readonly COMPOSITE_TOKEN_MISSING_TYPE: (path: string) => string;
948
+ readonly CONFLICT_TOKEN_VS_GROUP: (path: string) => string;
949
+ readonly CONFLICT_INCOMPATIBLE_TYPES: (expected: string, received: string, path: string) => string;
950
+ };
951
+ readonly METADATA: {
952
+ readonly COLLECTION_ERROR: (message: string) => string;
953
+ readonly INVALID_EXTENSIONS: (path: string) => string;
954
+ readonly INVALID_DESCRIPTION: (path: string) => string;
955
+ };
956
+ readonly VALIDATE: {
957
+ readonly MISSING_TYPE: (path: string) => string;
958
+ readonly UNKNOWN_TOKEN_TYPE: (type: string, path: string) => string;
959
+ readonly INVALID_COLOR: (value: unknown, path: string) => string;
960
+ readonly INVALID_DIMENSION: (value: unknown, path: string) => string;
961
+ readonly INVALID_DIMENSION_UNIT: (unit: unknown, path: string) => string;
962
+ readonly INVALID_FONT_FAMILY: (value: unknown, path: string) => string;
963
+ readonly INVALID_FONT_WEIGHT: (value: unknown, path: string) => string;
964
+ readonly INVALID_DURATION: (value: unknown, path: string) => string;
965
+ readonly INVALID_DURATION_UNIT: (unit: unknown, path: string) => string;
966
+ readonly INVALID_CUBIC_BEZIER: (value: unknown, path: string) => string;
967
+ readonly INVALID_STROKE_STYLE: (value: unknown, path: string) => string;
968
+ readonly INVALID_STROKE_LINE_CAP: (value: unknown, path: string) => string;
969
+ readonly INVALID_BORDER: (value: unknown, path: string) => string;
970
+ readonly INVALID_SHADOW: (value: unknown, path: string) => string;
971
+ readonly INVALID_SHADOW_INSET: (value: unknown, path: string) => string;
972
+ readonly INVALID_TRANSITION: (value: unknown, path: string) => string;
973
+ readonly INVALID_GRADIENT: (value: unknown, path: string) => string;
974
+ readonly INVALID_GRADIENT_STOP_POSITION: (value: unknown, path: string) => string;
975
+ readonly INVALID_TYPOGRAPHY: (value: unknown, path: string) => string;
976
+ readonly MISSING_REQUIRED_PROPERTY: (prop: string, path: string) => string;
977
+ readonly INVALID_NUMBER: (value: unknown, path: string) => string;
978
+ readonly INVALID_ARRAY: (value: unknown, path: string) => string;
979
+ readonly MISSING_FLUID_CONFIG: (path: string) => string;
980
+ readonly INVALID_FLUID_DIMENSION: (value: unknown, path: string) => string;
981
+ readonly INVALID_VIEWPORT_CONFIG: (value: unknown, path: string) => string;
982
+ readonly MISMATCHED_UNITS: (unit1: unknown, unit2: unknown, path: string) => string;
983
+ readonly INVALID_FLUID_VALUE_RANGE: (path: string) => string;
984
+ readonly INVALID_TOKEN_TYPE: (expected: string, received: string, path: string) => string;
985
+ readonly INVALID_TYPE: (expected: string, value: unknown, path: string) => string;
986
+ readonly INVALID_ENUM_VALUE: (enumValues: unknown[], value: unknown, path: string) => string;
987
+ };
988
+ readonly RESOLVE: {
989
+ readonly CIRCULAR_REFERENCE: (path: string, ref: string) => string;
990
+ readonly REFERENCE_NOT_FOUND: (ref: string, path: string) => string;
991
+ readonly TYPE_MISMATCH: (path: string) => string;
992
+ };
993
+ readonly GENERATE: {
994
+ readonly INVALID_CSS_VALUE: (key: string, value: unknown) => string;
995
+ readonly INVALID_VARIABLE_NAME: (path: string, name: string) => string;
996
+ };
997
+ readonly CONFIG: {
998
+ readonly INVALID_JSON: (error: string) => string;
999
+ readonly INVALID_CONFIG: (path: string, message: string) => string;
1000
+ readonly DUPLICATE_FILENAMES: (collection: string, filename: string, paths: string[]) => string;
1001
+ readonly FILE_NOT_FOUND: (path: string) => string;
1002
+ };
1003
+ readonly UTILITIES: {
1004
+ readonly RESERVED_PREFIX: (prefix: string, tokenType: string) => string;
1005
+ readonly DUPLICATE_CLASS_NAME: (className: string, paths: string[]) => string;
1006
+ readonly INVALID_PROPERTY_MAPPING: (tokenType: string) => string;
1007
+ readonly DUPLICATE_PREFIX: (prefix: string, tokenType: string) => string;
1008
+ readonly INVALID_COLLECTION: (property: string, collection: string, availableCollections: string[]) => string;
1009
+ readonly TOKEN_PATH_CONFLICT: (tokenPath: string, collections: string) => string;
1010
+ readonly MISSING_SOURCE: (property: string) => string;
1011
+ readonly INVALID_SOURCE_PATTERN: (property: string, source: string) => string;
1012
+ readonly INVALID_DIRECTIONS: (property: string) => string;
1013
+ readonly INVALID_CONFIG_OBJECT: "utilitiesConfig must be an object";
1014
+ readonly INVALID_TOKENS_OBJECT: "tokens must be an object";
1015
+ };
1016
+ };
1017
+
1018
+ declare const userConfigSchema: z.ZodObject<{
1019
+ tokens: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodObject<{
857
1020
  source: z.ZodArray<z.ZodString, "many">;
858
- type: z.ZodEnum<["starter-kit", "custom"]>;
859
1021
  themes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
860
1022
  }, "strip", z.ZodTypeAny, {
861
- type: "starter-kit" | "custom";
862
1023
  source: string[];
863
1024
  themes?: Record<string, string[]> | undefined;
864
1025
  }, {
865
- type: "starter-kit" | "custom";
866
1026
  source: string[];
867
1027
  themes?: Record<string, string[]> | undefined;
868
- }>, z.ZodRecord<z.ZodString, z.ZodObject<{
1028
+ }>>, z.ZodObject<{
869
1029
  source: z.ZodArray<z.ZodString, "many">;
870
- type: z.ZodEnum<["starter-kit", "custom"]>;
871
1030
  themes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
872
1031
  }, "strip", z.ZodTypeAny, {
873
- type: "starter-kit" | "custom";
874
1032
  source: string[];
875
1033
  themes?: Record<string, string[]> | undefined;
876
1034
  }, {
877
- type: "starter-kit" | "custom";
878
1035
  source: string[];
879
1036
  themes?: Record<string, string[]> | undefined;
880
- }>>]>;
881
- options: z.ZodOptional<z.ZodObject<{
1037
+ }>]>>;
1038
+ transforms: z.ZodOptional<z.ZodObject<{
882
1039
  fluid: z.ZodOptional<z.ZodObject<{
883
1040
  min: z.ZodNumber;
884
1041
  max: z.ZodNumber;
885
- }, "strict", z.ZodTypeAny, {
1042
+ }, "strip", z.ZodTypeAny, {
886
1043
  min: number;
887
1044
  max: number;
888
1045
  }, {
889
1046
  min: number;
890
1047
  max: number;
891
1048
  }>>;
892
- prefix: z.ZodOptional<z.ZodString>;
893
- color: z.ZodOptional<z.ZodEnum<["hex", "rgb", "rgba", "hsl", "hsla", "oklch", "p3"]>>;
1049
+ colorFallbackStrategy: z.ZodOptional<z.ZodEnum<["native", "polyfill"]>>;
894
1050
  }, "strip", z.ZodTypeAny, {
895
- color?: "hex" | "rgb" | "rgba" | "hsl" | "hsla" | "oklch" | "p3" | undefined;
896
1051
  fluid?: {
897
1052
  min: number;
898
1053
  max: number;
899
1054
  } | undefined;
900
- prefix?: string | undefined;
1055
+ colorFallbackStrategy?: "native" | "polyfill" | undefined;
901
1056
  }, {
902
- color?: "hex" | "rgb" | "rgba" | "hsl" | "hsla" | "oklch" | "p3" | undefined;
903
1057
  fluid?: {
904
1058
  min: number;
905
1059
  max: number;
906
1060
  } | undefined;
907
- prefix?: string | undefined;
1061
+ colorFallbackStrategy?: "native" | "polyfill" | undefined;
908
1062
  }>>;
909
- output: z.ZodObject<{
910
- directories: z.ZodObject<{
911
- tokens: z.ZodString;
912
- components: z.ZodOptional<z.ZodString>;
913
- css: z.ZodString;
914
- }, "strip", z.ZodTypeAny, {
915
- css: string;
916
- tokens: string;
917
- components?: string | undefined;
918
- }, {
919
- css: string;
920
- tokens: string;
921
- components?: string | undefined;
922
- }>;
923
- css: z.ZodObject<{
924
- separate: z.ZodBoolean;
925
- manageIndex: z.ZodOptional<z.ZodBoolean>;
926
- format: z.ZodOptional<z.ZodEnum<["css", "scss", "less"]>>;
927
- }, "strip", z.ZodTypeAny, {
928
- separate: boolean;
929
- manageIndex?: boolean | undefined;
930
- format?: "css" | "scss" | "less" | undefined;
931
- }, {
932
- separate: boolean;
933
- manageIndex?: boolean | undefined;
934
- format?: "css" | "scss" | "less" | undefined;
935
- }>;
1063
+ output: z.ZodOptional<z.ZodObject<{
1064
+ css: z.ZodOptional<z.ZodString>;
1065
+ components: z.ZodOptional<z.ZodString>;
1066
+ separate: z.ZodOptional<z.ZodBoolean>;
936
1067
  }, "strip", z.ZodTypeAny, {
937
- css: {
938
- separate: boolean;
939
- manageIndex?: boolean | undefined;
940
- format?: "css" | "scss" | "less" | undefined;
941
- };
942
- directories: {
943
- css: string;
944
- tokens: string;
945
- components?: string | undefined;
946
- };
1068
+ css?: string | undefined;
1069
+ components?: string | undefined;
1070
+ separate?: boolean | undefined;
947
1071
  }, {
948
- css: {
949
- separate: boolean;
950
- manageIndex?: boolean | undefined;
951
- format?: "css" | "scss" | "less" | undefined;
952
- };
953
- directories: {
954
- css: string;
955
- tokens: string;
956
- components?: string | undefined;
957
- };
958
- }>;
1072
+ css?: string | undefined;
1073
+ components?: string | undefined;
1074
+ separate?: boolean | undefined;
1075
+ }>>;
1076
+ utilities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
1077
+ source: z.ZodString;
1078
+ directions: z.ZodOptional<z.ZodUnion<[z.ZodEnum<["top", "right", "bottom", "left", "x", "y", "full", "all"]>, z.ZodArray<z.ZodEnum<["top", "right", "bottom", "left", "x", "y", "full", "all"]>, "many">]>>;
1079
+ prefix: z.ZodOptional<z.ZodString>;
1080
+ stripDuplicates: z.ZodOptional<z.ZodBoolean>;
1081
+ collection: z.ZodOptional<z.ZodString>;
1082
+ }, "strip", z.ZodTypeAny, {
1083
+ source: string;
1084
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1085
+ prefix?: string | undefined;
1086
+ stripDuplicates?: boolean | undefined;
1087
+ collection?: string | undefined;
1088
+ }, {
1089
+ source: string;
1090
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1091
+ prefix?: string | undefined;
1092
+ stripDuplicates?: boolean | undefined;
1093
+ collection?: string | undefined;
1094
+ }>, z.ZodArray<z.ZodObject<{
1095
+ source: z.ZodString;
1096
+ directions: z.ZodOptional<z.ZodUnion<[z.ZodEnum<["top", "right", "bottom", "left", "x", "y", "full", "all"]>, z.ZodArray<z.ZodEnum<["top", "right", "bottom", "left", "x", "y", "full", "all"]>, "many">]>>;
1097
+ prefix: z.ZodOptional<z.ZodString>;
1098
+ stripDuplicates: z.ZodOptional<z.ZodBoolean>;
1099
+ collection: z.ZodOptional<z.ZodString>;
1100
+ }, "strip", z.ZodTypeAny, {
1101
+ source: string;
1102
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1103
+ prefix?: string | undefined;
1104
+ stripDuplicates?: boolean | undefined;
1105
+ collection?: string | undefined;
1106
+ }, {
1107
+ source: string;
1108
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1109
+ prefix?: string | undefined;
1110
+ stripDuplicates?: boolean | undefined;
1111
+ collection?: string | undefined;
1112
+ }>, "many">]>>>;
959
1113
  }, "strip", z.ZodTypeAny, {
960
- tokens: {
961
- type: "starter-kit" | "custom";
1114
+ tokens?: {
962
1115
  source: string[];
963
1116
  themes?: Record<string, string[]> | undefined;
964
1117
  } | Record<string, {
965
- type: "starter-kit" | "custom";
966
1118
  source: string[];
967
1119
  themes?: Record<string, string[]> | undefined;
968
- }>;
969
- output: {
970
- css: {
971
- separate: boolean;
972
- manageIndex?: boolean | undefined;
973
- format?: "css" | "scss" | "less" | undefined;
974
- };
975
- directories: {
976
- css: string;
977
- tokens: string;
978
- components?: string | undefined;
979
- };
980
- };
981
- options?: {
982
- color?: "hex" | "rgb" | "rgba" | "hsl" | "hsla" | "oklch" | "p3" | undefined;
1120
+ }> | undefined;
1121
+ transforms?: {
983
1122
  fluid?: {
984
1123
  min: number;
985
1124
  max: number;
986
1125
  } | undefined;
987
- prefix?: string | undefined;
1126
+ colorFallbackStrategy?: "native" | "polyfill" | undefined;
988
1127
  } | undefined;
1128
+ output?: {
1129
+ css?: string | undefined;
1130
+ components?: string | undefined;
1131
+ separate?: boolean | undefined;
1132
+ } | undefined;
1133
+ utilities?: Record<string, {
1134
+ source: string;
1135
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1136
+ prefix?: string | undefined;
1137
+ stripDuplicates?: boolean | undefined;
1138
+ collection?: string | undefined;
1139
+ } | {
1140
+ source: string;
1141
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1142
+ prefix?: string | undefined;
1143
+ stripDuplicates?: boolean | undefined;
1144
+ collection?: string | undefined;
1145
+ }[]> | undefined;
989
1146
  }, {
990
- tokens: {
991
- type: "starter-kit" | "custom";
1147
+ tokens?: {
992
1148
  source: string[];
993
1149
  themes?: Record<string, string[]> | undefined;
994
1150
  } | Record<string, {
995
- type: "starter-kit" | "custom";
996
1151
  source: string[];
997
1152
  themes?: Record<string, string[]> | undefined;
1153
+ }> | undefined;
1154
+ transforms?: {
1155
+ fluid?: {
1156
+ min: number;
1157
+ max: number;
1158
+ } | undefined;
1159
+ colorFallbackStrategy?: "native" | "polyfill" | undefined;
1160
+ } | undefined;
1161
+ output?: {
1162
+ css?: string | undefined;
1163
+ components?: string | undefined;
1164
+ separate?: boolean | undefined;
1165
+ } | undefined;
1166
+ utilities?: Record<string, {
1167
+ source: string;
1168
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1169
+ prefix?: string | undefined;
1170
+ stripDuplicates?: boolean | undefined;
1171
+ collection?: string | undefined;
1172
+ } | {
1173
+ source: string;
1174
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1175
+ prefix?: string | undefined;
1176
+ stripDuplicates?: boolean | undefined;
1177
+ collection?: string | undefined;
1178
+ }[]> | undefined;
1179
+ }>;
1180
+ declare const internalConfigSchema: z.ZodObject<{
1181
+ tokens: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodObject<{
1182
+ source: z.ZodArray<z.ZodString, "many">;
1183
+ themes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
1184
+ }, "strip", z.ZodTypeAny, {
1185
+ source: string[];
1186
+ themes?: Record<string, string[]> | undefined;
1187
+ }, {
1188
+ source: string[];
1189
+ themes?: Record<string, string[]> | undefined;
1190
+ }>>, z.ZodObject<{
1191
+ source: z.ZodArray<z.ZodString, "many">;
1192
+ themes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
1193
+ }, "strip", z.ZodTypeAny, {
1194
+ source: string[];
1195
+ themes?: Record<string, string[]> | undefined;
1196
+ }, {
1197
+ source: string[];
1198
+ themes?: Record<string, string[]> | undefined;
1199
+ }>]>>;
1200
+ transforms: z.ZodObject<{
1201
+ fluid: z.ZodObject<{
1202
+ min: z.ZodNumber;
1203
+ max: z.ZodNumber;
1204
+ }, "strip", z.ZodTypeAny, {
1205
+ min: number;
1206
+ max: number;
1207
+ }, {
1208
+ min: number;
1209
+ max: number;
1210
+ }>;
1211
+ colorFallbackStrategy: z.ZodEnum<["native", "polyfill"]>;
1212
+ }, "strip", z.ZodTypeAny, {
1213
+ fluid: {
1214
+ min: number;
1215
+ max: number;
1216
+ };
1217
+ colorFallbackStrategy: "native" | "polyfill";
1218
+ }, {
1219
+ fluid: {
1220
+ min: number;
1221
+ max: number;
1222
+ };
1223
+ colorFallbackStrategy: "native" | "polyfill";
998
1224
  }>;
1225
+ output: z.ZodObject<{
1226
+ css: z.ZodString;
1227
+ components: z.ZodString;
1228
+ separate: z.ZodBoolean;
1229
+ }, "strip", z.ZodTypeAny, {
1230
+ components: string;
1231
+ css: string;
1232
+ separate: boolean;
1233
+ }, {
1234
+ components: string;
1235
+ css: string;
1236
+ separate: boolean;
1237
+ }>;
1238
+ utilities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
1239
+ source: z.ZodString;
1240
+ directions: z.ZodOptional<z.ZodUnion<[z.ZodEnum<["top", "right", "bottom", "left", "x", "y", "full", "all"]>, z.ZodArray<z.ZodEnum<["top", "right", "bottom", "left", "x", "y", "full", "all"]>, "many">]>>;
1241
+ prefix: z.ZodOptional<z.ZodString>;
1242
+ stripDuplicates: z.ZodOptional<z.ZodBoolean>;
1243
+ collection: z.ZodOptional<z.ZodString>;
1244
+ }, "strip", z.ZodTypeAny, {
1245
+ source: string;
1246
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1247
+ prefix?: string | undefined;
1248
+ stripDuplicates?: boolean | undefined;
1249
+ collection?: string | undefined;
1250
+ }, {
1251
+ source: string;
1252
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1253
+ prefix?: string | undefined;
1254
+ stripDuplicates?: boolean | undefined;
1255
+ collection?: string | undefined;
1256
+ }>, z.ZodArray<z.ZodObject<{
1257
+ source: z.ZodString;
1258
+ directions: z.ZodOptional<z.ZodUnion<[z.ZodEnum<["top", "right", "bottom", "left", "x", "y", "full", "all"]>, z.ZodArray<z.ZodEnum<["top", "right", "bottom", "left", "x", "y", "full", "all"]>, "many">]>>;
1259
+ prefix: z.ZodOptional<z.ZodString>;
1260
+ stripDuplicates: z.ZodOptional<z.ZodBoolean>;
1261
+ collection: z.ZodOptional<z.ZodString>;
1262
+ }, "strip", z.ZodTypeAny, {
1263
+ source: string;
1264
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1265
+ prefix?: string | undefined;
1266
+ stripDuplicates?: boolean | undefined;
1267
+ collection?: string | undefined;
1268
+ }, {
1269
+ source: string;
1270
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1271
+ prefix?: string | undefined;
1272
+ stripDuplicates?: boolean | undefined;
1273
+ collection?: string | undefined;
1274
+ }>, "many">]>>>;
1275
+ }, "strip", z.ZodTypeAny, {
999
1276
  output: {
1000
- css: {
1001
- separate: boolean;
1002
- manageIndex?: boolean | undefined;
1003
- format?: "css" | "scss" | "less" | undefined;
1004
- };
1005
- directories: {
1006
- css: string;
1007
- tokens: string;
1008
- components?: string | undefined;
1277
+ components: string;
1278
+ css: string;
1279
+ separate: boolean;
1280
+ };
1281
+ transforms: {
1282
+ fluid: {
1283
+ min: number;
1284
+ max: number;
1009
1285
  };
1286
+ colorFallbackStrategy: "native" | "polyfill";
1010
1287
  };
1011
- options?: {
1012
- color?: "hex" | "rgb" | "rgba" | "hsl" | "hsla" | "oklch" | "p3" | undefined;
1013
- fluid?: {
1288
+ tokens?: {
1289
+ source: string[];
1290
+ themes?: Record<string, string[]> | undefined;
1291
+ } | Record<string, {
1292
+ source: string[];
1293
+ themes?: Record<string, string[]> | undefined;
1294
+ }> | undefined;
1295
+ utilities?: Record<string, {
1296
+ source: string;
1297
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1298
+ prefix?: string | undefined;
1299
+ stripDuplicates?: boolean | undefined;
1300
+ collection?: string | undefined;
1301
+ } | {
1302
+ source: string;
1303
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1304
+ prefix?: string | undefined;
1305
+ stripDuplicates?: boolean | undefined;
1306
+ collection?: string | undefined;
1307
+ }[]> | undefined;
1308
+ }, {
1309
+ output: {
1310
+ components: string;
1311
+ css: string;
1312
+ separate: boolean;
1313
+ };
1314
+ transforms: {
1315
+ fluid: {
1014
1316
  min: number;
1015
1317
  max: number;
1016
- } | undefined;
1318
+ };
1319
+ colorFallbackStrategy: "native" | "polyfill";
1320
+ };
1321
+ tokens?: {
1322
+ source: string[];
1323
+ themes?: Record<string, string[]> | undefined;
1324
+ } | Record<string, {
1325
+ source: string[];
1326
+ themes?: Record<string, string[]> | undefined;
1327
+ }> | undefined;
1328
+ utilities?: Record<string, {
1329
+ source: string;
1330
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1017
1331
  prefix?: string | undefined;
1018
- } | undefined;
1332
+ stripDuplicates?: boolean | undefined;
1333
+ collection?: string | undefined;
1334
+ } | {
1335
+ source: string;
1336
+ directions?: "top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all" | ("top" | "right" | "bottom" | "left" | "x" | "y" | "full" | "all")[] | undefined;
1337
+ prefix?: string | undefined;
1338
+ stripDuplicates?: boolean | undefined;
1339
+ collection?: string | undefined;
1340
+ }[]> | undefined;
1019
1341
  }>;
1020
1342
 
1021
- export { type ResolvedToken, type ResolvedTokens, type SugarcubeConfig, type TokenCollection, type TokenLoader, type TokenTree, type ValidationPipelineResult, configSchema, generationPipeline, getTokenPathsFromConfig, loadConfig, manageCSSIndex, parseAndValidateConfig, tokensToCSSPipeline, validateConfig, validationPipeline, writeCSSFilesToDisk };
1343
+ /**
1344
+ * Type guards for configuration objects.
1345
+ * Functions to check the structure and type of configuration data.
1346
+ */
1347
+ /**
1348
+ * Type guard to check if tokens is a single collection.
1349
+ *
1350
+ * @param tokens - The tokens configuration to check
1351
+ * @returns True if tokens is a single collection, false if it's multiple collections
1352
+ *
1353
+ * @example
1354
+ * if (isSingleCollection(config.tokens)) {
1355
+ * // config.tokens is TokenCollection
1356
+ * } else {
1357
+ * // config.tokens is TokenCollections
1358
+ * }
1359
+ */
1360
+ declare function isSingleCollection(tokens: TokenCollection | TokenCollections): tokens is TokenCollection;
1361
+
1362
+ declare function isResolvedToken(token: unknown): token is ResolvedToken;
1363
+ declare function isResolvedTokenOfType<T extends TokenType>(token: unknown, type: T): token is ResolvedToken<T>;
1364
+
1365
+ export { type ArbitraryUtilityValue, type CSSFileOutput, type Candidate, DEFAULT_COLLECTION, DEFAULT_CONFIG, DEFAULT_DESIGN_TOKENS_PATH, DEFAULT_STYLES_PATH, DEFAULT_THEME, DEFAULT_UTILITIES_FILENAME, DEFAULT_VARIABLES_FILENAME, ErrorMessages, type FunctionalCandidate, type FunctionalVariant, GLOBAL_DIR, Instrumentation, type InternalConfig, type LoadedConfig, type NamedUtilityValue, type NormalizedConvertedTokens, type OutputConfig, type PipelineResult, type ResolvedToken, type ResolvedTokens, SUGARCUBE_CONFIG_FILE, SUGARCUBE_FILE, type StaticCandidate, type StaticUtilityPattern, type StaticVariant, type TokenCollection, type TokenCollections, type TokenLoader, type TokenPipelineSource, type TokenTree, UTILITIES_DIR, type UserConfig, type UserOutputConfig, type UtilitiesConfig, type UtilityValue, VARIABLES_FILE_SUFFIX, type Variant, configFileExists, convertConfigToUnoRules, discoverAllFiles, fillDefaults, findConfigFile, generateCSSVariables, generateIndex, generateIndexContent, internalConfigSchema, isResolvedToken, isResolvedTokenOfType, isSingleCollection, loadAndResolveTokens, loadInternalConfig, loadTSConfig, loadUserConfig, parseAndValidateConfig, processAndConvertTokens, shouldRegenerateIndex, userConfigSchema, validateConfig, validateInternalConfig, validateUserConfig, writeCSSUtilitiesToDisk, writeCSSVariablesToDisk };