mnfst 0.5.323 → 0.5.325

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,2 +1,2 @@
1
- !function(){"use strict";const t="0.5.323",e="mnfst-sw:",n=e+"meta",a=/\.(css|js|mjs|json|csv|tsv|ya?ml|md|txt|xml|svg|png|jpe?g|gif|webp|avif|ico|bmp|woff2?|ttf|otf|eot|mp3|mp4|webm|ogg|wav|flac|m4a|wasm|webmanifest|map)$/i,s=/^\/(sw\.js$|precache\.json$|v1\/|_appwrite\/|_ai\/|__mnfst|__edit)/,i=/^(cdn\.manifestx\.dev|cdn\.jsdelivr\.net|unpkg\.com|esm\.run)$/,c="https://cdn.manifestx.dev/npm/",r=/^api\.(iconify\.design|simplesvg\.com|unisvg\.com)$/,o=/@\d+\.\d+\.\d+[^/]*(\/|$)/,l=/@[^/]+(\/|$)/;let f=null,u=!1;function m(t){try{return new URL(self.location.href).searchParams.get(t)||""}catch(t){return""}}function h(){return{version:-1===t.indexOf("-dev")?t:m("v")||"dev",deployment:m("d")}}function w(t){return e+t.version+":"+(t.deployment||"-")+":"}async function d(){const t=h();try{const e=await fetch("/manifest.json",{cache:"no-store"});if(e.ok){const n=await e.json();n&&"string"==typeof n.deployment&&n.deployment&&(t.deployment=n.deployment)}}catch(t){}try{const e=await caches.open(n);await e.put("/__meta",new Response(JSON.stringify(t),{headers:{"content-type":"application/json"}}))}catch(t){}return t}function p(){return f||(f=(async()=>{try{const t=await caches.open(n),e=await t.match("/__meta");if(e){const t=await e.json();if(t&&t.version)return t}}catch(t){}return d()})().catch(()=>h())),f}async function y(t){if(u)throw new Error("killed");const e=await p();return caches.open(w(e)+t)}function g(t){return t.url.replace(/([?&])t=\d+(?=&|$)/,"$1").replace(/[?&]$/,"").replace(/\?&/,"?")}function v(t){if("GET"!==t.method)return null;if(t.headers.has("range"))return null;if(-1!==(t.headers.get("accept")||"").indexOf("text/event-stream"))return null;const e=new URL(g(t));if("http:"!==e.protocol&&"https:"!==e.protocol)return null;const n=e.origin===self.location.origin,c=e.pathname;return"navigate"===t.mode||"document"===t.destination?n?"document":null:n?s.test(c)?null:/(^|\/)manifest\.json$/.test(c)?"manifest":e.searchParams.get("v")?"immutable":/\.html?$/i.test(c)?"document":a.test(c)?"swr":null:r.test(e.host)?/\.json$/.test(c)?"immutable":null:i.test(e.host)?o.test(c)||/\/alpinejs@/.test(c)?"immutable":l.test(c)?"swr":null:null}function j(t){return!!t&&t.ok&&!t.redirected&&("basic"===t.type||"cors"===t.type||"default"===t.type)}function _(t){const e=new URL(t.url).origin===self.location.origin||"cors"===t.mode?fetch(t):fetch(new Request(t.url,{mode:"cors",credentials:"omit",redirect:"follow",integrity:t.integrity||""}));if(0!==t.url.indexOf(c))return e;const n=()=>fetch(new Request("https://cdn.jsdelivr.net/npm/"+t.url.slice(30),{mode:"cors",credentials:"omit",redirect:"follow",integrity:t.integrity||""}));return e.then(t=>t.ok?t:n().then(e=>e.ok?e:t).catch(()=>t),()=>n())}async function k(t,e){const n=await y("pages"),a=g(t);try{const e=await fetch(t);return j(e)&&await n.put(a,e.clone()),e}catch(s){const i=await n.match(a,{ignoreSearch:e});if(i)return i;if(e&&"navigate"===t.mode){const t=await n.match("/index.html")||await n.match("/");if(t)return t}throw s}}function $(t,e){const n=t.request;switch(e){case"immutable":return async function(t){const e=await y("assets"),n=g(t),a=await e.match(n);if(a)return a;const s=await _(t);return j(s)&&await e.put(n,s.clone()),s}(n);case"swr":return async function(t,e){const n=await y("swr"),a=g(t),s=await n.match(a),i=(async()=>{const e=await _(t);return j(e)&&(await n.put(a,e.clone()),await async function(t){const e=await t.keys(),n=e.length-500;for(let a=0;a<n;a++)await t.delete(e[a])}(n)),e})();return s?(e.waitUntil(i.catch(()=>{})),s):i}(n,t);case"document":return k(n,!0);case"manifest":return k(n,!1);default:return fetch(n)}}const x={version:h().version,ready:!0};self.__mnfstSw=x,self.addEventListener("install",t=>{try{f=null,t.waitUntil(d().then(t=>{f=Promise.resolve(t)}).catch(()=>{}))}catch(t){}}),self.addEventListener("activate",t=>{try{t.waitUntil((async()=>{if(!self.registration||"undefined"==typeof caches||"function"!=typeof fetch||self.__mnfstSw!==x)return void await self.registration.unregister();const t=await p();await async function(t){const a=w(t),s=await caches.keys();await Promise.all(s.filter(t=>0===t.indexOf(e)&&t!==n&&0!==t.indexOf(a)).map(t=>caches.delete(t)))}(t).catch(()=>{}),async function(t){let e;try{const t=await fetch("/precache.json",{cache:"no-store"});if(!t.ok)return;e=await t.json()}catch(t){return}if(!e||!Array.isArray(e.files))return;if(e.deployment&&t.deployment&&e.deployment!==t.deployment)return;const n=e.files.filter(t=>"string"==typeof t),a=async t=>{try{const e=new Request(new URL(t,self.location.origin).href),n=v(e);if(!n)return;const a="immutable"===n?"assets":"swr"===n?"swr":"pages",s=await y(a),i=g(e);if(await s.match(i))return;const c=await _(e);j(c)&&await s.put(i,c)}catch(t){}};let s=0;await Promise.all(Array.from({length:4},async()=>{for(;s<n.length;)await a(n[s++])}))}(t).catch(()=>{})})().catch(()=>{}))}catch(t){}}),self.addEventListener("fetch",t=>{if(u)return;let e=null;try{e=v(t.request)}catch(t){return}if(e)try{t.respondWith($(t,e).catch(()=>fetch(t.request)))}catch(t){}}),self.addEventListener("message",t=>{try{const n=t.data;if(!n||"manifest:sw"!==n.type)return;const a=e=>{try{const n=t.ports&&t.ports[0];n?n.postMessage(e):t.source&&t.source.postMessage&&t.source.postMessage(e)}catch(t){}};if("ping"===n.action)return void a({type:"manifest:sw",action:"pong"});if("version"===n.action)return void t.waitUntil(p().then(t=>a({type:"manifest:sw",action:"version",version:t.version,deployment:t.deployment,key:w(t)})).catch(()=>{}));"kill"===n.action&&(u=!0,t.waitUntil((async()=>{await async function(){const t=await caches.keys();await Promise.all(t.filter(t=>0===t.indexOf(e)).map(t=>caches.delete(t)))}().catch(()=>{}),await self.registration.unregister().catch(()=>{}),a({type:"manifest:sw",action:"killed"})})().catch(()=>{})))}catch(t){}})}();
1
+ !function(){"use strict";const t="0.5.325",e="mnfst-sw:",n=e+"meta",a=/\.(css|js|mjs|json|csv|tsv|ya?ml|md|txt|xml|svg|png|jpe?g|gif|webp|avif|ico|bmp|woff2?|ttf|otf|eot|mp3|mp4|webm|ogg|wav|flac|m4a|wasm|webmanifest|map)$/i,s=/^\/(sw\.js$|precache\.json$|v1\/|_appwrite\/|_ai\/|__mnfst|__edit)/,i=/^(cdn\.manifestx\.dev|cdn\.jsdelivr\.net|unpkg\.com|esm\.run)$/,c="https://cdn.manifestx.dev/npm/",r=/^api\.(iconify\.design|simplesvg\.com|unisvg\.com)$/,o=/@\d+\.\d+\.\d+[^/]*(\/|$)/,l=/@[^/]+(\/|$)/;let f=null,u=!1;function m(t){try{return new URL(self.location.href).searchParams.get(t)||""}catch(t){return""}}function h(){return{version:-1===t.indexOf("-dev")?t:m("v")||"dev",deployment:m("d")}}function w(t){return e+t.version+":"+(t.deployment||"-")+":"}async function d(){const t=h();try{const e=await fetch("/manifest.json",{cache:"no-store"});if(e.ok){const n=await e.json();n&&"string"==typeof n.deployment&&n.deployment&&(t.deployment=n.deployment)}}catch(t){}try{const e=await caches.open(n);await e.put("/__meta",new Response(JSON.stringify(t),{headers:{"content-type":"application/json"}}))}catch(t){}return t}function p(){return f||(f=(async()=>{try{const t=await caches.open(n),e=await t.match("/__meta");if(e){const t=await e.json();if(t&&t.version)return t}}catch(t){}return d()})().catch(()=>h())),f}async function y(t){if(u)throw new Error("killed");const e=await p();return caches.open(w(e)+t)}function g(t){return t.url.replace(/([?&])t=\d+(?=&|$)/,"$1").replace(/[?&]$/,"").replace(/\?&/,"?")}function v(t){if("GET"!==t.method)return null;if(t.headers.has("range"))return null;if(-1!==(t.headers.get("accept")||"").indexOf("text/event-stream"))return null;const e=new URL(g(t));if("http:"!==e.protocol&&"https:"!==e.protocol)return null;const n=e.origin===self.location.origin,c=e.pathname;return"navigate"===t.mode||"document"===t.destination?n?"document":null:n?s.test(c)?null:/(^|\/)manifest\.json$/.test(c)?"manifest":e.searchParams.get("v")?"immutable":/\.html?$/i.test(c)?"document":a.test(c)?"swr":null:r.test(e.host)?/\.json$/.test(c)?"immutable":null:i.test(e.host)?o.test(c)||/\/alpinejs@/.test(c)?"immutable":l.test(c)?"swr":null:null}function j(t){return!!t&&t.ok&&!t.redirected&&("basic"===t.type||"cors"===t.type||"default"===t.type)}function _(t){const e=new URL(t.url).origin===self.location.origin||"cors"===t.mode?fetch(t):fetch(new Request(t.url,{mode:"cors",credentials:"omit",redirect:"follow",integrity:t.integrity||""}));if(0!==t.url.indexOf(c))return e;const n=()=>fetch(new Request("https://cdn.jsdelivr.net/npm/"+t.url.slice(30),{mode:"cors",credentials:"omit",redirect:"follow",integrity:t.integrity||""}));return e.then(t=>t.ok?t:n().then(e=>e.ok?e:t).catch(()=>t),()=>n())}async function k(t,e){const n=await y("pages"),a=g(t);try{const e=await fetch(t);return j(e)&&await n.put(a,e.clone()),e}catch(s){const i=await n.match(a,{ignoreSearch:e});if(i)return i;if(e&&"navigate"===t.mode){const t=await n.match("/index.html")||await n.match("/");if(t)return t}throw s}}function $(t,e){const n=t.request;switch(e){case"immutable":return async function(t){const e=await y("assets"),n=g(t),a=await e.match(n);if(a)return a;const s=await _(t);return j(s)&&await e.put(n,s.clone()),s}(n);case"swr":return async function(t,e){const n=await y("swr"),a=g(t),s=await n.match(a),i=(async()=>{const e=await _(t);return j(e)&&(await n.put(a,e.clone()),await async function(t){const e=await t.keys(),n=e.length-500;for(let a=0;a<n;a++)await t.delete(e[a])}(n)),e})();return s?(e.waitUntil(i.catch(()=>{})),s):i}(n,t);case"document":return k(n,!0);case"manifest":return k(n,!1);default:return fetch(n)}}const x={version:h().version,ready:!0};self.__mnfstSw=x,self.addEventListener("install",t=>{try{f=null,t.waitUntil(d().then(t=>{f=Promise.resolve(t)}).catch(()=>{}))}catch(t){}}),self.addEventListener("activate",t=>{try{t.waitUntil((async()=>{if(!self.registration||"undefined"==typeof caches||"function"!=typeof fetch||self.__mnfstSw!==x)return void await self.registration.unregister();const t=await p();await async function(t){const a=w(t),s=await caches.keys();await Promise.all(s.filter(t=>0===t.indexOf(e)&&t!==n&&0!==t.indexOf(a)).map(t=>caches.delete(t)))}(t).catch(()=>{}),async function(t){let e;try{const t=await fetch("/precache.json",{cache:"no-store"});if(!t.ok)return;e=await t.json()}catch(t){return}if(!e||!Array.isArray(e.files))return;if(e.deployment&&t.deployment&&e.deployment!==t.deployment)return;const n=e.files.filter(t=>"string"==typeof t),a=async t=>{try{const e=new Request(new URL(t,self.location.origin).href),n=v(e);if(!n)return;const a="immutable"===n?"assets":"swr"===n?"swr":"pages",s=await y(a),i=g(e);if(await s.match(i))return;const c=await _(e);j(c)&&await s.put(i,c)}catch(t){}};let s=0;await Promise.all(Array.from({length:4},async()=>{for(;s<n.length;)await a(n[s++])}))}(t).catch(()=>{})})().catch(()=>{}))}catch(t){}}),self.addEventListener("fetch",t=>{if(u)return;let e=null;try{e=v(t.request)}catch(t){return}if(e)try{t.respondWith($(t,e).catch(()=>fetch(t.request)))}catch(t){}}),self.addEventListener("message",t=>{try{const n=t.data;if(!n||"manifest:sw"!==n.type)return;const a=e=>{try{const n=t.ports&&t.ports[0];n?n.postMessage(e):t.source&&t.source.postMessage&&t.source.postMessage(e)}catch(t){}};if("ping"===n.action)return void a({type:"manifest:sw",action:"pong"});if("version"===n.action)return void t.waitUntil(p().then(t=>a({type:"manifest:sw",action:"version",version:t.version,deployment:t.deployment,key:w(t)})).catch(()=>{}));"kill"===n.action&&(u=!0,t.waitUntil((async()=>{await async function(){const t=await caches.keys();await Promise.all(t.filter(t=>0===t.indexOf(e)).map(t=>caches.delete(t)))}().catch(()=>{}),await self.registration.unregister().catch(()=>{}),a({type:"manifest:sw",action:"killed"})})().catch(()=>{})))}catch(t){}})}();
2
2
  //# sourceMappingURL=manifest.sw.min.js.map
@@ -1158,7 +1158,7 @@ TailwindCompiler.prototype.loadAndApplyCache = function () {
1158
1158
  if (currentClasses.size > 0) {
1159
1159
  for (const [key, value] of this.cache.entries()) {
1160
1160
  // Extract classes from cache key (format: "class1,class2-themeHash")
1161
- // Find the last occurrence of '-' followed by 8 chars (theme hash length)
1161
+ // The theme hash has no '-': split on the last one
1162
1162
  const lastDashIndex = key.lastIndexOf('-');
1163
1163
  const classesPart = lastDashIndex > 0 ? key.substring(0, lastDashIndex) : key;
1164
1164
  const cachedClasses = classesPart ? classesPart.split(',') : [];
@@ -1287,8 +1287,13 @@ TailwindCompiler.prototype.loadPersistentCache = function () {
1287
1287
 
1288
1288
  // Generate a hash of the theme variables to detect changes
1289
1289
  TailwindCompiler.prototype.generateThemeHash = function (themeCss) {
1290
- // Use encodeURIComponent to handle non-Latin1 characters safely
1291
- return encodeURIComponent(themeCss).slice(0, 8); // Simple hash of theme content
1290
+ // FNV-1a over the whole theme text
1291
+ let h = 0x811c9dc5;
1292
+ for (let i = 0; i < themeCss.length; i++) {
1293
+ h ^= themeCss.charCodeAt(i);
1294
+ h = Math.imul(h, 0x01000193);
1295
+ }
1296
+ return (h >>> 0).toString(36) + themeCss.length.toString(36);
1292
1297
  };
1293
1298
 
1294
1299
  // Clean up old cache entries
@@ -1319,12 +1324,20 @@ TailwindCompiler.prototype.cleanupCache = function () {
1319
1324
 
1320
1325
  // Ensure #manifest-styles is last in head so our responsive/variant rules win over Tailwind and any later-injected styles
1321
1326
  TailwindCompiler.prototype.ensureUtilityStylesLast = function () {
1322
- if (this.styleElement && this.styleElement.parentNode && document.head.lastElementChild !== this.styleElement) {
1323
- document.head.appendChild(this.styleElement);
1324
- if (this.resyncUtilitiesText) this.resyncUtilitiesText();
1325
- }
1327
+ if (!this.styleElement || !this.styleElement.parentNode) return;
1328
+ // Only a stylesheet after ours can out-order it (scripts and meta tags cannot)
1329
+ let later = this.styleElement.nextElementSibling;
1330
+ while (later && !isStylesheetNode(later)) later = later.nextElementSibling;
1331
+ if (!later && this.styleElement.parentNode === document.head) return;
1332
+ document.head.appendChild(this.styleElement);
1333
+ if (this.resyncUtilitiesText) this.resyncUtilitiesText();
1326
1334
  };
1327
1335
 
1336
+ // Any <link> counts: a preload can become a stylesheet after insertion
1337
+ function isStylesheetNode(node) {
1338
+ return node.localName === 'style' || node.localName === 'link';
1339
+ }
1340
+
1328
1341
  // When any element is added to head after ours, move #manifest-styles to end. Handles CDN load order (e.g. Tailwind injecting after we run).
1329
1342
  TailwindCompiler.prototype.setupUtilityStylesOrderObserver = function () {
1330
1343
  if (!document.head || !this.styleElement) return;
@@ -1334,6 +1347,7 @@ TailwindCompiler.prototype.setupUtilityStylesOrderObserver = function () {
1334
1347
  if (mutation.type !== 'childList' || !mutation.addedNodes.length) continue;
1335
1348
  for (const node of mutation.addedNodes) {
1336
1349
  if (node.nodeType !== Node.ELEMENT_NODE || node === self.styleElement) continue;
1350
+ if (!isStylesheetNode(node)) continue;
1337
1351
  self.ensureUtilityStylesLast();
1338
1352
  break;
1339
1353
  }
@@ -1438,7 +1452,10 @@ TailwindCompiler.prototype.scanStaticClasses = async function () {
1438
1452
 
1439
1453
  const componentUrls = [];
1440
1454
 
1441
- if (registry && registry.manifest) {
1455
+ // A complete shipped sheet was baked from these same files: nothing to learn by fetching them
1456
+ const baked = !!document.querySelector('[data-mnfst-utilities][data-mnfst-utilities-complete]');
1457
+
1458
+ if (!baked && registry && registry.manifest) {
1442
1459
  // Get all component paths from manifest
1443
1460
  const allComponents = [
1444
1461
  ...(registry.manifest.preloadedComponents || []),
@@ -1449,6 +1466,14 @@ TailwindCompiler.prototype.scanStaticClasses = async function () {
1449
1466
 
1450
1467
  const componentPromises = componentUrls.map(async (url) => {
1451
1468
  try {
1469
+ // The components loader already holds or is fetching this file: share it
1470
+ const loader = window.ManifestComponentsLoader;
1471
+ const name = url.split('/').pop().replace('.html', '');
1472
+ const held = loader && (loader.cache?.[name] || loader._raw?.[name]);
1473
+ if (held) {
1474
+ const html = await held;
1475
+ if (html) { this.extractClassesFromHTML(html, staticClasses); return; }
1476
+ }
1452
1477
  // Use root-relative URL first to avoid 404s on doc routes (e.g. /getting-started/...)
1453
1478
  const rootRelative = url.startsWith('/') ? url : '/' + url;
1454
1479
  const pathsToTry = [rootRelative, url];
@@ -1652,6 +1677,12 @@ TailwindCompiler.prototype.getUsedClasses = function () {
1652
1677
  }
1653
1678
  };
1654
1679
 
1680
+ function isDevHostname(host) {
1681
+ const h = String(host || '').toLowerCase();
1682
+ return !h || h === 'localhost' || h === '127.0.0.1' || h === '[::1]' || h === '::1' || h === '0.0.0.0' ||
1683
+ h.endsWith('.localhost') || h.endsWith('.local') || h.endsWith('.test');
1684
+ }
1685
+
1655
1686
  // Fetch theme content from CSS files
1656
1687
  TailwindCompiler.prototype.fetchThemeContent = async function () {
1657
1688
  const themeContents = new Set();
@@ -1695,25 +1726,33 @@ TailwindCompiler.prototype.fetchThemeContent = async function () {
1695
1726
  cacheTime = this.hasScannedStatic ? 5000 : 30000;
1696
1727
  }
1697
1728
 
1698
- if (cached && (now - cached.timestamp) < cacheTime) {
1729
+ // Off a dev host a stylesheet never changes under a loaded page: fetch once, from the HTTP cache
1730
+ const dev = isDevHostname(location.hostname);
1731
+ if (cached && (!dev || (now - cached.timestamp) < cacheTime)) {
1699
1732
  content = cached.content;
1700
1733
  needsFetch = false;
1701
1734
  }
1702
1735
 
1703
1736
  if (needsFetch) {
1704
- // Add timestamp for development cache busting, but keep it minimal
1705
- const timestamp = Math.floor(now / 1000); // Only changes every second
1706
- const url = `${source}${source.includes('?') ? '&' : '?'}t=${timestamp}`;
1707
-
1708
- const response = await fetch(url);
1737
+ // Dev: cache-bust so an edited stylesheet is re-read
1738
+ const url = dev ? `${source}${source.includes('?') ? '&' : '?'}t=${Math.floor(now / 1000)}` : source;
1739
+
1740
+ // Overlapping compiles share one request
1741
+ const inflight = this._cssInflight || (this._cssInflight = new Map());
1742
+ let pending = inflight.get(url);
1743
+ if (!pending) {
1744
+ pending = fetch(url).then(response => (response.ok ? response.text() : null));
1745
+ inflight.set(url, pending);
1746
+ const done = () => inflight.delete(url);
1747
+ pending.then(done, done);
1748
+ }
1749
+ content = await pending;
1709
1750
 
1710
- if (!response.ok) {
1751
+ if (content === null) {
1711
1752
  console.warn('Failed to fetch stylesheet:', url);
1712
1753
  return;
1713
1754
  }
1714
1755
 
1715
- content = await response.text();
1716
-
1717
1756
  // Cache the content with timestamp
1718
1757
  this.cssContentCache.set(cacheKey, {
1719
1758
  content: content,
@@ -3373,6 +3412,9 @@ TailwindCompiler.prototype.compileDelta = function (themeCss) {
3373
3412
  const applied = this._applied;
3374
3413
  const candidates = [];
3375
3414
  for (const cls of this.dynamicClassCache) if (!applied.classes.has(cls)) candidates.push(cls);
3415
+ // A shipped at-rule variant arriving beside our own rules may need re-emitting after a bare partner: full regen decides
3416
+ if (this.staticUtilitiesCoveredClasses && applied.entries.length &&
3417
+ candidates.some(c => this.isAtRuleVariantClass(c) && this.isClassCovered(c))) return false;
3376
3418
  const classes = this.filterStaticallyCoveredClasses(candidates);
3377
3419
  // Tailwind display classes at a breakpoint join the display block, which only a full regen emits
3378
3420
  if (tailwindResponsiveDisplay(classes).length) return false;
@@ -3515,6 +3557,28 @@ TailwindCompiler.prototype.clearStaleUtilityPatches = function () {
3515
3557
  }
3516
3558
  };
3517
3559
 
3560
+ // Boot-time guesses are unlayered and beat every layered variant: drop them once real rules cover the page
3561
+ TailwindCompiler.prototype.dropCriticalStyles = function () {
3562
+ if (!this.criticalStyleElement) return;
3563
+ requestAnimationFrame(() => requestAnimationFrame(() => {
3564
+ if (this.criticalStyleElement && this.criticalStyleElement.parentNode) {
3565
+ this.criticalStyleElement.parentNode.removeChild(this.criticalStyleElement);
3566
+ this.criticalStyleElement = null;
3567
+ }
3568
+ this.ensureUtilityStylesLast();
3569
+ }));
3570
+ };
3571
+
3572
+ // Nothing to generate yet: arm delta on an empty layer so later classes insert, not regenerate
3573
+ TailwindCompiler.prototype.armEmptyDelta = function (themeCss, classes) {
3574
+ if (!this.styleElement) return;
3575
+ // A replayed cache sheet stays until the next full write replaces it
3576
+ if (!this.staticUtilitiesCoveredClasses && this.styleElement.textContent.trim()) return;
3577
+ this._applied = null;
3578
+ this.styleElement.textContent = '@layer utilities {\n}';
3579
+ this.recordAppliedUtilities([], themeCss, classes);
3580
+ };
3581
+
3518
3582
  // Main compilation method
3519
3583
  TailwindCompiler.prototype.compile = async function () {
3520
3584
  if (this.usesStaticPrerenderUtilities) {
@@ -3593,11 +3657,13 @@ TailwindCompiler.prototype.compile = async function () {
3593
3657
  }
3594
3658
  }
3595
3659
 
3596
- const allUtilities = this.orderedUtilitiesCss(this.generateOrderedUtilities(themeCss, staticUsedData));
3660
+ const staticEntries = this.generateOrderedUtilities(themeCss, staticUsedData);
3661
+ const allUtilities = this.orderedUtilitiesCss(staticEntries);
3597
3662
 
3598
3663
  if (allUtilities) {
3599
3664
  const finalCss = `@layer utilities {\n${allUtilities}\n}`;
3600
3665
 
3666
+ this._applied = null; // a move below must not write the previous delta state back
3601
3667
  this.styleElement.textContent = finalCss;
3602
3668
  this.ensureUtilityStylesLast();
3603
3669
  this.scheduleEnsureUtilityStylesLast();
@@ -3615,6 +3681,7 @@ TailwindCompiler.prototype.compile = async function () {
3615
3681
  });
3616
3682
  });
3617
3683
  this.lastClassesHash = staticUsedData.classes.sort().join(',');
3684
+ this.recordAppliedUtilities(staticEntries, themeCss, []);
3618
3685
 
3619
3686
  // Save to cache for next page load
3620
3687
  const themeHash = this.generateThemeHash(themeCss);
@@ -3627,6 +3694,7 @@ TailwindCompiler.prototype.compile = async function () {
3627
3694
  this.savePersistentCache();
3628
3695
  } else {
3629
3696
  this.clearStaleUtilityPatches();
3697
+ this.armEmptyDelta(themeCss, []);
3630
3698
  }
3631
3699
  }
3632
3700
 
@@ -3639,7 +3707,10 @@ TailwindCompiler.prototype.compile = async function () {
3639
3707
  let prefetchedTheme = null;
3640
3708
  if (this.canCompileDelta()) {
3641
3709
  prefetchedTheme = await this.fetchThemeContent();
3642
- if (prefetchedTheme && this.lastThemeKey === this._applied.themeKey && this.compileDelta(this._applied.themeCss)) return;
3710
+ if (prefetchedTheme && this.lastThemeKey === this._applied.themeKey && this.compileDelta(this._applied.themeCss)) {
3711
+ this.dropCriticalStyles();
3712
+ return;
3713
+ }
3643
3714
  }
3644
3715
 
3645
3716
  // For subsequent compilations, check for new dynamic classes
@@ -3684,6 +3755,7 @@ TailwindCompiler.prototype.compile = async function () {
3684
3755
  if (allUtilities) {
3685
3756
  const finalCss = `@layer utilities {\n${allUtilities}\n}`;
3686
3757
 
3758
+ this._applied = null; // a move below must not write the previous delta state back
3687
3759
  this.styleElement.textContent = finalCss;
3688
3760
  this.ensureUtilityStylesLast();
3689
3761
  this.scheduleEnsureUtilityStylesLast();
@@ -3716,6 +3788,8 @@ TailwindCompiler.prototype.compile = async function () {
3716
3788
  this.savePersistentCache();
3717
3789
  } else {
3718
3790
  this.clearStaleUtilityPatches();
3791
+ this.lastClassesHash = dynamicClassesHash;
3792
+ this.armEmptyDelta(themeCss, dynamicClasses);
3719
3793
  }
3720
3794
  } else {
3721
3795
  this._applied = null; // theme text moved: order keys are stale until the next full write
@@ -4213,7 +4287,7 @@ TailwindCompiler.prototype.setupComponentLoadListener = function () {
4213
4287
  // compile() queues a retry when busy; dropping the call here lost classes seen mid-compile
4214
4288
  const debouncedCompile = this.debounce(() => this.compile(), this.options.debounceTime);
4215
4289
 
4216
- // Recompile when components load/process; re-scan so component HTML is covered.
4290
+ // Recompile when components load/process (the observer has already collected their classes)
4217
4291
  const handleComponentEvent = () => {
4218
4292
  if (!this.hasScannedStatic) {
4219
4293
  this.staticScanPromise = null;
@@ -4225,39 +4299,6 @@ TailwindCompiler.prototype.setupComponentLoadListener = function () {
4225
4299
  document.addEventListener('manifest:component-loaded', handleComponentEvent);
4226
4300
  document.addEventListener('manifest:components-processed', handleComponentEvent);
4227
4301
  document.addEventListener('manifest:components-ready', handleComponentEvent);
4228
- // Also listen for manifest-prefixed events (for future compatibility)
4229
- document.addEventListener('manifest:components-processed', handleComponentEvent);
4230
- document.addEventListener('manifest:components-ready', handleComponentEvent);
4231
-
4232
- // On route change, recompile only if genuinely new dynamic classes appeared.
4233
- document.addEventListener('manifest:route-change', (event) => {
4234
- if (this.hasScannedStatic) {
4235
- setTimeout(() => {
4236
- const currentDynamicCount = this.dynamicClassCache.size;
4237
- const currentClassesHash = this.lastClassesHash;
4238
-
4239
- // Scan for new classes
4240
- const usedData = this.getUsedClasses();
4241
- const newDynamicCount = this.dynamicClassCache.size;
4242
- const dynamicClasses = Array.from(this.dynamicClassCache);
4243
- const newClassesHash = dynamicClasses.sort().join(',');
4244
-
4245
- if (newDynamicCount > currentDynamicCount && newClassesHash !== currentClassesHash) {
4246
- const newClasses = dynamicClasses.filter(cls =>
4247
- // Ignore highlight/code-processing artifacts
4248
- !cls.includes('hljs') &&
4249
- !cls.startsWith('language-') &&
4250
- !cls.includes('copy') &&
4251
- !cls.includes('lines')
4252
- );
4253
-
4254
- if (newClasses.length > 0) {
4255
- debouncedCompile();
4256
- }
4257
- }
4258
- }, 300); // let code processing finish
4259
- }
4260
- });
4261
4302
 
4262
4303
  // Single MutationObserver for all DOM changes: recompile only when a class not yet seen appears
4263
4304
  const observer = new MutationObserver((mutations) => {
@@ -4266,7 +4307,7 @@ TailwindCompiler.prototype.setupComponentLoadListener = function () {
4266
4307
  for (const mutation of mutations) {
4267
4308
  if (mutation.type === 'attributes') {
4268
4309
  if (this.ignoredAttributes.includes(mutation.attributeName) || mutation.attributeName !== 'class') continue;
4269
- if (mutation.target.nodeType === Node.ELEMENT_NODE && this.collectNewClasses(mutation.target)) fresh = true;
4310
+ if (mutation.target.nodeType === Node.ELEMENT_NODE && this.collectNewClasses(mutation.target, false, true)) fresh = true;
4270
4311
  } else if (mutation.type === 'childList') {
4271
4312
  for (const node of mutation.addedNodes) {
4272
4313
  if (node.nodeType !== Node.ELEMENT_NODE) continue;
@@ -4296,10 +4337,23 @@ TailwindCompiler.prototype.setupComponentLoadListener = function () {
4296
4337
  };
4297
4338
 
4298
4339
  // Record classes not seen before; true when any were new. Quiet = collect without triggering
4299
- TailwindCompiler.prototype.collectNewClasses = function (el, quiet) {
4340
+ // classOnly: a class attribute change (the element's binding expression was read when it was added)
4341
+ TailwindCompiler.prototype.collectNewClasses = function (el, quiet, classOnly) {
4300
4342
  if (!el.getAttribute) return false;
4301
4343
  const value = el.getAttribute('class');
4302
- let fresh = value ? this.recordClasses(value.split(/\s+/), quiet) : false;
4344
+ let fresh = false;
4345
+ if (value) {
4346
+ // Rows repeat a handful of class strings: one fully recorded needs no re-split
4347
+ const seen = this._seenClassStrings || (this._seenClassStrings = new Set());
4348
+ if (!seen.has(value)) {
4349
+ fresh = this.recordClasses(value.split(/\s+/), quiet);
4350
+ if (!quiet) {
4351
+ if (seen.size > 5000) seen.clear();
4352
+ seen.add(value);
4353
+ }
4354
+ }
4355
+ }
4356
+ if (classOnly) return fresh;
4303
4357
  const bound = el.getAttribute(':class') || el.getAttribute('x-bind:class');
4304
4358
  if (bound && this.recordClasses(this.bindingClasses(bound), quiet)) fresh = true;
4305
4359
  return fresh;