@qwik.dev/router 2.0.0-beta.3 → 2.0.0-beta.30

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.
Files changed (84) hide show
  1. package/adapters/static/vite.d.ts +1 -1
  2. package/lib/adapters/azure-swa/vite/index.d.ts +2 -2
  3. package/lib/adapters/azure-swa/vite/index.mjs +39 -44
  4. package/lib/adapters/bun-server/vite/index.d.ts +2 -2
  5. package/lib/adapters/bun-server/vite/index.mjs +6 -7
  6. package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
  7. package/lib/adapters/cloud-run/vite/index.mjs +6 -7
  8. package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
  9. package/lib/adapters/cloudflare-pages/vite/index.mjs +23 -32
  10. package/lib/adapters/deno-server/vite/index.d.ts +2 -2
  11. package/lib/adapters/deno-server/vite/index.mjs +13 -9
  12. package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
  13. package/lib/adapters/netlify-edge/vite/index.mjs +22 -36
  14. package/lib/adapters/node-server/vite/index.d.ts +2 -2
  15. package/lib/adapters/node-server/vite/index.mjs +6 -7
  16. package/lib/adapters/shared/vite/index.d.ts +7 -19
  17. package/lib/adapters/shared/vite/index.mjs +244 -233
  18. package/lib/adapters/ssg/vite/index.d.ts +13 -0
  19. package/lib/adapters/ssg/vite/index.mjs +17 -0
  20. package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
  21. package/lib/adapters/vercel-edge/vite/index.mjs +33 -19
  22. package/lib/chunks/deepFreeze.qwik.mjs +18 -0
  23. package/lib/chunks/error-handler.mjs +57 -0
  24. package/lib/chunks/fs.mjs +144 -0
  25. package/lib/chunks/http-error.qwik.mjs +35 -0
  26. package/lib/chunks/mime-types.mjs +52 -0
  27. package/lib/chunks/not-found-wrapper.qwik.mjs +25 -0
  28. package/lib/chunks/pathname.mjs +105 -0
  29. package/lib/chunks/redirect-handler.mjs +6 -0
  30. package/lib/chunks/routing.qwik.mjs +820 -0
  31. package/lib/chunks/system.mjs +333 -0
  32. package/lib/chunks/use-functions.qwik.mjs +35 -0
  33. package/lib/chunks/worker-thread.qwik.mjs +2572 -0
  34. package/lib/index.d.ts +358 -141
  35. package/lib/index.qwik.mjs +865 -1156
  36. package/lib/middleware/aws-lambda/index.d.ts +3 -2
  37. package/lib/middleware/aws-lambda/index.mjs +15 -13
  38. package/lib/middleware/azure-swa/index.mjs +17 -218
  39. package/lib/middleware/bun/index.d.ts +11 -0
  40. package/lib/middleware/bun/index.mjs +51 -94
  41. package/lib/middleware/cloudflare-pages/index.mjs +23 -28
  42. package/lib/middleware/deno/index.d.ts +11 -0
  43. package/lib/middleware/deno/index.mjs +50 -94
  44. package/lib/middleware/firebase/index.mjs +7 -11
  45. package/lib/middleware/netlify-edge/index.mjs +23 -29
  46. package/lib/middleware/node/index.mjs +31 -100
  47. package/lib/middleware/request-handler/index.d.ts +161 -83
  48. package/lib/middleware/request-handler/index.mjs +1458 -1257
  49. package/lib/middleware/vercel-edge/index.mjs +28 -33
  50. package/lib/modules.d.ts +11 -16
  51. package/lib/service-worker/index.mjs +4 -0
  52. package/lib/{static → ssg}/index.d.ts +45 -13
  53. package/lib/ssg/index.mjs +336 -0
  54. package/lib/vite/index.d.ts +38 -10
  55. package/lib/vite/index.mjs +2067 -26841
  56. package/modules.d.ts +11 -16
  57. package/package.json +62 -67
  58. package/ssg.d.ts +2 -0
  59. package/static.d.ts +1 -1
  60. package/lib/adapters/azure-swa/vite/index.cjs +0 -96
  61. package/lib/adapters/bun-server/vite/index.cjs +0 -50
  62. package/lib/adapters/cloud-run/vite/index.cjs +0 -47
  63. package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -115
  64. package/lib/adapters/deno-server/vite/index.cjs +0 -62
  65. package/lib/adapters/netlify-edge/vite/index.cjs +0 -129
  66. package/lib/adapters/node-server/vite/index.cjs +0 -50
  67. package/lib/adapters/shared/vite/index.cjs +0 -378
  68. package/lib/adapters/static/vite/index.cjs +0 -368
  69. package/lib/adapters/static/vite/index.d.ts +0 -10
  70. package/lib/adapters/static/vite/index.mjs +0 -331
  71. package/lib/adapters/vercel-edge/vite/index.cjs +0 -118
  72. package/lib/index.qwik.cjs +0 -1947
  73. package/lib/middleware/node/index.cjs +0 -314
  74. package/lib/middleware/request-handler/index.cjs +0 -1614
  75. package/lib/service-worker.cjs +0 -17
  76. package/lib/service-worker.mjs +0 -15
  77. package/lib/static/deno.mjs +0 -8
  78. package/lib/static/index.cjs +0 -67
  79. package/lib/static/index.mjs +0 -48
  80. package/lib/static/node.cjs +0 -1124
  81. package/lib/static/node.mjs +0 -1086
  82. package/lib/vite/index.cjs +0 -27445
  83. package/middleware/request-handler/generated/not-found-paths.ts +0 -7
  84. package/middleware/request-handler/generated/static-paths.ts +0 -35
@@ -0,0 +1,820 @@
1
+ import { createAsyncQrl, inlinedQrl, _captures, isBrowser, withLocale } from '@qwik.dev/core';
2
+ import { _deserialize, _UNINITIALIZED } from '@qwik.dev/core/internal';
3
+ import { p } from '@qwik.dev/core/preloader';
4
+ import { d as deepFreeze } from './deepFreeze.qwik.mjs';
5
+
6
+ const CLIENT_DATA_CACHE = /* @__PURE__ */ new Map();
7
+ const QACTION_KEY = "qaction";
8
+ const QLOADER_KEY = "qloaders";
9
+ const QFN_KEY = "qfunc";
10
+ const QDATA_KEY = "qdata";
11
+ const Q_ROUTE = "q:route";
12
+ const DEFAULT_LOADERS_SERIALIZATION_STRATEGY = globalThis.__DEFAULT_LOADERS_SERIALIZATION_STRATEGY__ || "never";
13
+
14
+ const MAX_Q_DATA_RETRY_COUNT = 3;
15
+ const getFetchOptions = (action, noCache) => {
16
+ const actionData = action?.data;
17
+ if (!actionData) {
18
+ if (noCache) {
19
+ return {
20
+ cache: "no-cache",
21
+ headers: {
22
+ "Cache-Control": "no-cache",
23
+ Pragma: "no-cache"
24
+ }
25
+ };
26
+ }
27
+ return void 0;
28
+ }
29
+ if (actionData instanceof FormData) {
30
+ return {
31
+ method: "POST",
32
+ body: actionData
33
+ };
34
+ } else {
35
+ return {
36
+ method: "POST",
37
+ body: JSON.stringify(actionData),
38
+ headers: {
39
+ "Content-Type": "application/json; charset=UTF-8"
40
+ }
41
+ };
42
+ }
43
+ };
44
+ const loadClientData = async (url, opts, retryCount = 0) => {
45
+ const pagePathname = url.pathname;
46
+ const pageSearch = url.search;
47
+ const clientDataPath = getClientDataPath(pagePathname, pageSearch, {
48
+ actionId: opts?.action?.id,
49
+ loaderIds: opts?.loaderIds
50
+ });
51
+ let qData;
52
+ if (!opts?.action) {
53
+ qData = CLIENT_DATA_CACHE.get(clientDataPath);
54
+ }
55
+ if (opts?.preloadRouteBundles !== false) {
56
+ preloadRouteBundles(pagePathname, 0.8);
57
+ }
58
+ let resolveFn;
59
+ if (!qData) {
60
+ const fetchOptions = getFetchOptions(opts?.action, opts?.clearCache);
61
+ if (opts?.action) {
62
+ opts.action.data = void 0;
63
+ }
64
+ qData = fetch(clientDataPath, fetchOptions).then((rsp) => {
65
+ if (rsp.status === 404 && opts?.loaderIds && retryCount < MAX_Q_DATA_RETRY_COUNT) {
66
+ opts.loaderIds = void 0;
67
+ return loadClientData(url, opts, retryCount + 1);
68
+ }
69
+ if (rsp.redirected) {
70
+ const redirectedURL = new URL(rsp.url);
71
+ const isQData = redirectedURL.pathname.endsWith("/q-data.json");
72
+ if (!isQData || redirectedURL.origin !== location.origin) {
73
+ if (!opts?.isPrefetch) {
74
+ location.href = redirectedURL.href;
75
+ }
76
+ return;
77
+ }
78
+ }
79
+ if ((rsp.headers.get("content-type") || "").includes("json")) {
80
+ return rsp.text().then((text) => {
81
+ const clientData = _deserialize(text);
82
+ if (!clientData) {
83
+ location.href = url.href;
84
+ return;
85
+ }
86
+ if (opts?.clearCache) {
87
+ CLIENT_DATA_CACHE.delete(clientDataPath);
88
+ }
89
+ if (clientData.redirect) {
90
+ location.href = clientData.redirect;
91
+ } else if (opts?.action) {
92
+ const { action } = opts;
93
+ const actionData = clientData.loaders[action.id];
94
+ resolveFn = () => {
95
+ action.resolve({
96
+ status: rsp.status,
97
+ result: actionData
98
+ });
99
+ };
100
+ }
101
+ return clientData;
102
+ });
103
+ } else {
104
+ if (opts?.isPrefetch !== true) {
105
+ location.href = url.href;
106
+ }
107
+ return void 0;
108
+ }
109
+ });
110
+ if (!opts?.action) {
111
+ CLIENT_DATA_CACHE.set(clientDataPath, qData);
112
+ }
113
+ }
114
+ return qData.then((v) => {
115
+ if (!v) {
116
+ CLIENT_DATA_CACHE.delete(clientDataPath);
117
+ }
118
+ resolveFn && resolveFn();
119
+ return v;
120
+ });
121
+ };
122
+
123
+ const toPath = (url) => url.pathname + url.search + url.hash;
124
+ const toUrl = (url, baseUrl) => new URL(url, baseUrl.href);
125
+ const isSameOrigin = (a, b) => a.origin === b.origin;
126
+ const withSlash = (path) => path.endsWith("/") ? path : path + "/";
127
+ const isSamePathname = ({ pathname: a }, { pathname: b }) => {
128
+ const lDiff = Math.abs(a.length - b.length);
129
+ return lDiff === 0 ? a === b : lDiff === 1 && withSlash(a) === withSlash(b);
130
+ };
131
+ const isSameSearchQuery = (a, b) => a.search === b.search;
132
+ const isSamePath = (a, b) => isSameSearchQuery(a, b) && isSamePathname(a, b);
133
+ const getClientDataPath = (pathname, pageSearch, options) => {
134
+ let search = pageSearch ?? "";
135
+ if (options?.actionId) {
136
+ search += (search ? "&" : "?") + QACTION_KEY + "=" + encodeURIComponent(options.actionId);
137
+ }
138
+ if (options?.loaderIds) {
139
+ for (const loaderId of options.loaderIds) {
140
+ search += (search ? "&" : "?") + QLOADER_KEY + "=" + encodeURIComponent(loaderId);
141
+ }
142
+ }
143
+ return pathname + (pathname.endsWith("/") ? "" : "/") + "q-data.json" + search;
144
+ };
145
+ const getClientNavPath = (props, baseUrl) => {
146
+ const href = props.href;
147
+ if (typeof href === "string" && typeof props.target !== "string" && !props.reload) {
148
+ try {
149
+ const linkUrl = toUrl(href.trim(), baseUrl.url);
150
+ const currentUrl = toUrl("", baseUrl.url);
151
+ if (isSameOrigin(linkUrl, currentUrl)) {
152
+ return toPath(linkUrl);
153
+ }
154
+ } catch (e) {
155
+ console.error(e);
156
+ }
157
+ } else if (props.reload) {
158
+ return toPath(toUrl("", baseUrl.url));
159
+ }
160
+ return null;
161
+ };
162
+ const shouldPreload = (clientNavPath, currentLoc) => {
163
+ if (clientNavPath) {
164
+ const prefetchUrl = toUrl(clientNavPath, currentLoc.url);
165
+ const currentUrl = toUrl("", currentLoc.url);
166
+ return !isSamePathname(prefetchUrl, currentUrl);
167
+ }
168
+ return false;
169
+ };
170
+ const isPromise = (value) => {
171
+ return value && typeof value.then === "function";
172
+ };
173
+ const createLoaderSignal = (loadersObject, loaderId, url, serializationStrategy, container) => {
174
+ return createAsyncQrl(/* @__PURE__ */ inlinedQrl(async () => {
175
+ const loaderId2 = _captures[0], loadersObject2 = _captures[1], url2 = _captures[2];
176
+ if (isBrowser && loadersObject2[loaderId2] === _UNINITIALIZED) {
177
+ const data = await loadClientData(url2, {
178
+ loaderIds: [
179
+ loaderId2
180
+ ]
181
+ });
182
+ loadersObject2[loaderId2] = data?.loaders[loaderId2] ?? _UNINITIALIZED;
183
+ }
184
+ return loadersObject2[loaderId2];
185
+ }, "createLoaderSignal_createAsync_CFLMoh8rnzw", [
186
+ loaderId,
187
+ loadersObject,
188
+ url
189
+ ]), {
190
+ container,
191
+ serializationStrategy
192
+ });
193
+ };
194
+
195
+ const newScrollState = () => {
196
+ return {
197
+ x: 0,
198
+ y: 0,
199
+ w: 0,
200
+ h: 0
201
+ };
202
+ };
203
+ const clientNavigate = (win, navType, fromURL, toURL, replaceState = false) => {
204
+ if (navType !== "popstate") {
205
+ const samePath = isSamePath(fromURL, toURL);
206
+ const sameHash = fromURL.hash === toURL.hash;
207
+ if (!samePath || !sameHash) {
208
+ const newState = {
209
+ _qRouterScroll: newScrollState()
210
+ };
211
+ if (replaceState) {
212
+ win.history.replaceState(newState, "", toPath(toURL));
213
+ } else {
214
+ win.history.pushState(newState, "", toPath(toURL));
215
+ }
216
+ }
217
+ }
218
+ };
219
+ const preloadRouteBundles = (path, probability = 0.8) => {
220
+ if (isBrowser) {
221
+ path = path.endsWith("/") ? path : path + "/";
222
+ path = path.length > 1 && path.startsWith("/") ? path.slice(1) : path;
223
+ p(path, probability);
224
+ }
225
+ };
226
+
227
+ const mergeArray = (existingArr, newArr) => {
228
+ if (Array.isArray(newArr)) {
229
+ for (const newItem of newArr) {
230
+ if (typeof newItem.key === "string") {
231
+ const existingIndex = existingArr.findIndex((i) => i.key === newItem.key);
232
+ if (existingIndex > -1) {
233
+ existingArr[existingIndex] = newItem;
234
+ continue;
235
+ }
236
+ }
237
+ existingArr.push(newItem);
238
+ }
239
+ }
240
+ };
241
+ const resolveDocumentHead = (resolvedHead, updatedHead) => {
242
+ if (typeof updatedHead.title === "string") {
243
+ resolvedHead.title = updatedHead.title;
244
+ }
245
+ mergeArray(resolvedHead.meta, updatedHead.meta);
246
+ mergeArray(resolvedHead.links, updatedHead.links);
247
+ mergeArray(resolvedHead.styles, updatedHead.styles);
248
+ mergeArray(resolvedHead.scripts, updatedHead.scripts);
249
+ Object.assign(resolvedHead.frontmatter, updatedHead.frontmatter);
250
+ };
251
+ const createDocumentHead = (defaults) => ({
252
+ title: defaults?.title || "",
253
+ meta: [
254
+ ...defaults?.meta || []
255
+ ],
256
+ links: [
257
+ ...defaults?.links || []
258
+ ],
259
+ styles: [
260
+ ...defaults?.styles || []
261
+ ],
262
+ scripts: [
263
+ ...defaults?.scripts || []
264
+ ],
265
+ frontmatter: {
266
+ ...defaults?.frontmatter
267
+ }
268
+ });
269
+ const resolveRouteConfig = (resolveValue, routeLocation, contentModules, locale, status, defaults) => withLocale(locale, () => {
270
+ const head = createDocumentHead(defaults);
271
+ let eTag;
272
+ let cacheKey;
273
+ const fns = [];
274
+ for (let i = 0; i < contentModules.length; i++) {
275
+ const contentModule = contentModules[i];
276
+ if (!contentModule) {
277
+ continue;
278
+ }
279
+ const isLast = i === contentModules.length - 1;
280
+ let config;
281
+ if (contentModule.routeConfig) {
282
+ config = contentModule.routeConfig;
283
+ } else if (contentModule.head) {
284
+ const synthetic = {
285
+ head: void 0
286
+ };
287
+ const headExport = contentModule.head;
288
+ if (typeof headExport === "function") {
289
+ const mod = contentModule;
290
+ config = (props) => ({
291
+ head: headExport(props),
292
+ eTag: mod.eTag,
293
+ cacheKey: mod.cacheKey
294
+ });
295
+ } else {
296
+ synthetic.head = headExport;
297
+ const mod = contentModule;
298
+ if (mod.eTag !== void 0) {
299
+ synthetic.eTag = mod.eTag;
300
+ }
301
+ if (mod.cacheKey !== void 0) {
302
+ synthetic.cacheKey = mod.cacheKey;
303
+ }
304
+ config = synthetic;
305
+ }
306
+ } else {
307
+ const mod = contentModule;
308
+ if (mod.eTag !== void 0 || mod.cacheKey !== void 0) {
309
+ config = {
310
+ eTag: mod.eTag,
311
+ cacheKey: mod.cacheKey
312
+ };
313
+ }
314
+ }
315
+ if (!config) {
316
+ continue;
317
+ }
318
+ if (typeof config === "function") {
319
+ fns.unshift({
320
+ fn: config,
321
+ isLast
322
+ });
323
+ } else {
324
+ if (config.head) {
325
+ resolveDocumentHead(head, config.head);
326
+ }
327
+ if (config.eTag !== void 0) {
328
+ eTag = config.eTag;
329
+ }
330
+ if (config.cacheKey !== void 0) {
331
+ cacheKey = config.cacheKey;
332
+ }
333
+ }
334
+ }
335
+ if (fns.length) {
336
+ const headProps = {
337
+ head,
338
+ status,
339
+ withLocale: (fn) => fn(),
340
+ resolveValue,
341
+ ...routeLocation
342
+ };
343
+ for (const { fn } of fns) {
344
+ const result = fn(headProps);
345
+ if (result.head) {
346
+ resolveDocumentHead(head, result.head);
347
+ }
348
+ if (result.eTag !== void 0) {
349
+ eTag = result.eTag;
350
+ }
351
+ if (result.cacheKey !== void 0) {
352
+ cacheKey = result.cacheKey;
353
+ }
354
+ }
355
+ }
356
+ return {
357
+ head,
358
+ eTag,
359
+ cacheKey
360
+ };
361
+ });
362
+ const resolveHead = (endpoint, routeLocation, contentModules, locale, defaults) => {
363
+ const getData = (loaderOrAction) => {
364
+ const id = loaderOrAction.__id;
365
+ if (loaderOrAction.__brand === "server_loader") {
366
+ if (!(id in endpoint.loaders)) {
367
+ throw new Error("You can not get the returned data of a loader that has not been executed for this request.");
368
+ }
369
+ }
370
+ const data = endpoint.loaders[id];
371
+ if (isPromise(data)) {
372
+ throw new Error("Loaders returning a promise can not be resolved for the head function.");
373
+ }
374
+ return data;
375
+ };
376
+ return resolveRouteConfig(getData, routeLocation, contentModules, locale, endpoint.status, defaults).head;
377
+ };
378
+
379
+ const MODULE_CACHE = /* @__PURE__ */ new WeakMap();
380
+ const httpErrorLoader = () => import('./http-error.qwik.mjs');
381
+ function walkTrieKeys(root, keys) {
382
+ let node = root;
383
+ const layouts = [];
384
+ if (node._L) {
385
+ layouts.push(node._L);
386
+ }
387
+ for (const key of keys) {
388
+ let next = node[key];
389
+ if (!next && node._M) {
390
+ for (const group of node._M) {
391
+ next = group[key];
392
+ if (next) {
393
+ if (group._L) {
394
+ layouts.push(group._L);
395
+ }
396
+ break;
397
+ }
398
+ }
399
+ }
400
+ if (!next) {
401
+ return void 0;
402
+ }
403
+ node = next;
404
+ if (node._L) {
405
+ layouts.push(node._L);
406
+ }
407
+ }
408
+ return {
409
+ node,
410
+ layouts
411
+ };
412
+ }
413
+ function collectNodeMeta(node, groups, layouts, errorLoaderRef, notFoundLoaderRef, menuLoaderRef) {
414
+ for (const g of groups) {
415
+ if (g._L) {
416
+ layouts.push(g._L);
417
+ }
418
+ if (g._E) {
419
+ errorLoaderRef.v = g._E;
420
+ }
421
+ if (g._4) {
422
+ notFoundLoaderRef.v = g._4;
423
+ }
424
+ if (g._N) {
425
+ menuLoaderRef.v = g._N;
426
+ }
427
+ }
428
+ if (node._L) {
429
+ layouts.push(node._L);
430
+ }
431
+ if (node._E) {
432
+ errorLoaderRef.v = node._E;
433
+ }
434
+ if (node._4) {
435
+ notFoundLoaderRef.v = node._4;
436
+ }
437
+ if (node._N) {
438
+ menuLoaderRef.v = node._N;
439
+ }
440
+ }
441
+ function tryWildcardMatch(node, part, partLower, parts, partIndex, params) {
442
+ let next = node._W;
443
+ if (next) {
444
+ const prefix = next._0;
445
+ const suffix = next._9;
446
+ if (prefix || suffix) {
447
+ const pre = prefix || "";
448
+ const suf = suffix || "";
449
+ if (partLower.length > pre.length + suf.length && (!pre || partLower.startsWith(pre.toLowerCase())) && (!suf || partLower.endsWith(suf.toLowerCase()))) {
450
+ const paramName = next._P;
451
+ const value = part.slice(pre.length, suf ? part.length - suf.length : void 0);
452
+ params[paramName] = value;
453
+ return {
454
+ next,
455
+ routePart: `${pre}[${paramName}]${suf}`,
456
+ done: false
457
+ };
458
+ }
459
+ } else {
460
+ const paramName = next._P;
461
+ params[paramName] = part;
462
+ return {
463
+ next,
464
+ routePart: `[${paramName}]`,
465
+ done: false
466
+ };
467
+ }
468
+ }
469
+ next = node._A;
470
+ if (next) {
471
+ const paramName = next._P;
472
+ const restValue = parts.slice(partIndex).join("/");
473
+ params[paramName] = restValue;
474
+ return {
475
+ next,
476
+ routePart: `[...${paramName}]`,
477
+ done: true
478
+ };
479
+ }
480
+ return void 0;
481
+ }
482
+ function findChild(node, part, partLower, parts, partIndex, params) {
483
+ const exact = node[partLower];
484
+ if (exact) {
485
+ return {
486
+ next: exact,
487
+ groups: [],
488
+ routePart: part,
489
+ done: false
490
+ };
491
+ }
492
+ if (node._M) {
493
+ for (const group of node._M) {
494
+ const groupResult = findChild(group, part, partLower, parts, partIndex, params);
495
+ if (groupResult) {
496
+ groupResult.groups.unshift(group);
497
+ return groupResult;
498
+ }
499
+ }
500
+ }
501
+ const wildcard = tryWildcardMatch(node, part, partLower, parts, partIndex, params);
502
+ if (wildcard) {
503
+ return {
504
+ ...wildcard,
505
+ groups: []
506
+ };
507
+ }
508
+ return void 0;
509
+ }
510
+ function findIndexNode(node) {
511
+ if (node._I || node._G) {
512
+ return {
513
+ target: node,
514
+ groups: []
515
+ };
516
+ }
517
+ if (node._M) {
518
+ for (const group of node._M) {
519
+ const result = findIndexNode(group);
520
+ if (result) {
521
+ if (result.target !== group) {
522
+ result.groups.unshift(group);
523
+ }
524
+ return result;
525
+ }
526
+ }
527
+ }
528
+ return void 0;
529
+ }
530
+ function resolveLoaders(root, node, gatheredLayouts) {
531
+ if (node._G) {
532
+ const keys = node._G.split("/").filter((p) => p.length > 0);
533
+ const target = walkTrieKeys(root, keys);
534
+ if (!target) {
535
+ return void 0;
536
+ }
537
+ let targetNode = target.node;
538
+ const targetLayouts = target.layouts;
539
+ if (!targetNode._I && !targetNode._G) {
540
+ const indexResult = findIndexNode(targetNode);
541
+ if (indexResult) {
542
+ for (const g of indexResult.groups) {
543
+ if (g._L) {
544
+ targetLayouts.push(g._L);
545
+ }
546
+ }
547
+ targetNode = indexResult.target;
548
+ if (targetNode._L) {
549
+ targetLayouts.push(targetNode._L);
550
+ }
551
+ }
552
+ }
553
+ return resolveLoaders(root, targetNode, targetLayouts);
554
+ }
555
+ const index = node._I;
556
+ if (!index) {
557
+ return void 0;
558
+ }
559
+ if (Array.isArray(index)) {
560
+ return index;
561
+ }
562
+ return [
563
+ ...gatheredLayouts,
564
+ index
565
+ ];
566
+ }
567
+ function findRestNode(node) {
568
+ if (node._A) {
569
+ return {
570
+ next: node._A,
571
+ groups: []
572
+ };
573
+ }
574
+ if (node._M) {
575
+ for (const group of node._M) {
576
+ const result = findRestNode(group);
577
+ if (result) {
578
+ result.groups.unshift(group);
579
+ return result;
580
+ }
581
+ }
582
+ }
583
+ return void 0;
584
+ }
585
+ function matchRouteTree(root = {}, pathname) {
586
+ let node = root;
587
+ const params = {};
588
+ const routeParts = [];
589
+ const layouts = [];
590
+ const errorLoaderRef = {
591
+ v: void 0
592
+ };
593
+ const notFoundLoaderRef = {
594
+ v: void 0
595
+ };
596
+ const menuLoaderRef = {
597
+ v: void 0
598
+ };
599
+ if (root._L) {
600
+ layouts.push(root._L);
601
+ }
602
+ if (root._E) {
603
+ errorLoaderRef.v = root._E;
604
+ }
605
+ if (root._4) {
606
+ notFoundLoaderRef.v = root._4;
607
+ }
608
+ if (root._N) {
609
+ menuLoaderRef.v = root._N;
610
+ }
611
+ let done = false;
612
+ let matched = true;
613
+ const parts = pathname.split("/").filter((p) => p.length > 0).map(decodeURIComponent);
614
+ let restFallback;
615
+ let i = 0;
616
+ const len = parts.length;
617
+ for (; !done && i < len; i++) {
618
+ const part = parts[i];
619
+ const partLower = part.toLowerCase();
620
+ const restInfo = findRestNode(node);
621
+ if (restInfo) {
622
+ restFallback = {
623
+ aNode: restInfo.next,
624
+ groups: restInfo.groups,
625
+ paramName: restInfo.next._P,
626
+ restValue: parts.slice(i).join("/"),
627
+ routeParts: [
628
+ ...routeParts
629
+ ],
630
+ params: {
631
+ ...params
632
+ },
633
+ layouts: [
634
+ ...layouts
635
+ ],
636
+ errorLoader: errorLoaderRef.v,
637
+ notFoundLoader: notFoundLoaderRef.v,
638
+ menuLoader: menuLoaderRef.v
639
+ };
640
+ }
641
+ const found = findChild(node, part, partLower, parts, i, params);
642
+ if (!found) {
643
+ matched = false;
644
+ break;
645
+ }
646
+ routeParts.push(found.routePart);
647
+ done = found.done;
648
+ node = found.next;
649
+ collectNodeMeta(node, found.groups, layouts, errorLoaderRef, notFoundLoaderRef, menuLoaderRef);
650
+ }
651
+ if (matched && !done && i === len) {
652
+ if (!node._I && !node._G) {
653
+ const indexResult = findIndexNode(node);
654
+ if (indexResult) {
655
+ collectNodeMeta(indexResult.target, indexResult.groups, layouts, errorLoaderRef, notFoundLoaderRef, menuLoaderRef);
656
+ node = indexResult.target;
657
+ }
658
+ }
659
+ if (!node._I && !node._G && node._A) {
660
+ const next = node._A;
661
+ const paramName = next._P;
662
+ params[paramName] = "";
663
+ routeParts.push(`[...${paramName}]`);
664
+ node = next;
665
+ if (node._L) {
666
+ layouts.push(node._L);
667
+ }
668
+ if (node._N) {
669
+ menuLoaderRef.v = node._N;
670
+ }
671
+ }
672
+ if (!node._I && !node._G) {
673
+ const restInfo = findRestNode(node);
674
+ if (restInfo) {
675
+ const next = restInfo.next;
676
+ const paramName = next._P;
677
+ params[paramName] = "";
678
+ routeParts.push(`[...${paramName}]`);
679
+ collectNodeMeta(next, restInfo.groups, layouts, errorLoaderRef, notFoundLoaderRef, menuLoaderRef);
680
+ node = next;
681
+ }
682
+ }
683
+ }
684
+ const loaders = matched && (done || i >= len) ? resolveLoaders(root, node, layouts) : void 0;
685
+ if (!loaders && restFallback) {
686
+ const fb = restFallback;
687
+ const fbParams = {
688
+ ...fb.params,
689
+ [fb.paramName]: fb.restValue
690
+ };
691
+ const fbRouteParts = [
692
+ ...fb.routeParts,
693
+ `[...${fb.paramName}]`
694
+ ];
695
+ const fbLayouts = [
696
+ ...fb.layouts
697
+ ];
698
+ const fbErrorRef = {
699
+ v: fb.errorLoader
700
+ };
701
+ const fbNotFoundRef = {
702
+ v: fb.notFoundLoader
703
+ };
704
+ const fbMenuRef = {
705
+ v: fb.menuLoader
706
+ };
707
+ collectNodeMeta(fb.aNode, fb.groups, fbLayouts, fbErrorRef, fbNotFoundRef, fbMenuRef);
708
+ const fbLoaders = resolveLoaders(root, fb.aNode, fbLayouts);
709
+ if (fbLoaders) {
710
+ return {
711
+ loaders: fbLoaders,
712
+ params: fbParams,
713
+ routeParts: fbRouteParts,
714
+ notFound: false,
715
+ routeBundleNames: fb.aNode._B,
716
+ menuLoader: fbMenuRef.v,
717
+ errorLoader: fbErrorRef.v,
718
+ notFoundLoader: fbNotFoundRef.v
719
+ };
720
+ }
721
+ errorLoaderRef.v = fbErrorRef.v;
722
+ notFoundLoaderRef.v = fbNotFoundRef.v;
723
+ menuLoaderRef.v = fbMenuRef.v;
724
+ }
725
+ if (!loaders) {
726
+ const loader = notFoundLoaderRef.v || errorLoaderRef.v || httpErrorLoader;
727
+ return {
728
+ loaders: [
729
+ loader
730
+ ],
731
+ params,
732
+ routeParts,
733
+ notFound: true,
734
+ routeBundleNames: void 0,
735
+ menuLoader: menuLoaderRef.v,
736
+ errorLoader: errorLoaderRef.v,
737
+ notFoundLoader: notFoundLoaderRef.v
738
+ };
739
+ }
740
+ return {
741
+ loaders,
742
+ params,
743
+ routeParts,
744
+ notFound: false,
745
+ routeBundleNames: node._B,
746
+ menuLoader: menuLoaderRef.v,
747
+ errorLoader: errorLoaderRef.v,
748
+ notFoundLoader: notFoundLoaderRef.v
749
+ };
750
+ }
751
+ const loadModule = (moduleLoader, pendingLoads, moduleSetter, cacheModules) => {
752
+ if (typeof moduleLoader === "function") {
753
+ const loadedModule = MODULE_CACHE.get(moduleLoader);
754
+ if (loadedModule) {
755
+ moduleSetter(loadedModule);
756
+ } else {
757
+ const moduleOrPromise = moduleLoader();
758
+ if (typeof moduleOrPromise.then === "function") {
759
+ pendingLoads.push(moduleOrPromise.then((loadedModule2) => {
760
+ if (cacheModules !== false) {
761
+ MODULE_CACHE.set(moduleLoader, loadedModule2);
762
+ }
763
+ moduleSetter(loadedModule2);
764
+ }));
765
+ } else if (moduleOrPromise) {
766
+ moduleSetter(moduleOrPromise);
767
+ }
768
+ }
769
+ }
770
+ };
771
+ const loadRoute = async (routes, cacheModules, pathname, isInternal) => {
772
+ const result = matchRouteTree(routes, pathname);
773
+ const { loaders, params, routeParts, notFound, routeBundleNames, menuLoader, errorLoader, notFoundLoader } = result;
774
+ const routeName = "/" + routeParts.join("/");
775
+ const modules = new Array(loaders.length);
776
+ const pendingLoads = [];
777
+ loaders.forEach((moduleLoader, i) => {
778
+ loadModule(moduleLoader, pendingLoads, (routeModule) => modules[i] = routeModule, cacheModules);
779
+ });
780
+ let menu = void 0;
781
+ if (!isInternal) {
782
+ loadModule(menuLoader, pendingLoads, (menuModule) => menu = menuModule?.default, cacheModules);
783
+ }
784
+ if (notFound && notFoundLoader) {
785
+ let notFoundMod;
786
+ let errorMod;
787
+ loadModule(notFoundLoader, pendingLoads, (mod) => notFoundMod = mod, cacheModules);
788
+ loadModule(errorLoader || httpErrorLoader, pendingLoads, (mod) => errorMod = mod, cacheModules);
789
+ if (pendingLoads.length > 0) {
790
+ await Promise.all(pendingLoads);
791
+ }
792
+ const { createNotFoundWrapper } = await import('./not-found-wrapper.qwik.mjs');
793
+ const wrapperModule = createNotFoundWrapper(notFoundMod, errorMod);
794
+ return {
795
+ $routeName$: routeName,
796
+ $params$: params,
797
+ $mods$: [
798
+ wrapperModule
799
+ ],
800
+ $menu$: deepFreeze(menu),
801
+ $routeBundleNames$: routeBundleNames,
802
+ $notFound$: notFound,
803
+ $errorLoader$: errorLoader
804
+ };
805
+ }
806
+ if (pendingLoads.length > 0) {
807
+ await Promise.all(pendingLoads);
808
+ }
809
+ return {
810
+ $routeName$: routeName,
811
+ $params$: params,
812
+ $mods$: modules,
813
+ $menu$: deepFreeze(menu),
814
+ $routeBundleNames$: routeBundleNames,
815
+ $notFound$: notFound,
816
+ $errorLoader$: errorLoader
817
+ };
818
+ };
819
+
820
+ export { CLIENT_DATA_CACHE as C, DEFAULT_LOADERS_SERIALIZATION_STRATEGY as D, Q_ROUTE as Q, createDocumentHead as a, isSameOrigin as b, createLoaderSignal as c, clientNavigate as d, loadRoute as e, toPath as f, getClientNavPath as g, QFN_KEY as h, isSamePath as i, QACTION_KEY as j, QDATA_KEY as k, loadClientData as l, resolveRouteConfig as m, QLOADER_KEY as n, isPromise as o, preloadRouteBundles as p, resolveHead as r, shouldPreload as s, toUrl as t };