@unocss/transformer-directives 0.55.6 → 0.56.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.cjs CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const core = require('@unocss/core');
6
6
  const cssTree = require('css-tree');
7
+ const ruleUtils = require('@unocss/rule-utils');
7
8
 
8
9
  const themeFnRE = /theme\((.*?)\)/g;
9
10
  function handleThemeFn({ code, uno, options }, node) {
@@ -17,8 +18,9 @@ function handleThemeFn({ code, uno, options }, node) {
17
18
  const rawArg = match[1].trim();
18
19
  if (!rawArg)
19
20
  throw new Error("theme() expect exact one argument, but got 0");
21
+ const [rawKey, alpha] = rawArg.slice(1, -1).split("/");
20
22
  let value = uno.config.theme;
21
- const keys = rawArg.slice(1, -1).split(".");
23
+ const keys = rawKey.trim().split(".");
22
24
  keys.every((key) => {
23
25
  if (value[key] != null)
24
26
  value = value[key];
@@ -29,6 +31,11 @@ function handleThemeFn({ code, uno, options }, node) {
29
31
  return true;
30
32
  });
31
33
  if (typeof value === "string") {
34
+ if (alpha) {
35
+ const color = ruleUtils.parseCssColor(value);
36
+ if (color)
37
+ value = ruleUtils.colorToString(color, alpha);
38
+ }
32
39
  code.overwrite(
33
40
  offset + match.index,
34
41
  offset + match.index + match[0].length,
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { expandVariantGroup, notNull, regexScopePlaceholder, cssIdRE, toArray } from '@unocss/core';
2
2
  import { generate, parse, clone, walk } from 'css-tree';
3
+ import { parseCssColor, colorToString } from '@unocss/rule-utils';
3
4
 
4
5
  const themeFnRE = /theme\((.*?)\)/g;
5
6
  function handleThemeFn({ code, uno, options }, node) {
@@ -13,8 +14,9 @@ function handleThemeFn({ code, uno, options }, node) {
13
14
  const rawArg = match[1].trim();
14
15
  if (!rawArg)
15
16
  throw new Error("theme() expect exact one argument, but got 0");
17
+ const [rawKey, alpha] = rawArg.slice(1, -1).split("/");
16
18
  let value = uno.config.theme;
17
- const keys = rawArg.slice(1, -1).split(".");
19
+ const keys = rawKey.trim().split(".");
18
20
  keys.every((key) => {
19
21
  if (value[key] != null)
20
22
  value = value[key];
@@ -25,6 +27,11 @@ function handleThemeFn({ code, uno, options }, node) {
25
27
  return true;
26
28
  });
27
29
  if (typeof value === "string") {
30
+ if (alpha) {
31
+ const color = parseCssColor(value);
32
+ if (color)
33
+ value = colorToString(color, alpha);
34
+ }
28
35
  code.overwrite(
29
36
  offset + match.index,
30
37
  offset + match.index + match[0].length,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/transformer-directives",
3
- "version": "0.55.6",
3
+ "version": "0.56.0",
4
4
  "description": "UnoCSS transformer for `@apply` directive",
5
5
  "author": "hannoeru <me@hanlee.co>",
6
6
  "license": "MIT",
@@ -33,7 +33,8 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "css-tree": "^2.3.1",
36
- "@unocss/core": "0.55.6"
36
+ "@unocss/core": "0.56.0",
37
+ "@unocss/rule-utils": "0.56.0"
37
38
  },
38
39
  "devDependencies": {
39
40
  "magic-string": "^0.30.3"