@qwik.dev/core 2.0.0-beta.32 → 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,293 +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: 0, o: 25, u: 0.65 };
14
- const rel = isBrowser$1 && doc.createElement("link").relList?.supports?.("modulepreload") ? "modulePreload" : "preload";
15
- const loadStart = 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 log = (...e) => {
35
- console.log(`Preloader ${performance.now() - loadStart}ms ${preloadCount}/${queue.length} queued>`, ...e);
36
- };
37
- const sortQueue = () => {
38
- if (queueDirty) {
39
- queue.sort((e, t) => e.l - t.l);
40
- queueDirty = 0;
41
- }
42
- };
43
- function trigger() {
44
- isTriggerScheduled = 0;
45
- if (!queue.length) return;
46
- sortQueue();
47
- const e = performance.now() + yieldInterval;
48
- let t = 0;
49
- while (queue.length) {
50
- 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) {
58
- queue.shift();
59
- preloadOne(n);
60
- if (performance.now() >= e) {
61
- t = 1;
62
- break;
63
- }
64
- } else break;
65
- }
66
- if (t && queue.length && !isTriggerScheduled) {
67
- isTriggerScheduled = 1;
68
- nextTriggerMacroTask();
69
- }
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
- }
77
- const enqueueAdjustment = (e, t, n, s) => {
78
- adjustmentStack.unshift({ $: e, l: t, B: s, h: n });
79
- };
80
- const processAdjustmentFrame = () => {
81
- 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) {
86
- adjustmentStack.pop();
87
- return 0;
88
- }
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;
94
- 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;
101
- const n3 = e2 / t2;
102
- a = Math.max(0.02, o.l * n3);
103
- s.A = n3;
104
- }
105
- adjustmentStack.push({ $: o, l: a, B: e.B, h: e.h });
106
- return 1;
107
- }
108
- if (e.B?.has(t)) {
109
- adjustmentStack.pop();
110
- return 0;
111
- }
112
- const n = t.l;
113
- t.l = e.l;
114
- if (n - t.l < 0.01) {
115
- adjustmentStack.pop();
116
- return 0;
117
- }
118
- if (
119
- // don't queue until we have initialized the preloader
120
- base != null && t.i < BundleImportState_Preload
121
- ) {
122
- if (t.i === BundleImportState_None) {
123
- t.i = BundleImportState_Queued;
124
- queue.push(t);
125
- config.t && log(`queued ${Math.round((1 - t.l) * 100)}%`, t.k);
126
- }
127
- queueDirty = 1;
128
- }
129
- if (t.S?.length) {
130
- const n2 = e.B || /* @__PURE__ */ new Set();
131
- n2.add(t);
132
- e.B = n2;
133
- e.S = t.S;
134
- e.j = 0;
135
- return 0;
136
- }
137
- adjustmentStack.pop();
138
- return 0;
139
- };
140
- function processPendingAdjustments() {
141
- if (isProcessingAdjustments || !adjustmentStack.length) return;
142
- isAdjustmentScheduled = 0;
143
- isProcessingAdjustments = 1;
144
- const e = shouldYieldInBrowser ? performance.now() + yieldInterval : 0;
145
- let t = 0;
146
- while (adjustmentStack.length) {
147
- t = 1;
148
- const n = processAdjustmentFrame();
149
- if (shouldYieldInBrowser && n && performance.now() >= e) {
150
- if (!isAdjustmentScheduled) {
151
- isAdjustmentScheduled = 1;
152
- nextAdjustmentMacroTask();
153
- }
154
- break;
155
- }
156
- }
157
- isProcessingAdjustments = 0;
158
- if (t && shouldYieldInBrowser) nextTriggerMacroTask();
159
- }
160
- const preloadOne = (e) => {
161
- if (e.i >= BundleImportState_Preload) return;
162
- preloadCount++;
163
- 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);
167
- const n = doc.createElement("link");
168
- n.href = new URL(`${base}${e.k}`, doc.baseURI).toString();
169
- n.rel = rel;
170
- n.as = "script";
171
- n.onload = n.onerror = () => {
172
- preloadCount--;
173
- 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);
177
- n.remove();
178
- nextTriggerMacroTask();
179
- };
180
- doc.head.appendChild(n);
181
- };
182
- const adjustProbabilities = (e, t, n) => {
183
- enqueueAdjustment(e, t, { T: 0 }, n);
184
- if (shouldYieldInBrowser) nextAdjustmentMacroTask();
185
- else processPendingAdjustments();
186
- };
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);
191
- };
192
- const preload = (e, t) => {
193
- if (!e?.length) return;
194
- let n = t ? 1 - t : 0.4;
195
- const s = { T: 0 };
196
- 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);
200
- }
201
- else handleBundle(e, n, s);
202
- if (shouldYieldInBrowser) nextAdjustmentMacroTask();
203
- else processPendingAdjustments();
204
- };
205
- if (isBrowser$2) document.addEventListener("qsymbol", (e) => {
206
- const { symbol: t, href: n } = e.detail;
207
- if (n) {
208
- const e2 = t.slice(t.lastIndexOf("_") + 1);
209
- preload(e2, 1);
210
- }
211
- });
212
- let base;
213
- let graph;
214
- 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 });
216
- const parseBundleGraph = (e) => {
217
- const t = /* @__PURE__ */ new Map();
218
- let n = 0;
219
- while (n < e.length) {
220
- const s = e[n++];
221
- const o = [];
222
- let r;
223
- 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 });
227
- n++;
228
- }
229
- t.set(s, o);
230
- }
231
- return t;
232
- };
233
- const getBundle = (e) => {
234
- let t = bundles.get(e);
235
- if (!t) {
236
- let n;
237
- if (graph) {
238
- n = graph.get(e);
239
- if (!n) return;
240
- if (!n.length) n = void 0;
241
- }
242
- t = makeBundle(e, n);
243
- bundles.set(e, t);
244
- }
245
- return t;
246
- };
247
- const loadBundleGraph = (e, t, n) => {
248
- 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"];
252
- }
253
- if (!isBrowser || e == null) return;
254
- base = e;
255
- if (t) t.then((e2) => e2.text()).then((e2) => {
256
- graph = parseBundleGraph(JSON.parse(e2));
257
- const t2 = [];
258
- for (const [e3, n3] of graph.entries()) {
259
- const s2 = getBundle(e3);
260
- s2.S = n3;
261
- if (s2.l < 1) {
262
- t2.push([s2, s2.l]);
263
- s2.l = 1;
264
- }
265
- }
266
- config.t && log(`parseBundleGraph got ${graph.size} bundles, adjusting ${t2.length}`);
267
- if (!t2.length) {
268
- nextTriggerMacroTask();
269
- return;
270
- }
271
- let n2 = 0;
272
- const s = createMacroTask(() => {
273
- const e3 = performance.now() + yieldInterval;
274
- while (n2 < t2.length) {
275
- const [o, r] = t2[n2];
276
- n2++;
277
- adjustProbabilities(o, r);
278
- if (n2 < t2.length && performance.now() >= e3) {
279
- s();
280
- return;
281
- }
282
- }
283
- nextTriggerMacroTask();
284
- });
285
- s();
286
- }).catch(console.warn);
287
- };
288
- export {
289
- parseBundleGraph as g,
290
- handleBundle as h,
291
- loadBundleGraph as l,
292
- preload as p
293
- };
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
  }
package/dist/server.d.ts CHANGED
@@ -98,32 +98,12 @@ declare interface JSXNode<T extends string | FunctionComponent | unknown = unkno
98
98
  */
99
99
  declare type JSXOutput = JSXNode | string | number | boolean | null | undefined | JSXOutput[];
100
100
 
101
- /** @public @deprecated Use `preloader` instead */
102
- export declare interface PrefetchImplementation {
103
- /** @deprecated No longer used. */
104
- linkRel?: 'prefetch' | 'preload' | 'modulepreload' | null;
105
- /** @deprecated No longer used. */
106
- linkFetchPriority?: 'auto' | 'low' | 'high' | null;
107
- /** @deprecated No longer used. */
108
- linkInsert?: 'js-append' | 'html-append' | null;
109
- /** @deprecated No longer used. */
110
- workerFetchInsert?: 'always' | 'no-link-support' | null;
111
- /** @deprecated No longer used. */
112
- prefetchEvent?: 'always' | null;
113
- }
114
-
115
101
  /** @public */
116
102
  export declare interface PrefetchResource {
117
103
  url: string;
118
104
  imports: PrefetchResource[];
119
105
  }
120
106
 
121
- /** @public */
122
- export declare interface PrefetchStrategy {
123
- implementation?: PrefetchImplementation;
124
- symbolsToPrefetch?: SymbolsToPrefetch;
125
- }
126
-
127
107
  /** @public */
128
108
  export declare interface PreloaderOptions {
129
109
  /**
@@ -137,20 +117,6 @@ export declare interface PreloaderOptions {
137
117
  * Defaults to `5`
138
118
  */
139
119
  ssrPreloads?: number;
140
- /**
141
- * The minimum probability for a bundle to be added as a preload link during SSR.
142
- *
143
- * Defaults to `0.7` (70% probability)
144
- *
145
- * This makes sure that the most likely bundles are preloaded ahead of time.
146
- */
147
- ssrPreloadProbability?: number;
148
- /**
149
- * Log preloader debug information to the console.
150
- *
151
- * Defaults to `false`
152
- */
153
- debug?: boolean;
154
120
  /**
155
121
  * Maximum number of simultaneous preload links that the preloader will maintain. If you set this
156
122
  * higher, the browser will have all JS files in memory sooner, but it will contend with other
@@ -163,15 +129,6 @@ export declare interface PreloaderOptions {
163
129
  * Defaults to `25`
164
130
  */
165
131
  maxIdlePreloads?: number;
166
- /**
167
- * @deprecated The minimum probability for a bundle to be added to the preload queue.
168
- *
169
- * Defaulted to `0.35` (35% probability).
170
- *
171
- * Deprecated because this could cause performance issues with bundles fetched on on click instead
172
- * of being preloaded ahead of time.
173
- */
174
- preloadProbability?: number;
175
132
  }
176
133
 
177
134
  /** @public */
@@ -217,8 +174,6 @@ export declare interface RenderOptions extends SerializeDocumentOptions {
217
174
  qwikLoader?: QwikLoaderOptions;
218
175
  /** Specifies how preloading is handled. This ensures that code is instantly available when needed. */
219
176
  preloader?: PreloaderOptions | false;
220
- /** @deprecated Use `preloader` instead */
221
- prefetchStrategy?: PrefetchStrategy | null;
222
177
  /**
223
178
  * When set, the app is serialized into a fragment. And the returned html is not a complete
224
179
  * document. Defaults to `html`
@@ -336,15 +291,6 @@ export declare interface StreamingOptions {
336
291
  inOrder?: InOrderStreaming;
337
292
  }
338
293
 
339
- /**
340
- * Auto: Prefetch all possible QRLs used by the document. Default
341
- *
342
- * @public
343
- */
344
- export declare type SymbolsToPrefetch = 'auto' | ((opts: {
345
- manifest: ServerQwikManifest;
346
- }) => PrefetchResource[]);
347
-
348
294
  /** @public */
349
295
  export declare const versions: {
350
296
  readonly qwik: string;