@barocss/kit 0.0.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,10 +13,10 @@
13
13
  - **🚀 JIT Parsing** - Parse Tailwind syntax and generate CSS instantly
14
14
  - **🔍 AST Processing** - Advanced Abstract Syntax Tree manipulation
15
15
  - **⚡ Incremental Parsing** - Efficient parsing with caching
16
- - **🎯 Tailwind Compatible** - Full Tailwind CSS syntax support
16
+ - **🎯 Tailwind-style syntax** - See the [versioned compatibility baseline](docs/tailwind-compatibility.md)
17
17
  - **🌐 Universal** - Works in browsers, Node.js, and any JavaScript environment
18
- - **🎨 Complete Utility Support** - Layout, spacing, colors, typography, and more
19
- - **📱 Responsive & Interactive** - All variants work out of the box
18
+ - **🎨 Utility presets** - Layout, spacing, colors, typography, and more
19
+ - **📱 Responsive & interactive variants** - See the measured examples below
20
20
  - **🧠 Smart Caching** - Caching system for performance optimization
21
21
 
22
22
  ## 🚀 Quick Start
@@ -234,7 +234,7 @@ const stats = parser.getStats();
234
234
 
235
235
  ## 📱 Supported Utilities
236
236
 
237
- BaroCSS supports **most Tailwind CSS utilities**:
237
+ BaroCSS supports the utilities listed below. See the [compatibility baseline](docs/tailwind-compatibility.md) for measured examples.
238
238
 
239
239
  ### Layout
240
240
  - `container`, `columns`, `break-after`, `break-before`
package/dist/index.d.ts CHANGED
@@ -72,6 +72,87 @@ export declare type AstNode = {
72
72
 
73
73
  export declare function atRule(name: string, params: string, nodes: AstNode[], source?: string): AstNode;
74
74
 
75
+ /**
76
+ * The structured input format for BaroCSS engine.
77
+ * Designed to be easily generated by AI models.
78
+ */
79
+ export declare type BaroJsonInput = {
80
+ /**
81
+ * The core utility to apply.
82
+ * Corresponds to the utility class name in Tailwind (e.g., 'bg-red-500', 'p-4').
83
+ */
84
+ utility: {
85
+ /**
86
+ * The utility prefix.
87
+ * @example 'bg', 'text', 'p', 'm', 'flex', 'hidden'
88
+ */
89
+ name: string;
90
+ /**
91
+ * The value of the utility.
92
+ * Optional for boolean utilities like 'flex', 'hidden'.
93
+ * @example 'red-500', '4', 'lg', '#123456'
94
+ */
95
+ value?: string;
96
+ /**
97
+ * Whether the value is an arbitrary value (JIT).
98
+ * @default false
99
+ * @example true for 'bg-[#123456]'
100
+ */
101
+ arbitrary?: boolean;
102
+ /**
103
+ * Whether the value is negative.
104
+ * @default false
105
+ * @example true for '-m-4'
106
+ */
107
+ negative?: boolean;
108
+ /**
109
+ * Opacity modifier for colors.
110
+ * @example '50' for 'bg-red-500/50'
111
+ */
112
+ opacity?: string;
113
+ /**
114
+ * Whether the value is a custom property.
115
+ * @default false
116
+ * @example true for 'bg-(--my-bg)'
117
+ */
118
+ customProperty?: boolean;
119
+ /**
120
+ * Whether the utility is marked as important (!).
121
+ * @default false
122
+ * @example true for '!bg-red-500'
123
+ */
124
+ important?: boolean;
125
+ };
126
+ /**
127
+ * List of variants/modifiers to apply.
128
+ * Applied from outside to inside (left to right in string format).
129
+ * @example ['hover', 'focus'] for 'hover:focus:bg-red-500'
130
+ */
131
+ variants?: Array<string | BaroVariant>;
132
+ };
133
+
134
+ /**
135
+ * Detailed configuration for a variant.
136
+ */
137
+ export declare type BaroVariant = {
138
+ /**
139
+ * The name of the variant.
140
+ * @example 'hover', 'focus', 'sm', 'data', 'group-hover'
141
+ */
142
+ name: string;
143
+ /**
144
+ * The value for parameterized variants.
145
+ * @example 'open' for 'data-[state=open]'
146
+ */
147
+ value?: string;
148
+ /**
149
+ * Whether the variant is arbitrary.
150
+ * @default false
151
+ * @example true for 'min-[320px]'
152
+ */
153
+ arbitrary?: boolean;
154
+ };
155
+
75
156
  /**
76
157
  * Clear all caches (for context changes or testing)
77
158
  */
@@ -80,7 +161,7 @@ export declare type AstNode = {
80
161
  /**
81
162
  * Clear all AST caches (mainly for testing)
82
163
  */
83
- export declare function clearAstCache(): void;
164
+ export declare function clearAstCache(ctx?: Context): void;
84
165
 
85
166
  /**
86
167
  * collectDeclPaths
@@ -123,9 +204,8 @@ export declare type AstNode = {
123
204
  */
124
205
  preflight?: PreflightLevel;
125
206
  /**
126
- * Whether to clear all caches when context is created/changed
127
- * - true (default): Clear all caches on context change
128
- * - false: Keep existing caches
207
+ * @deprecated Contexts now own their caches. Creating a context does not
208
+ * clear caches that belong to another context.
129
209
  */
130
210
  clearCacheOnContextChange?: boolean;
131
211
  [key: string]: unknown;
@@ -170,7 +250,7 @@ export declare type AstNode = {
170
250
 
171
251
  declare type Function_2 = (...args: unknown[]) => unknown;
172
252
 
173
- export declare function functionalModifier(match: ModifierRegistration['match'], modifySelector: ModifierRegistration['modifySelector'], wrap?: ModifierRegistration['wrap'], options?: Partial<ModifierRegistration>): void;
253
+ export declare function functionalModifier(match: ModifierRegistration['match'], modifySelector: ModifierRegistration['modifySelector'], wrap?: ModifierRegistration['wrap'], options?: Partial<ModifierRegistration>, ctx?: Context): void;
174
254
 
175
255
  /**
176
256
  * functionalUtility: A helper that registers dynamic utilities (theme, arbitrary, custom, negative, fraction, etc.) directly
@@ -186,7 +266,7 @@ export declare type AstNode = {
186
266
  * category: 'layout',
187
267
  * });
188
268
  */
189
- export declare function functionalUtility(opts: FunctionalUtilityOptions): void;
269
+ export declare function functionalUtility(opts: FunctionalUtilityOptions, ctx?: Context): void;
190
270
 
191
271
  export declare type FunctionalUtilityExtra = {
192
272
  opacity?: string;
@@ -407,6 +487,18 @@ export declare type AstNode = {
407
487
  dedup?: boolean;
408
488
  }): string;
409
489
 
490
+ /**
491
+ * Generates CSS from a list of BaroJsonInput objects.
492
+ *
493
+ * @param inputs Array of BaroJsonInput
494
+ * @param ctx Context
495
+ * @param opts Options (minify, etc.)
496
+ * @returns CSS string
497
+ */
498
+ export declare function generateCssFromJson(inputs: BaroJsonInput[], ctx: Context, opts?: {
499
+ minify?: boolean;
500
+ }): string;
501
+
410
502
  /**
411
503
  * Returns an array of optimized results for multiple class names with dedup/filter.
412
504
  * - Each object: { cls, ast, css }
@@ -431,11 +523,18 @@ export declare type AstNode = {
431
523
  rootCssList: string[];
432
524
  };
433
525
 
434
- export declare function getModifier(): ModifierRegistration[];
526
+ /** Read AST cache statistics for one context, or the legacy global cache. */
527
+ export declare function getAstCacheStats(ctx?: Context): {
528
+ size: number;
529
+ maxSize: number;
530
+ hitRate: number;
531
+ };
532
+
533
+ export declare function getModifier(ctx?: Context): ModifierRegistration[];
435
534
 
436
535
  export declare function getPreflightCSS(level?: PreflightLevel): string;
437
536
 
438
- export declare function getUtility(): UtilityRegistration[];
537
+ export declare function getUtility(ctx?: Context): UtilityRegistration[];
439
538
 
440
539
  export declare type HasItems = {
441
540
  items?: AstNode[];
@@ -664,6 +763,16 @@ export declare type AstNode = {
664
763
  getProcessedClasses(): string[];
665
764
  }
666
765
 
766
+ /**
767
+ * Converts a single BaroJsonInput object into an AST tree.
768
+ * Bypasses string parsing and directly invokes utility/modifier handlers.
769
+ *
770
+ * @param input BaroJsonInput object
771
+ * @param ctx Context
772
+ * @returns AstNode[]
773
+ */
774
+ export declare function jsonToAst(input: BaroJsonInput, ctx: Context): AstNode[];
775
+
667
776
  /**
668
777
  * mergeAstTreeList
669
778
  * Takes a list of declPathToAst results (AstNode[][]), merges same at-rule(name, params) etc., and returns the final AST tree.
@@ -685,13 +794,7 @@ export declare type AstNode = {
685
794
  context: Context;
686
795
  variantChain?: ParsedModifier[];
687
796
  index?: number;
688
- }) => string | {
689
- selector: string;
690
- flatten?: boolean;
691
- wrappingType?: 'rule' | 'style-rule' | 'at-rule';
692
- override?: boolean;
693
- source?: string;
694
- };
797
+ }) => string | ModifierSelector | ModifierSelector[];
695
798
  wrap?: (mod: ParsedModifier, context: Context) => AstNode[];
696
799
  astHandler?: (ast: AstNode[], mod: ParsedModifier, context: Context, variantChain?: ParsedModifier[], index?: number) => AstNode[];
697
800
  sort?: number;
@@ -701,6 +804,14 @@ export declare type AstNode = {
701
804
 
702
805
  export declare const modifierRegistry: ModifierRegistration[];
703
806
 
807
+ export declare type ModifierSelector = {
808
+ selector: string;
809
+ flatten?: boolean;
810
+ wrappingType?: 'rule' | 'style-rule' | 'at-rule';
811
+ override?: boolean;
812
+ source?: string;
813
+ };
814
+
704
815
  /**
705
816
  * optimizeAst
706
817
  * Merges/organizes AST generated by parseClassToAst into an optimized AST tree based on decl-to-root path.
@@ -728,7 +839,7 @@ export declare type AstNode = {
728
839
  * @param className e.g. 'group-hover:sm:bg-[red]', 'text-[color:var(--foo)]'
729
840
  * @returns { modifiers, utility }
730
841
  */
731
- export declare function parseClassName(className: string): {
842
+ export declare function parseClassName(className: string, ctx?: Context): {
732
843
  modifiers: ParsedModifier[];
733
844
  utility: ParsedUtility | null;
734
845
  };
@@ -809,7 +920,9 @@ export declare type AstNode = {
809
920
 
810
921
  export declare function raw(value: string, source?: string): AstNode;
811
922
 
812
- export declare function registerUtility(util: UtilityRegistration): void;
923
+ export declare function registerModifier(modifier: ModifierRegistration, ctx?: Context): void;
924
+
925
+ export declare function registerUtility(util: UtilityRegistration, ctx?: Context): void;
813
926
 
814
927
  export declare function resolveTheme(config: Config): Theme;
815
928
 
@@ -817,6 +930,9 @@ export declare type AstNode = {
817
930
 
818
931
  export declare function rule(selector: string, nodes: AstNode[], source?: string): AstNode;
819
932
 
933
+ /** Internal hook for caches owned by contexts. */
934
+ export declare function setContextCacheReset(reset: () => void): void;
935
+
820
936
  /**
821
937
  * staticModifier: A helper that registers a modifier name and an array of CSS selectors directly to the registry
822
938
  *
@@ -831,7 +947,7 @@ export declare type AstNode = {
831
947
  *
832
948
  * @returns {void}
833
949
  */
834
- export declare function staticModifier(name: string, selectors: string[], options?: any): void;
950
+ export declare function staticModifier(name: string, selectors: string[], options?: any, ctx?: Context): void;
835
951
 
836
952
  /**
837
953
  * staticUtility: A helper that registers a utility name and an array of CSS declaration pairs directly to the registry
@@ -861,7 +977,7 @@ export declare type AstNode = {
861
977
  description?: string;
862
978
  category?: string;
863
979
  priority?: number;
864
- }): void;
980
+ }, ctx?: Context): void;
865
981
 
866
982
  declare type StaticUtilityValue = AstNode | [string, string] | [string, [string, string][]] | ((value: string) => AstNode);
867
983