@unocss/postcss 66.5.11 → 66.6.0-beta.1

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