forgecss 0.8.0 → 0.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forgecss",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "description": "ForgeCSS turns strings into fully generated responsive CSS using a custom DSL.",
6
6
  "author": "Krasimir Tsonev",
@@ -1,7 +1,14 @@
1
- import { extractStyles, getStylesByClassName, invalidateInventory, resolveApplys } from "./lib/inventory.js";
1
+ import {
2
+ extractStyles,
3
+ getStylesByClassName,
4
+ invalidateInventory,
5
+ resolveApplys,
6
+ getInventory
7
+ } from "./lib/inventory.js";
2
8
  import { invalidateUsageCache, findUsages, getUsages } from "./lib/usages.js";
3
9
  import { astToRules, rulesToCSS } from "../lib/forge-lang/Compiler.js";
4
10
  import { toAST } from "../lib/forge-lang/Parser.js";
11
+ import fx from '../lib/fx.js'
5
12
 
6
13
  const DEFAULT_OPTIONS = {
7
14
  usageAttributes: ["class", "className"],
@@ -10,7 +17,7 @@ const DEFAULT_OPTIONS = {
10
17
  minify: true
11
18
  };
12
19
 
13
- export default function ForgeCSS(options) {
20
+ function ForgeCSS(options) {
14
21
  const config = { ...DEFAULT_OPTIONS };
15
22
 
16
23
  config.breakpoints = Object.assign({}, DEFAULT_OPTIONS.breakpoints, options?.breakpoints ?? {});
@@ -71,6 +78,12 @@ export default function ForgeCSS(options) {
71
78
  console.error(`forgecss: error extracting usages.`, err);
72
79
  }
73
80
  return result();
74
- }
81
+ },
82
+ getUsages,
83
+ getStylesByClassName,
84
+ getInventory,
85
+ fx
75
86
  };
76
87
  }
88
+
89
+ window.ForgeCSS = ForgeCSS;
@@ -5,7 +5,7 @@ let INVENTORY = {};
5
5
 
6
6
  export async function extractStyles(css = null) {
7
7
  const content = css;
8
- INVENTORY[filePath] = postcss.parse(content, { parser: safeParser });
8
+ INVENTORY['styles.css'] = postcss.parse(content, { parser: safeParser });
9
9
  }
10
10
  export function getStylesByClassName(selector) {
11
11
  const decls = [];
@@ -23,14 +23,8 @@ export function getStylesByClassName(selector) {
23
23
  }
24
24
  return decls;
25
25
  }
26
- export function invalidateInventory(filePath) {
27
- if (!filePath) {
28
- INVENTORY = {};
29
- return;
30
- }
31
- if (INVENTORY[filePath]) {
32
- delete INVENTORY[filePath];
33
- }
26
+ export function invalidateInventory() {
27
+ INVENTORY = {};
34
28
  }
35
29
  export function resolveApplys() {
36
30
  let resolvedApplies;
@@ -59,4 +53,7 @@ export function resolveApplys() {
59
53
  });
60
54
  });
61
55
  return resolvedApplies;
56
+ }
57
+ export function getInventory() {
58
+ return INVENTORY;
62
59
  }
@@ -3,14 +3,14 @@ import { visit } from "unist-util-visit";
3
3
 
4
4
  let USAGES = {};
5
5
 
6
- export async function findUsages(fileContent = null) {
6
+ export async function findUsages(filePath, fileContent = null) {
7
7
  try {
8
8
  if (USAGES[filePath]) {
9
9
  // already processed
10
10
  return;
11
11
  }
12
12
  USAGES[filePath] = [];
13
- const content = fileContent
13
+ const content = fileContent;
14
14
 
15
15
  const ast = fromHtml(content);
16
16
  visit(ast, "element", (node) => {
@@ -19,17 +19,11 @@ export async function findUsages(fileContent = null) {
19
19
  }
20
20
  });
21
21
  } catch (err) {
22
- console.error(`forgecss: error processing file ${filePath.replace(process.cwd(), '')}`, err);
22
+ console.error(`forgecss: error processing file ${filePath}`, err);
23
23
  }
24
24
  }
25
- export function invalidateUsageCache(filePath) {
26
- if (!filePath) {
27
- USAGES = {};
28
- return;
29
- }
30
- if (USAGES[filePath]) {
31
- delete USAGES[filePath];
32
- }
25
+ export function invalidateUsageCache() {
26
+ USAGES = {};
33
27
  }
34
28
  export function getUsages() {
35
29
  return USAGES;