rune-lab 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (433) hide show
  1. package/.gitignore +12 -0
  2. package/README.md +3 -3
  3. package/deno.json +50 -0
  4. package/justfile +5 -0
  5. package/package.json +2 -79
  6. package/scripts/build_pkg.ts +51 -0
  7. package/scripts/ci.just +26 -0
  8. package/scripts/deploy.just +21 -0
  9. package/scripts/dev.just +4 -0
  10. package/scripts/inject.just +72 -0
  11. package/src/RuneProvider.svelte +105 -0
  12. package/src/i18n/message-resolver.test.ts +103 -0
  13. package/src/i18n/message-resolver.ts +89 -0
  14. package/src/i18n/project.inlang/settings.json +26 -0
  15. package/src/i18n/translations/ar.json +89 -0
  16. package/src/i18n/translations/de.json +89 -0
  17. package/src/i18n/translations/en.json +89 -0
  18. package/src/i18n/translations/es.json +89 -0
  19. package/src/i18n/translations/fr.json +89 -0
  20. package/src/i18n/translations/hi.json +89 -0
  21. package/src/i18n/translations/it.json +89 -0
  22. package/src/i18n/translations/ja.json +89 -0
  23. package/src/i18n/translations/ko.json +89 -0
  24. package/src/i18n/translations/pt.json +89 -0
  25. package/src/i18n/translations/ru.json +89 -0
  26. package/src/i18n/translations/vi.json +89 -0
  27. package/src/i18n/translations/zh.json +89 -0
  28. package/src/kernel/deno.json +5 -0
  29. package/src/kernel/src/actions/portal.ts +41 -0
  30. package/src/kernel/src/actions/shortcut-listener.ts +50 -0
  31. package/src/kernel/src/context/app.svelte.ts +98 -0
  32. package/src/kernel/src/context/context.ts +31 -0
  33. package/src/kernel/src/context/stores.svelte.ts +96 -0
  34. package/src/kernel/src/context/types.ts +110 -0
  35. package/src/kernel/src/context/useRuneLab.ts +38 -0
  36. package/src/kernel/src/mod.ts +13 -0
  37. package/src/kernel/src/persistence/createConfigStore.svelte.ts +120 -0
  38. package/src/kernel/src/persistence/drivers.test.ts +95 -0
  39. package/src/kernel/src/persistence/drivers.ts +77 -0
  40. package/src/kernel/src/persistence/provider.test.ts +58 -0
  41. package/{dist/state/persistence/provider.js → src/kernel/src/persistence/provider.ts} +29 -14
  42. package/src/kernel/src/persistence/types.ts +19 -0
  43. package/src/kernel/src/persistence/usePersistence.ts +9 -0
  44. package/src/kernel/src/registry/mod.ts +221 -0
  45. package/src/kernel/src/registry/registry.test.ts +162 -0
  46. package/src/kernel/src/tokens/props.ts +94 -0
  47. package/src/mod.ts +10 -0
  48. package/src/runes/layout/deno.json +5 -0
  49. package/src/runes/layout/src/APP_CONFIGURATIONS.ts +56 -0
  50. package/{dist/ui/features/config → src/runes/layout/src}/AppSettingSelector.svelte +1 -1
  51. package/{dist/ui/layout → src/runes/layout/src}/ConnectedNavigationPanel.svelte +1 -1
  52. package/{dist/ui/layout → src/runes/layout/src}/ConnectedWorkspaceStrip.svelte +1 -1
  53. package/src/runes/layout/src/Icon.svelte +7 -0
  54. package/{dist/ui/features/config → src/runes/layout/src}/LanguageSelector.svelte +7 -5
  55. package/{dist/ui/layout → src/runes/layout/src}/NavigationPanel.svelte +1 -4
  56. package/{dist/ui/features/config → src/runes/layout/src}/ResourceSelector.svelte +3 -5
  57. package/{dist/ui/features/config → src/runes/layout/src}/ThemeSelector.svelte +2 -2
  58. package/{dist/ui/layout → src/runes/layout/src}/WorkspaceLayout.svelte +6 -4
  59. package/{dist/ui/layout → src/runes/layout/src}/WorkspaceStrip.svelte +1 -1
  60. package/src/runes/layout/src/connection-factory.ts +95 -0
  61. package/src/runes/layout/src/language.svelte.ts +44 -0
  62. package/src/runes/layout/src/mod.ts +71 -0
  63. package/src/runes/layout/src/store.svelte.ts +142 -0
  64. package/src/runes/layout/src/theme.svelte.ts +73 -0
  65. package/src/runes/layout/src/types.ts +11 -0
  66. package/src/runes/palettes/deno.json +8 -0
  67. package/{dist/ui/features/command-palette → src/runes/palettes/src/commands}/CommandPalette.svelte +4 -4
  68. package/src/runes/palettes/src/commands/mod.ts +2 -0
  69. package/src/runes/palettes/src/commands/store.svelte.ts +80 -0
  70. package/src/runes/palettes/src/mod.ts +51 -0
  71. package/{dist/ui/components → src/runes/palettes/src/notifications}/Toaster.svelte +1 -2
  72. package/src/runes/palettes/src/notifications/bridge.ts +56 -0
  73. package/src/runes/palettes/src/notifications/mod.ts +4 -0
  74. package/src/runes/palettes/src/notifications/store.svelte.ts +58 -0
  75. package/{dist/ui/features → src/runes/palettes/src}/shortcuts/ShortcutPalette.svelte +4 -4
  76. package/src/runes/palettes/src/shortcuts/mod.ts +4 -0
  77. package/src/runes/palettes/src/shortcuts/store.svelte.ts +85 -0
  78. package/src/runes/palettes/src/shortcuts/types.ts +4 -0
  79. package/src/runes/palettes/src/shortcuts/useShortcuts.ts +85 -0
  80. package/src/runes/plugins/money/deno.json +8 -0
  81. package/{dist/ui/features/config → src/runes/plugins/money/src}/CurrencySelector.svelte +2 -2
  82. package/{dist/ui/components/money → src/runes/plugins/money/src}/MoneyDisplay.svelte +2 -2
  83. package/{dist/ui/components/money → src/runes/plugins/money/src}/MoneyInput.svelte +4 -8
  84. package/src/runes/plugins/money/src/currency.svelte.ts +95 -0
  85. package/src/runes/plugins/money/src/currency.test.ts +40 -0
  86. package/src/runes/plugins/money/src/exchange-rate.svelte.ts +176 -0
  87. package/src/runes/plugins/money/src/exchange-rate.test.ts +95 -0
  88. package/src/runes/plugins/money/src/mod.ts +79 -0
  89. package/src/runes/plugins/money/src/money-primitive.test.ts +217 -0
  90. package/src/runes/plugins/money/src/money-primitive.ts +220 -0
  91. package/src/runes/plugins/money/src/money.test.ts +183 -0
  92. package/src/runes/plugins/money/src/money.ts +382 -0
  93. package/src/runes/plugins/money/src/strategies.test.ts +143 -0
  94. package/{dist/core/exchange-rate/strategies.js → src/runes/plugins/money/src/strategies.ts} +45 -22
  95. package/src/runes/plugins/money/src/types.ts +27 -0
  96. package/src/runes/plugins/money/src/useMoney.ts +261 -0
  97. package/src/runes/plugins/money/src/useMoneyFilter.ts +132 -0
  98. package/tsconfig.json +41 -0
  99. package/vite.config.ts +44 -0
  100. package/dist/core/design-tokens/props.d.ts +0 -52
  101. package/dist/core/design-tokens/props.d.ts.map +0 -1
  102. package/dist/core/design-tokens/props.js +0 -34
  103. package/dist/core/exchange-rate/strategies.d.ts +0 -52
  104. package/dist/core/exchange-rate/strategies.d.ts.map +0 -1
  105. package/dist/core/index.d.ts +0 -9
  106. package/dist/core/index.d.ts.map +0 -1
  107. package/dist/core/index.js +0 -8
  108. package/dist/core/internal/message-resolver.d.ts +0 -42
  109. package/dist/core/internal/message-resolver.d.ts.map +0 -1
  110. package/dist/core/internal/message-resolver.js +0 -47
  111. package/dist/core/layout/types.d.ts +0 -60
  112. package/dist/core/layout/types.d.ts.map +0 -1
  113. package/dist/core/layout/types.js +0 -4
  114. package/dist/core/money/index.d.ts +0 -2
  115. package/dist/core/money/index.d.ts.map +0 -1
  116. package/dist/core/money/index.js +0 -2
  117. package/dist/core/money/money-primitive.d.ts +0 -101
  118. package/dist/core/money/money-primitive.d.ts.map +0 -1
  119. package/dist/core/money/money-primitive.js +0 -161
  120. package/dist/core/money/money.d.ts +0 -129
  121. package/dist/core/money/money.d.ts.map +0 -1
  122. package/dist/core/money/money.js +0 -250
  123. package/dist/core/persistence/types.d.ts +0 -18
  124. package/dist/core/persistence/types.d.ts.map +0 -1
  125. package/dist/core/persistence/types.js +0 -2
  126. package/dist/core/shortcuts/types.d.ts +0 -60
  127. package/dist/core/shortcuts/types.d.ts.map +0 -1
  128. package/dist/core/shortcuts/types.js +0 -4
  129. package/dist/index.d.ts +0 -6
  130. package/dist/index.js +0 -7
  131. package/dist/state/api.svelte.d.ts +0 -26
  132. package/dist/state/api.svelte.js +0 -65
  133. package/dist/state/app.svelte.d.ts +0 -48
  134. package/dist/state/app.svelte.js +0 -82
  135. package/dist/state/auth/index.d.ts +0 -2
  136. package/dist/state/auth/index.js +0 -2
  137. package/dist/state/auth/session.svelte.d.ts +0 -40
  138. package/dist/state/auth/session.svelte.js +0 -59
  139. package/dist/state/auth/types.d.ts +0 -30
  140. package/dist/state/auth/types.js +0 -3
  141. package/dist/state/cart.svelte.d.ts +0 -64
  142. package/dist/state/cart.svelte.js +0 -122
  143. package/dist/state/commands.svelte.d.ts +0 -46
  144. package/dist/state/commands.svelte.js +0 -62
  145. package/dist/state/composables/useMoney.d.ts +0 -31
  146. package/dist/state/composables/useMoney.js +0 -126
  147. package/dist/state/composables/useMoneyFilter.d.ts +0 -20
  148. package/dist/state/composables/useMoneyFilter.js +0 -81
  149. package/dist/state/composables/usePersistence.d.ts +0 -2
  150. package/dist/state/composables/usePersistence.js +0 -5
  151. package/dist/state/composables/useRuneLab.d.ts +0 -19
  152. package/dist/state/composables/useRuneLab.js +0 -30
  153. package/dist/state/composables/useShortcuts.d.ts +0 -33
  154. package/dist/state/composables/useShortcuts.js +0 -75
  155. package/dist/state/context.d.ts +0 -15
  156. package/dist/state/context.js +0 -16
  157. package/dist/state/createConfigStore.svelte.d.ts +0 -28
  158. package/dist/state/createConfigStore.svelte.js +0 -72
  159. package/dist/state/currency.svelte.d.ts +0 -32
  160. package/dist/state/currency.svelte.js +0 -96
  161. package/dist/state/currency.test.d.ts +0 -1
  162. package/dist/state/currency.test.js +0 -35
  163. package/dist/state/exchange-rate.svelte.d.ts +0 -43
  164. package/dist/state/exchange-rate.svelte.js +0 -145
  165. package/dist/state/exchange-rate.test.d.ts +0 -1
  166. package/dist/state/exchange-rate.test.js +0 -75
  167. package/dist/state/index.d.ts +0 -26
  168. package/dist/state/index.js +0 -32
  169. package/dist/state/language.svelte.d.ts +0 -57
  170. package/dist/state/language.svelte.js +0 -43
  171. package/dist/state/layout.svelte.d.ts +0 -49
  172. package/dist/state/layout.svelte.js +0 -108
  173. package/dist/state/persistence/drivers.d.ts +0 -12
  174. package/dist/state/persistence/drivers.js +0 -75
  175. package/dist/state/persistence/drivers.test.d.ts +0 -1
  176. package/dist/state/persistence/drivers.test.js +0 -79
  177. package/dist/state/persistence/provider.d.ts +0 -23
  178. package/dist/state/persistence/provider.test.d.ts +0 -1
  179. package/dist/state/persistence/provider.test.js +0 -51
  180. package/dist/state/registry/index.d.ts +0 -44
  181. package/dist/state/registry/index.js +0 -58
  182. package/dist/state/registry/registry.test.d.ts +0 -1
  183. package/dist/state/registry/registry.test.js +0 -112
  184. package/dist/state/registry/types.d.ts +0 -20
  185. package/dist/state/registry/types.js +0 -3
  186. package/dist/state/shortcuts.svelte.d.ts +0 -121
  187. package/dist/state/shortcuts.svelte.js +0 -222
  188. package/dist/state/theme.svelte.d.ts +0 -15
  189. package/dist/state/theme.svelte.js +0 -92
  190. package/dist/state/toast-bridge.d.ts +0 -29
  191. package/dist/state/toast-bridge.js +0 -43
  192. package/dist/state/toast.svelte.d.ts +0 -27
  193. package/dist/state/toast.svelte.js +0 -43
  194. package/dist/ui/actions/portal.d.ts +0 -7
  195. package/dist/ui/actions/portal.js +0 -32
  196. package/dist/ui/components/ApiMonitor.svelte +0 -162
  197. package/dist/ui/components/ApiMonitor.svelte.d.ts +0 -3
  198. package/dist/ui/components/Icon.svelte +0 -108
  199. package/dist/ui/components/Icon.svelte.d.ts +0 -14
  200. package/dist/ui/components/Kyntharil.svelte +0 -48
  201. package/dist/ui/components/Kyntharil.svelte.d.ts +0 -6
  202. package/dist/ui/components/RuneProvider.svelte +0 -218
  203. package/dist/ui/components/RuneProvider.svelte.d.ts +0 -49
  204. package/dist/ui/components/Toaster.svelte.d.ts +0 -18
  205. package/dist/ui/components/money/MoneyDisplay.svelte.d.ts +0 -33
  206. package/dist/ui/components/money/MoneyDisplay.svelte.test.d.ts +0 -1
  207. package/dist/ui/components/money/MoneyDisplay.svelte.test.js +0 -117
  208. package/dist/ui/components/money/MoneyInput.svelte.d.ts +0 -34
  209. package/dist/ui/components/money/index.d.ts +0 -2
  210. package/dist/ui/components/money/index.js +0 -3
  211. package/dist/ui/components/user/UserAvatar.svelte +0 -66
  212. package/dist/ui/components/user/UserAvatar.svelte.d.ts +0 -13
  213. package/dist/ui/components/user/UserProfile.svelte +0 -79
  214. package/dist/ui/components/user/UserProfile.svelte.d.ts +0 -17
  215. package/dist/ui/components/user/index.d.ts +0 -2
  216. package/dist/ui/components/user/index.js +0 -3
  217. package/dist/ui/features/command-palette/CommandPalette.svelte.d.ts +0 -6
  218. package/dist/ui/features/config/APP_CONFIGURATIONS.d.ts +0 -29
  219. package/dist/ui/features/config/APP_CONFIGURATIONS.js +0 -38
  220. package/dist/ui/features/config/AppSettingSelector.svelte.d.ts +0 -13
  221. package/dist/ui/features/config/CurrencySelector.svelte.d.ts +0 -8
  222. package/dist/ui/features/config/LanguageSelector.svelte.d.ts +0 -8
  223. package/dist/ui/features/config/ResourceSelector.svelte.d.ts +0 -25
  224. package/dist/ui/features/config/ThemeSelector.svelte.d.ts +0 -8
  225. package/dist/ui/features/notifications/NotificationBell.svelte.d.ts +0 -11
  226. package/dist/ui/features/notifications/index.d.ts +0 -1
  227. package/dist/ui/features/notifications/index.js +0 -2
  228. package/dist/ui/features/shortcuts/ShortcutBinder.svelte +0 -17
  229. package/dist/ui/features/shortcuts/ShortcutBinder.svelte.d.ts +0 -7
  230. package/dist/ui/features/shortcuts/ShortcutPalette.svelte.d.ts +0 -6
  231. package/dist/ui/index.d.ts +0 -30
  232. package/dist/ui/index.js +0 -46
  233. package/dist/ui/layout/ConnectedNavigationPanel.svelte.d.ts +0 -10
  234. package/dist/ui/layout/ConnectedWorkspaceStrip.svelte.d.ts +0 -9
  235. package/dist/ui/layout/ContentArea.svelte.d.ts +0 -8
  236. package/dist/ui/layout/DetailPanel.svelte.d.ts +0 -7
  237. package/dist/ui/layout/NavigationPanel.svelte.d.ts +0 -14
  238. package/dist/ui/layout/WorkspaceLayout.svelte.d.ts +0 -32
  239. package/dist/ui/layout/WorkspaceStrip.svelte.d.ts +0 -11
  240. package/dist/ui/layout/connection-factory.d.ts +0 -50
  241. package/dist/ui/layout/connection-factory.js +0 -58
  242. package/dist/ui/layout/index.d.ts +0 -7
  243. package/dist/ui/layout/index.js +0 -7
  244. package/dist/ui/paraglide/README.md +0 -147
  245. package/dist/ui/paraglide/messages/_index.d.ts +0 -87
  246. package/dist/ui/paraglide/messages/_index.js +0 -88
  247. package/dist/ui/paraglide/messages/abyss.d.ts +0 -16
  248. package/dist/ui/paraglide/messages/abyss.js +0 -84
  249. package/dist/ui/paraglide/messages/acid.d.ts +0 -16
  250. package/dist/ui/paraglide/messages/acid.js +0 -84
  251. package/dist/ui/paraglide/messages/active_toasts.d.ts +0 -16
  252. package/dist/ui/paraglide/messages/active_toasts.js +0 -84
  253. package/dist/ui/paraglide/messages/aed3.d.ts +0 -17
  254. package/dist/ui/paraglide/messages/aed3.js +0 -85
  255. package/dist/ui/paraglide/messages/all_currencies.d.ts +0 -16
  256. package/dist/ui/paraglide/messages/all_currencies.js +0 -84
  257. package/dist/ui/paraglide/messages/all_languages.d.ts +0 -16
  258. package/dist/ui/paraglide/messages/all_languages.js +0 -84
  259. package/dist/ui/paraglide/messages/all_themes.d.ts +0 -16
  260. package/dist/ui/paraglide/messages/all_themes.js +0 -84
  261. package/dist/ui/paraglide/messages/api_status.d.ts +0 -16
  262. package/dist/ui/paraglide/messages/api_status.js +0 -84
  263. package/dist/ui/paraglide/messages/app_info.d.ts +0 -16
  264. package/dist/ui/paraglide/messages/app_info.js +0 -84
  265. package/dist/ui/paraglide/messages/appearance.d.ts +0 -16
  266. package/dist/ui/paraglide/messages/appearance.js +0 -84
  267. package/dist/ui/paraglide/messages/aqua.d.ts +0 -16
  268. package/dist/ui/paraglide/messages/aqua.js +0 -84
  269. package/dist/ui/paraglide/messages/ar.d.ts +0 -16
  270. package/dist/ui/paraglide/messages/ar.js +0 -84
  271. package/dist/ui/paraglide/messages/autumn.d.ts +0 -16
  272. package/dist/ui/paraglide/messages/autumn.js +0 -84
  273. package/dist/ui/paraglide/messages/black.d.ts +0 -16
  274. package/dist/ui/paraglide/messages/black.js +0 -84
  275. package/dist/ui/paraglide/messages/brl3.d.ts +0 -17
  276. package/dist/ui/paraglide/messages/brl3.js +0 -85
  277. package/dist/ui/paraglide/messages/bumblebee.d.ts +0 -16
  278. package/dist/ui/paraglide/messages/bumblebee.js +0 -84
  279. package/dist/ui/paraglide/messages/business.d.ts +0 -16
  280. package/dist/ui/paraglide/messages/business.js +0 -84
  281. package/dist/ui/paraglide/messages/cad3.d.ts +0 -17
  282. package/dist/ui/paraglide/messages/cad3.js +0 -85
  283. package/dist/ui/paraglide/messages/caramellatte.d.ts +0 -16
  284. package/dist/ui/paraglide/messages/caramellatte.js +0 -84
  285. package/dist/ui/paraglide/messages/cmyk.d.ts +0 -16
  286. package/dist/ui/paraglide/messages/cmyk.js +0 -84
  287. package/dist/ui/paraglide/messages/cny3.d.ts +0 -17
  288. package/dist/ui/paraglide/messages/cny3.js +0 -85
  289. package/dist/ui/paraglide/messages/coffee.d.ts +0 -16
  290. package/dist/ui/paraglide/messages/coffee.js +0 -84
  291. package/dist/ui/paraglide/messages/commands_label.d.ts +0 -16
  292. package/dist/ui/paraglide/messages/commands_label.js +0 -84
  293. package/dist/ui/paraglide/messages/corporate.d.ts +0 -16
  294. package/dist/ui/paraglide/messages/corporate.js +0 -84
  295. package/dist/ui/paraglide/messages/cupcake.d.ts +0 -16
  296. package/dist/ui/paraglide/messages/cupcake.js +0 -84
  297. package/dist/ui/paraglide/messages/currency.d.ts +0 -16
  298. package/dist/ui/paraglide/messages/currency.js +0 -84
  299. package/dist/ui/paraglide/messages/current_currency.d.ts +0 -16
  300. package/dist/ui/paraglide/messages/current_currency.js +0 -84
  301. package/dist/ui/paraglide/messages/current_language.d.ts +0 -16
  302. package/dist/ui/paraglide/messages/current_language.js +0 -84
  303. package/dist/ui/paraglide/messages/current_theme.d.ts +0 -16
  304. package/dist/ui/paraglide/messages/current_theme.js +0 -84
  305. package/dist/ui/paraglide/messages/currently_in_queue.d.ts +0 -16
  306. package/dist/ui/paraglide/messages/currently_in_queue.js +0 -84
  307. package/dist/ui/paraglide/messages/cyberpunk.d.ts +0 -16
  308. package/dist/ui/paraglide/messages/cyberpunk.js +0 -84
  309. package/dist/ui/paraglide/messages/dark.d.ts +0 -16
  310. package/dist/ui/paraglide/messages/dark.js +0 -84
  311. package/dist/ui/paraglide/messages/de.d.ts +0 -16
  312. package/dist/ui/paraglide/messages/de.js +0 -84
  313. package/dist/ui/paraglide/messages/dim.d.ts +0 -16
  314. package/dist/ui/paraglide/messages/dim.js +0 -84
  315. package/dist/ui/paraglide/messages/dracula.d.ts +0 -16
  316. package/dist/ui/paraglide/messages/dracula.js +0 -84
  317. package/dist/ui/paraglide/messages/emerald.d.ts +0 -16
  318. package/dist/ui/paraglide/messages/emerald.js +0 -84
  319. package/dist/ui/paraglide/messages/en.d.ts +0 -16
  320. package/dist/ui/paraglide/messages/en.js +0 -84
  321. package/dist/ui/paraglide/messages/es.d.ts +0 -16
  322. package/dist/ui/paraglide/messages/es.js +0 -84
  323. package/dist/ui/paraglide/messages/eur3.d.ts +0 -17
  324. package/dist/ui/paraglide/messages/eur3.js +0 -85
  325. package/dist/ui/paraglide/messages/extended_controls.d.ts +0 -16
  326. package/dist/ui/paraglide/messages/extended_controls.js +0 -84
  327. package/dist/ui/paraglide/messages/fantasy.d.ts +0 -16
  328. package/dist/ui/paraglide/messages/fantasy.js +0 -84
  329. package/dist/ui/paraglide/messages/forest.d.ts +0 -16
  330. package/dist/ui/paraglide/messages/forest.js +0 -84
  331. package/dist/ui/paraglide/messages/fr.d.ts +0 -16
  332. package/dist/ui/paraglide/messages/fr.js +0 -84
  333. package/dist/ui/paraglide/messages/garden.d.ts +0 -16
  334. package/dist/ui/paraglide/messages/garden.js +0 -84
  335. package/dist/ui/paraglide/messages/gbp3.d.ts +0 -17
  336. package/dist/ui/paraglide/messages/gbp3.js +0 -85
  337. package/dist/ui/paraglide/messages/halloween.d.ts +0 -16
  338. package/dist/ui/paraglide/messages/halloween.js +0 -84
  339. package/dist/ui/paraglide/messages/hello_world.d.ts +0 -18
  340. package/dist/ui/paraglide/messages/hello_world.js +0 -84
  341. package/dist/ui/paraglide/messages/hi.d.ts +0 -16
  342. package/dist/ui/paraglide/messages/hi.js +0 -84
  343. package/dist/ui/paraglide/messages/inr3.d.ts +0 -17
  344. package/dist/ui/paraglide/messages/inr3.js +0 -85
  345. package/dist/ui/paraglide/messages/it.d.ts +0 -16
  346. package/dist/ui/paraglide/messages/it.js +0 -84
  347. package/dist/ui/paraglide/messages/ja.d.ts +0 -16
  348. package/dist/ui/paraglide/messages/ja.js +0 -84
  349. package/dist/ui/paraglide/messages/jpy3.d.ts +0 -17
  350. package/dist/ui/paraglide/messages/jpy3.js +0 -85
  351. package/dist/ui/paraglide/messages/ko.d.ts +0 -16
  352. package/dist/ui/paraglide/messages/ko.js +0 -84
  353. package/dist/ui/paraglide/messages/krw3.d.ts +0 -17
  354. package/dist/ui/paraglide/messages/krw3.js +0 -85
  355. package/dist/ui/paraglide/messages/languages.d.ts +0 -16
  356. package/dist/ui/paraglide/messages/languages.js +0 -84
  357. package/dist/ui/paraglide/messages/lemonade.d.ts +0 -16
  358. package/dist/ui/paraglide/messages/lemonade.js +0 -84
  359. package/dist/ui/paraglide/messages/light.d.ts +0 -16
  360. package/dist/ui/paraglide/messages/light.js +0 -84
  361. package/dist/ui/paraglide/messages/live_store_dashboard.d.ts +0 -16
  362. package/dist/ui/paraglide/messages/live_store_dashboard.js +0 -84
  363. package/dist/ui/paraglide/messages/localization.d.ts +0 -16
  364. package/dist/ui/paraglide/messages/localization.js +0 -84
  365. package/dist/ui/paraglide/messages/lofi.d.ts +0 -16
  366. package/dist/ui/paraglide/messages/lofi.js +0 -84
  367. package/dist/ui/paraglide/messages/luxury.d.ts +0 -16
  368. package/dist/ui/paraglide/messages/luxury.js +0 -84
  369. package/dist/ui/paraglide/messages/mxn3.d.ts +0 -17
  370. package/dist/ui/paraglide/messages/mxn3.js +0 -85
  371. package/dist/ui/paraglide/messages/name_label.d.ts +0 -16
  372. package/dist/ui/paraglide/messages/name_label.js +0 -84
  373. package/dist/ui/paraglide/messages/night.d.ts +0 -16
  374. package/dist/ui/paraglide/messages/night.js +0 -84
  375. package/dist/ui/paraglide/messages/nord.d.ts +0 -16
  376. package/dist/ui/paraglide/messages/nord.js +0 -84
  377. package/dist/ui/paraglide/messages/pastel.d.ts +0 -16
  378. package/dist/ui/paraglide/messages/pastel.js +0 -84
  379. package/dist/ui/paraglide/messages/pt.d.ts +0 -16
  380. package/dist/ui/paraglide/messages/pt.js +0 -84
  381. package/dist/ui/paraglide/messages/real_time_monitor_desc.d.ts +0 -16
  382. package/dist/ui/paraglide/messages/real_time_monitor_desc.js +0 -84
  383. package/dist/ui/paraglide/messages/registered_in_registry.d.ts +0 -16
  384. package/dist/ui/paraglide/messages/registered_in_registry.js +0 -84
  385. package/dist/ui/paraglide/messages/retro.d.ts +0 -16
  386. package/dist/ui/paraglide/messages/retro.js +0 -84
  387. package/dist/ui/paraglide/messages/ru.d.ts +0 -16
  388. package/dist/ui/paraglide/messages/ru.js +0 -84
  389. package/dist/ui/paraglide/messages/silk.d.ts +0 -16
  390. package/dist/ui/paraglide/messages/silk.js +0 -84
  391. package/dist/ui/paraglide/messages/state_label.d.ts +0 -16
  392. package/dist/ui/paraglide/messages/state_label.js +0 -84
  393. package/dist/ui/paraglide/messages/sunset.d.ts +0 -16
  394. package/dist/ui/paraglide/messages/sunset.js +0 -84
  395. package/dist/ui/paraglide/messages/synthwave.d.ts +0 -16
  396. package/dist/ui/paraglide/messages/synthwave.js +0 -84
  397. package/dist/ui/paraglide/messages/system.d.ts +0 -16
  398. package/dist/ui/paraglide/messages/system.js +0 -84
  399. package/dist/ui/paraglide/messages/theme.d.ts +0 -16
  400. package/dist/ui/paraglide/messages/theme.js +0 -84
  401. package/dist/ui/paraglide/messages/themes.d.ts +0 -16
  402. package/dist/ui/paraglide/messages/themes.js +0 -84
  403. package/dist/ui/paraglide/messages/url_label.d.ts +0 -16
  404. package/dist/ui/paraglide/messages/url_label.js +0 -84
  405. package/dist/ui/paraglide/messages/usd3.d.ts +0 -17
  406. package/dist/ui/paraglide/messages/usd3.js +0 -85
  407. package/dist/ui/paraglide/messages/valentine.d.ts +0 -16
  408. package/dist/ui/paraglide/messages/valentine.js +0 -84
  409. package/dist/ui/paraglide/messages/version_label.d.ts +0 -16
  410. package/dist/ui/paraglide/messages/version_label.js +0 -84
  411. package/dist/ui/paraglide/messages/vi.d.ts +0 -16
  412. package/dist/ui/paraglide/messages/vi.js +0 -84
  413. package/dist/ui/paraglide/messages/winter.d.ts +0 -16
  414. package/dist/ui/paraglide/messages/winter.js +0 -84
  415. package/dist/ui/paraglide/messages/wireframe.d.ts +0 -16
  416. package/dist/ui/paraglide/messages/wireframe.js +0 -84
  417. package/dist/ui/paraglide/messages/zh.d.ts +0 -16
  418. package/dist/ui/paraglide/messages/zh.js +0 -84
  419. package/dist/ui/paraglide/messages.d.ts +0 -2
  420. package/dist/ui/paraglide/messages.js +0 -4
  421. package/dist/ui/paraglide/registry.d.ts +0 -21
  422. package/dist/ui/paraglide/registry.js +0 -31
  423. package/dist/ui/paraglide/runtime.d.ts +0 -730
  424. package/dist/ui/paraglide/runtime.js +0 -1812
  425. package/dist/ui/paraglide/server.d.ts +0 -92
  426. package/dist/ui/paraglide/server.js +0 -239
  427. package/dist/ui/primitives/DatePicker.svelte +0 -257
  428. package/dist/ui/primitives/DatePicker.svelte.d.ts +0 -17
  429. package/dist/ui/primitives/index.d.ts +0 -1
  430. package/dist/ui/primitives/index.js +0 -3
  431. /package/{dist/ui/layout → src/runes/layout/src}/ContentArea.svelte +0 -0
  432. /package/{dist/ui/layout → src/runes/layout/src}/DetailPanel.svelte +0 -0
  433. /package/{dist/ui/features → src/runes/palettes/src}/notifications/NotificationBell.svelte +0 -0
@@ -1,1812 +0,0 @@
1
- /* eslint-disable */
2
-
3
- /** @type {any} */
4
- const URLPattern = {}
5
-
6
- /**
7
- * The project's base locale.
8
- *
9
- * @example
10
- * if (locale === baseLocale) {
11
- * // do something
12
- * }
13
- */
14
- export const baseLocale = "en";
15
- /**
16
- * The project's locales that have been specified in the settings.
17
- *
18
- * @example
19
- * if (locales.includes(userSelectedLocale) === false) {
20
- * throw new Error('Locale is not available');
21
- * }
22
- */
23
- export const locales = /** @type {const} */ (["es","fr","it","pt","en","de","ru","hi","ar","zh","ja","ko","vi"]);
24
- /** @type {string} */
25
- export const cookieName = "PARAGLIDE_LOCALE";
26
- /** @type {number} */
27
- export const cookieMaxAge = 34560000;
28
- /** @type {string} */
29
- export const cookieDomain = "";
30
- /** @type {string} */
31
- export const localStorageKey = "PARAGLIDE_LOCALE";
32
- /**
33
- * @type {Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>}
34
- */
35
- export const strategy = [
36
- "cookie",
37
- "globalVariable",
38
- "baseLocale"
39
- ];
40
- /**
41
- * Route-level strategy overrides.
42
- *
43
- * `match` uses URLPattern syntax.
44
- *
45
- * @type {Array<{
46
- * match: string;
47
- * strategy?: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
48
- * exclude?: boolean;
49
- * }>}
50
- */
51
- export const routeStrategies = [];
52
- /**
53
- * The used URL patterns.
54
- *
55
- * @type {Array<{ pattern: string, localized: Array<[Locale, string]> }>}
56
- */
57
- export const urlPatterns = [
58
- {
59
- "pattern": ":protocol://:domain(.*)::port?/:path(.*)?",
60
- "localized": [
61
- [
62
- "es",
63
- ":protocol://:domain(.*)::port?/es/:path(.*)?"
64
- ],
65
- [
66
- "fr",
67
- ":protocol://:domain(.*)::port?/fr/:path(.*)?"
68
- ],
69
- [
70
- "it",
71
- ":protocol://:domain(.*)::port?/it/:path(.*)?"
72
- ],
73
- [
74
- "pt",
75
- ":protocol://:domain(.*)::port?/pt/:path(.*)?"
76
- ],
77
- [
78
- "de",
79
- ":protocol://:domain(.*)::port?/de/:path(.*)?"
80
- ],
81
- [
82
- "ru",
83
- ":protocol://:domain(.*)::port?/ru/:path(.*)?"
84
- ],
85
- [
86
- "hi",
87
- ":protocol://:domain(.*)::port?/hi/:path(.*)?"
88
- ],
89
- [
90
- "ar",
91
- ":protocol://:domain(.*)::port?/ar/:path(.*)?"
92
- ],
93
- [
94
- "zh",
95
- ":protocol://:domain(.*)::port?/zh/:path(.*)?"
96
- ],
97
- [
98
- "ja",
99
- ":protocol://:domain(.*)::port?/ja/:path(.*)?"
100
- ],
101
- [
102
- "ko",
103
- ":protocol://:domain(.*)::port?/ko/:path(.*)?"
104
- ],
105
- [
106
- "vi",
107
- ":protocol://:domain(.*)::port?/vi/:path(.*)?"
108
- ],
109
- [
110
- "en",
111
- ":protocol://:domain(.*)::port?/:path(.*)?"
112
- ]
113
- ]
114
- }
115
- ];
116
- /** @type {string | undefined} */
117
- let cachedRouteStrategyUrl;
118
- /** @type {{ match: string; strategy?: typeof strategy; exclude?: boolean } | undefined} */
119
- let cachedRouteStrategy;
120
- /**
121
- * @param {string | URL} url
122
- * @returns {{ match: string; strategy?: typeof strategy; exclude?: boolean } | undefined}
123
- */
124
- function findMatchingRouteStrategy(url) {
125
- if (routeStrategies.length === 0) {
126
- return undefined;
127
- }
128
- const urlString = typeof url === "string" ? url : url.href;
129
- if (cachedRouteStrategyUrl === urlString) {
130
- return cachedRouteStrategy;
131
- }
132
- const urlObject = new URL(urlString, "http://dummy.com");
133
- let match;
134
- for (const routeStrategy of routeStrategies) {
135
- const pattern = new URLPattern(routeStrategy.match, urlObject.href);
136
- if (pattern.exec(urlObject.href)) {
137
- match = routeStrategy;
138
- break;
139
- }
140
- }
141
- cachedRouteStrategyUrl = urlString;
142
- cachedRouteStrategy = match;
143
- return match;
144
- }
145
- /**
146
- * Returns the strategy to use for a specific URL.
147
- *
148
- * If no route strategy matches (or the matching rule is `exclude: true`),
149
- * the global strategy is returned.
150
- *
151
- * @param {string | URL} url
152
- * @returns {typeof strategy}
153
- */
154
- export function getStrategyForUrl(url) {
155
- const routeStrategy = findMatchingRouteStrategy(url);
156
- if (routeStrategy &&
157
- routeStrategy.exclude !== true &&
158
- Array.isArray(routeStrategy.strategy)) {
159
- return routeStrategy.strategy;
160
- }
161
- return strategy;
162
- }
163
- /**
164
- * Returns whether the given URL is excluded from middleware i18n processing.
165
- *
166
- * @param {string | URL} url
167
- * @returns {boolean}
168
- */
169
- export function isExcludedByRouteStrategy(url) {
170
- return findMatchingRouteStrategy(url)?.exclude === true;
171
- }
172
- /**
173
- * @typedef {{
174
- * getStore(): {
175
- * locale?: Locale,
176
- * origin?: string,
177
- * messageCalls?: Set<string>
178
- * } | undefined,
179
- * run: (store: { locale?: Locale, origin?: string, messageCalls?: Set<string>},
180
- * cb: any) => any
181
- * }} ParaglideAsyncLocalStorage
182
- */
183
- /**
184
- * Server side async local storage that is set by `serverMiddleware()`.
185
- *
186
- * The variable is used to retrieve the locale and origin in a server-side
187
- * rendering context without effecting other requests.
188
- *
189
- * @type {ParaglideAsyncLocalStorage | undefined}
190
- */
191
- export let serverAsyncLocalStorage = undefined;
192
- export const disableAsyncLocalStorage = false;
193
- export const experimentalMiddlewareLocaleSplitting = false;
194
- export const isServer = typeof window === 'undefined';
195
- /** @type {Locale | undefined} */
196
- export const experimentalStaticLocale = undefined;
197
- /**
198
- * Sets the server side async local storage.
199
- *
200
- * The function is needed because the `runtime.js` file
201
- * must define the `serverAsyncLocalStorage` variable to
202
- * avoid a circular import between `runtime.js` and
203
- * `server.js` files.
204
- *
205
- * @param {ParaglideAsyncLocalStorage | undefined} value
206
- */
207
- export function overwriteServerAsyncLocalStorage(value) {
208
- serverAsyncLocalStorage = value;
209
- }
210
- const TREE_SHAKE_COOKIE_STRATEGY_USED = true;
211
- const TREE_SHAKE_URL_STRATEGY_USED = false;
212
- const TREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED = true;
213
- const TREE_SHAKE_PREFERRED_LANGUAGE_STRATEGY_USED = false;
214
- const TREE_SHAKE_DEFAULT_URL_PATTERN_USED = true;
215
- const TREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED = false;
216
-
217
- /** @type {any} */ (globalThis).__paraglide =
218
- /** @type {any} */ (globalThis).__paraglide ?? {};
219
- /** @type {any} */ (globalThis).__paraglide.ssr =
220
- /** @type {any} */ (globalThis).__paraglide.ssr ?? {};
221
-
222
- /**
223
- * This is a fallback to get started with a custom
224
- * strategy and avoid type errors.
225
- *
226
- * The implementation is overwritten
227
- * by `overwriteGetLocale()` and `defineSetLocale()`.
228
- *
229
- * @type {Locale | undefined}
230
- */
231
- let _locale;
232
- let localeInitiallySet = false;
233
- /**
234
- * Get the current locale.
235
- *
236
- * The locale is resolved using your configured strategies (URL, cookie, localStorage, etc.)
237
- * in the order they are defined. In SSR contexts, the locale is retrieved from AsyncLocalStorage
238
- * which is set by the `paraglideMiddleware()`.
239
- *
240
- * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy - Configure locale detection strategies
241
- *
242
- * @example
243
- * if (getLocale() === 'de') {
244
- * console.log('Germany 🇩🇪');
245
- * } else if (getLocale() === 'nl') {
246
- * console.log('Netherlands 🇳🇱');
247
- * }
248
- *
249
- * @returns {Locale} The current locale.
250
- */
251
- export let getLocale = () => {
252
- if (experimentalStaticLocale !== undefined) {
253
- return experimentalStaticLocale;
254
- }
255
- // if running in a server-side rendering context
256
- // retrieve the locale from the async local storage
257
- if (serverAsyncLocalStorage) {
258
- const locale = serverAsyncLocalStorage?.getStore()?.locale;
259
- if (locale) {
260
- return locale;
261
- }
262
- }
263
- let strategyToUse = strategy;
264
- if (!isServer && typeof window !== "undefined" && window.location?.href) {
265
- strategyToUse = getStrategyForUrl(window.location.href);
266
- }
267
- const resolved = resolveLocaleWithStrategies(strategyToUse, typeof window !== "undefined" ? window.location?.href : undefined);
268
- if (resolved) {
269
- if (!localeInitiallySet) {
270
- _locale = resolved;
271
- // https://github.com/opral/inlang-paraglide-js/issues/455
272
- localeInitiallySet = true;
273
- setLocale(resolved, { reload: false });
274
- }
275
- return resolved;
276
- }
277
- throw new Error("No locale found. Read the docs https://inlang.com/m/gerre34r/library-inlang-paraglideJs/errors#no-locale-found");
278
- };
279
- /**
280
- * Resolve locale for a given URL using route-aware strategies.
281
- *
282
- * @param {string | URL} url
283
- * @returns {Locale}
284
- */
285
- export function getLocaleForUrl(url) {
286
- if (experimentalStaticLocale !== undefined) {
287
- return experimentalStaticLocale;
288
- }
289
- const strategyToUse = getStrategyForUrl(url);
290
- const resolved = resolveLocaleWithStrategies(strategyToUse, typeof url === "string" ? url : url.href);
291
- if (resolved) {
292
- return resolved;
293
- }
294
- throw new Error("No locale found. Read the docs https://inlang.com/m/gerre34r/library-inlang-paraglideJs/errors#no-locale-found");
295
- }
296
- /**
297
- * @param {typeof strategy} strategyToUse
298
- * @param {string | undefined} urlForUrlStrategy
299
- * @returns {Locale | undefined}
300
- */
301
- function resolveLocaleWithStrategies(strategyToUse, urlForUrlStrategy) {
302
- /** @type {string | undefined} */
303
- let locale;
304
- for (const strat of strategyToUse) {
305
- if (TREE_SHAKE_COOKIE_STRATEGY_USED && strat === "cookie") {
306
- locale = extractLocaleFromCookie();
307
- }
308
- else if (strat === "baseLocale") {
309
- locale = baseLocale;
310
- }
311
- else if (TREE_SHAKE_URL_STRATEGY_USED &&
312
- strat === "url" &&
313
- !isServer &&
314
- typeof urlForUrlStrategy === "string") {
315
- locale = extractLocaleFromUrl(urlForUrlStrategy);
316
- }
317
- else if (TREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED &&
318
- strat === "globalVariable" &&
319
- _locale !== undefined) {
320
- locale = _locale;
321
- }
322
- else if (TREE_SHAKE_PREFERRED_LANGUAGE_STRATEGY_USED &&
323
- strat === "preferredLanguage" &&
324
- !isServer) {
325
- locale = extractLocaleFromNavigator();
326
- }
327
- else if (TREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED &&
328
- strat === "localStorage" &&
329
- !isServer) {
330
- locale = localStorage.getItem(localStorageKey) ?? undefined;
331
- }
332
- else if (isCustomStrategy(strat) && customClientStrategies.has(strat)) {
333
- const handler = customClientStrategies.get(strat);
334
- if (handler) {
335
- const result = handler.getLocale();
336
- // Handle both sync and async results - skip async in sync getLocale
337
- if (result instanceof Promise) {
338
- // Can't await in sync function, skip async strategies
339
- continue;
340
- }
341
- if (result !== undefined) {
342
- return assertIsLocale(result);
343
- }
344
- }
345
- }
346
- const matchedLocale = toLocale(locale);
347
- if (matchedLocale) {
348
- return matchedLocale;
349
- }
350
- }
351
- return undefined;
352
- }
353
- /**
354
- * Overwrite the `getLocale()` function.
355
- *
356
- * Use this function to overwrite how the locale is resolved. This is useful
357
- * for custom locale resolution or advanced use cases like SSG with concurrent rendering.
358
- *
359
- * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy
360
- *
361
- * @example
362
- * overwriteGetLocale(() => {
363
- * return Cookies.get('locale') ?? baseLocale
364
- * });
365
- *
366
- * @param {() => Locale} fn - The new implementation for `getLocale()`.
367
- */
368
- export const overwriteGetLocale = (fn) => {
369
- getLocale = fn;
370
- };
371
-
372
- const rtlLanguages = new Set([
373
- "ar",
374
- "dv",
375
- "fa",
376
- "he",
377
- "ks",
378
- "ku",
379
- "ps",
380
- "sd",
381
- "ug",
382
- "ur",
383
- "yi",
384
- ]);
385
- /**
386
- * Get writing direction for a locale.
387
- *
388
- * Uses `Intl.Locale` text info when available and falls back to a
389
- * language-based RTL check for runtimes without `getTextInfo()`.
390
- *
391
- * @example
392
- * getTextDirection(); // "ltr" or "rtl" for current locale
393
- * getTextDirection("ar"); // "rtl"
394
- * getTextDirection("en"); // "ltr"
395
- *
396
- * @param {string} [locale] - Target locale. If not provided, uses `getLocale()`
397
- * @returns {"ltr" | "rtl"}
398
- */
399
- export function getTextDirection(locale = getLocale()) {
400
- try {
401
- const intlLocale = /** @type {Intl.Locale & {
402
- getTextInfo?: () => { direction?: string };
403
- textInfo?: { direction?: string };
404
- }} */ (new Intl.Locale(locale));
405
- const direction = intlLocale.getTextInfo?.().direction ?? intlLocale.textInfo?.direction;
406
- if (direction === "ltr" || direction === "rtl") {
407
- return direction;
408
- }
409
- }
410
- catch {
411
- // Ignore Intl.Locale parsing/runtime errors and use fallback below.
412
- }
413
- const language = locale.split("-")[0]?.toLowerCase();
414
- return rtlLanguages.has(language ?? "") ? "rtl" : "ltr";
415
- }
416
-
417
- /**
418
- * Navigates to the localized URL, or reloads the current page
419
- *
420
- * @param {string} [newLocation] The new location
421
- */
422
- const navigateOrReload = (newLocation) => {
423
- if (newLocation) {
424
- // reload the page by navigating to the new url
425
- window.location.href = newLocation;
426
- }
427
- else {
428
- // reload the page to reflect the new locale
429
- window.location.reload();
430
- }
431
- };
432
- /**
433
- * @typedef {(newLocale: Locale, options?: { reload?: boolean }) => void | Promise<void>} SetLocaleFn
434
- */
435
- /**
436
- * Set the locale.
437
- *
438
- * Updates the locale using your configured strategies (cookie, localStorage, URL, etc.).
439
- * By default, this reloads the page on the client to reflect the new locale. Reloading
440
- * can be disabled by passing `reload: false` as an option, but you'll need to ensure
441
- * the UI updates to reflect the new locale.
442
- *
443
- * If any custom strategy's `setLocale` function is async, then this function
444
- * will become async as well.
445
- *
446
- * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy
447
- *
448
- * @example
449
- * setLocale('en');
450
- *
451
- * @example
452
- * setLocale('en', { reload: false });
453
- *
454
- * @type {SetLocaleFn}
455
- */
456
- export let setLocale = (newLocale, options) => {
457
- const optionsWithDefaults = {
458
- reload: true,
459
- ...options,
460
- };
461
- // locale is already set
462
- // https://github.com/opral/inlang-paraglide-js/issues/430
463
- /** @type {Locale | undefined} */
464
- let currentLocale;
465
- try {
466
- currentLocale = getLocale();
467
- }
468
- catch {
469
- // do nothing, no locale has been set yet.
470
- }
471
- /** @type {Array<Promise<void>>} */
472
- const customSetLocalePromises = [];
473
- /** @type {string | undefined} */
474
- let newLocation = undefined;
475
- let strategyToUse = strategy;
476
- if (!isServer && typeof window !== "undefined" && window.location?.href) {
477
- strategyToUse = getStrategyForUrl(window.location.href);
478
- }
479
- for (const strat of strategyToUse) {
480
- if (TREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED &&
481
- strat === "globalVariable") {
482
- // a default for a custom strategy to get started quickly
483
- // is likely overwritten by `defineSetLocale()`
484
- _locale = newLocale;
485
- }
486
- else if (TREE_SHAKE_COOKIE_STRATEGY_USED && strat === "cookie") {
487
- if (isServer ||
488
- typeof document === "undefined" ||
489
- typeof window === "undefined") {
490
- continue;
491
- }
492
- // set the cookie
493
- const cookieString = `${cookieName}=${newLocale}; path=/; max-age=${cookieMaxAge}`;
494
- document.cookie = cookieDomain
495
- ? `${cookieString}; domain=${cookieDomain}`
496
- : cookieString;
497
- }
498
- else if (strat === "baseLocale") {
499
- // nothing to be set here. baseLocale is only a fallback
500
- continue;
501
- }
502
- else if (TREE_SHAKE_URL_STRATEGY_USED &&
503
- strat === "url" &&
504
- typeof window !== "undefined") {
505
- // route to the new url
506
- //
507
- // this triggers a page reload but a user rarely
508
- // switches locales, so this should be fine.
509
- //
510
- // if the behavior is not desired, the implementation
511
- // can be overwritten by `defineSetLocale()` to avoid
512
- // a full page reload.
513
- newLocation = localizeUrl(window.location.href, {
514
- locale: newLocale,
515
- }).href;
516
- }
517
- else if (TREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED &&
518
- strat === "localStorage" &&
519
- typeof window !== "undefined") {
520
- // set the localStorage
521
- localStorage.setItem(localStorageKey, newLocale);
522
- }
523
- else if (isCustomStrategy(strat) && customClientStrategies.has(strat)) {
524
- const handler = customClientStrategies.get(strat);
525
- if (handler) {
526
- let result = handler.setLocale(newLocale);
527
- // Handle async setLocale
528
- if (result instanceof Promise) {
529
- result = result.catch((error) => {
530
- throw new Error(`Custom strategy "${strat}" setLocale failed.`, {
531
- cause: error,
532
- });
533
- });
534
- customSetLocalePromises.push(result);
535
- }
536
- }
537
- }
538
- }
539
- const runReload = () => {
540
- if (!isServer &&
541
- optionsWithDefaults.reload &&
542
- window.location &&
543
- newLocale !== currentLocale) {
544
- navigateOrReload(newLocation);
545
- }
546
- };
547
- if (customSetLocalePromises.length) {
548
- return Promise.all(customSetLocalePromises).then(() => {
549
- runReload();
550
- });
551
- }
552
- runReload();
553
- return;
554
- };
555
- /**
556
- * Overwrite the `setLocale()` function.
557
- *
558
- * Use this function to overwrite how the locale is set. For example,
559
- * modify a cookie, env variable, or a user's preference.
560
- *
561
- * @example
562
- * overwriteSetLocale((newLocale) => {
563
- * // set the locale in a cookie
564
- * return Cookies.set('locale', newLocale)
565
- * });
566
- *
567
- * @param {SetLocaleFn} fn
568
- */
569
- export const overwriteSetLocale = (fn) => {
570
- setLocale = fn;
571
- };
572
-
573
- /**
574
- * The origin of the current URL.
575
- *
576
- * Defaults to "http://y.com" in non-browser environments. If this
577
- * behavior is not desired, the implementation can be overwritten
578
- * by `overwriteGetUrlOrigin()`.
579
- *
580
- * @type {() => string}
581
- */
582
- export let getUrlOrigin = () => {
583
- if (serverAsyncLocalStorage) {
584
- return serverAsyncLocalStorage.getStore()?.origin ?? "http://fallback.com";
585
- }
586
- else if (typeof window !== "undefined") {
587
- return window.location.origin;
588
- }
589
- return "http://fallback.com";
590
- };
591
- /**
592
- * Overwrite the getUrlOrigin function.
593
- *
594
- * Use this function in server environments to
595
- * define how the URL origin is resolved.
596
- *
597
- * @param {() => string} fn - The new implementation for `getUrlOrigin()`.
598
- */
599
- export let overwriteGetUrlOrigin = (fn) => {
600
- getUrlOrigin = fn;
601
- };
602
-
603
- /**
604
- * Coerces a locale-like string to the canonical locale value used by the runtime.
605
- *
606
- * @param {unknown} value
607
- * @returns {Locale | undefined}
608
- */
609
- export function toLocale(value) {
610
- if (typeof value !== "string") {
611
- return undefined;
612
- }
613
- const lowerValue = value.toLowerCase();
614
- for (const locale of locales) {
615
- if (locale.toLowerCase() === lowerValue) {
616
- return locale;
617
- }
618
- }
619
- return undefined;
620
- }
621
- /**
622
- * Check if something is an available locale with the canonical project casing.
623
- *
624
- * @example
625
- * if (isLocale(params.locale)) {
626
- * setLocale(params.locale);
627
- * } else {
628
- * setLocale('en');
629
- * }
630
- *
631
- * Use `toLocale()` when you want case-insensitive matching and canonicalization.
632
- *
633
- * @param {unknown} locale
634
- * @returns {locale is Locale}
635
- */
636
- export function isLocale(locale) {
637
- return !!locale && locales.some((item) => item === locale);
638
- }
639
- /**
640
- * Asserts that the input can be normalized to a locale.
641
- *
642
- * @param {unknown} input - The input to check.
643
- * @returns {Locale} The input normalized to a Locale.
644
- * @throws {Error} If the input is not a locale.
645
- */
646
- export function assertIsLocale(input) {
647
- const locale = toLocale(input);
648
- if (locale)
649
- return locale;
650
- throw new Error(`Invalid locale: ${input}. Expected one of: ${locales.join(", ")}`);
651
- }
652
-
653
- /**
654
- * Extracts a locale from a request.
655
- *
656
- * Use the function on the server to extract the locale
657
- * from a request.
658
- *
659
- * The function goes through the strategies in the order
660
- * they are defined. If a strategy returns an invalid locale,
661
- * it will fall back to the next strategy.
662
- *
663
- * Note: Custom server strategies are not supported in this synchronous version.
664
- * Use `extractLocaleFromRequestAsync` if you need custom server strategies with async getLocale methods.
665
- *
666
- * @example
667
- * const locale = extractLocaleFromRequest(request);
668
- *
669
- * @param {Request} request
670
- * @returns {Locale}
671
- */
672
- export const extractLocaleFromRequest = (request) => {
673
- return extractLocaleFromRequestWithStrategies(request, getStrategyForUrl(request.url));
674
- };
675
- /**
676
- * Extracts a locale from a request using the provided strategy order.
677
- *
678
- * @param {Request} request
679
- * @param {typeof strategy} strategies
680
- * @returns {Locale}
681
- */
682
- export const extractLocaleFromRequestWithStrategies = (request, strategies) => {
683
- /** @type {string|undefined} */
684
- let locale;
685
- for (const strat of strategies) {
686
- if (TREE_SHAKE_COOKIE_STRATEGY_USED && strat === "cookie") {
687
- locale = request.headers
688
- .get("cookie")
689
- ?.split("; ")
690
- .find((c) => c.startsWith(cookieName + "="))
691
- ?.split("=")[1];
692
- }
693
- else if (TREE_SHAKE_URL_STRATEGY_USED && strat === "url") {
694
- locale = extractLocaleFromUrl(request.url);
695
- }
696
- else if (TREE_SHAKE_PREFERRED_LANGUAGE_STRATEGY_USED &&
697
- strat === "preferredLanguage") {
698
- locale = extractLocaleFromHeader(request);
699
- }
700
- else if (strat === "globalVariable") {
701
- locale = _locale;
702
- }
703
- else if (strat === "baseLocale") {
704
- return baseLocale;
705
- }
706
- else if (strat === "localStorage") {
707
- continue;
708
- }
709
- else if (isCustomStrategy(strat)) {
710
- // Custom strategies are not supported in sync version
711
- // Use extractLocaleFromRequestAsync for custom server strategies
712
- continue;
713
- }
714
- const matchedLocale = toLocale(locale);
715
- if (matchedLocale) {
716
- return matchedLocale;
717
- }
718
- }
719
- 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://inlang.com/m/gerre34r/library-inlang-paraglideJs/errors#no-locale-found");
720
- };
721
-
722
- /**
723
- * Asynchronously extracts a locale from a request.
724
- *
725
- * This function supports async custom server strategies, unlike the synchronous
726
- * `extractLocaleFromRequest`. Use this function when you have custom server strategies
727
- * that need to perform asynchronous operations (like database calls) in their getLocale method.
728
- *
729
- * The function first processes any custom server strategies asynchronously, then falls back
730
- * to the synchronous `extractLocaleFromRequest` for all other strategies.
731
- *
732
- * @see {@link https://github.com/opral/inlang-paraglide-js/issues/527#issuecomment-2978151022}
733
- *
734
- * @example
735
- * // Basic usage
736
- * const locale = await extractLocaleFromRequestAsync(request);
737
- *
738
- * @example
739
- * // With custom async server strategy
740
- * defineCustomServerStrategy("custom-database", {
741
- * getLocale: async (request) => {
742
- * const userId = extractUserIdFromRequest(request);
743
- * return await getUserLocaleFromDatabase(userId);
744
- * }
745
- * });
746
- *
747
- * const locale = await extractLocaleFromRequestAsync(request);
748
- *
749
- * @param {Request} request - The request object to extract the locale from.
750
- * @returns {Promise<Locale>} The extracted locale.
751
- */
752
- export const extractLocaleFromRequestAsync = async (request) => {
753
- /** @type {string|undefined} */
754
- let locale;
755
- const strategy = getStrategyForUrl(request.url);
756
- // Process custom strategies first, in order
757
- for (const strat of strategy) {
758
- if (isCustomStrategy(strat) && customServerStrategies.has(strat)) {
759
- const handler = customServerStrategies.get(strat);
760
- if (handler) {
761
- /** @type {string|undefined} */
762
- locale = await handler.getLocale(request);
763
- }
764
- // If we got a valid locale from this custom strategy, use it
765
- const matchedLocale = toLocale(locale);
766
- if (matchedLocale) {
767
- return matchedLocale;
768
- }
769
- }
770
- }
771
- // If no custom strategy provided a valid locale, fall back to sync version
772
- return extractLocaleFromRequestWithStrategies(request, strategy);
773
- };
774
-
775
- /**
776
- * Extracts a cookie from the document.
777
- *
778
- * Will return undefined if the document is not available or if the cookie is not set.
779
- * The `document` object is not available in server-side rendering, so this function should not be called in that context.
780
- *
781
- * @returns {Locale | undefined}
782
- */
783
- export function extractLocaleFromCookie() {
784
- if (typeof document === "undefined" || !document.cookie) {
785
- return;
786
- }
787
- const match = document.cookie.match(new RegExp(`(^| )${cookieName}=([^;]+)`));
788
- const locale = match?.[2];
789
- return toLocale(locale);
790
- }
791
-
792
- /**
793
- * Extracts a locale from the accept-language header.
794
- *
795
- * Use the function on the server to extract the locale
796
- * from the accept-language header that is sent by the client.
797
- *
798
- * @example
799
- * const locale = extractLocaleFromHeader(request);
800
- *
801
- * @param {Request} request - The request object to extract the locale from.
802
- * @returns {Locale | undefined} The negotiated preferred language.
803
- */
804
- export function extractLocaleFromHeader(request) {
805
- const acceptLanguageHeader = request.headers.get("accept-language");
806
- if (acceptLanguageHeader) {
807
- // Parse language preferences with their q-values and base language codes
808
- const languages = acceptLanguageHeader
809
- .split(",")
810
- .map((lang) => {
811
- const [tag, q = "1"] = lang.trim().split(";q=");
812
- // Get both the full tag and base language code
813
- const baseTag = tag?.split("-")[0];
814
- return {
815
- fullTag: tag,
816
- baseTag,
817
- q: Number(q),
818
- };
819
- })
820
- .sort((a, b) => b.q - a.q);
821
- for (const lang of languages) {
822
- const fullLocale = toLocale(lang.fullTag);
823
- if (fullLocale) {
824
- return fullLocale;
825
- }
826
- const baseLocale = toLocale(lang.baseTag);
827
- if (baseLocale) {
828
- return baseLocale;
829
- }
830
- }
831
- return undefined;
832
- }
833
- return undefined;
834
- }
835
-
836
- /**
837
- * Negotiates a preferred language from navigator.languages.
838
- *
839
- * Use the function on the client to extract the locale
840
- * from the navigator.languages array.
841
- *
842
- * @example
843
- * const locale = extractLocaleFromNavigator();
844
- *
845
- * @returns {Locale | undefined}
846
- */
847
- export function extractLocaleFromNavigator() {
848
- if (!navigator?.languages?.length) {
849
- return undefined;
850
- }
851
- const languages = navigator.languages.map((lang) => ({
852
- fullTag: lang,
853
- baseTag: lang.split("-")[0],
854
- }));
855
- for (const lang of languages) {
856
- const fullLocale = toLocale(lang.fullTag);
857
- if (fullLocale) {
858
- return fullLocale;
859
- }
860
- const baseLocale = toLocale(lang.baseTag);
861
- if (baseLocale) {
862
- return baseLocale;
863
- }
864
- }
865
- return undefined;
866
- }
867
-
868
- /**
869
- * If extractLocaleFromUrl is called many times on the same page and the URL
870
- * hasn't changed, we don't need to recompute it every time which can get expensive.
871
- * We might use a LRU cache if needed, but for now storing only the last result is enough.
872
- * https://github.com/opral/monorepo/pull/3575#discussion_r2066731243
873
- */
874
- /** @type {string|undefined} */
875
- let cachedUrl;
876
- /** @type {Locale|undefined} */
877
- let cachedLocale;
878
- /**
879
- * Extracts the locale from a given URL using native URLPattern.
880
- *
881
- * The built-in default `/:locale/...` routing is case-insensitive because it
882
- * canonicalizes the first path segment with `toLocale()`. Custom `urlPatterns`
883
- * keep URLPattern's normal exact matching semantics for path segments.
884
- *
885
- * @param {URL|string} url - The full URL from which to extract the locale.
886
- * @returns {Locale|undefined} The extracted locale, or undefined if no locale is found.
887
- */
888
- export function extractLocaleFromUrl(url) {
889
- const urlString = typeof url === "string" ? url : url.href;
890
- if (cachedUrl === urlString) {
891
- return cachedLocale;
892
- }
893
- /** @type {Locale | undefined} */
894
- let result;
895
- if (TREE_SHAKE_DEFAULT_URL_PATTERN_USED) {
896
- result = defaultUrlPatternExtractLocale(url);
897
- }
898
- else {
899
- const urlObj = typeof url === "string" ? new URL(url) : url;
900
- // Iterate over URL patterns
901
- for (const element of urlPatterns) {
902
- for (const [locale, localizedPattern] of element.localized) {
903
- const match = new URLPattern(localizedPattern, urlObj.href).exec(urlObj.href);
904
- if (match) {
905
- result = locale;
906
- break;
907
- }
908
- }
909
- if (result)
910
- break;
911
- }
912
- }
913
- cachedUrl = urlString;
914
- cachedLocale = result;
915
- return result;
916
- }
917
- /**
918
- * https://github.com/opral/inlang-paraglide-js/issues/381
919
- *
920
- * @param {URL | string} url - The full URL from which to extract the locale.
921
- * @returns {Locale | undefined} The extracted locale, or undefined if no locale is found.
922
- */
923
- function defaultUrlPatternExtractLocale(url) {
924
- const urlObj = new URL(url, "http://dummy.com");
925
- const pathSegments = urlObj.pathname.split("/").filter(Boolean);
926
- return toLocale(pathSegments[0]) || baseLocale;
927
- }
928
-
929
- /**
930
- * Lower-level URL localization function, primarily used in server contexts.
931
- *
932
- * This function is designed for server-side usage where you need precise control
933
- * over URL localization, such as in middleware or request handlers. It works with
934
- * URL objects and always returns absolute URLs.
935
- *
936
- * For client-side UI components, use `localizeHref()` instead, which provides
937
- * a more convenient API with relative paths and automatic locale detection.
938
- *
939
- * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing
940
- *
941
- * @example
942
- * ```typescript
943
- * // Server middleware example
944
- * app.use((req, res, next) => {
945
- * const url = new URL(req.url, `${req.protocol}://${req.headers.host}`);
946
- * const localized = localizeUrl(url, { locale: "de" });
947
- *
948
- * if (localized.href !== url.href) {
949
- * return res.redirect(localized.href);
950
- * }
951
- * next();
952
- * });
953
- * ```
954
- *
955
- * @example
956
- * ```typescript
957
- * // Using with URL patterns
958
- * const url = new URL("https://example.com/about");
959
- * localizeUrl(url, { locale: "de" });
960
- * // => URL("https://example.com/de/about")
961
- *
962
- * // Using with domain-based localization
963
- * const url = new URL("https://example.com/store");
964
- * localizeUrl(url, { locale: "de" });
965
- * // => URL("https://de.example.com/store")
966
- * ```
967
- *
968
- * @param {string | URL} url - The URL to localize. If string, must be absolute.
969
- * @param {object} [options] - Options for localization
970
- * @param {Locale} [options.locale] - Target locale. If not provided, uses getLocale()
971
- * @returns {URL} The localized URL, always absolute
972
- */
973
- export function localizeUrl(url, options) {
974
- const targetLocale = options?.locale
975
- ? assertIsLocale(options?.locale)
976
- : getLocale();
977
- if (TREE_SHAKE_DEFAULT_URL_PATTERN_USED) {
978
- return localizeUrlDefaultPattern(url, targetLocale);
979
- }
980
- const urlObj = typeof url === "string" ? new URL(url) : url;
981
- // Iterate over URL patterns
982
- for (const element of urlPatterns) {
983
- // match localized patterns
984
- for (const [, localizedPattern] of element.localized) {
985
- const match = new URLPattern(localizedPattern, urlObj.href).exec(urlObj.href);
986
- if (!match) {
987
- continue;
988
- }
989
- const targetPattern = element.localized.find(([locale]) => locale === targetLocale)?.[1];
990
- if (!targetPattern) {
991
- continue;
992
- }
993
- const localizedUrl = fillPattern(targetPattern, aggregateGroups(match), urlObj.origin);
994
- return fillMissingUrlParts(localizedUrl, match);
995
- }
996
- const unlocalizedMatch = new URLPattern(element.pattern, urlObj.href).exec(urlObj.href);
997
- if (unlocalizedMatch) {
998
- const targetPattern = element.localized.find(([locale]) => locale === targetLocale)?.[1];
999
- if (targetPattern) {
1000
- const localizedUrl = fillPattern(targetPattern, aggregateGroups(unlocalizedMatch), urlObj.origin);
1001
- return fillMissingUrlParts(localizedUrl, unlocalizedMatch);
1002
- }
1003
- }
1004
- }
1005
- // If no match found, return the original URL
1006
- return urlObj;
1007
- }
1008
- /**
1009
- * https://github.com/opral/inlang-paraglide-js/issues/381
1010
- *
1011
- * @param {string | URL} url
1012
- * @param {Locale} locale
1013
- * @returns {URL}
1014
- */
1015
- function localizeUrlDefaultPattern(url, locale) {
1016
- const urlObj = typeof url === "string" ? new URL(url, getUrlOrigin()) : new URL(url);
1017
- const currentLocale = extractLocaleFromUrl(urlObj);
1018
- // If current locale matches target locale, no change needed
1019
- if (currentLocale === locale) {
1020
- return urlObj;
1021
- }
1022
- const pathSegments = urlObj.pathname.split("/").filter(Boolean);
1023
- // If current path starts with a locale, remove it
1024
- if (pathSegments.length > 0 && toLocale(pathSegments[0])) {
1025
- pathSegments.shift();
1026
- }
1027
- // For base locale, don't add prefix
1028
- if (locale === baseLocale) {
1029
- urlObj.pathname = "/" + pathSegments.join("/");
1030
- }
1031
- else {
1032
- // For other locales, add prefix
1033
- urlObj.pathname = "/" + locale + "/" + pathSegments.join("/");
1034
- }
1035
- return urlObj;
1036
- }
1037
- /**
1038
- * Low-level URL de-localization function, primarily used in server contexts.
1039
- *
1040
- * This function is designed for server-side usage where you need precise control
1041
- * over URL de-localization, such as in middleware or request handlers. It works with
1042
- * URL objects and always returns absolute URLs.
1043
- *
1044
- * For client-side UI components, use `deLocalizeHref()` instead, which provides
1045
- * a more convenient API with relative paths.
1046
- *
1047
- * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing
1048
- *
1049
- * @example
1050
- * ```typescript
1051
- * // Server middleware example
1052
- * app.use((req, res, next) => {
1053
- * const url = new URL(req.url, `${req.protocol}://${req.headers.host}`);
1054
- * const baseUrl = deLocalizeUrl(url);
1055
- *
1056
- * // Store the base URL for later use
1057
- * req.baseUrl = baseUrl;
1058
- * next();
1059
- * });
1060
- * ```
1061
- *
1062
- * @example
1063
- * ```typescript
1064
- * // Using with URL patterns
1065
- * const url = new URL("https://example.com/de/about");
1066
- * deLocalizeUrl(url); // => URL("https://example.com/about")
1067
- *
1068
- * // Using with domain-based localization
1069
- * const url = new URL("https://de.example.com/store");
1070
- * deLocalizeUrl(url); // => URL("https://example.com/store")
1071
- * ```
1072
- *
1073
- * @param {string | URL} url - The URL to de-localize. If string, must be absolute.
1074
- * @returns {URL} The de-localized URL, always absolute
1075
- */
1076
- export function deLocalizeUrl(url) {
1077
- if (TREE_SHAKE_DEFAULT_URL_PATTERN_USED) {
1078
- return deLocalizeUrlDefaultPattern(url);
1079
- }
1080
- const urlObj = typeof url === "string" ? new URL(url) : url;
1081
- // Iterate over URL patterns
1082
- for (const element of urlPatterns) {
1083
- // Iterate over localized versions
1084
- for (const [, localizedPattern] of element.localized) {
1085
- const match = new URLPattern(localizedPattern, urlObj.href).exec(urlObj.href);
1086
- if (match) {
1087
- // Convert localized URL back to the base pattern
1088
- const groups = aggregateGroups(match);
1089
- const baseUrl = fillPattern(element.pattern, groups, urlObj.origin);
1090
- return fillMissingUrlParts(baseUrl, match);
1091
- }
1092
- }
1093
- // match unlocalized pattern
1094
- const unlocalizedMatch = new URLPattern(element.pattern, urlObj.href).exec(urlObj.href);
1095
- if (unlocalizedMatch) {
1096
- const baseUrl = fillPattern(element.pattern, aggregateGroups(unlocalizedMatch), urlObj.origin);
1097
- return fillMissingUrlParts(baseUrl, unlocalizedMatch);
1098
- }
1099
- }
1100
- // no match found return the original url
1101
- return urlObj;
1102
- }
1103
- /**
1104
- * De-localizes a URL using the default pattern (/:locale/*)
1105
- * @param {string|URL} url
1106
- * @returns {URL}
1107
- */
1108
- function deLocalizeUrlDefaultPattern(url) {
1109
- const urlObj = typeof url === "string" ? new URL(url, getUrlOrigin()) : new URL(url);
1110
- const pathSegments = urlObj.pathname.split("/").filter(Boolean);
1111
- // If first segment is a locale, remove it
1112
- if (pathSegments.length > 0 && toLocale(pathSegments[0])) {
1113
- urlObj.pathname = "/" + pathSegments.slice(1).join("/");
1114
- }
1115
- return urlObj;
1116
- }
1117
- /**
1118
- * Takes matches of implicit wildcards in the UrlPattern (when a part is missing
1119
- * it is equal to '*') and adds them back to the result of fillPattern.
1120
- *
1121
- * At least protocol and hostname are required to create a valid URL inside fillPattern.
1122
- *
1123
- * @param {URL} url
1124
- * @param {any} match
1125
- * @returns {URL}
1126
- */
1127
- function fillMissingUrlParts(url, match) {
1128
- if (match.protocol.groups["0"]) {
1129
- url.protocol = match.protocol.groups["0"] ?? "";
1130
- }
1131
- if (match.hostname.groups["0"]) {
1132
- url.hostname = match.hostname.groups["0"] ?? "";
1133
- }
1134
- if (match.username.groups["0"]) {
1135
- url.username = match.username.groups["0"] ?? "";
1136
- }
1137
- if (match.password.groups["0"]) {
1138
- url.password = match.password.groups["0"] ?? "";
1139
- }
1140
- if (match.port.groups["0"]) {
1141
- url.port = match.port.groups["0"] ?? "";
1142
- }
1143
- if (match.pathname.groups["0"]) {
1144
- url.pathname = match.pathname.groups["0"] ?? "";
1145
- }
1146
- if (match.search.groups["0"]) {
1147
- url.search = match.search.groups["0"] ?? "";
1148
- }
1149
- if (match.hash.groups["0"]) {
1150
- url.hash = match.hash.groups["0"] ?? "";
1151
- }
1152
- return url;
1153
- }
1154
- /**
1155
- * Fills a URL pattern with values for named groups, supporting all URLPattern-style modifiers.
1156
- *
1157
- * This function will eventually be replaced by https://github.com/whatwg/urlpattern/issues/73
1158
- *
1159
- * Matches:
1160
- * - :name -> Simple
1161
- * - :name? -> Optional
1162
- * - :name+ -> One or more
1163
- * - :name* -> Zero or more
1164
- * - :name(...) -> Regex group
1165
- * - {text} -> Group delimiter
1166
- * - {text}? -> Optional group delimiter
1167
- *
1168
- * If the value is `null`, the segment is removed.
1169
- *
1170
- * @param {string} pattern - The URL pattern containing named groups.
1171
- * @param {Record<string, string | null | undefined>} values - Object of values for named groups.
1172
- * @param {string} origin - Base URL to use for URL construction.
1173
- * @returns {URL} - The constructed URL with named groups filled.
1174
- */
1175
- function fillPattern(pattern, values, origin) {
1176
- // Pre-process the pattern to handle explicit port numbers
1177
- // This detects patterns like "http://localhost:5173" and protects the port number
1178
- // from being interpreted as a parameter
1179
- let processedPattern = pattern.replace(/(https?:\/\/[^:/]+):(\d+)(\/|$)/g, (_, protocol, port, slash) => {
1180
- // Replace ":5173" with "#PORT-5173#" to protect it from parameter replacement
1181
- return `${protocol}#PORT-${port}#${slash}`;
1182
- });
1183
- // First, handle group delimiters with curly braces
1184
- let processedGroupDelimiters = processedPattern.replace(/\{([^{}]*)\}([?+*]?)/g, (_, content, modifier) => {
1185
- // For optional group delimiters
1186
- if (modifier === "?") {
1187
- // For optional groups, we'll include the content
1188
- return content;
1189
- }
1190
- // For non-optional group delimiters, always include the content
1191
- return content;
1192
- });
1193
- // Then handle named groups
1194
- let filled = processedGroupDelimiters.replace(/(\/?):([a-zA-Z0-9_]+)(\([^)]*\))?([?+*]?)/g, (_, slash, name, __, modifier) => {
1195
- const value = values[name];
1196
- if (value === null) {
1197
- // If value is null, remove the entire segment including the preceding slash
1198
- return "";
1199
- }
1200
- if (modifier === "?") {
1201
- // Optional segment
1202
- return value !== undefined ? `${slash}${value}` : "";
1203
- }
1204
- if (modifier === "+" || modifier === "*") {
1205
- // Repeatable segments
1206
- if (value === undefined && modifier === "+") {
1207
- throw new Error(`Missing value for "${name}" (one or more required)`);
1208
- }
1209
- return value ? `${slash}${value}` : "";
1210
- }
1211
- // Simple named group (no modifier)
1212
- if (value === undefined) {
1213
- throw new Error(`Missing value for "${name}"`);
1214
- }
1215
- return `${slash}${value}`;
1216
- });
1217
- // Restore port numbers
1218
- filled = filled.replace(/#PORT-(\d+)#/g, ":$1");
1219
- return new URL(filled, origin);
1220
- }
1221
- /**
1222
- * Aggregates named groups from various parts of the URLPattern match result.
1223
- *
1224
- *
1225
- * @param {any} match - The URLPattern match result object.
1226
- * @returns {Record<string, string | null | undefined>} An object containing all named groups from the match.
1227
- */
1228
- export function aggregateGroups(match) {
1229
- return {
1230
- ...match.hash.groups,
1231
- ...match.hostname.groups,
1232
- ...match.password.groups,
1233
- ...match.pathname.groups,
1234
- ...match.port.groups,
1235
- ...match.protocol.groups,
1236
- ...match.search.groups,
1237
- ...match.username.groups,
1238
- };
1239
- }
1240
-
1241
- /**
1242
- * @typedef {object} ShouldRedirectServerInput
1243
- * @property {Request} request
1244
- * @property {string | URL} [url]
1245
- * @property {Locale} [locale]
1246
- *
1247
- * @typedef {object} ShouldRedirectClientInput
1248
- * @property {undefined} [request]
1249
- * @property {string | URL} [url]
1250
- * @property {Locale} [locale]
1251
- *
1252
- * @typedef {ShouldRedirectServerInput | ShouldRedirectClientInput} ShouldRedirectInput
1253
- *
1254
- * @typedef {object} ShouldRedirectResult
1255
- * @property {boolean} shouldRedirect - Indicates whether the consumer should perform a redirect.
1256
- * @property {Locale} locale - Locale resolved using the configured strategies.
1257
- * @property {URL | undefined} redirectUrl - Destination URL when a redirect is required.
1258
- */
1259
- /**
1260
- * Determines whether a redirect is required to align the current URL with the active locale.
1261
- *
1262
- * This helper mirrors the logic that powers `paraglideMiddleware`, but works in both server
1263
- * and client environments. It evaluates the configured strategies in order, computes the
1264
- * canonical localized URL, and reports when the current URL does not match.
1265
- *
1266
- * When called in the browser without arguments, the current `window.location.href` is used.
1267
- *
1268
- * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing#client-side-redirects
1269
- *
1270
- * @example
1271
- * // Client side usage (e.g. TanStack Router beforeLoad hook)
1272
- * async function beforeLoad({ location }) {
1273
- * const decision = await shouldRedirect({ url: location.href });
1274
- *
1275
- * if (decision.shouldRedirect) {
1276
- * throw redirect({ to: decision.redirectUrl.href });
1277
- * }
1278
- * }
1279
- *
1280
- * @example
1281
- * // Server side usage with a Request
1282
- * export async function handle(request) {
1283
- * const decision = await shouldRedirect({ request });
1284
- *
1285
- * if (decision.shouldRedirect) {
1286
- * return Response.redirect(decision.redirectUrl, 307);
1287
- * }
1288
- *
1289
- * return render(request, decision.locale);
1290
- * }
1291
- *
1292
- * @param {ShouldRedirectInput} [input]
1293
- * @returns {Promise<ShouldRedirectResult>}
1294
- */
1295
- export async function shouldRedirect(input = {}) {
1296
- const currentUrl = resolveUrl(input);
1297
- const locale = await resolveLocale(input, currentUrl);
1298
- const strategy = getStrategyForUrl(currentUrl.href);
1299
- if (isExcludedByRouteStrategy(currentUrl.href) || !strategy.includes("url")) {
1300
- return { shouldRedirect: false, locale, redirectUrl: undefined };
1301
- }
1302
- const localizedUrl = localizeUrl(currentUrl.href, { locale });
1303
- const shouldRedirectToLocalizedUrl = normalizeUrl(localizedUrl.href) !== normalizeUrl(currentUrl.href);
1304
- return {
1305
- shouldRedirect: shouldRedirectToLocalizedUrl,
1306
- locale,
1307
- redirectUrl: shouldRedirectToLocalizedUrl ? localizedUrl : undefined,
1308
- };
1309
- }
1310
- /**
1311
- * Resolves the locale either from the provided input or by using the configured strategies.
1312
- *
1313
- * @param {ShouldRedirectInput} input
1314
- * @param {URL} currentUrl
1315
- * @returns {Promise<Locale>}
1316
- */
1317
- async function resolveLocale(input, currentUrl) {
1318
- const locale = toLocale(input.locale);
1319
- if (locale) {
1320
- return locale;
1321
- }
1322
- if (input.request) {
1323
- return extractLocaleFromRequestAsync(input.request);
1324
- }
1325
- if (typeof input.url !== "undefined") {
1326
- return getLocaleForUrl(currentUrl.href);
1327
- }
1328
- return getLocale();
1329
- }
1330
- /**
1331
- * Resolves the current URL from the provided input or runtime context.
1332
- *
1333
- * @param {ShouldRedirectInput} input
1334
- * @returns {URL}
1335
- */
1336
- function resolveUrl(input) {
1337
- if (input.request) {
1338
- return new URL(input.request.url);
1339
- }
1340
- if (input.url instanceof URL) {
1341
- return new URL(input.url.href);
1342
- }
1343
- if (typeof input.url === "string") {
1344
- return new URL(input.url, getUrlOrigin());
1345
- }
1346
- if (typeof window !== "undefined" && window?.location?.href) {
1347
- return new URL(window.location.href);
1348
- }
1349
- throw new Error("shouldRedirect() requires either a request, an absolute URL, or must run in a browser environment.");
1350
- }
1351
- /**
1352
- * Normalize url for comparison by stripping the trailing slash.
1353
- *
1354
- * @param {string} url
1355
- * @returns {string}
1356
- */
1357
- function normalizeUrl(url) {
1358
- const urlObj = new URL(url);
1359
- urlObj.pathname = urlObj.pathname.replace(/\/$/, "");
1360
- return urlObj.href;
1361
- }
1362
-
1363
- /**
1364
- * High-level URL localization function optimized for client-side UI usage.
1365
- *
1366
- * This is a convenience wrapper around `localizeUrl()` that provides features
1367
- * needed in UI:
1368
- *
1369
- * - Accepts relative paths (e.g., "/about")
1370
- * - Returns relative paths when possible
1371
- * - Automatically detects current locale if not specified
1372
- * - Handles string input/output instead of URL objects
1373
- *
1374
- * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing
1375
- *
1376
- * @example
1377
- * ```typescript
1378
- * // In a React/Vue/Svelte component
1379
- * const NavLink = ({ href }) => {
1380
- * // Automatically uses current locale, keeps path relative
1381
- * return <a href={localizeHref(href)}>...</a>;
1382
- * };
1383
- *
1384
- * // Examples:
1385
- * localizeHref("/about")
1386
- * // => "/de/about" (if current locale is "de")
1387
- * localizeHref("/store", { locale: "fr" })
1388
- * // => "/fr/store" (explicit locale)
1389
- *
1390
- * // Cross-origin links remain absolute
1391
- * localizeHref("https://other-site.com/about")
1392
- * // => "https://other-site.com/de/about"
1393
- * ```
1394
- *
1395
- * For server-side URL localization (e.g., in middleware), use `localizeUrl()`
1396
- * which provides more precise control over URL handling.
1397
- *
1398
- * @param {string} href - The href to localize (can be relative or absolute)
1399
- * @param {object} [options] - Options for localization
1400
- * @param {Locale} [options.locale] - Target locale. If not provided, uses `getLocale()`
1401
- * @returns {string} The localized href, relative if input was relative
1402
- */
1403
- export function localizeHref(href, options) {
1404
- const currentLocale = getLocale();
1405
- const locale = options?.locale ?? currentLocale;
1406
- const url = new URL(href, getUrlOrigin());
1407
- const localized = localizeUrl(url, { locale });
1408
- // if the origin is identical and the href is relative,
1409
- // return the relative path
1410
- if (href.startsWith("/") && url.origin === localized.origin) {
1411
- // check for cross origin localization in which case an absolute URL must be returned.
1412
- if (locale !== currentLocale) {
1413
- const localizedCurrentLocale = localizeUrl(url, {
1414
- locale: currentLocale,
1415
- });
1416
- if (localizedCurrentLocale.origin !== localized.origin) {
1417
- return localized.href;
1418
- }
1419
- }
1420
- return localized.pathname + localized.search + localized.hash;
1421
- }
1422
- return localized.href;
1423
- }
1424
- /**
1425
- * High-level URL de-localization function optimized for client-side UI usage.
1426
- *
1427
- * This is a convenience wrapper around `deLocalizeUrl()` that provides features
1428
- * needed in the UI:
1429
- *
1430
- * - Accepts relative paths (e.g., "/de/about")
1431
- * - Returns relative paths when possible
1432
- * - Handles string input/output instead of URL objects
1433
- *
1434
- * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/i18n-routing
1435
- *
1436
- * @example
1437
- * ```typescript
1438
- * // In a React/Vue/Svelte component
1439
- * const LocaleSwitcher = ({ href }) => {
1440
- * // Remove locale prefix before switching
1441
- * const baseHref = deLocalizeHref(href);
1442
- * return locales.map(locale =>
1443
- * <a href={localizeHref(baseHref, { locale })}>
1444
- * Switch to {locale}
1445
- * </a>
1446
- * );
1447
- * };
1448
- *
1449
- * // Examples:
1450
- * deLocalizeHref("/de/about") // => "/about"
1451
- * deLocalizeHref("/fr/store") // => "/store"
1452
- *
1453
- * // Cross-origin links remain absolute
1454
- * deLocalizeHref("https://example.com/de/about")
1455
- * // => "https://example.com/about"
1456
- * ```
1457
- *
1458
- * For server-side URL de-localization (e.g., in middleware), use `deLocalizeUrl()`
1459
- * which provides more precise control over URL handling.
1460
- *
1461
- * @param {string} href - The href to de-localize (can be relative or absolute)
1462
- * @returns {string} The de-localized href, relative if input was relative
1463
- */
1464
- export function deLocalizeHref(href) {
1465
- const url = new URL(href, getUrlOrigin());
1466
- const deLocalized = deLocalizeUrl(url);
1467
- // If the origin is identical and the href is relative,
1468
- // return the relative path instead of the full URL.
1469
- if (href.startsWith("/") && url.origin === deLocalized.origin) {
1470
- return deLocalized.pathname + deLocalized.search + deLocalized.hash;
1471
- }
1472
- return deLocalized.href;
1473
- }
1474
-
1475
- /**
1476
- * @param {string} safeModuleId
1477
- * @param {Locale} locale
1478
- */
1479
- export function trackMessageCall(safeModuleId, locale) {
1480
- if (isServer === false)
1481
- return;
1482
- const store = serverAsyncLocalStorage?.getStore();
1483
- if (store) {
1484
- store.messageCalls?.add(`${safeModuleId}:${locale}`);
1485
- }
1486
- }
1487
-
1488
- /**
1489
- * Generates localized URL variants for all provided URLs based on your configured locales and URL patterns.
1490
- *
1491
- * This function is essential for Static Site Generation (SSG) where you need to tell your framework
1492
- * which pages to pre-render at build time. It's also useful for generating sitemaps and
1493
- * `<link rel="alternate" hreflang>` tags for SEO.
1494
- *
1495
- * The function respects your `urlPatterns` configuration - if you have translated pathnames
1496
- * (e.g., `/about` → `/ueber-uns` for German), it will generate the correct localized paths.
1497
- *
1498
- * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/static-site-generation
1499
- *
1500
- * @example
1501
- * // Basic usage - generate all locale variants for a list of paths
1502
- * const localizedUrls = generateStaticLocalizedUrls([
1503
- * "/",
1504
- * "/about",
1505
- * "/blog/post-1",
1506
- * ]);
1507
- * // Returns URL objects for each locale:
1508
- * // ["/en/", "/de/", "/en/about", "/de/about", "/en/blog/post-1", "/de/blog/post-1"]
1509
- *
1510
- * @example
1511
- * // Use with framework SSG APIs
1512
- * // SvelteKit
1513
- * export function entries() {
1514
- * const paths = ["/", "/about", "/contact"];
1515
- * return generateStaticLocalizedUrls(paths).map(url => ({
1516
- * locale: extractLocaleFromUrl(url)
1517
- * }));
1518
- * }
1519
- *
1520
- * @example
1521
- * // Sitemap generation
1522
- * const allPages = ["/", "/about", "/blog"];
1523
- * const sitemapUrls = generateStaticLocalizedUrls(allPages);
1524
- *
1525
- * @param {(string | URL)[]} urls - List of canonical URLs or paths to generate localized versions for.
1526
- * Can be absolute URLs (`https://example.com/about`) or paths (`/about`).
1527
- * Paths are resolved against `http://localhost` internally.
1528
- * @returns {URL[]} Array of URL objects representing all localized variants.
1529
- * The order follows each input URL with all its locale variants before moving to the next URL.
1530
- */
1531
- export function generateStaticLocalizedUrls(urls) {
1532
- /** @type {Set<URL>} */
1533
- const localizedUrls = new Set();
1534
- // For default URL pattern, we can optimize the generation
1535
- if (TREE_SHAKE_DEFAULT_URL_PATTERN_USED) {
1536
- for (const urlInput of urls) {
1537
- const url = urlInput instanceof URL
1538
- ? urlInput
1539
- : new URL(urlInput, "http://localhost");
1540
- // Base locale doesn't get a prefix
1541
- localizedUrls.add(url);
1542
- // Other locales get their code as prefix
1543
- for (const locale of locales) {
1544
- if (locale !== baseLocale) {
1545
- const localizedPath = `/${locale}${url.pathname}${url.search}${url.hash}`;
1546
- const localizedUrl = new URL(localizedPath, url.origin);
1547
- localizedUrls.add(localizedUrl);
1548
- }
1549
- }
1550
- }
1551
- return Array.from(localizedUrls);
1552
- }
1553
- // For custom URL patterns, we need to use localizeUrl for each URL and locale
1554
- for (const urlInput of urls) {
1555
- const url = urlInput instanceof URL
1556
- ? urlInput
1557
- : new URL(urlInput, "http://localhost");
1558
- // Try each URL pattern to find one that matches
1559
- let patternFound = false;
1560
- for (const pattern of urlPatterns) {
1561
- try {
1562
- // Try to match the unlocalized pattern
1563
- const unlocalizedMatch = new URLPattern(pattern.pattern, url.href).exec(url.href);
1564
- if (!unlocalizedMatch)
1565
- continue;
1566
- patternFound = true;
1567
- // Track unique localized URLs to avoid duplicates when patterns are the same
1568
- const seenUrls = new Set();
1569
- // Generate localized URL for each locale
1570
- for (const [locale] of pattern.localized) {
1571
- try {
1572
- const localizedUrl = localizeUrl(url, { locale });
1573
- const urlString = localizedUrl.href;
1574
- // Only add if we haven't seen this exact URL before
1575
- if (!seenUrls.has(urlString)) {
1576
- seenUrls.add(urlString);
1577
- localizedUrls.add(localizedUrl);
1578
- }
1579
- }
1580
- catch {
1581
- // Skip if localization fails for this locale
1582
- continue;
1583
- }
1584
- }
1585
- break;
1586
- }
1587
- catch {
1588
- // Skip if pattern matching fails
1589
- continue;
1590
- }
1591
- }
1592
- // If no pattern matched, use the URL as is
1593
- if (!patternFound) {
1594
- localizedUrls.add(url);
1595
- }
1596
- }
1597
- return Array.from(localizedUrls);
1598
- }
1599
-
1600
- /**
1601
- * @typedef {"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage"} BuiltInStrategy
1602
- */
1603
- /**
1604
- * @typedef {`custom_${string}`} CustomStrategy
1605
- */
1606
- /**
1607
- * @typedef {BuiltInStrategy | CustomStrategy} Strategy
1608
- */
1609
- /**
1610
- * @typedef {Array<Strategy>} Strategies
1611
- */
1612
- /**
1613
- * @typedef {{ getLocale: (request?: Request) => Promise<string | undefined> | (string | undefined) }} CustomServerStrategyHandler
1614
- */
1615
- /**
1616
- * @typedef {{ getLocale: () => Promise<string|undefined> | (string | undefined), setLocale: (locale: string) => Promise<void> | void }} CustomClientStrategyHandler
1617
- */
1618
- /** @type {Map<string, CustomServerStrategyHandler>} */
1619
- export const customServerStrategies = new Map();
1620
- /** @type {Map<string, CustomClientStrategyHandler>} */
1621
- export const customClientStrategies = new Map();
1622
- /**
1623
- * Checks if the given strategy is a custom strategy.
1624
- *
1625
- * @param {unknown} strategy The name of the custom strategy to validate.
1626
- * Must be a string that starts with "custom-" followed by alphanumeric characters, hyphens, or underscores.
1627
- * @returns {boolean} Returns true if it is a custom strategy, false otherwise.
1628
- */
1629
- export function isCustomStrategy(strategy) {
1630
- return (typeof strategy === "string" && /^custom-[A-Za-z0-9_-]+$/.test(strategy));
1631
- }
1632
- /**
1633
- * Defines a custom strategy that is executed on the server.
1634
- *
1635
- * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy#write-your-own-strategy
1636
- *
1637
- * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
1638
- * @param {CustomServerStrategyHandler} handler The handler for the custom strategy, which should implement
1639
- * the method getLocale.
1640
- * @returns {void}
1641
- */
1642
- export function defineCustomServerStrategy(strategy, handler) {
1643
- if (!isCustomStrategy(strategy)) {
1644
- throw new Error(`Invalid custom strategy: "${strategy}". Must be a custom strategy following the pattern custom-name.`);
1645
- }
1646
- customServerStrategies.set(strategy, handler);
1647
- }
1648
- /**
1649
- * Defines a custom strategy that is executed on the client.
1650
- *
1651
- * @see https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy#write-your-own-strategy
1652
- *
1653
- * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
1654
- * @param {CustomClientStrategyHandler} handler The handler for the custom strategy, which should implement the
1655
- * methods getLocale and setLocale.
1656
- * @returns {void}
1657
- */
1658
- export function defineCustomClientStrategy(strategy, handler) {
1659
- if (!isCustomStrategy(strategy)) {
1660
- throw new Error(`Invalid custom strategy: "${strategy}". Must be a custom strategy following the pattern custom-name.`);
1661
- }
1662
- customClientStrategies.set(strategy, handler);
1663
- }
1664
-
1665
- // ------ TYPES ------
1666
- export {};
1667
- /**
1668
- * A locale that is available in the project.
1669
- *
1670
- * @example
1671
- * setLocale(request.locale as Locale)
1672
- *
1673
- * @typedef {typeof locales[number]} Locale
1674
- */
1675
- /**
1676
- * A branded type representing a localized string.
1677
- *
1678
- * Message functions return this type instead of \`string\`, enabling TypeScript
1679
- * to distinguish translated strings from regular strings at compile time.
1680
- * This allows you to enforce that only properly localized content is used
1681
- * in your UI components.
1682
- *
1683
- * Since \`LocalizedString\` is a branded subtype of \`string\`, it remains fully
1684
- * backward compatible—you can pass it anywhere a \`string\` is expected.
1685
- *
1686
- * @example
1687
- * // Enforce localized strings in your components
1688
- * function PageTitle(props: { title: LocalizedString }) {
1689
- * return <h1>{props.title}</h1>
1690
- * }
1691
- *
1692
- * // ✅ Correct: using a message function
1693
- * <PageTitle title={m.welcome_title()} />
1694
- *
1695
- * // ❌ Type error: raw strings are not LocalizedString
1696
- * <PageTitle title="Welcome" />
1697
- *
1698
- * @example
1699
- * // LocalizedString is assignable to string (backward compatible)
1700
- * const localized: LocalizedString = m.greeting()
1701
- * const str: string = localized // ✅ works fine
1702
- *
1703
- * // But string is not assignable to LocalizedString
1704
- * const raw: LocalizedString = "Hello" // ❌ Type error
1705
- *
1706
- * @example
1707
- * // Catches accidental string concatenation
1708
- * function showMessage(msg: LocalizedString) { ... }
1709
- *
1710
- * showMessage(m.hello()) // ✅
1711
- * showMessage("Hello " + userName) // ❌ Type error
1712
- * showMessage(m.hello_user({ name: userName })) // ✅ use params instead
1713
- *
1714
- * @typedef {string & { readonly __brand: 'LocalizedString' }} LocalizedString
1715
- */
1716
- /**
1717
- * A single markup option passed to a tag instance.
1718
- *
1719
- * @typedef {{
1720
- * name: string;
1721
- * value: unknown;
1722
- * }} MessageMarkupOption
1723
- */
1724
- /**
1725
- * A single static markup attribute attached to a tag instance.
1726
- *
1727
- * @typedef {{
1728
- * name: string;
1729
- * value: string | true;
1730
- * }} MessageMarkupAttribute
1731
- */
1732
- /**
1733
- * Record of markup options for a tag instance.
1734
- *
1735
- * @typedef {Record<string, unknown>} MessageMarkupOptions
1736
- */
1737
- /**
1738
- * Record of markup attributes for a tag instance.
1739
- *
1740
- * @typedef {Record<string, string | true>} MessageMarkupAttributes
1741
- */
1742
- /**
1743
- * Type-level schema for a single markup tag.
1744
- *
1745
- * @typedef {{
1746
- * options: MessageMarkupOptions;
1747
- * attributes: MessageMarkupAttributes;
1748
- * children: boolean;
1749
- * }} MessageMarkupTag
1750
- */
1751
- /**
1752
- * Type-level schema for all markup tags in a message.
1753
- *
1754
- * @typedef {Record<string, MessageMarkupTag>} MessageMarkupSchema
1755
- */
1756
- /**
1757
- * Type-only metadata attached to compiled message functions.
1758
- *
1759
- * @template Inputs
1760
- * @template Options
1761
- * @template {MessageMarkupSchema} [Markup = MessageMarkupSchema]
1762
- * @typedef {{
1763
- * readonly __paraglide?: {
1764
- * inputs: Inputs;
1765
- * options: Options;
1766
- * markup: Markup;
1767
- * };
1768
- * }} MessageMetadata
1769
- */
1770
- /**
1771
- * A compiled, framework-neutral message part.
1772
- *
1773
- * @typedef {{
1774
- * type: "text";
1775
- * value: string;
1776
- * } | {
1777
- * type: "markup-start";
1778
- * name: string;
1779
- * options: MessageMarkupOptions;
1780
- * attributes: MessageMarkupAttributes;
1781
- * } | {
1782
- * type: "markup-end";
1783
- * name: string;
1784
- * options: MessageMarkupOptions;
1785
- * attributes: MessageMarkupAttributes;
1786
- * } | {
1787
- * type: "markup-standalone";
1788
- * name: string;
1789
- * options: MessageMarkupOptions;
1790
- * attributes: MessageMarkupAttributes;
1791
- * }} MessagePart
1792
- */
1793
- /**
1794
- * A message function is a message for a specific locale.
1795
- *
1796
- * @example
1797
- * m.hello({ name: 'world' })
1798
- *
1799
- * @typedef {(inputs?: Record<string, never>) => LocalizedString} MessageFunction
1800
- */
1801
- /**
1802
- * A message bundle function that selects the message to be returned.
1803
- *
1804
- * Uses `getLocale()` under the hood to determine the locale with an option.
1805
- *
1806
- * @template {string} T
1807
- *
1808
- * @example
1809
- * * m.hello({ name: 'world' }, { locale: "en" })
1810
- *
1811
- * @typedef {(params: Record<string, never>, options: { locale: T }) => LocalizedString} MessageBundleFunction
1812
- */