@unocss/vite 0.51.13 → 0.52.1
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.cjs +1 -222
- package/dist/index.d.ts +3 -37
- package/dist/index.mjs +3 -222
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -853,225 +853,6 @@ function VueScopedPlugin({ uno, ready }) {
|
|
|
853
853
|
};
|
|
854
854
|
}
|
|
855
855
|
|
|
856
|
-
const SELECTOR_REGEX = /(?<![\d(])([[\.][\S\s]+?)({[\S\s]+?})/g;
|
|
857
|
-
function wrapSelectorsWithGlobal(css) {
|
|
858
|
-
return css.replace(SELECTOR_REGEX, ":global($1)$2");
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
function hash(str) {
|
|
862
|
-
let i;
|
|
863
|
-
let l;
|
|
864
|
-
let hval = 2166136261;
|
|
865
|
-
for (i = 0, l = str.length; i < l; i++) {
|
|
866
|
-
hval ^= str.charCodeAt(i);
|
|
867
|
-
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
868
|
-
}
|
|
869
|
-
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
const classesRE = /class=(["'\`])([^\{][\S\s]*?)\1/g;
|
|
873
|
-
const classesExpressionsRE = /class=(["'\`])?(\{[\S\s]+?\})\1/g;
|
|
874
|
-
const classesDirectivesRE = /class:([\S]+?)={/g;
|
|
875
|
-
const classesDirectivesShorthandRE = /class:([^=>\s/]+)[{>\s/]/g;
|
|
876
|
-
const classesInsideExpressionsRE = /(["'\`])([\S\s]+?)\1/g;
|
|
877
|
-
async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
878
|
-
const {
|
|
879
|
-
classPrefix = "uno-",
|
|
880
|
-
combine = true,
|
|
881
|
-
hashFn = hash
|
|
882
|
-
} = options;
|
|
883
|
-
let styles = "";
|
|
884
|
-
let map;
|
|
885
|
-
const alreadyHasStyles = code.match(/<style[^>]*>[\s\S]*?<\/style\s*>/);
|
|
886
|
-
const preflights = code.includes("uno:preflights");
|
|
887
|
-
const safelist = code.includes("uno:safelist");
|
|
888
|
-
if (preflights || safelist) {
|
|
889
|
-
const { css: css2 } = await uno.generate("", { preflights, safelist });
|
|
890
|
-
styles = css2;
|
|
891
|
-
}
|
|
892
|
-
const classes = [...code.matchAll(classesRE), ...code.matchAll(classesExpressionsRE)];
|
|
893
|
-
const classDirectives = [...code.matchAll(classesDirectivesRE)];
|
|
894
|
-
const classDirectivesShorthand = [...code.matchAll(classesDirectivesShorthandRE)];
|
|
895
|
-
const originalShortcuts = uno.config.shortcuts;
|
|
896
|
-
const shortcuts = {};
|
|
897
|
-
const toGenerate = /* @__PURE__ */ new Set();
|
|
898
|
-
const s = new MagicString__default(code);
|
|
899
|
-
let idHash;
|
|
900
|
-
if (!combine)
|
|
901
|
-
idHash = hashFn(id);
|
|
902
|
-
function isOriginalOriginalShortcut(token) {
|
|
903
|
-
return !!originalShortcuts.find((s2) => s2[0] === token);
|
|
904
|
-
}
|
|
905
|
-
function queueCompiledClass(tokens) {
|
|
906
|
-
if (combine) {
|
|
907
|
-
const _shortcuts = tokens.filter((t) => isOriginalOriginalShortcut(t));
|
|
908
|
-
for (const s2 of _shortcuts)
|
|
909
|
-
toGenerate.add(s2);
|
|
910
|
-
const _tokens = tokens.filter((t) => !isOriginalOriginalShortcut(t));
|
|
911
|
-
if (!_tokens.length)
|
|
912
|
-
return _shortcuts.join(" ");
|
|
913
|
-
const hash2 = hashFn(_tokens.join(" ") + id);
|
|
914
|
-
const className = `${classPrefix}${hash2}`;
|
|
915
|
-
shortcuts[className] = _tokens;
|
|
916
|
-
toGenerate.add(className);
|
|
917
|
-
return [className, ..._shortcuts].join(" ");
|
|
918
|
-
} else {
|
|
919
|
-
return tokens.map((token) => {
|
|
920
|
-
if (isOriginalOriginalShortcut(token)) {
|
|
921
|
-
toGenerate.add(token);
|
|
922
|
-
return token;
|
|
923
|
-
}
|
|
924
|
-
const className = `_${token}_${idHash}`;
|
|
925
|
-
shortcuts[className] = [token];
|
|
926
|
-
toGenerate.add(className);
|
|
927
|
-
return className;
|
|
928
|
-
}).join(" ");
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
async function sortKnownAndUnknownClasses(str) {
|
|
932
|
-
const classArr = str.split(/\s+/);
|
|
933
|
-
const result = await Promise.all(classArr.filter(Boolean).map(async (t) => [t, !!await uno.parseToken(t)]));
|
|
934
|
-
const known = result.filter(([, matched2]) => matched2).map(([t]) => t).sort();
|
|
935
|
-
if (!known.length)
|
|
936
|
-
return null;
|
|
937
|
-
const replacements = result.filter(([, matched2]) => !matched2).map(([i]) => i);
|
|
938
|
-
const className = queueCompiledClass(known);
|
|
939
|
-
return [className, ...replacements].join(" ");
|
|
940
|
-
}
|
|
941
|
-
const processedMap = /* @__PURE__ */ new Set();
|
|
942
|
-
for (const match of classes) {
|
|
943
|
-
let body = core.expandVariantGroup(match[2].trim());
|
|
944
|
-
let replaced = false;
|
|
945
|
-
const expressions = [...body.matchAll(classesInsideExpressionsRE)];
|
|
946
|
-
for (const expression of expressions) {
|
|
947
|
-
const replacement2 = await sortKnownAndUnknownClasses(expression[2].trim());
|
|
948
|
-
if (replacement2) {
|
|
949
|
-
body = body.replace(expression[2], replacement2);
|
|
950
|
-
replaced = true;
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
const replacement = await sortKnownAndUnknownClasses(body);
|
|
954
|
-
if (replacement) {
|
|
955
|
-
body = body.replace(body, replacement);
|
|
956
|
-
replaced = true;
|
|
957
|
-
}
|
|
958
|
-
if (!replaced)
|
|
959
|
-
continue;
|
|
960
|
-
const start = match.index + (match[1] ? 7 : 6);
|
|
961
|
-
const end = match.index + match[0].length - (match[1] ? 1 : 0);
|
|
962
|
-
processedMap.add(start);
|
|
963
|
-
s.overwrite(start, end, body);
|
|
964
|
-
}
|
|
965
|
-
for (const match of classDirectives) {
|
|
966
|
-
const token = match[1];
|
|
967
|
-
const result = !!await uno.parseToken(token);
|
|
968
|
-
if (!result)
|
|
969
|
-
continue;
|
|
970
|
-
const className = queueCompiledClass([token]);
|
|
971
|
-
const start = match.index + "class:".length;
|
|
972
|
-
processedMap.add(start);
|
|
973
|
-
s.overwrite(start, start + match[1].length, className);
|
|
974
|
-
}
|
|
975
|
-
for (const match of classDirectivesShorthand) {
|
|
976
|
-
const token = match[1];
|
|
977
|
-
const result = !!await uno.parseToken(token);
|
|
978
|
-
if (!result)
|
|
979
|
-
continue;
|
|
980
|
-
const className = queueCompiledClass([token]);
|
|
981
|
-
const start = match.index + "class:".length;
|
|
982
|
-
processedMap.add(start);
|
|
983
|
-
s.overwrite(start, start + match[1].length, `${className}={${token}}`);
|
|
984
|
-
}
|
|
985
|
-
const templateCode = code.replace(/<(script|style)[^>]*>[\s\S]*?<\/\1\s*>/g, (match) => Array(match.length).fill(" ").join(""));
|
|
986
|
-
const { matched } = await uno.generate(templateCode, { preflights: false, safelist: false, minify: true });
|
|
987
|
-
for (const token of matched) {
|
|
988
|
-
const match = token.match(core.attributifyRE);
|
|
989
|
-
if (match) {
|
|
990
|
-
const [, name, value] = match;
|
|
991
|
-
if (!value) {
|
|
992
|
-
let start = 0;
|
|
993
|
-
templateCode.split(/([\s"'`;*]|:\(|\)"|\)\s)/g).forEach((i) => {
|
|
994
|
-
const end = start + i.length;
|
|
995
|
-
if (i === name && !processedMap.has(start)) {
|
|
996
|
-
const className = queueCompiledClass([name]);
|
|
997
|
-
s.appendLeft(start, `class:${className}={true} `);
|
|
998
|
-
s.overwrite(start, end, "");
|
|
999
|
-
}
|
|
1000
|
-
start = end;
|
|
1001
|
-
});
|
|
1002
|
-
} else {
|
|
1003
|
-
const regex = new RegExp(`(${core.escapeRegExp(name)}=)(['"])[^\\2]*?${core.escapeRegExp(value)}[^\\2]*?\\2`, "g");
|
|
1004
|
-
for (const match2 of templateCode.matchAll(regex)) {
|
|
1005
|
-
const escaped = match2[1];
|
|
1006
|
-
const body = match2[0].slice(escaped.length);
|
|
1007
|
-
let bodyIndex = body.match(`[\\b\\s'"]${core.escapeRegExp(value)}[\\b\\s'"]`)?.index ?? -1;
|
|
1008
|
-
if (body[bodyIndex]?.match(/[\s'"]/))
|
|
1009
|
-
bodyIndex++;
|
|
1010
|
-
if (bodyIndex < 0)
|
|
1011
|
-
return;
|
|
1012
|
-
const [, base] = await uno.matchVariants(value);
|
|
1013
|
-
const variants = value.replace(base, "");
|
|
1014
|
-
const className = queueCompiledClass([`${variants + name}-${base}`]);
|
|
1015
|
-
s.appendLeft(match2.index, `class:${className}={true} `);
|
|
1016
|
-
s.overwrite(match2.index, match2.index + match2[0].length, "");
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
uno.config.shortcuts = [...originalShortcuts, ...Object.entries(shortcuts)];
|
|
1022
|
-
const { css } = await uno.generate(toGenerate, { preflights: false, safelist: false, minify: true });
|
|
1023
|
-
styles += wrapSelectorsWithGlobal(css);
|
|
1024
|
-
uno.config.shortcuts = originalShortcuts;
|
|
1025
|
-
if (toGenerate.size > 0 || s.hasChanged()) {
|
|
1026
|
-
code = s.toString();
|
|
1027
|
-
map = s.generateMap({ hires: true, source: id });
|
|
1028
|
-
} else {
|
|
1029
|
-
return;
|
|
1030
|
-
}
|
|
1031
|
-
if (alreadyHasStyles) {
|
|
1032
|
-
return {
|
|
1033
|
-
code: code.replace(/(<style[^>]*>)/, `$1${styles}`),
|
|
1034
|
-
map
|
|
1035
|
-
};
|
|
1036
|
-
}
|
|
1037
|
-
return {
|
|
1038
|
-
code: `${code}
|
|
1039
|
-
<style>${styles}</style>`,
|
|
1040
|
-
map
|
|
1041
|
-
};
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
function SvelteScopedPlugin({ ready, uno }) {
|
|
1045
|
-
let viteConfig;
|
|
1046
|
-
let filter = pluginutils.createFilter([/\.svelte$/, /\.svelte\.md$/, /\.svx$/], defaultExclude);
|
|
1047
|
-
return {
|
|
1048
|
-
name: "unocss:svelte-scoped",
|
|
1049
|
-
enforce: "pre",
|
|
1050
|
-
async configResolved(_viteConfig) {
|
|
1051
|
-
viteConfig = _viteConfig;
|
|
1052
|
-
const { config } = await ready;
|
|
1053
|
-
filter = pluginutils.createFilter(
|
|
1054
|
-
config.include || [/\.svelte$/, /\.svelte\.md$/, /\.svx$/],
|
|
1055
|
-
config.exclude || defaultExclude
|
|
1056
|
-
);
|
|
1057
|
-
},
|
|
1058
|
-
transform(code, id) {
|
|
1059
|
-
if (!filter(id))
|
|
1060
|
-
return;
|
|
1061
|
-
return transformSvelteSFC(code, id, uno, { combine: viteConfig.command === "build" });
|
|
1062
|
-
},
|
|
1063
|
-
handleHotUpdate(ctx) {
|
|
1064
|
-
const read = ctx.read;
|
|
1065
|
-
if (filter(ctx.file)) {
|
|
1066
|
-
ctx.read = async () => {
|
|
1067
|
-
const code = await read();
|
|
1068
|
-
return (await transformSvelteSFC(code, ctx.file, uno, { combine: viteConfig.command === "build" }))?.code || code;
|
|
1069
|
-
};
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
};
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
856
|
function ShadowDomModuleModePlugin({ uno }) {
|
|
1076
857
|
const partExtractorRegex = /^part-\[(.+)]:/;
|
|
1077
858
|
const nameRegexp = /<([^\s^!>]+)\s*([^>]*)>/;
|
|
@@ -1362,7 +1143,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
|
|
|
1362
1143
|
} else if (mode === "vue-scoped") {
|
|
1363
1144
|
plugins.push(VueScopedPlugin(ctx));
|
|
1364
1145
|
} else if (mode === "svelte-scoped") {
|
|
1365
|
-
|
|
1146
|
+
throw new Error("[unocss] svelte-scoped mode is now its own package, please use @unocss/svelte-scoped according to the docs");
|
|
1366
1147
|
} else if (mode === "shadow-dom") {
|
|
1367
1148
|
plugins.push(ShadowDomModuleModePlugin(ctx));
|
|
1368
1149
|
} else if (mode === "global") {
|
|
@@ -1383,8 +1164,6 @@ exports.GlobalModeBuildPlugin = GlobalModeBuildPlugin;
|
|
|
1383
1164
|
exports.GlobalModeDevPlugin = GlobalModeDevPlugin;
|
|
1384
1165
|
exports.GlobalModePlugin = GlobalModePlugin;
|
|
1385
1166
|
exports.PerModuleModePlugin = PerModuleModePlugin;
|
|
1386
|
-
exports.SvelteScopedPlugin = SvelteScopedPlugin;
|
|
1387
1167
|
exports.VueScopedPlugin = VueScopedPlugin;
|
|
1388
1168
|
exports["default"] = UnocssPlugin;
|
|
1389
1169
|
exports.defineConfig = defineConfig;
|
|
1390
|
-
exports.transformSvelteSFC = transformSvelteSFC;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as vite from 'vite';
|
|
2
2
|
import { Plugin } from 'vite';
|
|
3
|
-
import { UserConfig, UnocssPluginContext,
|
|
3
|
+
import { UserConfig, UnocssPluginContext, UserConfigDefaults } from '@unocss/core';
|
|
4
4
|
|
|
5
5
|
interface VitePluginConfig<Theme extends {} = {}> extends UserConfig<Theme> {
|
|
6
6
|
/**
|
|
@@ -16,12 +16,11 @@ interface VitePluginConfig<Theme extends {} = {}> extends UserConfig<Theme> {
|
|
|
16
16
|
* - `dist-chunk` - generate a CSS sheet for each code chunk on build, great for MPA
|
|
17
17
|
* - `per-module` - generate a CSS sheet for each module, can be scoped
|
|
18
18
|
* - `vue-scoped` - inject generated CSS to Vue SFC's `<style scoped>` for isolation
|
|
19
|
-
* - `svelte-scoped` - inject generated CSS to Svelte's `<style>` for isolation
|
|
20
19
|
* - `shadow-dom` - inject generated CSS to `Shadow DOM` css style block for each web component
|
|
21
20
|
*
|
|
22
21
|
* @default 'global'
|
|
23
22
|
*/
|
|
24
|
-
mode?: 'global' | 'per-module' | 'vue-scoped' | '
|
|
23
|
+
mode?: 'global' | 'per-module' | 'vue-scoped' | 'dist-chunk' | 'shadow-dom';
|
|
25
24
|
/**
|
|
26
25
|
* Transform CSS for `@apply` directive
|
|
27
26
|
*
|
|
@@ -60,40 +59,7 @@ declare function PerModuleModePlugin({ uno, filter }: UnocssPluginContext): Plug
|
|
|
60
59
|
|
|
61
60
|
declare function VueScopedPlugin({ uno, ready }: UnocssPluginContext): Plugin;
|
|
62
61
|
|
|
63
|
-
interface TransformSFCOptions {
|
|
64
|
-
/**
|
|
65
|
-
* Prefix for compiled class name
|
|
66
|
-
* @default 'uno-'
|
|
67
|
-
*/
|
|
68
|
-
classPrefix?: string;
|
|
69
|
-
/**
|
|
70
|
-
* Add hash and combine recognized tokens (optimal for production); set false in dev mode for easy dev tools toggling to allow for design adjustments in the browser
|
|
71
|
-
* @default true
|
|
72
|
-
*/
|
|
73
|
-
combine?: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Hash function
|
|
76
|
-
*/
|
|
77
|
-
hashFn?: (str: string) => string;
|
|
78
|
-
}
|
|
79
|
-
declare function transformSvelteSFC(code: string, id: string, uno: UnoGenerator, options?: TransformSFCOptions): Promise<{
|
|
80
|
-
code: string;
|
|
81
|
-
map?: SourceMap;
|
|
82
|
-
} | undefined>;
|
|
83
|
-
interface SourceMap {
|
|
84
|
-
file: string;
|
|
85
|
-
mappings: string;
|
|
86
|
-
names: string[];
|
|
87
|
-
sources: string[];
|
|
88
|
-
sourcesContent: string[];
|
|
89
|
-
version: number;
|
|
90
|
-
toString(): string;
|
|
91
|
-
toUrl(): string;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
declare function SvelteScopedPlugin({ ready, uno }: UnocssPluginContext): Plugin;
|
|
95
|
-
|
|
96
62
|
declare function defineConfig<Theme extends {}>(config: VitePluginConfig<Theme>): VitePluginConfig<Theme>;
|
|
97
63
|
declare function UnocssPlugin<Theme extends {}>(configOrPath?: VitePluginConfig<Theme> | string, defaults?: UserConfigDefaults): Plugin[];
|
|
98
64
|
|
|
99
|
-
export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin,
|
|
65
|
+
export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, VitePluginConfig, VueScopedPlugin, UnocssPlugin as default, defineConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import UnocssInspector from '@unocss/inspector';
|
|
2
|
-
import { cssIdRE, createGenerator, BetterMap, notNull,
|
|
2
|
+
import { cssIdRE, createGenerator, BetterMap, notNull, toEscapedSelector } from '@unocss/core';
|
|
3
3
|
import { createFilter } from '@rollup/pluginutils';
|
|
4
4
|
import { loadConfig } from '@unocss/config';
|
|
5
5
|
import { createHash } from 'node:crypto';
|
|
@@ -840,225 +840,6 @@ function VueScopedPlugin({ uno, ready }) {
|
|
|
840
840
|
};
|
|
841
841
|
}
|
|
842
842
|
|
|
843
|
-
const SELECTOR_REGEX = /(?<![\d(])([[\.][\S\s]+?)({[\S\s]+?})/g;
|
|
844
|
-
function wrapSelectorsWithGlobal(css) {
|
|
845
|
-
return css.replace(SELECTOR_REGEX, ":global($1)$2");
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
function hash(str) {
|
|
849
|
-
let i;
|
|
850
|
-
let l;
|
|
851
|
-
let hval = 2166136261;
|
|
852
|
-
for (i = 0, l = str.length; i < l; i++) {
|
|
853
|
-
hval ^= str.charCodeAt(i);
|
|
854
|
-
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
855
|
-
}
|
|
856
|
-
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
const classesRE = /class=(["'\`])([^\{][\S\s]*?)\1/g;
|
|
860
|
-
const classesExpressionsRE = /class=(["'\`])?(\{[\S\s]+?\})\1/g;
|
|
861
|
-
const classesDirectivesRE = /class:([\S]+?)={/g;
|
|
862
|
-
const classesDirectivesShorthandRE = /class:([^=>\s/]+)[{>\s/]/g;
|
|
863
|
-
const classesInsideExpressionsRE = /(["'\`])([\S\s]+?)\1/g;
|
|
864
|
-
async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
865
|
-
const {
|
|
866
|
-
classPrefix = "uno-",
|
|
867
|
-
combine = true,
|
|
868
|
-
hashFn = hash
|
|
869
|
-
} = options;
|
|
870
|
-
let styles = "";
|
|
871
|
-
let map;
|
|
872
|
-
const alreadyHasStyles = code.match(/<style[^>]*>[\s\S]*?<\/style\s*>/);
|
|
873
|
-
const preflights = code.includes("uno:preflights");
|
|
874
|
-
const safelist = code.includes("uno:safelist");
|
|
875
|
-
if (preflights || safelist) {
|
|
876
|
-
const { css: css2 } = await uno.generate("", { preflights, safelist });
|
|
877
|
-
styles = css2;
|
|
878
|
-
}
|
|
879
|
-
const classes = [...code.matchAll(classesRE), ...code.matchAll(classesExpressionsRE)];
|
|
880
|
-
const classDirectives = [...code.matchAll(classesDirectivesRE)];
|
|
881
|
-
const classDirectivesShorthand = [...code.matchAll(classesDirectivesShorthandRE)];
|
|
882
|
-
const originalShortcuts = uno.config.shortcuts;
|
|
883
|
-
const shortcuts = {};
|
|
884
|
-
const toGenerate = /* @__PURE__ */ new Set();
|
|
885
|
-
const s = new MagicString(code);
|
|
886
|
-
let idHash;
|
|
887
|
-
if (!combine)
|
|
888
|
-
idHash = hashFn(id);
|
|
889
|
-
function isOriginalOriginalShortcut(token) {
|
|
890
|
-
return !!originalShortcuts.find((s2) => s2[0] === token);
|
|
891
|
-
}
|
|
892
|
-
function queueCompiledClass(tokens) {
|
|
893
|
-
if (combine) {
|
|
894
|
-
const _shortcuts = tokens.filter((t) => isOriginalOriginalShortcut(t));
|
|
895
|
-
for (const s2 of _shortcuts)
|
|
896
|
-
toGenerate.add(s2);
|
|
897
|
-
const _tokens = tokens.filter((t) => !isOriginalOriginalShortcut(t));
|
|
898
|
-
if (!_tokens.length)
|
|
899
|
-
return _shortcuts.join(" ");
|
|
900
|
-
const hash2 = hashFn(_tokens.join(" ") + id);
|
|
901
|
-
const className = `${classPrefix}${hash2}`;
|
|
902
|
-
shortcuts[className] = _tokens;
|
|
903
|
-
toGenerate.add(className);
|
|
904
|
-
return [className, ..._shortcuts].join(" ");
|
|
905
|
-
} else {
|
|
906
|
-
return tokens.map((token) => {
|
|
907
|
-
if (isOriginalOriginalShortcut(token)) {
|
|
908
|
-
toGenerate.add(token);
|
|
909
|
-
return token;
|
|
910
|
-
}
|
|
911
|
-
const className = `_${token}_${idHash}`;
|
|
912
|
-
shortcuts[className] = [token];
|
|
913
|
-
toGenerate.add(className);
|
|
914
|
-
return className;
|
|
915
|
-
}).join(" ");
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
async function sortKnownAndUnknownClasses(str) {
|
|
919
|
-
const classArr = str.split(/\s+/);
|
|
920
|
-
const result = await Promise.all(classArr.filter(Boolean).map(async (t) => [t, !!await uno.parseToken(t)]));
|
|
921
|
-
const known = result.filter(([, matched2]) => matched2).map(([t]) => t).sort();
|
|
922
|
-
if (!known.length)
|
|
923
|
-
return null;
|
|
924
|
-
const replacements = result.filter(([, matched2]) => !matched2).map(([i]) => i);
|
|
925
|
-
const className = queueCompiledClass(known);
|
|
926
|
-
return [className, ...replacements].join(" ");
|
|
927
|
-
}
|
|
928
|
-
const processedMap = /* @__PURE__ */ new Set();
|
|
929
|
-
for (const match of classes) {
|
|
930
|
-
let body = expandVariantGroup(match[2].trim());
|
|
931
|
-
let replaced = false;
|
|
932
|
-
const expressions = [...body.matchAll(classesInsideExpressionsRE)];
|
|
933
|
-
for (const expression of expressions) {
|
|
934
|
-
const replacement2 = await sortKnownAndUnknownClasses(expression[2].trim());
|
|
935
|
-
if (replacement2) {
|
|
936
|
-
body = body.replace(expression[2], replacement2);
|
|
937
|
-
replaced = true;
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
const replacement = await sortKnownAndUnknownClasses(body);
|
|
941
|
-
if (replacement) {
|
|
942
|
-
body = body.replace(body, replacement);
|
|
943
|
-
replaced = true;
|
|
944
|
-
}
|
|
945
|
-
if (!replaced)
|
|
946
|
-
continue;
|
|
947
|
-
const start = match.index + (match[1] ? 7 : 6);
|
|
948
|
-
const end = match.index + match[0].length - (match[1] ? 1 : 0);
|
|
949
|
-
processedMap.add(start);
|
|
950
|
-
s.overwrite(start, end, body);
|
|
951
|
-
}
|
|
952
|
-
for (const match of classDirectives) {
|
|
953
|
-
const token = match[1];
|
|
954
|
-
const result = !!await uno.parseToken(token);
|
|
955
|
-
if (!result)
|
|
956
|
-
continue;
|
|
957
|
-
const className = queueCompiledClass([token]);
|
|
958
|
-
const start = match.index + "class:".length;
|
|
959
|
-
processedMap.add(start);
|
|
960
|
-
s.overwrite(start, start + match[1].length, className);
|
|
961
|
-
}
|
|
962
|
-
for (const match of classDirectivesShorthand) {
|
|
963
|
-
const token = match[1];
|
|
964
|
-
const result = !!await uno.parseToken(token);
|
|
965
|
-
if (!result)
|
|
966
|
-
continue;
|
|
967
|
-
const className = queueCompiledClass([token]);
|
|
968
|
-
const start = match.index + "class:".length;
|
|
969
|
-
processedMap.add(start);
|
|
970
|
-
s.overwrite(start, start + match[1].length, `${className}={${token}}`);
|
|
971
|
-
}
|
|
972
|
-
const templateCode = code.replace(/<(script|style)[^>]*>[\s\S]*?<\/\1\s*>/g, (match) => Array(match.length).fill(" ").join(""));
|
|
973
|
-
const { matched } = await uno.generate(templateCode, { preflights: false, safelist: false, minify: true });
|
|
974
|
-
for (const token of matched) {
|
|
975
|
-
const match = token.match(attributifyRE);
|
|
976
|
-
if (match) {
|
|
977
|
-
const [, name, value] = match;
|
|
978
|
-
if (!value) {
|
|
979
|
-
let start = 0;
|
|
980
|
-
templateCode.split(/([\s"'`;*]|:\(|\)"|\)\s)/g).forEach((i) => {
|
|
981
|
-
const end = start + i.length;
|
|
982
|
-
if (i === name && !processedMap.has(start)) {
|
|
983
|
-
const className = queueCompiledClass([name]);
|
|
984
|
-
s.appendLeft(start, `class:${className}={true} `);
|
|
985
|
-
s.overwrite(start, end, "");
|
|
986
|
-
}
|
|
987
|
-
start = end;
|
|
988
|
-
});
|
|
989
|
-
} else {
|
|
990
|
-
const regex = new RegExp(`(${escapeRegExp(name)}=)(['"])[^\\2]*?${escapeRegExp(value)}[^\\2]*?\\2`, "g");
|
|
991
|
-
for (const match2 of templateCode.matchAll(regex)) {
|
|
992
|
-
const escaped = match2[1];
|
|
993
|
-
const body = match2[0].slice(escaped.length);
|
|
994
|
-
let bodyIndex = body.match(`[\\b\\s'"]${escapeRegExp(value)}[\\b\\s'"]`)?.index ?? -1;
|
|
995
|
-
if (body[bodyIndex]?.match(/[\s'"]/))
|
|
996
|
-
bodyIndex++;
|
|
997
|
-
if (bodyIndex < 0)
|
|
998
|
-
return;
|
|
999
|
-
const [, base] = await uno.matchVariants(value);
|
|
1000
|
-
const variants = value.replace(base, "");
|
|
1001
|
-
const className = queueCompiledClass([`${variants + name}-${base}`]);
|
|
1002
|
-
s.appendLeft(match2.index, `class:${className}={true} `);
|
|
1003
|
-
s.overwrite(match2.index, match2.index + match2[0].length, "");
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
uno.config.shortcuts = [...originalShortcuts, ...Object.entries(shortcuts)];
|
|
1009
|
-
const { css } = await uno.generate(toGenerate, { preflights: false, safelist: false, minify: true });
|
|
1010
|
-
styles += wrapSelectorsWithGlobal(css);
|
|
1011
|
-
uno.config.shortcuts = originalShortcuts;
|
|
1012
|
-
if (toGenerate.size > 0 || s.hasChanged()) {
|
|
1013
|
-
code = s.toString();
|
|
1014
|
-
map = s.generateMap({ hires: true, source: id });
|
|
1015
|
-
} else {
|
|
1016
|
-
return;
|
|
1017
|
-
}
|
|
1018
|
-
if (alreadyHasStyles) {
|
|
1019
|
-
return {
|
|
1020
|
-
code: code.replace(/(<style[^>]*>)/, `$1${styles}`),
|
|
1021
|
-
map
|
|
1022
|
-
};
|
|
1023
|
-
}
|
|
1024
|
-
return {
|
|
1025
|
-
code: `${code}
|
|
1026
|
-
<style>${styles}</style>`,
|
|
1027
|
-
map
|
|
1028
|
-
};
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
function SvelteScopedPlugin({ ready, uno }) {
|
|
1032
|
-
let viteConfig;
|
|
1033
|
-
let filter = createFilter([/\.svelte$/, /\.svelte\.md$/, /\.svx$/], defaultExclude);
|
|
1034
|
-
return {
|
|
1035
|
-
name: "unocss:svelte-scoped",
|
|
1036
|
-
enforce: "pre",
|
|
1037
|
-
async configResolved(_viteConfig) {
|
|
1038
|
-
viteConfig = _viteConfig;
|
|
1039
|
-
const { config } = await ready;
|
|
1040
|
-
filter = createFilter(
|
|
1041
|
-
config.include || [/\.svelte$/, /\.svelte\.md$/, /\.svx$/],
|
|
1042
|
-
config.exclude || defaultExclude
|
|
1043
|
-
);
|
|
1044
|
-
},
|
|
1045
|
-
transform(code, id) {
|
|
1046
|
-
if (!filter(id))
|
|
1047
|
-
return;
|
|
1048
|
-
return transformSvelteSFC(code, id, uno, { combine: viteConfig.command === "build" });
|
|
1049
|
-
},
|
|
1050
|
-
handleHotUpdate(ctx) {
|
|
1051
|
-
const read = ctx.read;
|
|
1052
|
-
if (filter(ctx.file)) {
|
|
1053
|
-
ctx.read = async () => {
|
|
1054
|
-
const code = await read();
|
|
1055
|
-
return (await transformSvelteSFC(code, ctx.file, uno, { combine: viteConfig.command === "build" }))?.code || code;
|
|
1056
|
-
};
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
};
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
843
|
function ShadowDomModuleModePlugin({ uno }) {
|
|
1063
844
|
const partExtractorRegex = /^part-\[(.+)]:/;
|
|
1064
845
|
const nameRegexp = /<([^\s^!>]+)\s*([^>]*)>/;
|
|
@@ -1349,7 +1130,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
|
|
|
1349
1130
|
} else if (mode === "vue-scoped") {
|
|
1350
1131
|
plugins.push(VueScopedPlugin(ctx));
|
|
1351
1132
|
} else if (mode === "svelte-scoped") {
|
|
1352
|
-
|
|
1133
|
+
throw new Error("[unocss] svelte-scoped mode is now its own package, please use @unocss/svelte-scoped according to the docs");
|
|
1353
1134
|
} else if (mode === "shadow-dom") {
|
|
1354
1135
|
plugins.push(ShadowDomModuleModePlugin(ctx));
|
|
1355
1136
|
} else if (mode === "global") {
|
|
@@ -1365,4 +1146,4 @@ function UnocssPlugin(configOrPath, defaults = {}) {
|
|
|
1365
1146
|
return plugins.filter(Boolean);
|
|
1366
1147
|
}
|
|
1367
1148
|
|
|
1368
|
-
export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin,
|
|
1149
|
+
export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, VueScopedPlugin, UnocssPlugin as default, defineConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.1",
|
|
4
4
|
"description": "The Vite plugin for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,15 +47,15 @@
|
|
|
47
47
|
"chokidar": "^3.5.3",
|
|
48
48
|
"fast-glob": "^3.2.12",
|
|
49
49
|
"magic-string": "^0.30.0",
|
|
50
|
-
"@unocss/config": "0.
|
|
51
|
-
"@unocss/core": "0.
|
|
52
|
-
"@unocss/inspector": "0.
|
|
53
|
-
"@unocss/scope": "0.
|
|
54
|
-
"@unocss/transformer-directives": "0.
|
|
50
|
+
"@unocss/config": "0.52.1",
|
|
51
|
+
"@unocss/core": "0.52.1",
|
|
52
|
+
"@unocss/inspector": "0.52.1",
|
|
53
|
+
"@unocss/scope": "0.52.1",
|
|
54
|
+
"@unocss/transformer-directives": "0.52.1"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"vite": "^4.3.
|
|
58
|
-
"@unocss/shared-integration": "0.
|
|
57
|
+
"vite": "^4.3.8",
|
|
58
|
+
"@unocss/shared-integration": "0.52.1"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "unbuild",
|