@unocss/transformer-directives 0.44.4 → 0.45.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 CHANGED
@@ -45,7 +45,9 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
45
45
  if (!body)
46
46
  return;
47
47
  const classNames = core.expandVariantGroup(body).split(/\s+/g).map((className) => className.trim().replace(/\\/, ""));
48
- const utils = (await Promise.all(classNames.map((i) => uno.parseToken(i, "-")))).filter(core.notNull).flat().sort((a, b) => a[0] - b[0]).sort((a, b) => (a[3] ? uno.parentOrders.get(a[3]) ?? 0 : 0) - (b[3] ? uno.parentOrders.get(b[3]) ?? 0 : 0)).reduce((acc, item) => {
48
+ const utils = (await Promise.all(
49
+ classNames.map((i) => uno.parseToken(i, "-"))
50
+ )).filter(core.notNull).flat().sort((a, b) => a[0] - b[0]).sort((a, b) => (a[3] ? uno.parentOrders.get(a[3]) ?? 0 : 0) - (b[3] ? uno.parentOrders.get(b[3]) ?? 0 : 0)).reduce((acc, item) => {
49
51
  const target = acc.find((i) => i[1] === item[1] && i[3] === item[3]);
50
52
  if (target)
51
53
  target[2] += item[2];
@@ -83,7 +85,10 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
83
85
  code.appendRight(calcOffset(childNode.loc.end.offset), body2);
84
86
  }
85
87
  }
86
- code.remove(calcOffset(childNode.loc.start.offset), calcOffset(childNode.loc.end.offset));
88
+ code.remove(
89
+ calcOffset(childNode.loc.start.offset),
90
+ calcOffset(childNode.loc.end.offset)
91
+ );
87
92
  };
88
93
  const handleThemeFn = (node) => {
89
94
  const value = node.value;
@@ -108,7 +113,11 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
108
113
  return true;
109
114
  });
110
115
  if (typeof value2 === "string") {
111
- code.overwrite(offset2 + match.index, offset2 + match.index + match[0].length, value2);
116
+ code.overwrite(
117
+ offset2 + match.index,
118
+ offset2 + match.index + match[0].length,
119
+ value2
120
+ );
112
121
  } else if (throwOnMissing) {
113
122
  throw new Error(`theme of "${rawArg.slice(1, -1)}" did not found`);
114
123
  }
@@ -119,11 +128,13 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
119
128
  if (hasThemeFn && node.type === "Declaration")
120
129
  handleThemeFn(node);
121
130
  if (isApply && node.type === "Rule") {
122
- await Promise.all(node.block.children.map(async (childNode, _childItem) => {
123
- if (childNode.type === "Raw")
124
- return transformDirectives(code, uno, options, filename, childNode.value, calcOffset(childNode.loc.start.offset));
125
- await handleApply(node, childNode);
126
- }).toArray());
131
+ await Promise.all(
132
+ node.block.children.map(async (childNode, _childItem) => {
133
+ if (childNode.type === "Raw")
134
+ return transformDirectives(code, uno, options, filename, childNode.value, calcOffset(childNode.loc.start.offset));
135
+ await handleApply(node, childNode);
136
+ }).toArray()
137
+ );
127
138
  }
128
139
  };
129
140
  cssTree.walk(ast, (...args) => stack.push(processNode(...args)));
package/dist/index.mjs CHANGED
@@ -41,7 +41,9 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
41
41
  if (!body)
42
42
  return;
43
43
  const classNames = expandVariantGroup(body).split(/\s+/g).map((className) => className.trim().replace(/\\/, ""));
44
- const utils = (await Promise.all(classNames.map((i) => uno.parseToken(i, "-")))).filter(notNull).flat().sort((a, b) => a[0] - b[0]).sort((a, b) => (a[3] ? uno.parentOrders.get(a[3]) ?? 0 : 0) - (b[3] ? uno.parentOrders.get(b[3]) ?? 0 : 0)).reduce((acc, item) => {
44
+ const utils = (await Promise.all(
45
+ classNames.map((i) => uno.parseToken(i, "-"))
46
+ )).filter(notNull).flat().sort((a, b) => a[0] - b[0]).sort((a, b) => (a[3] ? uno.parentOrders.get(a[3]) ?? 0 : 0) - (b[3] ? uno.parentOrders.get(b[3]) ?? 0 : 0)).reduce((acc, item) => {
45
47
  const target = acc.find((i) => i[1] === item[1] && i[3] === item[3]);
46
48
  if (target)
47
49
  target[2] += item[2];
@@ -79,7 +81,10 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
79
81
  code.appendRight(calcOffset(childNode.loc.end.offset), body2);
80
82
  }
81
83
  }
82
- code.remove(calcOffset(childNode.loc.start.offset), calcOffset(childNode.loc.end.offset));
84
+ code.remove(
85
+ calcOffset(childNode.loc.start.offset),
86
+ calcOffset(childNode.loc.end.offset)
87
+ );
83
88
  };
84
89
  const handleThemeFn = (node) => {
85
90
  const value = node.value;
@@ -104,7 +109,11 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
104
109
  return true;
105
110
  });
106
111
  if (typeof value2 === "string") {
107
- code.overwrite(offset2 + match.index, offset2 + match.index + match[0].length, value2);
112
+ code.overwrite(
113
+ offset2 + match.index,
114
+ offset2 + match.index + match[0].length,
115
+ value2
116
+ );
108
117
  } else if (throwOnMissing) {
109
118
  throw new Error(`theme of "${rawArg.slice(1, -1)}" did not found`);
110
119
  }
@@ -115,11 +124,13 @@ async function transformDirectives(code, uno, options, filename, originalCode, o
115
124
  if (hasThemeFn && node.type === "Declaration")
116
125
  handleThemeFn(node);
117
126
  if (isApply && node.type === "Rule") {
118
- await Promise.all(node.block.children.map(async (childNode, _childItem) => {
119
- if (childNode.type === "Raw")
120
- return transformDirectives(code, uno, options, filename, childNode.value, calcOffset(childNode.loc.start.offset));
121
- await handleApply(node, childNode);
122
- }).toArray());
127
+ await Promise.all(
128
+ node.block.children.map(async (childNode, _childItem) => {
129
+ if (childNode.type === "Raw")
130
+ return transformDirectives(code, uno, options, filename, childNode.value, calcOffset(childNode.loc.start.offset));
131
+ await handleApply(node, childNode);
132
+ }).toArray()
133
+ );
123
134
  }
124
135
  };
125
136
  walk(ast, (...args) => stack.push(processNode(...args)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/transformer-directives",
3
- "version": "0.44.4",
3
+ "version": "0.45.1",
4
4
  "description": "UnoCSS transformer for `@apply` directive",
5
5
  "author": "hannoeru <me@hanlee.co>",
6
6
  "license": "MIT",
@@ -31,7 +31,7 @@
31
31
  "dist"
32
32
  ],
33
33
  "dependencies": {
34
- "@unocss/core": "0.44.4",
34
+ "@unocss/core": "0.45.1",
35
35
  "css-tree": "^2.1.0"
36
36
  },
37
37
  "devDependencies": {