@unocss/core 66.8.1 → 66.9.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.mts +26 -1
- package/dist/index.mjs +39 -15
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -702,6 +702,10 @@ interface ConfigBase<Theme extends object = object> {
|
|
|
702
702
|
* Custom transformers to the source code.
|
|
703
703
|
*/
|
|
704
704
|
transformers?: SourceCodeTransformer[];
|
|
705
|
+
/**
|
|
706
|
+
* Processors to transform generated CSS layers before they are exposed.
|
|
707
|
+
*/
|
|
708
|
+
processors?: CSSProcessor<Theme>[];
|
|
705
709
|
}
|
|
706
710
|
interface OutputCssLayersOptions {
|
|
707
711
|
/**
|
|
@@ -942,6 +946,27 @@ interface SourceCodeTransformer {
|
|
|
942
946
|
highlightAnnotations?: HighlightAnnotation[];
|
|
943
947
|
} | void>;
|
|
944
948
|
}
|
|
949
|
+
interface CSSProcessorContext<Theme extends object = object> {
|
|
950
|
+
/**
|
|
951
|
+
* The current CSS layer being processed.
|
|
952
|
+
*/
|
|
953
|
+
layer: string;
|
|
954
|
+
/**
|
|
955
|
+
* The theme object
|
|
956
|
+
*/
|
|
957
|
+
theme: Theme;
|
|
958
|
+
/**
|
|
959
|
+
* Environment mode
|
|
960
|
+
*
|
|
961
|
+
* @default 'build'
|
|
962
|
+
*/
|
|
963
|
+
envMode: 'dev' | 'build';
|
|
964
|
+
}
|
|
965
|
+
interface CSSProcessor<Theme extends object = object> {
|
|
966
|
+
name: string;
|
|
967
|
+
order?: number;
|
|
968
|
+
process: (css: string, context: CSSProcessorContext<Theme>) => Awaitable<string>;
|
|
969
|
+
}
|
|
945
970
|
interface ContentOptions {
|
|
946
971
|
/**
|
|
947
972
|
* Glob patterns to extract from the file system, in addition to other content sources.
|
|
@@ -1172,4 +1197,4 @@ declare const defaultSplitRE: RegExp;
|
|
|
1172
1197
|
declare const splitWithVariantGroupRE: RegExp;
|
|
1173
1198
|
declare const extractorSplit: Extractor;
|
|
1174
1199
|
//#endregion
|
|
1175
|
-
export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BaseContext, BetterMap, BlocklistMeta, BlocklistRule, BlocklistValue, CSSEntries, CSSEntriesInput, CSSEntry, CSSObject, CSSObjectInput, CSSValue, CSSValueInput, CSSValues, CliEntryItem, CliOptions, ConfigBase, ContentOptions, ControlSymbols, ControlSymbolsEntry, ControlSymbolsValue, CountableSet, DEFAULT_LAYERS, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, Emitter, ExtendedTokenInfo, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, HighlightAnnotation, LAYER_DEFAULT, LAYER_IMPORTS, LAYER_PREFLIGHTS, LAYER_SHORTCUTS, 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, TwoKeyMap, UnoGenerator, UnocssPluginContext, Unsubscribe, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, Variant, VariantContext, VariantFunction, VariantHandler, VariantHandlerContext, VariantMatchedResult, VariantObject, 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 };
|
|
1200
|
+
export { ArgumentType, Arrayable, AutoCompleteExtractor, AutoCompleteExtractorContext, AutoCompleteExtractorResult, AutoCompleteFunction, AutoCompleteTemplate, Awaitable, BaseContext, BetterMap, BlocklistMeta, BlocklistRule, BlocklistValue, CSSEntries, CSSEntriesInput, CSSEntry, CSSObject, CSSObjectInput, CSSProcessor, CSSProcessorContext, CSSValue, CSSValueInput, CSSValues, CliEntryItem, CliOptions, ConfigBase, ContentOptions, ControlSymbols, ControlSymbolsEntry, ControlSymbolsValue, CountableSet, DEFAULT_LAYERS, DeepPartial, DynamicMatcher, DynamicRule, DynamicShortcut, DynamicShortcutMatcher, Emitter, ExtendedTokenInfo, Extractor, ExtractorContext, FilterPattern, FlatObjectTuple, GenerateOptions, GenerateResult, GeneratorOptions, HighlightAnnotation, LAYER_DEFAULT, LAYER_IMPORTS, LAYER_PREFLIGHTS, LAYER_SHORTCUTS, 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, TwoKeyMap, UnoGenerator, UnocssPluginContext, Unsubscribe, UserConfig, UserConfigDefaults, UserOnlyOptions, UserShortcuts, UtilObject, Variant, VariantContext, VariantFunction, VariantHandler, VariantHandlerContext, VariantMatchedResult, VariantObject, 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 };
|
package/dist/index.mjs
CHANGED
|
@@ -320,7 +320,7 @@ function isStaticShortcut(sc) {
|
|
|
320
320
|
const regexCache = {};
|
|
321
321
|
function makeRegexClassGroup(separators = ["-", ":"]) {
|
|
322
322
|
const key = separators.map((s) => escapeRegExp(s)).join("|");
|
|
323
|
-
if (!regexCache[key]) regexCache[key] = new RegExp(`((?:[!@*<~\\w+:_-]|\\[
|
|
323
|
+
if (!regexCache[key]) regexCache[key] = new RegExp(`((?:[!@*<~\\w+:_-]|\\[&?>?:?[^\\s\\]]*\\])+?)(${key})\\(((?:[~!<>@*\\w\\s:/\\\\,%#.$?-]|\\[[^\\]]*?\\])+?)\\)(?!\\s*?=>)`, "gm");
|
|
324
324
|
regexCache[key].lastIndex = 0;
|
|
325
325
|
return regexCache[key];
|
|
326
326
|
}
|
|
@@ -361,10 +361,11 @@ function parseVariantGroup(str, separators = ["-", ":"], depth = 5) {
|
|
|
361
361
|
depth -= 1;
|
|
362
362
|
} while (hasChanged && depth);
|
|
363
363
|
let expanded;
|
|
364
|
+
const groupsInOrder = [...groupsByOffset].sort(([a], [b]) => a - b);
|
|
364
365
|
if (typeof str === "string") {
|
|
365
366
|
expanded = "";
|
|
366
367
|
let prevOffset = 0;
|
|
367
|
-
for (const [offset, group] of
|
|
368
|
+
for (const [offset, group] of groupsInOrder) {
|
|
368
369
|
expanded += str.slice(prevOffset, offset);
|
|
369
370
|
expanded += group.items.map((item) => item.className).join(" ");
|
|
370
371
|
prevOffset = offset + group.length;
|
|
@@ -372,7 +373,7 @@ function parseVariantGroup(str, separators = ["-", ":"], depth = 5) {
|
|
|
372
373
|
expanded += str.slice(prevOffset);
|
|
373
374
|
} else {
|
|
374
375
|
expanded = str;
|
|
375
|
-
for (const [offset, group] of
|
|
376
|
+
for (const [offset, group] of groupsInOrder) expanded.overwrite(offset, offset + group.length, group.items.map((item) => item.className).join(" "));
|
|
376
377
|
}
|
|
377
378
|
return {
|
|
378
379
|
prefixes: Array.from(prefixes),
|
|
@@ -576,7 +577,8 @@ async function resolveConfig(userConfig = {}, defaults = {}) {
|
|
|
576
577
|
separators,
|
|
577
578
|
details: config.details ?? config.envMode === "dev",
|
|
578
579
|
content,
|
|
579
|
-
transformers: uniqueBy(getMerged("transformers"), (a, b) => a.name === b.name)
|
|
580
|
+
transformers: uniqueBy(getMerged("transformers"), (a, b) => a.name === b.name),
|
|
581
|
+
processors: uniqueBy(getMerged("processors"), (a, b) => a.name === b.name)
|
|
580
582
|
};
|
|
581
583
|
const extendThemes = getMerged("extendTheme");
|
|
582
584
|
for (const extendTheme of extendThemes) resolved.theme = extendTheme(resolved.theme, resolved) || resolved.theme;
|
|
@@ -631,7 +633,7 @@ function definePreset(preset) {
|
|
|
631
633
|
}
|
|
632
634
|
//#endregion
|
|
633
635
|
//#region package.json
|
|
634
|
-
var version = "66.
|
|
636
|
+
var version = "66.9.0";
|
|
635
637
|
//#endregion
|
|
636
638
|
//#region src/generator.ts
|
|
637
639
|
const symbols = {
|
|
@@ -864,15 +866,16 @@ var UnoGeneratorInternal = class UnoGeneratorInternal {
|
|
|
864
866
|
})();
|
|
865
867
|
const sortLayers = (layers) => this.config.sortLayers(layers.sort((a, b) => (this.config.layers[a] ?? 0) - (this.config.layers[b] ?? 0) || a.localeCompare(b)));
|
|
866
868
|
const layers = sortLayers(Array.from(layerSet));
|
|
867
|
-
const
|
|
869
|
+
const rawLayerCache = {};
|
|
870
|
+
const processedLayerCache = {};
|
|
868
871
|
const outputCssLayers = this.config.outputToCssLayers;
|
|
869
872
|
const getLayerAlias = (layer) => {
|
|
870
873
|
let alias = layer;
|
|
871
874
|
if (typeof outputCssLayers === "object") alias = outputCssLayers.cssLayerName?.(layer);
|
|
872
875
|
return alias === null ? null : alias ?? layer;
|
|
873
876
|
};
|
|
874
|
-
const
|
|
875
|
-
if (
|
|
877
|
+
const getRawLayer = (layer = LAYER_DEFAULT) => {
|
|
878
|
+
if (rawLayerCache[layer] != null) return rawLayerCache[layer];
|
|
876
879
|
let css = Array.from(sheet).sort((a, b) => (this.tokenProcessor.getParentOrder(a[0]) ?? 0) - (this.tokenProcessor.getParentOrder(b[0]) ?? 0) || a[0]?.localeCompare(b[0] || "") || 0).map(([parent, items]) => {
|
|
877
880
|
const sorted = items.filter((i) => (i[4]?.layer || "default") === layer).sort((a, b) => {
|
|
878
881
|
return a[0] - b[0] || (a[4]?.sort || 0) - (b[4]?.sort || 0) || a[5]?.currentSelector?.localeCompare(b[5]?.currentSelector ?? "") || a[1]?.localeCompare(b[1] || "") || a[2]?.localeCompare(b[2] || "") || 0;
|
|
@@ -915,17 +918,32 @@ var UnoGeneratorInternal = class UnoGeneratorInternal {
|
|
|
915
918
|
return `${parents.join("{")}{${nl}${rules}${nl}${"}".repeat(parents.length)}`;
|
|
916
919
|
}).filter(Boolean).join(nl);
|
|
917
920
|
if (preflights) css = [preflightsMap[layer], css].filter(Boolean).join(nl);
|
|
921
|
+
if (!css) return rawLayerCache[layer] = "";
|
|
918
922
|
let alias;
|
|
919
|
-
if (outputCssLayers
|
|
923
|
+
if (outputCssLayers) {
|
|
920
924
|
alias = getLayerAlias(layer);
|
|
921
925
|
if (alias !== null) css = `@layer ${alias}{${nl}${css}${nl}}`;
|
|
922
926
|
}
|
|
923
|
-
|
|
924
|
-
return
|
|
927
|
+
css = (minify ? "" : `/* layer: ${layer}${alias && alias !== layer ? `, alias: ${alias}` : ""} */${nl}`) + css;
|
|
928
|
+
return rawLayerCache[layer] = css;
|
|
929
|
+
};
|
|
930
|
+
const processors = this.config.processors?.slice().sort((a, b) => (a.order || 0) - (b.order || 0)) ?? [];
|
|
931
|
+
const processLayer = async (css, layer) => {
|
|
932
|
+
let processed = css;
|
|
933
|
+
const context = {
|
|
934
|
+
layer,
|
|
935
|
+
theme: this.config.theme,
|
|
936
|
+
envMode: this.config.envMode || "build"
|
|
937
|
+
};
|
|
938
|
+
for (const processor of processors) processed = await processor.process(processed, context);
|
|
939
|
+
return processed;
|
|
940
|
+
};
|
|
941
|
+
const getLayer = (layer = LAYER_DEFAULT) => {
|
|
942
|
+
return processedLayerCache[layer] ?? getRawLayer(layer);
|
|
925
943
|
};
|
|
926
944
|
const getLayers = (includes = layers, excludes) => {
|
|
927
945
|
const layers = includes.filter((i) => !excludes?.includes(i));
|
|
928
|
-
const css = layers.map(getLayer).filter(Boolean);
|
|
946
|
+
const css = layers.map((layer) => getLayer(layer)).filter(Boolean);
|
|
929
947
|
if (outputCssLayers) {
|
|
930
948
|
let layerNames = layers;
|
|
931
949
|
if (typeof outputCssLayers === "object" && outputCssLayers.allLayers) layerNames = sortLayers(Object.keys(this.config.layers));
|
|
@@ -934,10 +952,16 @@ var UnoGeneratorInternal = class UnoGeneratorInternal {
|
|
|
934
952
|
return css.join(nl);
|
|
935
953
|
};
|
|
936
954
|
const setLayer = async (layer, callback) => {
|
|
937
|
-
const
|
|
938
|
-
|
|
939
|
-
|
|
955
|
+
const raw = await callback(getRawLayer(layer));
|
|
956
|
+
const processed = await processLayer(raw, layer);
|
|
957
|
+
rawLayerCache[layer] = raw;
|
|
958
|
+
processedLayerCache[layer] = processed;
|
|
959
|
+
return processed;
|
|
940
960
|
};
|
|
961
|
+
await Promise.all(layers.map(async (layer) => {
|
|
962
|
+
const raw = getRawLayer(layer);
|
|
963
|
+
processedLayerCache[layer] = raw ? await processLayer(raw, layer) : raw;
|
|
964
|
+
}));
|
|
941
965
|
return {
|
|
942
966
|
get css() {
|
|
943
967
|
return getLayers();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "66.
|
|
4
|
+
"version": "66.9.0",
|
|
5
5
|
"description": "The instant on-demand Atomic CSS engine.",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"magic-string": "^1.2.
|
|
36
|
+
"magic-string": "^1.2.2",
|
|
37
37
|
"unconfig": "^7.5.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|