@deepseek-insight/dsi 0.5.9 → 0.5.11

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 (177) hide show
  1. package/README.md +27 -60
  2. package/bin/dsi.mjs +112 -8
  3. package/build/client/_app/immutable/assets/0.B-x78bUH.css +2 -0
  4. package/build/client/_app/immutable/assets/2.DHY7FpOZ.css +1 -0
  5. package/build/client/_app/immutable/chunks/06CitLNM.js +1 -0
  6. package/build/client/_app/immutable/chunks/{CJ_zvTBg.js → 1KjP5PPV.js} +1 -1
  7. package/build/client/_app/immutable/chunks/{BAZKJuQw.js → 4BUyCMHs.js} +1 -1
  8. package/build/client/_app/immutable/chunks/{qEGLx2Wc.js → 5BuKkouu.js} +1 -1
  9. package/build/client/_app/immutable/chunks/{Cj-Zm41R.js → 5W1abxrJ.js} +1 -1
  10. package/build/client/_app/immutable/chunks/{DlLP-Tuk.js → 7Qwz4TD3.js} +1 -1
  11. package/build/client/_app/immutable/chunks/{2irkVCIh.js → B3Lta-Nn.js} +1 -1
  12. package/build/client/_app/immutable/chunks/{Dr0pcX_F.js → B5bIZjCh.js} +1 -1
  13. package/build/client/_app/immutable/chunks/{CZXl7qUb.js → BDws8KMN.js} +1 -1
  14. package/build/client/_app/immutable/chunks/{CmbEK4CY.js → BFYiBR8b.js} +1 -1
  15. package/build/client/_app/immutable/chunks/{BI4pMaIG.js → BK9wQfnJ.js} +1 -1
  16. package/build/client/_app/immutable/chunks/{Beo7Z46k.js → BKMUCRSB.js} +1 -1
  17. package/build/client/_app/immutable/chunks/{D16vkywU.js → BNCXVe_Y.js} +1 -1
  18. package/build/client/_app/immutable/chunks/{DtBGId5S.js → BO15_-NJ.js} +1 -1
  19. package/build/client/_app/immutable/chunks/{CfZ7uSQe.js → BOGXkyy3.js} +1 -1
  20. package/build/client/_app/immutable/chunks/{BhNEBkk_.js → BP1EDRMh.js} +1 -1
  21. package/build/client/_app/immutable/chunks/{Bn9NRi0R.js → BQFPW2iU.js} +1 -1
  22. package/build/client/_app/immutable/chunks/{DI6I60fv.js → BS84xqUl.js} +1 -1
  23. package/build/client/_app/immutable/chunks/BhA_Mtox.js +2 -0
  24. package/build/client/_app/immutable/chunks/{DVXVVWkX.js → BhMqa9V0.js} +1 -1
  25. package/build/client/_app/immutable/chunks/{OmE6SGvs.js → BnEcDyty.js} +1 -1
  26. package/build/client/_app/immutable/chunks/{D4gq_dik.js → BoJ5ww2X.js} +1 -1
  27. package/build/client/_app/immutable/chunks/{BnF5Jm-h.js → BtWgux0k.js} +1 -1
  28. package/build/client/_app/immutable/chunks/BuVjHIij.js +1 -0
  29. package/build/client/_app/immutable/chunks/{CA_WNCsl.js → C7xeaPF2.js} +1 -1
  30. package/build/client/_app/immutable/chunks/{GBaNblmo.js → CA7VtFsM.js} +1 -1
  31. package/build/client/_app/immutable/chunks/{9TvT6fta.js → CIZRvqf3.js} +1 -1
  32. package/build/client/_app/immutable/chunks/{DuM1hSCa.js → CKk3hDrH.js} +1 -1
  33. package/build/client/_app/immutable/chunks/CM2YlsBZ.js +1 -0
  34. package/build/client/_app/immutable/chunks/{DzVMo6mB.js → CQNMOuVz.js} +1 -1
  35. package/build/client/_app/immutable/chunks/{wFIeY1Cf.js → CVJBb63S.js} +1 -1
  36. package/build/client/_app/immutable/chunks/CWCyOfZL.js +1 -0
  37. package/build/client/_app/immutable/chunks/{Dg_UWGX7.js → CWJVj28H.js} +1 -1
  38. package/build/client/_app/immutable/chunks/{sIEmSkn6.js → CWRt23V2.js} +1 -1
  39. package/build/client/_app/immutable/chunks/{DWDfcLfy.js → CXDjw6BI.js} +1 -1
  40. package/build/client/_app/immutable/chunks/{B38Unp4-.js → CbmGLQlS.js} +1 -1
  41. package/build/client/_app/immutable/chunks/{raVGrKQy.js → CfKp2keY.js} +4 -4
  42. package/build/client/_app/immutable/chunks/{LWre5GKl.js → CfPrYC2A.js} +1 -1
  43. package/build/client/_app/immutable/chunks/{zpcgJjUg.js → CfqeI44h.js} +1 -1
  44. package/build/client/_app/immutable/chunks/{BJL7RCQE.js → CjMviqoD.js} +1 -1
  45. package/build/client/_app/immutable/chunks/CoCs8NEu.js +1 -0
  46. package/build/client/_app/immutable/chunks/Ct7xT-0E.js +1 -0
  47. package/build/client/_app/immutable/chunks/{DGarjVZC.js → CwpTIVX4.js} +1 -1
  48. package/build/client/_app/immutable/chunks/{C1JXY9b5.js → D-p2gaJO.js} +1 -1
  49. package/build/client/_app/immutable/chunks/{CWVpRRWx.js → D2Punuji.js} +1 -1
  50. package/build/client/_app/immutable/chunks/{CWKM3f5q.js → D9XozwcM.js} +1 -1
  51. package/build/client/_app/immutable/chunks/DFZg0vdm.js +8 -0
  52. package/build/client/_app/immutable/chunks/{BOfSXrr7.js → DHChdxxK.js} +1 -1
  53. package/build/client/_app/immutable/chunks/DKLs56Hm.js +1 -0
  54. package/build/client/_app/immutable/chunks/{D0I62FkS.js → DTVIMflS.js} +1 -1
  55. package/build/client/_app/immutable/chunks/{D8-5qLJg.js → DVsJyQaB.js} +1 -1
  56. package/build/client/_app/immutable/chunks/{Btk-1DaX.js → D_4vyw9k.js} +1 -1
  57. package/build/client/_app/immutable/chunks/{CPgSxomx.js → Da0rl5Rb.js} +1 -1
  58. package/build/client/_app/immutable/chunks/DemMpn7y.js +1 -0
  59. package/build/client/_app/immutable/chunks/{DPKol_4Z.js → DfxnqpU2.js} +1 -1
  60. package/build/client/_app/immutable/chunks/DnA33f7e.js +3 -0
  61. package/build/client/_app/immutable/chunks/{6GKQw8m6.js → DrLWFO8Z.js} +1 -1
  62. package/build/client/_app/immutable/chunks/{DITEY8D_.js → DtdNJetN.js} +1 -1
  63. package/build/client/_app/immutable/chunks/{DLOOos_8.js → Dufckt0T.js} +1 -1
  64. package/build/client/_app/immutable/chunks/{DAS1CLuE.js → DzNl4lTU.js} +1 -1
  65. package/build/client/_app/immutable/chunks/E-1cXrsM.js +1 -0
  66. package/build/client/_app/immutable/chunks/{Kcoq1pzq.js → FDKaBHdO.js} +1 -1
  67. package/build/client/_app/immutable/chunks/{BD8HEhdy.js → KCYBrblk.js} +5 -5
  68. package/build/client/_app/immutable/chunks/N_z8g1dA.js +1 -0
  69. package/build/client/_app/immutable/chunks/{DbcKN35_.js → NxBjh70M.js} +1 -1
  70. package/build/client/_app/immutable/chunks/{B1YSaoU7.js → T453H1uG.js} +1 -1
  71. package/build/client/_app/immutable/chunks/{DqwfDHZH.js → XM-sjL-p.js} +1 -1
  72. package/build/client/_app/immutable/chunks/{Cy8ZCjxB.js → _OxPZn8v.js} +1 -1
  73. package/build/client/_app/immutable/chunks/{DvCMcJ3P.js → dg-Ik0Xp.js} +1 -1
  74. package/build/client/_app/immutable/chunks/{Cd6K7Y8m.js → eNqKaSDb.js} +1 -1
  75. package/build/client/_app/immutable/chunks/{mVHw7KEX.js → hFCLiR2C.js} +1 -1
  76. package/build/client/_app/immutable/chunks/{Rh9cy7xg.js → pRzztTzl.js} +1 -1
  77. package/build/client/_app/immutable/chunks/{Cb1pwoev.js → qDr7l6ST.js} +1 -1
  78. package/build/client/_app/immutable/chunks/{nDMCpPkF.js → tziyL5EM.js} +1 -1
  79. package/build/client/_app/immutable/chunks/{UNxFjlik.js → wRPKccfz.js} +1 -1
  80. package/build/client/_app/immutable/entry/app.CO61_ZoK.js +2 -0
  81. package/build/client/_app/immutable/entry/start.D2897Ko1.js +1 -0
  82. package/build/client/_app/immutable/nodes/0.Cl1RKBMO.js +1 -0
  83. package/build/client/_app/immutable/nodes/1.BTAH4lX4.js +1 -0
  84. package/build/client/_app/immutable/nodes/2.BIBOCzYk.js +174 -0
  85. package/build/client/_app/version.json +1 -1
  86. package/build/env.js +2 -2
  87. package/build/handler.js +9 -9
  88. package/build/index.js +9 -9
  89. package/build/server/chunks/chunks/{app-config.svelte.js-Co9jacqT.js → app-config.svelte.js-BkhuJ9bF.js} +2 -2
  90. package/build/server/chunks/chunks/{config.js-BBYogCe7.js → config.js-D2vQdial.js} +9 -2
  91. package/build/server/chunks/chunks/{db.js-C4EPtpZT.js → db.js-Cya8uRCD.js} +2 -2
  92. package/build/server/chunks/chunks/{db2.js-BYr2lzQs.js → db2.js-CPqi0hcH.js} +2 -2
  93. package/build/server/chunks/chunks/{dsh-connection.js-D52KwDXm.js → dsh-connection.js-DlwhJZaV.js} +3 -3
  94. package/build/server/chunks/chunks/{exports.js-DMiPee3x.js → exports.js-DH_tjtdv.js} +4 -4
  95. package/build/server/chunks/chunks/git-probe.js-nfLEa58f.js +219 -0
  96. package/build/server/chunks/chunks/image-limits.js-CUdJ0f7r.js +41 -0
  97. package/build/server/chunks/chunks/{insight-config.js-BAitz0O1.js → insight-config.js-BwcV3Bct.js} +5 -159
  98. package/build/server/chunks/chunks/{internal.js-kXJJJomG.js → internal.js-CRfRCfoU.js} +6 -5
  99. package/build/server/chunks/chunks/{internal2.js-D-DAuSVh.js → internal2.js-BcS47nI-.js} +2 -2
  100. package/build/server/chunks/chunks/{image-limits.js-BMPZ55kJ.js → permission-state.js-yvwUSnug.js} +8 -41
  101. package/build/server/chunks/chunks/runtime.js-BPLc5RLR.js +854 -0
  102. package/build/server/chunks/chunks/{server.js-DoCd0fEo.js → server.js-11-pxAWV.js} +73 -2
  103. package/build/server/chunks/chunks/settings-document.js-BIwLIxnE.js +162 -0
  104. package/build/server/chunks/chunks/{shared.js-C4-Py8s_.js → shared.js-HQ0rfhm4.js} +4 -4
  105. package/build/server/chunks/chunks/{state.js-7BOeaoQB.js → state.js-BB7-MsQ0.js} +42 -10
  106. package/build/server/chunks/chunks/{utils.js-tOWCe9Wk.js → utils.js-CAdNO8Tu.js} +6 -6
  107. package/build/server/chunks/chunks/{watcher.js-CZl6B1Gm.js → watcher.js-CmpeTgh-.js} +4 -4
  108. package/build/server/chunks/entries/endpoints/api/a2a/_id_/{_server.ts.js-BiJNs-w9.js → _server.ts.js-D5AWBpBQ.js} +7 -6
  109. package/build/server/chunks/entries/endpoints/api/a2a/{_server.ts.js-DpYiPNfK.js → _server.ts.js-BZvM0qV8.js} +9 -8
  110. package/build/server/chunks/entries/endpoints/api/a2a/register/{_server.ts.js-hsrqtyai.js → _server.ts.js-CwQ8v1Gr.js} +9 -8
  111. package/build/server/chunks/entries/endpoints/api/config/{_server.ts.js-C22-pOYW.js → _server.ts.js-DRFbC3XB.js} +6 -5
  112. package/build/server/chunks/entries/endpoints/api/dsh/directory/{_server.ts.js-GB8GCnt9.js → _server.ts.js-1NUslX2J.js} +7 -6
  113. package/build/server/chunks/entries/endpoints/api/dsh/pick-directory/{_server.ts.js-1f1lp4p6.js → _server.ts.js-BaNBBHLR.js} +7 -6
  114. package/build/server/chunks/entries/endpoints/api/dsh/presets/{_server.ts.js-bQ6fWiaE.js → _server.ts.js-CW2NY_YQ.js} +7 -6
  115. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/attachment/{_server.ts.js-Dpn0vlL4.js → _server.ts.js-QA9zJsqt.js} +7 -6
  116. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/cancel/{_server.ts.js-BCKU6r0e.js → _server.ts.js-CVXZhV9H.js} +7 -6
  117. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/catalog/{_server.ts.js-B6CP7Ox-.js → _server.ts.js-Cit4Casr.js} +7 -6
  118. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/command/{_server.ts.js-CuIGYst7.js → _server.ts.js-CyjB1woG.js} +7 -6
  119. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/events/{_server.ts.js-BJk9GfEb.js → _server.ts.js-DllJ8vBI.js} +9 -7
  120. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/fork/{_server.ts.js-BRjJibko.js → _server.ts.js-BNnAmzy2.js} +7 -6
  121. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/goal/{_server.ts.js-Du0XmI7X.js → _server.ts.js-BM_jJMFG.js} +7 -6
  122. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/history/{_server.ts.js-BmxbonR_.js → _server.ts.js-qKiwUxSN.js} +7 -6
  123. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/models/{_server.ts.js-B03gh2aZ.js → _server.ts.js-CZ0zXTiV.js} +7 -6
  124. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/permission/{_server.ts.js-BO9Iy5Ki.js → _server.ts.js-3o3S3pHm.js} +7 -6
  125. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/prompt/{_server.ts.js-qr2peU-n.js → _server.ts.js-DsCnz_8J.js} +7 -6
  126. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/rename/{_server.ts.js-D4PIEynR.js → _server.ts.js-6QBc29c0.js} +7 -6
  127. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/respond/{_server.ts.js-CcBAtZWB.js → _server.ts.js-Cur_rwoa.js} +7 -6
  128. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/select-model/{_server.ts.js-CE1gTwwX.js → _server.ts.js-BBRIvxEV.js} +7 -6
  129. package/build/server/chunks/entries/endpoints/api/dsh/sessions/{_server.ts.js-GugaguYO.js → _server.ts.js-HXmuGYk_.js} +7 -6
  130. package/build/server/chunks/entries/endpoints/api/dsh/workspace-file/{_server.ts.js-D7ZCMRXo.js → _server.ts.js-BtF78EDX.js} +7 -6
  131. package/build/server/chunks/entries/endpoints/api/dsh/workspace-file-bytes/{_server.ts.js-BeLFfBNx.js → _server.ts.js-DaxAqI2r.js} +7 -6
  132. package/build/server/chunks/entries/endpoints/api/dsh/workspace-tree/{_server.ts.js-CUMrE1yT.js → _server.ts.js-Cp3JRhml.js} +7 -6
  133. package/build/server/chunks/entries/endpoints/api/dsh/workspaces/{_server.ts.js-CPTg8pND.js → _server.ts.js-DCHNOxOw.js} +7 -6
  134. package/build/server/chunks/entries/endpoints/api/dsh/workspaces/_workspaceId_/delete/{_server.ts.js-ikZ2NK35.js → _server.ts.js-CTCYuknC.js} +7 -6
  135. package/build/server/chunks/entries/endpoints/api/dsh/workspaces/_workspaceId_/rename/{_server.ts.js-DO-sihfI.js → _server.ts.js-B1O7CmG7.js} +7 -6
  136. package/build/server/chunks/entries/endpoints/api/prompts/_id_/{_server.ts.js-CtWIL8u1.js → _server.ts.js-CMAYot0u.js} +7 -6
  137. package/build/server/chunks/entries/endpoints/api/prompts/{_server.ts.js-CCV5F65b.js → _server.ts.js-Bk-I6Cmq.js} +7 -6
  138. package/build/server/chunks/entries/endpoints/api/prompts/use/{_server.ts.js-5zjPgL0k.js → _server.ts.js-CWdigZaS.js} +7 -6
  139. package/build/server/chunks/entries/endpoints/api/settings/{_server.ts.js-DGy6xjPE.js → _server.ts.js-BgZ3eon4.js} +6 -5
  140. package/build/server/chunks/entries/endpoints/api/workspace/file-write/_server.ts.js-CMDHM8Ts.js +109 -0
  141. package/build/server/chunks/entries/endpoints/api/workspace/git-events/_server.ts.js-DsrelTvu.js +295 -0
  142. package/build/server/chunks/entries/endpoints/api/workspace/git-file-head/_server.ts.js-Bjo1hSe3.js +87 -0
  143. package/build/server/chunks/entries/endpoints/api/workspace/git-map/_server.ts.js-kbPAnTV6.js +75 -0
  144. package/build/server/chunks/entries/endpoints/api/workspace/git-status/_server.ts.js-CGSk5JWn.js +80 -0
  145. package/build/server/chunks/entries/hooks.server.js-B7FsvqtT.js +307 -0
  146. package/build/server/chunks/entries/pages/_error.svelte.js-BVjBiEZD.js +183 -0
  147. package/build/server/chunks/entries/pages/{_page.server.ts.js-BGXwU4Ay.js → _page.server.ts.js-CNU4x-f1.js} +5 -4
  148. package/build/server/chunks/entries/pages/{_page.svelte.js-N0F4WBmN.js → _page.svelte.js-D6UC7cGf.js} +5212 -380
  149. package/build/server/chunks/{handler-DonVRS0X.js → handler-BKbAUWNh.js} +8 -8
  150. package/build/server/chunks/{index.js-BeG-TgOY.js → index.js-DNjzSibQ.js} +35 -35
  151. package/build/server/chunks/{manifest.js-CjHfy5rn.js → manifest.js-By1cjJ9N.js} +72 -44
  152. package/build/server/chunks/nodes/{0.js-DCyDo8-C.js → 0.js-BRdcKR1I.js} +3 -3
  153. package/build/server/chunks/nodes/1.js-nA42GX_X.js +9 -0
  154. package/build/server/chunks/nodes/2.js-C5a91sl7.js +26 -0
  155. package/package.json +5 -2
  156. package/build/client/_app/immutable/assets/0.DqFt8jIM.css +0 -2
  157. package/build/client/_app/immutable/assets/2.CybNpyHE.css +0 -1
  158. package/build/client/_app/immutable/chunks/Bp4uuUjI.js +0 -3
  159. package/build/client/_app/immutable/chunks/COnL3E7k.js +0 -1
  160. package/build/client/_app/immutable/chunks/CsHVnZCH.js +0 -1
  161. package/build/client/_app/immutable/chunks/D1qzYj9m.js +0 -1
  162. package/build/client/_app/immutable/chunks/DXeGLmed.js +0 -8
  163. package/build/client/_app/immutable/chunks/ESmLJICu.js +0 -1
  164. package/build/client/_app/immutable/chunks/PaZBB01u.js +0 -1
  165. package/build/client/_app/immutable/chunks/UmdltqoE.js +0 -1
  166. package/build/client/_app/immutable/chunks/Y2GhLLeG.js +0 -1
  167. package/build/client/_app/immutable/chunks/c6YVk1M6.js +0 -2
  168. package/build/client/_app/immutable/chunks/i0VQdJtv.js +0 -1
  169. package/build/client/_app/immutable/entry/app.BleekCCN.js +0 -2
  170. package/build/client/_app/immutable/entry/start.BpFQKF_D.js +0 -1
  171. package/build/client/_app/immutable/nodes/0.B_ZEZy7b.js +0 -1
  172. package/build/client/_app/immutable/nodes/1.CY-dc03C.js +0 -1
  173. package/build/client/_app/immutable/nodes/2.DbShW3bE.js +0 -69
  174. package/build/server/chunks/entries/endpoints/api/dsh/workspace-file/save/_server.ts.js-CO9iOVa4.js +0 -110
  175. package/build/server/chunks/entries/pages/_error.svelte.js-COiCqUkC.js +0 -41
  176. package/build/server/chunks/nodes/1.js-_W3O7q0J.js +0 -9
  177. package/build/server/chunks/nodes/2.js-BKYP_GxW.js +0 -24
@@ -0,0 +1,854 @@
1
+ //#region src/lib/paraglide/runtime.js
2
+ /** @type {any} */
3
+ var URLPattern = {};
4
+ /**
5
+ * The project's locales that have been specified in the settings.
6
+ *
7
+ * @example
8
+ * if (locales.includes(userSelectedLocale) === false) {
9
+ * throw new Error('Locale is not available');
10
+ * }
11
+ */
12
+ var locales = [
13
+ "en",
14
+ "zh",
15
+ "id"
16
+ ];
17
+ /** @type {string} */
18
+ var cookieName = "dsi.locale";
19
+ /** @type {number} */
20
+ var cookieMaxAge = 3456e4;
21
+ /**
22
+ * @type {Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>}
23
+ */
24
+ var strategy = [
25
+ "cookie",
26
+ "preferredLanguage",
27
+ "baseLocale"
28
+ ];
29
+ /**
30
+ * Route-level strategy overrides.
31
+ *
32
+ * `match` uses URLPattern syntax.
33
+ *
34
+ * @type {Array<{
35
+ * match: string;
36
+ * strategy?: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
37
+ * exclude?: boolean;
38
+ * }>}
39
+ */
40
+ var routeStrategies = [];
41
+ /**
42
+ * @typedef {{
43
+ * getStore(): {
44
+ * locale?: Locale,
45
+ * origin?: string,
46
+ * messageCalls?: Set<string>
47
+ * } | undefined,
48
+ * run: (store: { locale?: Locale, origin?: string, messageCalls?: Set<string>},
49
+ * cb: any) => any
50
+ * }} ParaglideAsyncLocalStorage
51
+ */
52
+ /**
53
+ * Server side async local storage that is set by `serverMiddleware()`.
54
+ *
55
+ * The variable is used to retrieve the locale and origin in a server-side
56
+ * rendering context without effecting other requests.
57
+ *
58
+ * @type {ParaglideAsyncLocalStorage | undefined}
59
+ */
60
+ var serverAsyncLocalStorage = void 0;
61
+ /**
62
+ * Returns the current server-side async local storage instance.
63
+ *
64
+ * Accessing the mutable value through a function keeps it observable when
65
+ * module interceptors wrap exported bindings and snapshot their initial value.
66
+ *
67
+ * @returns {ParaglideAsyncLocalStorage | undefined}
68
+ */
69
+ function getServerAsyncLocalStorage() {
70
+ return serverAsyncLocalStorage;
71
+ }
72
+ var isServer = typeof window === "undefined";
73
+ /**
74
+ * Sets the server side async local storage.
75
+ *
76
+ * The function is needed because the `runtime.js` file
77
+ * must define the `serverAsyncLocalStorage` variable to
78
+ * avoid a circular import between `runtime.js` and
79
+ * `server.js` files.
80
+ *
81
+ * @param {ParaglideAsyncLocalStorage | undefined} value
82
+ */
83
+ function overwriteServerAsyncLocalStorage(value) {
84
+ serverAsyncLocalStorage = value;
85
+ }
86
+ /** @type {any} */ globalThis.__paraglide = globalThis.__paraglide ?? {};
87
+ /** @type {any} */ globalThis.__paraglide.ssr = globalThis.__paraglide.ssr ?? {};
88
+ /**
89
+ * This is a fallback to get started with a custom
90
+ * strategy and avoid type errors.
91
+ *
92
+ * The implementation is overwritten
93
+ * by `overwriteGetLocale()` and `defineSetLocale()`.
94
+ *
95
+ * @type {Locale | undefined}
96
+ */
97
+ var _locale;
98
+ var localeInitiallySet = false;
99
+ /**
100
+ * Get the current locale.
101
+ *
102
+ * The locale is resolved using your configured strategies (URL, cookie, localStorage, etc.)
103
+ * in the order they are defined. In SSR contexts, the locale is retrieved from AsyncLocalStorage
104
+ * which is set by the `paraglideMiddleware()`.
105
+ *
106
+ * @see https://paraglidejs.com/strategy - Configure locale detection strategies
107
+ *
108
+ * @example
109
+ * if (getLocale() === 'de') {
110
+ * console.log('Germany 🇩🇪');
111
+ * } else if (getLocale() === 'nl') {
112
+ * console.log('Netherlands 🇳🇱');
113
+ * }
114
+ *
115
+ * @returns {Locale} The current locale.
116
+ */
117
+ var getLocale = () => {
118
+ if (serverAsyncLocalStorage) {
119
+ const locale = serverAsyncLocalStorage?.getStore()?.locale;
120
+ if (locale) return locale;
121
+ }
122
+ let strategyToUse = strategy;
123
+ if (!isServer && typeof window !== "undefined" && window.location?.href) strategyToUse = getStrategyForUrl(window.location.href);
124
+ const resolved = resolveLocaleWithStrategies(strategyToUse);
125
+ if (resolved) {
126
+ if (!localeInitiallySet) {
127
+ _locale = resolved;
128
+ localeInitiallySet = true;
129
+ setLocale(resolved, { reload: false });
130
+ }
131
+ return resolved;
132
+ }
133
+ throw new Error("No locale found. Read the docs https://paraglidejs.com/errors#no-locale-found");
134
+ };
135
+ /**
136
+ * Resolve locale for a given URL using route-aware strategies.
137
+ *
138
+ * @param {string | URL} url
139
+ * @returns {Locale}
140
+ */
141
+ function getLocaleForUrl(url) {
142
+ const resolved = resolveLocaleWithStrategies(getStrategyForUrl(url), typeof url === "string" ? url : url.href);
143
+ if (resolved) return resolved;
144
+ throw new Error("No locale found. Read the docs https://paraglidejs.com/errors#no-locale-found");
145
+ }
146
+ /**
147
+ * @param {typeof strategy} strategyToUse
148
+ * @param {string | undefined} urlForUrlStrategy
149
+ * @returns {Locale | undefined}
150
+ */
151
+ function resolveLocaleWithStrategies(strategyToUse, urlForUrlStrategy) {
152
+ /** @type {string | undefined} */
153
+ let locale;
154
+ for (const strat of strategyToUse) {
155
+ if (strat === "cookie") locale = extractLocaleFromCookie();
156
+ else if (strat === "baseLocale") locale = "en";
157
+ else if (strat === "preferredLanguage" && !isServer) locale = extractLocaleFromNavigator();
158
+ else if (isCustomStrategy(strat) && customClientStrategies.has(strat)) {
159
+ const handler = customClientStrategies.get(strat);
160
+ if (handler) {
161
+ const result = handler.getLocale();
162
+ if (result instanceof Promise) continue;
163
+ if (result !== void 0) return assertIsLocale(result);
164
+ }
165
+ }
166
+ const matchedLocale = toLocale(locale);
167
+ if (matchedLocale) return matchedLocale;
168
+ }
169
+ }
170
+ /**
171
+ * Navigates to the localized URL, or reloads the current page
172
+ *
173
+ * @param {string} [newLocation] The new location
174
+ */
175
+ var navigateOrReload = (newLocation) => {
176
+ window.location.reload();
177
+ };
178
+ /**
179
+ * @typedef {(newLocale: Locale, options?: { reload?: boolean }) => void | Promise<void>} SetLocaleFn
180
+ */
181
+ /**
182
+ * Set the locale.
183
+ *
184
+ * Updates the locale using your configured strategies (cookie, localStorage, URL, etc.).
185
+ * By default, this navigates the client to the localized URL or reloads the current
186
+ * document to reflect the new locale. `reload: false` is a narrow browser-only escape
187
+ * hatch for a fully client-rendered, non-URL-routed surface that owns its reactive
188
+ * updates and document state. It does not re-render the UI or update the document.
189
+ * Do not use it for normal locale pickers, URL-routed pages, or switching an SSR,
190
+ * SSG, or hydrated document. It is incompatible with per-locale builds.
191
+ *
192
+ * If any custom strategy's `setLocale` function is async, then this function
193
+ * will become async as well.
194
+ *
195
+ * @see https://paraglidejs.com/strategy
196
+ *
197
+ * @example
198
+ * setLocale('en');
199
+ *
200
+ * @example
201
+ * setLocale('en', { reload: false });
202
+ *
203
+ * @type {SetLocaleFn}
204
+ */
205
+ var setLocale = (newLocale, options) => {
206
+ const optionsWithDefaults = {
207
+ reload: true,
208
+ ...options
209
+ };
210
+ /** @type {Locale | undefined} */
211
+ let currentLocale;
212
+ try {
213
+ currentLocale = getLocale();
214
+ } catch {}
215
+ /** @type {Array<Promise<void>>} */
216
+ const customSetLocalePromises = [];
217
+ let strategyToUse = strategy;
218
+ if (!isServer && typeof window !== "undefined" && window.location?.href) strategyToUse = getStrategyForUrl(window.location.href);
219
+ for (const strat of strategyToUse) if (strat === "cookie") {
220
+ if (isServer || typeof document === "undefined" || typeof window === "undefined") continue;
221
+ const cookieString = `${cookieName}=${newLocale}; path=/; max-age=${cookieMaxAge}`;
222
+ document.cookie = cookieString;
223
+ clearLocaleCookieCache();
224
+ } else if (strat === "baseLocale") continue;
225
+ else if (isCustomStrategy(strat) && customClientStrategies.has(strat)) {
226
+ const handler = customClientStrategies.get(strat);
227
+ if (handler) {
228
+ let result = handler.setLocale(newLocale);
229
+ if (result instanceof Promise) {
230
+ result = result.catch((error) => {
231
+ throw new Error(`Custom strategy "${strat}" setLocale failed.`, { cause: error });
232
+ });
233
+ customSetLocalePromises.push(result);
234
+ }
235
+ }
236
+ }
237
+ const runReload = () => {
238
+ if (!isServer && optionsWithDefaults.reload && window.location && newLocale !== currentLocale) navigateOrReload();
239
+ };
240
+ if (customSetLocalePromises.length) return Promise.all(customSetLocalePromises).then(() => {
241
+ runReload();
242
+ });
243
+ runReload();
244
+ };
245
+ /**
246
+ * The origin of the current URL.
247
+ *
248
+ * Defaults to "http://example.com" in non-browser environments. If this
249
+ * behavior is not desired, the implementation can be overwritten
250
+ * by `overwriteGetUrlOrigin()`.
251
+ *
252
+ * @type {() => string}
253
+ */
254
+ var getUrlOrigin = () => {
255
+ if (serverAsyncLocalStorage) return serverAsyncLocalStorage.getStore()?.origin ?? "http://fallback.com";
256
+ else if (typeof window !== "undefined") return window.location.origin;
257
+ return "http://fallback.com";
258
+ };
259
+ /**
260
+ * Coerces a locale-like string to the canonical locale value used by the runtime.
261
+ *
262
+ * @param {unknown} value
263
+ * @returns {Locale | undefined}
264
+ */
265
+ function toLocale(value) {
266
+ if (typeof value !== "string") return;
267
+ const lowerValue = value.toLowerCase();
268
+ for (const locale of locales) if (locale.toLowerCase() === lowerValue) return locale;
269
+ }
270
+ /**
271
+ * Asserts that the input can be normalized to a locale.
272
+ *
273
+ * @param {unknown} input - The input to check.
274
+ * @returns {Locale} The input normalized to a Locale.
275
+ * @throws {Error} If the input is not a locale.
276
+ */
277
+ function assertIsLocale(input) {
278
+ const locale = toLocale(input);
279
+ if (locale) return locale;
280
+ throw new Error(`Invalid locale: ${input}. Expected one of: ${locales.join(", ")}`);
281
+ }
282
+ /**
283
+ * Applies the configured trailing slash policy to a URL.
284
+ *
285
+ * The root pathname always remains `/`. Query parameters and hashes are not
286
+ * modified.
287
+ *
288
+ * @param {URL} url
289
+ * @returns {URL}
290
+ */
291
+ function normalizeTrailingSlash(url) {
292
+ return url;
293
+ }
294
+ /**
295
+ * Matches a canonical URL while allowing configured patterns to retain their
296
+ * existing trailing slash style.
297
+ *
298
+ * @param {URLPattern} pattern
299
+ * @param {URL} url
300
+ * @returns {any}
301
+ */
302
+ function execUrlPattern(pattern, url) {
303
+ return pattern.exec(url.href);
304
+ }
305
+ /**
306
+ * Extracts a locale from a request using the provided strategy order.
307
+ *
308
+ * @param {Request} request
309
+ * @param {typeof strategy} strategies
310
+ * @param {string | URL} [url]
311
+ * @returns {Locale}
312
+ */
313
+ var extractLocaleFromRequestWithStrategies = (request, strategies, url = request.url) => {
314
+ resolveEffectiveRequestUrl(request, url);
315
+ /** @type {string|undefined} */
316
+ let locale;
317
+ for (const strat of strategies) {
318
+ if (strat === "cookie") {
319
+ const cookiePrefix = "dsi.locale=";
320
+ locale = request.headers.get("cookie")?.split(";").map((c) => c.trim()).find((c) => c.startsWith(cookiePrefix))?.slice(11);
321
+ } else if (strat === "preferredLanguage") locale = extractLocaleFromHeader(request);
322
+ else if (strat === "globalVariable") locale = _locale;
323
+ else if (strat === "baseLocale") return "en";
324
+ else if (strat === "localStorage") continue;
325
+ else if (isCustomStrategy(strat)) continue;
326
+ const matchedLocale = toLocale(locale);
327
+ if (matchedLocale) return matchedLocale;
328
+ }
329
+ throw new Error("No locale found. There is an error in your strategy. Try adding 'baseLocale' as the very last strategy. Read more here https://paraglidejs.com/errors#no-locale-found");
330
+ };
331
+ /**
332
+ * @param {Request} request
333
+ * @param {string | URL | undefined} effectiveRequestUrl
334
+ * @returns {URL}
335
+ */
336
+ function resolveEffectiveRequestUrl(request, effectiveRequestUrl = request.url) {
337
+ if (effectiveRequestUrl instanceof URL) return new URL(effectiveRequestUrl.href);
338
+ return new URL(effectiveRequestUrl, request.url);
339
+ }
340
+ /**
341
+ * Asynchronously extracts a locale from a request.
342
+ *
343
+ * This function supports async custom server strategies, unlike the synchronous
344
+ * `extractLocaleFromRequest`. Use this function when you have custom server strategies
345
+ * that need to perform asynchronous operations (like database calls) in their getLocale method.
346
+ *
347
+ * The function first processes any custom server strategies asynchronously, then falls back
348
+ * to the synchronous `extractLocaleFromRequest` for all other strategies.
349
+ *
350
+ * @see {@link https://github.com/opral/inlang-paraglide-js/issues/527#issuecomment-2978151022}
351
+ *
352
+ * @example
353
+ * // Basic usage
354
+ * const locale = await extractLocaleFromRequestAsync(request);
355
+ *
356
+ * @example
357
+ * // With custom async server strategy
358
+ * defineCustomServerStrategy("custom-database", {
359
+ * getLocale: async (request) => {
360
+ * const userId = extractUserIdFromRequest(request);
361
+ * return await getUserLocaleFromDatabase(userId);
362
+ * }
363
+ * });
364
+ *
365
+ * const locale = await extractLocaleFromRequestAsync(request);
366
+ *
367
+ * @param {Request} request - The request object to extract the locale from.
368
+ * @param {{ effectiveRequestUrl?: string | URL }} [options] - Effective request URL to use for route matching and locale detection with the URL strategy.
369
+ * @returns {Promise<Locale>} The extracted locale.
370
+ */
371
+ var extractLocaleFromRequestAsync = async (request, options = {}) => {
372
+ /** @type {string|undefined} */
373
+ let locale;
374
+ const effectiveRequestUrl = resolveEffectiveRequestUrlFromRequestAsync(request, options.effectiveRequestUrl);
375
+ const strategy = getStrategyForUrl(effectiveRequestUrl);
376
+ for (const strat of strategy) if (isCustomStrategy(strat) && customServerStrategies.has(strat)) {
377
+ const handler = customServerStrategies.get(strat);
378
+ if (handler)
379
+ /** @type {string|undefined} */
380
+ locale = await handler.getLocale(request);
381
+ const matchedLocale = toLocale(locale);
382
+ if (matchedLocale) return matchedLocale;
383
+ }
384
+ return extractLocaleFromRequestWithStrategies(request, strategy, effectiveRequestUrl);
385
+ };
386
+ /**
387
+ * @param {Request} request
388
+ * @param {string | URL | undefined} effectiveRequestUrl
389
+ * @returns {URL}
390
+ */
391
+ function resolveEffectiveRequestUrlFromRequestAsync(request, effectiveRequestUrl = request.url) {
392
+ if (effectiveRequestUrl instanceof URL) return new URL(effectiveRequestUrl.href);
393
+ return new URL(effectiveRequestUrl, request.url);
394
+ }
395
+ var cookieNamePattern = cookieName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
396
+ var localeCookiePattern = new RegExp(`(?:^|;\\s*)${cookieNamePattern}=([^;]*)`);
397
+ var noCachedLocale = Symbol();
398
+ /** @type {Locale | undefined | typeof noCachedLocale} */
399
+ var cachedLocaleFromCookie = noCachedLocale;
400
+ /**
401
+ * Clears the cached locale from `document.cookie`.
402
+ */
403
+ function clearLocaleCookieCache() {
404
+ cachedLocaleFromCookie = noCachedLocale;
405
+ }
406
+ function scheduleLocaleCookieCacheClear() {
407
+ if (typeof queueMicrotask === "function") queueMicrotask(clearLocaleCookieCache);
408
+ else Promise.resolve().then(clearLocaleCookieCache);
409
+ }
410
+ /**
411
+ * Extracts a cookie from the document.
412
+ *
413
+ * Will return undefined if the document is not available or if the cookie is not set.
414
+ * The `document` object is not available in server-side rendering, so this function should not be called in that context.
415
+ *
416
+ * @returns {Locale | undefined}
417
+ */
418
+ function extractLocaleFromCookie() {
419
+ if (typeof document === "undefined") return;
420
+ if (cachedLocaleFromCookie !== noCachedLocale) return cachedLocaleFromCookie;
421
+ const locale = document.cookie.match(localeCookiePattern)?.[1];
422
+ cachedLocaleFromCookie = toLocale(locale);
423
+ scheduleLocaleCookieCacheClear();
424
+ return cachedLocaleFromCookie;
425
+ }
426
+ /**
427
+ * Extracts a locale from the accept-language header.
428
+ *
429
+ * Use the function on the server to extract the locale
430
+ * from the accept-language header that is sent by the client.
431
+ *
432
+ * @example
433
+ * const locale = extractLocaleFromHeader(request);
434
+ *
435
+ * @param {Request} request - The request object to extract the locale from.
436
+ * @returns {Locale | undefined} The negotiated preferred language.
437
+ */
438
+ function extractLocaleFromHeader(request) {
439
+ const acceptLanguageHeader = request.headers.get("accept-language");
440
+ if (acceptLanguageHeader) {
441
+ const languages = acceptLanguageHeader.split(",").map((lang) => {
442
+ const [tag, q = "1"] = lang.trim().split(";q=");
443
+ return {
444
+ fullTag: tag,
445
+ baseTag: tag?.split("-")[0],
446
+ q: Number(q)
447
+ };
448
+ }).sort((a, b) => b.q - a.q);
449
+ for (const lang of languages) {
450
+ const fullLocale = toLocale(lang.fullTag);
451
+ if (fullLocale) return fullLocale;
452
+ const baseLocale = toLocale(lang.baseTag);
453
+ if (baseLocale) return baseLocale;
454
+ }
455
+ return;
456
+ }
457
+ }
458
+ /**
459
+ * Negotiates a preferred language from navigator.languages.
460
+ *
461
+ * Use the function on the client to extract the locale
462
+ * from the navigator.languages array.
463
+ *
464
+ * @example
465
+ * const locale = extractLocaleFromNavigator();
466
+ *
467
+ * @returns {Locale | undefined}
468
+ */
469
+ function extractLocaleFromNavigator() {
470
+ if (!navigator?.languages?.length) return;
471
+ const languages = navigator.languages.map((lang) => ({
472
+ fullTag: lang,
473
+ baseTag: lang.split("-")[0]
474
+ }));
475
+ for (const lang of languages) {
476
+ const fullLocale = toLocale(lang.fullTag);
477
+ if (fullLocale) return fullLocale;
478
+ const baseLocale = toLocale(lang.baseTag);
479
+ if (baseLocale) return baseLocale;
480
+ }
481
+ }
482
+ /**
483
+ * If extractLocaleFromUrl is called many times on the same page and the URL
484
+ * hasn't changed, we don't need to recompute it every time which can get expensive.
485
+ * We might use a LRU cache if needed, but for now storing only the last result is enough.
486
+ * https://github.com/opral/monorepo/pull/3575#discussion_r2066731243
487
+ */
488
+ /** @type {string|undefined} */
489
+ var cachedUrl;
490
+ /** @type {Locale|undefined} */
491
+ var cachedLocale;
492
+ /**
493
+ * Extracts the locale from a given URL using native URLPattern.
494
+ *
495
+ * The built-in default `/:locale/...` routing is case-insensitive because it
496
+ * canonicalizes the first path segment with `toLocale()`. Custom `urlPatterns`
497
+ * keep URLPattern's normal exact matching semantics for path segments.
498
+ *
499
+ * @param {URL|string} url - The full URL from which to extract the locale.
500
+ * @returns {Locale|undefined} The extracted locale, or undefined if no locale is found.
501
+ */
502
+ function extractLocaleFromUrl(url) {
503
+ const urlString = typeof url === "string" ? url : url.href;
504
+ if (cachedUrl === urlString) return cachedLocale;
505
+ /** @type {Locale | undefined} */
506
+ let result;
507
+ result = defaultUrlPatternExtractLocale(normalizeTrailingSlash(typeof url === "string" ? new URL(url, "http://example.com") : new URL(url)));
508
+ cachedUrl = urlString;
509
+ cachedLocale = result;
510
+ return result;
511
+ }
512
+ /**
513
+ * https://github.com/opral/inlang-paraglide-js/issues/381
514
+ *
515
+ * @param {URL | string} url - The full URL from which to extract the locale.
516
+ * @returns {Locale | undefined} The extracted locale, or undefined if no locale is found.
517
+ */
518
+ function defaultUrlPatternExtractLocale(url) {
519
+ return toLocale(new URL(url, "http://example.com").pathname.split("/").filter(Boolean)[0]) || "en";
520
+ }
521
+ /**
522
+ * Lower-level URL localization function, primarily used in server contexts.
523
+ *
524
+ * This function is designed for server-side usage where you need precise control
525
+ * over URL localization, such as in middleware or request handlers. It works with
526
+ * URL objects and always returns absolute URLs.
527
+ *
528
+ * For client-side UI components, use `localizeHref()` instead, which provides
529
+ * a more convenient API with relative paths and automatic locale detection.
530
+ *
531
+ * @see https://paraglidejs.com/i18n-routing
532
+ *
533
+ * @example
534
+ * ```typescript
535
+ * // Server middleware example
536
+ * app.use((req, res, next) => {
537
+ * const url = new URL(req.url, `${req.protocol}://${req.headers.host}`);
538
+ * const localized = localizeUrl(url, { locale: "de" });
539
+ *
540
+ * if (localized.href !== url.href) {
541
+ * return res.redirect(localized.href);
542
+ * }
543
+ * next();
544
+ * });
545
+ * ```
546
+ *
547
+ * @example
548
+ * ```typescript
549
+ * // Using with URL patterns
550
+ * const url = new URL("https://example.com/about");
551
+ * localizeUrl(url, { locale: "de" });
552
+ * // => URL("https://example.com/de/about")
553
+ *
554
+ * // Using with domain-based localization
555
+ * const url = new URL("https://example.com/store");
556
+ * localizeUrl(url, { locale: "de" });
557
+ * // => URL("https://de.example.com/store")
558
+ * ```
559
+ *
560
+ * @param {string | URL} url - The URL to localize. If string, must be absolute.
561
+ * @param {object} [options] - Options for localization
562
+ * @param {Locale} [options.locale] - Target locale. If not provided, uses getLocale()
563
+ * @returns {URL} The localized URL, always absolute
564
+ */
565
+ function localizeUrl(url, options) {
566
+ return localizeUrlDefaultPattern(url, options?.locale ? assertIsLocale(options?.locale) : getLocale());
567
+ }
568
+ /**
569
+ * https://github.com/opral/inlang-paraglide-js/issues/381
570
+ *
571
+ * @param {string | URL} url
572
+ * @param {Locale} locale
573
+ * @returns {URL}
574
+ */
575
+ function localizeUrlDefaultPattern(url, locale) {
576
+ const urlObj = normalizeTrailingSlash(typeof url === "string" ? new URL(url, getUrlOrigin()) : new URL(url));
577
+ if (extractLocaleFromUrl(urlObj) === locale) return normalizeTrailingSlash(urlObj);
578
+ const pathSegments = urlObj.pathname.split("/").filter(Boolean);
579
+ if (pathSegments.length > 0 && toLocale(pathSegments[0])) pathSegments.shift();
580
+ if (locale === "en") urlObj.pathname = "/" + pathSegments.join("/");
581
+ else urlObj.pathname = "/" + locale + "/" + pathSegments.join("/");
582
+ return normalizeTrailingSlash(urlObj);
583
+ }
584
+ /**
585
+ * Low-level URL de-localization function, primarily used in server contexts.
586
+ *
587
+ * This function is designed for server-side usage where you need precise control
588
+ * over URL de-localization, such as in middleware or request handlers. It works with
589
+ * URL objects and always returns absolute URLs.
590
+ *
591
+ * For client-side UI components, use `deLocalizeHref()` instead, which provides
592
+ * a more convenient API with relative paths.
593
+ *
594
+ * @see https://paraglidejs.com/i18n-routing
595
+ *
596
+ * @example
597
+ * ```typescript
598
+ * // Server middleware example
599
+ * app.use((req, res, next) => {
600
+ * const url = new URL(req.url, `${req.protocol}://${req.headers.host}`);
601
+ * const baseUrl = deLocalizeUrl(url);
602
+ *
603
+ * // Store the base URL for later use
604
+ * req.baseUrl = baseUrl;
605
+ * next();
606
+ * });
607
+ * ```
608
+ *
609
+ * @example
610
+ * ```typescript
611
+ * // Using with URL patterns
612
+ * const url = new URL("https://example.com/de/about");
613
+ * deLocalizeUrl(url); // => URL("https://example.com/about")
614
+ *
615
+ * // Using with domain-based localization
616
+ * const url = new URL("https://de.example.com/store");
617
+ * deLocalizeUrl(url); // => URL("https://example.com/store")
618
+ * ```
619
+ *
620
+ * @param {string | URL} url - The URL to de-localize. If string, must be absolute.
621
+ * @returns {URL} The de-localized URL, always absolute
622
+ */
623
+ function deLocalizeUrl(url) {
624
+ return deLocalizeUrlDefaultPattern(url);
625
+ }
626
+ /**
627
+ * De-localizes a URL using the default pattern (/:locale/*)
628
+ * @param {string|URL} url
629
+ * @returns {URL}
630
+ */
631
+ function deLocalizeUrlDefaultPattern(url) {
632
+ const urlObj = normalizeTrailingSlash(typeof url === "string" ? new URL(url, getUrlOrigin()) : new URL(url));
633
+ const pathSegments = urlObj.pathname.split("/").filter(Boolean);
634
+ if (pathSegments.length > 0 && toLocale(pathSegments[0])) urlObj.pathname = "/" + pathSegments.slice(1).join("/");
635
+ return normalizeTrailingSlash(urlObj);
636
+ }
637
+ /** @type {string | undefined} */
638
+ var cachedRouteStrategyUrl;
639
+ /** @type {{ match: string; strategy?: typeof strategy; exclude?: boolean } | undefined} */
640
+ var cachedRouteStrategy;
641
+ /**
642
+ * Match route policy against both the public URL and its canonical URL.
643
+ *
644
+ * The function is deliberately separate from variables.js: configuration is
645
+ * inert data, while canonicalization and route selection form a routing layer.
646
+ *
647
+ * @param {string | URL} url
648
+ * @returns {{ match: string; strategy?: typeof strategy; exclude?: boolean } | undefined}
649
+ */
650
+ function findMatchingRouteStrategy(url) {
651
+ if (routeStrategies.length === 0) return;
652
+ const urlString = typeof url === "string" ? url : url.href;
653
+ if (cachedRouteStrategyUrl === urlString) return cachedRouteStrategy;
654
+ const publicUrl = normalizeTrailingSlash(new URL(urlString, "http://example.com"));
655
+ const canonicalUrl = deLocalizeUrl(publicUrl);
656
+ const candidateUrls = canonicalUrl.href === publicUrl.href ? [publicUrl] : [publicUrl, canonicalUrl];
657
+ let match;
658
+ for (const candidateUrl of candidateUrls) {
659
+ for (const routeStrategy of routeStrategies) if (execUrlPattern(new URLPattern(routeStrategy.match, candidateUrl.href), candidateUrl)) {
660
+ match = routeStrategy;
661
+ break;
662
+ }
663
+ if (match) break;
664
+ }
665
+ cachedRouteStrategyUrl = urlString;
666
+ cachedRouteStrategy = match;
667
+ return match;
668
+ }
669
+ /**
670
+ * Returns the strategy to use for a specific URL.
671
+ *
672
+ * If no route strategy matches (or the matching rule is `exclude: true`),
673
+ * the global strategy is returned.
674
+ *
675
+ * @param {string | URL} url
676
+ * @returns {typeof strategy}
677
+ */
678
+ function getStrategyForUrl(url) {
679
+ const routeStrategy = findMatchingRouteStrategy(url);
680
+ if (routeStrategy && routeStrategy.exclude !== true && Array.isArray(routeStrategy.strategy)) return routeStrategy.strategy;
681
+ return strategy;
682
+ }
683
+ /**
684
+ * Returns whether the given URL is excluded from middleware i18n processing.
685
+ *
686
+ * @param {string | URL} url
687
+ * @returns {boolean}
688
+ */
689
+ function isExcludedByRouteStrategy(url) {
690
+ return findMatchingRouteStrategy(url)?.exclude === true;
691
+ }
692
+ /**
693
+ * @typedef {object} ShouldRedirectServerInput
694
+ * @property {Request} request
695
+ * @property {string | URL} [effectiveRequestUrl] - Effective request URL to use for route matching, locale detection with the URL strategy, and redirect targets.
696
+ * @property {Locale} [locale]
697
+ *
698
+ * @typedef {object} ShouldRedirectClientInput
699
+ * @property {undefined} [request]
700
+ * @property {string | URL} [url]
701
+ * @property {Locale} [locale]
702
+ *
703
+ * @typedef {ShouldRedirectServerInput | ShouldRedirectClientInput} ShouldRedirectInput
704
+ *
705
+ * @typedef {object} ShouldRedirectResult
706
+ * @property {boolean} shouldRedirect - Indicates whether the consumer should perform a redirect.
707
+ * @property {Locale} locale - Locale resolved using the configured strategies.
708
+ * @property {URL | undefined} redirectUrl - Destination URL when a redirect is required.
709
+ */
710
+ /**
711
+ * Determines whether a redirect is required to align the current URL with the active locale.
712
+ *
713
+ * This helper mirrors the logic that powers `paraglideMiddleware`, but works in both server
714
+ * and client environments. It evaluates the configured strategies in order, computes the
715
+ * canonical localized URL, and reports when the current URL does not match.
716
+ *
717
+ * When called in the browser without arguments, the current `window.location.href` is used.
718
+ *
719
+ * @see https://paraglidejs.com/i18n-routing#redirects
720
+ *
721
+ * @example
722
+ * // Client side usage (e.g. TanStack Router beforeLoad hook)
723
+ * async function beforeLoad({ location }) {
724
+ * const decision = await shouldRedirect({ url: location.href });
725
+ *
726
+ * if (decision.shouldRedirect) {
727
+ * throw redirect({ to: decision.redirectUrl.href });
728
+ * }
729
+ * }
730
+ *
731
+ * @example
732
+ * // Server side usage with a Request
733
+ * export async function handle(request) {
734
+ * const decision = await shouldRedirect({ request });
735
+ *
736
+ * if (decision.shouldRedirect) {
737
+ * return Response.redirect(decision.redirectUrl, 307);
738
+ * }
739
+ *
740
+ * return render(request, decision.locale);
741
+ * }
742
+ *
743
+ * @example
744
+ * // Server side usage behind a proxy where request.url is not public-facing
745
+ * export async function handle(request) {
746
+ * const effectiveRequestUrl = new URL(request.url);
747
+ * effectiveRequestUrl.protocol = "https:";
748
+ * effectiveRequestUrl.host = "example.com";
749
+ *
750
+ * const decision = await shouldRedirect({
751
+ * request,
752
+ * effectiveRequestUrl,
753
+ * });
754
+ *
755
+ * if (decision.shouldRedirect) {
756
+ * return Response.redirect(decision.redirectUrl, 307);
757
+ * }
758
+ * }
759
+ *
760
+ * @param {ShouldRedirectInput} [input]
761
+ * @returns {Promise<ShouldRedirectResult>}
762
+ */
763
+ async function shouldRedirect(input = {}) {
764
+ const currentUrl = resolveUrl(input);
765
+ const locale = await resolveLocale(input, currentUrl);
766
+ const strategy = getStrategyForUrl(currentUrl.href);
767
+ if (isExcludedByRouteStrategy(currentUrl.href) || !strategy.includes("url")) return {
768
+ shouldRedirect: false,
769
+ locale,
770
+ redirectUrl: void 0
771
+ };
772
+ const localizedUrl = localizeUrl(currentUrl.href, { locale });
773
+ const shouldRedirectToLocalizedUrl = normalizeUrl(localizedUrl.href) !== normalizeUrl(currentUrl.href);
774
+ return {
775
+ shouldRedirect: shouldRedirectToLocalizedUrl,
776
+ locale,
777
+ redirectUrl: shouldRedirectToLocalizedUrl ? localizedUrl : void 0
778
+ };
779
+ }
780
+ /**
781
+ * Resolves the locale either from the provided input or by using the configured strategies.
782
+ *
783
+ * @param {ShouldRedirectInput} input
784
+ * @param {URL} currentUrl
785
+ * @returns {Promise<Locale>}
786
+ */
787
+ async function resolveLocale(input, currentUrl) {
788
+ const locale = toLocale(input.locale);
789
+ if (locale) return locale;
790
+ if (input.request) return extractLocaleFromRequestAsync(input.request, { effectiveRequestUrl: currentUrl });
791
+ if ("url" in input && typeof input.url !== "undefined") return getLocaleForUrl(currentUrl.href);
792
+ return getLocale();
793
+ }
794
+ /**
795
+ * Resolves the current URL from the provided input or runtime context.
796
+ *
797
+ * @param {ShouldRedirectInput} input
798
+ * @returns {URL}
799
+ */
800
+ function resolveUrl(input) {
801
+ if ("effectiveRequestUrl" in input && input.effectiveRequestUrl instanceof URL) return new URL(input.effectiveRequestUrl.href);
802
+ if ("effectiveRequestUrl" in input && typeof input.effectiveRequestUrl === "string") return new URL(input.effectiveRequestUrl, input.request ? input.request.url : getUrlOrigin());
803
+ if (input.request) return new URL(input.request.url);
804
+ if ("url" in input && input.url instanceof URL) return new URL(input.url.href);
805
+ if ("url" in input && typeof input.url === "string") return new URL(input.url, getUrlOrigin());
806
+ if (typeof window !== "undefined" && window?.location?.href) return new URL(window.location.href);
807
+ throw new Error("shouldRedirect() requires either a request, an absolute URL, or must run in a browser environment.");
808
+ }
809
+ /**
810
+ * Normalize url for comparison by stripping the trailing slash.
811
+ *
812
+ * @param {string} url
813
+ * @returns {string}
814
+ */
815
+ function normalizeUrl(url) {
816
+ const urlObj = new URL(url);
817
+ urlObj.pathname = urlObj.pathname.replace(/\/$/, "");
818
+ return urlObj.href;
819
+ }
820
+ /**
821
+ * @typedef {"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage"} BuiltInStrategy
822
+ */
823
+ /**
824
+ * @typedef {`custom_${string}`} CustomStrategy
825
+ */
826
+ /**
827
+ * @typedef {BuiltInStrategy | CustomStrategy} Strategy
828
+ */
829
+ /**
830
+ * @typedef {Array<Strategy>} Strategies
831
+ */
832
+ /**
833
+ * @typedef {{ getLocale: (request?: Request) => Promise<string | undefined> | (string | undefined) }} CustomServerStrategyHandler
834
+ */
835
+ /**
836
+ * @typedef {{ getLocale: () => Promise<string|undefined> | (string | undefined), setLocale: (locale: string) => Promise<void> | void }} CustomClientStrategyHandler
837
+ */
838
+ /** @type {Map<string, CustomServerStrategyHandler>} */
839
+ var customServerStrategies = /* @__PURE__ */ new Map();
840
+ /** @type {Map<string, CustomClientStrategyHandler>} */
841
+ var customClientStrategies = /* @__PURE__ */ new Map();
842
+ /**
843
+ * Checks if the given strategy is a custom strategy.
844
+ *
845
+ * @param {unknown} strategy The name of the custom strategy to validate.
846
+ * Must be a string that starts with "custom-" followed by alphanumeric characters, hyphens, or underscores.
847
+ * @returns {boolean} Returns true if it is a custom strategy, false otherwise.
848
+ */
849
+ function isCustomStrategy(strategy) {
850
+ return typeof strategy === "string" && /^custom-[A-Za-z0-9_-]+$/.test(strategy);
851
+ }
852
+
853
+ export { getStrategyForUrl as a, shouldRedirect as b, getLocale as c, deLocalizeUrl as d, getServerAsyncLocalStorage as g, isExcludedByRouteStrategy as i, overwriteServerAsyncLocalStorage as o, serverAsyncLocalStorage as s };
854
+ //# sourceMappingURL=runtime.js-BPLc5RLR.js.map