@unocss/vite 0.50.1 → 0.50.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/dist/index.cjs +49 -18
- package/dist/index.mjs +50 -19
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -400,7 +400,11 @@ function GlobalModeBuildPlugin(ctx) {
|
|
|
400
400
|
if (config.build.rollupOptions.output) {
|
|
401
401
|
const outputOptions = config.build.rollupOptions.output;
|
|
402
402
|
const outputDirs = Array.isArray(outputOptions) ? outputOptions.map((option) => option.dir).filter(Boolean) : outputOptions.dir ? [outputOptions.dir] : [];
|
|
403
|
-
|
|
403
|
+
outputDirs.forEach((dir) => {
|
|
404
|
+
distDirs.push(dir);
|
|
405
|
+
if (!path.isAbsolute(dir))
|
|
406
|
+
distDirs.push(path.resolve(config.root, dir));
|
|
407
|
+
});
|
|
404
408
|
}
|
|
405
409
|
const cssPostPlugin = config.plugins.find((i) => i.name === "vite:css-post");
|
|
406
410
|
const cssPlugin = config.plugins.find((i) => i.name === "vite:css");
|
|
@@ -861,19 +865,6 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
|
861
865
|
const classes = [...code.matchAll(classesRE)];
|
|
862
866
|
const classDirectives = [...code.matchAll(classesDirectivesRE)];
|
|
863
867
|
const classDirectivesShorthand = [...code.matchAll(classDirectivesShorthandRE)];
|
|
864
|
-
if (!classes.length && !classDirectives.length && !classDirectivesShorthand.length) {
|
|
865
|
-
if (preflights || safelist) {
|
|
866
|
-
if (alreadyHasStyles) {
|
|
867
|
-
return {
|
|
868
|
-
code: code.replace(/(<style[^>]*>)/, `$1${styles}`)
|
|
869
|
-
};
|
|
870
|
-
}
|
|
871
|
-
return { code: `${code}
|
|
872
|
-
<style>${styles}</style>` };
|
|
873
|
-
} else {
|
|
874
|
-
return;
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
868
|
const originalShortcuts = uno.config.shortcuts;
|
|
878
869
|
const shortcuts = {};
|
|
879
870
|
const toGenerate = /* @__PURE__ */ new Set();
|
|
@@ -913,13 +904,14 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
|
913
904
|
async function sortKnownAndUnknownClasses(str) {
|
|
914
905
|
const classArr = str.split(/\s+/);
|
|
915
906
|
const result = await Promise.all(classArr.filter(Boolean).map(async (t) => [t, !!await uno.parseToken(t)]));
|
|
916
|
-
const known = result.filter(([,
|
|
907
|
+
const known = result.filter(([, matched2]) => matched2).map(([t]) => t).sort();
|
|
917
908
|
if (!known.length)
|
|
918
909
|
return null;
|
|
919
|
-
const replacements = result.filter(([,
|
|
910
|
+
const replacements = result.filter(([, matched2]) => !matched2).map(([i]) => i);
|
|
920
911
|
const className = queueCompiledClass(known);
|
|
921
912
|
return [className, ...replacements].join(" ");
|
|
922
913
|
}
|
|
914
|
+
const processedMap = /* @__PURE__ */ new Set();
|
|
923
915
|
for (const match of classes) {
|
|
924
916
|
let body = core.expandVariantGroup(match[2].trim());
|
|
925
917
|
const inlineConditionals = [...body.matchAll(classesFromInlineConditionalsRE)];
|
|
@@ -930,8 +922,10 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
|
930
922
|
}
|
|
931
923
|
const replacement = await sortKnownAndUnknownClasses(body);
|
|
932
924
|
if (replacement) {
|
|
933
|
-
const start = match.index;
|
|
934
|
-
|
|
925
|
+
const start = match.index + 7;
|
|
926
|
+
const end = match.index + match[0].length - 1;
|
|
927
|
+
processedMap.add(start);
|
|
928
|
+
s.overwrite(start, end, replacement);
|
|
935
929
|
}
|
|
936
930
|
}
|
|
937
931
|
for (const match of classDirectives) {
|
|
@@ -941,6 +935,7 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
|
941
935
|
continue;
|
|
942
936
|
const className = queueCompiledClass([token]);
|
|
943
937
|
const start = match.index + "class:".length;
|
|
938
|
+
processedMap.add(start);
|
|
944
939
|
s.overwrite(start, start + match[1].length, className);
|
|
945
940
|
}
|
|
946
941
|
for (const match of classDirectivesShorthand) {
|
|
@@ -950,8 +945,44 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
|
950
945
|
continue;
|
|
951
946
|
const className = queueCompiledClass([token]);
|
|
952
947
|
const start = match.index + "class:".length;
|
|
948
|
+
processedMap.add(start);
|
|
953
949
|
s.overwrite(start, start + match[1].length, `${className}={${token}}`);
|
|
954
950
|
}
|
|
951
|
+
const { matched } = await uno.generate(code, { preflights: false, safelist: false, minify: true });
|
|
952
|
+
for (const token of matched) {
|
|
953
|
+
const match = token.match(core.attributifyRE);
|
|
954
|
+
if (match) {
|
|
955
|
+
const [, name, value] = match;
|
|
956
|
+
if (!value) {
|
|
957
|
+
let start = 0;
|
|
958
|
+
code.split(/([\s"'`;*]|:\(|\)"|\)\s)/g).forEach((i) => {
|
|
959
|
+
const end = start + i.length;
|
|
960
|
+
if (i === name && !processedMap.has(start)) {
|
|
961
|
+
const className = queueCompiledClass([name]);
|
|
962
|
+
s.appendLeft(start, `class:${className}={true} `);
|
|
963
|
+
s.overwrite(start, end, "");
|
|
964
|
+
}
|
|
965
|
+
start = end;
|
|
966
|
+
});
|
|
967
|
+
} else {
|
|
968
|
+
const regex = new RegExp(`(${core.escapeRegExp(name)}=)(['"])[^\\2]*?${core.escapeRegExp(value)}[^\\2]*?\\2`, "g");
|
|
969
|
+
for (const match2 of code.matchAll(regex)) {
|
|
970
|
+
const escaped = match2[1];
|
|
971
|
+
const body = match2[0].slice(escaped.length);
|
|
972
|
+
let bodyIndex = body.match(`[\\b\\s'"]${core.escapeRegExp(value)}[\\b\\s'"]`)?.index ?? -1;
|
|
973
|
+
if (body[bodyIndex]?.match(/[\s'"]/))
|
|
974
|
+
bodyIndex++;
|
|
975
|
+
if (bodyIndex < 0)
|
|
976
|
+
return;
|
|
977
|
+
const [, base] = await uno.matchVariants(value);
|
|
978
|
+
const variants = value.replace(base, "");
|
|
979
|
+
const className = queueCompiledClass([`${variants + name}-${base}`]);
|
|
980
|
+
s.appendLeft(match2.index, `class:${className}={true} `);
|
|
981
|
+
s.overwrite(match2.index, match2.index + match2[0].length, "");
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
955
986
|
uno.config.shortcuts = [...originalShortcuts, ...Object.entries(shortcuts)];
|
|
956
987
|
const { css } = await uno.generate(toGenerate, { preflights: false, safelist: false, minify: true });
|
|
957
988
|
styles += wrapSelectorsWithGlobal(css);
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import UnocssInspector from '@unocss/inspector';
|
|
2
|
-
import { cssIdRE, createGenerator, BetterMap, notNull, expandVariantGroup, toEscapedSelector } from '@unocss/core';
|
|
2
|
+
import { cssIdRE, createGenerator, BetterMap, notNull, expandVariantGroup, attributifyRE, escapeRegExp, toEscapedSelector } from '@unocss/core';
|
|
3
3
|
import { createFilter } from '@rollup/pluginutils';
|
|
4
4
|
import { loadConfig } from '@unocss/config';
|
|
5
5
|
import { createHash } from 'crypto';
|
|
@@ -387,7 +387,11 @@ function GlobalModeBuildPlugin(ctx) {
|
|
|
387
387
|
if (config.build.rollupOptions.output) {
|
|
388
388
|
const outputOptions = config.build.rollupOptions.output;
|
|
389
389
|
const outputDirs = Array.isArray(outputOptions) ? outputOptions.map((option) => option.dir).filter(Boolean) : outputOptions.dir ? [outputOptions.dir] : [];
|
|
390
|
-
|
|
390
|
+
outputDirs.forEach((dir) => {
|
|
391
|
+
distDirs.push(dir);
|
|
392
|
+
if (!isAbsolute(dir))
|
|
393
|
+
distDirs.push(resolve(config.root, dir));
|
|
394
|
+
});
|
|
391
395
|
}
|
|
392
396
|
const cssPostPlugin = config.plugins.find((i) => i.name === "vite:css-post");
|
|
393
397
|
const cssPlugin = config.plugins.find((i) => i.name === "vite:css");
|
|
@@ -848,19 +852,6 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
|
848
852
|
const classes = [...code.matchAll(classesRE)];
|
|
849
853
|
const classDirectives = [...code.matchAll(classesDirectivesRE)];
|
|
850
854
|
const classDirectivesShorthand = [...code.matchAll(classDirectivesShorthandRE)];
|
|
851
|
-
if (!classes.length && !classDirectives.length && !classDirectivesShorthand.length) {
|
|
852
|
-
if (preflights || safelist) {
|
|
853
|
-
if (alreadyHasStyles) {
|
|
854
|
-
return {
|
|
855
|
-
code: code.replace(/(<style[^>]*>)/, `$1${styles}`)
|
|
856
|
-
};
|
|
857
|
-
}
|
|
858
|
-
return { code: `${code}
|
|
859
|
-
<style>${styles}</style>` };
|
|
860
|
-
} else {
|
|
861
|
-
return;
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
855
|
const originalShortcuts = uno.config.shortcuts;
|
|
865
856
|
const shortcuts = {};
|
|
866
857
|
const toGenerate = /* @__PURE__ */ new Set();
|
|
@@ -900,13 +891,14 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
|
900
891
|
async function sortKnownAndUnknownClasses(str) {
|
|
901
892
|
const classArr = str.split(/\s+/);
|
|
902
893
|
const result = await Promise.all(classArr.filter(Boolean).map(async (t) => [t, !!await uno.parseToken(t)]));
|
|
903
|
-
const known = result.filter(([,
|
|
894
|
+
const known = result.filter(([, matched2]) => matched2).map(([t]) => t).sort();
|
|
904
895
|
if (!known.length)
|
|
905
896
|
return null;
|
|
906
|
-
const replacements = result.filter(([,
|
|
897
|
+
const replacements = result.filter(([, matched2]) => !matched2).map(([i]) => i);
|
|
907
898
|
const className = queueCompiledClass(known);
|
|
908
899
|
return [className, ...replacements].join(" ");
|
|
909
900
|
}
|
|
901
|
+
const processedMap = /* @__PURE__ */ new Set();
|
|
910
902
|
for (const match of classes) {
|
|
911
903
|
let body = expandVariantGroup(match[2].trim());
|
|
912
904
|
const inlineConditionals = [...body.matchAll(classesFromInlineConditionalsRE)];
|
|
@@ -917,8 +909,10 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
|
917
909
|
}
|
|
918
910
|
const replacement = await sortKnownAndUnknownClasses(body);
|
|
919
911
|
if (replacement) {
|
|
920
|
-
const start = match.index;
|
|
921
|
-
|
|
912
|
+
const start = match.index + 7;
|
|
913
|
+
const end = match.index + match[0].length - 1;
|
|
914
|
+
processedMap.add(start);
|
|
915
|
+
s.overwrite(start, end, replacement);
|
|
922
916
|
}
|
|
923
917
|
}
|
|
924
918
|
for (const match of classDirectives) {
|
|
@@ -928,6 +922,7 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
|
928
922
|
continue;
|
|
929
923
|
const className = queueCompiledClass([token]);
|
|
930
924
|
const start = match.index + "class:".length;
|
|
925
|
+
processedMap.add(start);
|
|
931
926
|
s.overwrite(start, start + match[1].length, className);
|
|
932
927
|
}
|
|
933
928
|
for (const match of classDirectivesShorthand) {
|
|
@@ -937,8 +932,44 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
|
937
932
|
continue;
|
|
938
933
|
const className = queueCompiledClass([token]);
|
|
939
934
|
const start = match.index + "class:".length;
|
|
935
|
+
processedMap.add(start);
|
|
940
936
|
s.overwrite(start, start + match[1].length, `${className}={${token}}`);
|
|
941
937
|
}
|
|
938
|
+
const { matched } = await uno.generate(code, { preflights: false, safelist: false, minify: true });
|
|
939
|
+
for (const token of matched) {
|
|
940
|
+
const match = token.match(attributifyRE);
|
|
941
|
+
if (match) {
|
|
942
|
+
const [, name, value] = match;
|
|
943
|
+
if (!value) {
|
|
944
|
+
let start = 0;
|
|
945
|
+
code.split(/([\s"'`;*]|:\(|\)"|\)\s)/g).forEach((i) => {
|
|
946
|
+
const end = start + i.length;
|
|
947
|
+
if (i === name && !processedMap.has(start)) {
|
|
948
|
+
const className = queueCompiledClass([name]);
|
|
949
|
+
s.appendLeft(start, `class:${className}={true} `);
|
|
950
|
+
s.overwrite(start, end, "");
|
|
951
|
+
}
|
|
952
|
+
start = end;
|
|
953
|
+
});
|
|
954
|
+
} else {
|
|
955
|
+
const regex = new RegExp(`(${escapeRegExp(name)}=)(['"])[^\\2]*?${escapeRegExp(value)}[^\\2]*?\\2`, "g");
|
|
956
|
+
for (const match2 of code.matchAll(regex)) {
|
|
957
|
+
const escaped = match2[1];
|
|
958
|
+
const body = match2[0].slice(escaped.length);
|
|
959
|
+
let bodyIndex = body.match(`[\\b\\s'"]${escapeRegExp(value)}[\\b\\s'"]`)?.index ?? -1;
|
|
960
|
+
if (body[bodyIndex]?.match(/[\s'"]/))
|
|
961
|
+
bodyIndex++;
|
|
962
|
+
if (bodyIndex < 0)
|
|
963
|
+
return;
|
|
964
|
+
const [, base] = await uno.matchVariants(value);
|
|
965
|
+
const variants = value.replace(base, "");
|
|
966
|
+
const className = queueCompiledClass([`${variants + name}-${base}`]);
|
|
967
|
+
s.appendLeft(match2.index, `class:${className}={true} `);
|
|
968
|
+
s.overwrite(match2.index, match2.index + match2[0].length, "");
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
942
973
|
uno.config.shortcuts = [...originalShortcuts, ...Object.entries(shortcuts)];
|
|
943
974
|
const { css } = await uno.generate(toGenerate, { preflights: false, safelist: false, minify: true });
|
|
944
975
|
styles += wrapSelectorsWithGlobal(css);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.50.
|
|
3
|
+
"version": "0.50.2",
|
|
4
4
|
"description": "The Vite plugin for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,17 +44,17 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@ampproject/remapping": "^2.2.0",
|
|
46
46
|
"@rollup/pluginutils": "^5.0.2",
|
|
47
|
-
"@unocss/config": "0.50.
|
|
48
|
-
"@unocss/core": "0.50.
|
|
49
|
-
"@unocss/inspector": "0.50.
|
|
50
|
-
"@unocss/scope": "0.50.
|
|
51
|
-
"@unocss/transformer-directives": "0.50.
|
|
47
|
+
"@unocss/config": "0.50.2",
|
|
48
|
+
"@unocss/core": "0.50.2",
|
|
49
|
+
"@unocss/inspector": "0.50.2",
|
|
50
|
+
"@unocss/scope": "0.50.2",
|
|
51
|
+
"@unocss/transformer-directives": "0.50.2",
|
|
52
52
|
"chokidar": "^3.5.3",
|
|
53
53
|
"fast-glob": "^3.2.12",
|
|
54
54
|
"magic-string": "^0.30.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@unocss/shared-integration": "0.50.
|
|
57
|
+
"@unocss/shared-integration": "0.50.2",
|
|
58
58
|
"vite": "^4.1.4"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|