@qwik.dev/core 2.0.0-beta.31 → 2.0.0-beta.34

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.
@@ -10,9 +10,9 @@ const createMacroTask = (e) => {
10
10
  };
11
11
  const isBrowser$1 = !isServer;
12
12
  const doc = isBrowser$1 ? document : void 0;
13
- const config = { t: 0, o: 25, u: 0.65 };
13
+ const config = { t: 25 };
14
14
  const rel = isBrowser$1 && doc.createElement("link").relList?.supports?.("modulepreload") ? "modulePreload" : "preload";
15
- const loadStart = performance.now();
15
+ performance.now();
16
16
  const isJSRegex = /\.[mc]?js$/;
17
17
  const yieldInterval = 1e3 / 60;
18
18
  const BundleImportState_None = 0;
@@ -31,12 +31,9 @@ let isAdjustmentScheduled = 0;
31
31
  let isProcessingAdjustments = 0;
32
32
  const shouldYieldInBrowser = isBrowser$2;
33
33
  const adjustmentStack = [];
34
- const log = (...e) => {
35
- console.log(`Preloader ${performance.now() - loadStart}ms ${preloadCount}/${queue.length} queued>`, ...e);
36
- };
37
34
  const sortQueue = () => {
38
35
  if (queueDirty) {
39
- queue.sort((e, t) => e.l - t.l);
36
+ queue.sort((e, t) => e.o - t.o);
40
37
  queueDirty = 0;
41
38
  }
42
39
  };
@@ -48,13 +45,9 @@ function trigger() {
48
45
  let t = 0;
49
46
  while (queue.length) {
50
47
  const n = queue[0];
51
- const s = n.l;
52
- const o = 1 - s;
53
- const r = graph ? config.o : (
54
- // While the graph is not available, we limit to 5 preloads
55
- 5
56
- );
57
- if (o >= 0.99 || preloadCount < r) {
48
+ const s = n.o;
49
+ const r = 1 - s;
50
+ if (r >= 0.99 || preloadCount < config.t) {
58
51
  queue.shift();
59
52
  preloadOne(n);
60
53
  if (performance.now() >= e) {
@@ -67,71 +60,62 @@ function trigger() {
67
60
  isTriggerScheduled = 1;
68
61
  nextTriggerMacroTask();
69
62
  }
70
- if (config.t && !queue.length) {
71
- const e2 = [...bundles.values()].filter((e3) => e3.i > BundleImportState_None);
72
- const t2 = e2.reduce((e3, t3) => e3 + t3.m, 0);
73
- const n = e2.reduce((e3, t3) => e3 + t3.p, 0);
74
- log(`>>>> done ${e2.length}/${bundles.size} total: ${t2}ms waited, ${n}ms loaded`);
75
- }
76
63
  }
77
- const enqueueAdjustment = (e, t, n, s) => {
78
- adjustmentStack.unshift({ $: e, l: t, B: s, h: n });
64
+ const enqueueAdjustment = (e, t, n) => {
65
+ adjustmentStack.unshift({ u: e, o: t, i: n });
79
66
  };
80
67
  const processAdjustmentFrame = () => {
81
68
  const e = adjustmentStack[adjustmentStack.length - 1];
82
- const t = e.$;
83
- if (e.S) {
84
- const n2 = e.j;
85
- if (n2 >= e.S.length) {
69
+ const t = e.u;
70
+ if (e.l) {
71
+ const n2 = e.m;
72
+ if (n2 >= e.l.length) {
86
73
  adjustmentStack.pop();
87
74
  return 0;
88
75
  }
89
- const s = e.S[n2];
90
- e.j = n2 + 1;
91
- const o = getBundle(s.k);
92
- if (o.l === 0) return 1;
93
- const r = 1 - t.l;
76
+ const s = e.l[n2];
77
+ e.m = n2 + 1;
78
+ const r = getBundle(s.p);
79
+ if (r.o === 0) return 1;
80
+ const o = 1 - t.o;
94
81
  let a;
95
- if (r === 1 || r >= 0.99 && e.h.T < 100) {
96
- e.h.T++;
97
- a = Math.min(0.01, 1 - s.I);
98
- } else {
99
- const e2 = 1 - s.I * r;
100
- const t2 = s.A;
82
+ if (o === 1 || o >= 0.99) a = Math.min(0.01, 1 - s.$);
83
+ else {
84
+ const e2 = 1 - s.$ * o;
85
+ const t2 = s.B;
101
86
  const n3 = e2 / t2;
102
- a = Math.max(0.02, o.l * n3);
103
- s.A = n3;
87
+ a = Math.max(0.02, r.o * n3);
88
+ s.B = n3;
104
89
  }
105
- adjustmentStack.push({ $: o, l: a, B: e.B, h: e.h });
90
+ adjustmentStack.push({ u: r, o: a, i: e.i });
106
91
  return 1;
107
92
  }
108
- if (e.B?.has(t)) {
93
+ if (e.i?.has(t)) {
109
94
  adjustmentStack.pop();
110
95
  return 0;
111
96
  }
112
- const n = t.l;
113
- t.l = e.l;
114
- if (n - t.l < 0.01) {
97
+ const n = t.o;
98
+ t.o = e.o;
99
+ if (n - t.o < 0.01) {
115
100
  adjustmentStack.pop();
116
101
  return 0;
117
102
  }
118
103
  if (
119
104
  // don't queue until we have initialized the preloader
120
- base != null && t.i < BundleImportState_Preload
105
+ base != null && t.S < BundleImportState_Preload
121
106
  ) {
122
- if (t.i === BundleImportState_None) {
123
- t.i = BundleImportState_Queued;
107
+ if (t.S === BundleImportState_None) {
108
+ t.S = BundleImportState_Queued;
124
109
  queue.push(t);
125
- config.t && log(`queued ${Math.round((1 - t.l) * 100)}%`, t.k);
126
110
  }
127
111
  queueDirty = 1;
128
112
  }
129
- if (t.S?.length) {
130
- const n2 = e.B || /* @__PURE__ */ new Set();
113
+ if (t.l?.length) {
114
+ const n2 = e.i || /* @__PURE__ */ new Set();
131
115
  n2.add(t);
132
- e.B = n2;
133
- e.S = t.S;
134
- e.j = 0;
116
+ e.i = n2;
117
+ e.l = t.l;
118
+ e.m = 0;
135
119
  return 0;
136
120
  }
137
121
  adjustmentStack.pop();
@@ -158,47 +142,42 @@ function processPendingAdjustments() {
158
142
  if (t && shouldYieldInBrowser) nextTriggerMacroTask();
159
143
  }
160
144
  const preloadOne = (e) => {
161
- if (e.i >= BundleImportState_Preload) return;
145
+ if (e.S >= BundleImportState_Preload) return;
162
146
  preloadCount++;
163
147
  const t = performance.now();
164
- e.m = t - e.M;
165
- e.i = BundleImportState_Preload;
166
- config.t && log(`<< load ${Math.round((1 - e.l) * 100)}% after ${`${e.m}ms`}`, e.k);
148
+ e.h = t - e.j;
149
+ e.S = BundleImportState_Preload;
167
150
  const n = doc.createElement("link");
168
- n.href = new URL(`${base}${e.k}`, doc.baseURI).toString();
151
+ n.href = new URL(`${base}${e.p}`, doc.baseURI).toString();
169
152
  n.rel = rel;
170
153
  n.as = "script";
171
154
  n.onload = n.onerror = () => {
172
155
  preloadCount--;
173
156
  const s = performance.now();
174
- e.p = s - t;
175
- e.i = BundleImportState_Loaded;
176
- config.t && log(`>> done after ${e.p}ms`, e.k);
157
+ e.k = s - t;
158
+ e.S = BundleImportState_Loaded;
177
159
  n.remove();
178
160
  nextTriggerMacroTask();
179
161
  };
180
162
  doc.head.appendChild(n);
181
163
  };
182
164
  const adjustProbabilities = (e, t, n) => {
183
- enqueueAdjustment(e, t, { T: 0 }, n);
165
+ enqueueAdjustment(e, t, n);
184
166
  if (shouldYieldInBrowser) nextAdjustmentMacroTask();
185
167
  else processPendingAdjustments();
186
168
  };
187
- const handleBundle = (e, t, n) => {
188
- const s = getBundle(e);
189
- if (s && s.l > t) if (n) enqueueAdjustment(s, t, n);
190
- else adjustProbabilities(s, t);
169
+ const handleBundle = (e, t) => {
170
+ const n = getBundle(e);
171
+ if (n) enqueueAdjustment(n, t);
191
172
  };
192
173
  const preload = (e, t) => {
193
174
  if (!e?.length) return;
194
- let n = t ? 1 - t : 0.4;
195
- const s = { T: 0 };
175
+ const n = t ? 1 - t : 0.4;
196
176
  if (Array.isArray(e)) for (let t2 = e.length - 1; t2 >= 0; t2--) {
197
- const o = e[t2];
198
- if (typeof o === "number") n = 1 - o / 10;
199
- else handleBundle(o, n, s);
177
+ const s = e[t2];
178
+ handleBundle(s, n);
200
179
  }
201
- else handleBundle(e, n, s);
180
+ else handleBundle(e, n);
202
181
  if (shouldYieldInBrowser) nextAdjustmentMacroTask();
203
182
  else processPendingAdjustments();
204
183
  };
@@ -212,21 +191,21 @@ if (isBrowser$2) document.addEventListener("qsymbol", (e) => {
212
191
  let base;
213
192
  let graph;
214
193
  const isBrowser = !isServer;
215
- const makeBundle = (e, t) => ({ k: e, i: isJSRegex.test(e) ? BundleImportState_None : BundleImportState_Alias, S: t, l: 1, M: performance.now(), m: 0, p: 0 });
194
+ const makeBundle = (e, t) => ({ p: e, S: isJSRegex.test(e) ? BundleImportState_None : BundleImportState_Alias, l: t, o: 1, j: performance.now(), h: 0, k: 0 });
216
195
  const parseBundleGraph = (e) => {
217
196
  const t = /* @__PURE__ */ new Map();
218
197
  let n = 0;
219
198
  while (n < e.length) {
220
199
  const s = e[n++];
221
- const o = [];
222
- let r;
200
+ const r = [];
201
+ let o;
223
202
  let a = 1;
224
- while (r = e[n], typeof r === "number") {
225
- if (r < 0) a = -r / 10;
226
- else o.push({ k: e[r], I: a, A: 1 });
203
+ while (o = e[n], typeof o === "number") {
204
+ if (o < 0) a = -o / 10;
205
+ else r.push({ p: e[o], $: a, B: 1 });
227
206
  n++;
228
207
  }
229
- t.set(s, o);
208
+ t.set(s, r);
230
209
  }
231
210
  return t;
232
211
  };
@@ -246,9 +225,7 @@ const getBundle = (e) => {
246
225
  };
247
226
  const loadBundleGraph = (e, t, n) => {
248
227
  if (n) {
249
- if ("d" in n) config.t = !!n.d;
250
- if ("P" in n) config.o = n["P"];
251
- if ("Q" in n) config.u = 1 - n["Q"];
228
+ if ("P" in n) config.t = n["P"];
252
229
  }
253
230
  if (!isBrowser || e == null) return;
254
231
  base = e;
@@ -257,13 +234,12 @@ const loadBundleGraph = (e, t, n) => {
257
234
  const t2 = [];
258
235
  for (const [e3, n3] of graph.entries()) {
259
236
  const s2 = getBundle(e3);
260
- s2.S = n3;
261
- if (s2.l < 1) {
262
- t2.push([s2, s2.l]);
263
- s2.l = 1;
237
+ s2.l = n3;
238
+ if (s2.o < 1) {
239
+ t2.push([s2, s2.o]);
240
+ s2.o = 1;
264
241
  }
265
242
  }
266
- config.t && log(`parseBundleGraph got ${graph.size} bundles, adjusting ${t2.length}`);
267
243
  if (!t2.length) {
268
244
  nextTriggerMacroTask();
269
245
  return;
@@ -272,9 +248,9 @@ const loadBundleGraph = (e, t, n) => {
272
248
  const s = createMacroTask(() => {
273
249
  const e3 = performance.now() + yieldInterval;
274
250
  while (n2 < t2.length) {
275
- const [o, r] = t2[n2];
251
+ const [r, o] = t2[n2];
276
252
  n2++;
277
- adjustProbabilities(o, r);
253
+ adjustProbabilities(r, o);
278
254
  if (n2 < t2.length && performance.now() >= e3) {
279
255
  s();
280
256
  return;
@@ -287,7 +263,6 @@ const loadBundleGraph = (e, t, n) => {
287
263
  };
288
264
  export {
289
265
  parseBundleGraph as g,
290
- handleBundle as h,
291
266
  loadBundleGraph as l,
292
267
  preload as p
293
268
  };