@barocss/kit 0.8.1 → 0.8.2

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.
@@ -0,0 +1,1245 @@
1
+ /** Arbitrary property class `[prop:value]` (parser sets token.property). */
2
+ export declare const arbitraryPropertyRegistration: UtilityRegistration;
3
+
4
+ /**
5
+ * AST cache management
6
+ */
7
+ export declare class AstCache {
8
+ private cache;
9
+ private maxSize;
10
+ set(key: string, ast: AstNode[]): void;
11
+ get(key: string): AstNode[] | undefined;
12
+ has(key: string): boolean;
13
+ clear(): void;
14
+ getStats(): {
15
+ size: number;
16
+ maxSize: number;
17
+ hitRate: number;
18
+ };
19
+ }
20
+
21
+ export declare const astCache: AstCache;
22
+
23
+ export declare type AstNode = {
24
+ type: "wrap";
25
+ items: AstNode[];
26
+ source?: string;
27
+ } | {
28
+ type: "decl";
29
+ prop: string;
30
+ value: string | [string, string][];
31
+ source?: string;
32
+ } | {
33
+ type: "at-rule";
34
+ name: string;
35
+ params: string;
36
+ nodes: AstNode[];
37
+ source?: string;
38
+ } | {
39
+ type: "style-rule";
40
+ selector: string;
41
+ nodes: AstNode[];
42
+ source?: string;
43
+ } | {
44
+ type: "rule";
45
+ selector: string;
46
+ nodes: AstNode[];
47
+ source?: string;
48
+ } | {
49
+ type: "at-root";
50
+ nodes: AstNode[];
51
+ source?: string;
52
+ } | {
53
+ type: "comment";
54
+ text: string;
55
+ source?: string;
56
+ } | {
57
+ type: "raw";
58
+ value: string;
59
+ source?: string;
60
+ };
61
+
62
+ /**
63
+ * Converts AST nodes to CSS string
64
+ * @param ast { AstNode[] } - Array of AST nodes to convert
65
+ * @param baseSelector { string } - Base selector for nested rules (e.g., ".parent" for ".parent .child")
66
+ * @param opts { minify?: boolean } - Options for CSS generation
67
+ * @param _indent { string } - Current indentation level for pretty formatting
68
+ */
69
+ export declare function astToCss(ast: AstNode[], baseSelector?: string, opts?: {
70
+ minify?: boolean;
71
+ important?: boolean;
72
+ }, _indent?: string): string;
73
+
74
+ export declare function atRoot(nodes: AstNode[], source?: string): AstNode;
75
+
76
+ export declare function atRule(name: string, params: string, nodes: AstNode[], source?: string): AstNode;
77
+
78
+ /**
79
+ * The structured input format for BaroCSS engine.
80
+ * Designed to be easily generated by AI models.
81
+ */
82
+ export declare type BaroJsonInput = {
83
+ /**
84
+ * The core utility to apply.
85
+ * Corresponds to the utility class name in Tailwind (e.g., 'bg-red-500', 'p-4').
86
+ */
87
+ utility: {
88
+ /**
89
+ * The utility prefix.
90
+ * @example 'bg', 'text', 'p', 'm', 'flex', 'hidden'
91
+ */
92
+ name: string;
93
+ /**
94
+ * The value of the utility.
95
+ * Optional for boolean utilities like 'flex', 'hidden'.
96
+ * @example 'red-500', '4', 'lg', '#123456'
97
+ */
98
+ value?: string;
99
+ /**
100
+ * Whether the value is an arbitrary value (JIT).
101
+ * @default false
102
+ * @example true for 'bg-[#123456]'
103
+ */
104
+ arbitrary?: boolean;
105
+ /**
106
+ * Whether the value is negative.
107
+ * @default false
108
+ * @example true for '-m-4'
109
+ */
110
+ negative?: boolean;
111
+ /**
112
+ * Opacity modifier for colors.
113
+ * @example '50' for 'bg-red-500/50'
114
+ */
115
+ opacity?: string;
116
+ /**
117
+ * Whether the value is a custom property.
118
+ * @default false
119
+ * @example true for 'bg-(--my-bg)'
120
+ */
121
+ customProperty?: boolean;
122
+ /**
123
+ * Whether the utility is marked as important (!).
124
+ * @default false
125
+ * @example true for '!bg-red-500'
126
+ */
127
+ important?: boolean;
128
+ };
129
+ /**
130
+ * List of variants/modifiers to apply.
131
+ * Applied from outside to inside (left to right in string format).
132
+ * @example ['hover', 'focus'] for 'hover:focus:bg-red-500'
133
+ */
134
+ variants?: Array<string | BaroVariant>;
135
+ };
136
+
137
+ /**
138
+ * Detailed configuration for a variant.
139
+ */
140
+ export declare type BaroVariant = {
141
+ /**
142
+ * The name of the variant.
143
+ * @example 'hover', 'focus', 'sm', 'data', 'group-hover'
144
+ */
145
+ name: string;
146
+ /**
147
+ * The value for parameterized variants.
148
+ * @example 'open' for 'data-[state=open]'
149
+ */
150
+ value?: string;
151
+ /**
152
+ * Whether the variant is arbitrary.
153
+ * @default false
154
+ * @example true for 'min-[320px]'
155
+ */
156
+ arbitrary?: boolean;
157
+ };
158
+
159
+ /**
160
+ * Clear all caches (for context changes or testing)
161
+ */
162
+ export declare function clearAllCaches(): void;
163
+
164
+ /**
165
+ * Clear all AST caches (mainly for testing)
166
+ */
167
+ export declare function clearAstCache(ctx?: Context): void;
168
+
169
+ /**
170
+ * collectDeclPaths
171
+ * Collects all paths from AST tree to decl(leaf) (including variant chains).
172
+ * - Input: AST node array
173
+ * - Output: decl-to-root path(variant chain) array
174
+ * - Usage: Used for path extraction for AST optimization/merging in optimizeAst, declPathToAst, etc.
175
+ *
176
+ * @param nodes AstNode[] - AST tree
177
+ * @param path PathNode[] - Recursive use (initial value omitted)
178
+ * @returns DeclPath[] - Array of paths to decl (variant chains)
179
+ */
180
+ export declare function collectDeclPaths(nodes?: AstNode[], path?: PathNode[]): DeclPath[];
181
+
182
+ export declare function comment(text: string, source?: string): AstNode;
183
+
184
+ export declare function compareKeys(a: RuleKey, b: RuleKey): number;
185
+
186
+ export declare interface Config {
187
+ prefix?: string;
188
+ cssVarPrefix?: string;
189
+ /**
190
+ * Modern dark mode strategy
191
+ * - 'media': uses @media (prefers-color-scheme: dark)
192
+ * - 'class': uses .dark selector
193
+ * - string[]: custom selectors (e.g. ['class', '[data-theme="dark"]'])
194
+ */
195
+ darkMode?: 'media' | 'class' | string[];
196
+ theme?: Theme;
197
+ presets?: {
198
+ theme: Theme;
199
+ }[];
200
+ /**
201
+ * Whether to include preflight CSS
202
+ * - 'minimal': Minimal preflight CSS
203
+ * - 'standard': Standard preflight CSS
204
+ * - 'full': Full preflight CSS
205
+ * - true: Full preflight CSS (default)
206
+ * - false: No preflight CSS
207
+ *
208
+ * default: true (full preflight)
209
+ */
210
+ preflight?: PreflightLevel;
211
+ /**
212
+ * Enable kit console diagnostics (off by default).
213
+ * This sets a process-wide flag (see setDebug): it affects every context, and a
214
+ * config without this key leaves the current flag unchanged.
215
+ */
216
+ debug?: boolean;
217
+ /**
218
+ * @deprecated Contexts now own their caches. Creating a context does not
219
+ * clear caches that belong to another context.
220
+ */
221
+ clearCacheOnContextChange?: boolean;
222
+ /**
223
+ * #287: static custom utilities, the runtime mirror of a stylesheet's static `@utility name { ... }`.
224
+ * Name → declarations (property → value; CSS custom properties allowed). Each one is registered on
225
+ * this context only; variants and `!` apply as usual. A name equal to a built-in extends it like
226
+ * `@utility` in Tailwind 4: the built-in declarations are emitted first, then the custom ones (a later
227
+ * duplicate property wins). An entry with an invalid name, property or value is skipped whole.
228
+ * @example utilities: { 'max-w-app': { 'max-width': '72rem', 'margin-inline': 'auto' } }
229
+ */
230
+ utilities?: CustomUtilities;
231
+ [key: string]: unknown;
232
+ }
233
+
234
+ export declare function configGetter(config: ContextRecord, ...path: (string | number)[]): unknown;
235
+
236
+ export declare interface Context {
237
+ hasPreset: (category: string, preset: string) => boolean;
238
+ theme: (...path: (string | number)[]) => unknown;
239
+ config: (...path: (string | number)[]) => unknown;
240
+ themeToCssVars: (prefix?: string) => string;
241
+ extendTheme: (category: string, values: Record<string, unknown> | Function_2) => void;
242
+ getPreflightCSS: (level?: PreflightLevel) => string;
243
+ }
244
+
245
+ declare type ContextRecord = Record<string, unknown>;
246
+
247
+ export declare function createContext(configObj: Config): Context;
248
+
249
+ /** #287: static custom utilities by class name. */
250
+ export declare type CustomUtilities = Record<string, CustomUtilityDeclarations>;
251
+
252
+ /** #287: declarations of one static custom utility (property → value). */
253
+ export declare type CustomUtilityDeclarations = Record<string, string | number>;
254
+
255
+ export declare function decl(prop: string, value: string | [string, string][], source?: string): AstNode;
256
+
257
+ export declare type DeclPath = PathNode[];
258
+
259
+ /**
260
+ * declPathToAst
261
+ * Converts decl-to-root path(variant chain) to actual nested AST.
262
+ * - Input: DeclPath(variant chain)
263
+ * - Output: Nested AstNode[]
264
+ * - Consecutive same variants (same key) are merged, nested in outside→inside order
265
+ *
266
+ * @param declPath DeclPath
267
+ * @returns AstNode[]
268
+ */
269
+ export declare function declPathToAst(declPath: DeclPath): AstNode[];
270
+
271
+ export declare function deepMerge<T extends Record<string, unknown>>(base: T, override: Partial<T>): T;
272
+
273
+ export declare const defaultConfig: Config;
274
+
275
+ export declare function escapeClassName(className: string): string;
276
+
277
+ /**
278
+ * Add Tailwind-style spacing inside calc()/min()/max()/clamp():
279
+ * `calc(100%-2rem)` -> `calc(100% - 2rem)`. Leaves nested non-math functions
280
+ * (var(--x-y)), unary signs and exponents (1e-3) alone.
281
+ */
282
+ export declare function expandThemeFunctions(value: string): string;
283
+
284
+ declare type Function_2 = (...args: unknown[]) => unknown;
285
+
286
+ export declare function functionalModifier(match: ModifierRegistration['match'], modifySelector: ModifierRegistration['modifySelector'], wrap?: ModifierRegistration['wrap'], options?: Partial<ModifierRegistration>, ctx?: Context): void;
287
+
288
+ export declare function functionalUtility(opts: FunctionalUtilityOptions, ctx?: Context): void;
289
+
290
+ export declare type FunctionalUtilityExtra = {
291
+ opacity?: string;
292
+ realThemeValue?: string;
293
+ };
294
+
295
+ export declare type FunctionalUtilityOptions = {
296
+ /**
297
+ * The name of the utility
298
+ *
299
+ * prefix is automatically added to the name
300
+ */
301
+ name: string;
302
+ /**
303
+ * The CSS property to set
304
+ *
305
+ * css property is automatically added to the prop
306
+ */
307
+ prop?: string;
308
+ /**
309
+ * The theme key to look up values
310
+ *
311
+ * theme key is automatically added to the themeKey
312
+ *
313
+ * @example
314
+ * ```
315
+ * themeKey: 'colors'
316
+ * ```
317
+ */
318
+ themeKey?: string;
319
+ /**
320
+ * The theme keys to look up values
321
+ *
322
+ * theme keys are automatically added to the themeKeys
323
+ *
324
+ * @example
325
+ * ```
326
+ * themeKeys: ['colors', 'spacing']
327
+ * ```
328
+ */
329
+ themeKeys?: string[];
330
+ /**
331
+ * Whether to support arbitrary values
332
+ *
333
+ * `bg-[#ff0000]`
334
+ *
335
+ * @example
336
+ * ```
337
+ * supportsArbitrary: true
338
+ * ```
339
+ */
340
+ supportsArbitrary?: boolean;
341
+ /**
342
+ * Whether to support fraction values
343
+ *
344
+ * `m-4`
345
+ *
346
+ * @example
347
+ * ```
348
+ * supportsFraction: true
349
+ * ```
350
+ */
351
+ supportsFraction?: boolean;
352
+ /**
353
+ * Whether to support custom properties
354
+ *
355
+ * `bg-(--my-bg)`
356
+ *
357
+ * @example
358
+ * ```
359
+ * supportsCustomProperty: true
360
+ * ```
361
+ */
362
+ supportsCustomProperty?: boolean;
363
+ /**
364
+ * Whether to support negative values
365
+ *
366
+ * `-m-4`
367
+ *
368
+ * @example
369
+ * ```
370
+ * supportsNegative: true
371
+ * ```
372
+ */
373
+ supportsNegative?: boolean;
374
+ /**
375
+ * Whether to support opacity values
376
+ */
377
+ supportsOpacity?: boolean;
378
+ /**
379
+ * The handler function that processes values
380
+ *
381
+ * @example
382
+ * ```
383
+ * handle: (value, ctx, token, extra) => {
384
+ * return [decl('background-color', value)];
385
+ * }
386
+ * ```
387
+ *
388
+ * @param value The value to process
389
+ * @param ctx The context
390
+ * @param token The parsed utility
391
+ * @param extra The extra metadata
392
+ *
393
+ * @returns {AstNode[] | null | undefined} The AST nodes or null | undefined
394
+ */
395
+ handle?: (value: string, ctx: Context, token: ParsedUtility, extra?: FunctionalUtilityExtra) => AstNode[] | null | undefined;
396
+ /**
397
+ * The handler function that processes bare values
398
+ *
399
+ * @example
400
+ * ```
401
+ * handleBareValue: ({ value }) => isPositiveInteger(value) ? value : null,
402
+ * ```
403
+ *
404
+ * @param args The arguments
405
+ * @param args.value The value to process
406
+ * @param args.ctx The context
407
+ * @param args.token The parsed utility
408
+ * @param args.extra The extra metadata
409
+ *
410
+ * @returns {string | null | undefined} The processed value or null | undefined
411
+ */
412
+ handleBareValue?: (args: {
413
+ value: string;
414
+ ctx: Context;
415
+ token: ParsedUtility;
416
+ extra?: FunctionalUtilityExtra;
417
+ }) => string | null | undefined;
418
+ /**
419
+ * The handler function that processes negative bare values
420
+ *
421
+ * @example
422
+ * ```
423
+ * handleNegativeBareValue: ({ value }) => isPositiveInteger(value) ? value : null,
424
+ * ```
425
+ */
426
+ /**
427
+ * #261: the utility uses the spacing scale, so a named `theme.spacing` key (`p-gutter`) resolves to
428
+ * `var(--spacing-<key>)` (negative: `calc(var(--spacing-<key>) * -1)`), as in Tailwind 4. Only tried
429
+ * after the bare-value handler rejects the value, so built-in keywords keep precedence.
430
+ */
431
+ spacingKeys?: boolean;
432
+ handleNegativeBareValue?: (args: {
433
+ value: string;
434
+ ctx: Context;
435
+ token: ParsedUtility;
436
+ extra?: FunctionalUtilityExtra;
437
+ }) => string | null | undefined;
438
+ /**
439
+ * The handler function that processes custom property values
440
+ *
441
+ *
442
+ * @example
443
+ * ```
444
+ * handleCustomProperty: (value, ctx, token, extra) => [decl('background-color', value)],
445
+ * ```
446
+ *
447
+ * @param args The arguments
448
+ * @param args.value The value to process
449
+ * @param args.ctx The context
450
+ * @param args.token The parsed utility
451
+ * @param args.extra The extra metadata
452
+ *
453
+ * @returns {AstNode[] | null | undefined} The AST nodes or null | undefined
454
+ */
455
+ handleCustomProperty?: (value: string, ctx: Context, token: ParsedUtility, extra?: FunctionalUtilityExtra) => AstNode[] | null | undefined;
456
+ /**
457
+ * The description of the utility
458
+ *
459
+ * @example
460
+ * ```
461
+ * description: 'Custom utility description',
462
+ * ```
463
+ */
464
+ description?: string;
465
+ /**
466
+ * The category of the utility
467
+ *
468
+ * It is used to group utilities in the documentation and styles
469
+ *
470
+ *
471
+ * @example
472
+ * ```
473
+ * category: 'background',
474
+ * ```
475
+ */
476
+ category?: string;
477
+ /**
478
+ * The priority of the utility
479
+ *
480
+ * It is used to sort utilities in the styles
481
+ *
482
+ * @example
483
+ * ```
484
+ * priority: 10,
485
+ * ```
486
+ *
487
+ * The higher the number, the higher the priority
488
+ *
489
+ * @default 0
490
+ */
491
+ priority?: number;
492
+ };
493
+
494
+ /**
495
+ * generateCss
496
+ * Takes multiple classNames and generates CSS for each, joining them.
497
+ * - Input: classList(string), Context, options
498
+ * - Output: string (result of joining multiple CSS blocks)
499
+ * - Processes internally parseClassToAst → optimizeAst → astToCss in sequence
500
+ * - Supports options like dedup, minify
501
+ *
502
+ * @param classList string (e.g., 'bg-red-500 text-lg hover:bg-blue-500')
503
+ * @param ctx Context
504
+ * @param opts { minify?: boolean, dedup?: boolean }
505
+ * @returns string
506
+ *
507
+ * @example
508
+ * const css = generateCss('sm:dark:hover:bg-red-500 sm:focus:bg-blue-500', ctx);
509
+ */
510
+ export declare function generateCss(classList: string, ctx: Context, opts?: {
511
+ minify?: boolean;
512
+ dedup?: boolean;
513
+ }): string;
514
+
515
+ /**
516
+ * Generates CSS from a list of BaroJsonInput objects.
517
+ *
518
+ * @param inputs Array of BaroJsonInput
519
+ * @param ctx Context
520
+ * @param opts Options (minify, etc.)
521
+ * @returns CSS string
522
+ */
523
+ export declare function generateCssFromJson(inputs: BaroJsonInput[], ctx: Context, opts?: {
524
+ minify?: boolean;
525
+ }): string;
526
+
527
+ /**
528
+ * Returns an array of optimized results for multiple class names with dedup/filter.
529
+ * - Each object: { cls, ast, css }
530
+ * - Supports minify, dedup options
531
+ * - Applies astToCss(cleanAst, cls, opts) per class
532
+ * @param classList string (space-separated)
533
+ * @param ctx Context
534
+ * @param opts { minify?: boolean; dedup?: boolean }
535
+ * @returns Array<{ cls: string; ast: AstNode[]; css: string }>
536
+ */
537
+ export declare function generateCssRules(classList: string, ctx: Context, opts?: {
538
+ minify?: boolean;
539
+ dedup?: boolean;
540
+ }): Array<GenerateCssRulesResult>;
541
+
542
+ export declare type GenerateCssRulesResult = {
543
+ cls: string;
544
+ ast: AstNode[];
545
+ css: string;
546
+ cssList: string[];
547
+ rootCss: string;
548
+ rootCssList: string[];
549
+ };
550
+
551
+ /** Read AST cache statistics for one context, or the legacy global cache. */
552
+ export declare function getAstCacheStats(ctx?: Context): {
553
+ size: number;
554
+ maxSize: number;
555
+ hitRate: number;
556
+ };
557
+
558
+ export declare function getModifier(ctx?: Context): ModifierRegistration[];
559
+
560
+ export declare function getPreflightCSS(level?: PreflightLevel): string;
561
+
562
+ export declare function getUtility(ctx?: Context): UtilityRegistration[];
563
+
564
+ /**
565
+ * #273: true when an emitted selector or at-rule prelude contains a comment opener or closer outside a CSS escape.
566
+ * Backslash-escape pairs are skipped, so an escaped `\/` or `\*` from a class name never counts. Used by the
567
+ * serializer on the final, composed string, where adjacent pieces that were each safe alone can join into one.
568
+ */
569
+ export declare function hasCommentDelimiter(text: string): boolean;
570
+
571
+ /** #248: a comment opener or closer anywhere in a variant (quoted or not) could leave a comment unclosed in the output. */
572
+ export declare function hasCommentToken(value: string): boolean;
573
+
574
+ /**
575
+ * #323: true when emitted text contains a markup end-tag opener (less-than then slash). Generated CSS can be
576
+ * placed inside an HTML style element, where that sequence could end the element early. CSS escapes in the
577
+ * output never form it, and a lone less-than (range media queries) stays allowed.
578
+ */
579
+ export declare function hasHtmlEndTagOpener(text: string): boolean;
580
+
581
+ export declare type HasItems = {
582
+ items?: AstNode[];
583
+ };
584
+
585
+ export declare type HasName = {
586
+ name?: string;
587
+ };
588
+
589
+ export declare type HasNodes = {
590
+ nodes?: AstNode[];
591
+ };
592
+
593
+ export declare type HasParams = {
594
+ params?: string;
595
+ };
596
+
597
+ export declare function hasPreset(themeObj: Theme, category: string, preset: string): boolean;
598
+
599
+ export declare type HasProp = {
600
+ prop?: string;
601
+ };
602
+
603
+ export declare type HasSelector = {
604
+ selector?: string;
605
+ };
606
+
607
+ export declare type HasSource = {
608
+ source?: string;
609
+ };
610
+
611
+ export declare type HasText = {
612
+ text?: string;
613
+ };
614
+
615
+ export declare type HasValue = {
616
+ value?: string | [string, string][];
617
+ };
618
+
619
+ /**
620
+ * Incremental parsing system for efficient class processing
621
+ *
622
+ * This class provides an optimized approach to CSS class processing by:
623
+ * - Tracking processed classes to avoid redundant work
624
+ * - Batching multiple class operations for better performance
625
+ * - Supporting both synchronous and asynchronous processing modes
626
+ *
627
+ * ## Usage Patterns
628
+ *
629
+ * ### Universal Usage (Node.js & Browser)
630
+ * ```typescript
631
+ * const parser = new IncrementalParser(ctx);
632
+ *
633
+ * // Process classes synchronously
634
+ * const results = parser.processClasses(['bg-blue-500', 'text-lg']);
635
+ *
636
+ * // Process single class
637
+ * const result = parser.processClass('bg-red-500');
638
+ *
639
+ * // Get statistics
640
+ * const stats = parser.getStats();
641
+ * ```
642
+ *
643
+ * ### Browser Integration
644
+ * ```typescript
645
+ * const parser = new IncrementalParser(ctx);
646
+ * const BrowserRuntime = new BrowserRuntime();
647
+ *
648
+ * // Process classes and manually inject CSS
649
+ * const results = parser.processClasses(['bg-blue-500', 'text-lg']);
650
+ * results.forEach(result => {
651
+ * if (result.css) {
652
+ * BrowserRuntime.insertRule(result.css);
653
+ * }
654
+ * });
655
+ *
656
+ * // Use with ChangeDetector for automatic DOM monitoring
657
+ * const detector = new ChangeDetector(parser);
658
+ * detector.observe(document.body, { scan: true });
659
+ * ```
660
+ *
661
+ * ## Architecture
662
+ *
663
+ * - **IncrementalParser**: Pure CSS processing (works in Node.js and browser)
664
+ * - **ChangeDetector**: Browser-only DOM monitoring (uses MutationObserver)
665
+ * - **BrowserRuntime**: Browser-only CSS injection (uses DOM APIs)
666
+ */
667
+ export declare class IncrementalParser {
668
+ /** Set of class names that have already been processed to avoid duplicates */
669
+ private processedClasses;
670
+ /** BAROCSS context for theme and utility resolution */
671
+ private ctx;
672
+ /** Maximum number of classes to process in a single batch */
673
+ private batchSize;
674
+ /** Debounce delay for batch processing in milliseconds */
675
+ private debounceMs;
676
+ /** Set of classes waiting to be processed */
677
+ private pendingClasses;
678
+ /** Timer for debounced batch processing */
679
+ private batchTimer;
680
+ /**
681
+ * Create a new IncrementalParser instance
682
+ *
683
+ * @param ctx - BAROCSS context for theme and utility resolution
684
+ */
685
+ constructor(ctx: Context);
686
+ /**
687
+ * Processes a single CSS class and generates its AST and CSS representation
688
+ *
689
+ * This method performs the complete pipeline for a single class:
690
+ * 1. Checks if the class has already been processed
691
+ * 2. Parses the class name to extract utility information
692
+ * 3. Generates the Abstract Syntax Tree (AST)
693
+ * 4. Converts the AST to CSS rules
694
+ * 5. Marks the class as processed to avoid future duplicates
695
+ *
696
+ * @param className - The CSS class name to process (e.g., 'bg-blue-500')
697
+ * @returns Object containing AST and CSS, or null if processing failed or class was already processed
698
+ */
699
+ processClass(className: string): GenerateCssRulesResult | null;
700
+ /**
701
+ * Processes multiple CSS classes in batches for optimal performance
702
+ *
703
+ * This method handles multiple classes efficiently by:
704
+ * - Filtering out already processed classes to avoid redundant work
705
+ * - Processing classes in configurable batch sizes
706
+ * - Returning comprehensive results for each processed class
707
+ *
708
+ * @param classes - Array of CSS class names to process
709
+ * @returns Array of processing results, each containing className, AST, and CSS
710
+ */
711
+ processClasses(classes: string[]): Array<GenerateCssRulesResult>;
712
+ /**
713
+ * Adds classes to the pending queue for asynchronous batch processing
714
+ *
715
+ * This method is used by the ChangeDetector when new classes are discovered
716
+ * in the DOM. Classes are queued and processed together to minimize
717
+ * performance impact from frequent DOM mutations.
718
+ *
719
+ * @param classes - Array of CSS class names to queue for processing
720
+ */
721
+ addToPending(classes: string[]): void;
722
+ /**
723
+ * Schedule batch processing with debouncing
724
+ *
725
+ * This method uses setTimeout to debounce rapid class additions
726
+ * and process them in batches for better performance.
727
+ */
728
+ private scheduleBatchProcessing;
729
+ /**
730
+ * Process pending classes from the queue
731
+ *
732
+ * This method is called by the debounced timer to process
733
+ * all classes that have been added to the pending queue.
734
+ */
735
+ private processPendingClasses;
736
+ /**
737
+ * Core method that processes classes and marks them as processed
738
+ *
739
+ * This is the common processing logic used by both pending and synchronous
740
+ * processing methods. It:
741
+ * 1. Processes the provided classes using the batch processor
742
+ * 2. Marks classes as processed to prevent duplicates
743
+ *
744
+ * @param classes - Array of CSS class names to process
745
+ */
746
+ private applyClasses;
747
+ /**
748
+ * Returns comprehensive statistics about the incremental parser's state
749
+ *
750
+ * This method provides detailed metrics including:
751
+ * - Number of processed classes
752
+ * - Number of pending classes
753
+ * - Cache statistics from AST and CSS caches
754
+ *
755
+ * @returns Object containing processing statistics and cache information
756
+ */
757
+ getStats(): {
758
+ processedClasses: number;
759
+ pendingClasses: number;
760
+ cacheStats: {
761
+ ast: {
762
+ size: number;
763
+ maxSize: number;
764
+ hitRate: number;
765
+ };
766
+ css: {};
767
+ };
768
+ };
769
+ /**
770
+ * Clears all processed classes and pending queue
771
+ *
772
+ * This method is useful when the theme or configuration changes,
773
+ * requiring all classes to be reprocessed. It:
774
+ * - Clears the processed classes set
775
+ * - Clears the pending classes queue
776
+ * - Cancels any pending batch processing timer
777
+ */
778
+ clearProcessed(): void;
779
+ /**
780
+ * Checks if a specific class has been processed
781
+ *
782
+ * @param cls - The CSS class name to check
783
+ * @returns True if the class has been processed, false otherwise
784
+ */
785
+ isProcessed(cls: string): boolean;
786
+ /**
787
+ * Marks a class as processed to prevent future duplicate processing
788
+ *
789
+ * @param cls - The CSS class name to mark as processed
790
+ */
791
+ markProcessed(cls: string): void;
792
+ /**
793
+ * Forgets that a class was processed, so a later request generates it again
794
+ * (used when the browser runtime reclaims an unused class's rules, #269).
795
+ *
796
+ * @param cls - The CSS class name to forget
797
+ */
798
+ unmarkProcessed(cls: string): void;
799
+ /**
800
+ * Process classes synchronously and update BrowserRuntime cache
801
+ * This method is used by ChangeDetector for scan operations
802
+ */
803
+ processClassesSync(classes: string[]): void;
804
+ /**
805
+ * Returns all currently processed class names
806
+ *
807
+ * This method is useful for debugging and monitoring purposes,
808
+ * providing visibility into which classes have been processed.
809
+ *
810
+ * @returns Array of all processed class names
811
+ */
812
+ getProcessedClasses(): string[];
813
+ }
814
+
815
+ /**
816
+ * #332: true when an emitted selector or at-rule prelude has balanced, correctly nested `()`, `[]` and `{}` and
817
+ * no open quote. CSS escapes (backslash pairs) and quoted strings are skipped, so escaped brackets from a class
818
+ * name never count. Top-level commas are allowed (selector lists, `:is(a, b)`). Checked on the final composed
819
+ * string: an unbalanced prelude in concatenated CSS text would swallow the rules that follow it.
820
+ */
821
+ export declare function isBalancedPrelude(text: string): boolean;
822
+
823
+ export declare function isDebug(): boolean;
824
+
825
+ /**
826
+ * #221: isSafeVariantValue for a whole variant token, except that has-[…]/not-[…] (optionally group-/peer-) may
827
+ * carry a comma at the top level of their bracket value: those variants wrap the value in `:has()`/`:not()`.
828
+ * The value itself must still be balanced and free of `{`, `}` and `;`, so it cannot close the pseudo-class.
829
+ */
830
+ export declare function isSafeVariantToken(value: string): boolean;
831
+
832
+ export declare function isSafeVariantValue(value: string, allowTopLevelComma?: boolean): boolean;
833
+
834
+ export declare function isStructureSafeValue(value: string): boolean;
835
+
836
+ /**
837
+ * #224: true when a utility value (or a whole utility token) cannot change the structure of the declaration block it
838
+ * is pasted into. Rejects, outside quotes: `{`, `}`, `;`, unbalanced or mismatched ()/[], and a quote left open.
839
+ * Commas are allowed (values are not selector lists), so this is isSafeVariantValue with top-level commas allowed.
840
+ */
841
+ /**
842
+ * #332: a variant token's bracket groups must be well formed. An empty group (`[]`, as in an empty
843
+ * `has-[]`/`group-has-[]`/`[]` variant) has nothing to select and emits nothing. A token that opens with `[`
844
+ * is one arbitrary variant: its first group must close at the token's last character, so two adjacent groups
845
+ * are never read as a single variant whose inner text is unbalanced. CSS escapes and quoted strings are skipped.
846
+ */
847
+ export declare function isWellFormedVariantBrackets(value: string): boolean;
848
+
849
+ /**
850
+ * Converts a single BaroJsonInput object into an AST tree.
851
+ * Bypasses string parsing and directly invokes utility/modifier handlers.
852
+ *
853
+ * @param input BaroJsonInput object
854
+ * @param ctx Context
855
+ * @returns AstNode[]
856
+ */
857
+ export declare function jsonToAst(input: BaroJsonInput, ctx: Context): AstNode[];
858
+
859
+ /**
860
+ * mergeAstTreeList
861
+ * Takes a list of declPathToAst results (AstNode[][]), merges same at-rule(name, params) etc., and returns the final AST tree.
862
+ * - Input: AstNode[][] (nested ASTs of multiple decl-to-root paths)
863
+ * @returns AstNode[]
864
+ * - Usage: Used in optimizeAst for final AST merging/optimization
865
+ *
866
+ * @param astList AstNode[][]
867
+ * @returns AstNode[]
868
+ */
869
+ export declare function mergeAstTreeList(astList: AstNode[][]): AstNode[];
870
+
871
+ export declare type ModifierRegistration = {
872
+ match: (mod: string, context: Context) => boolean;
873
+ modifySelector?: (params: {
874
+ selector: string;
875
+ fullClassName: string;
876
+ mod: ParsedModifier;
877
+ context: Context;
878
+ variantChain?: ParsedModifier[];
879
+ index?: number;
880
+ }) => string | ModifierSelector | ModifierSelector[];
881
+ wrap?: (mod: ParsedModifier, context: Context) => AstNode[];
882
+ astHandler?: (ast: AstNode[], mod: ParsedModifier, context: Context, variantChain?: ParsedModifier[], index?: number) => AstNode[];
883
+ sort?: number;
884
+ description?: string;
885
+ source?: string;
886
+ /** Static variant name; lets the parser tell `placeholder-shown:` (variant) from a `placeholder-*` utility (#307). */
887
+ name?: string;
888
+ };
889
+
890
+ export declare const modifierRegistry: ModifierRegistration[];
891
+
892
+ export declare type ModifierSelector = {
893
+ selector: string;
894
+ flatten?: boolean;
895
+ wrappingType?: 'rule' | 'style-rule' | 'at-rule';
896
+ override?: boolean;
897
+ source?: string;
898
+ };
899
+
900
+ export declare function normalizeMathSpacing(value: string): string;
901
+
902
+ /**
903
+ * optimizeAst
904
+ * Merges/organizes AST generated by parseClassToAst into an optimized AST tree based on decl-to-root path.
905
+ * - Input: AstNode[] (result of parseClassToAst)
906
+ * - Output: Optimized AST tree (AstNode[])
907
+ * - Uses collectDeclPaths, declPathToAst, mergeAstTreeList internally
908
+ * - Reflects all variant wrapping structures (nesting, siblings, merging, etc.)
909
+ *
910
+ * @param ast AstNode[]
911
+ * @returns AstNode[]
912
+ */
913
+ export declare function optimizeAst(ast: AstNode[]): AstNode[];
914
+
915
+ /**
916
+ * Parses a class name string into modifiers and utility using tokenization
917
+ * Supports both directions:
918
+ * - modifier:utility (traditional CSS)
919
+ * - utility:modifier (Master CSS style)
920
+ *
921
+ * Examples:
922
+ * - 'group-hover:sm:bg-[red]' → modifier:utility
923
+ * - 'bg-red-500:hover' → utility:modifier
924
+ * - 'text-[color:var(--foo)]' → utility only
925
+ *
926
+ * @param className e.g. 'group-hover:sm:bg-[red]', 'text-[color:var(--foo)]'
927
+ * @returns { modifiers, utility }
928
+ */
929
+ export declare function parseClassName(className: string, ctx?: Context): {
930
+ modifiers: ParsedModifier[];
931
+ utility: ParsedUtility | null;
932
+ };
933
+
934
+ /**
935
+ * parseClassToAst
936
+ * Parses className(including variant chain) to generate AST tree.
937
+ * - Input: className(string), Context
938
+ * - Output: AstNode[] (multiple roots possible for variant wrapping path)
939
+ * - Perfectly supports variant wrapping structure (Cartesian product, nesting, siblings, etc.)
940
+ * - Accumulates wrappers in wrappers and applies them from right to left.
941
+ * - Can return multiple root asts.
942
+ *
943
+ * @param fullClassName string (e.g., 'sm:dark:hover:bg-red-500')
944
+ * @param ctx Context
945
+ * @returns AstNode[]
946
+ *
947
+ * @example
948
+ * const ast = parseClassToAst('sm:dark:hover:bg-red-500', ctx);
949
+ * // ast is an AST tree with sm, dark, hover variants nested
950
+ */
951
+ export declare function parseClassToAst(fullClassName: string, ctx: Context): AstNode[];
952
+
953
+ export declare interface ParsedModifier {
954
+ type: string;
955
+ value?: string;
956
+ negative?: boolean;
957
+ arbitrary?: boolean;
958
+ [key: string]: unknown;
959
+ }
960
+
961
+ export declare interface ParsedUtility {
962
+ category?: string;
963
+ prefix: string;
964
+ value?: string;
965
+ arbitrary?: boolean;
966
+ customProperty?: boolean;
967
+ negative?: boolean;
968
+ opacity?: string;
969
+ priority?: number;
970
+ important?: boolean;
971
+ /** Set for an arbitrary property class (`[prop:value]`); `value` holds the raw value. */
972
+ property?: string;
973
+ [key: string]: unknown;
974
+ }
975
+
976
+ /**
977
+ * Parse result cache management
978
+ */
979
+ export declare class ParseResultCache {
980
+ private cache;
981
+ private maxSize;
982
+ set(key: string, result: {
983
+ modifiers: ParsedModifier[];
984
+ utility: ParsedUtility | null;
985
+ }): void;
986
+ get(key: string): {
987
+ modifiers: ParsedModifier[];
988
+ utility: ParsedUtility | null;
989
+ } | undefined;
990
+ has(key: string): boolean;
991
+ clear(): void;
992
+ getStats(): {
993
+ size: number;
994
+ maxSize: number;
995
+ hitRate: number;
996
+ };
997
+ }
998
+
999
+ export declare const parseResultCache: ParseResultCache;
1000
+
1001
+ /**
1002
+ * decl-to-root path collection function (reused in normalizeAstOrder, etc.)
1003
+ */
1004
+ export declare type PathNode = Partial<AstNode>;
1005
+
1006
+ declare type PreflightLevel = 'minimal' | 'standard' | 'full' | true | false;
1007
+
1008
+ export declare function property(name: string, initialValue?: string, syntax?: string, source?: string): AstNode;
1009
+
1010
+ export declare function raw(value: string, source?: string): AstNode;
1011
+
1012
+ export declare function registerModifier(modifier: ModifierRegistration, ctx?: Context): void;
1013
+
1014
+ export declare function registerUtility(util: UtilityRegistration, ctx?: Context): void;
1015
+
1016
+ export declare function resolveTheme(config: Config): Theme;
1017
+
1018
+ export declare function rootToCss(nodes: AstNode[], opts?: {
1019
+ minify?: boolean;
1020
+ }): string;
1021
+
1022
+ export declare function rule(selector: string, nodes: AstNode[], source?: string): AstNode;
1023
+
1024
+ /**
1025
+ * Tailwind-compatible cascade order for runtime-inserted rules (#254); shared by @barocss/server (#267).
1026
+ *
1027
+ * The runtime discovers classes in DOM order, so without sorting `lg:px-8`
1028
+ * seen before `sm:px-6` would land earlier and lose at >= 1024px. Each rule
1029
+ * gets a sort key derived from its leading `@media` / `@container` preludes:
1030
+ *
1031
+ * 0 base, state media (hover), motion/contrast, unknown
1032
+ * 1 max-* breakpoints (larger width first)
1033
+ * 2 min-* breakpoints (smaller width first)
1034
+ * 3 @max-* container queries (larger width first)
1035
+ * 4 @min-* container queries (smaller width first)
1036
+ * 5 orientation, dark (prefers-color-scheme), print, forced-colors
1037
+ *
1038
+ * Nested at-rules (e.g. `sm:dark:`) contribute one key pair per level, so
1039
+ * `sm:` < `sm:dark:` < `md:`. Equal keys keep discovery order.
1040
+ */
1041
+ export declare type RuleKey = number[];
1042
+
1043
+ export declare function ruleSortKey(rule: string): RuleKey;
1044
+
1045
+ /** Internal hook for caches owned by contexts. */
1046
+ export declare function setContextCacheReset(reset: () => void): void;
1047
+
1048
+ export declare function setDebug(enabled: boolean): void;
1049
+
1050
+ /**
1051
+ * staticModifier: A helper that registers a modifier name and an array of CSS selectors directly to the registry
1052
+ *
1053
+ * @example
1054
+ * ```
1055
+ * staticModifier('disabled', ['&:disabled'], { source: 'pseudo' });
1056
+ * ```
1057
+ *
1058
+ * @param name The name of the modifier
1059
+ * @param selectors The selectors of the modifier
1060
+ * @param options The options of the modifier
1061
+ *
1062
+ * @returns {void}
1063
+ */
1064
+ export declare function staticModifier(name: string, selectors: string[], options?: any, ctx?: Context): void;
1065
+
1066
+ /**
1067
+ * staticUtility: A helper that registers a utility name and an array of CSS declaration pairs directly to the registry
1068
+ *
1069
+ * @example
1070
+ * ```
1071
+ * staticUtility('block', [['display', 'block']]);
1072
+ * staticUtility('hidden', [['display', 'none']]);
1073
+ * staticUtility('space-x-px', [
1074
+ * [
1075
+ * '& > :not([hidden]) ~ :not([hidden])', // selector
1076
+ * [
1077
+ * ['margin-inline-start', '1px'], // [prop, value]
1078
+ * ['margin-inline-end', '1px'], // [prop, value]
1079
+ * ],
1080
+ * ],
1081
+ * ]);
1082
+ * ```
1083
+ *
1084
+ * @param name The name of the utility
1085
+ * @param decls The declarations of the utility
1086
+ * @param opts The options of the utility
1087
+ *
1088
+ * @returns {void}
1089
+ */
1090
+ export declare function staticUtility(name: string, decls: StaticUtilityValue[], opts?: {
1091
+ description?: string;
1092
+ category?: string;
1093
+ priority?: number;
1094
+ }, ctx?: Context): void;
1095
+
1096
+ declare type StaticUtilityValue = AstNode | [string, string] | [string, [string, string][]] | ((value: string) => AstNode);
1097
+
1098
+ export declare function styleRule(selector: string, nodes: AstNode[], source?: string): AstNode;
1099
+
1100
+ export declare interface Theme {
1101
+ extend?: Theme;
1102
+ [namespace: string]: unknown;
1103
+ }
1104
+
1105
+ export declare type ThemeGetter = (...path: (string | number)[]) => unknown;
1106
+
1107
+ /**
1108
+ * Modern theme getter for BAROCSS
1109
+ *
1110
+ * - Supports category-level (first path segment) function values only.
1111
+ * - If the category (e.g., 'spacing', 'colors') is a function, it will be executed with the theme getter as argument.
1112
+ * - This allows dynamic theme extension and plugin-style patterns, e.g.:
1113
+ * spacing: (theme) => ({ ...theme('spacing'), '72': '18rem' })
1114
+ * - Leaf (property) functions are NOT supported and will be ignored (returns undefined).
1115
+ * - Infinite recursion is prevented: If the exact same path is being resolved recursively (directly or indirectly), undefined is returned for that call.
1116
+ * - Category-level functions can safely call theme('category.otherKey') for dynamic references.
1117
+ * - Only true recursion on the same path is blocked.
1118
+ * - All theme lookups (theme('category.key')) will always re-execute the category function if present, ensuring dynamic resolution.
1119
+ *
1120
+ * @param themeObj - The theme object (possibly with category functions)
1121
+ * @param path - Path segments (string or number), or dot-path string (e.g. 'colors.red.500')
1122
+ * @returns The resolved theme value, or undefined if not found or if a leaf function is encountered
1123
+ *
1124
+ * @example
1125
+ * const theme = {
1126
+ * spacing: (theme) => ({ 1: '0.25rem', 2: theme('spacing.1') }),
1127
+ * };
1128
+ * themeGetter(theme, 'spacing.2'); // '0.25rem'
1129
+ *
1130
+ * @example
1131
+ * // Infinite recursion is prevented:
1132
+ * const theme = {
1133
+ * spacing: (theme) => theme('spacing.1'),
1134
+ * };
1135
+ * themeGetter(theme, 'spacing.1'); // undefined
1136
+ */
1137
+ export declare function themeGetter(themeObj: Theme, ...path: (string | number)[]): unknown;
1138
+
1139
+ export declare function themeToCssVars(theme: Theme): string;
1140
+
1141
+ export declare interface Token {
1142
+ value: string;
1143
+ start: number;
1144
+ end: number;
1145
+ }
1146
+
1147
+ /**
1148
+ * Tokenizes a class name string into an array of tokens
1149
+ * Only handles separation by ':' while respecting brackets and parentheses
1150
+ *
1151
+ * Examples:
1152
+ * - 'hover:bg-red-500' → [{ value: 'hover' }, { value: 'bg-red-500' }]
1153
+ * - 'bg-[#ff0000]:hover' → [{ value: 'bg-[#ff0000]' }, { value: 'hover' }]
1154
+ * - 'text-[color:var(--foo)]' → [{ value: 'text-[color:var(--foo)]' }]
1155
+ * - '!bg-[red]' → [{ value: '!bg-[red]' }]
1156
+ */
1157
+ export declare function tokenize(className: string): Token[];
1158
+
1159
+ /** Index after the last key <= `key` (stable upper bound) in sorted `keys`. */
1160
+ export declare function upperBound(keys: RuleKey[], key: RuleKey): number;
1161
+
1162
+ /**
1163
+ * Utility cache management
1164
+ */
1165
+ export declare class UtilityCache {
1166
+ private cache;
1167
+ private maxSize;
1168
+ set(key: string, value: boolean): void;
1169
+ get(key: string): boolean | undefined;
1170
+ has(key: string): boolean;
1171
+ clear(): void;
1172
+ getStats(): {
1173
+ size: number;
1174
+ maxSize: number;
1175
+ hitRate: number;
1176
+ };
1177
+ }
1178
+
1179
+ export declare const utilityCache: UtilityCache;
1180
+
1181
+ export declare interface UtilityRegistration {
1182
+ /**
1183
+ * The name of the utility
1184
+ */
1185
+ name: string;
1186
+ /**
1187
+ * The match function for the utility
1188
+ * @param className The class name of the utility
1189
+ * @returns {boolean} Whether the utility matches the class name
1190
+ */
1191
+ match: (className: string) => boolean;
1192
+ /**
1193
+ * Handler for utility value
1194
+ * @param value Utility value (e.g. 'red-500')
1195
+ * @param ctx Context
1196
+ * @param token Parsed token
1197
+ * @param options Registration options
1198
+ */
1199
+ handler: (value: string, ctx: Context, token: ParsedUtility, options: UtilityRegistration) => AstNode[] | null | undefined;
1200
+ /**
1201
+ * The description of the utility
1202
+ * @example
1203
+ * ```
1204
+ * description: 'Custom utility description',
1205
+ * ```
1206
+ */
1207
+ description?: string;
1208
+ /**
1209
+ * The category of the utility
1210
+ * @example
1211
+ * ```
1212
+ * category: 'background',
1213
+ * ```
1214
+ */
1215
+ category?: string;
1216
+ /**
1217
+ * The priority of the utility
1218
+ * @example
1219
+ * ```
1220
+ * priority: 10,
1221
+ * ```
1222
+ */
1223
+ priority?: number;
1224
+ [key: string]: unknown;
1225
+ }
1226
+
1227
+ /**
1228
+ * WeakMap-based cache for memory optimization
1229
+ */
1230
+ export declare class WeakCache<T> {
1231
+ private cache;
1232
+ private keyMap;
1233
+ private maxSize;
1234
+ set(key: string, value: T): void;
1235
+ get(key: string): T | undefined;
1236
+ has(key: string): boolean;
1237
+ clear(): void;
1238
+ getStats(): {
1239
+ size: number;
1240
+ maxSize: number;
1241
+ hitRate: number;
1242
+ };
1243
+ }
1244
+
1245
+ export { }