@unocss/transformer-directives 0.26.0 → 0.26.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.
- package/README.md +18 -1
- package/dist/index.cjs +16 -9
- package/dist/index.mjs +17 -10
- package/package.json +2 -7
package/README.md
CHANGED
|
@@ -21,7 +21,24 @@ Unocss({
|
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
```css
|
|
25
|
+
.custom-div {
|
|
26
|
+
@apply text-center my-0 font-medium;
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Will be transformed to:
|
|
31
|
+
|
|
32
|
+
```css
|
|
33
|
+
.custom-div {
|
|
34
|
+
margin-top: 0rem;
|
|
35
|
+
margin-bottom: 0rem;
|
|
36
|
+
text-align: center;
|
|
37
|
+
font-weight: 500;
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
> Currently only `@apply` is supported.
|
|
25
42
|
|
|
26
43
|
## License
|
|
27
44
|
|
package/dist/index.cjs
CHANGED
|
@@ -5,11 +5,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
const core = require('@unocss/core');
|
|
6
6
|
const cssTree = require('css-tree');
|
|
7
7
|
|
|
8
|
+
const regexCssId = /\.(css|postcss|sass|scss|less|stylus|styl)$/;
|
|
9
|
+
|
|
8
10
|
function transformerDirectives() {
|
|
9
11
|
return {
|
|
10
12
|
name: "css-directive",
|
|
11
13
|
enforce: "pre",
|
|
12
|
-
idFilter: (id) => id.
|
|
14
|
+
idFilter: (id) => !!id.match(regexCssId),
|
|
13
15
|
transform: (code, id, ctx) => {
|
|
14
16
|
return transformDirectives(code, ctx.uno, id);
|
|
15
17
|
}
|
|
@@ -47,21 +49,26 @@ async function transformDirectives(css, uno, filename) {
|
|
|
47
49
|
return;
|
|
48
50
|
const parentSelector = cssTree.generate(node.prelude);
|
|
49
51
|
for (const i of utils) {
|
|
50
|
-
const [,
|
|
52
|
+
const [, _selector, body, parent] = i;
|
|
53
|
+
const selector = _selector?.replace(core.regexScopePlaceholder, " ") || _selector;
|
|
51
54
|
if (parent) {
|
|
52
55
|
const newNodeCss = `${parent}{${parentSelector}{${body}}}`;
|
|
53
56
|
const insertNodeAst = cssTree.parse(newNodeCss);
|
|
54
57
|
list.insertList(insertNodeAst.children, item);
|
|
55
58
|
} else if (selector && selector !== ".\\-") {
|
|
56
|
-
const
|
|
59
|
+
const selectorAST = cssTree.parse(selector, {
|
|
57
60
|
context: "selector"
|
|
58
|
-
}).children.filter((i2) => i2.type === "PseudoClassSelector");
|
|
59
|
-
const parentSelectorAst = cssTree.clone(node.prelude);
|
|
60
|
-
parentSelectorAst.children.forEach((i2) => {
|
|
61
|
-
if (i2.type === "Selector")
|
|
62
|
-
i2.children.appendList(pseudoClassSelectors.copy());
|
|
63
61
|
});
|
|
64
|
-
const
|
|
62
|
+
const prelude = cssTree.clone(node.prelude);
|
|
63
|
+
prelude.children.forEach((child) => {
|
|
64
|
+
const parentSelectorAst = cssTree.clone(selectorAST);
|
|
65
|
+
parentSelectorAst.children.forEach((i2) => {
|
|
66
|
+
if (i2.type === "ClassSelector" && i2.name === "\\-")
|
|
67
|
+
Object.assign(i2, cssTree.clone(child));
|
|
68
|
+
});
|
|
69
|
+
Object.assign(child, parentSelectorAst);
|
|
70
|
+
});
|
|
71
|
+
const newNodeCss = `${cssTree.generate(prelude)}{${body}}`;
|
|
65
72
|
const insertNodeAst = cssTree.parse(newNodeCss);
|
|
66
73
|
list.insertList(insertNodeAst.children, item);
|
|
67
74
|
} else {
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { expandVariantGroup, notNull } from '@unocss/core';
|
|
1
|
+
import { expandVariantGroup, notNull, regexScopePlaceholder } from '@unocss/core';
|
|
2
2
|
import { parse, walk, generate, clone, List } from 'css-tree';
|
|
3
3
|
|
|
4
|
+
const regexCssId = /\.(css|postcss|sass|scss|less|stylus|styl)$/;
|
|
5
|
+
|
|
4
6
|
function transformerDirectives() {
|
|
5
7
|
return {
|
|
6
8
|
name: "css-directive",
|
|
7
9
|
enforce: "pre",
|
|
8
|
-
idFilter: (id) => id.
|
|
10
|
+
idFilter: (id) => !!id.match(regexCssId),
|
|
9
11
|
transform: (code, id, ctx) => {
|
|
10
12
|
return transformDirectives(code, ctx.uno, id);
|
|
11
13
|
}
|
|
@@ -43,21 +45,26 @@ async function transformDirectives(css, uno, filename) {
|
|
|
43
45
|
return;
|
|
44
46
|
const parentSelector = generate(node.prelude);
|
|
45
47
|
for (const i of utils) {
|
|
46
|
-
const [,
|
|
48
|
+
const [, _selector, body, parent] = i;
|
|
49
|
+
const selector = _selector?.replace(regexScopePlaceholder, " ") || _selector;
|
|
47
50
|
if (parent) {
|
|
48
51
|
const newNodeCss = `${parent}{${parentSelector}{${body}}}`;
|
|
49
52
|
const insertNodeAst = parse(newNodeCss);
|
|
50
53
|
list.insertList(insertNodeAst.children, item);
|
|
51
54
|
} else if (selector && selector !== ".\\-") {
|
|
52
|
-
const
|
|
55
|
+
const selectorAST = parse(selector, {
|
|
53
56
|
context: "selector"
|
|
54
|
-
}).children.filter((i2) => i2.type === "PseudoClassSelector");
|
|
55
|
-
const parentSelectorAst = clone(node.prelude);
|
|
56
|
-
parentSelectorAst.children.forEach((i2) => {
|
|
57
|
-
if (i2.type === "Selector")
|
|
58
|
-
i2.children.appendList(pseudoClassSelectors.copy());
|
|
59
57
|
});
|
|
60
|
-
const
|
|
58
|
+
const prelude = clone(node.prelude);
|
|
59
|
+
prelude.children.forEach((child) => {
|
|
60
|
+
const parentSelectorAst = clone(selectorAST);
|
|
61
|
+
parentSelectorAst.children.forEach((i2) => {
|
|
62
|
+
if (i2.type === "ClassSelector" && i2.name === "\\-")
|
|
63
|
+
Object.assign(i2, clone(child));
|
|
64
|
+
});
|
|
65
|
+
Object.assign(child, parentSelectorAst);
|
|
66
|
+
});
|
|
67
|
+
const newNodeCss = `${generate(prelude)}{${body}}`;
|
|
61
68
|
const insertNodeAst = parse(newNodeCss);
|
|
62
69
|
list.insertList(insertNodeAst.children, item);
|
|
63
70
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/transformer-directives",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.3",
|
|
4
4
|
"description": "UnoCSS transformer for `@apply` directive",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unocss",
|
|
@@ -30,15 +30,10 @@
|
|
|
30
30
|
"main": "./dist/index.cjs",
|
|
31
31
|
"module": "./dist/index.mjs",
|
|
32
32
|
"types": "./dist/index.d.ts",
|
|
33
|
-
"peerDependencies": {
|
|
34
|
-
"@unocss/core": "0.26.0"
|
|
35
|
-
},
|
|
36
33
|
"dependencies": {
|
|
34
|
+
"@unocss/core": "0.26.3",
|
|
37
35
|
"css-tree": "^2.0.4"
|
|
38
36
|
},
|
|
39
|
-
"devDependencies": {
|
|
40
|
-
"@unocss/core": "0.26.0"
|
|
41
|
-
},
|
|
42
37
|
"scripts": {
|
|
43
38
|
"build": "unbuild",
|
|
44
39
|
"stub": "unbuild --stub"
|