esm-styles 0.1.8 → 0.1.10

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.
@@ -155,7 +155,10 @@ export const joinSelectorPath = (path) => {
155
155
  // Compute cartesian product of all segments
156
156
  const combos = utils.cartesianProduct(path);
157
157
  // Join each combination into a selector string
158
- return combos.map((parts) => parts.reduce((acc, part) => {
158
+ return combos.map((parts) => parts.reduce((acc, part, idx) => {
159
+ // Check if previous part is a root selector
160
+ const prev = idx > 0 ? parts[idx - 1] : null;
161
+ const isPrevRoot = prev && (prev === ':root' || prev.startsWith(':root.'));
159
162
  if (part.startsWith('__')) {
160
163
  return acc + (acc ? ' ' : '') + '.' + part.slice(2);
161
164
  }
@@ -178,9 +181,18 @@ export const joinSelectorPath = (path) => {
178
181
  else if (isHtmlTag(part)) {
179
182
  return acc + (acc ? ' ' : '') + part;
180
183
  }
181
- else {
182
- // Not a tag, not a special selector: treat as class
183
- return acc + (acc ? '' : '') + '.' + part;
184
+ else if (/^([a-z][a-z0-9]*)\.(.+)/.test(part)) {
185
+ // If part matches 'tag.class...' and tag is an HTML tag
186
+ const match = part.match(/^([a-z][a-z0-9]*)\.(.+)/);
187
+ if (match && isHtmlTag(match[1])) {
188
+ return acc + (acc ? ' ' : '') + match[1] + '.' + match[2];
189
+ }
184
190
  }
191
+ // Not a tag, not a special selector: treat as class or custom element
192
+ // If previous part is a root selector, insert a space
193
+ if (isPrevRoot) {
194
+ return acc + ' ' + '.' + part;
195
+ }
196
+ return acc + (acc ? '' : '') + '.' + part;
185
197
  }, ''));
186
198
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esm-styles",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "A library for working with ESM styles",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",