@bloxbean/yaci-viewer 0.10.0-preview4

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