@unocss/core 0.1.0-beta.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.
- package/LICENSE +21 -0
- package/README.md +18 -0
- package/dist/index.d.ts +219 -0
- package/dist/index.js +698 -0
- package/dist/index.mjs +661 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @unocss/core
|
|
2
|
+
|
|
3
|
+
The core engine of [UnoCSS](https://github.com/antfu/unocss) without any presets. Can be used as the engine of your own atomic-css framework.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createGenerator } from '@unocss/core'
|
|
9
|
+
|
|
10
|
+
const generator = createGenerator({ /* user options */ }, { /* default options */ })
|
|
11
|
+
|
|
12
|
+
const { css } = await generator.generate(code)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
|
|
17
|
+
MIT License © 2021-PRESENT [Anthony Fu](https://github.com/antfu)
|
|
18
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
declare type Awaitable<T> = T | Promise<T>;
|
|
2
|
+
declare type ArgumentType<T> = T extends ((...args: infer A) => any) ? A : never;
|
|
3
|
+
declare type Shift<T> = T extends [_: any, ...args: infer A] ? A : never;
|
|
4
|
+
declare type RestArgs<T> = Shift<ArgumentType<T>>;
|
|
5
|
+
declare type DeepPartial<T> = {
|
|
6
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
7
|
+
};
|
|
8
|
+
declare type CSSObject = Record<string, string | number | undefined>;
|
|
9
|
+
declare type CSSEntries = [string, string | number | undefined][];
|
|
10
|
+
declare type Extractor = (code: string, id?: string) => Awaitable<Set<string> | undefined>;
|
|
11
|
+
declare type DynamicRule = [RegExp, ((match: string[], theme: Theme) => Awaitable<CSSObject | CSSEntries | undefined>)];
|
|
12
|
+
declare type StaticRule = [string, CSSObject | CSSEntries];
|
|
13
|
+
declare type Rule = DynamicRule | StaticRule;
|
|
14
|
+
declare type DynamicShortcut = [RegExp, ((match: string[]) => (string | string[] | undefined))];
|
|
15
|
+
declare type StaticShortcut = [string, string | string[]];
|
|
16
|
+
declare type StaticShortcutMap = Record<string, string | string[]>;
|
|
17
|
+
declare type UserShortcuts = StaticShortcutMap | (StaticShortcut | DynamicShortcut | StaticShortcutMap)[];
|
|
18
|
+
declare type Shortcut = StaticShortcut | DynamicShortcut;
|
|
19
|
+
declare type ExcludeRule = string | RegExp;
|
|
20
|
+
declare type Variant = {
|
|
21
|
+
match: (input: string, theme: Theme) => string | undefined;
|
|
22
|
+
selector?: (input: string, theme: Theme) => string | undefined;
|
|
23
|
+
rewrite?: (input: CSSEntries, theme: Theme) => CSSEntries | undefined;
|
|
24
|
+
mediaQuery?: (selector: string, theme: Theme) => string | undefined;
|
|
25
|
+
};
|
|
26
|
+
interface Theme {
|
|
27
|
+
borderRadius?: Record<string, string>;
|
|
28
|
+
breakpoints?: Record<string, string>;
|
|
29
|
+
colors?: Record<string, string | Record<string, string>>;
|
|
30
|
+
fontFamily?: Record<string, string>;
|
|
31
|
+
fontSize?: Record<string, [string, string]>;
|
|
32
|
+
lineHeight?: Record<string, string>;
|
|
33
|
+
letterSpacing?: Record<string, string>;
|
|
34
|
+
}
|
|
35
|
+
interface ConfigBase {
|
|
36
|
+
/**
|
|
37
|
+
* Rules to generate CSS utilities
|
|
38
|
+
*/
|
|
39
|
+
rules?: Rule[];
|
|
40
|
+
/**
|
|
41
|
+
* Variants that preprocess the selectors,
|
|
42
|
+
* having the ability to rewrite the CSS object.
|
|
43
|
+
*/
|
|
44
|
+
variants?: Variant[];
|
|
45
|
+
/**
|
|
46
|
+
* Similar to Windi CSS's shortcuts,
|
|
47
|
+
* allows you have create new utilities by combining existing ones.
|
|
48
|
+
*/
|
|
49
|
+
shortcuts?: UserShortcuts;
|
|
50
|
+
/**
|
|
51
|
+
* Rules to exclude the selectors for your design system (to narrow down the possibilities).
|
|
52
|
+
* Combining `warnExcluded` options it can also helps you identify wrong usages.
|
|
53
|
+
*/
|
|
54
|
+
excluded?: ExcludeRule[];
|
|
55
|
+
/**
|
|
56
|
+
* Extractors to handle the source file and outputs possible classes/selectors
|
|
57
|
+
* Can be language-aware.
|
|
58
|
+
*/
|
|
59
|
+
extractors?: Extractor[];
|
|
60
|
+
/**
|
|
61
|
+
* Theme object for shared configuration between rules
|
|
62
|
+
*/
|
|
63
|
+
theme?: Theme;
|
|
64
|
+
}
|
|
65
|
+
interface Preset extends ConfigBase {
|
|
66
|
+
enforce?: 'pre' | 'post';
|
|
67
|
+
}
|
|
68
|
+
interface GeneratorOptions {
|
|
69
|
+
/**
|
|
70
|
+
* Merge utilities with the exact same body to save the file size
|
|
71
|
+
*
|
|
72
|
+
* @default true
|
|
73
|
+
*/
|
|
74
|
+
mergeSelectors?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Emit warning when excluded selectors are found
|
|
77
|
+
*
|
|
78
|
+
* @default true
|
|
79
|
+
*/
|
|
80
|
+
warnExcluded?: boolean;
|
|
81
|
+
}
|
|
82
|
+
interface UserConfig extends ConfigBase, GeneratorOptions {
|
|
83
|
+
theme?: Theme;
|
|
84
|
+
presets?: Preset[];
|
|
85
|
+
}
|
|
86
|
+
interface UserConfigDefaults extends ConfigBase {
|
|
87
|
+
theme?: Theme;
|
|
88
|
+
presets?: Preset[];
|
|
89
|
+
}
|
|
90
|
+
interface ResolvedConfig extends Omit<Required<UserConfig>, 'presets' | 'rules' | 'shortcuts'> {
|
|
91
|
+
shortcuts: Shortcut[];
|
|
92
|
+
rulesSize: number;
|
|
93
|
+
rulesDynamic: (DynamicRule | undefined)[];
|
|
94
|
+
rulesStaticMap: Record<string, [number, CSSObject | CSSEntries] | undefined>;
|
|
95
|
+
}
|
|
96
|
+
interface GenerateResult {
|
|
97
|
+
css: string;
|
|
98
|
+
matched: Set<string>;
|
|
99
|
+
}
|
|
100
|
+
declare type VariantMatchedResult = readonly [
|
|
101
|
+
string,
|
|
102
|
+
string,
|
|
103
|
+
Variant[]
|
|
104
|
+
];
|
|
105
|
+
declare type ParsedUtil = readonly [
|
|
106
|
+
number,
|
|
107
|
+
string,
|
|
108
|
+
CSSEntries,
|
|
109
|
+
Variant[]
|
|
110
|
+
];
|
|
111
|
+
declare type StringifiedUtil = readonly [
|
|
112
|
+
number,
|
|
113
|
+
string,
|
|
114
|
+
string,
|
|
115
|
+
string | undefined
|
|
116
|
+
];
|
|
117
|
+
declare function defineConfig(config: UserConfig): UserConfig;
|
|
118
|
+
|
|
119
|
+
declare function escapeRegExp(string: string): string;
|
|
120
|
+
/**
|
|
121
|
+
* CSS Selector Escape
|
|
122
|
+
*/
|
|
123
|
+
declare function escapeSelector(str: string): string;
|
|
124
|
+
declare const e: typeof escapeSelector;
|
|
125
|
+
|
|
126
|
+
declare function entriesToCss(arr?: CSSEntries): string;
|
|
127
|
+
declare function isObject(item: any): item is Record<string, any>;
|
|
128
|
+
declare function mergeDeep<T>(original: T, patch: DeepPartial<T>): T;
|
|
129
|
+
declare function isStaticRule(rule: Rule): rule is StaticRule;
|
|
130
|
+
declare function isStaticShortcut(sc: Shortcut): sc is StaticShortcut;
|
|
131
|
+
|
|
132
|
+
declare function toArray<T>(value?: T | T[]): T[];
|
|
133
|
+
declare function uniq<T>(value: T[]): T[];
|
|
134
|
+
declare function mergeSet<T>(target: Set<T>, append: Set<T>): Set<T>;
|
|
135
|
+
|
|
136
|
+
declare const variantMatcher: (name: string) => (input: string) => string | undefined;
|
|
137
|
+
|
|
138
|
+
declare function size(str: string): string | undefined;
|
|
139
|
+
declare function border(str: string): string | undefined;
|
|
140
|
+
declare function number(str: string): number | undefined;
|
|
141
|
+
declare function percent(str: string): string | undefined;
|
|
142
|
+
declare function fraction(str: string): string | undefined;
|
|
143
|
+
declare function bracket(str: string): string | undefined;
|
|
144
|
+
|
|
145
|
+
declare const handlers_size: typeof size;
|
|
146
|
+
declare const handlers_border: typeof border;
|
|
147
|
+
declare const handlers_number: typeof number;
|
|
148
|
+
declare const handlers_percent: typeof percent;
|
|
149
|
+
declare const handlers_fraction: typeof fraction;
|
|
150
|
+
declare const handlers_bracket: typeof bracket;
|
|
151
|
+
declare namespace handlers {
|
|
152
|
+
export {
|
|
153
|
+
handlers_size as size,
|
|
154
|
+
handlers_border as border,
|
|
155
|
+
handlers_number as number,
|
|
156
|
+
handlers_percent as percent,
|
|
157
|
+
handlers_fraction as fraction,
|
|
158
|
+
handlers_bracket as bracket,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
declare type HandlerName = keyof typeof handlers;
|
|
163
|
+
declare const handlersNames: ("number" | "size" | "border" | "percent" | "fraction" | "bracket")[];
|
|
164
|
+
declare type Handler = {
|
|
165
|
+
[K in HandlerName]: Handler;
|
|
166
|
+
} & {
|
|
167
|
+
(str: string): string | undefined;
|
|
168
|
+
__options: {
|
|
169
|
+
sequence: HandlerName[];
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
declare const handler: Handler;
|
|
173
|
+
|
|
174
|
+
declare function hex2rgba(hex: string): [number, number, number, number] | [number, number, number] | undefined;
|
|
175
|
+
|
|
176
|
+
declare function getMatchedPositions(code: string, matched: Set<string>): [number, number][];
|
|
177
|
+
|
|
178
|
+
declare const attributifyRE: RegExp;
|
|
179
|
+
declare const validateFilterRE: RegExp;
|
|
180
|
+
declare function isAttributifySelector(selector: string): RegExpMatchArray | null;
|
|
181
|
+
declare function isValidSelector(selector?: string): selector is string;
|
|
182
|
+
|
|
183
|
+
declare class TwoKeyMap<K1, K2, V> {
|
|
184
|
+
_map: Map<K1, Map<K2, V>>;
|
|
185
|
+
get(key1: K1, key2: K2): V | undefined;
|
|
186
|
+
getFallback(key1: K1, key2: K2, fallback: V): V;
|
|
187
|
+
set(key1: K1, key2: K2, value: V): this;
|
|
188
|
+
has(key1: K1, key2: K2): boolean | undefined;
|
|
189
|
+
delete(key1: K1, key2: K2): boolean;
|
|
190
|
+
deleteTop(key1: K1): boolean;
|
|
191
|
+
map<T>(fn: (v: V, k1: K1, k2: K2) => T): T[];
|
|
192
|
+
}
|
|
193
|
+
declare class BetterMap<K, V> extends Map<K, V> {
|
|
194
|
+
map<R>(mapFn: (value: V, key: K) => R): R[];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
declare const extractorSplit: Extractor;
|
|
198
|
+
|
|
199
|
+
declare class UnoGenerator {
|
|
200
|
+
userConfig: UserConfig;
|
|
201
|
+
defaults: UserConfigDefaults;
|
|
202
|
+
private _cache;
|
|
203
|
+
config: ResolvedConfig;
|
|
204
|
+
excluded: Set<string>;
|
|
205
|
+
constructor(userConfig?: UserConfig, defaults?: UserConfigDefaults);
|
|
206
|
+
setConfig(userConfig?: UserConfig, defaults?: UserConfigDefaults): void;
|
|
207
|
+
applyExtractors(code: string, id?: string, set?: Set<string>): Promise<Set<string>>;
|
|
208
|
+
generate(input: string | Set<string>, id?: string, scope?: string): Promise<GenerateResult>;
|
|
209
|
+
matchVariants(raw: string): VariantMatchedResult;
|
|
210
|
+
applyVariants(parsed: ParsedUtil, variants?: Variant[], raw?: string): readonly [string, CSSEntries, string | undefined];
|
|
211
|
+
parseUtil(input: string | VariantMatchedResult): Promise<ParsedUtil | undefined>;
|
|
212
|
+
stringifyUtil(parsed?: ParsedUtil): StringifiedUtil | undefined;
|
|
213
|
+
expandShortcut(processed: string): string[] | undefined;
|
|
214
|
+
stringifyShortcuts(parent: VariantMatchedResult, expanded: string[]): Promise<StringifiedUtil[]>;
|
|
215
|
+
isExcluded(raw: string): boolean;
|
|
216
|
+
}
|
|
217
|
+
declare function createGenerator(config?: UserConfig, defaults?: UserConfigDefaults): UnoGenerator;
|
|
218
|
+
|
|
219
|
+
export { ArgumentType, Awaitable, BetterMap, CSSEntries, CSSObject, ConfigBase, DeepPartial, DynamicRule, DynamicShortcut, ExcludeRule, Extractor, GenerateResult, GeneratorOptions, Handler, HandlerName, ParsedUtil, Preset, ResolvedConfig, RestArgs, Rule, Shift, Shortcut, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, Theme, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserShortcuts, Variant, VariantMatchedResult, attributifyRE, border, bracket, createGenerator, defineConfig, e, entriesToCss, escapeRegExp, escapeSelector, extractorSplit, fraction, getMatchedPositions, handler, handlersNames, hex2rgba, isAttributifySelector, isObject, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, number, percent, size, toArray, uniq, validateFilterRE, variantMatcher };
|