esm-styles 0.1.2 → 0.1.3

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/index.js CHANGED
@@ -14,5 +14,5 @@ export { jsKeyToCssKey, isEndValue } from './lib/utils/common.js';
14
14
  export { processMediaQueries } from './lib/utils/media.js';
15
15
  export { obj2css, prettifyCss } from './lib/utils/obj2css.js';
16
16
  export function greet() {
17
- return 'esm-styles 0.1.2';
17
+ return 'esm-styles 0.1.3';
18
18
  }
@@ -31,8 +31,17 @@ export function getCss(object, mediaQueries = {}, mediaPrefixes = {}, auto) {
31
31
  const nodeType = determineNodeType(node, path);
32
32
  const pathParts = path.split('\\');
33
33
  const key = pathParts.pop() || '';
34
+ // Skip processing media query nodes that are nested within selectors
35
+ // as they will be handled separately in the media query section
36
+ const isNestedMediaQuery = pathParts.some((part) => part.startsWith('@media ') ||
37
+ (part.startsWith('@') &&
38
+ mediaQueries[part.replace(/^@\s*/, '')] !== undefined));
34
39
  switch (nodeType) {
35
40
  case 'selector': {
41
+ // Skip if this is inside a media query - it will be handled separately
42
+ if (isNestedMediaQuery) {
43
+ break;
44
+ }
36
45
  // Handle CSS property-value pairs
37
46
  const selector = joinSelectors(pathParts);
38
47
  // Create cartesian product of selectors for comma-separated parts
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Utilities for handling media queries
3
3
  */
4
- import { indent } from './common.js';
4
+ import { indent, jsKeyToCssKey } from './common.js';
5
5
  import { obj2css } from './obj2css.js';
6
6
  import { isEndValue } from './common.js';
7
7
  /**
@@ -36,7 +36,9 @@ export function processMediaQueries(mediaObject, mediaQueries = {}) {
36
36
  if (isEndValue(styles)) {
37
37
  return '';
38
38
  }
39
- const stylesCss = obj2css(styles);
39
+ // Process the styles to convert camelCase properties to kebab-case
40
+ const processedStyles = processStylesForMedia(styles);
41
+ const stylesCss = obj2css(processedStyles);
40
42
  if (!stylesCss.trim()) {
41
43
  return '';
42
44
  }
@@ -46,6 +48,31 @@ export function processMediaQueries(mediaObject, mediaQueries = {}) {
46
48
  // Join all media query blocks with newlines
47
49
  return mediaCssStrings.filter((css) => css).join('\n\n');
48
50
  }
51
+ /**
52
+ * Processes styles for media queries to ensure camelCase is converted to kebab-case
53
+ * @param styles - Style object to process
54
+ * @returns Processed style object with converted property names
55
+ */
56
+ function processStylesForMedia(styles) {
57
+ const result = {};
58
+ // Process each selector in the styles
59
+ Object.keys(styles).forEach((selector) => {
60
+ const selectorStyles = styles[selector];
61
+ // Skip if not an object
62
+ if (isEndValue(selectorStyles)) {
63
+ result[selector] = selectorStyles;
64
+ return;
65
+ }
66
+ const processedProps = {};
67
+ // Convert each property name to kebab-case
68
+ Object.keys(selectorStyles).forEach((prop) => {
69
+ const cssKey = jsKeyToCssKey(prop);
70
+ processedProps[cssKey] = selectorStyles[prop];
71
+ });
72
+ result[selector] = processedProps;
73
+ });
74
+ return result;
75
+ }
49
76
  /**
50
77
  * Checks if a key represents a media query
51
78
  * @param key - Key to check
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esm-styles",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "A library for working with ESM styles",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",