mnfst 0.5.312 → 0.5.314

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.
@@ -353,9 +353,6 @@ function createVariants() {
353
353
  'xl': '@media (min-width: 1280px)',
354
354
  '2xl': '@media (min-width: 1536px)',
355
355
 
356
- // Supports queries
357
- 'supports': '@supports',
358
-
359
356
  // Starting style
360
357
  'starting': '@starting-style',
361
358
 
@@ -1915,14 +1912,14 @@ TailwindCompiler.prototype.parseClassName = function (className) {
1915
1912
  // Generate utilities from CSS variables
1916
1913
  TailwindCompiler.prototype.generateUtilitiesFromVars = function (cssText, usedData) {
1917
1914
  try {
1918
- const utilities = [];
1915
+ const out = [];
1919
1916
  const generatedRules = new Set(); // Track generated rules to prevent duplicates
1920
1917
  const variables = this.extractThemeVariables(cssText);
1921
1918
  const { classes: usedClasses, variableSuffixes } = usedData;
1922
1919
  // Optional: raw rules + their full-regen order keys (incremental apply places deltas by them)
1923
1920
  const rulesOut = usedData.rulesOut, keysOut = usedData.keysOut;
1924
1921
  let slot = null;
1925
- const emit = (rule, sub) => { utilities.push(rule); if (rulesOut) { rulesOut.push(rule); keysOut.push(slot.concat(slot[3] ? 2 : sub)); } }; // opacity rules order by discovery
1922
+ const emit = (rule, sub, order) => { out.push({ rule, key: ruleKey(rule, order, slot.concat(slot[3] ? 2 : sub)) }); }; // opacity rules order by discovery
1926
1923
 
1927
1924
  if (variables.size === 0) {
1928
1925
  return '';
@@ -2028,7 +2025,7 @@ TailwindCompiler.prototype.generateUtilitiesFromVars = function (cssText, usedDa
2028
2025
  const finalRule = hasMediaQuery ? wrapAtRules(atRules, rule) : rule;
2029
2026
 
2030
2027
  if (!generatedRules.has(finalRule)) {
2031
- emit(finalRule, 2);
2028
+ emit(finalRule, 2, atRuleOrder(parsed.variants));
2032
2029
  generatedRules.add(finalRule);
2033
2030
  }
2034
2031
  }
@@ -2106,7 +2103,7 @@ TailwindCompiler.prototype.generateUtilitiesFromVars = function (cssText, usedDa
2106
2103
  }
2107
2104
  }
2108
2105
 
2109
- return utilities.join('\n');
2106
+ return flushEntries(out, rulesOut, keysOut);
2110
2107
  } catch (error) {
2111
2108
  console.error('Error generating utilities:', error);
2112
2109
  return '';
@@ -2143,6 +2140,76 @@ function breakpointRank(name) {
2143
2140
  return bp.max ? -bp.px : bp.px;
2144
2141
  }
2145
2142
 
2143
+ // ---- At-rule order (Tailwind v4 variant order; the highest-order variant decides, then the next) ----
2144
+ const NO_RANK = -1e9;
2145
+ const ORDER_STEP = 1e7;
2146
+ const BREAKPOINT_ORDER = 10;
2147
+ const MEDIA_ORDER = [
2148
+ [/prefers-reduced-motion:\s*no-preference/, 1], [/prefers-reduced-motion:\s*reduce/, 2],
2149
+ [/prefers-contrast:\s*more/, 3], [/prefers-contrast:\s*less/, 4],
2150
+ [/orientation:\s*portrait/, 21], [/orientation:\s*landscape/, 22], [/prefers-color-scheme/, 23],
2151
+ [/^@media print/, 25], [/forced-colors/, 26], [/inverted-colors/, 27],
2152
+ [/\(pointer:\s*none/, 28], [/\(pointer:\s*coarse/, 29], [/\(pointer:\s*fine/, 30],
2153
+ [/any-pointer:\s*none/, 31], [/any-pointer:\s*coarse/, 32], [/any-pointer:\s*fine/, 33],
2154
+ [/scripting:\s*none/, 34]
2155
+ ];
2156
+
2157
+ function toPx(size) {
2158
+ const u = /^(-?\d*\.?\d+)(px|rem|em)$/.exec(size.trim());
2159
+ return u ? parseFloat(u[1]) * (u[2] === 'px' ? 1 : 16) : null;
2160
+ }
2161
+
2162
+ // Width condition → rank (max widest first, then min ascending); null if none
2163
+ function widthRank(selector) {
2164
+ let m = /\((?:min-width:\s*|width\s*>=\s*)([^)]+)\)/.exec(selector);
2165
+ if (m) { const px = toPx(m[1]); return px === null ? 1e5 : px; }
2166
+ m = /\((?:max-width:\s*|width\s*<\s*)([^)]+)\)/.exec(selector);
2167
+ if (m) { const px = toPx(m[1]); return px === null ? -1e5 : -px; }
2168
+ return null;
2169
+ }
2170
+
2171
+ // One at-rule variant's place in Tailwind's order; null for selector variants
2172
+ function variantOrder(selector) {
2173
+ if (typeof selector !== 'string' || !selector.startsWith('@')) return null;
2174
+ if (selector.startsWith('@supports')) return 0;
2175
+ if (selector.startsWith('@container')) return 20 * ORDER_STEP + (widthRank(selector) || 0);
2176
+ if (selector.startsWith('@starting-style')) return 24 * ORDER_STEP;
2177
+ if (!selector.startsWith('@media')) return 40 * ORDER_STEP;
2178
+ const r = widthRank(selector);
2179
+ if (r !== null) return BREAKPOINT_ORDER * ORDER_STEP + r;
2180
+ for (const [re, n] of MEDIA_ORDER) if (re.test(selector)) return n * ORDER_STEP;
2181
+ return 40 * ORDER_STEP;
2182
+ }
2183
+
2184
+ // Top three at-rule variant orders, highest first (md: before motion-safe:md: before lg:)
2185
+ function atRuleOrder(variants) {
2186
+ const orders = [];
2187
+ for (const v of variants || []) {
2188
+ const o = v && variantOrder(v.selector);
2189
+ if (o !== null && o !== undefined) orders.push(o);
2190
+ }
2191
+ orders.sort((a, b) => b - a);
2192
+ return [0, 1, 2].map(i => i < orders.length ? orders[i] : NO_RANK);
2193
+ }
2194
+
2195
+ // Full order key: [at-rule, o1, o2, o3, section, var/entry, pair/array, opacity, sub]
2196
+ const KEY_SECTION = 4;
2197
+ function ruleKey(rule, order, slotKey) {
2198
+ const head = isAtRule(rule) ? [1].concat(order || [40 * ORDER_STEP, NO_RANK, NO_RANK]) : [0, 0, 0, 0];
2199
+ return head.concat(slotKey);
2200
+ }
2201
+
2202
+ function sortEntries(entries) {
2203
+ return entries.slice().sort((a, b) => compareKeys(a.key, b.key));
2204
+ }
2205
+
2206
+ // Sorted text; raw rules + keys go to rulesOut/keysOut when the caller asked for them
2207
+ function flushEntries(out, rulesOut, keysOut) {
2208
+ const sorted = sortEntries(out);
2209
+ if (rulesOut) for (const e of sorted) { rulesOut.push(e.rule); keysOut.push(e.key); }
2210
+ return sorted.map(e => e.rule).join('\n');
2211
+ }
2212
+
2146
2213
  // Top-level display declarations only (nested blocks ignored)
2147
2214
  function topLevelDisplay(css) {
2148
2215
  let flat = '', depth = 0;
@@ -2188,12 +2255,12 @@ function tailwindResponsiveDisplay(usedClasses) {
2188
2255
  // Generate custom utilities from discovered custom utility classes
2189
2256
  TailwindCompiler.prototype.generateCustomUtilities = function (usedData) {
2190
2257
  try {
2191
- const utilities = [];
2258
+ const out = [];
2192
2259
  const generatedRules = new Set();
2193
2260
  const { classes: usedClasses } = usedData;
2194
2261
  const rulesOut = usedData.rulesOut, keysOut = usedData.keysOut;
2195
2262
  let slot = null;
2196
- const emit = (rule, sub) => { utilities.push(rule); if (rulesOut) { rulesOut.push(rule); keysOut.push(slot.concat(sub)); } };
2263
+ const emit = (rule, sub, order) => { out.push({ rule, key: ruleKey(rule, order, slot.concat(sub)) }); };
2197
2264
  const responsiveDisplay = [];
2198
2265
 
2199
2266
  // Helper to clean up [object Object] from CSS strings
@@ -2537,7 +2604,7 @@ TailwindCompiler.prototype.generateCustomUtilities = function (usedData) {
2537
2604
  }
2538
2605
 
2539
2606
  if (!generatedRules.has(finalRule)) {
2540
- emit(finalRule, 2);
2607
+ emit(finalRule, 2, atRuleOrder(parsed.variants));
2541
2608
  generatedRules.add(finalRule);
2542
2609
  }
2543
2610
  }
@@ -2630,70 +2697,46 @@ TailwindCompiler.prototype.generateCustomUtilities = function (usedData) {
2630
2697
  const rule = `${e.media} { ${own}${own} { display: ${e.css} } }`;
2631
2698
  if (generatedRules.has(rule)) continue;
2632
2699
  generatedRules.add(rule);
2633
- slot = [2, e.rank, 0, 0];
2634
- emit(rule, 2);
2700
+ slot = [2, 0, 0, 0];
2701
+ emit(rule, 2, [BREAKPOINT_ORDER * ORDER_STEP + e.rank, NO_RANK, NO_RANK]);
2635
2702
  }
2636
2703
  }
2637
2704
 
2638
- return utilities.join('\n');
2705
+ return flushEntries(out, rulesOut, keysOut);
2639
2706
  } catch (error) {
2640
2707
  console.error('Error generating custom utilities:', error);
2641
2708
  return '';
2642
2709
  }
2643
2710
  };
2644
2711
 
2645
- // Split generated CSS into top-level rules (each starts with . or an at-rule)
2646
- TailwindCompiler.prototype.splitUtilityRules = function (utilitiesText) {
2647
- const rules = [];
2648
- let currentRule = '';
2649
- for (const line of utilitiesText.split('\n')) {
2650
- if (line.trim().match(/^(\.|@media|@layer|@supports)/)) {
2651
- if (currentRule.trim()) rules.push(currentRule.trim());
2652
- currentRule = line;
2653
- } else {
2654
- currentRule += '\n' + line;
2655
- }
2656
- }
2657
- if (currentRule.trim()) rules.push(currentRule.trim());
2658
- return rules;
2712
+ // Rules + order keys for theme and custom utilities, in sheet order (base, then at-rules in Tailwind variant order).
2713
+ // Full compile, incremental apply, cache text and the node bake all write this order.
2714
+ TailwindCompiler.prototype.generateOrderedUtilities = function (themeCss, usedData) {
2715
+ const data = Object.assign({}, usedData, { rulesOut: [], keysOut: [] });
2716
+ this.generateUtilitiesFromVars(themeCss, data);
2717
+ this.generateCustomUtilities(data);
2718
+ return sortEntries(data.rulesOut.map((rule, i) => ({ rule, key: data.keysOut[i] })));
2659
2719
  };
2660
2720
 
2661
- // Sort utilities so base classes come before variants (@media)
2662
- TailwindCompiler.prototype.sortUtilities = function (utilitiesText) {
2663
- if (!utilitiesText) return '';
2664
- const rules = this.splitUtilityRules(utilitiesText);
2665
- rules.sort((a, b) => {
2666
- const aHasMedia = a.startsWith('@media');
2667
- const bHasMedia = b.startsWith('@media');
2668
- if (!aHasMedia && bHasMedia) return -1;
2669
- if (aHasMedia && !bHasMedia) return 1;
2670
- return 0;
2671
- });
2672
- return rules.join('\n\n');
2721
+ TailwindCompiler.prototype.orderedUtilitiesCss = function (entries) {
2722
+ return entries.map(e => e.rule).join('\n\n');
2673
2723
  };
2674
2724
 
2675
2725
  // ---- Incremental apply: new rules go in through CSSOM, never a whole-sheet rewrite ----
2676
2726
  // Entries mirror the layer's cssRules 1:1, each keyed by where a full regen would emit it
2677
- // ([media, section, var/entry, pair/array, region, sub]); deltas are inserted at that index.
2727
+ // (see ruleKey); deltas are inserted at that index.
2678
2728
 
2679
2729
  const utilitiesCssFrom = (applied) => `@layer utilities {\n${applied.entries.map(e => e.rule).join('\n\n')}\n}`;
2680
- const isMediaRule = (rule) => rule.trim().startsWith('@media');
2730
+ const isAtRule = (rule) => rule.trim().startsWith('@');
2681
2731
 
2682
2732
  function compareKeys(a, b) {
2683
2733
  for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return a[i] - b[i];
2684
2734
  return 0;
2685
2735
  }
2686
2736
 
2687
- // Raw rules + order keys for a class set, as a full regen would emit them (base before @media, stable)
2737
+ // Raw rules + order keys for a class set, as a full regen would emit them
2688
2738
  TailwindCompiler.prototype.generateKeyedUtilities = function (themeCss, classes) {
2689
- const usedData = { classes, variableSuffixes: [], rulesOut: [], keysOut: [] };
2690
- this.generateUtilitiesFromVars(themeCss, usedData);
2691
- this.generateCustomUtilities(usedData);
2692
- const out = usedData.rulesOut.map((rule, i) => {
2693
- const media = isMediaRule(rule) ? 1 : 0;
2694
- return { rule, key: [media].concat(usedData.keysOut[i]) };
2695
- });
2696
- return out.filter(e => !e.key[0]).concat(out.filter(e => e.key[0]));
2739
+ return this.generateOrderedUtilities(themeCss, { classes, variableSuffixes: [] });
2697
2740
  };
2698
2741
 
2699
2742
  TailwindCompiler.prototype.utilitiesLayerRule = function () {
@@ -2712,7 +2755,7 @@ TailwindCompiler.prototype.entriesMatchSheet = function (entries) {
2712
2755
  const layer = this.utilitiesLayerRule();
2713
2756
  if (!layer || layer.cssRules.length !== entries.length) return false;
2714
2757
  for (let i = 0; i < entries.length; i++) {
2715
- if ((layer.cssRules[i] instanceof CSSMediaRule) !== !!entries[i].key[0]) return false;
2758
+ if (!(layer.cssRules[i] instanceof CSSStyleRule) !== !!entries[i].key[0]) return false;
2716
2759
  }
2717
2760
  return true;
2718
2761
  };
@@ -2752,7 +2795,11 @@ TailwindCompiler.prototype.compileDelta = function (themeCss) {
2752
2795
  const candidates = [];
2753
2796
  for (const cls of this.dynamicClassCache) if (!applied.classes.has(cls)) candidates.push(cls);
2754
2797
  const classes = this.filterStaticallyCoveredClasses(candidates);
2798
+ // Tailwind display classes at a breakpoint join the display block, which only a full regen emits
2799
+ if (tailwindResponsiveDisplay(classes).length) return false;
2755
2800
  const fresh = classes.length ? this.generateKeyedUtilities(themeCss, classes).filter(e => !applied.rules.has(e.rule)) : [];
2801
+ // The display block's contents depend on every used class: a new block rule means a full regen
2802
+ if (fresh.some(e => e.key[KEY_SECTION] === 2)) return false;
2756
2803
  const entries = applied.entries;
2757
2804
 
2758
2805
  // Place every rule first; bail before touching the sheet if any is ambiguous
@@ -2760,9 +2807,10 @@ TailwindCompiler.prototype.compileDelta = function (themeCss) {
2760
2807
  for (const e of fresh) {
2761
2808
  let lo = 0, hi = entries.length;
2762
2809
  while (lo < hi) { const mid = (lo + hi) >> 1; if (compareKeys(entries[mid].key, e.key) <= 0) lo = mid + 1; else hi = mid; }
2763
- // Same utility, same group, both variants: full regen orders them by discovery
2764
- if (e.key[5] === 2) {
2765
- const sameSlot = (x) => x && compareKeys(x.key.slice(0, 5), e.key.slice(0, 5)) === 0 && x.key[5] === 2;
2810
+ // Same utility, same media rank, both variants: full regen orders them by discovery
2811
+ const last = e.key.length - 1;
2812
+ if (e.key[last] === 2) {
2813
+ const sameSlot = (x) => x && compareKeys(x.key.slice(0, last), e.key.slice(0, last)) === 0 && x.key[last] === 2;
2766
2814
  if (sameSlot(entries[lo - 1]) || sameSlot(entries[lo]) || plan.some(q => sameSlot(q.e))) return false;
2767
2815
  }
2768
2816
  plan.push({ e, at: lo });
@@ -2966,14 +3014,8 @@ TailwindCompiler.prototype.compile = async function () {
2966
3014
  }
2967
3015
  }
2968
3016
 
2969
- // Generate both variable-based and custom utilities
2970
- const varUtilities = this.generateUtilitiesFromVars(themeCss, staticUsedData);
2971
- const customUtilitiesGenerated = this.generateCustomUtilities(staticUsedData);
3017
+ const allUtilities = this.orderedUtilitiesCss(this.generateOrderedUtilities(themeCss, staticUsedData));
2972
3018
 
2973
- let allUtilities = [varUtilities, customUtilitiesGenerated].filter(Boolean).join('\n\n');
2974
- // Sort utilities so base classes come before variants
2975
- allUtilities = this.sortUtilities(allUtilities);
2976
-
2977
3019
  if (allUtilities) {
2978
3020
  const finalCss = `@layer utilities {\n${allUtilities}\n}`;
2979
3021
 
@@ -3057,16 +3099,9 @@ TailwindCompiler.prototype.compile = async function () {
3057
3099
  // Generate utilities for all classes (static + dynamic) if needed
3058
3100
  if (hasVariableChanges || dynamicClassesHash !== this.lastClassesHash) {
3059
3101
 
3060
- // Generate both variable-based and custom utilities
3061
- const rulesOut = [], keysOut = [];
3062
- const keyedData = Object.assign({}, usedData, { rulesOut, keysOut });
3063
- const varUtilities = this.generateUtilitiesFromVars(themeCss, keyedData);
3064
- const customUtilitiesGenerated = this.generateCustomUtilities(keyedData);
3102
+ const entries = this.generateOrderedUtilities(themeCss, usedData);
3103
+ const allUtilities = this.orderedUtilitiesCss(entries);
3065
3104
 
3066
- let allUtilities = [varUtilities, customUtilitiesGenerated].filter(Boolean).join('\n\n');
3067
- // Sort utilities so base classes come before variants
3068
- allUtilities = this.sortUtilities(allUtilities);
3069
-
3070
3105
  if (allUtilities) {
3071
3106
  const finalCss = `@layer utilities {\n${allUtilities}\n}`;
3072
3107
 
@@ -3087,8 +3122,7 @@ TailwindCompiler.prototype.compile = async function () {
3087
3122
  });
3088
3123
  });
3089
3124
  this.lastClassesHash = dynamicClassesHash;
3090
- const entries = rulesOut.map((rule, i) => ({ rule, key: [isMediaRule(rule) ? 1 : 0].concat(keysOut[i]) }));
3091
- this.recordAppliedUtilities(entries.filter(e => !e.key[0]).concat(entries.filter(e => e.key[0])), themeCss, dynamicClasses);
3125
+ this.recordAppliedUtilities(entries, themeCss, dynamicClasses);
3092
3126
  // Classes that arrived during the await above still need a pass
3093
3127
  if (this.dynamicClassCache.size > dynamicClasses.length) this.compile();
3094
3128
 
@@ -3359,11 +3393,7 @@ export async function compileUtilities({ classes = [], themeCss = '', baseCss =
3359
3393
 
3360
3394
  const usedData = { classes: uniqueClasses, variableSuffixes: [] };
3361
3395
 
3362
- const varUtilities = compiler.generateUtilitiesFromVars(cssText, usedData);
3363
- const customUtilities = compiler.generateCustomUtilities(usedData);
3364
-
3365
- let allUtilities = [varUtilities, customUtilities].filter(Boolean).join('\n\n');
3366
- allUtilities = compiler.sortUtilities(allUtilities);
3396
+ const allUtilities = compiler.orderedUtilitiesCss(compiler.generateOrderedUtilities(cssText, usedData));
3367
3397
 
3368
3398
  const manifestLayer = allUtilities ? `@layer utilities {\n${allUtilities}\n}` : '';
3369
3399
  const tailwindLayer = await compileTailwindPass(uniqueClasses, tailwind);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst",
3
- "version": "0.5.312",
3
+ "version": "0.5.314",
4
4
  "private": false,
5
5
  "workspaces": [
6
6
  "templates/starter",
@@ -63,6 +63,7 @@
63
63
  "test:e2e:prerender-patch": "node tests/e2e/utilities-prerender-patch.e2e.mjs",
64
64
  "test:e2e:hidden-responsive": "node tests/e2e/utilities-hidden-responsive.e2e.mjs",
65
65
  "test:e2e:breakpoint-range": "node tests/e2e/utilities-breakpoint-range.e2e.mjs",
66
+ "test:e2e:responsive-order": "node tests/e2e/utilities-responsive-order.e2e.mjs",
66
67
  "test:e2e:tailwind-dark": "node tests/e2e/tailwind-dark-variant.e2e.mjs",
67
68
  "test:e2e:inline-style-variants": "node tests/e2e/utilities-inline-style-variants.e2e.mjs",
68
69
  "test:e2e:presence-tabs": "node tests/e2e/presence-tabs.e2e.mjs",