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