@barocss/kit 0.0.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.
- package/LICENSE +21 -0
- package/README.md +366 -0
- package/dist/default.d.ts +7 -0
- package/dist/index.d.ts +1012 -0
- package/dist/index.js +7763 -0
- package/dist/index.js.map +1 -0
- package/dist/theme/default.d.ts +2 -0
- package/dist/theme/default.js +601 -0
- package/dist/theme/default.js.map +1 -0
- package/package.json +40 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1012 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AST cache management
|
|
3
|
+
*/
|
|
4
|
+
export declare class AstCache {
|
|
5
|
+
private cache;
|
|
6
|
+
private maxSize;
|
|
7
|
+
set(key: string, ast: AstNode[]): void;
|
|
8
|
+
get(key: string): AstNode[] | undefined;
|
|
9
|
+
has(key: string): boolean;
|
|
10
|
+
clear(): void;
|
|
11
|
+
getStats(): {
|
|
12
|
+
size: number;
|
|
13
|
+
maxSize: number;
|
|
14
|
+
hitRate: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export declare const astCache: AstCache;
|
|
19
|
+
|
|
20
|
+
export declare type AstNode = {
|
|
21
|
+
type: "wrap";
|
|
22
|
+
items: AstNode[];
|
|
23
|
+
source?: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: "decl";
|
|
26
|
+
prop: string;
|
|
27
|
+
value: string | [string, string][];
|
|
28
|
+
source?: string;
|
|
29
|
+
} | {
|
|
30
|
+
type: "at-rule";
|
|
31
|
+
name: string;
|
|
32
|
+
params: string;
|
|
33
|
+
nodes: AstNode[];
|
|
34
|
+
source?: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: "style-rule";
|
|
37
|
+
selector: string;
|
|
38
|
+
nodes: AstNode[];
|
|
39
|
+
source?: string;
|
|
40
|
+
} | {
|
|
41
|
+
type: "rule";
|
|
42
|
+
selector: string;
|
|
43
|
+
nodes: AstNode[];
|
|
44
|
+
source?: string;
|
|
45
|
+
} | {
|
|
46
|
+
type: "at-root";
|
|
47
|
+
nodes: AstNode[];
|
|
48
|
+
source?: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: "comment";
|
|
51
|
+
text: string;
|
|
52
|
+
source?: string;
|
|
53
|
+
} | {
|
|
54
|
+
type: "raw";
|
|
55
|
+
value: string;
|
|
56
|
+
source?: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Converts AST nodes to CSS string
|
|
61
|
+
* @param ast { AstNode[] } - Array of AST nodes to convert
|
|
62
|
+
* @param baseSelector { string } - Base selector for nested rules (e.g., ".parent" for ".parent .child")
|
|
63
|
+
* @param opts { minify?: boolean } - Options for CSS generation
|
|
64
|
+
* @param _indent { string } - Current indentation level for pretty formatting
|
|
65
|
+
*/
|
|
66
|
+
export declare function astToCss(ast: AstNode[], baseSelector?: string, opts?: {
|
|
67
|
+
minify?: boolean;
|
|
68
|
+
important?: boolean;
|
|
69
|
+
}, _indent?: string): string;
|
|
70
|
+
|
|
71
|
+
export declare function atRoot(nodes: AstNode[], source?: string): AstNode;
|
|
72
|
+
|
|
73
|
+
export declare function atRule(name: string, params: string, nodes: AstNode[], source?: string): AstNode;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Clear all caches (for context changes or testing)
|
|
77
|
+
*/
|
|
78
|
+
export declare function clearAllCaches(): void;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Clear all AST caches (mainly for testing)
|
|
82
|
+
*/
|
|
83
|
+
export declare function clearAstCache(): void;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* collectDeclPaths
|
|
87
|
+
* Collects all paths from AST tree to decl(leaf) (including variant chains).
|
|
88
|
+
* - Input: AST node array
|
|
89
|
+
* - Output: decl-to-root path(variant chain) array
|
|
90
|
+
* - Usage: Used for path extraction for AST optimization/merging in optimizeAst, declPathToAst, etc.
|
|
91
|
+
*
|
|
92
|
+
* @param nodes AstNode[] - AST tree
|
|
93
|
+
* @param path PathNode[] - Recursive use (initial value omitted)
|
|
94
|
+
* @returns DeclPath[] - Array of paths to decl (variant chains)
|
|
95
|
+
*/
|
|
96
|
+
export declare function collectDeclPaths(nodes?: AstNode[], path?: PathNode[]): DeclPath[];
|
|
97
|
+
|
|
98
|
+
export declare function comment(text: string, source?: string): AstNode;
|
|
99
|
+
|
|
100
|
+
export declare interface Config {
|
|
101
|
+
prefix?: string;
|
|
102
|
+
cssVarPrefix?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Modern dark mode strategy
|
|
105
|
+
* - 'media': uses @media (prefers-color-scheme: dark)
|
|
106
|
+
* - 'class': uses .dark selector
|
|
107
|
+
* - string[]: custom selectors (e.g. ['class', '[data-theme="dark"]'])
|
|
108
|
+
*/
|
|
109
|
+
darkMode?: 'media' | 'class' | string[];
|
|
110
|
+
theme?: Theme;
|
|
111
|
+
presets?: {
|
|
112
|
+
theme: Theme;
|
|
113
|
+
}[];
|
|
114
|
+
/**
|
|
115
|
+
* Whether to include preflight CSS
|
|
116
|
+
* - 'minimal': Minimal preflight CSS
|
|
117
|
+
* - 'standard': Standard preflight CSS
|
|
118
|
+
* - 'full': Full preflight CSS
|
|
119
|
+
* - true: Full preflight CSS (default)
|
|
120
|
+
* - false: No preflight CSS
|
|
121
|
+
*
|
|
122
|
+
* default: true (full preflight)
|
|
123
|
+
*/
|
|
124
|
+
preflight?: PreflightLevel;
|
|
125
|
+
/**
|
|
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
|
|
129
|
+
*/
|
|
130
|
+
clearCacheOnContextChange?: boolean;
|
|
131
|
+
[key: string]: unknown;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export declare function configGetter(config: ContextRecord, ...path: (string | number)[]): unknown;
|
|
135
|
+
|
|
136
|
+
export declare interface Context {
|
|
137
|
+
hasPreset: (category: string, preset: string) => boolean;
|
|
138
|
+
theme: (...path: (string | number)[]) => unknown;
|
|
139
|
+
config: (...path: (string | number)[]) => unknown;
|
|
140
|
+
themeToCssVars: (prefix?: string) => string;
|
|
141
|
+
extendTheme: (category: string, values: Record<string, unknown> | Function_2) => void;
|
|
142
|
+
getPreflightCSS: (level?: PreflightLevel) => string;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
declare type ContextRecord = Record<string, unknown>;
|
|
146
|
+
|
|
147
|
+
export declare function createContext(configObj: Config): Context;
|
|
148
|
+
|
|
149
|
+
export declare function decl(prop: string, value: string | [string, string][], source?: string): AstNode;
|
|
150
|
+
|
|
151
|
+
export declare type DeclPath = PathNode[];
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* declPathToAst
|
|
155
|
+
* Converts decl-to-root path(variant chain) to actual nested AST.
|
|
156
|
+
* - Input: DeclPath(variant chain)
|
|
157
|
+
* - Output: Nested AstNode[]
|
|
158
|
+
* - Consecutive same variants (same key) are merged, nested in outside→inside order
|
|
159
|
+
*
|
|
160
|
+
* @param declPath DeclPath
|
|
161
|
+
* @returns AstNode[]
|
|
162
|
+
*/
|
|
163
|
+
export declare function declPathToAst(declPath: DeclPath): AstNode[];
|
|
164
|
+
|
|
165
|
+
export declare function deepMerge<T extends Record<string, unknown>>(base: T, override: Partial<T>): T;
|
|
166
|
+
|
|
167
|
+
export declare const defaultConfig: Config;
|
|
168
|
+
|
|
169
|
+
export declare function escapeClassName(className: string): string;
|
|
170
|
+
|
|
171
|
+
declare type Function_2 = (...args: unknown[]) => unknown;
|
|
172
|
+
|
|
173
|
+
export declare function functionalModifier(match: ModifierRegistration['match'], modifySelector: ModifierRegistration['modifySelector'], wrap?: ModifierRegistration['wrap'], options?: Partial<ModifierRegistration>): void;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* functionalUtility: A helper that registers dynamic utilities (theme, arbitrary, custom, negative, fraction, etc.) directly
|
|
177
|
+
*
|
|
178
|
+
* Example:
|
|
179
|
+
* functionalUtility({
|
|
180
|
+
* name: 'z',
|
|
181
|
+
* supportsNegative: true,
|
|
182
|
+
* themeKeys: ['--z-index'],
|
|
183
|
+
* handleBareValue: ({ value }) => isPositiveInteger(value) ? value : null,
|
|
184
|
+
* handle: (value) => [decl('z-index', value)],
|
|
185
|
+
* description: 'z-index utility',
|
|
186
|
+
* category: 'layout',
|
|
187
|
+
* });
|
|
188
|
+
*/
|
|
189
|
+
export declare function functionalUtility(opts: FunctionalUtilityOptions): void;
|
|
190
|
+
|
|
191
|
+
export declare type FunctionalUtilityExtra = {
|
|
192
|
+
opacity?: string;
|
|
193
|
+
realThemeValue?: string;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
export declare type FunctionalUtilityOptions = {
|
|
197
|
+
/**
|
|
198
|
+
* The name of the utility
|
|
199
|
+
*
|
|
200
|
+
* prefix is automatically added to the name
|
|
201
|
+
*/
|
|
202
|
+
name: string;
|
|
203
|
+
/**
|
|
204
|
+
* The CSS property to set
|
|
205
|
+
*
|
|
206
|
+
* css property is automatically added to the prop
|
|
207
|
+
*/
|
|
208
|
+
prop?: string;
|
|
209
|
+
/**
|
|
210
|
+
* The theme key to look up values
|
|
211
|
+
*
|
|
212
|
+
* theme key is automatically added to the themeKey
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```
|
|
216
|
+
* themeKey: 'colors'
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
themeKey?: string;
|
|
220
|
+
/**
|
|
221
|
+
* The theme keys to look up values
|
|
222
|
+
*
|
|
223
|
+
* theme keys are automatically added to the themeKeys
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```
|
|
227
|
+
* themeKeys: ['colors', 'spacing']
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
themeKeys?: string[];
|
|
231
|
+
/**
|
|
232
|
+
* Whether to support arbitrary values
|
|
233
|
+
*
|
|
234
|
+
* `bg-[#ff0000]`
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```
|
|
238
|
+
* supportsArbitrary: true
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
supportsArbitrary?: boolean;
|
|
242
|
+
/**
|
|
243
|
+
* Whether to support fraction values
|
|
244
|
+
*
|
|
245
|
+
* `m-4`
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```
|
|
249
|
+
* supportsFraction: true
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
supportsFraction?: boolean;
|
|
253
|
+
/**
|
|
254
|
+
* Whether to support custom properties
|
|
255
|
+
*
|
|
256
|
+
* `bg-(--my-bg)`
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```
|
|
260
|
+
* supportsCustomProperty: true
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
supportsCustomProperty?: boolean;
|
|
264
|
+
/**
|
|
265
|
+
* Whether to support negative values
|
|
266
|
+
*
|
|
267
|
+
* `-m-4`
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```
|
|
271
|
+
* supportsNegative: true
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
supportsNegative?: boolean;
|
|
275
|
+
/**
|
|
276
|
+
* Whether to support opacity values
|
|
277
|
+
*/
|
|
278
|
+
supportsOpacity?: boolean;
|
|
279
|
+
/**
|
|
280
|
+
* The handler function that processes values
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```
|
|
284
|
+
* handle: (value, ctx, token, extra) => {
|
|
285
|
+
* return [decl('background-color', value)];
|
|
286
|
+
* }
|
|
287
|
+
* ```
|
|
288
|
+
*
|
|
289
|
+
* @param value The value to process
|
|
290
|
+
* @param ctx The context
|
|
291
|
+
* @param token The parsed utility
|
|
292
|
+
* @param extra The extra metadata
|
|
293
|
+
*
|
|
294
|
+
* @returns {AstNode[] | null | undefined} The AST nodes or null | undefined
|
|
295
|
+
*/
|
|
296
|
+
handle?: (value: string, ctx: Context, token: ParsedUtility, extra?: FunctionalUtilityExtra) => AstNode[] | null | undefined;
|
|
297
|
+
/**
|
|
298
|
+
* The handler function that processes bare values
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```
|
|
302
|
+
* handleBareValue: ({ value }) => isPositiveInteger(value) ? value : null,
|
|
303
|
+
* ```
|
|
304
|
+
*
|
|
305
|
+
* @param args The arguments
|
|
306
|
+
* @param args.value The value to process
|
|
307
|
+
* @param args.ctx The context
|
|
308
|
+
* @param args.token The parsed utility
|
|
309
|
+
* @param args.extra The extra metadata
|
|
310
|
+
*
|
|
311
|
+
* @returns {string | null | undefined} The processed value or null | undefined
|
|
312
|
+
*/
|
|
313
|
+
handleBareValue?: (args: {
|
|
314
|
+
value: string;
|
|
315
|
+
ctx: Context;
|
|
316
|
+
token: ParsedUtility;
|
|
317
|
+
extra?: FunctionalUtilityExtra;
|
|
318
|
+
}) => string | null | undefined;
|
|
319
|
+
/**
|
|
320
|
+
* The handler function that processes negative bare values
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```
|
|
324
|
+
* handleNegativeBareValue: ({ value }) => isPositiveInteger(value) ? value : null,
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
handleNegativeBareValue?: (args: {
|
|
328
|
+
value: string;
|
|
329
|
+
ctx: Context;
|
|
330
|
+
token: ParsedUtility;
|
|
331
|
+
extra?: FunctionalUtilityExtra;
|
|
332
|
+
}) => string | null | undefined;
|
|
333
|
+
/**
|
|
334
|
+
* The handler function that processes custom property values
|
|
335
|
+
*
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```
|
|
339
|
+
* handleCustomProperty: (value, ctx, token, extra) => [decl('background-color', value)],
|
|
340
|
+
* ```
|
|
341
|
+
*
|
|
342
|
+
* @param args The arguments
|
|
343
|
+
* @param args.value The value to process
|
|
344
|
+
* @param args.ctx The context
|
|
345
|
+
* @param args.token The parsed utility
|
|
346
|
+
* @param args.extra The extra metadata
|
|
347
|
+
*
|
|
348
|
+
* @returns {AstNode[] | null | undefined} The AST nodes or null | undefined
|
|
349
|
+
*/
|
|
350
|
+
handleCustomProperty?: (value: string, ctx: Context, token: ParsedUtility, extra?: FunctionalUtilityExtra) => AstNode[] | null | undefined;
|
|
351
|
+
/**
|
|
352
|
+
* The description of the utility
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```
|
|
356
|
+
* description: 'Custom utility description',
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
description?: string;
|
|
360
|
+
/**
|
|
361
|
+
* The category of the utility
|
|
362
|
+
*
|
|
363
|
+
* It is used to group utilities in the documentation and styles
|
|
364
|
+
*
|
|
365
|
+
*
|
|
366
|
+
* @example
|
|
367
|
+
* ```
|
|
368
|
+
* category: 'background',
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
category?: string;
|
|
372
|
+
/**
|
|
373
|
+
* The priority of the utility
|
|
374
|
+
*
|
|
375
|
+
* It is used to sort utilities in the styles
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* ```
|
|
379
|
+
* priority: 10,
|
|
380
|
+
* ```
|
|
381
|
+
*
|
|
382
|
+
* The higher the number, the higher the priority
|
|
383
|
+
*
|
|
384
|
+
* @default 0
|
|
385
|
+
*/
|
|
386
|
+
priority?: number;
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* generateCss
|
|
391
|
+
* Takes multiple classNames and generates CSS for each, joining them.
|
|
392
|
+
* - Input: classList(string), Context, options
|
|
393
|
+
* - Output: string (result of joining multiple CSS blocks)
|
|
394
|
+
* - Processes internally parseClassToAst → optimizeAst → astToCss in sequence
|
|
395
|
+
* - Supports options like dedup, minify
|
|
396
|
+
*
|
|
397
|
+
* @param classList string (e.g., 'bg-red-500 text-lg hover:bg-blue-500')
|
|
398
|
+
* @param ctx Context
|
|
399
|
+
* @param opts { minify?: boolean, dedup?: boolean }
|
|
400
|
+
* @returns string
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* const css = generateCss('sm:dark:hover:bg-red-500 sm:focus:bg-blue-500', ctx);
|
|
404
|
+
*/
|
|
405
|
+
export declare function generateCss(classList: string, ctx: Context, opts?: {
|
|
406
|
+
minify?: boolean;
|
|
407
|
+
dedup?: boolean;
|
|
408
|
+
}): string;
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Returns an array of optimized results for multiple class names with dedup/filter.
|
|
412
|
+
* - Each object: { cls, ast, css }
|
|
413
|
+
* - Supports minify, dedup options
|
|
414
|
+
* - Applies astToCss(cleanAst, cls, opts) per class
|
|
415
|
+
* @param classList string (space-separated)
|
|
416
|
+
* @param ctx Context
|
|
417
|
+
* @param opts { minify?: boolean; dedup?: boolean }
|
|
418
|
+
* @returns Array<{ cls: string; ast: AstNode[]; css: string }>
|
|
419
|
+
*/
|
|
420
|
+
export declare function generateCssRules(classList: string, ctx: Context, opts?: {
|
|
421
|
+
minify?: boolean;
|
|
422
|
+
dedup?: boolean;
|
|
423
|
+
}): Array<GenerateCssRulesResult>;
|
|
424
|
+
|
|
425
|
+
export declare type GenerateCssRulesResult = {
|
|
426
|
+
cls: string;
|
|
427
|
+
ast: AstNode[];
|
|
428
|
+
css: string;
|
|
429
|
+
cssList: string[];
|
|
430
|
+
rootCss: string;
|
|
431
|
+
rootCssList: string[];
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
export declare function getModifier(): ModifierRegistration[];
|
|
435
|
+
|
|
436
|
+
export declare function getPreflightCSS(level?: PreflightLevel): string;
|
|
437
|
+
|
|
438
|
+
export declare function getUtility(): UtilityRegistration[];
|
|
439
|
+
|
|
440
|
+
export declare type HasItems = {
|
|
441
|
+
items?: AstNode[];
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
export declare type HasName = {
|
|
445
|
+
name?: string;
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
export declare type HasNodes = {
|
|
449
|
+
nodes?: AstNode[];
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
export declare type HasParams = {
|
|
453
|
+
params?: string;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
export declare function hasPreset(themeObj: Theme, category: string, preset: string): boolean;
|
|
457
|
+
|
|
458
|
+
export declare type HasProp = {
|
|
459
|
+
prop?: string;
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
export declare type HasSelector = {
|
|
463
|
+
selector?: string;
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
export declare type HasSource = {
|
|
467
|
+
source?: string;
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
export declare type HasText = {
|
|
471
|
+
text?: string;
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
export declare type HasValue = {
|
|
475
|
+
value?: string | [string, string][];
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Incremental parsing system for efficient class processing
|
|
480
|
+
*
|
|
481
|
+
* This class provides an optimized approach to CSS class processing by:
|
|
482
|
+
* - Tracking processed classes to avoid redundant work
|
|
483
|
+
* - Batching multiple class operations for better performance
|
|
484
|
+
* - Supporting both synchronous and asynchronous processing modes
|
|
485
|
+
*
|
|
486
|
+
* ## Usage Patterns
|
|
487
|
+
*
|
|
488
|
+
* ### Universal Usage (Node.js & Browser)
|
|
489
|
+
* ```typescript
|
|
490
|
+
* const parser = new IncrementalParser(ctx);
|
|
491
|
+
*
|
|
492
|
+
* // Process classes synchronously
|
|
493
|
+
* const results = parser.processClasses(['bg-blue-500', 'text-lg']);
|
|
494
|
+
*
|
|
495
|
+
* // Process single class
|
|
496
|
+
* const result = parser.processClass('bg-red-500');
|
|
497
|
+
*
|
|
498
|
+
* // Get statistics
|
|
499
|
+
* const stats = parser.getStats();
|
|
500
|
+
* ```
|
|
501
|
+
*
|
|
502
|
+
* ### Browser Integration
|
|
503
|
+
* ```typescript
|
|
504
|
+
* const parser = new IncrementalParser(ctx);
|
|
505
|
+
* const BrowserRuntime = new BrowserRuntime();
|
|
506
|
+
*
|
|
507
|
+
* // Process classes and manually inject CSS
|
|
508
|
+
* const results = parser.processClasses(['bg-blue-500', 'text-lg']);
|
|
509
|
+
* results.forEach(result => {
|
|
510
|
+
* if (result.css) {
|
|
511
|
+
* BrowserRuntime.insertRule(result.css);
|
|
512
|
+
* }
|
|
513
|
+
* });
|
|
514
|
+
*
|
|
515
|
+
* // Use with ChangeDetector for automatic DOM monitoring
|
|
516
|
+
* const detector = new ChangeDetector(parser);
|
|
517
|
+
* detector.observe(document.body, { scan: true });
|
|
518
|
+
* ```
|
|
519
|
+
*
|
|
520
|
+
* ## Architecture
|
|
521
|
+
*
|
|
522
|
+
* - **IncrementalParser**: Pure CSS processing (works in Node.js and browser)
|
|
523
|
+
* - **ChangeDetector**: Browser-only DOM monitoring (uses MutationObserver)
|
|
524
|
+
* - **BrowserRuntime**: Browser-only CSS injection (uses DOM APIs)
|
|
525
|
+
*/
|
|
526
|
+
export declare class IncrementalParser {
|
|
527
|
+
/** Set of class names that have already been processed to avoid duplicates */
|
|
528
|
+
private processedClasses;
|
|
529
|
+
/** BAROCSS context for theme and utility resolution */
|
|
530
|
+
private ctx;
|
|
531
|
+
/** Maximum number of classes to process in a single batch */
|
|
532
|
+
private batchSize;
|
|
533
|
+
/** Debounce delay for batch processing in milliseconds */
|
|
534
|
+
private debounceMs;
|
|
535
|
+
/** Set of classes waiting to be processed */
|
|
536
|
+
private pendingClasses;
|
|
537
|
+
/** Timer for debounced batch processing */
|
|
538
|
+
private batchTimer;
|
|
539
|
+
/**
|
|
540
|
+
* Create a new IncrementalParser instance
|
|
541
|
+
*
|
|
542
|
+
* @param ctx - BAROCSS context for theme and utility resolution
|
|
543
|
+
*/
|
|
544
|
+
constructor(ctx: Context);
|
|
545
|
+
/**
|
|
546
|
+
* Processes a single CSS class and generates its AST and CSS representation
|
|
547
|
+
*
|
|
548
|
+
* This method performs the complete pipeline for a single class:
|
|
549
|
+
* 1. Checks if the class has already been processed
|
|
550
|
+
* 2. Parses the class name to extract utility information
|
|
551
|
+
* 3. Generates the Abstract Syntax Tree (AST)
|
|
552
|
+
* 4. Converts the AST to CSS rules
|
|
553
|
+
* 5. Marks the class as processed to avoid future duplicates
|
|
554
|
+
*
|
|
555
|
+
* @param className - The CSS class name to process (e.g., 'bg-blue-500')
|
|
556
|
+
* @returns Object containing AST and CSS, or null if processing failed or class was already processed
|
|
557
|
+
*/
|
|
558
|
+
processClass(className: string): GenerateCssRulesResult | null;
|
|
559
|
+
/**
|
|
560
|
+
* Processes multiple CSS classes in batches for optimal performance
|
|
561
|
+
*
|
|
562
|
+
* This method handles multiple classes efficiently by:
|
|
563
|
+
* - Filtering out already processed classes to avoid redundant work
|
|
564
|
+
* - Processing classes in configurable batch sizes
|
|
565
|
+
* - Returning comprehensive results for each processed class
|
|
566
|
+
*
|
|
567
|
+
* @param classes - Array of CSS class names to process
|
|
568
|
+
* @returns Array of processing results, each containing className, AST, and CSS
|
|
569
|
+
*/
|
|
570
|
+
processClasses(classes: string[]): Array<GenerateCssRulesResult>;
|
|
571
|
+
/**
|
|
572
|
+
* Adds classes to the pending queue for asynchronous batch processing
|
|
573
|
+
*
|
|
574
|
+
* This method is used by the ChangeDetector when new classes are discovered
|
|
575
|
+
* in the DOM. Classes are queued and processed together to minimize
|
|
576
|
+
* performance impact from frequent DOM mutations.
|
|
577
|
+
*
|
|
578
|
+
* @param classes - Array of CSS class names to queue for processing
|
|
579
|
+
*/
|
|
580
|
+
addToPending(classes: string[]): void;
|
|
581
|
+
/**
|
|
582
|
+
* Schedule batch processing with debouncing
|
|
583
|
+
*
|
|
584
|
+
* This method uses setTimeout to debounce rapid class additions
|
|
585
|
+
* and process them in batches for better performance.
|
|
586
|
+
*/
|
|
587
|
+
private scheduleBatchProcessing;
|
|
588
|
+
/**
|
|
589
|
+
* Process pending classes from the queue
|
|
590
|
+
*
|
|
591
|
+
* This method is called by the debounced timer to process
|
|
592
|
+
* all classes that have been added to the pending queue.
|
|
593
|
+
*/
|
|
594
|
+
private processPendingClasses;
|
|
595
|
+
/**
|
|
596
|
+
* Core method that processes classes and marks them as processed
|
|
597
|
+
*
|
|
598
|
+
* This is the common processing logic used by both pending and synchronous
|
|
599
|
+
* processing methods. It:
|
|
600
|
+
* 1. Processes the provided classes using the batch processor
|
|
601
|
+
* 2. Marks classes as processed to prevent duplicates
|
|
602
|
+
*
|
|
603
|
+
* @param classes - Array of CSS class names to process
|
|
604
|
+
*/
|
|
605
|
+
private applyClasses;
|
|
606
|
+
/**
|
|
607
|
+
* Returns comprehensive statistics about the incremental parser's state
|
|
608
|
+
*
|
|
609
|
+
* This method provides detailed metrics including:
|
|
610
|
+
* - Number of processed classes
|
|
611
|
+
* - Number of pending classes
|
|
612
|
+
* - Cache statistics from AST and CSS caches
|
|
613
|
+
*
|
|
614
|
+
* @returns Object containing processing statistics and cache information
|
|
615
|
+
*/
|
|
616
|
+
getStats(): {
|
|
617
|
+
processedClasses: number;
|
|
618
|
+
pendingClasses: number;
|
|
619
|
+
cacheStats: {
|
|
620
|
+
ast: {
|
|
621
|
+
size: number;
|
|
622
|
+
maxSize: number;
|
|
623
|
+
hitRate: number;
|
|
624
|
+
};
|
|
625
|
+
css: {};
|
|
626
|
+
};
|
|
627
|
+
};
|
|
628
|
+
/**
|
|
629
|
+
* Clears all processed classes and pending queue
|
|
630
|
+
*
|
|
631
|
+
* This method is useful when the theme or configuration changes,
|
|
632
|
+
* requiring all classes to be reprocessed. It:
|
|
633
|
+
* - Clears the processed classes set
|
|
634
|
+
* - Clears the pending classes queue
|
|
635
|
+
* - Cancels any pending batch processing timer
|
|
636
|
+
*/
|
|
637
|
+
clearProcessed(): void;
|
|
638
|
+
/**
|
|
639
|
+
* Checks if a specific class has been processed
|
|
640
|
+
*
|
|
641
|
+
* @param cls - The CSS class name to check
|
|
642
|
+
* @returns True if the class has been processed, false otherwise
|
|
643
|
+
*/
|
|
644
|
+
isProcessed(cls: string): boolean;
|
|
645
|
+
/**
|
|
646
|
+
* Marks a class as processed to prevent future duplicate processing
|
|
647
|
+
*
|
|
648
|
+
* @param cls - The CSS class name to mark as processed
|
|
649
|
+
*/
|
|
650
|
+
markProcessed(cls: string): void;
|
|
651
|
+
/**
|
|
652
|
+
* Process classes synchronously and update BrowserRuntime cache
|
|
653
|
+
* This method is used by ChangeDetector for scan operations
|
|
654
|
+
*/
|
|
655
|
+
processClassesSync(classes: string[]): void;
|
|
656
|
+
/**
|
|
657
|
+
* Returns all currently processed class names
|
|
658
|
+
*
|
|
659
|
+
* This method is useful for debugging and monitoring purposes,
|
|
660
|
+
* providing visibility into which classes have been processed.
|
|
661
|
+
*
|
|
662
|
+
* @returns Array of all processed class names
|
|
663
|
+
*/
|
|
664
|
+
getProcessedClasses(): string[];
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* mergeAstTreeList
|
|
669
|
+
* Takes a list of declPathToAst results (AstNode[][]), merges same at-rule(name, params) etc., and returns the final AST tree.
|
|
670
|
+
* - Input: AstNode[][] (nested ASTs of multiple decl-to-root paths)
|
|
671
|
+
* @returns AstNode[]
|
|
672
|
+
* - Usage: Used in optimizeAst for final AST merging/optimization
|
|
673
|
+
*
|
|
674
|
+
* @param astList AstNode[][]
|
|
675
|
+
* @returns AstNode[]
|
|
676
|
+
*/
|
|
677
|
+
export declare function mergeAstTreeList(astList: AstNode[][]): AstNode[];
|
|
678
|
+
|
|
679
|
+
export declare type ModifierRegistration = {
|
|
680
|
+
match: (mod: string, context: Context) => boolean;
|
|
681
|
+
modifySelector?: (params: {
|
|
682
|
+
selector: string;
|
|
683
|
+
fullClassName: string;
|
|
684
|
+
mod: ParsedModifier;
|
|
685
|
+
context: Context;
|
|
686
|
+
variantChain?: ParsedModifier[];
|
|
687
|
+
index?: number;
|
|
688
|
+
}) => string | {
|
|
689
|
+
selector: string;
|
|
690
|
+
flatten?: boolean;
|
|
691
|
+
wrappingType?: 'rule' | 'style-rule' | 'at-rule';
|
|
692
|
+
override?: boolean;
|
|
693
|
+
source?: string;
|
|
694
|
+
};
|
|
695
|
+
wrap?: (mod: ParsedModifier, context: Context) => AstNode[];
|
|
696
|
+
astHandler?: (ast: AstNode[], mod: ParsedModifier, context: Context, variantChain?: ParsedModifier[], index?: number) => AstNode[];
|
|
697
|
+
sort?: number;
|
|
698
|
+
description?: string;
|
|
699
|
+
source?: string;
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
export declare const modifierRegistry: ModifierRegistration[];
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* optimizeAst
|
|
706
|
+
* Merges/organizes AST generated by parseClassToAst into an optimized AST tree based on decl-to-root path.
|
|
707
|
+
* - Input: AstNode[] (result of parseClassToAst)
|
|
708
|
+
* - Output: Optimized AST tree (AstNode[])
|
|
709
|
+
* - Uses collectDeclPaths, declPathToAst, mergeAstTreeList internally
|
|
710
|
+
* - Reflects all variant wrapping structures (nesting, siblings, merging, etc.)
|
|
711
|
+
*
|
|
712
|
+
* @param ast AstNode[]
|
|
713
|
+
* @returns AstNode[]
|
|
714
|
+
*/
|
|
715
|
+
export declare function optimizeAst(ast: AstNode[]): AstNode[];
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Parses a class name string into modifiers and utility using tokenization
|
|
719
|
+
* Supports both directions:
|
|
720
|
+
* - modifier:utility (traditional CSS)
|
|
721
|
+
* - utility:modifier (Master CSS style)
|
|
722
|
+
*
|
|
723
|
+
* Examples:
|
|
724
|
+
* - 'group-hover:sm:bg-[red]' → modifier:utility
|
|
725
|
+
* - 'bg-red-500:hover' → utility:modifier
|
|
726
|
+
* - 'text-[color:var(--foo)]' → utility only
|
|
727
|
+
*
|
|
728
|
+
* @param className e.g. 'group-hover:sm:bg-[red]', 'text-[color:var(--foo)]'
|
|
729
|
+
* @returns { modifiers, utility }
|
|
730
|
+
*/
|
|
731
|
+
export declare function parseClassName(className: string): {
|
|
732
|
+
modifiers: ParsedModifier[];
|
|
733
|
+
utility: ParsedUtility | null;
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* parseClassToAst
|
|
738
|
+
* Parses className(including variant chain) to generate AST tree.
|
|
739
|
+
* - Input: className(string), Context
|
|
740
|
+
* - Output: AstNode[] (multiple roots possible for variant wrapping path)
|
|
741
|
+
* - Perfectly supports variant wrapping structure (Cartesian product, nesting, siblings, etc.)
|
|
742
|
+
* - Accumulates wrappers in wrappers and applies them from right to left.
|
|
743
|
+
* - Can return multiple root asts.
|
|
744
|
+
*
|
|
745
|
+
* @param fullClassName string (e.g., 'sm:dark:hover:bg-red-500')
|
|
746
|
+
* @param ctx Context
|
|
747
|
+
* @returns AstNode[]
|
|
748
|
+
*
|
|
749
|
+
* @example
|
|
750
|
+
* const ast = parseClassToAst('sm:dark:hover:bg-red-500', ctx);
|
|
751
|
+
* // ast is an AST tree with sm, dark, hover variants nested
|
|
752
|
+
*/
|
|
753
|
+
export declare function parseClassToAst(fullClassName: string, ctx: Context): AstNode[];
|
|
754
|
+
|
|
755
|
+
export declare interface ParsedModifier {
|
|
756
|
+
type: string;
|
|
757
|
+
value?: string;
|
|
758
|
+
negative?: boolean;
|
|
759
|
+
arbitrary?: boolean;
|
|
760
|
+
[key: string]: unknown;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
export declare interface ParsedUtility {
|
|
764
|
+
category?: string;
|
|
765
|
+
prefix: string;
|
|
766
|
+
value?: string;
|
|
767
|
+
arbitrary?: boolean;
|
|
768
|
+
customProperty?: boolean;
|
|
769
|
+
negative?: boolean;
|
|
770
|
+
opacity?: string;
|
|
771
|
+
priority?: number;
|
|
772
|
+
important?: boolean;
|
|
773
|
+
[key: string]: unknown;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Parse result cache management
|
|
778
|
+
*/
|
|
779
|
+
export declare class ParseResultCache {
|
|
780
|
+
private cache;
|
|
781
|
+
private maxSize;
|
|
782
|
+
set(key: string, result: {
|
|
783
|
+
modifiers: ParsedModifier[];
|
|
784
|
+
utility: ParsedUtility | null;
|
|
785
|
+
}): void;
|
|
786
|
+
get(key: string): {
|
|
787
|
+
modifiers: ParsedModifier[];
|
|
788
|
+
utility: ParsedUtility | null;
|
|
789
|
+
} | undefined;
|
|
790
|
+
has(key: string): boolean;
|
|
791
|
+
clear(): void;
|
|
792
|
+
getStats(): {
|
|
793
|
+
size: number;
|
|
794
|
+
maxSize: number;
|
|
795
|
+
hitRate: number;
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
export declare const parseResultCache: ParseResultCache;
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* decl-to-root path collection function (reused in normalizeAstOrder, etc.)
|
|
803
|
+
*/
|
|
804
|
+
export declare type PathNode = Partial<AstNode>;
|
|
805
|
+
|
|
806
|
+
declare type PreflightLevel = 'minimal' | 'standard' | 'full' | true | false;
|
|
807
|
+
|
|
808
|
+
export declare function property(name: string, initialValue?: string, syntax?: string, source?: string): AstNode;
|
|
809
|
+
|
|
810
|
+
export declare function raw(value: string, source?: string): AstNode;
|
|
811
|
+
|
|
812
|
+
export declare function registerUtility(util: UtilityRegistration): void;
|
|
813
|
+
|
|
814
|
+
export declare function resolveTheme(config: Config): Theme;
|
|
815
|
+
|
|
816
|
+
export declare function rootToCss(nodes: AstNode[]): string;
|
|
817
|
+
|
|
818
|
+
export declare function rule(selector: string, nodes: AstNode[], source?: string): AstNode;
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* staticModifier: A helper that registers a modifier name and an array of CSS selectors directly to the registry
|
|
822
|
+
*
|
|
823
|
+
* @example
|
|
824
|
+
* ```
|
|
825
|
+
* staticModifier('disabled', ['&:disabled'], { source: 'pseudo' });
|
|
826
|
+
* ```
|
|
827
|
+
*
|
|
828
|
+
* @param name The name of the modifier
|
|
829
|
+
* @param selectors The selectors of the modifier
|
|
830
|
+
* @param options The options of the modifier
|
|
831
|
+
*
|
|
832
|
+
* @returns {void}
|
|
833
|
+
*/
|
|
834
|
+
export declare function staticModifier(name: string, selectors: string[], options?: any): void;
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* staticUtility: A helper that registers a utility name and an array of CSS declaration pairs directly to the registry
|
|
838
|
+
*
|
|
839
|
+
* @example
|
|
840
|
+
* ```
|
|
841
|
+
* staticUtility('block', [['display', 'block']]);
|
|
842
|
+
* staticUtility('hidden', [['display', 'none']]);
|
|
843
|
+
* staticUtility('space-x-px', [
|
|
844
|
+
* [
|
|
845
|
+
* '& > :not([hidden]) ~ :not([hidden])', // selector
|
|
846
|
+
* [
|
|
847
|
+
* ['margin-inline-start', '1px'], // [prop, value]
|
|
848
|
+
* ['margin-inline-end', '1px'], // [prop, value]
|
|
849
|
+
* ],
|
|
850
|
+
* ],
|
|
851
|
+
* ]);
|
|
852
|
+
* ```
|
|
853
|
+
*
|
|
854
|
+
* @param name The name of the utility
|
|
855
|
+
* @param decls The declarations of the utility
|
|
856
|
+
* @param opts The options of the utility
|
|
857
|
+
*
|
|
858
|
+
* @returns {void}
|
|
859
|
+
*/
|
|
860
|
+
export declare function staticUtility(name: string, decls: StaticUtilityValue[], opts?: {
|
|
861
|
+
description?: string;
|
|
862
|
+
category?: string;
|
|
863
|
+
priority?: number;
|
|
864
|
+
}): void;
|
|
865
|
+
|
|
866
|
+
declare type StaticUtilityValue = AstNode | [string, string] | [string, [string, string][]] | ((value: string) => AstNode);
|
|
867
|
+
|
|
868
|
+
export declare function styleRule(selector: string, nodes: AstNode[], source?: string): AstNode;
|
|
869
|
+
|
|
870
|
+
export declare interface Theme {
|
|
871
|
+
extend?: Theme;
|
|
872
|
+
[namespace: string]: unknown;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
export declare type ThemeGetter = (...path: (string | number)[]) => unknown;
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Modern theme getter for BAROCSS
|
|
879
|
+
*
|
|
880
|
+
* - Supports category-level (first path segment) function values only.
|
|
881
|
+
* - If the category (e.g., 'spacing', 'colors') is a function, it will be executed with the theme getter as argument.
|
|
882
|
+
* - This allows dynamic theme extension and plugin-style patterns, e.g.:
|
|
883
|
+
* spacing: (theme) => ({ ...theme('spacing'), '72': '18rem' })
|
|
884
|
+
* - Leaf (property) functions are NOT supported and will be ignored (returns undefined).
|
|
885
|
+
* - Infinite recursion is prevented: If the exact same path is being resolved recursively (directly or indirectly), undefined is returned for that call.
|
|
886
|
+
* - Category-level functions can safely call theme('category.otherKey') for dynamic references.
|
|
887
|
+
* - Only true recursion on the same path is blocked.
|
|
888
|
+
* - All theme lookups (theme('category.key')) will always re-execute the category function if present, ensuring dynamic resolution.
|
|
889
|
+
*
|
|
890
|
+
* @param themeObj - The theme object (possibly with category functions)
|
|
891
|
+
* @param path - Path segments (string or number), or dot-path string (e.g. 'colors.red.500')
|
|
892
|
+
* @returns The resolved theme value, or undefined if not found or if a leaf function is encountered
|
|
893
|
+
*
|
|
894
|
+
* @example
|
|
895
|
+
* const theme = {
|
|
896
|
+
* spacing: (theme) => ({ 1: '0.25rem', 2: theme('spacing.1') }),
|
|
897
|
+
* };
|
|
898
|
+
* themeGetter(theme, 'spacing.2'); // '0.25rem'
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* // Infinite recursion is prevented:
|
|
902
|
+
* const theme = {
|
|
903
|
+
* spacing: (theme) => theme('spacing.1'),
|
|
904
|
+
* };
|
|
905
|
+
* themeGetter(theme, 'spacing.1'); // undefined
|
|
906
|
+
*/
|
|
907
|
+
export declare function themeGetter(themeObj: Theme, ...path: (string | number)[]): unknown;
|
|
908
|
+
|
|
909
|
+
export declare function themeToCssVars(theme: Theme): string;
|
|
910
|
+
|
|
911
|
+
export declare interface Token {
|
|
912
|
+
value: string;
|
|
913
|
+
start: number;
|
|
914
|
+
end: number;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
* Tokenizes a class name string into an array of tokens
|
|
919
|
+
* Only handles separation by ':' while respecting brackets and parentheses
|
|
920
|
+
*
|
|
921
|
+
* Examples:
|
|
922
|
+
* - 'hover:bg-red-500' → [{ value: 'hover' }, { value: 'bg-red-500' }]
|
|
923
|
+
* - 'bg-[#ff0000]:hover' → [{ value: 'bg-[#ff0000]' }, { value: 'hover' }]
|
|
924
|
+
* - 'text-[color:var(--foo)]' → [{ value: 'text-[color:var(--foo)]' }]
|
|
925
|
+
* - '!bg-[red]' → [{ value: '!bg-[red]' }]
|
|
926
|
+
*/
|
|
927
|
+
export declare function tokenize(className: string): Token[];
|
|
928
|
+
|
|
929
|
+
/**
|
|
930
|
+
* Utility cache management
|
|
931
|
+
*/
|
|
932
|
+
export declare class UtilityCache {
|
|
933
|
+
private cache;
|
|
934
|
+
private maxSize;
|
|
935
|
+
set(key: string, value: boolean): void;
|
|
936
|
+
get(key: string): boolean | undefined;
|
|
937
|
+
has(key: string): boolean;
|
|
938
|
+
clear(): void;
|
|
939
|
+
getStats(): {
|
|
940
|
+
size: number;
|
|
941
|
+
maxSize: number;
|
|
942
|
+
hitRate: number;
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
export declare const utilityCache: UtilityCache;
|
|
947
|
+
|
|
948
|
+
export declare interface UtilityRegistration {
|
|
949
|
+
/**
|
|
950
|
+
* The name of the utility
|
|
951
|
+
*/
|
|
952
|
+
name: string;
|
|
953
|
+
/**
|
|
954
|
+
* The match function for the utility
|
|
955
|
+
* @param className The class name of the utility
|
|
956
|
+
* @returns {boolean} Whether the utility matches the class name
|
|
957
|
+
*/
|
|
958
|
+
match: (className: string) => boolean;
|
|
959
|
+
/**
|
|
960
|
+
* Handler for utility value
|
|
961
|
+
* @param value Utility value (e.g. 'red-500')
|
|
962
|
+
* @param ctx Context
|
|
963
|
+
* @param token Parsed token
|
|
964
|
+
* @param options Registration options
|
|
965
|
+
*/
|
|
966
|
+
handler: (value: string, ctx: Context, token: ParsedUtility, options: UtilityRegistration) => AstNode[] | null | undefined;
|
|
967
|
+
/**
|
|
968
|
+
* The description of the utility
|
|
969
|
+
* @example
|
|
970
|
+
* ```
|
|
971
|
+
* description: 'Custom utility description',
|
|
972
|
+
* ```
|
|
973
|
+
*/
|
|
974
|
+
description?: string;
|
|
975
|
+
/**
|
|
976
|
+
* The category of the utility
|
|
977
|
+
* @example
|
|
978
|
+
* ```
|
|
979
|
+
* category: 'background',
|
|
980
|
+
* ```
|
|
981
|
+
*/
|
|
982
|
+
category?: string;
|
|
983
|
+
/**
|
|
984
|
+
* The priority of the utility
|
|
985
|
+
* @example
|
|
986
|
+
* ```
|
|
987
|
+
* priority: 10,
|
|
988
|
+
* ```
|
|
989
|
+
*/
|
|
990
|
+
priority?: number;
|
|
991
|
+
[key: string]: unknown;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
/**
|
|
995
|
+
* WeakMap-based cache for memory optimization
|
|
996
|
+
*/
|
|
997
|
+
export declare class WeakCache<T> {
|
|
998
|
+
private cache;
|
|
999
|
+
private keyMap;
|
|
1000
|
+
private maxSize;
|
|
1001
|
+
set(key: string, value: T): void;
|
|
1002
|
+
get(key: string): T | undefined;
|
|
1003
|
+
has(key: string): boolean;
|
|
1004
|
+
clear(): void;
|
|
1005
|
+
getStats(): {
|
|
1006
|
+
size: number;
|
|
1007
|
+
maxSize: number;
|
|
1008
|
+
hitRate: number;
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
export { }
|