@qwik.dev/router 2.0.0-beta.11 → 2.0.0-beta.13

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 (140) hide show
  1. package/lib/adapters/azure-swa/vite/index.cjs +61 -5
  2. package/lib/adapters/azure-swa/vite/index.mjs +26 -205
  3. package/lib/adapters/bun-server/vite/index.cjs +27 -5
  4. package/lib/adapters/bun-server/vite/index.mjs +14 -200
  5. package/lib/adapters/cloud-run/vite/index.cjs +24 -5
  6. package/lib/adapters/cloud-run/vite/index.mjs +13 -199
  7. package/lib/adapters/cloudflare-pages/vite/index.cjs +65 -1
  8. package/lib/adapters/cloudflare-pages/vite/index.mjs +63 -4
  9. package/lib/adapters/deno-server/vite/index.cjs +39 -5
  10. package/lib/adapters/deno-server/vite/index.mjs +16 -202
  11. package/lib/adapters/netlify-edge/vite/index.cjs +88 -6
  12. package/lib/adapters/netlify-edge/vite/index.mjs +56 -244
  13. package/lib/adapters/node-server/vite/index.cjs +27 -5
  14. package/lib/adapters/node-server/vite/index.mjs +14 -200
  15. package/lib/adapters/shared/vite/index.cjs +303 -2
  16. package/lib/adapters/shared/vite/index.d.ts +4 -4
  17. package/lib/adapters/shared/vite/index.mjs +248 -147
  18. package/lib/adapters/ssg/vite/index.cjs +19 -5
  19. package/lib/adapters/ssg/vite/index.mjs +11 -197
  20. package/lib/adapters/vercel-edge/vite/index.cjs +81 -5
  21. package/lib/adapters/vercel-edge/vite/index.d.ts +1 -1
  22. package/lib/adapters/vercel-edge/vite/index.mjs +48 -233
  23. package/lib/chunks/error-handler.cjs +58 -0
  24. package/lib/chunks/error-handler.mjs +59 -0
  25. package/lib/chunks/format-error.cjs +136 -0
  26. package/lib/chunks/format-error.mjs +137 -0
  27. package/lib/chunks/fs.cjs +274 -0
  28. package/lib/chunks/fs.mjs +275 -0
  29. package/lib/chunks/index.cjs +877 -0
  30. package/lib/chunks/index.mjs +876 -0
  31. package/lib/chunks/mime-types.cjs +52 -0
  32. package/lib/chunks/mime-types.mjs +53 -0
  33. package/lib/chunks/routing.qwik.cjs +452 -0
  34. package/lib/chunks/routing.qwik.mjs +453 -0
  35. package/lib/chunks/types.qwik.cjs +24 -0
  36. package/lib/chunks/types.qwik.mjs +25 -0
  37. package/lib/index.d.ts +9 -3
  38. package/lib/index.qwik.cjs +530 -994
  39. package/lib/index.qwik.mjs +499 -965
  40. package/lib/middleware/aws-lambda/index.cjs +52 -1
  41. package/lib/middleware/aws-lambda/index.mjs +37 -26
  42. package/lib/middleware/azure-swa/index.cjs +92 -1
  43. package/lib/middleware/azure-swa/index.mjs +64 -46
  44. package/lib/middleware/bun/index.cjs +143 -1
  45. package/lib/middleware/bun/index.mjs +103 -117
  46. package/lib/middleware/cloudflare-pages/index.cjs +96 -1
  47. package/lib/middleware/cloudflare-pages/index.mjs +68 -47
  48. package/lib/middleware/deno/index.cjs +130 -1
  49. package/lib/middleware/deno/index.mjs +93 -112
  50. package/lib/middleware/firebase/index.cjs +33 -1
  51. package/lib/middleware/firebase/index.mjs +25 -16
  52. package/lib/middleware/netlify-edge/index.cjs +71 -1
  53. package/lib/middleware/netlify-edge/index.mjs +52 -36
  54. package/lib/middleware/node/index.cjs +219 -1
  55. package/lib/middleware/node/index.mjs +178 -165
  56. package/lib/middleware/request-handler/index.cjs +1488 -18
  57. package/lib/middleware/request-handler/index.d.ts +20 -2
  58. package/lib/middleware/request-handler/index.mjs +1223 -882
  59. package/lib/middleware/vercel-edge/index.cjs +98 -1
  60. package/lib/middleware/vercel-edge/index.mjs +71 -47
  61. package/lib/service-worker/index.cjs +5 -0
  62. package/lib/service-worker/index.mjs +5 -0
  63. package/lib/ssg/index.cjs +15 -1
  64. package/lib/ssg/index.mjs +12 -19
  65. package/lib/vite/index.cjs +2006 -27
  66. package/lib/vite/index.d.ts +6 -6
  67. package/lib/vite/index.mjs +1592 -1223
  68. package/package.json +9 -8
  69. package/lib/adapters/azure-swa/vite/index-BqUeglYs.cjs +0 -1
  70. package/lib/adapters/azure-swa/vite/index-CBIchDYq.js +0 -651
  71. package/lib/adapters/azure-swa/vite/index-ClHGw5z1.js +0 -6
  72. package/lib/adapters/azure-swa/vite/index-CrwlB95_.js +0 -22
  73. package/lib/adapters/azure-swa/vite/index-DTIOTwZo.cjs +0 -11
  74. package/lib/adapters/azure-swa/vite/index-vQuPcef3.cjs +0 -1
  75. package/lib/adapters/bun-server/vite/index-BqUeglYs.cjs +0 -1
  76. package/lib/adapters/bun-server/vite/index-CBIchDYq.js +0 -651
  77. package/lib/adapters/bun-server/vite/index-ClHGw5z1.js +0 -6
  78. package/lib/adapters/bun-server/vite/index-CrwlB95_.js +0 -22
  79. package/lib/adapters/bun-server/vite/index-DTIOTwZo.cjs +0 -11
  80. package/lib/adapters/bun-server/vite/index-vQuPcef3.cjs +0 -1
  81. package/lib/adapters/cloud-run/vite/index-BqUeglYs.cjs +0 -1
  82. package/lib/adapters/cloud-run/vite/index-CBIchDYq.js +0 -651
  83. package/lib/adapters/cloud-run/vite/index-ClHGw5z1.js +0 -6
  84. package/lib/adapters/cloud-run/vite/index-CrwlB95_.js +0 -22
  85. package/lib/adapters/cloud-run/vite/index-DTIOTwZo.cjs +0 -11
  86. package/lib/adapters/cloud-run/vite/index-vQuPcef3.cjs +0 -1
  87. package/lib/adapters/cloudflare-pages/vite/index-Bg_9YkM5.js +0 -22
  88. package/lib/adapters/cloudflare-pages/vite/index-C1aDmh1S.cjs +0 -1
  89. package/lib/adapters/cloudflare-pages/vite/index-CHT9Y93A.js +0 -254
  90. package/lib/adapters/cloudflare-pages/vite/index-Ck7KvpK1.cjs +0 -11
  91. package/lib/adapters/cloudflare-pages/vite/index-ClHGw5z1.js +0 -6
  92. package/lib/adapters/cloudflare-pages/vite/index-Cp1cjAds.js +0 -645
  93. package/lib/adapters/cloudflare-pages/vite/index-D9RL9dvJ.cjs +0 -5
  94. package/lib/adapters/cloudflare-pages/vite/index-vQuPcef3.cjs +0 -1
  95. package/lib/adapters/deno-server/vite/index-BqUeglYs.cjs +0 -1
  96. package/lib/adapters/deno-server/vite/index-CBIchDYq.js +0 -651
  97. package/lib/adapters/deno-server/vite/index-ClHGw5z1.js +0 -6
  98. package/lib/adapters/deno-server/vite/index-CrwlB95_.js +0 -22
  99. package/lib/adapters/deno-server/vite/index-DTIOTwZo.cjs +0 -11
  100. package/lib/adapters/deno-server/vite/index-vQuPcef3.cjs +0 -1
  101. package/lib/adapters/netlify-edge/vite/index-BqUeglYs.cjs +0 -1
  102. package/lib/adapters/netlify-edge/vite/index-CBIchDYq.js +0 -651
  103. package/lib/adapters/netlify-edge/vite/index-ClHGw5z1.js +0 -6
  104. package/lib/adapters/netlify-edge/vite/index-CrwlB95_.js +0 -22
  105. package/lib/adapters/netlify-edge/vite/index-DTIOTwZo.cjs +0 -11
  106. package/lib/adapters/netlify-edge/vite/index-vQuPcef3.cjs +0 -1
  107. package/lib/adapters/node-server/vite/index-BqUeglYs.cjs +0 -1
  108. package/lib/adapters/node-server/vite/index-CBIchDYq.js +0 -651
  109. package/lib/adapters/node-server/vite/index-ClHGw5z1.js +0 -6
  110. package/lib/adapters/node-server/vite/index-CrwlB95_.js +0 -22
  111. package/lib/adapters/node-server/vite/index-DTIOTwZo.cjs +0 -11
  112. package/lib/adapters/node-server/vite/index-vQuPcef3.cjs +0 -1
  113. package/lib/adapters/shared/vite/index-BqUeglYs.cjs +0 -1
  114. package/lib/adapters/shared/vite/index-CBIchDYq.js +0 -651
  115. package/lib/adapters/shared/vite/index-ClHGw5z1.js +0 -6
  116. package/lib/adapters/shared/vite/index-CrwlB95_.js +0 -22
  117. package/lib/adapters/shared/vite/index-DTIOTwZo.cjs +0 -11
  118. package/lib/adapters/shared/vite/index-vQuPcef3.cjs +0 -1
  119. package/lib/adapters/ssg/vite/index-BqUeglYs.cjs +0 -1
  120. package/lib/adapters/ssg/vite/index-CBIchDYq.js +0 -651
  121. package/lib/adapters/ssg/vite/index-ClHGw5z1.js +0 -6
  122. package/lib/adapters/ssg/vite/index-CrwlB95_.js +0 -22
  123. package/lib/adapters/ssg/vite/index-DTIOTwZo.cjs +0 -11
  124. package/lib/adapters/ssg/vite/index-vQuPcef3.cjs +0 -1
  125. package/lib/adapters/vercel-edge/vite/index-BqUeglYs.cjs +0 -1
  126. package/lib/adapters/vercel-edge/vite/index-CBIchDYq.js +0 -651
  127. package/lib/adapters/vercel-edge/vite/index-ClHGw5z1.js +0 -6
  128. package/lib/adapters/vercel-edge/vite/index-CrwlB95_.js +0 -22
  129. package/lib/adapters/vercel-edge/vite/index-DTIOTwZo.cjs +0 -11
  130. package/lib/adapters/vercel-edge/vite/index-vQuPcef3.cjs +0 -1
  131. package/lib/service-worker.cjs +0 -1
  132. package/lib/service-worker.mjs +0 -5
  133. package/lib/ssg/deno.cjs +0 -1
  134. package/lib/ssg/deno.mjs +0 -6
  135. package/lib/ssg/index-CBIchDYq.js +0 -651
  136. package/lib/ssg/index-ClHGw5z1.js +0 -6
  137. package/lib/ssg/index-DTIOTwZo.cjs +0 -11
  138. package/lib/ssg/index-vQuPcef3.cjs +0 -1
  139. package/lib/ssg/node.cjs +0 -11
  140. package/lib/ssg/node.mjs +0 -651
@@ -2,12 +2,16 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("@qwik.dev/core/jsx-runtime");
4
4
  const core = require("@qwik.dev/core");
5
- const preloader = require("@qwik.dev/core/preloader");
6
- const internal = require("@qwik.dev/core/internal");
5
+ const routing = require("./chunks/routing.qwik.cjs");
7
6
  const qwikRouterConfig = require("@qwik-router-config");
8
- const zod = require("zod");
7
+ const internal = require("@qwik.dev/core/internal");
8
+ const requestHandler = require("@qwik.dev/router/middleware/request-handler");
9
+ const v = require("valibot");
10
+ const z = require("zod");
9
11
  const swRegister = require("@qwik-router-sw-register");
10
12
  const server = require("@qwik.dev/core/server");
13
+ require("@qwik.dev/core/preloader");
14
+ require("./chunks/types.qwik.cjs");
11
15
  function _interopNamespaceDefault(e) {
12
16
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
13
17
  if (e) {
@@ -25,231 +29,21 @@ function _interopNamespaceDefault(e) {
25
29
  return Object.freeze(n);
26
30
  }
27
31
  const qwikRouterConfig__namespace = /* @__PURE__ */ _interopNamespaceDefault(qwikRouterConfig);
32
+ const v__namespace = /* @__PURE__ */ _interopNamespaceDefault(v);
33
+ const z__namespace = /* @__PURE__ */ _interopNamespaceDefault(z);
28
34
  const ErrorBoundary = core.component$((props) => {
29
- const store2 = core.useErrorBoundary();
30
- core.useOnWindow("qerror", core.$((e) => {
31
- store2.error = e.detail.error;
32
- }));
33
- if (store2.error && props.fallback$) {
34
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
35
- children: props.fallback$(store2.error)
36
- });
35
+ const store = core.useErrorBoundary();
36
+ core.useOnWindow(
37
+ "qerror",
38
+ core.$((e) => {
39
+ store.error = e.detail.error;
40
+ })
41
+ );
42
+ if (store.error && props.fallback$) {
43
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.fallback$(store.error) });
37
44
  }
38
45
  return /* @__PURE__ */ jsxRuntime.jsx(core.Slot, {});
39
46
  });
40
- const MODULE_CACHE = /* @__PURE__ */ new WeakMap();
41
- const CLIENT_DATA_CACHE = /* @__PURE__ */ new Map();
42
- const QACTION_KEY = "qaction";
43
- const QLOADER_KEY = "qloaders";
44
- const QFN_KEY = "qfunc";
45
- const QDATA_KEY = "qdata";
46
- const Q_ROUTE = "q:route";
47
- const DEFAULT_LOADERS_SERIALIZATION_STRATEGY = globalThis.__DEFAULT_LOADERS_SERIALIZATION_STRATEGY__ || "never";
48
- const MAX_Q_DATA_RETRY_COUNT = 3;
49
- const loadClientData = async (url, element, opts, retryCount = 0) => {
50
- const pagePathname = url.pathname;
51
- const pageSearch = url.search;
52
- const clientDataPath = getClientDataPath(pagePathname, pageSearch, {
53
- actionId: opts?.action?.id,
54
- loaderIds: opts?.loaderIds
55
- });
56
- let qData;
57
- if (!opts?.action) {
58
- qData = CLIENT_DATA_CACHE.get(clientDataPath);
59
- }
60
- if (opts?.preloadRouteBundles !== false) {
61
- preloadRouteBundles(pagePathname, 0.8);
62
- }
63
- let resolveFn;
64
- if (!qData) {
65
- const fetchOptions = getFetchOptions(opts?.action, opts?.clearCache);
66
- if (opts?.action) {
67
- opts.action.data = void 0;
68
- }
69
- qData = fetch(clientDataPath, fetchOptions).then((rsp) => {
70
- if (rsp.status === 404 && opts?.loaderIds && retryCount < MAX_Q_DATA_RETRY_COUNT) {
71
- opts.loaderIds = void 0;
72
- return loadClientData(url, element, opts, retryCount + 1);
73
- }
74
- if (rsp.redirected) {
75
- const redirectedURL = new URL(rsp.url);
76
- const isQData = redirectedURL.pathname.endsWith("/q-data.json");
77
- if (!isQData || redirectedURL.origin !== location.origin) {
78
- if (!opts?.isPrefetch) {
79
- location.href = redirectedURL.href;
80
- }
81
- return;
82
- }
83
- }
84
- if ((rsp.headers.get("content-type") || "").includes("json")) {
85
- return rsp.text().then((text) => {
86
- const [clientData] = internal._deserialize(text, element);
87
- if (!clientData) {
88
- location.href = url.href;
89
- return;
90
- }
91
- if (opts?.clearCache) {
92
- CLIENT_DATA_CACHE.delete(clientDataPath);
93
- }
94
- if (clientData.redirect) {
95
- location.href = clientData.redirect;
96
- } else if (opts?.action) {
97
- const { action } = opts;
98
- const actionData = clientData.loaders[action.id];
99
- resolveFn = () => {
100
- action.resolve({
101
- status: rsp.status,
102
- result: actionData
103
- });
104
- };
105
- }
106
- return clientData;
107
- });
108
- } else {
109
- if (opts?.isPrefetch !== true) {
110
- location.href = url.href;
111
- }
112
- return void 0;
113
- }
114
- });
115
- if (!opts?.action) {
116
- CLIENT_DATA_CACHE.set(clientDataPath, qData);
117
- }
118
- }
119
- return qData.then((v) => {
120
- if (!v) {
121
- CLIENT_DATA_CACHE.delete(clientDataPath);
122
- }
123
- resolveFn && resolveFn();
124
- return v;
125
- });
126
- };
127
- const getFetchOptions = (action, noCache) => {
128
- const actionData = action?.data;
129
- if (!actionData) {
130
- if (noCache) {
131
- return {
132
- cache: "no-cache",
133
- headers: {
134
- "Cache-Control": "no-cache",
135
- Pragma: "no-cache"
136
- }
137
- };
138
- }
139
- return void 0;
140
- }
141
- if (actionData instanceof FormData) {
142
- return {
143
- method: "POST",
144
- body: actionData
145
- };
146
- } else {
147
- return {
148
- method: "POST",
149
- body: JSON.stringify(actionData),
150
- headers: {
151
- "Content-Type": "application/json; charset=UTF-8"
152
- }
153
- };
154
- }
155
- };
156
- const toPath = (url) => url.pathname + url.search + url.hash;
157
- const toUrl = (url, baseUrl) => new URL(url, baseUrl.href);
158
- const isSameOrigin = (a, b) => a.origin === b.origin;
159
- const withSlash = (path) => path.endsWith("/") ? path : path + "/";
160
- const isSamePathname = ({ pathname: a }, { pathname: b }) => {
161
- const lDiff = Math.abs(a.length - b.length);
162
- return lDiff === 0 ? a === b : lDiff === 1 && withSlash(a) === withSlash(b);
163
- };
164
- const isSameSearchQuery = (a, b) => a.search === b.search;
165
- const isSamePath = (a, b) => isSameSearchQuery(a, b) && isSamePathname(a, b);
166
- const getClientDataPath = (pathname, pageSearch, options) => {
167
- let search = pageSearch ?? "";
168
- if (options?.actionId) {
169
- search += (search ? "&" : "?") + QACTION_KEY + "=" + encodeURIComponent(options.actionId);
170
- }
171
- if (options?.loaderIds) {
172
- for (const loaderId of options.loaderIds) {
173
- search += (search ? "&" : "?") + QLOADER_KEY + "=" + encodeURIComponent(loaderId);
174
- }
175
- }
176
- return pathname + (pathname.endsWith("/") ? "" : "/") + "q-data.json" + search;
177
- };
178
- const getClientNavPath = (props, baseUrl) => {
179
- const href = props.href;
180
- if (typeof href === "string" && typeof props.target !== "string" && !props.reload) {
181
- try {
182
- const linkUrl = toUrl(href.trim(), baseUrl.url);
183
- const currentUrl = toUrl("", baseUrl.url);
184
- if (isSameOrigin(linkUrl, currentUrl)) {
185
- return toPath(linkUrl);
186
- }
187
- } catch (e) {
188
- console.error(e);
189
- }
190
- } else if (props.reload) {
191
- return toPath(toUrl("", baseUrl.url));
192
- }
193
- return null;
194
- };
195
- const shouldPreload = (clientNavPath, currentLoc) => {
196
- if (clientNavPath) {
197
- const prefetchUrl = toUrl(clientNavPath, currentLoc.url);
198
- const currentUrl = toUrl("", currentLoc.url);
199
- return !isSamePathname(prefetchUrl, currentUrl);
200
- }
201
- return false;
202
- };
203
- const isPromise = (value) => {
204
- return value && typeof value.then === "function";
205
- };
206
- const createLoaderSignal = (loadersObject, loaderId, url, serializationStrategy, container) => {
207
- return core.createAsyncComputed$(async () => {
208
- if (core.isBrowser && loadersObject[loaderId] === internal._UNINITIALIZED) {
209
- const data = await loadClientData(url, void 0, {
210
- loaderIds: [
211
- loaderId
212
- ]
213
- });
214
- loadersObject[loaderId] = data?.loaders[loaderId] ?? internal._UNINITIALIZED;
215
- }
216
- return loadersObject[loaderId];
217
- }, {
218
- container,
219
- serializationStrategy
220
- });
221
- };
222
- const clientNavigate = (win, navType, fromURL, toURL, replaceState = false) => {
223
- if (navType !== "popstate") {
224
- const samePath = isSamePath(fromURL, toURL);
225
- const sameHash = fromURL.hash === toURL.hash;
226
- if (!samePath || !sameHash) {
227
- const newState = {
228
- _qRouterScroll: newScrollState()
229
- };
230
- if (replaceState) {
231
- win.history.replaceState(newState, "", toPath(toURL));
232
- } else {
233
- win.history.pushState(newState, "", toPath(toURL));
234
- }
235
- }
236
- }
237
- };
238
- const newScrollState = () => {
239
- return {
240
- x: 0,
241
- y: 0,
242
- w: 0,
243
- h: 0
244
- };
245
- };
246
- const preloadRouteBundles = (path, probability = 0.8) => {
247
- if (core.isBrowser) {
248
- path = path.endsWith("/") ? path : path + "/";
249
- path = path.length > 1 && path.startsWith("/") ? path.slice(1) : path;
250
- preloader.p(path, probability);
251
- }
252
- };
253
47
  const RouteStateContext = /* @__PURE__ */ core.createContextId("qc-s");
254
48
  const ContentContext = /* @__PURE__ */ core.createContextId("qc-c");
255
49
  const ContentInternalContext = /* @__PURE__ */ core.createContextId("qc-ic");
@@ -257,7 +51,6 @@ const DocumentHeadContext = /* @__PURE__ */ core.createContextId("qc-h");
257
51
  const RouteLocationContext = /* @__PURE__ */ core.createContextId("qc-l");
258
52
  const RouteNavigateContext = /* @__PURE__ */ core.createContextId("qc-n");
259
53
  const RouteActionContext = /* @__PURE__ */ core.createContextId("qc-a");
260
- const RouteInternalContext = /* @__PURE__ */ core.createContextId("qc-ir");
261
54
  const RoutePreventNavigateContext = /* @__PURE__ */ core.createContextId("qc-p");
262
55
  const useContent = () => core.useContext(ContentContext);
263
56
  const useDocumentHead = () => core.useContext(DocumentHeadContext);
@@ -265,7 +58,9 @@ const useLocation = () => core.useContext(RouteLocationContext);
265
58
  const useNavigate = () => core.useContext(RouteNavigateContext);
266
59
  const usePreventNavigateQrl = (fn) => {
267
60
  if (!__EXPERIMENTAL__.preventNavigate) {
268
- throw new Error('usePreventNavigate$ is experimental and must be enabled with `experimental: ["preventNavigate"]` in the `qwikVite` plugin.');
61
+ throw new Error(
62
+ 'usePreventNavigate$ is experimental and must be enabled with `experimental: ["preventNavigate"]` in the `qwikVite` plugin.'
63
+ );
269
64
  }
270
65
  const registerPreventNav = core.useContext(RoutePreventNavigateContext);
271
66
  core.useVisibleTask$(() => registerPreventNav(fn));
@@ -278,23 +73,31 @@ const Link = core.component$((props) => {
278
73
  const loc = useLocation();
279
74
  const originalHref = props.href;
280
75
  const anchorRef = core.useSignal();
281
- const { onClick$, prefetch: prefetchProp, reload, replaceState, scroll, ...linkProps } = /* @__PURE__ */ (() => props)();
282
- const clientNavPath = core.untrack(() => getClientNavPath({
283
- ...linkProps,
284
- reload
285
- }, loc));
76
+ const {
77
+ onClick$,
78
+ prefetch: prefetchProp,
79
+ reload,
80
+ replaceState,
81
+ scroll,
82
+ ...linkProps
83
+ } = /* @__PURE__ */ (() => props)();
84
+ const clientNavPath = core.untrack(() => routing.getClientNavPath({ ...linkProps, reload }, loc));
286
85
  linkProps.href = clientNavPath || originalHref;
287
- const prefetchData = core.untrack(() => !!clientNavPath && prefetchProp !== false && prefetchProp !== "js" || void 0);
288
- const prefetch = core.untrack(() => prefetchData || !!clientNavPath && prefetchProp !== false && shouldPreload(clientNavPath, loc));
86
+ const prefetchData = core.untrack(
87
+ () => !!clientNavPath && prefetchProp !== false && prefetchProp !== "js" || void 0
88
+ );
89
+ const prefetch = core.untrack(
90
+ () => prefetchData || !!clientNavPath && prefetchProp !== false && routing.shouldPreload(clientNavPath, loc)
91
+ );
289
92
  const handlePrefetch = prefetch ? core.$((_, elm) => {
290
93
  if (navigator.connection?.saveData) {
291
94
  return;
292
95
  }
293
96
  if (elm && elm.href) {
294
97
  const url = new URL(elm.href);
295
- preloadRouteBundles(url.pathname);
98
+ routing.preloadRouteBundles(url.pathname);
296
99
  if (elm.hasAttribute("data-prefetch")) {
297
- loadClientData(url, elm, {
100
+ routing.loadClientData(url, elm, {
298
101
  preloadRouteBundles: false,
299
102
  isPrefetch: true
300
103
  });
@@ -310,11 +113,7 @@ const Link = core.component$((props) => {
310
113
  if (event.defaultPrevented) {
311
114
  if (elm.href) {
312
115
  elm.setAttribute("aria-pressed", "true");
313
- nav(elm.href, {
314
- forceReload: reload,
315
- replaceState,
316
- scroll
317
- }).then(() => {
116
+ nav(elm.href, { forceReload: reload, replaceState, scroll }).then(() => {
318
117
  elm.removeAttribute("aria-pressed");
319
118
  });
320
119
  }
@@ -322,7 +121,7 @@ const Link = core.component$((props) => {
322
121
  }) : void 0;
323
122
  const handlePreload = core.$((_, elm) => {
324
123
  const url = new URL(elm.href);
325
- preloadRouteBundles(url.pathname, 1);
124
+ routing.preloadRouteBundles(url.pathname, 1);
326
125
  });
327
126
  core.useVisibleTask$(({ track }) => {
328
127
  track(() => loc.url.pathname);
@@ -330,7 +129,9 @@ const Link = core.component$((props) => {
330
129
  if (handler) {
331
130
  const event = new CustomEvent("qvisible");
332
131
  if (Array.isArray(handler)) {
333
- handler.flat(10).forEach((handler2) => handler2?.(event, anchorRef.value));
132
+ handler.flat(10).forEach(
133
+ (handler2) => handler2?.(event, anchorRef.value)
134
+ );
334
135
  } else {
335
136
  handler?.(event, anchorRef.value);
336
137
  }
@@ -339,45 +140,44 @@ const Link = core.component$((props) => {
339
140
  handlePrefetch?.(void 0, anchorRef.value);
340
141
  }
341
142
  });
342
- return /* @__PURE__ */ jsxRuntime.jsx("a", {
343
- ref: anchorRef,
344
- "q:link": !!clientNavPath,
345
- ...linkProps,
346
- onClick$: [
347
- preventDefault,
348
- handlePreload,
349
- onClick$,
350
- handleClientSideNavigation
351
- ],
352
- "data-prefetch": prefetchData,
353
- onMouseOver$: [
354
- linkProps.onMouseOver$,
355
- handlePrefetch
356
- ],
357
- onFocus$: [
358
- linkProps.onFocus$,
359
- handlePrefetch
360
- ],
361
- // We need to prevent the onQVisible$ from being called twice since it is handled in the visible task
362
- onQVisible$: [],
363
- children: /* @__PURE__ */ jsxRuntime.jsx(core.Slot, {})
364
- });
143
+ return /* @__PURE__ */ jsxRuntime.jsx(
144
+ "a",
145
+ {
146
+ ref: anchorRef,
147
+ ...{ "q:link": !!clientNavPath },
148
+ ...linkProps,
149
+ onClick$: [
150
+ preventDefault,
151
+ handlePreload,
152
+ // needs to be in between preventDefault and onClick$ to ensure it starts asap.
153
+ onClick$,
154
+ handleClientSideNavigation
155
+ ],
156
+ "data-prefetch": prefetchData,
157
+ onMouseOver$: [linkProps.onMouseOver$, handlePrefetch],
158
+ onFocus$: [linkProps.onFocus$, handlePrefetch],
159
+ onQVisible$: [],
160
+ children: /* @__PURE__ */ jsxRuntime.jsx(core.Slot, {})
161
+ }
162
+ );
365
163
  });
366
- const resolveHead = (endpoint, routeLocation, contentModules, locale, defaults) => {
164
+ const resolveHead = (endpoint, routeLocation, contentModules, locale, defaults) => core.withLocale(locale, () => {
367
165
  const head = createDocumentHead(defaults);
368
- const getData = (loaderOrAction) => {
166
+ const getData = ((loaderOrAction) => {
369
167
  const id = loaderOrAction.__id;
370
168
  if (loaderOrAction.__brand === "server_loader") {
371
169
  if (!(id in endpoint.loaders)) {
372
- throw new Error("You can not get the returned data of a loader that has not been executed for this request.");
170
+ throw new Error(
171
+ "You can not get the returned data of a loader that has not been executed for this request."
172
+ );
373
173
  }
374
174
  }
375
175
  const data = endpoint.loaders[id];
376
- if (isPromise(data)) {
176
+ if (routing.isPromise(data)) {
377
177
  throw new Error("Loaders returning a promise can not be resolved for the head function.");
378
178
  }
379
179
  return data;
380
- };
180
+ });
381
181
  const fns = [];
382
182
  for (const contentModule of contentModules) {
383
183
  const contentModuleHead = contentModule?.head;
@@ -392,18 +192,16 @@ const resolveHead = (endpoint, routeLocation, contentModules, locale, defaults)
392
192
  if (fns.length) {
393
193
  const headProps = {
394
194
  head,
395
- withLocale: (fn) => core.withLocale(locale, fn),
195
+ withLocale: (fn) => fn(),
396
196
  resolveValue: getData,
397
197
  ...routeLocation
398
198
  };
399
- core.withLocale(locale, () => {
400
- for (const fn of fns) {
401
- resolveDocumentHead(head, fn(headProps));
402
- }
403
- });
199
+ for (const fn of fns) {
200
+ resolveDocumentHead(head, fn(headProps));
201
+ }
404
202
  }
405
203
  return head;
406
- };
204
+ });
407
205
  const resolveDocumentHead = (resolvedHead, updatedHead) => {
408
206
  if (typeof updatedHead.title === "string") {
409
207
  resolvedHead.title = updatedHead.title;
@@ -430,244 +228,34 @@ const mergeArray = (existingArr, newArr) => {
430
228
  };
431
229
  const createDocumentHead = (defaults) => ({
432
230
  title: defaults?.title || "",
433
- meta: [
434
- ...defaults?.meta || []
435
- ],
436
- links: [
437
- ...defaults?.links || []
438
- ],
439
- styles: [
440
- ...defaults?.styles || []
441
- ],
442
- scripts: [
443
- ...defaults?.scripts || []
444
- ],
445
- frontmatter: {
446
- ...defaults?.frontmatter
447
- }
231
+ meta: [...defaults?.meta || []],
232
+ links: [...defaults?.links || []],
233
+ styles: [...defaults?.styles || []],
234
+ scripts: [...defaults?.scripts || []],
235
+ frontmatter: { ...defaults?.frontmatter }
448
236
  });
449
- function matchRoute(route, path) {
450
- const routeIdx = startIdxSkipSlash(route);
451
- const routeLength = lengthNoTrailingSlash(route);
452
- const pathIdx = startIdxSkipSlash(path);
453
- const pathLength = lengthNoTrailingSlash(path);
454
- return matchRoutePart(route, routeIdx, routeLength, path, pathIdx, pathLength);
455
- }
456
- function matchRoutePart(route, routeIdx, routeLength, path, pathIdx, pathLength) {
457
- if (path.startsWith("/build/")) {
458
- return null;
459
- }
460
- let params = null;
461
- while (routeIdx < routeLength) {
462
- const routeCh = route.charCodeAt(routeIdx++);
463
- const pathCh = path.charCodeAt(pathIdx++);
464
- if (routeCh === 91) {
465
- const isMany = isThreeDots(route, routeIdx);
466
- const paramNameStart = routeIdx + (isMany ? 3 : 0);
467
- const paramNameEnd = scan(route, paramNameStart, routeLength, 93);
468
- const paramName = route.substring(paramNameStart, paramNameEnd);
469
- const paramSuffixEnd = scan(route, paramNameEnd + 1, routeLength, 47);
470
- const suffix = route.substring(paramNameEnd + 1, paramSuffixEnd);
471
- routeIdx = paramNameEnd + 1;
472
- const paramValueStart = pathIdx - 1;
473
- if (isMany) {
474
- const match = recursiveScan(paramName, suffix, path, paramValueStart, pathLength, route, routeIdx + suffix.length + 1, routeLength);
475
- if (match) {
476
- return Object.assign(params || (params = {}), match);
477
- }
478
- }
479
- const paramValueEnd = scan(path, paramValueStart, pathLength, 47, suffix);
480
- if (paramValueEnd == -1) {
481
- return null;
482
- }
483
- const paramValue = path.substring(paramValueStart, paramValueEnd);
484
- if (!isMany && !suffix && !paramValue) {
485
- return null;
486
- }
487
- pathIdx = paramValueEnd;
488
- (params || (params = {}))[paramName] = decodeURIComponent(paramValue);
489
- } else if (routeCh !== pathCh) {
490
- if (!(isNaN(pathCh) && isRestParameter(route, routeIdx))) {
491
- return null;
492
- }
493
- }
494
- }
495
- if (allConsumed(route, routeIdx) && allConsumed(path, pathIdx)) {
496
- return params || {};
497
- } else {
498
- return null;
499
- }
500
- }
501
- function isRestParameter(text, idx) {
502
- return text.charCodeAt(idx) === 91 && isThreeDots(text, idx + 1);
503
- }
504
- function lengthNoTrailingSlash(text) {
505
- const length = text.length;
506
- return length > 1 && text.charCodeAt(length - 1) === 47 ? length - 1 : length;
507
- }
508
- function allConsumed(text, idx) {
509
- const length = text.length;
510
- return idx >= length || idx == length - 1 && text.charCodeAt(idx) === 47;
511
- }
512
- function startIdxSkipSlash(text) {
513
- return text.charCodeAt(0) === 47 ? 1 : 0;
514
- }
515
- function isThreeDots(text, idx) {
516
- return text.charCodeAt(idx) === 46 && text.charCodeAt(idx + 1) === 46 && text.charCodeAt(idx + 2) === 46;
517
- }
518
- function scan(text, idx, end, ch, suffix = "") {
519
- while (idx < end && text.charCodeAt(idx) !== ch) {
520
- idx++;
521
- }
522
- const suffixLength = suffix.length;
523
- for (let i = 0; i < suffixLength; i++) {
524
- if (text.charCodeAt(idx - suffixLength + i) !== suffix.charCodeAt(i)) {
525
- return -1;
526
- }
527
- }
528
- return idx - suffixLength;
529
- }
530
- function recursiveScan(paramName, suffix, path, pathStart, pathLength, route, routeStart, routeLength) {
531
- if (path.charCodeAt(pathStart) === 47) {
532
- pathStart++;
533
- }
534
- let pathIdx = pathLength;
535
- const sep = suffix + "/";
536
- while (pathIdx >= pathStart) {
537
- const match = matchRoutePart(route, routeStart, routeLength, path, pathIdx, pathLength);
538
- if (match) {
539
- let value = path.substring(pathStart, Math.min(pathIdx, pathLength));
540
- if (value.endsWith(sep)) {
541
- value = value.substring(0, value.length - sep.length);
542
- }
543
- match[paramName] = decodeURIComponent(value);
544
- return match;
545
- }
546
- const newPathIdx = lastIndexOf(path, pathStart, sep, pathIdx, pathStart - 1) + sep.length;
547
- if (pathIdx === newPathIdx) {
548
- break;
549
- }
550
- pathIdx = newPathIdx;
551
- }
552
- return null;
553
- }
554
- function lastIndexOf(text, start, match, searchIdx, notFoundIdx) {
555
- let idx = text.lastIndexOf(match, searchIdx);
556
- if (idx == searchIdx - match.length) {
557
- idx = text.lastIndexOf(match, searchIdx - match.length - 1);
558
- }
559
- return idx > start ? idx : notFoundIdx;
560
- }
561
- var RouteDataProp = /* @__PURE__ */ (function(RouteDataProp2) {
562
- RouteDataProp2[RouteDataProp2["RouteName"] = 0] = "RouteName";
563
- RouteDataProp2[RouteDataProp2["Loaders"] = 1] = "Loaders";
564
- RouteDataProp2[RouteDataProp2["OriginalPathname"] = 2] = "OriginalPathname";
565
- RouteDataProp2[RouteDataProp2["RouteBundleNames"] = 3] = "RouteBundleNames";
566
- return RouteDataProp2;
567
- })({});
568
- var MenuDataProp = /* @__PURE__ */ (function(MenuDataProp2) {
569
- MenuDataProp2[MenuDataProp2["Pathname"] = 0] = "Pathname";
570
- MenuDataProp2[MenuDataProp2["MenuLoader"] = 1] = "MenuLoader";
571
- return MenuDataProp2;
572
- })({});
573
- const deepFreeze = (obj) => {
574
- if (obj == null) {
575
- return obj;
576
- }
577
- Object.getOwnPropertyNames(obj).forEach((prop) => {
578
- const value = obj[prop];
579
- if (value && typeof value === "object" && !Object.isFrozen(value)) {
580
- deepFreeze(value);
581
- }
582
- });
583
- return Object.freeze(obj);
584
- };
585
- const loadRoute = async (routes, menus, cacheModules, pathname, isInternal) => {
586
- if (!Array.isArray(routes)) {
587
- return null;
588
- }
589
- for (const routeData of routes) {
590
- const routeName = routeData[RouteDataProp.RouteName];
591
- const params = matchRoute(routeName, pathname);
592
- if (!params) {
593
- continue;
594
- }
595
- const loaders = routeData[RouteDataProp.Loaders];
596
- const routeBundleNames = routeData[RouteDataProp.RouteBundleNames];
597
- const modules = new Array(loaders.length);
598
- const pendingLoads = [];
599
- loaders.forEach((moduleLoader, i) => {
600
- loadModule(moduleLoader, pendingLoads, (routeModule) => modules[i] = routeModule, cacheModules);
601
- });
602
- let menu = void 0;
603
- {
604
- const menuLoader = getMenuLoader(menus, pathname);
605
- loadModule(menuLoader, pendingLoads, (menuModule) => menu = menuModule?.default, cacheModules);
606
- }
607
- if (pendingLoads.length > 0) {
608
- await Promise.all(pendingLoads);
609
- }
610
- return [
611
- routeName,
612
- params,
613
- modules,
614
- deepFreeze(menu),
615
- routeBundleNames
616
- ];
617
- }
618
- return null;
619
- };
620
- const loadModule = (moduleLoader, pendingLoads, moduleSetter, cacheModules) => {
621
- if (typeof moduleLoader === "function") {
622
- const loadedModule = MODULE_CACHE.get(moduleLoader);
623
- if (loadedModule) {
624
- moduleSetter(loadedModule);
625
- } else {
626
- const moduleOrPromise = moduleLoader();
627
- if (typeof moduleOrPromise.then === "function") {
628
- pendingLoads.push(moduleOrPromise.then((loadedModule2) => {
629
- if (cacheModules !== false) {
630
- MODULE_CACHE.set(moduleLoader, loadedModule2);
631
- }
632
- moduleSetter(loadedModule2);
633
- }));
634
- } else if (moduleOrPromise) {
635
- moduleSetter(moduleOrPromise);
636
- }
637
- }
638
- }
639
- };
640
- const getMenuLoader = (menus, pathname) => {
641
- if (menus) {
642
- pathname = pathname.endsWith("/") ? pathname : pathname + "/";
643
- const menu = menus.find((m) => m[MenuDataProp.Pathname] === pathname || pathname.startsWith(m[MenuDataProp.Pathname]));
644
- if (menu) {
645
- return menu[MenuDataProp.MenuLoader];
646
- }
647
- }
648
- };
649
237
  function callRestoreScrollOnDocument() {
650
238
  if (document.__q_scroll_restore__) {
651
239
  document.__q_scroll_restore__();
652
240
  document.__q_scroll_restore__ = void 0;
653
241
  }
654
242
  }
655
- const restoreScroll = (type, toUrl2, fromUrl, scroller, scrollState) => {
243
+ const restoreScroll = (type, toUrl, fromUrl, scroller, scrollState) => {
656
244
  if (type === "popstate" && scrollState) {
657
245
  scroller.scrollTo(scrollState.x, scrollState.y);
658
246
  } else if (type === "link" || type === "form") {
659
- if (!hashScroll(toUrl2, fromUrl)) {
247
+ if (!hashScroll(toUrl, fromUrl)) {
660
248
  scroller.scrollTo(0, 0);
661
249
  }
662
250
  }
663
251
  };
664
- const hashScroll = (toUrl2, fromUrl) => {
665
- const elmId = toUrl2.hash.slice(1);
252
+ const hashScroll = (toUrl, fromUrl) => {
253
+ const elmId = toUrl.hash.slice(1);
666
254
  const elm = elmId && document.getElementById(elmId);
667
255
  if (elm) {
668
256
  elm.scrollIntoView();
669
257
  return true;
670
- } else if (!elm && toUrl2.hash && isSamePath(toUrl2, fromUrl)) {
258
+ } else if (!elm && toUrl.hash && routing.isSamePath(toUrl, fromUrl)) {
671
259
  return true;
672
260
  }
673
261
  return false;
@@ -690,21 +278,11 @@ const saveScrollHistory = (scrollState) => {
690
278
  history.replaceState(state, "");
691
279
  };
692
280
  const spaInit = core.event$((_, el) => {
693
- const win = window;
694
- const spa = "_qRouterSPA";
695
- const initPopstate = "_qRouterInitPopstate";
696
- const initAnchors = "_qRouterInitAnchors";
697
- const initVisibility = "_qRouterInitVisibility";
698
- const initScroll = "_qRouterInitScroll";
699
- if (!win[spa] && !win[initPopstate] && !win[initAnchors] && !win[initVisibility] && !win[initScroll]) {
281
+ if (!window._qRouterSPA && !window._qRouterInitPopstate) {
700
282
  const currentPath = location.pathname + location.search;
701
- const historyPatch = "_qRouterHistoryPatch";
702
- const scrollEnabled = "_qRouterScrollEnabled";
703
- const debounceTimeout = "_qRouterScrollDebounce";
704
- const scrollHistory = "_qRouterScroll";
705
283
  const checkAndScroll = (scrollState) => {
706
284
  if (scrollState) {
707
- win.scrollTo(scrollState.x, scrollState.y);
285
+ window.scrollTo(scrollState.x, scrollState.y);
708
286
  }
709
287
  };
710
288
  const currentScrollState2 = () => {
@@ -718,16 +296,16 @@ const spaInit = core.event$((_, el) => {
718
296
  };
719
297
  const saveScrollState = (scrollState) => {
720
298
  const state = history.state || {};
721
- state[scrollHistory] = scrollState || currentScrollState2();
299
+ state._qRouterScroll = scrollState || currentScrollState2();
722
300
  history.replaceState(state, "");
723
301
  };
724
302
  saveScrollState();
725
- win[initPopstate] = () => {
726
- if (win[spa]) {
303
+ window._qRouterInitPopstate = () => {
304
+ if (window._qRouterSPA) {
727
305
  return;
728
306
  }
729
- win[scrollEnabled] = false;
730
- clearTimeout(win[debounceTimeout]);
307
+ window._qRouterScrollEnabled = false;
308
+ clearTimeout(window._qRouterScrollDebounce);
731
309
  if (currentPath !== location.pathname + location.search) {
732
310
  const getContainer = (el2) => el2.closest("[q\\:container]:not([q\\:container=html]):not([q\\:container=text])");
733
311
  const container = getContainer(el);
@@ -737,33 +315,31 @@ const spaInit = core.event$((_, el) => {
737
315
  id: "qc--n"
738
316
  });
739
317
  if (nav) {
740
- nav(location.href, {
741
- type: "popstate"
742
- });
318
+ nav(location.href, { type: "popstate" });
743
319
  } else {
744
320
  location.reload();
745
321
  }
746
322
  } else {
747
323
  if (history.scrollRestoration === "manual") {
748
- const scrollState = history.state?.[scrollHistory];
324
+ const scrollState = history.state?._qRouterScroll;
749
325
  checkAndScroll(scrollState);
750
- win[scrollEnabled] = true;
326
+ window._qRouterScrollEnabled = true;
751
327
  }
752
328
  }
753
329
  };
754
- if (!win[historyPatch]) {
755
- win[historyPatch] = true;
330
+ if (!window._qRouterHistoryPatch) {
331
+ window._qRouterHistoryPatch = true;
756
332
  const pushState = history.pushState;
757
333
  const replaceState = history.replaceState;
758
334
  const prepareState = (state) => {
759
335
  if (state === null || typeof state === "undefined") {
760
336
  state = {};
761
337
  } else if (state?.constructor !== Object) {
762
- state = {
763
- _data: state
764
- };
338
+ state = { _data: state };
765
339
  if (core.isDev) {
766
- 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`");
340
+ console.warn(
341
+ "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`"
342
+ );
767
343
  }
768
344
  }
769
345
  state._qRouterScroll = state._qRouterScroll || currentScrollState2();
@@ -778,8 +354,8 @@ const spaInit = core.event$((_, el) => {
778
354
  return replaceState.call(history, state, title, url);
779
355
  };
780
356
  }
781
- win[initAnchors] = (event) => {
782
- if (win[spa] || event.defaultPrevented) {
357
+ window._qRouterInitAnchors = (event) => {
358
+ if (window._qRouterSPA || event.defaultPrevented) {
783
359
  return;
784
360
  }
785
361
  const target = event.target.closest("a[href]");
@@ -798,13 +374,9 @@ const spaInit = core.event$((_, el) => {
798
374
  if (dest.href.endsWith("#")) {
799
375
  window.scrollTo(0, 0);
800
376
  } else {
801
- win[scrollEnabled] = false;
802
- clearTimeout(win[debounceTimeout]);
803
- saveScrollState({
804
- ...currentScrollState2(),
805
- x: 0,
806
- y: 0
807
- });
377
+ window._qRouterScrollEnabled = false;
378
+ clearTimeout(window._qRouterScrollDebounce);
379
+ saveScrollState({ ...currentScrollState2(), x: 0, y: 0 });
808
380
  location.reload();
809
381
  }
810
382
  } else {
@@ -817,30 +389,28 @@ const spaInit = core.event$((_, el) => {
817
389
  }
818
390
  }
819
391
  };
820
- win[initVisibility] = () => {
821
- if (!win[spa] && win[scrollEnabled] && document.visibilityState === "hidden") {
392
+ window._qRouterInitVisibility = () => {
393
+ if (!window._qRouterSPA && window._qRouterScrollEnabled && document.visibilityState === "hidden") {
822
394
  saveScrollState();
823
395
  }
824
396
  };
825
- win[initScroll] = () => {
826
- if (win[spa] || !win[scrollEnabled]) {
397
+ window._qRouterInitScroll = () => {
398
+ if (window._qRouterSPA || !window._qRouterScrollEnabled) {
827
399
  return;
828
400
  }
829
- clearTimeout(win[debounceTimeout]);
830
- win[debounceTimeout] = setTimeout(() => {
401
+ clearTimeout(window._qRouterScrollDebounce);
402
+ window._qRouterScrollDebounce = setTimeout(() => {
831
403
  saveScrollState();
832
- win[debounceTimeout] = void 0;
404
+ window._qRouterScrollDebounce = void 0;
833
405
  }, 200);
834
406
  };
835
- win[scrollEnabled] = true;
407
+ window._qRouterScrollEnabled = true;
836
408
  setTimeout(() => {
837
- win.addEventListener("popstate", win[initPopstate]);
838
- win.addEventListener("scroll", win[initScroll], {
839
- passive: true
840
- });
841
- document.body.addEventListener("click", win[initAnchors]);
842
- if (!win.navigation) {
843
- document.addEventListener("visibilitychange", win[initVisibility], {
409
+ window.addEventListener("popstate", window._qRouterInitPopstate);
410
+ window.addEventListener("scroll", window._qRouterInitScroll, { passive: true });
411
+ document.addEventListener("click", window._qRouterInitAnchors);
412
+ if (!window.navigation) {
413
+ document.addEventListener("visibilitychange", window._qRouterInitVisibility, {
844
414
  passive: true
845
415
  });
846
416
  }
@@ -858,37 +428,40 @@ const startViewTransition = (params) => {
858
428
  } catch {
859
429
  transition = document.startViewTransition(params.update);
860
430
  }
861
- const event = new CustomEvent("qviewtransition", {
862
- detail: transition
863
- });
431
+ const event = new CustomEvent("qviewtransition", { detail: transition });
864
432
  document.dispatchEvent(event);
865
433
  return transition;
866
434
  } else {
867
435
  params.update?.();
868
436
  }
869
437
  };
870
- const transitionCss = "@layer qwik {\n @supports selector(html:active-view-transition-type(type)) {\n html:active-view-transition-type(qwik-navigation) {\n :root {\n view-transition-name: none;\n }\n }\n }\n @supports not selector(html:active-view-transition-type(type)) {\n :root {\n view-transition-name: none;\n }\n }\n}\n";
438
+ 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}}}";
871
439
  const QWIK_CITY_SCROLLER = "_qCityScroller";
872
440
  const QWIK_ROUTER_SCROLLER = "_qRouterScroller";
873
441
  const preventNav = {};
874
- const internalState = {
875
- navCount: 0
876
- };
442
+ const internalState = { navCount: 0 };
877
443
  const useQwikRouter = (props) => {
444
+ if (!core.isServer) {
445
+ throw new Error(
446
+ "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."
447
+ );
448
+ }
878
449
  core.useStyles$(transitionCss);
879
450
  const env = useQwikRouterEnv();
880
451
  if (!env?.params) {
881
- throw new Error(`Missing Qwik Router Env Data for help visit https://github.com/QwikDev/qwik/issues/6237`);
452
+ throw new Error(
453
+ `Missing Qwik Router Env Data for help visit https://github.com/QwikDev/qwik/issues/6237`
454
+ );
882
455
  }
883
456
  const urlEnv = core.useServerData("url");
884
457
  if (!urlEnv) {
885
458
  throw new Error(`Missing Qwik URL Env Data`);
886
459
  }
887
460
  const serverHead = core.useServerData("documentHead");
888
- if (core.isServer) {
889
- if (env.ev.originalUrl.pathname !== env.ev.url.pathname && !__EXPERIMENTAL__.enableRequestRewrite) {
890
- 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.`);
891
- }
461
+ if (env.ev.originalUrl.pathname !== env.ev.url.pathname && !__EXPERIMENTAL__.enableRequestRewrite) {
462
+ throw new Error(
463
+ `enableRequestRewrite is an experimental feature and is not enabled. Please enable the feature flag by adding \`experimental: ["enableRequestRewrite"]\` to your qwikVite plugin options.`
464
+ );
892
465
  }
893
466
  const url = new URL(urlEnv);
894
467
  const routeLocationTarget = {
@@ -897,35 +470,39 @@ const useQwikRouter = (props) => {
897
470
  isNavigating: false,
898
471
  prevUrl: void 0
899
472
  };
900
- const routeLocation = core.useStore(routeLocationTarget, {
901
- deep: false
902
- });
473
+ const routeLocation = core.useStore(routeLocationTarget, { deep: false });
903
474
  const navResolver = {};
904
475
  const container = internal._getContextContainer();
905
476
  const getSerializationStrategy = (loaderId) => {
906
- return env.response.loadersSerializationStrategy.get(loaderId) || DEFAULT_LOADERS_SERIALIZATION_STRATEGY;
477
+ return env.response.loadersSerializationStrategy.get(loaderId) || routing.DEFAULT_LOADERS_SERIALIZATION_STRATEGY;
907
478
  };
908
479
  const loadersObject = {};
909
480
  const loaderState = {};
910
481
  for (const [key, value] of Object.entries(env.response.loaders)) {
911
482
  loadersObject[key] = value;
912
- loaderState[key] = createLoaderSignal(loadersObject, key, url, getSerializationStrategy(key), container);
483
+ loaderState[key] = routing.createLoaderSignal(
484
+ loadersObject,
485
+ key,
486
+ url,
487
+ getSerializationStrategy(key),
488
+ container
489
+ );
913
490
  }
914
491
  loadersObject[internal.SerializerSymbol] = (obj) => {
915
492
  const loadersSerializationObject = {};
916
- for (const [k, v] of Object.entries(obj)) {
917
- loadersSerializationObject[k] = getSerializationStrategy(k) === "always" ? v : internal._UNINITIALIZED;
493
+ for (const [k, v2] of Object.entries(obj)) {
494
+ loadersSerializationObject[k] = getSerializationStrategy(k) === "always" ? v2 : internal._UNINITIALIZED;
918
495
  }
919
496
  return loadersSerializationObject;
920
497
  };
921
498
  const routeInternal = core.useSignal({
922
499
  type: "initial",
923
500
  dest: url,
924
- forceReload: false,
925
- replaceState: false,
926
501
  scroll: true
927
502
  });
928
- const documentHead = core.useStore(() => createDocumentHead(serverHead));
503
+ const documentHead = core.useStore(
504
+ () => createDocumentHead(serverHead)
505
+ );
929
506
  const content = core.useStore({
930
507
  headings: void 0,
931
508
  menu: void 0
@@ -933,14 +510,16 @@ const useQwikRouter = (props) => {
933
510
  const contentInternal = core.useSignal();
934
511
  const currentActionId = env.response.action;
935
512
  const currentAction = currentActionId ? env.response.loaders[currentActionId] : void 0;
936
- const actionState = core.useSignal(currentAction ? {
937
- id: currentActionId,
938
- data: env.response.formData,
939
- output: {
940
- result: currentAction,
941
- status: env.response.status
942
- }
943
- } : void 0);
513
+ const actionState = core.useSignal(
514
+ currentAction ? {
515
+ id: currentActionId,
516
+ data: env.response.formData,
517
+ output: {
518
+ result: currentAction,
519
+ status: env.response.status
520
+ }
521
+ } : void 0
522
+ );
944
523
  const registerPreventNav = core.$((fn$) => {
945
524
  if (!core.isBrowser) {
946
525
  return;
@@ -950,9 +529,9 @@ const useQwikRouter = (props) => {
950
529
  if (!preventNav.$cbs$) {
951
530
  return;
952
531
  }
953
- const prevents = [
954
- ...preventNav.$cbs$.values()
955
- ].map((cb) => cb.resolved ? cb.resolved() : cb());
532
+ const prevents = [...preventNav.$cbs$.values()].map(
533
+ (cb) => cb.resolved ? cb.resolved() : cb()
534
+ );
956
535
  if (prevents.some(Boolean)) {
957
536
  event.preventDefault();
958
537
  event.returnValue = true;
@@ -972,17 +551,22 @@ const useQwikRouter = (props) => {
972
551
  };
973
552
  });
974
553
  const goto = core.$(async (path, opt) => {
975
- const { type = "link", forceReload = path === void 0, replaceState = false, scroll = true } = typeof opt === "object" ? opt : {
976
- forceReload: opt
977
- };
554
+ const {
555
+ type = "link",
556
+ forceReload = path === void 0,
557
+ // Hack for nav() because this API is already set.
558
+ replaceState = false,
559
+ scroll = true
560
+ } = typeof opt === "object" ? opt : { forceReload: opt };
978
561
  internalState.navCount++;
562
+ if (core.isBrowser && type === "link" && routeInternal.value.type === "initial") {
563
+ routeInternal.value.dest = new URL(window.location.href);
564
+ }
979
565
  const lastDest = routeInternal.value.dest;
980
- const dest = path === void 0 ? lastDest : typeof path === "number" ? path : toUrl(path, routeLocation.url);
981
- if (preventNav.$cbs$ && (forceReload || typeof dest === "number" || !isSamePath(dest, lastDest) || !isSameOrigin(dest, lastDest))) {
566
+ const dest = path === void 0 ? lastDest : typeof path === "number" ? path : routing.toUrl(path, routeLocation.url);
567
+ if (preventNav.$cbs$ && (forceReload || typeof dest === "number" || !routing.isSamePath(dest, lastDest) || !routing.isSameOrigin(dest, lastDest))) {
982
568
  const ourNavId = internalState.navCount;
983
- const prevents = await Promise.all([
984
- ...preventNav.$cbs$.values()
985
- ].map((cb) => cb(dest)));
569
+ const prevents = await Promise.all([...preventNav.$cbs$.values()].map((cb) => cb(dest)));
986
570
  if (ourNavId !== internalState.navCount || prevents.some(Boolean)) {
987
571
  if (ourNavId === internalState.navCount && type === "popstate") {
988
572
  history.pushState(null, "", lastDest);
@@ -996,13 +580,13 @@ const useQwikRouter = (props) => {
996
580
  }
997
581
  return;
998
582
  }
999
- if (!isSameOrigin(dest, lastDest)) {
583
+ if (!routing.isSameOrigin(dest, lastDest)) {
1000
584
  if (core.isBrowser) {
1001
585
  location.href = dest.href;
1002
586
  }
1003
587
  return;
1004
588
  }
1005
- if (!forceReload && isSamePath(dest, lastDest)) {
589
+ if (!forceReload && routing.isSamePath(dest, lastDest)) {
1006
590
  if (core.isBrowser) {
1007
591
  if (type === "link" && dest.href !== location.href) {
1008
592
  history.pushState(null, "", dest);
@@ -1011,7 +595,9 @@ const useQwikRouter = (props) => {
1011
595
  if (!scroller) {
1012
596
  scroller = document.getElementById(QWIK_CITY_SCROLLER);
1013
597
  if (scroller && core.isDev) {
1014
- console.warn(`Please update your scroller ID to "${QWIK_ROUTER_SCROLLER}" as "${QWIK_CITY_SCROLLER}" is deprecated and will be removed in V3`);
598
+ console.warn(
599
+ `Please update your scroller ID to "${QWIK_ROUTER_SCROLLER}" as "${QWIK_CITY_SCROLLER}" is deprecated and will be removed in V3`
600
+ );
1015
601
  }
1016
602
  }
1017
603
  if (!scroller) {
@@ -1032,8 +618,13 @@ const useQwikRouter = (props) => {
1032
618
  scroll
1033
619
  };
1034
620
  if (core.isBrowser) {
1035
- loadClientData(dest, internal._getContextElement());
1036
- loadRoute(qwikRouterConfig__namespace.routes, qwikRouterConfig__namespace.menus, qwikRouterConfig__namespace.cacheModules, dest.pathname);
621
+ routing.loadClientData(dest, internal._getContextElement());
622
+ routing.loadRoute(
623
+ qwikRouterConfig__namespace.routes,
624
+ qwikRouterConfig__namespace.menus,
625
+ qwikRouterConfig__namespace.cacheModules,
626
+ dest.pathname
627
+ );
1037
628
  }
1038
629
  actionState.value = void 0;
1039
630
  routeLocation.isNavigating = true;
@@ -1048,14 +639,11 @@ const useQwikRouter = (props) => {
1048
639
  core.useContextProvider(RouteNavigateContext, goto);
1049
640
  core.useContextProvider(RouteStateContext, loaderState);
1050
641
  core.useContextProvider(RouteActionContext, actionState);
1051
- core.useContextProvider(RouteInternalContext, routeInternal);
1052
642
  core.useContextProvider(RoutePreventNavigateContext, registerPreventNav);
1053
643
  core.useTask$(({ track }) => {
1054
644
  async function run() {
1055
- const [navigation, action] = track(() => [
1056
- routeInternal.value,
1057
- actionState.value
1058
- ]);
645
+ const navigation = track(routeInternal);
646
+ const action = track(actionState);
1059
647
  const locale = core.getLocale("");
1060
648
  const prevUrl = routeLocation.url;
1061
649
  const navType = action ? "form" : navigation.type;
@@ -1077,26 +665,28 @@ const useQwikRouter = (props) => {
1077
665
  } else if (!globalThis.__NO_TRAILING_SLASH__) {
1078
666
  trackUrl.pathname += "/";
1079
667
  }
1080
- let loadRoutePromise = loadRoute(qwikRouterConfig__namespace.routes, qwikRouterConfig__namespace.menus, qwikRouterConfig__namespace.cacheModules, trackUrl.pathname);
668
+ let loadRoutePromise = routing.loadRoute(
669
+ qwikRouterConfig__namespace.routes,
670
+ qwikRouterConfig__namespace.menus,
671
+ qwikRouterConfig__namespace.cacheModules,
672
+ trackUrl.pathname
673
+ );
1081
674
  elm = internal._getContextElement();
1082
- const pageData = clientPageData = await loadClientData(trackUrl, elm, {
675
+ const pageData = clientPageData = await routing.loadClientData(trackUrl, elm, {
1083
676
  action,
1084
677
  clearCache: true
1085
678
  });
1086
679
  if (!pageData) {
1087
- routeInternal.untrackedValue = {
1088
- type: navType,
1089
- dest: trackUrl
1090
- };
680
+ routeInternal.untrackedValue = { type: navType, dest: trackUrl };
1091
681
  return;
1092
682
  }
1093
683
  const newHref = pageData.href;
1094
684
  const newURL = new URL(newHref, trackUrl);
1095
- if (!isSamePath(newURL, trackUrl)) {
685
+ if (!routing.isSamePath(newURL, trackUrl)) {
1096
686
  if (!pageData.isRewrite) {
1097
687
  trackUrl = newURL;
1098
688
  }
1099
- loadRoutePromise = loadRoute(
689
+ loadRoutePromise = routing.loadRoute(
1100
690
  qwikRouterConfig__namespace.routes,
1101
691
  qwikRouterConfig__namespace.menus,
1102
692
  qwikRouterConfig__namespace.cacheModules,
@@ -1116,13 +706,13 @@ const useQwikRouter = (props) => {
1116
706
  const [routeName, params, mods, menu] = loadedRoute;
1117
707
  const contentModules = mods;
1118
708
  const pageModule = contentModules[contentModules.length - 1];
1119
- if (navigation.dest.search && !!isSamePath(trackUrl, prevUrl)) {
709
+ if (navigation.dest.search && !!routing.isSamePath(trackUrl, prevUrl)) {
1120
710
  trackUrl.search = navigation.dest.search;
1121
711
  }
1122
712
  let shouldForcePrevUrl = false;
1123
713
  let shouldForceUrl = false;
1124
714
  let shouldForceParams = false;
1125
- if (!isSamePath(trackUrl, prevUrl)) {
715
+ if (!routing.isSamePath(trackUrl, prevUrl)) {
1126
716
  if (internal._hasStoreEffects(routeLocation, "prevUrl")) {
1127
717
  shouldForcePrevUrl = true;
1128
718
  }
@@ -1140,11 +730,14 @@ const useQwikRouter = (props) => {
1140
730
  }
1141
731
  routeLocationTarget.params = params;
1142
732
  }
1143
- routeInternal.untrackedValue = {
1144
- type: navType,
1145
- dest: trackUrl
1146
- };
1147
- const resolvedHead = resolveHead(clientPageData, routeLocation, contentModules, locale, serverHead);
733
+ routeInternal.untrackedValue = { type: navType, dest: trackUrl };
734
+ const resolvedHead = resolveHead(
735
+ clientPageData,
736
+ routeLocation,
737
+ contentModules,
738
+ locale,
739
+ serverHead
740
+ );
1148
741
  content.headings = pageModule.headings;
1149
742
  content.menu = menu;
1150
743
  contentInternal.untrackedValue = core.noSerialize(contentModules);
@@ -1160,7 +753,8 @@ const useQwikRouter = (props) => {
1160
753
  scrollState = getScrollHistory();
1161
754
  }
1162
755
  const scroller = document.getElementById(QWIK_ROUTER_SCROLLER) ?? document.documentElement;
1163
- if (navigation.scroll && (!navigation.forceReload || !isSamePath(trackUrl, prevUrl)) && (navType === "link" || navType === "popstate") || navType === "form" && !isSamePath(trackUrl, prevUrl)) {
756
+ if (navigation.scroll && (!navigation.forceReload || !routing.isSamePath(trackUrl, prevUrl)) && (navType === "link" || navType === "popstate") || // Action might have responded with a redirect.
757
+ navType === "form" && !routing.isSamePath(trackUrl, prevUrl)) {
1164
758
  document.__q_scroll_restore__ = () => restoreScroll(navType, trackUrl, prevUrl, scroller, scrollState);
1165
759
  }
1166
760
  const loaders = clientPageData?.loaders;
@@ -1171,39 +765,44 @@ const useQwikRouter = (props) => {
1171
765
  const awaitedValue = await value;
1172
766
  loadersObject[key] = awaitedValue;
1173
767
  if (!signal) {
1174
- loaderState[key] = createLoaderSignal(loadersObject, key, trackUrl, DEFAULT_LOADERS_SERIALIZATION_STRATEGY, container2);
768
+ loaderState[key] = routing.createLoaderSignal(
769
+ loadersObject,
770
+ key,
771
+ trackUrl,
772
+ routing.DEFAULT_LOADERS_SERIALIZATION_STRATEGY,
773
+ container2
774
+ );
1175
775
  } else {
1176
776
  signal.invalidate();
1177
777
  }
1178
778
  }
1179
779
  }
1180
- CLIENT_DATA_CACHE.clear();
1181
- const win = window;
1182
- if (!win._qRouterSPA) {
1183
- win._qRouterSPA = true;
780
+ routing.CLIENT_DATA_CACHE.clear();
781
+ if (!window._qRouterSPA) {
782
+ window._qRouterSPA = true;
1184
783
  history.scrollRestoration = "manual";
1185
- win.addEventListener("popstate", () => {
1186
- win._qRouterScrollEnabled = false;
1187
- clearTimeout(win._qRouterScrollDebounce);
784
+ window.addEventListener("popstate", () => {
785
+ window._qRouterScrollEnabled = false;
786
+ clearTimeout(window._qRouterScrollDebounce);
1188
787
  goto(location.href, {
1189
788
  type: "popstate"
1190
789
  });
1191
790
  });
1192
- win.removeEventListener("popstate", win._qRouterInitPopstate);
1193
- win._qRouterInitPopstate = void 0;
1194
- if (!win._qRouterHistoryPatch) {
1195
- win._qRouterHistoryPatch = true;
791
+ window.removeEventListener("popstate", window._qRouterInitPopstate);
792
+ window._qRouterInitPopstate = void 0;
793
+ if (!window._qRouterHistoryPatch) {
794
+ window._qRouterHistoryPatch = true;
1196
795
  const pushState = history.pushState;
1197
796
  const replaceState2 = history.replaceState;
1198
797
  const prepareState = (state) => {
1199
798
  if (state === null || typeof state === "undefined") {
1200
799
  state = {};
1201
800
  } else if (state?.constructor !== Object) {
1202
- state = {
1203
- _data: state
1204
- };
801
+ state = { _data: state };
1205
802
  if (core.isDev) {
1206
- 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`");
803
+ console.warn(
804
+ "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`"
805
+ );
1207
806
  }
1208
807
  }
1209
808
  state._qRouterScroll = state._qRouterScroll || currentScrollState(scroller);
@@ -1218,7 +817,7 @@ const useQwikRouter = (props) => {
1218
817
  return replaceState2.call(history, state, title, url2);
1219
818
  };
1220
819
  }
1221
- document.body.addEventListener("click", (event) => {
820
+ document.addEventListener("click", (event) => {
1222
821
  if (event.defaultPrevented) {
1223
822
  return;
1224
823
  }
@@ -1227,14 +826,14 @@ const useQwikRouter = (props) => {
1227
826
  const href = target.getAttribute("href");
1228
827
  const prev = new URL(location.href);
1229
828
  const dest = new URL(href, prev);
1230
- if (isSameOrigin(dest, prev) && isSamePath(dest, prev)) {
829
+ if (routing.isSameOrigin(dest, prev) && routing.isSamePath(dest, prev)) {
1231
830
  event.preventDefault();
1232
831
  if (!dest.hash && !dest.href.endsWith("#")) {
1233
832
  if (dest.href !== prev.href) {
1234
833
  history.pushState(null, "", dest);
1235
834
  }
1236
- win._qRouterScrollEnabled = false;
1237
- clearTimeout(win._qRouterScrollDebounce);
835
+ window._qRouterScrollEnabled = false;
836
+ clearTimeout(window._qRouterScrollDebounce);
1238
837
  saveScrollHistory({
1239
838
  ...currentScrollState(scroller),
1240
839
  x: 0,
@@ -1247,48 +846,54 @@ const useQwikRouter = (props) => {
1247
846
  }
1248
847
  }
1249
848
  });
1250
- document.body.removeEventListener("click", win._qRouterInitAnchors);
1251
- win._qRouterInitAnchors = void 0;
849
+ document.removeEventListener("click", window._qRouterInitAnchors);
850
+ window._qRouterInitAnchors = void 0;
1252
851
  if (!window.navigation) {
1253
- document.addEventListener("visibilitychange", () => {
1254
- if ((win._qRouterScrollEnabled || win._qCityScrollEnabled) && document.visibilityState === "hidden") {
1255
- if (win._qCityScrollEnabled) {
1256
- console.warn('"_qCityScrollEnabled" is deprecated. Use "_qRouterScrollEnabled" instead.');
852
+ document.addEventListener(
853
+ "visibilitychange",
854
+ () => {
855
+ if ((window._qRouterScrollEnabled || window._qCityScrollEnabled) && document.visibilityState === "hidden") {
856
+ if (window._qCityScrollEnabled) {
857
+ console.warn(
858
+ '"_qCityScrollEnabled" is deprecated. Use "_qRouterScrollEnabled" instead.'
859
+ );
860
+ }
861
+ const scrollState2 = currentScrollState(scroller);
862
+ saveScrollHistory(scrollState2);
1257
863
  }
864
+ },
865
+ { passive: true }
866
+ );
867
+ document.removeEventListener("visibilitychange", window._qRouterInitVisibility);
868
+ window._qRouterInitVisibility = void 0;
869
+ }
870
+ window.addEventListener(
871
+ "scroll",
872
+ () => {
873
+ if (!window._qRouterScrollEnabled && !window._qCityScrollEnabled) {
874
+ return;
875
+ }
876
+ clearTimeout(window._qRouterScrollDebounce);
877
+ window._qRouterScrollDebounce = setTimeout(() => {
1258
878
  const scrollState2 = currentScrollState(scroller);
1259
879
  saveScrollHistory(scrollState2);
1260
- }
1261
- }, {
1262
- passive: true
1263
- });
1264
- document.removeEventListener("visibilitychange", win._qRouterInitVisibility);
1265
- win._qRouterInitVisibility = void 0;
1266
- }
1267
- win.addEventListener("scroll", () => {
1268
- if (!win._qRouterScrollEnabled && !win._qCityScrollEnabled) {
1269
- return;
1270
- }
1271
- clearTimeout(win._qRouterScrollDebounce);
1272
- win._qRouterScrollDebounce = setTimeout(() => {
1273
- const scrollState2 = currentScrollState(scroller);
1274
- saveScrollHistory(scrollState2);
1275
- win._qRouterScrollDebounce = void 0;
1276
- }, 200);
1277
- }, {
1278
- passive: true
1279
- });
1280
- removeEventListener("scroll", win._qRouterInitScroll);
1281
- win._qRouterInitScroll = void 0;
880
+ window._qRouterScrollDebounce = void 0;
881
+ }, 200);
882
+ },
883
+ { passive: true }
884
+ );
885
+ removeEventListener("scroll", window._qRouterInitScroll);
886
+ window._qRouterInitScroll = void 0;
1282
887
  spaInit.resolve();
1283
888
  }
1284
889
  if (navType !== "popstate") {
1285
- win._qRouterScrollEnabled = false;
1286
- clearTimeout(win._qRouterScrollDebounce);
890
+ window._qRouterScrollEnabled = false;
891
+ clearTimeout(window._qRouterScrollDebounce);
1287
892
  const scrollState2 = currentScrollState(scroller);
1288
893
  saveScrollHistory(scrollState2);
1289
894
  }
1290
895
  const navigate = () => {
1291
- clientNavigate(window, navType, prevUrl, trackUrl, replaceState);
896
+ routing.clientNavigate(window, navType, prevUrl, trackUrl, replaceState);
1292
897
  contentInternal.force();
1293
898
  return internal._waitUntilRendered(elm);
1294
899
  };
@@ -1298,9 +903,7 @@ const useQwikRouter = (props) => {
1298
903
  } else {
1299
904
  const viewTransition = startViewTransition({
1300
905
  update: navigate,
1301
- types: [
1302
- "qwik-navigation"
1303
- ]
906
+ types: ["qwik-navigation"]
1304
907
  });
1305
908
  if (!viewTransition) {
1306
909
  return Promise.resolve();
@@ -1310,10 +913,10 @@ const useQwikRouter = (props) => {
1310
913
  };
1311
914
  _waitNextPage().then(() => {
1312
915
  const container2 = internal._getQContainerElement(elm);
1313
- container2.setAttribute(Q_ROUTE, routeName);
916
+ container2.setAttribute(routing.Q_ROUTE, routeName);
1314
917
  const scrollState2 = currentScrollState(scroller);
1315
918
  saveScrollHistory(scrollState2);
1316
- win._qRouterScrollEnabled = true;
919
+ window._qRouterScrollEnabled = true;
1317
920
  if (core.isBrowser) {
1318
921
  callRestoreScrollOnDocument();
1319
922
  }
@@ -1347,31 +950,27 @@ const QwikCityProvider = QwikRouterProvider;
1347
950
  const useQwikMockRouter = (props) => {
1348
951
  const urlEnv = props.url ?? "http://localhost/";
1349
952
  const url = new URL(urlEnv);
1350
- const routeLocation = core.useStore({
1351
- url,
1352
- params: props.params ?? {},
1353
- isNavigating: false,
1354
- prevUrl: void 0
1355
- }, {
1356
- deep: false
1357
- });
953
+ const routeLocation = core.useStore(
954
+ {
955
+ url,
956
+ params: props.params ?? {},
957
+ isNavigating: false,
958
+ prevUrl: void 0
959
+ },
960
+ { deep: false }
961
+ );
1358
962
  const loaderState = {};
1359
- const routeInternal = core.useSignal({
1360
- type: "initial",
1361
- dest: url
1362
- });
1363
963
  const goto = props.goto ?? core.$(async () => {
1364
964
  console.warn("QwikRouterMockProvider: goto not provided");
1365
965
  });
1366
- const documentHead = core.useStore(createDocumentHead, {
1367
- deep: false
1368
- });
1369
- const content = core.useStore({
1370
- headings: void 0,
1371
- menu: void 0
1372
- }, {
1373
- deep: false
1374
- });
966
+ const documentHead = core.useStore(createDocumentHead, { deep: false });
967
+ const content = core.useStore(
968
+ {
969
+ headings: void 0,
970
+ menu: void 0
971
+ },
972
+ { deep: false }
973
+ );
1375
974
  const contentInternal = core.useSignal();
1376
975
  const actionState = core.useSignal();
1377
976
  core.useContextProvider(ContentContext, content);
@@ -1381,7 +980,6 @@ const useQwikMockRouter = (props) => {
1381
980
  core.useContextProvider(RouteNavigateContext, goto);
1382
981
  core.useContextProvider(RouteStateContext, loaderState);
1383
982
  core.useContextProvider(RouteActionContext, actionState);
1384
- core.useContextProvider(RouteInternalContext, routeInternal);
1385
983
  };
1386
984
  const QwikRouterMockProvider = core.component$((props) => {
1387
985
  useQwikMockRouter(props);
@@ -1405,10 +1003,11 @@ const RouterOutlet = core.component$(() => {
1405
1003
  });
1406
1004
  }
1407
1005
  }
1408
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1409
- children: [
1410
- cmp,
1411
- !__EXPERIMENTAL__.noSPA && /* @__PURE__ */ jsxRuntime.jsx("script", {
1006
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1007
+ cmp,
1008
+ !__EXPERIMENTAL__.noSPA && /* @__PURE__ */ jsxRuntime.jsx(
1009
+ "script",
1010
+ {
1412
1011
  "document:onQCInit$": spaInit,
1413
1012
  "document:onQInit$": core.sync$(() => {
1414
1013
  ((w, h) => {
@@ -1422,93 +1021,19 @@ const RouterOutlet = core.component$(() => {
1422
1021
  }
1423
1022
  })(window, history);
1424
1023
  })
1425
- })
1426
- ]
1427
- });
1024
+ }
1025
+ )
1026
+ ] });
1428
1027
  }
1429
1028
  return core.SkipRender;
1430
1029
  });
1431
- var store;
1432
- // @__NO_SIDE_EFFECTS__
1433
- function getGlobalConfig(config2) {
1434
- return {
1435
- lang: config2?.lang ?? store?.lang,
1436
- message: config2?.message,
1437
- abortEarly: config2?.abortEarly ?? store?.abortEarly,
1438
- abortPipeEarly: config2?.abortPipeEarly ?? store?.abortPipeEarly
1439
- };
1440
- }
1441
- // @__NO_SIDE_EFFECTS__
1442
- function getDotPath(issue) {
1443
- if (issue.path) {
1444
- let key = "";
1445
- for (const item of issue.path) {
1446
- if (typeof item.key === "string" || typeof item.key === "number") {
1447
- if (key) {
1448
- key += `.${item.key}`;
1449
- } else {
1450
- key += item.key;
1451
- }
1452
- } else {
1453
- return null;
1454
- }
1455
- }
1456
- return key;
1457
- }
1458
- return null;
1459
- }
1460
- // @__NO_SIDE_EFFECTS__
1461
- function flatten(issues) {
1462
- const flatErrors = {};
1463
- for (const issue of issues) {
1464
- if (issue.path) {
1465
- const dotPath = /* @__PURE__ */ getDotPath(issue);
1466
- if (dotPath) {
1467
- if (!flatErrors.nested) {
1468
- flatErrors.nested = {};
1469
- }
1470
- if (flatErrors.nested[dotPath]) {
1471
- flatErrors.nested[dotPath].push(issue.message);
1472
- } else {
1473
- flatErrors.nested[dotPath] = [issue.message];
1474
- }
1475
- } else {
1476
- if (flatErrors.other) {
1477
- flatErrors.other.push(issue.message);
1478
- } else {
1479
- flatErrors.other = [issue.message];
1480
- }
1481
- }
1482
- } else {
1483
- if (flatErrors.root) {
1484
- flatErrors.root.push(issue.message);
1485
- } else {
1486
- flatErrors.root = [issue.message];
1487
- }
1488
- }
1489
- }
1490
- return flatErrors;
1491
- }
1492
- // @__NO_SIDE_EFFECTS__
1493
- async function safeParseAsync(schema, input, config2) {
1494
- const dataset = await schema["~run"](
1495
- { value: input },
1496
- /* @__PURE__ */ getGlobalConfig(config2)
1497
- );
1498
- return {
1499
- typed: dataset.typed,
1500
- success: !dataset.issues,
1501
- output: dataset.value,
1502
- issues: dataset.issues
1503
- };
1504
- }
1505
- const routeActionQrl = (actionQrl, ...rest) => {
1030
+ const routeActionQrl = ((actionQrl, ...rest) => {
1506
1031
  const { id, validators } = getValidators(rest, actionQrl);
1507
1032
  function action() {
1508
1033
  const loc = useLocation();
1509
1034
  const currentAction = useAction();
1510
1035
  const initialState = {
1511
- actionPath: `?${QACTION_KEY}=${id}`,
1036
+ actionPath: `?${routing.QACTION_KEY}=${id}`,
1512
1037
  submitted: false,
1513
1038
  isRunning: false,
1514
1039
  status: void 0,
@@ -1568,16 +1093,15 @@ Action.run() can only be called on the browser, for example when a user clicks a
1568
1093
  if (form.getAttribute("data-spa-reset") === "true") {
1569
1094
  form.reset();
1570
1095
  }
1571
- const detail = {
1572
- status,
1573
- value: result
1574
- };
1575
- form.dispatchEvent(new CustomEvent("submitcompleted", {
1576
- bubbles: false,
1577
- cancelable: false,
1578
- composed: false,
1579
- detail
1580
- }));
1096
+ const detail = { status, value: result };
1097
+ form.dispatchEvent(
1098
+ new CustomEvent("submitcompleted", {
1099
+ bubbles: false,
1100
+ cancelable: false,
1101
+ composed: false,
1102
+ detail
1103
+ })
1104
+ );
1581
1105
  }
1582
1106
  return {
1583
1107
  status,
@@ -1594,8 +1118,8 @@ Action.run() can only be called on the browser, for example when a user clicks a
1594
1118
  action.__id = id;
1595
1119
  Object.freeze(action);
1596
1120
  return action;
1597
- };
1598
- const globalActionQrl = (actionQrl, ...rest) => {
1121
+ });
1122
+ const globalActionQrl = ((actionQrl, ...rest) => {
1599
1123
  const action = routeActionQrl(actionQrl, ...rest);
1600
1124
  if (core.isServer) {
1601
1125
  if (typeof globalThis._qwikActionsMap === "undefined") {
@@ -1604,10 +1128,14 @@ const globalActionQrl = (actionQrl, ...rest) => {
1604
1128
  globalThis._qwikActionsMap.set(action.__id, action);
1605
1129
  }
1606
1130
  return action;
1607
- };
1608
- const routeAction$ = /* @__PURE__ */ core.implicit$FirstArg(routeActionQrl);
1609
- const globalAction$ = /* @__PURE__ */ core.implicit$FirstArg(globalActionQrl);
1610
- const routeLoaderQrl = (loaderQrl, ...rest) => {
1131
+ });
1132
+ const routeAction$ = /* @__PURE__ */ core.implicit$FirstArg(
1133
+ routeActionQrl
1134
+ );
1135
+ const globalAction$ = /* @__PURE__ */ core.implicit$FirstArg(
1136
+ globalActionQrl
1137
+ );
1138
+ const routeLoaderQrl = ((loaderQrl, ...rest) => {
1611
1139
  const { id, validators, serializationStrategy } = getValidators(rest, loaderQrl);
1612
1140
  function loader() {
1613
1141
  const state = internal._resolveContextWithoutSequentialScope(RouteStateContext);
@@ -1627,18 +1155,19 @@ const routeLoaderQrl = (loaderQrl, ...rest) => {
1627
1155
  loader.__validators = validators;
1628
1156
  loader.__id = id;
1629
1157
  loader.__serializationStrategy = serializationStrategy;
1158
+ loader.__expires = -1;
1630
1159
  Object.freeze(loader);
1631
1160
  return loader;
1632
- };
1161
+ });
1633
1162
  const routeLoader$ = /* @__PURE__ */ core.implicit$FirstArg(routeLoaderQrl);
1634
- const validatorQrl = (validator) => {
1163
+ const validatorQrl = ((validator) => {
1635
1164
  if (core.isServer) {
1636
1165
  return {
1637
1166
  validate: validator
1638
1167
  };
1639
1168
  }
1640
1169
  return void 0;
1641
- };
1170
+ });
1642
1171
  const validator$ = /* @__PURE__ */ core.implicit$FirstArg(validatorQrl);
1643
1172
  const flattenValibotIssues = (issues) => {
1644
1173
  return issues.reduce((acc, issue) => {
@@ -1661,7 +1190,9 @@ const flattenValibotIssues = (issues) => {
1661
1190
  };
1662
1191
  const valibotQrl = (qrl) => {
1663
1192
  if (!__EXPERIMENTAL__.valibot) {
1664
- throw new Error('Valibot is an experimental feature and is not enabled. Please enable the feature flag by adding `experimental: ["valibot"]` to your qwikVite plugin options.');
1193
+ throw new Error(
1194
+ 'Valibot is an experimental feature and is not enabled. Please enable the feature flag by adding `experimental: ["valibot"]` to your qwikVite plugin options.'
1195
+ );
1665
1196
  }
1666
1197
  if (core.isServer) {
1667
1198
  return {
@@ -1669,7 +1200,7 @@ const valibotQrl = (qrl) => {
1669
1200
  async validate(ev, inputData) {
1670
1201
  const schema = await qrl.resolve().then((obj) => typeof obj === "function" ? obj(ev) : obj);
1671
1202
  const data = inputData ?? await ev.parseBody();
1672
- const result = await /* @__PURE__ */ safeParseAsync(schema, data);
1203
+ const result = await v__namespace.safeParseAsync(schema, data);
1673
1204
  if (result.success) {
1674
1205
  return {
1675
1206
  success: true,
@@ -1683,7 +1214,7 @@ const valibotQrl = (qrl) => {
1683
1214
  success: false,
1684
1215
  status: 400,
1685
1216
  error: {
1686
- formErrors: (/* @__PURE__ */ flatten(result.issues)).root ?? [],
1217
+ formErrors: v__namespace.flatten(result.issues).root ?? [],
1687
1218
  fieldErrors: flattenValibotIssues(result.issues)
1688
1219
  }
1689
1220
  };
@@ -1695,9 +1226,7 @@ const valibotQrl = (qrl) => {
1695
1226
  };
1696
1227
  const valibot$ = /* @__PURE__ */ core.implicit$FirstArg(valibotQrl);
1697
1228
  const flattenZodIssues = (issues) => {
1698
- issues = Array.isArray(issues) ? issues : [
1699
- issues
1700
- ];
1229
+ issues = Array.isArray(issues) ? issues : [issues];
1701
1230
  return issues.reduce((acc, issue) => {
1702
1231
  const isExpectingArray = "expected" in issue && issue.expected === "array";
1703
1232
  const hasArrayType = issue.path.some((path) => typeof path === "number") || isExpectingArray;
@@ -1722,12 +1251,12 @@ const zodQrl = (qrl) => {
1722
1251
  async validate(ev, inputData) {
1723
1252
  const schema = await qrl.resolve().then((obj) => {
1724
1253
  if (typeof obj === "function") {
1725
- obj = obj(zod.z, ev);
1254
+ obj = obj(z__namespace, ev);
1726
1255
  }
1727
- if (obj instanceof zod.z.Schema) {
1256
+ if (obj instanceof z__namespace.Schema) {
1728
1257
  return obj;
1729
1258
  } else {
1730
- return zod.z.object(obj);
1259
+ return z__namespace.object(obj);
1731
1260
  }
1732
1261
  });
1733
1262
  const data = inputData ?? await ev.parseBody();
@@ -1764,98 +1293,101 @@ const serverQrl = (qrl, options) => {
1764
1293
  const headers = options?.headers || {};
1765
1294
  const origin = options?.origin || "";
1766
1295
  const fetchOptions = options?.fetchOptions || {};
1767
- function rpc() {
1768
- return core.$(async function(...args) {
1769
- const abortSignal = args.length > 0 && args[0] instanceof AbortSignal ? args.shift() : void 0;
1770
- if (core.isServer) {
1771
- let requestEvent = globalThis.qcAsyncRequestStore?.getStore();
1772
- if (!requestEvent) {
1773
- const contexts = [
1774
- useQwikRouterEnv()?.ev,
1775
- this,
1776
- internal._getContextEvent()
1777
- ];
1778
- requestEvent = contexts.find((v2) => v2 && Object.prototype.hasOwnProperty.call(v2, "sharedMap") && Object.prototype.hasOwnProperty.call(v2, "cookie"));
1296
+ return core.$(async function(...args) {
1297
+ const abortSignal = args.length > 0 && args[0] instanceof AbortSignal ? args.shift() : void 0;
1298
+ if (core.isServer) {
1299
+ let requestEvent = requestHandler._asyncRequestStore?.getStore();
1300
+ if (!requestEvent) {
1301
+ const contexts = [useQwikRouterEnv()?.ev, this, internal._getContextEvent()];
1302
+ requestEvent = contexts.find(
1303
+ (v2) => v2 && Object.prototype.hasOwnProperty.call(v2, "sharedMap") && Object.prototype.hasOwnProperty.call(v2, "cookie")
1304
+ );
1305
+ }
1306
+ return qrl.apply(requestEvent, core.isDev ? routing.deepFreeze(args) : args);
1307
+ } else {
1308
+ const ctxElm = internal._getContextElement();
1309
+ const filteredArgs = args.map((arg) => {
1310
+ if (arg instanceof SubmitEvent && arg.target instanceof HTMLFormElement) {
1311
+ return new FormData(arg.target);
1312
+ } else if (arg instanceof Event) {
1313
+ return null;
1314
+ } else if (arg instanceof Node) {
1315
+ return null;
1779
1316
  }
1780
- return qrl.apply(requestEvent, core.isDev ? deepFreeze(args) : args);
1317
+ return arg;
1318
+ });
1319
+ const qrlHash = qrl.getHash();
1320
+ let query = "";
1321
+ const config = {
1322
+ ...fetchOptions,
1323
+ method,
1324
+ headers: {
1325
+ ...headers,
1326
+ "Content-Type": "application/qwik-json",
1327
+ Accept: "application/json, application/qwik-json, text/qwik-json-stream, text/plain",
1328
+ // Required so we don't call accidentally
1329
+ "X-QRL": qrlHash
1330
+ },
1331
+ signal: abortSignal
1332
+ };
1333
+ const captured = qrl.getCaptured();
1334
+ let toSend;
1335
+ if (captured?.length) {
1336
+ toSend = [filteredArgs, captured];
1781
1337
  } else {
1782
- const ctxElm = internal._getContextElement();
1783
- const filteredArgs = args.map((arg) => {
1784
- if (arg instanceof SubmitEvent && arg.target instanceof HTMLFormElement) {
1785
- return new FormData(arg.target);
1786
- } else if (arg instanceof Event) {
1787
- return null;
1788
- } else if (arg instanceof Node) {
1789
- return null;
1790
- }
1791
- return arg;
1792
- });
1793
- const qrlHash = qrl.getHash();
1794
- let query = "";
1795
- const config = {
1796
- ...fetchOptions,
1797
- method,
1798
- headers: {
1799
- ...headers,
1800
- "Content-Type": "application/qwik-json",
1801
- Accept: "application/json, application/qwik-json, text/qwik-json-stream, text/plain",
1802
- // Required so we don't call accidentally
1803
- "X-QRL": qrlHash
1804
- },
1805
- signal: abortSignal
1806
- };
1807
- const body = await internal._serialize([
1808
- qrl,
1809
- ...filteredArgs
1810
- ]);
1811
- if (method === "GET") {
1812
- query += `&${QDATA_KEY}=${encodeURIComponent(body)}`;
1813
- } else {
1814
- config.body = body;
1815
- }
1816
- const res = await fetch(`${origin}?${QFN_KEY}=${qrlHash}${query}`, config);
1817
- const contentType = res.headers.get("Content-Type");
1818
- if (res.ok && contentType === "text/qwik-json-stream" && res.body) {
1819
- return (async function* () {
1820
- try {
1821
- for await (const result of deserializeStream(res.body, ctxElm ?? document.documentElement, abortSignal)) {
1822
- yield result;
1823
- }
1824
- } finally {
1825
- if (!abortSignal?.aborted) {
1826
- await res.body.cancel();
1827
- }
1338
+ toSend = filteredArgs.length ? [filteredArgs] : [];
1339
+ }
1340
+ const body = await internal._serialize(toSend);
1341
+ if (method === "GET") {
1342
+ query += `&${routing.QDATA_KEY}=${encodeURIComponent(body)}`;
1343
+ } else {
1344
+ config.body = body;
1345
+ }
1346
+ const res = await fetch(`${origin}?${routing.QFN_KEY}=${qrlHash}${query}`, config);
1347
+ const contentType = res.headers.get("Content-Type");
1348
+ if (res.ok && contentType === "text/qwik-json-stream" && res.body) {
1349
+ return (async function* () {
1350
+ try {
1351
+ for await (const result of deserializeStream(
1352
+ res.body,
1353
+ ctxElm ?? document.documentElement,
1354
+ abortSignal
1355
+ )) {
1356
+ yield result;
1357
+ }
1358
+ } finally {
1359
+ if (!abortSignal?.aborted) {
1360
+ await res.body.cancel();
1828
1361
  }
1829
- })();
1830
- } else if (contentType === "application/qwik-json") {
1831
- const str = await res.text();
1832
- const [obj] = internal._deserialize(str, ctxElm ?? document.documentElement);
1833
- if (res.status >= 400) {
1834
- throw obj;
1835
- }
1836
- return obj;
1837
- } else if (contentType === "application/json") {
1838
- const obj = await res.json();
1839
- if (res.status >= 400) {
1840
- throw obj;
1841
- }
1842
- return obj;
1843
- } else if (contentType === "text/plain" || contentType === "text/html") {
1844
- const str = await res.text();
1845
- if (res.status >= 400) {
1846
- throw str;
1847
1362
  }
1848
- return str;
1363
+ })();
1364
+ } else if (contentType === "application/qwik-json") {
1365
+ const str = await res.text();
1366
+ const [obj] = internal._deserialize(str, ctxElm ?? document.documentElement);
1367
+ if (res.status >= 400) {
1368
+ throw obj;
1849
1369
  }
1370
+ return obj;
1371
+ } else if (contentType === "application/json") {
1372
+ const obj = await res.json();
1373
+ if (res.status >= 400) {
1374
+ throw obj;
1375
+ }
1376
+ return obj;
1377
+ } else if (contentType === "text/plain" || contentType === "text/html") {
1378
+ const str = await res.text();
1379
+ if (res.status >= 400) {
1380
+ throw str;
1381
+ }
1382
+ return str;
1850
1383
  }
1851
- });
1852
- }
1853
- return rpc();
1384
+ }
1385
+ });
1854
1386
  };
1855
1387
  const server$ = /* @__PURE__ */ core.implicit$FirstArg(serverQrl);
1856
1388
  const getValidators = (rest, qrl) => {
1857
1389
  let id;
1858
- let serializationStrategy = DEFAULT_LOADERS_SERIALIZATION_STRATEGY;
1390
+ let serializationStrategy = routing.DEFAULT_LOADERS_SERIALIZATION_STRATEGY;
1859
1391
  const validators = [];
1860
1392
  if (rest.length === 1) {
1861
1393
  const options = rest[0];
@@ -1901,9 +1433,7 @@ const deserializeStream = async function* (stream, ctxElm, abortSignal) {
1901
1433
  if (result.done) {
1902
1434
  break;
1903
1435
  }
1904
- buffer += decoder.decode(result.value, {
1905
- stream: true
1906
- });
1436
+ buffer += decoder.decode(result.value, { stream: true });
1907
1437
  const lines = buffer.split(/\n/);
1908
1438
  buffer = lines.pop();
1909
1439
  for (const line of lines) {
@@ -1915,95 +1445,106 @@ const deserializeStream = async function* (stream, ctxElm, abortSignal) {
1915
1445
  reader.releaseLock();
1916
1446
  }
1917
1447
  };
1918
- const ServiceWorkerRegister = (props) => /* @__PURE__ */ jsxRuntime.jsx("script", {
1919
- type: "module",
1920
- dangerouslySetInnerHTML: swRegister,
1921
- nonce: props.nonce
1922
- });
1448
+ const ServiceWorkerRegister = (props) => /* @__PURE__ */ jsxRuntime.jsx("script", { type: "module", dangerouslySetInnerHTML: swRegister, nonce: props.nonce });
1923
1449
  const Form = ({ action, spaReset, reloadDocument, onSubmit$, ...rest }, key) => {
1924
1450
  if (action) {
1925
1451
  const isArrayApi = Array.isArray(onSubmit$);
1926
1452
  if (isArrayApi) {
1927
- return core.jsx("form", {
1453
+ return core.jsx(
1454
+ "form",
1455
+ {
1456
+ ...rest,
1457
+ action: action.actionPath,
1458
+ "preventdefault:submit": !reloadDocument,
1459
+ onSubmit$: [
1460
+ ...onSubmit$,
1461
+ // action.submit "submitcompleted" event for onSubmitCompleted$ events
1462
+ !reloadDocument ? core.$((evt) => {
1463
+ if (!action.submitted) {
1464
+ return action.submit(evt);
1465
+ }
1466
+ }) : void 0
1467
+ ],
1468
+ method: "post",
1469
+ ["data-spa-reset"]: spaReset ? "true" : void 0
1470
+ },
1471
+ key
1472
+ );
1473
+ }
1474
+ return core.jsx(
1475
+ "form",
1476
+ {
1928
1477
  ...rest,
1929
1478
  action: action.actionPath,
1930
1479
  "preventdefault:submit": !reloadDocument,
1931
1480
  onSubmit$: [
1932
- ...onSubmit$,
1481
+ // Since v2, this fires before the action is executed so it can be prevented
1482
+ onSubmit$,
1933
1483
  // action.submit "submitcompleted" event for onSubmitCompleted$ events
1934
- !reloadDocument ? core.$((evt) => {
1935
- if (!action.submitted) {
1936
- return action.submit(evt);
1937
- }
1938
- }) : void 0
1484
+ !reloadDocument ? action.submit : void 0
1939
1485
  ],
1940
1486
  method: "post",
1941
1487
  ["data-spa-reset"]: spaReset ? "true" : void 0
1942
- }, key);
1943
- }
1944
- return core.jsx("form", {
1945
- ...rest,
1946
- action: action.actionPath,
1947
- "preventdefault:submit": !reloadDocument,
1948
- onSubmit$: [
1949
- // Since v2, this fires before the action is executed so it can be prevented
1950
- onSubmit$,
1951
- // action.submit "submitcompleted" event for onSubmitCompleted$ events
1952
- !reloadDocument ? action.submit : void 0
1953
- ],
1954
- method: "post",
1955
- ["data-spa-reset"]: spaReset ? "true" : void 0
1956
- }, key);
1488
+ },
1489
+ key
1490
+ );
1957
1491
  } else {
1958
- return /* @__PURE__ */ jsxRuntime.jsx(GetForm, {
1959
- spaReset,
1960
- reloadDocument,
1961
- onSubmit$,
1962
- ...rest
1963
- }, key);
1492
+ return /* @__PURE__ */ jsxRuntime.jsx(
1493
+ GetForm,
1494
+ {
1495
+ spaReset,
1496
+ reloadDocument,
1497
+ onSubmit$,
1498
+ ...rest
1499
+ },
1500
+ key
1501
+ );
1964
1502
  }
1965
1503
  };
1966
- const GetForm = core.component$(({ action: _0, spaReset, reloadDocument, onSubmit$, ...rest }) => {
1967
- const nav = useNavigate();
1968
- return /* @__PURE__ */ jsxRuntime.jsx("form", {
1969
- action: "get",
1970
- "preventdefault:submit": !reloadDocument,
1971
- "data-spa-reset": spaReset ? "true" : void 0,
1972
- ...rest,
1973
- onSubmit$: [
1974
- ...Array.isArray(onSubmit$) ? onSubmit$ : [
1975
- onSubmit$
1976
- ],
1977
- core.$(async (_evt, form) => {
1978
- const formData = new FormData(form);
1979
- const params = new URLSearchParams();
1980
- formData.forEach((value, key) => {
1981
- if (typeof value === "string") {
1982
- params.append(key, value);
1983
- }
1984
- });
1985
- await nav("?" + params.toString(), {
1986
- type: "form",
1987
- forceReload: true
1988
- });
1989
- }),
1990
- core.$((_evt, form) => {
1991
- if (form.getAttribute("data-spa-reset") === "true") {
1992
- form.reset();
1993
- }
1994
- form.dispatchEvent(new CustomEvent("submitcompleted", {
1995
- bubbles: false,
1996
- cancelable: false,
1997
- composed: false,
1998
- detail: {
1999
- status: 200
2000
- }
2001
- }));
2002
- })
2003
- ],
2004
- children: /* @__PURE__ */ jsxRuntime.jsx(core.Slot, {})
2005
- });
2006
- });
1504
+ const GetForm = core.component$(
1505
+ ({ action: _0, spaReset, reloadDocument, onSubmit$, ...rest }) => {
1506
+ const nav = useNavigate();
1507
+ return /* @__PURE__ */ jsxRuntime.jsx(
1508
+ "form",
1509
+ {
1510
+ action: "get",
1511
+ "preventdefault:submit": !reloadDocument,
1512
+ "data-spa-reset": spaReset ? "true" : void 0,
1513
+ ...rest,
1514
+ onSubmit$: [
1515
+ ...Array.isArray(onSubmit$) ? onSubmit$ : [onSubmit$],
1516
+ core.$(async (_evt, form) => {
1517
+ const formData = new FormData(form);
1518
+ const params = new URLSearchParams();
1519
+ formData.forEach((value, key) => {
1520
+ if (typeof value === "string") {
1521
+ params.append(key, value);
1522
+ }
1523
+ });
1524
+ await nav("?" + params.toString(), { type: "form", forceReload: true });
1525
+ }),
1526
+ core.$((_evt, form) => {
1527
+ if (form.getAttribute("data-spa-reset") === "true") {
1528
+ form.reset();
1529
+ }
1530
+ form.dispatchEvent(
1531
+ new CustomEvent("submitcompleted", {
1532
+ bubbles: false,
1533
+ cancelable: false,
1534
+ composed: false,
1535
+ detail: {
1536
+ status: 200
1537
+ }
1538
+ })
1539
+ );
1540
+ })
1541
+ // end of array
1542
+ ],
1543
+ children: /* @__PURE__ */ jsxRuntime.jsx(core.Slot, {})
1544
+ }
1545
+ );
1546
+ }
1547
+ );
2007
1548
  const untypedAppUrl = function appUrl(route, params, paramsPrefix = "") {
2008
1549
  const path = route.split("/");
2009
1550
  for (let i = 0; i < path.length; i++) {
@@ -2041,52 +1582,47 @@ function omitProps(obj, keys) {
2041
1582
  return omittedObj;
2042
1583
  }
2043
1584
  const createRenderer = (getOptions) => {
2044
- return (opts) => {
1585
+ return ((opts) => {
2045
1586
  const { jsx, options } = getOptions(opts);
2046
1587
  return server.renderToStream(jsx, options);
2047
- };
1588
+ });
2048
1589
  };
2049
1590
  const DocumentHeadTags = core.component$((props) => {
2050
1591
  let head = useDocumentHead();
2051
1592
  if (props) {
2052
- head = {
2053
- ...head,
2054
- ...props
2055
- };
1593
+ head = { ...head, ...props };
2056
1594
  }
2057
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
2058
- children: [
2059
- head.title && /* @__PURE__ */ jsxRuntime.jsx("title", {
2060
- children: head.title
2061
- }),
2062
- head.meta.map((m) => /* @__PURE__ */ jsxRuntime.jsx("meta", {
2063
- ...m
2064
- })),
2065
- head.links.map((l) => /* @__PURE__ */ jsxRuntime.jsx("link", {
2066
- ...l
2067
- })),
2068
- head.styles.map((s) => {
2069
- const props2 = s.props || s;
2070
- return /* @__PURE__ */ core.createElement("style", {
1595
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1596
+ head.title && /* @__PURE__ */ jsxRuntime.jsx("title", { children: head.title }),
1597
+ head.meta.map((m) => /* @__PURE__ */ jsxRuntime.jsx("meta", { ...m })),
1598
+ head.links.map((l) => /* @__PURE__ */ jsxRuntime.jsx("link", { ...l })),
1599
+ head.styles.map((s) => {
1600
+ const props2 = s.props || s;
1601
+ return /* @__PURE__ */ core.createElement(
1602
+ "style",
1603
+ {
2071
1604
  ...props2,
2072
1605
  dangerouslySetInnerHTML: s.style || props2.dangerouslySetInnerHTML,
2073
1606
  key: s.key
2074
- });
2075
- }),
2076
- head.scripts.map((s) => {
2077
- const props2 = s.props || s;
2078
- return /* @__PURE__ */ core.createElement("script", {
1607
+ }
1608
+ );
1609
+ }),
1610
+ head.scripts.map((s) => {
1611
+ const props2 = s.props || s;
1612
+ return /* @__PURE__ */ core.createElement(
1613
+ "script",
1614
+ {
2079
1615
  ...props2,
2080
1616
  dangerouslySetInnerHTML: s.script || props2.dangerouslySetInnerHTML,
2081
1617
  key: s.key
2082
- });
2083
- })
2084
- ]
2085
- });
1618
+ }
1619
+ );
1620
+ })
1621
+ ] });
2086
1622
  });
2087
1623
  Object.defineProperty(exports, "z", {
2088
1624
  enumerable: true,
2089
- get: () => zod.z
1625
+ get: () => z.z
2090
1626
  });
2091
1627
  exports.DocumentHeadTags = DocumentHeadTags;
2092
1628
  exports.ErrorBoundary = ErrorBoundary;