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.
@@ -435,7 +435,20 @@ if (typeof navigator !== 'undefined' && navigator.webdriver === true) {
435
435
  }
436
436
  }
437
437
 
438
- // Resolve internal link to absolute pathname for pushState. Relative hrefs (e.g. "gadget") are resolved against the app base, not the current URL, so we never get additive paths like /src/dist/widget/gadget/widget/...
438
+ // Href parts: path, ?query, #hash
439
+ function splitHref(href) {
440
+ const hashAt = href.indexOf('#');
441
+ const hash = hashAt === -1 ? '' : href.slice(hashAt + 1);
442
+ const beforeHash = hashAt === -1 ? href : href.slice(0, hashAt);
443
+ const queryAt = beforeHash.indexOf('?');
444
+ return {
445
+ path: queryAt === -1 ? beforeHash : beforeHash.slice(0, queryAt),
446
+ search: queryAt === -1 ? '' : beforeHash.slice(queryAt),
447
+ hash
448
+ };
449
+ }
450
+
451
+ // Resolve internal link to absolute pathname against the app base
439
452
  function resolveHref(href) {
440
453
  if (!href || href.startsWith('#') || href.startsWith('mailto:') || href.startsWith('tel:')) return href;
441
454
  try {
@@ -570,21 +583,20 @@ function interceptLinkClicks() {
570
583
  return;
571
584
  }
572
585
 
586
+ const { path, search, hash } = splitHref(href);
587
+ const fullHref = (path ? resolveHref(path) : '') + search + (hash ? '#' + hash : '');
588
+
573
589
  // target=_blank: open the resolved URL (base path, locale) in a new tab
574
590
  if (target === '_blank') {
575
- const [path, hash] = href.split('#');
576
591
  event.preventDefault();
577
592
  event.stopPropagation();
578
593
  event.stopImmediatePropagation();
579
- window.open(resolveHref(path) + (hash ? '#' + hash : ''), '_blank', 'noopener');
594
+ window.open(fullHref, '_blank', link.relList?.contains('noreferrer') ? 'noopener,noreferrer' : 'noopener');
580
595
  return;
581
596
  }
582
597
 
583
598
  // Handle links with both route and anchor (e.g., /page#section)
584
- if (href.includes('#')) {
585
- const [path, hash] = href.split('#');
586
- const fullHref = resolveHref(path) + (hash ? '#' + hash : '');
587
-
599
+ if (hash) {
588
600
  event.preventDefault();
589
601
  event.stopPropagation();
590
602
  event.stopImmediatePropagation();
@@ -620,7 +632,6 @@ function interceptLinkClicks() {
620
632
  isInternalNavigation = true;
621
633
 
622
634
  // Update URL without page reload (use base path when app is in a subpath, e.g. /src/dist/gadget)
623
- const fullHref = resolveHref(href);
624
635
  history.pushState(null, '', fullHref);
625
636
 
626
637
  // Handle route change
@@ -16,7 +16,7 @@
16
16
 
17
17
  // Build stamps the published version here; unstamped (dev) falls back to the
18
18
  // registration URL's `v`, then 'dev'.
19
- const BUILD_VERSION = '0.5.287';
19
+ const BUILD_VERSION = '0.5.289';
20
20
  const CACHE_PREFIX = 'mnfst-sw:';
21
21
  const META_CACHE = CACHE_PREFIX + 'meta';
22
22
  // Sized to hold a full precache.json warm-up (PRECACHE_MAX_ENTRIES server-side)
@@ -354,58 +354,30 @@ function createVariants() {
354
354
  'android': 'html[data-os="android"] &',
355
355
  'apple': 'html[data-os="macos"] &, html[data-os="ios"] &',
356
356
 
357
- // Data attribute variants (common patterns)
358
- 'data-open': '[data-state="open"] &',
359
- 'data-closed': '[data-state="closed"] &',
360
- 'data-checked': '[data-state="checked"] &',
361
- 'data-unchecked': '[data-state="unchecked"] &',
362
- 'data-on': '[data-state="on"] &',
363
- 'data-off': '[data-state="off"] &',
364
- 'data-visible': '[data-state="visible"] &',
365
- 'data-hidden': '[data-state="hidden"] &',
366
- 'data-disabled': '[data-disabled] &',
367
- 'data-loading': '[data-loading] &',
368
- 'data-error': '[data-error] &',
369
- 'data-success': '[data-success] &',
370
- 'data-warning': '[data-warning] &',
371
- 'data-selected': '[data-selected] &',
372
- 'data-highlighted': '[data-highlighted] &',
373
- 'data-pressed': '[data-pressed] &',
374
- 'data-expanded': '[data-expanded] &',
375
- 'data-collapsed': '[data-collapsed] &',
376
- 'data-active': '[data-active] &',
377
- 'data-inactive': '[data-inactive] &',
378
- 'data-valid': '[data-valid] &',
379
- 'data-invalid': '[data-invalid] &',
380
- 'data-required': '[data-required] &',
381
- 'data-optional': '[data-optional] &',
382
- 'data-readonly': '[data-readonly] &',
383
- 'data-write': '[data-write] &',
384
-
385
- // Aria attribute variants (common patterns)
386
- 'aria-expanded': '[aria-expanded="true"] &',
387
- 'aria-collapsed': '[aria-expanded="false"] &',
388
- 'aria-pressed': '[aria-pressed="true"] &',
389
- 'aria-unpressed': '[aria-pressed="false"] &',
390
- 'aria-checked': '[aria-checked="true"] &',
391
- 'aria-unchecked': '[aria-checked="false"] &',
392
- 'aria-selected': '[aria-selected="true"] &',
393
- 'aria-unselected': '[aria-selected="false"] &',
394
- 'aria-invalid': '[aria-invalid="true"] &',
395
- 'aria-valid': '[aria-invalid="false"] &',
396
- 'aria-required': '[aria-required="true"] &',
397
- 'aria-optional': '[aria-required="false"] &',
398
- 'aria-disabled': '[aria-disabled="true"] &',
399
- 'aria-enabled': '[aria-disabled="false"] &',
400
- 'aria-hidden': '[aria-hidden="true"] &',
401
- 'aria-visible': '[aria-hidden="false"] &',
402
- 'aria-busy': '[aria-busy="true"] &',
403
- 'aria-available': '[aria-busy="false"] &',
404
- 'aria-current': '[aria-current="true"] &',
405
- 'aria-not-current': '[aria-current="false"] &',
406
- 'aria-live': '[aria-live="polite"] &, [aria-live="assertive"] &',
407
- 'aria-atomic': '[aria-atomic="true"] &',
408
- 'aria-relevant': '[aria-relevant="additions"] &, [aria-relevant="removals"] &, [aria-relevant="text"] &, [aria-relevant="all"] &'
357
+ // Attribute variants sit on the element itself (Tailwind v4); data-*, data-[…] and aria-[…] are parsed in parseClassName
358
+ 'aria-expanded': '&[aria-expanded="true"]',
359
+ 'aria-collapsed': '&[aria-expanded="false"]',
360
+ 'aria-pressed': '&[aria-pressed="true"]',
361
+ 'aria-unpressed': '&[aria-pressed="false"]',
362
+ 'aria-checked': '&[aria-checked="true"]',
363
+ 'aria-unchecked': '&[aria-checked="false"]',
364
+ 'aria-selected': '&[aria-selected="true"]',
365
+ 'aria-unselected': '&[aria-selected="false"]',
366
+ 'aria-invalid': '&[aria-invalid="true"]',
367
+ 'aria-valid': '&[aria-invalid="false"]',
368
+ 'aria-required': '&[aria-required="true"]',
369
+ 'aria-optional': '&[aria-required="false"]',
370
+ 'aria-disabled': '&[aria-disabled="true"]',
371
+ 'aria-enabled': '&[aria-disabled="false"]',
372
+ 'aria-hidden': '&[aria-hidden="true"]',
373
+ 'aria-visible': '&[aria-hidden="false"]',
374
+ 'aria-busy': '&[aria-busy="true"]',
375
+ 'aria-available': '&[aria-busy="false"]',
376
+ 'aria-current': '&[aria-current="true"]',
377
+ 'aria-not-current': '&[aria-current="false"]',
378
+ 'aria-live': '&:is([aria-live="polite"], [aria-live="assertive"])',
379
+ 'aria-atomic': '&[aria-atomic="true"]',
380
+ 'aria-relevant': '&:is([aria-relevant="additions"], [aria-relevant="removals"], [aria-relevant="text"], [aria-relevant="all"])'
409
381
  };
410
382
  }
411
383
 
@@ -1521,19 +1493,21 @@ TailwindCompiler.prototype.extractClassesFromHTML = function (html, classSet) {
1521
1493
  }
1522
1494
  }
1523
1495
 
1524
- // Also check for x-data and other Alpine directives that might contain classes
1525
- const alpineRegex = /x-(?:data|bind:class|class)=["']([^"']+)["']/g;
1496
+ // Alpine class bindings: every literal they could apply
1497
+ const bindingRegex = /(?<![\w-])(?::|x-bind:)class=(["'])((?:(?!\1)[\s\S])*)\1/g;
1498
+ while ((match = bindingRegex.exec(html)) !== null) {
1499
+ this.collectBindingClasses(match[2], classSet);
1500
+ }
1501
+
1502
+ // x-data is arbitrary JS: keep single-token string literals only
1503
+ const alpineRegex = /x-data=["']([^"']+)["']/g;
1526
1504
  while ((match = alpineRegex.exec(html)) !== null) {
1527
- // Simple extraction - could be enhanced for complex Alpine expressions
1528
1505
  const content = match[1];
1529
1506
  const classMatches = content.match(/['"`]([^'"`\s]+)['"`]/g);
1530
1507
  if (classMatches) {
1531
1508
  for (const classMatch of classMatches) {
1532
1509
  const cls = classMatch.replace(/['"`]/g, '');
1533
- // x-data is arbitrary JS — a plain string literal in there
1534
- // (e.g. `location.pathname.split('/')`) matches this quoted-
1535
- // token scan too, so require a letter/digit; a punctuation-only
1536
- // "token" like a bare '/' is skipped (seen on a live page).
1510
+ // Skip punctuation-only literals such as split('/')
1537
1511
  if (cls && !cls.startsWith('$') && !cls.includes('(') && /[a-zA-Z0-9]/.test(cls)) {
1538
1512
  classSet.add(cls);
1539
1513
  }
@@ -1542,6 +1516,26 @@ TailwindCompiler.prototype.extractClassesFromHTML = function (html, classSet) {
1542
1516
  }
1543
1517
  };
1544
1518
 
1519
+ // Class names a :class / x-bind:class expression can apply: string literals and object keys
1520
+ TailwindCompiler.prototype.collectBindingClasses = function (expr, classSet) {
1521
+ if (!expr) return;
1522
+ if (expr.includes('&')) expr = expr.replace(/&quot;/g, '"').replace(/&#0?39;|&apos;/g, "'").replace(/&amp;/g, '&');
1523
+ const add = (token) => {
1524
+ if (!token || token.startsWith('x-') || token.startsWith('$') || !/[a-zA-Z0-9]/.test(token)) return;
1525
+ if (token.includes('://') || /^\d+:/.test(token)) return; // URLs, times
1526
+ if ((token.includes('[') ? /[{}'"`$;]/ : /[(){}'"`$;,]/).test(token)) return;
1527
+ classSet.add(token);
1528
+ };
1529
+ const literal = /(['"`])((?:\\[\s\S]|(?!\1)[^\\])*)\1/g;
1530
+ let m;
1531
+ while ((m = literal.exec(expr)) !== null) {
1532
+ for (const token of m[2].split(/\s+/)) add(token);
1533
+ if (m[1] === '`' && m[2].includes('${')) this.collectBindingClasses(m[2].replace(/`/g, ' '), classSet);
1534
+ }
1535
+ const bareKey = /[{,]\s*([A-Za-z_][\w-]*)\s*:/g;
1536
+ while ((m = bareKey.exec(expr)) !== null) add(m[1]);
1537
+ };
1538
+
1545
1539
  // Get all used classes from static and dynamic sources
1546
1540
  TailwindCompiler.prototype.getUsedClasses = function () {
1547
1541
  try {
@@ -1552,6 +1546,10 @@ TailwindCompiler.prototype.getUsedClasses = function () {
1552
1546
  for (const cls of this.staticClassCache) {
1553
1547
  allClasses.add(cls);
1554
1548
  }
1549
+ // Classes seen so far, including binding literals not yet in the DOM
1550
+ for (const cls of this.dynamicClassCache) {
1551
+ allClasses.add(cls);
1552
+ }
1555
1553
 
1556
1554
  // Scan current DOM for dynamic classes only
1557
1555
  const elements = document.getElementsByTagName('*');
@@ -2237,6 +2235,19 @@ TailwindCompiler.prototype.isTailwindGeneratedClass = function (className) {
2237
2235
  return tailwindPatterns.some(pattern => pattern.test(className));
2238
2236
  };
2239
2237
 
2238
+ // `[data-good]`, `[data-tone="good"]`, `[aria-busy="true"]` for a data-/aria- variant's remainder
2239
+ function attributeVariantCondition(kind, rest) {
2240
+ if (rest.startsWith('[') && rest.endsWith(']')) {
2241
+ const m = rest.slice(1, -1).match(/^([a-zA-Z0-9_-]+)(?:([~|^$*]?=)(.+))?$/);
2242
+ if (!m) return null;
2243
+ if (!m[2]) return `[${kind}-${m[1]}]`;
2244
+ const value = m[3].replace(/^(['"])(.*)\1$/, '$2').replace(/_/g, ' ').replace(/"/g, '\\"');
2245
+ return `[${kind}-${m[1]}${m[2]}"${value}"]`;
2246
+ }
2247
+ if (!/^[a-zA-Z0-9_-]+$/.test(rest)) return null;
2248
+ return kind === 'aria' ? `[aria-${rest}="true"]` : `[data-${rest}]`;
2249
+ }
2250
+
2240
2251
  // Parse a class name into its components (variants, base class, important)
2241
2252
  TailwindCompiler.prototype.parseClassName = function (className) {
2242
2253
  // Check cache first
@@ -2314,20 +2325,17 @@ TailwindCompiler.prototype.parseClassName = function (className) {
2314
2325
 
2315
2326
  // THIRD: Handle parameterized variants (only if exact match not found)
2316
2327
 
2317
- // Handle data-[...] variants like data-[state=active] (not starting with bracket)
2318
- // These should be regular attribute selectors, not arbitrary
2319
- const dataMatch = variant.match(/^data-\[(.+)\]$/);
2320
- if (dataMatch) {
2321
- const attrValue = dataMatch[1];
2322
- // Add quotes around the value if it contains = (e.g., state=active -> state="active")
2323
- const quotedValue = attrValue.includes('=')
2324
- ? attrValue.replace(/^([^=]+)=(.+)$/, '$1="$2"')
2325
- : attrValue;
2326
- return {
2327
- name: variant,
2328
- selector: `[data-${quotedValue}] &`,
2329
- isArbitrary: false
2330
- };
2328
+ // Attribute variants (Tailwind v4): the condition sits on the element; group-/peer- move it to the marker
2329
+ const attrMatch = variant.match(/^(group-|peer-)?(data|aria)-(.+)$/);
2330
+ if (attrMatch) {
2331
+ const named = attrMatch[1] && /^&([[:][^&]*)$/.exec(this.variants[`${attrMatch[2]}-${attrMatch[3]}`] || '');
2332
+ const condition = named ? named[1] : attributeVariantCondition(attrMatch[2], attrMatch[3]);
2333
+ if (condition) {
2334
+ const selector = !attrMatch[1] ? `&${condition}`
2335
+ : attrMatch[1] === 'group-' ? `:where(.group${condition}) &`
2336
+ : `:where(.peer${condition}) ~ &`;
2337
+ return { name: variant, selector, isArbitrary: false };
2338
+ }
2331
2339
  }
2332
2340
 
2333
2341
  // Handle parameterized nth variants: nth-3, nth-last-2, nth-of-type-2, nth-last-of-type-2
@@ -2435,6 +2443,7 @@ TailwindCompiler.prototype.parseClassName = function (className) {
2435
2443
  this._warnedVariants.add(variant);
2436
2444
  console.warn(`Unknown variant: ${variant}`);
2437
2445
  }
2446
+ result.unknown = true;
2438
2447
  return null;
2439
2448
  }).filter(Boolean);
2440
2449
 
@@ -2503,6 +2512,7 @@ TailwindCompiler.prototype.generateUtilitiesFromVars = function (cssText, usedDa
2503
2512
  if (variantClass === baseClass) continue;
2504
2513
 
2505
2514
  const parsed = this.parseClassName(variantClass);
2515
+ if (parsed.unknown) continue; // never drop a condition and emit unconditionally
2506
2516
 
2507
2517
  // Check if this is an important variant
2508
2518
  const isImportant = parsed.important;
@@ -2821,6 +2831,7 @@ TailwindCompiler.prototype.generateCustomUtilities = function (usedData) {
2821
2831
  if (variantClass === baseClass) continue;
2822
2832
 
2823
2833
  const parsed = this.parseClassName(variantClass);
2834
+ if (parsed.unknown) continue; // never drop a condition and emit unconditionally
2824
2835
 
2825
2836
  // Check if this is an important variant
2826
2837
  const isImportant = parsed.important;
@@ -3152,7 +3163,7 @@ TailwindCompiler.prototype.entriesMatchSheet = function (entries) {
3152
3163
  };
3153
3164
 
3154
3165
  // After a full write: remember its rules so later compiles can insert beside them
3155
- TailwindCompiler.prototype.recordAppliedUtilities = function (entries, themeCss) {
3166
+ TailwindCompiler.prototype.recordAppliedUtilities = function (entries, themeCss, compiledClasses) {
3156
3167
  this._applied = null;
3157
3168
  if (window.__manifestRender === true || !this.entriesMatchSheet(entries)) return;
3158
3169
  this._applied = {
@@ -3160,7 +3171,7 @@ TailwindCompiler.prototype.recordAppliedUtilities = function (entries, themeCss)
3160
3171
  themeCss, // keys index this exact variable order
3161
3172
  entries,
3162
3173
  rules: new Set(entries.map(e => e.rule)),
3163
- classes: new Set(this.dynamicClassCache),
3174
+ classes: new Set(compiledClasses), // only what this write covered
3164
3175
  dirty: false // inserted rules not yet in textContent
3165
3176
  };
3166
3177
  };
@@ -3508,7 +3519,9 @@ TailwindCompiler.prototype.compile = async function () {
3508
3519
  });
3509
3520
  this.lastClassesHash = dynamicClassesHash;
3510
3521
  const entries = rulesOut.map((rule, i) => ({ rule, key: [isMediaRule(rule) ? 1 : 0].concat(keysOut[i]) }));
3511
- this.recordAppliedUtilities(entries.filter(e => !e.key[0]).concat(entries.filter(e => e.key[0])), themeCss);
3522
+ this.recordAppliedUtilities(entries.filter(e => !e.key[0]).concat(entries.filter(e => e.key[0])), themeCss, dynamicClasses);
3523
+ // Classes that arrived during the await above still need a pass
3524
+ if (this.dynamicClassCache.size > dynamicClasses.length) this.compile();
3512
3525
 
3513
3526
  // Save to cache for next page load
3514
3527
  const themeHash = this.generateThemeHash(themeCss);
@@ -3935,11 +3948,8 @@ TailwindCompiler.prototype.setupUncoveredClassWatcher = function () {
3935
3948
 
3936
3949
  // Setup component load listener and MutationObserver
3937
3950
  TailwindCompiler.prototype.setupComponentLoadListener = function () {
3938
- const debouncedCompile = this.debounce(() => {
3939
- if (!this.isCompiling) {
3940
- this.compile();
3941
- }
3942
- }, this.options.debounceTime);
3951
+ // compile() queues a retry when busy; dropping the call here lost classes seen mid-compile
3952
+ const debouncedCompile = this.debounce(() => this.compile(), this.options.debounceTime);
3943
3953
 
3944
3954
  // Recompile when components load/process; re-scan so component HTML is covered.
3945
3955
  const handleComponentEvent = () => {
@@ -4025,10 +4035,31 @@ TailwindCompiler.prototype.setupComponentLoadListener = function () {
4025
4035
 
4026
4036
  // Record classes not seen before; true when any were new. Quiet = collect without triggering
4027
4037
  TailwindCompiler.prototype.collectNewClasses = function (el, quiet) {
4028
- const value = el.getAttribute && el.getAttribute('class');
4029
- if (!value) return false;
4038
+ if (!el.getAttribute) return false;
4039
+ const value = el.getAttribute('class');
4040
+ let fresh = value ? this.recordClasses(value.split(/\s+/), quiet) : false;
4041
+ const bound = el.getAttribute(':class') || el.getAttribute('x-bind:class');
4042
+ if (bound && this.recordClasses(this.bindingClasses(bound), quiet)) fresh = true;
4043
+ return fresh;
4044
+ };
4045
+
4046
+ // Binding literals per expression, cached: x-for clones repeat the same few
4047
+ TailwindCompiler.prototype.bindingClasses = function (expr) {
4048
+ if (!this._bindingClasses) this._bindingClasses = new Map();
4049
+ let list = this._bindingClasses.get(expr);
4050
+ if (!list) {
4051
+ const set = new Set();
4052
+ this.collectBindingClasses(expr, set);
4053
+ list = Array.from(set);
4054
+ if (this._bindingClasses.size > 500) this._bindingClasses.clear();
4055
+ this._bindingClasses.set(expr, list);
4056
+ }
4057
+ return list;
4058
+ };
4059
+
4060
+ TailwindCompiler.prototype.recordClasses = function (list, quiet) {
4030
4061
  let fresh = false;
4031
- for (const cls of value.split(/\s+/)) {
4062
+ for (const cls of list) {
4032
4063
  if (!cls || this.staticClassCache.has(cls)) continue;
4033
4064
  if (this.dynamicClassCache.has(cls)) {
4034
4065
  if (!quiet && this.quietClasses.delete(cls)) fresh = true;