@teacss/postcss 0.3.7 → 0.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/esm.mjs +33 -4
- package/package.json +7 -7
package/dist/esm.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { readFile, stat } from "node:fs/promises";
|
|
|
2
2
|
import { dirname, extname, join, normalize, relative, resolve } from "node:path";
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
import { createRecoveryConfigLoader, entryDiscoveryFiles, getConfigSourcesFromError } from "@teacss/config";
|
|
5
|
-
import { createGenerator, expandVariantGroup, splitClassTokens } from "@teacss/core";
|
|
5
|
+
import { createGenerator, expandClassGroups, expandVariantGroup, splitClassTokens } from "@teacss/core";
|
|
6
6
|
import { hasIconFn, hasThemeFn } from "@teacss/rule-helpers";
|
|
7
7
|
import { defaultFilesystemGlobs } from "@teacss/runtime";
|
|
8
8
|
import postcss from "postcss";
|
|
@@ -10,6 +10,32 @@ import { glob, isDynamicPattern } from "tinyglobby";
|
|
|
10
10
|
import { formatMissingApplyTokens, missingApplyTokens, prepareApplyUtilities, renderStandaloneApplyUtility, resolveApplyTokens, resolveCssFunction, resolveScreenQuery } from "@teacss/directives/core";
|
|
11
11
|
import { generate, parse, walk } from "css-tree";
|
|
12
12
|
//#region src/apply.ts
|
|
13
|
+
/**
|
|
14
|
+
* `@apply {a;b}@cond;` — PostCSS reads the group as the at-rule's own block, so
|
|
15
|
+
* `params` is empty and the trailing condition arrives as a separate sibling
|
|
16
|
+
* at-rule. Recover the authored text from the source, and report the siblings
|
|
17
|
+
* that belong to this directive so they are removed with it rather than
|
|
18
|
+
* surviving into the output as a bare `@hover;`.
|
|
19
|
+
*/
|
|
20
|
+
function readGroupApply(rule, directiveName) {
|
|
21
|
+
if (rule.params !== "" || !rule.nodes) return;
|
|
22
|
+
const input = rule.source?.input?.css;
|
|
23
|
+
const start = rule.source?.start?.offset;
|
|
24
|
+
let end = rule.source?.end?.offset;
|
|
25
|
+
if (input == null || start == null || end == null) return;
|
|
26
|
+
const consumed = [];
|
|
27
|
+
let next = rule.next();
|
|
28
|
+
while (next?.type === "atrule" && next.source?.start?.offset === end && next.source?.end?.offset != null) {
|
|
29
|
+
end = next.source.end.offset;
|
|
30
|
+
consumed.push(next);
|
|
31
|
+
next = next.next();
|
|
32
|
+
}
|
|
33
|
+
const body = input.slice(start + directiveName.length + 1, end).replace(/;\s*$/, "").trim();
|
|
34
|
+
return body ? {
|
|
35
|
+
body,
|
|
36
|
+
consumed
|
|
37
|
+
} : void 0;
|
|
38
|
+
}
|
|
13
39
|
async function parseApply(root, generator, directiveName) {
|
|
14
40
|
const rules = [];
|
|
15
41
|
const lastParentAfterNode = /* @__PURE__ */ new Map();
|
|
@@ -18,17 +44,20 @@ async function parseApply(root, generator, directiveName) {
|
|
|
18
44
|
rules.push(rule);
|
|
19
45
|
});
|
|
20
46
|
const resolvedRules = await Promise.all(rules.map(async (rule) => {
|
|
21
|
-
const
|
|
47
|
+
const group = readGroupApply(rule, directiveName);
|
|
48
|
+
const parsed = await resolveApplyTokens(splitClassTokens(expandVariantGroup(expandClassGroups(group ? group.body : rule.params))), generator);
|
|
22
49
|
const missing = missingApplyTokens(parsed);
|
|
23
50
|
if (missing.length) throw rule.error(formatMissingApplyTokens(missing));
|
|
24
51
|
return {
|
|
25
52
|
parsed,
|
|
26
|
-
rule
|
|
53
|
+
rule,
|
|
54
|
+
consumed: group?.consumed ?? []
|
|
27
55
|
};
|
|
28
56
|
}));
|
|
29
|
-
for (const { parsed, rule } of resolvedRules) {
|
|
57
|
+
for (const { parsed, rule, consumed } of resolvedRules) {
|
|
30
58
|
const hostRule = rule.parent;
|
|
31
59
|
if (!hostRule) continue;
|
|
60
|
+
for (const node of consumed) node.remove();
|
|
32
61
|
const source = rule.source;
|
|
33
62
|
const utils = prepareApplyUtilities(parsed, generator.parentOrders);
|
|
34
63
|
if (!utils.length) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teacss/postcss",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "PostCSS plugin for TeaCSS — generate utilities within a PostCSS pipeline.",
|
|
5
5
|
"homepage": "https://css.teasim.com",
|
|
6
6
|
"funding": "https://github.com/sponsors/billgo",
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
"dev": "tsdown --watch"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@teacss/config": "0.
|
|
27
|
-
"@teacss/core": "0.
|
|
28
|
-
"@teacss/directives": "0.
|
|
29
|
-
"@teacss/rule-helpers": "0.
|
|
30
|
-
"@teacss/runtime": "0.
|
|
26
|
+
"@teacss/config": "0.4.0",
|
|
27
|
+
"@teacss/core": "0.4.0",
|
|
28
|
+
"@teacss/directives": "0.4.0",
|
|
29
|
+
"@teacss/rule-helpers": "0.4.0",
|
|
30
|
+
"@teacss/runtime": "0.4.0",
|
|
31
31
|
"css-tree": "^3.2.1",
|
|
32
32
|
"tinyglobby": "^0.2.17"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@teacss/preset-standard": "0.
|
|
35
|
+
"@teacss/preset-standard": "0.4.0",
|
|
36
36
|
"@types/css-tree": "^2.3.11",
|
|
37
37
|
"consola": "^3.4.2",
|
|
38
38
|
"magic-string": "^1.1.0",
|