mnfst 0.5.333 → 0.5.335
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/lib/manifest.appwrite.data.js +1 -1
- package/lib/manifest.code.js +16 -12
- package/lib/manifest.code.min.js +1 -1
- package/lib/manifest.code.min.js.map +1 -1
- package/lib/manifest.data.js +1 -1
- package/lib/manifest.data.min.js +1 -1
- package/lib/manifest.integrity.json +12 -12
- package/lib/manifest.js +180 -24
- package/lib/manifest.min.js +1 -1
- package/lib/manifest.min.js.map +1 -1
- package/lib/manifest.modules.integrity.json +9 -9
- package/lib/manifest.sw.js +1 -1
- package/lib/manifest.sw.min.js +1 -1
- package/lib/manifest.utilities.js +624 -1
- package/lib/manifest.utilities.min.js +1 -1
- package/lib/manifest.utilities.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -821,6 +821,8 @@ TailwindCompiler.prototype.addCriticalBlockingStylesSync = function () {
|
|
|
821
821
|
// Ignore errors
|
|
822
822
|
}
|
|
823
823
|
|
|
824
|
+
dropGeneratedThemeVars(cssVariables);
|
|
825
|
+
|
|
824
826
|
// 5. Scan for classes that need utilities
|
|
825
827
|
const classesToGenerate = new Set();
|
|
826
828
|
try {
|
|
@@ -1042,6 +1044,8 @@ TailwindCompiler.prototype.generateSynchronousUtilities = function () {
|
|
|
1042
1044
|
// Ignore errors accessing computed styles
|
|
1043
1045
|
}
|
|
1044
1046
|
|
|
1047
|
+
dropGeneratedThemeVars(cssVariables);
|
|
1048
|
+
|
|
1045
1049
|
// Method 4: Scan HTML source directly for class attributes
|
|
1046
1050
|
try {
|
|
1047
1051
|
const htmlSource = document.documentElement.outerHTML;
|
|
@@ -1107,6 +1111,18 @@ TailwindCompiler.prototype.generateSynchronousUtilities = function () {
|
|
|
1107
1111
|
};
|
|
1108
1112
|
|
|
1109
1113
|
|
|
1114
|
+
// Tailwind's own theme (engine or cached output) is Tailwind's to apply, as in a full compile
|
|
1115
|
+
function dropGeneratedThemeVars(cssVariables) {
|
|
1116
|
+
try {
|
|
1117
|
+
for (const style of document.querySelectorAll('style')) {
|
|
1118
|
+
if (!isGeneratedUtilitiesStyle(style)) continue;
|
|
1119
|
+
const re = /--([\w-]+)\s*:/g;
|
|
1120
|
+
let m;
|
|
1121
|
+
while ((m = re.exec(style.textContent || '')) !== null) cssVariables.delete(m[1]);
|
|
1122
|
+
}
|
|
1123
|
+
} catch (e) { /* keep what was found */ }
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1110
1126
|
|
|
1111
1127
|
// Cache management
|
|
1112
1128
|
// Methods for loading, saving, and managing cached utilities
|
|
@@ -4310,7 +4326,8 @@ TailwindCompiler.prototype.setupComponentLoadListener = function () {
|
|
|
4310
4326
|
if (mutation.target.nodeType === Node.ELEMENT_NODE && this.collectNewClasses(mutation.target, false, true)) fresh = true;
|
|
4311
4327
|
} else if (mutation.type === 'childList') {
|
|
4312
4328
|
for (const node of mutation.addedNodes) {
|
|
4313
|
-
|
|
4329
|
+
// Tailwind cache's engine carrier: not page content
|
|
4330
|
+
if (node.nodeType !== Node.ELEMENT_NODE || node.hasAttribute('data-tailwind-seed')) continue;
|
|
4314
4331
|
const isIgnoredElement = this.ignoredElementSelectors.some(selector =>
|
|
4315
4332
|
node.tagName?.toLowerCase() === selector.toLowerCase() ||
|
|
4316
4333
|
node.closest(selector)
|
|
@@ -4495,6 +4512,610 @@ if (window.Alpine && typeof window.Alpine.magic === 'function') {
|
|
|
4495
4512
|
}
|
|
4496
4513
|
|
|
4497
4514
|
|
|
4515
|
+
// Tailwind engine output cache: the loader replays it (manifest.js replayTailwindCache);
|
|
4516
|
+
// this side watches for anything it doesn't cover and records the engine's output.
|
|
4517
|
+
|
|
4518
|
+
const TAILWIND_CACHE_IGNORED = new Set(['dark', 'light', 'window-resizing']);
|
|
4519
|
+
const TAILWIND_CACHE_MAX_TOKENS = 6000;
|
|
4520
|
+
const TAILWIND_CACHE_MAX_CSS = 256 * 1024;
|
|
4521
|
+
const TAILWIND_CACHE_ENTRIES = 4;
|
|
4522
|
+
const TAILWIND_CACHE_BUDGET = 1024 * 1024;
|
|
4523
|
+
const TAILWIND_CACHE_QUIET = 1000;
|
|
4524
|
+
const TAILWIND_CACHE_MIN_INTERVAL = 10000;
|
|
4525
|
+
const TAILWIND_CACHE_FEED_DELAY = 250;
|
|
4526
|
+
const TAILWIND_CACHE_SKIP_PATHS = 32;
|
|
4527
|
+
const TAILWIND_CACHE_OVER_IDS = 16;
|
|
4528
|
+
const TAILWIND_CACHE_MAX_AGE = 7 * 24 * 60 * 60 * 1000;
|
|
4529
|
+
const TAILWIND_CACHE_STRINGS = 4000;
|
|
4530
|
+
|
|
4531
|
+
function tailwindAuthorBlockTexts() {
|
|
4532
|
+
return Array.from(document.querySelectorAll('style[type="text/tailwindcss"]:not(#manifest-tailwind-variants)'), s => s.textContent);
|
|
4533
|
+
}
|
|
4534
|
+
|
|
4535
|
+
function tailwindVariantsText() {
|
|
4536
|
+
const el = document.getElementById('manifest-tailwind-variants');
|
|
4537
|
+
return el ? el.textContent : null;
|
|
4538
|
+
}
|
|
4539
|
+
|
|
4540
|
+
function sameTailwindSequence(a, b) {
|
|
4541
|
+
return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
4542
|
+
}
|
|
4543
|
+
|
|
4544
|
+
function isTailwindEngineStyle(el) {
|
|
4545
|
+
return el.localName === 'style' && !el.id && !el.hasAttribute('data-tailwind-cache') &&
|
|
4546
|
+
!el.hasAttribute('data-mnfst-utilities') && (el.textContent || '').startsWith('/*! tailwindcss');
|
|
4547
|
+
}
|
|
4548
|
+
|
|
4549
|
+
function findTailwindEngineStyle() {
|
|
4550
|
+
for (const s of document.querySelectorAll('style')) if (isTailwindEngineStyle(s)) return s;
|
|
4551
|
+
return null;
|
|
4552
|
+
}
|
|
4553
|
+
|
|
4554
|
+
function addClassTokens(value, into) {
|
|
4555
|
+
if (!value) return into;
|
|
4556
|
+
for (const t of value.split(/\s+/)) if (t && !TAILWIND_CACHE_IGNORED.has(t)) into.add(t);
|
|
4557
|
+
return into;
|
|
4558
|
+
}
|
|
4559
|
+
|
|
4560
|
+
// Class strings already split: churn mostly toggles between a few, so each is split once
|
|
4561
|
+
function addClassString(value, into, done) {
|
|
4562
|
+
if (!value || done.has(value)) return;
|
|
4563
|
+
if (done.size > TAILWIND_CACHE_STRINGS) done.clear();
|
|
4564
|
+
done.add(value);
|
|
4565
|
+
addClassTokens(value, into);
|
|
4566
|
+
}
|
|
4567
|
+
|
|
4568
|
+
function documentClassTokens(into) {
|
|
4569
|
+
for (const el of document.querySelectorAll('[class]')) {
|
|
4570
|
+
if (!el.hasAttribute('data-tailwind-seed')) addClassTokens(el.getAttribute('class'), into);
|
|
4571
|
+
}
|
|
4572
|
+
return into;
|
|
4573
|
+
}
|
|
4574
|
+
|
|
4575
|
+
// Literal strings and object keys of an Alpine :class expression
|
|
4576
|
+
const TAILWIND_LITERAL_TOKEN = /^[^\s"'`{}();,]+$/;
|
|
4577
|
+
function literalClassTokens(expr, into) {
|
|
4578
|
+
const strings = /(['"`])((?:\\.|(?!\1)[^\\])*)\1/g;
|
|
4579
|
+
let m;
|
|
4580
|
+
while ((m = strings.exec(expr)) !== null) {
|
|
4581
|
+
if (m[2].includes('${')) continue;
|
|
4582
|
+
for (const t of m[2].split(/\s+/)) if (t && TAILWIND_LITERAL_TOKEN.test(t) && !TAILWIND_CACHE_IGNORED.has(t)) into.add(t);
|
|
4583
|
+
}
|
|
4584
|
+
const keys = /[{,]\s*([A-Za-z_][\w-]*)\s*:/g;
|
|
4585
|
+
while ((m = keys.exec(expr)) !== null) into.add(m[1]);
|
|
4586
|
+
return into;
|
|
4587
|
+
}
|
|
4588
|
+
|
|
4589
|
+
// Class tokens a later visit may need beyond what the observers saw: <template> contents,
|
|
4590
|
+
// x-transition values and literal :class strings
|
|
4591
|
+
const TAILWIND_TRANSITION_XPATH = ".//*[@*[starts-with(name(), 'x-transition:')]]";
|
|
4592
|
+
function staticClassTokens(into) {
|
|
4593
|
+
const scan = (root) => {
|
|
4594
|
+
for (const el of root.querySelectorAll('[\\:class], [x-bind\\:class]')) {
|
|
4595
|
+
literalClassTokens(el.getAttribute(':class') || el.getAttribute('x-bind:class') || '', into);
|
|
4596
|
+
}
|
|
4597
|
+
let hits = null;
|
|
4598
|
+
try {
|
|
4599
|
+
const snap = document.evaluate(TAILWIND_TRANSITION_XPATH, root, null, 7, null);
|
|
4600
|
+
hits = Array.from({ length: snap.snapshotLength }, (_, i) => snap.snapshotItem(i));
|
|
4601
|
+
} catch (e) {
|
|
4602
|
+
hits = root.querySelectorAll('*');
|
|
4603
|
+
}
|
|
4604
|
+
for (const el of hits) {
|
|
4605
|
+
for (const a of el.attributes) if (a.name.startsWith('x-transition:')) addClassTokens(a.value, into);
|
|
4606
|
+
}
|
|
4607
|
+
for (const t of root.querySelectorAll('template')) {
|
|
4608
|
+
if (!t.content || t.hasAttribute('data-tailwind-seed')) continue;
|
|
4609
|
+
for (const el of t.content.querySelectorAll('[class]')) addClassTokens(el.getAttribute('class'), into);
|
|
4610
|
+
scan(t.content);
|
|
4611
|
+
}
|
|
4612
|
+
};
|
|
4613
|
+
scan(document);
|
|
4614
|
+
return into;
|
|
4615
|
+
}
|
|
4616
|
+
|
|
4617
|
+
function shippedUtilitiesSheetPresent() {
|
|
4618
|
+
try {
|
|
4619
|
+
return !!document.querySelector('[data-mnfst-utilities], link[href*="prerender.tailwind.css"], link[href*="prerender.utilities.css"]');
|
|
4620
|
+
} catch (e) {
|
|
4621
|
+
return true;
|
|
4622
|
+
}
|
|
4623
|
+
}
|
|
4624
|
+
|
|
4625
|
+
function isTailwindBlock(node) {
|
|
4626
|
+
return node && node.nodeType === 1 && node.localName === 'style' && node.getAttribute('type') === 'text/tailwindcss';
|
|
4627
|
+
}
|
|
4628
|
+
|
|
4629
|
+
function holdsTailwindBlock(node) {
|
|
4630
|
+
return isTailwindBlock(node) || !!(node && node.nodeType === 1 && node.firstElementChild && node.querySelector('style[type="text/tailwindcss"]'));
|
|
4631
|
+
}
|
|
4632
|
+
|
|
4633
|
+
// Runs before the next frame is drawn (or soon, in a hidden tab)
|
|
4634
|
+
function beforeNextFrame(fn) {
|
|
4635
|
+
if (document.hidden || typeof requestAnimationFrame !== 'function') setTimeout(fn, 0);
|
|
4636
|
+
else requestAnimationFrame(fn);
|
|
4637
|
+
}
|
|
4638
|
+
|
|
4639
|
+
// Shows the engine tokens it hasn't seen, then calls done. The engine scans [class] anywhere in the
|
|
4640
|
+
// document; an inert <template> in <head>, removed as soon as the engine's sheet updates (else before
|
|
4641
|
+
// the next frame), is the least visible carrier.
|
|
4642
|
+
function feedTailwindEngine(tokens, done) {
|
|
4643
|
+
const t = document.createElement('template');
|
|
4644
|
+
t.setAttribute('data-tailwind-seed', '');
|
|
4645
|
+
t.setAttribute('class', Array.from(tokens).join(' '));
|
|
4646
|
+
let finished = false;
|
|
4647
|
+
const finish = () => {
|
|
4648
|
+
if (finished) return;
|
|
4649
|
+
finished = true;
|
|
4650
|
+
o.disconnect();
|
|
4651
|
+
t.remove();
|
|
4652
|
+
done();
|
|
4653
|
+
};
|
|
4654
|
+
const o = new MutationObserver((mutations) => {
|
|
4655
|
+
for (const m of mutations) {
|
|
4656
|
+
const el = m.target.nodeType === 1 ? m.target : m.target.parentNode;
|
|
4657
|
+
if (el && isTailwindEngineStyle(el)) return finish();
|
|
4658
|
+
}
|
|
4659
|
+
});
|
|
4660
|
+
o.observe(document.head, { childList: true, subtree: true, characterData: true });
|
|
4661
|
+
document.head.appendChild(t);
|
|
4662
|
+
beforeNextFrame(finish);
|
|
4663
|
+
}
|
|
4664
|
+
|
|
4665
|
+
// Replay mode: cached CSS is in place and the engine was not fetched
|
|
4666
|
+
function watchCachedTailwind(state) {
|
|
4667
|
+
const rec = state.record;
|
|
4668
|
+
const known = new Set(rec.tokens);
|
|
4669
|
+
const known_strings = new Set();
|
|
4670
|
+
const blockObservers = [];
|
|
4671
|
+
let loading = false;
|
|
4672
|
+
let observer = null;
|
|
4673
|
+
let swap = null;
|
|
4674
|
+
let ready = document.readyState !== 'loading';
|
|
4675
|
+
|
|
4676
|
+
const stop = () => {
|
|
4677
|
+
if (observer) observer.disconnect();
|
|
4678
|
+
blockObservers.forEach(o => o.disconnect());
|
|
4679
|
+
};
|
|
4680
|
+
state.stop = () => { stop(); if (swap) swap.disconnect(); };
|
|
4681
|
+
|
|
4682
|
+
const handoff = (seed, reason, unseen) => {
|
|
4683
|
+
// Engine sheet takes the cached copy's place in the cascade
|
|
4684
|
+
const finish = () => {
|
|
4685
|
+
const engine = findTailwindEngineStyle();
|
|
4686
|
+
if (!engine) return false;
|
|
4687
|
+
if (state.style && state.style.isConnected) {
|
|
4688
|
+
state.style.parentNode.insertBefore(engine, state.style);
|
|
4689
|
+
state.style.remove();
|
|
4690
|
+
}
|
|
4691
|
+
state.style = null;
|
|
4692
|
+
recordTailwindEngine(state, seed);
|
|
4693
|
+
window.dispatchEvent(new CustomEvent('manifest:tailwind-cache', { detail: { engineLoaded: true, reason, unseen: unseen || [] } }));
|
|
4694
|
+
return true;
|
|
4695
|
+
};
|
|
4696
|
+
const swapWhenReady = () => beforeNextFrame(() => {
|
|
4697
|
+
if (finish()) return;
|
|
4698
|
+
swap = new MutationObserver(() => { if (finish()) swap.disconnect(); });
|
|
4699
|
+
swap.observe(document.head, { childList: true, subtree: true, characterData: true });
|
|
4700
|
+
});
|
|
4701
|
+
if (seed) feedTailwindEngine(seed, swapWhenReady);
|
|
4702
|
+
else swapWhenReady();
|
|
4703
|
+
};
|
|
4704
|
+
|
|
4705
|
+
const load = (reason, unseen) => {
|
|
4706
|
+
if (loading) return;
|
|
4707
|
+
loading = true;
|
|
4708
|
+
stop();
|
|
4709
|
+
state.reason = reason;
|
|
4710
|
+
// Same blocks: seed the engine with the cached tokens so its output covers the union
|
|
4711
|
+
const seed = reason === 'unseen' ? rec.tokens : null;
|
|
4712
|
+
const p = state.load || (state.load = window.Manifest.loadTailwind());
|
|
4713
|
+
p.then(() => handoff(seed, reason, unseen)).catch(() => {
|
|
4714
|
+
state.load = null;
|
|
4715
|
+
loading = false;
|
|
4716
|
+
arm();
|
|
4717
|
+
});
|
|
4718
|
+
};
|
|
4719
|
+
|
|
4720
|
+
// parsed: the mismatch was in the document by DOMContentLoaded (or when the watcher armed)
|
|
4721
|
+
const checkBlocks = (parsed = !ready) => {
|
|
4722
|
+
const variants = tailwindVariantsText();
|
|
4723
|
+
const ok = sameTailwindSequence(tailwindAuthorBlockTexts(), rec.blocks) &&
|
|
4724
|
+
(variants === null || rec.variants === undefined || variants === rec.variants);
|
|
4725
|
+
if (ok) return true;
|
|
4726
|
+
// A block in the parsed page: the cached sheet is another page's theme, so drop it now.
|
|
4727
|
+
// One added by script later: keep the previous, correct sheet until the engine's replaces it.
|
|
4728
|
+
if (parsed) {
|
|
4729
|
+
if (state.style) state.style.remove();
|
|
4730
|
+
state.style = null;
|
|
4731
|
+
skipTailwindCachePath(state);
|
|
4732
|
+
}
|
|
4733
|
+
load('config');
|
|
4734
|
+
return false;
|
|
4735
|
+
};
|
|
4736
|
+
|
|
4737
|
+
const watchBlock = (el) => {
|
|
4738
|
+
const o = new MutationObserver(() => checkBlocks());
|
|
4739
|
+
o.observe(el, { characterData: true, childList: true, subtree: true });
|
|
4740
|
+
blockObservers.push(o);
|
|
4741
|
+
};
|
|
4742
|
+
|
|
4743
|
+
const unseenIn = (value, unseen) => {
|
|
4744
|
+
if (!value || known_strings.has(value)) return;
|
|
4745
|
+
let all = true;
|
|
4746
|
+
for (const t of value.split(/\s+/)) {
|
|
4747
|
+
if (t && !TAILWIND_CACHE_IGNORED.has(t) && !known.has(t)) { unseen.add(t); all = false; }
|
|
4748
|
+
}
|
|
4749
|
+
if (all) {
|
|
4750
|
+
if (known_strings.size > TAILWIND_CACHE_STRINGS) known_strings.clear();
|
|
4751
|
+
known_strings.add(value);
|
|
4752
|
+
}
|
|
4753
|
+
};
|
|
4754
|
+
|
|
4755
|
+
const arm = () => {
|
|
4756
|
+
observer = new MutationObserver((mutations) => {
|
|
4757
|
+
if (loading) return;
|
|
4758
|
+
const unseen = new Set();
|
|
4759
|
+
let blocks = false;
|
|
4760
|
+
for (const m of mutations) {
|
|
4761
|
+
if (m.type === 'attributes') {
|
|
4762
|
+
if (m.attributeName === 'type') { if (m.target.localName === 'style') blocks = true; continue; }
|
|
4763
|
+
// Old values catch classes that came and went within one task (x-transition)
|
|
4764
|
+
unseenIn(m.oldValue, unseen);
|
|
4765
|
+
unseenIn(m.target.getAttribute('class'), unseen);
|
|
4766
|
+
continue;
|
|
4767
|
+
}
|
|
4768
|
+
if (isTailwindBlock(m.target)) blocks = true;
|
|
4769
|
+
for (const n of m.removedNodes) if (holdsTailwindBlock(n)) blocks = true;
|
|
4770
|
+
for (const n of m.addedNodes) {
|
|
4771
|
+
if (n.nodeType !== 1 || n.hasAttribute('data-tailwind-seed')) continue;
|
|
4772
|
+
if (isTailwindBlock(n)) { blocks = true; watchBlock(n); }
|
|
4773
|
+
unseenIn(n.getAttribute('class'), unseen);
|
|
4774
|
+
if (n.firstElementChild) {
|
|
4775
|
+
for (const d of n.querySelectorAll('[class]')) unseenIn(d.getAttribute('class'), unseen);
|
|
4776
|
+
for (const s of n.querySelectorAll('style[type="text/tailwindcss"]')) { blocks = true; watchBlock(s); }
|
|
4777
|
+
}
|
|
4778
|
+
}
|
|
4779
|
+
}
|
|
4780
|
+
if (blocks && !checkBlocks()) return;
|
|
4781
|
+
if (unseen.size) load('unseen', Array.from(unseen));
|
|
4782
|
+
});
|
|
4783
|
+
observer.observe(document.documentElement, { childList: true, subtree: true, attributes: true, attributeOldValue: true, attributeFilter: ['class', 'type'] });
|
|
4784
|
+
document.querySelectorAll('style[type="text/tailwindcss"]').forEach(watchBlock);
|
|
4785
|
+
};
|
|
4786
|
+
|
|
4787
|
+
const scanAll = () => {
|
|
4788
|
+
const unseen = new Set();
|
|
4789
|
+
for (const el of document.querySelectorAll('[class]')) if (!el.hasAttribute('data-tailwind-seed')) unseenIn(el.getAttribute('class'), unseen);
|
|
4790
|
+
if (unseen.size) load('unseen', Array.from(unseen));
|
|
4791
|
+
};
|
|
4792
|
+
|
|
4793
|
+
touchTailwindCacheEntry(state);
|
|
4794
|
+
arm();
|
|
4795
|
+
if (!checkBlocks(true)) return;
|
|
4796
|
+
scanAll();
|
|
4797
|
+
const onReady = () => {
|
|
4798
|
+
if (loading) return;
|
|
4799
|
+
// A shipped sheet means the eager path; blocks parsed in <body> must match too
|
|
4800
|
+
if (shippedUtilitiesSheetPresent()) return load('shipped');
|
|
4801
|
+
const ok = checkBlocks(true);
|
|
4802
|
+
ready = true;
|
|
4803
|
+
if (ok) scanAll();
|
|
4804
|
+
};
|
|
4805
|
+
if (!ready) document.addEventListener('DOMContentLoaded', onReady, { once: true });
|
|
4806
|
+
else onReady();
|
|
4807
|
+
}
|
|
4808
|
+
|
|
4809
|
+
function readTailwindCacheIndex(state) {
|
|
4810
|
+
try {
|
|
4811
|
+
const index = JSON.parse(localStorage.getItem(state.key) || 'null');
|
|
4812
|
+
if (index && Array.isArray(index.ids) && index.sizes && typeof index.sizes === 'object') {
|
|
4813
|
+
if (!index.skip || typeof index.skip !== 'object' || Array.isArray(index.skip)) index.skip = {};
|
|
4814
|
+
if (!index.over || typeof index.over !== 'object') index.over = {};
|
|
4815
|
+
return index;
|
|
4816
|
+
}
|
|
4817
|
+
} catch (e) { /* rebuilt below */ }
|
|
4818
|
+
return { ids: [], sizes: {}, skip: {}, over: {} };
|
|
4819
|
+
}
|
|
4820
|
+
|
|
4821
|
+
function saveTailwindCacheIndex(state, index) {
|
|
4822
|
+
try {
|
|
4823
|
+
localStorage.setItem(state.key, JSON.stringify(index));
|
|
4824
|
+
return true;
|
|
4825
|
+
} catch (e) {
|
|
4826
|
+
return false;
|
|
4827
|
+
}
|
|
4828
|
+
}
|
|
4829
|
+
|
|
4830
|
+
// A replayed entry counts as recently used
|
|
4831
|
+
function touchTailwindCacheEntry(state) {
|
|
4832
|
+
try {
|
|
4833
|
+
const index = readTailwindCacheIndex(state);
|
|
4834
|
+
if (!state.id || index.ids[0] === state.id || !index.ids.includes(state.id)) return;
|
|
4835
|
+
index.ids = [state.id, ...index.ids.filter(x => x !== state.id)];
|
|
4836
|
+
saveTailwindCacheIndex(state, index);
|
|
4837
|
+
} catch (e) { /* order only */ }
|
|
4838
|
+
}
|
|
4839
|
+
|
|
4840
|
+
// This page (by pathname) needed a block in <body>: visits in the next 7 days go straight to the engine
|
|
4841
|
+
function skipTailwindCachePath(state) {
|
|
4842
|
+
try {
|
|
4843
|
+
if (!state.pathId) return;
|
|
4844
|
+
state.skipped = true;
|
|
4845
|
+
const index = readTailwindCacheIndex(state);
|
|
4846
|
+
index.skip[state.pathId] = Date.now();
|
|
4847
|
+
const paths = Object.keys(index.skip).sort((a, b) => index.skip[b] - index.skip[a]);
|
|
4848
|
+
for (const old of paths.slice(TAILWIND_CACHE_SKIP_PATHS)) delete index.skip[old];
|
|
4849
|
+
saveTailwindCacheIndex(state, index);
|
|
4850
|
+
} catch (e) { /* replay only */ }
|
|
4851
|
+
}
|
|
4852
|
+
|
|
4853
|
+
function isTailwindCacheOver(index, id) {
|
|
4854
|
+
const t = index.over[id];
|
|
4855
|
+
return typeof t === 'number' && Date.now() - t >= 0 && Date.now() - t <= TAILWIND_CACHE_MAX_AGE;
|
|
4856
|
+
}
|
|
4857
|
+
|
|
4858
|
+
// Over the cap for this block set: no entry, and later visits skip recording
|
|
4859
|
+
function markTailwindCacheOver(state, id) {
|
|
4860
|
+
try {
|
|
4861
|
+
const index = readTailwindCacheIndex(state);
|
|
4862
|
+
index.over[id] = Date.now();
|
|
4863
|
+
const ids = Object.keys(index.over).sort((a, b) => index.over[b] - index.over[a]);
|
|
4864
|
+
for (const old of ids.slice(TAILWIND_CACHE_OVER_IDS)) delete index.over[old];
|
|
4865
|
+
index.ids = index.ids.filter(x => x !== id);
|
|
4866
|
+
delete index.sizes[id];
|
|
4867
|
+
localStorage.removeItem(`${state.key}:${id}`);
|
|
4868
|
+
saveTailwindCacheIndex(state, index);
|
|
4869
|
+
} catch (e) { /* recording stops anyway */ }
|
|
4870
|
+
}
|
|
4871
|
+
|
|
4872
|
+
// Keys under this cache's prefix that the index doesn't list (lost multi-tab races, older versions)
|
|
4873
|
+
function sweepTailwindCache(state, index) {
|
|
4874
|
+
const prefix = state.key.slice(0, state.key.lastIndexOf(':') + 1);
|
|
4875
|
+
const keep = new Set([state.key, ...index.ids.map(id => `${state.key}:${id}`)]);
|
|
4876
|
+
for (let i = localStorage.length - 1; i >= 0; i--) {
|
|
4877
|
+
const k = localStorage.key(i);
|
|
4878
|
+
if (k && k.startsWith(prefix) && !keep.has(k)) localStorage.removeItem(k);
|
|
4879
|
+
}
|
|
4880
|
+
}
|
|
4881
|
+
|
|
4882
|
+
// Bounded LRU: at most TAILWIND_CACHE_ENTRIES entries within TAILWIND_CACHE_BUDGET
|
|
4883
|
+
function writeTailwindCache(state, record) {
|
|
4884
|
+
const id = state.idFor(record.blocks);
|
|
4885
|
+
const entryKey = `${state.key}:${id}`;
|
|
4886
|
+
try {
|
|
4887
|
+
const index = readTailwindCacheIndex(state);
|
|
4888
|
+
const drop = (old) => {
|
|
4889
|
+
index.ids = index.ids.filter(x => x !== old);
|
|
4890
|
+
delete index.sizes[old];
|
|
4891
|
+
localStorage.removeItem(`${state.key}:${old}`);
|
|
4892
|
+
};
|
|
4893
|
+
const json = JSON.stringify(record);
|
|
4894
|
+
index.ids = [id, ...index.ids.filter(x => x !== id)];
|
|
4895
|
+
index.sizes[id] = json.length;
|
|
4896
|
+
delete index.over[id];
|
|
4897
|
+
const total = () => index.ids.reduce((n, x) => n + (index.sizes[x] || 0), 0);
|
|
4898
|
+
while (index.ids.length > 1 && (index.ids.length > TAILWIND_CACHE_ENTRIES || total() > TAILWIND_CACHE_BUDGET)) drop(index.ids[index.ids.length - 1]);
|
|
4899
|
+
sweepTailwindCache(state, index);
|
|
4900
|
+
for (;;) {
|
|
4901
|
+
try {
|
|
4902
|
+
localStorage.setItem(entryKey, json);
|
|
4903
|
+
localStorage.setItem(state.key, JSON.stringify(index));
|
|
4904
|
+
return true;
|
|
4905
|
+
} catch (e) {
|
|
4906
|
+
if (index.ids.length <= 1) {
|
|
4907
|
+
drop(id);
|
|
4908
|
+
saveTailwindCacheIndex(state, index);
|
|
4909
|
+
return false;
|
|
4910
|
+
}
|
|
4911
|
+
drop(index.ids[index.ids.length - 1]);
|
|
4912
|
+
}
|
|
4913
|
+
}
|
|
4914
|
+
} catch (e) {
|
|
4915
|
+
return false;
|
|
4916
|
+
}
|
|
4917
|
+
}
|
|
4918
|
+
|
|
4919
|
+
// Engine mode: record its output and every token it has been shown under the current blocks
|
|
4920
|
+
function recordTailwindEngine(state, seedTokens) {
|
|
4921
|
+
if (state.recording) return;
|
|
4922
|
+
state.recording = true;
|
|
4923
|
+
if (state.parsedMismatch && !state.skipped) skipTailwindCachePath(state);
|
|
4924
|
+
const blockId = () => state.idFor(tailwindAuthorBlockTexts());
|
|
4925
|
+
if (isTailwindCacheOver(readTailwindCacheIndex(state), blockId())) return;
|
|
4926
|
+
|
|
4927
|
+
const seenStrings = new Set();
|
|
4928
|
+
const seen = documentClassTokens(new Set(seedTokens || []));
|
|
4929
|
+
// Tokens the engine has compiled under the current blocks; a block change empties it
|
|
4930
|
+
let fed = new Set(seedTokens || []);
|
|
4931
|
+
let gen = 0;
|
|
4932
|
+
let engineGen = findTailwindEngineStyle() ? 0 : -1;
|
|
4933
|
+
let dirty = true;
|
|
4934
|
+
let saveTimer = null;
|
|
4935
|
+
let feedTimer = null;
|
|
4936
|
+
let lastSave = 0;
|
|
4937
|
+
let feeding = false;
|
|
4938
|
+
let stopped = false;
|
|
4939
|
+
const blockObservers = [];
|
|
4940
|
+
|
|
4941
|
+
const overCap = (engine) => (engine && engine.textContent.length > TAILWIND_CACHE_MAX_CSS) || seen.size > TAILWIND_CACHE_MAX_TOKENS;
|
|
4942
|
+
const giveUp = () => {
|
|
4943
|
+
stop();
|
|
4944
|
+
markTailwindCacheOver(state, blockId());
|
|
4945
|
+
state.over = true;
|
|
4946
|
+
};
|
|
4947
|
+
|
|
4948
|
+
const write = (tokens) => {
|
|
4949
|
+
if (state.parsedMismatch && !state.skipped) skipTailwindCachePath(state);
|
|
4950
|
+
if (stopped || shippedUtilitiesSheetPresent()) return;
|
|
4951
|
+
const engine = findTailwindEngineStyle();
|
|
4952
|
+
if (!engine) return;
|
|
4953
|
+
// Only a sheet built from the current blocks, with tokens shown under them
|
|
4954
|
+
if (engineGen !== gen) return schedule();
|
|
4955
|
+
if (overCap(engine)) return giveUp();
|
|
4956
|
+
dirty = false;
|
|
4957
|
+
lastSave = Date.now();
|
|
4958
|
+
const body = !!(document.body && document.body.querySelector('style[type="text/tailwindcss"]'));
|
|
4959
|
+
const record = { v: state.v, t: lastSave, blocks: tailwindAuthorBlockTexts(), variants: tailwindVariantsText(), body, tokens: Array.from(tokens), css: engine.textContent };
|
|
4960
|
+
if (writeTailwindCache(state, record)) state.saved = record;
|
|
4961
|
+
};
|
|
4962
|
+
|
|
4963
|
+
// Shows the engine every pending token; the next frame sees it compiled
|
|
4964
|
+
const feed = (then) => {
|
|
4965
|
+
if (stopped) return;
|
|
4966
|
+
if (feeding && !then) { feedTimer = setTimeout(() => feed(), TAILWIND_CACHE_FEED_DELAY); return; }
|
|
4967
|
+
const engine = findTailwindEngineStyle();
|
|
4968
|
+
if (feeding || !engine || engineGen !== gen) return then && then();
|
|
4969
|
+
if (overCap(engine)) return giveUp();
|
|
4970
|
+
// On the page now: the engine compiled it in its own pass
|
|
4971
|
+
const present = documentClassTokens(new Set());
|
|
4972
|
+
const pending = [];
|
|
4973
|
+
for (const t of seen) {
|
|
4974
|
+
if (fed.has(t)) continue;
|
|
4975
|
+
if (present.has(t)) fed.add(t);
|
|
4976
|
+
else pending.push(t);
|
|
4977
|
+
}
|
|
4978
|
+
if (!pending.length) return then && then();
|
|
4979
|
+
feeding = true;
|
|
4980
|
+
const startGen = gen;
|
|
4981
|
+
feedTailwindEngine(pending, () => {
|
|
4982
|
+
feeding = false;
|
|
4983
|
+
if (gen === startGen) pending.forEach(t => fed.add(t));
|
|
4984
|
+
if (then) then();
|
|
4985
|
+
});
|
|
4986
|
+
};
|
|
4987
|
+
|
|
4988
|
+
// Full save: static scan, stringify and write. Throttled; feeding is not
|
|
4989
|
+
const save = () => {
|
|
4990
|
+
saveTimer = null;
|
|
4991
|
+
if (!dirty || stopped) return;
|
|
4992
|
+
if (feeding) return schedule();
|
|
4993
|
+
if (overCap(findTailwindEngineStyle())) return giveUp();
|
|
4994
|
+
staticClassTokens(seen);
|
|
4995
|
+
feed(() => write(fed));
|
|
4996
|
+
};
|
|
4997
|
+
|
|
4998
|
+
const schedule = () => {
|
|
4999
|
+
if (stopped) return;
|
|
5000
|
+
dirty = true;
|
|
5001
|
+
clearTimeout(saveTimer);
|
|
5002
|
+
saveTimer = setTimeout(save, Math.max(TAILWIND_CACHE_QUIET, lastSave + TAILWIND_CACHE_MIN_INTERVAL - Date.now()));
|
|
5003
|
+
};
|
|
5004
|
+
|
|
5005
|
+
const scheduleFeed = () => {
|
|
5006
|
+
clearTimeout(feedTimer);
|
|
5007
|
+
feedTimer = setTimeout(() => feed(), TAILWIND_CACHE_FEED_DELAY);
|
|
5008
|
+
schedule();
|
|
5009
|
+
};
|
|
5010
|
+
|
|
5011
|
+
// Any block change ends recording for this page view: the engine rebuilds on some changes and not
|
|
5012
|
+
// others (a removal keeps the removed theme), and no later sheet can be attributed to a full build
|
|
5013
|
+
const blockChanged = () => {
|
|
5014
|
+
if (state.parsedMismatch && !state.skipped) skipTailwindCachePath(state);
|
|
5015
|
+
gen++;
|
|
5016
|
+
fed = new Set();
|
|
5017
|
+
state.recordingEnded = 'blocks';
|
|
5018
|
+
stop();
|
|
5019
|
+
};
|
|
5020
|
+
const watchBlock = (el) => {
|
|
5021
|
+
const o = new MutationObserver(blockChanged);
|
|
5022
|
+
o.observe(el, { characterData: true, childList: true, subtree: true });
|
|
5023
|
+
blockObservers.push(o);
|
|
5024
|
+
};
|
|
5025
|
+
|
|
5026
|
+
const tokenObserver = new MutationObserver((mutations) => {
|
|
5027
|
+
const before = seen.size;
|
|
5028
|
+
let blocks = false;
|
|
5029
|
+
for (const m of mutations) {
|
|
5030
|
+
if (m.type === 'attributes') {
|
|
5031
|
+
if (m.attributeName === 'type') { if (m.target.localName === 'style') blocks = true; continue; }
|
|
5032
|
+
if (m.target.hasAttribute('data-tailwind-seed')) continue;
|
|
5033
|
+
addClassString(m.oldValue, seen, seenStrings);
|
|
5034
|
+
addClassString(m.target.getAttribute('class'), seen, seenStrings);
|
|
5035
|
+
continue;
|
|
5036
|
+
}
|
|
5037
|
+
if (isTailwindBlock(m.target)) blocks = true;
|
|
5038
|
+
for (const n of m.removedNodes) if (holdsTailwindBlock(n)) blocks = true;
|
|
5039
|
+
for (const n of m.addedNodes) {
|
|
5040
|
+
if (n.nodeType !== 1 || n.hasAttribute('data-tailwind-seed')) continue;
|
|
5041
|
+
if (isTailwindBlock(n)) { blocks = true; watchBlock(n); }
|
|
5042
|
+
addClassString(n.getAttribute('class'), seen, seenStrings);
|
|
5043
|
+
if (n.firstElementChild) {
|
|
5044
|
+
for (const d of n.querySelectorAll('[class]')) addClassString(d.getAttribute('class'), seen, seenStrings);
|
|
5045
|
+
for (const s of n.querySelectorAll('style[type="text/tailwindcss"]')) { blocks = true; watchBlock(s); }
|
|
5046
|
+
}
|
|
5047
|
+
}
|
|
5048
|
+
}
|
|
5049
|
+
if (blocks) blockChanged();
|
|
5050
|
+
else if (seen.size !== before) scheduleFeed();
|
|
5051
|
+
});
|
|
5052
|
+
tokenObserver.observe(document.documentElement, { childList: true, subtree: true, attributes: true, attributeOldValue: true, attributeFilter: ['class', 'type'] });
|
|
5053
|
+
document.querySelectorAll('style[type="text/tailwindcss"]').forEach(watchBlock);
|
|
5054
|
+
|
|
5055
|
+
// Engine sheet updates: it now reflects the current blocks
|
|
5056
|
+
const headObserver = new MutationObserver((mutations) => {
|
|
5057
|
+
for (const m of mutations) {
|
|
5058
|
+
const el = m.target.nodeType === 1 ? m.target : m.target.parentNode;
|
|
5059
|
+
if ((el && isTailwindEngineStyle(el)) || Array.from(m.addedNodes).some(n => n.nodeType === 1 && isTailwindEngineStyle(n))) {
|
|
5060
|
+
// First sheet built from the current blocks: show it what it lost in the rebuild
|
|
5061
|
+
const rebuilt = engineGen !== gen;
|
|
5062
|
+
engineGen = gen;
|
|
5063
|
+
return rebuilt ? scheduleFeed() : schedule();
|
|
5064
|
+
}
|
|
5065
|
+
}
|
|
5066
|
+
});
|
|
5067
|
+
headObserver.observe(document.head, { childList: true, subtree: true, characterData: true });
|
|
5068
|
+
|
|
5069
|
+
// Leaving: what the engine has compiled is the fed tokens plus what is on the page now
|
|
5070
|
+
const flush = () => {
|
|
5071
|
+
if (!dirty || stopped || engineGen !== gen) return;
|
|
5072
|
+
clearTimeout(saveTimer);
|
|
5073
|
+
write(documentClassTokens(new Set(fed)));
|
|
5074
|
+
};
|
|
5075
|
+
const onHidden = () => { if (document.visibilityState === 'hidden') flush(); };
|
|
5076
|
+
window.addEventListener('pagehide', flush);
|
|
5077
|
+
document.addEventListener('visibilitychange', onHidden);
|
|
5078
|
+
|
|
5079
|
+
const stop = () => {
|
|
5080
|
+
stopped = true;
|
|
5081
|
+
tokenObserver.disconnect();
|
|
5082
|
+
headObserver.disconnect();
|
|
5083
|
+
blockObservers.forEach(o => o.disconnect());
|
|
5084
|
+
clearTimeout(saveTimer);
|
|
5085
|
+
clearTimeout(feedTimer);
|
|
5086
|
+
window.removeEventListener('pagehide', flush);
|
|
5087
|
+
document.removeEventListener('visibilitychange', onHidden);
|
|
5088
|
+
};
|
|
5089
|
+
state.stop = stop;
|
|
5090
|
+
schedule();
|
|
5091
|
+
}
|
|
5092
|
+
|
|
5093
|
+
function armTailwindCache() {
|
|
5094
|
+
const state = window.__tailwindCache;
|
|
5095
|
+
if (!state || state.armed) return;
|
|
5096
|
+
state.armed = true;
|
|
5097
|
+
// Replay is decided once <head> is parsed: watch or record after that
|
|
5098
|
+
if (state.decision) state.decision.then(() => startTailwindCache(state));
|
|
5099
|
+
else startTailwindCache(state);
|
|
5100
|
+
}
|
|
5101
|
+
|
|
5102
|
+
function startTailwindCache(state) {
|
|
5103
|
+
if (state.parsedMismatch && !state.skipped) skipTailwindCachePath(state);
|
|
5104
|
+
if (state.record && state.style && state.style.isConnected) watchCachedTailwind(state);
|
|
5105
|
+
else afterTailwindHead(() => recordTailwindEngine(state, null));
|
|
5106
|
+
}
|
|
5107
|
+
|
|
5108
|
+
// Head blocks the parser inserts are the baseline, not changes: record only once <head> is parsed
|
|
5109
|
+
function afterTailwindHead(fn) {
|
|
5110
|
+
if (document.body) return fn();
|
|
5111
|
+
let done = false;
|
|
5112
|
+
const go = () => { if (!done) { done = true; o.disconnect(); fn(); } };
|
|
5113
|
+
const o = new MutationObserver(() => { if (document.body) go(); });
|
|
5114
|
+
o.observe(document.documentElement, { childList: true });
|
|
5115
|
+
document.addEventListener('DOMContentLoaded', go, { once: true });
|
|
5116
|
+
}
|
|
5117
|
+
|
|
5118
|
+
|
|
4498
5119
|
// Utilities initialization: create compiler, set up event listeners
|
|
4499
5120
|
|
|
4500
5121
|
// Stamp <html data-os> so OS variants (mac:, ios:, …) resolve in pure CSS
|
|
@@ -4568,6 +5189,8 @@ const compiler = (existingCompiler && existingCompiler.styleElement && existingC
|
|
|
4568
5189
|
// Expose utilities compiler for optional integration
|
|
4569
5190
|
window.ManifestUtilities = compiler;
|
|
4570
5191
|
|
|
5192
|
+
armTailwindCache();
|
|
5193
|
+
|
|
4571
5194
|
if (document.readyState === 'loading') {
|
|
4572
5195
|
document.addEventListener('DOMContentLoaded', () => {
|
|
4573
5196
|
});
|