@unocss/transformer-directives 0.60.1 → 0.60.3

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.
Files changed (2) hide show
  1. package/dist/index.mjs +10 -5
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -52,7 +52,7 @@ function handleScreen({ code, uno }, node) {
52
52
  }
53
53
  }
54
54
  function calcMaxWidthBySize(size) {
55
- const value = size.match(/^-?[0-9]+\.?[0-9]*/)?.[0] || "";
55
+ const value = size.match(/^-?\d+\.?\d*/)?.[0] || "";
56
56
  const unit = size.slice(value.length);
57
57
  const maxWidth = Number.parseFloat(value) - 0.1;
58
58
  return Number.isNaN(maxWidth) ? size : `${maxWidth}${unit}`;
@@ -71,20 +71,22 @@ async function handleApply(ctx, node) {
71
71
  }
72
72
  async function parseApply({ code, uno, offset, applyVariable }, node, childNode) {
73
73
  const calcOffset = (pos) => offset ? pos + offset : pos;
74
+ const original = code.original;
74
75
  let body;
75
76
  if (childNode.type === "Atrule" && childNode.name === "apply" && childNode.prelude && childNode.prelude.type === "Raw") {
76
77
  body = removeQuotes(childNode.prelude.value.trim());
77
78
  } else if (childNode.type === "Declaration" && applyVariable.includes(childNode.property) && childNode.value.type === "Value") {
78
- let rawValue = code.original.slice(
79
+ let rawValue = original.slice(
79
80
  calcOffset(childNode.value.loc.start.offset),
80
81
  calcOffset(childNode.value.loc.end.offset)
81
- );
82
+ ).trim();
82
83
  rawValue = removeQuotes(rawValue);
83
84
  const items = rawValue.split(/\s+/g).filter(Boolean).map((i) => removeQuotes(i));
84
85
  body = items.join(" ");
85
86
  }
86
87
  if (!body)
87
88
  return;
89
+ body = removeComments(body);
88
90
  const classNames = expandVariantGroup(body).split(/\s+/g).map((className) => className.trim().replace(/\\/, ""));
89
91
  const utils = (await Promise.all(
90
92
  classNames.map((i) => uno.parseToken(i, "-"))
@@ -98,7 +100,7 @@ async function parseApply({ code, uno, offset, applyVariable }, node, childNode)
98
100
  }, []);
99
101
  if (!utils.length)
100
102
  return;
101
- const simicolonOffset = code.toString()[childNode.loc.end.offset] === ";" ? 1 : 0;
103
+ const simicolonOffset = original[calcOffset(childNode.loc.end.offset)] === ";" ? 1 : 0;
102
104
  for (const i of utils) {
103
105
  const [, _selector, body2, parent] = i;
104
106
  const selectorOrGroup = _selector?.replace(regexScopePlaceholder, " ") || _selector;
@@ -126,7 +128,7 @@ async function parseApply({ code, uno, offset, applyVariable }, node, childNode)
126
128
  code.appendLeft(calcOffset(node.loc.end.offset), css);
127
129
  } else {
128
130
  if (body2.includes("@"))
129
- code.appendRight(code.original.length + simicolonOffset, body2);
131
+ code.appendRight(original.length + simicolonOffset, body2);
130
132
  else
131
133
  code.appendRight(calcOffset(childNode.loc.end.offset + simicolonOffset), body2);
132
134
  }
@@ -139,6 +141,9 @@ async function parseApply({ code, uno, offset, applyVariable }, node, childNode)
139
141
  function removeQuotes(value) {
140
142
  return value.replace(/^(['"])(.*)\1$/, "$2");
141
143
  }
144
+ function removeComments(value) {
145
+ return value.replace(/(\/\*(?:.|\n)*?\*\/)|(\/\/.*)/g, "");
146
+ }
142
147
 
143
148
  function handleFunction({ code, uno, options }, node) {
144
149
  const { throwOnMissing = true } = options;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/transformer-directives",
3
3
  "type": "module",
4
- "version": "0.60.1",
4
+ "version": "0.60.3",
5
5
  "description": "UnoCSS transformer for `@apply` directive",
6
6
  "author": "hannoeru <me@hanlee.co>",
7
7
  "license": "MIT",
@@ -33,8 +33,8 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "css-tree": "^2.3.1",
36
- "@unocss/core": "0.60.1",
37
- "@unocss/rule-utils": "0.60.1"
36
+ "@unocss/core": "0.60.3",
37
+ "@unocss/rule-utils": "0.60.3"
38
38
  },
39
39
  "devDependencies": {
40
40
  "magic-string": "^0.30.10"