forgecss 0.3.0 → 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/index.d.ts +2 -4
- package/index.js +2 -6
- package/lib/generator.js +2 -0
- package/lib/inventory.d.ts +1 -0
- package/lib/inventory.js +29 -0
- package/lib/transformers/mediaQuery.js +2 -2
- package/package.json +1 -1
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -8,17 +8,13 @@ const DEFAULT_OPTIONS = {
|
|
|
8
8
|
inventoryFiles: ["css", "less", "scss"],
|
|
9
9
|
usageFiles: ["html", "jsx", "tsx"],
|
|
10
10
|
usageAttributes: ["class", "className"],
|
|
11
|
-
|
|
12
|
-
queries: {}
|
|
13
|
-
}
|
|
11
|
+
breakpoints: {}
|
|
14
12
|
};
|
|
15
13
|
|
|
16
14
|
export default function ForgeCSS(options) {
|
|
17
15
|
const config = { ...DEFAULT_OPTIONS };
|
|
18
16
|
|
|
19
|
-
config.
|
|
20
|
-
queries: Object.assign({}, DEFAULT_OPTIONS.mapping.queries, options?.mapping?.queries ?? {})
|
|
21
|
-
};
|
|
17
|
+
config.breakpoints = Object.assign({}, DEFAULT_OPTIONS.breakpoints, options?.breakpoints ?? {});
|
|
22
18
|
|
|
23
19
|
async function result(output) {
|
|
24
20
|
try {
|
package/lib/generator.js
CHANGED
|
@@ -2,6 +2,7 @@ import { getUsages } from "./usages.js";
|
|
|
2
2
|
import arbitraryTransformer from "./transformers/arbitrary.js";
|
|
3
3
|
import mediaQueryTransformer from "./transformers/mediaQuery.js";
|
|
4
4
|
import pseudoClassTransformer from "./transformers/pseudo.js";
|
|
5
|
+
import { resolveApplys } from "./inventory.js";
|
|
5
6
|
|
|
6
7
|
export async function generateOutputCSS(config) {
|
|
7
8
|
const bucket = {};
|
|
@@ -27,6 +28,7 @@ export async function generateOutputCSS(config) {
|
|
|
27
28
|
}
|
|
28
29
|
});
|
|
29
30
|
});
|
|
31
|
+
resolveApplys(bucket);
|
|
30
32
|
return Object.keys(bucket)
|
|
31
33
|
.map((key) => {
|
|
32
34
|
if (bucket[key].rules) {
|
package/lib/inventory.d.ts
CHANGED
package/lib/inventory.js
CHANGED
|
@@ -19,8 +19,37 @@ export function getStylesByClassName(selector) {
|
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
|
+
if (decls.length === 0) {
|
|
23
|
+
console.warn(`forgecss: Warning - no styles found for class "${selector}".`);
|
|
24
|
+
}
|
|
22
25
|
return decls;
|
|
23
26
|
}
|
|
24
27
|
export function invalidateInvetory() {
|
|
25
28
|
INVENTORY = {};
|
|
29
|
+
}
|
|
30
|
+
export function resolveApplys(bucket) {
|
|
31
|
+
Object.keys(INVENTORY).forEach((filePath) => {
|
|
32
|
+
INVENTORY[filePath].walkRules((rule) => {
|
|
33
|
+
rule.walkDecls((d) => {
|
|
34
|
+
if (d.prop === '--apply') {
|
|
35
|
+
const classesToApply = d.value.split(' ').map(c => c.trim()).filter(Boolean);
|
|
36
|
+
const newRule = postcss.rule({ selector: rule.selector });
|
|
37
|
+
classesToApply.forEach((className) => {
|
|
38
|
+
const styles = getStylesByClassName(className);
|
|
39
|
+
styles.forEach((style) => {
|
|
40
|
+
newRule.append({
|
|
41
|
+
prop: style.prop,
|
|
42
|
+
value: style.value,
|
|
43
|
+
important: style.important
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
if (!bucket['_APPLY_']) {
|
|
48
|
+
bucket["_APPLY_"] = postcss.root();
|
|
49
|
+
}
|
|
50
|
+
bucket["_APPLY_"].append(newRule);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
26
55
|
}
|
|
@@ -4,14 +4,14 @@ import { setDeclarations } from "../helpers.js";
|
|
|
4
4
|
import {normalizeLabel} from "../../client/fx.js";
|
|
5
5
|
|
|
6
6
|
export default function mediaQueryTransformer(config, label, classes, bucket) {
|
|
7
|
-
if (!config?.
|
|
7
|
+
if (!config?.breakpoints[label]) {
|
|
8
8
|
return false;
|
|
9
9
|
}
|
|
10
10
|
if (!bucket[label]) {
|
|
11
11
|
bucket[label] = {
|
|
12
12
|
rules: postcss.atRule({
|
|
13
13
|
name: "media",
|
|
14
|
-
params: `all and (${config.
|
|
14
|
+
params: `all and (${config.breakpoints[label]})`
|
|
15
15
|
}),
|
|
16
16
|
classes: {}
|
|
17
17
|
};
|