@unocss/core 0.55.1 → 0.55.2

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