@gulbanana/jagman 0.0.1

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 (220) hide show
  1. package/LICENSE +663 -0
  2. package/README.md +40 -0
  3. package/bin/jagman.js +35 -0
  4. package/build/client/_app/immutable/assets/0.B3c8us65.css +1 -0
  5. package/build/client/_app/immutable/assets/0.B3c8us65.css.br +0 -0
  6. package/build/client/_app/immutable/assets/0.B3c8us65.css.gz +0 -0
  7. package/build/client/_app/immutable/assets/2.QhF3SmLf.css +1 -0
  8. package/build/client/_app/immutable/assets/2.QhF3SmLf.css.br +0 -0
  9. package/build/client/_app/immutable/assets/2.QhF3SmLf.css.gz +0 -0
  10. package/build/client/_app/immutable/assets/4.BoAskxZr.css +1 -0
  11. package/build/client/_app/immutable/assets/4.BoAskxZr.css.br +0 -0
  12. package/build/client/_app/immutable/assets/4.BoAskxZr.css.gz +0 -0
  13. package/build/client/_app/immutable/assets/5.DYpN9IwI.css +1 -0
  14. package/build/client/_app/immutable/assets/5.DYpN9IwI.css.br +0 -0
  15. package/build/client/_app/immutable/assets/5.DYpN9IwI.css.gz +0 -0
  16. package/build/client/_app/immutable/assets/7.BBPBRqyF.css +1 -0
  17. package/build/client/_app/immutable/assets/7.BBPBRqyF.css.br +0 -0
  18. package/build/client/_app/immutable/assets/7.BBPBRqyF.css.gz +0 -0
  19. package/build/client/_app/immutable/assets/8.WP6ZlE0M.css +1 -0
  20. package/build/client/_app/immutable/assets/8.WP6ZlE0M.css.br +0 -0
  21. package/build/client/_app/immutable/assets/8.WP6ZlE0M.css.gz +0 -0
  22. package/build/client/_app/immutable/assets/9.DH8YZ1_b.css +1 -0
  23. package/build/client/_app/immutable/assets/9.DH8YZ1_b.css.br +0 -0
  24. package/build/client/_app/immutable/assets/9.DH8YZ1_b.css.gz +0 -0
  25. package/build/client/_app/immutable/assets/ErrorSpan.BarpW_JY.css +1 -0
  26. package/build/client/_app/immutable/assets/ErrorSpan.BarpW_JY.css.br +0 -0
  27. package/build/client/_app/immutable/assets/ErrorSpan.BarpW_JY.css.gz +0 -0
  28. package/build/client/_app/immutable/assets/Icon.Di_GsCEs.css +1 -0
  29. package/build/client/_app/immutable/assets/Icon.Di_GsCEs.css.br +0 -0
  30. package/build/client/_app/immutable/assets/Icon.Di_GsCEs.css.gz +0 -0
  31. package/build/client/_app/immutable/assets/Pane.LvSW-vL-.css +1 -0
  32. package/build/client/_app/immutable/assets/Pane.LvSW-vL-.css.br +0 -0
  33. package/build/client/_app/immutable/assets/Pane.LvSW-vL-.css.gz +0 -0
  34. package/build/client/_app/immutable/assets/favicon.DGDeBov5.svg +191 -0
  35. package/build/client/_app/immutable/assets/favicon.DGDeBov5.svg.br +0 -0
  36. package/build/client/_app/immutable/assets/favicon.DGDeBov5.svg.gz +0 -0
  37. package/build/client/_app/immutable/assets/feather-sprite.BfIm3Xr9.svg +1 -0
  38. package/build/client/_app/immutable/assets/feather-sprite.BfIm3Xr9.svg.br +0 -0
  39. package/build/client/_app/immutable/assets/feather-sprite.BfIm3Xr9.svg.gz +0 -0
  40. package/build/client/_app/immutable/assets/gc-dark.DHisUerN.svg +101 -0
  41. package/build/client/_app/immutable/assets/gc-dark.DHisUerN.svg.br +0 -0
  42. package/build/client/_app/immutable/assets/gc-dark.DHisUerN.svg.gz +0 -0
  43. package/build/client/_app/immutable/assets/gc-light.C55NzigM.svg +100 -0
  44. package/build/client/_app/immutable/assets/gc-light.C55NzigM.svg.br +0 -0
  45. package/build/client/_app/immutable/assets/gc-light.C55NzigM.svg.gz +0 -0
  46. package/build/client/_app/immutable/chunks/B3ZkAhB4.js +1 -0
  47. package/build/client/_app/immutable/chunks/B3ZkAhB4.js.br +0 -0
  48. package/build/client/_app/immutable/chunks/B3ZkAhB4.js.gz +0 -0
  49. package/build/client/_app/immutable/chunks/B9tazVuH.js +2 -0
  50. package/build/client/_app/immutable/chunks/B9tazVuH.js.br +0 -0
  51. package/build/client/_app/immutable/chunks/B9tazVuH.js.gz +0 -0
  52. package/build/client/_app/immutable/chunks/BdkrN5mN.js +1 -0
  53. package/build/client/_app/immutable/chunks/BdkrN5mN.js.br +0 -0
  54. package/build/client/_app/immutable/chunks/BdkrN5mN.js.gz +0 -0
  55. package/build/client/_app/immutable/chunks/ByNAvWKi.js +1 -0
  56. package/build/client/_app/immutable/chunks/ByNAvWKi.js.br +0 -0
  57. package/build/client/_app/immutable/chunks/ByNAvWKi.js.gz +0 -0
  58. package/build/client/_app/immutable/chunks/C8oOvULD.js +1 -0
  59. package/build/client/_app/immutable/chunks/C8oOvULD.js.br +0 -0
  60. package/build/client/_app/immutable/chunks/C8oOvULD.js.gz +0 -0
  61. package/build/client/_app/immutable/chunks/CCH3sm1V.js +1 -0
  62. package/build/client/_app/immutable/chunks/CCH3sm1V.js.br +0 -0
  63. package/build/client/_app/immutable/chunks/CCH3sm1V.js.gz +0 -0
  64. package/build/client/_app/immutable/chunks/CDD8JGhu.js +1 -0
  65. package/build/client/_app/immutable/chunks/CDD8JGhu.js.br +0 -0
  66. package/build/client/_app/immutable/chunks/CDD8JGhu.js.gz +0 -0
  67. package/build/client/_app/immutable/chunks/CKIpFoVh.js +1 -0
  68. package/build/client/_app/immutable/chunks/CKIpFoVh.js.br +0 -0
  69. package/build/client/_app/immutable/chunks/CKIpFoVh.js.gz +0 -0
  70. package/build/client/_app/immutable/chunks/CMyhPqp1.js +1 -0
  71. package/build/client/_app/immutable/chunks/CMyhPqp1.js.br +0 -0
  72. package/build/client/_app/immutable/chunks/CMyhPqp1.js.gz +0 -0
  73. package/build/client/_app/immutable/chunks/COe4_SPO.js +1 -0
  74. package/build/client/_app/immutable/chunks/COe4_SPO.js.br +0 -0
  75. package/build/client/_app/immutable/chunks/COe4_SPO.js.gz +0 -0
  76. package/build/client/_app/immutable/chunks/CaZKc3PV.js +2 -0
  77. package/build/client/_app/immutable/chunks/CaZKc3PV.js.br +0 -0
  78. package/build/client/_app/immutable/chunks/CaZKc3PV.js.gz +0 -0
  79. package/build/client/_app/immutable/chunks/Cj8zunyE.js +1 -0
  80. package/build/client/_app/immutable/chunks/Cj8zunyE.js.br +2 -0
  81. package/build/client/_app/immutable/chunks/Cj8zunyE.js.gz +0 -0
  82. package/build/client/_app/immutable/chunks/CvfIoSRb.js +1 -0
  83. package/build/client/_app/immutable/chunks/CvfIoSRb.js.br +0 -0
  84. package/build/client/_app/immutable/chunks/CvfIoSRb.js.gz +0 -0
  85. package/build/client/_app/immutable/chunks/DhBP0au1.js +1 -0
  86. package/build/client/_app/immutable/chunks/DhBP0au1.js.br +0 -0
  87. package/build/client/_app/immutable/chunks/DhBP0au1.js.gz +0 -0
  88. package/build/client/_app/immutable/chunks/F2VqmO6x.js +1 -0
  89. package/build/client/_app/immutable/chunks/F2VqmO6x.js.br +0 -0
  90. package/build/client/_app/immutable/chunks/F2VqmO6x.js.gz +0 -0
  91. package/build/client/_app/immutable/chunks/hlNgmD7C.js +1 -0
  92. package/build/client/_app/immutable/chunks/hlNgmD7C.js.br +0 -0
  93. package/build/client/_app/immutable/chunks/hlNgmD7C.js.gz +0 -0
  94. package/build/client/_app/immutable/chunks/tW0gGpbB.js +2 -0
  95. package/build/client/_app/immutable/chunks/tW0gGpbB.js.br +0 -0
  96. package/build/client/_app/immutable/chunks/tW0gGpbB.js.gz +0 -0
  97. package/build/client/_app/immutable/entry/app.BJglbmCx.js +2 -0
  98. package/build/client/_app/immutable/entry/app.BJglbmCx.js.br +0 -0
  99. package/build/client/_app/immutable/entry/app.BJglbmCx.js.gz +0 -0
  100. package/build/client/_app/immutable/entry/start.f6OGjaz6.js +1 -0
  101. package/build/client/_app/immutable/entry/start.f6OGjaz6.js.br +2 -0
  102. package/build/client/_app/immutable/entry/start.f6OGjaz6.js.gz +0 -0
  103. package/build/client/_app/immutable/nodes/0.BcUb2smo.js +1 -0
  104. package/build/client/_app/immutable/nodes/0.BcUb2smo.js.br +0 -0
  105. package/build/client/_app/immutable/nodes/0.BcUb2smo.js.gz +0 -0
  106. package/build/client/_app/immutable/nodes/1.xem2AZVD.js +1 -0
  107. package/build/client/_app/immutable/nodes/1.xem2AZVD.js.br +0 -0
  108. package/build/client/_app/immutable/nodes/1.xem2AZVD.js.gz +0 -0
  109. package/build/client/_app/immutable/nodes/2.CDTJMs0M.js +1 -0
  110. package/build/client/_app/immutable/nodes/2.CDTJMs0M.js.br +1 -0
  111. package/build/client/_app/immutable/nodes/2.CDTJMs0M.js.gz +0 -0
  112. package/build/client/_app/immutable/nodes/3.Kr4ly1KY.js +1 -0
  113. package/build/client/_app/immutable/nodes/3.Kr4ly1KY.js.br +0 -0
  114. package/build/client/_app/immutable/nodes/3.Kr4ly1KY.js.gz +0 -0
  115. package/build/client/_app/immutable/nodes/4.CkrrNwwZ.js +1 -0
  116. package/build/client/_app/immutable/nodes/4.CkrrNwwZ.js.br +0 -0
  117. package/build/client/_app/immutable/nodes/4.CkrrNwwZ.js.gz +0 -0
  118. package/build/client/_app/immutable/nodes/5.Ck9pAYWh.js +3 -0
  119. package/build/client/_app/immutable/nodes/5.Ck9pAYWh.js.br +0 -0
  120. package/build/client/_app/immutable/nodes/5.Ck9pAYWh.js.gz +0 -0
  121. package/build/client/_app/immutable/nodes/6.BZru-VFo.js +1 -0
  122. package/build/client/_app/immutable/nodes/6.BZru-VFo.js.br +0 -0
  123. package/build/client/_app/immutable/nodes/6.BZru-VFo.js.gz +0 -0
  124. package/build/client/_app/immutable/nodes/7.DQKVlDfB.js +1 -0
  125. package/build/client/_app/immutable/nodes/7.DQKVlDfB.js.br +0 -0
  126. package/build/client/_app/immutable/nodes/7.DQKVlDfB.js.gz +0 -0
  127. package/build/client/_app/immutable/nodes/8.CRaTbcsI.js +1 -0
  128. package/build/client/_app/immutable/nodes/8.CRaTbcsI.js.br +0 -0
  129. package/build/client/_app/immutable/nodes/8.CRaTbcsI.js.gz +0 -0
  130. package/build/client/_app/immutable/nodes/9.ZY9fPTpH.js +1 -0
  131. package/build/client/_app/immutable/nodes/9.ZY9fPTpH.js.br +0 -0
  132. package/build/client/_app/immutable/nodes/9.ZY9fPTpH.js.gz +0 -0
  133. package/build/client/_app/version.json +1 -0
  134. package/build/client/_app/version.json.br +0 -0
  135. package/build/client/_app/version.json.gz +0 -0
  136. package/build/env.js +94 -0
  137. package/build/handler.js +1494 -0
  138. package/build/index.js +345 -0
  139. package/build/server/chunks/0-DFKHNL47.js +9 -0
  140. package/build/server/chunks/0-DFKHNL47.js.map +1 -0
  141. package/build/server/chunks/1-rBV5UzK8.js +9 -0
  142. package/build/server/chunks/1-rBV5UzK8.js.map +1 -0
  143. package/build/server/chunks/2-DNhpm2f0.js +9 -0
  144. package/build/server/chunks/2-DNhpm2f0.js.map +1 -0
  145. package/build/server/chunks/3-BriZP-4z.js +9 -0
  146. package/build/server/chunks/3-BriZP-4z.js.map +1 -0
  147. package/build/server/chunks/4-BRqbjiow.js +9 -0
  148. package/build/server/chunks/4-BRqbjiow.js.map +1 -0
  149. package/build/server/chunks/5-DxPUkn7K.js +9 -0
  150. package/build/server/chunks/5-DxPUkn7K.js.map +1 -0
  151. package/build/server/chunks/6-OQ8ks1e7.js +19 -0
  152. package/build/server/chunks/6-OQ8ks1e7.js.map +1 -0
  153. package/build/server/chunks/7-wbR5qPH1.js +9 -0
  154. package/build/server/chunks/7-wbR5qPH1.js.map +1 -0
  155. package/build/server/chunks/8-BL7_9qSi.js +9 -0
  156. package/build/server/chunks/8-BL7_9qSi.js.map +1 -0
  157. package/build/server/chunks/9-DC9G3Slz.js +9 -0
  158. package/build/server/chunks/9-DC9G3Slz.js.map +1 -0
  159. package/build/server/chunks/ErrorSpan-BSqKaGqG.js +9 -0
  160. package/build/server/chunks/ErrorSpan-BSqKaGqG.js.map +1 -0
  161. package/build/server/chunks/Icon-Dr5EwAkb.js +10 -0
  162. package/build/server/chunks/Icon-Dr5EwAkb.js.map +1 -0
  163. package/build/server/chunks/Pane-DcSwhEiL.js +41 -0
  164. package/build/server/chunks/Pane-DcSwhEiL.js.map +1 -0
  165. package/build/server/chunks/_error.svelte-Cw0MGN-r.js +18 -0
  166. package/build/server/chunks/_error.svelte-Cw0MGN-r.js.map +1 -0
  167. package/build/server/chunks/_layout.svelte-CFeu3znf.js +14 -0
  168. package/build/server/chunks/_layout.svelte-CFeu3znf.js.map +1 -0
  169. package/build/server/chunks/_layout.svelte-CQ3MtcgC.js +33 -0
  170. package/build/server/chunks/_layout.svelte-CQ3MtcgC.js.map +1 -0
  171. package/build/server/chunks/_layout.svelte-D_GQeKpE.js +9 -0
  172. package/build/server/chunks/_layout.svelte-D_GQeKpE.js.map +1 -0
  173. package/build/server/chunks/_page.svelte-C8O6i1zq.js +282 -0
  174. package/build/server/chunks/_page.svelte-C8O6i1zq.js.map +1 -0
  175. package/build/server/chunks/_page.svelte-CfJpXtNh.js +104 -0
  176. package/build/server/chunks/_page.svelte-CfJpXtNh.js.map +1 -0
  177. package/build/server/chunks/_page.svelte-CkpYjdBP.js +68 -0
  178. package/build/server/chunks/_page.svelte-CkpYjdBP.js.map +1 -0
  179. package/build/server/chunks/_page.svelte-DbAHpdpc.js +6 -0
  180. package/build/server/chunks/_page.svelte-DbAHpdpc.js.map +1 -0
  181. package/build/server/chunks/agent-C7A3zEr3.js +708 -0
  182. package/build/server/chunks/agent-C7A3zEr3.js.map +1 -0
  183. package/build/server/chunks/data.remote-3GWudL8p.js +28 -0
  184. package/build/server/chunks/data.remote-3GWudL8p.js.map +1 -0
  185. package/build/server/chunks/data.remote2-DPGOveFg.js +23 -0
  186. package/build/server/chunks/data.remote2-DPGOveFg.js.map +1 -0
  187. package/build/server/chunks/data.remote3-CDhxyD61.js +25 -0
  188. package/build/server/chunks/data.remote3-CDhxyD61.js.map +1 -0
  189. package/build/server/chunks/error.svelte-D0cH8izO.js +13 -0
  190. package/build/server/chunks/error.svelte-D0cH8izO.js.map +1 -0
  191. package/build/server/chunks/exports-DsGzTZ0S.js +121 -0
  192. package/build/server/chunks/exports-DsGzTZ0S.js.map +1 -0
  193. package/build/server/chunks/hooks.server-Cke-TrVc.js +14 -0
  194. package/build/server/chunks/hooks.server-Cke-TrVc.js.map +1 -0
  195. package/build/server/chunks/index-CoD1IJuy.js +190 -0
  196. package/build/server/chunks/index-CoD1IJuy.js.map +1 -0
  197. package/build/server/chunks/index-DwoWbz0A.js +1819 -0
  198. package/build/server/chunks/index-DwoWbz0A.js.map +1 -0
  199. package/build/server/chunks/index2-Ej5CkWKF.js +44 -0
  200. package/build/server/chunks/index2-Ej5CkWKF.js.map +1 -0
  201. package/build/server/chunks/mock-data-D8qN6SIX.js +18 -0
  202. package/build/server/chunks/mock-data-D8qN6SIX.js.map +1 -0
  203. package/build/server/chunks/opencode-vgZ5DMQ2.js +452 -0
  204. package/build/server/chunks/opencode-vgZ5DMQ2.js.map +1 -0
  205. package/build/server/chunks/remote-1jrju9-CYV2OBS9.js +16 -0
  206. package/build/server/chunks/remote-1jrju9-CYV2OBS9.js.map +1 -0
  207. package/build/server/chunks/remote-1t3e9fx-Bq2E-Huu.js +16 -0
  208. package/build/server/chunks/remote-1t3e9fx-Bq2E-Huu.js.map +1 -0
  209. package/build/server/chunks/remote-dsfuc2-DwI4AU9q.js +15 -0
  210. package/build/server/chunks/remote-dsfuc2-DwI4AU9q.js.map +1 -0
  211. package/build/server/chunks/root-C5lyo0VT.js +2906 -0
  212. package/build/server/chunks/root-C5lyo0VT.js.map +1 -0
  213. package/build/server/chunks/shared-bytReIJX.js +1236 -0
  214. package/build/server/chunks/shared-bytReIJX.js.map +1 -0
  215. package/build/server/index.js +4422 -0
  216. package/build/server/index.js.map +1 -0
  217. package/build/server/manifest.js +83 -0
  218. package/build/server/manifest.js.map +1 -0
  219. package/build/shims.js +32 -0
  220. package/package.json +70 -0
@@ -0,0 +1,4422 @@
1
+ import { r as root, d as decode_pathname, D as DEV, n as normalize_path, c as disable_search, w as with_request_store, e as decode_params, f as text_encoder, h as resolve, m as make_trackable, i as get_relative_path, a as base64_encode, t as text_decoder } from './chunks/root-C5lyo0VT.js';
2
+ import { j as json, t as text, R as Redirect, S as SvelteKitError, H as HttpError, e as error, A as ActionFailure } from './chunks/index-CoD1IJuy.js';
3
+ import { f as format_server_error, i as is_form_content_type, T as TRAILING_SLASH_PARAM, I as INVALIDATED_PARAM, a as has_prerendered_path, b as handle_fatal_error, r as redirect_response, m as method_not_allowed, n as negotiate, g as get_global_name, c as create_remote_key, d as serialize_uses, e as clarify_devalue_error, h as handle_error_and_jsonify, E as ENDPOINT_METHODS, P as PAGE_METHODS, j as get_status, k as normalize_error, l as static_error_page, p as parse_remote_arg, o as stringify, q as deserialize_binary_form, t as get_node_type, u as stringify$1, v as escape_html, S as SVELTE_KIT_ASSETS } from './chunks/shared-bytReIJX.js';
4
+ import { v as validate_layout_server_exports, a as validate_layout_exports, b as validate_page_server_exports, c as validate_page_exports, w as writable, r as readable } from './chunks/exports-DsGzTZ0S.js';
5
+ import { ad as uneval } from './chunks/index-DwoWbz0A.js';
6
+
7
+ /**
8
+ * @template {{ tracing: { enabled: boolean, root: import('@opentelemetry/api').Span, current: import('@opentelemetry/api').Span } }} T
9
+ * @param {T} event_like
10
+ * @param {import('@opentelemetry/api').Span} current
11
+ * @returns {T}
12
+ */
13
+ function merge_tracing(event_like, current) {
14
+ return {
15
+ ...event_like,
16
+ tracing: {
17
+ ...event_like.tracing,
18
+ current
19
+ }
20
+ };
21
+ }
22
+
23
+ let base = "";
24
+ let assets = base;
25
+ const app_dir = "_app";
26
+ const relative = true;
27
+ const initial = { base, assets };
28
+ function override(paths) {
29
+ base = paths.base;
30
+ assets = paths.assets;
31
+ }
32
+ function reset() {
33
+ base = initial.base;
34
+ assets = initial.assets;
35
+ }
36
+
37
+ let public_env = {};
38
+ function set_private_env(environment) {
39
+ }
40
+ function set_public_env(environment) {
41
+ public_env = environment;
42
+ }
43
+ let read_implementation = null;
44
+ function set_read_implementation(fn) {
45
+ read_implementation = fn;
46
+ }
47
+ const options = {
48
+ app_template_contains_nonce: false,
49
+ async: false,
50
+ csp: { "mode": "auto", "directives": { "upgrade-insecure-requests": false, "block-all-mixed-content": false }, "reportOnly": { "upgrade-insecure-requests": false, "block-all-mixed-content": false } },
51
+ csrf_check_origin: true,
52
+ csrf_trusted_origins: [],
53
+ embedded: false,
54
+ env_public_prefix: "PUBLIC_",
55
+ env_private_prefix: "",
56
+ hash_routing: false,
57
+ hooks: null,
58
+ // added lazily, via `get_hooks`
59
+ preload_strategy: "modulepreload",
60
+ root,
61
+ service_worker: false,
62
+ service_worker_options: void 0,
63
+ templates: {
64
+ app: ({ head, body, assets, nonce, env }) => '<!doctype html>\n<html lang="en">\n\n<head>\n <meta charset="utf-8" />\n <meta name="viewport" content="width=device-width, initial-scale=1" />\n ' + head + '\n</head>\n\n<body data-sveltekit-preload-data="hover">\n <div style="display: contents">' + body + "</div>\n</body>\n\n</html>",
65
+ error: ({ status, message }) => '<!doctype html>\n<html lang="en">\n <head>\n <meta charset="utf-8" />\n <title>' + message + `</title>
66
+
67
+ <style>
68
+ body {
69
+ --bg: white;
70
+ --fg: #222;
71
+ --divider: #ccc;
72
+ background: var(--bg);
73
+ color: var(--fg);
74
+ font-family:
75
+ system-ui,
76
+ -apple-system,
77
+ BlinkMacSystemFont,
78
+ 'Segoe UI',
79
+ Roboto,
80
+ Oxygen,
81
+ Ubuntu,
82
+ Cantarell,
83
+ 'Open Sans',
84
+ 'Helvetica Neue',
85
+ sans-serif;
86
+ display: flex;
87
+ align-items: center;
88
+ justify-content: center;
89
+ height: 100vh;
90
+ margin: 0;
91
+ }
92
+
93
+ .error {
94
+ display: flex;
95
+ align-items: center;
96
+ max-width: 32rem;
97
+ margin: 0 1rem;
98
+ }
99
+
100
+ .status {
101
+ font-weight: 200;
102
+ font-size: 3rem;
103
+ line-height: 1;
104
+ position: relative;
105
+ top: -0.05rem;
106
+ }
107
+
108
+ .message {
109
+ border-left: 1px solid var(--divider);
110
+ padding: 0 0 0 1rem;
111
+ margin: 0 0 0 1rem;
112
+ min-height: 2.5rem;
113
+ display: flex;
114
+ align-items: center;
115
+ }
116
+
117
+ .message h1 {
118
+ font-weight: 400;
119
+ font-size: 1em;
120
+ margin: 0;
121
+ }
122
+
123
+ @media (prefers-color-scheme: dark) {
124
+ body {
125
+ --bg: #222;
126
+ --fg: #ddd;
127
+ --divider: #666;
128
+ }
129
+ }
130
+ </style>
131
+ </head>
132
+ <body>
133
+ <div class="error">
134
+ <span class="status">` + status + '</span>\n <div class="message">\n <h1>' + message + "</h1>\n </div>\n </div>\n </body>\n</html>\n"
135
+ },
136
+ version_hash: "wvumzh"
137
+ };
138
+ async function get_hooks() {
139
+ let handle;
140
+ let handleFetch;
141
+ let handleError;
142
+ let handleValidationError;
143
+ let init;
144
+ ({ handle, handleFetch, handleError, handleValidationError, init } = await import('./chunks/hooks.server-Cke-TrVc.js'));
145
+ let reroute;
146
+ let transport;
147
+ return {
148
+ handle,
149
+ handleFetch,
150
+ handleError,
151
+ handleValidationError,
152
+ init,
153
+ reroute,
154
+ transport
155
+ };
156
+ }
157
+
158
+ var cookie = {};
159
+
160
+ /*!
161
+ * cookie
162
+ * Copyright(c) 2012-2014 Roman Shtylman
163
+ * Copyright(c) 2015 Douglas Christopher Wilson
164
+ * MIT Licensed
165
+ */
166
+
167
+ var hasRequiredCookie;
168
+
169
+ function requireCookie () {
170
+ if (hasRequiredCookie) return cookie;
171
+ hasRequiredCookie = 1;
172
+
173
+ /**
174
+ * Module exports.
175
+ * @public
176
+ */
177
+
178
+ cookie.parse = parse;
179
+ cookie.serialize = serialize;
180
+
181
+ /**
182
+ * Module variables.
183
+ * @private
184
+ */
185
+
186
+ var __toString = Object.prototype.toString;
187
+
188
+ /**
189
+ * RegExp to match field-content in RFC 7230 sec 3.2
190
+ *
191
+ * field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
192
+ * field-vchar = VCHAR / obs-text
193
+ * obs-text = %x80-FF
194
+ */
195
+
196
+ var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
197
+
198
+ /**
199
+ * Parse a cookie header.
200
+ *
201
+ * Parse the given cookie header string into an object
202
+ * The object has the various cookies as keys(names) => values
203
+ *
204
+ * @param {string} str
205
+ * @param {object} [options]
206
+ * @return {object}
207
+ * @public
208
+ */
209
+
210
+ function parse(str, options) {
211
+ if (typeof str !== 'string') {
212
+ throw new TypeError('argument str must be a string');
213
+ }
214
+
215
+ var obj = {};
216
+ var opt = options || {};
217
+ var dec = opt.decode || decode;
218
+
219
+ var index = 0;
220
+ while (index < str.length) {
221
+ var eqIdx = str.indexOf('=', index);
222
+
223
+ // no more cookie pairs
224
+ if (eqIdx === -1) {
225
+ break
226
+ }
227
+
228
+ var endIdx = str.indexOf(';', index);
229
+
230
+ if (endIdx === -1) {
231
+ endIdx = str.length;
232
+ } else if (endIdx < eqIdx) {
233
+ // backtrack on prior semicolon
234
+ index = str.lastIndexOf(';', eqIdx - 1) + 1;
235
+ continue
236
+ }
237
+
238
+ var key = str.slice(index, eqIdx).trim();
239
+
240
+ // only assign once
241
+ if (undefined === obj[key]) {
242
+ var val = str.slice(eqIdx + 1, endIdx).trim();
243
+
244
+ // quoted values
245
+ if (val.charCodeAt(0) === 0x22) {
246
+ val = val.slice(1, -1);
247
+ }
248
+
249
+ obj[key] = tryDecode(val, dec);
250
+ }
251
+
252
+ index = endIdx + 1;
253
+ }
254
+
255
+ return obj;
256
+ }
257
+
258
+ /**
259
+ * Serialize data into a cookie header.
260
+ *
261
+ * Serialize the a name value pair into a cookie string suitable for
262
+ * http headers. An optional options object specified cookie parameters.
263
+ *
264
+ * serialize('foo', 'bar', { httpOnly: true })
265
+ * => "foo=bar; httpOnly"
266
+ *
267
+ * @param {string} name
268
+ * @param {string} val
269
+ * @param {object} [options]
270
+ * @return {string}
271
+ * @public
272
+ */
273
+
274
+ function serialize(name, val, options) {
275
+ var opt = options || {};
276
+ var enc = opt.encode || encode;
277
+
278
+ if (typeof enc !== 'function') {
279
+ throw new TypeError('option encode is invalid');
280
+ }
281
+
282
+ if (!fieldContentRegExp.test(name)) {
283
+ throw new TypeError('argument name is invalid');
284
+ }
285
+
286
+ var value = enc(val);
287
+
288
+ if (value && !fieldContentRegExp.test(value)) {
289
+ throw new TypeError('argument val is invalid');
290
+ }
291
+
292
+ var str = name + '=' + value;
293
+
294
+ if (null != opt.maxAge) {
295
+ var maxAge = opt.maxAge - 0;
296
+
297
+ if (isNaN(maxAge) || !isFinite(maxAge)) {
298
+ throw new TypeError('option maxAge is invalid')
299
+ }
300
+
301
+ str += '; Max-Age=' + Math.floor(maxAge);
302
+ }
303
+
304
+ if (opt.domain) {
305
+ if (!fieldContentRegExp.test(opt.domain)) {
306
+ throw new TypeError('option domain is invalid');
307
+ }
308
+
309
+ str += '; Domain=' + opt.domain;
310
+ }
311
+
312
+ if (opt.path) {
313
+ if (!fieldContentRegExp.test(opt.path)) {
314
+ throw new TypeError('option path is invalid');
315
+ }
316
+
317
+ str += '; Path=' + opt.path;
318
+ }
319
+
320
+ if (opt.expires) {
321
+ var expires = opt.expires;
322
+
323
+ if (!isDate(expires) || isNaN(expires.valueOf())) {
324
+ throw new TypeError('option expires is invalid');
325
+ }
326
+
327
+ str += '; Expires=' + expires.toUTCString();
328
+ }
329
+
330
+ if (opt.httpOnly) {
331
+ str += '; HttpOnly';
332
+ }
333
+
334
+ if (opt.secure) {
335
+ str += '; Secure';
336
+ }
337
+
338
+ if (opt.partitioned) {
339
+ str += '; Partitioned';
340
+ }
341
+
342
+ if (opt.priority) {
343
+ var priority = typeof opt.priority === 'string'
344
+ ? opt.priority.toLowerCase()
345
+ : opt.priority;
346
+
347
+ switch (priority) {
348
+ case 'low':
349
+ str += '; Priority=Low';
350
+ break
351
+ case 'medium':
352
+ str += '; Priority=Medium';
353
+ break
354
+ case 'high':
355
+ str += '; Priority=High';
356
+ break
357
+ default:
358
+ throw new TypeError('option priority is invalid')
359
+ }
360
+ }
361
+
362
+ if (opt.sameSite) {
363
+ var sameSite = typeof opt.sameSite === 'string'
364
+ ? opt.sameSite.toLowerCase() : opt.sameSite;
365
+
366
+ switch (sameSite) {
367
+ case true:
368
+ str += '; SameSite=Strict';
369
+ break;
370
+ case 'lax':
371
+ str += '; SameSite=Lax';
372
+ break;
373
+ case 'strict':
374
+ str += '; SameSite=Strict';
375
+ break;
376
+ case 'none':
377
+ str += '; SameSite=None';
378
+ break;
379
+ default:
380
+ throw new TypeError('option sameSite is invalid');
381
+ }
382
+ }
383
+
384
+ return str;
385
+ }
386
+
387
+ /**
388
+ * URL-decode string value. Optimized to skip native call when no %.
389
+ *
390
+ * @param {string} str
391
+ * @returns {string}
392
+ */
393
+
394
+ function decode (str) {
395
+ return str.indexOf('%') !== -1
396
+ ? decodeURIComponent(str)
397
+ : str
398
+ }
399
+
400
+ /**
401
+ * URL-encode value.
402
+ *
403
+ * @param {string} val
404
+ * @returns {string}
405
+ */
406
+
407
+ function encode (val) {
408
+ return encodeURIComponent(val)
409
+ }
410
+
411
+ /**
412
+ * Determine if value is a Date.
413
+ *
414
+ * @param {*} val
415
+ * @private
416
+ */
417
+
418
+ function isDate (val) {
419
+ return __toString.call(val) === '[object Date]' ||
420
+ val instanceof Date
421
+ }
422
+
423
+ /**
424
+ * Try decoding a string using a decoding function.
425
+ *
426
+ * @param {string} str
427
+ * @param {function} decode
428
+ * @private
429
+ */
430
+
431
+ function tryDecode(str, decode) {
432
+ try {
433
+ return decode(str);
434
+ } catch (e) {
435
+ return str;
436
+ }
437
+ }
438
+ return cookie;
439
+ }
440
+
441
+ var cookieExports = requireCookie();
442
+
443
+ var defaultParseOptions = {
444
+ decodeValues: true,
445
+ map: false,
446
+ silent: false,
447
+ split: "auto", // auto = split strings but not arrays
448
+ };
449
+
450
+ function isForbiddenKey(key) {
451
+ return typeof key !== "string" || key in {};
452
+ }
453
+
454
+ function createNullObj() {
455
+ return Object.create(null);
456
+ }
457
+
458
+ function isNonEmptyString(str) {
459
+ return typeof str === "string" && !!str.trim();
460
+ }
461
+
462
+ function parseString(setCookieValue, options) {
463
+ var parts = setCookieValue.split(";").filter(isNonEmptyString);
464
+
465
+ var nameValuePairStr = parts.shift();
466
+ var parsed = parseNameValuePair(nameValuePairStr);
467
+ var name = parsed.name;
468
+ var value = parsed.value;
469
+
470
+ options = options
471
+ ? Object.assign({}, defaultParseOptions, options)
472
+ : defaultParseOptions;
473
+
474
+ if (isForbiddenKey(name)) {
475
+ return null;
476
+ }
477
+
478
+ try {
479
+ value = options.decodeValues ? decodeURIComponent(value) : value; // decode cookie value
480
+ } catch (e) {
481
+ console.error(
482
+ "set-cookie-parser: failed to decode cookie value. Set options.decodeValues=false to disable decoding.",
483
+ e
484
+ );
485
+ }
486
+
487
+ var cookie = createNullObj();
488
+ cookie.name = name;
489
+ cookie.value = value;
490
+
491
+ parts.forEach(function (part) {
492
+ var sides = part.split("=");
493
+ var key = sides.shift().trimLeft().toLowerCase();
494
+ if (isForbiddenKey(key)) {
495
+ return;
496
+ }
497
+ var value = sides.join("=");
498
+ if (key === "expires") {
499
+ cookie.expires = new Date(value);
500
+ } else if (key === "max-age") {
501
+ var n = parseInt(value, 10);
502
+ if (!Number.isNaN(n)) cookie.maxAge = n;
503
+ } else if (key === "secure") {
504
+ cookie.secure = true;
505
+ } else if (key === "httponly") {
506
+ cookie.httpOnly = true;
507
+ } else if (key === "samesite") {
508
+ cookie.sameSite = value;
509
+ } else if (key === "partitioned") {
510
+ cookie.partitioned = true;
511
+ } else if (key) {
512
+ cookie[key] = value;
513
+ }
514
+ });
515
+
516
+ return cookie;
517
+ }
518
+
519
+ function parseNameValuePair(nameValuePairStr) {
520
+ // Parses name-value-pair according to rfc6265bis draft
521
+
522
+ var name = "";
523
+ var value = "";
524
+ var nameValueArr = nameValuePairStr.split("=");
525
+ if (nameValueArr.length > 1) {
526
+ name = nameValueArr.shift();
527
+ value = nameValueArr.join("="); // everything after the first =, joined by a "=" if there was more than one part
528
+ } else {
529
+ value = nameValuePairStr;
530
+ }
531
+
532
+ return { name: name, value: value };
533
+ }
534
+
535
+ function parseSetCookie(input, options) {
536
+ options = options
537
+ ? Object.assign({}, defaultParseOptions, options)
538
+ : defaultParseOptions;
539
+
540
+ if (!input) {
541
+ if (!options.map) {
542
+ return [];
543
+ } else {
544
+ return createNullObj();
545
+ }
546
+ }
547
+
548
+ if (input.headers) {
549
+ if (typeof input.headers.getSetCookie === "function") {
550
+ // for fetch responses - they combine headers of the same type in the headers array,
551
+ // but getSetCookie returns an uncombined array
552
+ input = input.headers.getSetCookie();
553
+ } else if (input.headers["set-cookie"]) {
554
+ // fast-path for node.js (which automatically normalizes header names to lower-case)
555
+ input = input.headers["set-cookie"];
556
+ } else {
557
+ // slow-path for other environments - see #25
558
+ var sch =
559
+ input.headers[
560
+ Object.keys(input.headers).find(function (key) {
561
+ return key.toLowerCase() === "set-cookie";
562
+ })
563
+ ];
564
+ // warn if called on a request-like object with a cookie header rather than a set-cookie header - see #34, 36
565
+ if (!sch && input.headers.cookie && !options.silent) {
566
+ console.warn(
567
+ "Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
568
+ );
569
+ }
570
+ input = sch;
571
+ }
572
+ }
573
+
574
+ var split = options.split;
575
+ var isArray = Array.isArray(input);
576
+
577
+ if (split === "auto") {
578
+ split = !isArray;
579
+ }
580
+
581
+ if (!isArray) {
582
+ input = [input];
583
+ }
584
+
585
+ input = input.filter(isNonEmptyString);
586
+
587
+ if (split) {
588
+ input = input.map(splitCookiesString).flat();
589
+ }
590
+
591
+ if (!options.map) {
592
+ return input
593
+ .map(function (str) {
594
+ return parseString(str, options);
595
+ })
596
+ .filter(Boolean);
597
+ } else {
598
+ var cookies = createNullObj();
599
+ return input.reduce(function (cookies, str) {
600
+ var cookie = parseString(str, options);
601
+ if (cookie && !isForbiddenKey(cookie.name)) {
602
+ cookies[cookie.name] = cookie;
603
+ }
604
+ return cookies;
605
+ }, cookies);
606
+ }
607
+ }
608
+
609
+ /*
610
+ Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
611
+ that are within a single set-cookie field-value, such as in the Expires portion.
612
+
613
+ This is uncommon, but explicitly allowed - see https://tools.ietf.org/html/rfc2616#section-4.2
614
+ Node.js does this for every header *except* set-cookie - see https://github.com/nodejs/node/blob/d5e363b77ebaf1caf67cd7528224b651c86815c1/lib/_http_incoming.js#L128
615
+ React Native's fetch does this for *every* header, including set-cookie.
616
+
617
+ Based on: https://github.com/google/j2objc/commit/16820fdbc8f76ca0c33472810ce0cb03d20efe25
618
+ Credits to: https://github.com/tomball for original and https://github.com/chrusart for JavaScript implementation
619
+ */
620
+ function splitCookiesString(cookiesString) {
621
+ if (Array.isArray(cookiesString)) {
622
+ return cookiesString;
623
+ }
624
+ if (typeof cookiesString !== "string") {
625
+ return [];
626
+ }
627
+
628
+ var cookiesStrings = [];
629
+ var pos = 0;
630
+ var start;
631
+ var ch;
632
+ var lastComma;
633
+ var nextStart;
634
+ var cookiesSeparatorFound;
635
+
636
+ function skipWhitespace() {
637
+ while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
638
+ pos += 1;
639
+ }
640
+ return pos < cookiesString.length;
641
+ }
642
+
643
+ function notSpecialChar() {
644
+ ch = cookiesString.charAt(pos);
645
+
646
+ return ch !== "=" && ch !== ";" && ch !== ",";
647
+ }
648
+
649
+ while (pos < cookiesString.length) {
650
+ start = pos;
651
+ cookiesSeparatorFound = false;
652
+
653
+ while (skipWhitespace()) {
654
+ ch = cookiesString.charAt(pos);
655
+ if (ch === ",") {
656
+ // ',' is a cookie separator if we have later first '=', not ';' or ','
657
+ lastComma = pos;
658
+ pos += 1;
659
+
660
+ skipWhitespace();
661
+ nextStart = pos;
662
+
663
+ while (pos < cookiesString.length && notSpecialChar()) {
664
+ pos += 1;
665
+ }
666
+
667
+ // currently special character
668
+ if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
669
+ // we found cookies separator
670
+ cookiesSeparatorFound = true;
671
+ // pos is inside the next cookie, so back up and return it.
672
+ pos = nextStart;
673
+ cookiesStrings.push(cookiesString.substring(start, lastComma));
674
+ start = pos;
675
+ } else {
676
+ // in param ',' or param separator ';',
677
+ // we continue from that comma
678
+ pos = lastComma + 1;
679
+ }
680
+ } else {
681
+ pos += 1;
682
+ }
683
+ }
684
+
685
+ if (!cookiesSeparatorFound || pos >= cookiesString.length) {
686
+ cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
687
+ }
688
+ }
689
+
690
+ return cookiesStrings;
691
+ }
692
+
693
+ // named export for CJS
694
+ parseSetCookie.parseSetCookie = parseSetCookie;
695
+ // for backwards compatibility
696
+ parseSetCookie.parse = parseSetCookie;
697
+ parseSetCookie.parseString = parseString;
698
+ parseSetCookie.splitCookiesString = splitCookiesString;
699
+
700
+ function with_resolvers() {
701
+ let resolve2;
702
+ let reject;
703
+ const promise = new Promise((res, rej) => {
704
+ resolve2 = res;
705
+ reject = rej;
706
+ });
707
+ return { promise, resolve: resolve2, reject };
708
+ }
709
+ const NULL_BODY_STATUS = [101, 103, 204, 205, 304];
710
+ const IN_WEBCONTAINER = !!globalThis.process?.versions?.webcontainer;
711
+ async function render_endpoint(event, event_state, mod, state) {
712
+ const method = (
713
+ /** @type {import('types').HttpMethod} */
714
+ event.request.method
715
+ );
716
+ let handler = mod[method] || mod.fallback;
717
+ if (method === "HEAD" && !mod.HEAD && mod.GET) {
718
+ handler = mod.GET;
719
+ }
720
+ if (!handler) {
721
+ return method_not_allowed(mod, method);
722
+ }
723
+ const prerender = mod.prerender ?? state.prerender_default;
724
+ if (prerender && (mod.POST || mod.PATCH || mod.PUT || mod.DELETE)) {
725
+ throw new Error("Cannot prerender endpoints that have mutative methods");
726
+ }
727
+ if (state.prerendering && !state.prerendering.inside_reroute && !prerender) {
728
+ if (state.depth > 0) {
729
+ throw new Error(`${event.route.id} is not prerenderable`);
730
+ } else {
731
+ return new Response(void 0, { status: 204 });
732
+ }
733
+ }
734
+ event_state.is_endpoint_request = true;
735
+ try {
736
+ const response = await with_request_store(
737
+ { event, state: event_state },
738
+ () => handler(
739
+ /** @type {import('@sveltejs/kit').RequestEvent<Record<string, any>>} */
740
+ event
741
+ )
742
+ );
743
+ if (!(response instanceof Response)) {
744
+ throw new Error(
745
+ `Invalid response from route ${event.url.pathname}: handler should return a Response object`
746
+ );
747
+ }
748
+ if (state.prerendering && (!state.prerendering.inside_reroute || prerender)) {
749
+ const cloned = new Response(response.clone().body, {
750
+ status: response.status,
751
+ statusText: response.statusText,
752
+ headers: new Headers(response.headers)
753
+ });
754
+ cloned.headers.set("x-sveltekit-prerender", String(prerender));
755
+ if (state.prerendering.inside_reroute && prerender) {
756
+ cloned.headers.set(
757
+ "x-sveltekit-routeid",
758
+ encodeURI(
759
+ /** @type {string} */
760
+ event.route.id
761
+ )
762
+ );
763
+ state.prerendering.dependencies.set(event.url.pathname, { response: cloned, body: null });
764
+ } else {
765
+ return cloned;
766
+ }
767
+ }
768
+ return response;
769
+ } catch (e) {
770
+ if (e instanceof Redirect) {
771
+ return new Response(void 0, {
772
+ status: e.status,
773
+ headers: { location: e.location }
774
+ });
775
+ }
776
+ throw e;
777
+ }
778
+ }
779
+ function is_endpoint_request(event) {
780
+ const { method, headers: headers2 } = event.request;
781
+ if (ENDPOINT_METHODS.includes(method) && !PAGE_METHODS.includes(method)) {
782
+ return true;
783
+ }
784
+ if (method === "POST" && headers2.get("x-sveltekit-action") === "true") return false;
785
+ const accept = event.request.headers.get("accept") ?? "*/*";
786
+ return negotiate(accept, ["*", "text/html"]) !== "text/html";
787
+ }
788
+ function compact(arr) {
789
+ return arr.filter(
790
+ /** @returns {val is NonNullable<T>} */
791
+ (val) => val != null
792
+ );
793
+ }
794
+ const DATA_SUFFIX = "/__data.json";
795
+ const HTML_DATA_SUFFIX = ".html__data.json";
796
+ function has_data_suffix(pathname) {
797
+ return pathname.endsWith(DATA_SUFFIX) || pathname.endsWith(HTML_DATA_SUFFIX);
798
+ }
799
+ function add_data_suffix(pathname) {
800
+ if (pathname.endsWith(".html")) return pathname.replace(/\.html$/, HTML_DATA_SUFFIX);
801
+ return pathname.replace(/\/$/, "") + DATA_SUFFIX;
802
+ }
803
+ function strip_data_suffix(pathname) {
804
+ if (pathname.endsWith(HTML_DATA_SUFFIX)) {
805
+ return pathname.slice(0, -HTML_DATA_SUFFIX.length) + ".html";
806
+ }
807
+ return pathname.slice(0, -DATA_SUFFIX.length);
808
+ }
809
+ const ROUTE_SUFFIX = "/__route.js";
810
+ function has_resolution_suffix(pathname) {
811
+ return pathname.endsWith(ROUTE_SUFFIX);
812
+ }
813
+ function add_resolution_suffix(pathname) {
814
+ return pathname.replace(/\/$/, "") + ROUTE_SUFFIX;
815
+ }
816
+ function strip_resolution_suffix(pathname) {
817
+ return pathname.slice(0, -ROUTE_SUFFIX.length);
818
+ }
819
+ const noop_span = {
820
+ spanContext() {
821
+ return noop_span_context;
822
+ },
823
+ setAttribute() {
824
+ return this;
825
+ },
826
+ setAttributes() {
827
+ return this;
828
+ },
829
+ addEvent() {
830
+ return this;
831
+ },
832
+ setStatus() {
833
+ return this;
834
+ },
835
+ updateName() {
836
+ return this;
837
+ },
838
+ end() {
839
+ return this;
840
+ },
841
+ isRecording() {
842
+ return false;
843
+ },
844
+ recordException() {
845
+ return this;
846
+ },
847
+ addLink() {
848
+ return this;
849
+ },
850
+ addLinks() {
851
+ return this;
852
+ }
853
+ };
854
+ const noop_span_context = {
855
+ traceId: "",
856
+ spanId: "",
857
+ traceFlags: 0
858
+ };
859
+ async function record_span({ name, attributes, fn }) {
860
+ {
861
+ return fn(noop_span);
862
+ }
863
+ }
864
+ function is_action_json_request(event) {
865
+ const accept = negotiate(event.request.headers.get("accept") ?? "*/*", [
866
+ "application/json",
867
+ "text/html"
868
+ ]);
869
+ return accept === "application/json" && event.request.method === "POST";
870
+ }
871
+ async function handle_action_json_request(event, event_state, options2, server) {
872
+ const actions = server?.actions;
873
+ if (!actions) {
874
+ const no_actions_error = new SvelteKitError(
875
+ 405,
876
+ "Method Not Allowed",
877
+ `POST method not allowed. No form actions exist for ${"this page"}`
878
+ );
879
+ return action_json(
880
+ {
881
+ type: "error",
882
+ error: await handle_error_and_jsonify(event, event_state, options2, no_actions_error)
883
+ },
884
+ {
885
+ status: no_actions_error.status,
886
+ headers: {
887
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
888
+ // "The server must generate an Allow header field in a 405 status code response"
889
+ allow: "GET"
890
+ }
891
+ }
892
+ );
893
+ }
894
+ check_named_default_separate(actions);
895
+ try {
896
+ const data = await call_action(event, event_state, actions);
897
+ if (DEV) ;
898
+ if (data instanceof ActionFailure) {
899
+ return action_json({
900
+ type: "failure",
901
+ status: data.status,
902
+ // @ts-expect-error we assign a string to what is supposed to be an object. That's ok
903
+ // because we don't use the object outside, and this way we have better code navigation
904
+ // through knowing where the related interface is used.
905
+ data: stringify_action_response(
906
+ data.data,
907
+ /** @type {string} */
908
+ event.route.id,
909
+ options2.hooks.transport
910
+ )
911
+ });
912
+ } else {
913
+ return action_json({
914
+ type: "success",
915
+ status: data ? 200 : 204,
916
+ // @ts-expect-error see comment above
917
+ data: stringify_action_response(
918
+ data,
919
+ /** @type {string} */
920
+ event.route.id,
921
+ options2.hooks.transport
922
+ )
923
+ });
924
+ }
925
+ } catch (e) {
926
+ const err = normalize_error(e);
927
+ if (err instanceof Redirect) {
928
+ return action_json_redirect(err);
929
+ }
930
+ return action_json(
931
+ {
932
+ type: "error",
933
+ error: await handle_error_and_jsonify(
934
+ event,
935
+ event_state,
936
+ options2,
937
+ check_incorrect_fail_use(err)
938
+ )
939
+ },
940
+ {
941
+ status: get_status(err)
942
+ }
943
+ );
944
+ }
945
+ }
946
+ function check_incorrect_fail_use(error2) {
947
+ return error2 instanceof ActionFailure ? new Error('Cannot "throw fail()". Use "return fail()"') : error2;
948
+ }
949
+ function action_json_redirect(redirect) {
950
+ return action_json({
951
+ type: "redirect",
952
+ status: redirect.status,
953
+ location: redirect.location
954
+ });
955
+ }
956
+ function action_json(data, init2) {
957
+ return json(data, init2);
958
+ }
959
+ function is_action_request(event) {
960
+ return event.request.method === "POST";
961
+ }
962
+ async function handle_action_request(event, event_state, server) {
963
+ const actions = server?.actions;
964
+ if (!actions) {
965
+ event.setHeaders({
966
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
967
+ // "The server must generate an Allow header field in a 405 status code response"
968
+ allow: "GET"
969
+ });
970
+ return {
971
+ type: "error",
972
+ error: new SvelteKitError(
973
+ 405,
974
+ "Method Not Allowed",
975
+ `POST method not allowed. No form actions exist for ${"this page"}`
976
+ )
977
+ };
978
+ }
979
+ check_named_default_separate(actions);
980
+ try {
981
+ const data = await call_action(event, event_state, actions);
982
+ if (DEV) ;
983
+ if (data instanceof ActionFailure) {
984
+ return {
985
+ type: "failure",
986
+ status: data.status,
987
+ data: data.data
988
+ };
989
+ } else {
990
+ return {
991
+ type: "success",
992
+ status: 200,
993
+ // @ts-expect-error this will be removed upon serialization, so `undefined` is the same as omission
994
+ data
995
+ };
996
+ }
997
+ } catch (e) {
998
+ const err = normalize_error(e);
999
+ if (err instanceof Redirect) {
1000
+ return {
1001
+ type: "redirect",
1002
+ status: err.status,
1003
+ location: err.location
1004
+ };
1005
+ }
1006
+ return {
1007
+ type: "error",
1008
+ error: check_incorrect_fail_use(err)
1009
+ };
1010
+ }
1011
+ }
1012
+ function check_named_default_separate(actions) {
1013
+ if (actions.default && Object.keys(actions).length > 1) {
1014
+ throw new Error(
1015
+ "When using named actions, the default action cannot be used. See the docs for more info: https://svelte.dev/docs/kit/form-actions#named-actions"
1016
+ );
1017
+ }
1018
+ }
1019
+ async function call_action(event, event_state, actions) {
1020
+ const url = new URL(event.request.url);
1021
+ let name = "default";
1022
+ for (const param of url.searchParams) {
1023
+ if (param[0].startsWith("/")) {
1024
+ name = param[0].slice(1);
1025
+ if (name === "default") {
1026
+ throw new Error('Cannot use reserved action name "default"');
1027
+ }
1028
+ break;
1029
+ }
1030
+ }
1031
+ const action = actions[name];
1032
+ if (!action) {
1033
+ throw new SvelteKitError(404, "Not Found", `No action with name '${name}' found`);
1034
+ }
1035
+ if (!is_form_content_type(event.request)) {
1036
+ throw new SvelteKitError(
1037
+ 415,
1038
+ "Unsupported Media Type",
1039
+ `Form actions expect form-encoded data — received ${event.request.headers.get(
1040
+ "content-type"
1041
+ )}`
1042
+ );
1043
+ }
1044
+ return record_span({
1045
+ name: "sveltekit.form_action",
1046
+ attributes: {
1047
+ "http.route": event.route.id || "unknown"
1048
+ },
1049
+ fn: async (current2) => {
1050
+ const traced_event = merge_tracing(event, current2);
1051
+ const result = await with_request_store(
1052
+ { event: traced_event, state: event_state },
1053
+ () => action(traced_event)
1054
+ );
1055
+ if (result instanceof ActionFailure) {
1056
+ current2.setAttributes({
1057
+ "sveltekit.form_action.result.type": "failure",
1058
+ "sveltekit.form_action.result.status": result.status
1059
+ });
1060
+ }
1061
+ return result;
1062
+ }
1063
+ });
1064
+ }
1065
+ function uneval_action_response(data, route_id, transport) {
1066
+ const replacer = (thing) => {
1067
+ for (const key2 in transport) {
1068
+ const encoded = transport[key2].encode(thing);
1069
+ if (encoded) {
1070
+ return `app.decode('${key2}', ${uneval(encoded, replacer)})`;
1071
+ }
1072
+ }
1073
+ };
1074
+ return try_serialize(data, (value) => uneval(value, replacer), route_id);
1075
+ }
1076
+ function stringify_action_response(data, route_id, transport) {
1077
+ const encoders = Object.fromEntries(
1078
+ Object.entries(transport).map(([key2, value]) => [key2, value.encode])
1079
+ );
1080
+ return try_serialize(data, (value) => stringify$1(value, encoders), route_id);
1081
+ }
1082
+ function try_serialize(data, fn, route_id) {
1083
+ try {
1084
+ return fn(data);
1085
+ } catch (e) {
1086
+ const error2 = (
1087
+ /** @type {any} */
1088
+ e
1089
+ );
1090
+ if (data instanceof Response) {
1091
+ throw new Error(
1092
+ `Data returned from action inside ${route_id} is not serializable. Form actions need to return plain objects or fail(). E.g. return { success: true } or return fail(400, { message: "invalid" });`,
1093
+ { cause: e }
1094
+ );
1095
+ }
1096
+ if ("path" in error2) {
1097
+ let message = `Data returned from action inside ${route_id} is not serializable: ${error2.message}`;
1098
+ if (error2.path !== "") message += ` (data.${error2.path})`;
1099
+ throw new Error(message, { cause: e });
1100
+ }
1101
+ throw error2;
1102
+ }
1103
+ }
1104
+ function create_async_iterator() {
1105
+ let resolved = -1;
1106
+ let returned = -1;
1107
+ const deferred = [];
1108
+ return {
1109
+ iterate: (transform = (x) => x) => {
1110
+ return {
1111
+ [Symbol.asyncIterator]() {
1112
+ return {
1113
+ next: async () => {
1114
+ const next = deferred[++returned];
1115
+ if (!next) return { value: null, done: true };
1116
+ const value = await next.promise;
1117
+ return { value: transform(value), done: false };
1118
+ }
1119
+ };
1120
+ }
1121
+ };
1122
+ },
1123
+ add: (promise) => {
1124
+ deferred.push(with_resolvers());
1125
+ void promise.then((value) => {
1126
+ deferred[++resolved].resolve(value);
1127
+ });
1128
+ }
1129
+ };
1130
+ }
1131
+ function server_data_serializer(event, event_state, options2) {
1132
+ let promise_id = 1;
1133
+ let max_nodes = -1;
1134
+ const iterator = create_async_iterator();
1135
+ const global = get_global_name(options2);
1136
+ function get_replacer(index) {
1137
+ return function replacer(thing) {
1138
+ if (typeof thing?.then === "function") {
1139
+ const id = promise_id++;
1140
+ const promise = thing.then(
1141
+ /** @param {any} data */
1142
+ (data) => ({ data })
1143
+ ).catch(
1144
+ /** @param {any} error */
1145
+ async (error2) => ({
1146
+ error: await handle_error_and_jsonify(event, event_state, options2, error2)
1147
+ })
1148
+ ).then(
1149
+ /**
1150
+ * @param {{data: any; error: any}} result
1151
+ */
1152
+ async ({ data, error: error2 }) => {
1153
+ let str;
1154
+ try {
1155
+ str = uneval(error2 ? [, error2] : [data], replacer);
1156
+ } catch {
1157
+ error2 = await handle_error_and_jsonify(
1158
+ event,
1159
+ event_state,
1160
+ options2,
1161
+ new Error(`Failed to serialize promise while rendering ${event.route.id}`)
1162
+ );
1163
+ str = uneval([, error2], replacer);
1164
+ }
1165
+ return {
1166
+ index,
1167
+ str: `${global}.resolve(${id}, ${str.includes("app.decode") ? `(app) => ${str}` : `() => ${str}`})`
1168
+ };
1169
+ }
1170
+ );
1171
+ iterator.add(promise);
1172
+ return `${global}.defer(${id})`;
1173
+ } else {
1174
+ for (const key2 in options2.hooks.transport) {
1175
+ const encoded = options2.hooks.transport[key2].encode(thing);
1176
+ if (encoded) {
1177
+ return `app.decode('${key2}', ${uneval(encoded, replacer)})`;
1178
+ }
1179
+ }
1180
+ }
1181
+ };
1182
+ }
1183
+ const strings = (
1184
+ /** @type {string[]} */
1185
+ []
1186
+ );
1187
+ return {
1188
+ set_max_nodes(i) {
1189
+ max_nodes = i;
1190
+ },
1191
+ add_node(i, node) {
1192
+ try {
1193
+ if (!node) {
1194
+ strings[i] = "null";
1195
+ return;
1196
+ }
1197
+ const payload = { type: "data", data: node.data, uses: serialize_uses(node) };
1198
+ if (node.slash) payload.slash = node.slash;
1199
+ strings[i] = uneval(payload, get_replacer(i));
1200
+ } catch (e) {
1201
+ e.path = e.path.slice(1);
1202
+ throw new Error(clarify_devalue_error(
1203
+ event,
1204
+ /** @type {any} */
1205
+ e
1206
+ ), { cause: e });
1207
+ }
1208
+ },
1209
+ get_data(csp) {
1210
+ const open = `<script${csp.script_needs_nonce ? ` nonce="${csp.nonce}"` : ""}>`;
1211
+ const close = `<\/script>
1212
+ `;
1213
+ return {
1214
+ data: `[${compact(max_nodes > -1 ? strings.slice(0, max_nodes) : strings).join(",")}]`,
1215
+ chunks: promise_id > 1 ? iterator.iterate(({ index, str }) => {
1216
+ if (max_nodes > -1 && index >= max_nodes) {
1217
+ return "";
1218
+ }
1219
+ return open + str + close;
1220
+ }) : null
1221
+ };
1222
+ }
1223
+ };
1224
+ }
1225
+ function server_data_serializer_json(event, event_state, options2) {
1226
+ let promise_id = 1;
1227
+ const iterator = create_async_iterator();
1228
+ const reducers = {
1229
+ ...Object.fromEntries(
1230
+ Object.entries(options2.hooks.transport).map(([key2, value]) => [key2, value.encode])
1231
+ ),
1232
+ /** @param {any} thing */
1233
+ Promise: (thing) => {
1234
+ if (typeof thing?.then !== "function") {
1235
+ return;
1236
+ }
1237
+ const id = promise_id++;
1238
+ let key2 = "data";
1239
+ const promise = thing.catch(
1240
+ /** @param {any} e */
1241
+ async (e) => {
1242
+ key2 = "error";
1243
+ return handle_error_and_jsonify(
1244
+ event,
1245
+ event_state,
1246
+ options2,
1247
+ /** @type {any} */
1248
+ e
1249
+ );
1250
+ }
1251
+ ).then(
1252
+ /** @param {any} value */
1253
+ async (value) => {
1254
+ let str;
1255
+ try {
1256
+ str = stringify$1(value, reducers);
1257
+ } catch {
1258
+ const error2 = await handle_error_and_jsonify(
1259
+ event,
1260
+ event_state,
1261
+ options2,
1262
+ new Error(`Failed to serialize promise while rendering ${event.route.id}`)
1263
+ );
1264
+ key2 = "error";
1265
+ str = stringify$1(error2, reducers);
1266
+ }
1267
+ return `{"type":"chunk","id":${id},"${key2}":${str}}
1268
+ `;
1269
+ }
1270
+ );
1271
+ iterator.add(promise);
1272
+ return id;
1273
+ }
1274
+ };
1275
+ const strings = (
1276
+ /** @type {string[]} */
1277
+ []
1278
+ );
1279
+ return {
1280
+ add_node(i, node) {
1281
+ try {
1282
+ if (!node) {
1283
+ strings[i] = "null";
1284
+ return;
1285
+ }
1286
+ if (node.type === "error" || node.type === "skip") {
1287
+ strings[i] = JSON.stringify(node);
1288
+ return;
1289
+ }
1290
+ strings[i] = `{"type":"data","data":${stringify$1(node.data, reducers)},"uses":${JSON.stringify(
1291
+ serialize_uses(node)
1292
+ )}${node.slash ? `,"slash":${JSON.stringify(node.slash)}` : ""}}`;
1293
+ } catch (e) {
1294
+ e.path = "data" + e.path;
1295
+ throw new Error(clarify_devalue_error(
1296
+ event,
1297
+ /** @type {any} */
1298
+ e
1299
+ ), { cause: e });
1300
+ }
1301
+ },
1302
+ get_data() {
1303
+ return {
1304
+ data: `{"type":"data","nodes":[${strings.join(",")}]}
1305
+ `,
1306
+ chunks: promise_id > 1 ? iterator.iterate() : null
1307
+ };
1308
+ }
1309
+ };
1310
+ }
1311
+ async function load_server_data({ event, event_state, state, node, parent }) {
1312
+ if (!node?.server) return null;
1313
+ let is_tracking = true;
1314
+ const uses = {
1315
+ dependencies: /* @__PURE__ */ new Set(),
1316
+ params: /* @__PURE__ */ new Set(),
1317
+ parent: false,
1318
+ route: false,
1319
+ url: false,
1320
+ search_params: /* @__PURE__ */ new Set()
1321
+ };
1322
+ const load = node.server.load;
1323
+ const slash = node.server.trailingSlash;
1324
+ if (!load) {
1325
+ return { type: "data", data: null, uses, slash };
1326
+ }
1327
+ const url = make_trackable(
1328
+ event.url,
1329
+ () => {
1330
+ if (is_tracking) {
1331
+ uses.url = true;
1332
+ }
1333
+ },
1334
+ (param) => {
1335
+ if (is_tracking) {
1336
+ uses.search_params.add(param);
1337
+ }
1338
+ }
1339
+ );
1340
+ if (state.prerendering) {
1341
+ disable_search(url);
1342
+ }
1343
+ const result = await record_span({
1344
+ name: "sveltekit.load",
1345
+ attributes: {
1346
+ "sveltekit.load.node_id": node.server_id || "unknown",
1347
+ "sveltekit.load.node_type": get_node_type(node.server_id),
1348
+ "http.route": event.route.id || "unknown"
1349
+ },
1350
+ fn: async (current2) => {
1351
+ const traced_event = merge_tracing(event, current2);
1352
+ const result2 = await with_request_store(
1353
+ { event: traced_event, state: event_state },
1354
+ () => load.call(null, {
1355
+ ...traced_event,
1356
+ fetch: (info, init2) => {
1357
+ new URL(info instanceof Request ? info.url : info, event.url);
1358
+ return event.fetch(info, init2);
1359
+ },
1360
+ /** @param {string[]} deps */
1361
+ depends: (...deps) => {
1362
+ for (const dep of deps) {
1363
+ const { href } = new URL(dep, event.url);
1364
+ uses.dependencies.add(href);
1365
+ }
1366
+ },
1367
+ params: new Proxy(event.params, {
1368
+ get: (target, key2) => {
1369
+ if (is_tracking) {
1370
+ uses.params.add(key2);
1371
+ }
1372
+ return target[
1373
+ /** @type {string} */
1374
+ key2
1375
+ ];
1376
+ }
1377
+ }),
1378
+ parent: async () => {
1379
+ if (is_tracking) {
1380
+ uses.parent = true;
1381
+ }
1382
+ return parent();
1383
+ },
1384
+ route: new Proxy(event.route, {
1385
+ get: (target, key2) => {
1386
+ if (is_tracking) {
1387
+ uses.route = true;
1388
+ }
1389
+ return target[
1390
+ /** @type {'id'} */
1391
+ key2
1392
+ ];
1393
+ }
1394
+ }),
1395
+ url,
1396
+ untrack(fn) {
1397
+ is_tracking = false;
1398
+ try {
1399
+ return fn();
1400
+ } finally {
1401
+ is_tracking = true;
1402
+ }
1403
+ }
1404
+ })
1405
+ );
1406
+ return result2;
1407
+ }
1408
+ });
1409
+ return {
1410
+ type: "data",
1411
+ data: result ?? null,
1412
+ uses,
1413
+ slash
1414
+ };
1415
+ }
1416
+ async function load_data({
1417
+ event,
1418
+ event_state,
1419
+ fetched,
1420
+ node,
1421
+ parent,
1422
+ server_data_promise,
1423
+ state,
1424
+ resolve_opts,
1425
+ csr
1426
+ }) {
1427
+ const server_data_node = await server_data_promise;
1428
+ const load = node?.universal?.load;
1429
+ if (!load) {
1430
+ return server_data_node?.data ?? null;
1431
+ }
1432
+ const result = await record_span({
1433
+ name: "sveltekit.load",
1434
+ attributes: {
1435
+ "sveltekit.load.node_id": node.universal_id || "unknown",
1436
+ "sveltekit.load.node_type": get_node_type(node.universal_id),
1437
+ "http.route": event.route.id || "unknown"
1438
+ },
1439
+ fn: async (current2) => {
1440
+ const traced_event = merge_tracing(event, current2);
1441
+ return await with_request_store(
1442
+ { event: traced_event, state: event_state },
1443
+ () => load.call(null, {
1444
+ url: event.url,
1445
+ params: event.params,
1446
+ data: server_data_node?.data ?? null,
1447
+ route: event.route,
1448
+ fetch: create_universal_fetch(event, state, fetched, csr, resolve_opts),
1449
+ setHeaders: event.setHeaders,
1450
+ depends: () => {
1451
+ },
1452
+ parent,
1453
+ untrack: (fn) => fn(),
1454
+ tracing: traced_event.tracing
1455
+ })
1456
+ );
1457
+ }
1458
+ });
1459
+ return result ?? null;
1460
+ }
1461
+ function create_universal_fetch(event, state, fetched, csr, resolve_opts) {
1462
+ const universal_fetch = async (input, init2) => {
1463
+ const cloned_body = input instanceof Request && input.body ? input.clone().body : null;
1464
+ const cloned_headers = input instanceof Request && [...input.headers].length ? new Headers(input.headers) : init2?.headers;
1465
+ let response = await event.fetch(input, init2);
1466
+ const url = new URL(input instanceof Request ? input.url : input, event.url);
1467
+ const same_origin = url.origin === event.url.origin;
1468
+ let dependency;
1469
+ if (same_origin) {
1470
+ if (state.prerendering) {
1471
+ dependency = { response, body: null };
1472
+ state.prerendering.dependencies.set(url.pathname, dependency);
1473
+ }
1474
+ } else if (url.protocol === "https:" || url.protocol === "http:") {
1475
+ const mode = input instanceof Request ? input.mode : init2?.mode ?? "cors";
1476
+ if (mode === "no-cors") {
1477
+ response = new Response("", {
1478
+ status: response.status,
1479
+ statusText: response.statusText,
1480
+ headers: response.headers
1481
+ });
1482
+ } else {
1483
+ const acao = response.headers.get("access-control-allow-origin");
1484
+ if (!acao || acao !== event.url.origin && acao !== "*") {
1485
+ throw new Error(
1486
+ `CORS error: ${acao ? "Incorrect" : "No"} 'Access-Control-Allow-Origin' header is present on the requested resource`
1487
+ );
1488
+ }
1489
+ }
1490
+ }
1491
+ let teed_body;
1492
+ const proxy = new Proxy(response, {
1493
+ get(response2, key2, receiver) {
1494
+ async function push_fetched(body2, is_b64) {
1495
+ const status_number = Number(response2.status);
1496
+ if (isNaN(status_number)) {
1497
+ throw new Error(
1498
+ `response.status is not a number. value: "${response2.status}" type: ${typeof response2.status}`
1499
+ );
1500
+ }
1501
+ fetched.push({
1502
+ url: same_origin ? url.href.slice(event.url.origin.length) : url.href,
1503
+ method: event.request.method,
1504
+ request_body: (
1505
+ /** @type {string | ArrayBufferView | undefined} */
1506
+ input instanceof Request && cloned_body ? await stream_to_string(cloned_body) : init2?.body
1507
+ ),
1508
+ request_headers: cloned_headers,
1509
+ response_body: body2,
1510
+ response: response2,
1511
+ is_b64
1512
+ });
1513
+ }
1514
+ if (key2 === "body") {
1515
+ if (response2.body === null) {
1516
+ return null;
1517
+ }
1518
+ if (teed_body) {
1519
+ return teed_body;
1520
+ }
1521
+ const [a, b] = response2.body.tee();
1522
+ void (async () => {
1523
+ let result = new Uint8Array();
1524
+ for await (const chunk of a) {
1525
+ const combined = new Uint8Array(result.length + chunk.length);
1526
+ combined.set(result, 0);
1527
+ combined.set(chunk, result.length);
1528
+ result = combined;
1529
+ }
1530
+ if (dependency) {
1531
+ dependency.body = new Uint8Array(result);
1532
+ }
1533
+ void push_fetched(base64_encode(result), true);
1534
+ })();
1535
+ return teed_body = b;
1536
+ }
1537
+ if (key2 === "arrayBuffer") {
1538
+ return async () => {
1539
+ const buffer = await response2.arrayBuffer();
1540
+ const bytes = new Uint8Array(buffer);
1541
+ if (dependency) {
1542
+ dependency.body = bytes;
1543
+ }
1544
+ if (buffer instanceof ArrayBuffer) {
1545
+ await push_fetched(base64_encode(bytes), true);
1546
+ }
1547
+ return buffer;
1548
+ };
1549
+ }
1550
+ async function text2() {
1551
+ const body2 = await response2.text();
1552
+ if (body2 === "" && NULL_BODY_STATUS.includes(response2.status)) {
1553
+ await push_fetched(void 0, false);
1554
+ return void 0;
1555
+ }
1556
+ if (!body2 || typeof body2 === "string") {
1557
+ await push_fetched(body2, false);
1558
+ }
1559
+ if (dependency) {
1560
+ dependency.body = body2;
1561
+ }
1562
+ return body2;
1563
+ }
1564
+ if (key2 === "text") {
1565
+ return text2;
1566
+ }
1567
+ if (key2 === "json") {
1568
+ return async () => {
1569
+ const body2 = await text2();
1570
+ return body2 ? JSON.parse(body2) : void 0;
1571
+ };
1572
+ }
1573
+ const value = Reflect.get(response2, key2, response2);
1574
+ if (value instanceof Function) {
1575
+ return Object.defineProperties(
1576
+ /**
1577
+ * @this {any}
1578
+ */
1579
+ function() {
1580
+ return Reflect.apply(value, this === receiver ? response2 : this, arguments);
1581
+ },
1582
+ {
1583
+ name: { value: value.name },
1584
+ length: { value: value.length }
1585
+ }
1586
+ );
1587
+ }
1588
+ return value;
1589
+ }
1590
+ });
1591
+ if (csr) {
1592
+ const get = response.headers.get;
1593
+ response.headers.get = (key2) => {
1594
+ const lower = key2.toLowerCase();
1595
+ const value = get.call(response.headers, lower);
1596
+ if (value && !lower.startsWith("x-sveltekit-")) {
1597
+ const included = resolve_opts.filterSerializedResponseHeaders(lower, value);
1598
+ if (!included) {
1599
+ throw new Error(
1600
+ `Failed to get response header "${lower}" — it must be included by the \`filterSerializedResponseHeaders\` option: https://svelte.dev/docs/kit/hooks#Server-hooks-handle (at ${event.route.id})`
1601
+ );
1602
+ }
1603
+ }
1604
+ return value;
1605
+ };
1606
+ }
1607
+ return proxy;
1608
+ };
1609
+ return (input, init2) => {
1610
+ const response = universal_fetch(input, init2);
1611
+ response.catch(() => {
1612
+ });
1613
+ return response;
1614
+ };
1615
+ }
1616
+ async function stream_to_string(stream) {
1617
+ let result = "";
1618
+ const reader = stream.getReader();
1619
+ while (true) {
1620
+ const { done, value } = await reader.read();
1621
+ if (done) {
1622
+ break;
1623
+ }
1624
+ result += text_decoder.decode(value);
1625
+ }
1626
+ return result;
1627
+ }
1628
+ function hash(...values) {
1629
+ let hash2 = 5381;
1630
+ for (const value of values) {
1631
+ if (typeof value === "string") {
1632
+ let i = value.length;
1633
+ while (i) hash2 = hash2 * 33 ^ value.charCodeAt(--i);
1634
+ } else if (ArrayBuffer.isView(value)) {
1635
+ const buffer = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
1636
+ let i = buffer.length;
1637
+ while (i) hash2 = hash2 * 33 ^ buffer[--i];
1638
+ } else {
1639
+ throw new TypeError("value must be a string or TypedArray");
1640
+ }
1641
+ }
1642
+ return (hash2 >>> 0).toString(36);
1643
+ }
1644
+ const replacements = {
1645
+ "<": "\\u003C",
1646
+ "\u2028": "\\u2028",
1647
+ "\u2029": "\\u2029"
1648
+ };
1649
+ const pattern = new RegExp(`[${Object.keys(replacements).join("")}]`, "g");
1650
+ function serialize_data(fetched, filter, prerendering = false) {
1651
+ const headers2 = {};
1652
+ let cache_control = null;
1653
+ let age = null;
1654
+ let varyAny = false;
1655
+ for (const [key2, value] of fetched.response.headers) {
1656
+ if (filter(key2, value)) {
1657
+ headers2[key2] = value;
1658
+ }
1659
+ if (key2 === "cache-control") cache_control = value;
1660
+ else if (key2 === "age") age = value;
1661
+ else if (key2 === "vary" && value.trim() === "*") varyAny = true;
1662
+ }
1663
+ const payload = {
1664
+ status: fetched.response.status,
1665
+ statusText: fetched.response.statusText,
1666
+ headers: headers2,
1667
+ body: fetched.response_body
1668
+ };
1669
+ const safe_payload = JSON.stringify(payload).replace(pattern, (match) => replacements[match]);
1670
+ const attrs = [
1671
+ 'type="application/json"',
1672
+ "data-sveltekit-fetched",
1673
+ `data-url="${escape_html(fetched.url, true)}"`
1674
+ ];
1675
+ if (fetched.is_b64) {
1676
+ attrs.push("data-b64");
1677
+ }
1678
+ if (fetched.request_headers || fetched.request_body) {
1679
+ const values = [];
1680
+ if (fetched.request_headers) {
1681
+ values.push([...new Headers(fetched.request_headers)].join(","));
1682
+ }
1683
+ if (fetched.request_body) {
1684
+ values.push(fetched.request_body);
1685
+ }
1686
+ attrs.push(`data-hash="${hash(...values)}"`);
1687
+ }
1688
+ if (!prerendering && fetched.method === "GET" && cache_control && !varyAny) {
1689
+ const match = /s-maxage=(\d+)/g.exec(cache_control) ?? /max-age=(\d+)/g.exec(cache_control);
1690
+ if (match) {
1691
+ const ttl = +match[1] - +(age ?? "0");
1692
+ attrs.push(`data-ttl="${ttl}"`);
1693
+ }
1694
+ }
1695
+ return `<script ${attrs.join(" ")}>${safe_payload}<\/script>`;
1696
+ }
1697
+ const s = JSON.stringify;
1698
+ function sha256(data) {
1699
+ if (!key[0]) precompute();
1700
+ const out = init.slice(0);
1701
+ const array2 = encode(data);
1702
+ for (let i = 0; i < array2.length; i += 16) {
1703
+ const w = array2.subarray(i, i + 16);
1704
+ let tmp;
1705
+ let a;
1706
+ let b;
1707
+ let out0 = out[0];
1708
+ let out1 = out[1];
1709
+ let out2 = out[2];
1710
+ let out3 = out[3];
1711
+ let out4 = out[4];
1712
+ let out5 = out[5];
1713
+ let out6 = out[6];
1714
+ let out7 = out[7];
1715
+ for (let i2 = 0; i2 < 64; i2++) {
1716
+ if (i2 < 16) {
1717
+ tmp = w[i2];
1718
+ } else {
1719
+ a = w[i2 + 1 & 15];
1720
+ b = w[i2 + 14 & 15];
1721
+ tmp = w[i2 & 15] = (a >>> 7 ^ a >>> 18 ^ a >>> 3 ^ a << 25 ^ a << 14) + (b >>> 17 ^ b >>> 19 ^ b >>> 10 ^ b << 15 ^ b << 13) + w[i2 & 15] + w[i2 + 9 & 15] | 0;
1722
+ }
1723
+ tmp = tmp + out7 + (out4 >>> 6 ^ out4 >>> 11 ^ out4 >>> 25 ^ out4 << 26 ^ out4 << 21 ^ out4 << 7) + (out6 ^ out4 & (out5 ^ out6)) + key[i2];
1724
+ out7 = out6;
1725
+ out6 = out5;
1726
+ out5 = out4;
1727
+ out4 = out3 + tmp | 0;
1728
+ out3 = out2;
1729
+ out2 = out1;
1730
+ out1 = out0;
1731
+ out0 = tmp + (out1 & out2 ^ out3 & (out1 ^ out2)) + (out1 >>> 2 ^ out1 >>> 13 ^ out1 >>> 22 ^ out1 << 30 ^ out1 << 19 ^ out1 << 10) | 0;
1732
+ }
1733
+ out[0] = out[0] + out0 | 0;
1734
+ out[1] = out[1] + out1 | 0;
1735
+ out[2] = out[2] + out2 | 0;
1736
+ out[3] = out[3] + out3 | 0;
1737
+ out[4] = out[4] + out4 | 0;
1738
+ out[5] = out[5] + out5 | 0;
1739
+ out[6] = out[6] + out6 | 0;
1740
+ out[7] = out[7] + out7 | 0;
1741
+ }
1742
+ const bytes = new Uint8Array(out.buffer);
1743
+ reverse_endianness(bytes);
1744
+ return btoa(String.fromCharCode(...bytes));
1745
+ }
1746
+ const init = new Uint32Array(8);
1747
+ const key = new Uint32Array(64);
1748
+ function precompute() {
1749
+ function frac(x) {
1750
+ return (x - Math.floor(x)) * 4294967296;
1751
+ }
1752
+ let prime = 2;
1753
+ for (let i = 0; i < 64; prime++) {
1754
+ let is_prime = true;
1755
+ for (let factor = 2; factor * factor <= prime; factor++) {
1756
+ if (prime % factor === 0) {
1757
+ is_prime = false;
1758
+ break;
1759
+ }
1760
+ }
1761
+ if (is_prime) {
1762
+ if (i < 8) {
1763
+ init[i] = frac(prime ** (1 / 2));
1764
+ }
1765
+ key[i] = frac(prime ** (1 / 3));
1766
+ i++;
1767
+ }
1768
+ }
1769
+ }
1770
+ function reverse_endianness(bytes) {
1771
+ for (let i = 0; i < bytes.length; i += 4) {
1772
+ const a = bytes[i + 0];
1773
+ const b = bytes[i + 1];
1774
+ const c = bytes[i + 2];
1775
+ const d = bytes[i + 3];
1776
+ bytes[i + 0] = d;
1777
+ bytes[i + 1] = c;
1778
+ bytes[i + 2] = b;
1779
+ bytes[i + 3] = a;
1780
+ }
1781
+ }
1782
+ function encode(str) {
1783
+ const encoded = text_encoder.encode(str);
1784
+ const length = encoded.length * 8;
1785
+ const size = 512 * Math.ceil((length + 65) / 512);
1786
+ const bytes = new Uint8Array(size / 8);
1787
+ bytes.set(encoded);
1788
+ bytes[encoded.length] = 128;
1789
+ reverse_endianness(bytes);
1790
+ const words = new Uint32Array(bytes.buffer);
1791
+ words[words.length - 2] = Math.floor(length / 4294967296);
1792
+ words[words.length - 1] = length;
1793
+ return words;
1794
+ }
1795
+ const array = new Uint8Array(16);
1796
+ function generate_nonce() {
1797
+ crypto.getRandomValues(array);
1798
+ return btoa(String.fromCharCode(...array));
1799
+ }
1800
+ const quoted = /* @__PURE__ */ new Set([
1801
+ "self",
1802
+ "unsafe-eval",
1803
+ "unsafe-hashes",
1804
+ "unsafe-inline",
1805
+ "none",
1806
+ "strict-dynamic",
1807
+ "report-sample",
1808
+ "wasm-unsafe-eval",
1809
+ "script"
1810
+ ]);
1811
+ const crypto_pattern = /^(nonce|sha\d\d\d)-/;
1812
+ class BaseProvider {
1813
+ /** @type {boolean} */
1814
+ #use_hashes;
1815
+ /** @type {boolean} */
1816
+ #script_needs_csp;
1817
+ /** @type {boolean} */
1818
+ #script_src_needs_csp;
1819
+ /** @type {boolean} */
1820
+ #script_src_elem_needs_csp;
1821
+ /** @type {boolean} */
1822
+ #style_needs_csp;
1823
+ /** @type {boolean} */
1824
+ #style_src_needs_csp;
1825
+ /** @type {boolean} */
1826
+ #style_src_attr_needs_csp;
1827
+ /** @type {boolean} */
1828
+ #style_src_elem_needs_csp;
1829
+ /** @type {import('types').CspDirectives} */
1830
+ #directives;
1831
+ /** @type {Set<import('types').Csp.Source>} */
1832
+ #script_src;
1833
+ /** @type {Set<import('types').Csp.Source>} */
1834
+ #script_src_elem;
1835
+ /** @type {Set<import('types').Csp.Source>} */
1836
+ #style_src;
1837
+ /** @type {Set<import('types').Csp.Source>} */
1838
+ #style_src_attr;
1839
+ /** @type {Set<import('types').Csp.Source>} */
1840
+ #style_src_elem;
1841
+ /** @type {boolean} */
1842
+ script_needs_nonce;
1843
+ /** @type {boolean} */
1844
+ style_needs_nonce;
1845
+ /** @type {boolean} */
1846
+ script_needs_hash;
1847
+ /** @type {string} */
1848
+ #nonce;
1849
+ /**
1850
+ * @param {boolean} use_hashes
1851
+ * @param {import('types').CspDirectives} directives
1852
+ * @param {string} nonce
1853
+ */
1854
+ constructor(use_hashes, directives, nonce) {
1855
+ this.#use_hashes = use_hashes;
1856
+ this.#directives = directives;
1857
+ const d = this.#directives;
1858
+ this.#script_src = /* @__PURE__ */ new Set();
1859
+ this.#script_src_elem = /* @__PURE__ */ new Set();
1860
+ this.#style_src = /* @__PURE__ */ new Set();
1861
+ this.#style_src_attr = /* @__PURE__ */ new Set();
1862
+ this.#style_src_elem = /* @__PURE__ */ new Set();
1863
+ const effective_script_src = d["script-src"] || d["default-src"];
1864
+ const script_src_elem = d["script-src-elem"];
1865
+ const effective_style_src = d["style-src"] || d["default-src"];
1866
+ const style_src_attr = d["style-src-attr"];
1867
+ const style_src_elem = d["style-src-elem"];
1868
+ const style_needs_csp = (directive) => !!directive && !directive.some((value) => value === "unsafe-inline");
1869
+ const script_needs_csp = (directive) => !!directive && (!directive.some((value) => value === "unsafe-inline") || directive.some((value) => value === "strict-dynamic"));
1870
+ this.#script_src_needs_csp = script_needs_csp(effective_script_src);
1871
+ this.#script_src_elem_needs_csp = script_needs_csp(script_src_elem);
1872
+ this.#style_src_needs_csp = style_needs_csp(effective_style_src);
1873
+ this.#style_src_attr_needs_csp = style_needs_csp(style_src_attr);
1874
+ this.#style_src_elem_needs_csp = style_needs_csp(style_src_elem);
1875
+ this.#script_needs_csp = this.#script_src_needs_csp || this.#script_src_elem_needs_csp;
1876
+ this.#style_needs_csp = this.#style_src_needs_csp || this.#style_src_attr_needs_csp || this.#style_src_elem_needs_csp;
1877
+ this.script_needs_nonce = this.#script_needs_csp && !this.#use_hashes;
1878
+ this.style_needs_nonce = this.#style_needs_csp && !this.#use_hashes;
1879
+ this.script_needs_hash = this.#script_needs_csp && this.#use_hashes;
1880
+ this.#nonce = nonce;
1881
+ }
1882
+ /** @param {string} content */
1883
+ add_script(content) {
1884
+ if (!this.#script_needs_csp) return;
1885
+ const source = this.#use_hashes ? `sha256-${sha256(content)}` : `nonce-${this.#nonce}`;
1886
+ if (this.#script_src_needs_csp) {
1887
+ this.#script_src.add(source);
1888
+ }
1889
+ if (this.#script_src_elem_needs_csp) {
1890
+ this.#script_src_elem.add(source);
1891
+ }
1892
+ }
1893
+ /** @param {`sha256-${string}`[]} hashes */
1894
+ add_script_hashes(hashes) {
1895
+ for (const hash2 of hashes) {
1896
+ if (this.#script_src_needs_csp) {
1897
+ this.#script_src.add(hash2);
1898
+ }
1899
+ if (this.#script_src_elem_needs_csp) {
1900
+ this.#script_src_elem.add(hash2);
1901
+ }
1902
+ }
1903
+ }
1904
+ /** @param {string} content */
1905
+ add_style(content) {
1906
+ if (!this.#style_needs_csp) return;
1907
+ const source = this.#use_hashes ? `sha256-${sha256(content)}` : `nonce-${this.#nonce}`;
1908
+ if (this.#style_src_needs_csp) {
1909
+ this.#style_src.add(source);
1910
+ }
1911
+ if (this.#style_src_attr_needs_csp) {
1912
+ this.#style_src_attr.add(source);
1913
+ }
1914
+ if (this.#style_src_elem_needs_csp) {
1915
+ const sha256_empty_comment_hash = "sha256-9OlNO0DNEeaVzHL4RZwCLsBHA8WBQ8toBp/4F5XV2nc=";
1916
+ const d = this.#directives;
1917
+ if (d["style-src-elem"] && !d["style-src-elem"].includes(sha256_empty_comment_hash) && !this.#style_src_elem.has(sha256_empty_comment_hash)) {
1918
+ this.#style_src_elem.add(sha256_empty_comment_hash);
1919
+ }
1920
+ if (source !== sha256_empty_comment_hash) {
1921
+ this.#style_src_elem.add(source);
1922
+ }
1923
+ }
1924
+ }
1925
+ /**
1926
+ * @param {boolean} [is_meta]
1927
+ */
1928
+ get_header(is_meta = false) {
1929
+ const header = [];
1930
+ const directives = { ...this.#directives };
1931
+ if (this.#style_src.size > 0) {
1932
+ directives["style-src"] = [
1933
+ ...directives["style-src"] || directives["default-src"] || [],
1934
+ ...this.#style_src
1935
+ ];
1936
+ }
1937
+ if (this.#style_src_attr.size > 0) {
1938
+ directives["style-src-attr"] = [
1939
+ ...directives["style-src-attr"] || [],
1940
+ ...this.#style_src_attr
1941
+ ];
1942
+ }
1943
+ if (this.#style_src_elem.size > 0) {
1944
+ directives["style-src-elem"] = [
1945
+ ...directives["style-src-elem"] || [],
1946
+ ...this.#style_src_elem
1947
+ ];
1948
+ }
1949
+ if (this.#script_src.size > 0) {
1950
+ directives["script-src"] = [
1951
+ ...directives["script-src"] || directives["default-src"] || [],
1952
+ ...this.#script_src
1953
+ ];
1954
+ }
1955
+ if (this.#script_src_elem.size > 0) {
1956
+ directives["script-src-elem"] = [
1957
+ ...directives["script-src-elem"] || [],
1958
+ ...this.#script_src_elem
1959
+ ];
1960
+ }
1961
+ for (const key2 in directives) {
1962
+ if (is_meta && (key2 === "frame-ancestors" || key2 === "report-uri" || key2 === "sandbox")) {
1963
+ continue;
1964
+ }
1965
+ const value = (
1966
+ /** @type {string[] | true} */
1967
+ directives[key2]
1968
+ );
1969
+ if (!value) continue;
1970
+ const directive = [key2];
1971
+ if (Array.isArray(value)) {
1972
+ value.forEach((value2) => {
1973
+ if (quoted.has(value2) || crypto_pattern.test(value2)) {
1974
+ directive.push(`'${value2}'`);
1975
+ } else {
1976
+ directive.push(value2);
1977
+ }
1978
+ });
1979
+ }
1980
+ header.push(directive.join(" "));
1981
+ }
1982
+ return header.join("; ");
1983
+ }
1984
+ }
1985
+ class CspProvider extends BaseProvider {
1986
+ get_meta() {
1987
+ const content = this.get_header(true);
1988
+ if (!content) {
1989
+ return;
1990
+ }
1991
+ return `<meta http-equiv="content-security-policy" content="${escape_html(content, true)}">`;
1992
+ }
1993
+ }
1994
+ class CspReportOnlyProvider extends BaseProvider {
1995
+ /**
1996
+ * @param {boolean} use_hashes
1997
+ * @param {import('types').CspDirectives} directives
1998
+ * @param {string} nonce
1999
+ */
2000
+ constructor(use_hashes, directives, nonce) {
2001
+ super(use_hashes, directives, nonce);
2002
+ if (Object.values(directives).filter((v) => !!v).length > 0) {
2003
+ const has_report_to = directives["report-to"]?.length ?? 0 > 0;
2004
+ const has_report_uri = directives["report-uri"]?.length ?? 0 > 0;
2005
+ if (!has_report_to && !has_report_uri) {
2006
+ throw Error(
2007
+ "`content-security-policy-report-only` must be specified with either the `report-to` or `report-uri` directives, or both"
2008
+ );
2009
+ }
2010
+ }
2011
+ }
2012
+ }
2013
+ class Csp {
2014
+ /** @readonly */
2015
+ nonce = generate_nonce();
2016
+ /** @type {CspProvider} */
2017
+ csp_provider;
2018
+ /** @type {CspReportOnlyProvider} */
2019
+ report_only_provider;
2020
+ /**
2021
+ * @param {import('./types.js').CspConfig} config
2022
+ * @param {import('./types.js').CspOpts} opts
2023
+ */
2024
+ constructor({ mode, directives, reportOnly }, { prerender }) {
2025
+ const use_hashes = mode === "hash" || mode === "auto" && prerender;
2026
+ this.csp_provider = new CspProvider(use_hashes, directives, this.nonce);
2027
+ this.report_only_provider = new CspReportOnlyProvider(use_hashes, reportOnly, this.nonce);
2028
+ }
2029
+ get script_needs_hash() {
2030
+ return this.csp_provider.script_needs_hash || this.report_only_provider.script_needs_hash;
2031
+ }
2032
+ get script_needs_nonce() {
2033
+ return this.csp_provider.script_needs_nonce || this.report_only_provider.script_needs_nonce;
2034
+ }
2035
+ get style_needs_nonce() {
2036
+ return this.csp_provider.style_needs_nonce || this.report_only_provider.style_needs_nonce;
2037
+ }
2038
+ /** @param {string} content */
2039
+ add_script(content) {
2040
+ this.csp_provider.add_script(content);
2041
+ this.report_only_provider.add_script(content);
2042
+ }
2043
+ /** @param {`sha256-${string}`[]} hashes */
2044
+ add_script_hashes(hashes) {
2045
+ this.csp_provider.add_script_hashes(hashes);
2046
+ this.report_only_provider.add_script_hashes(hashes);
2047
+ }
2048
+ /** @param {string} content */
2049
+ add_style(content) {
2050
+ this.csp_provider.add_style(content);
2051
+ this.report_only_provider.add_style(content);
2052
+ }
2053
+ }
2054
+ function exec(match, params, matchers) {
2055
+ const result = {};
2056
+ const values = match.slice(1);
2057
+ const values_needing_match = values.filter((value) => value !== void 0);
2058
+ let buffered = 0;
2059
+ for (let i = 0; i < params.length; i += 1) {
2060
+ const param = params[i];
2061
+ let value = values[i - buffered];
2062
+ if (param.chained && param.rest && buffered) {
2063
+ value = values.slice(i - buffered, i + 1).filter((s2) => s2).join("/");
2064
+ buffered = 0;
2065
+ }
2066
+ if (value === void 0) {
2067
+ if (param.rest) {
2068
+ value = "";
2069
+ } else {
2070
+ continue;
2071
+ }
2072
+ }
2073
+ if (!param.matcher || matchers[param.matcher](value)) {
2074
+ result[param.name] = value;
2075
+ const next_param = params[i + 1];
2076
+ const next_value = values[i + 1];
2077
+ if (next_param && !next_param.rest && next_param.optional && next_value && param.chained) {
2078
+ buffered = 0;
2079
+ }
2080
+ if (!next_param && !next_value && Object.keys(result).length === values_needing_match.length) {
2081
+ buffered = 0;
2082
+ }
2083
+ continue;
2084
+ }
2085
+ if (param.optional && param.chained) {
2086
+ buffered++;
2087
+ continue;
2088
+ }
2089
+ return;
2090
+ }
2091
+ if (buffered) return;
2092
+ return result;
2093
+ }
2094
+ function find_route(path, routes, matchers) {
2095
+ for (const route of routes) {
2096
+ const match = route.pattern.exec(path);
2097
+ if (!match) continue;
2098
+ const matched = exec(match, route.params, matchers);
2099
+ if (matched) {
2100
+ return {
2101
+ route,
2102
+ params: decode_params(matched)
2103
+ };
2104
+ }
2105
+ }
2106
+ return null;
2107
+ }
2108
+ function generate_route_object(route, url, manifest) {
2109
+ const { errors, layouts, leaf } = route;
2110
+ const nodes = [...errors, ...layouts.map((l) => l?.[1]), leaf[1]].filter((n) => typeof n === "number").map((n) => `'${n}': () => ${create_client_import(manifest._.client.nodes?.[n], url)}`).join(",\n ");
2111
+ return [
2112
+ `{
2113
+ id: ${s(route.id)}`,
2114
+ `errors: ${s(route.errors)}`,
2115
+ `layouts: ${s(route.layouts)}`,
2116
+ `leaf: ${s(route.leaf)}`,
2117
+ `nodes: {
2118
+ ${nodes}
2119
+ }
2120
+ }`
2121
+ ].join(",\n ");
2122
+ }
2123
+ function create_client_import(import_path, url) {
2124
+ if (!import_path) return "Promise.resolve({})";
2125
+ if (import_path[0] === "/") {
2126
+ return `import('${import_path}')`;
2127
+ }
2128
+ if (assets !== "") {
2129
+ return `import('${assets}/${import_path}')`;
2130
+ }
2131
+ let path = get_relative_path(url.pathname, `${base}/${import_path}`);
2132
+ if (path[0] !== ".") path = `./${path}`;
2133
+ return `import('${path}')`;
2134
+ }
2135
+ async function resolve_route(resolved_path, url, manifest) {
2136
+ if (!manifest._.client.routes) {
2137
+ return text("Server-side route resolution disabled", { status: 400 });
2138
+ }
2139
+ const matchers = await manifest._.matchers();
2140
+ const result = find_route(resolved_path, manifest._.client.routes, matchers);
2141
+ return create_server_routing_response(result?.route ?? null, result?.params ?? {}, url, manifest).response;
2142
+ }
2143
+ function create_server_routing_response(route, params, url, manifest) {
2144
+ const headers2 = new Headers({
2145
+ "content-type": "application/javascript; charset=utf-8"
2146
+ });
2147
+ if (route) {
2148
+ const csr_route = generate_route_object(route, url, manifest);
2149
+ const body2 = `${create_css_import(route, url, manifest)}
2150
+ export const route = ${csr_route}; export const params = ${JSON.stringify(params)};`;
2151
+ return { response: text(body2, { headers: headers2 }), body: body2 };
2152
+ } else {
2153
+ return { response: text("", { headers: headers2 }), body: "" };
2154
+ }
2155
+ }
2156
+ function create_css_import(route, url, manifest) {
2157
+ const { errors, layouts, leaf } = route;
2158
+ let css = "";
2159
+ for (const node of [...errors, ...layouts.map((l) => l?.[1]), leaf[1]]) {
2160
+ if (typeof node !== "number") continue;
2161
+ const node_css = manifest._.client.css?.[node];
2162
+ for (const css_path of node_css ?? []) {
2163
+ css += `'${assets || base}/${css_path}',`;
2164
+ }
2165
+ }
2166
+ if (!css) return "";
2167
+ return `${create_client_import(
2168
+ /** @type {string} */
2169
+ manifest._.client.start,
2170
+ url
2171
+ )}.then(x => x.load_css([${css}]));`;
2172
+ }
2173
+ const updated = {
2174
+ ...readable(false),
2175
+ check: () => false
2176
+ };
2177
+ async function render_response({
2178
+ branch,
2179
+ fetched,
2180
+ options: options2,
2181
+ manifest,
2182
+ state,
2183
+ page_config,
2184
+ status,
2185
+ error: error2 = null,
2186
+ event,
2187
+ event_state,
2188
+ resolve_opts,
2189
+ action_result,
2190
+ data_serializer
2191
+ }) {
2192
+ if (state.prerendering) {
2193
+ if (options2.csp.mode === "nonce") {
2194
+ throw new Error('Cannot use prerendering if config.kit.csp.mode === "nonce"');
2195
+ }
2196
+ if (options2.app_template_contains_nonce) {
2197
+ throw new Error("Cannot use prerendering if page template contains %sveltekit.nonce%");
2198
+ }
2199
+ }
2200
+ const { client } = manifest._;
2201
+ const modulepreloads = new Set(client.imports);
2202
+ const stylesheets = new Set(client.stylesheets);
2203
+ const fonts = new Set(client.fonts);
2204
+ const link_headers = /* @__PURE__ */ new Set();
2205
+ const inline_styles = /* @__PURE__ */ new Map();
2206
+ let rendered;
2207
+ const form_value = action_result?.type === "success" || action_result?.type === "failure" ? action_result.data ?? null : null;
2208
+ let base$1 = base;
2209
+ let assets$1 = assets;
2210
+ let base_expression = s(base);
2211
+ const csp = new Csp(options2.csp, {
2212
+ prerender: !!state.prerendering
2213
+ });
2214
+ {
2215
+ if (!state.prerendering?.fallback) {
2216
+ const segments = event.url.pathname.slice(base.length).split("/").slice(2);
2217
+ base$1 = segments.map(() => "..").join("/") || ".";
2218
+ base_expression = `new URL(${s(base$1)}, location).pathname.slice(0, -1)`;
2219
+ if (!assets || assets[0] === "/" && assets !== SVELTE_KIT_ASSETS) {
2220
+ assets$1 = base$1;
2221
+ }
2222
+ } else if (options2.hash_routing) {
2223
+ base_expression = "new URL('.', location).pathname.slice(0, -1)";
2224
+ }
2225
+ }
2226
+ if (page_config.ssr) {
2227
+ const props = {
2228
+ stores: {
2229
+ page: writable(null),
2230
+ navigating: writable(null),
2231
+ updated
2232
+ },
2233
+ constructors: await Promise.all(
2234
+ branch.map(({ node }) => {
2235
+ if (!node.component) {
2236
+ throw new Error(`Missing +page.svelte component for route ${event.route.id}`);
2237
+ }
2238
+ return node.component();
2239
+ })
2240
+ ),
2241
+ form: form_value
2242
+ };
2243
+ let data2 = {};
2244
+ for (let i = 0; i < branch.length; i += 1) {
2245
+ data2 = { ...data2, ...branch[i].data };
2246
+ props[`data_${i}`] = data2;
2247
+ }
2248
+ props.page = {
2249
+ error: error2,
2250
+ params: (
2251
+ /** @type {Record<string, any>} */
2252
+ event.params
2253
+ ),
2254
+ route: event.route,
2255
+ status,
2256
+ url: event.url,
2257
+ data: data2,
2258
+ form: form_value,
2259
+ state: {}
2260
+ };
2261
+ const render_opts = {
2262
+ context: /* @__PURE__ */ new Map([
2263
+ [
2264
+ "__request__",
2265
+ {
2266
+ page: props.page
2267
+ }
2268
+ ]
2269
+ ]),
2270
+ csp: csp.script_needs_nonce ? { nonce: csp.nonce } : { hash: csp.script_needs_hash }
2271
+ };
2272
+ try {
2273
+ if (DEV) ;
2274
+ rendered = await with_request_store({ event, state: event_state }, async () => {
2275
+ if (relative) override({ base: base$1, assets: assets$1 });
2276
+ const maybe_promise = options2.root.render(props, render_opts);
2277
+ const rendered2 = options2.async && "then" in maybe_promise ? (
2278
+ /** @type {ReturnType<typeof options.root.render> & Promise<any>} */
2279
+ maybe_promise.then((r) => r)
2280
+ ) : maybe_promise;
2281
+ if (options2.async) {
2282
+ reset();
2283
+ }
2284
+ const { head: head2, html: html2, css, hashes } = (
2285
+ /** @type {ReturnType<typeof options.root.render>} */
2286
+ options2.async ? await rendered2 : rendered2
2287
+ );
2288
+ if (hashes) {
2289
+ csp.add_script_hashes(hashes.script);
2290
+ }
2291
+ return { head: head2, html: html2, css, hashes };
2292
+ });
2293
+ } finally {
2294
+ reset();
2295
+ }
2296
+ for (const { node } of branch) {
2297
+ for (const url of node.imports) modulepreloads.add(url);
2298
+ for (const url of node.stylesheets) stylesheets.add(url);
2299
+ for (const url of node.fonts) fonts.add(url);
2300
+ if (node.inline_styles && !client.inline) {
2301
+ Object.entries(await node.inline_styles()).forEach(([filename, css]) => {
2302
+ if (typeof css === "string") {
2303
+ inline_styles.set(filename, css);
2304
+ return;
2305
+ }
2306
+ inline_styles.set(filename, css(`${assets$1}/${app_dir}/immutable/assets`, assets$1));
2307
+ });
2308
+ }
2309
+ }
2310
+ } else {
2311
+ rendered = { head: "", html: "", css: { code: "", map: null }, hashes: { script: [] } };
2312
+ }
2313
+ const head = new Head(rendered.head, !!state.prerendering);
2314
+ let body2 = rendered.html;
2315
+ const prefixed = (path) => {
2316
+ if (path.startsWith("/")) {
2317
+ return base + path;
2318
+ }
2319
+ return `${assets$1}/${path}`;
2320
+ };
2321
+ const style = client.inline ? client.inline?.style : Array.from(inline_styles.values()).join("\n");
2322
+ if (style) {
2323
+ const attributes = [];
2324
+ if (csp.style_needs_nonce) attributes.push(`nonce="${csp.nonce}"`);
2325
+ csp.add_style(style);
2326
+ head.add_style(style, attributes);
2327
+ }
2328
+ for (const dep of stylesheets) {
2329
+ const path = prefixed(dep);
2330
+ const attributes = ['rel="stylesheet"'];
2331
+ if (inline_styles.has(dep)) {
2332
+ attributes.push("disabled", 'media="(max-width: 0)"');
2333
+ } else {
2334
+ if (resolve_opts.preload({ type: "css", path })) {
2335
+ link_headers.add(`<${encodeURI(path)}>; rel="preload"; as="style"; nopush`);
2336
+ }
2337
+ }
2338
+ head.add_stylesheet(path, attributes);
2339
+ }
2340
+ for (const dep of fonts) {
2341
+ const path = prefixed(dep);
2342
+ if (resolve_opts.preload({ type: "font", path })) {
2343
+ const ext = dep.slice(dep.lastIndexOf(".") + 1);
2344
+ head.add_link_tag(path, ['rel="preload"', 'as="font"', `type="font/${ext}"`, "crossorigin"]);
2345
+ link_headers.add(
2346
+ `<${encodeURI(path)}>; rel="preload"; as="font"; type="font/${ext}"; crossorigin; nopush`
2347
+ );
2348
+ }
2349
+ }
2350
+ const global = get_global_name(options2);
2351
+ const { data, chunks } = data_serializer.get_data(csp);
2352
+ if (page_config.ssr && page_config.csr) {
2353
+ body2 += `
2354
+ ${fetched.map(
2355
+ (item) => serialize_data(item, resolve_opts.filterSerializedResponseHeaders, !!state.prerendering)
2356
+ ).join("\n ")}`;
2357
+ }
2358
+ if (page_config.csr) {
2359
+ const route = manifest._.client.routes?.find((r) => r.id === event.route.id) ?? null;
2360
+ if (client.uses_env_dynamic_public && state.prerendering) {
2361
+ modulepreloads.add(`${app_dir}/env.js`);
2362
+ }
2363
+ if (!client.inline) {
2364
+ const included_modulepreloads = Array.from(modulepreloads, (dep) => prefixed(dep)).filter(
2365
+ (path) => resolve_opts.preload({ type: "js", path })
2366
+ );
2367
+ for (const path of included_modulepreloads) {
2368
+ link_headers.add(`<${encodeURI(path)}>; rel="modulepreload"; nopush`);
2369
+ if (options2.preload_strategy !== "modulepreload") {
2370
+ head.add_script_preload(path);
2371
+ } else {
2372
+ head.add_link_tag(path, ['rel="modulepreload"']);
2373
+ }
2374
+ }
2375
+ }
2376
+ if (manifest._.client.routes && state.prerendering && !state.prerendering.fallback) {
2377
+ const pathname = add_resolution_suffix(event.url.pathname);
2378
+ state.prerendering.dependencies.set(
2379
+ pathname,
2380
+ create_server_routing_response(route, event.params, new URL(pathname, event.url), manifest)
2381
+ );
2382
+ }
2383
+ const blocks = [];
2384
+ const load_env_eagerly = client.uses_env_dynamic_public && state.prerendering;
2385
+ const properties = [`base: ${base_expression}`];
2386
+ if (assets) {
2387
+ properties.push(`assets: ${s(assets)}`);
2388
+ }
2389
+ if (client.uses_env_dynamic_public) {
2390
+ properties.push(`env: ${load_env_eagerly ? "null" : s(public_env)}`);
2391
+ }
2392
+ if (chunks) {
2393
+ blocks.push("const deferred = new Map();");
2394
+ properties.push(`defer: (id) => new Promise((fulfil, reject) => {
2395
+ deferred.set(id, { fulfil, reject });
2396
+ })`);
2397
+ let app_declaration = "";
2398
+ if (Object.keys(options2.hooks.transport).length > 0) {
2399
+ if (client.inline) {
2400
+ app_declaration = `const app = __sveltekit_${options2.version_hash}.app.app;`;
2401
+ } else if (client.app) {
2402
+ app_declaration = `const app = await import(${s(prefixed(client.app))});`;
2403
+ } else {
2404
+ app_declaration = `const { app } = await import(${s(prefixed(client.start))});`;
2405
+ }
2406
+ }
2407
+ const prelude = app_declaration ? `${app_declaration}
2408
+ const [data, error] = fn(app);` : `const [data, error] = fn();`;
2409
+ properties.push(`resolve: async (id, fn) => {
2410
+ ${prelude}
2411
+
2412
+ const try_to_resolve = () => {
2413
+ if (!deferred.has(id)) {
2414
+ setTimeout(try_to_resolve, 0);
2415
+ return;
2416
+ }
2417
+ const { fulfil, reject } = deferred.get(id);
2418
+ deferred.delete(id);
2419
+ if (error) reject(error);
2420
+ else fulfil(data);
2421
+ }
2422
+ try_to_resolve();
2423
+ }`);
2424
+ }
2425
+ blocks.push(`${global} = {
2426
+ ${properties.join(",\n ")}
2427
+ };`);
2428
+ const args = ["element"];
2429
+ blocks.push("const element = document.currentScript.parentElement;");
2430
+ if (page_config.ssr) {
2431
+ const serialized = { form: "null", error: "null" };
2432
+ if (form_value) {
2433
+ serialized.form = uneval_action_response(
2434
+ form_value,
2435
+ /** @type {string} */
2436
+ event.route.id,
2437
+ options2.hooks.transport
2438
+ );
2439
+ }
2440
+ if (error2) {
2441
+ serialized.error = uneval(error2);
2442
+ }
2443
+ const hydrate = [
2444
+ `node_ids: [${branch.map(({ node }) => node.index).join(", ")}]`,
2445
+ `data: ${data}`,
2446
+ `form: ${serialized.form}`,
2447
+ `error: ${serialized.error}`
2448
+ ];
2449
+ if (status !== 200) {
2450
+ hydrate.push(`status: ${status}`);
2451
+ }
2452
+ if (manifest._.client.routes) {
2453
+ if (route) {
2454
+ const stringified = generate_route_object(route, event.url, manifest).replaceAll(
2455
+ "\n",
2456
+ "\n "
2457
+ );
2458
+ hydrate.push(`params: ${uneval(event.params)}`, `server_route: ${stringified}`);
2459
+ }
2460
+ } else if (options2.embedded) {
2461
+ hydrate.push(`params: ${uneval(event.params)}`, `route: ${s(event.route)}`);
2462
+ }
2463
+ const indent = " ".repeat(load_env_eagerly ? 7 : 6);
2464
+ args.push(`{
2465
+ ${indent} ${hydrate.join(`,
2466
+ ${indent} `)}
2467
+ ${indent}}`);
2468
+ }
2469
+ const { remote_data: remote_cache } = event_state;
2470
+ let serialized_remote_data = "";
2471
+ if (remote_cache) {
2472
+ const remote = {};
2473
+ for (const [info, cache] of remote_cache) {
2474
+ if (!info.id) continue;
2475
+ for (const key2 in cache) {
2476
+ remote[create_remote_key(info.id, key2)] = await cache[key2];
2477
+ }
2478
+ }
2479
+ const replacer = (thing) => {
2480
+ for (const key2 in options2.hooks.transport) {
2481
+ const encoded = options2.hooks.transport[key2].encode(thing);
2482
+ if (encoded) {
2483
+ return `app.decode('${key2}', ${uneval(encoded, replacer)})`;
2484
+ }
2485
+ }
2486
+ };
2487
+ serialized_remote_data = `${global}.data = ${uneval(remote, replacer)};
2488
+
2489
+ `;
2490
+ }
2491
+ const boot = client.inline ? `${client.inline.script}
2492
+
2493
+ ${serialized_remote_data}${global}.app.start(${args.join(", ")});` : client.app ? `Promise.all([
2494
+ import(${s(prefixed(client.start))}),
2495
+ import(${s(prefixed(client.app))})
2496
+ ]).then(([kit, app]) => {
2497
+ ${serialized_remote_data}kit.start(app, ${args.join(", ")});
2498
+ });` : `import(${s(prefixed(client.start))}).then((app) => {
2499
+ ${serialized_remote_data}app.start(${args.join(", ")})
2500
+ });`;
2501
+ if (load_env_eagerly) {
2502
+ blocks.push(`import(${s(`${base$1}/${app_dir}/env.js`)}).then(({ env }) => {
2503
+ ${global}.env = env;
2504
+
2505
+ ${boot.replace(/\n/g, "\n ")}
2506
+ });`);
2507
+ } else {
2508
+ blocks.push(boot);
2509
+ }
2510
+ if (options2.service_worker) {
2511
+ let opts = "";
2512
+ if (options2.service_worker_options != null) {
2513
+ const service_worker_options = { ...options2.service_worker_options };
2514
+ opts = `, ${s(service_worker_options)}`;
2515
+ }
2516
+ blocks.push(`if ('serviceWorker' in navigator) {
2517
+ addEventListener('load', function () {
2518
+ navigator.serviceWorker.register('${prefixed("service-worker.js")}'${opts});
2519
+ });
2520
+ }`);
2521
+ }
2522
+ const init_app = `
2523
+ {
2524
+ ${blocks.join("\n\n ")}
2525
+ }
2526
+ `;
2527
+ csp.add_script(init_app);
2528
+ body2 += `
2529
+ <script${csp.script_needs_nonce ? ` nonce="${csp.nonce}"` : ""}>${init_app}<\/script>
2530
+ `;
2531
+ }
2532
+ const headers2 = new Headers({
2533
+ "x-sveltekit-page": "true",
2534
+ "content-type": "text/html"
2535
+ });
2536
+ if (state.prerendering) {
2537
+ const csp_headers = csp.csp_provider.get_meta();
2538
+ if (csp_headers) {
2539
+ head.add_http_equiv(csp_headers);
2540
+ }
2541
+ if (state.prerendering.cache) {
2542
+ head.add_http_equiv(
2543
+ `<meta http-equiv="cache-control" content="${state.prerendering.cache}">`
2544
+ );
2545
+ }
2546
+ } else {
2547
+ const csp_header = csp.csp_provider.get_header();
2548
+ if (csp_header) {
2549
+ headers2.set("content-security-policy", csp_header);
2550
+ }
2551
+ const report_only_header = csp.report_only_provider.get_header();
2552
+ if (report_only_header) {
2553
+ headers2.set("content-security-policy-report-only", report_only_header);
2554
+ }
2555
+ if (link_headers.size) {
2556
+ headers2.set("link", Array.from(link_headers).join(", "));
2557
+ }
2558
+ }
2559
+ const html = options2.templates.app({
2560
+ head: head.build(),
2561
+ body: body2,
2562
+ assets: assets$1,
2563
+ nonce: (
2564
+ /** @type {string} */
2565
+ csp.nonce
2566
+ ),
2567
+ env: public_env
2568
+ });
2569
+ const transformed = await resolve_opts.transformPageChunk({
2570
+ html,
2571
+ done: true
2572
+ }) || "";
2573
+ if (!chunks) {
2574
+ headers2.set("etag", `"${hash(transformed)}"`);
2575
+ }
2576
+ return !chunks ? text(transformed, {
2577
+ status,
2578
+ headers: headers2
2579
+ }) : new Response(
2580
+ new ReadableStream({
2581
+ async start(controller) {
2582
+ controller.enqueue(text_encoder.encode(transformed + "\n"));
2583
+ for await (const chunk of chunks) {
2584
+ if (chunk.length) controller.enqueue(text_encoder.encode(chunk));
2585
+ }
2586
+ controller.close();
2587
+ },
2588
+ type: "bytes"
2589
+ }),
2590
+ {
2591
+ headers: headers2
2592
+ }
2593
+ );
2594
+ }
2595
+ class Head {
2596
+ #rendered;
2597
+ #prerendering;
2598
+ /** @type {string[]} */
2599
+ #http_equiv = [];
2600
+ /** @type {string[]} */
2601
+ #link_tags = [];
2602
+ /** @type {string[]} */
2603
+ #script_preloads = [];
2604
+ /** @type {string[]} */
2605
+ #style_tags = [];
2606
+ /** @type {string[]} */
2607
+ #stylesheet_links = [];
2608
+ /**
2609
+ * @param {string} rendered
2610
+ * @param {boolean} prerendering
2611
+ */
2612
+ constructor(rendered, prerendering) {
2613
+ this.#rendered = rendered;
2614
+ this.#prerendering = prerendering;
2615
+ }
2616
+ build() {
2617
+ return [
2618
+ ...this.#http_equiv,
2619
+ ...this.#link_tags,
2620
+ ...this.#script_preloads,
2621
+ this.#rendered,
2622
+ ...this.#style_tags,
2623
+ ...this.#stylesheet_links
2624
+ ].join("\n ");
2625
+ }
2626
+ /**
2627
+ * @param {string} style
2628
+ * @param {string[]} attributes
2629
+ */
2630
+ add_style(style, attributes) {
2631
+ this.#style_tags.push(
2632
+ `<style${attributes.length ? " " + attributes.join(" ") : ""}>${style}</style>`
2633
+ );
2634
+ }
2635
+ /**
2636
+ * @param {string} href
2637
+ * @param {string[]} attributes
2638
+ */
2639
+ add_stylesheet(href, attributes) {
2640
+ this.#stylesheet_links.push(`<link href="${href}" ${attributes.join(" ")}>`);
2641
+ }
2642
+ /** @param {string} href */
2643
+ add_script_preload(href) {
2644
+ this.#script_preloads.push(
2645
+ `<link rel="preload" as="script" crossorigin="anonymous" href="${href}">`
2646
+ );
2647
+ }
2648
+ /**
2649
+ * @param {string} href
2650
+ * @param {string[]} attributes
2651
+ */
2652
+ add_link_tag(href, attributes) {
2653
+ if (!this.#prerendering) return;
2654
+ this.#link_tags.push(`<link href="${href}" ${attributes.join(" ")}>`);
2655
+ }
2656
+ /** @param {string} tag */
2657
+ add_http_equiv(tag) {
2658
+ if (!this.#prerendering) return;
2659
+ this.#http_equiv.push(tag);
2660
+ }
2661
+ }
2662
+ class PageNodes {
2663
+ data;
2664
+ /**
2665
+ * @param {Array<import('types').SSRNode | undefined>} nodes
2666
+ */
2667
+ constructor(nodes) {
2668
+ this.data = nodes;
2669
+ }
2670
+ layouts() {
2671
+ return this.data.slice(0, -1);
2672
+ }
2673
+ page() {
2674
+ return this.data.at(-1);
2675
+ }
2676
+ validate() {
2677
+ for (const layout of this.layouts()) {
2678
+ if (layout) {
2679
+ validate_layout_server_exports(
2680
+ layout.server,
2681
+ /** @type {string} */
2682
+ layout.server_id
2683
+ );
2684
+ validate_layout_exports(
2685
+ layout.universal,
2686
+ /** @type {string} */
2687
+ layout.universal_id
2688
+ );
2689
+ }
2690
+ }
2691
+ const page = this.page();
2692
+ if (page) {
2693
+ validate_page_server_exports(
2694
+ page.server,
2695
+ /** @type {string} */
2696
+ page.server_id
2697
+ );
2698
+ validate_page_exports(
2699
+ page.universal,
2700
+ /** @type {string} */
2701
+ page.universal_id
2702
+ );
2703
+ }
2704
+ }
2705
+ /**
2706
+ * @template {'prerender' | 'ssr' | 'csr' | 'trailingSlash'} Option
2707
+ * @param {Option} option
2708
+ * @returns {Value | undefined}
2709
+ */
2710
+ #get_option(option) {
2711
+ return this.data.reduce(
2712
+ (value, node) => {
2713
+ return node?.universal?.[option] ?? node?.server?.[option] ?? value;
2714
+ },
2715
+ /** @type {Value | undefined} */
2716
+ void 0
2717
+ );
2718
+ }
2719
+ csr() {
2720
+ return this.#get_option("csr") ?? true;
2721
+ }
2722
+ ssr() {
2723
+ return this.#get_option("ssr") ?? true;
2724
+ }
2725
+ prerender() {
2726
+ return this.#get_option("prerender") ?? false;
2727
+ }
2728
+ trailing_slash() {
2729
+ return this.#get_option("trailingSlash") ?? "never";
2730
+ }
2731
+ get_config() {
2732
+ let current2 = {};
2733
+ for (const node of this.data) {
2734
+ if (!node?.universal?.config && !node?.server?.config) continue;
2735
+ current2 = {
2736
+ ...current2,
2737
+ // TODO: should we override the server config value with the universal value similar to other page options?
2738
+ ...node?.universal?.config,
2739
+ ...node?.server?.config
2740
+ };
2741
+ }
2742
+ return Object.keys(current2).length ? current2 : void 0;
2743
+ }
2744
+ should_prerender_data() {
2745
+ return this.data.some(
2746
+ // prerender in case of trailingSlash because the client retrieves that value from the server
2747
+ (node) => node?.server?.load || node?.server?.trailingSlash !== void 0
2748
+ );
2749
+ }
2750
+ }
2751
+ async function respond_with_error({
2752
+ event,
2753
+ event_state,
2754
+ options: options2,
2755
+ manifest,
2756
+ state,
2757
+ status,
2758
+ error: error2,
2759
+ resolve_opts
2760
+ }) {
2761
+ if (event.request.headers.get("x-sveltekit-error")) {
2762
+ return static_error_page(
2763
+ options2,
2764
+ status,
2765
+ /** @type {Error} */
2766
+ error2.message
2767
+ );
2768
+ }
2769
+ const fetched = [];
2770
+ try {
2771
+ const branch = [];
2772
+ const default_layout = await manifest._.nodes[0]();
2773
+ const nodes = new PageNodes([default_layout]);
2774
+ const ssr = nodes.ssr();
2775
+ const csr = nodes.csr();
2776
+ const data_serializer = server_data_serializer(event, event_state, options2);
2777
+ if (ssr) {
2778
+ state.error = true;
2779
+ const server_data_promise = load_server_data({
2780
+ event,
2781
+ event_state,
2782
+ state,
2783
+ node: default_layout,
2784
+ // eslint-disable-next-line @typescript-eslint/require-await
2785
+ parent: async () => ({})
2786
+ });
2787
+ const server_data = await server_data_promise;
2788
+ data_serializer.add_node(0, server_data);
2789
+ const data = await load_data({
2790
+ event,
2791
+ event_state,
2792
+ fetched,
2793
+ node: default_layout,
2794
+ // eslint-disable-next-line @typescript-eslint/require-await
2795
+ parent: async () => ({}),
2796
+ resolve_opts,
2797
+ server_data_promise,
2798
+ state,
2799
+ csr
2800
+ });
2801
+ branch.push(
2802
+ {
2803
+ node: default_layout,
2804
+ server_data,
2805
+ data
2806
+ },
2807
+ {
2808
+ node: await manifest._.nodes[1](),
2809
+ // 1 is always the root error
2810
+ data: null,
2811
+ server_data: null
2812
+ }
2813
+ );
2814
+ }
2815
+ return await render_response({
2816
+ options: options2,
2817
+ manifest,
2818
+ state,
2819
+ page_config: {
2820
+ ssr,
2821
+ csr
2822
+ },
2823
+ status,
2824
+ error: await handle_error_and_jsonify(event, event_state, options2, error2),
2825
+ branch,
2826
+ fetched,
2827
+ event,
2828
+ event_state,
2829
+ resolve_opts,
2830
+ data_serializer
2831
+ });
2832
+ } catch (e) {
2833
+ if (e instanceof Redirect) {
2834
+ return redirect_response(e.status, e.location);
2835
+ }
2836
+ return static_error_page(
2837
+ options2,
2838
+ get_status(e),
2839
+ (await handle_error_and_jsonify(event, event_state, options2, e)).message
2840
+ );
2841
+ }
2842
+ }
2843
+ async function handle_remote_call(event, state, options2, manifest, id) {
2844
+ return record_span({
2845
+ name: "sveltekit.remote.call",
2846
+ attributes: {},
2847
+ fn: (current2) => {
2848
+ const traced_event = merge_tracing(event, current2);
2849
+ return with_request_store(
2850
+ { event: traced_event, state },
2851
+ () => handle_remote_call_internal(traced_event, state, options2, manifest, id)
2852
+ );
2853
+ }
2854
+ });
2855
+ }
2856
+ async function handle_remote_call_internal(event, state, options2, manifest, id) {
2857
+ const [hash2, name, additional_args] = id.split("/");
2858
+ const remotes = manifest._.remotes;
2859
+ if (!remotes[hash2]) error(404);
2860
+ const module = await remotes[hash2]();
2861
+ const fn = module.default[name];
2862
+ if (!fn) error(404);
2863
+ const info = fn.__;
2864
+ const transport = options2.hooks.transport;
2865
+ event.tracing.current.setAttributes({
2866
+ "sveltekit.remote.call.type": info.type,
2867
+ "sveltekit.remote.call.name": info.name
2868
+ });
2869
+ let form_client_refreshes;
2870
+ try {
2871
+ if (info.type === "query_batch") {
2872
+ if (event.request.method !== "POST") {
2873
+ throw new SvelteKitError(
2874
+ 405,
2875
+ "Method Not Allowed",
2876
+ `\`query.batch\` functions must be invoked via POST request, not ${event.request.method}`
2877
+ );
2878
+ }
2879
+ const { payloads } = await event.request.json();
2880
+ const args = await Promise.all(
2881
+ payloads.map((payload2) => parse_remote_arg(payload2, transport))
2882
+ );
2883
+ const results = await with_request_store({ event, state }, () => info.run(args, options2));
2884
+ return json(
2885
+ /** @type {RemoteFunctionResponse} */
2886
+ {
2887
+ type: "result",
2888
+ result: stringify(results, transport)
2889
+ }
2890
+ );
2891
+ }
2892
+ if (info.type === "form") {
2893
+ if (event.request.method !== "POST") {
2894
+ throw new SvelteKitError(
2895
+ 405,
2896
+ "Method Not Allowed",
2897
+ `\`form\` functions must be invoked via POST request, not ${event.request.method}`
2898
+ );
2899
+ }
2900
+ if (!is_form_content_type(event.request)) {
2901
+ throw new SvelteKitError(
2902
+ 415,
2903
+ "Unsupported Media Type",
2904
+ `\`form\` functions expect form-encoded data — received ${event.request.headers.get(
2905
+ "content-type"
2906
+ )}`
2907
+ );
2908
+ }
2909
+ const { data: data2, meta, form_data } = await deserialize_binary_form(event.request);
2910
+ form_client_refreshes = meta.remote_refreshes;
2911
+ if (additional_args && !("id" in data2)) {
2912
+ data2.id = JSON.parse(decodeURIComponent(additional_args));
2913
+ }
2914
+ const fn2 = info.fn;
2915
+ const result = await with_request_store({ event, state }, () => fn2(data2, meta, form_data));
2916
+ return json(
2917
+ /** @type {RemoteFunctionResponse} */
2918
+ {
2919
+ type: "result",
2920
+ result: stringify(result, transport),
2921
+ refreshes: result.issues ? void 0 : await serialize_refreshes(meta.remote_refreshes)
2922
+ }
2923
+ );
2924
+ }
2925
+ if (info.type === "command") {
2926
+ const { payload: payload2, refreshes } = await event.request.json();
2927
+ const arg = parse_remote_arg(payload2, transport);
2928
+ const data2 = await with_request_store({ event, state }, () => fn(arg));
2929
+ return json(
2930
+ /** @type {RemoteFunctionResponse} */
2931
+ {
2932
+ type: "result",
2933
+ result: stringify(data2, transport),
2934
+ refreshes: await serialize_refreshes(refreshes)
2935
+ }
2936
+ );
2937
+ }
2938
+ const payload = info.type === "prerender" ? additional_args : (
2939
+ /** @type {string} */
2940
+ // new URL(...) necessary because we're hiding the URL from the user in the event object
2941
+ new URL(event.request.url).searchParams.get("payload")
2942
+ );
2943
+ const data = await with_request_store(
2944
+ { event, state },
2945
+ () => fn(parse_remote_arg(payload, transport))
2946
+ );
2947
+ return json(
2948
+ /** @type {RemoteFunctionResponse} */
2949
+ {
2950
+ type: "result",
2951
+ result: stringify(data, transport)
2952
+ }
2953
+ );
2954
+ } catch (error2) {
2955
+ if (error2 instanceof Redirect) {
2956
+ return json(
2957
+ /** @type {RemoteFunctionResponse} */
2958
+ {
2959
+ type: "redirect",
2960
+ location: error2.location,
2961
+ refreshes: await serialize_refreshes(form_client_refreshes)
2962
+ }
2963
+ );
2964
+ }
2965
+ const status = error2 instanceof HttpError || error2 instanceof SvelteKitError ? error2.status : 500;
2966
+ return json(
2967
+ /** @type {RemoteFunctionResponse} */
2968
+ {
2969
+ type: "error",
2970
+ error: await handle_error_and_jsonify(event, state, options2, error2),
2971
+ status
2972
+ },
2973
+ {
2974
+ // By setting a non-200 during prerendering we fail the prerender process (unless handleHttpError handles it).
2975
+ // Errors at runtime will be passed to the client and are handled there
2976
+ status: state.prerendering ? status : void 0,
2977
+ headers: {
2978
+ "cache-control": "private, no-store"
2979
+ }
2980
+ }
2981
+ );
2982
+ }
2983
+ async function serialize_refreshes(client_refreshes) {
2984
+ const refreshes = state.refreshes ?? {};
2985
+ if (client_refreshes) {
2986
+ for (const key2 of client_refreshes) {
2987
+ if (refreshes[key2] !== void 0) continue;
2988
+ const [hash3, name2, payload] = key2.split("/");
2989
+ const loader = manifest._.remotes[hash3];
2990
+ const fn2 = (await loader?.())?.default?.[name2];
2991
+ if (!fn2) error(400, "Bad Request");
2992
+ refreshes[key2] = with_request_store(
2993
+ { event, state },
2994
+ () => fn2(parse_remote_arg(payload, transport))
2995
+ );
2996
+ }
2997
+ }
2998
+ if (Object.keys(refreshes).length === 0) {
2999
+ return void 0;
3000
+ }
3001
+ return stringify(
3002
+ Object.fromEntries(
3003
+ await Promise.all(
3004
+ Object.entries(refreshes).map(async ([key2, promise]) => [key2, await promise])
3005
+ )
3006
+ ),
3007
+ transport
3008
+ );
3009
+ }
3010
+ }
3011
+ async function handle_remote_form_post(event, state, manifest, id) {
3012
+ return record_span({
3013
+ name: "sveltekit.remote.form.post",
3014
+ attributes: {},
3015
+ fn: (current2) => {
3016
+ const traced_event = merge_tracing(event, current2);
3017
+ return with_request_store(
3018
+ { event: traced_event, state },
3019
+ () => handle_remote_form_post_internal(traced_event, state, manifest, id)
3020
+ );
3021
+ }
3022
+ });
3023
+ }
3024
+ async function handle_remote_form_post_internal(event, state, manifest, id) {
3025
+ const [hash2, name, action_id] = id.split("/");
3026
+ const remotes = manifest._.remotes;
3027
+ const module = await remotes[hash2]?.();
3028
+ let form = (
3029
+ /** @type {RemoteForm<any, any>} */
3030
+ module?.default[name]
3031
+ );
3032
+ if (!form) {
3033
+ event.setHeaders({
3034
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
3035
+ // "The server must generate an Allow header field in a 405 status code response"
3036
+ allow: "GET"
3037
+ });
3038
+ return {
3039
+ type: "error",
3040
+ error: new SvelteKitError(
3041
+ 405,
3042
+ "Method Not Allowed",
3043
+ `POST method not allowed. No form actions exist for ${"this page"}`
3044
+ )
3045
+ };
3046
+ }
3047
+ if (action_id) {
3048
+ form = with_request_store({ event, state }, () => form.for(JSON.parse(action_id)));
3049
+ }
3050
+ try {
3051
+ const fn = (
3052
+ /** @type {RemoteInfo & { type: 'form' }} */
3053
+ /** @type {any} */
3054
+ form.__.fn
3055
+ );
3056
+ const { data, meta, form_data } = await deserialize_binary_form(event.request);
3057
+ if (action_id && !("id" in data)) {
3058
+ data.id = JSON.parse(decodeURIComponent(action_id));
3059
+ }
3060
+ await with_request_store({ event, state }, () => fn(data, meta, form_data));
3061
+ return {
3062
+ type: "success",
3063
+ status: 200
3064
+ };
3065
+ } catch (e) {
3066
+ const err = normalize_error(e);
3067
+ if (err instanceof Redirect) {
3068
+ return {
3069
+ type: "redirect",
3070
+ status: err.status,
3071
+ location: err.location
3072
+ };
3073
+ }
3074
+ return {
3075
+ type: "error",
3076
+ error: check_incorrect_fail_use(err)
3077
+ };
3078
+ }
3079
+ }
3080
+ function get_remote_id(url) {
3081
+ return url.pathname.startsWith(`${base}/${app_dir}/remote/`) && url.pathname.replace(`${base}/${app_dir}/remote/`, "");
3082
+ }
3083
+ function get_remote_action(url) {
3084
+ return url.searchParams.get("/remote");
3085
+ }
3086
+ const MAX_DEPTH = 10;
3087
+ async function render_page(event, event_state, page, options2, manifest, state, nodes, resolve_opts) {
3088
+ if (state.depth > MAX_DEPTH) {
3089
+ return text(`Not found: ${event.url.pathname}`, {
3090
+ status: 404
3091
+ // TODO in some cases this should be 500. not sure how to differentiate
3092
+ });
3093
+ }
3094
+ if (is_action_json_request(event)) {
3095
+ const node = await manifest._.nodes[page.leaf]();
3096
+ return handle_action_json_request(event, event_state, options2, node?.server);
3097
+ }
3098
+ try {
3099
+ const leaf_node = (
3100
+ /** @type {import('types').SSRNode} */
3101
+ nodes.page()
3102
+ );
3103
+ let status = 200;
3104
+ let action_result = void 0;
3105
+ if (is_action_request(event)) {
3106
+ const remote_id = get_remote_action(event.url);
3107
+ if (remote_id) {
3108
+ action_result = await handle_remote_form_post(event, event_state, manifest, remote_id);
3109
+ } else {
3110
+ action_result = await handle_action_request(event, event_state, leaf_node.server);
3111
+ }
3112
+ if (action_result?.type === "redirect") {
3113
+ return redirect_response(action_result.status, action_result.location);
3114
+ }
3115
+ if (action_result?.type === "error") {
3116
+ status = get_status(action_result.error);
3117
+ }
3118
+ if (action_result?.type === "failure") {
3119
+ status = action_result.status;
3120
+ }
3121
+ }
3122
+ const should_prerender = nodes.prerender();
3123
+ if (should_prerender) {
3124
+ const mod = leaf_node.server;
3125
+ if (mod?.actions) {
3126
+ throw new Error("Cannot prerender pages with actions");
3127
+ }
3128
+ } else if (state.prerendering) {
3129
+ return new Response(void 0, {
3130
+ status: 204
3131
+ });
3132
+ }
3133
+ state.prerender_default = should_prerender;
3134
+ const should_prerender_data = nodes.should_prerender_data();
3135
+ const data_pathname = add_data_suffix(event.url.pathname);
3136
+ const fetched = [];
3137
+ const ssr = nodes.ssr();
3138
+ const csr = nodes.csr();
3139
+ if (ssr === false && !(state.prerendering && should_prerender_data)) {
3140
+ if (DEV && action_result && !event.request.headers.has("x-sveltekit-action")) ;
3141
+ return await render_response({
3142
+ branch: [],
3143
+ fetched,
3144
+ page_config: {
3145
+ ssr: false,
3146
+ csr
3147
+ },
3148
+ status,
3149
+ error: null,
3150
+ event,
3151
+ event_state,
3152
+ options: options2,
3153
+ manifest,
3154
+ state,
3155
+ resolve_opts,
3156
+ data_serializer: server_data_serializer(event, event_state, options2)
3157
+ });
3158
+ }
3159
+ const branch = [];
3160
+ let load_error = null;
3161
+ const data_serializer = server_data_serializer(event, event_state, options2);
3162
+ const data_serializer_json = state.prerendering && should_prerender_data ? server_data_serializer_json(event, event_state, options2) : null;
3163
+ const server_promises = nodes.data.map((node, i) => {
3164
+ if (load_error) {
3165
+ throw load_error;
3166
+ }
3167
+ return Promise.resolve().then(async () => {
3168
+ try {
3169
+ if (node === leaf_node && action_result?.type === "error") {
3170
+ throw action_result.error;
3171
+ }
3172
+ const server_data = await load_server_data({
3173
+ event,
3174
+ event_state,
3175
+ state,
3176
+ node,
3177
+ parent: async () => {
3178
+ const data = {};
3179
+ for (let j = 0; j < i; j += 1) {
3180
+ const parent = await server_promises[j];
3181
+ if (parent) Object.assign(data, parent.data);
3182
+ }
3183
+ return data;
3184
+ }
3185
+ });
3186
+ if (node) {
3187
+ data_serializer.add_node(i, server_data);
3188
+ }
3189
+ data_serializer_json?.add_node(i, server_data);
3190
+ return server_data;
3191
+ } catch (e) {
3192
+ load_error = /** @type {Error} */
3193
+ e;
3194
+ throw load_error;
3195
+ }
3196
+ });
3197
+ });
3198
+ const load_promises = nodes.data.map((node, i) => {
3199
+ if (load_error) throw load_error;
3200
+ return Promise.resolve().then(async () => {
3201
+ try {
3202
+ return await load_data({
3203
+ event,
3204
+ event_state,
3205
+ fetched,
3206
+ node,
3207
+ parent: async () => {
3208
+ const data = {};
3209
+ for (let j = 0; j < i; j += 1) {
3210
+ Object.assign(data, await load_promises[j]);
3211
+ }
3212
+ return data;
3213
+ },
3214
+ resolve_opts,
3215
+ server_data_promise: server_promises[i],
3216
+ state,
3217
+ csr
3218
+ });
3219
+ } catch (e) {
3220
+ load_error = /** @type {Error} */
3221
+ e;
3222
+ throw load_error;
3223
+ }
3224
+ });
3225
+ });
3226
+ for (const p of server_promises) p.catch(() => {
3227
+ });
3228
+ for (const p of load_promises) p.catch(() => {
3229
+ });
3230
+ for (let i = 0; i < nodes.data.length; i += 1) {
3231
+ const node = nodes.data[i];
3232
+ if (node) {
3233
+ try {
3234
+ const server_data = await server_promises[i];
3235
+ const data = await load_promises[i];
3236
+ branch.push({ node, server_data, data });
3237
+ } catch (e) {
3238
+ const err = normalize_error(e);
3239
+ if (err instanceof Redirect) {
3240
+ if (state.prerendering && should_prerender_data) {
3241
+ const body2 = JSON.stringify({
3242
+ type: "redirect",
3243
+ location: err.location
3244
+ });
3245
+ state.prerendering.dependencies.set(data_pathname, {
3246
+ response: text(body2),
3247
+ body: body2
3248
+ });
3249
+ }
3250
+ return redirect_response(err.status, err.location);
3251
+ }
3252
+ const status2 = get_status(err);
3253
+ const error2 = await handle_error_and_jsonify(event, event_state, options2, err);
3254
+ while (i--) {
3255
+ if (page.errors[i]) {
3256
+ const index = (
3257
+ /** @type {number} */
3258
+ page.errors[i]
3259
+ );
3260
+ const node2 = await manifest._.nodes[index]();
3261
+ let j = i;
3262
+ while (!branch[j]) j -= 1;
3263
+ data_serializer.set_max_nodes(j + 1);
3264
+ const layouts = compact(branch.slice(0, j + 1));
3265
+ const nodes2 = new PageNodes(layouts.map((layout) => layout.node));
3266
+ return await render_response({
3267
+ event,
3268
+ event_state,
3269
+ options: options2,
3270
+ manifest,
3271
+ state,
3272
+ resolve_opts,
3273
+ page_config: {
3274
+ ssr: nodes2.ssr(),
3275
+ csr: nodes2.csr()
3276
+ },
3277
+ status: status2,
3278
+ error: error2,
3279
+ branch: layouts.concat({
3280
+ node: node2,
3281
+ data: null,
3282
+ server_data: null
3283
+ }),
3284
+ fetched,
3285
+ data_serializer
3286
+ });
3287
+ }
3288
+ }
3289
+ return static_error_page(options2, status2, error2.message);
3290
+ }
3291
+ } else {
3292
+ branch.push(null);
3293
+ }
3294
+ }
3295
+ if (state.prerendering && data_serializer_json) {
3296
+ let { data, chunks } = data_serializer_json.get_data();
3297
+ if (chunks) {
3298
+ for await (const chunk of chunks) {
3299
+ data += chunk;
3300
+ }
3301
+ }
3302
+ state.prerendering.dependencies.set(data_pathname, {
3303
+ response: text(data),
3304
+ body: data
3305
+ });
3306
+ }
3307
+ return await render_response({
3308
+ event,
3309
+ event_state,
3310
+ options: options2,
3311
+ manifest,
3312
+ state,
3313
+ resolve_opts,
3314
+ page_config: {
3315
+ csr,
3316
+ ssr
3317
+ },
3318
+ status,
3319
+ error: null,
3320
+ branch: ssr === false ? [] : compact(branch),
3321
+ action_result,
3322
+ fetched,
3323
+ data_serializer: ssr === false ? server_data_serializer(event, event_state, options2) : data_serializer
3324
+ });
3325
+ } catch (e) {
3326
+ if (e instanceof Redirect) {
3327
+ return redirect_response(e.status, e.location);
3328
+ }
3329
+ return await respond_with_error({
3330
+ event,
3331
+ event_state,
3332
+ options: options2,
3333
+ manifest,
3334
+ state,
3335
+ status: e instanceof HttpError ? e.status : 500,
3336
+ error: e,
3337
+ resolve_opts
3338
+ });
3339
+ }
3340
+ }
3341
+ function once(fn) {
3342
+ let done = false;
3343
+ let result;
3344
+ return () => {
3345
+ if (done) return result;
3346
+ done = true;
3347
+ return result = fn();
3348
+ };
3349
+ }
3350
+ async function render_data(event, event_state, route, options2, manifest, state, invalidated_data_nodes, trailing_slash) {
3351
+ if (!route.page) {
3352
+ return new Response(void 0, {
3353
+ status: 404
3354
+ });
3355
+ }
3356
+ try {
3357
+ const node_ids = [...route.page.layouts, route.page.leaf];
3358
+ const invalidated = invalidated_data_nodes ?? node_ids.map(() => true);
3359
+ let aborted = false;
3360
+ const url = new URL(event.url);
3361
+ url.pathname = normalize_path(url.pathname, trailing_slash);
3362
+ const new_event = { ...event, url };
3363
+ const functions = node_ids.map((n, i) => {
3364
+ return once(async () => {
3365
+ try {
3366
+ if (aborted) {
3367
+ return (
3368
+ /** @type {import('types').ServerDataSkippedNode} */
3369
+ {
3370
+ type: "skip"
3371
+ }
3372
+ );
3373
+ }
3374
+ const node = n == void 0 ? n : await manifest._.nodes[n]();
3375
+ return load_server_data({
3376
+ event: new_event,
3377
+ event_state,
3378
+ state,
3379
+ node,
3380
+ parent: async () => {
3381
+ const data2 = {};
3382
+ for (let j = 0; j < i; j += 1) {
3383
+ const parent = (
3384
+ /** @type {import('types').ServerDataNode | null} */
3385
+ await functions[j]()
3386
+ );
3387
+ if (parent) {
3388
+ Object.assign(data2, parent.data);
3389
+ }
3390
+ }
3391
+ return data2;
3392
+ }
3393
+ });
3394
+ } catch (e) {
3395
+ aborted = true;
3396
+ throw e;
3397
+ }
3398
+ });
3399
+ });
3400
+ const promises = functions.map(async (fn, i) => {
3401
+ if (!invalidated[i]) {
3402
+ return (
3403
+ /** @type {import('types').ServerDataSkippedNode} */
3404
+ {
3405
+ type: "skip"
3406
+ }
3407
+ );
3408
+ }
3409
+ return fn();
3410
+ });
3411
+ let length = promises.length;
3412
+ const nodes = await Promise.all(
3413
+ promises.map(
3414
+ (p, i) => p.catch(async (error2) => {
3415
+ if (error2 instanceof Redirect) {
3416
+ throw error2;
3417
+ }
3418
+ length = Math.min(length, i + 1);
3419
+ return (
3420
+ /** @type {import('types').ServerErrorNode} */
3421
+ {
3422
+ type: "error",
3423
+ error: await handle_error_and_jsonify(event, event_state, options2, error2),
3424
+ status: error2 instanceof HttpError || error2 instanceof SvelteKitError ? error2.status : void 0
3425
+ }
3426
+ );
3427
+ })
3428
+ )
3429
+ );
3430
+ const data_serializer = server_data_serializer_json(event, event_state, options2);
3431
+ for (let i = 0; i < nodes.length; i++) data_serializer.add_node(i, nodes[i]);
3432
+ const { data, chunks } = data_serializer.get_data();
3433
+ if (!chunks) {
3434
+ return json_response(data);
3435
+ }
3436
+ return new Response(
3437
+ new ReadableStream({
3438
+ async start(controller) {
3439
+ controller.enqueue(text_encoder.encode(data));
3440
+ for await (const chunk of chunks) {
3441
+ controller.enqueue(text_encoder.encode(chunk));
3442
+ }
3443
+ controller.close();
3444
+ },
3445
+ type: "bytes"
3446
+ }),
3447
+ {
3448
+ headers: {
3449
+ // we use a proprietary content type to prevent buffering.
3450
+ // the `text` prefix makes it inspectable
3451
+ "content-type": "text/sveltekit-data",
3452
+ "cache-control": "private, no-store"
3453
+ }
3454
+ }
3455
+ );
3456
+ } catch (e) {
3457
+ const error2 = normalize_error(e);
3458
+ if (error2 instanceof Redirect) {
3459
+ return redirect_json_response(error2);
3460
+ } else {
3461
+ return json_response(await handle_error_and_jsonify(event, event_state, options2, error2), 500);
3462
+ }
3463
+ }
3464
+ }
3465
+ function json_response(json2, status = 200) {
3466
+ return text(typeof json2 === "string" ? json2 : JSON.stringify(json2), {
3467
+ status,
3468
+ headers: {
3469
+ "content-type": "application/json",
3470
+ "cache-control": "private, no-store"
3471
+ }
3472
+ });
3473
+ }
3474
+ function redirect_json_response(redirect) {
3475
+ return json_response(
3476
+ /** @type {import('types').ServerRedirectNode} */
3477
+ {
3478
+ type: "redirect",
3479
+ location: redirect.location
3480
+ }
3481
+ );
3482
+ }
3483
+ const INVALID_COOKIE_CHARACTER_REGEX = /[\x00-\x1F\x7F()<>@,;:"/[\]?={} \t]/;
3484
+ function validate_options(options2) {
3485
+ if (options2?.path === void 0) {
3486
+ throw new Error("You must specify a `path` when setting, deleting or serializing cookies");
3487
+ }
3488
+ }
3489
+ function generate_cookie_key(domain, path, name) {
3490
+ return `${domain || ""}${path}?${encodeURIComponent(name)}`;
3491
+ }
3492
+ function get_cookies(request, url) {
3493
+ const header = request.headers.get("cookie") ?? "";
3494
+ const initial_cookies = cookieExports.parse(header, { decode: (value) => value });
3495
+ let normalized_url;
3496
+ const new_cookies = /* @__PURE__ */ new Map();
3497
+ const defaults = {
3498
+ httpOnly: true,
3499
+ sameSite: "lax",
3500
+ secure: url.hostname === "localhost" && url.protocol === "http:" ? false : true
3501
+ };
3502
+ const cookies = {
3503
+ // The JSDoc param annotations appearing below for get, set and delete
3504
+ // are necessary to expose the `cookie` library types to
3505
+ // typescript users. `@type {import('@sveltejs/kit').Cookies}` above is not
3506
+ // sufficient to do so.
3507
+ /**
3508
+ * @param {string} name
3509
+ * @param {import('cookie').CookieParseOptions} [opts]
3510
+ */
3511
+ get(name, opts) {
3512
+ const best_match = Array.from(new_cookies.values()).filter((c) => {
3513
+ return c.name === name && domain_matches(url.hostname, c.options.domain) && path_matches(url.pathname, c.options.path);
3514
+ }).sort((a, b) => b.options.path.length - a.options.path.length)[0];
3515
+ if (best_match) {
3516
+ return best_match.options.maxAge === 0 ? void 0 : best_match.value;
3517
+ }
3518
+ const req_cookies = cookieExports.parse(header, { decode: opts?.decode });
3519
+ const cookie = req_cookies[name];
3520
+ return cookie;
3521
+ },
3522
+ /**
3523
+ * @param {import('cookie').CookieParseOptions} [opts]
3524
+ */
3525
+ getAll(opts) {
3526
+ const cookies2 = cookieExports.parse(header, { decode: opts?.decode });
3527
+ const lookup = /* @__PURE__ */ new Map();
3528
+ for (const c of new_cookies.values()) {
3529
+ if (domain_matches(url.hostname, c.options.domain) && path_matches(url.pathname, c.options.path)) {
3530
+ const existing = lookup.get(c.name);
3531
+ if (!existing || c.options.path.length > existing.options.path.length) {
3532
+ lookup.set(c.name, c);
3533
+ }
3534
+ }
3535
+ }
3536
+ for (const c of lookup.values()) {
3537
+ cookies2[c.name] = c.value;
3538
+ }
3539
+ return Object.entries(cookies2).map(([name, value]) => ({ name, value }));
3540
+ },
3541
+ /**
3542
+ * @param {string} name
3543
+ * @param {string} value
3544
+ * @param {import('./page/types.js').Cookie['options']} options
3545
+ */
3546
+ set(name, value, options2) {
3547
+ const illegal_characters = name.match(INVALID_COOKIE_CHARACTER_REGEX);
3548
+ if (illegal_characters) {
3549
+ console.warn(
3550
+ `The cookie name "${name}" will be invalid in SvelteKit 3.0 as it contains ${illegal_characters.join(
3551
+ " and "
3552
+ )}. See RFC 2616 for more details https://datatracker.ietf.org/doc/html/rfc2616#section-2.2`
3553
+ );
3554
+ }
3555
+ validate_options(options2);
3556
+ set_internal(name, value, { ...defaults, ...options2 });
3557
+ },
3558
+ /**
3559
+ * @param {string} name
3560
+ * @param {import('./page/types.js').Cookie['options']} options
3561
+ */
3562
+ delete(name, options2) {
3563
+ validate_options(options2);
3564
+ cookies.set(name, "", { ...options2, maxAge: 0 });
3565
+ },
3566
+ /**
3567
+ * @param {string} name
3568
+ * @param {string} value
3569
+ * @param {import('./page/types.js').Cookie['options']} options
3570
+ */
3571
+ serialize(name, value, options2) {
3572
+ validate_options(options2);
3573
+ let path = options2.path;
3574
+ if (!options2.domain || options2.domain === url.hostname) {
3575
+ if (!normalized_url) {
3576
+ throw new Error("Cannot serialize cookies until after the route is determined");
3577
+ }
3578
+ path = resolve(normalized_url, path);
3579
+ }
3580
+ return cookieExports.serialize(name, value, { ...defaults, ...options2, path });
3581
+ }
3582
+ };
3583
+ function get_cookie_header(destination, header2) {
3584
+ const combined_cookies = {
3585
+ // cookies sent by the user agent have lowest precedence
3586
+ ...initial_cookies
3587
+ };
3588
+ for (const cookie of new_cookies.values()) {
3589
+ if (!domain_matches(destination.hostname, cookie.options.domain)) continue;
3590
+ if (!path_matches(destination.pathname, cookie.options.path)) continue;
3591
+ const encoder = cookie.options.encode || encodeURIComponent;
3592
+ combined_cookies[cookie.name] = encoder(cookie.value);
3593
+ }
3594
+ if (header2) {
3595
+ const parsed = cookieExports.parse(header2, { decode: (value) => value });
3596
+ for (const name in parsed) {
3597
+ combined_cookies[name] = parsed[name];
3598
+ }
3599
+ }
3600
+ return Object.entries(combined_cookies).map(([name, value]) => `${name}=${value}`).join("; ");
3601
+ }
3602
+ const internal_queue = [];
3603
+ function set_internal(name, value, options2) {
3604
+ if (!normalized_url) {
3605
+ internal_queue.push(() => set_internal(name, value, options2));
3606
+ return;
3607
+ }
3608
+ let path = options2.path;
3609
+ if (!options2.domain || options2.domain === url.hostname) {
3610
+ path = resolve(normalized_url, path);
3611
+ }
3612
+ const cookie_key = generate_cookie_key(options2.domain, path, name);
3613
+ const cookie = { name, value, options: { ...options2, path } };
3614
+ new_cookies.set(cookie_key, cookie);
3615
+ }
3616
+ function set_trailing_slash(trailing_slash) {
3617
+ normalized_url = normalize_path(url.pathname, trailing_slash);
3618
+ internal_queue.forEach((fn) => fn());
3619
+ }
3620
+ return { cookies, new_cookies, get_cookie_header, set_internal, set_trailing_slash };
3621
+ }
3622
+ function domain_matches(hostname, constraint) {
3623
+ if (!constraint) return true;
3624
+ const normalized = constraint[0] === "." ? constraint.slice(1) : constraint;
3625
+ if (hostname === normalized) return true;
3626
+ return hostname.endsWith("." + normalized);
3627
+ }
3628
+ function path_matches(path, constraint) {
3629
+ if (!constraint) return true;
3630
+ const normalized = constraint.endsWith("/") ? constraint.slice(0, -1) : constraint;
3631
+ if (path === normalized) return true;
3632
+ return path.startsWith(normalized + "/");
3633
+ }
3634
+ function add_cookies_to_headers(headers2, cookies) {
3635
+ for (const new_cookie of cookies) {
3636
+ const { name, value, options: options2 } = new_cookie;
3637
+ headers2.append("set-cookie", cookieExports.serialize(name, value, options2));
3638
+ if (options2.path.endsWith(".html")) {
3639
+ const path = add_data_suffix(options2.path);
3640
+ headers2.append("set-cookie", cookieExports.serialize(name, value, { ...options2, path }));
3641
+ }
3642
+ }
3643
+ }
3644
+ function create_fetch({ event, options: options2, manifest, state, get_cookie_header, set_internal }) {
3645
+ const server_fetch = async (info, init2) => {
3646
+ const original_request = normalize_fetch_input(info, init2, event.url);
3647
+ let mode = (info instanceof Request ? info.mode : init2?.mode) ?? "cors";
3648
+ let credentials = (info instanceof Request ? info.credentials : init2?.credentials) ?? "same-origin";
3649
+ return options2.hooks.handleFetch({
3650
+ event,
3651
+ request: original_request,
3652
+ fetch: async (info2, init3) => {
3653
+ const request = normalize_fetch_input(info2, init3, event.url);
3654
+ const url = new URL(request.url);
3655
+ if (!request.headers.has("origin")) {
3656
+ request.headers.set("origin", event.url.origin);
3657
+ }
3658
+ if (info2 !== original_request) {
3659
+ mode = (info2 instanceof Request ? info2.mode : init3?.mode) ?? "cors";
3660
+ credentials = (info2 instanceof Request ? info2.credentials : init3?.credentials) ?? "same-origin";
3661
+ }
3662
+ if ((request.method === "GET" || request.method === "HEAD") && (mode === "no-cors" && url.origin !== event.url.origin || url.origin === event.url.origin)) {
3663
+ request.headers.delete("origin");
3664
+ }
3665
+ const decoded = decodeURIComponent(url.pathname);
3666
+ if (url.origin !== event.url.origin || base && decoded !== base && !decoded.startsWith(`${base}/`)) {
3667
+ if (`.${url.hostname}`.endsWith(`.${event.url.hostname}`) && credentials !== "omit") {
3668
+ const cookie = get_cookie_header(url, request.headers.get("cookie"));
3669
+ if (cookie) request.headers.set("cookie", cookie);
3670
+ }
3671
+ return fetch(request);
3672
+ }
3673
+ const prefix = assets || base;
3674
+ const filename = (decoded.startsWith(prefix) ? decoded.slice(prefix.length) : decoded).slice(1);
3675
+ const filename_html = `${filename}/index.html`;
3676
+ const is_asset = manifest.assets.has(filename) || filename in manifest._.server_assets;
3677
+ const is_asset_html = manifest.assets.has(filename_html) || filename_html in manifest._.server_assets;
3678
+ if (is_asset || is_asset_html) {
3679
+ const file = is_asset ? filename : filename_html;
3680
+ if (state.read) {
3681
+ const type = is_asset ? manifest.mimeTypes[filename.slice(filename.lastIndexOf("."))] : "text/html";
3682
+ return new Response(state.read(file), {
3683
+ headers: type ? { "content-type": type } : {}
3684
+ });
3685
+ } else if (read_implementation && file in manifest._.server_assets) {
3686
+ const length = manifest._.server_assets[file];
3687
+ const type = manifest.mimeTypes[file.slice(file.lastIndexOf("."))];
3688
+ return new Response(read_implementation(file), {
3689
+ headers: {
3690
+ "Content-Length": "" + length,
3691
+ "Content-Type": type
3692
+ }
3693
+ });
3694
+ }
3695
+ return await fetch(request);
3696
+ }
3697
+ if (has_prerendered_path(manifest, base + decoded)) {
3698
+ return await fetch(request);
3699
+ }
3700
+ if (credentials !== "omit") {
3701
+ const cookie = get_cookie_header(url, request.headers.get("cookie"));
3702
+ if (cookie) {
3703
+ request.headers.set("cookie", cookie);
3704
+ }
3705
+ const authorization = event.request.headers.get("authorization");
3706
+ if (authorization && !request.headers.has("authorization")) {
3707
+ request.headers.set("authorization", authorization);
3708
+ }
3709
+ }
3710
+ if (!request.headers.has("accept")) {
3711
+ request.headers.set("accept", "*/*");
3712
+ }
3713
+ if (!request.headers.has("accept-language")) {
3714
+ request.headers.set(
3715
+ "accept-language",
3716
+ /** @type {string} */
3717
+ event.request.headers.get("accept-language")
3718
+ );
3719
+ }
3720
+ const response = await internal_fetch(request, options2, manifest, state);
3721
+ const set_cookie = response.headers.get("set-cookie");
3722
+ if (set_cookie) {
3723
+ for (const str of splitCookiesString(set_cookie)) {
3724
+ const { name, value, ...options3 } = parseString(str, {
3725
+ decodeValues: false
3726
+ });
3727
+ const path = options3.path ?? (url.pathname.split("/").slice(0, -1).join("/") || "/");
3728
+ set_internal(name, value, {
3729
+ path,
3730
+ encode: (value2) => value2,
3731
+ .../** @type {import('cookie').CookieSerializeOptions} */
3732
+ options3
3733
+ });
3734
+ }
3735
+ }
3736
+ return response;
3737
+ }
3738
+ });
3739
+ };
3740
+ return (input, init2) => {
3741
+ const response = server_fetch(input, init2);
3742
+ response.catch(() => {
3743
+ });
3744
+ return response;
3745
+ };
3746
+ }
3747
+ function normalize_fetch_input(info, init2, url) {
3748
+ if (info instanceof Request) {
3749
+ return info;
3750
+ }
3751
+ return new Request(typeof info === "string" ? new URL(info, url) : info, init2);
3752
+ }
3753
+ async function internal_fetch(request, options2, manifest, state) {
3754
+ if (request.signal) {
3755
+ if (request.signal.aborted) {
3756
+ throw new DOMException("The operation was aborted.", "AbortError");
3757
+ }
3758
+ let remove_abort_listener = () => {
3759
+ };
3760
+ const abort_promise = new Promise((_, reject) => {
3761
+ const on_abort = () => {
3762
+ reject(new DOMException("The operation was aborted.", "AbortError"));
3763
+ };
3764
+ request.signal.addEventListener("abort", on_abort, { once: true });
3765
+ remove_abort_listener = () => request.signal.removeEventListener("abort", on_abort);
3766
+ });
3767
+ const result = await Promise.race([
3768
+ respond(request, options2, manifest, {
3769
+ ...state,
3770
+ depth: state.depth + 1
3771
+ }),
3772
+ abort_promise
3773
+ ]);
3774
+ remove_abort_listener();
3775
+ return result;
3776
+ } else {
3777
+ return await respond(request, options2, manifest, {
3778
+ ...state,
3779
+ depth: state.depth + 1
3780
+ });
3781
+ }
3782
+ }
3783
+ let body;
3784
+ let etag;
3785
+ let headers;
3786
+ function get_public_env(request) {
3787
+ body ??= `export const env=${JSON.stringify(public_env)}`;
3788
+ etag ??= `W/${Date.now()}`;
3789
+ headers ??= new Headers({
3790
+ "content-type": "application/javascript; charset=utf-8",
3791
+ etag
3792
+ });
3793
+ if (request.headers.get("if-none-match") === etag) {
3794
+ return new Response(void 0, { status: 304, headers });
3795
+ }
3796
+ return new Response(body, { headers });
3797
+ }
3798
+ const default_transform = ({ html }) => html;
3799
+ const default_filter = () => false;
3800
+ const default_preload = ({ type }) => type === "js" || type === "css";
3801
+ const page_methods = /* @__PURE__ */ new Set(["GET", "HEAD", "POST"]);
3802
+ const allowed_page_methods = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
3803
+ const respond = propagate_context(internal_respond);
3804
+ async function internal_respond(request, options2, manifest, state) {
3805
+ const url = new URL(request.url);
3806
+ const is_route_resolution_request = has_resolution_suffix(url.pathname);
3807
+ const is_data_request = has_data_suffix(url.pathname);
3808
+ const remote_id = get_remote_id(url);
3809
+ {
3810
+ const request_origin = request.headers.get("origin");
3811
+ if (remote_id) {
3812
+ if (request.method !== "GET" && request_origin !== url.origin) {
3813
+ const message = "Cross-site remote requests are forbidden";
3814
+ return json({ message }, { status: 403 });
3815
+ }
3816
+ } else if (options2.csrf_check_origin) {
3817
+ const forbidden = is_form_content_type(request) && (request.method === "POST" || request.method === "PUT" || request.method === "PATCH" || request.method === "DELETE") && request_origin !== url.origin && (!request_origin || !options2.csrf_trusted_origins.includes(request_origin));
3818
+ if (forbidden) {
3819
+ const message = `Cross-site ${request.method} form submissions are forbidden`;
3820
+ const opts = { status: 403 };
3821
+ if (request.headers.get("accept") === "application/json") {
3822
+ return json({ message }, opts);
3823
+ }
3824
+ return text(message, opts);
3825
+ }
3826
+ }
3827
+ }
3828
+ if (options2.hash_routing && url.pathname !== base + "/" && url.pathname !== "/[fallback]") {
3829
+ return text("Not found", { status: 404 });
3830
+ }
3831
+ let invalidated_data_nodes;
3832
+ if (is_route_resolution_request) {
3833
+ url.pathname = strip_resolution_suffix(url.pathname);
3834
+ } else if (is_data_request) {
3835
+ url.pathname = strip_data_suffix(url.pathname) + (url.searchParams.get(TRAILING_SLASH_PARAM) === "1" ? "/" : "") || "/";
3836
+ url.searchParams.delete(TRAILING_SLASH_PARAM);
3837
+ invalidated_data_nodes = url.searchParams.get(INVALIDATED_PARAM)?.split("").map((node) => node === "1");
3838
+ url.searchParams.delete(INVALIDATED_PARAM);
3839
+ } else if (remote_id) {
3840
+ url.pathname = request.headers.get("x-sveltekit-pathname") ?? base;
3841
+ url.search = request.headers.get("x-sveltekit-search") ?? "";
3842
+ }
3843
+ const headers2 = {};
3844
+ const { cookies, new_cookies, get_cookie_header, set_internal, set_trailing_slash } = get_cookies(
3845
+ request,
3846
+ url
3847
+ );
3848
+ const event_state = {
3849
+ prerendering: state.prerendering,
3850
+ transport: options2.hooks.transport,
3851
+ handleValidationError: options2.hooks.handleValidationError,
3852
+ tracing: {
3853
+ record_span
3854
+ },
3855
+ is_in_remote_function: false
3856
+ };
3857
+ const event = {
3858
+ cookies,
3859
+ // @ts-expect-error `fetch` needs to be created after the `event` itself
3860
+ fetch: null,
3861
+ getClientAddress: state.getClientAddress || (() => {
3862
+ throw new Error(
3863
+ `${"@sveltejs/adapter-node"} does not specify getClientAddress. Please raise an issue`
3864
+ );
3865
+ }),
3866
+ locals: {},
3867
+ params: {},
3868
+ platform: state.platform,
3869
+ request,
3870
+ route: { id: null },
3871
+ setHeaders: (new_headers) => {
3872
+ for (const key2 in new_headers) {
3873
+ const lower = key2.toLowerCase();
3874
+ const value = new_headers[key2];
3875
+ if (lower === "set-cookie") {
3876
+ throw new Error(
3877
+ "Use `event.cookies.set(name, value, options)` instead of `event.setHeaders` to set cookies"
3878
+ );
3879
+ } else if (lower in headers2) {
3880
+ if (lower === "server-timing") {
3881
+ headers2[lower] += ", " + value;
3882
+ } else {
3883
+ throw new Error(`"${key2}" header is already set`);
3884
+ }
3885
+ } else {
3886
+ headers2[lower] = value;
3887
+ if (state.prerendering && lower === "cache-control") {
3888
+ state.prerendering.cache = /** @type {string} */
3889
+ value;
3890
+ }
3891
+ }
3892
+ }
3893
+ },
3894
+ url,
3895
+ isDataRequest: is_data_request,
3896
+ isSubRequest: state.depth > 0,
3897
+ isRemoteRequest: !!remote_id
3898
+ };
3899
+ event.fetch = create_fetch({
3900
+ event,
3901
+ options: options2,
3902
+ manifest,
3903
+ state,
3904
+ get_cookie_header,
3905
+ set_internal
3906
+ });
3907
+ if (state.emulator?.platform) {
3908
+ event.platform = await state.emulator.platform({
3909
+ config: {},
3910
+ prerender: !!state.prerendering?.fallback
3911
+ });
3912
+ }
3913
+ let resolved_path = url.pathname;
3914
+ if (!remote_id) {
3915
+ const prerendering_reroute_state = state.prerendering?.inside_reroute;
3916
+ try {
3917
+ if (state.prerendering) state.prerendering.inside_reroute = true;
3918
+ resolved_path = await options2.hooks.reroute({ url: new URL(url), fetch: event.fetch }) ?? url.pathname;
3919
+ } catch {
3920
+ return text("Internal Server Error", {
3921
+ status: 500
3922
+ });
3923
+ } finally {
3924
+ if (state.prerendering) state.prerendering.inside_reroute = prerendering_reroute_state;
3925
+ }
3926
+ }
3927
+ try {
3928
+ resolved_path = decode_pathname(resolved_path);
3929
+ } catch {
3930
+ return text("Malformed URI", { status: 400 });
3931
+ }
3932
+ if (
3933
+ // the resolved path has been decoded so it should be compared to the decoded url pathname
3934
+ resolved_path !== decode_pathname(url.pathname) && !state.prerendering?.fallback && has_prerendered_path(manifest, resolved_path)
3935
+ ) {
3936
+ const url2 = new URL(request.url);
3937
+ url2.pathname = is_data_request ? add_data_suffix(resolved_path) : is_route_resolution_request ? add_resolution_suffix(resolved_path) : resolved_path;
3938
+ try {
3939
+ const response = await fetch(url2, request);
3940
+ const headers22 = new Headers(response.headers);
3941
+ if (headers22.has("content-encoding")) {
3942
+ headers22.delete("content-encoding");
3943
+ headers22.delete("content-length");
3944
+ }
3945
+ return new Response(response.body, {
3946
+ headers: headers22,
3947
+ status: response.status,
3948
+ statusText: response.statusText
3949
+ });
3950
+ } catch (error2) {
3951
+ return await handle_fatal_error(event, event_state, options2, error2);
3952
+ }
3953
+ }
3954
+ let route = null;
3955
+ if (base && !state.prerendering?.fallback) {
3956
+ if (!resolved_path.startsWith(base)) {
3957
+ return text("Not found", { status: 404 });
3958
+ }
3959
+ resolved_path = resolved_path.slice(base.length) || "/";
3960
+ }
3961
+ if (is_route_resolution_request) {
3962
+ return resolve_route(resolved_path, new URL(request.url), manifest);
3963
+ }
3964
+ if (resolved_path === `/${app_dir}/env.js`) {
3965
+ return get_public_env(request);
3966
+ }
3967
+ if (!remote_id && resolved_path.startsWith(`/${app_dir}`)) {
3968
+ const headers22 = new Headers();
3969
+ headers22.set("cache-control", "public, max-age=0, must-revalidate");
3970
+ return text("Not found", { status: 404, headers: headers22 });
3971
+ }
3972
+ if (!state.prerendering?.fallback) {
3973
+ const matchers = await manifest._.matchers();
3974
+ const result = find_route(resolved_path, manifest._.routes, matchers);
3975
+ if (result) {
3976
+ route = result.route;
3977
+ event.route = { id: route.id };
3978
+ event.params = result.params;
3979
+ }
3980
+ }
3981
+ let resolve_opts = {
3982
+ transformPageChunk: default_transform,
3983
+ filterSerializedResponseHeaders: default_filter,
3984
+ preload: default_preload
3985
+ };
3986
+ let trailing_slash = "never";
3987
+ try {
3988
+ const page_nodes = route?.page ? new PageNodes(await load_page_nodes(route.page, manifest)) : void 0;
3989
+ if (route && !remote_id) {
3990
+ if (url.pathname === base || url.pathname === base + "/") {
3991
+ trailing_slash = "always";
3992
+ } else if (page_nodes) {
3993
+ if (DEV) ;
3994
+ trailing_slash = page_nodes.trailing_slash();
3995
+ } else if (route.endpoint) {
3996
+ const node = await route.endpoint();
3997
+ trailing_slash = node.trailingSlash ?? "never";
3998
+ if (DEV) ;
3999
+ }
4000
+ if (!is_data_request) {
4001
+ const normalized = normalize_path(url.pathname, trailing_slash);
4002
+ if (normalized !== url.pathname && !state.prerendering?.fallback) {
4003
+ return new Response(void 0, {
4004
+ status: 308,
4005
+ headers: {
4006
+ "x-sveltekit-normalize": "1",
4007
+ location: (
4008
+ // ensure paths starting with '//' are not treated as protocol-relative
4009
+ (normalized.startsWith("//") ? url.origin + normalized : normalized) + (url.search === "?" ? "" : url.search)
4010
+ )
4011
+ }
4012
+ });
4013
+ }
4014
+ }
4015
+ if (state.before_handle || state.emulator?.platform) {
4016
+ let config = {};
4017
+ let prerender = false;
4018
+ if (route.endpoint) {
4019
+ const node = await route.endpoint();
4020
+ config = node.config ?? config;
4021
+ prerender = node.prerender ?? prerender;
4022
+ } else if (page_nodes) {
4023
+ config = page_nodes.get_config() ?? config;
4024
+ prerender = page_nodes.prerender();
4025
+ }
4026
+ if (state.before_handle) {
4027
+ state.before_handle(event, config, prerender);
4028
+ }
4029
+ if (state.emulator?.platform) {
4030
+ event.platform = await state.emulator.platform({ config, prerender });
4031
+ }
4032
+ }
4033
+ }
4034
+ set_trailing_slash(trailing_slash);
4035
+ if (state.prerendering && !state.prerendering.fallback && !state.prerendering.inside_reroute) {
4036
+ disable_search(url);
4037
+ }
4038
+ const response = await record_span({
4039
+ name: "sveltekit.handle.root",
4040
+ attributes: {
4041
+ "http.route": event.route.id || "unknown",
4042
+ "http.method": event.request.method,
4043
+ "http.url": event.url.href,
4044
+ "sveltekit.is_data_request": is_data_request,
4045
+ "sveltekit.is_sub_request": event.isSubRequest
4046
+ },
4047
+ fn: async (root_span) => {
4048
+ const traced_event = {
4049
+ ...event,
4050
+ tracing: {
4051
+ enabled: false,
4052
+ root: root_span,
4053
+ current: root_span
4054
+ }
4055
+ };
4056
+ return await with_request_store(
4057
+ { event: traced_event, state: event_state },
4058
+ () => options2.hooks.handle({
4059
+ event: traced_event,
4060
+ resolve: (event2, opts) => {
4061
+ return record_span({
4062
+ name: "sveltekit.resolve",
4063
+ attributes: {
4064
+ "http.route": event2.route.id || "unknown"
4065
+ },
4066
+ fn: (resolve_span) => {
4067
+ return with_request_store(
4068
+ null,
4069
+ () => resolve2(merge_tracing(event2, resolve_span), page_nodes, opts).then(
4070
+ (response2) => {
4071
+ for (const key2 in headers2) {
4072
+ const value = headers2[key2];
4073
+ response2.headers.set(
4074
+ key2,
4075
+ /** @type {string} */
4076
+ value
4077
+ );
4078
+ }
4079
+ add_cookies_to_headers(response2.headers, new_cookies.values());
4080
+ if (state.prerendering && event2.route.id !== null) {
4081
+ response2.headers.set("x-sveltekit-routeid", encodeURI(event2.route.id));
4082
+ }
4083
+ resolve_span.setAttributes({
4084
+ "http.response.status_code": response2.status,
4085
+ "http.response.body.size": response2.headers.get("content-length") || "unknown"
4086
+ });
4087
+ return response2;
4088
+ }
4089
+ )
4090
+ );
4091
+ }
4092
+ });
4093
+ }
4094
+ })
4095
+ );
4096
+ }
4097
+ });
4098
+ if (response.status === 200 && response.headers.has("etag")) {
4099
+ let if_none_match_value = request.headers.get("if-none-match");
4100
+ if (if_none_match_value?.startsWith('W/"')) {
4101
+ if_none_match_value = if_none_match_value.substring(2);
4102
+ }
4103
+ const etag2 = (
4104
+ /** @type {string} */
4105
+ response.headers.get("etag")
4106
+ );
4107
+ if (if_none_match_value === etag2) {
4108
+ const headers22 = new Headers({ etag: etag2 });
4109
+ for (const key2 of [
4110
+ "cache-control",
4111
+ "content-location",
4112
+ "date",
4113
+ "expires",
4114
+ "vary",
4115
+ "set-cookie"
4116
+ ]) {
4117
+ const value = response.headers.get(key2);
4118
+ if (value) headers22.set(key2, value);
4119
+ }
4120
+ return new Response(void 0, {
4121
+ status: 304,
4122
+ headers: headers22
4123
+ });
4124
+ }
4125
+ }
4126
+ if (is_data_request && response.status >= 300 && response.status <= 308) {
4127
+ const location = response.headers.get("location");
4128
+ if (location) {
4129
+ return redirect_json_response(new Redirect(
4130
+ /** @type {any} */
4131
+ response.status,
4132
+ location
4133
+ ));
4134
+ }
4135
+ }
4136
+ return response;
4137
+ } catch (e) {
4138
+ if (e instanceof Redirect) {
4139
+ const response = is_data_request || remote_id ? redirect_json_response(e) : route?.page && is_action_json_request(event) ? action_json_redirect(e) : redirect_response(e.status, e.location);
4140
+ add_cookies_to_headers(response.headers, new_cookies.values());
4141
+ return response;
4142
+ }
4143
+ return await handle_fatal_error(event, event_state, options2, e);
4144
+ }
4145
+ async function resolve2(event2, page_nodes, opts) {
4146
+ try {
4147
+ if (opts) {
4148
+ resolve_opts = {
4149
+ transformPageChunk: opts.transformPageChunk || default_transform,
4150
+ filterSerializedResponseHeaders: opts.filterSerializedResponseHeaders || default_filter,
4151
+ preload: opts.preload || default_preload
4152
+ };
4153
+ }
4154
+ if (options2.hash_routing || state.prerendering?.fallback) {
4155
+ return await render_response({
4156
+ event: event2,
4157
+ event_state,
4158
+ options: options2,
4159
+ manifest,
4160
+ state,
4161
+ page_config: { ssr: false, csr: true },
4162
+ status: 200,
4163
+ error: null,
4164
+ branch: [],
4165
+ fetched: [],
4166
+ resolve_opts,
4167
+ data_serializer: server_data_serializer(event2, event_state, options2)
4168
+ });
4169
+ }
4170
+ if (remote_id) {
4171
+ return await handle_remote_call(event2, event_state, options2, manifest, remote_id);
4172
+ }
4173
+ if (route) {
4174
+ const method = (
4175
+ /** @type {import('types').HttpMethod} */
4176
+ event2.request.method
4177
+ );
4178
+ let response2;
4179
+ if (is_data_request) {
4180
+ response2 = await render_data(
4181
+ event2,
4182
+ event_state,
4183
+ route,
4184
+ options2,
4185
+ manifest,
4186
+ state,
4187
+ invalidated_data_nodes,
4188
+ trailing_slash
4189
+ );
4190
+ } else if (route.endpoint && (!route.page || is_endpoint_request(event2))) {
4191
+ response2 = await render_endpoint(event2, event_state, await route.endpoint(), state);
4192
+ } else if (route.page) {
4193
+ if (!page_nodes) {
4194
+ throw new Error("page_nodes not found. This should never happen");
4195
+ } else if (page_methods.has(method)) {
4196
+ response2 = await render_page(
4197
+ event2,
4198
+ event_state,
4199
+ route.page,
4200
+ options2,
4201
+ manifest,
4202
+ state,
4203
+ page_nodes,
4204
+ resolve_opts
4205
+ );
4206
+ } else {
4207
+ const allowed_methods = new Set(allowed_page_methods);
4208
+ const node = await manifest._.nodes[route.page.leaf]();
4209
+ if (node?.server?.actions) {
4210
+ allowed_methods.add("POST");
4211
+ }
4212
+ if (method === "OPTIONS") {
4213
+ response2 = new Response(null, {
4214
+ status: 204,
4215
+ headers: {
4216
+ allow: Array.from(allowed_methods.values()).join(", ")
4217
+ }
4218
+ });
4219
+ } else {
4220
+ const mod = [...allowed_methods].reduce(
4221
+ (acc, curr) => {
4222
+ acc[curr] = true;
4223
+ return acc;
4224
+ },
4225
+ /** @type {Record<string, any>} */
4226
+ {}
4227
+ );
4228
+ response2 = method_not_allowed(mod, method);
4229
+ }
4230
+ }
4231
+ } else {
4232
+ throw new Error("Route is neither page nor endpoint. This should never happen");
4233
+ }
4234
+ if (request.method === "GET" && route.page && route.endpoint) {
4235
+ const vary = response2.headers.get("vary")?.split(",")?.map((v) => v.trim().toLowerCase());
4236
+ if (!(vary?.includes("accept") || vary?.includes("*"))) {
4237
+ response2 = new Response(response2.body, {
4238
+ status: response2.status,
4239
+ statusText: response2.statusText,
4240
+ headers: new Headers(response2.headers)
4241
+ });
4242
+ response2.headers.append("Vary", "Accept");
4243
+ }
4244
+ }
4245
+ return response2;
4246
+ }
4247
+ if (state.error && event2.isSubRequest) {
4248
+ const headers22 = new Headers(request.headers);
4249
+ headers22.set("x-sveltekit-error", "true");
4250
+ return await fetch(request, { headers: headers22 });
4251
+ }
4252
+ if (state.error) {
4253
+ return text("Internal Server Error", {
4254
+ status: 500
4255
+ });
4256
+ }
4257
+ if (state.depth === 0) {
4258
+ if (DEV && event2.url.pathname === "/.well-known/appspecific/com.chrome.devtools.json") ;
4259
+ return await respond_with_error({
4260
+ event: event2,
4261
+ event_state,
4262
+ options: options2,
4263
+ manifest,
4264
+ state,
4265
+ status: 404,
4266
+ error: new SvelteKitError(404, "Not Found", `Not found: ${event2.url.pathname}`),
4267
+ resolve_opts
4268
+ });
4269
+ }
4270
+ if (state.prerendering) {
4271
+ return text("not found", { status: 404 });
4272
+ }
4273
+ const response = await fetch(request);
4274
+ return new Response(response.body, response);
4275
+ } catch (e) {
4276
+ return await handle_fatal_error(event2, event_state, options2, e);
4277
+ } finally {
4278
+ event2.cookies.set = () => {
4279
+ throw new Error("Cannot use `cookies.set(...)` after the response has been generated");
4280
+ };
4281
+ event2.setHeaders = () => {
4282
+ throw new Error("Cannot use `setHeaders(...)` after the response has been generated");
4283
+ };
4284
+ }
4285
+ }
4286
+ }
4287
+ function load_page_nodes(page, manifest) {
4288
+ return Promise.all([
4289
+ // we use == here rather than === because [undefined] serializes as "[null]"
4290
+ ...page.layouts.map((n) => n == void 0 ? n : manifest._.nodes[n]()),
4291
+ manifest._.nodes[page.leaf]()
4292
+ ]);
4293
+ }
4294
+ function propagate_context(fn) {
4295
+ return async (req, ...rest) => {
4296
+ {
4297
+ return fn(req, ...rest);
4298
+ }
4299
+ };
4300
+ }
4301
+ function filter_env(env, allowed, disallowed) {
4302
+ return Object.fromEntries(
4303
+ Object.entries(env).filter(
4304
+ ([k]) => k.startsWith(allowed) && (disallowed === "" || !k.startsWith(disallowed))
4305
+ )
4306
+ );
4307
+ }
4308
+ function set_app(value) {
4309
+ }
4310
+ let init_promise;
4311
+ let current = null;
4312
+ class Server {
4313
+ /** @type {import('types').SSROptions} */
4314
+ #options;
4315
+ /** @type {import('@sveltejs/kit').SSRManifest} */
4316
+ #manifest;
4317
+ /** @param {import('@sveltejs/kit').SSRManifest} manifest */
4318
+ constructor(manifest) {
4319
+ this.#options = options;
4320
+ this.#manifest = manifest;
4321
+ if (IN_WEBCONTAINER) {
4322
+ const respond2 = this.respond.bind(this);
4323
+ this.respond = async (...args) => {
4324
+ const { promise, resolve: resolve2 } = (
4325
+ /** @type {PromiseWithResolvers<void>} */
4326
+ with_resolvers()
4327
+ );
4328
+ const previous = current;
4329
+ current = promise;
4330
+ await previous;
4331
+ return respond2(...args).finally(resolve2);
4332
+ };
4333
+ }
4334
+ }
4335
+ /**
4336
+ * @param {import('@sveltejs/kit').ServerInitOptions} opts
4337
+ */
4338
+ async init({ env, read }) {
4339
+ const { env_public_prefix, env_private_prefix } = this.#options;
4340
+ set_private_env(filter_env(env, env_private_prefix, env_public_prefix));
4341
+ set_public_env(filter_env(env, env_public_prefix, env_private_prefix));
4342
+ if (read) {
4343
+ const wrapped_read = (file) => {
4344
+ const result = read(file);
4345
+ if (result instanceof ReadableStream) {
4346
+ return result;
4347
+ } else {
4348
+ return new ReadableStream({
4349
+ async start(controller) {
4350
+ try {
4351
+ const stream = await Promise.resolve(result);
4352
+ if (!stream) {
4353
+ controller.close();
4354
+ return;
4355
+ }
4356
+ const reader = stream.getReader();
4357
+ while (true) {
4358
+ const { done, value } = await reader.read();
4359
+ if (done) break;
4360
+ controller.enqueue(value);
4361
+ }
4362
+ controller.close();
4363
+ } catch (error2) {
4364
+ controller.error(error2);
4365
+ }
4366
+ }
4367
+ });
4368
+ }
4369
+ };
4370
+ set_read_implementation(wrapped_read);
4371
+ }
4372
+ await (init_promise ??= (async () => {
4373
+ try {
4374
+ const module = await get_hooks();
4375
+ this.#options.hooks = {
4376
+ handle: module.handle || (({ event, resolve: resolve2 }) => resolve2(event)),
4377
+ handleError: module.handleError || (({ status, error: error2, event }) => {
4378
+ const error_message = format_server_error(
4379
+ status,
4380
+ /** @type {Error} */
4381
+ error2,
4382
+ event
4383
+ );
4384
+ console.error(error_message);
4385
+ }),
4386
+ handleFetch: module.handleFetch || (({ request, fetch: fetch2 }) => fetch2(request)),
4387
+ handleValidationError: module.handleValidationError || (({ issues }) => {
4388
+ console.error("Remote function schema validation failed:", issues);
4389
+ return { message: "Bad Request" };
4390
+ }),
4391
+ reroute: module.reroute || (() => {
4392
+ }),
4393
+ transport: module.transport || {}
4394
+ };
4395
+ set_app({
4396
+ decoders: module.transport ? Object.fromEntries(Object.entries(module.transport).map(([k, v]) => [k, v.decode])) : {}
4397
+ });
4398
+ if (module.init) {
4399
+ await module.init();
4400
+ }
4401
+ } catch (e) {
4402
+ {
4403
+ throw e;
4404
+ }
4405
+ }
4406
+ })());
4407
+ }
4408
+ /**
4409
+ * @param {Request} request
4410
+ * @param {import('types').RequestOptions} options
4411
+ */
4412
+ async respond(request, options2) {
4413
+ return respond(request, this.#options, this.#manifest, {
4414
+ ...options2,
4415
+ error: false,
4416
+ depth: 0
4417
+ });
4418
+ }
4419
+ }
4420
+
4421
+ export { Server };
4422
+ //# sourceMappingURL=index.js.map