mnfst 0.5.287 → 0.5.289

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.
@@ -372,58 +372,30 @@ function createVariants() {
372
372
  'android': 'html[data-os="android"] &',
373
373
  'apple': 'html[data-os="macos"] &, html[data-os="ios"] &',
374
374
 
375
- // Data attribute variants (common patterns)
376
- 'data-open': '[data-state="open"] &',
377
- 'data-closed': '[data-state="closed"] &',
378
- 'data-checked': '[data-state="checked"] &',
379
- 'data-unchecked': '[data-state="unchecked"] &',
380
- 'data-on': '[data-state="on"] &',
381
- 'data-off': '[data-state="off"] &',
382
- 'data-visible': '[data-state="visible"] &',
383
- 'data-hidden': '[data-state="hidden"] &',
384
- 'data-disabled': '[data-disabled] &',
385
- 'data-loading': '[data-loading] &',
386
- 'data-error': '[data-error] &',
387
- 'data-success': '[data-success] &',
388
- 'data-warning': '[data-warning] &',
389
- 'data-selected': '[data-selected] &',
390
- 'data-highlighted': '[data-highlighted] &',
391
- 'data-pressed': '[data-pressed] &',
392
- 'data-expanded': '[data-expanded] &',
393
- 'data-collapsed': '[data-collapsed] &',
394
- 'data-active': '[data-active] &',
395
- 'data-inactive': '[data-inactive] &',
396
- 'data-valid': '[data-valid] &',
397
- 'data-invalid': '[data-invalid] &',
398
- 'data-required': '[data-required] &',
399
- 'data-optional': '[data-optional] &',
400
- 'data-readonly': '[data-readonly] &',
401
- 'data-write': '[data-write] &',
402
-
403
- // Aria attribute variants (common patterns)
404
- 'aria-expanded': '[aria-expanded="true"] &',
405
- 'aria-collapsed': '[aria-expanded="false"] &',
406
- 'aria-pressed': '[aria-pressed="true"] &',
407
- 'aria-unpressed': '[aria-pressed="false"] &',
408
- 'aria-checked': '[aria-checked="true"] &',
409
- 'aria-unchecked': '[aria-checked="false"] &',
410
- 'aria-selected': '[aria-selected="true"] &',
411
- 'aria-unselected': '[aria-selected="false"] &',
412
- 'aria-invalid': '[aria-invalid="true"] &',
413
- 'aria-valid': '[aria-invalid="false"] &',
414
- 'aria-required': '[aria-required="true"] &',
415
- 'aria-optional': '[aria-required="false"] &',
416
- 'aria-disabled': '[aria-disabled="true"] &',
417
- 'aria-enabled': '[aria-disabled="false"] &',
418
- 'aria-hidden': '[aria-hidden="true"] &',
419
- 'aria-visible': '[aria-hidden="false"] &',
420
- 'aria-busy': '[aria-busy="true"] &',
421
- 'aria-available': '[aria-busy="false"] &',
422
- 'aria-current': '[aria-current="true"] &',
423
- 'aria-not-current': '[aria-current="false"] &',
424
- 'aria-live': '[aria-live="polite"] &, [aria-live="assertive"] &',
425
- 'aria-atomic': '[aria-atomic="true"] &',
426
- 'aria-relevant': '[aria-relevant="additions"] &, [aria-relevant="removals"] &, [aria-relevant="text"] &, [aria-relevant="all"] &'
375
+ // Attribute variants sit on the element itself (Tailwind v4); data-*, data-[…] and aria-[…] are parsed in parseClassName
376
+ 'aria-expanded': '&[aria-expanded="true"]',
377
+ 'aria-collapsed': '&[aria-expanded="false"]',
378
+ 'aria-pressed': '&[aria-pressed="true"]',
379
+ 'aria-unpressed': '&[aria-pressed="false"]',
380
+ 'aria-checked': '&[aria-checked="true"]',
381
+ 'aria-unchecked': '&[aria-checked="false"]',
382
+ 'aria-selected': '&[aria-selected="true"]',
383
+ 'aria-unselected': '&[aria-selected="false"]',
384
+ 'aria-invalid': '&[aria-invalid="true"]',
385
+ 'aria-valid': '&[aria-invalid="false"]',
386
+ 'aria-required': '&[aria-required="true"]',
387
+ 'aria-optional': '&[aria-required="false"]',
388
+ 'aria-disabled': '&[aria-disabled="true"]',
389
+ 'aria-enabled': '&[aria-disabled="false"]',
390
+ 'aria-hidden': '&[aria-hidden="true"]',
391
+ 'aria-visible': '&[aria-hidden="false"]',
392
+ 'aria-busy': '&[aria-busy="true"]',
393
+ 'aria-available': '&[aria-busy="false"]',
394
+ 'aria-current': '&[aria-current="true"]',
395
+ 'aria-not-current': '&[aria-current="false"]',
396
+ 'aria-live': '&:is([aria-live="polite"], [aria-live="assertive"])',
397
+ 'aria-atomic': '&[aria-atomic="true"]',
398
+ 'aria-relevant': '&:is([aria-relevant="additions"], [aria-relevant="removals"], [aria-relevant="text"], [aria-relevant="all"])'
427
399
  };
428
400
  }
429
401
 
@@ -955,19 +927,21 @@ TailwindCompiler.prototype.extractClassesFromHTML = function (html, classSet) {
955
927
  }
956
928
  }
957
929
 
958
- // Also check for x-data and other Alpine directives that might contain classes
959
- const alpineRegex = /x-(?:data|bind:class|class)=["']([^"']+)["']/g;
930
+ // Alpine class bindings: every literal they could apply
931
+ const bindingRegex = /(?<![\w-])(?::|x-bind:)class=(["'])((?:(?!\1)[\s\S])*)\1/g;
932
+ while ((match = bindingRegex.exec(html)) !== null) {
933
+ this.collectBindingClasses(match[2], classSet);
934
+ }
935
+
936
+ // x-data is arbitrary JS: keep single-token string literals only
937
+ const alpineRegex = /x-data=["']([^"']+)["']/g;
960
938
  while ((match = alpineRegex.exec(html)) !== null) {
961
- // Simple extraction - could be enhanced for complex Alpine expressions
962
939
  const content = match[1];
963
940
  const classMatches = content.match(/['"`]([^'"`\s]+)['"`]/g);
964
941
  if (classMatches) {
965
942
  for (const classMatch of classMatches) {
966
943
  const cls = classMatch.replace(/['"`]/g, '');
967
- // x-data is arbitrary JS — a plain string literal in there
968
- // (e.g. `location.pathname.split('/')`) matches this quoted-
969
- // token scan too, so require a letter/digit; a punctuation-only
970
- // "token" like a bare '/' is skipped (seen on a live page).
944
+ // Skip punctuation-only literals such as split('/')
971
945
  if (cls && !cls.startsWith('$') && !cls.includes('(') && /[a-zA-Z0-9]/.test(cls)) {
972
946
  classSet.add(cls);
973
947
  }
@@ -976,6 +950,26 @@ TailwindCompiler.prototype.extractClassesFromHTML = function (html, classSet) {
976
950
  }
977
951
  };
978
952
 
953
+ // Class names a :class / x-bind:class expression can apply: string literals and object keys
954
+ TailwindCompiler.prototype.collectBindingClasses = function (expr, classSet) {
955
+ if (!expr) return;
956
+ if (expr.includes('&')) expr = expr.replace(/&quot;/g, '"').replace(/&#0?39;|&apos;/g, "'").replace(/&amp;/g, '&');
957
+ const add = (token) => {
958
+ if (!token || token.startsWith('x-') || token.startsWith('$') || !/[a-zA-Z0-9]/.test(token)) return;
959
+ if (token.includes('://') || /^\d+:/.test(token)) return; // URLs, times
960
+ if ((token.includes('[') ? /[{}'"`$;]/ : /[(){}'"`$;,]/).test(token)) return;
961
+ classSet.add(token);
962
+ };
963
+ const literal = /(['"`])((?:\\[\s\S]|(?!\1)[^\\])*)\1/g;
964
+ let m;
965
+ while ((m = literal.exec(expr)) !== null) {
966
+ for (const token of m[2].split(/\s+/)) add(token);
967
+ if (m[1] === '`' && m[2].includes('${')) this.collectBindingClasses(m[2].replace(/`/g, ' '), classSet);
968
+ }
969
+ const bareKey = /[{,]\s*([A-Za-z_][\w-]*)\s*:/g;
970
+ while ((m = bareKey.exec(expr)) !== null) add(m[1]);
971
+ };
972
+
979
973
  // Get all used classes from static and dynamic sources
980
974
  TailwindCompiler.prototype.getUsedClasses = function () {
981
975
  try {
@@ -986,6 +980,10 @@ TailwindCompiler.prototype.getUsedClasses = function () {
986
980
  for (const cls of this.staticClassCache) {
987
981
  allClasses.add(cls);
988
982
  }
983
+ // Classes seen so far, including binding literals not yet in the DOM
984
+ for (const cls of this.dynamicClassCache) {
985
+ allClasses.add(cls);
986
+ }
989
987
 
990
988
  // Scan current DOM for dynamic classes only
991
989
  const elements = document.getElementsByTagName('*');
@@ -1671,6 +1669,19 @@ TailwindCompiler.prototype.isTailwindGeneratedClass = function (className) {
1671
1669
  return tailwindPatterns.some(pattern => pattern.test(className));
1672
1670
  };
1673
1671
 
1672
+ // `[data-good]`, `[data-tone="good"]`, `[aria-busy="true"]` for a data-/aria- variant's remainder
1673
+ function attributeVariantCondition(kind, rest) {
1674
+ if (rest.startsWith('[') && rest.endsWith(']')) {
1675
+ const m = rest.slice(1, -1).match(/^([a-zA-Z0-9_-]+)(?:([~|^$*]?=)(.+))?$/);
1676
+ if (!m) return null;
1677
+ if (!m[2]) return `[${kind}-${m[1]}]`;
1678
+ const value = m[3].replace(/^(['"])(.*)\1$/, '$2').replace(/_/g, ' ').replace(/"/g, '\\"');
1679
+ return `[${kind}-${m[1]}${m[2]}"${value}"]`;
1680
+ }
1681
+ if (!/^[a-zA-Z0-9_-]+$/.test(rest)) return null;
1682
+ return kind === 'aria' ? `[aria-${rest}="true"]` : `[data-${rest}]`;
1683
+ }
1684
+
1674
1685
  // Parse a class name into its components (variants, base class, important)
1675
1686
  TailwindCompiler.prototype.parseClassName = function (className) {
1676
1687
  // Check cache first
@@ -1748,20 +1759,17 @@ TailwindCompiler.prototype.parseClassName = function (className) {
1748
1759
 
1749
1760
  // THIRD: Handle parameterized variants (only if exact match not found)
1750
1761
 
1751
- // Handle data-[...] variants like data-[state=active] (not starting with bracket)
1752
- // These should be regular attribute selectors, not arbitrary
1753
- const dataMatch = variant.match(/^data-\[(.+)\]$/);
1754
- if (dataMatch) {
1755
- const attrValue = dataMatch[1];
1756
- // Add quotes around the value if it contains = (e.g., state=active -> state="active")
1757
- const quotedValue = attrValue.includes('=')
1758
- ? attrValue.replace(/^([^=]+)=(.+)$/, '$1="$2"')
1759
- : attrValue;
1760
- return {
1761
- name: variant,
1762
- selector: `[data-${quotedValue}] &`,
1763
- isArbitrary: false
1764
- };
1762
+ // Attribute variants (Tailwind v4): the condition sits on the element; group-/peer- move it to the marker
1763
+ const attrMatch = variant.match(/^(group-|peer-)?(data|aria)-(.+)$/);
1764
+ if (attrMatch) {
1765
+ const named = attrMatch[1] && /^&([[:][^&]*)$/.exec(this.variants[`${attrMatch[2]}-${attrMatch[3]}`] || '');
1766
+ const condition = named ? named[1] : attributeVariantCondition(attrMatch[2], attrMatch[3]);
1767
+ if (condition) {
1768
+ const selector = !attrMatch[1] ? `&${condition}`
1769
+ : attrMatch[1] === 'group-' ? `:where(.group${condition}) &`
1770
+ : `:where(.peer${condition}) ~ &`;
1771
+ return { name: variant, selector, isArbitrary: false };
1772
+ }
1765
1773
  }
1766
1774
 
1767
1775
  // Handle parameterized nth variants: nth-3, nth-last-2, nth-of-type-2, nth-last-of-type-2
@@ -1869,6 +1877,7 @@ TailwindCompiler.prototype.parseClassName = function (className) {
1869
1877
  this._warnedVariants.add(variant);
1870
1878
  console.warn(`Unknown variant: ${variant}`);
1871
1879
  }
1880
+ result.unknown = true;
1872
1881
  return null;
1873
1882
  }).filter(Boolean);
1874
1883
 
@@ -1937,6 +1946,7 @@ TailwindCompiler.prototype.generateUtilitiesFromVars = function (cssText, usedDa
1937
1946
  if (variantClass === baseClass) continue;
1938
1947
 
1939
1948
  const parsed = this.parseClassName(variantClass);
1949
+ if (parsed.unknown) continue; // never drop a condition and emit unconditionally
1940
1950
 
1941
1951
  // Check if this is an important variant
1942
1952
  const isImportant = parsed.important;
@@ -2255,6 +2265,7 @@ TailwindCompiler.prototype.generateCustomUtilities = function (usedData) {
2255
2265
  if (variantClass === baseClass) continue;
2256
2266
 
2257
2267
  const parsed = this.parseClassName(variantClass);
2268
+ if (parsed.unknown) continue; // never drop a condition and emit unconditionally
2258
2269
 
2259
2270
  // Check if this is an important variant
2260
2271
  const isImportant = parsed.important;
@@ -2586,7 +2597,7 @@ TailwindCompiler.prototype.entriesMatchSheet = function (entries) {
2586
2597
  };
2587
2598
 
2588
2599
  // After a full write: remember its rules so later compiles can insert beside them
2589
- TailwindCompiler.prototype.recordAppliedUtilities = function (entries, themeCss) {
2600
+ TailwindCompiler.prototype.recordAppliedUtilities = function (entries, themeCss, compiledClasses) {
2590
2601
  this._applied = null;
2591
2602
  if (window.__manifestRender === true || !this.entriesMatchSheet(entries)) return;
2592
2603
  this._applied = {
@@ -2594,7 +2605,7 @@ TailwindCompiler.prototype.recordAppliedUtilities = function (entries, themeCss)
2594
2605
  themeCss, // keys index this exact variable order
2595
2606
  entries,
2596
2607
  rules: new Set(entries.map(e => e.rule)),
2597
- classes: new Set(this.dynamicClassCache),
2608
+ classes: new Set(compiledClasses), // only what this write covered
2598
2609
  dirty: false // inserted rules not yet in textContent
2599
2610
  };
2600
2611
  };
@@ -2942,7 +2953,9 @@ TailwindCompiler.prototype.compile = async function () {
2942
2953
  });
2943
2954
  this.lastClassesHash = dynamicClassesHash;
2944
2955
  const entries = rulesOut.map((rule, i) => ({ rule, key: [isMediaRule(rule) ? 1 : 0].concat(keysOut[i]) }));
2945
- this.recordAppliedUtilities(entries.filter(e => !e.key[0]).concat(entries.filter(e => e.key[0])), themeCss);
2956
+ this.recordAppliedUtilities(entries.filter(e => !e.key[0]).concat(entries.filter(e => e.key[0])), themeCss, dynamicClasses);
2957
+ // Classes that arrived during the await above still need a pass
2958
+ if (this.dynamicClassCache.size > dynamicClasses.length) this.compile();
2946
2959
 
2947
2960
  // Save to cache for next page load
2948
2961
  const themeHash = this.generateThemeHash(themeCss);
@@ -3223,18 +3236,12 @@ export async function compileUtilities({ classes = [], themeCss = '', baseCss =
3223
3236
  return `@layer base, components, utilities;\n\n${body}`;
3224
3237
  }
3225
3238
 
3226
- // `class:token=` (per-class conditional binding) and the `:class="..."`
3227
- // shorthand aren't matched by extractClassesFromHTML's `x-(data|bind:class|class)=`
3228
- // regex (no `x-` prefix), so pick those up here too — cheap regex pass, not a
3229
- // JS/expression parser, so only literal-looking quoted tokens are kept.
3239
+ // `class:token=` per-class conditional bindings; extractClassesFromHTML covers `:class`
3230
3240
  const CLASS_TOKEN_BINDING_RE = /\bclass:([a-zA-Z0-9_-]+(?:\\.[a-zA-Z0-9_-]+)*)\s*=/g;
3231
- // Backreference to the opening quote so a nested quote char (`:class="'a b'"`)
3232
- // doesn't truncate the match early.
3233
- const SHORTHAND_CLASS_BINDING_RE = /\B:class=(["'])((?:(?!\1)[\s\S])*)\1/g;
3234
3241
 
3235
3242
  /**
3236
3243
  * Scan HTML for utility class tokens using the same extraction the browser
3237
- * plugin uses (extractClassesFromHTML), plus `class:`/`:class` static tokens.
3244
+ * plugin uses (extractClassesFromHTML, which reads `:class` literals), plus `class:` tokens.
3238
3245
  * Skips `x-`/`$` tokens. Returns a sorted, deduplicated array.
3239
3246
  *
3240
3247
  * `safelist` (manifest.json's `utilities.safelist`) is folded into the result
@@ -3257,19 +3264,5 @@ export function scanClasses(html, { safelist = [] } = {}) {
3257
3264
  if (cls && !cls.startsWith('x-') && !cls.startsWith('$')) set.add(cls);
3258
3265
  }
3259
3266
 
3260
- SHORTHAND_CLASS_BINDING_RE.lastIndex = 0;
3261
- while ((m = SHORTHAND_CLASS_BINDING_RE.exec(html)) !== null) {
3262
- const content = m[2];
3263
- const quoted = content.match(/['"`]([^'"`\s]+)['"`]/g);
3264
- if (quoted) {
3265
- for (const q of quoted) {
3266
- const cls = q.replace(/['"`]/g, '');
3267
- // Reject punctuation-only "tokens" (e.g. a bare '/' from an
3268
- // unrelated string literal in the expression) — see helpers.js.
3269
- if (cls && !cls.startsWith('$') && !cls.startsWith('x-') && !cls.includes('(') && /[a-zA-Z0-9]/.test(cls)) set.add(cls);
3270
- }
3271
- }
3272
- }
3273
-
3274
3267
  return Array.from(set).sort();
3275
3268
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst",
3
- "version": "0.5.287",
3
+ "version": "0.5.289",
4
4
  "private": false,
5
5
  "workspaces": [
6
6
  "templates/starter",