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

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,268 +1 @@
1
- import { isServer, isBrowser as isBrowser$2 } from "@qwik.dev/core/build";
2
- const createMacroTask = (e) => {
3
- let t;
4
- if (typeof MessageChannel !== "undefined") {
5
- const n = new MessageChannel();
6
- n.port1.onmessage = () => e();
7
- t = () => n.port2.postMessage(null);
8
- } else t = () => setTimeout(e);
9
- return t;
10
- };
11
- const isBrowser$1 = !isServer;
12
- const doc = isBrowser$1 ? document : void 0;
13
- const config = { t: 25 };
14
- const rel = isBrowser$1 && doc.createElement("link").relList?.supports?.("modulepreload") ? "modulePreload" : "preload";
15
- performance.now();
16
- const isJSRegex = /\.[mc]?js$/;
17
- const yieldInterval = 1e3 / 60;
18
- const BundleImportState_None = 0;
19
- const BundleImportState_Queued = 1;
20
- const BundleImportState_Preload = 2;
21
- const BundleImportState_Alias = 3;
22
- const BundleImportState_Loaded = 4;
23
- const bundles = /* @__PURE__ */ new Map();
24
- let queueDirty;
25
- let preloadCount = 0;
26
- const queue = [];
27
- const nextTriggerMacroTask = createMacroTask(trigger);
28
- const nextAdjustmentMacroTask = createMacroTask(processPendingAdjustments);
29
- let isTriggerScheduled = 0;
30
- let isAdjustmentScheduled = 0;
31
- let isProcessingAdjustments = 0;
32
- const shouldYieldInBrowser = isBrowser$2;
33
- const adjustmentStack = [];
34
- const sortQueue = () => {
35
- if (queueDirty) {
36
- queue.sort((e, t) => e.o - t.o);
37
- queueDirty = 0;
38
- }
39
- };
40
- function trigger() {
41
- isTriggerScheduled = 0;
42
- if (!queue.length) return;
43
- sortQueue();
44
- const e = performance.now() + yieldInterval;
45
- let t = 0;
46
- while (queue.length) {
47
- const n = queue[0];
48
- const s = n.o;
49
- const r = 1 - s;
50
- if (r >= 0.99 || preloadCount < config.t) {
51
- queue.shift();
52
- preloadOne(n);
53
- if (performance.now() >= e) {
54
- t = 1;
55
- break;
56
- }
57
- } else break;
58
- }
59
- if (t && queue.length && !isTriggerScheduled) {
60
- isTriggerScheduled = 1;
61
- nextTriggerMacroTask();
62
- }
63
- }
64
- const enqueueAdjustment = (e, t, n) => {
65
- adjustmentStack.unshift({ u: e, o: t, i: n });
66
- };
67
- const processAdjustmentFrame = () => {
68
- const e = adjustmentStack[adjustmentStack.length - 1];
69
- const t = e.u;
70
- if (e.l) {
71
- const n2 = e.m;
72
- if (n2 >= e.l.length) {
73
- adjustmentStack.pop();
74
- return 0;
75
- }
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;
81
- let 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;
86
- const n3 = e2 / t2;
87
- a = Math.max(0.02, r.o * n3);
88
- s.B = n3;
89
- }
90
- adjustmentStack.push({ u: r, o: a, i: e.i });
91
- return 1;
92
- }
93
- if (e.i?.has(t)) {
94
- adjustmentStack.pop();
95
- return 0;
96
- }
97
- const n = t.o;
98
- t.o = e.o;
99
- if (n - t.o < 0.01) {
100
- adjustmentStack.pop();
101
- return 0;
102
- }
103
- if (
104
- // don't queue until we have initialized the preloader
105
- base != null && t.S < BundleImportState_Preload
106
- ) {
107
- if (t.S === BundleImportState_None) {
108
- t.S = BundleImportState_Queued;
109
- queue.push(t);
110
- }
111
- queueDirty = 1;
112
- }
113
- if (t.l?.length) {
114
- const n2 = e.i || /* @__PURE__ */ new Set();
115
- n2.add(t);
116
- e.i = n2;
117
- e.l = t.l;
118
- e.m = 0;
119
- return 0;
120
- }
121
- adjustmentStack.pop();
122
- return 0;
123
- };
124
- function processPendingAdjustments() {
125
- if (isProcessingAdjustments || !adjustmentStack.length) return;
126
- isAdjustmentScheduled = 0;
127
- isProcessingAdjustments = 1;
128
- const e = shouldYieldInBrowser ? performance.now() + yieldInterval : 0;
129
- let t = 0;
130
- while (adjustmentStack.length) {
131
- t = 1;
132
- const n = processAdjustmentFrame();
133
- if (shouldYieldInBrowser && n && performance.now() >= e) {
134
- if (!isAdjustmentScheduled) {
135
- isAdjustmentScheduled = 1;
136
- nextAdjustmentMacroTask();
137
- }
138
- break;
139
- }
140
- }
141
- isProcessingAdjustments = 0;
142
- if (t && shouldYieldInBrowser) nextTriggerMacroTask();
143
- }
144
- const preloadOne = (e) => {
145
- if (e.S >= BundleImportState_Preload) return;
146
- preloadCount++;
147
- const t = performance.now();
148
- e.h = t - e.j;
149
- e.S = BundleImportState_Preload;
150
- const n = doc.createElement("link");
151
- n.href = new URL(`${base}${e.p}`, doc.baseURI).toString();
152
- n.rel = rel;
153
- n.as = "script";
154
- n.onload = n.onerror = () => {
155
- preloadCount--;
156
- const s = performance.now();
157
- e.k = s - t;
158
- e.S = BundleImportState_Loaded;
159
- n.remove();
160
- nextTriggerMacroTask();
161
- };
162
- doc.head.appendChild(n);
163
- };
164
- const adjustProbabilities = (e, t, n) => {
165
- enqueueAdjustment(e, t, n);
166
- if (shouldYieldInBrowser) nextAdjustmentMacroTask();
167
- else processPendingAdjustments();
168
- };
169
- const handleBundle = (e, t) => {
170
- const n = getBundle(e);
171
- if (n) enqueueAdjustment(n, t);
172
- };
173
- const preload = (e, t) => {
174
- if (!e?.length) return;
175
- const n = t ? 1 - t : 0.4;
176
- if (Array.isArray(e)) for (let t2 = e.length - 1; t2 >= 0; t2--) {
177
- const s = e[t2];
178
- handleBundle(s, n);
179
- }
180
- else handleBundle(e, n);
181
- if (shouldYieldInBrowser) nextAdjustmentMacroTask();
182
- else processPendingAdjustments();
183
- };
184
- if (isBrowser$2) document.addEventListener("qsymbol", (e) => {
185
- const { symbol: t, href: n } = e.detail;
186
- if (n) {
187
- const e2 = t.slice(t.lastIndexOf("_") + 1);
188
- preload(e2, 1);
189
- }
190
- });
191
- let base;
192
- let graph;
193
- const isBrowser = !isServer;
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 });
195
- const parseBundleGraph = (e) => {
196
- const t = /* @__PURE__ */ new Map();
197
- let n = 0;
198
- while (n < e.length) {
199
- const s = e[n++];
200
- const r = [];
201
- let o;
202
- let 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 });
206
- n++;
207
- }
208
- t.set(s, r);
209
- }
210
- return t;
211
- };
212
- const getBundle = (e) => {
213
- let t = bundles.get(e);
214
- if (!t) {
215
- let n;
216
- if (graph) {
217
- n = graph.get(e);
218
- if (!n) return;
219
- if (!n.length) n = void 0;
220
- }
221
- t = makeBundle(e, n);
222
- bundles.set(e, t);
223
- }
224
- return t;
225
- };
226
- const loadBundleGraph = (e, t, n) => {
227
- if (n) {
228
- if ("P" in n) config.t = n["P"];
229
- }
230
- if (!isBrowser || e == null) return;
231
- base = e;
232
- if (t) t.then((e2) => e2.text()).then((e2) => {
233
- graph = parseBundleGraph(JSON.parse(e2));
234
- const t2 = [];
235
- for (const [e3, n3] of graph.entries()) {
236
- const s2 = getBundle(e3);
237
- s2.l = n3;
238
- if (s2.o < 1) {
239
- t2.push([s2, s2.o]);
240
- s2.o = 1;
241
- }
242
- }
243
- if (!t2.length) {
244
- nextTriggerMacroTask();
245
- return;
246
- }
247
- let n2 = 0;
248
- const s = createMacroTask(() => {
249
- const e3 = performance.now() + yieldInterval;
250
- while (n2 < t2.length) {
251
- const [r, o] = t2[n2];
252
- n2++;
253
- adjustProbabilities(r, o);
254
- if (n2 < t2.length && performance.now() >= e3) {
255
- s();
256
- return;
257
- }
258
- }
259
- nextTriggerMacroTask();
260
- });
261
- s();
262
- }).catch(console.warn);
263
- };
264
- export {
265
- parseBundleGraph as g,
266
- loadBundleGraph as l,
267
- preload as p
268
- };
1
+ import{isServer as e}from"@qwik.dev/core/build";const n=e=>{let n;if(typeof MessageChannel!=="undefined"){const t=new MessageChannel;t.port1.onmessage=()=>e();n=()=>t.port2.postMessage(null)}else n=()=>setTimeout(e);return n};const t=typeof document!=="undefined";const o=!e&&t;const s=o?document:void 0;const c={t:25};const r=o&&s.createElement("link").relList?.supports?.("modulepreload")?"modulePreload":"preload";performance.now();const i=/\.[mc]?js$/;const f=1e3/60;const l=0;const a=1;const $=2;const u=3;const m=4;const d=/* @__PURE__ */new Map;let p;let b=0;const w=[];const h=n(q);const y=n(S);let M=0;let P=0;let k=0;const v=[];const g=()=>{if(p){w.sort((e,n)=>e.o-n.o);p=0}};function q(){M=0;if(!w.length)return;g();const e=performance.now()+f;let n=0;while(w.length){const t=w[0];const o=t.o;const s=1-o;if(s>=.99||b<c.t){w.shift();T(t);if(performance.now()>=e){n=1;break}}else break}if(n&&w.length&&!M){M=1;h()}}const x=(e,n,t)=>{v.unshift({i:e,o:n,l:t})};const C=()=>{const e=v[v.length-1];const n=e.i;if(e.$){const t=e.u;if(t>=e.$.length){v.pop();return 0}const o=e.$[t];e.u=t+1;const s=R(o.m);if(s.o===0)return 1;const c=1-n.o;let r;if(c===1||c>=.99)r=Math.min(.01,1-o.p);else{const e=1-o.p*c;const n=o.h;const t=e/n;r=Math.max(.02,s.o*t);o.h=t}v.push({i:s,o:r,l:e.l});return 1}if(e.l?.has(n)){v.pop();return 0}const t=n.o;n.o=e.o;if(t-n.o<.01){v.pop();return 0}if(J!=null&&n.M<$){if(n.M===l){n.M=a;w.push(n)}p=1}if(n.$?.length){const t=e.l||/* @__PURE__ */new Set;t.add(n);e.l=t;e.$=n.$;e.u=0;return 0}v.pop();return 0};function S(){if(k||!v.length)return;P=0;k=1;const e=o?performance.now()+f:0;let n=0;while(v.length){n=1;const t=C();if(o&&t&&performance.now()>=e){if(!P){P=1;y()}break}}k=0;if(n&&o)h()}const T=e=>{if(e.M>=$)return;b++;const n=performance.now();e.k=n-e.v;e.M=$;const t=s.createElement("link");t.href=new URL(`${J}${e.m}`,s.baseURI).toString();t.rel=r;t.as="script";t.onload=t.onerror=()=>{b--;const o=performance.now();e.q=o-n;e.M=m;t.remove();h()};s.head.appendChild(t)};const j=(e,n,t)=>{x(e,n,t);if(o)y();else S()};const A=(e,n)=>{const t=R(e);if(t)x(t,n)};const I=(e,n)=>{if(!e?.length)return;const t=n?1-n:.4;if(Array.isArray(e))for(let o=e.length-1;o>=0;o--){const n=e[o];A(n,t)}else A(e,t);if(o)y();else S()};if(o)document.addEventListener("qsymbol",e=>{const{symbol:n,href:t}=e.detail;if(t){const e=n.slice(n.lastIndexOf("_")+1);I(e,1)}});let J;let L;const N=(e,n)=>({m:e,M:i.test(e)?l:u,$:n,o:1,v:performance.now(),k:0,q:0});const O=e=>{const n=/* @__PURE__ */new Map;let t=0;while(t<e.length){const o=e[t++];const s=[];let c;let r=1;while(c=e[t],typeof c==="number"){if(c<0)r=-c/10;else s.push({m:e[c],p:r,h:1});t++}n.set(o,s)}return n};const R=e=>{let n=d.get(e);if(!n){let t;if(L){t=L.get(e);if(!t)return;if(!t.length)t=void 0}n=N(e,t);d.set(e,n)}return n};const U=(e,t,s)=>{if(s)if("P"in s)c.t=s["P"];if(!o||e==null)return;J=e;if(t)t.then(e=>e.text()).then(e=>{L=O(JSON.parse(e));const t=[];for(const[n,c]of L.entries()){const e=R(n);e.$=c;if(e.o<1){t.push([e,e.o]);e.o=1}}if(!t.length){h();return}let o=0;const s=n(()=>{const e=performance.now()+f;while(o<t.length){const[n,c]=t[o];o++;j(n,c);if(o<t.length&&performance.now()>=e){s();return}}h()});s()}).catch(console.warn)};export{O as g,U as l,I as p};
@@ -1,5 +1,6 @@
1
1
  /// <reference types="./server" />
2
2
  declare module '@qwik-client-manifest' {
3
+ /** @deprecated Use `getClientManifest()` instead */
3
4
  const manifest: import('./optimizer').QwikManifest;
4
5
  export { manifest };
5
6
  }