mnfst 0.5.198-next.0 → 0.5.198-next.2

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.
@@ -14,8 +14,23 @@ const killed = !!document.querySelector('script[data-defer="off"]') || window.__
14
14
 
15
15
  const pending = new Set();
16
16
  let ready = false;
17
+ let bootDrained = false;
17
18
  let idleHandle = null;
18
19
 
20
+ // Urgent = mounted after boot, within a gesture window (a pane the user just opened), capped per gesture
21
+ const URGENT_WINDOW_MS = 1500;
22
+ const URGENT_CAP = 8;
23
+ let lastGestureAt = -Infinity;
24
+ let urgentWindowAt = -Infinity;
25
+ let urgentInWindow = 0;
26
+ const now = () => (typeof performance !== 'undefined' && performance.now) ? performance.now() : Date.now();
27
+
28
+ function isUrgent() {
29
+ if (!ready || !bootDrained || now() - lastGestureAt > URGENT_WINDOW_MS) return false;
30
+ if (urgentWindowAt !== lastGestureAt) { urgentWindowAt = lastGestureAt; urgentInWindow = 0; }
31
+ return urgentInWindow++ < URGENT_CAP;
32
+ }
33
+
19
34
  // ---- Detection ----
20
35
 
21
36
  const isPopoverOpen = (el) => { try { return el.matches(':popover-open'); } catch (_) { return false; } };
@@ -87,6 +102,7 @@ function register(el, rule, opts) {
87
102
  lazy: !!(opts && opts.lazy),
88
103
  discard: !!(opts && opts.discard),
89
104
  priority: opts ? opts.priority : 0,
105
+ urgent: isUrgent(),
90
106
  rendered: false,
91
107
  cleanup: []
92
108
  };
@@ -159,19 +175,20 @@ function wire(rec) {
159
175
  }
160
176
  }
161
177
 
162
- // ---- Idle prewarm (after manifest:ready; priority asc, then document order) ----
178
+ // ---- Idle prewarm (after manifest:ready; urgent first, then priority asc, then document order) ----
163
179
 
164
- const idle = window.requestIdleCallback
165
- ? (fn) => window.requestIdleCallback(fn, { timeout: 1000 })
166
- : (fn) => setTimeout(fn, 50);
180
+ const idle = (fn, timeout) => window.requestIdleCallback
181
+ ? window.requestIdleCallback(fn, { timeout })
182
+ : setTimeout(fn, 50);
167
183
 
168
184
  function next() {
169
185
  let best = null;
170
186
  for (const rec of pending) {
171
187
  if (!rec.el.isConnected) { pending.delete(rec); continue; }
172
188
  if (!best
173
- || rec.priority < best.priority
174
- || (rec.priority === best.priority && (best.el.compareDocumentPosition(rec.el) & Node.DOCUMENT_POSITION_PRECEDING))) {
189
+ || (rec.urgent && !best.urgent)
190
+ || (rec.urgent === best.urgent && (rec.priority < best.priority
191
+ || (rec.priority === best.priority && (best.el.compareDocumentPosition(rec.el) & Node.DOCUMENT_POSITION_PRECEDING))))) {
175
192
  best = rec;
176
193
  }
177
194
  }
@@ -179,19 +196,22 @@ function next() {
179
196
  }
180
197
 
181
198
  function schedule() {
182
- if (idleHandle !== null || !ready || pending.size === 0) return;
199
+ if (pending.size === 0) { if (ready) bootDrained = true; return; }
200
+ if (idleHandle !== null || !ready) return;
201
+ const head = next();
183
202
  idleHandle = idle(() => {
184
203
  idleHandle = null;
185
204
  const rec = next();
186
205
  if (rec) render(rec);
187
206
  schedule();
188
- });
207
+ }, head && head.urgent ? 100 : 1000);
189
208
  }
190
209
 
191
210
  function markReady() {
192
211
  if (ready) return;
193
212
  ready = true;
194
213
  schedule();
214
+ setTimeout(() => { bootDrained = true; }, 5000); // lazy components may keep the boot queue busy
195
215
  }
196
216
 
197
217
  function armReady() {
@@ -224,6 +244,7 @@ function intercept(el, skip) {
224
244
  function initializeDeferPlugin() {
225
245
  Alpine.directive('defer', () => { });
226
246
  if (!killed) Alpine.interceptInit(Alpine.skipDuringClone(intercept));
247
+ ['pointerdown', 'keydown'].forEach((type) => document.addEventListener(type, () => { lastGestureAt = now(); }, { capture: true, passive: true }));
227
248
  armReady();
228
249
  }
229
250
 
@@ -12,7 +12,7 @@
12
12
  "manifest.computed.js": "sha384-LDxER8pyYyYwUxIYIyiJA02s+49g8CzpSlOj28On0DFIUgetT3UmvE/9xOsTwT66",
13
13
  "manifest.data.js": "sha384-urUiANuQfrc+AfwTB7+nMneF2C1+EfV+S5+eg4PQnZCJ0Aid50KwSARufiVrGAXd",
14
14
  "manifest.datepicker.js": "sha384-8vTJYkLqqvgXgm1w1becuaRR/jUEpiLBjBJ6RsRbUr+ZkypvspD6EsssuDrX4SQq",
15
- "manifest.defer.js": "sha384-pUFSB9Ksb7ht5KnXWvQ0K5roeAdmeDTMRF1R0BdLt2eaihQVZSa1mWfY6B6huGNK",
15
+ "manifest.defer.js": "sha384-IxVROtFvzgYYP/zfSTULfKW9HfUBBu02pjXPfJ/myyKoAU/lj59qFVNq0WAHNLZI",
16
16
  "manifest.dropdowns.js": "sha384-4HuHkBt4i8sTPUDLB9rNLli2/lWLY1tjtCLzey37gRwueG+FRLCnVH1q7ljiVvJR",
17
17
  "manifest.edit.js": "sha384-ZvgV3ax7yHtSC23zdvRYJPzBsBpGFBLuBJMgfQ1IDumv97Cn2bpHOePxyQikfl5L",
18
18
  "manifest.export.js": "sha384-HCy3n6ifrcAGIyzTRgZ5JIRvSX9q9/8ykMKRSbt1QTnhXz6PgYlV0AE2N2Yi2re+",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst",
3
- "version": "0.5.198-next.0",
3
+ "version": "0.5.198-next.2",
4
4
  "private": false,
5
5
  "workspaces": [
6
6
  "templates/starter",
@@ -76,7 +76,7 @@
76
76
  "homepage": "https://manifestx.dev",
77
77
  "repository": {
78
78
  "type": "git",
79
- "url": "https://github.com/Manifest-X/Manifest.git"
79
+ "url": "git+https://github.com/Manifest-X/Manifest.git"
80
80
  },
81
81
  "bugs": {
82
82
  "url": "https://github.com/Manifest-X/Manifest/issues"