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 CHANGED
@@ -2,10 +2,8 @@ export type ForgeCSSOptions = {
2
2
  inventoryFiles?: string[];
3
3
  usageFiles?: string[];
4
4
  usageAttributes?: string[];
5
- mapping?: {
6
- queries?: {
7
- [key: string]: string
8
- };
5
+ breakpoints?: {
6
+ [key: string]: string
9
7
  };
10
8
  };
11
9
 
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
- mapping: {
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.mapping = {
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) {
@@ -1,3 +1,4 @@
1
1
  export function extractStyles(filePath: string, css?: string | null): Promise<void>;
2
2
  export function getStylesByClassName(selector: string): object[];
3
3
  export function invalidateInvetory(): void;
4
+ export function resolveApplys(bucket: object): void
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?.mapping?.queries[label]) {
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.mapping.queries[label]})`
14
+ params: `all and (${config.breakpoints[label]})`
15
15
  }),
16
16
  classes: {}
17
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forgecss",
3
- "version": "0.3.0",
3
+ "version": "0.4.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",