@sugarcube-org/core 0.0.1-alpha.3 → 0.0.1-alpha.4
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 +286 -11
- package/dist/index.js +17 -7
- package/package.json +11 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
1
3
|
type ColorFormat = "hex" | "rgb" | "rgba" | "hsl" | "hsla" | "oklch" | "p3";
|
|
2
4
|
type ColorConfig = {
|
|
3
5
|
format?: ColorFormat;
|
|
@@ -23,6 +25,14 @@ type DirectoriesConfig = {
|
|
|
23
25
|
css: string;
|
|
24
26
|
};
|
|
25
27
|
type CSSOutputConfig = {
|
|
28
|
+
/**
|
|
29
|
+
* Controls how CSS variables are organized in output files:
|
|
30
|
+
* - When false: Generates one file per collection, combining all tokens within each collection
|
|
31
|
+
* (e.g., base/tokens.variables.css, ui/tokens.variables.css)
|
|
32
|
+
* - When true: Generates separate files by token type within each collection
|
|
33
|
+
* (e.g., base/colors.variables.css, base/space.variables.css)
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
26
36
|
separate: boolean;
|
|
27
37
|
manageIndex?: boolean;
|
|
28
38
|
format?: "css" | "scss" | "less";
|
|
@@ -41,8 +51,8 @@ interface SugarcubeConfig {
|
|
|
41
51
|
* Represents a single CSS file output with its name and content
|
|
42
52
|
*/
|
|
43
53
|
type CSSFile = {
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
path: string;
|
|
55
|
+
css: string;
|
|
46
56
|
};
|
|
47
57
|
/**
|
|
48
58
|
* Represents the output from generateCSS which always returns exactly one file
|
|
@@ -92,12 +102,15 @@ type Token = NodeMetadata & {
|
|
|
92
102
|
$type?: TokenType;
|
|
93
103
|
};
|
|
94
104
|
/**
|
|
95
|
-
* A group of tokens that can be nested
|
|
105
|
+
* A group of tokens that can be nested. The type allows for:
|
|
106
|
+
* - Regular token properties (non-$ prefixed) which must be Token | TokenGroup
|
|
107
|
+
* - Metadata properties from NodeMetadata (like $description, $extensions)
|
|
108
|
+
* - $type property for type inheritance as specified in the W3C spec
|
|
109
|
+
* - undefined to support optional metadata properties
|
|
96
110
|
*/
|
|
97
|
-
type TokenGroup = {
|
|
98
|
-
[key: string]: Token | TokenGroup;
|
|
99
|
-
} & NodeMetadata & {
|
|
111
|
+
type TokenGroup = NodeMetadata & {
|
|
100
112
|
$type?: TokenType;
|
|
113
|
+
[key: string]: Token | TokenGroup | TokenType | undefined;
|
|
101
114
|
};
|
|
102
115
|
/**
|
|
103
116
|
* All possible token types, either simple or composite
|
|
@@ -277,10 +290,13 @@ type FlattenedToken<T extends TokenType = TokenType> = NodeMetadata & {
|
|
|
277
290
|
$originalPath: string;
|
|
278
291
|
};
|
|
279
292
|
/**
|
|
280
|
-
* A map of flattened tokens and metadata by their lookup path
|
|
293
|
+
* A map of flattened tokens and metadata by their lookup path, with an index for quick reference lookups
|
|
281
294
|
*/
|
|
282
295
|
type FlattenedTokens = {
|
|
283
|
-
|
|
296
|
+
tokens: {
|
|
297
|
+
[lookupKey: string]: FlattenedToken | NodeMetadata;
|
|
298
|
+
};
|
|
299
|
+
pathIndex: Map<string, string>;
|
|
284
300
|
};
|
|
285
301
|
/**
|
|
286
302
|
* An error that occurred during token flattening
|
|
@@ -446,7 +462,9 @@ type GenerationPipelineResult = {
|
|
|
446
462
|
warnings: PipelineWarnings;
|
|
447
463
|
};
|
|
448
464
|
|
|
449
|
-
declare function tokensToCSSPipeline(config: SugarcubeConfig
|
|
465
|
+
declare function tokensToCSSPipeline(config: SugarcubeConfig, options?: {
|
|
466
|
+
loader?: TokenLoader;
|
|
467
|
+
}): Promise<TokensToCSSPipelineResult>;
|
|
450
468
|
|
|
451
469
|
declare function validationPipeline(config: SugarcubeConfig, options: ValidationPipelineOptions): Promise<ValidationPipelineResult>;
|
|
452
470
|
|
|
@@ -477,6 +495,10 @@ type ProcessedTree = {
|
|
|
477
495
|
tokens: ResolvedTokens;
|
|
478
496
|
};
|
|
479
497
|
|
|
498
|
+
/**
|
|
499
|
+
* Process token trees by filtering resolved tokens based on collection and theme.
|
|
500
|
+
* Uses a two-level index (collection -> theme) for O(1) lookups.
|
|
501
|
+
*/
|
|
480
502
|
declare function processTrees(trees: TokenTree[], resolved: ResolvedTokens): ProcessedTree[];
|
|
481
503
|
|
|
482
504
|
/**
|
|
@@ -550,12 +572,265 @@ type CSSTransitionProperties = {
|
|
|
550
572
|
|
|
551
573
|
declare function convert(tokens: NormalizedTokens, config: SugarcubeConfig): NormalizedConvertedTokens;
|
|
552
574
|
|
|
575
|
+
/**
|
|
576
|
+
* Normalizes processed token trees into a collection-theme-token structure.
|
|
577
|
+
*
|
|
578
|
+
* This stage:
|
|
579
|
+
* 1. Organizes tokens by collection and theme
|
|
580
|
+
* 2. Removes collection prefixes from token keys (e.g., "default.color.primary" -> "color.primary")
|
|
581
|
+
* 3. Preserves metadata nodes
|
|
582
|
+
* 4. Maintains theme isolation (tokens only appear in their specified theme)
|
|
583
|
+
*
|
|
584
|
+
* The output structure is:
|
|
585
|
+
* {
|
|
586
|
+
* [collection]: {
|
|
587
|
+
* [theme]: {
|
|
588
|
+
* [tokenKey]: Token
|
|
589
|
+
* }
|
|
590
|
+
* }
|
|
591
|
+
* }
|
|
592
|
+
*
|
|
593
|
+
* For example:
|
|
594
|
+
* {
|
|
595
|
+
* default: {
|
|
596
|
+
* default: { "color.primary": { $value: "#FF0000" } },
|
|
597
|
+
* dark: { "color.primary": { $value: "#000000" } }
|
|
598
|
+
* },
|
|
599
|
+
* components: {
|
|
600
|
+
* default: { "button.primary": { $value: "#00FF00" } }
|
|
601
|
+
* }
|
|
602
|
+
* }
|
|
603
|
+
*/
|
|
553
604
|
declare function normalizeTokens(trees: ProcessedTree[]): NormalizeResult;
|
|
554
605
|
|
|
555
606
|
/**
|
|
556
607
|
* Generates CSS variable files from normalized and converted design tokens.
|
|
557
|
-
*
|
|
608
|
+
* Output organization is controlled by config.output.css.separate:
|
|
609
|
+
*
|
|
610
|
+
* When separate=false (default):
|
|
611
|
+
* - Generates one file per collection
|
|
612
|
+
* - Each collection's tokens are combined into a single file named 'tokens.variables.css'
|
|
613
|
+
* - Example for collections 'base' and 'ui':
|
|
614
|
+
* - base/tokens.variables.css
|
|
615
|
+
* - ui/tokens.variables.css
|
|
616
|
+
*
|
|
617
|
+
* When separate=true:
|
|
618
|
+
* - Generates multiple files per collection, based on source filenames
|
|
619
|
+
* - Files are organized in directories by collection name
|
|
620
|
+
* - Example for collection 'base' with source 'base.json' and collection 'ui' with source 'ui.json':
|
|
621
|
+
* - base/base.variables.css
|
|
622
|
+
* - ui/ui.variables.css
|
|
623
|
+
*
|
|
624
|
+
* Note: Each collection gets its own directory regardless of the 'separate' setting.
|
|
625
|
+
* This maintains a clear separation between different token collections.
|
|
558
626
|
*/
|
|
559
627
|
declare function generate(tokens: NormalizedConvertedTokens, config: SugarcubeConfig): Promise<CSSGenerationResult>;
|
|
560
628
|
|
|
561
|
-
|
|
629
|
+
/**
|
|
630
|
+
* Adds a warning banner to generated CSS content
|
|
631
|
+
*/
|
|
632
|
+
declare function addWarningBanner(cssContent: string): string;
|
|
633
|
+
/**
|
|
634
|
+
* Gets the token file paths from config for use in warning banners
|
|
635
|
+
*/
|
|
636
|
+
declare function getTokenPathsFromConfig(config: SugarcubeConfig): string[];
|
|
637
|
+
/**
|
|
638
|
+
* Writes CSS files to disk with directory creation
|
|
639
|
+
*/
|
|
640
|
+
declare function writeCSSFilesToDisk(output: CSSFileOutput, addBanner?: boolean, tokenPaths?: string[]): Promise<CSSFileOutput>;
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Validates the configuration object against the schema
|
|
644
|
+
*/
|
|
645
|
+
declare function validateConfig(config: Partial<SugarcubeConfig>): SugarcubeConfig;
|
|
646
|
+
/**
|
|
647
|
+
* Parses and validates a JSON configuration string
|
|
648
|
+
*/
|
|
649
|
+
declare function parseAndValidateConfig(configString: string): SugarcubeConfig;
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Loads and validates the config file from disk
|
|
653
|
+
*/
|
|
654
|
+
declare function loadConfig(configPath?: string): Promise<SugarcubeConfig>;
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Manages the CSS index file that imports all CSS files.
|
|
658
|
+
* @param options.cssOutputDirectory - Directory where the index.css will be created/updated
|
|
659
|
+
* @param options.files - CSS files to include in the index
|
|
660
|
+
* @returns Path to the generated index file
|
|
661
|
+
*/
|
|
662
|
+
declare function manageCSSIndex({ cssOutputDirectory, files, }: {
|
|
663
|
+
cssOutputDirectory: string;
|
|
664
|
+
files: string[];
|
|
665
|
+
}): Promise<string>;
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Schema for configuration
|
|
669
|
+
*/
|
|
670
|
+
declare const configSchema: z.ZodObject<{
|
|
671
|
+
tokens: z.ZodUnion<[z.ZodObject<{
|
|
672
|
+
source: z.ZodArray<z.ZodString, "many">;
|
|
673
|
+
type: z.ZodEnum<["starter-kit", "custom"]>;
|
|
674
|
+
themes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
|
|
675
|
+
}, "strip", z.ZodTypeAny, {
|
|
676
|
+
source: string[];
|
|
677
|
+
type: "starter-kit" | "custom";
|
|
678
|
+
themes?: Record<string, string[]> | undefined;
|
|
679
|
+
}, {
|
|
680
|
+
source: string[];
|
|
681
|
+
type: "starter-kit" | "custom";
|
|
682
|
+
themes?: Record<string, string[]> | undefined;
|
|
683
|
+
}>, z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
684
|
+
source: z.ZodArray<z.ZodString, "many">;
|
|
685
|
+
type: z.ZodEnum<["starter-kit", "custom"]>;
|
|
686
|
+
themes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
|
|
687
|
+
}, "strip", z.ZodTypeAny, {
|
|
688
|
+
source: string[];
|
|
689
|
+
type: "starter-kit" | "custom";
|
|
690
|
+
themes?: Record<string, string[]> | undefined;
|
|
691
|
+
}, {
|
|
692
|
+
source: string[];
|
|
693
|
+
type: "starter-kit" | "custom";
|
|
694
|
+
themes?: Record<string, string[]> | undefined;
|
|
695
|
+
}>>]>;
|
|
696
|
+
options: z.ZodOptional<z.ZodObject<{
|
|
697
|
+
fluid: z.ZodOptional<z.ZodObject<{
|
|
698
|
+
min: z.ZodNumber;
|
|
699
|
+
max: z.ZodNumber;
|
|
700
|
+
}, "strict", z.ZodTypeAny, {
|
|
701
|
+
min: number;
|
|
702
|
+
max: number;
|
|
703
|
+
}, {
|
|
704
|
+
min: number;
|
|
705
|
+
max: number;
|
|
706
|
+
}>>;
|
|
707
|
+
prefix: z.ZodOptional<z.ZodString>;
|
|
708
|
+
color: z.ZodOptional<z.ZodEnum<["hex", "rgb", "rgba", "hsl", "hsla", "oklch", "p3"]>>;
|
|
709
|
+
}, "strip", z.ZodTypeAny, {
|
|
710
|
+
color?: "hex" | "rgb" | "rgba" | "hsl" | "hsla" | "oklch" | "p3" | undefined;
|
|
711
|
+
fluid?: {
|
|
712
|
+
min: number;
|
|
713
|
+
max: number;
|
|
714
|
+
} | undefined;
|
|
715
|
+
prefix?: string | undefined;
|
|
716
|
+
}, {
|
|
717
|
+
color?: "hex" | "rgb" | "rgba" | "hsl" | "hsla" | "oklch" | "p3" | undefined;
|
|
718
|
+
fluid?: {
|
|
719
|
+
min: number;
|
|
720
|
+
max: number;
|
|
721
|
+
} | undefined;
|
|
722
|
+
prefix?: string | undefined;
|
|
723
|
+
}>>;
|
|
724
|
+
output: z.ZodObject<{
|
|
725
|
+
directories: z.ZodObject<{
|
|
726
|
+
tokens: z.ZodString;
|
|
727
|
+
components: z.ZodOptional<z.ZodString>;
|
|
728
|
+
css: z.ZodString;
|
|
729
|
+
}, "strip", z.ZodTypeAny, {
|
|
730
|
+
css: string;
|
|
731
|
+
tokens: string;
|
|
732
|
+
components?: string | undefined;
|
|
733
|
+
}, {
|
|
734
|
+
css: string;
|
|
735
|
+
tokens: string;
|
|
736
|
+
components?: string | undefined;
|
|
737
|
+
}>;
|
|
738
|
+
css: z.ZodObject<{
|
|
739
|
+
separate: z.ZodBoolean;
|
|
740
|
+
manageIndex: z.ZodOptional<z.ZodBoolean>;
|
|
741
|
+
format: z.ZodOptional<z.ZodEnum<["css", "scss", "less"]>>;
|
|
742
|
+
}, "strip", z.ZodTypeAny, {
|
|
743
|
+
separate: boolean;
|
|
744
|
+
manageIndex?: boolean | undefined;
|
|
745
|
+
format?: "css" | "scss" | "less" | undefined;
|
|
746
|
+
}, {
|
|
747
|
+
separate: boolean;
|
|
748
|
+
manageIndex?: boolean | undefined;
|
|
749
|
+
format?: "css" | "scss" | "less" | undefined;
|
|
750
|
+
}>;
|
|
751
|
+
}, "strip", z.ZodTypeAny, {
|
|
752
|
+
css: {
|
|
753
|
+
separate: boolean;
|
|
754
|
+
manageIndex?: boolean | undefined;
|
|
755
|
+
format?: "css" | "scss" | "less" | undefined;
|
|
756
|
+
};
|
|
757
|
+
directories: {
|
|
758
|
+
css: string;
|
|
759
|
+
tokens: string;
|
|
760
|
+
components?: string | undefined;
|
|
761
|
+
};
|
|
762
|
+
}, {
|
|
763
|
+
css: {
|
|
764
|
+
separate: boolean;
|
|
765
|
+
manageIndex?: boolean | undefined;
|
|
766
|
+
format?: "css" | "scss" | "less" | undefined;
|
|
767
|
+
};
|
|
768
|
+
directories: {
|
|
769
|
+
css: string;
|
|
770
|
+
tokens: string;
|
|
771
|
+
components?: string | undefined;
|
|
772
|
+
};
|
|
773
|
+
}>;
|
|
774
|
+
}, "strip", z.ZodTypeAny, {
|
|
775
|
+
tokens: {
|
|
776
|
+
source: string[];
|
|
777
|
+
type: "starter-kit" | "custom";
|
|
778
|
+
themes?: Record<string, string[]> | undefined;
|
|
779
|
+
} | Record<string, {
|
|
780
|
+
source: string[];
|
|
781
|
+
type: "starter-kit" | "custom";
|
|
782
|
+
themes?: Record<string, string[]> | undefined;
|
|
783
|
+
}>;
|
|
784
|
+
output: {
|
|
785
|
+
css: {
|
|
786
|
+
separate: boolean;
|
|
787
|
+
manageIndex?: boolean | undefined;
|
|
788
|
+
format?: "css" | "scss" | "less" | undefined;
|
|
789
|
+
};
|
|
790
|
+
directories: {
|
|
791
|
+
css: string;
|
|
792
|
+
tokens: string;
|
|
793
|
+
components?: string | undefined;
|
|
794
|
+
};
|
|
795
|
+
};
|
|
796
|
+
options?: {
|
|
797
|
+
color?: "hex" | "rgb" | "rgba" | "hsl" | "hsla" | "oklch" | "p3" | undefined;
|
|
798
|
+
fluid?: {
|
|
799
|
+
min: number;
|
|
800
|
+
max: number;
|
|
801
|
+
} | undefined;
|
|
802
|
+
prefix?: string | undefined;
|
|
803
|
+
} | undefined;
|
|
804
|
+
}, {
|
|
805
|
+
tokens: {
|
|
806
|
+
source: string[];
|
|
807
|
+
type: "starter-kit" | "custom";
|
|
808
|
+
themes?: Record<string, string[]> | undefined;
|
|
809
|
+
} | Record<string, {
|
|
810
|
+
source: string[];
|
|
811
|
+
type: "starter-kit" | "custom";
|
|
812
|
+
themes?: Record<string, string[]> | undefined;
|
|
813
|
+
}>;
|
|
814
|
+
output: {
|
|
815
|
+
css: {
|
|
816
|
+
separate: boolean;
|
|
817
|
+
manageIndex?: boolean | undefined;
|
|
818
|
+
format?: "css" | "scss" | "less" | undefined;
|
|
819
|
+
};
|
|
820
|
+
directories: {
|
|
821
|
+
css: string;
|
|
822
|
+
tokens: string;
|
|
823
|
+
components?: string | undefined;
|
|
824
|
+
};
|
|
825
|
+
};
|
|
826
|
+
options?: {
|
|
827
|
+
color?: "hex" | "rgb" | "rgba" | "hsl" | "hsla" | "oklch" | "p3" | undefined;
|
|
828
|
+
fluid?: {
|
|
829
|
+
min: number;
|
|
830
|
+
max: number;
|
|
831
|
+
} | undefined;
|
|
832
|
+
prefix?: string | undefined;
|
|
833
|
+
} | undefined;
|
|
834
|
+
}>;
|
|
835
|
+
|
|
836
|
+
export { type CSSFileOutput, type CSSGenerationResult, type CSSOutputConfig, type ColorConfig, type ColorFormat, type DirectoriesConfig, type FluidConfig, type LoadError, type LoadResult, type OptionsConfig, type OutputConfig, type ResolutionError, type ResolvedToken, type ResolvedTokens, type SugarcubeConfig, type TokenCollection, type TokenCollections, type TokenLoader, type TokenMemoryData, type TokenSource, type TokenTree, type ValidationError, addWarningBanner, configSchema, convert, flatten, generate, generationPipeline, getTokenPathsFromConfig, loadConfig, loadTreesFromConfig, loadTreesFromMemory, manageCSSIndex, normalizeTokens, parseAndValidateConfig, processTrees, resolve, tokensToCSSPipeline, validate, validateConfig, validationPipeline, writeCSSFilesToDisk };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
var ae=Object.defineProperty;var o=(e,t)=>ae(e,"name",{value:t,configurable:!0});import{readFile as ce}from"node:fs/promises";import le from"fast-glob";import ue,{relative as b}from"node:path";import{converter as S,formatHex as P}from"culori";const l={LOAD:{FILE_NOT_FOUND:o(e=>`File not found: ${e}`,"FILE_NOT_FOUND"),INVALID_JSON:o((e,t)=>`Invalid JSON in file ${e}: ${t}`,"INVALID_JSON"),READ_ERROR:o((e,t)=>`Error reading file ${e}: ${t}`,"READ_ERROR"),INVALID_SOURCE:o(e=>`Invalid source: expected string or array of file descriptors, got ${typeof e}`,"INVALID_SOURCE"),NO_FILES_FOUND:o(e=>`No files found matching pattern: ${e}.`,"NO_FILES_FOUND"),GLOB_ERROR:o((e,t)=>`Error resolving glob pattern ${e}: ${t}`,"GLOB_ERROR"),EMPTY_CONFIG:o(()=>"No token files specified in sugarcube.config.json","EMPTY_CONFIG")},PARSE:{INVALID_INPUT_TYPE:o(e=>`Invalid input: expected string, got ${e}`,"INVALID_INPUT_TYPE"),JSON_PARSE_ERROR:o(e=>`JSON parsing error: ${e}`,"JSON_PARSE_ERROR"),UNEXPECTED_ERROR:o(e=>`Unexpected error during parsing: ${e}`,"UNEXPECTED_ERROR")},FLATTEN:{INVALID_TOKEN_NAME:o(e=>`Invalid token name '${e}': cannot contain '.', '{', or '}'`,"INVALID_TOKEN_NAME"),INVALID_NODE_STRUCTURE:o(e=>`Invalid node structure at ${e}: expected object`,"INVALID_NODE_STRUCTURE"),MISSING_INHERITED_TYPE:o(e=>`Token at ${e} has no $type (neither explicit nor inherited)`,"MISSING_INHERITED_TYPE"),MISSING_DOLLAR_PREFIX:o(e=>`Token at ${e} is using 'value' or 'type' without the required '$' prefix. Use '$value' and '$type' instead.`,"MISSING_DOLLAR_PREFIX")},METADATA:{COLLECTION_ERROR:o(e=>`Error collecting metadata: ${e}`,"COLLECTION_ERROR"),INVALID_EXTENSIONS:o(e=>`Invalid extensions at ${e}: expected object, got ${typeof e}`,"INVALID_EXTENSIONS"),INVALID_DESCRIPTION:o(e=>`Invalid description at ${e}: expected string, got ${typeof e}`,"INVALID_DESCRIPTION")},VALIDATE:{MISSING_TYPE:o(e=>`Token at '${e}' is missing the "$type" property`,"MISSING_TYPE"),MISSING_VALUE:o(e=>`Token at '${e}' is missing the "$value" property`,"MISSING_VALUE"),UNKNOWN_TOKEN_TYPE:o((e,t)=>`Unknown token type '${e}' at ${t}. Valid types are: color, dimension, fontFamily, fontWeight, duration, cubicBezier, strokeStyle, border, transition, shadow, gradient, typography`,"UNKNOWN_TOKEN_TYPE"),INVALID_COLOR:o((e,t)=>`Invalid color at ${t}: '${e}'. Color should be a valid hex value`,"INVALID_COLOR"),INVALID_DIMENSION:o((e,t)=>`Invalid dimension at '${t}': ${e}. Dimensions should have a numeric value and unit, like { "value": 16, "unit": "px" }`,"INVALID_DIMENSION"),INVALID_DIMENSION_UNIT:o((e,t)=>`Invalid unit at ${t}': '${e}'. Unit must be either "px" or "rem"`,"INVALID_DIMENSION_UNIT"),INVALID_FONT_FAMILY:o((e,t)=>`Invalid font family at '${t}': ${e}. Should be a string or array of strings, like "Arial" or ["Arial", "sans-serif"]`,"INVALID_FONT_FAMILY"),INVALID_FONT_WEIGHT:o((e,t)=>`Invalid font weight at '${t}': ${e}. Should be a number between 1-1000 or a keyword like "thin", "light", "normal", "bold"`,"INVALID_FONT_WEIGHT"),INVALID_DURATION:o((e,t)=>`Invalid duration at '${t}': ${e}. Should be like { "value": 300, "unit": "ms" }`,"INVALID_DURATION"),INVALID_DURATION_UNIT:o((e,t)=>`Invalid unit at ${t}: "${e}". Unit must be "ms" or "s"`,"INVALID_DURATION_UNIT"),INVALID_CUBIC_BEZIER:o((e,t)=>`Invalid cubic bezier at ${t}: "${e}". Should be an array of 4 numbers between 0 and 1`,"INVALID_CUBIC_BEZIER"),INVALID_CUBIC_BEZIER_RANGE:o((e,t)=>`Invalid cubic bezier control points at '${t}': ${e}. X values must be between 0 and 1`,"INVALID_CUBIC_BEZIER_RANGE"),INVALID_STROKE_STYLE:o((e,t)=>`Invalid stroke style at ${t}: "${e}". Should be "solid", "dashed", "dotted", etc.`,"INVALID_STROKE_STYLE"),INVALID_STROKE_LINE_CAP:o((e,t)=>`Invalid line cap at ${t}: "${e}". Should be one of: round, butt, square`,"INVALID_STROKE_LINE_CAP"),INVALID_BORDER:o((e,t)=>`Invalid border at ${t}: "${e}". Should have color, width, and style properties`,"INVALID_BORDER"),INVALID_SHADOW:o((e,t)=>`Invalid shadow at ${t}: "${e}". Should have color, offsetX, offsetY properties (blur and spread are optional)`,"INVALID_SHADOW"),INVALID_SHADOW_INSET:o((e,t)=>`Invalid inset value at ${t}: "${e}". Should be true or false`,"INVALID_SHADOW_INSET"),INVALID_TRANSITION:o((e,t)=>`Invalid transition at ${t}: "${e}". Should have duration, delay, and timingFunction properties`,"INVALID_TRANSITION"),INVALID_GRADIENT:o((e,t)=>`Invalid gradient at ${t}: "${e}". Should be an array of color stops with position values between 0 and 1`,"INVALID_GRADIENT"),INVALID_GRADIENT_STOP_POSITION:o((e,t)=>`Invalid gradient stop position at ${t}: "${e}". Position must be between 0 and 1`,"INVALID_GRADIENT_STOP_POSITION"),INVALID_TYPOGRAPHY:o((e,t)=>`Invalid typography at ${t}: "${e}". Should have fontFamily and fontSize (fontWeight, letterSpacing, and lineHeight are optional)`,"INVALID_TYPOGRAPHY"),MISSING_REQUIRED_PROPERTY:o((e,t)=>`Missing required property '${e}' at ${t}`,"MISSING_REQUIRED_PROPERTY"),INVALID_NUMBER:o((e,t)=>`Invalid number at ${t}: "${e}". Expected a number value`,"INVALID_NUMBER"),INVALID_ARRAY:o((e,t)=>`Invalid array at ${t}: "${e}". Expected an array value`,"INVALID_ARRAY"),MISSING_FLUID_CONFIG:o(e=>`Missing fluid configuration. Token at ${e} requires fluid viewport settings.`,"MISSING_FLUID_CONFIG"),INVALID_FLUID_DIMENSION:o((e,t)=>`Invalid fluid dimension at ${t}: "${e}". Fluid dimensions should have min and max values, like { "min": { "value": 16, "unit": "px" }, "max": { "value": 24, "unit": "px" } }`,"INVALID_FLUID_DIMENSION"),INVALID_VIEWPORT_CONFIG:o((e,t)=>`Invalid viewport configuration at ${t}: "${e}". Viewport config should have min and max dimension values`,"INVALID_VIEWPORT_CONFIG"),MISMATCHED_UNITS:o((e,t,n)=>`Mismatched units at ${n}: min uses '${e}', max uses '${t}'. Both values must use the same unit`,"MISMATCHED_UNITS"),INVALID_FLUID_VALUE_RANGE:o(e=>`Invalid fluid value range at ${e}: min value must be less than max value`,"INVALID_FLUID_VALUE_RANGE"),INVALID_TOKEN_TYPE:o((e,t,n)=>`Invalid token type at ${n}: expected ${e}, got ${t}`,"INVALID_TOKEN_TYPE"),INVALID_TYPE:o((e,t,n)=>`Expected ${e}, received ${typeof t} at ${n}`,"INVALID_TYPE"),INVALID_ENUM_VALUE:o((e,t,n)=>`Expected value to be one of [${e.join(", ")}], but got ${String(t)} at ${n}`,"INVALID_ENUM_VALUE")},RESOLVE:{CIRCULAR_REFERENCE:o((e,t)=>`Circular reference detected: ${e} -> ${t}`,"CIRCULAR_REFERENCE"),REFERENCE_NOT_FOUND:o((e,t)=>`Reference not found: ${t} in ${e}`,"REFERENCE_NOT_FOUND"),TYPE_MISMATCH:o(e=>`Type mismatch in reference resolution at ${e}`,"TYPE_MISMATCH")},NORMALIZE:{DUPLICATE_FILE_WARNING:o((e,t)=>`Warning: File '${e}' is assigned to multiple collections without modes (in '${t}'). This will create duplicate CSS variables in :root since collections without modes default to root scope.`,"DUPLICATE_FILE_WARNING"),DUPLICATE_MODE_WARNING:o((e,t,n)=>`Warning: File '${e}' is assigned to multiple modes in collection '${t}' (in '${n}'). This means the same token values will be duplicated across different theme selectors.`,"DUPLICATE_MODE_WARNING")},GENERATE:{INVALID_CSS_VALUE:o((e,t)=>`Invalid CSS value for property '${e}': ${t}`,"INVALID_CSS_VALUE"),INVALID_VARIABLE_NAME:o((e,t)=>`Invalid CSS variable name at '${e}': ${t}`,"INVALID_VARIABLE_NAME")}};async function U(e){const t={files:[],errors:[]};for(const n of e)try{const r=!n.includes("*")&&!n.endsWith(".json")?ue.join(n,"**/*.json"):n,i=await le(r,{absolute:!0,onlyFiles:!0});if(i.length===0){t.errors.push({pattern:n,error:l.LOAD.NO_FILES_FOUND(n)});continue}t.files.push(...i)}catch(r){t.errors.push({pattern:n,error:l.LOAD.GLOB_ERROR(n,r instanceof Error?r.message:"Unknown error")})}return t}o(U,"resolveFiles");async function G(e){try{const t=await ce(e,"utf-8");return JSON.parse(t)}catch(t){throw t instanceof Error?t instanceof SyntaxError?new Error(l.LOAD.INVALID_JSON(e,t.message)):"code"in t&&t.code==="ENOENT"?new Error(l.LOAD.FILE_NOT_FOUND(e)):new Error(l.LOAD.READ_ERROR(e,t.message)):new Error(l.LOAD.READ_ERROR(e,"Unknown error"))}}o(G,"loadTree");function fe(e){const t=new Set;return e.themes&&Object.values(e.themes).forEach(n=>{n.forEach(r=>t.add(r))}),t}o(fe,"collectThemePaths");async function _(e){const t=[],n=[],r=Array.isArray(e.tokens)?{default:{source:e.tokens,type:"custom"}}:"source"in e.tokens?{default:e.tokens}:e.tokens;for(const[i,s]of Object.entries(r)){const a=fe(s),{files:c,errors:u}=await U(Array.isArray(s.source)?s.source:[s.source]);if(u.length>0){t.push(...u.map(f=>({file:f.pattern,message:f.error})));continue}for(const f of c){const h=b(process.cwd(),f);if(!a.has(h))try{const d=await G(f),m={collection:i,tokens:d,sourcePath:h};n.push(m)}catch(d){t.push({file:f,message:d instanceof Error?d.message:"Unknown error"})}}if(s.themes)for(const[f,h]of Object.entries(s.themes))try{const{files:d,errors:m}=await U(h);if(m.length>0){t.push(...m.map(I=>({file:I.pattern,message:I.error})));continue}for(const I of d)try{const y=await G(I),A={collection:i,theme:f,tokens:y,sourcePath:b(process.cwd(),I)};n.push(A)}catch(y){t.push({file:I,message:y instanceof Error?y.message:"Unknown error"})}}catch(d){t.push({file:h.join(", "),message:d instanceof Error?d.message:"Unknown error"})}}return{trees:n,errors:t}}o(_,"loadTreesFromConfig");async function Y(e){const t=[],n=[],r=new Map;for(const[i,{collection:s,theme:a,content:c}]of Object.entries(e)){r.has(s)||r.set(s,new Map);const u=r.get(s);u.has(a)||u.set(a,[]),u.get(a).push({content:c,path:i})}for(const[i,s]of r)for(const[a,c]of s)for(const{content:u,path:f}of c)try{const h=JSON.parse(u);t.push({collection:i,theme:a,tokens:h,sourcePath:b(process.cwd(),f)})}catch(h){n.push({file:f,message:`Failed to parse JSON content: ${h.message}`})}return{trees:t,errors:n}}o(Y,"loadTreesFromMemory");function de(e){if(typeof e!="object"||e===null||"$value"in e)return!1;const t="value"in e,n="type"in e;if(t&&n)return!0;if(t){const r=e.value;return typeof r=="string"||typeof r=="number"||Array.isArray(r)}return!1}o(de,"looksLikeUnprefixedToken");function pe(e,t){const n={},r=[];function i(a=[]){const c=[t.collection];return t.theme&&c.push(t.theme),a.length>0&&c.push(a.join(".")),c.join(".")}o(i,"createLookupKey"),(e.$description||e.$extensions)&&(n[i()]={$description:e.$description,$extensions:e.$extensions});function s(a,c=[],u){if(c.length>0&&(a.$description||a.$extensions)&&(n[i(c)]={$description:a.$description,$extensions:a.$extensions}),"$value"in a)return;const f=a.$type||u,h=Object.keys(a).filter(d=>!d.startsWith("$"));for(const d of h){const m=a[d],I=[...c,d];if(de(m)){r.push({path:I.join("."),source:t,message:l.FLATTEN.MISSING_DOLLAR_PREFIX(I.join("."))});continue}if(d.includes(".")||d.includes("{")||d.includes("}")){r.push({path:I.join("."),source:t,message:l.FLATTEN.INVALID_TOKEN_NAME(d)});continue}if("$value"in m){if(!f&&!m.$type){r.push({path:I.join("."),source:t,message:l.FLATTEN.MISSING_INHERITED_TYPE(I.join("."))});continue}n[i(I)]={...m,$type:m.$type||f,$path:I.join("."),$source:{collection:t.collection,theme:t.theme,sourcePath:t.sourcePath},$originalPath:I.join(".")}}else s(m,I,f)}}return o(s,"processNode"),s(e),{tokens:n,errors:r}}o(pe,"flattenTree");function L(e){return e.reduce((t,n)=>{const{tokens:r,errors:i}=pe(n.tokens,{collection:n.collection,theme:n.theme,sourcePath:n.sourcePath});return{tokens:{...t.tokens,...r},errors:[...t.errors,...i]}},{tokens:{},errors:[]})}o(L,"flatten");const he={isObject:o(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObject")};function p(e){return typeof e=="string"&&e.startsWith("{")&&e.endsWith("}")}o(p,"isReference");function $(e,t,n,r){if(p(t))return[];switch(e.type){case"object":return Ie(e,t,n,r);case"union":return $e(e,t,n,r);case"array":return ye(e,t,n,r);default:return me(e,t,n,r)}}o($,"validateSchema");function me(e,t,n,r){return typeof t!==e.type?[{path:n,message:e.errorMessage?.(t,n)||l.VALIDATE.INVALID_TYPE(e.type,t,n),source:r}]:e.validate?.(t,n,r)??[]}o(me,"validateSimpleValue");function Ie(e,t,n,r){if(!he.isObject(t))return[{path:n,message:e.errorMessage?.(t,n)||l.VALIDATE.INVALID_TYPE("object",t,n),source:r}];const i=[],s=t;if(e.required)for(const a of e.required)a in s||i.push({path:`${n}.${a}`,message:l.VALIDATE.MISSING_REQUIRED_PROPERTY(a,n),source:r});for(const[a,c]of Object.entries(e.properties))a in s&&i.push(...$(c,s[a],`${n}.${a}`,r));return i}o(Ie,"validateObject");function $e(e,t,n,r){let i=[],s=1/0;for(const a of e.oneOf){if(a.type==="string"&&typeof t!="string"||a.type==="object"&&typeof t!="object")continue;const c=$(a,t,n,r);if(c.length===0)return e.validate?.(t,n,r)??[];c.length<s&&(i=c,s=c.length)}return s===1/0?[{path:n,message:l.VALIDATE.INVALID_TYPE(e.oneOf.map(a=>a.type).join(" or "),t,n),source:r}]:i}o($e,"validateUnion");function ye(e,t,n,r){return Array.isArray(t)?e.validate?.(t,n,r)??[]:[{path:n,message:e.errorMessage?.(t,n)||l.VALIDATE.INVALID_TYPE("array",t,n),source:r}]}o(ye,"validateArray");const E={tokenType:"color",schema:{type:"string",errorMessage:o((e,t)=>l.VALIDATE.INVALID_COLOR(e,t),"errorMessage"),validate:o((e,t,n)=>/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(e)?[]:[{path:t,message:l.VALIDATE.INVALID_COLOR(e,t),source:n}],"validate")}};function ge(e,t,n){return $(E.schema,e,t,n)}o(ge,"validateColor");const T={tokenType:"number",schema:{type:"number",errorMessage:o((e,t)=>l.VALIDATE.INVALID_NUMBER(e,t),"errorMessage"),validate:o((e,t,n)=>typeof e!="number"||isNaN(e)?[{path:t,message:l.VALIDATE.INVALID_NUMBER(e,t),source:n}]:[],"validate")}};function Ae(e,t,n){return $(T.schema,e,t,n)}o(Ae,"validateNumber");const g={tokenType:"dimension",schema:{type:"object",errorMessage:o((e,t)=>l.VALIDATE.INVALID_DIMENSION(e,t),"errorMessage"),properties:{value:T.schema,unit:{type:"string",validate:o((e,t,n)=>typeof e!="string"||!["px","rem"].includes(e)?[{path:t,message:l.VALIDATE.INVALID_DIMENSION_UNIT(e,t),source:n}]:[],"validate")}},required:["value","unit"]}};function Ee(e,t,n){return $(g.schema,e,t,n)}o(Ee,"validateDimension");const z={tokenType:"fontFamily",schema:{type:"union",oneOf:[{type:"string",errorMessage:o((e,t)=>l.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage")},{type:"array",errorMessage:o((e,t)=>l.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage"),validate:o((e,t,n)=>e.every(i=>typeof i=="string")?[]:[{path:t,message:l.VALIDATE.INVALID_FONT_FAMILY(e,t),source:n}],"validate")}],errorMessage:o((e,t)=>l.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage")}};function Te(e,t,n){return $(z.schema,e,t,n)}o(Te,"validateFontFamily");const Ne=["thin","hairline","extra-light","ultra-light","light","normal","regular","book","medium","semi-bold","demi-bold","bold","extra-bold","ultra-bold","black","heavy","extra-black","ultra-black"],W={tokenType:"fontWeight",schema:{type:"union",errorMessage:o((e,t)=>l.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),oneOf:[{type:"number",errorMessage:o((e,t)=>l.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),validate:o((e,t,n)=>e<1||e>1e3?[{path:t,message:l.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}]:[],"validate")},{type:"string",errorMessage:o((e,t)=>l.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),validate:o((e,t,n)=>Ne.includes(e.toLowerCase())?[]:[{path:t,message:l.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}],"validate")}]}};function De(e,t,n){return $(W.schema,e,t,n)}o(De,"validateFontWeight");const be=["ms","s"],V={tokenType:"duration",schema:{type:"object",errorMessage:o((e,t)=>l.VALIDATE.INVALID_DURATION(e,t),"errorMessage"),properties:{value:T.schema,unit:{type:"string",validate:o((e,t,n)=>be.includes(e)?[]:[{path:t,message:l.VALIDATE.INVALID_DURATION_UNIT(e,t),source:n}],"validate")}},required:["value","unit"]}};function Se(e,t,n){return $(V.schema,e,t,n)}o(Se,"validateDuration");const B={tokenType:"cubicBezier",schema:{type:"array",errorMessage:o((e,t)=>l.VALIDATE.INVALID_CUBIC_BEZIER(e,t),"errorMessage"),validate:o((e,t,n)=>{const r=e;if(r.length!==4||!r.every(a=>typeof a=="number"))return[{path:t,message:l.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}];const[i,,s]=r;return i<0||i>1||s<0||s>1?[{path:t,message:l.VALIDATE.INVALID_CUBIC_BEZIER_RANGE(e,t),source:n}]:[]},"validate")}};function _e(e,t,n){return $(B.schema,e,t,n)}o(_e,"validateCubicBezier");const Le={tokenType:"typography",schema:{type:"object",properties:{fontFamily:z.schema,fontSize:g.schema,letterSpacing:g.schema,lineHeight:T.schema,fontWeight:W.schema},required:["fontFamily","fontSize"],errorMessage:o((e,t)=>l.VALIDATE.INVALID_TYPOGRAPHY(e,t),"errorMessage")}};function Ve(e,t,n){return $(Le.schema,e,t,n)}o(Ve,"validateTypography");const Oe=["solid","dashed","dotted","double","groove","ridge","outset","inset"],ve=["round","butt","square"],Fe={type:"object",errorMessage:o((e,t)=>l.VALIDATE.INVALID_STROKE_STYLE(e,t),"errorMessage"),properties:{dashArray:{type:"array",validate:o((e,t,n)=>{const r=e,i=[];return r.forEach((s,a)=>{typeof s!="string"&&i.push(...$(g.schema,s,`${t}.${a}`,n))}),i},"validate")},lineCap:{type:"string",validate:o((e,t,n)=>ve.includes(e)?[]:[{path:t,message:l.VALIDATE.INVALID_STROKE_LINE_CAP(e,t),source:n}],"validate")}},required:["dashArray","lineCap"]},H={tokenType:"strokeStyle",schema:{type:"union",oneOf:[{type:"string",validate:o((e,t,n)=>!Oe.includes(e)&&typeof e=="string"?[{path:t,message:l.VALIDATE.INVALID_STROKE_STYLE(e,t),source:n}]:[],"validate")},Fe]}};function ke(e,t,n){return $(H.schema,e,t,n)}o(ke,"validateStrokeStyle");const Re={tokenType:"border",schema:{type:"object",properties:{color:E.schema,width:g.schema,style:H.schema},required:["color","width","style"],errorMessage:o((e,t)=>l.VALIDATE.INVALID_BORDER(e,t),"errorMessage")}};function we(e,t,n){return $(Re.schema,e,t,n)}o(we,"validateBorder");const Ce={tokenType:"transition",schema:{type:"object",properties:{duration:V.schema,delay:V.schema,timingFunction:B.schema},required:["duration","delay","timingFunction"],errorMessage:o((e,t)=>l.VALIDATE.INVALID_TRANSITION(e,t),"errorMessage")}};function xe(e,t,n){return $(Ce.schema,e,t,n)}o(xe,"validateTransition");const q={tokenType:"shadow",schema:{type:"object",properties:{color:E.schema,offsetX:g.schema,offsetY:g.schema,blur:g.schema,spread:g.schema,inset:{type:"boolean",errorMessage:o((e,t)=>l.VALIDATE.INVALID_SHADOW_INSET(e,t),"errorMessage")}},required:["color","offsetX","offsetY","blur","spread"],errorMessage:o((e,t)=>l.VALIDATE.INVALID_SHADOW(e,t),"errorMessage")}};function Me(e,t,n){const r=[];return Array.isArray(e)?(e.forEach((i,s)=>{r.push(...$(q.schema,i,`${t}[${s}]`,n))}),r):$(q.schema,e,t,n)}o(Me,"validateShadow");const je={type:"object",errorMessage:o((e,t)=>l.VALIDATE.INVALID_GRADIENT(e,t),"errorMessage"),properties:{color:{type:"string",validate:E.schema.validate},position:{type:"number",validate:o((e,t,n)=>e<0||e>1?[{path:t,message:l.VALIDATE.INVALID_GRADIENT_STOP_POSITION(e,t),source:n}]:[],"validate")}},required:["color","position"]},Pe={tokenType:"gradient",schema:{type:"array",errorMessage:o((e,t)=>l.VALIDATE.INVALID_ARRAY(e,t),"errorMessage"),validate:o((e,t,n)=>{const r=e,i=[];return r.forEach((s,a)=>{i.push(...$(je,s,`${t}[${a}]`,n))}),i},"validate")}};function Ue(e,t,n){return $(Pe.schema,e,t,n)}o(Ue,"validateGradient");const Ge={tokenType:"fluidDimension",schema:{type:"object",errorMessage:o((e,t)=>l.VALIDATE.INVALID_FLUID_DIMENSION(e,t),"errorMessage"),properties:{min:g.schema,max:g.schema},required:["min","max"]}};function Ye(e,t,n){return $(Ge.schema,e,t,n)}o(Ye,"validateFluidDimension");const ze={color:ge,dimension:Ee,fluidDimension:Ye,duration:Se,cubicBezier:_e,fontFamily:Te,fontWeight:De,number:Ae,strokeStyle:ke,typography:Ve,border:we,shadow:Me,gradient:Ue,transition:xe};function O(e){const t=[];for(const[n,r]of Object.entries(e)){if(typeof r!="object"||r===null||!("$type"in r)||!("$path"in r)||r.$path.startsWith("$"))continue;const i=ze[r.$type];if(!i){t.push({path:r.$path,message:l.VALIDATE.UNKNOWN_TOKEN_TYPE(r.$type,r.$path),source:r.$source});continue}t.push(...i(r.$value,r.$path,r.$source))}return t}o(O,"validate");function N(e,t,n,r){return typeof t=="string"&&p(t)?We(e,t,n,r):Array.isArray(t)?t.map(i=>N(e,i,n,r)):typeof t=="object"&&t!==null?Object.entries(t).reduce((s,[a,c])=>({...s,[a]:N(`${e}.${a}`,c,n,r)}),{}):t}o(N,"resolveValue");function v(e){const t={},n=new Set,r=[];for(const[i,s]of Object.entries(e))try{if(!("$value"in s)){t[i]=s;continue}const a=s;t[i]={...a,$resolvedValue:N(a.$path,a.$value,e,n)}}catch(a){const c=a instanceof Error?a.message:String(a),u=s,f=u.$path,h=u.$source;let d,m;c.includes("Circular reference detected")?(d="circular",m=c):c.includes("Reference not found")?(d="missing",m=c):(d="type-mismatch",m=l.RESOLVE.TYPE_MISMATCH(f)),r.push({type:d,path:f,source:h,message:m})}return{resolved:t,errors:r}}o(v,"resolve");function We(e,t,n,r){const i=t.slice(1,-1),s=Object.keys(n).find(u=>{const f=n[u];return f?"$originalPath"in f&&f.$originalPath===i:!1});if(!s)throw new Error(`Reference not found: ${i} in ${e}`);if(r.has(s))throw new Error(`Circular reference detected: ${e} -> ${s}`);const a=n[s];if(!a||!("$value"in a))throw new Error(`Reference not found: ${i} in ${e}`);r.add(s);const c=N(s,a.$value,n,r);return r.delete(s),c}o(We,"resolveReferenceChain");function F(e,t){return e.map(n=>({collection:n.collection,theme:n.theme,tokens:Object.entries(t).reduce((r,[i,s])=>("$source"in s&&(s.$source.collection!==n.collection||n.theme&&s.$source.theme!==n.theme||s.$source.theme&&s.$source.theme!==n.theme)||(!("$type"in s)||s.$source.collection===n.collection&&(!n.theme||s.$source.theme===n.theme))&&(r[i]=s),r),{})}))}o(F,"processTrees");function D(e){return["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","emoji","math","fangsong"].includes(e.toLowerCase())?e:/[\s'"!@#$%^&*()=+[\]{};:|\\/,.<>?~]/.test(e)?`"${e}"`:e}o(D,"quoteFont");const Be={thin:100,hairline:100,"extra-light":200,"ultra-light":200,light:300,normal:400,regular:400,book:400,medium:500,"semi-bold":600,"demi-bold":600,bold:700,"extra-bold":800,"ultra-bold":800,black:900,heavy:900,"extra-black":950,"ultra-black":950};function K(e){return p(e)?{value:e}:typeof e=="number"?{value:e}:{value:Be[e.toLowerCase()]??e}}o(K,"convertFontWeightToken");function He(e){if(p(e))return{"font-family":e,"font-size":e};const t={"font-family":p(e.fontFamily)?e.fontFamily:Array.isArray(e.fontFamily)?e.fontFamily.map(n=>D(n)).join(", "):D(e.fontFamily),"font-size":p(e.fontSize)?e.fontSize:`${e.fontSize.value}${e.fontSize.unit}`};return e.fontWeight&&(t["font-weight"]=p(e.fontWeight)?e.fontWeight:K(e.fontWeight).value),e.letterSpacing&&(t["letter-spacing"]=p(e.letterSpacing)?e.letterSpacing:`${e.letterSpacing.value}${e.letterSpacing.unit}`),e.lineHeight&&(t["line-height"]=(p(e.lineHeight),e.lineHeight)),t}o(He,"convertTypographyToken");function X(e){return e?`${e.value}${e.unit}`:"0ms"}o(X,"formatDuration");function qe(e){if(p(e))return{value:e};const t=p(e.duration)?e.duration:X(e.duration),n=p(e.timingFunction)?e.timingFunction:`cubic-bezier(${e.timingFunction.join(", ")})`,r=e.delay&&(p(e.delay)?e.delay:X(e.delay));return{value:[t,n,r].filter(Boolean).join(" ")}}o(qe,"convertTransitionToken");function Ke(e){return p(e)?{value:e}:{value:`cubic-bezier(${e.join(", ")})`}}o(Ke,"convertCubicBezierToken");function Xe(e){return p(e)?{value:e}:{value:e}}o(Xe,"convertNumberToken");function Ze(e){return p(e)?{value:e}:{value:`${e.value}${e.unit}`}}o(Ze,"convertDurationToken");function Z(e){return p(e)?{value:e}:typeof e=="string"?{value:e}:{value:`${e.dashArray.map(n=>p(n)?n:`${n.value}${n.unit}`).join(" ")} ${e.lineCap}`}}o(Z,"convertStrokeStyleToken");function Je(e){if(p(e))return{value:e};const t=p(e.width)?e.width:`${e.width.value}${e.width.unit}`,n=(p(e.color),e.color),r=typeof e.style=="string"?e.style:Z(e.style).value;return{value:`${t} ${r} ${n}`}}o(Je,"convertBorderToken");function J(e){const t=p(e.offsetX)?e.offsetX:`${e.offsetX.value}${e.offsetX.unit}`,n=p(e.offsetY)?e.offsetY:`${e.offsetY.value}${e.offsetY.unit}`,r=p(e.blur)?e.blur:`${e.blur.value}${e.blur.unit}`,i=p(e.spread)?e.spread:`${e.spread.value}${e.spread.unit}`,s=(p(e.color),e.color);return`${e.inset?"inset ":""}${t} ${n} ${r} ${i} ${s}`}o(J,"convertSingleShadow");function Qe(e){return p(e)?{value:e}:Array.isArray(e)?{value:e.map(J).join(", ")}:{value:J(e)}}o(Qe,"convertShadowToken");function et(e){return p(e)?{value:e}:{value:`linear-gradient(${e.map(n=>{const r=(p(n.color),n.color),i=p(n.position)?n.position:`${n.position*100}`;return`${r} ${i}%`}).join(", ")})`}}o(et,"convertGradientToken");function tt(e){return p(e)?{value:e}:{value:Array.isArray(e)?e.map(n=>D(n)).join(", "):D(e)}}o(tt,"convertFontFamilyToken");function nt(e){return p(e)?{value:e}:{value:`${e.value}${e.unit}`}}o(nt,"convertDimensionToken");function Q(e,t=16){return e.unit==="px"?e.value:e.value*t}o(Q,"normalizeToPixels");function rt(e,t){const{min:n,max:r}=e,i=t.fluidConfig;if(!i)throw new Error(l.VALIDATE.MISSING_FLUID_CONFIG(t.path??""));const s=16,a=Q(n,s),c=Q(r,s),u=i.min,f=i.max;if(a===c)return{value:`${a/s}rem`};const h=a/s,d=c/s,m=u/s,I=f/s,y=(d-h)/(I-m),A=-1*m*y+h;return{value:`clamp(${h}rem, ${A.toFixed(2)}rem + ${(y*100).toFixed(2)}vw, ${d}rem)`}}o(rt,"convertFluidDimension");function ot(e,t){if(p(e))return{value:e};if(!t.fluidConfig)throw new Error(l.VALIDATE.MISSING_FLUID_CONFIG(t.path??""));return rt(e,t)}o(ot,"convertFluidDimensionToken");function k(e,t){try{const n=t==="rgba"?"rgb":t==="hsla"?"hsl":t,r=S(n==="hex"?"rgb":n)(e);if(!r)throw new Error(`Failed to convert color ${e} to ${t}`);switch(n){case"hsl":{if(r.mode!=="hsl")throw new Error("Unexpected color mode");const i=r.h??0,s=r.s??0,a=r.l??0,c=r.alpha;return c!==void 0&&c<1?`hsl(${Math.round(i)} ${Math.round(s*100)}% ${Math.round(a*100)}% / ${c.toFixed(2)})`:`hsl(${Math.round(i)} ${Math.round(s*100)}% ${Math.round(a*100)}%)`}case"oklch":{if(r.mode!=="oklch")throw new Error("Unexpected color mode");const i=r.l??0,s=r.c??0,a=r.h??0,c=r.alpha;return c!==void 0&&c<1?`oklch(${i.toFixed(3)} ${s.toFixed(3)} ${a.toFixed(1)} / ${c.toFixed(2)})`:`oklch(${i.toFixed(3)} ${s.toFixed(3)} ${a.toFixed(1)})`}case"rgb":{if(r.mode!=="rgb")throw new Error("Unexpected color mode");const i=Math.round((r.r??0)*255),s=Math.round((r.g??0)*255),a=Math.round((r.b??0)*255),c=r.alpha;return c!==void 0&&c<1?`rgb(${i} ${s} ${a} / ${c.toFixed(2)})`:`rgb(${i} ${s} ${a})`}case"p3":{if(r.mode!=="p3")throw new Error("Unexpected color mode");const i=r.r??0,s=r.g??0,a=r.b??0,c=r.alpha;return c!==void 0&&c<1?`color(display-p3 ${i.toFixed(6)} ${s.toFixed(6)} ${a.toFixed(6)} / ${c.toFixed(2)})`:`color(display-p3 ${i.toFixed(6)} ${s.toFixed(6)} ${a.toFixed(6)})`}default:{const i=S("rgb")(r);return i?P(i):e}}}catch{const r=S("rgb")(e);return console.warn(`Failed to convert color ${e} to ${t}, falling back to hex`),r?P(r):e}}o(k,"convertHexToColorString");function it(e,t){if(p(e))return{value:e};const n=t.colorFormat||"hex";try{const r=k(e,n);return n==="p3"?{value:k(e,"hex")||e,featureValues:[{query:"@supports (color: color(display-p3 1 1 1))",value:r||e}]}:{value:r||e}}catch{return console.warn(`Failed to convert color ${e} to ${n}, falling back to hex`),{value:k(e,"hex")}}}o(it,"convertColorToken");const ee={duration:Ze,number:Xe,cubicBezier:Ke,color:it,dimension:nt,fluidDimension:ot,typography:He,border:Je,shadow:Qe,gradient:et,transition:qe,strokeStyle:Z,fontFamily:tt,fontWeight:K};function st(e,t){const n=ee[e.$type];return{...e.$description?{$description:e.$description}:{},...e.$extensions?{$extensions:e.$extensions}:{},$type:e.$type,$value:e.$value,$path:e.$path,$source:e.$source,$originalPath:e.$originalPath,$resolvedValue:e.$resolvedValue,$cssProperties:n(e.$value,t)}}o(st,"convertSingleToken");function te(e,t){const n={};for(const[r,i]of Object.entries(e)){if(!i||typeof i!="object")continue;if(!("$type"in i)){n[r]={...i.$description?{$description:i.$description}:{},...i.$extensions?{$extensions:i.$extensions}:{}};continue}if(!ee[i.$type])continue;const s={fluidConfig:t.options?.fluid,colorFormat:t.options?.color,path:i.$path};n[r]=st(i,s)}return n}o(te,"convertTokens");function R(e,t){const n={};for(const[r,i]of Object.entries(e)){const s={default:te(i.default,t)};for(const[a,c]of Object.entries(i))a!=="default"&&(s[a]=te(c,t));n[r]=s}return n}o(R,"convert");const ne=new Map;function at(e){const t=ne.get(e);if(t)return t;const n=e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z])(?=[a-z])/g,"$1-$2").toLowerCase();return ne.set(e,n),n}o(at,"toKebabCase");function w({collection:e,filename:t,separate:n,baseDir:r}){const i=`${t}.variables.css`;return e==="default"?`${r}/${i}`:`${r}/${e}/${i}`}o(w,"getOutputPath");const re="@supports (color: color(display-p3 1 1 1))";function ct(e){return e.$type==="typography"}o(ct,"isTypographyToken");function C(e){return e.split(".").join("-")}o(C,"formatCSSVarPath");function oe(e){return typeof e=="number"?e:typeof e!="string"?(console.warn("Unexpected value type in convertReferenceToCSSVar, got:",e),String(e)):e.replace(/\{([^}]+)\}/g,(t,n)=>`var(--${n.split(".").map(at).join("-")})`)}o(oe,"convertReferenceToCSSVar");function lt(e){const t=e.$cssProperties;if("value"in t)return{name:`--${C(e.$path)}`,value:oe(t.value)}}o(lt,"generateSingleVariable");function ut(e){return Object.entries(e.$cssProperties).filter(([t,n])=>n!==void 0).map(([t,n])=>({name:`--${C(e.$path)}-${t}`,value:oe(n)}))}o(ut,"generateTypographyVariables");function ie(e){if(e.$type!=="color")return[];const t=e.$cssProperties;return"featureValues"in t?t.featureValues?.filter(n=>n.query===re).map(n=>({name:`--${C(e.$path)}`,value:n.value}))??[]:[]}o(ie,"generateFeatureVariables");function se(e){const t=[`${e.selector} {`];if(e.comment&&t.push(` /* ${e.comment} */`),e.vars.length>0){const n=e.vars.map(r=>` ${r.name}: ${r.value};`).join(`
|
|
1
|
+
var $e=Object.defineProperty;var o=(e,t)=>$e(e,"name",{value:t,configurable:!0});import{readFile as ye}from"node:fs/promises";import Ae from"fast-glob";import Ee,{relative as L}from"node:path";import{converter as _,formatHex8 as Te,formatHex as z}from"culori";import T from"path";import Ne,{mkdir as be,readFile as Y,writeFile as B}from"fs/promises";import{existsSync as H}from"fs";import{z as m}from"zod";const u={LOAD:{NO_FILES_FOUND:o(e=>`No files found matching pattern: ${e}.`,"NO_FILES_FOUND"),INVALID_JSON:o((e,t)=>`Invalid JSON in file ${e}: ${t}`,"INVALID_JSON"),GLOB_ERROR:o((e,t)=>`Error resolving glob pattern ${e}: ${t}`,"GLOB_ERROR")},FLATTEN:{INVALID_TOKEN_NAME:o(e=>`Invalid token name "${e}": Token names cannot contain dots (.), curly braces ({,}), or other special characters`,"INVALID_TOKEN_NAME"),MISSING_DOLLAR_PREFIX:o(e=>`Token at ${e} is using 'value' or 'type' without the required '$' prefix. Use '$value' and '$type' instead.`,"MISSING_DOLLAR_PREFIX")},METADATA:{COLLECTION_ERROR:o(e=>`Error collecting metadata: ${e}`,"COLLECTION_ERROR"),INVALID_EXTENSIONS:o(e=>`Invalid extensions at ${e}: expected object, got ${typeof e}`,"INVALID_EXTENSIONS"),INVALID_DESCRIPTION:o(e=>`Invalid description at ${e}: expected string, got ${typeof e}`,"INVALID_DESCRIPTION")},VALIDATE:{MISSING_TYPE:o(e=>`Token at '${e}' is missing the "$type" property`,"MISSING_TYPE"),UNKNOWN_TOKEN_TYPE:o((e,t)=>`Unknown token type '${e}' at ${t}. Valid types are: color, dimension, fontFamily, fontWeight, duration, cubicBezier, strokeStyle, border, transition, shadow, gradient, typography`,"UNKNOWN_TOKEN_TYPE"),INVALID_COLOR:o((e,t)=>`Invalid color at ${t}: '${e}'. Color should be a valid hex value`,"INVALID_COLOR"),INVALID_DIMENSION:o((e,t)=>`Invalid dimension at '${t}': ${e}. Dimensions should have a numeric value and unit, like { "value": 16, "unit": "px" }`,"INVALID_DIMENSION"),INVALID_DIMENSION_UNIT:o((e,t)=>`Invalid unit at ${t}': '${e}'. Unit must be either "px" or "rem"`,"INVALID_DIMENSION_UNIT"),INVALID_FONT_FAMILY:o((e,t)=>`Invalid font family at '${t}': ${e}. Should be a string or array of strings, like "Arial" or ["Arial", "sans-serif"]`,"INVALID_FONT_FAMILY"),INVALID_FONT_WEIGHT:o((e,t)=>`Invalid font weight at '${t}': ${e}. Should be a number between 1-1000 or a keyword like "thin", "light", "normal", "bold"`,"INVALID_FONT_WEIGHT"),INVALID_DURATION:o((e,t)=>`Invalid duration at '${t}': ${e}. Should be like { "value": 300, "unit": "ms" }`,"INVALID_DURATION"),INVALID_DURATION_UNIT:o((e,t)=>`Invalid unit at ${t}: "${e}". Unit must be "ms" or "s"`,"INVALID_DURATION_UNIT"),INVALID_CUBIC_BEZIER:o((e,t)=>`Invalid cubic bezier at ${t}: "${e}". Should be an array of 4 numbers between 0 and 1`,"INVALID_CUBIC_BEZIER"),INVALID_STROKE_STYLE:o((e,t)=>`Invalid stroke style at ${t}: "${e}". Should be "solid", "dashed", "dotted", etc.`,"INVALID_STROKE_STYLE"),INVALID_STROKE_LINE_CAP:o((e,t)=>`Invalid line cap at ${t}: "${e}". Should be one of: round, butt, square`,"INVALID_STROKE_LINE_CAP"),INVALID_BORDER:o((e,t)=>`Invalid border at ${t}: "${e}". Should have color, width, and style properties`,"INVALID_BORDER"),INVALID_SHADOW:o((e,t)=>`Invalid shadow at ${t}: "${e}". Should have color, offsetX, offsetY properties (blur and spread are optional)`,"INVALID_SHADOW"),INVALID_SHADOW_INSET:o((e,t)=>`Invalid inset value at ${t}: "${e}". Should be true or false`,"INVALID_SHADOW_INSET"),INVALID_TRANSITION:o((e,t)=>`Invalid transition at ${t}: "${e}". Should have duration, delay, and timingFunction properties`,"INVALID_TRANSITION"),INVALID_GRADIENT:o((e,t)=>`Invalid gradient at ${t}: "${e}". Should be an array of color stops with position values between 0 and 1`,"INVALID_GRADIENT"),INVALID_GRADIENT_STOP_POSITION:o((e,t)=>`Invalid gradient stop position at ${t}: "${e}". Position must be between 0 and 1`,"INVALID_GRADIENT_STOP_POSITION"),INVALID_TYPOGRAPHY:o((e,t)=>`Invalid typography at ${t}: "${e}". Should have fontFamily and fontSize (fontWeight, letterSpacing, and lineHeight are optional)`,"INVALID_TYPOGRAPHY"),MISSING_REQUIRED_PROPERTY:o((e,t)=>`Missing required property '${e}' at ${t}`,"MISSING_REQUIRED_PROPERTY"),INVALID_NUMBER:o((e,t)=>`Invalid number at ${t}: "${e}". Expected a number value`,"INVALID_NUMBER"),INVALID_ARRAY:o((e,t)=>`Invalid array at ${t}: "${e}". Expected an array value`,"INVALID_ARRAY"),MISSING_FLUID_CONFIG:o(e=>`Missing fluid configuration. Token at ${e} requires fluid viewport settings.`,"MISSING_FLUID_CONFIG"),INVALID_FLUID_DIMENSION:o((e,t)=>`Invalid fluid dimension at ${t}: "${e}". Fluid dimensions should have min and max values, like { "min": { "value": 16, "unit": "px" }, "max": { "value": 24, "unit": "px" } }`,"INVALID_FLUID_DIMENSION"),INVALID_VIEWPORT_CONFIG:o((e,t)=>`Invalid viewport configuration at ${t}: "${e}". Viewport config should have min and max dimension values`,"INVALID_VIEWPORT_CONFIG"),MISMATCHED_UNITS:o((e,t,n)=>`Mismatched units at ${n}: min uses '${e}', max uses '${t}'. Both values must use the same unit`,"MISMATCHED_UNITS"),INVALID_FLUID_VALUE_RANGE:o(e=>`Invalid fluid value range at ${e}: min value must be less than max value`,"INVALID_FLUID_VALUE_RANGE"),INVALID_TOKEN_TYPE:o((e,t,n)=>`Invalid token type at ${n}: expected ${e}, got ${t}`,"INVALID_TOKEN_TYPE"),INVALID_TYPE:o((e,t,n)=>`Expected ${e}, received ${typeof t} at ${n}`,"INVALID_TYPE"),INVALID_ENUM_VALUE:o((e,t,n)=>`Expected value to be one of [${e.join(", ")}], but got ${String(t)} at ${n}`,"INVALID_ENUM_VALUE")},RESOLVE:{CIRCULAR_REFERENCE:o((e,t)=>`Circular reference detected: ${e} -> ${t}`,"CIRCULAR_REFERENCE"),REFERENCE_NOT_FOUND:o((e,t)=>`Reference not found: ${e} in ${t}`,"REFERENCE_NOT_FOUND"),TYPE_MISMATCH:o(e=>`Type mismatch in ${e}`,"TYPE_MISMATCH")},GENERATE:{INVALID_CSS_VALUE:o((e,t)=>`Invalid CSS value for property '${e}': ${t}`,"INVALID_CSS_VALUE"),INVALID_VARIABLE_NAME:o((e,t)=>`Invalid CSS variable name at '${e}': ${t}`,"INVALID_VARIABLE_NAME")},CONFIG:{INVALID_JSON:o(e=>`Invalid JSON in config file: ${e}`,"INVALID_JSON"),INVALID_CONFIG:o((e,t)=>`Invalid configuration at ${e}: ${t}`,"INVALID_CONFIG"),DUPLICATE_FILENAMES:o((e,t,n)=>`Duplicate filename "${t}" found in collection "${e}":
|
|
2
|
+
${n.map(r=>` - ${r}`).join(`
|
|
3
|
+
`)}`,"DUPLICATE_FILENAMES"),FILE_NOT_FOUND:o(e=>`Cannot read config file at ${e} - check file permissions and path`,"FILE_NOT_FOUND")}};async function q(e){const t={files:[],errors:[]};for(const n of e)try{const r=!n.includes("*")&&!n.endsWith(".json")?Ee.join(n,"**/*.json"):n,s=await Ae(r,{absolute:!0,onlyFiles:!0});if(s.length===0){t.errors.push({pattern:n,error:u.LOAD.NO_FILES_FOUND(n)});continue}t.files.push(...s)}catch(r){t.errors.push({pattern:n,error:u.LOAD.GLOB_ERROR(n,r instanceof Error?r.message:"Unknown error")})}return t}o(q,"resolveFiles");async function K(e){try{const t=await ye(e,"utf-8");return JSON.parse(t)}catch(t){throw t instanceof Error&&t instanceof SyntaxError?new Error(u.LOAD.INVALID_JSON(e,t.message)):t}}o(K,"loadTree");function Se(e){const t=new Set;return e.themes&&Object.values(e.themes).forEach(n=>{n.forEach(r=>t.add(r))}),t}o(Se,"collectThemePaths");async function O(e){const t=[],n=[],r=Array.isArray(e.tokens)?{default:{source:e.tokens,type:"custom"}}:"source"in e.tokens?{default:e.tokens}:e.tokens;for(const[s,i]of Object.entries(r)){const a=Se(i),{files:c,errors:l}=await q(Array.isArray(i.source)?i.source:[i.source]);if(l.length>0){t.push(...l.map(f=>({file:f.pattern,message:f.error})));continue}for(const f of c){const p=L(process.cwd(),f);if(!a.has(p))try{const d=await K(f),I={collection:s,tokens:d,sourcePath:p};n.push(I)}catch(d){t.push({file:f,message:d instanceof Error?d.message:"Unknown error"})}}if(i.themes)for(const[f,p]of Object.entries(i.themes))try{const{files:d,errors:I}=await q(p);if(I.length>0){t.push(...I.map(g=>({file:g.pattern,message:g.error})));continue}for(const g of d)try{const y=await K(g),A={collection:s,theme:f,tokens:y,sourcePath:L(process.cwd(),g)};n.push(A)}catch(y){t.push({file:g,message:y instanceof Error?y.message:"Unknown error"})}}catch(d){t.push({file:p.join(", "),message:d instanceof Error?d.message:"Unknown error"})}}return{trees:n,errors:t}}o(O,"loadTreesFromConfig");async function V(e){const t=[],n=[],r=new Map;for(const[s,{collection:i,theme:a,content:c}]of Object.entries(e)){r.has(i)||r.set(i,new Map);const l=r.get(i);l.has(a)||l.set(a,[]),l.get(a).push({content:c,path:s})}for(const[s,i]of r)for(const[a,c]of i)for(const{content:l,path:f}of c)try{const p=JSON.parse(l);t.push({collection:s,theme:a,tokens:p,sourcePath:L(process.cwd(),f)})}catch(p){p instanceof Error?p instanceof SyntaxError?n.push({file:f,message:u.LOAD.INVALID_JSON(f,p.message)}):n.push({file:f,message:p.message}):n.push({file:f,message:"Unknown error"})}return{trees:t,errors:n}}o(V,"loadTreesFromMemory");function De(e){if(typeof e!="object"||e===null||"$value"in e)return!1;const t="value"in e,n="type"in e;if(t&&n)return!0;if(t){const r=e.value;return typeof r=="string"||typeof r=="number"||Array.isArray(r)}return!1}o(De,"looksLikeUnprefixedToken");function Le(e,t){const n={tokens:{},pathIndex:new Map},r=[];function s(a=[]){const c=[t.collection];return t.theme&&c.push(t.theme),a.length>0&&c.push(a.join(".")),c.join(".")}o(s,"createLookupKey"),(e.$description||e.$extensions)&&(n.tokens[s()]={$description:e.$description,$extensions:e.$extensions});function i(a,c=[],l){if(c.length>0){const d=s(c);n.tokens[d]={$description:a.$description,$extensions:a.$extensions,$path:c.join("."),$source:{collection:t.collection,theme:t.theme,sourcePath:t.sourcePath}}}if("$value"in a)return;const f=a.$type||l,p=Object.keys(a).filter(d=>!d.startsWith("$"));for(const d of p){const I=a[d],g=[...c,d];if(De(I)){r.push({path:g.join("."),source:t,message:u.FLATTEN.MISSING_DOLLAR_PREFIX(g.join("."))});continue}if(d.includes(".")||d.includes("{")||d.includes("}")){r.push({path:g.join("."),source:t,message:u.FLATTEN.INVALID_TOKEN_NAME(d)});continue}if("$value"in I){const y=s(g),A=g.join(".");n.tokens[y]={...I,$type:I.$type||f,$path:A,$source:{collection:t.collection,theme:t.theme,sourcePath:t.sourcePath},$originalPath:A},n.pathIndex.set(A,y)}else i(I,g,f)}}return o(i,"processNode"),i(e),{tokens:n,errors:r}}o(Le,"flattenTree");function F(e){const t={tokens:{},pathIndex:new Map},n=[];for(const r of e){const{tokens:s,errors:i}=Le(r.tokens,{collection:r.collection,theme:r.theme,sourcePath:r.sourcePath});Object.assign(t.tokens,s.tokens);for(const[a,c]of s.pathIndex)t.pathIndex.set(a,c);n.push(...i)}return{tokens:t,errors:n}}o(F,"flatten");const _e={isObject:o(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isObject")};function h(e){return typeof e=="string"&&e.startsWith("{")&&e.endsWith("}")}o(h,"isReference");function $(e,t,n,r){if(h(t))return[];switch(e.type){case"object":return Ve(e,t,n,r);case"union":return Fe(e,t,n,r);case"array":return ke(e,t,n,r);default:return Oe(e,t,n,r)}}o($,"validateSchema");function Oe(e,t,n,r){return typeof t!==e.type?[{path:n,message:e.errorMessage?.(t,n)||u.VALIDATE.INVALID_TYPE(e.type,t,n),source:r}]:e.validate?.(t,n,r)??[]}o(Oe,"validateSimpleValue");function Ve(e,t,n,r){if(!_e.isObject(t))return[{path:n,message:e.errorMessage?.(t,n)||u.VALIDATE.INVALID_TYPE("object",t,n),source:r}];const s=[],i=t;if(e.required)for(const a of e.required)a in i||s.push({path:`${n}.${a}`,message:u.VALIDATE.MISSING_REQUIRED_PROPERTY(a,n),source:r});for(const[a,c]of Object.entries(e.properties))a in i&&s.push(...$(c,i[a],`${n}.${a}`,r));return s}o(Ve,"validateObject");function Fe(e,t,n,r){let s=[],i=1/0;for(const a of e.oneOf){if(a.type==="string"&&typeof t!="string"||a.type==="object"&&typeof t!="object")continue;const c=$(a,t,n,r);if(c.length===0)return e.validate?.(t,n,r)??[];c.length<i&&(s=c,i=c.length)}return i===1/0?[{path:n,message:u.VALIDATE.INVALID_TYPE(e.oneOf.map(a=>a.type).join(" or "),t,n),source:r}]:s}o(Fe,"validateUnion");function ke(e,t,n,r){return Array.isArray(t)?e.validate?.(t,n,r)??[]:[{path:n,message:e.errorMessage?.(t,n)||u.VALIDATE.INVALID_TYPE("array",t,n),source:r}]}o(ke,"validateArray");const N={tokenType:"color",schema:{type:"string",errorMessage:o((e,t)=>u.VALIDATE.INVALID_COLOR(e,t),"errorMessage"),validate:o((e,t,n)=>/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(e)?[]:[{path:t,message:u.VALIDATE.INVALID_COLOR(e,t),source:n}],"validate")}};function ve(e,t,n){return $(N.schema,e,t,n)}o(ve,"validateColor");const b={tokenType:"number",schema:{type:"number",errorMessage:o((e,t)=>u.VALIDATE.INVALID_NUMBER(e,t),"errorMessage"),validate:o((e,t,n)=>typeof e!="number"||isNaN(e)?[{path:t,message:u.VALIDATE.INVALID_NUMBER(e,t),source:n}]:[],"validate")}};function we(e,t,n){return $(b.schema,e,t,n)}o(we,"validateNumber");const E={tokenType:"dimension",schema:{type:"object",errorMessage:o((e,t)=>u.VALIDATE.INVALID_DIMENSION(e,t),"errorMessage"),properties:{value:b.schema,unit:{type:"string",validate:o((e,t,n)=>typeof e!="string"||!["px","rem"].includes(e)?[{path:t,message:u.VALIDATE.INVALID_DIMENSION_UNIT(e,t),source:n}]:[],"validate")}},required:["value","unit"]}};function xe(e,t,n){return $(E.schema,e,t,n)}o(xe,"validateDimension");const X={tokenType:"fontFamily",schema:{type:"union",oneOf:[{type:"string",errorMessage:o((e,t)=>u.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage")},{type:"array",errorMessage:o((e,t)=>u.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage"),validate:o((e,t,n)=>e.every(s=>typeof s=="string")?[]:[{path:t,message:u.VALIDATE.INVALID_FONT_FAMILY(e,t),source:n}],"validate")}],errorMessage:o((e,t)=>u.VALIDATE.INVALID_FONT_FAMILY(e,t),"errorMessage")}};function Ce(e,t,n){return $(X.schema,e,t,n)}o(Ce,"validateFontFamily");const Re=["thin","hairline","extra-light","ultra-light","light","normal","regular","book","medium","semi-bold","demi-bold","bold","extra-bold","ultra-bold","black","heavy","extra-black","ultra-black"],J={tokenType:"fontWeight",schema:{type:"union",errorMessage:o((e,t)=>u.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),oneOf:[{type:"number",errorMessage:o((e,t)=>u.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),validate:o((e,t,n)=>e<1||e>1e3?[{path:t,message:u.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}]:[],"validate")},{type:"string",errorMessage:o((e,t)=>u.VALIDATE.INVALID_FONT_WEIGHT(e,t),"errorMessage"),validate:o((e,t,n)=>Re.includes(e.toLowerCase())?[]:[{path:t,message:u.VALIDATE.INVALID_FONT_WEIGHT(e,t),source:n}],"validate")}]}};function je(e,t,n){return $(J.schema,e,t,n)}o(je,"validateFontWeight");const Me=["ms","s"],k={tokenType:"duration",schema:{type:"object",errorMessage:o((e,t)=>u.VALIDATE.INVALID_DURATION(e,t),"errorMessage"),properties:{value:b.schema,unit:{type:"string",validate:o((e,t,n)=>Me.includes(e)?[]:[{path:t,message:u.VALIDATE.INVALID_DURATION_UNIT(e,t),source:n}],"validate")}},required:["value","unit"]}};function Pe(e,t,n){return $(k.schema,e,t,n)}o(Pe,"validateDuration");const Z={tokenType:"cubicBezier",schema:{type:"array",errorMessage:o((e,t)=>u.VALIDATE.INVALID_CUBIC_BEZIER(e,t),"errorMessage"),validate:o((e,t,n)=>{const r=e;if(r.length!==4||!r.every(a=>typeof a=="number"))return[{path:t,message:u.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}];const[s,,i]=r;return s<0||s>1||i<0||i>1?[{path:t,message:u.VALIDATE.INVALID_CUBIC_BEZIER(e,t),source:n}]:[]},"validate")}};function Ue(e,t,n){return $(Z.schema,e,t,n)}o(Ue,"validateCubicBezier");const Ge={tokenType:"typography",schema:{type:"object",properties:{fontFamily:X.schema,fontSize:E.schema,letterSpacing:E.schema,lineHeight:b.schema,fontWeight:J.schema},required:["fontFamily","fontSize"],errorMessage:o((e,t)=>u.VALIDATE.INVALID_TYPOGRAPHY(e,t),"errorMessage")}};function We(e,t,n){return $(Ge.schema,e,t,n)}o(We,"validateTypography");const ze=["solid","dashed","dotted","double","groove","ridge","outset","inset"],Ye=["round","butt","square"],Be={type:"object",errorMessage:o((e,t)=>u.VALIDATE.INVALID_STROKE_STYLE(e,t),"errorMessage"),properties:{dashArray:{type:"array",validate:o((e,t,n)=>{const r=e,s=[];return r.forEach((i,a)=>{typeof i!="string"&&s.push(...$(E.schema,i,`${t}.${a}`,n))}),s},"validate")},lineCap:{type:"string",validate:o((e,t,n)=>Ye.includes(e)?[]:[{path:t,message:u.VALIDATE.INVALID_STROKE_LINE_CAP(e,t),source:n}],"validate")}},required:["dashArray","lineCap"]},Q={tokenType:"strokeStyle",schema:{type:"union",oneOf:[{type:"string",validate:o((e,t,n)=>!ze.includes(e)&&typeof e=="string"?[{path:t,message:u.VALIDATE.INVALID_STROKE_STYLE(e,t),source:n}]:[],"validate")},Be]}};function He(e,t,n){return $(Q.schema,e,t,n)}o(He,"validateStrokeStyle");const qe={tokenType:"border",schema:{type:"object",properties:{color:N.schema,width:E.schema,style:Q.schema},required:["color","width","style"],errorMessage:o((e,t)=>u.VALIDATE.INVALID_BORDER(e,t),"errorMessage")}};function Ke(e,t,n){return $(qe.schema,e,t,n)}o(Ke,"validateBorder");const Xe={tokenType:"transition",schema:{type:"object",properties:{duration:k.schema,delay:k.schema,timingFunction:Z.schema},required:["duration","delay","timingFunction"],errorMessage:o((e,t)=>u.VALIDATE.INVALID_TRANSITION(e,t),"errorMessage")}};function Je(e,t,n){return $(Xe.schema,e,t,n)}o(Je,"validateTransition");const ee={tokenType:"shadow",schema:{type:"object",properties:{color:N.schema,offsetX:E.schema,offsetY:E.schema,blur:E.schema,spread:E.schema,inset:{type:"boolean",errorMessage:o((e,t)=>u.VALIDATE.INVALID_SHADOW_INSET(e,t),"errorMessage")}},required:["color","offsetX","offsetY","blur","spread"],errorMessage:o((e,t)=>u.VALIDATE.INVALID_SHADOW(e,t),"errorMessage")}};function Ze(e,t,n){const r=[];return Array.isArray(e)?(e.forEach((s,i)=>{r.push(...$(ee.schema,s,`${t}[${i}]`,n))}),r):$(ee.schema,e,t,n)}o(Ze,"validateShadow");const Qe={type:"object",errorMessage:o((e,t)=>u.VALIDATE.INVALID_GRADIENT(e,t),"errorMessage"),properties:{color:{type:"string",validate:N.schema.validate},position:{type:"number",validate:o((e,t,n)=>e<0||e>1?[{path:t,message:u.VALIDATE.INVALID_GRADIENT_STOP_POSITION(e,t),source:n}]:[],"validate")}},required:["color","position"]},et={tokenType:"gradient",schema:{type:"array",errorMessage:o((e,t)=>u.VALIDATE.INVALID_ARRAY(e,t),"errorMessage"),validate:o((e,t,n)=>{const r=e,s=[];return r.forEach((i,a)=>{s.push(...$(Qe,i,`${t}[${a}]`,n))}),s},"validate")}};function tt(e,t,n){return $(et.schema,e,t,n)}o(tt,"validateGradient");const nt={tokenType:"fluidDimension",schema:{type:"object",errorMessage:o((e,t)=>u.VALIDATE.INVALID_FLUID_DIMENSION(e,t),"errorMessage"),properties:{min:E.schema,max:E.schema},required:["min","max"]}};function rt(e,t,n){return $(nt.schema,e,t,n)}o(rt,"validateFluidDimension");const ot={color:ve,dimension:xe,fluidDimension:rt,duration:Pe,cubicBezier:Ue,fontFamily:Ce,fontWeight:je,number:we,strokeStyle:He,typography:We,border:Ke,shadow:Ze,gradient:tt,transition:Je};function v(e){const t=[];for(const[n,r]of Object.entries(e.tokens)){if(typeof r!="object"||r===null||!("$type"in r)||!("$path"in r)||r.$path.startsWith("$"))continue;if(!("$value"in r)){t.push({path:r.$path,message:u.VALIDATE.MISSING_REQUIRED_PROPERTY("$value",r.$path),source:r.$source});continue}const s=ot[r.$type];if(!s){t.push({path:r.$path,message:u.VALIDATE.UNKNOWN_TOKEN_TYPE(r.$type,r.$path),source:r.$source});continue}const i=r;t.push(...s(i.$value,i.$path,i.$source))}return t}o(v,"validate");function S(e,t,n,r){return typeof t=="string"&&h(t)?st(e,t,n,r):Array.isArray(t)?t.map(s=>S(e,s,n,r)):typeof t=="object"&&t!==null?Object.entries(t).reduce((i,[a,c])=>({...i,[a]:S(`${e}.${a}`,c,n,r)}),{}):t}o(S,"resolveValue");function w(e){const t={},n=new Set,r=[];for(const[s,i]of Object.entries(e.tokens))try{if(!("$value"in i)){t[s]=i;continue}const a=i;t[s]={...a,$resolvedValue:S(a.$path,a.$value,e,n)}}catch(a){const c=a instanceof Error?a.message:String(a),l=i,f=l.$path,p=l.$source;let d,I;c.includes("Circular reference detected")?(d="circular",I=c):c.includes("Reference not found")?(d="missing",I=c):(d="type-mismatch",I=u.RESOLVE.TYPE_MISMATCH(f)),r.push({type:d,path:f,source:p,message:I})}return{resolved:t,errors:r}}o(w,"resolve");function st(e,t,n,r){const s=t.slice(1,-1),i=n.pathIndex.get(s);if(!i)throw new Error(u.RESOLVE.REFERENCE_NOT_FOUND(s,e));if(r.has(i)){const l=n.tokens[i];throw!l||!("$path"in l)?new Error(u.RESOLVE.REFERENCE_NOT_FOUND(s,e)):new Error(u.RESOLVE.CIRCULAR_REFERENCE(e,l.$path))}const a=n.tokens[i];if(!a||!("$value"in a))throw new Error(u.RESOLVE.REFERENCE_NOT_FOUND(s,e));r.add(i);const c=S(i,a.$value,n,r);return r.delete(i),c}o(st,"resolveReferenceChain");function x(e,t){const n=new Map;for(const[r,s]of Object.entries(t)){if(!("$source"in s)){for(const l of e){const f=l.collection;n.has(f)||n.set(f,new Map);const p=n.get(f),d=l.theme;p.has(d)||p.set(d,{}),p.get(d)[r]=s}continue}const i=s.$source.collection,a=s.$source.theme;n.has(i)||n.set(i,new Map);const c=n.get(i);c.has(void 0)||c.set(void 0,{}),a||(c.get(void 0)[r]=s),a&&(c.has(a)||c.set(a,{}),c.get(a)[r]=s)}return e.map(r=>{const s=n.get(r.collection);if(!s)return{collection:r.collection,theme:r.theme,tokens:{}};if(r.theme){const i=s.get(r.theme)||{};return{collection:r.collection,theme:r.theme,tokens:i}}else{const i=s.get(void 0)||{};return{collection:r.collection,theme:r.theme,tokens:i}}})}o(x,"processTrees");function D(e){return["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","emoji","math","fangsong"].includes(e.toLowerCase())?e:/[\s'"!@#$%^&*()=+[\]{};:|\\/,.<>?~]/.test(e)?`"${e}"`:e}o(D,"quoteFont");const it={thin:100,hairline:100,"extra-light":200,"ultra-light":200,light:300,normal:400,regular:400,book:400,medium:500,"semi-bold":600,"demi-bold":600,bold:700,"extra-bold":800,"ultra-bold":800,black:900,heavy:900,"extra-black":950,"ultra-black":950};function te(e){return h(e)?{value:e}:typeof e=="number"?{value:e}:{value:it[e.toLowerCase()]??e}}o(te,"convertFontWeightToken");function at(e){if(h(e))return{"font-family":e,"font-size":e};const t={"font-family":h(e.fontFamily)?e.fontFamily:Array.isArray(e.fontFamily)?e.fontFamily.map(n=>D(n)).join(", "):D(e.fontFamily),"font-size":h(e.fontSize)?e.fontSize:`${e.fontSize.value}${e.fontSize.unit}`};return e.fontWeight&&(t["font-weight"]=h(e.fontWeight)?e.fontWeight:te(e.fontWeight).value),e.letterSpacing&&(t["letter-spacing"]=h(e.letterSpacing)?e.letterSpacing:`${e.letterSpacing.value}${e.letterSpacing.unit}`),e.lineHeight&&(t["line-height"]=(h(e.lineHeight),e.lineHeight)),t}o(at,"convertTypographyToken");function ne(e){return e?`${e.value}${e.unit}`:"0ms"}o(ne,"formatDuration");function ct(e){if(h(e))return{value:e};const t=h(e.duration)?e.duration:ne(e.duration),n=h(e.timingFunction)?e.timingFunction:`cubic-bezier(${e.timingFunction.join(", ")})`,r=e.delay&&(h(e.delay)?e.delay:ne(e.delay));return{value:[t,n,r].filter(Boolean).join(" ")}}o(ct,"convertTransitionToken");function lt(e){return h(e)?{value:e}:{value:`cubic-bezier(${e.join(", ")})`}}o(lt,"convertCubicBezierToken");function ut(e){return h(e)?{value:e}:{value:e}}o(ut,"convertNumberToken");function ft(e){return h(e)?{value:e}:{value:`${e.value}${e.unit}`}}o(ft,"convertDurationToken");function re(e){return h(e)?{value:e}:typeof e=="string"?{value:e}:{value:`${e.dashArray.map(n=>h(n)?n:`${n.value}${n.unit}`).join(" ")} ${e.lineCap}`}}o(re,"convertStrokeStyleToken");function dt(e){if(h(e))return{value:e};const t=h(e.width)?e.width:`${e.width.value}${e.width.unit}`,n=(h(e.color),e.color),r=typeof e.style=="string"?e.style:re(e.style).value;return{value:`${t} ${r} ${n}`}}o(dt,"convertBorderToken");function oe(e){const t=h(e.offsetX)?e.offsetX:`${e.offsetX.value}${e.offsetX.unit}`,n=h(e.offsetY)?e.offsetY:`${e.offsetY.value}${e.offsetY.unit}`,r=h(e.blur)?e.blur:`${e.blur.value}${e.blur.unit}`,s=h(e.spread)?e.spread:`${e.spread.value}${e.spread.unit}`,i=(h(e.color),e.color);return`${e.inset?"inset ":""}${t} ${n} ${r} ${s} ${i}`}o(oe,"convertSingleShadow");function pt(e){return h(e)?{value:e}:Array.isArray(e)?{value:e.map(oe).join(", ")}:{value:oe(e)}}o(pt,"convertShadowToken");function ht(e){return h(e)?{value:e}:{value:`linear-gradient(${e.map(n=>{const r=(h(n.color),n.color),s=h(n.position)?n.position:`${n.position*100}`;return`${r} ${s}%`}).join(", ")})`}}o(ht,"convertGradientToken");function mt(e){return h(e)?{value:e}:{value:Array.isArray(e)?e.map(n=>D(n)).join(", "):D(e)}}o(mt,"convertFontFamilyToken");function It(e){return h(e)?{value:e}:{value:`${e.value}${e.unit}`}}o(It,"convertDimensionToken");function se(e,t=16){return e.unit==="px"?e.value:e.value*t}o(se,"normalizeToPixels");function gt(e,t){const{min:n,max:r}=e,s=t.fluidConfig;if(!s)throw new Error(u.VALIDATE.MISSING_FLUID_CONFIG(t.path??""));const i=16,a=se(n,i),c=se(r,i),l=s.min,f=s.max;if(a===c)return{value:`${a/i}rem`};const p=a/i,d=c/i,I=l/i,g=f/i,y=(d-p)/(g-I),A=-1*I*y+p;return{value:`clamp(${p}rem, ${A.toFixed(2)}rem + ${(y*100).toFixed(2)}vw, ${d}rem)`}}o(gt,"convertFluidDimension");function $t(e,t){if(h(e))return{value:e};if(!t.fluidConfig)throw new Error(u.VALIDATE.MISSING_FLUID_CONFIG(t.path??""));return gt(e,t)}o($t,"convertFluidDimensionToken");function C(e){return e===1?"1":e===0?"0":e.toFixed(2)}o(C,"formatAlpha");function R(e,t){try{const n=t==="rgba"?"rgb":t==="hsla"?"hsl":t,r=_(n==="hex"?"rgb":n)(e);if(!r)throw new Error(`Failed to convert color ${e} to ${t}`);switch(n){case"hsl":{if(r.mode!=="hsl")throw new Error("Unexpected color mode");const s=Math.round(r.h??0),i=Math.round((r.s??0)*100),a=Math.round((r.l??0)*100),c=r.alpha;return c!==void 0?`hsl(${s} ${i}% ${a}% / ${C(c)})`:`hsl(${s} ${i}% ${a}%)`}case"oklch":{if(r.mode!=="oklch")throw new Error("Unexpected color mode");const s=r.l??0,i=r.c??0,a=r.h??0,c=r.alpha;return c!==void 0?`oklch(${s.toFixed(3)} ${i.toFixed(3)} ${a.toFixed(1)} / ${c.toFixed(2)})`:`oklch(${s.toFixed(3)} ${i.toFixed(3)} ${a.toFixed(1)})`}case"rgb":{if(r.mode!=="rgb")throw new Error("Unexpected color mode");const s=Math.round((r.r??0)*255),i=Math.round((r.g??0)*255),a=Math.round((r.b??0)*255),c=r.alpha;return c!==void 0?`rgb(${s} ${i} ${a} / ${C(c)})`:`rgb(${s} ${i} ${a})`}case"p3":{if(r.mode!=="p3")throw new Error("Unexpected color mode");const s=r.r??0,i=r.g??0,a=r.b??0,c=r.alpha;return c!==void 0?`color(display-p3 ${s.toFixed(6)} ${i.toFixed(6)} ${a.toFixed(6)} / ${C(c)})`:`color(display-p3 ${s.toFixed(6)} ${i.toFixed(6)} ${a.toFixed(6)})`}default:{const s=_("rgb")(r);return s?s.alpha!==void 0?Te(s):z(s):e}}}catch{const r=_("rgb")(e);return console.warn(`Failed to convert color ${e} to ${t}, falling back to hex`),r?z(r):e}}o(R,"convertHexToColorString");function yt(e,t){if(h(e))return{value:e};const n=t.colorFormat||"hex";try{const r=R(e,n);return n==="p3"?{value:R(e,"hex")||e,featureValues:[{query:"@supports (color: color(display-p3 1 1 1))",value:r||e}]}:{value:r||e}}catch{return console.warn(`Failed to convert color ${e} to ${n}, falling back to hex`),{value:R(e,"hex")}}}o(yt,"convertColorToken");const ie={duration:ft,number:ut,cubicBezier:lt,color:yt,dimension:It,fluidDimension:$t,typography:at,border:dt,shadow:pt,gradient:ht,transition:ct,strokeStyle:re,fontFamily:mt,fontWeight:te};function At(e,t){const n=ie[e.$type];return{...e.$description?{$description:e.$description}:{},...e.$extensions?{$extensions:e.$extensions}:{},$type:e.$type,$value:e.$value,$path:e.$path,$source:e.$source,$originalPath:e.$originalPath,$resolvedValue:e.$resolvedValue,$cssProperties:n(e.$value,t)}}o(At,"convertSingleToken");function ae(e,t){const n={};for(const[r,s]of Object.entries(e)){if(!s||typeof s!="object")continue;if(!("$type"in s)){n[r]={...s.$description?{$description:s.$description}:{},...s.$extensions?{$extensions:s.$extensions}:{}};continue}if(!ie[s.$type])continue;const i={fluidConfig:t.options?.fluid,colorFormat:t.options?.color,path:s.$path};n[r]=At(s,i)}return n}o(ae,"convertTokens");function j(e,t){const n={};for(const[r,s]of Object.entries(e)){const i={default:ae(s.default,t)};for(const[a,c]of Object.entries(s))a!=="default"&&(i[a]=ae(c,t));n[r]=i}return n}o(j,"convert");const ce=new Map;function Et(e){const t=ce.get(e);if(t)return t;const n=e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z])(?=[a-z])/g,"$1-$2").toLowerCase();return ce.set(e,n),n}o(Et,"toKebabCase");function M({collection:e,filename:t,separate:n,baseDir:r}){const s=`${t}.variables.css`;return e==="default"?`${r}/${s}`:`${r}/${e}/${s}`}o(M,"getOutputPath");const le="@supports (color: color(display-p3 1 1 1))";function Tt(e){return e.$type==="typography"}o(Tt,"isTypographyToken");function P(e){return e.split(".").join("-")}o(P,"formatCSSVarPath");function ue(e){return typeof e=="number"?e:typeof e!="string"?(console.warn("Unexpected value type in convertReferenceToCSSVar, got:",e),String(e)):e.replace(/\{([^}]+)\}/g,(t,n)=>`var(--${n.split(".").map(Et).join("-")})`)}o(ue,"convertReferenceToCSSVar");function Nt(e){const t=e.$cssProperties;if("value"in t)return{name:`--${P(e.$path)}`,value:ue(t.value)}}o(Nt,"generateSingleVariable");function bt(e){return Object.entries(e.$cssProperties).filter(([t,n])=>n!==void 0).map(([t,n])=>({name:`--${P(e.$path)}-${t}`,value:ue(n)}))}o(bt,"generateTypographyVariables");function fe(e){if(e.$type!=="color")return[];const t=e.$cssProperties;return"featureValues"in t?t.featureValues?.filter(n=>n.query===le).map(n=>({name:`--${P(e.$path)}`,value:n.value}))??[]:[]}o(fe,"generateFeatureVariables");function de(e){const t=[`${e.selector} {`];if(e.comment&&t.push(` /* ${e.comment} */`),e.vars.length>0){const n=e.vars.map(r=>` ${r.name}: ${r.value};`).join(`
|
|
2
4
|
`);t.push(n)}return t.push("}"),t.join(`
|
|
3
|
-
`)}o(
|
|
4
|
-
`).map(
|
|
5
|
+
`)}o(de,"generateCSSBlock");function St(e){const t=[];return e.root.vars.length>0&&t.push(de({selector:e.root.selector,vars:e.root.vars})),e.features.forEach(n=>{const s=de({selector:e.root.selector,vars:n.vars}).split(`
|
|
6
|
+
`).map(i=>` ${i}`).join(`
|
|
5
7
|
`);t.push(`${n.query} {
|
|
6
|
-
${
|
|
8
|
+
${s}
|
|
7
9
|
}`)}),t.filter(Boolean).join(`
|
|
8
10
|
|
|
9
|
-
`)}o(
|
|
11
|
+
`)}o(St,"convertCSSVarsToString");function Dt(e){if(Tt(e))return{vars:bt(e),features:fe(e)};const t=Nt(e);return{vars:t?[t]:[],features:fe(e)}}o(Dt,"generateVariablesForToken");async function U(e,t={}){const n=Object.entries(e).filter(([c,l])=>c!=="$extensions"&&"$type"in l).map(([c,l])=>Dt(l));let r=":root";t.theme&&t.theme!=="default"&&(r=`[data-theme="${t.theme}"]`);const s=n.flatMap(c=>c.vars),i=n.flatMap(c=>c.features||[]),a=St({root:{selector:r,vars:s},features:i.length?[{query:le,vars:i}]:[]});return a.trim()?{output:[{path:"tokens.variables.css",css:Lt(a)}]}:{output:[{path:"tokens.variables.css",css:""}]}}o(U,"generateCSS");function Lt(e){return e.endsWith(`
|
|
10
12
|
`)?e:e+`
|
|
11
|
-
`}o(
|
|
13
|
+
`}o(Lt,"formatCSSVars");async function G(e,t){const n={};for(const[r,s]of Object.entries(e)){n[r]={default:{}},s.default&&(n[r].default=s.default);for(const[i,a]of Object.entries(s))i!=="default"&&a&&(n[r][i]=a);Object.keys(n[r].default).length===0&&Object.keys(n[r]).length===1&&delete n[r]}return t.output.css.separate?{output:await Ot(n,t)}:{output:await _t(n,t)}}o(G,"generate");async function _t(e,t){const n=`${t.output.directories.css}/global/variables`,r=[];for(const[s,i]of Object.entries(e)){const a=[];for(const[c,l]of Object.entries(i)){const f=await U(l,{theme:c!=="default"?c:void 0,collection:s!=="default"?s:void 0});f.output[0].css.trim()&&a.push(f.output[0].css)}a.length>0&&r.push({path:M({collection:s,filename:"tokens",separate:!1,baseDir:n}),css:a.filter(Boolean).join(`
|
|
12
14
|
`).trim()+`
|
|
13
|
-
`})}return r}o(
|
|
15
|
+
`})}return r}o(_t,"generateSingleFile");async function Ot(e,t){const n=`${t.output.directories.css}/global/variables`,r=[];for(const[s,i]of Object.entries(e))if(Object.keys(i).length!==0){for(const[a,c]of Object.entries(i))if(Object.keys(c).length!==0)if(a==="default"){const l=new Map;for(const[f,p]of Object.entries(c)){if(!("$type"in p))continue;const I=p.$source.sourcePath;l.has(I)||l.set(I,{}),l.get(I)[f]=p}for(const[f,p]of l){if(Object.keys(p).length===0)continue;const d=f.split("/").pop()?.replace(/\.json$/,"")??"tokens",g=(await U(p,{collection:s==="default"?void 0:s})).output[0].css;g.trim()&&r.push({path:M({collection:s,filename:d,separate:!0,baseDir:n}),css:g})}}else{const f=(await U(c,{theme:a,collection:s==="default"?void 0:s})).output[0].css;f.trim()&&r.push({path:M({collection:s,filename:a,separate:!0,baseDir:n}),css:f})}}return r}o(Ot,"generateSeparateFiles");function W(e){const t=[],n=[],r=new Set,s=new Map;e.forEach(c=>{const{collection:l,theme:f="default"}=c;r.add(l),s.has(l)||s.set(l,new Set),s.get(l).add(f)});const i={};function a(c){const l={default:{}};i[c]=l;const f=s.get(c);return f&&f.forEach(p=>{l[p]={}}),l}return o(a,"addCollection"),r.forEach(c=>{a(c)}),e.forEach(c=>{const{collection:l,theme:f="default",tokens:p}=c,d=i[l]||a(l),I=d[f]||(d[f]={});Object.entries(p).forEach(([g,y])=>{const A=g.replace(`${l}.`,"");I[A]=y})}),{tokens:i,errors:n,warnings:t}}o(W,"normalizeTokens");async function Vt(e,t){const n={load:[],flatten:[],validation:[],resolution:[]},r={normalization:[]},{trees:s,errors:i}=await(t?.loader?.type==="memory"?V(t.loader.data):O(e));n.load.push(...i);const{tokens:a,errors:c}=F(s);n.flatten.push(...c);const l=v(a);if(n.validation.push(...l),l.length>0)return{output:[],trees:s,errors:n,warnings:r};const{resolved:f,errors:p}=w(a);n.resolution.push(...p);const d=x(s,f),{tokens:I,warnings:g}=W(d);r.normalization.push(...g);const y=j(I,e),{output:A}=await G(y,e);return{output:A,trees:s,errors:n,warnings:r}}o(Vt,"tokensToCSSPipeline");async function Ft(e,t){const{trees:n,errors:r}=await(t.loader.type==="memory"?V(t.loader.data):O(t.loader.paths)),{tokens:s,errors:i}=F(n),a=v(s),{resolved:c,errors:l}=w(s);return{trees:n,flattenedTokens:s,resolved:c,errors:{load:r,flatten:i,validation:a,resolution:l}}}o(Ft,"validationPipeline");async function kt(e,t,n){const r={normalization:[]},s=x(e,t),{tokens:i,warnings:a}=W(s);r.normalization.push(...a);const c=j(i,n),{output:l}=await G(c,n);return{output:l,warnings:r}}o(kt,"generationPipeline");function vt(e){return"source"in e&&Array.isArray(e.source)}o(vt,"isSingleCollection");function pe(e){return`/**
|
|
16
|
+
* \u26A0\uFE0F AUTOMATICALLY GENERATED FILE - DO NOT EDIT DIRECTLY \u26A0\uFE0F
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
${e}`}o(pe,"addWarningBanner");function wt(e){return vt(e.tokens)?e.tokens.source:Object.values(e.tokens).flatMap(t=>"source"in t?t.source:[])}o(wt,"getTokenPathsFromConfig");async function xt(e,t=!0,n){for(const r of e){const s=t&&n?pe(r.css):r.css;try{await be(T.dirname(r.path),{recursive:!0});let i=!0;if(H(r.path))try{await Y(r.path,"utf-8")===s&&(i=!1)}catch{}i&&await B(r.path,s,"utf-8")}catch(i){throw new Error(`Failed to write CSS file ${r.path}: ${i instanceof Error?i.message:"Unknown error"}`)}}return e}o(xt,"writeCSSFilesToDisk");const he=m.object({tokens:m.union([m.object({source:m.array(m.string()),type:m.enum(["starter-kit","custom"]),themes:m.record(m.array(m.string())).optional()}),m.record(m.string(),m.object({source:m.array(m.string()),type:m.enum(["starter-kit","custom"]),themes:m.record(m.array(m.string())).optional()}))]),options:m.object({fluid:m.object({min:m.number(),max:m.number()}).strict().optional(),prefix:m.string().optional(),color:m.enum(["hex","rgb","rgba","hsl","hsla","oklch","p3"]).optional()}).optional(),output:m.object({directories:m.object({tokens:m.string(),components:m.string().optional(),css:m.string()}),css:m.object({separate:m.boolean(),manageIndex:m.boolean().optional(),format:m.enum(["css","scss","less"]).optional()})})});function me(e){const t=he.safeParse(e);if(!t.success){const n=t.error.errors.map(r=>{const s=r.path.join(".");return u.CONFIG.INVALID_CONFIG(s||"root",r.message)});throw new Error(n.join(`
|
|
20
|
+
`))}return Ct(t.data),t.data}o(me,"validateConfig");function Ie(e){try{const t=JSON.parse(e);return me(t)}catch(t){throw t instanceof SyntaxError?new Error(u.CONFIG.INVALID_JSON(t.message)):t}}o(Ie,"parseAndValidateConfig");function Ct(e){if(typeof e.tokens=="object")for(const[t,n]of Object.entries(e.tokens)){if(!n.source?.length)continue;const r=new Map;n.source.forEach(s=>{const i=T.basename(s),a=r.get(i)||[];r.set(i,[...a,s])});for(const[s,i]of r)if(i.length>1)throw new Error(u.CONFIG.DUPLICATE_FILENAMES(t,s,i))}}o(Ct,"validateFileNames");async function Rt(e="sugarcube.config.json"){try{const t=await Ne.readFile(e,"utf-8");return Ie(t)}catch(t){throw t instanceof Error&&"code"in t&&t.code==="ENOENT"?new Error(u.CONFIG.FILE_NOT_FOUND(e)):t}}o(Rt,"loadConfig");function jt(e){const t=e.split("/"),n=t.findIndex(s=>s==="variables");if(n===-1||n===t.length-1)return"default";const r=t[n+1];return!r||r.endsWith(".css")?"default":r}o(jt,"getCollectionFromPath");function ge(e,t){if(e.includes("/variables/")){const n=jt(e),r=t.variables.get(n)??[];r.push(e),t.variables.set(n,r)}else e.startsWith("global/")?t.global.push(e):e.startsWith("compositions/")?t.compositions.push(e):e.startsWith("utilities/")&&t.utilities.push(e)}o(ge,"groupFile");async function Mt(e,t){const n={variables:new Map,global:[],compositions:[],utilities:[]},r=T.join(t,"index.css");let s="";H(r)&&(s=await Y(r,"utf-8"),s.split(`
|
|
21
|
+
`).filter(l=>l.trim().startsWith("@import")).map(l=>l.match(/'([^']+)'/)?.[1]).filter(l=>l!==void 0).forEach(l=>ge(l,n))),e.filter(c=>c.endsWith(".css")).forEach(c=>{const l=T.relative(t,c).replace(/\\/g,"/");ge(l,n)});const i=["reset.css","fonts.css","global-styles.css"];n.global.sort((c,l)=>{const f=i.findIndex(d=>c.endsWith(d)),p=i.findIndex(d=>l.endsWith(d));return f-p});const a=[];for(const[,c]of Array.from(n.variables.entries()).sort())c.length>0&&a.push(...c.sort().map(l=>`@import '${l}';`));return n.global.length>0&&(a.length&&a.push(""),a.push(...n.global.map(c=>`@import '${c}';`))),n.compositions.length>0&&(a.length&&a.push(""),a.push(...n.compositions.sort().map(c=>`@import '${c}';`))),n.utilities.length>0&&(a.length&&a.push(""),a.push(...n.utilities.sort().map(c=>`@import '${c}';`))),a.filter(Boolean).join(`
|
|
22
|
+
`)+`
|
|
23
|
+
`}o(Mt,"generateCSSIndex");async function Pt({cssOutputDirectory:e,files:t}){const n=t.filter(s=>s.endsWith(".css"));if(n.length===0)throw new Error("No CSS files to manage");const r=T.join(e,"index.css");try{const s=await Mt(n,e);return await B(r,s),r}catch(s){throw new Error(`Failed to manage CSS index file: ${s instanceof Error?s.message:String(s)}`)}}o(Pt,"manageCSSIndex");export{pe as addWarningBanner,he as configSchema,j as convert,F as flatten,G as generate,kt as generationPipeline,wt as getTokenPathsFromConfig,Rt as loadConfig,O as loadTreesFromConfig,V as loadTreesFromMemory,Pt as manageCSSIndex,W as normalizeTokens,Ie as parseAndValidateConfig,x as processTrees,w as resolve,Vt as tokensToCSSPipeline,v as validate,me as validateConfig,Ft as validationPipeline,xt as writeCSSFilesToDisk};
|
package/package.json
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sugarcube-org/core",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.4",
|
|
4
4
|
"publishConfig": {
|
|
5
|
-
"access": "
|
|
5
|
+
"access": "public"
|
|
6
6
|
},
|
|
7
|
+
"description": "Core functionality for sugarcube",
|
|
8
|
+
"license": "AGPL-3.0",
|
|
7
9
|
"main": "./dist/index.js",
|
|
8
10
|
"types": "./dist/index.d.ts",
|
|
9
11
|
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./dist/index.js"
|
|
14
|
+
},
|
|
10
15
|
"files": [
|
|
11
16
|
"dist",
|
|
12
17
|
"README.md"
|
|
13
18
|
],
|
|
14
19
|
"devDependencies": {
|
|
20
|
+
"@vitest/coverage-istanbul": "2.1.2",
|
|
15
21
|
"pkgroll": "^2.5.1",
|
|
16
22
|
"tsx": "^4.19.2"
|
|
17
23
|
},
|
|
@@ -27,8 +33,10 @@
|
|
|
27
33
|
"scripts": {
|
|
28
34
|
"build": "pkgroll --minify",
|
|
29
35
|
"dev": "pkgroll --watch",
|
|
30
|
-
"test": "vitest
|
|
36
|
+
"test": "vitest --no-watch",
|
|
31
37
|
"test:watch": "vitest",
|
|
38
|
+
"test:coverage": "vitest run --coverage",
|
|
39
|
+
"test:bench": "vitest bench --no-watch",
|
|
32
40
|
"type-check": "tsc --noEmit",
|
|
33
41
|
"ci": "pnpm type-check && pnpm test"
|
|
34
42
|
}
|