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