esm-styles 0.1.10 → 0.1.12

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[];
@@ -1,4 +1,15 @@
1
1
  import * as utils from './cartesian.js';
2
+ const svgTags = [
3
+ 'circle',
4
+ 'ellipse',
5
+ 'g',
6
+ 'line',
7
+ 'polygon',
8
+ 'polyline',
9
+ 'path',
10
+ 'rect',
11
+ 'text',
12
+ ];
2
13
  // List of standard HTML tags (not exhaustive, but covers common cases)
3
14
  const HTML_TAGS = new Set([
4
15
  'html',
@@ -135,11 +146,28 @@ const HTML_TAGS = new Set([
135
146
  'strike',
136
147
  'tt',
137
148
  'xmp',
149
+ ...svgTags,
138
150
  ]);
139
151
  const isHtmlTag = (key) => {
140
152
  // Only match if the key is a plain tag name (no underscores, no special chars)
141
153
  return HTML_TAGS.has(key);
142
154
  };
155
+ // Check if selector starts with an HTML tag followed by a combinator or other selector parts
156
+ export const startsWithHtmlTag = (selector) => {
157
+ // Common combinators and selector parts that might follow a tag
158
+ const combinators = [' ', '>', '+', '~', ':', '[', '.'];
159
+ // Check if the selector starts with an HTML tag followed by a combinator
160
+ for (const tag of HTML_TAGS) {
161
+ if (selector === tag)
162
+ return true;
163
+ for (const combinator of combinators) {
164
+ if (selector.startsWith(tag + combinator)) {
165
+ return true;
166
+ }
167
+ }
168
+ }
169
+ return false;
170
+ };
143
171
  export const isSpecialSelector = (key) => {
144
172
  // Pseudo-classes/elements, id, attribute selectors
145
173
  return (key.startsWith(':') ||
@@ -159,7 +187,11 @@ export const joinSelectorPath = (path) => {
159
187
  // Check if previous part is a root selector
160
188
  const prev = idx > 0 ? parts[idx - 1] : null;
161
189
  const isPrevRoot = prev && (prev === ':root' || prev.startsWith(':root.'));
162
- if (part.startsWith('__')) {
190
+ if (part === '*') {
191
+ // Universal selector
192
+ return acc + (acc ? ' ' : '') + '*';
193
+ }
194
+ else if (part.startsWith('__')) {
163
195
  return acc + (acc ? ' ' : '') + '.' + part.slice(2);
164
196
  }
165
197
  else if (part.startsWith('_')) {
@@ -181,6 +213,10 @@ export const joinSelectorPath = (path) => {
181
213
  else if (isHtmlTag(part)) {
182
214
  return acc + (acc ? ' ' : '') + part;
183
215
  }
216
+ else if (startsWithHtmlTag(part)) {
217
+ // Handle compound selectors that start with HTML tags (e.g., 'div > *')
218
+ return acc + (acc ? ' ' : '') + part;
219
+ }
184
220
  else if (/^([a-z][a-z0-9]*)\.(.+)/.test(part)) {
185
221
  // If part matches 'tag.class...' and tag is an HTML tag
186
222
  const match = part.match(/^([a-z][a-z0-9]*)\.(.+)/);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esm-styles",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "A library for working with ESM styles",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",