forgecss 0.10.0 → 0.12.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.
@@ -1,59 +0,0 @@
1
- import postcss from "postcss";
2
- import safeParser from "postcss-safe-parser";
3
-
4
- let INVENTORY = {};
5
-
6
- export async function extractStyles(css = null) {
7
- const content = css;
8
- INVENTORY['styles.css'] = postcss.parse(content, { parser: safeParser });
9
- }
10
- export function getStylesByClassName(selector) {
11
- const decls = [];
12
- Object.keys(INVENTORY).forEach((filePath) => {
13
- INVENTORY[filePath].walkRules((rule) => {
14
- if (rule.selectors && rule.selectors.includes(`.${selector}`)) {
15
- rule.walkDecls((d) => {
16
- decls.push({ prop: d.prop, value: d.value, important: d.important });
17
- });
18
- }
19
- });
20
- });
21
- if (decls.length === 0) {
22
- console.warn(`forgecss: no styles found for class "${selector}".`);
23
- }
24
- return decls;
25
- }
26
- export function invalidateInventory() {
27
- INVENTORY = {};
28
- }
29
- export function resolveApplys() {
30
- let resolvedApplies;
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 (!resolvedApplies) {
48
- resolvedApplies = postcss.root();
49
- }
50
- resolvedApplies.append(newRule);
51
- }
52
- });
53
- });
54
- });
55
- return resolvedApplies;
56
- }
57
- export function getInventory() {
58
- return INVENTORY;
59
- }
@@ -1,30 +0,0 @@
1
- import { fromHtml } from "hast-util-from-html";
2
- import { visit } from "unist-util-visit";
3
-
4
- let USAGES = {};
5
-
6
- export async function findUsages(filePath, fileContent = null) {
7
- try {
8
- if (USAGES[filePath]) {
9
- // already processed
10
- return;
11
- }
12
- USAGES[filePath] = [];
13
- const content = fileContent;
14
-
15
- const ast = fromHtml(content);
16
- visit(ast, "element", (node) => {
17
- if (node.properties.className) {
18
- USAGES[filePath].push(node.properties.className.join(" "));
19
- }
20
- });
21
- } catch (err) {
22
- console.error(`forgecss: error processing file ${filePath}`, err);
23
- }
24
- }
25
- export function invalidateUsageCache() {
26
- USAGES = {};
27
- }
28
- export function getUsages() {
29
- return USAGES;
30
- }