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

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/not-found-wrapper.qwik.mjs +25 -0
  27. package/lib/chunks/pathname.mjs +105 -0
  28. package/lib/chunks/redirect-handler.mjs +6 -0
  29. package/lib/chunks/routing.qwik.mjs +821 -0
  30. package/lib/chunks/system.mjs +333 -0
  31. package/lib/chunks/url.mjs +61 -0
  32. package/lib/chunks/use-functions.qwik.mjs +35 -0
  33. package/lib/chunks/worker-thread.qwik.mjs +2573 -0
  34. package/lib/index.d.ts +362 -142
  35. package/lib/index.qwik.mjs +949 -1244
  36. package/lib/middleware/aws-lambda/index.d.ts +0 -5
  37. package/lib/middleware/aws-lambda/index.mjs +14 -17
  38. package/lib/middleware/azure-swa/index.mjs +16 -221
  39. package/lib/middleware/bun/index.d.ts +11 -0
  40. package/lib/middleware/bun/index.mjs +50 -97
  41. package/lib/middleware/cloudflare-pages/index.mjs +22 -31
  42. package/lib/middleware/deno/index.d.ts +11 -0
  43. package/lib/middleware/deno/index.mjs +49 -97
  44. package/lib/middleware/firebase/index.mjs +6 -15
  45. package/lib/middleware/netlify-edge/index.mjs +22 -32
  46. package/lib/middleware/node/index.mjs +31 -105
  47. package/lib/middleware/request-handler/index.d.ts +163 -88
  48. package/lib/middleware/request-handler/index.mjs +1458 -1260
  49. package/lib/middleware/vercel-edge/index.mjs +27 -36
  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
@@ -1,583 +1,163 @@
1
- import { jsx, Fragment, jsxs } from "@qwik.dev/core/jsx-runtime";
2
- import { component$, useErrorBoundary, useOnWindow, $, Slot, isBrowser, createContextId, implicit$FirstArg, useContext, useVisibleTask$, noSerialize, useServerData, useSignal, untrack, sync$, isDev, withLocale, event$, useStyles$, isServer, useStore, useContextProvider, useTask$, getLocale, jsx as jsx$1, SkipRender } from "@qwik.dev/core";
3
- import { p } from "@qwik.dev/core/preloader";
4
- import { _deserialize, _weakSerialize, _getContextElement, _getQContainerElement, _waitUntilRendered, _wrapStore, _getContextEvent, _serialize } from "@qwik.dev/core/internal";
5
- import * as qwikRouterConfig from "@qwik-router-config";
6
- import { z } from "zod";
7
- import { z as z2 } from "zod";
8
- import swRegister from "@qwik-router-sw-register";
9
- const ErrorBoundary = component$((props) => {
10
- const store2 = useErrorBoundary();
11
- useOnWindow("qerror", $((e) => {
1
+ import { componentQrl, inlinedQrl, useErrorBoundary, useOnWindow, _captures, _jsxSorted, Slot, useSignal, untrack, _qrlSync, useVisibleTaskQrl, isDev, _jsxSplit, _getConstProps, _getVarProps, eventQrl, isServer, useStylesQrl, useServerData, useStore, useContextProvider, useTaskQrl, getLocale, noSerialize, isBrowser, useContext, SkipRender, implicit$FirstArg, withLocale, _wrapProp, _restProps, _fnSignal, createElement } from '@qwik.dev/core';
2
+ import { Fragment } from '@qwik.dev/core/jsx-runtime';
3
+ import { g as getClientNavPath, s as shouldPreload, p as preloadRouteBundles, l as loadClientData, i as isSamePath, c as createLoaderSignal, a as createDocumentHead, b as loadRoute, r as resolveHead, C as CLIENT_DATA_CACHE, d as isSameOrigin, Q as Q_ROUTE, D as DEFAULT_LOADERS_SERIALIZATION_STRATEGY, t as toUrl, e as clientNavigate, f as toPath, h as QFN_KEY, j as QACTION_KEY, k as QDATA_KEY } from './chunks/routing.qwik.mjs';
4
+ import { u as useNavigate, a as useLocation, b as useQwikRouterEnv, C as ContentContext, c as ContentInternalContext, D as DocumentHeadContext, H as HttpStatusContext, R as RouteLocationContext, d as RouteNavigateContext, e as RouteStateContext, f as RouteActionContext, g as RoutePreventNavigateContext, h as useAction, i as useDocumentHead } from './chunks/use-functions.qwik.mjs';
5
+ export { j as useContent, k as useHttpStatus, l as usePreventNavigate$, m as usePreventNavigateQrl } from './chunks/use-functions.qwik.mjs';
6
+ import * as qwikRouterConfig from '@qwik-router-config';
7
+ import { _getContextContainer, SerializerSymbol, _UNINITIALIZED, _hasStoreEffects, forceStoreEffects, _waitUntilRendered, _getContextHostElement, _getContextEvent, _serialize, _deserialize, _resolveContextWithoutSequentialScope } from '@qwik.dev/core/internal';
8
+ import { _asyncRequestStore } from '@qwik.dev/router/middleware/request-handler';
9
+ import * as v from 'valibot';
10
+ import * as z from 'zod';
11
+ export { z } from 'zod';
12
+ import swRegister from '@qwik-router-sw-register';
13
+ import { renderToStream } from '@qwik.dev/core/server';
14
+
15
+ const ErrorBoundary = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
16
+ const store = useErrorBoundary();
17
+ useOnWindow("qerror", /* @__PURE__ */ inlinedQrl((e) => {
18
+ const store2 = _captures[0];
12
19
  store2.error = e.detail.error;
13
- }));
14
- if (store2.error && props.fallback$) {
15
- return /* @__PURE__ */ jsx(Fragment, {
16
- children: props.fallback$(store2.error)
17
- });
18
- }
19
- return /* @__PURE__ */ jsx(Slot, {});
20
- });
21
- const MODULE_CACHE = /* @__PURE__ */ new WeakMap();
22
- const CLIENT_DATA_CACHE = /* @__PURE__ */ new Map();
23
- const QACTION_KEY = "qaction";
24
- const QFN_KEY = "qfunc";
25
- const QDATA_KEY = "qdata";
26
- const toPath = (url) => url.pathname + url.search + url.hash;
27
- const toUrl = (url, baseUrl) => new URL(url, baseUrl.href);
28
- const isSameOrigin = (a, b) => a.origin === b.origin;
29
- const withSlash = (path) => path.endsWith("/") ? path : path + "/";
30
- const isSamePathname = ({ pathname: a }, { pathname: b }) => {
31
- const lDiff = Math.abs(a.length - b.length);
32
- return lDiff === 0 ? a === b : lDiff === 1 && withSlash(a) === withSlash(b);
33
- };
34
- const isSameSearchQuery = (a, b) => a.search === b.search;
35
- const isSamePath = (a, b) => isSameSearchQuery(a, b) && isSamePathname(a, b);
36
- const getClientDataPath = (pathname, pageSearch, action) => {
37
- let search = pageSearch ?? "";
38
- if (action) {
39
- search += (search ? "&" : "?") + QACTION_KEY + "=" + encodeURIComponent(action.id);
40
- }
41
- return pathname + (pathname.endsWith("/") ? "" : "/") + "q-data.json" + search;
42
- };
43
- const getClientNavPath = (props, baseUrl) => {
44
- const href = props.href;
45
- if (typeof href === "string" && typeof props.target !== "string" && !props.reload) {
46
- try {
47
- const linkUrl = toUrl(href.trim(), baseUrl.url);
48
- const currentUrl = toUrl("", baseUrl.url);
49
- if (isSameOrigin(linkUrl, currentUrl)) {
50
- return toPath(linkUrl);
51
- }
52
- } catch (e) {
53
- console.error(e);
54
- }
55
- } else if (props.reload) {
56
- return toPath(toUrl("", baseUrl.url));
57
- }
58
- return null;
59
- };
60
- const shouldPreload = (clientNavPath, currentLoc) => {
61
- if (clientNavPath) {
62
- const prefetchUrl = toUrl(clientNavPath, currentLoc.url);
63
- const currentUrl = toUrl("", currentLoc.url);
64
- return !isSamePathname(prefetchUrl, currentUrl);
65
- }
66
- return false;
67
- };
68
- const isPromise = (value) => {
69
- return value && typeof value.then === "function";
70
- };
71
- const deepFreeze = (obj) => {
72
- if (obj == null) {
73
- return obj;
74
- }
75
- Object.getOwnPropertyNames(obj).forEach((prop) => {
76
- const value = obj[prop];
77
- if (value && typeof value === "object" && !Object.isFrozen(value)) {
78
- deepFreeze(value);
79
- }
80
- });
81
- return Object.freeze(obj);
82
- };
83
- const clientNavigate = (win, navType, fromURL, toURL, replaceState = false) => {
84
- if (navType !== "popstate") {
85
- const samePath = isSamePath(fromURL, toURL);
86
- const sameHash = fromURL.hash === toURL.hash;
87
- if (!samePath || !sameHash) {
88
- const newState = {
89
- _qRouterScroll: newScrollState()
90
- };
91
- if (replaceState) {
92
- win.history.replaceState(newState, "", toPath(toURL));
93
- } else {
94
- win.history.pushState(newState, "", toPath(toURL));
95
- }
96
- }
97
- }
98
- };
99
- const newScrollState = () => {
100
- return {
101
- x: 0,
102
- y: 0,
103
- w: 0,
104
- h: 0
105
- };
106
- };
107
- const prefetchSymbols = (path) => {
108
- if (isBrowser) {
109
- path = path.endsWith("/") ? path : path + "/";
110
- path = path.length > 1 && path.startsWith("/") ? path.slice(1) : path;
111
- p(path, 0.8);
112
- }
113
- };
114
- const loadClientData = async (url, element, opts) => {
115
- const pagePathname = url.pathname;
116
- const pageSearch = url.search;
117
- const clientDataPath = getClientDataPath(pagePathname, pageSearch, opts?.action);
118
- let qData;
119
- if (!opts?.action) {
120
- qData = CLIENT_DATA_CACHE.get(clientDataPath);
121
- }
122
- if (opts?.prefetchSymbols !== false) {
123
- prefetchSymbols(pagePathname);
124
- }
125
- let resolveFn;
126
- if (!qData) {
127
- const fetchOptions = getFetchOptions(opts?.action, opts?.clearCache);
128
- if (opts?.action) {
129
- opts.action.data = void 0;
130
- }
131
- qData = fetch(clientDataPath, fetchOptions).then((rsp) => {
132
- if (rsp.redirected) {
133
- const redirectedURL = new URL(rsp.url);
134
- const isQData = redirectedURL.pathname.endsWith("/q-data.json");
135
- if (!isQData || redirectedURL.origin !== location.origin) {
136
- location.href = redirectedURL.href;
137
- return;
138
- }
139
- }
140
- if ((rsp.headers.get("content-type") || "").includes("json")) {
141
- return rsp.text().then((text) => {
142
- const [clientData] = _deserialize(text, element);
143
- if (!clientData) {
144
- location.href = url.href;
145
- return;
146
- }
147
- if (opts?.clearCache) {
148
- CLIENT_DATA_CACHE.delete(clientDataPath);
149
- }
150
- if (clientData.redirect) {
151
- location.href = clientData.redirect;
152
- } else if (opts?.action) {
153
- const { action } = opts;
154
- const actionData = clientData.loaders[action.id];
155
- resolveFn = () => {
156
- action.resolve({
157
- status: rsp.status,
158
- result: actionData
159
- });
160
- };
161
- }
162
- return clientData;
163
- });
164
- } else {
165
- if (opts?.isPrefetch !== true) {
166
- location.href = url.href;
167
- }
168
- return void 0;
169
- }
170
- });
171
- if (!opts?.action) {
172
- CLIENT_DATA_CACHE.set(clientDataPath, qData);
173
- }
174
- }
175
- return qData.then((v) => {
176
- if (!v) {
177
- CLIENT_DATA_CACHE.delete(clientDataPath);
178
- }
179
- resolveFn && resolveFn();
180
- return v;
181
- });
182
- };
183
- const getFetchOptions = (action, noCache) => {
184
- const actionData = action?.data;
185
- if (!actionData) {
186
- if (noCache) {
187
- return {
188
- cache: "no-cache",
189
- headers: {
190
- "Cache-Control": "no-cache",
191
- Pragma: "no-cache"
192
- }
193
- };
194
- }
195
- return void 0;
196
- }
197
- if (actionData instanceof FormData) {
198
- return {
199
- method: "POST",
200
- body: actionData
201
- };
202
- } else {
203
- return {
204
- method: "POST",
205
- body: JSON.stringify(actionData),
206
- headers: {
207
- "Content-Type": "application/json, charset=UTF-8"
208
- }
209
- };
20
+ }, "ErrorBoundary_component_useOnWindow_G0jFRpoNY0M", [
21
+ store
22
+ ]));
23
+ if (store.error && props.fallback$) {
24
+ return /* @__PURE__ */ _jsxSorted(Fragment, null, null, props.fallback$(store.error), 1, "bA_0");
210
25
  }
211
- };
212
- const RouteStateContext = /* @__PURE__ */ createContextId("qc-s");
213
- const ContentContext = /* @__PURE__ */ createContextId("qc-c");
214
- const ContentInternalContext = /* @__PURE__ */ createContextId("qc-ic");
215
- const DocumentHeadContext = /* @__PURE__ */ createContextId("qc-h");
216
- const RouteLocationContext = /* @__PURE__ */ createContextId("qc-l");
217
- const RouteNavigateContext = /* @__PURE__ */ createContextId("qc-n");
218
- const RouteActionContext = /* @__PURE__ */ createContextId("qc-a");
219
- const RouteInternalContext = /* @__PURE__ */ createContextId("qc-ir");
220
- const RoutePreventNavigateContext = /* @__PURE__ */ createContextId("qc-p");
221
- const useContent = () => useContext(ContentContext);
222
- const useDocumentHead = () => useContext(DocumentHeadContext);
223
- const useLocation = () => useContext(RouteLocationContext);
224
- const useNavigate = () => useContext(RouteNavigateContext);
225
- const usePreventNavigateQrl = (fn) => {
226
- if (!__EXPERIMENTAL__.preventNavigate) {
227
- throw new Error('usePreventNavigate$ is experimental and must be enabled with `experimental: ["preventNavigate"]` in the `qwikVite` plugin.');
228
- }
229
- const registerPreventNav = useContext(RoutePreventNavigateContext);
230
- useVisibleTask$(() => registerPreventNav(fn));
231
- };
232
- const usePreventNavigate$ = implicit$FirstArg(usePreventNavigateQrl);
233
- const useAction = () => useContext(RouteActionContext);
234
- const useQwikRouterEnv = () => noSerialize(useServerData("qwikrouter"));
235
- const Link = component$((props) => {
26
+ return /* @__PURE__ */ _jsxSorted(Slot, null, null, null, 3, "bA_1");
27
+ }, "ErrorBoundary_component_pOa6vjtC7ik"));
28
+
29
+ const Link = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
236
30
  const nav = useNavigate();
237
31
  const loc = useLocation();
238
32
  const originalHref = props.href;
239
33
  const anchorRef = useSignal();
240
34
  const { onClick$, prefetch: prefetchProp, reload, replaceState, scroll, ...linkProps } = /* @__PURE__ */ (() => props)();
241
- const clientNavPath = untrack(() => getClientNavPath({
35
+ const clientNavPath = untrack(getClientNavPath, {
242
36
  ...linkProps,
243
37
  reload
244
- }, loc));
38
+ }, loc);
245
39
  linkProps.href = clientNavPath || originalHref;
246
- const prefetchData = untrack(() => !!clientNavPath && prefetchProp !== false && prefetchProp !== "js" || void 0);
247
- const prefetch = untrack(() => prefetchData || !!clientNavPath && prefetchProp !== false && shouldPreload(clientNavPath, loc));
248
- const handlePrefetch = prefetch ? $((_, elm) => {
40
+ const prefetchData = !!clientNavPath && prefetchProp !== false && prefetchProp !== "js" || void 0;
41
+ const prefetch = prefetchData || !!clientNavPath && prefetchProp !== false && untrack(shouldPreload, clientNavPath, loc);
42
+ const handlePrefetch = prefetch ? /* @__PURE__ */ inlinedQrl((_, elm) => {
249
43
  if (navigator.connection?.saveData) {
250
44
  return;
251
45
  }
252
46
  if (elm && elm.href) {
253
47
  const url = new URL(elm.href);
254
- prefetchSymbols(url.pathname);
48
+ preloadRouteBundles(url.pathname);
255
49
  if (elm.hasAttribute("data-prefetch")) {
256
- loadClientData(url, elm, {
257
- prefetchSymbols: false,
50
+ loadClientData(url, {
51
+ preloadRouteBundles: false,
258
52
  isPrefetch: true
259
53
  });
260
54
  }
261
55
  }
262
- }) : void 0;
263
- const preventDefault = clientNavPath ? sync$((event, target) => {
56
+ }, "Link_component_handlePrefetch_AGvVXzXKbms") : void 0;
57
+ const preventDefault = clientNavPath ? _qrlSync((event) => {
264
58
  if (!(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)) {
265
59
  event.preventDefault();
266
60
  }
267
- }) : void 0;
268
- const handleClick = clientNavPath ? $(async (event, elm) => {
61
+ }, "event=>{if(!(event.metaKey||event.ctrlKey||event.shiftKey||event.altKey)){event.preventDefault();}}") : void 0;
62
+ const handleClientSideNavigation = clientNavPath ? /* @__PURE__ */ inlinedQrl((event, elm) => {
63
+ const nav2 = _captures[0], reload2 = _captures[1], replaceState2 = _captures[2], scroll2 = _captures[3];
269
64
  if (event.defaultPrevented) {
270
65
  if (elm.href) {
271
66
  elm.setAttribute("aria-pressed", "true");
272
- await nav(elm.href, {
273
- forceReload: reload,
274
- replaceState,
275
- scroll
67
+ nav2(elm.href, {
68
+ forceReload: reload2,
69
+ replaceState: replaceState2,
70
+ scroll: scroll2
71
+ }).then(() => {
72
+ elm.removeAttribute("aria-pressed");
276
73
  });
277
- elm.removeAttribute("aria-pressed");
278
74
  }
279
75
  }
280
- }) : void 0;
281
- useVisibleTask$(({ track }) => {
282
- track(() => loc.url.pathname);
283
- const handler = linkProps.onQVisible$;
76
+ }, "Link_component_handleClientSideNavigation_h3qenoGeI6M", [
77
+ nav,
78
+ reload,
79
+ replaceState,
80
+ scroll
81
+ ]) : void 0;
82
+ const handlePreload = /* @__PURE__ */ inlinedQrl((_, elm) => {
83
+ const url = new URL(elm.href);
84
+ preloadRouteBundles(url.pathname, 1);
85
+ }, "Link_component_handlePreload_AAemwtuBjsE");
86
+ useVisibleTaskQrl(/* @__PURE__ */ inlinedQrl(({ track }) => {
87
+ const anchorRef2 = _captures[0], handlePrefetch2 = _captures[1], linkProps2 = _captures[2], loc2 = _captures[3];
88
+ track(() => loc2.url.pathname);
89
+ const handler = linkProps2.onQVisible$;
284
90
  if (handler) {
285
91
  const event = new CustomEvent("qvisible");
286
92
  if (Array.isArray(handler)) {
287
- handler.flat(10).forEach((handler2) => handler2?.(event, anchorRef.value));
93
+ handler.flat(10).forEach((handler2) => handler2?.(event, anchorRef2.value));
288
94
  } else {
289
- handler?.(event, anchorRef.value);
95
+ handler?.(event, anchorRef2.value);
290
96
  }
291
97
  }
292
- if (!isDev && anchorRef.value) {
293
- handlePrefetch?.(void 0, anchorRef.value);
98
+ if (!isDev && anchorRef2.value) {
99
+ handlePrefetch2?.(void 0, anchorRef2.value);
294
100
  }
295
- });
296
- return /* @__PURE__ */ jsx("a", {
101
+ }, "Link_component_useVisibleTask_xKeuRmnoNSA", [
102
+ anchorRef,
103
+ handlePrefetch,
104
+ linkProps,
105
+ loc
106
+ ]));
107
+ return /* @__PURE__ */ _jsxSplit("a", {
297
108
  ref: anchorRef,
298
109
  "q:link": !!clientNavPath,
299
- ...linkProps,
300
- onClick$: [
110
+ ..._getVarProps(linkProps),
111
+ ..._getConstProps(linkProps),
112
+ "q-e:click": [
301
113
  preventDefault,
114
+ handlePreload,
302
115
  onClick$,
303
- handleClick
116
+ handleClientSideNavigation
304
117
  ],
305
118
  "data-prefetch": prefetchData,
306
- onMouseOver$: [
119
+ "q-e:mouseover": [
307
120
  linkProps.onMouseOver$,
308
121
  handlePrefetch
309
122
  ],
310
- onFocus$: [
123
+ "q-e:focus": [
311
124
  linkProps.onFocus$,
312
125
  handlePrefetch
313
- ],
126
+ ]
127
+ }, {
314
128
  // We need to prevent the onQVisible$ from being called twice since it is handled in the visible task
315
- onQVisible$: [],
316
- children: /* @__PURE__ */ jsx(Slot, {})
317
- });
318
- });
319
- const resolveHead = (endpoint, routeLocation, contentModules, locale) => {
320
- const head = createDocumentHead();
321
- const getData = (loaderOrAction) => {
322
- const id = loaderOrAction.__id;
323
- if (loaderOrAction.__brand === "server_loader") {
324
- if (!(id in endpoint.loaders)) {
325
- throw new Error("You can not get the returned data of a loader that has not been executed for this request.");
326
- }
327
- }
328
- const data = endpoint.loaders[id];
329
- if (isPromise(data)) {
330
- throw new Error("Loaders returning a promise can not be resolved for the head function.");
331
- }
332
- return data;
333
- };
334
- const headProps = {
335
- head,
336
- withLocale: (fn) => withLocale(locale, fn),
337
- resolveValue: getData,
338
- ...routeLocation
339
- };
340
- for (let i = contentModules.length - 1; i >= 0; i--) {
341
- const contentModuleHead = contentModules[i] && contentModules[i].head;
342
- if (contentModuleHead) {
343
- if (typeof contentModuleHead === "function") {
344
- resolveDocumentHead(head, withLocale(locale, () => contentModuleHead(headProps)));
345
- } else if (typeof contentModuleHead === "object") {
346
- resolveDocumentHead(head, contentModuleHead);
347
- }
348
- }
349
- }
350
- return headProps.head;
351
- };
352
- const resolveDocumentHead = (resolvedHead, updatedHead) => {
353
- if (typeof updatedHead.title === "string") {
354
- resolvedHead.title = updatedHead.title;
355
- }
356
- mergeArray(resolvedHead.meta, updatedHead.meta);
357
- mergeArray(resolvedHead.links, updatedHead.links);
358
- mergeArray(resolvedHead.styles, updatedHead.styles);
359
- mergeArray(resolvedHead.scripts, updatedHead.scripts);
360
- Object.assign(resolvedHead.frontmatter, updatedHead.frontmatter);
361
- };
362
- const mergeArray = (existingArr, newArr) => {
363
- if (Array.isArray(newArr)) {
364
- for (const newItem of newArr) {
365
- if (typeof newItem.key === "string") {
366
- const existingIndex = existingArr.findIndex((i) => i.key === newItem.key);
367
- if (existingIndex > -1) {
368
- existingArr[existingIndex] = newItem;
369
- continue;
370
- }
371
- }
372
- existingArr.push(newItem);
373
- }
374
- }
375
- };
376
- const createDocumentHead = () => ({
377
- title: "",
378
- meta: [],
379
- links: [],
380
- styles: [],
381
- scripts: [],
382
- frontmatter: {}
383
- });
384
- function matchRoute(route, path) {
385
- const routeIdx = startIdxSkipSlash(route);
386
- const routeLength = lengthNoTrailingSlash(route);
387
- const pathIdx = startIdxSkipSlash(path);
388
- const pathLength = lengthNoTrailingSlash(path);
389
- return matchRoutePart(route, routeIdx, routeLength, path, pathIdx, pathLength);
390
- }
391
- function matchRoutePart(route, routeIdx, routeLength, path, pathIdx, pathLength) {
392
- let params = null;
393
- while (routeIdx < routeLength) {
394
- const routeCh = route.charCodeAt(routeIdx++);
395
- const pathCh = path.charCodeAt(pathIdx++);
396
- if (routeCh === 91) {
397
- const isMany = isThreeDots(route, routeIdx);
398
- const paramNameStart = routeIdx + (isMany ? 3 : 0);
399
- const paramNameEnd = scan(route, paramNameStart, routeLength, 93);
400
- const paramName = route.substring(paramNameStart, paramNameEnd);
401
- const paramSuffixEnd = scan(route, paramNameEnd + 1, routeLength, 47);
402
- const suffix = route.substring(paramNameEnd + 1, paramSuffixEnd);
403
- routeIdx = paramNameEnd + 1;
404
- const paramValueStart = pathIdx - 1;
405
- if (isMany) {
406
- const match = recursiveScan(paramName, suffix, path, paramValueStart, pathLength, route, routeIdx + suffix.length + 1, routeLength);
407
- if (match) {
408
- return Object.assign(params || (params = {}), match);
409
- }
410
- }
411
- const paramValueEnd = scan(path, paramValueStart, pathLength, 47, suffix);
412
- if (paramValueEnd == -1) {
413
- return null;
414
- }
415
- const paramValue = path.substring(paramValueStart, paramValueEnd);
416
- if (!isMany && !suffix && !paramValue) {
417
- return null;
418
- }
419
- pathIdx = paramValueEnd;
420
- (params || (params = {}))[paramName] = decodeURIComponent(paramValue);
421
- } else if (routeCh !== pathCh) {
422
- if (!(isNaN(pathCh) && isRestParameter(route, routeIdx))) {
423
- return null;
424
- }
425
- }
426
- }
427
- if (allConsumed(route, routeIdx) && allConsumed(path, pathIdx)) {
428
- return params || {};
429
- } else {
430
- return null;
431
- }
432
- }
433
- function isRestParameter(text, idx) {
434
- return text.charCodeAt(idx) === 91 && isThreeDots(text, idx + 1);
435
- }
436
- function lengthNoTrailingSlash(text) {
437
- const length = text.length;
438
- return length > 1 && text.charCodeAt(length - 1) === 47 ? length - 1 : length;
439
- }
440
- function allConsumed(text, idx) {
441
- const length = text.length;
442
- return idx >= length || idx == length - 1 && text.charCodeAt(idx) === 47;
443
- }
444
- function startIdxSkipSlash(text) {
445
- return text.charCodeAt(0) === 47 ? 1 : 0;
446
- }
447
- function isThreeDots(text, idx) {
448
- return text.charCodeAt(idx) === 46 && text.charCodeAt(idx + 1) === 46 && text.charCodeAt(idx + 2) === 46;
449
- }
450
- function scan(text, idx, end, ch, suffix = "") {
451
- while (idx < end && text.charCodeAt(idx) !== ch) {
452
- idx++;
453
- }
454
- const suffixLength = suffix.length;
455
- for (let i = 0; i < suffixLength; i++) {
456
- if (text.charCodeAt(idx - suffixLength + i) !== suffix.charCodeAt(i)) {
457
- return -1;
458
- }
459
- }
460
- return idx - suffixLength;
461
- }
462
- function recursiveScan(paramName, suffix, path, pathStart, pathLength, route, routeStart, routeLength) {
463
- if (path.charCodeAt(pathStart) === 47) {
464
- pathStart++;
465
- }
466
- let pathIdx = pathLength;
467
- const sep = suffix + "/";
468
- while (pathIdx >= pathStart) {
469
- const match = matchRoutePart(route, routeStart, routeLength, path, pathIdx, pathLength);
470
- if (match) {
471
- let value = path.substring(pathStart, Math.min(pathIdx, pathLength));
472
- if (value.endsWith(sep)) {
473
- value = value.substring(0, value.length - sep.length);
474
- }
475
- match[paramName] = decodeURIComponent(value);
476
- return match;
477
- }
478
- const newPathIdx = lastIndexOf(path, pathStart, sep, pathIdx, pathStart - 1) + sep.length;
479
- if (pathIdx === newPathIdx) {
480
- break;
481
- }
482
- pathIdx = newPathIdx;
483
- }
484
- return null;
485
- }
486
- function lastIndexOf(text, start, match, searchIdx, notFoundIdx) {
487
- let idx = text.lastIndexOf(match, searchIdx);
488
- if (idx == searchIdx - match.length) {
489
- idx = text.lastIndexOf(match, searchIdx - match.length - 1);
490
- }
491
- return idx > start ? idx : notFoundIdx;
492
- }
493
- const loadRoute = async (routes, menus, cacheModules, pathname) => {
494
- if (!Array.isArray(routes)) {
495
- return null;
496
- }
497
- for (const routeData of routes) {
498
- const routeName = routeData[0];
499
- const params = matchRoute(routeName, pathname);
500
- if (!params) {
501
- continue;
502
- }
503
- const loaders = routeData[1];
504
- const routeBundleNames = routeData[3];
505
- const modules = new Array(loaders.length);
506
- const pendingLoads = [];
507
- loaders.forEach((moduleLoader, i) => {
508
- loadModule(moduleLoader, pendingLoads, (routeModule) => modules[i] = routeModule, cacheModules);
509
- });
510
- const menuLoader = getMenuLoader(menus, pathname);
511
- let menu = void 0;
512
- loadModule(menuLoader, pendingLoads, (menuModule) => menu = menuModule?.default, cacheModules);
513
- if (pendingLoads.length > 0) {
514
- await Promise.all(pendingLoads);
515
- }
516
- return [
517
- routeName,
518
- params,
519
- modules,
520
- deepFreeze(menu),
521
- routeBundleNames
522
- ];
523
- }
524
- return null;
525
- };
526
- const loadModule = (moduleLoader, pendingLoads, moduleSetter, cacheModules) => {
527
- if (typeof moduleLoader === "function") {
528
- const loadedModule = MODULE_CACHE.get(moduleLoader);
529
- if (loadedModule) {
530
- moduleSetter(loadedModule);
531
- } else {
532
- const moduleOrPromise = moduleLoader();
533
- if (typeof moduleOrPromise.then === "function") {
534
- pendingLoads.push(moduleOrPromise.then((loadedModule2) => {
535
- if (cacheModules !== false) {
536
- MODULE_CACHE.set(moduleLoader, loadedModule2);
537
- }
538
- moduleSetter(loadedModule2);
539
- }));
540
- } else if (moduleOrPromise) {
541
- moduleSetter(moduleOrPromise);
542
- }
543
- }
544
- }
545
- };
546
- const getMenuLoader = (menus, pathname) => {
547
- if (menus) {
548
- pathname = pathname.endsWith("/") ? pathname : pathname + "/";
549
- const menu = menus.find((m) => m[0] === pathname || pathname.startsWith(m[0] + (pathname.endsWith("/") ? "" : "/")));
550
- if (menu) {
551
- return menu[1];
552
- }
553
- }
554
- };
129
+ "q-e:qvisible": []
130
+ }, /* @__PURE__ */ _jsxSorted(Slot, null, null, null, 3, "jO_0"), 0, "jO_1");
131
+ }, "Link_component_VPmar9tb3t4"));
132
+
133
+ const transitionCss = "@layer qwik{@supports selector(html:active-view-transition-type(type)){html:active-view-transition-type(qwik-navigation){:root{view-transition-name:none}}}@supports not selector(html:active-view-transition-type(type)){:root{view-transition-name:none}}}";
134
+
555
135
  function callRestoreScrollOnDocument() {
556
136
  if (document.__q_scroll_restore__) {
557
137
  document.__q_scroll_restore__();
558
138
  document.__q_scroll_restore__ = void 0;
559
139
  }
560
140
  }
561
- const restoreScroll = (type, toUrl2, fromUrl, scroller, scrollState) => {
562
- if (type === "popstate" && scrollState) {
563
- scroller.scrollTo(scrollState.x, scrollState.y);
564
- } else if (type === "link" || type === "form") {
565
- if (!hashScroll(toUrl2, fromUrl)) {
566
- scroller.scrollTo(0, 0);
567
- }
568
- }
569
- };
570
- const hashScroll = (toUrl2, fromUrl) => {
571
- const elmId = toUrl2.hash.slice(1);
141
+ const hashScroll = (toUrl, fromUrl) => {
142
+ const elmId = toUrl.hash.slice(1);
572
143
  const elm = elmId && document.getElementById(elmId);
573
144
  if (elm) {
574
145
  elm.scrollIntoView();
575
146
  return true;
576
- } else if (!elm && toUrl2.hash && isSamePath(toUrl2, fromUrl)) {
147
+ } else if (!elm && toUrl.hash && isSamePath(toUrl, fromUrl)) {
577
148
  return true;
578
149
  }
579
150
  return false;
580
151
  };
152
+ const restoreScroll = (type, toUrl, fromUrl, scroller, scrollState) => {
153
+ if (type === "popstate" && scrollState) {
154
+ scroller.scrollTo(scrollState.x, scrollState.y);
155
+ } else if (type === "link" || type === "form") {
156
+ if (!hashScroll(toUrl, fromUrl)) {
157
+ scroller.scrollTo(0, 0);
158
+ }
159
+ }
160
+ };
581
161
  const currentScrollState = (elm) => {
582
162
  return {
583
163
  x: elm.scrollLeft,
@@ -595,25 +175,16 @@ const saveScrollHistory = (scrollState) => {
595
175
  state._qRouterScroll = scrollState;
596
176
  history.replaceState(state, "");
597
177
  };
598
- const spaInit = event$((_, el) => {
599
- const win = window;
600
- const spa = "_qRouterSPA";
601
- const initPopstate = "_qRouterInitPopstate";
602
- const initAnchors = "_qRouterInitAnchors";
603
- const initVisibility = "_qRouterInitVisibility";
604
- const initScroll = "_qRouterInitScroll";
605
- if (!win[spa] && !win[initPopstate] && !win[initAnchors] && !win[initVisibility] && !win[initScroll]) {
178
+
179
+ const spaInit = eventQrl(/* @__PURE__ */ inlinedQrl((_, el) => {
180
+ if (!window._qRouterSPA && !window._qRouterInitPopstate) {
606
181
  const currentPath = location.pathname + location.search;
607
- const historyPatch = "_qRouterHistoryPatch";
608
- const scrollEnabled = "_qRouterScrollEnabled";
609
- const debounceTimeout = "_qRouterScrollDebounce";
610
- const scrollHistory = "_qRouterScroll";
611
182
  const checkAndScroll = (scrollState) => {
612
183
  if (scrollState) {
613
- win.scrollTo(scrollState.x, scrollState.y);
184
+ window.scrollTo(scrollState.x, scrollState.y);
614
185
  }
615
186
  };
616
- const currentScrollState2 = () => {
187
+ const currentScrollState = () => {
617
188
  const elm = document.documentElement;
618
189
  return {
619
190
  x: elm.scrollLeft,
@@ -624,23 +195,23 @@ const spaInit = event$((_, el) => {
624
195
  };
625
196
  const saveScrollState = (scrollState) => {
626
197
  const state = history.state || {};
627
- state[scrollHistory] = scrollState || currentScrollState2();
198
+ state._qRouterScroll = scrollState || currentScrollState();
628
199
  history.replaceState(state, "");
629
200
  };
630
201
  saveScrollState();
631
- win[initPopstate] = () => {
632
- if (win[spa]) {
202
+ window._qRouterInitPopstate = () => {
203
+ if (window._qRouterSPA) {
633
204
  return;
634
205
  }
635
- win[scrollEnabled] = false;
636
- clearTimeout(win[debounceTimeout]);
206
+ window._qRouterScrollEnabled = false;
207
+ clearTimeout(window._qRouterScrollDebounce);
637
208
  if (currentPath !== location.pathname + location.search) {
638
209
  const getContainer = (el2) => el2.closest("[q\\:container]:not([q\\:container=html]):not([q\\:container=text])");
639
210
  const container = getContainer(el);
640
211
  const domContainer = container.qContainer;
641
212
  const hostElement = domContainer.vNodeLocate(el);
642
213
  const nav = domContainer?.resolveContext(hostElement, {
643
- id: "qc--n"
214
+ id: "qr-n"
644
215
  });
645
216
  if (nav) {
646
217
  nav(location.href, {
@@ -651,14 +222,14 @@ const spaInit = event$((_, el) => {
651
222
  }
652
223
  } else {
653
224
  if (history.scrollRestoration === "manual") {
654
- const scrollState = history.state?.[scrollHistory];
225
+ const scrollState = history.state?._qRouterScroll;
655
226
  checkAndScroll(scrollState);
656
- win[scrollEnabled] = true;
227
+ window._qRouterScrollEnabled = true;
657
228
  }
658
229
  }
659
230
  };
660
- if (!win[historyPatch]) {
661
- win[historyPatch] = true;
231
+ if (!window._qRouterHistoryPatch) {
232
+ window._qRouterHistoryPatch = true;
662
233
  const pushState = history.pushState;
663
234
  const replaceState = history.replaceState;
664
235
  const prepareState = (state) => {
@@ -672,7 +243,7 @@ const spaInit = event$((_, el) => {
672
243
  console.warn("In a Qwik SPA context, `history.state` is used to store scroll state. Direct calls to `pushState()` and `replaceState()` must supply an actual Object type. We need to be able to automatically attach the scroll state to your state object. A new state object has been created, your data has been moved to: `history.state._data`");
673
244
  }
674
245
  }
675
- state._qRouterScroll = state._qRouterScroll || currentScrollState2();
246
+ state._qRouterScroll = state._qRouterScroll || currentScrollState();
676
247
  return state;
677
248
  };
678
249
  history.pushState = (state, title, url) => {
@@ -684,8 +255,8 @@ const spaInit = event$((_, el) => {
684
255
  return replaceState.call(history, state, title, url);
685
256
  };
686
257
  }
687
- win[initAnchors] = (event) => {
688
- if (win[spa] || event.defaultPrevented) {
258
+ window._qRouterInitAnchors = (event) => {
259
+ if (window._qRouterSPA || event.defaultPrevented) {
689
260
  return;
690
261
  }
691
262
  const target = event.target.closest("a[href]");
@@ -704,10 +275,10 @@ const spaInit = event$((_, el) => {
704
275
  if (dest.href.endsWith("#")) {
705
276
  window.scrollTo(0, 0);
706
277
  } else {
707
- win[scrollEnabled] = false;
708
- clearTimeout(win[debounceTimeout]);
278
+ window._qRouterScrollEnabled = false;
279
+ clearTimeout(window._qRouterScrollDebounce);
709
280
  saveScrollState({
710
- ...currentScrollState2(),
281
+ ...currentScrollState(),
711
282
  x: 0,
712
283
  y: 0
713
284
  });
@@ -723,36 +294,37 @@ const spaInit = event$((_, el) => {
723
294
  }
724
295
  }
725
296
  };
726
- win[initVisibility] = () => {
727
- if (!win[spa] && win[scrollEnabled] && document.visibilityState === "hidden") {
297
+ window._qRouterInitVisibility = () => {
298
+ if (!window._qRouterSPA && window._qRouterScrollEnabled && document.visibilityState === "hidden") {
728
299
  saveScrollState();
729
300
  }
730
301
  };
731
- win[initScroll] = () => {
732
- if (win[spa] || !win[scrollEnabled]) {
302
+ window._qRouterInitScroll = () => {
303
+ if (window._qRouterSPA || !window._qRouterScrollEnabled) {
733
304
  return;
734
305
  }
735
- clearTimeout(win[debounceTimeout]);
736
- win[debounceTimeout] = setTimeout(() => {
306
+ clearTimeout(window._qRouterScrollDebounce);
307
+ window._qRouterScrollDebounce = setTimeout(() => {
737
308
  saveScrollState();
738
- win[debounceTimeout] = void 0;
309
+ window._qRouterScrollDebounce = void 0;
739
310
  }, 200);
740
311
  };
741
- win[scrollEnabled] = true;
312
+ window._qRouterScrollEnabled = true;
742
313
  setTimeout(() => {
743
- addEventListener("popstate", win[initPopstate]);
744
- addEventListener("scroll", win[initScroll], {
314
+ window.addEventListener("popstate", window._qRouterInitPopstate);
315
+ window.addEventListener("scroll", window._qRouterInitScroll, {
745
316
  passive: true
746
317
  });
747
- document.body.addEventListener("click", win[initAnchors]);
748
- if (!win.navigation) {
749
- document.addEventListener("visibilitychange", win[initVisibility], {
318
+ document.addEventListener("click", window._qRouterInitAnchors);
319
+ if (!window.navigation) {
320
+ document.addEventListener("visibilitychange", window._qRouterInitVisibility, {
750
321
  passive: true
751
322
  });
752
323
  }
753
324
  }, 0);
754
325
  }
755
- });
326
+ }, "spa_init_event_igI1pUsax0E"));
327
+
756
328
  const startViewTransition = (params) => {
757
329
  if (!params.update) {
758
330
  return;
@@ -773,25 +345,18 @@ const startViewTransition = (params) => {
773
345
  params.update?.();
774
346
  }
775
347
  };
348
+
776
349
  const QWIK_CITY_SCROLLER = "_qCityScroller";
777
350
  const QWIK_ROUTER_SCROLLER = "_qRouterScroller";
778
351
  const preventNav = {};
779
352
  const internalState = {
780
353
  navCount: 0
781
354
  };
782
- const QwikRouterProvider = component$((props) => {
783
- useStyles$(`
784
- @layer qwik {
785
- @supports selector(html:active-view-transition-type(type)) {
786
- html:active-view-transition-type(qwik-router-spa) {
787
- :root{view-transition-name:none}
788
- }
789
- }
790
- @supports not selector(html:active-view-transition-type(type)) {
791
- :root{view-transition-name:none}
792
- }
793
- }
794
- `);
355
+ const useQwikRouter = (props) => {
356
+ if (!isServer) {
357
+ throw new Error("useQwikRouter can only run during SSR on the server. If you are seeing this, it means you are re-rendering the root of your application. Fix that or use the <QwikRouterProvider> component around the root of your application.");
358
+ }
359
+ useStylesQrl(/* @__PURE__ */ inlinedQrl(transitionCss, "qwik_view_transition_css_inline_vNfd9raIMI0"));
795
360
  const env = useQwikRouterEnv();
796
361
  if (!env?.params) {
797
362
  throw new Error(`Missing Qwik Router Env Data for help visit https://github.com/QwikDev/qwik/issues/6237`);
@@ -800,37 +365,54 @@ const QwikRouterProvider = component$((props) => {
800
365
  if (!urlEnv) {
801
366
  throw new Error(`Missing Qwik URL Env Data`);
802
367
  }
803
- if (isServer) {
804
- if (env.ev.originalUrl.pathname !== env.ev.url.pathname && !__EXPERIMENTAL__.enableRequestRewrite) {
805
- throw new Error(`enableRequestRewrite is an experimental feature and is not enabled. Please enable the feature flag by adding \`experimental: ["enableRequestRewrite"]\` to your qwikVite plugin options.`);
806
- }
368
+ const serverHead = useServerData("documentHead");
369
+ const manifestHash = useServerData("containerAttributes")?.["q:manifest-hash"];
370
+ if (env.ev.originalUrl.pathname !== env.ev.url.pathname && !__EXPERIMENTAL__.enableRequestRewrite) {
371
+ throw new Error(`enableRequestRewrite is an experimental feature and is not enabled. Please enable the feature flag by adding \`experimental: ["enableRequestRewrite"]\` to your qwikVite plugin options.`);
807
372
  }
808
373
  const url = new URL(urlEnv);
809
- const routeLocation = useStore({
374
+ const routeLocationTarget = {
810
375
  url,
811
376
  params: env.params,
812
377
  isNavigating: false,
813
378
  prevUrl: void 0
814
- }, {
379
+ };
380
+ const routeLocation = useStore(routeLocationTarget, {
815
381
  deep: false
816
382
  });
817
383
  const navResolver = {};
818
- const loaderState = _weakSerialize(useStore(env.response.loaders, {
819
- deep: false
820
- }));
384
+ const container = _getContextContainer();
385
+ const getSerializationStrategy = (loaderId) => {
386
+ return env.response.loadersSerializationStrategy.get(loaderId) || DEFAULT_LOADERS_SERIALIZATION_STRATEGY;
387
+ };
388
+ const loadersObject = {};
389
+ const loaderState = {};
390
+ for (const [key, value] of Object.entries(env.response.loaders)) {
391
+ loadersObject[key] = value;
392
+ loaderState[key] = createLoaderSignal(loadersObject, key, url, getSerializationStrategy(key), container);
393
+ }
394
+ loadersObject[SerializerSymbol] = (obj) => {
395
+ const loadersSerializationObject = {};
396
+ for (const [k, v] of Object.entries(obj)) {
397
+ loadersSerializationObject[k] = getSerializationStrategy(k) === "always" ? v : _UNINITIALIZED;
398
+ }
399
+ return loadersSerializationObject;
400
+ };
821
401
  const routeInternal = useSignal({
822
402
  type: "initial",
823
403
  dest: url,
824
- forceReload: false,
825
- replaceState: false,
826
404
  scroll: true
827
405
  });
828
- const documentHead = useStore(createDocumentHead);
406
+ const documentHead = useStore(() => createDocumentHead(serverHead, manifestHash));
829
407
  const content = useStore({
830
408
  headings: void 0,
831
409
  menu: void 0
832
410
  });
833
411
  const contentInternal = useSignal();
412
+ const httpStatus = useSignal({
413
+ status: env.response.status,
414
+ message: env.loadedRoute.$notFound$ ? "Not Found" : env.response.statusMessage ?? ""
415
+ });
834
416
  const currentActionId = env.response.action;
835
417
  const currentAction = currentActionId ? env.response.loaders[currentActionId] : void 0;
836
418
  const actionState = useSignal(currentAction ? {
@@ -841,11 +423,11 @@ const QwikRouterProvider = component$((props) => {
841
423
  status: env.response.status
842
424
  }
843
425
  } : void 0);
844
- const registerPreventNav = $((fn$) => {
426
+ const registerPreventNav = /* @__PURE__ */ inlinedQrl((fn$) => {
845
427
  if (!isBrowser) {
846
428
  return;
847
429
  }
848
- preventNav.$handler$ || (preventNav.$handler$ = (event) => {
430
+ preventNav.$handler$ ||= (event) => {
849
431
  internalState.navCount++;
850
432
  if (!preventNav.$cbs$) {
851
433
  return;
@@ -857,8 +439,8 @@ const QwikRouterProvider = component$((props) => {
857
439
  event.preventDefault();
858
440
  event.returnValue = true;
859
441
  }
860
- });
861
- (preventNav.$cbs$ || (preventNav.$cbs$ = /* @__PURE__ */ new Set())).add(fn$);
442
+ };
443
+ (preventNav.$cbs$ ||= /* @__PURE__ */ new Set()).add(fn$);
862
444
  fn$.resolve();
863
445
  window.addEventListener("beforeunload", preventNav.$handler$);
864
446
  return () => {
@@ -870,14 +452,30 @@ const QwikRouterProvider = component$((props) => {
870
452
  }
871
453
  }
872
454
  };
873
- });
874
- const goto = $(async (path, opt) => {
455
+ }, "useQwikRouter_registerPreventNav_69B0DK0eZJc");
456
+ const getScroller = /* @__PURE__ */ inlinedQrl(() => {
457
+ let scroller = document.getElementById(QWIK_ROUTER_SCROLLER);
458
+ if (!scroller) {
459
+ scroller = document.getElementById(QWIK_CITY_SCROLLER);
460
+ if (scroller && isDev) {
461
+ console.warn(`Please update your scroller ID to "${QWIK_ROUTER_SCROLLER}" as "${QWIK_CITY_SCROLLER}" is deprecated and will be removed in V3`);
462
+ }
463
+ }
464
+ return scroller ?? document.documentElement;
465
+ }, "useQwikRouter_getScroller_0UhDFwlxeFQ");
466
+ const goto = /* @__PURE__ */ inlinedQrl(async (path, opt) => {
467
+ const actionState2 = _captures[0], getScroller2 = _captures[1], navResolver2 = _captures[2], routeInternal2 = _captures[3], routeLocation2 = _captures[4];
875
468
  const { type = "link", forceReload = path === void 0, replaceState = false, scroll = true } = typeof opt === "object" ? opt : {
876
469
  forceReload: opt
877
470
  };
878
471
  internalState.navCount++;
879
- const lastDest = routeInternal.value.dest;
880
- const dest = path === void 0 ? lastDest : typeof path === "number" ? path : toUrl(path, routeLocation.url);
472
+ if (isBrowser && type === "link" && routeInternal2.value.type === "initial") {
473
+ const url2 = new URL(window.location.href);
474
+ routeInternal2.value.dest = url2;
475
+ routeLocation2.url = url2;
476
+ }
477
+ const lastDest = routeInternal2.value.dest;
478
+ const dest = path === void 0 ? lastDest : typeof path === "number" ? path : toUrl(path, routeLocation2.url);
881
479
  if (preventNav.$cbs$ && (forceReload || typeof dest === "number" || !isSamePath(dest, lastDest) || !isSameOrigin(dest, lastDest))) {
882
480
  const ourNavId = internalState.navCount;
883
481
  const prevents = await Promise.all([
@@ -907,84 +505,95 @@ const QwikRouterProvider = component$((props) => {
907
505
  if (type === "link" && dest.href !== location.href) {
908
506
  history.pushState(null, "", dest);
909
507
  }
910
- let scroller = document.getElementById(QWIK_ROUTER_SCROLLER);
911
- if (!scroller) {
912
- scroller = document.getElementById(QWIK_CITY_SCROLLER);
913
- if (scroller) {
914
- console.warn(`Please update your scroller ID to "${QWIK_ROUTER_SCROLLER}" as "${QWIK_CITY_SCROLLER}" is deprecated and will be removed in V3`);
915
- }
916
- }
917
- if (!scroller) {
918
- scroller = document.documentElement;
919
- }
508
+ const scroller = await getScroller2();
920
509
  restoreScroll(type, dest, new URL(location.href), scroller, getScrollHistory());
921
510
  if (type === "popstate") {
922
511
  window._qRouterScrollEnabled = true;
923
512
  }
924
513
  }
514
+ if (dest.href !== routeLocation2.url.href) {
515
+ const newUrl = new URL(dest.href);
516
+ routeInternal2.value.dest = newUrl;
517
+ routeLocation2.url = newUrl;
518
+ }
925
519
  return;
926
520
  }
927
- routeInternal.value = {
521
+ let historyUpdated = false;
522
+ if (isBrowser && type === "link" && !forceReload) {
523
+ const scroller = await getScroller2();
524
+ window._qRouterScrollEnabled = false;
525
+ clearTimeout(window._qRouterScrollDebounce);
526
+ const scrollState = currentScrollState(scroller);
527
+ saveScrollHistory(scrollState);
528
+ clientNavigate(window, type, new URL(location.href), dest, replaceState);
529
+ historyUpdated = true;
530
+ }
531
+ routeInternal2.value = {
928
532
  type,
929
533
  dest,
930
534
  forceReload,
931
535
  replaceState,
932
- scroll
536
+ scroll,
537
+ historyUpdated
933
538
  };
934
539
  if (isBrowser) {
935
- loadClientData(dest, _getContextElement());
936
- loadRoute(qwikRouterConfig.routes, qwikRouterConfig.menus, qwikRouterConfig.cacheModules, dest.pathname);
540
+ loadClientData(dest);
541
+ loadRoute(qwikRouterConfig.routes, qwikRouterConfig.cacheModules, dest.pathname);
937
542
  }
938
- actionState.value = void 0;
939
- routeLocation.isNavigating = true;
543
+ actionState2.value = void 0;
544
+ routeLocation2.isNavigating = true;
940
545
  return new Promise((resolve) => {
941
- navResolver.r = resolve;
546
+ navResolver2.r = resolve;
942
547
  });
943
- });
548
+ }, "useQwikRouter_goto_8j8Vrz2yUIM", [
549
+ actionState,
550
+ getScroller,
551
+ navResolver,
552
+ routeInternal,
553
+ routeLocation
554
+ ]);
944
555
  useContextProvider(ContentContext, content);
945
556
  useContextProvider(ContentInternalContext, contentInternal);
946
557
  useContextProvider(DocumentHeadContext, documentHead);
558
+ useContextProvider(HttpStatusContext, httpStatus);
947
559
  useContextProvider(RouteLocationContext, routeLocation);
948
560
  useContextProvider(RouteNavigateContext, goto);
949
561
  useContextProvider(RouteStateContext, loaderState);
950
562
  useContextProvider(RouteActionContext, actionState);
951
- useContextProvider(RouteInternalContext, routeInternal);
952
563
  useContextProvider(RoutePreventNavigateContext, registerPreventNav);
953
- useTask$(({ track }) => {
954
- async function run() {
955
- const [navigation, action] = track(() => [
956
- routeInternal.value,
957
- actionState.value
958
- ]);
564
+ useTaskQrl(
565
+ /* @__PURE__ */ inlinedQrl(async ({ track }) => {
566
+ const actionState2 = _captures[0], content2 = _captures[1], contentInternal2 = _captures[2], documentHead2 = _captures[3], env2 = _captures[4], getScroller2 = _captures[5], goto2 = _captures[6], httpStatus2 = _captures[7], loaderState2 = _captures[8], loadersObject2 = _captures[9], navResolver2 = _captures[10], props2 = _captures[11], routeInternal2 = _captures[12], routeLocation2 = _captures[13], routeLocationTarget2 = _captures[14], serverHead2 = _captures[15];
567
+ const container2 = _getContextContainer();
568
+ const navigation = track(routeInternal2);
569
+ const action = track(actionState2);
959
570
  const locale = getLocale("");
960
- const prevUrl = routeLocation.url;
571
+ const prevUrl = routeLocation2.url;
961
572
  const navType = action ? "form" : navigation.type;
962
573
  const replaceState = navigation.replaceState;
963
574
  let trackUrl;
964
575
  let clientPageData;
965
- let loadedRoute = null;
966
- let elm;
576
+ let loadedRoute;
967
577
  if (isServer) {
968
- trackUrl = new URL(navigation.dest, routeLocation.url);
969
- loadedRoute = env.loadedRoute;
970
- clientPageData = env.response;
578
+ trackUrl = new URL(navigation.dest, routeLocation2.url);
579
+ loadedRoute = env2.loadedRoute;
580
+ clientPageData = env2.response;
971
581
  } else {
972
582
  trackUrl = new URL(navigation.dest, location);
973
583
  if (trackUrl.pathname.endsWith("/")) {
974
- if (!qwikRouterConfig.trailingSlash) {
584
+ if (globalThis.__NO_TRAILING_SLASH__) {
975
585
  trackUrl.pathname = trackUrl.pathname.slice(0, -1);
976
586
  }
977
- } else if (qwikRouterConfig.trailingSlash) {
587
+ } else if (!globalThis.__NO_TRAILING_SLASH__) {
978
588
  trackUrl.pathname += "/";
979
589
  }
980
- let loadRoutePromise = loadRoute(qwikRouterConfig.routes, qwikRouterConfig.menus, qwikRouterConfig.cacheModules, trackUrl.pathname);
981
- elm = _getContextElement();
982
- const pageData = clientPageData = await loadClientData(trackUrl, elm, {
590
+ let loadRoutePromise = loadRoute(qwikRouterConfig.routes, qwikRouterConfig.cacheModules, trackUrl.pathname);
591
+ const pageData = clientPageData = await loadClientData(trackUrl, {
983
592
  action,
984
593
  clearCache: true
985
594
  });
986
595
  if (!pageData) {
987
- routeInternal.untrackedValue = {
596
+ routeInternal2.untrackedValue = {
988
597
  type: navType,
989
598
  dest: trackUrl
990
599
  };
@@ -998,7 +607,6 @@ const QwikRouterProvider = component$((props) => {
998
607
  }
999
608
  loadRoutePromise = loadRoute(
1000
609
  qwikRouterConfig.routes,
1001
- qwikRouterConfig.menus,
1002
610
  qwikRouterConfig.cacheModules,
1003
611
  newURL.pathname
1004
612
  // Load the actual required path.
@@ -1012,203 +620,274 @@ const QwikRouterProvider = component$((props) => {
1012
620
  return;
1013
621
  }
1014
622
  }
1015
- if (loadedRoute) {
1016
- const [routeName, params, mods, menu] = loadedRoute;
1017
- const contentModules = mods;
1018
- const pageModule = contentModules[contentModules.length - 1];
1019
- const isRedirect = navType === "form" && !isSamePath(trackUrl, prevUrl);
1020
- if (navigation.dest.search && !isRedirect) {
1021
- trackUrl.search = navigation.dest.search;
1022
- }
1023
- if (!isSamePath(trackUrl, prevUrl)) {
1024
- routeLocation.prevUrl = prevUrl;
1025
- }
1026
- routeLocation.url = trackUrl;
1027
- routeLocation.params = {
1028
- ...params
623
+ const { $routeName$, $params$, $mods$, $menu$, $notFound$ } = loadedRoute;
624
+ const contentModules = $mods$;
625
+ if ($notFound$) {
626
+ httpStatus2.value = {
627
+ status: 404,
628
+ message: "Not Found"
1029
629
  };
1030
- routeInternal.untrackedValue = {
1031
- type: navType,
1032
- dest: trackUrl
630
+ } else {
631
+ httpStatus2.value = {
632
+ status: clientPageData?.status ?? 200,
633
+ message: clientPageData?.statusMessage ?? ""
1033
634
  };
1034
- const resolvedHead = resolveHead(clientPageData, routeLocation, contentModules, locale);
1035
- content.headings = pageModule.headings;
1036
- content.menu = menu;
1037
- contentInternal.value = noSerialize(contentModules);
1038
- documentHead.links = resolvedHead.links;
1039
- documentHead.meta = resolvedHead.meta;
1040
- documentHead.styles = resolvedHead.styles;
1041
- documentHead.scripts = resolvedHead.scripts;
1042
- documentHead.title = resolvedHead.title;
1043
- documentHead.frontmatter = resolvedHead.frontmatter;
1044
- if (isBrowser) {
1045
- let scrollState;
1046
- if (navType === "popstate") {
1047
- scrollState = getScrollHistory();
1048
- }
1049
- const scroller = document.getElementById(QWIK_ROUTER_SCROLLER) ?? document.documentElement;
1050
- if (navigation.scroll && (!navigation.forceReload || !isSamePath(trackUrl, prevUrl)) && (navType === "link" || navType === "popstate") || isRedirect) {
1051
- document.__q_scroll_restore__ = () => restoreScroll(navType, trackUrl, prevUrl, scroller, scrollState);
1052
- }
1053
- const loaders = clientPageData?.loaders;
1054
- const win = window;
1055
- if (loaders) {
1056
- Object.assign(loaderState, loaders);
635
+ }
636
+ const pageModule = contentModules[contentModules.length - 1];
637
+ if (navigation.dest.search && !!isSamePath(trackUrl, prevUrl)) {
638
+ trackUrl.search = navigation.dest.search;
639
+ }
640
+ let shouldForcePrevUrl = false;
641
+ let shouldForceUrl = false;
642
+ let shouldForceParams = false;
643
+ if (!isSamePath(trackUrl, prevUrl)) {
644
+ if (_hasStoreEffects(routeLocation2, "prevUrl")) {
645
+ shouldForcePrevUrl = true;
646
+ }
647
+ routeLocationTarget2.prevUrl = prevUrl;
648
+ }
649
+ if (routeLocationTarget2.url !== trackUrl) {
650
+ if (_hasStoreEffects(routeLocation2, "url")) {
651
+ shouldForceUrl = true;
652
+ }
653
+ routeLocationTarget2.url = trackUrl;
654
+ }
655
+ if (routeLocationTarget2.params !== $params$) {
656
+ if (_hasStoreEffects(routeLocation2, "params")) {
657
+ shouldForceParams = true;
658
+ }
659
+ routeLocationTarget2.params = $params$;
660
+ }
661
+ routeInternal2.untrackedValue = {
662
+ type: navType,
663
+ dest: trackUrl
664
+ };
665
+ const resolvedHead = resolveHead(clientPageData, routeLocation2, contentModules, locale, serverHead2);
666
+ content2.headings = pageModule.headings;
667
+ content2.menu = $menu$;
668
+ contentInternal2.untrackedValue = noSerialize(contentModules);
669
+ documentHead2.links = resolvedHead.links;
670
+ documentHead2.meta = resolvedHead.meta;
671
+ documentHead2.styles = resolvedHead.styles;
672
+ documentHead2.scripts = resolvedHead.scripts;
673
+ documentHead2.title = resolvedHead.title;
674
+ documentHead2.frontmatter = resolvedHead.frontmatter;
675
+ if (isBrowser) {
676
+ let scrollState;
677
+ if (navType === "popstate") {
678
+ scrollState = getScrollHistory();
679
+ }
680
+ const scroller = await getScroller2();
681
+ if (navigation.scroll && (!navigation.forceReload || !isSamePath(trackUrl, prevUrl)) && (navType === "link" || navType === "popstate") || navType === "form" && !isSamePath(trackUrl, prevUrl)) {
682
+ document.__q_scroll_restore__ = () => restoreScroll(navType, trackUrl, prevUrl, scroller, scrollState);
683
+ }
684
+ const loaders = clientPageData?.loaders;
685
+ if (loaders) {
686
+ for (const [key, value] of Object.entries(loaders)) {
687
+ const signal = loaderState2[key];
688
+ const awaitedValue = await value;
689
+ loadersObject2[key] = awaitedValue;
690
+ if (!signal) {
691
+ loaderState2[key] = createLoaderSignal(loadersObject2, key, trackUrl, DEFAULT_LOADERS_SERIALIZATION_STRATEGY, container2);
692
+ } else {
693
+ signal.invalidate();
694
+ }
1057
695
  }
1058
- CLIENT_DATA_CACHE.clear();
1059
- if (!win._qRouterSPA) {
1060
- win._qRouterSPA = true;
1061
- history.scrollRestoration = "manual";
1062
- win.addEventListener("popstate", () => {
1063
- win._qRouterScrollEnabled = false;
1064
- clearTimeout(win._qRouterScrollDebounce);
1065
- goto(location.href, {
1066
- type: "popstate"
1067
- });
696
+ }
697
+ CLIENT_DATA_CACHE.clear();
698
+ if (!window._qRouterSPA) {
699
+ window._qRouterSPA = true;
700
+ history.scrollRestoration = "manual";
701
+ window.addEventListener("popstate", () => {
702
+ window._qRouterScrollEnabled = false;
703
+ clearTimeout(window._qRouterScrollDebounce);
704
+ goto2(location.href, {
705
+ type: "popstate"
1068
706
  });
1069
- win.removeEventListener("popstate", win._qRouterInitPopstate);
1070
- win._qRouterInitPopstate = void 0;
1071
- if (!win._qRouterHistoryPatch) {
1072
- win._qRouterHistoryPatch = true;
1073
- const pushState = history.pushState;
1074
- const replaceState2 = history.replaceState;
1075
- const prepareState = (state) => {
1076
- if (state === null || typeof state === "undefined") {
1077
- state = {};
1078
- } else if (state?.constructor !== Object) {
1079
- state = {
1080
- _data: state
1081
- };
1082
- if (isDev) {
1083
- console.warn("In a Qwik SPA context, `history.state` is used to store scroll state. Direct calls to `pushState()` and `replaceState()` must supply an actual Object type. We need to be able to automatically attach the scroll state to your state object. A new state object has been created, your data has been moved to: `history.state._data`");
1084
- }
707
+ });
708
+ window.removeEventListener("popstate", window._qRouterInitPopstate);
709
+ window._qRouterInitPopstate = void 0;
710
+ if (!window._qRouterHistoryPatch) {
711
+ window._qRouterHistoryPatch = true;
712
+ const pushState = history.pushState;
713
+ const replaceState2 = history.replaceState;
714
+ const prepareState = (state) => {
715
+ if (state === null || typeof state === "undefined") {
716
+ state = {};
717
+ } else if (state?.constructor !== Object) {
718
+ state = {
719
+ _data: state
720
+ };
721
+ if (isDev) {
722
+ console.warn("In a Qwik SPA context, `history.state` is used to store scroll state. Direct calls to `pushState()` and `replaceState()` must supply an actual Object type. We need to be able to automatically attach the scroll state to your state object. A new state object has been created, your data has been moved to: `history.state._data`");
1085
723
  }
1086
- state._qRouterScroll = state._qRouterScroll || currentScrollState(scroller);
1087
- return state;
1088
- };
1089
- history.pushState = (state, title, url2) => {
1090
- state = prepareState(state);
1091
- return pushState.call(history, state, title, url2);
1092
- };
1093
- history.replaceState = (state, title, url2) => {
1094
- state = prepareState(state);
1095
- return replaceState2.call(history, state, title, url2);
1096
- };
1097
- }
1098
- document.body.addEventListener("click", (event) => {
1099
- if (event.defaultPrevented) {
1100
- return;
1101
724
  }
1102
- const target = event.target.closest("a[href]");
1103
- if (target && !target.hasAttribute("preventdefault:click")) {
1104
- const href = target.getAttribute("href");
1105
- const prev = new URL(location.href);
1106
- const dest = new URL(href, prev);
1107
- if (isSameOrigin(dest, prev) && isSamePath(dest, prev)) {
1108
- event.preventDefault();
1109
- if (!dest.hash && !dest.href.endsWith("#")) {
1110
- if (dest.href !== prev.href) {
1111
- history.pushState(null, "", dest);
1112
- }
1113
- win._qRouterScrollEnabled = false;
1114
- clearTimeout(win._qRouterScrollDebounce);
1115
- saveScrollHistory({
1116
- ...currentScrollState(scroller),
1117
- x: 0,
1118
- y: 0
1119
- });
1120
- location.reload();
1121
- return;
725
+ state._qRouterScroll = state._qRouterScroll || currentScrollState(scroller);
726
+ return state;
727
+ };
728
+ history.pushState = (state, title, url2) => {
729
+ state = prepareState(state);
730
+ return pushState.call(history, state, title, url2);
731
+ };
732
+ history.replaceState = (state, title, url2) => {
733
+ state = prepareState(state);
734
+ return replaceState2.call(history, state, title, url2);
735
+ };
736
+ }
737
+ document.addEventListener("click", (event) => {
738
+ if (event.defaultPrevented) {
739
+ return;
740
+ }
741
+ const target = event.target.closest("a[href]");
742
+ if (target && !target.hasAttribute("preventdefault:click")) {
743
+ const href = target.getAttribute("href");
744
+ const prev = new URL(location.href);
745
+ const dest = new URL(href, prev);
746
+ if (isSameOrigin(dest, prev) && isSamePath(dest, prev)) {
747
+ event.preventDefault();
748
+ if (!dest.hash && !dest.href.endsWith("#")) {
749
+ if (dest.href !== prev.href) {
750
+ history.pushState(null, "", dest);
1122
751
  }
1123
- goto(target.getAttribute("href"));
752
+ window._qRouterScrollEnabled = false;
753
+ clearTimeout(window._qRouterScrollDebounce);
754
+ saveScrollHistory({
755
+ ...currentScrollState(scroller),
756
+ x: 0,
757
+ y: 0
758
+ });
759
+ location.reload();
760
+ return;
1124
761
  }
762
+ goto2(target.getAttribute("href"));
1125
763
  }
1126
- });
1127
- document.body.removeEventListener("click", win._qRouterInitAnchors);
1128
- win._qRouterInitAnchors = void 0;
1129
- if (!window.navigation) {
1130
- document.addEventListener("visibilitychange", () => {
1131
- if ((win._qRouterScrollEnabled || win._qCityScrollEnabled) && document.visibilityState === "hidden") {
1132
- if (win._qCityScrollEnabled) {
1133
- console.warn('"_qCityScrollEnabled" is deprecated. Use "_qRouterScrollEnabled" instead.');
1134
- }
1135
- const scrollState2 = currentScrollState(scroller);
1136
- saveScrollHistory(scrollState2);
1137
- }
1138
- }, {
1139
- passive: true
1140
- });
1141
- document.removeEventListener("visibilitychange", win._qRouterInitVisibility);
1142
- win._qRouterInitVisibility = void 0;
1143
764
  }
1144
- win.addEventListener("scroll", () => {
1145
- if (!win._qRouterScrollEnabled && !win._qCityScrollEnabled) {
1146
- return;
1147
- }
1148
- clearTimeout(win._qRouterScrollDebounce);
1149
- win._qRouterScrollDebounce = setTimeout(() => {
765
+ });
766
+ document.removeEventListener("click", window._qRouterInitAnchors);
767
+ window._qRouterInitAnchors = void 0;
768
+ if (!window.navigation) {
769
+ document.addEventListener("visibilitychange", () => {
770
+ if ((window._qRouterScrollEnabled || window._qCityScrollEnabled) && document.visibilityState === "hidden") {
771
+ if (window._qCityScrollEnabled) {
772
+ console.warn('"_qCityScrollEnabled" is deprecated. Use "_qRouterScrollEnabled" instead.');
773
+ }
1150
774
  const scrollState2 = currentScrollState(scroller);
1151
775
  saveScrollHistory(scrollState2);
1152
- win._qRouterScrollDebounce = void 0;
1153
- }, 200);
776
+ }
1154
777
  }, {
1155
778
  passive: true
1156
779
  });
1157
- removeEventListener("scroll", win._qRouterInitScroll);
1158
- win._qRouterInitScroll = void 0;
1159
- spaInit.resolve();
780
+ document.removeEventListener("visibilitychange", window._qRouterInitVisibility);
781
+ window._qRouterInitVisibility = void 0;
1160
782
  }
1161
- if (navType !== "popstate") {
1162
- win._qRouterScrollEnabled = false;
1163
- clearTimeout(win._qRouterScrollDebounce);
783
+ window.addEventListener("scroll", () => {
784
+ if (!window._qRouterScrollEnabled && !window._qCityScrollEnabled) {
785
+ return;
786
+ }
787
+ clearTimeout(window._qRouterScrollDebounce);
788
+ window._qRouterScrollDebounce = setTimeout(() => {
789
+ const scrollState2 = currentScrollState(scroller);
790
+ saveScrollHistory(scrollState2);
791
+ window._qRouterScrollDebounce = void 0;
792
+ }, 200);
793
+ }, {
794
+ passive: true
795
+ });
796
+ removeEventListener("scroll", window._qRouterInitScroll);
797
+ window._qRouterInitScroll = void 0;
798
+ spaInit.resolve();
799
+ }
800
+ if (navType !== "popstate") {
801
+ window._qRouterScrollEnabled = false;
802
+ clearTimeout(window._qRouterScrollDebounce);
803
+ if (!navigation.historyUpdated) {
1164
804
  const scrollState2 = currentScrollState(scroller);
1165
805
  saveScrollHistory(scrollState2);
1166
806
  }
1167
- const navigate = () => {
1168
- clientNavigate(window, navType, prevUrl, trackUrl, replaceState);
1169
- return _waitUntilRendered(elm);
1170
- };
1171
- const _waitNextPage = () => {
1172
- if (isServer || props.viewTransition === false) {
1173
- return navigate();
1174
- } else {
1175
- const viewTransition = startViewTransition({
1176
- update: navigate,
1177
- types: [
1178
- "qwik-navigation"
1179
- ]
1180
- });
1181
- if (!viewTransition) {
1182
- return Promise.resolve();
1183
- }
1184
- return viewTransition.ready;
807
+ }
808
+ const navigate = () => {
809
+ if (navigation.historyUpdated) {
810
+ const currentPath = location.pathname + location.search + location.hash;
811
+ const nextPath = toPath(trackUrl);
812
+ if (currentPath !== nextPath) {
813
+ history.replaceState(history.state, "", nextPath);
1185
814
  }
1186
- };
1187
- _waitNextPage().then(() => {
1188
- const container = _getQContainerElement(elm);
1189
- container.setAttribute("q:route", routeName);
1190
- const scrollState2 = currentScrollState(scroller);
1191
- saveScrollHistory(scrollState2);
1192
- win._qRouterScrollEnabled = true;
1193
- if (isBrowser) {
1194
- callRestoreScrollOnDocument();
815
+ } else {
816
+ clientNavigate(window, navType, prevUrl, trackUrl, replaceState);
817
+ }
818
+ contentInternal2.trigger();
819
+ return _waitUntilRendered(container2);
820
+ };
821
+ const _waitNextPage = () => {
822
+ if (isServer || props2?.viewTransition === false) {
823
+ return navigate();
824
+ } else {
825
+ const viewTransition = startViewTransition({
826
+ update: navigate,
827
+ types: [
828
+ "qwik-navigation"
829
+ ]
830
+ });
831
+ if (!viewTransition) {
832
+ return Promise.resolve();
1195
833
  }
1196
- routeLocation.isNavigating = false;
1197
- navResolver.r?.();
1198
- });
1199
- }
834
+ return viewTransition.ready;
835
+ }
836
+ };
837
+ _waitNextPage().catch((err) => {
838
+ navigate();
839
+ throw err;
840
+ }).finally(() => {
841
+ container2.element.setAttribute?.(Q_ROUTE, $routeName$);
842
+ const scrollState2 = currentScrollState(scroller);
843
+ saveScrollHistory(scrollState2);
844
+ window._qRouterScrollEnabled = true;
845
+ if (isBrowser) {
846
+ callRestoreScrollOnDocument();
847
+ }
848
+ if (shouldForcePrevUrl) {
849
+ forceStoreEffects(routeLocation2, "prevUrl");
850
+ }
851
+ if (shouldForceUrl) {
852
+ forceStoreEffects(routeLocation2, "url");
853
+ }
854
+ if (shouldForceParams) {
855
+ forceStoreEffects(routeLocation2, "params");
856
+ }
857
+ routeLocation2.isNavigating = false;
858
+ navResolver2.r?.();
859
+ });
1200
860
  }
861
+ }, "useQwikRouter_useTask_XpalYii770E", [
862
+ actionState,
863
+ content,
864
+ contentInternal,
865
+ documentHead,
866
+ env,
867
+ getScroller,
868
+ goto,
869
+ httpStatus,
870
+ loaderState,
871
+ loadersObject,
872
+ navResolver,
873
+ props,
874
+ routeInternal,
875
+ routeLocation,
876
+ routeLocationTarget,
877
+ serverHead
878
+ ]),
879
+ // We should only wait for navigation to complete on the server
880
+ {
881
+ deferUpdates: isServer
1201
882
  }
1202
- if (isServer) {
1203
- return run();
1204
- } else {
1205
- run();
1206
- }
1207
- });
1208
- return /* @__PURE__ */ jsx(Slot, {});
1209
- });
883
+ );
884
+ };
885
+ const QwikRouterProvider = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
886
+ useQwikRouter(props);
887
+ return /* @__PURE__ */ _jsxSorted(Slot, null, null, null, 3, "5y_0");
888
+ }, "QwikRouterProvider_component_6Kjfa79mqlY"));
1210
889
  const QwikCityProvider = QwikRouterProvider;
1211
- const QwikRouterMockProvider = component$((props) => {
890
+ const useQwikMockRouter = (props) => {
1212
891
  const urlEnv = props.url ?? "http://localhost/";
1213
892
  const url = new URL(urlEnv);
1214
893
  const routeLocation = useStore({
@@ -1219,14 +898,16 @@ const QwikRouterMockProvider = component$((props) => {
1219
898
  }, {
1220
899
  deep: false
1221
900
  });
1222
- const loaderState = useSignal({});
1223
- const routeInternal = useSignal({
1224
- type: "initial",
1225
- dest: url
1226
- });
1227
- const goto = props.goto ?? $(async () => {
1228
- console.warn("QwikRouterMockProvider: goto not provided");
901
+ const loadersData = props.loaders?.reduce((acc, { loader, data }) => {
902
+ acc[loader.__id] = data;
903
+ return acc;
904
+ }, {});
905
+ const loaderState = useStore(loadersData ?? {}, {
906
+ deep: false
1229
907
  });
908
+ const goto = props.goto ?? /* @__PURE__ */ inlinedQrl(async () => {
909
+ console.warn("QwikRouterMockProvider: goto not provided");
910
+ }, "useQwikMockRouter_goto_aViHFxQ1a3s");
1230
911
  const documentHead = useStore(createDocumentHead, {
1231
912
  deep: false
1232
913
  });
@@ -1238,254 +919,83 @@ const QwikRouterMockProvider = component$((props) => {
1238
919
  });
1239
920
  const contentInternal = useSignal();
1240
921
  const actionState = useSignal();
922
+ const httpStatus = useSignal({
923
+ status: 200,
924
+ message: ""
925
+ });
1241
926
  useContextProvider(ContentContext, content);
1242
927
  useContextProvider(ContentInternalContext, contentInternal);
1243
928
  useContextProvider(DocumentHeadContext, documentHead);
929
+ useContextProvider(HttpStatusContext, httpStatus);
1244
930
  useContextProvider(RouteLocationContext, routeLocation);
1245
931
  useContextProvider(RouteNavigateContext, goto);
1246
932
  useContextProvider(RouteStateContext, loaderState);
1247
933
  useContextProvider(RouteActionContext, actionState);
1248
- useContextProvider(RouteInternalContext, routeInternal);
1249
- return /* @__PURE__ */ jsx(Slot, {});
1250
- });
934
+ const actionsMocks = props.actions?.reduce((acc, { action, handler }) => {
935
+ acc[action.__id] = handler;
936
+ return acc;
937
+ }, {});
938
+ useTaskQrl(/* @__PURE__ */ inlinedQrl(async ({ track }) => {
939
+ const actionState2 = _captures[0], actionsMocks2 = _captures[1];
940
+ const action = track(actionState2);
941
+ if (!action?.resolve) {
942
+ return;
943
+ }
944
+ const mock = actionsMocks2?.[action.id];
945
+ if (mock) {
946
+ const actionResult = await mock(action.data);
947
+ action.resolve(actionResult);
948
+ }
949
+ }, "useQwikMockRouter_useTask_tXTLR4tzCy0", [
950
+ actionState,
951
+ actionsMocks
952
+ ]));
953
+ };
954
+ const QwikRouterMockProvider = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
955
+ useQwikMockRouter(props);
956
+ return /* @__PURE__ */ _jsxSorted(Slot, null, null, null, 3, "5y_1");
957
+ }, "QwikRouterMockProvider_component_IN4dVpT0x74"));
1251
958
  const QwikCityMockProvider = QwikRouterMockProvider;
1252
- const RouterOutlet = component$(() => {
959
+
960
+ const RouterOutlet = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl(() => {
1253
961
  const serverData = useServerData("containerAttributes");
1254
962
  if (!serverData) {
1255
963
  throw new Error("PrefetchServiceWorker component must be rendered on the server.");
1256
964
  }
1257
- const { value } = useContext(ContentInternalContext);
1258
- if (value && value.length > 0) {
1259
- const contentsLen = value.length;
965
+ const internalContext = useContext(ContentInternalContext);
966
+ const contents = internalContext.value;
967
+ if (contents && contents.length > 0) {
968
+ const contentsLen = contents.length;
1260
969
  let cmp = null;
1261
970
  for (let i = contentsLen - 1; i >= 0; i--) {
1262
- if (value[i].default) {
1263
- cmp = jsx$1(value[i].default, {
1264
- children: cmp
1265
- });
971
+ if (contents[i].default) {
972
+ cmp = _jsxSorted(contents[i].default, null, null, cmp, 1, "Fn_0");
1266
973
  }
1267
974
  }
1268
- return /* @__PURE__ */ jsxs(Fragment, {
1269
- children: [
1270
- cmp,
1271
- !__EXPERIMENTAL__.noSPA && /* @__PURE__ */ jsx("script", {
1272
- "document:onQCInit$": spaInit,
1273
- "document:onQInit$": sync$(() => {
1274
- ((w, h) => {
1275
- if (!w._qcs && h.scrollRestoration === "manual") {
1276
- w._qcs = true;
1277
- const s = h.state?._qRouterScroll;
1278
- if (s) {
1279
- w.scrollTo(s.x, s.y);
1280
- }
1281
- document.dispatchEvent(new Event("qcinit"));
975
+ return /* @__PURE__ */ _jsxSorted(Fragment, null, null, [
976
+ cmp,
977
+ !__EXPERIMENTAL__.noSPA && /* @__PURE__ */ _jsxSorted("script", {
978
+ "q-d:qinit": _qrlSync(() => {
979
+ ((w, h) => {
980
+ if (!w._qcs && h.scrollRestoration === "manual") {
981
+ w._qcs = true;
982
+ const s = h.state?._qRouterScroll;
983
+ if (s) {
984
+ w.scrollTo(s.x, s.y);
1282
985
  }
1283
- })(window, history);
1284
- })
1285
- })
1286
- ]
1287
- });
986
+ document.dispatchEvent(new Event("qcinit"));
987
+ }
988
+ })(window, history);
989
+ }, '()=>{((w,h)=>{if(!w._qcs&&h.scrollRestoration==="manual"){w._qcs=!0;const s=h.state?._qRouterScroll;if(s){w.scrollTo(s.x,s.y);}document.dispatchEvent(new Event("qcinit"));}})(window,history);}')
990
+ }, {
991
+ "q-d:qcinit": spaInit
992
+ }, null, 2, "Fn_1")
993
+ ], 1, "Fn_2");
1288
994
  }
1289
995
  return SkipRender;
1290
- });
1291
- var store;
1292
- function getGlobalConfig(config2) {
1293
- return {
1294
- lang: config2?.lang ?? store?.lang,
1295
- message: config2?.message,
1296
- abortEarly: config2?.abortEarly ?? store?.abortEarly,
1297
- abortPipeEarly: config2?.abortPipeEarly ?? store?.abortPipeEarly
1298
- };
1299
- }
1300
- function getDotPath(issue) {
1301
- if (issue.path) {
1302
- let key = "";
1303
- for (const item of issue.path) {
1304
- if (typeof item.key === "string" || typeof item.key === "number") {
1305
- if (key) {
1306
- key += `.${item.key}`;
1307
- } else {
1308
- key += item.key;
1309
- }
1310
- } else {
1311
- return null;
1312
- }
1313
- }
1314
- return key;
1315
- }
1316
- return null;
1317
- }
1318
- function flatten(issues) {
1319
- const flatErrors = {};
1320
- for (const issue of issues) {
1321
- if (issue.path) {
1322
- const dotPath = getDotPath(issue);
1323
- if (dotPath) {
1324
- if (!flatErrors.nested) {
1325
- flatErrors.nested = {};
1326
- }
1327
- if (flatErrors.nested[dotPath]) {
1328
- flatErrors.nested[dotPath].push(issue.message);
1329
- } else {
1330
- flatErrors.nested[dotPath] = [issue.message];
1331
- }
1332
- } else {
1333
- if (flatErrors.other) {
1334
- flatErrors.other.push(issue.message);
1335
- } else {
1336
- flatErrors.other = [issue.message];
1337
- }
1338
- }
1339
- } else {
1340
- if (flatErrors.root) {
1341
- flatErrors.root.push(issue.message);
1342
- } else {
1343
- flatErrors.root = [issue.message];
1344
- }
1345
- }
1346
- }
1347
- return flatErrors;
1348
- }
1349
- async function safeParseAsync(schema, input, config2) {
1350
- const dataset = await schema._run(
1351
- { typed: false, value: input },
1352
- getGlobalConfig(config2)
1353
- );
1354
- return {
1355
- typed: dataset.typed,
1356
- success: !dataset.issues,
1357
- output: dataset.value,
1358
- issues: dataset.issues
1359
- };
1360
- }
1361
- const routeActionQrl = (actionQrl, ...rest) => {
1362
- const { id, validators } = getValidators(rest, actionQrl);
1363
- function action() {
1364
- const loc = useLocation();
1365
- const currentAction = useAction();
1366
- const initialState = {
1367
- actionPath: `?${QACTION_KEY}=${id}`,
1368
- submitted: false,
1369
- isRunning: false,
1370
- status: void 0,
1371
- value: void 0,
1372
- formData: void 0
1373
- };
1374
- const state = useStore(() => {
1375
- const value = currentAction.value;
1376
- if (value && value?.id === id) {
1377
- const data = value.data;
1378
- if (data instanceof FormData) {
1379
- initialState.formData = data;
1380
- }
1381
- if (value.output) {
1382
- const { status, result } = value.output;
1383
- initialState.status = status;
1384
- initialState.value = result;
1385
- }
1386
- }
1387
- return initialState;
1388
- });
1389
- const submit = $((input = {}) => {
1390
- if (isServer) {
1391
- throw new Error(`Actions can not be invoked within the server during SSR.
1392
- Action.run() can only be called on the browser, for example when a user clicks a button, or submits a form.`);
1393
- }
1394
- let data;
1395
- let form;
1396
- if (input instanceof SubmitEvent) {
1397
- form = input.target;
1398
- data = new FormData(form);
1399
- if ((input.submitter instanceof HTMLInputElement || input.submitter instanceof HTMLButtonElement) && input.submitter.name) {
1400
- if (input.submitter.name) {
1401
- data.append(input.submitter.name, input.submitter.value);
1402
- }
1403
- }
1404
- } else {
1405
- data = input;
1406
- }
1407
- return new Promise((resolve) => {
1408
- if (data instanceof FormData) {
1409
- state.formData = data;
1410
- }
1411
- state.submitted = true;
1412
- state.isRunning = true;
1413
- loc.isNavigating = true;
1414
- currentAction.value = {
1415
- data,
1416
- id,
1417
- resolve: noSerialize(resolve)
1418
- };
1419
- }).then(({ result, status }) => {
1420
- state.isRunning = false;
1421
- state.status = status;
1422
- state.value = result;
1423
- if (form) {
1424
- if (form.getAttribute("data-spa-reset") === "true") {
1425
- form.reset();
1426
- }
1427
- const detail = {
1428
- status,
1429
- value: result
1430
- };
1431
- form.dispatchEvent(new CustomEvent("submitcompleted", {
1432
- bubbles: false,
1433
- cancelable: false,
1434
- composed: false,
1435
- detail
1436
- }));
1437
- }
1438
- return {
1439
- status,
1440
- value: result
1441
- };
1442
- });
1443
- });
1444
- initialState.submit = submit;
1445
- return state;
1446
- }
1447
- action.__brand = "server_action";
1448
- action.__validators = validators;
1449
- action.__qrl = actionQrl;
1450
- action.__id = id;
1451
- Object.freeze(action);
1452
- return action;
1453
- };
1454
- const globalActionQrl = (actionQrl, ...rest) => {
1455
- const action = routeActionQrl(actionQrl, ...rest);
1456
- if (isServer) {
1457
- if (typeof globalThis._qwikActionsMap === "undefined") {
1458
- globalThis._qwikActionsMap = /* @__PURE__ */ new Map();
1459
- }
1460
- globalThis._qwikActionsMap.set(action.__id, action);
1461
- }
1462
- return action;
1463
- };
1464
- const routeAction$ = /* @__PURE__ */ implicit$FirstArg(routeActionQrl);
1465
- const globalAction$ = /* @__PURE__ */ implicit$FirstArg(globalActionQrl);
1466
- const routeLoaderQrl = (loaderQrl, ...rest) => {
1467
- const { id, validators } = getValidators(rest, loaderQrl);
1468
- function loader() {
1469
- return useContext(RouteStateContext, (state) => {
1470
- if (!(id in state)) {
1471
- throw new Error(`routeLoader$ "${loaderQrl.getSymbol()}" was invoked in a route where it was not declared.
1472
- This is because the routeLoader$ was not exported in a 'layout.tsx' or 'index.tsx' file of the existing route.
1473
- For more information check: https://qwik.dev/docs/route-loader/
996
+ }, "RouterOutlet_component_QwONcWD5gIg"));
1474
997
 
1475
- If your are managing reusable logic or a library it is essential that this function is re-exported from within 'layout.tsx' or 'index.tsx file of the existing route otherwise it will not run or throw exception.
1476
- For more information check: https://qwik.dev/docs/re-exporting-loaders/`);
1477
- }
1478
- return _wrapStore(state, id);
1479
- });
1480
- }
1481
- loader.__brand = "server_loader";
1482
- loader.__qrl = loaderQrl;
1483
- loader.__validators = validators;
1484
- loader.__id = id;
1485
- Object.freeze(loader);
1486
- return loader;
1487
- };
1488
- const routeLoader$ = /* @__PURE__ */ implicit$FirstArg(routeLoaderQrl);
998
+ const getValue = (obj) => obj.value;
1489
999
  const validatorQrl = (validator) => {
1490
1000
  if (isServer) {
1491
1001
  return {
@@ -1524,7 +1034,7 @@ const valibotQrl = (qrl) => {
1524
1034
  async validate(ev, inputData) {
1525
1035
  const schema = await qrl.resolve().then((obj) => typeof obj === "function" ? obj(ev) : obj);
1526
1036
  const data = inputData ?? await ev.parseBody();
1527
- const result = await safeParseAsync(schema, data);
1037
+ const result = await v.safeParseAsync(schema, data);
1528
1038
  if (result.success) {
1529
1039
  return {
1530
1040
  success: true,
@@ -1538,7 +1048,7 @@ const valibotQrl = (qrl) => {
1538
1048
  success: false,
1539
1049
  status: 400,
1540
1050
  error: {
1541
- formErrors: flatten(result.issues).root ?? [],
1051
+ formErrors: v.flatten(result.issues).root ?? [],
1542
1052
  fieldErrors: flattenValibotIssues(result.issues)
1543
1053
  }
1544
1054
  };
@@ -1586,7 +1096,7 @@ const zodQrl = (qrl) => {
1586
1096
  }
1587
1097
  });
1588
1098
  const data = inputData ?? await ev.parseBody();
1589
- const result = await schema.safeParseAsync(data);
1099
+ const result = await withLocale(ev.locale(), () => schema.safeParseAsync(data));
1590
1100
  if (result.success) {
1591
1101
  return result;
1592
1102
  } else {
@@ -1608,108 +1118,9 @@ const zodQrl = (qrl) => {
1608
1118
  return void 0;
1609
1119
  };
1610
1120
  const zod$ = /* @__PURE__ */ implicit$FirstArg(zodQrl);
1611
- const serverQrl = (qrl, options) => {
1612
- if (isServer) {
1613
- const captured = qrl.getCaptured();
1614
- if (captured && captured.length > 0 && !_getContextElement()) {
1615
- throw new Error("For security reasons, we cannot serialize QRLs that capture lexical scope.");
1616
- }
1617
- }
1618
- const method = options?.method?.toUpperCase?.() || "POST";
1619
- const headers = options?.headers || {};
1620
- const origin = options?.origin || "";
1621
- const fetchOptions = options?.fetchOptions || {};
1622
- function rpc() {
1623
- return $(async function(...args) {
1624
- const abortSignal = args.length > 0 && args[0] instanceof AbortSignal ? args.shift() : void 0;
1625
- if (isServer) {
1626
- let requestEvent = globalThis.qcAsyncRequestStore?.getStore();
1627
- if (!requestEvent) {
1628
- const contexts = [
1629
- useQwikRouterEnv()?.ev,
1630
- this,
1631
- _getContextEvent()
1632
- ];
1633
- requestEvent = contexts.find((v2) => v2 && Object.prototype.hasOwnProperty.call(v2, "sharedMap") && Object.prototype.hasOwnProperty.call(v2, "cookie"));
1634
- }
1635
- return qrl.apply(requestEvent, isDev ? deepFreeze(args) : args);
1636
- } else {
1637
- const ctxElm = _getContextElement();
1638
- const filteredArgs = args.map((arg) => {
1639
- if (arg instanceof SubmitEvent && arg.target instanceof HTMLFormElement) {
1640
- return new FormData(arg.target);
1641
- } else if (arg instanceof Event) {
1642
- return null;
1643
- } else if (arg instanceof Node) {
1644
- return null;
1645
- }
1646
- return arg;
1647
- });
1648
- const qrlHash = qrl.getHash();
1649
- let query = "";
1650
- const config = {
1651
- ...fetchOptions,
1652
- method,
1653
- headers: {
1654
- ...headers,
1655
- "Content-Type": "application/qwik-json",
1656
- Accept: "application/json, application/qwik-json, text/qwik-json-stream, text/plain",
1657
- // Required so we don't call accidentally
1658
- "X-QRL": qrlHash
1659
- },
1660
- signal: abortSignal
1661
- };
1662
- const body = await _serialize([
1663
- qrl,
1664
- ...filteredArgs
1665
- ]);
1666
- if (method === "GET") {
1667
- query += `&${QDATA_KEY}=${encodeURIComponent(body)}`;
1668
- } else {
1669
- config.body = body;
1670
- }
1671
- const res = await fetch(`${origin}?${QFN_KEY}=${qrlHash}${query}`, config);
1672
- const contentType = res.headers.get("Content-Type");
1673
- if (res.ok && contentType === "text/qwik-json-stream" && res.body) {
1674
- return async function* () {
1675
- try {
1676
- for await (const result of deserializeStream(res.body, ctxElm ?? document.documentElement, abortSignal)) {
1677
- yield result;
1678
- }
1679
- } finally {
1680
- if (!abortSignal?.aborted) {
1681
- await res.body.cancel();
1682
- }
1683
- }
1684
- }();
1685
- } else if (contentType === "application/qwik-json") {
1686
- const str = await res.text();
1687
- const [obj] = _deserialize(str, ctxElm ?? document.documentElement);
1688
- if (res.status >= 400) {
1689
- throw obj;
1690
- }
1691
- return obj;
1692
- } else if (contentType === "application/json") {
1693
- const obj = await res.json();
1694
- if (res.status >= 400) {
1695
- throw obj;
1696
- }
1697
- return obj;
1698
- } else if (contentType === "text/plain" || contentType === "text/html") {
1699
- const str = await res.text();
1700
- if (res.status >= 400) {
1701
- throw str;
1702
- }
1703
- return str;
1704
- }
1705
- }
1706
- });
1707
- }
1708
- return rpc();
1709
- };
1710
- const server$ = /* @__PURE__ */ implicit$FirstArg(serverQrl);
1711
1121
  const getValidators = (rest, qrl) => {
1712
1122
  let id;
1123
+ let serializationStrategy = DEFAULT_LOADERS_SERIALIZATION_STRATEGY;
1713
1124
  const validators = [];
1714
1125
  if (rest.length === 1) {
1715
1126
  const options = rest[0];
@@ -1718,6 +1129,9 @@ const getValidators = (rest, qrl) => {
1718
1129
  validators.push(options);
1719
1130
  } else {
1720
1131
  id = options.id;
1132
+ if (options.serializationStrategy) {
1133
+ serializationStrategy = options.serializationStrategy;
1134
+ }
1721
1135
  if (options.validation) {
1722
1136
  validators.push(...options.validation);
1723
1137
  }
@@ -1738,10 +1152,148 @@ const getValidators = (rest, qrl) => {
1738
1152
  }
1739
1153
  return {
1740
1154
  validators: validators.reverse(),
1741
- id
1155
+ id,
1156
+ serializationStrategy
1742
1157
  };
1743
1158
  };
1744
- const deserializeStream = async function* (stream, ctxElm, abortSignal) {
1159
+ const routeActionQrl = (actionQrl, ...rest) => {
1160
+ const { id, validators } = getValidators(rest, actionQrl);
1161
+ function action() {
1162
+ const loc = useLocation();
1163
+ const currentAction = useAction();
1164
+ const initialState = {
1165
+ actionPath: `?${QACTION_KEY}=${id}`,
1166
+ submitted: false,
1167
+ isRunning: false,
1168
+ status: void 0,
1169
+ value: void 0,
1170
+ formData: void 0
1171
+ };
1172
+ const state = useStore(() => {
1173
+ const value = currentAction.value;
1174
+ if (value && value?.id === id) {
1175
+ const data = value.data;
1176
+ if (data instanceof FormData) {
1177
+ initialState.formData = data;
1178
+ }
1179
+ if (value.output) {
1180
+ const { status, result } = value.output;
1181
+ initialState.status = status;
1182
+ initialState.value = result;
1183
+ }
1184
+ }
1185
+ return initialState;
1186
+ });
1187
+ const submit = /* @__PURE__ */ inlinedQrl((input = {}) => {
1188
+ const currentAction2 = _captures[0], id2 = _captures[1], loc2 = _captures[2], state2 = _captures[3];
1189
+ if (isServer) {
1190
+ throw new Error(`Actions can not be invoked within the server during SSR.
1191
+ Action.run() can only be called on the browser, for example when a user clicks a button, or submits a form.`);
1192
+ }
1193
+ let data;
1194
+ let form;
1195
+ if (input instanceof SubmitEvent) {
1196
+ form = input.target;
1197
+ data = new FormData(form);
1198
+ if ((input.submitter instanceof HTMLInputElement || input.submitter instanceof HTMLButtonElement) && input.submitter.name) {
1199
+ if (input.submitter.name) {
1200
+ data.append(input.submitter.name, input.submitter.value);
1201
+ }
1202
+ }
1203
+ } else {
1204
+ data = input;
1205
+ }
1206
+ return new Promise((resolve) => {
1207
+ if (data instanceof FormData) {
1208
+ state2.formData = data;
1209
+ }
1210
+ state2.submitted = true;
1211
+ state2.isRunning = true;
1212
+ loc2.isNavigating = true;
1213
+ currentAction2.value = {
1214
+ data,
1215
+ id: id2,
1216
+ resolve: noSerialize(resolve)
1217
+ };
1218
+ }).then((_rawProps) => {
1219
+ state2.isRunning = false;
1220
+ state2.status = _rawProps.status;
1221
+ state2.value = _rawProps.result;
1222
+ if (form) {
1223
+ if (form.getAttribute("data-spa-reset") === "true") {
1224
+ form.reset();
1225
+ }
1226
+ const detail = {
1227
+ status: _rawProps.status,
1228
+ value: _rawProps.result
1229
+ };
1230
+ form.dispatchEvent(new CustomEvent("submitcompleted", {
1231
+ bubbles: false,
1232
+ cancelable: false,
1233
+ composed: false,
1234
+ detail
1235
+ }));
1236
+ }
1237
+ return {
1238
+ status: _rawProps.status,
1239
+ value: _rawProps.result
1240
+ };
1241
+ });
1242
+ }, "routeActionQrl_action_submit_YuS5bpdQ360", [
1243
+ currentAction,
1244
+ id,
1245
+ loc,
1246
+ state
1247
+ ]);
1248
+ initialState.submit = submit;
1249
+ return state;
1250
+ }
1251
+ action.__brand = "server_action";
1252
+ action.__validators = validators;
1253
+ action.__qrl = actionQrl;
1254
+ action.__id = id;
1255
+ Object.freeze(action);
1256
+ return action;
1257
+ };
1258
+ const globalActionQrl = (actionQrl, ...rest) => {
1259
+ const action = routeActionQrl(actionQrl, ...rest);
1260
+ if (isServer) {
1261
+ if (typeof globalThis._qwikActionsMap === "undefined") {
1262
+ globalThis._qwikActionsMap = /* @__PURE__ */ new Map();
1263
+ }
1264
+ globalThis._qwikActionsMap.set(action.__id, action);
1265
+ }
1266
+ return action;
1267
+ };
1268
+ const routeAction$ = /* @__PURE__ */ implicit$FirstArg(routeActionQrl);
1269
+ const globalAction$ = /* @__PURE__ */ implicit$FirstArg(globalActionQrl);
1270
+ const routeLoaderQrl = (loaderQrl, ...rest) => {
1271
+ const { id, validators, serializationStrategy } = getValidators(rest, loaderQrl);
1272
+ function loader() {
1273
+ const state = _resolveContextWithoutSequentialScope(RouteStateContext);
1274
+ if (!(id in state)) {
1275
+ throw new Error(`routeLoader$ "${loaderQrl.getSymbol()}" was invoked in a route where it was not declared.
1276
+ This is because the routeLoader$ was not exported in a 'layout.tsx' or 'index.tsx' file of the existing route.
1277
+ For more information check: https://qwik.dev/docs/route-loader/
1278
+
1279
+ If your are managing reusable logic or a library it is essential that this function is re-exported from within 'layout.tsx' or 'index.tsx file of the existing route otherwise it will not run or throw exception.
1280
+ For more information check: https://qwik.dev/docs/re-exporting-loaders/`);
1281
+ }
1282
+ const loaderData = state[id];
1283
+ untrack(getValue, loaderData);
1284
+ return loaderData;
1285
+ }
1286
+ loader.__brand = "server_loader";
1287
+ loader.__qrl = loaderQrl;
1288
+ loader.__validators = validators;
1289
+ loader.__id = id;
1290
+ loader.__serializationStrategy = serializationStrategy;
1291
+ loader.__expires = -1;
1292
+ Object.freeze(loader);
1293
+ return loader;
1294
+ };
1295
+ const routeLoader$ = /* @__PURE__ */ implicit$FirstArg(routeLoaderQrl);
1296
+ const deserializeStream = async function* (stream, abortSignal) {
1745
1297
  const reader = stream.getReader();
1746
1298
  try {
1747
1299
  let buffer = "";
@@ -1757,7 +1309,7 @@ const deserializeStream = async function* (stream, ctxElm, abortSignal) {
1757
1309
  const lines = buffer.split(/\n/);
1758
1310
  buffer = lines.pop();
1759
1311
  for (const line of lines) {
1760
- const [deserializedData] = _deserialize(line, ctxElm);
1312
+ const deserializedData = _deserialize(line);
1761
1313
  yield deserializedData;
1762
1314
  }
1763
1315
  }
@@ -1765,66 +1317,159 @@ const deserializeStream = async function* (stream, ctxElm, abortSignal) {
1765
1317
  reader.releaseLock();
1766
1318
  }
1767
1319
  };
1768
- const ServiceWorkerRegister = (props) => /* @__PURE__ */ jsx("script", {
1769
- type: "module",
1770
- dangerouslySetInnerHTML: swRegister,
1771
- nonce: props.nonce
1772
- });
1773
- const Form = ({ action, spaReset, reloadDocument, onSubmit$, ...rest }, key) => {
1774
- if (action) {
1775
- const isArrayApi = Array.isArray(onSubmit$);
1776
- if (isArrayApi) {
1777
- return jsx$1("form", {
1778
- ...rest,
1779
- action: action.actionPath,
1780
- "preventdefault:submit": !reloadDocument,
1781
- onSubmit$: [
1782
- ...onSubmit$,
1783
- // action.submit "submitcompleted" event for onSubmitCompleted$ events
1784
- !reloadDocument ? $((evt) => {
1785
- if (!action.submitted) {
1786
- return action.submit(evt);
1787
- }
1788
- }) : void 0
1789
- ],
1790
- method: "post",
1791
- ["data-spa-reset"]: spaReset ? "true" : void 0
1792
- }, key);
1320
+ const serverQrl = (qrl, options) => {
1321
+ if (isServer) {
1322
+ const captured = qrl.getCaptured();
1323
+ if (captured && captured.length > 0 && !_getContextHostElement()) {
1324
+ throw new Error("For security reasons, we cannot serialize QRLs that capture lexical scope.");
1793
1325
  }
1794
- return jsx$1("form", {
1795
- ...rest,
1796
- action: action.actionPath,
1797
- "preventdefault:submit": !reloadDocument,
1798
- onSubmit$: [
1799
- // Since v2, this fires before the action is executed so it can be prevented
1800
- onSubmit$,
1801
- // action.submit "submitcompleted" event for onSubmitCompleted$ events
1802
- !reloadDocument ? action.submit : void 0
1803
- ],
1804
- method: "post",
1805
- ["data-spa-reset"]: spaReset ? "true" : void 0
1806
- }, key);
1807
- } else {
1808
- return /* @__PURE__ */ jsx(GetForm, {
1809
- spaReset,
1810
- reloadDocument,
1811
- onSubmit$,
1812
- ...rest
1813
- }, key);
1814
1326
  }
1327
+ const method = options?.method?.toUpperCase?.() || "POST";
1328
+ const headers = options?.headers || {};
1329
+ const origin = options?.origin || "";
1330
+ const fetchOptions = options?.fetchOptions || {};
1331
+ return /* @__PURE__ */ inlinedQrl(async function(...args) {
1332
+ const fetchOptions2 = _captures[0], headers2 = _captures[1], method2 = _captures[2], origin2 = _captures[3], qrl2 = _captures[4];
1333
+ const abortSignal = args.length > 0 && args[0] instanceof AbortSignal ? args.shift() : void 0;
1334
+ if (isServer) {
1335
+ let requestEvent = _asyncRequestStore?.getStore();
1336
+ if (!requestEvent) {
1337
+ const contexts = [
1338
+ useQwikRouterEnv()?.ev,
1339
+ this,
1340
+ _getContextEvent()
1341
+ ];
1342
+ requestEvent = contexts.find((v2) => v2 && Object.prototype.hasOwnProperty.call(v2, "sharedMap") && Object.prototype.hasOwnProperty.call(v2, "cookie"));
1343
+ }
1344
+ return qrl2.apply(requestEvent, args);
1345
+ } else {
1346
+ let filteredArgs = args.map((arg) => {
1347
+ if (arg instanceof SubmitEvent && arg.target instanceof HTMLFormElement) {
1348
+ return new FormData(arg.target);
1349
+ } else if (arg instanceof Event) {
1350
+ return null;
1351
+ } else if (arg instanceof Node) {
1352
+ return null;
1353
+ }
1354
+ return arg;
1355
+ });
1356
+ if (!filteredArgs.length) {
1357
+ filteredArgs = void 0;
1358
+ }
1359
+ const qrlHash = qrl2.getHash();
1360
+ let query = "";
1361
+ const config = {
1362
+ ...fetchOptions2,
1363
+ method: method2,
1364
+ headers: {
1365
+ ...headers2,
1366
+ "Content-Type": "application/qwik-json",
1367
+ Accept: "application/json, application/qwik-json, text/qwik-json-stream, text/plain",
1368
+ // Required so we don't call accidentally
1369
+ "X-QRL": qrlHash
1370
+ },
1371
+ signal: abortSignal
1372
+ };
1373
+ const captured = qrl2.getCaptured();
1374
+ let toSend = [
1375
+ filteredArgs
1376
+ ];
1377
+ if (captured?.length) {
1378
+ toSend = [
1379
+ filteredArgs,
1380
+ ...captured
1381
+ ];
1382
+ } else {
1383
+ toSend = filteredArgs ? [
1384
+ filteredArgs
1385
+ ] : [];
1386
+ }
1387
+ const body = await _serialize(toSend);
1388
+ if (method2 === "GET") {
1389
+ query += `&${QDATA_KEY}=${encodeURIComponent(body)}`;
1390
+ } else {
1391
+ config.body = body;
1392
+ }
1393
+ const res = await fetch(`${origin2}?${QFN_KEY}=${qrlHash}${query}`, config);
1394
+ const contentType = res.headers.get("Content-Type");
1395
+ if (res.ok && contentType === "text/qwik-json-stream" && res.body) {
1396
+ return (async function* () {
1397
+ try {
1398
+ for await (const result of deserializeStream(res.body, abortSignal)) {
1399
+ yield result;
1400
+ }
1401
+ } finally {
1402
+ if (!abortSignal?.aborted) {
1403
+ await res.body.cancel();
1404
+ }
1405
+ }
1406
+ })();
1407
+ } else if (contentType === "application/qwik-json") {
1408
+ const str = await res.text();
1409
+ const obj = _deserialize(str);
1410
+ if (res.status >= 400) {
1411
+ throw obj;
1412
+ }
1413
+ return obj;
1414
+ } else if (contentType === "application/json") {
1415
+ const obj = await res.json();
1416
+ if (res.status >= 400) {
1417
+ throw obj;
1418
+ }
1419
+ return obj;
1420
+ } else if (contentType === "text/plain" || contentType === "text/html") {
1421
+ const str = await res.text();
1422
+ if (res.status >= 400) {
1423
+ throw str;
1424
+ }
1425
+ return str;
1426
+ }
1427
+ }
1428
+ }, "serverQrl_w03grD0Ag68", [
1429
+ fetchOptions,
1430
+ headers,
1431
+ method,
1432
+ origin,
1433
+ qrl
1434
+ ]);
1815
1435
  };
1816
- const GetForm = component$(({ action: _0, spaReset, reloadDocument, onSubmit$, ...rest }) => {
1436
+ const server$ = /* @__PURE__ */ implicit$FirstArg(serverQrl);
1437
+
1438
+ const ServiceWorkerRegister = (props) => /* @__PURE__ */ _jsxSorted("script", {
1439
+ nonce: _wrapProp(props, "nonce")
1440
+ }, {
1441
+ type: "module",
1442
+ dangerouslySetInnerHTML: swRegister
1443
+ }, null, 3, "1x_0");
1444
+
1445
+ const _hf0 = (p0) => !p0.reloadDocument;
1446
+ const _hf0_str = "!p0.reloadDocument";
1447
+ const _hf1 = (p0) => p0.spaReset ? "true" : void 0;
1448
+ const _hf1_str = 'p0.spaReset?"true":undefined';
1449
+ const GetForm = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((_rawProps) => {
1450
+ const rest = _restProps(_rawProps, [
1451
+ "action",
1452
+ "spaReset",
1453
+ "reloadDocument",
1454
+ "onSubmit$"
1455
+ ]);
1817
1456
  const nav = useNavigate();
1818
- return /* @__PURE__ */ jsx("form", {
1457
+ return /* @__PURE__ */ _jsxSplit("form", {
1819
1458
  action: "get",
1820
- "preventdefault:submit": !reloadDocument,
1821
- "data-spa-reset": spaReset ? "true" : void 0,
1822
- ...rest,
1823
- onSubmit$: [
1824
- ...Array.isArray(onSubmit$) ? onSubmit$ : [
1825
- onSubmit$
1459
+ "preventdefault:submit": _fnSignal(_hf0, [
1460
+ _rawProps
1461
+ ], _hf0_str),
1462
+ "data-spa-reset": _fnSignal(_hf1, [
1463
+ _rawProps
1464
+ ], _hf1_str),
1465
+ ..._getVarProps(rest),
1466
+ ..._getConstProps(rest),
1467
+ "q-e:submit": [
1468
+ ...Array.isArray(_rawProps.onSubmit$) ? _rawProps.onSubmit$ : [
1469
+ _rawProps.onSubmit$
1826
1470
  ],
1827
- $(async (_evt, form) => {
1471
+ /* @__PURE__ */ inlinedQrl(async (_evt, form) => {
1472
+ const nav2 = _captures[0];
1828
1473
  const formData = new FormData(form);
1829
1474
  const params = new URLSearchParams();
1830
1475
  formData.forEach((value, key) => {
@@ -1832,12 +1477,14 @@ const GetForm = component$(({ action: _0, spaReset, reloadDocument, onSubmit$, .
1832
1477
  params.append(key, value);
1833
1478
  }
1834
1479
  });
1835
- await nav("?" + params.toString(), {
1480
+ await nav2("?" + params.toString(), {
1836
1481
  type: "form",
1837
1482
  forceReload: true
1838
1483
  });
1839
- }),
1840
- $((_evt, form) => {
1484
+ }, "GetForm_component_form_q_e_submit_r3dkP9d2cF8", [
1485
+ nav
1486
+ ]),
1487
+ /* @__PURE__ */ inlinedQrl((_evt, form) => {
1841
1488
  if (form.getAttribute("data-spa-reset") === "true") {
1842
1489
  form.reset();
1843
1490
  }
@@ -1849,11 +1496,61 @@ const GetForm = component$(({ action: _0, spaReset, reloadDocument, onSubmit$, .
1849
1496
  status: 200
1850
1497
  }
1851
1498
  }));
1852
- })
1853
- ],
1854
- children: /* @__PURE__ */ jsx(Slot, {})
1855
- });
1856
- });
1499
+ }, "GetForm_component_form_q_e_submit_1_cuYklZAOHrA")
1500
+ ]
1501
+ }, null, /* @__PURE__ */ _jsxSorted(Slot, null, null, null, 3, "Q4_0"), 0, "Q4_1");
1502
+ }, "GetForm_component_2U5Z2Z8ryc0"));
1503
+ const Form = ({ action, spaReset, reloadDocument, onSubmit$, ...rest }, key) => {
1504
+ if (action) {
1505
+ const isArrayApi = Array.isArray(onSubmit$);
1506
+ if (isArrayApi) {
1507
+ return _jsxSplit("form", {
1508
+ ..._getVarProps(rest),
1509
+ ..._getConstProps(rest),
1510
+ action: _wrapProp(action, "actionPath"),
1511
+ "preventdefault:submit": !reloadDocument,
1512
+ "q-e:submit": [
1513
+ ...onSubmit$,
1514
+ // action.submit "submitcompleted" event for onSubmitCompleted$ events
1515
+ !reloadDocument ? /* @__PURE__ */ inlinedQrl((evt) => {
1516
+ const action2 = _captures[0];
1517
+ if (!action2.submitted) {
1518
+ return action2.submit(evt);
1519
+ }
1520
+ }, "Form_form_q_e_submit_6i0Jq5q8JFg", [
1521
+ action
1522
+ ]) : void 0
1523
+ ],
1524
+ ["data-spa-reset"]: spaReset ? "true" : void 0
1525
+ }, {
1526
+ method: "post"
1527
+ }, null, 0, key);
1528
+ }
1529
+ return _jsxSplit("form", {
1530
+ ..._getVarProps(rest),
1531
+ ..._getConstProps(rest),
1532
+ action: _wrapProp(action, "actionPath"),
1533
+ "preventdefault:submit": !reloadDocument,
1534
+ "q-e:submit": [
1535
+ // Since v2, this fires before the action is executed so it can be prevented
1536
+ onSubmit$,
1537
+ // action.submit "submitcompleted" event for onSubmitCompleted$ events
1538
+ !reloadDocument ? action.submit : void 0
1539
+ ],
1540
+ ["data-spa-reset"]: spaReset ? "true" : void 0
1541
+ }, {
1542
+ method: "post"
1543
+ }, null, 0, key);
1544
+ } else {
1545
+ return /* @__PURE__ */ _jsxSplit(GetForm, {
1546
+ spaReset,
1547
+ reloadDocument,
1548
+ onSubmit$,
1549
+ ...rest
1550
+ }, null, null, 0, key);
1551
+ }
1552
+ };
1553
+
1857
1554
  const untypedAppUrl = function appUrl(route, params, paramsPrefix = "") {
1858
1555
  const path = route.split("/");
1859
1556
  for (let i = 0; i < path.length; i++) {
@@ -1890,39 +1587,47 @@ function omitProps(obj, keys) {
1890
1587
  }
1891
1588
  return omittedObj;
1892
1589
  }
1893
- export {
1894
- ErrorBoundary,
1895
- Form,
1896
- Link,
1897
- QWIK_CITY_SCROLLER,
1898
- QWIK_ROUTER_SCROLLER,
1899
- QwikCityMockProvider,
1900
- QwikCityProvider,
1901
- QwikRouterMockProvider,
1902
- QwikRouterProvider,
1903
- RouterOutlet,
1904
- ServiceWorkerRegister,
1905
- globalAction$,
1906
- globalActionQrl,
1907
- omitProps,
1908
- routeAction$,
1909
- routeActionQrl,
1910
- routeLoader$,
1911
- routeLoaderQrl,
1912
- server$,
1913
- serverQrl,
1914
- untypedAppUrl,
1915
- useContent,
1916
- useDocumentHead,
1917
- useLocation,
1918
- useNavigate,
1919
- usePreventNavigate$,
1920
- usePreventNavigateQrl,
1921
- valibot$,
1922
- valibotQrl,
1923
- validator$,
1924
- validatorQrl,
1925
- z2 as z,
1926
- zod$,
1927
- zodQrl
1590
+
1591
+ const createRenderer = (getOptions) => {
1592
+ return (opts) => {
1593
+ const { jsx, options } = getOptions(opts);
1594
+ return renderToStream(jsx, options);
1595
+ };
1928
1596
  };
1597
+
1598
+ const DocumentHeadTags = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
1599
+ let head = useDocumentHead();
1600
+ if (props) {
1601
+ head = {
1602
+ ...head,
1603
+ ...props
1604
+ };
1605
+ }
1606
+ return /* @__PURE__ */ _jsxSorted(Fragment, null, null, [
1607
+ head.title && /* @__PURE__ */ _jsxSorted("title", null, null, head.title, 1, "r5_0"),
1608
+ head.meta.map((m) => /* @__PURE__ */ _jsxSplit("meta", {
1609
+ ..._getVarProps(m)
1610
+ }, _getConstProps(m), null, 0, "r5_1")),
1611
+ head.links.map((l) => /* @__PURE__ */ _jsxSplit("link", {
1612
+ ..._getVarProps(l)
1613
+ }, _getConstProps(l), null, 0, "r5_2")),
1614
+ head.styles.map((s) => {
1615
+ const props2 = s.props || s;
1616
+ return /* @__PURE__ */ createElement("style", {
1617
+ ...props2,
1618
+ dangerouslySetInnerHTML: s.style || props2.dangerouslySetInnerHTML,
1619
+ key: s.key
1620
+ });
1621
+ }),
1622
+ head.scripts.map((s) => {
1623
+ const props2 = s.props || s;
1624
+ return /* @__PURE__ */ createElement("script", {
1625
+ ...props2,
1626
+ dangerouslySetInnerHTML: s.script || props2.dangerouslySetInnerHTML,
1627
+ key: s.key
1628
+ });
1629
+ })
1630
+ ], 1, "r5_3");
1631
+ }, "DocumentHeadTags_component_9CrWYOoCpgY"));
1632
+
1633
+ export { DocumentHeadTags, ErrorBoundary, Form, Link, QWIK_CITY_SCROLLER, QWIK_ROUTER_SCROLLER, QwikCityMockProvider, QwikCityProvider, QwikRouterMockProvider, QwikRouterProvider, RouterOutlet, ServiceWorkerRegister, createRenderer, globalAction$, globalActionQrl, omitProps, routeAction$, routeActionQrl, routeLoader$, routeLoaderQrl, server$, serverQrl, untypedAppUrl, useDocumentHead, useLocation, useNavigate, useQwikRouter, valibot$, valibotQrl, validator$, validatorQrl, zod$, zodQrl };