@lovrozagar/flare 0.9.0 → 0.9.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovrozagar/flare",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Solid meta-framework. Server-driven, NDJSON streaming, renderToStream.",
5
5
  "keywords": [
6
6
  "flare",
@@ -37,18 +37,18 @@ function cssEscapeClass(cls: string): string {
37
37
  return cls.replace(/([^a-zA-Z0-9_-])/g, "\\$1");
38
38
  }
39
39
 
40
- function selectorMatchesAny(selector: string, prefixes: Set<string>): boolean {
40
+ /**
41
+ * What follows a requested utility's own class in `selector`: "" for the bare class, the variant
42
+ * suffix (`[aria-pressed="true"]`, `:focus-visible:disabled`, `:where(...)`, ` .child`) otherwise,
43
+ * or null when the selector is not that utility (`.p-40` is not `.p-4`).
44
+ */
45
+ function suffixAfterUtility(selector: string, prefixes: Set<string>): string | null {
41
46
  for (const prefix of prefixes) {
42
- if (
43
- selector === prefix ||
44
- selector.startsWith(`${prefix}:`) ||
45
- selector.startsWith(`${prefix} `) ||
46
- selector.startsWith(`${prefix},`)
47
- ) {
48
- return true;
49
- }
47
+ if (!selector.startsWith(prefix)) continue;
48
+ const suffix = selector.slice(prefix.length);
49
+ if (suffix === "" || /^[:[ ,]/.test(suffix)) return suffix;
50
50
  }
51
- return false;
51
+ return null;
52
52
  }
53
53
 
54
54
  function extractLayerContent(css: string, atStart: number): string {
@@ -108,13 +108,15 @@ function extractDeclsInner(css: string, selectorSet?: Set<string>): string {
108
108
  }
109
109
  }
110
110
  const body = remaining.slice(braceStart + 1, i).trim();
111
- const matchesFilter = !selectorSet || selectorMatchesAny(selector, selectorSet);
112
- if (matchesFilter && body.length > 0) {
113
- const pseudo = extractPseudo(selector);
114
- if (pseudo) {
115
- result.push(`&${pseudo} { ${body} }`);
111
+ if (body.length > 0) {
112
+ if (selectorSet) {
113
+ /* Keep the whole variant suffix: flattened attribute variants and chained pseudos. */
114
+ const suffix = suffixAfterUtility(selector, selectorSet);
115
+ if (suffix === "" || suffix?.startsWith(",")) result.push(body);
116
+ else if (suffix !== null) result.push(`&${suffix} { ${body} }`);
116
117
  } else {
117
- result.push(body);
118
+ const pseudo = extractPseudo(selector);
119
+ result.push(pseudo ? `&${pseudo} { ${body} }` : body);
118
120
  }
119
121
  }
120
122
  remaining = remaining.slice(i + 1).trim();