@unocss/rule-utils 66.5.10 → 66.5.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,36 +1,38 @@
1
- import { Arrayable, VariantHandlerContext, VariantObject } from '@unocss/core';
1
+ import MagicString from "magic-string";
2
+ import { LoadConfigResult } from "unconfig";
2
3
 
4
+ //#region src/colors.d.ts
3
5
  interface CSSColorValue {
4
- type: string;
5
- components: (string | number)[];
6
- alpha: string | number | undefined;
6
+ type: string;
7
+ components: (string | number)[];
8
+ alpha: string | number | undefined;
7
9
  }
8
10
  type RGBAColorValue = [number, number, number, number] | [number, number, number];
9
11
  interface ParsedColorValue {
10
- /**
11
- * Parsed color value.
12
- */
13
- color?: string;
14
- /**
15
- * Parsed opacity value.
16
- */
17
- opacity: string;
18
- /**
19
- * Color name.
20
- */
21
- name: string;
22
- /**
23
- * Color scale, preferably 000 - 999.
24
- */
25
- no: string;
26
- /**
27
- * {@link CSSColorValue}
28
- */
29
- cssColor: CSSColorValue | undefined;
30
- /**
31
- * Parsed alpha value from opacity
32
- */
33
- alpha: string | number | undefined;
12
+ /**
13
+ * Parsed color value.
14
+ */
15
+ color?: string;
16
+ /**
17
+ * Parsed opacity value.
18
+ */
19
+ opacity: string;
20
+ /**
21
+ * Color name.
22
+ */
23
+ name: string;
24
+ /**
25
+ * Color scale, preferably 000 - 999.
26
+ */
27
+ no: string;
28
+ /**
29
+ * {@link CSSColorValue}
30
+ */
31
+ cssColor: CSSColorValue | undefined;
32
+ /**
33
+ * Parsed alpha value from opacity
34
+ */
35
+ alpha: string | number | undefined;
34
36
  }
35
37
  declare const cssColorFunctions: string[];
36
38
  declare const rectangularColorSpace: string[];
@@ -43,36 +45,985 @@ declare function hex2rgba(hex?: string): RGBAColorValue | undefined;
43
45
  declare function parseCssColor(str?: string): CSSColorValue | undefined;
44
46
  declare function colorOpacityToString(color: CSSColorValue): string | number;
45
47
  declare function colorToString(color: CSSColorValue | string, alphaOverride?: string | number): string;
46
-
48
+ //#endregion
49
+ //#region src/directive.d.ts
47
50
  declare const themeFnRE: RegExp;
48
51
  declare function hasThemeFn(str: string): boolean;
49
52
  declare function transformThemeFn(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string;
50
53
  declare function transformThemeString(code: string, theme: Record<string, any>, throwOnMissing?: boolean): string | undefined;
51
54
  declare function calcMaxWidthBySize(size: string): string;
52
-
55
+ //#endregion
56
+ //#region src/handlers.d.ts
53
57
  type ValueHandlerCallback<T extends object> = (str: string, theme?: T) => string | number | undefined;
54
- type ValueHandler<K extends string, T extends object> = {
55
- [S in K]: ValueHandler<K, T>;
56
- } & {
57
- (str: string, theme?: T): string | undefined;
58
- __options: {
59
- sequence: K[];
60
- };
58
+ type ValueHandler<K$1 extends string, T extends object> = { [S in K$1]: ValueHandler<K$1, T> } & {
59
+ (str: string, theme?: T): string | undefined;
60
+ __options: {
61
+ sequence: K$1[];
62
+ };
61
63
  };
62
- declare function createValueHandler<K extends string, T extends object>(handlers: Record<K, ValueHandlerCallback<T>>): ValueHandler<K, T>;
63
-
64
+ declare function createValueHandler<K$1 extends string, T extends object>(handlers: Record<K$1, ValueHandlerCallback<T>>): ValueHandler<K$1, T>;
65
+ //#endregion
66
+ //#region src/icon.d.ts
64
67
  declare const iconFnRE: RegExp;
65
68
  declare function hasIconFn(str: string): boolean;
66
-
69
+ //#endregion
70
+ //#region ../../packages-engine/core/src/utils/countable-set.d.ts
71
+ declare class CountableSet<K$1> extends Set<K$1> {
72
+ _map: Map<K$1, number>;
73
+ constructor(values?: Iterable<K$1>);
74
+ add(key: K$1): this;
75
+ delete(key: K$1): boolean;
76
+ clear(): void;
77
+ getCount(key: K$1): number;
78
+ setCount(key: K$1, count: number): this;
79
+ }
80
+ //#endregion
81
+ //#region ../../packages-engine/core/src/utils/events.d.ts
82
+ type EventsMap = Record<string, any>;
83
+ interface DefaultEvents extends EventsMap {
84
+ [event: string]: (...args: any) => void;
85
+ }
86
+ interface Unsubscribe {
87
+ (): void;
88
+ }
89
+ declare class Emitter<Events extends EventsMap = DefaultEvents> {
90
+ /**
91
+ * Event names in keys and arrays with listeners in values.
92
+ *
93
+ * ```js
94
+ * emitter1.events = emitter2.events
95
+ * emitter2.events = { }
96
+ * ```
97
+ */
98
+ events: Partial<{ [E in keyof Events]: Events[E][] }>;
99
+ /**
100
+ * Add a listener for a given event.
101
+ *
102
+ * ```js
103
+ * const unbind = ee.on('tick', (tickType, tickDuration) => {
104
+ * count += 1
105
+ * })
106
+ *
107
+ * disable () {
108
+ * unbind()
109
+ * }
110
+ * ```
111
+ *
112
+ * @param event The event name.
113
+ * @param cb The listener function.
114
+ * @returns Unbind listener from event.
115
+ */
116
+ on<K$1 extends keyof Events>(this: this, event: K$1, cb: Events[K$1]): Unsubscribe;
117
+ /**
118
+ * Calls each of the listeners registered for a given event.
119
+ *
120
+ * ```js
121
+ * ee.emit('tick', tickType, tickDuration)
122
+ * ```
123
+ *
124
+ * @param event The event name.
125
+ * @param args The arguments for listeners.
126
+ */
127
+ emit<K$1 extends keyof Events>(this: this, event: K$1, ...args: Parameters<Events[K$1]>): void;
128
+ }
129
+ //#endregion
130
+ //#region ../../packages-engine/core/src/utils/map.d.ts
131
+ declare class BetterMap<K$1, V> extends Map<K$1, V> {
132
+ getFallback(key: K$1, fallback: V): V;
133
+ map<R>(mapFn: (value: V, key: K$1) => R): R[];
134
+ flatMap<R extends readonly unknown[]>(mapFn: (value: V, key: K$1) => R): R[number][];
135
+ }
136
+ //#endregion
137
+ //#region ../../packages-engine/core/src/generator.d.ts
138
+ declare class UnoGeneratorInternal<Theme extends object = object> {
139
+ userConfig: UserConfig<Theme>;
140
+ defaults: UserConfigDefaults<Theme>;
141
+ readonly version: string;
142
+ readonly events: Emitter<{
143
+ config: (config: ResolvedConfig<Theme>) => void;
144
+ }>;
145
+ config: ResolvedConfig<Theme>;
146
+ cache: Map<string, StringifiedUtil<Theme>[] | null>;
147
+ blocked: Set<string>;
148
+ parentOrders: Map<string, number>;
149
+ activatedRules: Set<Rule<Theme>>;
150
+ protected constructor(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>);
151
+ static create<Theme extends object = object>(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): Promise<UnoGeneratorInternal<Theme>>;
152
+ setConfig(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>): Promise<void>;
153
+ applyExtractors(code: string, id?: string, extracted?: Set<string>): Promise<Set<string>>;
154
+ applyExtractors(code: string, id?: string, extracted?: CountableSet<string>): Promise<CountableSet<string>>;
155
+ makeContext(raw: string, applied: VariantMatchedResult<Theme>): RuleContext<Theme>;
156
+ parseToken(raw: string, alias?: string): Promise<StringifiedUtil<Theme>[] | undefined | null>;
157
+ generate(input: string | Set<string> | CountableSet<string> | string[], options?: GenerateOptions<false>): Promise<GenerateResult<Set<string>>>;
158
+ generate(input: string | Set<string> | CountableSet<string> | string[], options?: GenerateOptions<true>): Promise<GenerateResult<Map<string, ExtendedTokenInfo<Theme>>>>;
159
+ matchVariants(raw: string, current?: string): Promise<readonly VariantMatchedResult<Theme>[]>;
160
+ private applyVariants;
161
+ constructCustomCSS(context: Readonly<RuleContext<Theme>>, body: CSSObject | CSSEntries, overrideSelector?: string): string;
162
+ parseUtil(input: string | VariantMatchedResult<Theme>, context: RuleContext<Theme>, internal?: boolean, shortcutPrefix?: string | string[] | undefined): Promise<(ParsedUtil | RawUtil)[] | undefined>;
163
+ private resolveCSSResult;
164
+ stringifyUtil(parsed?: ParsedUtil | RawUtil, context?: RuleContext<Theme>): StringifiedUtil<Theme>[] | undefined;
165
+ expandShortcut(input: string, context: RuleContext<Theme>, depth?: number): Promise<[(string | ShortcutInlineValue)[], RuleMeta | undefined] | undefined>;
166
+ stringifyShortcuts(parent: VariantMatchedResult<Theme>, context: RuleContext<Theme>, expanded: (string | ShortcutInlineValue)[], meta?: RuleMeta): Promise<StringifiedUtil<Theme>[] | undefined>;
167
+ isBlocked(raw: string): boolean;
168
+ getBlocked(raw: string): [BlocklistValue, BlocklistMeta | undefined] | undefined;
169
+ }
170
+ declare class UnoGenerator<Theme extends object = object> extends UnoGeneratorInternal<Theme> {
171
+ /**
172
+ * @deprecated `new UnoGenerator` is deprecated, please use `createGenerator()` instead
173
+ */
174
+ constructor(userConfig?: UserConfig<Theme>, defaults?: UserConfigDefaults<Theme>);
175
+ }
176
+ //#endregion
177
+ //#region ../../packages-engine/core/src/types.d.ts
178
+ type Awaitable<T> = T | Promise<T>;
179
+ type Arrayable<T> = T | T[];
180
+ type FlatObjectTuple<T> = { [K in keyof T]: T[K] };
181
+ type RequiredByKey<T, K$1 extends keyof T = keyof T> = FlatObjectTuple<Required<Pick<T, Extract<keyof T, K$1>>> & Omit<T, K$1>>;
182
+ type CSSObject = Record<string, string | number | undefined>;
183
+ /**
184
+ * [property, value, operators?]
185
+ *
186
+ * - operators: Used to perform specific operations on value or property.
187
+ */
188
+ type CSSEntry = [string, string | number | undefined, Arrayable<string>?];
189
+ type CSSEntries = CSSEntry[];
190
+ type CSSObjectInput = CSSObject | Partial<ControlSymbolsValue>;
191
+ type CSSEntriesInput = (CSSEntry | ControlSymbolsEntry)[];
192
+ type CSSValueInput = CSSObjectInput | CSSEntriesInput | CSSValue;
193
+ type PresetOptions = Record<string, any>;
194
+ interface RuleContext<Theme extends object = object> {
195
+ /**
196
+ * Unprocessed selector from user input.
197
+ * Useful for generating CSS rule.
198
+ */
199
+ rawSelector: string;
200
+ /**
201
+ * Current selector for rule matching
202
+ */
203
+ currentSelector: string;
204
+ /**
205
+ * UnoCSS generator instance
206
+ */
207
+ generator: UnoGenerator<Theme>;
208
+ /**
209
+ * Symbols for special handling
210
+ */
211
+ symbols: ControlSymbols;
212
+ /**
213
+ * The theme object
214
+ */
215
+ theme: Theme;
216
+ /**
217
+ * Matched variants handlers for this rule.
218
+ */
219
+ variantHandlers: VariantHandler[];
220
+ /**
221
+ * The result of variant matching.
222
+ */
223
+ variantMatch: VariantMatchedResult<Theme>;
224
+ /**
225
+ * Construct a custom CSS rule.
226
+ * Variants and selector escaping will be handled automatically.
227
+ */
228
+ constructCSS: (body: CSSEntries | CSSObject, overrideSelector?: string) => string;
229
+ /**
230
+ * Available only when `details` option is enabled.
231
+ */
232
+ rules?: Rule<Theme>[];
233
+ /**
234
+ * Available only when `details` option is enabled.
235
+ */
236
+ shortcuts?: Shortcut<Theme>[];
237
+ /**
238
+ * Available only when `details` option is enabled.
239
+ */
240
+ variants?: Variant<Theme>[];
241
+ }
242
+ declare const SymbolShortcutsNoMerge: unique symbol;
243
+ declare const SymbolNoMerge: unique symbol;
244
+ declare const SymbolVariants: unique symbol;
245
+ declare const SymbolParent: unique symbol;
246
+ declare const SymbolSelector: unique symbol;
247
+ declare const SymbolLayer: unique symbol;
248
+ declare const SymbolSort: unique symbol;
249
+ declare const SymbolBody: unique symbol;
250
+ interface ControlSymbols {
251
+ /**
252
+ * Prevent merging in shortcuts
253
+ */
254
+ shortcutsNoMerge: typeof SymbolShortcutsNoMerge;
255
+ /**
256
+ * Prevent merging in rules
257
+ */
258
+ noMerge: typeof SymbolNoMerge;
259
+ /**
260
+ * Additional variants applied to this rule
261
+ */
262
+ variants: typeof SymbolVariants;
263
+ /**
264
+ * Parent selector (`@media`, `@supports`, etc.)
265
+ */
266
+ parent: typeof SymbolParent;
267
+ /**
268
+ * Selector modifier
269
+ */
270
+ selector: typeof SymbolSelector;
271
+ /**
272
+ * Layer modifier
273
+ */
274
+ layer: typeof SymbolLayer;
275
+ /**
276
+ * Sort modifier
277
+ */
278
+ sort: typeof SymbolSort;
279
+ /**
280
+ * Custom css body modifier
281
+ */
282
+ body: typeof SymbolBody;
283
+ }
284
+ interface ControlSymbolsValue {
285
+ [SymbolShortcutsNoMerge]: true;
286
+ [SymbolNoMerge]: true;
287
+ [SymbolVariants]: VariantHandler[] | ((handlers: VariantHandler[]) => VariantHandler[]);
288
+ [SymbolParent]: string;
289
+ [SymbolSelector]: (selector: string) => string;
290
+ [SymbolLayer]: string;
291
+ [SymbolSort]: number;
292
+ [SymbolBody]: string;
293
+ }
294
+ type ObjectToEntry<T> = { [K in keyof T]: [K, T[K]] }[keyof T];
295
+ type ControlSymbolsEntry = ObjectToEntry<ControlSymbolsValue>;
296
+ interface VariantContext<Theme extends object = object> {
297
+ /**
298
+ * Unprocessed selector from user input.
299
+ */
300
+ rawSelector: string;
301
+ /**
302
+ * UnoCSS generator instance
303
+ */
304
+ generator: UnoGenerator<Theme>;
305
+ /**
306
+ * The theme object
307
+ */
308
+ theme: Theme;
309
+ }
310
+ interface ExtractorContext {
311
+ readonly original: string;
312
+ code: string;
313
+ id?: string;
314
+ extracted: Set<string> | CountableSet<string>;
315
+ envMode?: 'dev' | 'build';
316
+ }
317
+ interface BaseContext<Theme extends object = object> {
318
+ /**
319
+ * UnoCSS generator instance
320
+ */
321
+ generator: UnoGenerator<Theme>;
322
+ /**
323
+ * The theme object
324
+ */
325
+ theme: Theme;
326
+ }
327
+ interface PreflightContext<Theme extends object = object> extends BaseContext<Theme> {}
328
+ interface SafeListContext<Theme extends object = object> extends BaseContext<Theme> {}
329
+ interface Extractor {
330
+ name: string;
331
+ order?: number;
332
+ /**
333
+ * Extract the code and return a list of selectors.
334
+ *
335
+ * Return `undefined` to skip this extractor.
336
+ */
337
+ extract?: (ctx: ExtractorContext) => Awaitable<Set<string> | CountableSet<string> | string[] | undefined | void>;
338
+ }
339
+ interface RuleMeta {
340
+ /**
341
+ * The layer name of this rule.
342
+ * @default 'default'
343
+ */
344
+ layer?: string;
345
+ /**
346
+ * Option to not merge this selector even if the body are the same.
347
+ * @default false
348
+ */
349
+ noMerge?: boolean;
350
+ /**
351
+ * Fine tune sort
352
+ */
353
+ sort?: number;
354
+ /**
355
+ * Templates to provide autocomplete suggestions
356
+ */
357
+ autocomplete?: Arrayable<AutoCompleteTemplate>;
358
+ /**
359
+ * Matching prefix before this util
360
+ */
361
+ prefix?: string | string[];
362
+ /**
363
+ * Internal rules will only be matched for shortcuts but not the user code.
364
+ * @default false
365
+ */
366
+ internal?: boolean;
367
+ /**
368
+ * Store the hash of the rule boy
369
+ *
370
+ * @internal
371
+ * @private
372
+ */
373
+ __hash?: string;
374
+ /**
375
+ * Internal index of the rulelist
376
+ * @internal
377
+ * @private
378
+ */
379
+ __index?: number;
380
+ /**
381
+ * Custom metadata
382
+ */
383
+ custom?: Record<string, any>;
384
+ }
385
+ type CSSValue = CSSObject | CSSEntries;
386
+ type DynamicMatcher<Theme extends object = object> = (match: RegExpMatchArray, context: Readonly<RuleContext<Theme>>) => Awaitable<CSSValueInput | string | (CSSValueInput | string)[] | undefined> | Generator<CSSValueInput | string | undefined> | AsyncGenerator<CSSValueInput | string | undefined>;
387
+ type DynamicRule<Theme extends object = object> = [RegExp, DynamicMatcher<Theme>, RuleMeta?];
388
+ type StaticRule = [string, CSSObject | CSSEntries | (CSSValueInput | string)[], RuleMeta?];
389
+ type Rule<Theme extends object = object> = DynamicRule<Theme> | StaticRule;
390
+ type DynamicShortcutMatcher<Theme extends object = object> = ((match: RegExpMatchArray, context: Readonly<RuleContext<Theme>>) => (string | ShortcutValue[] | undefined));
391
+ type StaticShortcut = [string, string | ShortcutValue[], RuleMeta?];
392
+ type StaticShortcutMap = Record<string, string | ShortcutValue[]>;
393
+ type DynamicShortcut<Theme extends object = object> = [RegExp, DynamicShortcutMatcher<Theme>, RuleMeta?];
394
+ type UserShortcuts<Theme extends object = object> = StaticShortcutMap | (StaticShortcut | DynamicShortcut<Theme> | StaticShortcutMap)[];
395
+ type Shortcut<Theme extends object = object> = StaticShortcut | DynamicShortcut<Theme>;
396
+ interface ShortcutInlineValue {
397
+ handles: VariantHandler[];
398
+ value: ShortcutValue;
399
+ }
400
+ type ShortcutValue = string | CSSValue;
401
+ type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null;
402
+ interface Preflight<Theme extends object = object> {
403
+ getCSS: (context: PreflightContext<Theme>) => Promise<string | undefined> | string | undefined;
404
+ layer?: string;
405
+ }
406
+ interface BlocklistMeta {
407
+ /**
408
+ * Custom message to show why this selector is blocked.
409
+ */
410
+ message?: string | ((selector: string) => string);
411
+ }
412
+ type BlocklistValue = string | RegExp | ((selector: string) => boolean | null | undefined);
413
+ type BlocklistRule = BlocklistValue | [BlocklistValue, BlocklistMeta];
414
+ interface VariantHandlerContext {
415
+ /**
416
+ * Rewrite the output selector. Often be used to append parents.
417
+ */
418
+ prefix: string;
419
+ /**
420
+ * Rewrite the output selector. Often be used to append pseudo classes.
421
+ */
422
+ selector: string;
423
+ /**
424
+ * Rewrite the output selector. Often be used to append pseudo elements.
425
+ */
426
+ pseudo: string;
427
+ /**
428
+ * Rewrite the output css body. The input come in [key,value][] pairs.
429
+ */
430
+ entries: CSSEntries;
431
+ /**
432
+ * Provide a parent selector(e.g. media query) to the output css.
433
+ */
434
+ parent?: string;
435
+ /**
436
+ * Provide order to the `parent` parent selector within layer.
437
+ */
438
+ parentOrder?: number;
439
+ /**
440
+ * Override layer to the output css.
441
+ */
442
+ layer?: string;
443
+ /**
444
+ * Order in which the variant is sorted within single rule.
445
+ */
446
+ sort?: number;
447
+ /**
448
+ * Option to not merge the resulting entries even if the body are the same.
449
+ * @default false
450
+ */
451
+ noMerge?: boolean;
452
+ }
453
+ interface VariantHandler {
454
+ /**
455
+ * Callback to process the handler.
456
+ */
457
+ handle?: (input: VariantHandlerContext, next: (input: VariantHandlerContext) => VariantHandlerContext) => VariantHandlerContext;
458
+ /**
459
+ * The result rewritten selector for the next round of matching
460
+ */
461
+ matcher?: string;
462
+ /**
463
+ * Order in which the variant is applied to selector.
464
+ */
465
+ order?: number;
466
+ /**
467
+ * Rewrite the output selector. Often be used to append pseudo classes or parents.
468
+ */
469
+ selector?: (input: string, body: CSSEntries) => string | undefined;
470
+ /**
471
+ * Rewrite the output css body. The input come in [key,value][] pairs.
472
+ */
473
+ body?: (body: CSSEntries) => CSSEntries | undefined;
474
+ /**
475
+ * Provide a parent selector(e.g. media query) to the output css.
476
+ */
477
+ parent?: string | [string, number] | undefined;
478
+ /**
479
+ * Order in which the variant is sorted within single rule.
480
+ */
481
+ sort?: number;
482
+ /**
483
+ * Override layer to the output css.
484
+ */
485
+ layer?: string | undefined;
486
+ }
487
+ type VariantFunction<Theme extends object = object> = (matcher: string, context: Readonly<VariantContext<Theme>>) => Awaitable<string | VariantHandler | VariantHandler[] | undefined>;
488
+ interface VariantObject<Theme extends object = object> {
489
+ /**
490
+ * The name of the variant.
491
+ */
492
+ name?: string;
493
+ /**
494
+ * The entry function to match and rewrite the selector for further processing.
495
+ */
496
+ match: VariantFunction<Theme>;
497
+ /**
498
+ * Sort for when the match is applied.
499
+ */
500
+ order?: number;
501
+ /**
502
+ * Allows this variant to be used more than once in matching a single rule
503
+ *
504
+ * @default false
505
+ */
506
+ multiPass?: boolean;
507
+ /**
508
+ * Custom function for auto complete
509
+ */
510
+ autocomplete?: Arrayable<AutoCompleteFunction | AutoCompleteTemplate>;
511
+ }
512
+ type Variant<Theme extends object = object> = VariantFunction<Theme> | VariantObject<Theme>;
513
+ type Preprocessor = (matcher: string) => string | undefined;
514
+ type Postprocessor = (util: UtilObject) => void | UtilObject | (UtilObject | null | undefined)[];
515
+ type ThemeExtender<Theme extends object = object> = (theme: Theme, config: Readonly<ResolvedConfig<Theme>>) => Theme | void;
516
+ interface ConfigBase<Theme extends object = object> {
517
+ /**
518
+ * Rules to generate CSS utilities.
519
+ *
520
+ * Later entries have higher priority.
521
+ */
522
+ rules?: Rule<Theme>[];
523
+ /**
524
+ * Variant separator
525
+ *
526
+ * @default [':', '-']
527
+ */
528
+ separators?: Arrayable<string>;
529
+ /**
530
+ * Variants that preprocess the selectors,
531
+ * having the ability to rewrite the CSS object.
532
+ */
533
+ variants?: Variant<Theme>[];
534
+ /**
535
+ * Similar to Windi CSS's shortcuts,
536
+ * allows you have create new utilities by combining existing ones.
537
+ *
538
+ * Later entries have higher priority.
539
+ */
540
+ shortcuts?: UserShortcuts<Theme>;
541
+ /**
542
+ * Rules to exclude the selectors for your design system (to narrow down the possibilities).
543
+ * Combining `warnExcluded` options it can also help you identify wrong usages.
544
+ */
545
+ blocklist?: BlocklistRule[];
546
+ /**
547
+ * Utilities that always been included
548
+ */
549
+ safelist?: (string | ((context: SafeListContext<Theme>) => Arrayable<string>))[];
550
+ /**
551
+ * Extractors to handle the source file and outputs possible classes/selectors
552
+ * Can be language-aware.
553
+ */
554
+ extractors?: Extractor[];
555
+ /**
556
+ * Default extractor that are always applied.
557
+ * By default it split the source code by whitespace and quotes.
558
+ *
559
+ * It maybe be replaced by preset or user config,
560
+ * only one default extractor can be presented,
561
+ * later one will override the previous one.
562
+ *
563
+ * Pass `null` or `false` to disable the default extractor.
564
+ *
565
+ * @see https://github.com/unocss/unocss/blob/main/packages-engine/core/src/extractors/split.ts
566
+ * @default import('@unocss/core').defaultExtractor
567
+ */
568
+ extractorDefault?: Extractor | null | false;
569
+ /**
570
+ * Raw CSS injections.
571
+ */
572
+ preflights?: Preflight<Theme>[];
573
+ /**
574
+ * Theme object for shared configuration between rules
575
+ */
576
+ theme?: Theme;
577
+ /**
578
+ * Layer orders. Default to 0.
579
+ */
580
+ layers?: Record<string, number>;
581
+ /**
582
+ * Output the internal layers as CSS Cascade Layers.
583
+ */
584
+ outputToCssLayers?: boolean | OutputCssLayersOptions;
585
+ /**
586
+ * Custom function to sort layers.
587
+ */
588
+ sortLayers?: (layers: string[]) => string[];
589
+ /**
590
+ * Preprocess the incoming utilities, return falsy value to exclude
591
+ */
592
+ preprocess?: Arrayable<Preprocessor>;
593
+ /**
594
+ * Postprocess the generate utils object
595
+ */
596
+ postprocess?: Arrayable<Postprocessor>;
597
+ /**
598
+ * Custom functions mutate the theme object.
599
+ *
600
+ * It's also possible to return a new theme object to completely replace the original one.
601
+ */
602
+ extendTheme?: Arrayable<ThemeExtender<Theme>>;
603
+ /**
604
+ * Presets
605
+ */
606
+ presets?: (PresetOrFactoryAwaitable<Theme> | PresetOrFactoryAwaitable<Theme>[])[];
607
+ /**
608
+ * Additional options for auto complete
609
+ */
610
+ autocomplete?: {
611
+ /**
612
+ * Custom functions / templates to provide autocomplete suggestions
613
+ */
614
+ templates?: Arrayable<AutoCompleteFunction | AutoCompleteTemplate>;
615
+ /**
616
+ * Custom extractors to pickup possible classes and
617
+ * transform class-name style suggestions to the correct format
618
+ */
619
+ extractors?: Arrayable<AutoCompleteExtractor>;
620
+ /**
621
+ * Custom shorthands to provide autocomplete suggestions.
622
+ * if values is an array, it will be joined with `|` and wrapped with `()`
623
+ */
624
+ shorthands?: Record<string, string | string[]>;
625
+ };
626
+ /**
627
+ * Hook to modify the resolved config.
628
+ *
629
+ * First presets runs first and the user config
630
+ */
631
+ configResolved?: (config: ResolvedConfig<Theme>) => void;
632
+ /**
633
+ * Expose internal details for debugging / inspecting
634
+ *
635
+ * Added `rules`, `shortcuts`, `variants` to the context and expose the context object in `StringifiedUtil`
636
+ *
637
+ * You don't usually need to set this.
638
+ *
639
+ * @default `true` when `envMode` is `dev`, otherwise `false`
640
+ */
641
+ details?: boolean;
642
+ /**
643
+ * Options for sources to be extracted as utilities usages.
644
+ *
645
+ */
646
+ content?: ContentOptions;
647
+ /**
648
+ * Custom transformers to the source code.
649
+ */
650
+ transformers?: SourceCodeTransformer[];
651
+ }
652
+ interface OutputCssLayersOptions {
653
+ /**
654
+ * Specify the css layer that the internal layer should be output to.
655
+ *
656
+ * Return `null` to specify that the layer should not be output to any css layer.
657
+ */
658
+ cssLayerName?: (internalLayer: string) => string | undefined | null;
659
+ }
660
+ type AutoCompleteTemplate = string;
661
+ type AutoCompleteFunction = (input: string) => Awaitable<string[]>;
662
+ interface AutoCompleteExtractorContext {
663
+ content: string;
664
+ cursor: number;
665
+ }
666
+ interface Replacement {
667
+ /**
668
+ * The range of the original text
669
+ */
670
+ start: number;
671
+ end: number;
672
+ /**
673
+ * The text used to replace
674
+ */
675
+ replacement: string;
676
+ }
677
+ interface AutoCompleteExtractorResult {
678
+ /**
679
+ * The extracted string
680
+ */
681
+ extracted: string;
682
+ /**
683
+ * The function to convert the selected suggestion back
684
+ */
685
+ resolveReplacement: (suggestion: string) => Replacement;
686
+ /**
687
+ * The function to format suggestions
688
+ */
689
+ transformSuggestions?: (suggestions: string[]) => string[];
690
+ }
691
+ interface AutoCompleteExtractor {
692
+ name: string;
693
+ extract: (context: AutoCompleteExtractorContext) => Awaitable<AutoCompleteExtractorResult | null>;
694
+ order?: number;
695
+ }
696
+ interface Preset<Theme extends object = object> extends ConfigBase<Theme> {
697
+ name: string;
698
+ /**
699
+ * Enforce the preset to be applied before or after other presets
700
+ */
701
+ enforce?: 'pre' | 'post';
702
+ /**
703
+ * Preset options for other tools like IDE to consume
704
+ */
705
+ options?: PresetOptions;
706
+ /**
707
+ * Apply prefix to all utilities and shortcuts
708
+ */
709
+ prefix?: string | string[];
710
+ /**
711
+ * Apply layer to all utilities and shortcuts
712
+ */
713
+ layer?: string;
714
+ /**
715
+ * Custom API endpoint for cross-preset communication
716
+ */
717
+ api?: any;
718
+ /**
719
+ * Custom metadata for the preset
720
+ */
721
+ meta?: Record<string, any>;
722
+ }
723
+ type PresetFactory<Theme extends object = object, PresetOptions$1 extends object | undefined = undefined> = (options?: PresetOptions$1) => Preset<Theme>;
724
+ type PresetFactoryAwaitable<Theme extends object = object, PresetOptions$1 extends object | undefined = undefined> = (options?: PresetOptions$1) => Awaitable<Preset<Theme>>;
725
+ type PresetOrFactory<Theme extends object = object> = Preset<Theme> | PresetFactory<Theme, any>;
726
+ type PresetOrFactoryAwaitable<Theme extends object = object> = PresetOrFactory<Theme> | Promise<Preset<Theme>> | PresetFactoryAwaitable<Theme>;
727
+ interface GeneratorOptions {
728
+ /**
729
+ * Merge utilities with the exact same body to save the file size
730
+ *
731
+ * @default true
732
+ */
733
+ mergeSelectors?: boolean;
734
+ /**
735
+ * Emit warning when matched selectors are presented in blocklist
736
+ *
737
+ * @default true
738
+ */
739
+ warn?: boolean;
740
+ }
741
+ interface UserOnlyOptions<Theme extends object = object> {
742
+ /**
743
+ * The theme object, will be merged with the theme provides by presets
744
+ */
745
+ theme?: Theme;
746
+ /**
747
+ * Layout name of shortcuts
748
+ *
749
+ * @default 'shortcuts'
750
+ */
751
+ shortcutsLayer?: string;
752
+ /**
753
+ * Environment mode
754
+ *
755
+ * @default 'build'
756
+ */
757
+ envMode?: 'dev' | 'build';
758
+ /**
759
+ * legacy.renderModernChunks need to be consistent with @vitejs/plugin-legacy
760
+ */
761
+ legacy?: {
762
+ renderModernChunks: boolean;
763
+ };
764
+ /**
765
+ * Custom prefix for virtual modules
766
+ *
767
+ * @default '__uno'
768
+ */
769
+ virtualModulePrefix?: string;
770
+ }
771
+ /**
772
+ * For unocss-cli config
773
+ */
774
+ interface CliOptions {
775
+ cli?: {
776
+ entry?: Arrayable<CliEntryItem>;
777
+ };
778
+ }
779
+ interface UnocssPluginContext<Config extends UserConfig = UserConfig> {
780
+ /**
781
+ * Singleton promise for config loading
782
+ */
783
+ ready: Promise<LoadConfigResult<Config>>;
784
+ /**
785
+ * The UnoCSS generator instance. Should be used after `ready` resolved.
786
+ */
787
+ uno: UnoGenerator;
788
+ /**
789
+ * All tokens scanned
790
+ */
791
+ tokens: Set<string>;
792
+ /**
793
+ * Map for all module's raw content
794
+ */
795
+ modules: BetterMap<string, string>;
796
+ /**
797
+ * Module IDs that been affected by UnoCSS
798
+ */
799
+ affectedModules: Set<string>;
800
+ /**
801
+ * Pending promises
802
+ */
803
+ tasks: Promise<any>[];
804
+ /**
805
+ * Await all pending tasks
806
+ */
807
+ flushTasks: () => Promise<any>;
808
+ filter: (code: string, id: string) => boolean;
809
+ extract: (code: string, id?: string) => Promise<void>;
810
+ reloadConfig: () => Promise<LoadConfigResult<Config>>;
811
+ getConfig: () => Promise<Config>;
812
+ onReload: (fn: () => void) => void;
813
+ invalidate: () => void;
814
+ onInvalidate: (fn: () => void) => void;
815
+ root: string;
816
+ updateRoot: (root: string) => Promise<LoadConfigResult<Config>>;
817
+ getConfigFileList: () => string[];
818
+ /**
819
+ * Get regexes to match virtual module ids
820
+ */
821
+ getVMPRegexes: () => Promise<{
822
+ prefix: string;
823
+ RESOLVED_ID_WITH_QUERY_RE: RegExp;
824
+ RESOLVED_ID_RE: RegExp;
825
+ }>;
826
+ }
827
+ interface HighlightAnnotation {
828
+ offset: number;
829
+ length: number;
830
+ className: string;
831
+ }
832
+ type SourceCodeTransformerEnforce = 'pre' | 'post' | 'default';
833
+ interface SourceCodeTransformer {
834
+ name: string;
835
+ /**
836
+ * The order of transformer
837
+ */
838
+ enforce?: SourceCodeTransformerEnforce;
839
+ /**
840
+ * Custom id filter, if not provided, the extraction filter will be applied
841
+ */
842
+ idFilter?: (id: string) => boolean;
843
+ /**
844
+ * The transform function
845
+ */
846
+ transform: (code: MagicString, id: string, ctx: UnocssPluginContext) => Awaitable<{
847
+ highlightAnnotations?: HighlightAnnotation[];
848
+ } | void>;
849
+ }
850
+ interface ContentOptions {
851
+ /**
852
+ * Glob patterns to extract from the file system, in addition to other content sources.
853
+ *
854
+ * In dev mode, the files will be watched and trigger HMR.
855
+ *
856
+ * @default []
857
+ */
858
+ filesystem?: string[];
859
+ /**
860
+ * Inline text to be extracted
861
+ */
862
+ inline?: (string | {
863
+ code: string;
864
+ id?: string;
865
+ } | (() => Awaitable<string | {
866
+ code: string;
867
+ id?: string;
868
+ }>))[];
869
+ /**
870
+ * Filters to determine whether to extract certain modules from the build tools' transformation pipeline.
871
+ *
872
+ * Currently only works for Vite and Webpack integration.
873
+ *
874
+ * Set `false` to disable.
875
+ */
876
+ pipeline?: false | {
877
+ /**
878
+ * Patterns that filter the files being extracted.
879
+ * Supports regular expressions and `picomatch` glob patterns.
880
+ *
881
+ * By default, `.ts` and `.js` files are NOT extracted.
882
+ *
883
+ * @see https://www.npmjs.com/package/picomatch
884
+ * @default [/\.(vue|svelte|[jt]sx|vine.ts|mdx?|astro|elm|php|phtml|marko|html)($|\?)/]
885
+ */
886
+ include?: FilterPattern;
887
+ /**
888
+ * Patterns that filter the files NOT being extracted.
889
+ * Supports regular expressions and `picomatch` glob patterns.
890
+ *
891
+ * By default, `node_modules` and `dist` are also extracted.
892
+ *
893
+ * @see https://www.npmjs.com/package/picomatch
894
+ * @default [/\.(css|postcss|sass|scss|less|stylus|styl)($|\?)/]
895
+ */
896
+ exclude?: FilterPattern;
897
+ };
898
+ }
899
+ /**
900
+ * For other modules to aggregate the options
901
+ */
902
+ interface PluginOptions {
903
+ /**
904
+ * Load from configs files
905
+ *
906
+ * set `false` to disable
907
+ */
908
+ configFile?: string | false;
909
+ /**
910
+ * List of files that will also trigger config reloads
911
+ */
912
+ configDeps?: string[];
913
+ /**
914
+ * Custom transformers to the source code
915
+ */
916
+ transformers?: SourceCodeTransformer[];
917
+ /**
918
+ * Options for sources to be extracted as utilities usages
919
+ *
920
+ * Supported sources:
921
+ * - `filesystem` - extract from file system
922
+ * - `inline` - extract from plain inline text
923
+ * - `pipeline` - extract from build tools' transformation pipeline, such as Vite and Webpack
924
+ *
925
+ * The usage extracted from each source will be **merged** together.
926
+ */
927
+ content?: ContentOptions;
928
+ }
929
+ interface UserConfig<Theme extends object = object> extends ConfigBase<Theme>, UserOnlyOptions<Theme>, GeneratorOptions, PluginOptions, CliOptions {}
930
+ interface UserConfigDefaults<Theme extends object = object> extends ConfigBase<Theme>, UserOnlyOptions<Theme> {}
931
+ interface ResolvedConfig<Theme extends object = object> extends Omit<RequiredByKey<UserConfig<Theme>, 'mergeSelectors' | 'theme' | 'rules' | 'variants' | 'layers' | 'extractors' | 'blocklist' | 'safelist' | 'preflights' | 'sortLayers'>, 'rules' | 'shortcuts' | 'autocomplete' | 'presets'> {
932
+ presets: Preset<Theme>[];
933
+ shortcuts: Shortcut<Theme>[];
934
+ variants: VariantObject<Theme>[];
935
+ preprocess: Preprocessor[];
936
+ postprocess: Postprocessor[];
937
+ rulesSize: number;
938
+ rules: readonly Rule<Theme>[];
939
+ rulesDynamic: readonly DynamicRule<Theme>[];
940
+ rulesStaticMap: Record<string, StaticRule | undefined>;
941
+ autocomplete: {
942
+ templates: (AutoCompleteFunction | AutoCompleteTemplate)[];
943
+ extractors: AutoCompleteExtractor[];
944
+ shorthands: Record<string, string>;
945
+ };
946
+ separators: string[];
947
+ }
948
+ interface GenerateResult<T = Set<string>> {
949
+ css: string;
950
+ layers: string[];
951
+ getLayer: (name?: string) => string | undefined;
952
+ getLayers: (includes?: string[], excludes?: string[]) => string;
953
+ setLayer: (layer: string, callback: (content: string) => Promise<string>) => Promise<string>;
954
+ matched: T;
955
+ }
956
+ type VariantMatchedResult<Theme extends object = object> = [raw: string, current: string, variantHandlers: VariantHandler[], variants: Set<Variant<Theme>>];
957
+ type ParsedUtil = readonly [index: number, raw: string, entries: CSSEntries, meta: RuleMeta | undefined, variantHandlers: VariantHandler[]];
958
+ type RawUtil = readonly [index: number, rawCSS: string, meta: RuleMeta | undefined];
959
+ type StringifiedUtil<Theme extends object = object> = readonly [index: number, selector: string | undefined, body: string, parent: string | undefined, meta: RuleMeta | undefined, context: RuleContext<Theme> | undefined, noMerge: boolean | undefined];
960
+ interface CliEntryItem {
961
+ patterns: string[];
962
+ outFile: string;
963
+ }
964
+ interface UtilObject {
965
+ selector: string;
966
+ entries: CSSEntries;
967
+ parent: string | undefined;
968
+ layer: string | undefined;
969
+ sort: number | undefined;
970
+ noMerge: boolean | undefined;
971
+ }
972
+ /**
973
+ * Returned from `uno.generate()` when `extendedInfo` option is enabled.
974
+ */
975
+ interface ExtendedTokenInfo<Theme extends object = object> {
976
+ /**
977
+ * Stringified util data
978
+ */
979
+ data: StringifiedUtil<Theme>[];
980
+ /**
981
+ * Return -1 if the data structure is not countable
982
+ */
983
+ count: number;
984
+ }
985
+ interface GenerateOptions<T extends boolean> {
986
+ /**
987
+ * Filepath of the file being processed.
988
+ */
989
+ id?: string;
990
+ /**
991
+ * Generate preflights (if defined)
992
+ *
993
+ * @default true
994
+ */
995
+ preflights?: boolean;
996
+ /**
997
+ * Includes safelist
998
+ */
999
+ safelist?: boolean;
1000
+ /**
1001
+ * Generate minified CSS
1002
+ * @default false
1003
+ */
1004
+ minify?: boolean;
1005
+ /**
1006
+ * @experimental
1007
+ */
1008
+ scope?: string;
1009
+ /**
1010
+ * If return extended "matched" with payload and count
1011
+ */
1012
+ extendedInfo?: T;
1013
+ }
1014
+ //#endregion
1015
+ //#region src/utilities.d.ts
67
1016
  declare function getBracket(str: string, open: string, close: string): string[] | undefined;
68
1017
  declare function getStringComponent(str: string, open: string, close: string, separators: string | string[]): string[] | undefined;
69
1018
  declare function getStringComponents(str: string, separators: string | string[], limit?: number, open?: string, close?: string): string[] | undefined;
70
-
1019
+ //#endregion
1020
+ //#region src/variants.d.ts
71
1021
  declare function variantMatcher<T extends object = object>(name: string, handler: Arrayable<(input: VariantHandlerContext) => Record<string, any>>, options?: Omit<VariantObject<T>, 'match'>): VariantObject<T>;
72
1022
  declare function variantParentMatcher<T extends object = object>(name: string, parent: string): VariantObject<T>;
73
1023
  declare function variantGetBracket(prefix: string, matcher: string, separators: string[]): string[] | undefined;
74
1024
  declare function variantGetParameter(prefix: Arrayable<string>, matcher: string, separators: string[]): string[] | undefined;
75
-
1025
+ //#endregion
1026
+ //#region src/pseudo.d.ts
76
1027
  /**
77
1028
  * Note: the order of following pseudo classes will affect the order of generated css.
78
1029
  *
@@ -92,29 +1043,28 @@ declare const excludedPseudo: string[];
92
1043
  declare const PseudoClassesAndElementsStr: string;
93
1044
  declare const PseudoClassesAndElementsColonStr: string;
94
1045
  interface PseudoVariantOptions {
95
- /**
96
- * Generate tagged pseudo selector as `[group=""]` instead of `.group`
97
- *
98
- * @default false
99
- */
100
- attributifyPseudo?: boolean;
101
- /**
102
- * Utils prefix
103
- */
104
- prefix?: string | string[];
1046
+ /**
1047
+ * Generate tagged pseudo selector as `[group=""]` instead of `.group`
1048
+ *
1049
+ * @default false
1050
+ */
1051
+ attributifyPseudo?: boolean;
1052
+ /**
1053
+ * Utils prefix
1054
+ */
1055
+ prefix?: string | string[];
105
1056
  }
106
1057
  interface PseudoVariantUtilities<Theme extends object = object> {
107
- getBracket: typeof getBracket;
108
- h: {
109
- bracket: (s: string, theme?: Theme) => string | undefined;
110
- };
111
- variantGetBracket: typeof variantGetBracket;
1058
+ getBracket: typeof getBracket;
1059
+ h: {
1060
+ bracket: (s: string, theme?: Theme) => string | undefined;
1061
+ };
1062
+ variantGetBracket: typeof variantGetBracket;
112
1063
  }
113
1064
  declare function createTaggedPseudoClassMatcher<T extends object = object>(tag: string, parent: string, combinator: string, utils: PseudoVariantUtilities): VariantObject<T>;
114
1065
  declare function createPseudoClassesAndElements<T extends object = object>(utils: PseudoVariantUtilities): VariantObject<T>[];
115
1066
  declare function createPseudoClassFunctions<T extends object = object>(utils: PseudoVariantUtilities): VariantObject<T>;
116
1067
  declare function createTaggedPseudoClasses<T extends object = object>(options: PseudoVariantOptions, utils: PseudoVariantUtilities): VariantObject<T>[];
117
1068
  declare function createPartClasses<T extends object = object>(): VariantObject<T>;
118
-
119
- export { PseudoClassFunctions, PseudoClassFunctionsStr, PseudoClasses, PseudoClassesAndElementsColonStr, PseudoClassesAndElementsStr, PseudoClassesColon, PseudoClassesColonKeys, PseudoClassesColonStr, PseudoClassesKeys, PseudoClassesMulti, PseudoClassesMultiStr, PseudoClassesStr, alphaPlaceholders, alphaPlaceholdersRE, calcMaxWidthBySize, colorOpacityToString, colorToString, createPartClasses, createPseudoClassFunctions, createPseudoClassesAndElements, createTaggedPseudoClassMatcher, createTaggedPseudoClasses, createValueHandler, cssColorFunctions, excludedPseudo, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, hueInterpolationMethods, iconFnRE, isInterpolatedMethod, parseCssColor, polarColorSpace, rectangularColorSpace, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };
120
- export type { CSSColorValue, ParsedColorValue, PseudoVariantOptions, PseudoVariantUtilities, RGBAColorValue, ValueHandler, ValueHandlerCallback };
1069
+ //#endregion
1070
+ export { CSSColorValue, ParsedColorValue, PseudoClassFunctions, PseudoClassFunctionsStr, PseudoClasses, PseudoClassesAndElementsColonStr, PseudoClassesAndElementsStr, PseudoClassesColon, PseudoClassesColonKeys, PseudoClassesColonStr, PseudoClassesKeys, PseudoClassesMulti, PseudoClassesMultiStr, PseudoClassesStr, PseudoVariantOptions, PseudoVariantUtilities, RGBAColorValue, ValueHandler, ValueHandlerCallback, alphaPlaceholders, alphaPlaceholdersRE, calcMaxWidthBySize, colorOpacityToString, colorToString, createPartClasses, createPseudoClassFunctions, createPseudoClassesAndElements, createTaggedPseudoClassMatcher, createTaggedPseudoClasses, createValueHandler, cssColorFunctions, excludedPseudo, getBracket, getStringComponent, getStringComponents, hasIconFn, hasThemeFn, hex2rgba, hueInterpolationMethods, iconFnRE, isInterpolatedMethod, parseCssColor, polarColorSpace, rectangularColorSpace, themeFnRE, transformThemeFn, transformThemeString, variantGetBracket, variantGetParameter, variantMatcher, variantParentMatcher };