esm-styles 0.1.10 → 0.1.11
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,4 +1,5 @@
|
|
|
1
1
|
import type { IsSpecialSelector, IsClassSelector } from '../types/index.js';
|
|
2
|
+
export declare const startsWithHtmlTag: (selector: string) => boolean;
|
|
2
3
|
export declare const isSpecialSelector: IsSpecialSelector;
|
|
3
4
|
export declare const isClassSelector: IsClassSelector;
|
|
4
5
|
export declare const joinSelectorPath: (path: string[][]) => string[];
|
|
@@ -140,6 +140,22 @@ const isHtmlTag = (key) => {
|
|
|
140
140
|
// Only match if the key is a plain tag name (no underscores, no special chars)
|
|
141
141
|
return HTML_TAGS.has(key);
|
|
142
142
|
};
|
|
143
|
+
// Check if selector starts with an HTML tag followed by a combinator or other selector parts
|
|
144
|
+
export const startsWithHtmlTag = (selector) => {
|
|
145
|
+
// Common combinators and selector parts that might follow a tag
|
|
146
|
+
const combinators = [' ', '>', '+', '~', ':', '[', '.'];
|
|
147
|
+
// Check if the selector starts with an HTML tag followed by a combinator
|
|
148
|
+
for (const tag of HTML_TAGS) {
|
|
149
|
+
if (selector === tag)
|
|
150
|
+
return true;
|
|
151
|
+
for (const combinator of combinators) {
|
|
152
|
+
if (selector.startsWith(tag + combinator)) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
};
|
|
143
159
|
export const isSpecialSelector = (key) => {
|
|
144
160
|
// Pseudo-classes/elements, id, attribute selectors
|
|
145
161
|
return (key.startsWith(':') ||
|
|
@@ -159,7 +175,11 @@ export const joinSelectorPath = (path) => {
|
|
|
159
175
|
// Check if previous part is a root selector
|
|
160
176
|
const prev = idx > 0 ? parts[idx - 1] : null;
|
|
161
177
|
const isPrevRoot = prev && (prev === ':root' || prev.startsWith(':root.'));
|
|
162
|
-
if (part
|
|
178
|
+
if (part === '*') {
|
|
179
|
+
// Universal selector
|
|
180
|
+
return acc + (acc ? ' ' : '') + '*';
|
|
181
|
+
}
|
|
182
|
+
else if (part.startsWith('__')) {
|
|
163
183
|
return acc + (acc ? ' ' : '') + '.' + part.slice(2);
|
|
164
184
|
}
|
|
165
185
|
else if (part.startsWith('_')) {
|
|
@@ -181,6 +201,10 @@ export const joinSelectorPath = (path) => {
|
|
|
181
201
|
else if (isHtmlTag(part)) {
|
|
182
202
|
return acc + (acc ? ' ' : '') + part;
|
|
183
203
|
}
|
|
204
|
+
else if (startsWithHtmlTag(part)) {
|
|
205
|
+
// Handle compound selectors that start with HTML tags (e.g., 'div > *')
|
|
206
|
+
return acc + (acc ? ' ' : '') + part;
|
|
207
|
+
}
|
|
184
208
|
else if (/^([a-z][a-z0-9]*)\.(.+)/.test(part)) {
|
|
185
209
|
// If part matches 'tag.class...' and tag is an HTML tag
|
|
186
210
|
const match = part.match(/^([a-z][a-z0-9]*)\.(.+)/);
|