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