@unocss/core 66.5.10 → 66.5.11

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