@unocss/core 0.5.1 → 0.6.0
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 +34 -7
- package/dist/index.js +28 -8
- package/dist/index.mjs +28 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ declare class UnoGenerator {
|
|
|
14
14
|
parseUtil(input: string | VariantMatchedResult): Promise<ParsedUtil | RawUtil | undefined>;
|
|
15
15
|
stringifyUtil(parsed?: ParsedUtil | RawUtil): StringifiedUtil | undefined;
|
|
16
16
|
expandShortcut(processed: string, depth?: number): [string[], RuleMeta | undefined] | undefined;
|
|
17
|
-
stringifyShortcuts(parent: VariantMatchedResult, expanded: string[], meta
|
|
17
|
+
stringifyShortcuts(parent: VariantMatchedResult, expanded: string[], meta?: RuleMeta): Promise<StringifiedUtil[] | undefined>;
|
|
18
18
|
isExcluded(raw: string): boolean;
|
|
19
19
|
}
|
|
20
20
|
declare function createGenerator(config?: UserConfig, defaults?: UserConfigDefaults): UnoGenerator;
|
|
@@ -57,7 +57,16 @@ interface RuleContext<Theme extends {} = {}> {
|
|
|
57
57
|
*/
|
|
58
58
|
constructCSS: (body: CSSEntries | CSSObject, overrideSelector?: string) => string;
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
interface ExtractorContext {
|
|
61
|
+
readonly original: string;
|
|
62
|
+
code: string;
|
|
63
|
+
id?: string;
|
|
64
|
+
}
|
|
65
|
+
interface Extractor {
|
|
66
|
+
name: string;
|
|
67
|
+
extract(ctx: ExtractorContext): Awaitable<Set<string> | undefined>;
|
|
68
|
+
order?: number;
|
|
69
|
+
}
|
|
61
70
|
interface RuleMeta {
|
|
62
71
|
layer?: string;
|
|
63
72
|
}
|
|
@@ -167,13 +176,31 @@ interface GeneratorOptions {
|
|
|
167
176
|
*/
|
|
168
177
|
warnExcluded?: boolean;
|
|
169
178
|
}
|
|
170
|
-
interface
|
|
179
|
+
interface UserOnlyOptions<Theme extends {} = {}> {
|
|
180
|
+
/**
|
|
181
|
+
* The theme object, will be merged with the theme provides by presets
|
|
182
|
+
*/
|
|
171
183
|
theme?: Theme;
|
|
184
|
+
/**
|
|
185
|
+
* Layout name of shortcuts
|
|
186
|
+
*
|
|
187
|
+
* @default 'shortcuts'
|
|
188
|
+
*/
|
|
189
|
+
shortcutsLayer?: string;
|
|
190
|
+
/**
|
|
191
|
+
* Presets
|
|
192
|
+
*/
|
|
172
193
|
presets?: Preset[];
|
|
194
|
+
/**
|
|
195
|
+
* Environment mode
|
|
196
|
+
*
|
|
197
|
+
* @default 'build'
|
|
198
|
+
*/
|
|
199
|
+
envMode?: 'dev' | 'build';
|
|
173
200
|
}
|
|
174
|
-
interface
|
|
175
|
-
|
|
176
|
-
|
|
201
|
+
interface UserConfig<Theme extends {} = {}> extends ConfigBase<Theme>, UserOnlyOptions<Theme>, GeneratorOptions {
|
|
202
|
+
}
|
|
203
|
+
interface UserConfigDefaults<Theme extends {} = {}> extends ConfigBase<Theme>, UserOnlyOptions<Theme> {
|
|
177
204
|
}
|
|
178
205
|
interface ResolvedConfig extends Omit<Required<UserConfig>, 'presets' | 'rules' | 'shortcuts'> {
|
|
179
206
|
shortcuts: Shortcut[];
|
|
@@ -280,4 +307,4 @@ declare function withLayer<T>(layer: string, rules: Rule<T>[]): Rule<T>[];
|
|
|
280
307
|
|
|
281
308
|
declare const extractorSplit: Extractor;
|
|
282
309
|
|
|
283
|
-
export { ArgumentType, Awaitable, BetterMap, CSSEntries, CSSObject, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, ExcludeRule, Extractor, GenerateOptions, GenerateResult, GeneratorOptions, ParsedUtil, Preflight, Preset, RawUtil, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserShortcuts, Variant, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, createGenerator, e, entriesToCss, escapeRegExp, escapeSelector, extractorSplit, hasScopePlaceholder, hex2rgba, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeVariant, toArray, uniq, validateFilterRE, withLayer };
|
|
310
|
+
export { ArgumentType, Awaitable, BetterMap, CSSEntries, CSSObject, ConfigBase, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, ExcludeRule, Extractor, ExtractorContext, GenerateOptions, GenerateResult, GeneratorOptions, ParsedUtil, Preflight, Preset, RawUtil, ResolvedConfig, RestArgs, Rule, RuleContext, RuleMeta, Shift, Shortcut, StaticRule, StaticShortcut, StaticShortcutMap, StringifiedUtil, TwoKeyMap, UnoGenerator, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, Variant, VariantFunction, VariantHandler, VariantMatchedResult, VariantObject, attributifyRE, createGenerator, e, entriesToCss, escapeRegExp, escapeSelector, extractorSplit, hasScopePlaceholder, hex2rgba, isAttributifySelector, isObject, isRawUtil, isStaticRule, isStaticShortcut, isValidSelector, mergeDeep, mergeSet, normalizeVariant, toArray, uniq, validateFilterRE, withLayer };
|
package/dist/index.js
CHANGED
|
@@ -230,7 +230,13 @@ function withLayer(layer, rules) {
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
// src/extractors/split.ts
|
|
233
|
-
var extractorSplit =
|
|
233
|
+
var extractorSplit = {
|
|
234
|
+
name: "split",
|
|
235
|
+
order: 0,
|
|
236
|
+
extract({ code }) {
|
|
237
|
+
return new Set(code.split(/[\s'"`;>=]+/g).filter(isValidSelector));
|
|
238
|
+
}
|
|
239
|
+
};
|
|
234
240
|
|
|
235
241
|
// src/config.ts
|
|
236
242
|
function resolveShortcuts(shortcuts) {
|
|
@@ -240,6 +246,10 @@ function resolveShortcuts(shortcuts) {
|
|
|
240
246
|
return Object.entries(s);
|
|
241
247
|
});
|
|
242
248
|
}
|
|
249
|
+
var defaultLayers = {
|
|
250
|
+
shortcuts: -1,
|
|
251
|
+
default: 0
|
|
252
|
+
};
|
|
243
253
|
function resolveConfig(userConfig = {}, defaults = {}) {
|
|
244
254
|
const config = Object.assign({}, defaults, userConfig);
|
|
245
255
|
const rawPresets = config.presets || [];
|
|
@@ -248,7 +258,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
248
258
|
...rawPresets.filter((p) => !p.enforce),
|
|
249
259
|
...rawPresets.filter((p) => p.enforce === "post")
|
|
250
260
|
];
|
|
251
|
-
const layers = Object.assign(
|
|
261
|
+
const layers = Object.assign(defaultLayers, ...rawPresets.map((i) => i.layers), userConfig.layers);
|
|
252
262
|
function mergePresets(key) {
|
|
253
263
|
return uniq([
|
|
254
264
|
...sortedPresets.flatMap((p) => toArray(p[key] || [])),
|
|
@@ -258,6 +268,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
258
268
|
const extractors = mergePresets("extractors");
|
|
259
269
|
if (!extractors.length)
|
|
260
270
|
extractors.push(extractorSplit);
|
|
271
|
+
extractors.sort((a, b) => (a.order || 0) - (b.order || 0));
|
|
261
272
|
const rules = mergePresets("rules");
|
|
262
273
|
const rulesStaticMap = {};
|
|
263
274
|
const rulesSize = rules.length;
|
|
@@ -277,6 +288,8 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
277
288
|
excluded: [],
|
|
278
289
|
sortLayers: (layers2) => layers2,
|
|
279
290
|
...config,
|
|
291
|
+
envMode: config.envMode || "build",
|
|
292
|
+
shortcutsLayer: config.shortcutsLayer || "shortcuts",
|
|
280
293
|
layers,
|
|
281
294
|
theme,
|
|
282
295
|
rulesSize,
|
|
@@ -309,10 +322,17 @@ var UnoGenerator = class {
|
|
|
309
322
|
this._cache = new Map();
|
|
310
323
|
}
|
|
311
324
|
async applyExtractors(code, id, set = new Set()) {
|
|
312
|
-
|
|
313
|
-
|
|
325
|
+
const context = {
|
|
326
|
+
get original() {
|
|
327
|
+
return code;
|
|
328
|
+
},
|
|
329
|
+
code,
|
|
330
|
+
id
|
|
331
|
+
};
|
|
332
|
+
for (const extractor of this.config.extractors) {
|
|
333
|
+
const result = await extractor.extract(context);
|
|
314
334
|
result == null ? void 0 : result.forEach((t) => set.add(t));
|
|
315
|
-
}
|
|
335
|
+
}
|
|
316
336
|
return set;
|
|
317
337
|
}
|
|
318
338
|
async generate(input, {
|
|
@@ -421,11 +441,11 @@ ${rules}
|
|
|
421
441
|
css
|
|
422
442
|
].join("\n");
|
|
423
443
|
}
|
|
424
|
-
return layerCache[layer] = layerComments ? `/* layer: ${layer} */
|
|
444
|
+
return layerCache[layer] = layerComments && css ? `/* layer: ${layer} */
|
|
425
445
|
${css}` : css;
|
|
426
446
|
};
|
|
427
447
|
const getLayers = (excludes) => {
|
|
428
|
-
return layers.filter((i) => !(excludes == null ? void 0 : excludes.includes(i))).map((i) => getLayer(i) || "").join("\n");
|
|
448
|
+
return layers.filter((i) => !(excludes == null ? void 0 : excludes.includes(i))).map((i) => getLayer(i) || "").filter(Boolean).join("\n");
|
|
429
449
|
};
|
|
430
450
|
return {
|
|
431
451
|
get css() {
|
|
@@ -565,7 +585,7 @@ ${css}` : css;
|
|
|
565
585
|
meta
|
|
566
586
|
];
|
|
567
587
|
}
|
|
568
|
-
async stringifyShortcuts(parent, expanded, meta) {
|
|
588
|
+
async stringifyShortcuts(parent, expanded, meta = { layer: this.config.shortcutsLayer }) {
|
|
569
589
|
const selectorMap = new TwoKeyMap();
|
|
570
590
|
const parsed = (await Promise.all(uniq(expanded).map((i) => this.parseUtil(i)))).filter(Boolean).sort((a, b) => a[0] - b[0]);
|
|
571
591
|
const [raw, , parentVariants] = parent;
|
package/dist/index.mjs
CHANGED
|
@@ -193,7 +193,13 @@ function withLayer(layer, rules) {
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
// src/extractors/split.ts
|
|
196
|
-
var extractorSplit =
|
|
196
|
+
var extractorSplit = {
|
|
197
|
+
name: "split",
|
|
198
|
+
order: 0,
|
|
199
|
+
extract({ code }) {
|
|
200
|
+
return new Set(code.split(/[\s'"`;>=]+/g).filter(isValidSelector));
|
|
201
|
+
}
|
|
202
|
+
};
|
|
197
203
|
|
|
198
204
|
// src/config.ts
|
|
199
205
|
function resolveShortcuts(shortcuts) {
|
|
@@ -203,6 +209,10 @@ function resolveShortcuts(shortcuts) {
|
|
|
203
209
|
return Object.entries(s);
|
|
204
210
|
});
|
|
205
211
|
}
|
|
212
|
+
var defaultLayers = {
|
|
213
|
+
shortcuts: -1,
|
|
214
|
+
default: 0
|
|
215
|
+
};
|
|
206
216
|
function resolveConfig(userConfig = {}, defaults = {}) {
|
|
207
217
|
const config = Object.assign({}, defaults, userConfig);
|
|
208
218
|
const rawPresets = config.presets || [];
|
|
@@ -211,7 +221,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
211
221
|
...rawPresets.filter((p) => !p.enforce),
|
|
212
222
|
...rawPresets.filter((p) => p.enforce === "post")
|
|
213
223
|
];
|
|
214
|
-
const layers = Object.assign(
|
|
224
|
+
const layers = Object.assign(defaultLayers, ...rawPresets.map((i) => i.layers), userConfig.layers);
|
|
215
225
|
function mergePresets(key) {
|
|
216
226
|
return uniq([
|
|
217
227
|
...sortedPresets.flatMap((p) => toArray(p[key] || [])),
|
|
@@ -221,6 +231,7 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
221
231
|
const extractors = mergePresets("extractors");
|
|
222
232
|
if (!extractors.length)
|
|
223
233
|
extractors.push(extractorSplit);
|
|
234
|
+
extractors.sort((a, b) => (a.order || 0) - (b.order || 0));
|
|
224
235
|
const rules = mergePresets("rules");
|
|
225
236
|
const rulesStaticMap = {};
|
|
226
237
|
const rulesSize = rules.length;
|
|
@@ -240,6 +251,8 @@ function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
240
251
|
excluded: [],
|
|
241
252
|
sortLayers: (layers2) => layers2,
|
|
242
253
|
...config,
|
|
254
|
+
envMode: config.envMode || "build",
|
|
255
|
+
shortcutsLayer: config.shortcutsLayer || "shortcuts",
|
|
243
256
|
layers,
|
|
244
257
|
theme,
|
|
245
258
|
rulesSize,
|
|
@@ -272,10 +285,17 @@ var UnoGenerator = class {
|
|
|
272
285
|
this._cache = new Map();
|
|
273
286
|
}
|
|
274
287
|
async applyExtractors(code, id, set = new Set()) {
|
|
275
|
-
|
|
276
|
-
|
|
288
|
+
const context = {
|
|
289
|
+
get original() {
|
|
290
|
+
return code;
|
|
291
|
+
},
|
|
292
|
+
code,
|
|
293
|
+
id
|
|
294
|
+
};
|
|
295
|
+
for (const extractor of this.config.extractors) {
|
|
296
|
+
const result = await extractor.extract(context);
|
|
277
297
|
result == null ? void 0 : result.forEach((t) => set.add(t));
|
|
278
|
-
}
|
|
298
|
+
}
|
|
279
299
|
return set;
|
|
280
300
|
}
|
|
281
301
|
async generate(input, {
|
|
@@ -384,11 +404,11 @@ ${rules}
|
|
|
384
404
|
css
|
|
385
405
|
].join("\n");
|
|
386
406
|
}
|
|
387
|
-
return layerCache[layer] = layerComments ? `/* layer: ${layer} */
|
|
407
|
+
return layerCache[layer] = layerComments && css ? `/* layer: ${layer} */
|
|
388
408
|
${css}` : css;
|
|
389
409
|
};
|
|
390
410
|
const getLayers = (excludes) => {
|
|
391
|
-
return layers.filter((i) => !(excludes == null ? void 0 : excludes.includes(i))).map((i) => getLayer(i) || "").join("\n");
|
|
411
|
+
return layers.filter((i) => !(excludes == null ? void 0 : excludes.includes(i))).map((i) => getLayer(i) || "").filter(Boolean).join("\n");
|
|
392
412
|
};
|
|
393
413
|
return {
|
|
394
414
|
get css() {
|
|
@@ -528,7 +548,7 @@ ${css}` : css;
|
|
|
528
548
|
meta
|
|
529
549
|
];
|
|
530
550
|
}
|
|
531
|
-
async stringifyShortcuts(parent, expanded, meta) {
|
|
551
|
+
async stringifyShortcuts(parent, expanded, meta = { layer: this.config.shortcutsLayer }) {
|
|
532
552
|
const selectorMap = new TwoKeyMap();
|
|
533
553
|
const parsed = (await Promise.all(uniq(expanded).map((i) => this.parseUtil(i)))).filter(Boolean).sort((a, b) => a[0] - b[0]);
|
|
534
554
|
const [raw, , parentVariants] = parent;
|