@unocss/transformer-directives 66.3.2 → 66.4.0

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.d.mts CHANGED
@@ -38,4 +38,5 @@ interface TransformerDirectivesContext {
38
38
 
39
39
  declare function transformerDirectives(options?: TransformerDirectivesOptions): SourceCodeTransformer;
40
40
 
41
- export { type TransformerDirectivesContext, type TransformerDirectivesOptions, transformerDirectives as default };
41
+ export { transformerDirectives as default };
42
+ export type { TransformerDirectivesContext, TransformerDirectivesOptions };
package/dist/index.d.ts CHANGED
@@ -38,4 +38,5 @@ interface TransformerDirectivesContext {
38
38
 
39
39
  declare function transformerDirectives(options?: TransformerDirectivesOptions): SourceCodeTransformer;
40
40
 
41
- export { type TransformerDirectivesContext, type TransformerDirectivesOptions, transformerDirectives as default };
41
+ export { transformerDirectives as default };
42
+ export type { TransformerDirectivesContext, TransformerDirectivesOptions };
package/dist/index.mjs CHANGED
@@ -154,12 +154,22 @@ async function handleFunction({ code, uno, options }, node) {
154
154
  const { throwOnMissing = true } = options;
155
155
  switch (node.name) {
156
156
  case "theme": {
157
- if (node.children.size !== 1)
157
+ if (!node.children.size)
158
158
  throw new Error("theme() expect exact one argument");
159
159
  if (node.children.first.type !== "String")
160
160
  throw new Error("theme() expect a string argument");
161
+ let defaultValueLoc;
162
+ if (node.children.size > 1) {
163
+ const remains = node.children.toArray().slice(1);
164
+ if (!(remains[0].type === "Operator" && remains[0].value === ","))
165
+ throw new Error("theme() expect a comma between expression string and default value");
166
+ if (remains.length > 1)
167
+ defaultValueLoc = [remains[1].loc.start.offset, node.children.last.loc.end.offset];
168
+ }
161
169
  const themeStr = node.children.first.value;
162
- const value = transformThemeString(themeStr, uno.config.theme, throwOnMissing);
170
+ let value = transformThemeString(themeStr, uno.config.theme, !defaultValueLoc && throwOnMissing);
171
+ if (!value && defaultValueLoc)
172
+ value = code.slice(defaultValueLoc[0], defaultValueLoc[1]);
163
173
  if (value)
164
174
  code.overwrite(node.loc.start.offset, node.loc.end.offset, value);
165
175
  break;
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@unocss/transformer-directives",
3
3
  "type": "module",
4
- "version": "66.3.2",
4
+ "version": "66.4.0",
5
5
  "description": "UnoCSS transformer for `@apply` directive",
6
6
  "author": "hannoeru <me@hanlee.co>",
7
7
  "license": "MIT",
8
8
  "homepage": "https://unocss.dev",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://github.com/unocss/unocss",
11
+ "url": "git+https://github.com/unocss/unocss.git",
12
12
  "directory": "packages-presets/transformer-directives"
13
13
  },
14
14
  "bugs": {
@@ -33,8 +33,8 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "css-tree": "^3.1.0",
36
- "@unocss/core": "66.3.2",
37
- "@unocss/rule-utils": "66.3.2"
36
+ "@unocss/core": "66.4.0",
37
+ "@unocss/rule-utils": "66.4.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "magic-string": "^0.30.17"