fundus 0.0.2 → 0.0.3

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 (300) hide show
  1. package/README.md +58 -0
  2. package/build/client/_app/immutable/assets/0.DLhIsYA_.css.br +0 -0
  3. package/build/client/_app/immutable/assets/0.DLhIsYA_.css.gz +0 -0
  4. package/build/client/_app/immutable/assets/2.wavcNhPC.css +1 -0
  5. package/build/client/_app/immutable/assets/2.wavcNhPC.css.br +0 -0
  6. package/build/client/_app/immutable/assets/2.wavcNhPC.css.gz +0 -0
  7. package/build/client/_app/immutable/assets/3.Cjh_fXPY.css +1 -0
  8. package/build/client/_app/immutable/assets/3.Cjh_fXPY.css.br +0 -0
  9. package/build/client/_app/immutable/assets/3.Cjh_fXPY.css.gz +0 -0
  10. package/build/client/_app/immutable/assets/4.p004hmEN.css +1 -0
  11. package/build/client/_app/immutable/assets/4.p004hmEN.css.br +0 -0
  12. package/build/client/_app/immutable/assets/4.p004hmEN.css.gz +0 -0
  13. package/build/client/_app/immutable/assets/ConfirmDialog.BdKlitwi.css +1 -0
  14. package/build/client/_app/immutable/assets/ConfirmDialog.BdKlitwi.css.br +0 -0
  15. package/build/client/_app/immutable/assets/ConfirmDialog.BdKlitwi.css.gz +0 -0
  16. package/build/client/_app/immutable/assets/LibraryContextMenu.zyZtpKzC.css +1 -0
  17. package/build/client/_app/immutable/assets/LibraryContextMenu.zyZtpKzC.css.br +0 -0
  18. package/build/client/_app/immutable/assets/LibraryContextMenu.zyZtpKzC.css.gz +0 -0
  19. package/build/client/_app/immutable/chunks/BiIto6ft.js +1 -0
  20. package/build/client/_app/immutable/chunks/BiIto6ft.js.br +0 -0
  21. package/build/client/_app/immutable/chunks/BiIto6ft.js.gz +0 -0
  22. package/build/client/_app/immutable/chunks/Bjy-W4x2.js.br +0 -0
  23. package/build/client/_app/immutable/chunks/Bjy-W4x2.js.gz +0 -0
  24. package/build/client/_app/immutable/chunks/CNRz3sSw.js.br +0 -0
  25. package/build/client/_app/immutable/chunks/CNRz3sSw.js.gz +0 -0
  26. package/build/client/_app/immutable/chunks/CO4RBJfa.js.br +0 -0
  27. package/build/client/_app/immutable/chunks/CO4RBJfa.js.gz +0 -0
  28. package/{dist/editor/_app/immutable/chunks/DjvOiDmq.js → build/client/_app/immutable/chunks/CvY6YsFE.js} +1 -1
  29. package/build/client/_app/immutable/chunks/CvY6YsFE.js.br +0 -0
  30. package/build/client/_app/immutable/chunks/CvY6YsFE.js.gz +0 -0
  31. package/build/client/_app/immutable/chunks/DL0_39Ys.js +5 -0
  32. package/build/client/_app/immutable/chunks/DL0_39Ys.js.br +0 -0
  33. package/build/client/_app/immutable/chunks/DL0_39Ys.js.gz +0 -0
  34. package/{dist/editor/_app/immutable/chunks/BfPE5wdt.js → build/client/_app/immutable/chunks/DQ8SXFaX.js} +1 -1
  35. package/build/client/_app/immutable/chunks/DQ8SXFaX.js.br +0 -0
  36. package/build/client/_app/immutable/chunks/DQ8SXFaX.js.gz +0 -0
  37. package/build/client/_app/immutable/chunks/DjdrdRzT.js.br +0 -0
  38. package/build/client/_app/immutable/chunks/DjdrdRzT.js.gz +0 -0
  39. package/build/client/_app/immutable/chunks/xihTtKlq.js.br +1 -0
  40. package/build/client/_app/immutable/chunks/xihTtKlq.js.gz +0 -0
  41. package/{dist/editor/_app/immutable/entry/app.BkqbfI8n.js → build/client/_app/immutable/entry/app.ubN0v9bN.js} +2 -2
  42. package/build/client/_app/immutable/entry/app.ubN0v9bN.js.br +0 -0
  43. package/build/client/_app/immutable/entry/app.ubN0v9bN.js.gz +0 -0
  44. package/build/client/_app/immutable/entry/start.BW8dBDh6.js +1 -0
  45. package/build/client/_app/immutable/entry/start.BW8dBDh6.js.br +0 -0
  46. package/build/client/_app/immutable/entry/start.BW8dBDh6.js.gz +0 -0
  47. package/{dist/editor/_app/immutable/nodes/0.xdMI5GEU.js → build/client/_app/immutable/nodes/0.Dr5ijCIl.js} +1 -1
  48. package/build/client/_app/immutable/nodes/0.Dr5ijCIl.js.br +0 -0
  49. package/build/client/_app/immutable/nodes/0.Dr5ijCIl.js.gz +0 -0
  50. package/{dist/editor/_app/immutable/nodes/1.D9p2tfoJ.js → build/client/_app/immutable/nodes/1.DiIGIRAb.js} +1 -1
  51. package/build/client/_app/immutable/nodes/1.DiIGIRAb.js.br +3 -0
  52. package/build/client/_app/immutable/nodes/1.DiIGIRAb.js.gz +0 -0
  53. package/{dist/editor/_app/immutable/nodes/2.BrA0Hyzu.js → build/client/_app/immutable/nodes/2.B8KYmQcV.js} +3 -3
  54. package/build/client/_app/immutable/nodes/2.B8KYmQcV.js.br +0 -0
  55. package/build/client/_app/immutable/nodes/2.B8KYmQcV.js.gz +0 -0
  56. package/build/client/_app/immutable/nodes/3.B1jc7arT.js +104 -0
  57. package/build/client/_app/immutable/nodes/3.B1jc7arT.js.br +0 -0
  58. package/build/client/_app/immutable/nodes/3.B1jc7arT.js.gz +0 -0
  59. package/build/client/_app/immutable/nodes/4.BPK9n1mH.js +2 -0
  60. package/build/client/_app/immutable/nodes/4.BPK9n1mH.js.br +0 -0
  61. package/build/client/_app/immutable/nodes/4.BPK9n1mH.js.gz +0 -0
  62. package/build/client/_app/version.json +1 -0
  63. package/build/client/_app/version.json.br +0 -0
  64. package/build/client/_app/version.json.gz +0 -0
  65. package/build/env.js +100 -0
  66. package/build/env.js.map +1 -0
  67. package/build/handler.js +22 -0
  68. package/build/handler.js.map +1 -0
  69. package/build/index.js +145 -0
  70. package/build/index.js.map +1 -0
  71. package/build/server/chunks/chunks/context.js-Bw4WWLhG.js +443 -0
  72. package/build/server/chunks/chunks/context.js-Bw4WWLhG.js.map +1 -0
  73. package/build/server/chunks/chunks/core.js-DDntpb72.js +409 -0
  74. package/build/server/chunks/chunks/core.js-DDntpb72.js.map +1 -0
  75. package/build/server/chunks/chunks/env.js-l0sNRNKZ.js +2 -0
  76. package/build/server/chunks/chunks/env.js-l0sNRNKZ.js.map +1 -0
  77. package/build/server/chunks/chunks/exports.js-CLTzaOxn.js +152 -0
  78. package/build/server/chunks/chunks/exports.js-CLTzaOxn.js.map +1 -0
  79. package/build/server/chunks/chunks/folder-path.js-ytx9ucgg.js +64 -0
  80. package/build/server/chunks/chunks/folder-path.js-ytx9ucgg.js.map +1 -0
  81. package/build/server/chunks/chunks/http.js-Dxoa-jtP.js +100 -0
  82. package/build/server/chunks/chunks/http.js-Dxoa-jtP.js.map +1 -0
  83. package/build/server/chunks/chunks/internal.js-BDBSzJId.js +5753 -0
  84. package/build/server/chunks/chunks/internal.js-BDBSzJId.js.map +1 -0
  85. package/build/server/chunks/chunks/internal2.js-BlXt2rfE.js +22 -0
  86. package/build/server/chunks/chunks/internal2.js-BlXt2rfE.js.map +1 -0
  87. package/{dist/operations-DYM-5KVl.js → build/server/chunks/chunks/library-store.js-BP8cL-qD.js} +344 -444
  88. package/build/server/chunks/chunks/library-store.js-BP8cL-qD.js.map +1 -0
  89. package/build/server/chunks/chunks/manifest-appearance.js-DTk355LQ.js +146 -0
  90. package/build/server/chunks/chunks/manifest-appearance.js-DTk355LQ.js.map +1 -0
  91. package/build/server/chunks/chunks/routing.js-y-tryuip.js +213 -0
  92. package/build/server/chunks/chunks/routing.js-y-tryuip.js.map +1 -0
  93. package/build/server/chunks/chunks/shared.js-BWXgl1Xf.js +255 -0
  94. package/build/server/chunks/chunks/shared.js-BWXgl1Xf.js.map +1 -0
  95. package/build/server/chunks/chunks/utils.js-9oI5Oz0w.js +1048 -0
  96. package/build/server/chunks/chunks/utils.js-9oI5Oz0w.js.map +1 -0
  97. package/build/server/chunks/entries/endpoints/api/_...path_/_server.ts.js-WknZVW_S.js +27 -0
  98. package/build/server/chunks/entries/endpoints/api/_...path_/_server.ts.js-WknZVW_S.js.map +1 -0
  99. package/build/server/chunks/entries/endpoints/api/assets/_id_/_server.ts.js-BrZ__-HZ.js +24 -0
  100. package/build/server/chunks/entries/endpoints/api/assets/_id_/_server.ts.js-BrZ__-HZ.js.map +1 -0
  101. package/build/server/chunks/entries/endpoints/api/assets/_server.ts.js-PqADGPXc.js +45 -0
  102. package/build/server/chunks/entries/endpoints/api/assets/_server.ts.js-PqADGPXc.js.map +1 -0
  103. package/build/server/chunks/entries/endpoints/api/assets/delete/_server.ts.js-OqoE5PN-.js +31 -0
  104. package/build/server/chunks/entries/endpoints/api/assets/delete/_server.ts.js-OqoE5PN-.js.map +1 -0
  105. package/build/server/chunks/entries/endpoints/api/assets/move/_server.ts.js-CJ08e1ho.js +31 -0
  106. package/build/server/chunks/entries/endpoints/api/assets/move/_server.ts.js-CJ08e1ho.js.map +1 -0
  107. package/build/server/chunks/entries/endpoints/api/folders/_path_/_server.ts.js-DdF3eK2I.js +38 -0
  108. package/build/server/chunks/entries/endpoints/api/folders/_path_/_server.ts.js-DdF3eK2I.js.map +1 -0
  109. package/build/server/chunks/entries/endpoints/api/folders/_server.ts.js-Cxt6jsJ5.js +31 -0
  110. package/build/server/chunks/entries/endpoints/api/folders/_server.ts.js-Cxt6jsJ5.js.map +1 -0
  111. package/build/server/chunks/entries/endpoints/api/manifests/_name_/_server.ts.js-BWVM2Ntl.js +24 -0
  112. package/build/server/chunks/entries/endpoints/api/manifests/_name_/_server.ts.js-BWVM2Ntl.js.map +1 -0
  113. package/build/server/chunks/entries/endpoints/api/manifests/_server.ts.js-Z2bM-qHM.js +31 -0
  114. package/build/server/chunks/entries/endpoints/api/manifests/_server.ts.js-Z2bM-qHM.js.map +1 -0
  115. package/build/server/chunks/entries/endpoints/api/state/_server.ts.js-BX9H2Z34.js +24 -0
  116. package/build/server/chunks/entries/endpoints/api/state/_server.ts.js-BX9H2Z34.js.map +1 -0
  117. package/build/server/chunks/entries/endpoints/files/_...path_/_server.ts.js-BWHDZ8mz.js +27 -0
  118. package/build/server/chunks/entries/endpoints/files/_...path_/_server.ts.js-BWHDZ8mz.js.map +1 -0
  119. package/build/server/chunks/entries/endpoints/files/proxy/_...path_/_server.ts.js-CR_7mndO.js +24 -0
  120. package/build/server/chunks/entries/endpoints/files/proxy/_...path_/_server.ts.js-CR_7mndO.js.map +1 -0
  121. package/build/server/chunks/entries/endpoints/files/raw/_...path_/_server.ts.js-Cw1PDBvb.js +24 -0
  122. package/build/server/chunks/entries/endpoints/files/raw/_...path_/_server.ts.js-Cw1PDBvb.js.map +1 -0
  123. package/build/server/chunks/entries/hooks.server.js-BHoE0yBi.js +23 -0
  124. package/build/server/chunks/entries/hooks.server.js-BHoE0yBi.js.map +1 -0
  125. package/build/server/chunks/handler-10cx4zHn.js +1475 -0
  126. package/build/server/chunks/handler-10cx4zHn.js.map +1 -0
  127. package/build/server/chunks/index.js-DvPfiC00.js +3789 -0
  128. package/build/server/chunks/index.js-DvPfiC00.js.map +1 -0
  129. package/build/server/chunks/manifest.js-DoPjUnzD.js +149 -0
  130. package/build/server/chunks/manifest.js-DoPjUnzD.js.map +1 -0
  131. package/build/server/chunks/nodes/0.js-Di3qgAtW.js +11 -0
  132. package/build/server/chunks/nodes/0.js-Di3qgAtW.js.map +1 -0
  133. package/build/server/chunks/nodes/1.js-BlWSFIA8.js +7 -0
  134. package/build/server/chunks/nodes/1.js-BlWSFIA8.js.map +1 -0
  135. package/build/server/chunks/nodes/2.js-CO9nSPUN.js +7 -0
  136. package/build/server/chunks/nodes/2.js-CO9nSPUN.js.map +1 -0
  137. package/build/server/chunks/nodes/3.js-C2D6xpEO.js +7 -0
  138. package/build/server/chunks/nodes/3.js-C2D6xpEO.js.map +1 -0
  139. package/build/server/chunks/nodes/4.js-B3IuagJW.js +7 -0
  140. package/build/server/chunks/nodes/4.js-B3IuagJW.js.map +1 -0
  141. package/build/shims.js +33 -0
  142. package/build/shims.js.map +1 -0
  143. package/dist/cli.d.ts +2 -1
  144. package/dist/cli.js +109 -1332
  145. package/dist/config.d.ts +3 -2
  146. package/dist/config.js +2 -2
  147. package/dist/core/api-types.d.ts +141 -0
  148. package/dist/core/api-types.js +1 -0
  149. package/dist/core/asset-id.d.ts +28 -0
  150. package/dist/core/asset-id.js +59 -0
  151. package/dist/core/asset-reference.d.ts +23 -0
  152. package/dist/core/asset-reference.js +15 -0
  153. package/dist/core/canonicalize.d.ts +9 -0
  154. package/dist/core/canonicalize.js +36 -0
  155. package/dist/core/chroma-key.d.ts +30 -0
  156. package/dist/core/chroma-key.js +55 -0
  157. package/dist/core/config.d.ts +35 -0
  158. package/dist/core/config.js +4 -0
  159. package/dist/core/folder-path.d.ts +19 -0
  160. package/dist/core/folder-path.js +86 -0
  161. package/dist/core/index.d.ts +33 -499
  162. package/dist/core/index.js +17 -962
  163. package/dist/core/ingest.d.ts +18 -0
  164. package/dist/core/ingest.js +58 -0
  165. package/dist/core/library.d.ts +54 -0
  166. package/dist/core/library.js +138 -0
  167. package/dist/core/manifest-appearance.d.ts +35 -0
  168. package/dist/core/manifest-appearance.js +123 -0
  169. package/dist/core/manifest-entry.d.ts +104 -0
  170. package/dist/core/manifest-entry.js +1 -0
  171. package/dist/core/manifest-membership.d.ts +56 -0
  172. package/dist/core/manifest-membership.js +54 -0
  173. package/dist/core/plugins/audio.d.ts +26 -0
  174. package/dist/core/plugins/audio.js +44 -0
  175. package/dist/core/plugins/chroma-key-video.d.ts +29 -0
  176. package/dist/core/plugins/chroma-key-video.js +69 -0
  177. package/dist/core/plugins/contract.d.ts +35 -0
  178. package/dist/core/plugins/contract.js +1 -0
  179. package/dist/core/plugins/image.d.ts +30 -0
  180. package/dist/core/plugins/image.js +45 -0
  181. package/dist/core/plugins/slice.d.ts +22 -0
  182. package/dist/core/plugins/slice.js +60 -0
  183. package/dist/core/plugins/video.d.ts +45 -0
  184. package/dist/core/plugins/video.js +77 -0
  185. package/dist/core/reference-graph.d.ts +41 -0
  186. package/dist/core/reference-graph.js +138 -0
  187. package/dist/core/slice-data.d.ts +61 -0
  188. package/dist/core/slice-data.js +49 -0
  189. package/dist/runtime/chroma-key-gl.d.ts +40 -22
  190. package/dist/runtime/chroma-key-gl.js +189 -183
  191. package/dist/runtime/components/ChromaKeyVideo.svelte +3 -3
  192. package/dist/runtime/components/ChromaKeyVideo.svelte.d.ts +21 -0
  193. package/dist/runtime/components/Image.svelte +1 -1
  194. package/dist/runtime/components/Image.svelte.d.ts +9 -0
  195. package/dist/runtime/components/Slice.svelte +1 -1
  196. package/dist/runtime/components/Slice.svelte.d.ts +19 -0
  197. package/dist/runtime/components/SliceCanvas.svelte +3 -3
  198. package/dist/runtime/components/SliceCanvas.svelte.d.ts +10 -0
  199. package/dist/runtime/components/SliceDom.svelte +3 -3
  200. package/dist/runtime/components/SliceDom.svelte.d.ts +10 -0
  201. package/dist/runtime/components/Video.svelte +2 -2
  202. package/dist/runtime/components/Video.svelte.d.ts +18 -0
  203. package/dist/runtime/geometry.d.ts +55 -35
  204. package/dist/runtime/geometry.js +186 -191
  205. package/dist/runtime/index.d.ts +9 -9
  206. package/dist/runtime/index.js +9 -9
  207. package/dist/runtime/kind-handlers.d.ts +33 -24
  208. package/dist/runtime/kind-handlers.js +74 -65
  209. package/dist/runtime/manifest.d.ts +53 -47
  210. package/dist/runtime/manifest.js +133 -113
  211. package/dist/runtime/observe-border-box-size.d.ts +1 -4
  212. package/dist/runtime/observe-border-box-size.js +9 -10
  213. package/dist/runtime/preload-registry.d.ts +22 -8
  214. package/dist/runtime/preload-registry.js +65 -62
  215. package/dist/server/build.d.ts +8 -0
  216. package/dist/server/build.js +25 -0
  217. package/dist/server/check.d.ts +24 -0
  218. package/dist/server/check.js +199 -0
  219. package/dist/server/cli-commands.d.ts +25 -0
  220. package/dist/server/cli-commands.js +1178 -0
  221. package/dist/server/cli-init.d.ts +3 -0
  222. package/dist/server/cli-init.js +53 -0
  223. package/dist/server/cli-io.d.ts +46 -0
  224. package/dist/server/cli-io.js +105 -0
  225. package/dist/server/codegen.d.ts +58 -0
  226. package/dist/server/codegen.js +185 -0
  227. package/dist/server/config-loader.d.ts +34 -0
  228. package/dist/server/config-loader.js +103 -0
  229. package/dist/server/context.d.ts +8 -0
  230. package/dist/server/context.js +19 -0
  231. package/dist/server/folder-filesystem.d.ts +7 -0
  232. package/dist/server/folder-filesystem.js +39 -0
  233. package/dist/server/http.d.ts +12 -0
  234. package/dist/server/http.js +100 -0
  235. package/dist/server/index.d.ts +16 -0
  236. package/dist/server/index.js +9 -0
  237. package/dist/server/job-hash.d.ts +10 -0
  238. package/dist/server/job-hash.js +23 -0
  239. package/dist/server/library-store.d.ts +82 -0
  240. package/dist/server/library-store.js +763 -0
  241. package/dist/server/operations.d.ts +87 -0
  242. package/dist/server/operations.js +427 -0
  243. package/dist/server/plugins/audio.d.ts +7 -0
  244. package/dist/server/plugins/audio.js +27 -0
  245. package/dist/server/plugins/chroma-key-video.d.ts +9 -0
  246. package/dist/server/plugins/chroma-key-video.js +38 -0
  247. package/dist/server/plugins/contract.d.ts +100 -0
  248. package/dist/server/plugins/contract.js +16 -0
  249. package/dist/server/plugins/image.d.ts +8 -0
  250. package/dist/server/plugins/image.js +30 -0
  251. package/dist/server/plugins/slice.d.ts +14 -0
  252. package/dist/server/plugins/slice.js +63 -0
  253. package/dist/server/plugins/video.d.ts +6 -0
  254. package/dist/server/plugins/video.js +29 -0
  255. package/dist/server/plugins.d.ts +23 -0
  256. package/dist/server/plugins.js +33 -0
  257. package/dist/server/processing/audio-processing.d.ts +17 -0
  258. package/dist/server/processing/audio-processing.js +46 -0
  259. package/dist/server/processing/ffmpeg.d.ts +9 -0
  260. package/dist/server/processing/ffmpeg.js +50 -0
  261. package/dist/server/processing/image-processing.d.ts +16 -0
  262. package/dist/server/processing/image-processing.js +26 -0
  263. package/dist/server/processing/media-probe.d.ts +15 -0
  264. package/dist/server/processing/media-probe.js +27 -0
  265. package/dist/server/processing/processor.d.ts +50 -0
  266. package/dist/server/processing/processor.js +158 -0
  267. package/dist/server/processing/video-processing.d.ts +35 -0
  268. package/dist/server/processing/video-processing.js +87 -0
  269. package/dist/server/server.d.ts +13 -0
  270. package/dist/server/server.js +57 -0
  271. package/dist/server/start.d.ts +1 -0
  272. package/dist/server/start.js +33 -0
  273. package/package.json +29 -16
  274. package/dist/build-CZYFLLvl.js +0 -191
  275. package/dist/core/image-Dqmz8FXS.js +0 -54
  276. package/dist/core/reference-graph-CjuHbLDw.d.ts +0 -280
  277. package/dist/core/testing.d.ts +0 -27
  278. package/dist/core/testing.js +0 -80
  279. package/dist/editor/200.html +0 -37
  280. package/dist/editor/_app/immutable/assets/2.DIbbW7U1.css +0 -1
  281. package/dist/editor/_app/immutable/assets/3.C-9vFQ9A.css +0 -1
  282. package/dist/editor/_app/immutable/assets/4.BS8ElpOV.css +0 -1
  283. package/dist/editor/_app/immutable/assets/ConfirmDialog.CHEISE-L.css +0 -1
  284. package/dist/editor/_app/immutable/assets/LibraryContextMenu.CDjCmdV-.css +0 -1
  285. package/dist/editor/_app/immutable/chunks/Cx6qtxJg.js +0 -1
  286. package/dist/editor/_app/immutable/chunks/n7mvYc42.js +0 -5
  287. package/dist/editor/_app/immutable/entry/start.C8HHOLly.js +0 -1
  288. package/dist/editor/_app/immutable/nodes/3.WO7tZH_d.js +0 -104
  289. package/dist/editor/_app/immutable/nodes/4.DQtx17aW.js +0 -2
  290. package/dist/editor/_app/version.json +0 -1
  291. package/dist/index.d.ts +0 -370
  292. package/dist/index.js +0 -4
  293. package/dist/start-Bhnqt9Dc.js +0 -279
  294. package/dist/start-D2IXOrni.js +0 -2
  295. /package/{dist/editor → build/client}/_app/immutable/assets/0.DLhIsYA_.css +0 -0
  296. /package/{dist/editor → build/client}/_app/immutable/chunks/Bjy-W4x2.js +0 -0
  297. /package/{dist/editor → build/client}/_app/immutable/chunks/CNRz3sSw.js +0 -0
  298. /package/{dist/editor → build/client}/_app/immutable/chunks/CO4RBJfa.js +0 -0
  299. /package/{dist/editor → build/client}/_app/immutable/chunks/DjdrdRzT.js +0 -0
  300. /package/{dist/editor → build/client}/_app/immutable/chunks/xihTtKlq.js +0 -0
@@ -0,0 +1,1475 @@
1
+ import '../../shims.js';
2
+ import * as fs from 'node:fs';
3
+ import fs__default, { readdirSync, statSync, createReadStream } from 'node:fs';
4
+ import path, { resolve, sep, join, normalize } from 'node:path';
5
+ import process from 'node:process';
6
+ import http from 'node:http';
7
+ import { setImmediate } from 'node:timers';
8
+ import * as qs from 'node:querystring';
9
+ import { Readable } from 'node:stream';
10
+ import { S as SvelteKitError } from './chunks/shared.js-BWXgl1Xf.js';
11
+ import { y as splitCookiesString } from './chunks/utils.js-9oI5Oz0w.js';
12
+ import { S as Server } from './index.js-DvPfiC00.js';
13
+ import { m as manifest } from './manifest.js-DoPjUnzD.js';
14
+ import { env, dir, env_prefix } from '../../env.js';
15
+ import { format } from 'node:url';
16
+
17
+ function totalist(dir, callback, pre='') {
18
+ dir = resolve('.', dir);
19
+ let arr = readdirSync(dir);
20
+ let i=0, abs, stats;
21
+ for (; i < arr.length; i++) {
22
+ abs = join(dir, arr[i]);
23
+ stats = statSync(abs);
24
+ stats.isDirectory()
25
+ ? totalist(abs, callback, join(pre, arr[i]))
26
+ : callback(join(pre, arr[i]), abs, stats);
27
+ }
28
+ }
29
+
30
+ /**
31
+ * @typedef ParsedURL
32
+ * @type {import('.').ParsedURL}
33
+ */
34
+
35
+ /**
36
+ * @typedef Request
37
+ * @property {string} url
38
+ * @property {ParsedURL} _parsedUrl
39
+ */
40
+
41
+ /**
42
+ * @param {Request} req
43
+ * @returns {ParsedURL|void}
44
+ */
45
+ function parse$1(req) {
46
+ let raw = req.url;
47
+ if (raw == null) return;
48
+
49
+ let prev = req._parsedUrl;
50
+ if (prev && prev.raw === raw) return prev;
51
+
52
+ let pathname=raw, search='', query;
53
+
54
+ if (raw.length > 1) {
55
+ let idx = raw.indexOf('?', 1);
56
+
57
+ if (idx !== -1) {
58
+ search = raw.substring(idx);
59
+ pathname = raw.substring(0, idx);
60
+ if (search.length > 1) {
61
+ query = qs.parse(search.substring(1));
62
+ }
63
+ }
64
+ }
65
+
66
+ return req._parsedUrl = { pathname, search, query, raw };
67
+ }
68
+
69
+ const mimes = {
70
+ "3g2": "video/3gpp2",
71
+ "3gp": "video/3gpp",
72
+ "3gpp": "video/3gpp",
73
+ "3mf": "model/3mf",
74
+ "aac": "audio/aac",
75
+ "ac": "application/pkix-attr-cert",
76
+ "adp": "audio/adpcm",
77
+ "adts": "audio/aac",
78
+ "ai": "application/postscript",
79
+ "aml": "application/automationml-aml+xml",
80
+ "amlx": "application/automationml-amlx+zip",
81
+ "amr": "audio/amr",
82
+ "apng": "image/apng",
83
+ "appcache": "text/cache-manifest",
84
+ "appinstaller": "application/appinstaller",
85
+ "appx": "application/appx",
86
+ "appxbundle": "application/appxbundle",
87
+ "asc": "application/pgp-keys",
88
+ "atom": "application/atom+xml",
89
+ "atomcat": "application/atomcat+xml",
90
+ "atomdeleted": "application/atomdeleted+xml",
91
+ "atomsvc": "application/atomsvc+xml",
92
+ "au": "audio/basic",
93
+ "avci": "image/avci",
94
+ "avcs": "image/avcs",
95
+ "avif": "image/avif",
96
+ "aw": "application/applixware",
97
+ "bdoc": "application/bdoc",
98
+ "bin": "application/octet-stream",
99
+ "bmp": "image/bmp",
100
+ "bpk": "application/octet-stream",
101
+ "btf": "image/prs.btif",
102
+ "btif": "image/prs.btif",
103
+ "buffer": "application/octet-stream",
104
+ "ccxml": "application/ccxml+xml",
105
+ "cdfx": "application/cdfx+xml",
106
+ "cdmia": "application/cdmi-capability",
107
+ "cdmic": "application/cdmi-container",
108
+ "cdmid": "application/cdmi-domain",
109
+ "cdmio": "application/cdmi-object",
110
+ "cdmiq": "application/cdmi-queue",
111
+ "cer": "application/pkix-cert",
112
+ "cgm": "image/cgm",
113
+ "cjs": "application/node",
114
+ "class": "application/java-vm",
115
+ "coffee": "text/coffeescript",
116
+ "conf": "text/plain",
117
+ "cpl": "application/cpl+xml",
118
+ "cpt": "application/mac-compactpro",
119
+ "crl": "application/pkix-crl",
120
+ "css": "text/css",
121
+ "csv": "text/csv",
122
+ "cu": "application/cu-seeme",
123
+ "cwl": "application/cwl",
124
+ "cww": "application/prs.cww",
125
+ "davmount": "application/davmount+xml",
126
+ "dbk": "application/docbook+xml",
127
+ "deb": "application/octet-stream",
128
+ "def": "text/plain",
129
+ "deploy": "application/octet-stream",
130
+ "dib": "image/bmp",
131
+ "disposition-notification": "message/disposition-notification",
132
+ "dist": "application/octet-stream",
133
+ "distz": "application/octet-stream",
134
+ "dll": "application/octet-stream",
135
+ "dmg": "application/octet-stream",
136
+ "dms": "application/octet-stream",
137
+ "doc": "application/msword",
138
+ "dot": "application/msword",
139
+ "dpx": "image/dpx",
140
+ "drle": "image/dicom-rle",
141
+ "dsc": "text/prs.lines.tag",
142
+ "dssc": "application/dssc+der",
143
+ "dtd": "application/xml-dtd",
144
+ "dump": "application/octet-stream",
145
+ "dwd": "application/atsc-dwd+xml",
146
+ "ear": "application/java-archive",
147
+ "ecma": "application/ecmascript",
148
+ "elc": "application/octet-stream",
149
+ "emf": "image/emf",
150
+ "eml": "message/rfc822",
151
+ "emma": "application/emma+xml",
152
+ "emotionml": "application/emotionml+xml",
153
+ "eps": "application/postscript",
154
+ "epub": "application/epub+zip",
155
+ "exe": "application/octet-stream",
156
+ "exi": "application/exi",
157
+ "exp": "application/express",
158
+ "exr": "image/aces",
159
+ "ez": "application/andrew-inset",
160
+ "fdf": "application/fdf",
161
+ "fdt": "application/fdt+xml",
162
+ "fits": "image/fits",
163
+ "g3": "image/g3fax",
164
+ "gbr": "application/rpki-ghostbusters",
165
+ "geojson": "application/geo+json",
166
+ "gif": "image/gif",
167
+ "glb": "model/gltf-binary",
168
+ "gltf": "model/gltf+json",
169
+ "gml": "application/gml+xml",
170
+ "gpx": "application/gpx+xml",
171
+ "gram": "application/srgs",
172
+ "grxml": "application/srgs+xml",
173
+ "gxf": "application/gxf",
174
+ "gz": "application/gzip",
175
+ "h261": "video/h261",
176
+ "h263": "video/h263",
177
+ "h264": "video/h264",
178
+ "heic": "image/heic",
179
+ "heics": "image/heic-sequence",
180
+ "heif": "image/heif",
181
+ "heifs": "image/heif-sequence",
182
+ "hej2": "image/hej2k",
183
+ "held": "application/atsc-held+xml",
184
+ "hjson": "application/hjson",
185
+ "hlp": "application/winhlp",
186
+ "hqx": "application/mac-binhex40",
187
+ "hsj2": "image/hsj2",
188
+ "htm": "text/html",
189
+ "html": "text/html",
190
+ "ics": "text/calendar",
191
+ "ief": "image/ief",
192
+ "ifb": "text/calendar",
193
+ "iges": "model/iges",
194
+ "igs": "model/iges",
195
+ "img": "application/octet-stream",
196
+ "in": "text/plain",
197
+ "ini": "text/plain",
198
+ "ink": "application/inkml+xml",
199
+ "inkml": "application/inkml+xml",
200
+ "ipfix": "application/ipfix",
201
+ "iso": "application/octet-stream",
202
+ "its": "application/its+xml",
203
+ "jade": "text/jade",
204
+ "jar": "application/java-archive",
205
+ "jhc": "image/jphc",
206
+ "jls": "image/jls",
207
+ "jp2": "image/jp2",
208
+ "jpe": "image/jpeg",
209
+ "jpeg": "image/jpeg",
210
+ "jpf": "image/jpx",
211
+ "jpg": "image/jpeg",
212
+ "jpg2": "image/jp2",
213
+ "jpgm": "image/jpm",
214
+ "jpgv": "video/jpeg",
215
+ "jph": "image/jph",
216
+ "jpm": "image/jpm",
217
+ "jpx": "image/jpx",
218
+ "js": "text/javascript",
219
+ "json": "application/json",
220
+ "json5": "application/json5",
221
+ "jsonld": "application/ld+json",
222
+ "jsonml": "application/jsonml+json",
223
+ "jsx": "text/jsx",
224
+ "jt": "model/jt",
225
+ "jxr": "image/jxr",
226
+ "jxra": "image/jxra",
227
+ "jxrs": "image/jxrs",
228
+ "jxs": "image/jxs",
229
+ "jxsc": "image/jxsc",
230
+ "jxsi": "image/jxsi",
231
+ "jxss": "image/jxss",
232
+ "kar": "audio/midi",
233
+ "ktx": "image/ktx",
234
+ "ktx2": "image/ktx2",
235
+ "less": "text/less",
236
+ "lgr": "application/lgr+xml",
237
+ "list": "text/plain",
238
+ "litcoffee": "text/coffeescript",
239
+ "log": "text/plain",
240
+ "lostxml": "application/lost+xml",
241
+ "lrf": "application/octet-stream",
242
+ "m1v": "video/mpeg",
243
+ "m21": "application/mp21",
244
+ "m2a": "audio/mpeg",
245
+ "m2v": "video/mpeg",
246
+ "m3a": "audio/mpeg",
247
+ "m4a": "audio/mp4",
248
+ "m4p": "application/mp4",
249
+ "m4s": "video/iso.segment",
250
+ "ma": "application/mathematica",
251
+ "mads": "application/mads+xml",
252
+ "maei": "application/mmt-aei+xml",
253
+ "man": "text/troff",
254
+ "manifest": "text/cache-manifest",
255
+ "map": "application/json",
256
+ "mar": "application/octet-stream",
257
+ "markdown": "text/markdown",
258
+ "mathml": "application/mathml+xml",
259
+ "mb": "application/mathematica",
260
+ "mbox": "application/mbox",
261
+ "md": "text/markdown",
262
+ "mdx": "text/mdx",
263
+ "me": "text/troff",
264
+ "mesh": "model/mesh",
265
+ "meta4": "application/metalink4+xml",
266
+ "metalink": "application/metalink+xml",
267
+ "mets": "application/mets+xml",
268
+ "mft": "application/rpki-manifest",
269
+ "mid": "audio/midi",
270
+ "midi": "audio/midi",
271
+ "mime": "message/rfc822",
272
+ "mj2": "video/mj2",
273
+ "mjp2": "video/mj2",
274
+ "mjs": "text/javascript",
275
+ "mml": "text/mathml",
276
+ "mods": "application/mods+xml",
277
+ "mov": "video/quicktime",
278
+ "mp2": "audio/mpeg",
279
+ "mp21": "application/mp21",
280
+ "mp2a": "audio/mpeg",
281
+ "mp3": "audio/mpeg",
282
+ "mp4": "video/mp4",
283
+ "mp4a": "audio/mp4",
284
+ "mp4s": "application/mp4",
285
+ "mp4v": "video/mp4",
286
+ "mpd": "application/dash+xml",
287
+ "mpe": "video/mpeg",
288
+ "mpeg": "video/mpeg",
289
+ "mpf": "application/media-policy-dataset+xml",
290
+ "mpg": "video/mpeg",
291
+ "mpg4": "video/mp4",
292
+ "mpga": "audio/mpeg",
293
+ "mpp": "application/dash-patch+xml",
294
+ "mrc": "application/marc",
295
+ "mrcx": "application/marcxml+xml",
296
+ "ms": "text/troff",
297
+ "mscml": "application/mediaservercontrol+xml",
298
+ "msh": "model/mesh",
299
+ "msi": "application/octet-stream",
300
+ "msix": "application/msix",
301
+ "msixbundle": "application/msixbundle",
302
+ "msm": "application/octet-stream",
303
+ "msp": "application/octet-stream",
304
+ "mtl": "model/mtl",
305
+ "musd": "application/mmt-usd+xml",
306
+ "mxf": "application/mxf",
307
+ "mxmf": "audio/mobile-xmf",
308
+ "mxml": "application/xv+xml",
309
+ "n3": "text/n3",
310
+ "nb": "application/mathematica",
311
+ "nq": "application/n-quads",
312
+ "nt": "application/n-triples",
313
+ "obj": "model/obj",
314
+ "oda": "application/oda",
315
+ "oga": "audio/ogg",
316
+ "ogg": "audio/ogg",
317
+ "ogv": "video/ogg",
318
+ "ogx": "application/ogg",
319
+ "omdoc": "application/omdoc+xml",
320
+ "onepkg": "application/onenote",
321
+ "onetmp": "application/onenote",
322
+ "onetoc": "application/onenote",
323
+ "onetoc2": "application/onenote",
324
+ "opf": "application/oebps-package+xml",
325
+ "opus": "audio/ogg",
326
+ "otf": "font/otf",
327
+ "owl": "application/rdf+xml",
328
+ "oxps": "application/oxps",
329
+ "p10": "application/pkcs10",
330
+ "p7c": "application/pkcs7-mime",
331
+ "p7m": "application/pkcs7-mime",
332
+ "p7s": "application/pkcs7-signature",
333
+ "p8": "application/pkcs8",
334
+ "pdf": "application/pdf",
335
+ "pfr": "application/font-tdpfr",
336
+ "pgp": "application/pgp-encrypted",
337
+ "pkg": "application/octet-stream",
338
+ "pki": "application/pkixcmp",
339
+ "pkipath": "application/pkix-pkipath",
340
+ "pls": "application/pls+xml",
341
+ "png": "image/png",
342
+ "prc": "model/prc",
343
+ "prf": "application/pics-rules",
344
+ "provx": "application/provenance+xml",
345
+ "ps": "application/postscript",
346
+ "pskcxml": "application/pskc+xml",
347
+ "pti": "image/prs.pti",
348
+ "qt": "video/quicktime",
349
+ "raml": "application/raml+yaml",
350
+ "rapd": "application/route-apd+xml",
351
+ "rdf": "application/rdf+xml",
352
+ "relo": "application/p2p-overlay+xml",
353
+ "rif": "application/reginfo+xml",
354
+ "rl": "application/resource-lists+xml",
355
+ "rld": "application/resource-lists-diff+xml",
356
+ "rmi": "audio/midi",
357
+ "rnc": "application/relax-ng-compact-syntax",
358
+ "rng": "application/xml",
359
+ "roa": "application/rpki-roa",
360
+ "roff": "text/troff",
361
+ "rq": "application/sparql-query",
362
+ "rs": "application/rls-services+xml",
363
+ "rsat": "application/atsc-rsat+xml",
364
+ "rsd": "application/rsd+xml",
365
+ "rsheet": "application/urc-ressheet+xml",
366
+ "rss": "application/rss+xml",
367
+ "rtf": "text/rtf",
368
+ "rtx": "text/richtext",
369
+ "rusd": "application/route-usd+xml",
370
+ "s3m": "audio/s3m",
371
+ "sbml": "application/sbml+xml",
372
+ "scq": "application/scvp-cv-request",
373
+ "scs": "application/scvp-cv-response",
374
+ "sdp": "application/sdp",
375
+ "senmlx": "application/senml+xml",
376
+ "sensmlx": "application/sensml+xml",
377
+ "ser": "application/java-serialized-object",
378
+ "setpay": "application/set-payment-initiation",
379
+ "setreg": "application/set-registration-initiation",
380
+ "sgi": "image/sgi",
381
+ "sgm": "text/sgml",
382
+ "sgml": "text/sgml",
383
+ "shex": "text/shex",
384
+ "shf": "application/shf+xml",
385
+ "shtml": "text/html",
386
+ "sieve": "application/sieve",
387
+ "sig": "application/pgp-signature",
388
+ "sil": "audio/silk",
389
+ "silo": "model/mesh",
390
+ "siv": "application/sieve",
391
+ "slim": "text/slim",
392
+ "slm": "text/slim",
393
+ "sls": "application/route-s-tsid+xml",
394
+ "smi": "application/smil+xml",
395
+ "smil": "application/smil+xml",
396
+ "snd": "audio/basic",
397
+ "so": "application/octet-stream",
398
+ "spdx": "text/spdx",
399
+ "spp": "application/scvp-vp-response",
400
+ "spq": "application/scvp-vp-request",
401
+ "spx": "audio/ogg",
402
+ "sql": "application/sql",
403
+ "sru": "application/sru+xml",
404
+ "srx": "application/sparql-results+xml",
405
+ "ssdl": "application/ssdl+xml",
406
+ "ssml": "application/ssml+xml",
407
+ "stk": "application/hyperstudio",
408
+ "stl": "model/stl",
409
+ "stpx": "model/step+xml",
410
+ "stpxz": "model/step-xml+zip",
411
+ "stpz": "model/step+zip",
412
+ "styl": "text/stylus",
413
+ "stylus": "text/stylus",
414
+ "svg": "image/svg+xml",
415
+ "svgz": "image/svg+xml",
416
+ "swidtag": "application/swid+xml",
417
+ "t": "text/troff",
418
+ "t38": "image/t38",
419
+ "td": "application/urc-targetdesc+xml",
420
+ "tei": "application/tei+xml",
421
+ "teicorpus": "application/tei+xml",
422
+ "text": "text/plain",
423
+ "tfi": "application/thraud+xml",
424
+ "tfx": "image/tiff-fx",
425
+ "tif": "image/tiff",
426
+ "tiff": "image/tiff",
427
+ "toml": "application/toml",
428
+ "tr": "text/troff",
429
+ "trig": "application/trig",
430
+ "ts": "video/mp2t",
431
+ "tsd": "application/timestamped-data",
432
+ "tsv": "text/tab-separated-values",
433
+ "ttc": "font/collection",
434
+ "ttf": "font/ttf",
435
+ "ttl": "text/turtle",
436
+ "ttml": "application/ttml+xml",
437
+ "txt": "text/plain",
438
+ "u3d": "model/u3d",
439
+ "u8dsn": "message/global-delivery-status",
440
+ "u8hdr": "message/global-headers",
441
+ "u8mdn": "message/global-disposition-notification",
442
+ "u8msg": "message/global",
443
+ "ubj": "application/ubjson",
444
+ "uri": "text/uri-list",
445
+ "uris": "text/uri-list",
446
+ "urls": "text/uri-list",
447
+ "vcard": "text/vcard",
448
+ "vrml": "model/vrml",
449
+ "vtt": "text/vtt",
450
+ "vxml": "application/voicexml+xml",
451
+ "war": "application/java-archive",
452
+ "wasm": "application/wasm",
453
+ "wav": "audio/wav",
454
+ "weba": "audio/webm",
455
+ "webm": "video/webm",
456
+ "webmanifest": "application/manifest+json",
457
+ "webp": "image/webp",
458
+ "wgsl": "text/wgsl",
459
+ "wgt": "application/widget",
460
+ "wif": "application/watcherinfo+xml",
461
+ "wmf": "image/wmf",
462
+ "woff": "font/woff",
463
+ "woff2": "font/woff2",
464
+ "wrl": "model/vrml",
465
+ "wsdl": "application/wsdl+xml",
466
+ "wspolicy": "application/wspolicy+xml",
467
+ "x3d": "model/x3d+xml",
468
+ "x3db": "model/x3d+fastinfoset",
469
+ "x3dbz": "model/x3d+binary",
470
+ "x3dv": "model/x3d-vrml",
471
+ "x3dvz": "model/x3d+vrml",
472
+ "x3dz": "model/x3d+xml",
473
+ "xaml": "application/xaml+xml",
474
+ "xav": "application/xcap-att+xml",
475
+ "xca": "application/xcap-caps+xml",
476
+ "xcs": "application/calendar+xml",
477
+ "xdf": "application/xcap-diff+xml",
478
+ "xdssc": "application/dssc+xml",
479
+ "xel": "application/xcap-el+xml",
480
+ "xenc": "application/xenc+xml",
481
+ "xer": "application/patch-ops-error+xml",
482
+ "xfdf": "application/xfdf",
483
+ "xht": "application/xhtml+xml",
484
+ "xhtml": "application/xhtml+xml",
485
+ "xhvml": "application/xv+xml",
486
+ "xlf": "application/xliff+xml",
487
+ "xm": "audio/xm",
488
+ "xml": "text/xml",
489
+ "xns": "application/xcap-ns+xml",
490
+ "xop": "application/xop+xml",
491
+ "xpl": "application/xproc+xml",
492
+ "xsd": "application/xml",
493
+ "xsf": "application/prs.xsf+xml",
494
+ "xsl": "application/xml",
495
+ "xslt": "application/xml",
496
+ "xspf": "application/xspf+xml",
497
+ "xvm": "application/xv+xml",
498
+ "xvml": "application/xv+xml",
499
+ "yaml": "text/yaml",
500
+ "yang": "application/yang",
501
+ "yin": "application/yin+xml",
502
+ "yml": "text/yaml",
503
+ "zip": "application/zip"
504
+ };
505
+
506
+ function lookup(extn) {
507
+ let tmp = ('' + extn).trim().toLowerCase();
508
+ let idx = tmp.lastIndexOf('.');
509
+ return mimes[!~idx ? tmp : tmp.substring(++idx)];
510
+ }
511
+
512
+ const noop$1 = () => {};
513
+
514
+ function isMatch(uri, arr) {
515
+ for (let i=0; i < arr.length; i++) {
516
+ if (arr[i].test(uri)) return true;
517
+ }
518
+ }
519
+
520
+ function toAssume(uri, extns) {
521
+ let i=0, x, len=uri.length - 1;
522
+ if (uri.charCodeAt(len) === 47) {
523
+ uri = uri.substring(0, len);
524
+ }
525
+
526
+ let arr=[], tmp=`${uri}/index`;
527
+ for (; i < extns.length; i++) {
528
+ x = extns[i] ? `.${extns[i]}` : '';
529
+ if (uri) arr.push(uri + x);
530
+ arr.push(tmp + x);
531
+ }
532
+
533
+ return arr;
534
+ }
535
+
536
+ function viaCache(cache, uri, extns) {
537
+ let i=0, data, arr=toAssume(uri, extns);
538
+ for (; i < arr.length; i++) {
539
+ if (data = cache[arr[i]]) return data;
540
+ }
541
+ }
542
+
543
+ function viaLocal(dir, isEtag, uri, extns) {
544
+ let i=0, arr=toAssume(uri, extns);
545
+ let abs, stats, name, headers;
546
+ for (; i < arr.length; i++) {
547
+ abs = normalize(
548
+ join(dir, name=arr[i])
549
+ );
550
+
551
+ if (abs.startsWith(dir) && fs.existsSync(abs)) {
552
+ stats = fs.statSync(abs);
553
+ if (stats.isDirectory()) continue;
554
+ headers = toHeaders(name, stats, isEtag);
555
+ headers['Cache-Control'] = isEtag ? 'no-cache' : 'no-store';
556
+ return { abs, stats, headers };
557
+ }
558
+ }
559
+ }
560
+
561
+ function is404(req, res) {
562
+ return (res.statusCode=404,res.end());
563
+ }
564
+
565
+ function send(req, res, file, stats, headers) {
566
+ let code=200, tmp, opts={};
567
+ headers = { ...headers };
568
+
569
+ for (let key in headers) {
570
+ tmp = res.getHeader(key);
571
+ if (tmp) headers[key] = tmp;
572
+ }
573
+
574
+ if (tmp = res.getHeader('content-type')) {
575
+ headers['Content-Type'] = tmp;
576
+ }
577
+
578
+ if (req.headers.range) {
579
+ code = 206;
580
+ let [x, y] = req.headers.range.replace('bytes=', '').split('-');
581
+ let end = opts.end = parseInt(y, 10) || stats.size - 1;
582
+ let start = opts.start = parseInt(x, 10) || 0;
583
+
584
+ if (end >= stats.size) {
585
+ end = stats.size - 1;
586
+ }
587
+
588
+ if (start >= stats.size) {
589
+ res.setHeader('Content-Range', `bytes */${stats.size}`);
590
+ res.statusCode = 416;
591
+ return res.end();
592
+ }
593
+
594
+ headers['Content-Range'] = `bytes ${start}-${end}/${stats.size}`;
595
+ headers['Content-Length'] = (end - start + 1);
596
+ headers['Accept-Ranges'] = 'bytes';
597
+ }
598
+
599
+ res.writeHead(code, headers);
600
+ fs.createReadStream(file, opts).pipe(res);
601
+ }
602
+
603
+ const ENCODING = {
604
+ '.br': 'br',
605
+ '.gz': 'gzip',
606
+ };
607
+
608
+ function toHeaders(name, stats, isEtag) {
609
+ let enc = ENCODING[name.slice(-3)];
610
+
611
+ let ctype = lookup(name.slice(0, enc && -3)) || '';
612
+ if (ctype === 'text/html') ctype += ';charset=utf-8';
613
+
614
+ let headers = {
615
+ 'Content-Length': stats.size,
616
+ 'Content-Type': ctype,
617
+ 'Last-Modified': stats.mtime.toUTCString(),
618
+ };
619
+
620
+ if (enc) headers['Content-Encoding'] = enc;
621
+ if (isEtag) headers['ETag'] = `W/"${stats.size}-${stats.mtime.getTime()}"`;
622
+
623
+ return headers;
624
+ }
625
+
626
+ function sirv (dir, opts={}) {
627
+ dir = resolve(dir || '.');
628
+
629
+ let isNotFound = opts.onNoMatch || is404;
630
+ let setHeaders = opts.setHeaders || noop$1;
631
+
632
+ let extensions = opts.extensions || ['html', 'htm'];
633
+ let gzips = opts.gzip && extensions.map(x => `${x}.gz`).concat('gz');
634
+ let brots = opts.brotli && extensions.map(x => `${x}.br`).concat('br');
635
+
636
+ const FILES = {};
637
+
638
+ let fallback = '/';
639
+ let isEtag = !!opts.etag;
640
+ let isSPA = !!opts.single;
641
+ if (typeof opts.single === 'string') {
642
+ let idx = opts.single.lastIndexOf('.');
643
+ fallback += !!~idx ? opts.single.substring(0, idx) : opts.single;
644
+ }
645
+
646
+ let ignores = [];
647
+ if (opts.ignores !== false) {
648
+ ignores.push(/[/]([A-Za-z\s\d~$._-]+\.\w+){1,}$/); // any extn
649
+ if (opts.dotfiles) ignores.push(/\/\.\w/);
650
+ else ignores.push(/\/\.well-known/);
651
+ [].concat(opts.ignores || []).forEach(x => {
652
+ ignores.push(new RegExp(x, 'i'));
653
+ });
654
+ }
655
+
656
+ let cc = opts.maxAge != null && `public,max-age=${opts.maxAge}`;
657
+ if (cc && opts.immutable) cc += ',immutable';
658
+ else if (cc && opts.maxAge === 0) cc += ',must-revalidate';
659
+
660
+ if (!opts.dev) {
661
+ totalist(dir, (name, abs, stats) => {
662
+ if (/\.well-known[\\+\/]/.test(name)) ; // keep
663
+ else if (!opts.dotfiles && /(^\.|[\\+|\/+]\.)/.test(name)) return;
664
+
665
+ let headers = toHeaders(name, stats, isEtag);
666
+ if (cc) headers['Cache-Control'] = cc;
667
+
668
+ FILES['/' + name.normalize().replace(/\\+/g, '/')] = { abs, stats, headers };
669
+ });
670
+ }
671
+
672
+ let lookup = opts.dev ? viaLocal.bind(0, dir + sep, isEtag) : viaCache.bind(0, FILES);
673
+
674
+ return function (req, res, next) {
675
+ let extns = [''];
676
+ let pathname = parse$1(req).pathname;
677
+ let val = req.headers['accept-encoding'] || '';
678
+ if (gzips && val.includes('gzip')) extns.unshift(...gzips);
679
+ if (brots && /(br|brotli)/i.test(val)) extns.unshift(...brots);
680
+ extns.push(...extensions); // [...br, ...gz, orig, ...exts]
681
+
682
+ if (pathname.indexOf('%') !== -1) {
683
+ try { pathname = decodeURI(pathname); }
684
+ catch (err) { /* malform uri */ }
685
+ }
686
+
687
+ let data = lookup(pathname, extns) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns);
688
+ if (!data) return next ? next() : isNotFound(req, res);
689
+
690
+ if (isEtag && req.headers['if-none-match'] === data.headers['ETag']) {
691
+ res.writeHead(304);
692
+ return res.end();
693
+ }
694
+
695
+ if (gzips || brots) {
696
+ res.setHeader('Vary', 'Accept-Encoding');
697
+ }
698
+
699
+ setHeaders(res, pathname, data.stats);
700
+ send(req, res, data.abs, data.stats, data.headers);
701
+ };
702
+ }
703
+
704
+ /**
705
+ * @param {string|RegExp} input The route pattern
706
+ * @param {boolean} [loose] Allow open-ended matching. Ignored with `RegExp` input.
707
+ */
708
+ function parse(input, loose) {
709
+ if (input instanceof RegExp) return { keys:false, pattern:input };
710
+ var c, o, tmp, ext, keys=[], pattern='', arr = input.split('/');
711
+ arr[0] || arr.shift();
712
+
713
+ while (tmp = arr.shift()) {
714
+ c = tmp[0];
715
+ if (c === '*') {
716
+ keys.push(c);
717
+ pattern += tmp[1] === '?' ? '(?:/(.*))?' : '/(.*)';
718
+ } else if (c === ':') {
719
+ o = tmp.indexOf('?', 1);
720
+ ext = tmp.indexOf('.', 1);
721
+ keys.push( tmp.substring(1, !!~o ? o : !!~ext ? ext : tmp.length) );
722
+ pattern += !!~o && !~ext ? '(?:/([^/]+?))?' : '/([^/]+?)';
723
+ if (!!~ext) pattern += (!!~o ? '?' : '') + '\\' + tmp.substring(ext);
724
+ } else {
725
+ pattern += '/' + tmp;
726
+ }
727
+ }
728
+
729
+ return {
730
+ keys: keys,
731
+ pattern: new RegExp('^' + pattern + (loose ? '(?=$|\/)' : '\/?$'), 'i')
732
+ };
733
+ }
734
+
735
+ const MAP = {
736
+ "": 0,
737
+ GET: 1,
738
+ HEAD: 2,
739
+ PATCH: 3,
740
+ OPTIONS: 4,
741
+ CONNECT: 5,
742
+ DELETE: 6,
743
+ TRACE: 7,
744
+ POST: 8,
745
+ PUT: 9,
746
+ };
747
+
748
+ class Trouter {
749
+ constructor() {
750
+ this.routes = [];
751
+
752
+ this.all = this.add.bind(this, '');
753
+ this.get = this.add.bind(this, 'GET');
754
+ this.head = this.add.bind(this, 'HEAD');
755
+ this.patch = this.add.bind(this, 'PATCH');
756
+ this.options = this.add.bind(this, 'OPTIONS');
757
+ this.connect = this.add.bind(this, 'CONNECT');
758
+ this.delete = this.add.bind(this, 'DELETE');
759
+ this.trace = this.add.bind(this, 'TRACE');
760
+ this.post = this.add.bind(this, 'POST');
761
+ this.put = this.add.bind(this, 'PUT');
762
+ }
763
+
764
+ use(route, ...fns) {
765
+ let handlers = [].concat.apply([], fns);
766
+ let { keys, pattern } = parse(route, true);
767
+ this.routes.push({ keys, pattern, method: '', handlers, midx: MAP[''] });
768
+ return this;
769
+ }
770
+
771
+ add(method, route, ...fns) {
772
+ let { keys, pattern } = parse(route);
773
+ let handlers = [].concat.apply([], fns);
774
+ this.routes.push({ keys, pattern, method, handlers, midx: MAP[method] });
775
+ return this;
776
+ }
777
+
778
+ find(method, url) {
779
+ let midx = MAP[method];
780
+ let isHEAD = (midx === 2);
781
+ let i=0, j=0, k, tmp, arr=this.routes;
782
+ let matches=[], params={}, handlers=[];
783
+ for (; i < arr.length; i++) {
784
+ tmp = arr[i];
785
+ if (tmp.midx === midx || tmp.midx === 0 || (isHEAD && tmp.midx===1) ) {
786
+ if (tmp.keys === false) {
787
+ matches = tmp.pattern.exec(url);
788
+ if (matches === null) continue;
789
+ if (matches.groups !== void 0) for (k in matches.groups) params[k]=matches.groups[k];
790
+ tmp.handlers.length > 1 ? (handlers=handlers.concat(tmp.handlers)) : handlers.push(tmp.handlers[0]);
791
+ } else if (tmp.keys.length > 0) {
792
+ matches = tmp.pattern.exec(url);
793
+ if (matches === null) continue;
794
+ for (j=0; j < tmp.keys.length;) params[tmp.keys[j]]=matches[++j];
795
+ tmp.handlers.length > 1 ? (handlers=handlers.concat(tmp.handlers)) : handlers.push(tmp.handlers[0]);
796
+ } else if (tmp.pattern.test(url)) {
797
+ tmp.handlers.length > 1 ? (handlers=handlers.concat(tmp.handlers)) : handlers.push(tmp.handlers[0]);
798
+ }
799
+ } // else not a match
800
+ }
801
+
802
+ return { params, handlers };
803
+ }
804
+ }
805
+
806
+ function onError(err, req, res) {
807
+ let code = typeof err.status === 'number' && err.status;
808
+ code = res.statusCode = (code && code >= 100 ? code : 500);
809
+ if (typeof err === 'string' || Buffer.isBuffer(err)) res.end(err);
810
+ else res.end(err.message || http.STATUS_CODES[code]);
811
+ }
812
+
813
+ const mount = fn => fn instanceof Polka ? fn.attach : fn;
814
+
815
+ class Polka extends Trouter {
816
+ constructor(opts={}) {
817
+ super();
818
+ this.parse = parse$1;
819
+ this.server = opts.server;
820
+ this.handler = this.handler.bind(this);
821
+ this.onError = opts.onError || onError; // catch-all handler
822
+ this.onNoMatch = opts.onNoMatch || this.onError.bind(null, { status: 404 });
823
+ this.attach = (req, res) => setImmediate(this.handler, req, res);
824
+ }
825
+
826
+ use(base, ...fns) {
827
+ if (base === '/') {
828
+ super.use(base, fns.map(mount));
829
+ } else if (typeof base === 'function' || base instanceof Polka) {
830
+ super.use('/', [base, ...fns].map(mount));
831
+ } else {
832
+ super.use(base,
833
+ (req, _, next) => {
834
+ if (typeof base === 'string') {
835
+ let len = base.length;
836
+ base.startsWith('/') || len++;
837
+ req.url = req.url.substring(len) || '/';
838
+ req.path = req.path.substring(len) || '/';
839
+ } else {
840
+ req.url = req.url.replace(base, '') || '/';
841
+ req.path = req.path.replace(base, '') || '/';
842
+ }
843
+ if (req.url.charAt(0) !== '/') {
844
+ req.url = '/' + req.url;
845
+ }
846
+ next();
847
+ },
848
+ fns.map(mount),
849
+ (req, _, next) => {
850
+ req.path = req._parsedUrl.pathname;
851
+ req.url = req.path + req._parsedUrl.search;
852
+ next();
853
+ }
854
+ );
855
+ }
856
+ return this; // chainable
857
+ }
858
+
859
+ listen() {
860
+ (this.server = this.server || http.createServer()).on('request', this.attach);
861
+ this.server.listen.apply(this.server, arguments);
862
+ return this;
863
+ }
864
+
865
+ handler(req, res, next) {
866
+ let info = this.parse(req), path = info.pathname;
867
+ let obj = this.find(req.method, req.path=path);
868
+
869
+ req.url = path + info.search;
870
+ req.originalUrl = req.originalUrl || req.url;
871
+ req.query = info.query || {};
872
+ req.search = info.search;
873
+ req.params = obj.params;
874
+
875
+ if (path.length > 1 && path.indexOf('%', 1) !== -1) {
876
+ for (let k in req.params) {
877
+ try { req.params[k] = decodeURIComponent(req.params[k]); }
878
+ catch (e) { /* malform uri segment */ }
879
+ }
880
+ }
881
+
882
+ let i=0, arr=obj.handlers.concat(this.onNoMatch), len=arr.length;
883
+ let loop = async () => res.finished || (i < len) && arr[i++](req, res, next);
884
+ (next = next || (err => err ? this.onError(err, req, res, next) : loop().catch(next)))(); // init
885
+ }
886
+ }
887
+
888
+ function polka (opts) {
889
+ return new Polka(opts);
890
+ }
891
+
892
+ function noop() {}
893
+
894
+ /** @import { RemoteForm } from '@sveltejs/kit' */
895
+ /** @import { BinaryFormMeta, InternalRemoteFormIssue } from 'types' */
896
+ /** @import { StandardSchemaV1 } from '@standard-schema/spec' */
897
+
898
+
899
+ new TextDecoder();
900
+
901
+ /**
902
+ * Reads all `Set-Cookie` headers as separate values. `Headers.get('set-cookie')`
903
+ * collapses them into a single comma-joined string that browsers cannot parse, so
904
+ * we use `Headers.getSetCookie()` where available and fall back to splitting the
905
+ * joined string otherwise.
906
+ *
907
+ * TODO 3.0 `getSetCookie` is available in Node 19.7+; once we drop support for
908
+ * older versions we can use it directly and remove the `splitCookiesString` fallback
909
+ * @param {Headers} headers
910
+ * @returns {string[]}
911
+ */
912
+ function get_set_cookies(headers) {
913
+ if (typeof headers.getSetCookie === 'function') {
914
+ return headers.getSetCookie();
915
+ }
916
+
917
+ const set_cookie = headers.get('set-cookie');
918
+ return set_cookie ? splitCookiesString(set_cookie) : [];
919
+ }
920
+
921
+ /**
922
+ * @param {import('http').IncomingMessage} req
923
+ * @param {number} [body_size_limit]
924
+ */
925
+ function get_raw_body(req, body_size_limit) {
926
+ const h = req.headers;
927
+
928
+ if (!h['content-type']) {
929
+ return null;
930
+ }
931
+
932
+ const content_length = Number(h['content-length']);
933
+ const has_content_length = Number.isFinite(content_length);
934
+
935
+ // check if no request body
936
+ if (
937
+ (req.httpVersionMajor === 1 && !has_content_length && h['transfer-encoding'] == null) ||
938
+ content_length === 0
939
+ ) {
940
+ return null;
941
+ }
942
+
943
+ if (req.destroyed) {
944
+ const readable = new ReadableStream();
945
+ void readable.cancel();
946
+ return readable;
947
+ }
948
+
949
+ let size = 0;
950
+ let cancelled = false;
951
+
952
+ return new ReadableStream({
953
+ start(controller) {
954
+ if (body_size_limit !== undefined && has_content_length && content_length > body_size_limit) {
955
+ let message = `Content-length of ${content_length} exceeds limit of ${body_size_limit} bytes.`;
956
+
957
+ if (body_size_limit === 0) {
958
+ // https://github.com/sveltejs/kit/pull/11589
959
+ // TODO this exists to aid migration — remove in a future version
960
+ message += ' To disable body size limits, specify Infinity rather than 0.';
961
+ }
962
+
963
+ const error = new SvelteKitError(413, 'Payload Too Large', message);
964
+
965
+ controller.error(error);
966
+ return;
967
+ }
968
+
969
+ req.on('error', (error) => {
970
+ cancelled = true;
971
+ controller.error(error);
972
+ });
973
+
974
+ req.on('end', () => {
975
+ if (cancelled) return;
976
+ controller.close();
977
+ });
978
+
979
+ req.on('data', (chunk) => {
980
+ if (cancelled) return;
981
+
982
+ size += chunk.length;
983
+
984
+ if (body_size_limit !== undefined && size > body_size_limit) {
985
+ cancelled = true;
986
+
987
+ const message = `request body size exceeded BODY_SIZE_LIMIT of ${body_size_limit}`;
988
+
989
+ const error = new SvelteKitError(413, 'Payload Too Large', message);
990
+ controller.error(error);
991
+
992
+ return;
993
+ }
994
+
995
+ if (has_content_length && size > content_length) {
996
+ cancelled = true;
997
+
998
+ const message = `request body size exceeded content-length of ${content_length}`;
999
+
1000
+ const error = new SvelteKitError(413, 'Payload Too Large', message);
1001
+ controller.error(error);
1002
+
1003
+ return;
1004
+ }
1005
+
1006
+ controller.enqueue(chunk);
1007
+
1008
+ if (controller.desiredSize === null || controller.desiredSize <= 0) {
1009
+ req.pause();
1010
+ }
1011
+ });
1012
+ },
1013
+
1014
+ pull() {
1015
+ req.resume();
1016
+ },
1017
+
1018
+ cancel(reason) {
1019
+ cancelled = true;
1020
+ req.destroy(reason);
1021
+ }
1022
+ });
1023
+ }
1024
+
1025
+ /**
1026
+ * @param {{
1027
+ * request: import('http').IncomingMessage;
1028
+ * base: string;
1029
+ * bodySizeLimit?: number;
1030
+ * }} options
1031
+ * @returns {Promise<Request>}
1032
+ */
1033
+ // TODO 3.0 make the signature synchronous?
1034
+ // eslint-disable-next-line @typescript-eslint/require-await
1035
+ async function getRequest({ request, base, bodySizeLimit }) {
1036
+ let headers = /** @type {Record<string, string>} */ (request.headers);
1037
+ if (request.httpVersionMajor >= 2) {
1038
+ // the Request constructor rejects headers with ':' in the name
1039
+ headers = Object.assign({}, headers);
1040
+ // https://www.rfc-editor.org/rfc/rfc9113.html#section-8.3.1-2.3.5
1041
+ if (headers[':authority']) {
1042
+ headers.host = headers[':authority'];
1043
+ }
1044
+ delete headers[':authority'];
1045
+ delete headers[':method'];
1046
+ delete headers[':path'];
1047
+ delete headers[':scheme'];
1048
+ }
1049
+
1050
+ // TODO: Whenever Node >=22 is minimum supported version, we can use `request.readableAborted`
1051
+ // @see https://github.com/nodejs/node/blob/5cf3c3e24c7257a0c6192ed8ef71efec8ddac22b/lib/internal/streams/readable.js#L1443-L1453
1052
+ const controller = new AbortController();
1053
+ let errored = false;
1054
+ let end_emitted = false;
1055
+ request.once('error', () => (errored = true));
1056
+ request.once('end', () => (end_emitted = true));
1057
+ request.once('close', () => {
1058
+ if ((errored || request.destroyed) && !end_emitted) {
1059
+ controller.abort();
1060
+ }
1061
+ });
1062
+
1063
+ return new Request(base + request.url, {
1064
+ // @ts-expect-error
1065
+ duplex: 'half',
1066
+ method: request.method,
1067
+ headers: Object.entries(headers),
1068
+ signal: controller.signal,
1069
+ body:
1070
+ request.method === 'GET' || request.method === 'HEAD'
1071
+ ? undefined
1072
+ : get_raw_body(request, bodySizeLimit)
1073
+ });
1074
+ }
1075
+
1076
+ /**
1077
+ * @param {import('http').ServerResponse} res
1078
+ * @param {Response} response
1079
+ * @returns {Promise<void>}
1080
+ */
1081
+ // TODO 3.0 make the signature synchronous?
1082
+ // eslint-disable-next-line @typescript-eslint/require-await
1083
+ async function setResponse(res, response) {
1084
+ for (const [key, value] of response.headers) {
1085
+ try {
1086
+ res.setHeader(key, key === 'set-cookie' ? get_set_cookies(response.headers) : value);
1087
+ } catch (error) {
1088
+ res.getHeaderNames().forEach((name) => res.removeHeader(name));
1089
+ res.writeHead(500).end(String(error));
1090
+ return;
1091
+ }
1092
+ }
1093
+
1094
+ res.writeHead(response.status);
1095
+
1096
+ if (!response.body) {
1097
+ res.end();
1098
+ return;
1099
+ }
1100
+
1101
+ if (response.body.locked) {
1102
+ res.end(
1103
+ 'Fatal error: Response body is locked. ' +
1104
+ "This can happen when the response was already read (for example through 'response.json()' or 'response.text()')."
1105
+ );
1106
+ return;
1107
+ }
1108
+
1109
+ const reader = response.body.getReader();
1110
+
1111
+ if (res.destroyed) {
1112
+ void reader.cancel();
1113
+ return;
1114
+ }
1115
+
1116
+ const cancel = (/** @type {Error|undefined} */ error) => {
1117
+ res.off('close', cancel);
1118
+ res.off('error', cancel);
1119
+
1120
+ // If the reader has already been interrupted with an error earlier,
1121
+ // then it will appear here, it is useless, but it needs to be catch.
1122
+ reader.cancel(error).catch(noop);
1123
+ if (error) res.destroy(error);
1124
+ };
1125
+
1126
+ res.on('close', cancel);
1127
+ res.on('error', cancel);
1128
+
1129
+ void next();
1130
+ async function next() {
1131
+ try {
1132
+ for (;;) {
1133
+ const { done, value } = await reader.read();
1134
+
1135
+ if (done) break;
1136
+
1137
+ if (!res.write(value)) {
1138
+ res.once('drain', next);
1139
+ return;
1140
+ }
1141
+ }
1142
+ res.end();
1143
+ } catch (error) {
1144
+ cancel(error instanceof Error ? error : new Error(String(error)));
1145
+ }
1146
+ }
1147
+ }
1148
+
1149
+ /**
1150
+ * Converts a file on disk to a readable stream
1151
+ * @param {string} file
1152
+ * @returns {ReadableStream}
1153
+ * @since 2.4.0
1154
+ */
1155
+ function createReadableStream(file) {
1156
+ return /** @type {ReadableStream} */ (Readable.toWeb(createReadStream(file)));
1157
+ }
1158
+
1159
+ /**
1160
+ * Parses the given value into number of bytes.
1161
+ *
1162
+ * @param {string} value - Size in bytes. Can also be specified with a unit suffix kilobytes (K), megabytes (M), or gigabytes (G).
1163
+ * @returns {number}
1164
+ */
1165
+ function parse_as_bytes(value) {
1166
+ const multiplier =
1167
+ {
1168
+ K: 1024,
1169
+ M: 1024 * 1024,
1170
+ G: 1024 * 1024 * 1024
1171
+ }[value[value.length - 1]?.toUpperCase()] ?? 1;
1172
+ return Number(multiplier != 1 ? value.substring(0, value.length - 1) : value) * multiplier;
1173
+ }
1174
+
1175
+ /**
1176
+ * Parses and validates an origin URL.
1177
+ *
1178
+ * @param {string | undefined} value - Origin URL with http:// or https:// protocol
1179
+ * @returns {string | undefined} The validated origin, or undefined if value is undefined
1180
+ * @throws {Error} If value is provided but invalid
1181
+ */
1182
+ function parse_origin(value) {
1183
+ if (value === undefined) {
1184
+ return undefined;
1185
+ }
1186
+
1187
+ const trimmed = value.trim();
1188
+
1189
+ let url;
1190
+ try {
1191
+ url = new URL(trimmed);
1192
+ } catch (error) {
1193
+ throw new Error(
1194
+ `Invalid ORIGIN: '${trimmed}'. ` +
1195
+ `ORIGIN must be a valid URL with http:// or https:// protocol. ` +
1196
+ `For example: 'http://localhost:3000' or 'https://my.site'`,
1197
+ { cause: error }
1198
+ );
1199
+ }
1200
+
1201
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
1202
+ throw new Error(
1203
+ `Invalid ORIGIN: '${trimmed}'. ` +
1204
+ `Only http:// and https:// protocols are supported. ` +
1205
+ `Received protocol: ${url.protocol}`
1206
+ );
1207
+ }
1208
+
1209
+ return url.origin;
1210
+ }
1211
+
1212
+ /**
1213
+ * Formats the address the server is listening on.
1214
+ *
1215
+ * @param {string | false} path
1216
+ * @param {string} host
1217
+ * @param {string | false} port
1218
+ * @param {import('node:net').AddressInfo | string | null} address
1219
+ * @returns {string}
1220
+ */
1221
+ function format_listening_address(path, host, port, address) {
1222
+ if (path) {
1223
+ return path;
1224
+ }
1225
+
1226
+ if (address && typeof address === 'object') {
1227
+ return format({
1228
+ protocol: 'http:',
1229
+ hostname: address.address,
1230
+ port: address.port
1231
+ });
1232
+ }
1233
+
1234
+ return format({
1235
+ protocol: 'http:',
1236
+ hostname: host,
1237
+ port: String(port)
1238
+ });
1239
+ }
1240
+
1241
+ const prerendered = new Set([]);
1242
+
1243
+ const server = new Server(manifest);
1244
+
1245
+ // parse_origin validates ORIGIN and throws descriptive errors for invalid values
1246
+ const origin = parse_origin(env('ORIGIN', undefined));
1247
+
1248
+ const xff_depth = parseInt(env('XFF_DEPTH', '1'));
1249
+ const address_header = env('ADDRESS_HEADER', '').toLowerCase();
1250
+ const protocol_header = env('PROTOCOL_HEADER', '').toLowerCase();
1251
+ const host_header = env('HOST_HEADER', '').toLowerCase();
1252
+ const port_header = env('PORT_HEADER', '').toLowerCase();
1253
+
1254
+ const body_size_limit = parse_as_bytes(env('BODY_SIZE_LIMIT', '512K'));
1255
+
1256
+ if (isNaN(body_size_limit)) {
1257
+ throw new Error(
1258
+ `Invalid BODY_SIZE_LIMIT: '${env('BODY_SIZE_LIMIT')}'. Please provide a numeric value.`
1259
+ );
1260
+ }
1261
+
1262
+ const asset_dir = `${dir}/client${""}`;
1263
+
1264
+ await server.init({
1265
+ env: /** @type {Record<string, string>} */ (process.env),
1266
+ read: (file) => createReadableStream(`${asset_dir}/${file}`)
1267
+ });
1268
+
1269
+ /**
1270
+ * @param {string} path
1271
+ * @param {boolean} client
1272
+ */
1273
+ function serve(path, client = false) {
1274
+ return fs__default.existsSync(path)
1275
+ ? sirv(path, {
1276
+ etag: true,
1277
+ gzip: true,
1278
+ brotli: true,
1279
+ setHeaders: client
1280
+ ? (res, pathname) => {
1281
+ // only apply to build directory, not e.g. version.json
1282
+ if (
1283
+ pathname.startsWith(`/${manifest.appPath}/immutable/`) &&
1284
+ res.statusCode === 200
1285
+ ) {
1286
+ res.setHeader('cache-control', 'public,max-age=31536000,immutable');
1287
+ }
1288
+ }
1289
+ : undefined
1290
+ })
1291
+ : undefined;
1292
+ }
1293
+
1294
+ // required because the static file server ignores trailing slashes
1295
+ /** @returns {import('polka').Middleware} */
1296
+ function serve_prerendered() {
1297
+ const handler = serve(path.join(dir, 'prerendered'));
1298
+
1299
+ return (req, res, next) => {
1300
+ let { pathname, search, query } = parse$1(req);
1301
+
1302
+ try {
1303
+ pathname = decodeURIComponent(pathname);
1304
+ } catch {
1305
+ // ignore invalid URI
1306
+ }
1307
+
1308
+ if (prerendered.has(pathname)) {
1309
+ return handler?.(req, res, next);
1310
+ }
1311
+
1312
+ // remove or add trailing slash as appropriate
1313
+ let location = pathname.at(-1) === '/' ? pathname.slice(0, -1) : pathname + '/';
1314
+ if (prerendered.has(location)) {
1315
+ if (query) location += search;
1316
+ res.writeHead(308, { location }).end();
1317
+ } else {
1318
+ void next();
1319
+ }
1320
+ };
1321
+ }
1322
+
1323
+ /** @type {import('polka').Middleware} */
1324
+ const ssr = async (req, res) => {
1325
+ /** @type {Request} */
1326
+ let request;
1327
+
1328
+ try {
1329
+ request = await getRequest({
1330
+ base: origin || get_origin(req.headers),
1331
+ request: req,
1332
+ bodySizeLimit: body_size_limit
1333
+ });
1334
+ } catch {
1335
+ res.statusCode = 400;
1336
+ res.end('Bad Request');
1337
+ return;
1338
+ }
1339
+
1340
+ const response = await server.respond(request, {
1341
+ platform: { req },
1342
+ getClientAddress: () => {
1343
+ if (address_header) {
1344
+ if (!(address_header in req.headers)) {
1345
+ throw new Error(
1346
+ `Address header was specified with ${
1347
+ env_prefix + 'ADDRESS_HEADER'
1348
+ }=${address_header} but is absent from request`
1349
+ );
1350
+ }
1351
+
1352
+ const value = /** @type {string} */ (req.headers[address_header]) || '';
1353
+
1354
+ if (address_header === 'x-forwarded-for') {
1355
+ const addresses = value.split(',');
1356
+
1357
+ if (xff_depth < 1) {
1358
+ throw new Error(`${env_prefix + 'XFF_DEPTH'} must be a positive integer`);
1359
+ }
1360
+
1361
+ if (xff_depth > addresses.length) {
1362
+ throw new Error(
1363
+ `${env_prefix + 'XFF_DEPTH'} is ${xff_depth}, but only found ${
1364
+ addresses.length
1365
+ } addresses`
1366
+ );
1367
+ }
1368
+ return addresses[addresses.length - xff_depth].trim();
1369
+ }
1370
+
1371
+ return value;
1372
+ }
1373
+
1374
+ return (
1375
+ req.connection?.remoteAddress ||
1376
+ // @ts-expect-error
1377
+ req.connection?.socket?.remoteAddress ||
1378
+ req.socket?.remoteAddress ||
1379
+ // @ts-expect-error
1380
+ req.info?.remoteAddress
1381
+ );
1382
+ }
1383
+ });
1384
+
1385
+ // Reverse proxies such as nginx buffer responses by default (ignoring
1386
+ // `cache-control`), which breaks streaming responses like server-sent events.
1387
+ // `X-Accel-Buffering: no` opts out of that buffering and is a no-op on proxies
1388
+ // that don't recognise it. See https://github.com/sveltejs/kit/issues/15790
1389
+ if (response.headers.get('content-type') === 'text/event-stream') {
1390
+ response.headers.set('x-accel-buffering', 'no');
1391
+ }
1392
+
1393
+ await setResponse(res, response);
1394
+ };
1395
+
1396
+ /** @param {import('polka').Middleware[]} handlers */
1397
+ function sequence(handlers) {
1398
+ /** @type {import('polka').Middleware} */
1399
+ return (req, res, next) => {
1400
+ /**
1401
+ * @param {number} i
1402
+ * @returns {ReturnType<import('polka').Middleware>}
1403
+ */
1404
+ function handle(i) {
1405
+ if (i < handlers.length) {
1406
+ return handlers[i](req, res, () => handle(i + 1));
1407
+ } else {
1408
+ return next();
1409
+ }
1410
+ }
1411
+
1412
+ return handle(0);
1413
+ };
1414
+ }
1415
+
1416
+ /**
1417
+ * @param {string} name
1418
+ * @param {string | string[] | undefined} value
1419
+ * @returns {string | undefined}
1420
+ */
1421
+ function normalise_header(name, value) {
1422
+ if (!name) return undefined;
1423
+ if (Array.isArray(value)) {
1424
+ if (value.length === 0) return undefined;
1425
+ if (value.length === 1) return value[0];
1426
+ throw new Error(
1427
+ `Multiple values provided for ${name} header where only one expected: ${value}`
1428
+ );
1429
+ }
1430
+ return value;
1431
+ }
1432
+
1433
+ /**
1434
+ * @param {import('http').IncomingHttpHeaders} headers
1435
+ * @returns {string}
1436
+ */
1437
+ function get_origin(headers) {
1438
+ const protocol = decodeURIComponent(
1439
+ normalise_header(protocol_header, headers[protocol_header]) || 'https'
1440
+ );
1441
+
1442
+ // this helps us avoid host injections through the protocol header
1443
+ if (protocol.includes(':')) {
1444
+ throw new Error(
1445
+ `The ${protocol_header} header specified ${protocol} which is an invalid because it includes \`:\`. It should only contain the protocol scheme (e.g. \`https\`)`
1446
+ );
1447
+ }
1448
+
1449
+ const host =
1450
+ normalise_header(host_header, headers[host_header]) ||
1451
+ normalise_header('host', headers['host']);
1452
+ if (!host) {
1453
+ const header_names = host_header ? `${host_header} or host headers` : 'host header';
1454
+ throw new Error(
1455
+ `Could not determine host. The request must have a value provided by the ${header_names}`
1456
+ );
1457
+ }
1458
+
1459
+ const port = normalise_header(port_header, headers[port_header]);
1460
+ if (port && isNaN(+port)) {
1461
+ throw new Error(
1462
+ `The ${port_header} header specified ${port} which is an invalid port because it is not a number. The value should only contain the port number (e.g. 443)`
1463
+ );
1464
+ }
1465
+
1466
+ return port ? `${protocol}://${host}:${port}` : `${protocol}://${host}`;
1467
+ }
1468
+
1469
+ const handler = sequence(
1470
+ /** @type {(import('sirv').RequestHandler | import('polka').Middleware)[]} */
1471
+ ([serve(path.join(dir, 'client'), true), serve_prerendered(), ssr].filter(Boolean))
1472
+ );
1473
+
1474
+ export { format_listening_address as f, handler as h, polka as p };
1475
+ //# sourceMappingURL=handler-10cx4zHn.js.map