@unocss/vite 0.51.4 → 0.51.5

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 CHANGED
@@ -862,10 +862,11 @@ function hash(str) {
862
862
  return `00000${(hval >>> 0).toString(36)}`.slice(-6);
863
863
  }
864
864
 
865
- const classesRE = /class=(["'\`])([\S\s]+?)\1/g;
865
+ const classesRE = /class=(["'\`])([^\{][\S\s]*?)\1/g;
866
+ const classesExpressionsRE = /class=(["'\`])?(\{[\S\s]+?\})\1/g;
866
867
  const classesDirectivesRE = /class:([\S]+?)={/g;
867
- const classDirectivesShorthandRE = /class:([^=>\s/]+)[{>\s/]/g;
868
- const classesFromInlineConditionalsRE = /'([\S\s]+?)'/g;
868
+ const classesDirectivesShorthandRE = /class:([^=>\s/]+)[{>\s/]/g;
869
+ const classesInsideExpressionsRE = /(["'\`])([\S\s]+?)\1/g;
869
870
  async function transformSvelteSFC(code, id, uno, options = {}) {
870
871
  const {
871
872
  classPrefix = "uno-",
@@ -881,9 +882,9 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
881
882
  const { css: css2 } = await uno.generate("", { preflights, safelist });
882
883
  styles = css2;
883
884
  }
884
- const classes = [...code.matchAll(classesRE)];
885
+ const classes = [...code.matchAll(classesRE), ...code.matchAll(classesExpressionsRE)];
885
886
  const classDirectives = [...code.matchAll(classesDirectivesRE)];
886
- const classDirectivesShorthand = [...code.matchAll(classDirectivesShorthandRE)];
887
+ const classDirectivesShorthand = [...code.matchAll(classesDirectivesShorthandRE)];
887
888
  const originalShortcuts = uno.config.shortcuts;
888
889
  const shortcuts = {};
889
890
  const toGenerate = /* @__PURE__ */ new Set();
@@ -933,19 +934,26 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
933
934
  const processedMap = /* @__PURE__ */ new Set();
934
935
  for (const match of classes) {
935
936
  let body = core.expandVariantGroup(match[2].trim());
936
- const inlineConditionals = [...body.matchAll(classesFromInlineConditionalsRE)];
937
- for (const conditional of inlineConditionals) {
938
- const replacement2 = await sortKnownAndUnknownClasses(conditional[1].trim());
939
- if (replacement2)
940
- body = body.replace(conditional[0], `'${replacement2}'`);
937
+ let replaced = false;
938
+ const expressions = [...body.matchAll(classesInsideExpressionsRE)];
939
+ for (const expression of expressions) {
940
+ const replacement2 = await sortKnownAndUnknownClasses(expression[2].trim());
941
+ if (replacement2) {
942
+ body = body.replace(expression[2], replacement2);
943
+ replaced = true;
944
+ }
941
945
  }
942
946
  const replacement = await sortKnownAndUnknownClasses(body);
943
947
  if (replacement) {
944
- const start = match.index + 7;
945
- const end = match.index + match[0].length - 1;
946
- processedMap.add(start);
947
- s.overwrite(start, end, replacement);
948
+ body = body.replace(body, replacement);
949
+ replaced = true;
948
950
  }
951
+ if (!replaced)
952
+ continue;
953
+ const start = match.index + (match[1] ? 7 : 6);
954
+ const end = match.index + match[0].length - (match[1] ? 1 : 0);
955
+ processedMap.add(start);
956
+ s.overwrite(start, end, body);
949
957
  }
950
958
  for (const match of classDirectives) {
951
959
  const token = match[1];
package/dist/index.mjs CHANGED
@@ -849,10 +849,11 @@ function hash(str) {
849
849
  return `00000${(hval >>> 0).toString(36)}`.slice(-6);
850
850
  }
851
851
 
852
- const classesRE = /class=(["'\`])([\S\s]+?)\1/g;
852
+ const classesRE = /class=(["'\`])([^\{][\S\s]*?)\1/g;
853
+ const classesExpressionsRE = /class=(["'\`])?(\{[\S\s]+?\})\1/g;
853
854
  const classesDirectivesRE = /class:([\S]+?)={/g;
854
- const classDirectivesShorthandRE = /class:([^=>\s/]+)[{>\s/]/g;
855
- const classesFromInlineConditionalsRE = /'([\S\s]+?)'/g;
855
+ const classesDirectivesShorthandRE = /class:([^=>\s/]+)[{>\s/]/g;
856
+ const classesInsideExpressionsRE = /(["'\`])([\S\s]+?)\1/g;
856
857
  async function transformSvelteSFC(code, id, uno, options = {}) {
857
858
  const {
858
859
  classPrefix = "uno-",
@@ -868,9 +869,9 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
868
869
  const { css: css2 } = await uno.generate("", { preflights, safelist });
869
870
  styles = css2;
870
871
  }
871
- const classes = [...code.matchAll(classesRE)];
872
+ const classes = [...code.matchAll(classesRE), ...code.matchAll(classesExpressionsRE)];
872
873
  const classDirectives = [...code.matchAll(classesDirectivesRE)];
873
- const classDirectivesShorthand = [...code.matchAll(classDirectivesShorthandRE)];
874
+ const classDirectivesShorthand = [...code.matchAll(classesDirectivesShorthandRE)];
874
875
  const originalShortcuts = uno.config.shortcuts;
875
876
  const shortcuts = {};
876
877
  const toGenerate = /* @__PURE__ */ new Set();
@@ -920,19 +921,26 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
920
921
  const processedMap = /* @__PURE__ */ new Set();
921
922
  for (const match of classes) {
922
923
  let body = expandVariantGroup(match[2].trim());
923
- const inlineConditionals = [...body.matchAll(classesFromInlineConditionalsRE)];
924
- for (const conditional of inlineConditionals) {
925
- const replacement2 = await sortKnownAndUnknownClasses(conditional[1].trim());
926
- if (replacement2)
927
- body = body.replace(conditional[0], `'${replacement2}'`);
924
+ let replaced = false;
925
+ const expressions = [...body.matchAll(classesInsideExpressionsRE)];
926
+ for (const expression of expressions) {
927
+ const replacement2 = await sortKnownAndUnknownClasses(expression[2].trim());
928
+ if (replacement2) {
929
+ body = body.replace(expression[2], replacement2);
930
+ replaced = true;
931
+ }
928
932
  }
929
933
  const replacement = await sortKnownAndUnknownClasses(body);
930
934
  if (replacement) {
931
- const start = match.index + 7;
932
- const end = match.index + match[0].length - 1;
933
- processedMap.add(start);
934
- s.overwrite(start, end, replacement);
935
+ body = body.replace(body, replacement);
936
+ replaced = true;
935
937
  }
938
+ if (!replaced)
939
+ continue;
940
+ const start = match.index + (match[1] ? 7 : 6);
941
+ const end = match.index + match[0].length - (match[1] ? 1 : 0);
942
+ processedMap.add(start);
943
+ s.overwrite(start, end, body);
936
944
  }
937
945
  for (const match of classDirectives) {
938
946
  const token = match[1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.51.4",
3
+ "version": "0.51.5",
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.4",
51
- "@unocss/core": "0.51.4",
52
- "@unocss/inspector": "0.51.4",
53
- "@unocss/scope": "0.51.4",
54
- "@unocss/transformer-directives": "0.51.4"
50
+ "@unocss/config": "0.51.5",
51
+ "@unocss/core": "0.51.5",
52
+ "@unocss/inspector": "0.51.5",
53
+ "@unocss/scope": "0.51.5",
54
+ "@unocss/transformer-directives": "0.51.5"
55
55
  },
56
56
  "devDependencies": {
57
57
  "vite": "^4.2.1",
58
- "@unocss/shared-integration": "0.51.4"
58
+ "@unocss/shared-integration": "0.51.5"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "unbuild",